humble-video-noarch/src/main/java/io/humble/video/awt/BgrConverter.java
@Override
  public BufferedImage toImage(BufferedImage output, final MediaPicture input) {
    validatePicture(input);
    // test that the picture is valid
    if (output == null) {
      final byte[] bytes = new byte[willResample() ? mResampleMediaPicture.getDataPlaneSize(0) : input.getDataPlaneSize(0)];
      // create the data buffer from the bytes
      
      final DataBufferByte db = new DataBufferByte(bytes, bytes.length);
      
      // create an a sample model which matches the byte layout of the
      // image data and raster which contains the data which now can be
      // properly interpreted
      int w = mImageWidth;
      int h = mImageHeight;
      
      final SampleModel sm = new PixelInterleavedSampleModel(
        db.getDataType(), w, h, 3, 3 * w, mBandOffsets);
      final WritableRaster wr = Raster.createWritableRaster(sm, db, null);
      
      // create a color model
      
      final ColorModel colorModel = new ComponentColorModel(
        mColorSpace, false, false, ColorModel.OPAQUE, db.getDataType());
      
      // return a new image created from the color model and raster
      
      output = new BufferedImage(colorModel, wr, false, null);
    }

    MediaPicture picture;
    // resample as needed
    AtomicReference<JNIReference> ref = new AtomicReference<JNIReference>(null);
    try {
      if (willResample()) {
        picture = resample(mResampleMediaPicture, input, mToImageResampler);
      } else {
        picture = input;
      }

      final Buffer buffer = picture.getData(0);
      final int size = picture.getDataPlaneSize(0);
      final ByteBuffer byteBuf = buffer.getByteBuffer(0,
          size, ref);
      buffer.delete();

      // get the bytes out of the image
      final DataBufferByte db = (DataBufferByte) output.getRaster()
          .getDataBuffer();
      final byte[] bytes = db.getData();
      // and copy them in.
      byteBuf.get(bytes, 0, size);

      // return a new image created from the color model and raster

      return output;
    } finally {
      if (ref.get() != null)
        ref.get().delete();
    }
  }
@Override
  public BufferedImage toImage(BufferedImage output, final MediaPicture input) {
    validatePicture(input);
    // test that the picture is valid
    if (output == null) {
      final byte[] bytes = new byte[willResample() ? mResampleMediaPicture.getDataPlaneSize(0) : input.getDataPlaneSize(0)];
      // create the data buffer from the bytes
      
      final DataBufferByte db = new DataBufferByte(bytes, bytes.length);
      
      // create an a sample model which matches the byte layout of the
      // image data and raster which contains the data which now can be
      // properly interpreted
      int w = mImageWidth;
      int h = mImageHeight;
      
      final SampleModel sm = new PixelInterleavedSampleModel(
        db.getDataType(), w, h, 3, 3 * w, mBandOffsets);
      final WritableRaster wr = Raster.createWritableRaster(sm, db, null);
      
      // create a color model
      
      final ColorModel colorModel = new ComponentColorModel(
        mColorSpace, false, false, ColorModel.OPAQUE, db.getDataType());
      
      // return a new image created from the color model and raster
      
      output = new BufferedImage(colorModel, wr, false, null);
    }

    MediaPicture picture;
    // resample as needed
    AtomicReference<JNIReference> ref = new AtomicReference<JNIReference>(null);
    try {
      if (willResample()) {
        picture = resample(mResampleMediaPicture, input, mToImageResampler);
      } else {
        picture = input;
      }

      final Buffer buffer = picture.getData(0);
      final int size = picture.getDataPlaneSize(0);
      final ByteBuffer byteBuf = buffer.getByteBuffer(0,
          size, ref);
      buffer.delete();

      // get the bytes out of the image
      final DataBufferByte db = (DataBufferByte) output.getRaster()
          .getDataBuffer();
      final byte[] bytes = db.getData();
      // and copy them in.
      byteBuf.get(bytes, 0, size);

      // return a new image created from the color model and raster

      return output;
    } finally {
      if (ref.get() != null)
        ref.get().delete();
    }
  }
@ Override public BufferedImage toImage ( BufferedImage output , final MediaPicture input ) { validatePicture ( input ) ; // test that the picture is valid if ( output == null ) { final byte [ ] bytes = new byte [ willResample ( ) ? mResampleMediaPicture . getDataPlaneSize ( 0 ) : input . getDataPlaneSize ( 0 ) ] ; // create the data buffer from the bytes final DataBufferByte db = new DataBufferByte ( bytes , bytes . length ) ; // create an a sample model which matches the byte layout of the // image data and raster which contains the data which now can be // properly interpreted int w = mImageWidth ; int h = mImageHeight ; final SampleModel sm = new PixelInterleavedSampleModel ( db . getDataType ( ) , w , h , 3 , 3 * w , mBandOffsets ) ; final WritableRaster wr = Raster . createWritableRaster ( sm , db , null ) ; // create a color model final ColorModel colorModel = new ComponentColorModel ( mColorSpace , false , false , ColorModel . OPAQUE , db . getDataType ( ) ) ; // return a new image created from the color model and raster output = new BufferedImage ( colorModel , wr , false , null ) ; } MediaPicture picture ; // resample as needed AtomicReference < JNIReference > ref = new AtomicReference < JNIReference > ( null ) ; try { if ( willResample ( ) ) { picture = resample ( mResampleMediaPicture , input , mToImageResampler ) ; } else { picture = input ; } final Buffer buffer = picture . getData ( 0 ) ; final int size = picture . getDataPlaneSize ( 0 ) ; final ByteBuffer byteBuf = buffer . getByteBuffer ( 0 , size , ref ) ; buffer . delete ( ) ; // get the bytes out of the image final DataBufferByte db = ( DataBufferByte ) output . getRaster ( ) . getDataBuffer ( ) ; final byte [ ] bytes = db . getData ( ) ; // and copy them in. byteBuf . get ( bytes , 0 , size ) ; // return a new image created from the color model and raster return output ; } finally { if ( ref . get ( ) != null ) ref . get ( ) . delete ( ) ; } }
{@inheritDoc}
{