Package java.awt.image

Examples of java.awt.image.DataBufferByte


  private void testGetData1(TestHarness harness) {
    harness.checkPoint("getData()")
 
    // check simple case
    byte[] source = new byte[] {1, 2};
    DataBufferByte b = new DataBufferByte(source, 2);
    byte[] data = b.getData();
    harness.check(data.length == 2);
    harness.check(data[0] == 1);
    harness.check(data[1] == 2);

    // test where supplied array is bigger than 'size'
    source = new byte[] {1, 2, 3};
    b = new DataBufferByte(source, 2);
    data = b.getData();
    harness.check(data.length == 3);
    harness.check(data[0] == 1);
    harness.check(data[1] == 2);
    harness.check(data[2] == 3);

    // test where offsets are specified
    source = new byte[] {1, 2, 3, 4};
    b = new DataBufferByte(source, 2, 1);
    data = b.getData();
    harness.check(data.length == 4);
    harness.check(data[0] == 1);
    harness.check(data[1] == 2);
    harness.check(data[2] == 3);
    harness.check(data[3] == 4);
View Full Code Here


  private void testGetData2(TestHarness harness) {
    harness.checkPoint("getData(int)")
   
    byte[][] source = new byte[][] {{1, 2}, {3, 4}};
    DataBufferByte b = new DataBufferByte(source, 2);
    byte[] data = b.getData(1);
    harness.check(data.length == 2);
    harness.check(data[0] == 3);
    harness.check(data[1] == 4);
 
    // test where supplied array is bigger than 'size'
    source = new byte[][] {{1, 2, 3}, {4, 5, 6}};
    b = new DataBufferByte(source, 2);
    data = b.getData(1);
    harness.check(data.length == 3);
    harness.check(data[0] == 4);
    harness.check(data[1] == 5);
    harness.check(data[2] == 6);
 
    // test where offsets are specified
    source = new byte[][] {{1, 2, 3, 4}, {5, 6, 7, 8}};
    b = new DataBufferByte(source, 2, new int[] {1, 2});
    data = b.getData(1);
    harness.check(data.length == 4);
    harness.check(data[0] == 5);
    harness.check(data[1] == 6);
    harness.check(data[2] == 7);
    harness.check(data[3] == 8);
   
    // does a change to the source affect the DataBuffer? Yes
    source[1][2] = 99;
    harness.check(data[2] == 99);
   
    // check bounds exceptions
    boolean pass = true;
    try
    {
      b.getData(-1);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(pass);
  
    pass = false;
    try
    {
      b.getData(2);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
View Full Code Here

  implements Testlet
{
  public void test(TestHarness h)
  {
    // Check #1.
    h.check(new DataBufferByte(5).getDataType(), DataBuffer.TYPE_BYTE);
  }
View Full Code Here

  private void testSetElem1(TestHarness harness) {
    harness.checkPoint("setElem(int, int)")

    byte[] source = new byte[] {1, 2};
    DataBufferByte b = new DataBufferByte(source, 2);
    b.setElem(1, 99);
    harness.check(b.getElem(1) == 99);
 
    // does the source array get updated? Yes
    harness.check(source[1] == 99);

    // test with offsets
    source = new byte[] {1, 2, 3, 4, 5};
    b = new DataBufferByte(source, 4, 1);
    harness.check(b.getElem(1) == 3);
    b.setElem(1, 99);
    harness.check(b.getElem(1) == 99);
    harness.check(source[2] == 99);
 
    boolean pass = false;
    try
    {
      b.setElem(-2, 99);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(pass);
 
    pass = false;
    try
    {
      b.setElem(4, 99);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
View Full Code Here

  private void testSetElem2(TestHarness harness) {
    harness.checkPoint("setElem(int, int, int)")
 
    byte[][] source = new byte[][] {{1, 2}, {3, 4}};
    DataBufferByte b = new DataBufferByte(source, 2);
    b.setElem(1, 1, 99);
    harness.check(b.getElem(1, 1) == 99);
    // does the source array get updated?
    harness.check(source[1][1] == 99);

    boolean pass = false;
    try
    {
      b.setElem(-1, 1, 99);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    pass = false;
    try
    {
      b.setElem(2, 1, 99);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
View Full Code Here

   */
  public void test(TestHarness harness)     
  {
    // check that array updates pass through
    byte[][] data = new byte[][] {{1, 2}};
    DataBufferByte b = new DataBufferByte(data, 2);
    byte[][] banks = b.getBankData();
    harness.check(Arrays.equals(b.getBankData(), data));
    data[0][0] = 3;
    harness.check(banks[0][0] == 3);
 
    // test where supplied array is bigger than 'size'
    data = new byte[][] {{1, 2, 3}};
    b = new DataBufferByte(data, 2);
    banks = b.getBankData();
    harness.check(Arrays.equals(b.getBankData(), data));
 
    // test where offsets are specified
    data = new byte[][] {{1, 2, 3}, {4, 5, 6, 7}};
    b = new DataBufferByte(data, 2, new int[] {0, 1});
    banks = b.getBankData();
    harness.check(Arrays.equals(b.getBankData(), data));
 
    // check that a single bank buffer returns a valid array
    DataBufferByte b2 = new DataBufferByte(new byte[] {1, 2}, 2);
    banks = b2.getBankData();
    harness.check(banks.length == 1);
    harness.check(banks[0][0] == 1);
    harness.check(banks[0][1] == 2);
 
    // check that a multi bank buffer returns a valid array
    DataBufferByte b3 = new DataBufferByte(new byte[][] {{1}, {2}}, 1);
    banks = b3.getBankData();
    harness.check(banks.length == 2);
    harness.check(banks[0][0] == 1);
    harness.check(banks[1][0] == 2);
  }
View Full Code Here

    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);
  
    // set a value with x < 0
    try
    {
      m1.setPixel(-1, 0, new int[] { 0x10, 0x01 }, db);
View Full Code Here

  }

  private void testConstructor1(TestHarness harness)
  {
    harness.checkPoint("DataBufferByte(int)");
    DataBufferByte b1 = new DataBufferByte(1);
    harness.check(b1.getDataType() == DataBuffer.TYPE_BYTE);
    harness.check(b1.getSize() == 1);
    harness.check(b1.getNumBanks() == 1);
    harness.check(b1.getOffset() == 0);
 
    DataBufferByte b2 = new DataBufferByte(0);
    harness.check(b2.getSize() == 0);
    harness.check(b2.getNumBanks() == 1);
    harness.check(b2.getOffset() == 0);
 
    boolean pass = false;
    try
    {
      DataBufferByte b3 = new DataBufferByte(-1);
    }
    catch (NegativeArraySizeException e)
    {
      pass = true;
    }
View Full Code Here

  private void testConstructor2(TestHarness harness)  
  {
    harness.checkPoint("DataBufferByte(byte[][], int)");
    byte[][] source = new byte[][] {{1, 2}};
    DataBufferByte b = new DataBufferByte(source, 1);
    harness.check(b.getSize() == 1);
    harness.check(b.getNumBanks() == 1);
    harness.check(b.getOffset() == 0);
 
    // does a change to the source array affect the buffer? yes
    byte[][] banks = b.getBankData();
    harness.check(banks[0][0] == 1);
    source[0][0] = 3;
    harness.check(banks[0][0] == 3);
 
    // check null source
    boolean pass = false;
    try
    {
      DataBufferByte b1 = new DataBufferByte((byte[][]) null, 1);
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // check negative size
    DataBufferByte b1 = new DataBufferByte(source, -1);
    harness.check(b1.getSize() == -1);
  }
View Full Code Here

  public void test(TestHarness harness)     
  {
    SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
      DataBuffer.TYPE_BYTE, 2, 2, new int[] { 0xF0, 0x0F }
    );
    DataBufferByte db = new DataBufferByte(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0xAB, (byte) 0xCD }, 4);

    // check regular fetch
    int[] samples = m1.getPixels(0, 0, 1, 2, (int[]) null, db);
    harness.check(samples[0], 0x01)// 1
    harness.check(samples[1], 0x02)// 2
View Full Code Here

TOP

Related Classes of java.awt.image.DataBufferByte

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.