Package java.awt.image

Examples of java.awt.image.SinglePixelPackedSampleModel


  }

  private void testInt(TestHarness harness)
  {
    harness.checkPoint("(int, int, int, int, DataBuffer(Int))");
    SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
      DataBuffer.TYPE_INT, 2, 3, new int[] { 0xFFFF0000, 0x0000FFFF }
    );
    int[] i = new int[] { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666 };
    DataBuffer db = new DataBufferInt(i, 6)

    // set a value
    m1.setSample(0, 0, 0, 0x00CC, db);
    m1.setSample(1, 0, 0, 0x00BB, db);
    m1.setSample(0, 1, 0, 0x00AA, db);
    m1.setSample(1, 1, 0, 0x0099, db);
    m1.setSample(0, 2, 0, 0x0088, db);
    m1.setSample(1, 2, 0, 0x0077, db);
    m1.setSample(0, 0, 1, 0x0077, db);
    m1.setSample(1, 0, 1, 0x0088, db);
    m1.setSample(0, 1, 1, 0x0099, db);
    m1.setSample(1, 1, 1, 0x00AA, db);
    m1.setSample(0, 2, 1, 0x00BB, db);
    m1.setSample(1, 2, 1, 0x00CC, db);
    harness.check(db.getElem(0), 0x00CC0077);
    harness.check(db.getElem(1), 0x00BB0088);
    harness.check(db.getElem(2), 0x00AA0099);
    harness.check(db.getElem(3), 0x009900AA);
    harness.check(db.getElem(4), 0x008800BB);
    harness.check(db.getElem(5), 0x007700CC);
 
    // set a value with non-standard scanline stride
    SinglePixelPackedSampleModel m2 = new SinglePixelPackedSampleModel(
      DataBuffer.TYPE_INT, 2, 2, 3, new int[] { 0xFFFF0000, 0x0000FFFF }
    );
    m2.setSample(0, 0, 0, 0x0044, db);
    m2.setSample(1, 0, 0, 0x0033, db);
    m2.setSample(0, 1, 0, 0x0022, db);
    m2.setSample(1, 1, 0, 0x0011, db);
    m2.setSample(0, 0, 1, 0x0011, db);
    m2.setSample(1, 0, 1, 0x0022, db);
    m2.setSample(0, 1, 1, 0x0033, db);
    m2.setSample(1, 1, 1, 0x0044, db);
    harness.check(db.getElem(0), 0x00440011);
    harness.check(db.getElem(1), 0x00330022);
    harness.check(db.getElem(3), 0x00220033);
    harness.check(db.getElem(4), 0x00110044);
   
