Package java.awt.image

Examples of java.awt.image.ComponentSampleModel


public class getSample implements Testlet
{
  public void test(TestHarness harness)
  {
    ComponentSampleModel m = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 5,
            10, 3, 16, new int[] {0, 1, 2});
    DataBuffer db = m.createDataBuffer();
    harness.check(db.getNumBanks(), 1);
    db.setElem(0, 16, 0xAA);
    db.setElem(0, 17, 0xBB);
    db.setElem(0, 18, 0xCC);
    harness.check(m.getSample(0, 1, 0, db), 0xAA);
    harness.check(m.getSample(0, 1, 1, db), 0xBB);
    harness.check(m.getSample(0, 1, 2, db), 0xCC);
   
    // try negative x
    boolean pass = false;
    try
    {
      m.getSample(-1, 1, 0, db);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(pass);

    // try x == width
    pass = false;
    try
    {
      m.getSample(5, 0, 0, db);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(pass);
 
    // try negative y
    pass = false;
    try
    {
      m.getSample(1, -1, 0, db);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(pass);
 
    // try y == height
    pass = false;
    try
    {
      m.getSample(0, 10, 0, db);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
View Full Code Here


    harness.checkPoint("coerceData with BandedSampleModel");
    runTest(harness, new BandedSampleModel(DataBuffer.TYPE_BYTE,
                                           50, 50, 4));

    harness.checkPoint("coerceData with ComponentSampleModel");
    runTest(harness, new ComponentSampleModel(DataBuffer.TYPE_BYTE,
                                              50, 50, 4, 200,
                                              new int[]{0, 1, 2, 3}));

    // MultiPixelPackedSampleModel not allowed, since that sample model can
    // only represent one-banded images.  We should check to ensure failure
View Full Code Here

    harness.checkPoint("coerceData with BandedSampleModel");
    runTest(harness, new BandedSampleModel(DataBuffer.TYPE_INT,
                                           50, 50, 4));

    harness.checkPoint("coerceData with ComponentSampleModel");
    runTest(harness, new ComponentSampleModel(DataBuffer.TYPE_INT,
                                              50, 50, 4, 200,
                                              new int[]{0, 1, 2, 3}));

    // MultiPixelPackedSampleModel not allowed, since that sample model can
    // only represent one-banded images.  We should check to ensure failure
View Full Code Here

  }
 
  public void testMethod1(TestHarness harness)
  {
    harness.checkPoint("(int, int, int[], DataBuffer)");
    SampleModel m = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 5, 10,
           3, 16, new int[] {0, 2, 1});
    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 x < 0
    boolean pass = false;
    try
    {
      m.getPixel(-1, 1, (int[]) null, db);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // try x == width
    pass = false;
    try
    {
      m.getPixel(5, 1, (int[]) null, db);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // try y < 0
    pass = false;
    try
    {
      m.getPixel(1, -1, (int[]) null, db);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // try y == height
    pass = false;
    try
    {
      m.getPixel(1, 10, (int[]) null, db);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // try null data buffer
    pass = false;
    try
    {
      m.getPixel(1, 2, pixel, null);
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
View Full Code Here

  }
 
  public void testMethod2(TestHarness harness)
  {
    harness.checkPoint("(int, int, float[], DataBuffer)");
    SampleModel m = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 5, 10,
           3, 16, new int[] {0, 2, 1});
    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 x < 0
    boolean pass = false;
    try
    {
      m.getPixel(-1, 1, (float[]) null, db);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(pass);
     
    // try x == width
    pass = false;
    try
    {
      m.getPixel(5, 1, (float[]) null, db);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(pass);
     
    // try y < 0
    pass = false;
    try
    {
      m.getPixel(1, -1, (float[]) null, db);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(pass);
     
    // try y == height
    pass = false;
    try
    {
      m.getPixel(1, 10, (float[]) null, db);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(pass);
     
    // try null data buffer
    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, float[], DataBuffer)");
    SampleModel m = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 5, 10,
           3, 16, new int[] {0, 2, 1});
    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 x < 0
    boolean pass = false;
    try
    {
      m.getPixel(-1, 1, (float[]) null, db);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(pass);
       
    // try x == width
    pass = false;
    try
    {
      m.getPixel(5, 1, (float[]) null, db);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(pass);
       
    // try y < 0
    pass = false;
    try
    {
      m.getPixel(1, -1, (float[]) null, db);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(pass);
      
    // try y == height
    pass = false;
    try
    {
      m.getPixel(1, 10, (float[]) null, db);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(pass);
       
    // try null data buffer
    pass = false;
    try
    {
      m.getPixel(1, 2, pixel, 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.setDataElements(1, 1, pixel, db);
    harness.check(db.getElem(0, 8), 11);
    harness.check(db.getElem(0, 9), 22);
       
    // check bad type for data element array
    boolean pass = false;
    try
      {
        m.setDataElements(1, 1, "???", db);
      }
    catch (ClassCastException e)
      {
        pass = true;
      }
    harness.check(pass);
   
    // check that a null pixel array generates a NullPointerException
    pass = false;
    try
      {
        m.setDataElements(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.setDataElements(1, 1, pixel, null);
      }
    catch (NullPointerException e)
      {
        pass = true;
      }
View Full Code Here

public class getNumDataElements implements Testlet
{
  public void test(TestHarness harness)
  {
    ComponentSampleModel m = new ComponentSampleModel(DataBuffer.TYPE_INT,
            3, 2, 2, 6, new int[] {0, 1});
    harness.check(m.getNumDataElements(), 2);
  }
View Full Code Here

{
  public void test(TestHarness harness)
  {
    DataBuffer db = new DataBufferInt(12);
    int[] pixels = new int[] {11, 22, 33, 44};
    ComponentSampleModel m = new ComponentSampleModel(DataBuffer.TYPE_INT,
            3, 2, 2, 6, new int[] {0, 1});
    m.setPixels(0, 0, 2, 1, pixels, db);
    harness.check(db.getElem(0, 0), 11);
    harness.check(db.getElem(0, 1), 22);
    harness.check(db.getElem(0, 2), 33);
    harness.check(db.getElem(0, 3), 44);
       
    // check that a null pixel array generates a NullPointerException
    boolean pass = false;
    try
      {
        m.setPixels(0, 0, 2, 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.setPixels(0, 0, 2, 1, pixels, null);
      }
    catch (NullPointerException e)
      {
        pass = true;
      }
View Full Code Here

  }
 
  private void test1(TestHarness harness)
  {
    harness.checkPoint("()")
    ComponentSampleModel m1 = new ComponentSampleModel(DataBuffer.TYPE_INT, 22,
            11, 2, 44, new int[] {0, 0});
    int[] sizes = m1.getSampleSize();
    harness.check(sizes.length, 2);
    harness.check(sizes[0], 32);
    harness.check(sizes[1], 32);

    ComponentSampleModel m2 = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 22,
            11, 2, 44, new int[] {0, 0, 0});
    int[] sizes2 = m2.getSampleSize();
    harness.check(sizes2.length, 3);
    harness.check(sizes2[0], 8);
    harness.check(sizes2[1], 8);
    harness.check(sizes2[2], 8);
  }
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.