Package java.awt.image

Examples of java.awt.image.SinglePixelPackedSampleModel


    harness.check(sizes[3], 1);
  }
 
  public void test2(TestHarness harness)
  {
    SinglePixelPackedSampleModel m = new SinglePixelPackedSampleModel(
        DataBuffer.TYPE_INT, 10, 20, new int[] {0xFF, 0xFF00, 0xFF0000,
                0xFF000000});
    int[] sizes = m.getSampleSize();
    harness.check(sizes.length, 4);
    harness.check(sizes[0], 8);
    harness.check(sizes[1], 8);
    harness.check(sizes[2], 8);
    harness.check(sizes[3], 8);
   
    // if we alter the returned array, does that affect the model's state
    sizes[0] = 99;
    int[] sizes2 = m.getSampleSize();
    harness.check(sizes2 != sizes);
    harness.check(sizes2[0], 8);
  }
View Full Code Here


public class getSampleDouble implements Testlet
{
  public void test(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();
    harness.check(m.getSampleDouble(1, 2, 0, db), 0);
    harness.check(m.getSampleDouble(1, 2, 1, db), 0);
    harness.check(m.getSampleDouble(1, 2, 2, db), 0);
    m.setPixel(1, 2, new int[] {1, 2, 3}, db);
    harness.check(m.getSampleDouble(1, 2, 0, db), 1);
    harness.check(m.getSampleDouble(1, 2, 1, db), 2);
    harness.check(m.getSampleDouble(1, 2, 2, db), 3);
   
    // try band out of range
    boolean pass = false;
    try
    {
      m.getSampleDouble(1, 2, -1, db);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(true);
   
    pass = false;
    try
    {
      m.getSampleDouble(1, 2, 3, db);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(true);
   
    // try null data buffer
    pass = false;
    try
    {
      m.getSampleDouble(1, 2, 0, null);
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
View Full Code Here

   *
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)     
  {
    SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
      DataBuffer.TYPE_BYTE, 2, 2, new int[] { 224, 28, 3 }
    );
    harness.check(m1.getOffset(0, 0), 0);
    harness.check(m1.getOffset(1, 0), 1);
    harness.check(m1.getOffset(0, 1), 2);
    harness.check(m1.getOffset(1, 1), 3);
  }
View Full Code Here

   *
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)     
  {
    SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
      DataBuffer.TYPE_BYTE, 1, 2, new int[] { 224, 28, 3 }
    );
    SinglePixelPackedSampleModel m2 = (SinglePixelPackedSampleModel) m1.createCompatibleSampleModel(5, 10);
    harness.check(m2.getDataType(), DataBuffer.TYPE_BYTE);          // check 1
    harness.check(m2.getWidth(), 5);                                // check 2
    harness.check(m2.getHeight(), 10);                              // check 3
    harness.check(m2.getNumBands(), 3);                             // check 4
    harness.check(Arrays.equals(m1.getBitMasks(), m2.getBitMasks())); // check 5
    // if 'w' is <= 0 there should be an IllegalArgumentException
    try
    {
      /* SampleModel m3 = */ m1.createCompatibleSampleModel(0, 10);
View Full Code Here

public class createDataBuffer implements Testlet
{
   
  public void test(TestHarness harness)
  {
    SampleModel m = new SinglePixelPackedSampleModel(DataBuffer.TYPE_BYTE, 10,
            20, new int[] { 224, 28, 3 });
    DataBuffer db = m.createDataBuffer();
    harness.check(db.getDataType(), DataBuffer.TYPE_BYTE);
    harness.check(db.getNumBanks(), 1);
    harness.check(db.getSize(), 200);
    harness.check(db.getOffsets()[0], 0);
  }
View Full Code Here

  }


  private void testInt(TestHarness harness)
  {
    SinglePixelPackedSampleModel sm;
    DataBuffer dbuf;
    int[] bitMasks;

    harness.checkPoint("TYPE_INT");

    bitMasks = new int[] { 0xff00, 0xff };
    sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT,
                                          51, 83, bitMasks);
    dbuf = sm.createDataBuffer();

    // Check #1
    harness.check(dbuf instanceof DataBufferInt);

    // Check #2
    harness.check(dbuf.getDataType(), DataBuffer.TYPE_INT);

    // Check #3
    harness.check(dbuf.getNumBanks(), 1);

    // Check #4
    harness.check(dbuf.getOffset(), 0);

    // Check #5
    harness.check(dbuf.getSize(), /* width * height */ 51 * 83);

    // Check #6
    sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT,
                                          51, 83, /* stride */ 91,
                                          bitMasks);
    dbuf = sm.createDataBuffer();
    harness.check(dbuf.getSize(),
                  /* (stride * (height - 1)) + width */ 91 * 82 + 51);
  }
View Full Code Here

  }


  private void testUShort(TestHarness harness)
  {
    SinglePixelPackedSampleModel sm;
    DataBuffer dbuf;
    int[] bitMasks;

    harness.checkPoint("TYPE_USHORT");

    bitMasks = new int[] { 0x0f00, 0xf000 };
    sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_USHORT,
                                          42, 10, bitMasks);
    dbuf = sm.createDataBuffer();

    // Check #1
    harness.check(dbuf instanceof DataBufferUShort);

    // Check #2
    harness.check(dbuf.getDataType(), DataBuffer.TYPE_USHORT);

    // Check #3
    harness.check(dbuf.getNumBanks(), 1);

    // Check #4
    harness.check(dbuf.getOffset(), 0);

    // Check #5
    harness.check(dbuf.getSize(), /* width * height */ 42 * 10);

    // Check #6
    sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_USHORT,
                                          42, 10, /* stride */ 31,
                                          bitMasks);
    dbuf = sm.createDataBuffer();
    harness.check(dbuf.getSize(),
                  /* (stride * (height - 1)) + width */ 31 * 9 + 42);
  }
