Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Image performance tuning
Image performance tuning [message #441992] Fri, 27 August 2004 09:21 Go to next message
Elmar Bartowitsch is currently offline Elmar BartowitschFriend
Messages: 10
Registered: July 2009
Junior Member
Hi,

Are there any plans to improve the performance of SWT's image rendering
system? The features I need (scaled blitting with GC.drawImage) are
about five times faster with AWT than with SWT; therefore, I'm forced to
implement my render code with AWT and connect it to the SWT app using
SWT_AWT... I'd prefer to use a 'pure' SWT solution though.

So, is this of interest to anyone but me or are SWT images just meant to
display still images, without fancy processing stuff?

thx,
eb
Re: Image performance tuning [message #442044 is a reply to message #441992] Fri, 27 August 2004 13:54 Go to previous messageGo to next message
Andrew Brampton is currently offline Andrew BramptonFriend
Messages: 8
Registered: July 2009
Junior Member
Hi,
Could you show as a example of your SWT code?
I've recently made a control which displays thumbnails of many images and
allows the user to scroll through pages of this. So far I have not noticed
any slowness in my control, but that's maybe because I'm using a few tricks,
which may aid you.

Firstly I construct my canvas with SWT.NO_BACKGROUND and use
addPaintListener to do all the drawing.
When drawing I use a backbuffer to draw on, then the final step I draw the
backbuffer onto the main window... This speed my control up a lot, and
stopped flicking problems I was having when drawing each image one by one to
the window.
Another minor trick I'm using is to create a hashtable of image to
thumbnails, meaning I only need to create the thumbnail once, and then its
cached in the hashtable for fast access later.

Hope these tips help, if not maybe showing us your code could help us
improve your speed.
Thanks
Andrew

"Elmar Bartowitsch" <my.email.address.is.fhs-hagenberg@gmx.at> wrote in
message news:cgmu8i$n6$1@eclipse.org...
> Hi,
>
> Are there any plans to improve the performance of SWT's image rendering
> system? The features I need (scaled blitting with GC.drawImage) are about
> five times faster with AWT than with SWT; therefore, I'm forced to
> implement my render code with AWT and connect it to the SWT app using
> SWT_AWT... I'd prefer to use a 'pure' SWT solution though.
>
> So, is this of interest to anyone but me or are SWT images just meant to
> display still images, without fancy processing stuff?
>
> thx,
> eb
Re: Image performance tuning [message #442073 is a reply to message #441992] Fri, 27 August 2004 15:38 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
Performance is always our number one consideration in SWT. See:

http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/plat form-swt-home/R3_1/plan.html#Overall_Plan

Could you post a simple benchmark test case?

"Elmar Bartowitsch" <my.email.address.is.fhs-hagenberg@gmx.at> wrote in
message news:cgmu8i$n6$1@eclipse.org...
> Hi,
>
> Are there any plans to improve the performance of SWT's image rendering
> system? The features I need (scaled blitting with GC.drawImage) are
> about five times faster with AWT than with SWT; therefore, I'm forced to
> implement my render code with AWT and connect it to the SWT app using
> SWT_AWT... I'd prefer to use a 'pure' SWT solution though.
>
> So, is this of interest to anyone but me or are SWT images just meant to
> display still images, without fancy processing stuff?
>
> thx,
> eb
Re: Image performance tuning [message #442506 is a reply to message #442073] Mon, 06 September 2004 09:37 Go to previous messageGo to next message
Elmar Bartowitsch is currently offline Elmar BartowitschFriend
Messages: 10
Registered: July 2009
Junior Member
Thx for your answers & sorry for the delay!

> Could you post a simple benchmark test case?

Yes... but first a word of explanation: what I have to do in my
application is to display scaled pixel stripes from images. The images
can be very, very large (my current test image has a width of > 40000
pixels), and there are no restrictions on the scaling factor; so caching
pre-scaled images is not an option.

Ok, now the benchmark program... just creates image objects for AWT and
SWT (one containing the original image, one serving as a target buffer),
then clocks the time it takes to copy all pixel stripes from the source
to the target, applying a scaling factor of 0.5 (because the target
image is half as high as the source image).

The sample image is passed as the only command-line argument; any image
should work and produce an output showing the average time per copy
iteration in ms, indicating that the AWT test runs about five times
faster than the SWT test.

So.. here's the code:

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;

public class Main {
public static void main(String[] args) throws IOException {
final int runs = 100;

// create test images
final BufferedImage awtSource = ImageIO.read(new File(args[0]));
final BufferedImage awtTarget = new
BufferedImage(awtSource.getWidth(), awtSource.getHeight() / 2,
awtSource.getType());

final Image swtSource = new Image(Display.getDefault(), args[0]);
final Image swtTarget = new Image(Display.getDefault(),
swtSource.getBounds().width, swtSource.getBounds().height / 2);

// run AWT performance test
final long awtStartTime = System.currentTimeMillis();
for (int i = 0; i < runs; i++) {
copyStripesAWT(awtSource, awtTarget);
}
final long awtEndTime = System.currentTimeMillis();
System.out.println("AWT: " + (awtEndTime - awtStartTime) / runs);

// run SWT performance test
final long swtStartTime = System.currentTimeMillis();
for (int i = 0; i < runs; i++) {
copyStripesSWT(swtSource, swtTarget);
}
final long swtEndTime = System.currentTimeMillis();
System.out.println("SWT: " + (swtEndTime - swtStartTime) / runs);
}

private static void copyStripesAWT(BufferedImage source,
BufferedImage target) {
assert(source.getWidth() == target.getWidth());

final int stripeCount = source.getWidth();
final int sourceHeight = source.getHeight();
final int targetHeight = target.getHeight();
Graphics g = target.getGraphics();

for (int x = 0; x < stripeCount; x++) {
g.drawImage(source,
x, 0, // upper left corner of destination
x + 1, targetHeight, // lower right corner of destination
x, 0, // upper left corner of source
x + 1, sourceHeight, // lower right corner of source
null
);
}

g.dispose();
}

private static void copyStripesSWT(Image source, Image target) {
assert(source.getBounds().width == target.getBounds().width);

final int stripeCount = source.getBounds().width;
final int sourceHeight = source.getBounds().height;
final int targetHeight = target.getBounds().height;
GC gc = new GC(target);

for (int x = 0; x < stripeCount; x++) {
gc.drawImage(source,
x, 0, // upper left corner of source
1, sourceHeight, // size of source
x, 0, // upper left corner of destination
1, targetHeight // size of desination
);
}

gc.dispose();
}
}
Re: Image performance tuning [message #442544 is a reply to message #442506] Tue, 07 September 2004 19:03 Go to previous message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
Please enter a problem report with the snippet. Thanks!

"Elmar Bartowitsch" <my_email_address_is.el_barto@gmx.net> wrote in message
news:chhat8$ha4$1@eclipse.org...
> Thx for your answers & sorry for the delay!
>
> > Could you post a simple benchmark test case?
>
> Yes... but first a word of explanation: what I have to do in my
> application is to display scaled pixel stripes from images. The images
> can be very, very large (my current test image has a width of > 40000
> pixels), and there are no restrictions on the scaling factor; so caching
> pre-scaled images is not an option.
>
> Ok, now the benchmark program... just creates image objects for AWT and
> SWT (one containing the original image, one serving as a target buffer),
> then clocks the time it takes to copy all pixel stripes from the source
> to the target, applying a scaling factor of 0.5 (because the target
> image is half as high as the source image).
>
> The sample image is passed as the only command-line argument; any image
> should work and produce an output showing the average time per copy
> iteration in ms, indicating that the AWT test runs about five times
> faster than the SWT test.
>
> So.. here's the code:
>
> import java.awt.Graphics;
> import java.awt.image.BufferedImage;
> import java.io.File;
> import java.io.IOException;
> import javax.imageio.ImageIO;
> import org.eclipse.swt.graphics.GC;
> import org.eclipse.swt.graphics.Image;
> import org.eclipse.swt.widgets.Display;
>
> public class Main {
> public static void main(String[] args) throws IOException {
> final int runs = 100;
>
> // create test images
> final BufferedImage awtSource = ImageIO.read(new File(args[0]));
> final BufferedImage awtTarget = new
> BufferedImage(awtSource.getWidth(), awtSource.getHeight() / 2,
> awtSource.getType());
>
> final Image swtSource = new Image(Display.getDefault(), args[0]);
> final Image swtTarget = new Image(Display.getDefault(),
> swtSource.getBounds().width, swtSource.getBounds().height / 2);
>
> // run AWT performance test
> final long awtStartTime = System.currentTimeMillis();
> for (int i = 0; i < runs; i++) {
> copyStripesAWT(awtSource, awtTarget);
> }
> final long awtEndTime = System.currentTimeMillis();
> System.out.println("AWT: " + (awtEndTime - awtStartTime) / runs);
>
> // run SWT performance test
> final long swtStartTime = System.currentTimeMillis();
> for (int i = 0; i < runs; i++) {
> copyStripesSWT(swtSource, swtTarget);
> }
> final long swtEndTime = System.currentTimeMillis();
> System.out.println("SWT: " + (swtEndTime - swtStartTime) / runs);
> }
>
> private static void copyStripesAWT(BufferedImage source,
> BufferedImage target) {
> assert(source.getWidth() == target.getWidth());
>
> final int stripeCount = source.getWidth();
> final int sourceHeight = source.getHeight();
> final int targetHeight = target.getHeight();
> Graphics g = target.getGraphics();
>
> for (int x = 0; x < stripeCount; x++) {
> g.drawImage(source,
> x, 0, // upper left corner of destination
> x + 1, targetHeight, // lower right corner of destination
> x, 0, // upper left corner of source
> x + 1, sourceHeight, // lower right corner of source
> null
> );
> }
>
> g.dispose();
> }
>
> private static void copyStripesSWT(Image source, Image target) {
> assert(source.getBounds().width == target.getBounds().width);
>
> final int stripeCount = source.getBounds().width;
> final int sourceHeight = source.getBounds().height;
> final int targetHeight = target.getBounds().height;
> GC gc = new GC(target);
>
> for (int x = 0; x < stripeCount; x++) {
> gc.drawImage(source,
> x, 0, // upper left corner of source
> 1, sourceHeight, // size of source
> x, 0, // upper left corner of destination
> 1, targetHeight // size of desination
> );
> }
>
> gc.dispose();
> }
> }
Previous Topic:Native drawing onto a Printer device
Next Topic:Contribute action to JavaEditor popup menu
Goto Forum:
  


Current Time: Fri Apr 26 18:36:04 GMT 2024

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

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

Back to the top