Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Technology Project and PMC » SWT Image ... Speed
SWT Image ... Speed [message #30103] Mon, 07 October 2002 01:43 Go to next message
Justin Kilimnik is currently offline Justin KilimnikFriend
Messages: 12
Registered: July 2009
Junior Member
I have been doing a lot of work lately with the Eclipse workbench and
modifications to it, and a lot of work with SWT.

One major problem I have noticed with SWT is the Image class. Doing a
image read (1600x1200 JPEG) from the file system takes:

500ms in C++/Intel JPEG Graphics Lib
~1200ms in C# with .NET classes
~2000ms in Java using BufferedImageReader
~4000ms in SWT using the Image class and filename name constuctor

There seems to be no way to convert the standard Java Images to SWT images
so I am stuck with the bad performance of swt.Image. Is there anyway to
speed this up? One of the features with the Intel Graphics lib is that you
can (in simple terms) read the image size before loading the image fully
and decide if you wish to only read every 2nd, 4th, 8th, 16th pixel from
the file (which is a great feature when you are generating Thumbnails from
large images.

Is there someone out there on the SWT team that can help with any of this?
(I am prepared to get involved with this myself as well)
Re: SWT Image ... Speed [message #30173 is a reply to message #30103] Mon, 07 October 2002 13:27 Go to previous messageGo to next message
Scott Stanchfield is currently offline Scott StanchfieldFriend
Messages: 263
Registered: July 2009
Senior Member
Here's what I'm using for AWT -> SWT image conversion. Seems to work quite
well w/o the JPEG intermediary. (I used to do the JPEG path as well...).
Note that the error processing needs work -- this is still a rough version
so I could get the "real stuff" in my GUI builder to work...

I haven't done any timings (ironically, I don't have time to time it ;) If
you time this let me know how it does...

java.awt.Image awtImage = ...;

int[] pixels = new int[c.getWidth() * c.getHeight()];
PixelGrabber pg = new PixelGrabber(awtImage, 0, 0, c.getWidth(),
c.getHeight(), pixels, 0, c.getWidth());
try {
pg.grabPixels();
}
catch (InterruptedException e) {
System.err.println("interrupted waiting for pixels!");
return;
}

if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
System.err.println("image fetch aborted or errored");
return;
}

ImageData dest = new ImageData(c.getWidth(), c.getHeight(), 32, new
PaletteData(0xFF0000,0xFF00,0xFF));
byte[] data = dest.data;
for (int i = 0, index = 0; i < c.getWidth() * c.getHeight(); i++, index+=4)
{
int pixel = pixels[i];
data[index] = (byte)((pixel >> 24) & 0xFF);
data[index + 1] = (byte)((pixel >> 16) & 0xFF);
data[index + 2] = (byte)((pixel >> 8) & 0xFF);
data[index + 3] = (byte)(pixel & 0xFF);
}

Image swtImage = new Image(null, dest);


-- Scott

============================================================ ==
Scott Stanchfield scott@javadude.com http://javadude.com

Lead author of "Effective VisualAge for Java, Version 3"
http://javadude.com/evaj

VisualAge for Java Tips and Tricks http://javadude.com/vaj
Visit for Java Enlightenment! http://www.jguru.com
============================================================ ==

"Justin Kilimnik" <justink@au.ibm.com> wrote in message
news:anqore$vbb$1@rogue.oti.com...
> I have been doing a lot of work lately with the Eclipse workbench and
> modifications to it, and a lot of work with SWT.
>
> One major problem I have noticed with SWT is the Image class. Doing a
> image read (1600x1200 JPEG) from the file system takes:
>
> 500ms in C++/Intel JPEG Graphics Lib
> ~1200ms in C# with .NET classes
> ~2000ms in Java using BufferedImageReader
> ~4000ms in SWT using the Image class and filename name constuctor
>
> There seems to be no way to convert the standard Java Images to SWT images
> so I am stuck with the bad performance of swt.Image. Is there anyway to
> speed this up? One of the features with the Intel Graphics lib is that you
> can (in simple terms) read the image size before loading the image fully
> and decide if you wish to only read every 2nd, 4th, 8th, 16th pixel from
> the file (which is a great feature when you are generating Thumbnails from
> large images.
>
> Is there someone out there on the SWT team that can help with any of this?
> (I am prepared to get involved with this myself as well)
>
Re: SWT Image ... Speed [message #30562 is a reply to message #30173] Mon, 07 October 2002 23:18 Go to previous message
Justin Kilimnik is currently offline Justin KilimnikFriend
Messages: 12
Registered: July 2009
Junior Member
Thanks Scott,

I will test this out as soon as possible. With all the Java2D libs out
there it seems like we need some sort of bridge in this area....

Justin

Scott Stanchfield wrote:

> Here's what I'm using for AWT -> SWT image conversion. Seems to work quite
> well w/o the JPEG intermediary. (I used to do the JPEG path as well...).
> Note that the error processing needs work -- this is still a rough version
> so I could get the "real stuff" in my GUI builder to work...

> I haven't done any timings (ironically, I don't have time to time it ;) If
> you time this let me know how it does...

> java.awt.Image awtImage = ...;

> int[] pixels = new int[c.getWidth() * c.getHeight()];
> PixelGrabber pg = new PixelGrabber(awtImage, 0, 0, c.getWidth(),
> c.getHeight(), pixels, 0, c.getWidth());
> try {
> pg.grabPixels();
> }
> catch (InterruptedException e) {
> System.err.println("interrupted waiting for pixels!");
> return;
> }

> if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
> System.err.println("image fetch aborted or errored");
> return;
> }

> ImageData dest = new ImageData(c.getWidth(), c.getHeight(), 32, new
> PaletteData(0xFF0000,0xFF00,0xFF));
> byte[] data = dest.data;
> for (int i = 0, index = 0; i < c.getWidth() * c.getHeight(); i++, index+=4)
> {
> int pixel = pixels[i];
> data[index] = (byte)((pixel >> 24) & 0xFF);
> data[index + 1] = (byte)((pixel >> 16) & 0xFF);
> data[index + 2] = (byte)((pixel >> 8) & 0xFF);
> data[index + 3] = (byte)(pixel & 0xFF);
> }

> Image swtImage = new Image(null, dest);


> -- Scott

> ============================================================ ==
> Scott Stanchfield scott@javadude.com http://javadude.com

> Lead author of "Effective VisualAge for Java, Version 3"
> http://javadude.com/evaj

> VisualAge for Java Tips and Tricks http://javadude.com/vaj
> Visit for Java Enlightenment! http://www.jguru.com
> ============================================================ ==

> "Justin Kilimnik" <justink@au.ibm.com> wrote in message
> news:anqore$vbb$1@rogue.oti.com...
> > I have been doing a lot of work lately with the Eclipse workbench and
> > modifications to it, and a lot of work with SWT.
> >
> > One major problem I have noticed with SWT is the Image class. Doing a
> > image read (1600x1200 JPEG) from the file system takes:
> >
> > 500ms in C++/Intel JPEG Graphics Lib
> > ~1200ms in C# with .NET classes
> > ~2000ms in Java using BufferedImageReader
> > ~4000ms in SWT using the Image class and filename name constuctor
> >
> > There seems to be no way to convert the standard Java Images to SWT images
> > so I am stuck with the bad performance of swt.Image. Is there anyway to
> > speed this up? One of the features with the Intel Graphics lib is that you
> > can (in simple terms) read the image size before loading the image fully
> > and decide if you wish to only read every 2nd, 4th, 8th, 16th pixel from
> > the file (which is a great feature when you are generating Thumbnails from
> > large images.
> >
> > Is there someone out there on the SWT team that can help with any of this?
> > (I am prepared to get involved with this myself as well)
> >
Re: SWT Image ... Speed [message #584205 is a reply to message #30103] Mon, 07 October 2002 13:27 Go to previous message
Scott Stanchfield is currently offline Scott StanchfieldFriend
Messages: 263
Registered: July 2009
Senior Member
Here's what I'm using for AWT -> SWT image conversion. Seems to work quite
well w/o the JPEG intermediary. (I used to do the JPEG path as well...).
Note that the error processing needs work -- this is still a rough version
so I could get the "real stuff" in my GUI builder to work...

I haven't done any timings (ironically, I don't have time to time it ;) If
you time this let me know how it does...

java.awt.Image awtImage = ...;

int[] pixels = new int[c.getWidth() * c.getHeight()];
PixelGrabber pg = new PixelGrabber(awtImage, 0, 0, c.getWidth(),
c.getHeight(), pixels, 0, c.getWidth());
try {
pg.grabPixels();
}
catch (InterruptedException e) {
System.err.println("interrupted waiting for pixels!");
return;
}

if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
System.err.println("image fetch aborted or errored");
return;
}

ImageData dest = new ImageData(c.getWidth(), c.getHeight(), 32, new
PaletteData(0xFF0000,0xFF00,0xFF));
byte[] data = dest.data;
for (int i = 0, index = 0; i < c.getWidth() * c.getHeight(); i++, index+=4)
{
int pixel = pixels[i];
data[index] = (byte)((pixel >> 24) & 0xFF);
data[index + 1] = (byte)((pixel >> 16) & 0xFF);
data[index + 2] = (byte)((pixel >> 8) & 0xFF);
data[index + 3] = (byte)(pixel & 0xFF);
}

Image swtImage = new Image(null, dest);


-- Scott

============================================================ ==
Scott Stanchfield scott@javadude.com http://javadude.com

Lead author of "Effective VisualAge for Java, Version 3"
http://javadude.com/evaj

VisualAge for Java Tips and Tricks http://javadude.com/vaj
Visit for Java Enlightenment! http://www.jguru.com
============================================================ ==

"Justin Kilimnik" <justink@au.ibm.com> wrote in message
news:anqore$vbb$1@rogue.oti.com...
> I have been doing a lot of work lately with the Eclipse workbench and
> modifications to it, and a lot of work with SWT.
>
> One major problem I have noticed with SWT is the Image class. Doing a
> image read (1600x1200 JPEG) from the file system takes:
>
> 500ms in C++/Intel JPEG Graphics Lib
> ~1200ms in C# with .NET classes
> ~2000ms in Java using BufferedImageReader
> ~4000ms in SWT using the Image class and filename name constuctor
>
> There seems to be no way to convert the standard Java Images to SWT images
> so I am stuck with the bad performance of swt.Image. Is there anyway to
> speed this up? One of the features with the Intel Graphics lib is that you
> can (in simple terms) read the image size before loading the image fully
> and decide if you wish to only read every 2nd, 4th, 8th, 16th pixel from
> the file (which is a great feature when you are generating Thumbnails from
> large images.
>
> Is there someone out there on the SWT team that can help with any of this?
> (I am prepared to get involved with this myself as well)
>
Re: SWT Image ... Speed [message #584378 is a reply to message #30173] Mon, 07 October 2002 23:18 Go to previous message
Justin Kilimnik is currently offline Justin KilimnikFriend
Messages: 12
Registered: July 2009
Junior Member
Thanks Scott,

I will test this out as soon as possible. With all the Java2D libs out
there it seems like we need some sort of bridge in this area....

Justin

Scott Stanchfield wrote:

> Here's what I'm using for AWT -> SWT image conversion. Seems to work quite
> well w/o the JPEG intermediary. (I used to do the JPEG path as well...).
> Note that the error processing needs work -- this is still a rough version
> so I could get the "real stuff" in my GUI builder to work...

> I haven't done any timings (ironically, I don't have time to time it ;) If
> you time this let me know how it does...

> java.awt.Image awtImage = ...;

> int[] pixels = new int[c.getWidth() * c.getHeight()];
> PixelGrabber pg = new PixelGrabber(awtImage, 0, 0, c.getWidth(),
> c.getHeight(), pixels, 0, c.getWidth());
> try {
> pg.grabPixels();
> }
> catch (InterruptedException e) {
> System.err.println("interrupted waiting for pixels!");
> return;
> }

> if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
> System.err.println("image fetch aborted or errored");
> return;
> }

> ImageData dest = new ImageData(c.getWidth(), c.getHeight(), 32, new
> PaletteData(0xFF0000,0xFF00,0xFF));
> byte[] data = dest.data;
> for (int i = 0, index = 0; i < c.getWidth() * c.getHeight(); i++, index+=4)
> {
> int pixel = pixels[i];
> data[index] = (byte)((pixel >> 24) & 0xFF);
> data[index + 1] = (byte)((pixel >> 16) & 0xFF);
> data[index + 2] = (byte)((pixel >> 8) & 0xFF);
> data[index + 3] = (byte)(pixel & 0xFF);
> }

> Image swtImage = new Image(null, dest);


> -- Scott

> ============================================================ ==
> Scott Stanchfield scott@javadude.com http://javadude.com

> Lead author of "Effective VisualAge for Java, Version 3"
> http://javadude.com/evaj

> VisualAge for Java Tips and Tricks http://javadude.com/vaj
> Visit for Java Enlightenment! http://www.jguru.com
> ============================================================ ==

> "Justin Kilimnik" <justink@au.ibm.com> wrote in message
> news:anqore$vbb$1@rogue.oti.com...
> > I have been doing a lot of work lately with the Eclipse workbench and
> > modifications to it, and a lot of work with SWT.
> >
> > One major problem I have noticed with SWT is the Image class. Doing a
> > image read (1600x1200 JPEG) from the file system takes:
> >
> > 500ms in C++/Intel JPEG Graphics Lib
> > ~1200ms in C# with .NET classes
> > ~2000ms in Java using BufferedImageReader
> > ~4000ms in SWT using the Image class and filename name constuctor
> >
> > There seems to be no way to convert the standard Java Images to SWT images
> > so I am stuck with the bad performance of swt.Image. Is there anyway to
> > speed this up? One of the features with the Intel Graphics lib is that you
> > can (in simple terms) read the image size before loading the image fully
> > and decide if you wish to only read every 2nd, 4th, 8th, 16th pixel from
> > the file (which is a great feature when you are generating Thumbnails from
> > large images.
> >
> > Is there someone out there on the SWT team that can help with any of this?
> > (I am prepared to get involved with this myself as well)
> >
Previous Topic:[ANN] AntView 2.2.8 Released
Next Topic:Technology for Swing + SWT?
Goto Forum:
  


Current Time: Sat Nov 09 02:28:29 GMT 2024

Powered by FUDForum. Page generated in 0.06048 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top