Skip to main content

Scaling using java.awt.Image is vay faster than bufferedImage. But Why?

6 replies [Last post]
rahjman
Offline
Joined: 2008-09-17

Hi.

I am writing an Applet for viewing large (~2600x3500) tiff files. Here is my scaling method

public static BufferedImage getScaledInstance( Image img, int targetWidth,
int targetHeight, Object hint, boolean higherQuality ) {

long startTime = System.currentTimeMillis();

BufferedImage ret = null;
int w, h;
if (higherQuality) {
// Use multi-step technique: start with original size, then
// scale down in multiple passes with drawImage()
// until the target size is reached
w = img.getWidth(null);
h = img.getHeight(null);
} else {
// Use one-step technique: scale directly from original
// size to target size with a single drawImage() call
w = targetWidth;
h = targetHeight;
}

do {
if (higherQuality && w > targetWidth) {
w /= 2;
if (w < targetWidth) {
w = targetWidth;
}
}

if (higherQuality && h > targetHeight) {
h /= 2;
if (h < targetHeight) {
h = targetHeight;
}
}

ret = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = ret.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, hint);

g2.drawImage(img, 0, 0, w, h, null);
g2.dispose();

} while (w != targetWidth || h != targetHeight);

long stopTime = System.currentTimeMillis();
long runTime = stopTime - startTime;
System.out
.println("Run time: getScaledInstance() : " + runTime + " ms");

return ret;
}

If I use ImageIO to read the tiff file as a BufferedImage and pass it as a source image to method, It takes ~1600ms to scale it down to ~800x600. But if I use Jimi.getImage() and get the image as a java.awt.Image type and pass in method, it takes ~800ms to scale.

I wonder why bufferedimage is slower. I want to use ImageIO instead of Jimi as it supports more formats, it comes with default Jdk and Jimi seems old framework. But as I said, if I use ImageIO, I get a BufferedImage that scales slower.

And I wonder if I learn and use VolatileImage, should it be faster or I will no effect for my purpose.

Thanks and sorry for my bad english.

Edit: And I use BICUBIC hint and multi-step scaling for my method

Message was edited by: rahjman

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Jim Graham

There appears to be a bug in your method. Was this a cut-and-paste error?

java2d@JAVADESKTOP.ORG wrote:
> Hi.
>
> I am writing an Applet for viewing large (~2600x3500) tiff files. Here is my scaling method
>
> public static BufferedImage getScaledInstance( Image img, int targetWidth,
> int targetHeight, Object hint, boolean higherQuality ) {
>
> [...lines deleted for brevity...]
>
> ret = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
> Graphics2D g2 = ret.createGraphics();
> g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, hint);
>
> g2.drawImage(img, 0, 0, w, h, null);
> g2.dispose();

This line should be added here:

img = ret;

>
> } while (w != targetWidth || h != targetHeight);
> [...more lines deleted for brevity...]
> }

Does that help the timings any? It should definitely improve the
quality of the results for this case.

Also, which version of the JDK are you using and what kind of image is
returned from the ImageIO.read method? Doing a System.out.println() on
the returned BufferedImage will print out a lot of detail about its type
and internal storage structure. Also, if you run with the command line
argument "-Dsun.java2d.trace=log" you can see which kinds of operations
are used for the scaling operations.

...jim

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

rahjman
Offline
Joined: 2008-09-17

Thanks for your hint :) I really can't believe I forget that king of thing. But I surprised it did not make any difference.

And here infos that you asked;

Ä°mage info: sun.awt.image.ToolkitImage@21b220 //source image that i get with Jimi.

Run time: getScaledInstance() : 718 ms

//the returning scaled result as buffered image
BufferedImage info : BufferedImage@62937c: type = 1 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0 IntegerInterleavedRaster: width = 780 height = 1102 #Bands = 3 xOff = 0 yOff = 0 dataOffset[0] 0

and here the trace result;

