Examples of SinglePixelPackedSampleModel


Examples of java.awt.image.SinglePixelPackedSampleModel

                 (KEY_FORCE_TRANSPARENT_WHITE)).booleanValue();
        }

        int w = img.getWidth();
        int h = img.getHeight();
        SinglePixelPackedSampleModel sppsm;
        sppsm = (SinglePixelPackedSampleModel)img.getSampleModel();

        if (forceTransparentWhite) {
            //
            // This is a trick so that viewers which do not support
            // the alpha channel will see a white background (and not
            // a black one).
            //
            DataBufferInt biDB=(DataBufferInt)img.getRaster().getDataBuffer();
            int scanStride = sppsm.getScanlineStride();
            int dbOffset = biDB.getOffset();
            int pixels[] = biDB.getBankData()[0];
            int p = dbOffset;
            int adjust = scanStride - w;
            int a=0, r=0, g=0, b=0, pel=0;
            for(int i=0; i<h; i++){
                for(int j=0; j<w; j++){
                    pel = pixels[p];
                    a = (pel >> 24) & 0xff;
                    r = (pel >> 16) & 0xff;
                    g = (pel >> 8 ) & 0xff;
                    b =  pel        & 0xff;
                    r = (255*(255 -a) + a*r)/255;
                    g = (255*(255 -a) + a*g)/255;
                    b = (255*(255 -a) + a*b)/255;
                    pixels[p++] =
                        (a<<24 & 0xff000000) |
                        (r<<16 & 0xff0000) |
                        (g<<& 0xff00) |
                        (b     & 0xff);
                }
                p += adjust;
            }
        }

        try {
            TIFFImageEncoder tiffEncoder =
                new TIFFImageEncoder(ostream, params);
            int bands = sppsm.getNumBands();
            int [] off = new int[bands];
            for (int i=0; i<bands; i++)
                off[i] = i;
            SampleModel sm = new PixelInterleavedSampleModel
                (DataBuffer.TYPE_BYTE, w, h, bands, w*bands, off);
View Full Code Here

Examples of java.awt.image.SinglePixelPackedSampleModel

  }
 
  public void testMethod2(TestHarness harness)
  {
    harness.checkPoint("(int, int, int, int, float[], DataBuffer)");    
    SampleModel m = new SinglePixelPackedSampleModel(DataBuffer.TYPE_BYTE, 10,
            20, new int[] { 224, 28, 3 });
    DataBuffer db = m.createDataBuffer();
    float[] pixel = new float[18];
    m.getPixels(1, 2, 2, 3, pixel, db);
    harness.check(Arrays.equals(pixel, new float[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0}));
    m.setPixels(1, 2, 2, 3, new float[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
            13, 14, 15, 16, 17, 18}, db);
    m.getPixels(1, 2, 2, 3, pixel, db);
    harness.check(Arrays.equals(pixel, new float[] {1, 2, 3, 4, 5, 2, 7, 0, 1,
            2, 3, 0, 5, 6, 3, 0, 1, 2}));
   
    // try null pixel data
    boolean pass = false;
    try
    {
      m.setPixels(1, 2, 2, 3, (float[]) null, db);
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
    harness.check(pass);

    // try null data buffer
    pass = false;
    try
    {
      m.setPixels(1, 2, 2, 3, pixel, null);
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
View Full Code Here

Examples of java.awt.image.SinglePixelPackedSampleModel

  }

  private void testInt(TestHarness harness)
  {
    harness.checkPoint("(int, int, Object, DataBuffer(Int))");
    SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
      DataBuffer.TYPE_INT, 2, 3, new int[] { 0xFFFF0000, 0x0000FFFF }
    );
    int[] i = new int[] { 0x1111, 0x2222, 0x3333, 0x4444, 0x5555, 0x6666 };
    DataBuffer db = new DataBufferInt(i, 6)

    // set a value
    m1.setPixel(0, 0, new int[] { 0x00CC, 0x0077 }, db);
    m1.setPixel(1, 0, new int[] { 0x00BB, 0x0088 }, db);
    m1.setPixel(0, 1, new int[] { 0x00AA, 0x0099 }, db);
    m1.setPixel(1, 1, new int[] { 0x0099, 0x00AA }, db);
    m1.setPixel(0, 2, new int[] { 0x0088, 0x00BB }, db);
    m1.setPixel(1, 2, new int[] { 0x0077, 0x00CC }, db);
    harness.check(db.getElem(0), 0x00CC0077);
    harness.check(db.getElem(1), 0x00BB0088);
    harness.check(db.getElem(2), 0x00AA0099);
    harness.check(db.getElem(3), 0x009900AA);
    harness.check(db.getElem(4), 0x008800BB);
    harness.check(db.getElem(5), 0x007700CC);
    
    // set a value with non-standard scanline stride
    SinglePixelPackedSampleModel m2 = new SinglePixelPackedSampleModel(
      DataBuffer.TYPE_INT, 2, 2, 3, new int[] { 0xFFFF0000, 0x0000FFFF }
    );
    m2.setPixel(0, 0, new int[] { 0x0044, 0x0011 }, db);
    m2.setPixel(1, 0, new int[] { 0x0033, 0x0022 }, db);
    m2.setPixel(0, 1, new int[] { 0x0022, 0x0033 }, db);
    m2.setPixel(1, 1, new int[] { 0x0011, 0x0044 }, db);
    harness.check(db.getElem(0), 0x00440011);
    harness.check(db.getElem(1), 0x00330022);
    harness.check(db.getElem(3), 0x00220033);
    harness.check(db.getElem(4), 0x00110044);
      
View Full Code Here

Examples of java.awt.image.SinglePixelPackedSampleModel

  }

  public void testMethod3(TestHarness harness)
  {
    harness.checkPoint("(int, int, int, int, double[], DataBuffer)");    
    SampleModel m = new SinglePixelPackedSampleModel(DataBuffer.TYPE_BYTE, 10,
            20, new int[] { 224, 28, 3 });
    DataBuffer db = m.createDataBuffer();
    double[] pixel = new double[18];
    m.getPixels(1, 2, 2, 3, pixel, db);
    harness.check(Arrays.equals(pixel, new double[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0}));
    m.setPixels(1, 2, 2, 3, new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
            13, 14, 15, 16, 17, 18}, db);
    m.getPixels(1, 2, 2, 3, pixel, db);
    harness.check(Arrays.equals(pixel, new double[] {1, 2, 3, 4, 5, 2, 7, 0, 1,
            2, 3, 0, 5, 6, 3, 0, 1, 2}));
   
    // try null pixel data
    boolean pass = false;
    try
    {
      m.setPixels(1, 2, 2, 3, (double[]) null, db);
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
    harness.check(pass);

    // try null data buffer
    pass = false;
    try
    {
      m.setPixels(1, 2, 2, 3, pixel, null);
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
View Full Code Here

Examples of java.awt.image.SinglePixelPackedSampleModel

  }

  private void testConstructor1(TestHarness harness)
  {
    harness.checkPoint("(int, int, int, int[])");
    SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
      DataBuffer.TYPE_BYTE, 1, 2, new int[] { 224, 28, 3 }
    );
    harness.check(m1.getDataType(), DataBuffer.TYPE_BYTE);       // check 1
    harness.check(m1.getWidth(), 1);                             // check 2
    harness.check(m1.getHeight(), 2);                            // check 3
    harness.check(m1.getNumBands(), 3);                          // check 4
   
    // unsupported data type should throw an IllegalArgumentException
    try                                                          // check 5
    {
      /* SampleModel m2 = */ new SinglePixelPackedSampleModel(
        DataBuffer.TYPE_DOUBLE, 1, 2, new int[] { 224, 28, 3 }
      );
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
   
    // if 'w' is <= 0 there should be an IllegalArgumentException
    try                                                          // check 6
    {
      /* SampleModel m2 = */ new SinglePixelPackedSampleModel(
        DataBuffer.TYPE_BYTE, 0, 2, new int[] { 224, 28, 3 }
      );
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
   
    // if 'h' is <= 0 there should be an IllegalArgumentException
    try                                                          // check 7
    {
      /* SampleModel m2 = */ new SinglePixelPackedSampleModel(
        DataBuffer.TYPE_BYTE, 1, 0, new int[] { 224, 28, 3 }
      );
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
   
    // if mask array is empty there should be an IllegalArgumentException
    try                                                          // check 8
    {
      /* SampleModel m2 = */ new SinglePixelPackedSampleModel(
        DataBuffer.TYPE_BYTE, 1, 2, new int[] { }
      );
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }

    // if mask array contains a non-contiguous mask there should be an IllegalArgumentException
    try
    {
      /* SampleModel m2 = */ new SinglePixelPackedSampleModel(
        DataBuffer.TYPE_BYTE, 1, 2, new int[] { 224, 27, 3 }
      );
      harness.check(false);
    }
    catch (IllegalArgumentException e)
View Full Code Here

Examples of java.awt.image.SinglePixelPackedSampleModel

  }

  private void testConstructor2(TestHarness harness)  
  {
    harness.checkPoint("(int, int, int, int, int[])");
    SinglePixelPackedSampleModel m1 = new SinglePixelPackedSampleModel(
      DataBuffer.TYPE_BYTE, 1, 2, 3, new int[] { 224, 28, 3 }
    );
    harness.check(m1.getDataType(), DataBuffer.TYPE_BYTE);       // check 1
    harness.check(m1.getWidth(), 1);                             // check 2
    harness.check(m1.getHeight(), 2);                            // check 3
    harness.check(m1.getNumBands(), 3);                          // check 4
   
    // unsupported data type should throw an IllegalArgumentException
    try
    {
      /* SampleModel m2 = */ new SinglePixelPackedSampleModel(
        DataBuffer.TYPE_DOUBLE, 1, 2, 3, new int[] { 224, 28, 3 }
      );
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
   
    // if 'w' is <= 0 there should be an IllegalArgumentException
    try
    {
      /* SampleModel m2 = */ new SinglePixelPackedSampleModel(
        DataBuffer.TYPE_BYTE, 0, 2, 3, new int[] { 224, 28, 3 }
      );
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
   
    // if 'h' is <= 0 there should be an IllegalArgumentException
    try
    {
      /* SampleModel m2 = */ new SinglePixelPackedSampleModel(
        DataBuffer.TYPE_BYTE, 1, 0, 3, new int[] { 224, 28, 3 }
      );
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
   
    // if mask array is empty there should be an IllegalArgumentException
    try
    {
      /* SampleModel m2 = */ new SinglePixelPackedSampleModel(
        DataBuffer.TYPE_BYTE, 1, 2, 3, new int[] { }
      );
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }

    // if mask array contains a non-contiguous mask there should be an IllegalArgumentException
    try
    {
      /* SampleModel m2 = */ new SinglePixelPackedSampleModel(
        DataBuffer.TYPE_BYTE, 1, 2, new int[] { 224, 27, 3 }
      );
      harness.check(false);
    }
    catch (IllegalArgumentException e)
View Full Code Here

Examples of java.awt.image.SinglePixelPackedSampleModel

   *
   * @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 sample = m1.getSample(1, 1, 1, db);
    harness.check(sample, 0x0D);
    // check regular fetch with negative x
    try
    {
      sample = m1.getSample(-2, 0, 0, db);
      harness.check(false);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      harness.check(true);
    }
    // check regular fetch with negative y
    try
    {
      sample = m1.getSample(0, -1, 0, db);
      harness.check(false);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      harness.check(true);
    }
 
    // check null data buffer
    try
    {
      sample = m1.getSample(0, 0, 0, null);
      harness.check(false);
    }
    catch (NullPointerException e)
    {
      harness.check(true);
View Full Code Here

Examples of java.awt.image.SinglePixelPackedSampleModel

  }
 
  public void test1(TestHarness harness)
  {
    harness.checkPoint("()");
    SampleModel m = new SinglePixelPackedSampleModel(DataBuffer.TYPE_BYTE, 10,
            20, new int[] { 224, 28, 3 });
    int[] s = m.getSampleSize();
    harness.check(s.length, 3);
    harness.check(s[0], 3);   
    harness.check(s[1], 3);
    harness.check(s[2], 2);
  }
View Full Code Here

Examples of java.awt.image.SinglePixelPackedSampleModel

  }
 
  public void test2(TestHarness harness)
  {
    harness.checkPoint("(int)");
    SampleModel m = new SinglePixelPackedSampleModel(DataBuffer.TYPE_BYTE, 10,
            20, new int[] { 224, 28, 3 });
    harness.check(m.getSampleSize(0), 3);
    harness.check(m.getSampleSize(1), 3);
    harness.check(m.getSampleSize(2), 2);
   
    boolean pass = false;
    try
    {
      m.getSampleSize(-1);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    pass = false;
    try
    {
      m.getSampleSize(3);
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      pass = true;
    }
View Full Code Here

Examples of java.awt.image.SinglePixelPackedSampleModel

   *
   * @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 }
    );
    harness.check(Arrays.equals(m1.getBitOffsets(), new int[] { 5, 2, 0 }));
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.