hupeng1991 / java-image-scaling

Automatically exported from code.google.com/p/java-image-scaling
Other
0 stars 0 forks source link

Resize fails for TYPE_USHORT_GRAY image #35

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
— 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 anton.lo...@gmail.com on 17 Jun 2014 at 12:55

Attachments: