Bug 86457 - ImageLoader.save() doesn't save images 1 pixel wide
Summary: ImageLoader.save() doesn't save images 1 pixel wide
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.0.1   Edit
Hardware: PC Linux-GTK
: P3 normal (vote)
Target Milestone: 3.4 M5   Edit
Assignee: Carolyn MacLeod CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2005-02-24 07:11 EST by Stanislav Poboril CLA
Modified: 2008-02-07 11:46 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stanislav Poboril CLA 2005-02-24 07:11:29 EST
I tried to save JPEG with ImageData 24 bit depth, height 240 pixels, width 1
pixel and it thrown this exception:
org.eclipse.swt.SWTException: i/o error
(java.lang.ArrayIndexOutOfBoundsException: -1)
        at org.eclipse.swt.SWT.error(SWT.java:2691)
        at org.eclipse.swt.SWT.error(SWT.java:2616)
        at
org.eclipse.swt.internal.image.FileFormat.unloadIntoStream(FileFormat.java:111)
        at org.eclipse.swt.internal.image.FileFormat.save(FileFormat.java:99)
        at org.eclipse.swt.graphics.ImageLoader.save(ImageLoader.java:194)
Comment 1 Carolyn MacLeod CLA 2005-02-27 20:15:48 EST
Can you please attach the image to this bug report? Thanks!
Comment 2 Stanislav Poboril CLA 2005-02-28 03:09:13 EST
It is not dependent on particular image, so I've created test snippet instead.
And I've found that on Windows it doesn't work too.

import java.io.*;

import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;


public class Main {
    public static void main(String[] args) {
        final Shell shell = new Shell(SWT.SHELL_TRIM);
        shell.setLayout(new GridLayout(5, true));

        new Label(shell, SWT.NONE).setText("Width");

        final Text width = new Text(shell, SWT.BORDER);
        width.setText("1");
        width.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
        new Label(shell, SWT.NONE).setText("Height");

        final Text height = new Text(shell, SWT.BORDER);
        height.setText("240");
        height.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

        Button b = new Button(shell, SWT.NONE);
        b.setText("Test");

        shell.setDefaultButton(b);

        final Display d = shell.getDisplay();
        b.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                int w;
                int h;

                try {
                    w = Integer.parseInt(width.getText().trim());
                    h = Integer.parseInt(height.getText().trim());
                } catch (NumberFormatException exc) {
                    exc.printStackTrace();
                    e.doit = false;

                    return;
                }

                Image i = new Image(d, w, h);
                i.setBackground(d.getSystemColor(SWT.COLOR_RED));

                ImageLoader il = new ImageLoader();
                il.data = new ImageData[] {i.getImageData()};

                try {
                    il.save(new ByteArrayOutputStream(), SWT.IMAGE_JPEG);
                } catch (Exception exc) {
                    exc.printStackTrace();

                    MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR);
                    mb.setMessage("error");
                    mb.open();
                }
            }
        });

        shell.pack(true);
        shell.open();

        while (!shell.isDisposed()) {
            if (!d.readAndDispatch()) {
                d.sleep();
            }
        }
    }
}
Comment 3 Mark Powell CLA 2008-01-11 11:40:18 EST
I posted a fix for bug 47783 that also fixes this bug.  I tested it with the test case posted here to confirm.
Comment 4 Carolyn MacLeod CLA 2008-01-21 17:45:35 EST
Fixed > 20080121.

Released the patch from bug 47783 verbatim.
Tested it with the snippet in comment 2, and the snippet in bug 47783.
Also created a bunch of width 1 images and tested against those.
Walked through the code, and I am happy that the supplied patch exactly fixes
these 2 bugs.

Thanks again, Mark!