humble-video-noarch/src/main/java/io/humble/video/awt/BgrConverter.java
@Override
  public MediaPicture toPicture(MediaPicture output,
      final BufferedImage input, long timestamp) {
    // validate the image

    validateImage(input);
    
    if (output == null) {
      output = MediaPicture.make(mPictureWidth,
          mPictureHeight, getPictureType());
    }

    // get the image byte buffer buffer

    DataBuffer imageBuffer = input.getRaster().getDataBuffer();
    byte[] imageBytes = null;
    int[] imageInts = null;

    // handle byte buffer case

    if (imageBuffer instanceof DataBufferByte) {
      imageBytes = ((DataBufferByte) imageBuffer).getData();
    }

    // handle integer buffer case

    else if (imageBuffer instanceof DataBufferInt) {
      imageInts = ((DataBufferInt) imageBuffer).getData();
    }

    // if it's some other type, throw

    else {
      throw new IllegalArgumentException(
          "Unsupported BufferedImage data buffer type: "
              + imageBuffer.getDataType());
    }

    // create the video picture and get it's underlying buffer

    final AtomicReference<JNIReference> ref = new AtomicReference<JNIReference>(
        null);
    final MediaPicture picture = willResample() ? mResampleMediaPicture : output;
    try {
      Buffer buffer = picture.getData(0);
      int size = picture.getDataPlaneSize(0);
      ByteBuffer pictureByteBuffer = buffer.getByteBuffer(0,
          size, ref);
      buffer.delete();
      buffer = null;

      if (imageInts != null) {
        pictureByteBuffer.order(ByteOrder.BIG_ENDIAN);
        IntBuffer pictureIntBuffer = pictureByteBuffer.asIntBuffer();
        pictureIntBuffer.put(imageInts);
      } else {
        pictureByteBuffer.put(imageBytes);
      }
      pictureByteBuffer = null;
      picture.setTimeStamp(timestamp);
      picture.setComplete(true);

      // resample as needed
      if (willResample()) {
        resample(output, picture, mToPictureResampler);
      }
      return output;
    } finally {
      if (ref.get() != null)
        ref.get().delete();
    }
  }
@Override
  public MediaPicture toPicture(MediaPicture output,
      final BufferedImage input, long timestamp) {
    // validate the image

    validateImage(input);
    
    if (output == null) {
      output = MediaPicture.make(mPictureWidth,
          mPictureHeight, getPictureType());
    }

    // get the image byte buffer buffer

    DataBuffer imageBuffer = input.getRaster().getDataBuffer();
    byte[] imageBytes = null;
    int[] imageInts = null;

    // handle byte buffer case

    if (imageBuffer instanceof DataBufferByte) {
      imageBytes = ((DataBufferByte) imageBuffer).getData();
    }

    // handle integer buffer case

    else if (imageBuffer instanceof DataBufferInt) {
      imageInts = ((DataBufferInt) imageBuffer).getData();
    }

    // if it's some other type, throw

    else {
      throw new IllegalArgumentException(
          "Unsupported BufferedImage data buffer type: "
              + imageBuffer.getDataType());
    }

    // create the video picture and get it's underlying buffer

    final AtomicReference<JNIReference> ref = new AtomicReference<JNIReference>(
        null);
    final MediaPicture picture = willResample() ? mResampleMediaPicture : output;
    try {
      Buffer buffer = picture.getData(0);
      int size = picture.getDataPlaneSize(0);
      ByteBuffer pictureByteBuffer = buffer.getByteBuffer(0,
          size, ref);
      buffer.delete();
      buffer = null;

      if (imageInts != null) {
        pictureByteBuffer.order(ByteOrder.BIG_ENDIAN);
        IntBuffer pictureIntBuffer = pictureByteBuffer.asIntBuffer();
        pictureIntBuffer.put(imageInts);
      } else {
        pictureByteBuffer.put(imageBytes);
      }
      pictureByteBuffer = null;
      picture.setTimeStamp(timestamp);
      picture.setComplete(true);

      // resample as needed
      if (willResample()) {
        resample(output, picture, mToPictureResampler);
      }
      return output;
    } finally {
      if (ref.get() != null)
        ref.get().delete();
    }
  }
{@inheritDoc}