View Full Code Here


  }
 
  private void testByte(TestHarness harness)
  {
    harness.checkPoint("(int, int, Object, DataBuffer(Byte))");
    SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
      DataBuffer.TYPE_BYTE, 2, 2, new int[] { 224, 28, 3 }
    );
    byte[] b = new byte[] { (byte) 11, (byte) 22, (byte) 33, (byte) 44 };
    DataBuffer db = new DataBufferByte(b, 4)
   
    byte[] de = (byte[]) m1.getDataElements(1, 1, null, db);
    harness.check(de.length, 1);                    // check 1
    harness.check(de[0], (byte) 44);                // check 2
   
    // check for coordinates out of bounds
    try                                             // check 3
    {
      m1.getDataElements(2, 2, null, db);
      harness.check(false);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      harness.check(true);
    }
   
    // check for return object of wrong dimension
    try                                             // check 4
    {
      m1.getDataElements(1, 1, new byte[0], db);
      harness.check(false);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      harness.check(true);
    }

    // check for return object of wrong type
    try                                            // check 5
    {
      m1.getDataElements(1, 1, new int[1], db);
      harness.check(false);
    }
    catch (ClassCastException e)
    {
      harness.check(true);
    }

    // check for null data buffer
    try                                            // check 6
    {
      m1.getDataElements(0, 0, null, null);
      harness.check(false);
    }
    catch (NullPointerException e)
    {
      harness.check(true);
View Full Code Here

  }
  
  private void testUShort(TestHarness harness)
  {
    harness.checkPoint("(int, int, Object, DataBuffer(UShort))");
    SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
      DataBuffer.TYPE_USHORT, 2, 2, new int[] { 224, 28, 3 }
    );
    short[] s = new short[] { (short) 11, (short) 22, (short) 33, (short) 44 };
    DataBuffer db = new DataBufferUShort(s, 4)
   
    short[] de = (short[]) m1.getDataElements(1, 1, null, db);
    harness.check(de.length, 1);
    harness.check(de[0], (byte) 44);
   
    // check for coordinates out of bounds
    try
    {
      m1.getDataElements(2, 2, null, db);
      harness.check(false);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      harness.check(true);
    }

    // check for return object of wrong dimension
    try
    {
      m1.getDataElements(1, 1, new short[0], db);
      harness.check(false);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      harness.check(true);
    }

    // check for return object of wrong type
    try
    {
      m1.getDataElements(1, 1, new int[1], db);
      harness.check(false);
    }
    catch (ClassCastException e)
    {
      harness.check(true);
    }

    // check for null data buffer
    try
    {
      m1.getDataElements(0, 0, null, null);
      harness.check(false);
    }
    catch (NullPointerException e)
    {
      harness.check(true);
View Full Code Here

  }
 
  private void testInt(TestHarness harness)
  {
    harness.checkPoint("(int, int, Object, DataBuffer(Int))");
    SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
      DataBuffer.TYPE_INT, 2, 2, new int[] { 224, 28, 3 }
    );
    int[] i = new int[] { 11, 22, 33, 44 };
    DataBuffer db = new DataBufferInt(i, 4)
     
    int[] de = (int[]) m1.getDataElements(1, 1, null, db);
    harness.check(de.length, 1);
    harness.check(de[0], 44);
     
    // check for coordinates out of bounds
    try
    {
      m1.getDataElements(2, 2, null, db);
      harness.check(false);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      harness.check(true);
    }

    // check for return object of wrong dimension
    try
    {
      m1.getDataElements(1, 1, new int[0], db);
      harness.check(false);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      harness.check(true);
    }

    // check for return object of wrong type
    try
    {
      m1.getDataElements(1, 1, new byte[1], db);
      harness.check(false);
    }
    catch (ClassCastException e)
    {
      harness.check(true);
    }

    // check for null data buffer
    try
    {
      m1.getDataElements(0, 0, null, null);
      harness.check(false);
    }
    catch (NullPointerException e)
    {
      harness.check(true);
View Full Code Here

  }
 
  public void testMethod1(TestHarness harness)
  {
    harness.checkPoint("(int, int, int[], DataBuffer)");
    SampleModel m = new SinglePixelPackedSampleModel(DataBuffer.TYPE_BYTE, 10,
            20, new int[] { 224, 28, 3 });
    DataBuffer db = m.createDataBuffer();
    int[] pixel = new int[3];
    m.getPixel(1, 2, pixel, db);
    harness.check(Arrays.equals(pixel, new int[] {0, 0, 0}));
    m.setPixel(1, 2, new int[] {1, 2, 3}, db);
    m.getPixel(1, 2, pixel, db);
    harness.check(Arrays.equals(pixel, new int[] {1, 2, 3}));
   
    // if the incoming array is null, a new one is created
    pixel = m.getPixel(1, 2, (int[]) null, db);
    harness.check(Arrays.equals(pixel, new int[] {1, 2, 3}));
   
    // try null data buffer
    boolean pass = false;
    try
    {
      m.getPixel(1, 2, pixel, null);
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // try with a MultiPixelPackedSampleModel
    m = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, 10, 20, 2);
    db = m.createDataBuffer();
    db.setElem(0, 27);
    harness.check(m.getPixel(0, 0, (int[]) null, db)[0], 0);
    harness.check(m.getPixel(1, 0, (int[]) null, db)[0], 1);
    harness.check(m.getPixel(2, 0, (int[]) null, db)[0], 2);
    harness.check(m.getPixel(3, 0, (int[]) null, db)[0], 3);
    db.setElem(3, 27);
    harness.check(m.getPixel(0, 1, (int[]) null, db)[0], 0);
    harness.check(m.getPixel(1, 1, (int[]) null, db)[0], 1);
    harness.check(m.getPixel(2, 1, (int[]) null, db)[0], 2);
    harness.check(m.getPixel(3, 1, (int[]) null, db)[0], 3);
    db.setElem(6, 0x18);
    db.setElem(9, 0x30);
    db.setElem(12, 0x1C);
    harness.check(m.getPixel(1, 2, (int[]) null, db)[0], 1);
    harness.check(m.getPixel(2, 2, (int[]) null, db)[0], 2);
    harness.check(m.getPixel(1, 3, (int[]) null, db)[0], 3);
    harness.check(m.getPixel(2, 3, (int[]) null, db)[0], 0);
    harness.check(m.getPixel(1, 4, (int[]) null, db)[0], 1);
    harness.check(m.getPixel(2, 4, (int[]) null, db)[0], 3);
  }
