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

Wrong thumbnail colors #97

Open
lipniagov opened this issue Nov 12, 2013 · 10 comments
Open

Wrong thumbnail colors #97

lipniagov opened this issue Nov 12, 2013 · 10 comments

Comments

@lipniagov
Copy link

The image below transforms into wrong-colored thumbnail.
anime

My first guess was about alpha-channel, but i haven't found it in this image.
My thumbnail is equal to one that http://imgscalr.com/ produces.
(red color prevails)

(I also tried to rename it into jpg but the story was the same)

@ghost
Copy link

ghost commented Nov 12, 2013

@liptonshmidt Immediately after loading the image with ImageIO, what kind of Type is the image that ImageIO returns and what type is the image that the first call to imgscalr returns?

Given how the result looks I am almost certain this is a channel-loss issue, but I am wondering why the PNG conversion is having issues (typically this happens when people convert something with an ALPHA channel to JPG and it clips out the BLUE channel or something like that).

@lipniagov
Copy link
Author

Oh, I see, very interesting:

Immediately after loading the image with ImageIO, imageType == 5 (TYPE_3BYTE_BGR?)
after_io

And imgscalr returns thumbnail with imageType == 1 (TYPE_INT_RGB)
after_scalr

@ghost
Copy link

ghost commented Nov 13, 2013

Hrmm, I think the issue here is the conversion imgscalr is doing from the ComponentColorModel to the DirectColorModel when it converts the image to a more supported type (RGB).

Does this workaround work if you manually convert the initially loaded BufferedImage using this code:
http://stackoverflow.com/a/8385412

and then pass the result to imgscalr and save it out?

I really hope not because setting the pixel data on the buffer pixel-by-pixel is much slower, but at least it would help us understand where things are going south if you didn't mind trying it.

@lipniagov
Copy link
Author

If I understand, firstly I should convert uploaded BufferedImage to swt ImageData object as was demonstrated on stackoverflow, and then, to pass it to scalr, i should convert swt ImageData object back again to BufferedImage object?
If it is right, how should i perform the second conversion? Using code from http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet156.java ?

@ghost
Copy link

ghost commented Nov 16, 2013

Damn, I'm sorry -- I didn't realize that the answer was utilizing SWT classes - no, I wasn't suggesting that you needed to lean on the SWT classes to get this done.

I don't happen to know the right conversion here for the ComponentColorModel to make this picture look right however. The problem sounds familiar to me (I think I looked at this a few years ago) but I don't know the answer off hand using straight Java/Java2D.

If I run into the solution I will post it here however.

@gaydenko
Copy link

Any news?

@lordmarkm
Copy link

Sorry for the necro, has there been a resolution to this issue?

@Firefishy
Copy link

@lordmarkm we had the same issue as described here, code would work fine for days then start returning the wrong colours. Identical source images. We eventually swapped out imgscalr for TwelveMonkeys ImageIO scaling code.

@lordmarkm
Copy link

@Firefishy My problem turned out to be a java issue.
http://stackoverflow.com/questions/4386446/problem-using-imageio-write-jpg-file
The accepted answer on this link, using awt Toolkit instead of ImageIO to read my image fixed it.

@slorber
Copy link

slorber commented Mar 8, 2017

related: #119

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

No branches or pull requests

5 participants