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

Resize fails for TYPE_USHORT_GRAY image #35

Open
GoogleCodeExporter opened this issue Apr 20, 2015 · 0 comments
Open

Resize fails for TYPE_USHORT_GRAY image #35

GoogleCodeExporter opened this issue Apr 20, 2015 · 0 comments

Comments

@GoogleCodeExporter
Copy link

— What steps will reproduce the problem?
1. Load the image attached to this issue to BufferedImage object 'bi'.
2. Create ResampleOp 'resampleOp' instance with 120x90 dimensions
3. Invoke resampleOp.filter(bi, null);


— What is the expected output? What do you see instead?
I expect to get a reference to another BufferedImage. Instead I'm getting an 
error:
java.lang.ArrayIndexOutOfBoundsException: 851
    at com.mortennobel.imagescaling.ImageUtils.ints2bytes(ImageUtils.java:177)
    at com.mortennobel.imagescaling.ImageUtils.getPixelsBGR(ImageUtils.java:121)
    at com.mortennobel.imagescaling.ResampleOp.horizontallyFromSrcToWorkGray(ResampleOp.java:456)
    at com.mortennobel.imagescaling.ResampleOp.horizontallyFromSrcToWork(ResampleOp.java:396)
    at com.mortennobel.imagescaling.ResampleOp.doFilter(ResampleOp.java:152)
    at com.mortennobel.imagescaling.AdvancedResizeOp.filter(AdvancedResizeOp.java:81)
    at com.farpost.imagestorage.processing.functions.ImageResizerTest.test(ImageResizerTest.java:106)
(comment: the width of the image is 850)

Here is a detailed test I used to reproduce the problem: 
https://gist.github.com/antonlogvinenko/33f567656ff18abf4b49#file-gistfile1-java
-L14
The error is on line 19.  Line 14 is where I'm trying to change the color model 
to make this test pass (this helps).

I did a bit of debugging: ResampleOp.horizontallyFromSrcToWorkGray method 
allocates the byte[] array of the same size as the int[], but then it invokes 
ImageUtils.getPixelsBGR where the type of image is determined as 
TYPE_USHORT_GRAY, then ints2bytes is invoked (default branch of case) and it 
treats byte[] array as if it was 4 times bigger than it is — mapping each one 
int to 4 bytes, but the arrays have same size, 850, which obviously leads to an 
error.

What version of the product are you using? On what operating system?
0.8.5, test running on OS X, server running same code on Cent OS

Original issue reported on code.google.com by [email protected] on 17 Jun 2014 at 12:55

Attachments:

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

1 participant