What for is this condition "type == BufferedImage.TYPE_CUSTOM" used in the method Java2DFrameConverter.cloneBufferedImage?
https://github.com/bytedeco/javacv/blob/master/src/main/java/org/bytedeco/javacv/Java2DFrameConverter.java#L75
It makes all my images black. Without this condition all work fine.
It just tries to create a BufferedImage of the same type, but in the case of TYPE_CUSTOM, we probably need to do more work to support all kinds of formats...
It returns new BufferedImage with the same type but without data.
If I use this:
Java2DFrameConverter converter = new Java2DFrameConverter();
Java2DFrameConverter.cloneBufferedImage(converter.convert(frame));
it returns:
return new BufferedImage(bi.getWidth(), bi.getHeight(), type);
Maybe it's better to mark this condition with @todo (or just comment it) and to put only this code in the method?
return new BufferedImage(bi.getColorModel(), bi.copyData(null), bi.isAlphaPremultiplied(), null);
Well, that won't return an image of the right type. So let's get this fixed properly.
We could adopt this solution: https://stackoverflow.com/a/19327237/523744
Could you check that it works in your case? And please do send a PR! Thanks
Isn't it the same as my code above? Are you talking about this one:
static BufferedImage deepCopy(BufferedImage bi) {
ColorModel cm = bi.getColorModel();
boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
WritableRaster raster = bi.copyData(null);
return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
}
I just replaced this:
ColorModel cm = bi.getColorModel();
boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
with this:
bi.isAlphaPremultiplied();
And both of them work properly.
No, the one under, this one: https://stackoverflow.com/a/19327237/523744
Ok. I'll test it.
I also have found this method:
https://github.com/bytedeco/javacv/blob/master/src/main/java/org/bytedeco/javacv/Java2DFrameUtils.java#L47
Both of them passed the test.
Right, that's the same thing though. It doesn't copy the imageType when it's not equal to TYPE_CUSTOM.
Now what's the plan? Do I have to create PRs for both of this files or for the Java2DFrameConverter only?
Java2DFrameUtils should be using Java2DFrameConverter, so let's do that. Sounds good?
Yes. I was going to do it the same way.
Released in version 1.3.3. Thanks for your contribution!