Bug 47783 - Jpeg encoding (image height =1)
Summary: Jpeg encoding (image height =1)
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 2.1.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4 M5   Edit
Assignee: Carolyn MacLeod CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2003-12-01 04:57 EST by Olivier Oeuillot CLA
Modified: 2008-02-07 11:43 EST (History)
2 users (show)

See Also:


Attachments
reproducible testcase (1.52 KB, text/plain)
2007-08-05 22:59 EDT, Stef van Dijk CLA
no flags Details
Fix for 1-pixel-wide and 1-pixel-high JPEG encoding (59.20 KB, patch)
2008-01-11 11:35 EST, Mark Powell CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Oeuillot CLA 2003-12-01 04:57:43 EST
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 !
Comment 1 Stef van Dijk CLA 2007-06-22 15:01:31 EDT
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.
Comment 2 Carolyn MacLeod CLA 2007-06-22 15:32:57 EDT
Hi Stef!
What version of eclipse are you using?
Can you attach your image, please?
Thanks,
Carolyn
Comment 3 Stef van Dijk CLA 2007-06-22 15:56:42 EDT
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.
Comment 4 Stef van Dijk CLA 2007-08-05 22:59:54 EDT
Created attachment 75415 [details]
reproducible testcase
Comment 5 Stef van Dijk CLA 2007-08-05 23:00:48 EDT
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.
Comment 6 Mark Powell CLA 2008-01-01 13:21:34 EST
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.)
Comment 7 Mark Powell CLA 2008-01-11 11:35:43 EST
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.
Comment 8 Carolyn MacLeod CLA 2008-01-21 17:42:16 EST
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