Ä°mage info: sun.awt.image.ToolkitImage@15a0305
sun.java2d.loops.TransformHelper::TransformHelper(Index8Gray, SrcNoEa, IntArgbPre)
sun.java2d.loops.TransformHelper::TransformHelper(IntRgb, SrcNoEa, IntArgbPre)
Run time: getScaledInstance() : 703 ms
BufferedImage info : BufferedImage@1ec6696: type = 1 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0 IntegerInterleavedRaster: width = 780 height = 1102 #Bands = 3 xOff = 0 yOff = 0 dataOffset[0] 0
Run time: init() first scale Render: 1078 ms
GDIFillRect
DXFillRect
DXFillRect
DXFillRect
DXFillRect
DXFillRect
DXDrawRect
DXDrawLine
DXDrawLine
DXDrawLine
DXDrawLine
DXFillRect
DXDrawLine
DXDrawLine
DXDrawLine
DXDrawLine
DXDrawLine
DXDrawLine
DXFillRect
DXDrawLine
DXDrawLine
DXDrawLine
DXDrawLine
DXDrawLine
DXFillRect
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.windows.DDBlitLoops::Blit("Integer RGB DirectDraw", SrcNoEa, "Integer RGB DirectDraw")
sun.java2d.windows.DDBlitLoops::Blit("Integer RGB DirectDraw", SrcNoEa, "Integer RGB DirectDraw")
sun.java2d.windows.DDBlitLoops::Blit("Integer RGB DirectDraw", SrcNoEa, "Integer RGB DirectDraw")
sun.java2d.windows.DDBlitLoops::Blit("Integer RGB DirectDraw", SrcNoEa, "Integer RGB DirectDraw")
DXFillRect
DXFillRect
DXFillRect
DXFillRect
DXFillRect
DXFillRect
DXFillRect
DXDrawLine
DXDrawLine
DXDrawLine
DXDrawLine
DXDrawLine
DXDrawLine
DXDrawLine
DXFillRect
DXDrawLine
DXDrawLine
DXDrawLine
DXDrawLine
DXDrawLine
DXDrawLine
DXDrawLine
DXDrawLine
DXFillRect
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
DXFillRect
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.windows.DDBlitLoops::Blit("Integer RGB DirectDraw", SrcNoEa, "Integer RGB DirectDraw")
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
DXFillRect
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.windows.DDBlitLoops::Blit("Integer RGB DirectDraw", SrcNoEa, "Integer RGB DirectDraw")
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
DXFillRect
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.windows.DDBlitLoops::Blit("Integer RGB DirectDraw", SrcNoEa, "Integer RGB DirectDraw")
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.windows.DDBlitLoops::Blit("Integer RGB DirectDraw", SrcNoEa, "Integer RGB DirectDraw")
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.windows.DDBlitLoops::Blit("Integer RGB DirectDraw", SrcNoEa, "Integer RGB DirectDraw")
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.windows.DDBlitLoops::Blit("Integer RGB DirectDraw", SrcNoEa, "Integer RGB DirectDraw")
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.loops.MaskFill::MaskFill(AnyColor, SrcOver, IntRgb)
sun.java2d.windows.DDBlitLoops::Blit("Integer RGB DirectDraw", SrcNoEa, "Integer RGB DirectDraw")
DXFillRect
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.windows.DDBlitLoops::Blit("Integer RGB DirectDraw", SrcNoEa, "Integer RGB DirectDraw")
sun.java2d.windows.DDBlitLoops::Blit("Integer RGB DirectDraw", SrcNoEa, "Integer RGB DirectDraw")
sun.java2d.loops.DrawGlyphListAA::DrawGlyphListAA(AnyColor, SrcNoEa, IntRgb)
DXDrawRect
DXDrawRect
sun.java2d.windows.DDBlitLoops::Blit("Integer RGB DirectDraw", SrcNoEa, "Integer RGB DirectDraw")
DXFillRect
DXDrawLine
DXDrawLine
DXDrawLine
DXDrawLine
DXFillRect
DXDrawLine
DXDrawLine
DXDrawLine
DXDrawLine
DXDrawLine
DXFillRect
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.loops.Blit::Blit(IntRgb, SrcNoEa, IntRgb)
sun.java2d.windows.DDBlitLoops::Blit("Integer RGB DirectDraw", SrcNoEa, "Integer RGB DirectDraw")
sun.java2d.windows.DDBlitLoops::Blit("Integer RGB DirectDraw", SrcNoEa, "Integer RGB DirectDraw")
sun.java2d.windows.DDBlitLoops::Blit("Integer RGB DirectDraw", SrcNoEa, "Integer RGB DirectDraw")
sun.java2d.windows.DDBlitLoops::Blit("Integer RGB DirectDraw", SrcNoEa, "Integer RGB DirectDraw")
DXFillRect
DXFillRect
DXFillRect
DXFillRect
DXFillRect
DXFillRect
sun.java2d.windows.DDBlitLoops::Blit("Integer RGB DirectDraw", SrcNoEa, "Integer RGB DirectDraw")
DXFillRect
DXDrawLine
DXDrawLine
DXDrawLine
DXDrawLine
DXFillRect
DXDrawLine
DXDrawLine
DXDrawLine
DXDrawLine
DXDrawLine
sun.java2d.windows.DDBlitLoops::Blit("Integer RGB DirectDraw", SrcNoEa, "Integer RGB DirectDraw")
sun.java2d.windows.DDBlitLoops::Blit("Integer RGB DirectDraw", SrcNoEa, "Integer RGB DirectDraw")
sun.java2d.windows.DDBlitLoops::Blit("Integer RGB DirectDraw", SrcNoEa, "Integer RGB DirectDraw")
sun.java2d.windows.DDBlitLoops::Blit("Integer RGB DirectDraw", SrcNoEa, "Integer RGB DirectDraw")
DXFillRect
DXFillRect
DXFillRect
DXFillRect
DXFillRect
DXFillRect
sun.java2d.windows.DDBlitLoops::Blit("Integer RGB DirectDraw", SrcNoEa, "Integer RGB DirectDraw")
GDIFillRect