View Full Code Here

  }
 
  public void testMethod2(TestHarness harness)
  {
    harness.checkPoint("(int, int, float[], DataBuffer)");    
    SampleModel m = new SinglePixelPackedSampleModel(DataBuffer.TYPE_BYTE, 10,
            20, new int[] { 224, 28, 3 });
    DataBuffer db = m.createDataBuffer();
    float[] pixel = new float[3];
    m.getPixel(1, 2, pixel, db);
    harness.check(Arrays.equals(pixel, new float[] {0, 0, 0}));
    m.setPixel(1, 2, new int[] {1, 2, 3}, db);
    m.getPixel(1, 2, pixel, db);
    harness.check(Arrays.equals(pixel, new float[] {1, 2, 3}));
   
    // if the incoming array is null, a new one is created
    pixel = m.getPixel(1, 2, (float[]) null, db);
    harness.check(Arrays.equals(pixel, new float[] {1, 2, 3}));
   
    // try null data buffer
    boolean pass = false;
    try
    {
      m.getPixel(1, 2, pixel, null);
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
View Full Code Here

  }

  public void testMethod3(TestHarness harness)
  {
    harness.checkPoint("(int, int, double[], DataBuffer)");    
    SampleModel m = new SinglePixelPackedSampleModel(DataBuffer.TYPE_BYTE, 10,
            20, new int[] { 224, 28, 3 });
    DataBuffer db = m.createDataBuffer();
    double[] pixel = new double[3];
    m.getPixel(1, 2, pixel, db);
    harness.check(Arrays.equals(pixel, new double[] {0, 0, 0}));
    m.setPixel(1, 2, new int[] {1, 2, 3}, db);
    m.getPixel(1, 2, pixel, db);
    harness.check(Arrays.equals(pixel, new double[] {1, 2, 3}));
   
    // if the incoming array is null, a new one is created
    pixel = m.getPixel(1, 2, (double[]) null, db);
    harness.check(Arrays.equals(pixel, new double[] {1, 2, 3}));
   
    // try null data buffer
    boolean pass = false;
    try
    {
      m.getPixel(1, 2, pixel, null);
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
View Full Code Here

  }

  private void testByte(TestHarness harness)
  {
    harness.checkPoint("(int, int, Object, DataBuffer(Byte))");
    SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
      DataBuffer.TYPE_BYTE, 2, 3, new int[] { 0xF0, 0x0F }
    );
    byte[] b = new byte[] { (byte) 0x11, (byte) 0x22, (byte) 0x33, (byte) 0x44, (byte) 0x55, (byte) 0x66 };
    DataBuffer db = new DataBufferByte(b, 6)

    // set a value
    m1.setPixel(0, 0, new int[] { 0x0C, 0x07 }, db);
    m1.setPixel(1, 0, new int[] { 0x0B, 0x08 }, db);
    m1.setPixel(0, 1, new int[] { 0x0A, 0x09 }, db);
    m1.setPixel(1, 1, new int[] { 0x09, 0x0A }, db);
    m1.setPixel(0, 2, new int[] { 0x08, 0x0B }, db);
    m1.setPixel(1, 2, new int[] { 0x07, 0x0C }, db);
    harness.check(db.getElem(0), 0xC7);
    harness.check(db.getElem(1), 0xB8);
    harness.check(db.getElem(2), 0xA9);
    harness.check(db.getElem(3), 0x9A);
    harness.check(db.getElem(4), 0x8B);
    harness.check(db.getElem(5), 0x7C);
    // set a value with non-standard scanline stride
    SinglePixelPackedSampleModel m2 = new SinglePixelPackedSampleModel(
      DataBuffer.TYPE_BYTE, 2, 2, 3, new int[] { 0xF0, 0x0F }
    );
    m2.setPixel(0, 0, new int[] { 0x04, 0x01 }, db);
    m2.setPixel(1, 0, new int[] { 0x03, 0x02 }, db);
    m2.setPixel(0, 1, new int[] { 0x02, 0x03 }, db);
    m2.setPixel(1, 1, new int[] { 0x01, 0x04 }, db);
    harness.check(db.getElem(0), 0x41);
    harness.check(db.getElem(1), 0x32);
    harness.check(db.getElem(3), 0x23);
    harness.check(db.getElem(4), 0x14);
  
View Full Code Here

  }

  private void testUShort(TestHarness harness)
  {
    harness.checkPoint("(int, int, Object, DataBuffer(UShort))");
    SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
      DataBuffer.TYPE_USHORT, 2, 3, new int[] { 0xFF00, 0x00FF }
    );
    short[] s = new short[] { (short) 0x1111, (short) 0x2222, (short) 0x3333, (short) 0x4444, (short) 0x5555, (short) 0x6666 };
    DataBuffer db = new DataBufferUShort(s, 6)

    // set a value
    m1.setPixel(0, 0, new int[] { 0x00CC, 0x0077 }, db);
    m1.setPixel(1, 0, new int[] { 0x00BB, 0x0088 }, db);
    m1.setPixel(0, 1, new int[] { 0x00AA, 0x0099 }, db);
    m1.setPixel(1, 1, new int[] { 0x0099, 0x00AA }, db);
    m1.setPixel(0, 2, new int[] { 0x0088, 0x00BB }, db);
    m1.setPixel(1, 2, new int[] { 0x0077, 0x00CC }, db);
    harness.check(db.getElem(0), 0xCC77);
    harness.check(db.getElem(1), 0xBB88);
    harness.check(db.getElem(2), 0xAA99);
    harness.check(db.getElem(3), 0x99AA);
    harness.check(db.getElem(4), 0x88BB);
    harness.check(db.getElem(5), 0x77CC);
  
    // set a value with non-standard scanline stride
    SinglePixelPackedSampleModel m2 = new SinglePixelPackedSampleModel(
      DataBuffer.TYPE_USHORT, 2, 2, 3, new int[] { 0xFF00, 0x00FF }
    );
    m2.setPixel(0, 0, new int[] { 0x0044, 0x0011 }, db);
    m2.setPixel(1, 0, new int[] { 0x0033, 0x0022 }, db);
    m2.setPixel(0, 1, new int[] { 0x0022, 0x0033 }, db);
    m2.setPixel(1, 1, new int[] { 0x0011, 0x0044 }, db);
    harness.check(db.getElem(0), 0x4411);
    harness.check(db.getElem(1), 0x3322);
    harness.check(db.getElem(3), 0x2233);
    harness.check(db.getElem(4), 0x1144);
    
View Full Code Here

  }
 
  public void testMethod1(TestHarness harness)
  {
    harness.checkPoint("(int, int, int, int, int[], DataBuffer)");
    SampleModel m = new SinglePixelPackedSampleModel(DataBuffer.TYPE_BYTE, 10,
            20, new int[] { 224, 28, 3 });
    DataBuffer db = m.createDataBuffer();
    int[] pixel = new int[18];
    m.getPixels(1, 2, 2, 3, pixel, db);
    harness.check(Arrays.equals(pixel, new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0}));
    m.setPixels(1, 2, 2, 3, new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
            13, 14, 15, 16, 17, 18}, db);
    m.getPixels(1, 2, 2, 3, pixel, db);
    harness.check(Arrays.equals(pixel, new int[] {1, 2, 3, 4, 5, 2, 7, 0, 1,
            2, 3, 0, 5, 6, 3, 0, 1, 2}));
   
    // try null pixel data
    boolean pass = false;
    try
    {
      m.setPixels(1, 2, 2, 3, (int[]) null, db);
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
    harness.check(pass);

    // try null data buffer
    pass = false;
    try
    {
      m.setPixels(1, 2, 2, 3, pixel, null);
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
View Full Code Here

TOP

Related Classes of java.awt.image.SinglePixelPackedSampleModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.