Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImageUtil.createRotated() unexpectedly adds an alpha channel #1019

Open
whowrotethiscode opened this issue Sep 19, 2024 · 2 comments
Open

ImageUtil.createRotated() unexpectedly adds an alpha channel #1019

whowrotethiscode opened this issue Sep 19, 2024 · 2 comments

Comments

@whowrotethiscode
Copy link

Hello,

TwelveMonkeys version: 3.10.1

ImageUtil.createRotated() unexpectedly adds an alpha channel to the result image
when the source image does not have an alpha channel.

For example:

BufferedImage source = new BufferedImage(100, 50, BufferedImage.TYPE_INT_RGB);
assertEquals(100, source.getWidth());
assertEquals(50, source.getHeight());
assertFalse(source.getColorModel().hasAlpha());

BufferedImage result = ImageUtil.createRotated(source, 90);
assertEquals(50, result.getWidth());
assertEquals(100, result.getHeight());
assertFalse(result.getColorModel().hasAlpha()); // Unexpectedly fails

I noticed this after rotating a JPEG source image
then saving the result image as a JPEG
produces a IIOException: Bogus input colorspace

Obviously we can manually remove the alpha channel
after using ImageUtil.createRotated()

But it is suprising that an alpha channel has been added to the result image
after rotating a source image which does not have an alpha channel.

Thanks.

@haraldk
Copy link
Owner

haraldk commented Sep 19, 2024

Hi,

I agree that this is kind of surprising from an API standpoint. 😀

However, the code explicitly creates an image with transparencey in ImageUtil line 725... So not that surprising... I guess one could add a quick fix for this, by testing the fast flag (which basically tells if this is a quadrant rotation or not), and create a non-transparent image (possibly of the exact same type) in the fast case. I believe we only need transparency in the non-fast cases.

Feel free to provide a PR for this, and add the test case above to verify the (new and improved) correct behavior!

@haraldk
Copy link
Owner

haraldk commented Sep 19, 2024

PS: I wrote this code quite a long time ago, and it was written mainly for quick and easy UI operations... It may not be sufficient for more advanced image processing with high pixel depth or other fancy features. 😬

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants