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

Appletviewer bugs on rescaled images (colours messed)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.3.0
    • client-libs
    • 2d
    • beta2
    • x86
    • windows_2000



      Name: yyT116575 Date: 11/03/2000


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      Following code bugs on 16bpp colormode@win2k. Works great on 32bpp colour.
      Sourcecode :

      /*
      <applet height=320 width=640 code=bugdemo.class></applet>
      Demonstration applet for Windows Appletviewer image scaling on 16bpp displaycards
      Tero R?nkk?
      Geological survey of Finland
      ###@###.### / ###@###.###


      problem: If you use 16bpp display `(high color) on windows (windows 2000 atleast)
      with appletviewer you'll get wrong colours on scaled (resized image).
      It works correctly on IE+Javaplugin and in 32bpp colour mode.
      You can change colour mode by pressing right mouse button on your
      desktop -> properties -> settings.

      Bigger image on applet is scaled image of smaller one on top of it. You
      can draw on bigger image and see.

      */



      import java.awt.*;
      import java.awt.event.*;
      import java.applet.*;
      import java.awt.image.*;
      import java.util.*;



      public class bugdemo extends Applet {
      private Image drawingImage;
      private Image zoomedImage;
      private Image currentImage;
      private Graphics drawingImageGraphics;
      private Graphics zoomedImageGraphics;
      private Graphics currentImageGraphics;

      private Color bColor = new Color(110, 153, 107); // Colours of background and foreground
      private Color fColor = new Color(200,50,50);

      private static int ORIGINALXSIZE = 100;
      private static int ORIGINALYSIZE = 50;
      private static int ZOOM = 4; // How much do we want to zoom?
      private static int ZOOMAREAXLOC = 102; //location of zoomed image
      private static int ZOOMAREAYLOC = 125;
      private static int ORIGINALIMAGEXLOC = 260; //Location of original image
      private static int ORIGINALIMAGEYLOC = 64;
      private int tempX;
      private int tempY;
      private int tempXM;
      private int tempYM;


      public void init(){

      drawingImage = createImage( ORIGINALXSIZE , ORIGINALYSIZE );
      currentImage = createImage( ORIGINALXSIZE , ORIGINALYSIZE );
      drawingImageGraphics = drawingImage.getGraphics();
      zoomedImage = createImage( ORIGINALXSIZE * ZOOM , ORIGINALYSIZE * ZOOM );
      zoomedImageGraphics = zoomedImage.getGraphics();
      currentImageGraphics = currentImage.getGraphics();
      currentImageGraphics.setColor(bColor);
      currentImageGraphics.fillRect(0,0,ORIGINALXSIZE,ORIGINALYSIZE); //Clear rect
        drawingImageGraphics.setColor(bColor);
      drawingImageGraphics.fillRect(0,0,ORIGINALXSIZE,ORIGINALYSIZE); //Clear rect
      currentImageGraphics.setColor(fColor);
      drawingImageGraphics.setColor(fColor);


      this.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseReleased(MouseEvent e) {
      This_mouseReleased(e);
      }
      public void mousePressed(MouseEvent e) {
      This_mousePressed(e);
            }
      });
      this.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
      public void mouseMoved(MouseEvent e) {
               This_mouseMoved(e);
      }
             public void mouseDragged(MouseEvent e) {
      This_mouseDragged(e);
             }
      });


      }


      public void paint(Graphics g)
      {
      g.drawImage(drawingImage ,ORIGINALIMAGEXLOC , ORIGINALIMAGEYLOC ,null);

      zoomedImageGraphics.drawImage(drawingImage,0,0,ORIGINALXSIZE *ZOOM,ORIGINALYSIZE * ZOOM,null);
      g.drawImage(zoomedImage ,ZOOMAREAXLOC , ZOOMAREAYLOC ,null);

      }

      //Update using double buffering
      public void update(Graphics g) {
      Graphics offgc;
      Image offscreen = null;
      Rectangle box = g.getClipRect();

      // create the offscreen buffer and associated Graphics
      offscreen = createImage(box.width, box.height);
      offgc = offscreen.getGraphics();
      // clear the exposed area
      offgc.setColor(getBackground());
      offgc.fillRect(0, 0, box.width, box.height);
      offgc.setColor(getForeground());
      // do normal redraw
      offgc.translate(-box.x, -box.y);
      paint(offgc);
      // transfer offscreen to window
      g.drawImage(offscreen, box.x, box.y, this);
      }

      private void drawPoint(int x, int y){
      drawingImageGraphics.drawLine( (x - ZOOMAREAXLOC + 1) /
      (ZOOM ) , (y - ZOOMAREAYLOC + 1 ) / (ZOOM ),(x - ZOOMAREAXLOC + 1) / (ZOOM ) ,
      (y - ZOOMAREAYLOC + 1 ) / (ZOOM ));
      this.repaint(x - (ZOOM + 1) ,y - (ZOOM + 1) ,ZOOM * 3,ZOOM * 3);
      }



      //EVENTHANDLERS
       
      ///////////////////////////////////////////////////////////////////////////////////////////////
       
      void This_mouseReleased(MouseEvent e) {
      currentImageGraphics.drawImage(drawingImage,0,0,null);
      this.repaint();
      }
       
      void This_mousePressed(MouseEvent e){
      int x = e.getX();
      int y = e.getY();
      if ( x > ZOOMAREAXLOC && x < (ZOOMAREAXLOC + (ORIGINALXSIZE *
      ZOOM)) && y > ZOOMAREAYLOC && y < (ZOOMAREAYLOC + (ORIGINALYSIZE * ZOOM))) {
      drawingImageGraphics.drawImage(currentImage,0,0,null);
      tempX = e.getX();
      tempY = e.getY();
      drawPoint(tempX,tempY);

      }

      }
       
      void This_mouseDragged(MouseEvent e){

      int x = e.getX();
      int y = e.getY();
      if ( x > ZOOMAREAXLOC && x < (ZOOMAREAXLOC + (ORIGINALXSIZE *
      ZOOM)) && y > ZOOMAREAYLOC && y < (ZOOMAREAYLOC + (ORIGINALYSIZE * ZOOM))) {
      drawPoint(x,y);
      } //END IF
      }

      void This_mouseMoved(MouseEvent e){
      int x = e.getX();
      int y = e.getY();
      tempXM = e.getX();
      tempYM = e.getY();
      if ( x > ZOOMAREAXLOC && x < (ZOOMAREAXLOC + (ORIGINALXSIZE *
      ZOOM)) && y > ZOOMAREAYLOC && y < (ZOOMAREAYLOC + (ORIGINALYSIZE * ZOOM))) {
      drawingImageGraphics.drawImage(currentImage,0,0,null);
      drawPoint(x,y);
      this.repaint();
      }

      }

      } //END CLASS
      (Review ID: 109849)
      ======================================================================

            chaasesunw Chet Haase (Inactive)
            yyoungsunw Yung-ching Young (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: