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

WritableRaster.setPixel() with an array of doubles, gives invalid results

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.2.0
    • 1.2.0
    • client-libs
    • None
    • 2d
    • 1.2beta4
    • generic
    • solaris_2.5.1
    • Not verified

      I'm having problem with the WritableRaster.setPixel() method. Supposely
      setPixel may take input as int, float, or double. But when I created a
      sample model of type DataBuffer.BYTE_DATA, and do setPixel with double
      array as input, I get all the wrong values. However, if I use int array
      as input, everything is fine.

      Enclosed is a short test program. I created a ComponenetSampleModel of
      width=10, height=10, band=3, datatype = BYTE_DATA. Then I initialized a
      double array of size 300, then do setPixel. When I do getPixel to print
      out the actual numbers, they are all wrong. Then I iniatialized a int
      array of size 300, and did the same thing. This time the numbers are
      correct.

      import java.awt.*;
      import java.awt.image.*;

      public class SetPixelTest {
          public static void main(String[] args) {
              int[] offsets = {0, 1, 2};
              int[] results;

              SampleModel sampleModel = new ComponentSampleModel(
                  DataBuffer.BYTE_DATA,
                  10, 10,
                  3, 30,
                  offsets);

              WritableRaster raster = Raster.createWritableRaster(sampleModel, null);

              /* Use double as input. */
              double[] dblpxls = new double[300];
              for (int i = 0; i < 300; i++) {
                  dblpxls[i] = (double)i;
              }
              raster.setPixel(0, 0, 10, 10, dblpxls);

              results = raster.getPixel(0, 0, 10, 10, (int[])null);
              for (int i = 0; i < 300; i++) {
                  System.out.print(results[i]);
                  System.out.print(" ");
              }
              System.out.println();
              System.out.println();

              /* Use int as input. */
              int[] intpxls = new int[300];
              for (int i = 0; i < 300; i++) {
                  intpxls[i] = i;
              }
              raster.setPixel(0, 0, 10, 10, intpxls);

              results = raster.getPixel(0, 0, 10, 10, (int[])null);
              for (int i = 0; i < 300; i++) {
                  System.out.print(results[i]);
                  System.out.print(" ");
              }
              System.out.println();
              System.out.println();
          }
      }

            jehung Jeannette Hung (Inactive)
            jehung Jeannette Hung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: