@Override
    public Format setOutputFormat(Format output) 
    {
        if (output == null || matches(output, outputFormats) == null)
        {
            return null;
        }

        RGBFormat incoming = (RGBFormat) output;

        Dimension size = incoming.getSize();
        int maxDataLength = incoming.getMaxDataLength();
        int lineStride = incoming.getLineStride();
        float frameRate = incoming.getFrameRate();

        if (size == null)
        {
            return null;
        }
        if (maxDataLength < size.width * size.height * 3)
        {
            maxDataLength = size.width * size.height * 3;
        }
        if (lineStride < size.width * 3)
        {
            lineStride = size.width * 3;
        }
        this.outputFormat = outputFormats[0].intersects(new RGBFormat(
                                                        size,
                                                        maxDataLength,
                                                        null,
                                                        frameRate,
                                                        Format.NOT_SPECIFIED,
                                                        Format.NOT_SPECIFIED,
                                                        Format.NOT_SPECIFIED,
                                                        Format.NOT_SPECIFIED,
                                                        Format.NOT_SPECIFIED,
                                                        lineStride,
                                                        Format.NOT_SPECIFIED,
                                                        Format.NOT_SPECIFIED));
        return outputFormat;
    }