Package java.awt.image

Examples of java.awt.image.ComponentSampleModel


            } else if (dataClass.isAssignableFrom(Byte.class)) {
                dataType = DataBuffer.TYPE_BYTE;
            }
        }
        if (sampleModel == null) {
            sampleModel = new ComponentSampleModel(dataType, width, height, 1, width, new int[]{0});
        }

        WritableRaster raster = RasterFactory.createWritableRaster(sampleModel, null);
        if (value != null) {
            // autobox only once
View Full Code Here


public class equals implements Testlet
{
  public void test(TestHarness harness)
  {
    ComponentSampleModel m1 = new ComponentSampleModel(DataBuffer.TYPE_INT,
            10, 20, 3, 40, new int[] {0, 1, 2});
    ComponentSampleModel m2 = new ComponentSampleModel(DataBuffer.TYPE_INT,
            10, 20, 3, 40, new int[] {0, 1, 2});
    harness.check(m1.equals(m2));
   
    m1 = new ComponentSampleModel(DataBuffer.TYPE_BYTE,
            10, 20, 3, 40, new int[] {0, 1, 2});
    harness.check(!m1.equals(m2));
    m2 = new ComponentSampleModel(DataBuffer.TYPE_BYTE,
            10, 20, 3, 40, new int[] {0, 1, 2});
    harness.check(m1.equals(m2));
   
    m1 = new ComponentSampleModel(DataBuffer.TYPE_BYTE,
            9, 20, 3, 40, new int[] {0, 1, 2});
    harness.check(!m1.equals(m2));
    m2 = new ComponentSampleModel(DataBuffer.TYPE_BYTE,
            9, 20, 3, 40, new int[] {0, 1, 2});
    harness.check(m1.equals(m2));
   
    m1 = new ComponentSampleModel(DataBuffer.TYPE_BYTE,
            9, 19, 3, 40, new int[] {0, 1, 2});
    harness.check(!m1.equals(m2));
    m2 = new ComponentSampleModel(DataBuffer.TYPE_BYTE,
            9, 19, 3, 40, new int[] {0, 1, 2});
    harness.check(m1.equals(m2));
   
    m1 = new ComponentSampleModel(DataBuffer.TYPE_BYTE,
            9, 19, 4, 40, new int[] {0, 1, 2});
    harness.check(!m1.equals(m2));
    m2 = new ComponentSampleModel(DataBuffer.TYPE_BYTE,
            9, 19, 4, 40, new int[] {0, 1, 2});
    harness.check(m1.equals(m2));

    m1 = new ComponentSampleModel(DataBuffer.TYPE_BYTE,
            9, 19, 4, 40, new int[] {0, 2, 1});
    harness.check(!m1.equals(m2));
    m2 = new ComponentSampleModel(DataBuffer.TYPE_BYTE,
            9, 19, 4, 40, new int[] {0, 2, 1});
    harness.check(m1.equals(m2));
  }
View Full Code Here

 
  private void test1(TestHarness harness)
  {
    harness.checkPoint("(int, int, int, double, DataBuffer)")
    DataBuffer db = new DataBufferDouble(12);
    ComponentSampleModel m = new ComponentSampleModel(DataBuffer.TYPE_DOUBLE,
            3, 2, 2, 6, new int[] {0, 1});
    m.setSample(2, 1, 0, 99.9, db);
    harness.check(db.getElem(0, 10), 99.0d);
    m.setSample(2, 1, 1, 88.8, db);
    harness.check(db.getElem(0, 11), 88.0d);
   
    // what happens if the data buffer doesn't hold doubles?
    DataBuffer db2 = new DataBufferInt(12);
    m.setSample(2, 1, 0, 99.9d, db2);
    harness.check(db2.getElem(0, 10), 99);
    m.setSample(2, 1, 1, 88.8d, db2);
    harness.check(db2.getElem(0, 11), 88);

    // check that a null data buffer generates a NullPointerException
    boolean pass = false;
    try
      {
        m.setSample(2, 1, 1, 77.7d, null);
      }
    catch (NullPointerException e)
      {
        pass = true;
      }
View Full Code Here

  private void test2(TestHarness harness)
  {
    harness.checkPoint("(int, int, int, float, DataBuffer)")

    DataBuffer db = new DataBufferFloat(12);
    ComponentSampleModel m = new ComponentSampleModel(DataBuffer.TYPE_FLOAT,
            3, 2, 2, 6, new int[] {0, 1});
    m.setSample(2, 1, 0, 99.9f, db);
    harness.check(db.getElem(0, 10), 99.0f);
    m.setSample(2, 1, 1, 88.8f, db);
    harness.check(db.getElem(0, 11), 88.0f);
   
    // what happens if the data buffer doesn't hold floats?
    DataBuffer db2 = new DataBufferInt(12);
    m.setSample(2, 1, 0, 99.9f, db2);
    harness.check(db2.getElem(0, 10), 99);
    m.setSample(2, 1, 1, 88.8f, db2);
    harness.check(db2.getElem(0, 11), 88);
    
    // check that a null data buffer generates a NullPointerException
    boolean pass = false;
    try
      {
        m.setSample(2, 1, 1, 77.7f, null);
      }
    catch (NullPointerException e)
      {
        pass = true;
      }
View Full Code Here

  private void test3(TestHarness harness)
  {
    harness.checkPoint("(int, int, int, int, DataBuffer)")
   
    DataBuffer db = new DataBufferInt(12);
    ComponentSampleModel m = new ComponentSampleModel(DataBuffer.TYPE_INT,
            3, 2, 2, 6, new int[] {0, 1});
    m.setSample(2, 1, 0, 99, db);
    harness.check(db.getElem(0, 10), 99);
    m.setSample(2, 1, 1, 88, db);
    harness.check(db.getElem(0, 11), 88);
   
    // what happens if the data buffer doesn't hold integers?
    DataBuffer db2 = new DataBufferByte(12);
    m.setSample(2, 1, 0, 99, db2);
    harness.check(db2.getElem(0, 10), 99);
    m.setSample(2, 1, 1, 888, db2);
    harness.check(db2.getElem(0, 11), 120)// (byte) 888
   
    // check that a null data buffer generates a NullPointerException
    boolean pass = false;
    try
      {
        m.setSample(2, 1, 1, 77, null);
      }
    catch (NullPointerException e)
      {
        pass = true;
      }
View Full Code Here

  public void test(TestHarness harness)
  {
    DataBuffer db = new DataBufferInt(12);
    for (int i = 0; i < 12; i++)
      db.setElem(i, i);
    ComponentSampleModel m = new ComponentSampleModel(DataBuffer.TYPE_INT,
            3, 2, 2, 6, new int[] {0, 1});
    Object elements = m.getDataElements(0, 0, 2, 1, null, db);
    int[] de = (int[]) elements;
    harness.check(de.length, 4);
    harness.check(de[0], 0);
    harness.check(de[1], 1);
    harness.check(de[2], 2);
    harness.check(de[3], 3);
   
    // try passing in a result array
    int[] result = new int[4];
    de = (int[]) m.getDataElements(0, 0, 2, 1, result, db);
    harness.check(de[0], 0);
    harness.check(de[1], 1);
    harness.check(de[2], 2);
    harness.check(de[3], 3);
    harness.check(de == result);
   
    // try null data buffer
    boolean pass = false;
    try
      {
        m.getDataElements(0, 0, 2, 1, result, null);
      }
    catch (NullPointerException e)
      {
        pass = true
      }
View Full Code Here

{
  public void test(TestHarness harness)
  {
    DataBuffer db = new DataBufferInt(12);
    int[] pixel = new int[] {11, 22};
    ComponentSampleModel m = new ComponentSampleModel(DataBuffer.TYPE_INT,
            3, 2, 2, 6, new int[] {0, 1});
    m.setPixel(1, 1, pixel, db);
    harness.check(db.getElem(0, 8), 11);
    harness.check(db.getElem(0, 9), 22);
       
    // check that a null pixel array generates a NullPointerException
    boolean pass = false;
    try
      {
        m.setPixel(1, 1, (int[]) null, db);
      }
    catch (NullPointerException e)
      {
        pass = true;
      }
    harness.check(pass);   

    // check that a null data buffer generates a NullPointerException
    pass = false;
    try
      {
        m.setPixel(1, 1, pixel, null);
      }
    catch (NullPointerException e)
      {
        pass = true;
      }
View Full Code Here

 
  public void testConstructor1(TestHarness harness)
  {
    harness.checkPoint("testConstructor1()");
   
    ComponentSampleModel m = new ComponentSampleModel(DataBuffer.TYPE_BYTE,
            10, 20, 3, 30, new int[] {0, 1, 2});
    harness.check(m.getDataType(), DataBuffer.TYPE_BYTE);
    harness.check(m.getWidth(), 10);
    harness.check(m.getHeight(), 20);
    harness.check(m.getPixelStride(), 3);
    harness.check(m.getScanlineStride(), 30);
    harness.check(Arrays.equals(m.getBandOffsets(), new int[] {0, 1, 2}));
   
    // try bad type
    boolean pass = false;
    try
    {
      m = new ComponentSampleModel(DataBuffer.TYPE_UNDEFINED, 10, 20, 3, 30,
              new int[] {0, 1, 2});
    }
    catch (IllegalArgumentException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // try zero width
    pass = false;
    try
    {
      m = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 0, 20, 3, 30,
              new int[] {0, 1, 2});
    }
    catch (IllegalArgumentException e)
    {
      pass = true;
    }
    harness.check(pass);

    // try zero height
    pass = false;
    try
    {
      m = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 10, 0, 3, 30,
              new int[] {0, 1, 2});
    }
    catch (IllegalArgumentException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // try negative pixel stride
    pass = false;
    try
    {
      m = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 10, 20, -1, 30,
              new int[] {0, 1, 2});
    }
    catch (IllegalArgumentException e)
    {
      pass = true;
    }
    harness.check(pass);

    // try negative scanline stride
    pass = false;
    try
    {
      m = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 10, 20, 3, -1,
              new int[] {0, 1, 2});
    }
    catch (IllegalArgumentException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // try width * height > Integer.MAX_VALUE
    pass = false;
    try
    {
      m = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 3,
              Integer.MAX_VALUE / 2, 3, 30, new int[] {0, 1, 2});
    }
    catch (IllegalArgumentException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // try null band offsets
    pass = false;
    try
    {
      m = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 10, 20, 3, 30, null);
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
View Full Code Here

    harness.checkPoint("(int, int, int, int, int, int[], int[])");

    int[] bankIndices = new int[] {0, 1};
    int[] bandOffsets = new int[] {0, 0};
   
    ComponentSampleModel m = new ComponentSampleModel(DataBuffer.TYPE_INT, 22,
            11, 1, 25, bankIndices, new int[] {0, 0});
    harness.check(m.getDataType(), DataBuffer.TYPE_INT);
    harness.check(m.getWidth(), 22);
    harness.check(m.getHeight(), 11);
    harness.check(m.getPixelStride(), 1);
    harness.check(m.getNumBands(), 2);
    harness.check(m.getNumDataElements(), 2);
    harness.check(Arrays.equals(m.getBankIndices(), new int[] {0, 1}));
    harness.check(m.getBankIndices() != bankIndices)// not the same instance
    harness.check(Arrays.equals(m.getBandOffsets(), bandOffsets));
    harness.check(m.getBandOffsets() != bandOffsets)// not the same instance
    // check unknown data type
    boolean pass = false;
    try
      {
        m = new ComponentSampleModel(DataBuffer.TYPE_UNDEFINED, 22,
                11, 1, 25, new int[] {0, 1}, new int[] {0, 0});
      }
    catch (IllegalArgumentException e)
      {
        pass = true
      }
    harness.check(pass);
   
    // check w = 0
    pass = false;
    try
      {
        m = new ComponentSampleModel(DataBuffer.TYPE_INT, 0,
            11, 1, 25, new int[] {0, 1}, new int[] {0, 0});
      }
    catch (IllegalArgumentException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // check h = 0
    pass = false;
    try
      {
        m = new ComponentSampleModel(DataBuffer.TYPE_INT, 22,
            0, 1, 25, new int[] {0, 1}, new int[] {0, 0});
      }
    catch (IllegalArgumentException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // check w * h exceeds Integer.MAX_VALUE
    pass = false;
    try
      {
        m = new ComponentSampleModel(DataBuffer.TYPE_INT, Integer.MAX_VALUE - 1,
            2, 1, 25, new int[] {0, 1}, new int[] {0, 0});
      }
    catch (IllegalArgumentException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // try pixelStride < 0
    pass = false;
    try
      {
        m = new ComponentSampleModel(DataBuffer.TYPE_INT, 22,
              11, -1, 25, new int[] {0, 1}, new int[] {0, 0});
      }
    catch (IllegalArgumentException e)
      {
        pass = true
      }
    harness.check(pass);
   
    // try scanlineStride = 0
    pass = false;
    try
      {
        m = new ComponentSampleModel(DataBuffer.TYPE_INT, 22,
                11, 1, -1, new int[] {0, 1}, new int[] {0, 0});
      }
    catch (IllegalArgumentException e)
      {
        pass = true
      }
    harness.check(pass);

    // try null bankIndices
    pass = false;
    try
      {
        m = new ComponentSampleModel(DataBuffer.TYPE_INT, 22, 11, 1, 25, null,
                new int[] {0, 0});
      }
    catch (NullPointerException e)
      {
        pass = true;
      }
    harness.check(pass);
     
    // try empty bankIndices
    pass = false;
    try
      {
        m = new ComponentSampleModel(DataBuffer.TYPE_INT, 22, 11, 1, 25,
                new int[0], new int[] {0, 0});
      }
    catch (ArrayIndexOutOfBoundsException e)
      {
        pass = true;
      }
    catch (IllegalArgumentException e)
      {
        pass = true;
      }
    harness.check(pass);
   
    // try null bandOffsets
    pass = false;
    try
      {
        m = new ComponentSampleModel(DataBuffer.TYPE_INT, 22, 11, 1, 25,
                new int[] {0, 0}, null);
      }
    catch (NullPointerException e)
      {
        pass = true;
      }
    harness.check(pass);
   
    // try arrays of different lengths
    pass = false;
    try
      {
        m = new ComponentSampleModel(DataBuffer.TYPE_INT, 22, 11, 1, 25,
                new int[1], new int[2]);
      }
    catch (IllegalArgumentException e)
      {
        pass = true;
View Full Code Here

public class getPixelStride implements Testlet
{
  public void test(TestHarness harness)
  {
    ComponentSampleModel m1 = new ComponentSampleModel(DataBuffer.TYPE_INT, 22,
        11, 2, 44, new int[] {0, 0});
    harness.check(m1.getPixelStride(), 2);
  }
View Full Code Here

TOP

Related Classes of java.awt.image.ComponentSampleModel

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.