Community
Participate
Working Groups
I seem to have some problems loading and saving certain types of images in SWT. I'm running Eclipse 2.1 on Windows XP. I have a set of JPEGs taken from the same digital camera and at the same resolution (1600x1200) and compression settings, and most of these pictures can be loaded with Image image = new Image( Display.getCurrent(), filename ); but a small number of them raise this exception: org.eclipse.swt.SWTException: Invalid image at org.eclipse.swt.SWT.error(SWT.java:2316) at org.eclipse.swt.SWT.error(SWT.java:2246) at org.eclipse.swt.internal.image.JPEGFileFormat.nextBit(JPEGFileFormat.java:1567) at org.eclipse.swt.internal.image.JPEGFileFormat.decodeUsingTable (JPEGFileFormat.java:748) at org.eclipse.swt.internal.image.JPEGFileFormat.decodeDCCoefficient (JPEGFileFormat.java:597) at org.eclipse.swt.internal.image.JPEGFileFormat.decodeMCUAtXAndY (JPEGFileFormat.java:673) at org.eclipse.swt.internal.image.JPEGFileFormat.decodeScan (JPEGFileFormat.java:736) at org.eclipse.swt.internal.image.JPEGFileFormat.loadFromByteStream (JPEGFileFormat.java:1450) at org.eclipse.swt.internal.image.FileFormat.loadFromStream(FileFormat.java:43) at org.eclipse.swt.internal.image.FileFormat.load(FileFormat.java:71) at org.eclipse.swt.graphics.ImageLoader.load(ImageLoader.java:120) at org.eclipse.swt.graphics.ImageLoader.load(ImageLoader.java:146) at org.eclipse.swt.graphics.ImageData.<init>(ImageData.java:350) at org.eclipse.swt.graphics.Image.<init>(Image.java:774) ... All of the pictures can be loaded by other apps, including Corel Photopaint which says they are all JPEGs... When I try to load (using the same method as above) and save the same GIF images, loading works and I can see the images, but saving fails. The GIF images are 8-bit images. The code: ImageLoader saver = new ImageLoader(); saver.data = new ImageDat[a] { image.getImageData() }; saver.save( filename, SWT.IMAGE_GIF ); The exception: org.eclipse.swt.SWTException: Unsupported color depth at org.eclipse.swt.SWT.error(SWT.java:2316) at org.eclipse.swt.SWT.error(SWT.java:2246) at org.eclipse.swt.internal.image.GIFFileFormat.unloadIntoByteStream (GIFFileFormat.java:428) at org.eclipse.swt.internal.image.FileFormat.unloadIntoStream(FileFormat.java:103) at org.eclipse.swt.internal.image.FileFormat.save(FileFormat.java:95) at org.eclipse.swt.graphics.ImageLoader.save(ImageLoader.java:190) at org.eclipse.swt.graphics.ImageLoader.save(ImageLoader.java:230) ... I also get an exception when loading and saving 24-bit PNGs (using SWT.IMAGE_PNG): org.eclipse.swt.SWTError: Not implemented at org.eclipse.swt.SWT.error(SWT.java:2342) at org.eclipse.swt.SWT.error(SWT.java:2246) at org.eclipse.swt.internal.image.PNGFileFormat.unloadIntoByteStream (PNGFileFormat.java:123) at org.eclipse.swt.internal.image.FileFormat.unloadIntoStream(FileFormat.java:103) at org.eclipse.swt.internal.image.FileFormat.save(FileFormat.java:95) at org.eclipse.swt.graphics.ImageLoader.save(ImageLoader.java:190) at org.eclipse.swt.graphics.ImageLoader.save(ImageLoader.java:230) I seem to be having no problems with BMP files, thankfully.
Created attachment 4985 [details] Example JPEG image that raises loading exception
Created attachment 4986 [details] Example GIF that raises exception when saving
Created attachment 4987 [details] Example PNG image that raises saving exception
CC to investigate and advise.
This PR will only deal with the JPEG loading problem. For the other savings issues, I have opened bug 38232. Please add yourself to the CC list.
The JPEG from comment #1 can now be loaded using new Image(Device, String); See bug 24451 comment 51 for details. This is not a fix, but it will most likely be a suitable work-around. I will leave this bug open, but I will reduce the priority to P4. Note that the GIF saving problem is covered in bug 38232, and the PNG saving problem is covered in bug 24697.
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it and remove the stalebug whiteboard tag. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. --