Package java.awt.image

Examples of java.awt.image.IndexColorModel


 

  public void test2(TestHarness harness)
  {
    harness.checkPoint("isValid(int)");
    IndexColorModel m1 = new IndexColorModel(2, 4, R4, G4, B4);
    harness.check(m1.isValid(0));
    try {
      harness.check(!m1.isValid(-1));
    }
    catch (Exception e)
    {
      harness.debug(e);  
    }
    harness.check(!m1.isValid(4));

    IndexColorModel m2 = new IndexColorModel(2, 4, CMAP_INT, 0,
            DataBuffer.TYPE_BYTE, new BigInteger("11"));
    harness.check(m2.isValid(0));
    harness.check(m2.isValid(1));
    harness.check(!m2.isValid(2));
    harness.check(m2.isValid(3));
 
View Full Code Here


   *
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness
  {
    IndexColorModel m1 = new IndexColorModel(2, 4, R4, G4, B4);
    int[] cs1 = m1.getComponentSize();
    harness.check(cs1.length, 3);
    harness.check(cs1[0], 8);
    harness.check(cs1[1], 8);
    harness.check(cs1[2], 8);

    IndexColorModel m2 = new IndexColorModel(2, 4, R4, G4, B4, 2);
    int[] cs2 = m2.getComponentSize();
    harness.check(cs2.length, 4);
    harness.check(cs2[0], 8);
    harness.check(cs2[1], 8);
    harness.check(cs2[2], 8);
    harness.check(cs2[3], 8);
    IndexColorModel m3a = new IndexColorModel(2, 4, CMAP, 0, false);
    int[] cs3a = m3a.getComponentSize();
    harness.check(cs3a.length, 3);
    harness.check(cs3a[0], 8);
    harness.check(cs3a[1], 8);
    harness.check(cs3a[2], 8);

    IndexColorModel m3b = new IndexColorModel(2, 4, CMAP, 0, false, 1);
    int[] cs3b = m3b.getComponentSize();
    harness.check(cs3b.length, 4);
    harness.check(cs3b[0], 8);
    harness.check(cs3b[1], 8);
    harness.check(cs3b[2], 8);
    harness.check(cs3b[3], 8);

    IndexColorModel m4 = new IndexColorModel(2, 4, CMAP_WITH_ALPHA, 0, true);
    int[] cs4 = m4.getComponentSize();
    harness.check(cs4.length, 4);
    harness.check(cs4[0], 8);
    harness.check(cs4[1], 8);
    harness.check(cs4[2], 8);
    harness.check(cs4[3], 8);

    IndexColorModel m5 = new IndexColorModel(2, 4, CMAP_WITH_ALPHA0, 0, true);
    int[] cs5 = m5.getComponentSize();
    harness.check(cs5.length, 4);
    harness.check(cs5[0], 8);
    harness.check(cs5[1], 8);
    harness.check(cs5[2], 8);
    harness.check(cs5[3], 8);

    IndexColorModel m6 = new IndexColorModel(2, 4, CMAP_WITH_ALPHA1, 0, true);
    int[] cs6 = m6.getComponentSize();
    harness.check(cs6.length, 3);
    harness.check(cs6[0], 8);
    harness.check(cs6[1], 8);
    harness.check(cs6[2], 8);
 
View Full Code Here

   *
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)
  {
    IndexColorModel m1 = new IndexColorModel(2, 4, R4, G4, B4);
    harness.check(m1.getTransparentPixel(), -1);

    IndexColorModel m2a = new IndexColorModel(2, 4, R4, G4, B4, 2);
    harness.check(m2a.getTransparentPixel(), 2);
    IndexColorModel m2b = new IndexColorModel(2, 4, R4, G4, B4, -2);
    harness.check(m2b.getTransparentPixel(), -1);

    IndexColorModel m2c = new IndexColorModel(2, 4, R4, G4, B4, 99);
    harness.check(m2c.getTransparentPixel(), -1);

    IndexColorModel m3a = new IndexColorModel(2, 4, CMAP, 0, false, 2);
    harness.check(m3a.getTransparentPixel(), 2);
    IndexColorModel m3b = new IndexColorModel(2, 4, CMAP, 0, false, -2);
    harness.check(m3b.getTransparentPixel(), -1);
    IndexColorModel m3c = new IndexColorModel(2, 4, CMAP, 0, false, 99);
    harness.check(m3c.getTransparentPixel(), -1);

    IndexColorModel m4a = new IndexColorModel(2, 4, CMAP_WITH_ALPHA, 0, true, 2);
    harness.check(m4a.getTransparentPixel(), 2);
    IndexColorModel m4b = new IndexColorModel(2, 4, CMAP_WITH_ALPHA, 0, true, -2);
    harness.check(m4b.getTransparentPixel(), -1);
    IndexColorModel m4c = new IndexColorModel(2, 4, CMAP_WITH_ALPHA, 0, true, 99);
    harness.check(m4c.getTransparentPixel(), -1);

    IndexColorModel m5a = new IndexColorModel(2, 4, CMAP_INT, 0, false, 2, DataBuffer.TYPE_BYTE);
    harness.check(m5a.getTransparentPixel(), 2);
    IndexColorModel m5b = new IndexColorModel(2, 4, CMAP_INT, 0, false, -2, DataBuffer.TYPE_BYTE);
    harness.check(m5b.getTransparentPixel(), -1);
    IndexColorModel m5c = new IndexColorModel(2, 4, CMAP_INT, 0, false, 99, DataBuffer.TYPE_BYTE);
    harness.check(m5c.getTransparentPixel(), -1);
 
View Full Code Here

 
  public void test_byte_binary(TestHarness harness)
  {
    BufferedImage img = new BufferedImage(10, 10, BufferedImage.TYPE_BYTE_BINARY);
    byte[] t = new byte[]{ 0, (byte)255 };
    harness.check(img.getColorModel().equals(new IndexColorModel( 1, 2, t, t, t )));
    harness.check(img.getSampleModel().equals(new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
                                                                             10, 10, 1)));
    harness.check(img.isAlphaPremultiplied(), img.getColorModel().isAlphaPremultiplied());
  }
View Full Code Here

      {
    r[ index ] = g[ index ] = b[ index ] =
      (byte)(18 + (index - 216) * 6);
    index++;
      }
    harness.check(img.getColorModel().equals(new IndexColorModel( 8, 256, r, g, b )));
    harness.check(img.getSampleModel().equals(new PixelInterleavedSampleModel( DataBuffer.TYPE_BYTE,
                                                                              10, 10,
                                                                              1, 10, new int[]{ 0 } )));
    harness.check(img.isAlphaPremultiplied(), img.getColorModel().isAlphaPremultiplied());
  }
View Full Code Here

            r[i] = (byte) (0 + (((i * 5)) % 10) * 20);
        }
        r[7] = ff;
        g[7] = 0;
        b[7] = 0;
        return new IndexColorModel(8, 256, r, g, b);
    }
View Full Code Here

            }
        }
        else
        {
            byte[] map = new byte[] { (byte) 0x00, (byte) 0xFF };
            colorModel = new IndexColorModel(1, map.length, map, map, map, Transparency.OPAQUE);
        }
        WritableRaster raster = colorModel.createCompatibleWritableRaster(cols, rows);
        DataBufferByte buffer = (DataBufferByte) raster.getDataBuffer();
        bufferData = buffer.getData();
        IOUtils.populateBuffer(stream.getUnfilteredStream(), bufferData);
        BufferedImage image = new BufferedImage(colorModel, raster, false, null);
        if (!blackIsOne)
        {
            // Inverting the bitmap
            // Note the previous approach with starting from an IndexColorModel didn't work
            // reliably. In some cases the image wouldn't be painted for some reason.
            // So a safe but slower approach was taken.
            invertBitmap(bufferData);
        }
        /*
         * If we have an image mask we need to add an alpha channel to the data
         */
        if (hasMask())
        {
            byte[] map = new byte[] { (byte) 0x00, (byte) 0xff };
            IndexColorModel cm = new IndexColorModel(1, map.length, map, map, map, Transparency.OPAQUE);
            raster = cm.createCompatibleWritableRaster(cols, rows);
            bufferData = ((DataBufferByte) raster.getDataBuffer()).getData();

            byte[] array = ((DataBufferByte) image.getData().getDataBuffer()).getData();
            System.arraycopy(array, 0, bufferData, 0,
                    (array.length < bufferData.length ? array.length : bufferData.length));
View Full Code Here

                }
                else
                {
                    map = new byte[] {(byte)0x00, (byte)0xff};
                }
                cm = new IndexColorModel(bpc, map.length, map, map, map, Transparency.OPAQUE);
            }
            else
            {
                if (colorspace instanceof PDICCBased)
                {
                    if (((PDICCBased)colorspace).getNumberOfComponents() == 1)
                    {
                        byte[] map = new byte[] {(byte)0xff};
                        cm = new IndexColorModel(bpc, 1, map, map, map, Transparency.OPAQUE);
                    }
                    else
                    {
                        cm = colorspace.createColorModel( bpc );
                    }
View Full Code Here

            int[] temp = new int[length];
            System.arraycopy(cmap, 0, temp, 0, cmap.length);
            cmap = temp;
        }
       
        return new IndexColorModel(bits, cmap.length, cmap, 0, true, transparentIndex,
                DataBuffer.TYPE_BYTE);
    }
View Full Code Here

        SampleModel sm = theTile.getSampleModel();
  ColorModel  cm;

        if ((colorType == PNG_COLOR_PALETTE) && !expandPalette) {
            if (outputHasAlphaPalette) {
                cm = new IndexColorModel(bitDepth,
                                                 paletteEntries,
                                                 redPalette,
                                                 greenPalette,
                                                 bluePalette,
                                                 alphaPalette);
            } else {
                cm = new IndexColorModel(bitDepth,
                                                 paletteEntries,
                                                 redPalette,
                                                 greenPalette,
                                                 bluePalette);
            }
        } else if ((colorType == PNG_COLOR_GRAY) &&
                   (bitDepth < 8) && !output8BitGray) {
            byte[] palette = expandBits[bitDepth];
            cm = new IndexColorModel(bitDepth,
                                             palette.length,
                                             palette,
                                             palette,
                                             palette);
        } else {
View Full Code Here

TOP

Related Classes of java.awt.image.IndexColorModel

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.