View Full Code Here

  }


  private void testByte(TestHarness harness)
  {
    SinglePixelPackedSampleModel sm;
    DataBuffer dbuf;
    int[] bitMasks;

    harness.checkPoint("TYPE_BYTE");

    bitMasks = new int[] { 0xf0, 0x08, 0x6, 0x1 };
    sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_BYTE,
                                          5, 3, bitMasks);
    dbuf = sm.createDataBuffer();

    // Check #1
    harness.check(dbuf instanceof DataBufferByte);

    // Check #2
    harness.check(dbuf.getDataType(), DataBuffer.TYPE_BYTE);

    // Check #3
    harness.check(dbuf.getNumBanks(), 1);

    // Check #4
    harness.check(dbuf.getOffset(), 0);

    // Check #5
    harness.check(dbuf.getSize(), /* width * height */ 5 * 3);

    // Check #6
    sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_USHORT,
                                          5, 3, /* stride */ 7,
                                          bitMasks);
    dbuf = sm.createDataBuffer();
    harness.check(dbuf.getSize(),
                  /* (stride * (height - 1)) + width */ 7 * 2 + 5);
  }
View Full Code Here

   *
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)     
  {
    SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
      DataBuffer.TYPE_BYTE, 2, 2, new int[] { 224, 28, 3 }
    );
    harness.check(m1.getScanlineStride(), 2);
    SinglePixelPackedSampleModel m2 = new SinglePixelPackedSampleModel(
      DataBuffer.TYPE_INT, 20, 30, 22, new int[] { 0xF0, 0x0F }
    );
    harness.check(m2.getScanlineStride(), 22);
  }
View Full Code Here

   *
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  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
    harness.check(samples[2], 0x0A)// 3
    harness.check(samples[3], 0x0B)// 4

    // check regular fetch with negative x
    try
    {
      samples = m1.getPixels(-1, 0, 1, 1, (int[]) null, db);
      harness.check(false);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      harness.check(true);
    }
    // check regular fetch with negative y
    try
    {
      samples = m1.getPixels(0, -1, 1, 1, (int[]) null, db);
      harness.check(false);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      harness.check(true);
    }
    // check regular fetch with w < 0
    try
    {
      samples = m1.getPixels(0, 0, -1, 1, (int[]) null, db);
      harness.check(false);
    }
    catch (NegativeArraySizeException e)
    {
      harness.check(true);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      harness.check(true);
    }
    // check regular fetch with h < 0
    try
    {
      samples = m1.getPixels(0, 0, 1, -1, (int[]) null, db);
      harness.check(false);
    }
    catch (NegativeArraySizeException e)
    {
      harness.check(true);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      harness.check(true);
    }
    // check regular fetch with presupplied array
    int[] samplesIn = new int[4];
    int[] samplesOut = m1.getPixels(1, 0, 1, 2, samplesIn, db);
    harness.check(samplesIn == samplesOut);
    harness.check(samplesOut[0], 0x03);
    harness.check(samplesOut[1], 0x04);
    harness.check(samplesOut[2], 0x0C);
    harness.check(samplesOut[3], 0x0D);

    // check regular fetch with presupplied array too short
    int[] samplesIn2 = new int[1];
    try
    {
      /* int[] samplesOut2 = */ m1.getPixels(1, 1, 1, 2, samplesIn2, db);
      harness.check(false);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      harness.check(true);
    }

    // check null data buffer
    try
    {
      samples = m1.getPixels(0, 0, 1, 1, (int[]) null, null);
      harness.check(false);
    }
    catch (NullPointerException e)
    {
      harness.check(true);
    }
   
    // check other array types
    try
    {
      float[] samples1 = m1.getPixels(0, 0, 1, 1, (float[]) null, db);
      harness.check(true);
    }
    catch (NullPointerException e)
    {
      harness.check(false);
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.