Jim Graham

Hi,

java2d@JAVADESKTOP.ORG wrote:
> And here infos that you asked;
>
> Ä°mage info: sun.awt.image.ToolkitImage@21b220 //source image that i get with Jimi.

As I read this you are saying that Jimi returned to you a ToolkitImage.
Is that correct? I think that was to be expected. Unfortunately
printing a ToolkitImage doesn't give any clues as to its internal format
like printing a BufferedImage, but we can figure it out from the trace
log (see below).

> Run time: getScaledInstance() : 718 ms

This is the run time for running your scaling method on the Jimi image,
correct?

> //the returning scaled result as buffered image
> BufferedImage info : BufferedImage@62937c: type = 1 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0 IntegerInterleavedRaster: width = 780 height = 1102 #Bands = 3 xOff = 0 yOff = 0 dataOffset[0] 0

What is this image? Is it the result of running your scaling method on
the Jimi image? If so, then this is not what I was asking for - we
already know the format of that image, because it is constructed
manually in the scaling loop (the call to the BufferedImage
constructor). INT_RGB are one of the standard formats which are well
supported in our registered graphics loops.

What I was really asking for is what kind of image you get back from the
ImageIO.Read call.

> and here the trace result;

There was a lot of extraneous information in your trace result.
Obviously there is a lot going on in your program and most of it has no
bearing at all on what is making the scaling method run slower for the
ImageIO image. I just wanted the few logged operations that occured
while running your scaling method. If I can make an educated guess
without knowing your program, I would say that would be the following lines:

> Ä°mage info: sun.awt.image.ToolkitImage@15a0305
> sun.java2d.loops.TransformHelper::TransformHelper(Index8Gray, SrcNoEa, IntArgbPre)
> sun.java2d.loops.TransformHelper::TransformHelper(IntRgb, SrcNoEa, IntArgbPre)
> Run time: getScaledInstance() : 703 ms
> BufferedImage info : BufferedImage@1ec6696: type = 1 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0 IntegerInterleavedRaster: width = 780 height = 1102 #Bands = 3 xOff = 0 yOff = 0 dataOffset[0] 0
> Run time: init() first scale Render: 1078 ms

and the rest of the log after that looked like other assorted graphics
calls that were happening later in your program. Is that correct?

From the above it looks like Jimi returned you an 8-bit grayscale
indexed image. (Printing a toolkit image doesn't print its internal
format, but you can infer the format by looking at the "source image"
type in the first TransformHelper operation.)

I'd be curious to see what kind of image is being returned from ImageIO
for your images and what loops are being used for the duration of the
scaling method (i.e. just an abbreviated log showing the operations
incurred during that one method). I'm guessing it uses a less optimal
format for which we might not have TransformHelper loops defined, but I
need to know the image format and the loops that were used to provide
any more specific information...

...jim

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

rahjman
Offline
Joined: 2008-09-17

I now completely understand you and you are completely right about your guesses :)

I am really glad with your kindness. As you see I don't have any deep info on this subject. But I try to learn what is going on under the hood.

I will write a simple console app that get tiff file with ImageIO.read and just scale it down. I guess I will not produce any unnecessary trace log. I will post the results shortly.

Thank you again.

rahjman
Offline
Joined: 2008-09-17

Here it is

Source image info: BufferedImage@187814: type = 12 IndexColorModel: #pixelBits = 1 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@73a7ab transparency = 1 transIndex = -1 has alpha = false isAlphaPre = false BytePackedRaster: width = 2480 height = 3504 #channels 1 xOff = 0 yOff = 0
sun.java2d.loops.Blit$GeneralMaskBlit::Blit(ByteBinary1Bit, SrcNoEa, IntArgbPre)
sun.java2d.loops.MaskBlit$General::MaskBlit(ByteBinary1Bit, SrcNoEa, IntArgbPre)
sun.java2d.loops.Blit::Blit(ByteBinary1Bit, SrcNoEa, IntArgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, AnyAlpha, IntArgbPre)
sun.java2d.loops.Blit$GeneralMaskBlit::Blit(IntArgbPre, SrcOverNoEa, IntRgb)
sun.java2d.loops.MaskBlit$General::MaskBlit(IntArgbPre, SrcOverNoEa, IntRgb)
sun.java2d.loops.Blit::Blit(IntArgbPre, SrcNoEa, IntArgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.Blit$GeneralMaskBlit::Blit(IntArgb, SrcOverNoEa, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.Blit$GeneralMaskBlit::Blit(IntArgb, SrcOverNoEa, IntRgb)
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
Run time: getScaledInstance() : 1641 ms

I hope this is what you want.

Jim Graham

As I suspected - this is boiling down to the fact that we don't have
specific loops to handle the type of image you are working with so our
"generalized backup loops" are being called on to do the work, albeit at
a slower pace.

The image you got from ImageIO appears to be a 1-bit binary image - I
assume your input data was just a bi-level, possibly black/white, image?
We don't have a lot of loops to handle those images so internally they
need to be converted to other formats for handling. Also, the code
appears to go through our other image scaling path which uses an
AffineTransformOp to scale it rather than the more direct
TransformHelper route that the other images are using.

The good news is that ImageIO is using an image format that takes 8
times less storage to store your source image. The bad news is that it
takes longer to scale.

The workaround would be for you to manually copy the image into a new
BufferedImage of a relatively safe known type - I'd recommend
TYPE_INT_ARGB for this even thought your image doesn't appear to have
alpha because a little birdy just told me that the only conversion loop
we have that is specific to 1-bit images is the one that converts to
that format.

You should also submit a bug on java.sun.com about the poor performance
of scaling 1-bit images - we should probably beef up the loops we have
for that type of image, especially since it seems to be a preferred
output format for at least one type of image format that ImageIO supports...

...jim

java2d@JAVADESKTOP.ORG wrote:
> Here it is
>
> Source image info: BufferedImage@187814: type = 12 IndexColorModel: #pixelBits = 1 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@73a7ab transparency = 1 transIndex = -1 has alpha = false isAlphaPre = false BytePackedRaster: width = 2480 height = 3504 #channels 1 xOff = 0 yOff = 0
> sun.java2d.loops.Blit$GeneralMaskBlit::Blit(ByteBinary1Bit, SrcNoEa, IntArgbPre)
> sun.java2d.loops.MaskBlit$General::MaskBlit(ByteBinary1Bit, SrcNoEa, IntArgbPre)
> sun.java2d.loops.Blit::Blit(ByteBinary1Bit, SrcNoEa, IntArgb)
> sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, AnyAlpha, IntArgbPre)
> sun.java2d.loops.Blit$GeneralMaskBlit::Blit(IntArgbPre, SrcOverNoEa, IntRgb)
> sun.java2d.loops.MaskBlit$General::MaskBlit(IntArgbPre, SrcOverNoEa, IntRgb)
> sun.java2d.loops.Blit::Blit(IntArgbPre, SrcNoEa, IntArgb)
> sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
> sun.java2d.loops.Blit$GeneralMaskBlit::Blit(IntArgb, SrcOverNoEa, IntRgb)
> sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
> sun.java2d.loops.Blit$GeneralMaskBlit::Blit(IntArgb, SrcOverNoEa, IntRgb)
> sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
> Run time: getScaledInstance() : 1641 ms
>
>
>
> I hope this is what you want.
> [Message sent by forum member 'rahjman' (rahjman)]
>
> http://forums.java.net/jive/thread.jspa?messageID=300105
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".