Community
Participate
Working Groups
I get an exception when I save an ImageData (width=x HEIGHT=1) to JPEG file : Exception: ------------------------------------------------------- java.lang.ArrayIndexOutOfBoundsException at java.lang.System.arraycopy(Native Method) at org.eclipse.swt.internal.image.JPEGFileFormat.compress(JPEGFileFormat.java:207) at org.eclipse.swt.internal.image.JPEGFileFormat.convertMultiRGBToYCbCr(JPEGFileFormat.java:373) at org.eclipse.swt.internal.image.JPEGFileFormat.convertImageToYCbCr(JPEGFileFormat.java:316) at org.eclipse.swt.internal.image.JPEGFileFormat.unloadIntoByteStream(JPEGFileFormat.java:1887) at org.eclipse.swt.internal.image.FileFormat.unloadIntoStream(FileFormat.java:107) at org.eclipse.swt.internal.image.FileFormat.save(FileFormat.java:99) at org.eclipse.swt.graphics.ImageLoader.save(ImageLoader.java:194) at XXXXXXXXXXXXXXX Source code: ------------------------------------------------------------------- if (compressedHeight < componentHeight) { int srcOfs = (compressedHeight - 1) * componentWidth; for (int yPos = compressedHeight; yPos <= componentHeight; yPos++) { int dstOfs = (yPos - 1) * componentWidth; System.arraycopy(imageComponent, srcOfs, imageComponent, dstOfs, componentWidth); } } So, if compressedHeight=1 , I understand that it calls an System.arrayCopy from a position O to the SAME position 0 ! Thanks for your fantastic project: ECLIPSE !
I am seeing this problem as well with a slight difference. My image is 1x128, but in the snippet below, compressedHeight has been computed to be 0, thus subtracting 1 and multiplying yields negative srcOfs and dstOfs values.
Hi Stef! What version of eclipse are you using? Can you attach your image, please? Thanks, Carolyn
Hey Carolyn. Long time no see. We're still running on Eclipse 3.2.2 at the moment, so it's SWT v3236b. I did peek quickly at the source for 3.3.0 v3325g, but it looked similar and I haven't tried running with that. I don't actually have an image file. We create the image using "new Image(display, width, height)", do some drawing and then calling getImageData(). We put that into an ImageLoader and use FileFormat to save it to a stream.
Created attachment 75415 [details] reproducible testcase
Sorry for not getting back to this sooner, but things have been busy (plus my machine crashed the first time I wrote a testcase and I doubt this is a hot topic for anyone ;)). I'm attaching a simple testcase that mimics what our product does (roughly) and recreates the problem. I just tried it with SWT 3.346 and got the same error I'd seen previously.
I have a fix for this for you...I need to ask for permission from my institution to post it for you (which I will hopefully get shortly.)
Created attachment 86691 [details] Fix for 1-pixel-wide and 1-pixel-high JPEG encoding Here is a fix for this bug. This fix avoids the exception thrown by this test case. I also tested it with the test case for bug 86457 and it fixed that as well.
Fixed > 20080121. Released the patch from comment 7 verbatim. Tested it with the snippet in comment 4, and the snippet in bug 86457. Also created a bunch of height 1 images and tested against those. Walked through the code, and I am happy that the supplied patch exactly fixes these 2 bugs. Thanks, Mark! I have added your name to our contributors page: http://www.eclipse.org/swt/contributors.txt