Package java.awt.image

Examples of java.awt.image.DataBufferDouble


  }
 
  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);
View Full Code Here


  private void testConstructor2(TestHarness harness)  
  {
    harness.checkPoint("DataBufferDouble(double[][], int)");
    double[][] source = new double[][] {{1.0, 2.0}};
    DataBufferDouble b = new DataBufferDouble(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
    double[][] banks = b.getBankData();
    harness.check(banks[0][0] == 1.0);
    source[0][0] = 3.0;
    harness.check(banks[0][0] == 3.0);

    // check null source
    boolean pass = false;
    try
    {
      DataBufferDouble b1 = new DataBufferDouble((double[][]) null, 1);
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
    harness.check(pass);
 
    // check negative size
    DataBufferDouble b1 = new DataBufferDouble(source, -1);
    harness.check(b1.getSize() == -1);
  }
View Full Code Here

  private void testConstructor3(TestHarness harness
  {
    harness.checkPoint("DataBufferDouble(double[][], int, int[])");
    double[][] source = new double[][] {{1, 2}};
    DataBufferDouble b = new DataBufferDouble(source, 1, new int[] {0});
    harness.check(b.getSize() == 1);
    harness.check(b.getNumBanks() == 1);
    harness.check(b.getOffset() == 0);

    // test where offsets are specified
    source = new double[][] {{1.0, 2.0, 3.0}, {4.0, 5.0, 6.0, 7.0}};
    b = new DataBufferDouble(source, 2, new int[] {0, 1});
    harness.check(b.getSize() == 2);
    harness.check(b.getNumBanks() == 2);
    harness.check(b.getOffsets()[1] == 1);
    harness.check(b.getElem(1, 0) == 5);

    // check null source
    boolean pass = false;
    try
    {
      DataBufferDouble b1 = new DataBufferDouble((double[][]) null, 1, new int[] {0});
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
    harness.check(pass);

    // check null offsets
    pass = false;
    try
    {
      DataBufferDouble b1 = new DataBufferDouble(new double[][]{{1.0, 2.0}}, 1, (int[]) null);
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
    harness.check(pass);
    // check source doesn't match offsets array
    pass = false;
    try
    {
      DataBufferDouble b2 = new DataBufferDouble(new double[][]{{1.0, 2.0}}, 1, new int[] {0, 0});
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
View Full Code Here

  }

  private void testConstructor4(TestHarness harness)
  {
    harness.checkPoint("DataBufferDouble(double[], int)");
    DataBufferDouble b = new DataBufferDouble(new double[] {1, 2}, 2);
    harness.check(b.getSize() == 2);
    harness.check(b.getNumBanks() == 1);
    harness.check(b.getOffset() == 0);
    boolean pass = false;
    try
    {
      // this constructor doesn't throw an exception until you
      // try to access the (null) data bank
      DataBufferDouble b1 = new DataBufferDouble((double[]) null, 1);
      int ignore = b1.getElem(0);
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
View Full Code Here

  }

  private void testConstructor5(TestHarness harness
  {
    harness.checkPoint("DataBufferDouble(double[], int, int)");
    DataBufferDouble b = new DataBufferDouble(new double[] {1, 2}, 2, 0);
    harness.check(b.getSize() == 2);
    harness.check(b.getNumBanks() == 1);
    harness.check(b.getOffset() == 0);

    boolean pass = false;
    try
    {
      // this constructor doesn't throw an exception until you
      // try to access the (null) data bank
      DataBufferDouble b1 = new DataBufferDouble((double[]) null, 1, 0);
      int ignore = b1.getElem(0);
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // does negative size fail? no
    pass = true;
    try
    {
      DataBufferDouble b1 = new DataBufferDouble(new double[] {1, 2}, -1, 0);
    }
    catch (NegativeArraySizeException e)
    {
      pass = false;
    }
View Full Code Here

  }

  private void testConstructor6(TestHarness harness
  {
    harness.checkPoint("DataBufferDouble(int, int)");
    DataBufferDouble b = new DataBufferDouble(2, 3);
    harness.check(b.getNumBanks() == 3);
    harness.check(b.getSize() == 2);
    harness.check(b.getOffset() == 0) ;
    // does negative size fail? yes
    boolean pass = false;
    try
    {
      DataBufferDouble b1 = new DataBufferDouble(-1, 1);
    }
    catch (NegativeArraySizeException e)
    {
      pass = true;
    }
    harness.check(pass);

    // does negative banks fail? yes
    pass = false;
    try
    {
      DataBufferDouble b1 = new DataBufferDouble(1, -1);
    }
    catch (NegativeArraySizeException e)
    {
      pass = true;
    }
View Full Code Here

  public void test(TestHarness h)
  {
    DataBuffer buf;
    double[] data = new double[] { 1.1, -2.2, 3.3, -4.4 };
   
    buf = new DataBufferDouble(new double[][] { data, data }, 2,
                               new int[] { 2, 0 });

    h.check(buf.getElem(0), 3);     // Check #1.
    h.check(buf.getElem(1), -4);    // Check #2.
    h.check(buf.getElem(0, 0), 3)// Check #3.
View Full Code Here

  {
    harness.checkPoint("getElem(int)")
     
    // test where supplied array is bigger than 'size'
    double[] source = new double[] {1, 2, 3};
    DataBufferDouble b = new DataBufferDouble(source, 2);
    harness.check(b.getElem(0) == 1);
    harness.check(b.getElem(1) == 2);
    harness.check(b.getElem(2) == 3);
   
    boolean pass = false;
    try
    {
      b.getElem(-1);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    pass = false;
    try
    {
      b.getElem(3);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // test where offsets are specified
    source = new double[] {1, 2, 3, 4};
    b = new DataBufferDouble(source, 2, 1);
    harness.check(b.getElem(-1) == 1);
    harness.check(b.getElem(0) == 2);
    harness.check(b.getElem(1) == 3);
    harness.check(b.getElem(2) == 4);

    pass = false;
    try
    {
      b.getElem(3);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(pass);

    pass = false;
    try
    {
      b.getElem(-2);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
View Full Code Here

  private void testGetElem2(TestHarness harness) {
    harness.checkPoint("getElem(int, int)")
   
    double[][] source = new double[][] {{1, 2}, {3, 4}};
    DataBufferDouble b = new DataBufferDouble(source, 2);
    harness.check(b.getElem(1, 0) == 3);
    harness.check(b.getElem(1, 1) == 4);
   
    // test where supplied array is bigger than 'size'
    source = new double[][] {{1, 2, 3}, {4, 5, 6}};
    b = new DataBufferDouble(source, 2);
    harness.check(b.getElem(1, 2) == 6);
     
    // test where offsets are specified
    source = new double[][] {{1, 2, 3, 4}, {5, 6, 7, 8}};
    b = new DataBufferDouble(source, 2, new int[] {1, 2});
    harness.check(b.getElem(1, -2) == 5);
    harness.check(b.getElem(1, -1) == 6);
    harness.check(b.getElem(1, 0) == 7);
    harness.check(b.getElem(1, 1) == 8);
      
    // does a change to the source affect the DataBuffer? Yes
    source[1][2] = 99;
    harness.check(source[1][2] == 99);
    harness.check(b.getElem(1, 0) == 99);
       
    // test when the bank index is out of bounds
    boolean pass = true;
    try
    {
      b.getElem(-1, 0);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(pass);
       
    pass = false;
    try
    {
      b.getElem(2, 0);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // test when the item index is out of bounds
    pass = true;
    try
    {
      b.getElem(0, -2);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(pass);
       
    pass = false;
    try
    {
      b.getElem(1, 5);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // the array of arrays should reflect the single dimension array
    DataBufferDouble b2 = new DataBufferDouble(new double[] {1, 2, 3}, 3);
    harness.check(b2.getElem(0, 1) == 2);
  }
View Full Code Here

  private void testGetData1(TestHarness harness) {
    harness.checkPoint("getData()")

    // check simple case
    double[] source = new double[] {1, 2};
    DataBufferDouble b = new DataBufferDouble(source, 2);
    double[] 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 double[] {1, 2, 3};
    b = new DataBufferDouble(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 double[] {1, 2, 3, 4};
    b = new DataBufferDouble(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

TOP

Related Classes of java.awt.image.DataBufferDouble

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.