Hello,

I sent the following problem to the JAI interest group, and was told by one of the JAI 
people
that this list would be better place to ask this question. Here is the problem:


I've got a simple JAI chain which rescales the data of a source PlanarImage and tries 
to force
the data of the destination image to be of type DataBuffer.TYPE_BYTE. Here is the code:

.
.
.
  // rescale the data in the image and force the destination image to
  // hold data of type DataBuffer.TYPE_BYTE.
  private PlanarImage rescale( PlanarImage image ) {

    PlanarImage result=null;

    Rectangle rect = image.getBounds();

    // rescale to range
    double[] scale = { 0.5 };
    double[] offset = { 0.0 };

    ParameterBlock pb = new ParameterBlock();
    pb.addSource( image );
    pb.add( scale );
    pb.add( offset );
    result = JAI.create( "rescale", pb,
                         getRenderingHints(
                                           DataBuffer.TYPE_BYTE,
                                           image.getSampleModel(),
                                           rect ) );

    return result;
  }

  RenderingHints getRenderingHints( int dType,
                                    SampleModel smSrc,
                                    Rectangle srcBounds ){

// This causes the repainting of the image to be very slow.
    SampleModel sm =
      RasterFactory.createBandedSampleModel( dType,
                                             (int)srcBounds.getWidth(),
                                             (int)srcBounds.getHeight(),
                                             smSrc.getNumBands() );

    ImageLayout il = new ImageLayout();
    il.setSampleModel(sm);
    return new RenderingHints(JAI.KEY_IMAGE_LAYOUT, il);
  }

.
.
.

This chain yields the creation of a destination image which is very slow to repaint 
when it is
embedded in an IconJAI object. Each time the image's got to repainted, it takes around 
20 or 30
seconds on a P466. I did some time profiling using the hprof agent and came out with 
the
following profiling data:

.
.
.
TRACE 348:
        sun.awt.color.CMM.cmmColorConvert(CMM.java:Native method)
        sun.awt.color.ICC_Transform.colorConvert(ICC_Transform.java:558)
        sun.awt.color.ICC_Transform.colorConvert(ICC_Transform.java:517)
        java.awt.color.ICC_ColorSpace.toRGB(ICC_ColorSpace.java:170)
        java.awt.image.ComponentColorModel.getRed(ComponentColorModel.java:353)
        java.awt.image.ComponentColorModel.getRGB(ComponentColorModel.java:711)
        sun.java2d.loops.OpaqueCopyAny.OpaqueBlit(CustomComponent.java:104)
        sun.java2d.loops.RasterOutputManager.convertFrom(RasterOutputManager.java:1463)
        
sun.java2d.loops.RasterOutputManager.performOpaqueBlit(RasterOutputManager.java:1021)
        
sun.java2d.loops.RasterOutputManager.compositeSrcDst(RasterOutputManager.java:668)
        sun.java2d.loops.RasterOutputManager.renderImage(RasterOutputManager.java:474)
        sun.java2d.SunGraphics2D.renderingPipeImage(SunGraphics2D.java:2232)
        sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:1761)
        
sun.awt.image.BufferedImageGraphics2D.drawImage(BufferedImageGraphics2D.java:512)
        IconJAI.paintIcon(<Unknown>:Unknown line)
        javax.swing.plaf.basic.BasicLabelUI.paint(BasicLabelUI.java:152)

.
.
.
CPU SAMPLES BEGIN (total = 1361) Sun May 28 15:56:55 2000
rank   self  accum   count trace method
   1 32.55% 32.55%     443   348 sun.awt.color.CMM.cmmColorConvert
   2  5.88% 38.43%      80   350 sun.awt.color.CMM.cmmGetNumComponents
   3  5.58% 44.01%      76   355 sun.awt.color.CMM.cmmGetNumComponents
   4  4.70% 48.71%      64   262 sun.awt.windows.WToolkit.eventLoop
   5  4.11% 52.83%      56   367 sun.awt.color.CMM.cmmGetNumComponents
   6  3.75% 56.58%      51   352 sun.awt.color.CMM.cmmGetNumComponents
   7  1.47% 58.05%      20    78 java.lang.Class.forName0
   8  1.47% 59.52%      20    67 java.lang.Class.forName0
CPU SAMPLES END

It seems that the color conversion is the reason of the problem, but to be honest I am 
not sure
of exactly what is going on here. I found out that one way to solve the problem was to 
force
the destination sample model to be of type PixelInterleavedSampleModel. Can anybody 
tell me
what is happening ? For those interested in having a closer look, I've attached the 
source code
of the test program and a test image (the JAIImageReader and IconJAI classes are those 
of the
JAI sample code).

lionel

Windows bitmap

PaintTest.java

Reply via email to