Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 338441 - Exception while saving image data
Summary: Exception while saving image data
Status: RESOLVED WORKSFORME
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.6   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 324440
  Show dependency tree
 
Reported: 2011-02-28 12:12 EST by Ivan Furnadjiev CLA
Modified: 2011-02-28 15:35 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ivan Furnadjiev CLA 2011-02-28 12:12:28 EST
Using the test case below:
public void testCase() {
    Display display = new Display();
    Color white = display.getSystemColor( SWT.COLOR_WHITE );
    PaletteData palette = new PaletteData( new RGB[] { white.getRGB() } );
    ImageData imageData = new ImageData( 10, 10, 24, palette );
    ImageLoader imageLoader = new ImageLoader();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    imageLoader.data = new ImageData[] { imageData };
    imageLoader.save( outputStream, SWT.IMAGE_PNG );
    assertTrue( outputStream.toByteArray().length > 0 );
  }
we got the following exception:
org.eclipse.swt.SWTException: Unsupported color depth
	at org.eclipse.swt.SWT.error(SWT.java:4209)
	at org.eclipse.swt.SWT.error(SWT.java:4124)
	at org.eclipse.swt.SWT.error(SWT.java:4095)
	at org.eclipse.swt.graphics.ImageData.getPixels(ImageData.java:850)
	at org.eclipse.swt.internal.image.PngEncoder.writeImageData(PngEncoder.java:247)
	at org.eclipse.swt.internal.image.PngEncoder.encode(PngEncoder.java:349)
	at org.eclipse.swt.internal.image.PNGFileFormat.unloadIntoByteStream(PNGFileFormat.java:146)
	at org.eclipse.swt.internal.image.FileFormat.unloadIntoStream(FileFormat.java:122)
	at org.eclipse.swt.internal.image.FileFormat.save(FileFormat.java:110)
	at org.eclipse.swt.graphics.ImageLoader.save(ImageLoader.java:202)
	at Image_Test.testCase(Image_Test.java:55)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at junit.framework.TestCase.runTest(TestCase.java:164)
	at junit.framework.TestCase.runBare(TestCase.java:130)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:120)
	at junit.framework.TestSuite.runTest(TestSuite.java:230)
	at junit.framework.TestSuite.run(TestSuite.java:225)
	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Is using of "indexed palette" with a color depth of 24 valid?
Comment 1 Felipe Heidrich CLA 2011-02-28 15:35:12 EST
That is wrong, you can't use indirect palette with 24 bit depth.
Create the palette using masks (direct palette), that should work.