Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4210988

Performance: Producing a large image is very slow

    XMLWordPrintable

    Details

    • Subcomponent:
      2d
    • CPU:
      generic, x86
    • OS:
      generic, windows_nt

      Description

      Name: gsC80088 Date: 02/11/99


      The following code implements a simple
      ImageProducer to create just a white image.

      The producer calls the consumers setPixels()
      method to produce each line.
      The fist call of setPixels takes about 12 seconds
      on my computer. Later calls run at normal speed.

      - java1.2beta4 doesn't have this delay.
      - the delay depends on the size of the image.

      Just run the code below.
      Trace information:

      let's go
      line 0:12448ms
      line 1:12458ms
      line 2:12468ms
      ... and so on


      import java.awt.*;
      import java.awt.image.*;
      import java.awt.event.*;
      //import com.sun.java.swing.*;
      import javax.swing.*;

      public class ImageTest extends JPanel
      {
          static JFrame frame;

          public ImageTest()
          {
              ImageIcon icon;
              JLabel label;
              Image image;
              Producer prod;
              ImageProducer ip;
              
              
              frame = new JFrame("Test");
              frame.addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent e) {System.exit(0);}
      });

              prod = new Producer();
              image = createImage(prod);

              icon = new ImageIcon(image);
              label = new JLabel(icon);
              label.setPreferredSize(new Dimension(800,400));


              System.out.println("produce image second time");
              prod = new Producer();
              image = createImage(prod);

              icon = new ImageIcon(image);
              label = new JLabel(icon);


              frame.getContentPane().setLayout(new BorderLayout());
              frame.getContentPane().add(label, BorderLayout.CENTER);

              frame.pack();
              frame.setVisible(true);
          }

          public static void main(String args[])
          {
              new ImageTest();
          }

          public class Producer implements ImageProducer
          {
              public void startProduction(ImageConsumer ic)
              {
                  ColorModel cm;
                  int aiPixelsWhite[];
                  int iImageWidth, iImageLength;
                  int i,iLine;
                  long lTime;
                  
                  iImageWidth=2480;
                  iImageLength=1748;
                  
                  aiPixelsWhite = new int[iImageWidth];
                  for ( i = 0; i < aiPixelsWhite.length; i++)
                  {
                      aiPixelsWhite[i]=0xffffffff; //white
                  }
                  
                  cm = ColorModel.getRGBdefault();
                  
                  ic.setDimensions(iImageWidth, iImageLength);
                  
                  System.out.println("let's go");
                  
                  lTime = System.currentTimeMillis();
                  for ( iLine = 0; iLine < iImageLength; iLine++)
                  {
                      ic.setPixels(0,iLine,iImageWidth,1,cm,aiPixelsWhite,0,iImageWidth);
                      System.out.println("line "+iLine+":" + (System.currentTimeMillis()-lTime)+"ms");
                  }

                  ic.imageComplete(ImageConsumer.STATICIMAGEDONE);
              }
          
              public void addConsumer(ImageConsumer ic)
              {
                  System.out.println("ImageConsumer");
              }

              public boolean isConsumer(ImageConsumer ic)
              {
                  System.out.println("isConsumer");
                  return false;
              }

              public void removeConsumer(ImageConsumer ic)
              {
                  System.out.println("removeConsumer");
              }

              public void requestTopDownLeftRightResend(ImageConsumer ic)
              {
                  System.out.println("requestTopDownLeftRightResend");
              }



      }

          
      }
      (Review ID: 47781)
      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            bae Andrew Brygin
            Reporter:
            gstone Greg Stone
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: