Package java.awt.image

Examples of java.awt.image.IndexColorModel


            forceToIntARGB();
        }

        if(isIntRGB){
            int buff[] = new int[w];
            IndexColorModel icm = (IndexColorModel) model;
            int colorMap[] = new int[icm.getMapSize()];
            icm.getRGBs(colorMap);
            DataBufferInt dbi = (DataBufferInt) raster.getDataBuffer();
            int data[] = dbi.getData();
            int scanline = raster.getWidth();
            int rof = dbi.getOffset() + y * scanline + x;
            if(model instanceof IndexColorModel){
View Full Code Here


        Object obj = null;
        int pixels[] = new int[w];

        if(cm instanceof IndexColorModel){
            IndexColorModel icm = (IndexColorModel) cm;
            int colorMap[] = new int[icm.getMapSize()];
            icm.getRGBs(colorMap);

            for (int y = 0; y < h; y++) {
                obj = raster.getDataElements(0, y, w, 1, obj);
                byte ba[] = (byte[]) obj;
                for (int x = 0; x < ba.length; x++) {
View Full Code Here

            SinglePixelPackedSampleModel sppsm = (SinglePixelPackedSampleModel) sm;
            scanlineStride = sppsm.getScanlineStride();

        }else if(cm instanceof IndexColorModel){
            cmType = ICM;
            IndexColorModel icm = (IndexColorModel) cm;
            colorMapSize = icm.getMapSize();
            colorMap = new int[colorMapSize];
            icm.getRGBs(colorMap);
            transpPixel = icm.getTransparentPixel();
            isGrayPallete = Surface.isGrayPallete(icm);

            if(sm instanceof MultiPixelPackedSampleModel){
                smType = MPPSM;
                MultiPixelPackedSampleModel mppsm =
View Full Code Here

            colorModel instanceof IndexColorModel &&
            dataType != DataBuffer.TYPE_BYTE) {
            // Don't support (unsigned) short palette-color images.
      throw new Error("TIFFImageEncoder6");
        }
  IndexColorModel icm = null;
  int sizeOfColormap = 0
        char colormap[] = null;

        // Set image type.
  int imageType = TIFF_UNSUPPORTED;
        int numExtraSamples = 0;
        int extraSampleType = EXTRA_SAMPLE_UNSPECIFIED;
        if(colorModel instanceof IndexColorModel) { // Bilevel or palette
            icm = (IndexColorModel)colorModel;
            int mapSize = icm.getMapSize();

            if(sampleSize[0] == 1 && numBands == 1) { // Bilevel image

    if (mapSize != 2) {
        throw new IllegalArgumentException(
          "TIFFImageEncoder7");
    }

    byte r[] = new byte[mapSize];
    icm.getReds(r);
    byte g[] = new byte[mapSize];
    icm.getGreens(g);
    byte b[] = new byte[mapSize];
    icm.getBlues(b);

    if ((r[0] & 0xff) == 0 &&
        (r[1] & 0xff) == 255 &&
        (g[0] & 0xff) == 0 &&
        (g[1] & 0xff) == 255 &&
        (b[0] & 0xff) == 0 &&
        (b[1] & 0xff) == 255) {

        imageType = TIFF_BILEVEL_BLACK_IS_ZERO;

    } else if ((r[0] & 0xff) == 255 &&
         (r[1] & 0xff) == 0 &&
         (g[0] & 0xff) == 255 &&
         (g[1] & 0xff) == 0 &&
         (b[0] & 0xff) == 255 &&
         (b[1] & 0xff) == 0) {
       
        imageType = TIFF_BILEVEL_WHITE_IS_ZERO;

    } else {
        imageType = TIFF_PALETTE;
    }

      } else if(numBands == 1) { // Non-bilevel image.
    // Palette color image.
    imageType = TIFF_PALETTE;
      }
  } else if(colorModel == null) {

            if(sampleSize[0] == 1 && numBands == 1) { // bilevel
                imageType = TIFF_BILEVEL_BLACK_IS_ZERO;
            } else { // generic image
                imageType = TIFF_GENERIC;
                if(numBands > 1) {
                    numExtraSamples = numBands - 1;
                }
            }

        } else { // colorModel is non-null but not an IndexColorModel
            ColorSpace colorSpace = colorModel.getColorSpace();

            switch(colorSpace.getType()) {
            case ColorSpace.TYPE_CMYK:
                imageType = TIFF_CMYK;
                break;
            case ColorSpace.TYPE_GRAY:
                imageType = TIFF_GRAY;
                break;
            case ColorSpace.TYPE_Lab:
                imageType = TIFF_CIELAB;
                break;
            case ColorSpace.TYPE_RGB:
                if(compression == COMP_JPEG_TTN2 &&
                   encodeParam.getJPEGCompressRGBToYCbCr()) {
                    imageType = TIFF_YCBCR;
                } else {
                    imageType = TIFF_RGB;
                }
                break;
            case ColorSpace.TYPE_YCbCr:
                imageType = TIFF_YCBCR;
                break;
            default:
                imageType = TIFF_GENERIC; // generic
                break;
            }

            if(imageType == TIFF_GENERIC) {
                numExtraSamples = numBands - 1;
            } else if(numBands > 1) {
                numExtraSamples = numBands - colorSpace.getNumComponents();
            }

            if(numExtraSamples == 1 && colorModel.hasAlpha()) {
                extraSampleType = colorModel.isAlphaPremultiplied() ?
                    EXTRA_SAMPLE_ASSOCIATED_ALPHA :
                    EXTRA_SAMPLE_UNASSOCIATED_ALPHA;
            }
        }

        if(imageType == TIFF_UNSUPPORTED) {
            throw new Error("TIFFImageEncoder8");
        }

        // Check JPEG compatibility.
        if(compression == COMP_JPEG_TTN2) {
            if(imageType == TIFF_PALETTE) {
                throw new Error("TIFFImageEncoder11");
            } else if(!(sampleSize[0] == 8 &&
                        (imageType == TIFF_GRAY ||
                         imageType == TIFF_RGB ||
                         imageType == TIFF_YCBCR))) {
                throw new Error("TIFFImageEncoder9");
            }
        }
 
  int photometricInterpretation = -1;
  switch (imageType) {

  case TIFF_BILEVEL_WHITE_IS_ZERO:
      photometricInterpretation = 0;
      break;

  case TIFF_BILEVEL_BLACK_IS_ZERO:
      photometricInterpretation = 1;
      break;

  case TIFF_GRAY:
        case TIFF_GENERIC:
      // Since the CS_GRAY colorspace is always of type black_is_zero
      photometricInterpretation = 1;
      break;

  case TIFF_PALETTE:
      photometricInterpretation = 3;

      icm = (IndexColorModel)colorModel;
      sizeOfColormap = icm.getMapSize();

      byte r[] = new byte[sizeOfColormap];
      icm.getReds(r);
      byte g[] = new byte[sizeOfColormap];
      icm.getGreens(g);
      byte b[] = new byte[sizeOfColormap];
      icm.getBlues(b);

      int redIndex = 0, greenIndex = sizeOfColormap;
      int blueIndex = 2 * sizeOfColormap;
            colormap = new char[sizeOfColormap * 3];
      for (int i=0; i<sizeOfColormap; i++) {
View Full Code Here

        byte[] index = getLookupData();
        PDColorSpace baseColorSpace = getBaseColorSpace();
        ColorModel cm = null;
        if( baseColorSpace instanceof PDDeviceRGB )
        {
            cm = new IndexColorModel(bpc, size+1, index,0,false);
        }
        else
        {
            ColorModel baseColorModel = baseColorSpace.createColorModel(bpc);
            if( baseColorModel.getTransferType() != DataBuffer.TYPE_BYTE )
            {
                throw new IOException( "Not implemented" );
            }
            byte[] r = new byte[size+1];
            byte[] g = new byte[size+1];
            byte[] b = new byte[size+1];
            byte[] a = baseColorModel.hasAlpha() ? new byte[size+1] : null;
            byte[] inData = new byte[baseColorModel.getNumComponents()];
            for( int i = 0; i <= size; i++ )
            {
                System.arraycopy(index, i * inData.length, inData, 0, inData.length);
                r[i] = (byte)baseColorModel.getRed(inData);
                g[i] = (byte)baseColorModel.getGreen(inData);
                b[i] = (byte)baseColorModel.getBlue(inData);
                if(a != null)
                {
                    a[i] = (byte)baseColorModel.getAlpha(inData);
                }
            }
            cm = a == null ? new IndexColorModel(bpc, size+1, r, g, b) : new IndexColorModel(bpc, size+1, r, g, b, a);
        }
        return cm;
    }
View Full Code Here

            baseXOffset += curGlyph.getGlyphPointMetrics().getAdvanceX();
        }

        byte[] blackWhite = new byte[] { 0, (byte) 0xff };
        IndexColorModel colorModel = new IndexColorModel(1, 2, blackWhite,
                blackWhite, blackWhite);

        BufferedImage stringImage = new BufferedImage(colorModel, wr, false,
                null);
        return stringImage;
View Full Code Here

        out.println(':');
        if (model instanceof IndexColorModel) {
            out.println();
            out.println("Sample  Colors              Category or geophysics value");
            out.println("------  ----------------    ----------------------------");
            final IndexColorModel palette = (IndexColorModel) model;
            final int size = palette.getMapSize();
            final byte[] R = new byte[size];
            final byte[] G = new byte[size];
            final byte[] B = new byte[size];
            palette.getReds  (R);
            palette.getGreens(G);
            palette.getBlues (B);
            for (int i=0; i<size; i++) {
                format(out,   i);  out.print(":    RGB[");
                format(out, R[i]); out.print(',');
                format(out, G[i]); out.print(',');
                format(out, R[i]); out.print(']');
View Full Code Here

          red[i] = (byte) rgb.red;
          green[i] = (byte) rgb.green;
          blue[i] = (byte) rgb.blue;
        }
        if (data.transparentPixel != -1) {
          colorModel = new IndexColorModel(data.depth, rgbs.length, red,
              green, blue, data.transparentPixel);
        } else {
          colorModel = new IndexColorModel(data.depth, rgbs.length, red,
              green, blue);
        }
        BufferedImage bufferedImage = new BufferedImage(colorModel,
            colorModel.createCompatibleWritableRaster(data.width,
                data.height), false, null);
View Full Code Here

    public static void run(int bits, int size) {
        byte[] r = new byte[size];
        byte[] g = new byte[size];
        byte[] b = new byte[size];

        IndexColorModel cm = new IndexColorModel(bits, size, r, g, b);

        System.out.println("Bits         = " + bits);
        System.out.println("Size         = " + size);
        System.out.println("cm.PixelSize = " + cm.getPixelSize());
        System.out.println("cm.MapSize   = " + cm.getMapSize());
    }
View Full Code Here

        final byte[] r = {0, 63, (byte) 128, (byte) 168, (byte) 255};
        final byte[] g = {63, (byte) 128, (byte) 168, (byte) 255, 0};
        final byte[] b = {(byte) 128, (byte) 168, (byte) 255, 0, 63};

        final IndexColorModel model = new IndexColorModel(8, r.length, r, g, b);

        for (int i = 0; i < r.length; i++) {
            System.out.println("i=" + i);
            System.out.println("r: " + (r[i] & 0xFF) + ", " + model.getRed(i));
            System.out.println("g: " + (g[i] & 0xFF) + ", " + model.getGreen(i));
            System.out.println("b: " + (b[i] & 0xFF) + ", " + model.getBlue(i));
            System.out.println("rgb: " + Integer.toHexString(model.getRGB(i)));
        }
    }
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.