Examples of IndexColorModel


Examples of java.awt.image.IndexColorModel

                                                tileHeight,
                                                sampleSize);
            if(imageType == TYPE_BILEVEL) {
                byte[] map = new byte[] {(byte)(isWhiteZero ? 255 : 0),
                                         (byte)(isWhiteZero ? 0 : 255)};
    colorModel = new IndexColorModel(1, 2, map, map, map);
            } else {
                colorModel =
                    ImageCodec.createGrayIndexColorModel(sampleModel,
                                                         !isWhiteZero);
            }
            break;

        case TYPE_GRAY:
        case TYPE_GRAY_ALPHA:
        case TYPE_RGB:
        case TYPE_RGB_ALPHA:
  case TYPE_CMYK:
            // Create a pixel interleaved SampleModel with decreasing
            // band offsets.
            int[] RGBOffsets = new int[numBands];
            if(compression == COMP_JPEG_TTN2) {
                for (int i=0; i<numBands; i++) {
                    RGBOffsets[i] = numBands - 1 - i;
                }
            } else {
                for (int i=0; i<numBands; i++) {
                    RGBOffsets[i] = i;
                }
            }
            sampleModel = createPixelInterleavedSampleModel(dataType,
                                                            tileWidth,
                                                            tileHeight,
                                                            numBands,
                                                            numBands*tileWidth,
                                                            RGBOffsets);

            if(imageType == TYPE_GRAY || imageType == TYPE_RGB) {
                colorModel =
                    ImageCodec.createComponentColorModel(sampleModel);
            } else if (imageType == TYPE_CMYK) {
    colorModel = ImageCodec.createComponentColorModel(sampleModel,
                  SimpleCMYKColorSpace.getInstance());
      } else { // hasAlpha
                // Transparency.OPAQUE signifies image data that is
                // completely opaque, meaning that all pixels have an alpha
                // value of 1.0. So the extra band gets ignored, which is
                // what we want.
                int transparency = Transparency.OPAQUE;
                if(extraSamples == 1 || extraSamples == 2) {
        // associated (premultiplied) alpha when == 1
        // unassociated alpha when ==2
        // Fix bug: 4699316
                    transparency = Transparency.TRANSLUCENT;
                }

                colorModel =
                    createAlphaComponentColorModel(dataType,
                                                   numBands,
                                                   extraSamples == 1,
               transparency);
            }
            break;

        case TYPE_GENERIC:
        case TYPE_YCBCR_SUB:
            // For this case we can't display the image, so we create a
            // SampleModel with increasing bandOffsets, and keep the
            // ColorModel as null, as there is no appropriate ColorModel.

            int[] bandOffsets = new int[numBands];
            for (int i=0; i<numBands; i++) {
                bandOffsets[i] = i;
            }

            sampleModel =
                createPixelInterleavedSampleModel(dataType,
                                                  tileWidth, tileHeight,
                                                  numBands, numBands * tileWidth,
                                                  bandOffsets);
            colorModel = null;
            break;

        case TYPE_PALETTE:
      // Get the colormap
      TIFFField cfield = getField(dir, TIFFImageDecoder.TIFF_COLORMAP,
          "Colormap");
      colormap = cfield.getAsChars();

      // Could be either 1 or 3 bands depending on whether we use
      // IndexColorModel or not.
      if (decodePaletteAsShorts) {
    numBands = 3;

    // If no SampleFormat tag was specified and if the
    // sampleSize is less than or equal to 8, then the
    // dataType was initially set to byte, but now we want to
    // expand the palette as shorts, so the dataType should
    // be ushort.
    if (dataType == DataBuffer.TYPE_BYTE) {
        dataType = DataBuffer.TYPE_USHORT;
    }

    // Data will have to be unpacked into a 3 band short image
    // as we do not have a IndexColorModel that can deal with
    // a colormodel whose entries are of short data type.
    sampleModel =
        RasterFactory.createPixelInterleavedSampleModel(dataType,
                    tileWidth,
                    tileHeight,
                    numBands);
    colorModel = ImageCodec.createComponentColorModel(sampleModel);

      } else {

    numBands = 1;

    if (sampleSize == 4) {
        // Pixel data will not be unpacked, will use MPPSM to store
        // packed data and IndexColorModel to do the unpacking.
        sampleModel =
      new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
              tileWidth,
              tileHeight,
              sampleSize);
    } else if (sampleSize == 8) {
        sampleModel =
      RasterFactory.createPixelInterleavedSampleModel(
                  DataBuffer.TYPE_BYTE,
                  tileWidth,
                  tileHeight,
                  numBands);
    } else if (sampleSize == 16) {

        // Here datatype has to be unsigned since we are storing
        // indices into the IndexColorModel palette. Ofcourse
        // the actual palette entries are allowed to be negative.
                    dataType = DataBuffer.TYPE_USHORT;
        sampleModel =
      RasterFactory.createPixelInterleavedSampleModel(
              DataBuffer.TYPE_USHORT,
              tileWidth,
              tileHeight,
              numBands);
    }

    int bandLength = colormap.length/3;
    byte r[] = new byte[bandLength];
    byte g[] = new byte[bandLength];
    byte b[] = new byte[bandLength];

    int gIndex = bandLength;
    int bIndex = bandLength * 2;

    if (dataType == DataBuffer.TYPE_SHORT) {

        for (int i=0; i<bandLength; i++) {
      r[i] = param.decodeSigned16BitsTo8Bits(
                  (short)colormap[i]);
      g[i] = param.decodeSigned16BitsTo8Bits(
                 (short)colormap[gIndex+i]);
      b[i] = param.decodeSigned16BitsTo8Bits(
                 (short)colormap[bIndex+i]);
        }

    } else {

        for (int i=0; i<bandLength; i++) {
      r[i] = param.decode16BitsTo8Bits(colormap[i] & 0xffff);
      g[i] = param.decode16BitsTo8Bits(colormap[gIndex+i] &
               0xffff);
      b[i] = param.decode16BitsTo8Bits(colormap[bIndex+i] &
               0xffff);
        }

    }

    colorModel = new IndexColorModel(sampleSize,
             bandLength, r, g, b);
      }
            break;

        default:
View Full Code Here

Examples of java.awt.image.IndexColorModel

                }
            }
            return data;

        } else if (image.getColorModel() instanceof IndexColorModel) {
            IndexColorModel cmodel = (IndexColorModel)image.getColorModel();
            int size = cmodel.getMapSize();
            byte[] reds = new byte[size];
            byte[] greens = new byte[size];
            byte[] blues = new byte[size];
            cmodel.getReds(reds);
            cmodel.getGreens(greens);
            cmodel.getBlues(blues);
            RGB[] rgbs = new RGB[size];
            for (int ii = 0; ii < rgbs.length; ii++) {
                rgbs[ii] = new RGB(reds[ii] & 0xFF, greens[ii] & 0xFF, blues[ii] & 0xFF);
            }
            PaletteData palette = new PaletteData(rgbs);
            ImageData data = new ImageData(
                image.getWidth(), image.getHeight(), cmodel.getPixelSize(), palette);
            data.transparentPixel = cmodel.getTransparentPixel();
            WritableRaster raster = image.getRaster();
            int[] pixelArray = new int[1];
            for (int y = 0; y < data.height; y++) {
                for (int x = 0; x < data.width; x++) {
                    raster.getPixel(x, y, pixelArray);
                    data.setPixel(x, y, pixelArray[0]);
                }
            }
            return data;
        } else if (image.getColorModel() instanceof ComponentColorModel) {
            ComponentColorModel cmodel = (ComponentColorModel)image.getColorModel();
            PaletteData palette = new PaletteData(0x0000FF, 0x00FF00, 0xFF0000); // BGR
            ImageData data = new ImageData(image.getWidth(), image.getHeight(), 24, palette);
            if (cmodel.hasAlpha()) data.alphaData = new byte[image.getWidth() * image.getHeight()];
            WritableRaster raster = image.getRaster();
            int[] pixelArray = new int[4];
            for (int y = 0; y < data.height; y++) {
                for (int x = 0; x < data.width; x++) {
                    raster.getPixel(x, y, pixelArray);
View Full Code Here

Examples of java.awt.image.IndexColorModel

                    for(int j = end; j < 256; j++) {
                        band[j] = (byte)0xFF;
                    }
                }

                il.setColorModel(new IndexColorModel(8, 256,
                                                     cmap[0], cmap[1],
                                                     cmap[2]));
            }
        }
View Full Code Here

Examples of java.awt.image.IndexColorModel

                break;
            }
            // only do this if not copied and expanded
            if ((formatTagID & EXPANSION_MASK) == EXPANDED &&
                theColorModel instanceof IndexColorModel) {
                IndexColorModel icm = (IndexColorModel)theColorModel;
   
                int newNumBands = icm.getNumComponents();
   
                int mapSize = icm.getMapSize();
                int newBandDataOffsets[] = new int[newNumBands];
                int newScanlineStride = rectWidth*newNumBands;
                int newPixelStride = newNumBands;
                byte ctable[][] = new byte[newNumBands][mapSize];
   
                icm.getReds(ctable[0]);
                icm.getGreens(ctable[1]);
                icm.getBlues(ctable[2]);
                byte rtable[] = ctable[0];
                byte gtable[] = ctable[1];
                byte btable[] = ctable[2];
   
                byte atable[] = null;
                if (newNumBands == 4) {
                    icm.getAlphas(ctable[3]);
                    atable = ctable[3];
                }
   
                for (int i = 0; i < newNumBands; i++) {
                    newBandDataOffsets[i] = i;
View Full Code Here

Examples of java.awt.image.IndexColorModel

                    cmap[i] = (byte)(255 - i);
                }
            }
        }

        return new IndexColorModel(sampleSize, cmap.length,
                                   cmap, cmap, cmap);
    }
View Full Code Here

Examples of java.awt.image.IndexColorModel

                    for(int j = end; j < 256; j++) {
                        band[j] = (byte)0xFF;
                    }
                }

                il.setColorModel(new IndexColorModel(8, 256,
                                                     cmap[0], cmap[1],
                                                     cmap[2]));
            }
        }
View Full Code Here

Examples of java.awt.image.IndexColorModel

    im.getColorModel() instanceof IndexColorModel &&
    config != null &&
    config.containsKey(JAI.KEY_REPLACE_INDEX_COLOR_MODEL) &&
    ((Boolean)config.get(JAI.KEY_REPLACE_INDEX_COLOR_MODEL)).booleanValue()) {

    IndexColorModel icm = (IndexColorModel)im.getColorModel();

    // We need to change the ColorModel to a non IndexColorModel
    // so that operations such as geometric can take place
    // correctly. If the ColorModel is changed the SampleModel
    // needs to be changed too, so that they are compatible
    cm = PlanarImage.getDefaultColorModel(srcSM.getDataType(),
                  icm.getNumComponents());
   
    SampleModel newSM;
    if (cm != null) {
        newSM = cm.createCompatibleSampleModel(srcSM.getWidth(),
                 srcSM.getHeight());
    } else {
        newSM = RasterFactory.createPixelInterleavedSampleModel(
                  srcSM.getDataType(),
                  srcSM.getWidth(),
                  srcSM.getHeight(),
                  icm.getNumComponents());
    }

    il.setSampleModel(newSM);

      } else {
View Full Code Here

Examples of java.awt.image.IndexColorModel

         * Note, in this case, the source should have an integral data type.
         * And dest always has data type byte.
         */
        ColorModel srcColorModel = source.getColorModel();
        if (srcColorModel instanceof IndexColorModel) {
            IndexColorModel icm = (IndexColorModel)srcColorModel;
            ctable = new byte[3][icm.getMapSize()];
            icm.getReds(ctable[0]);
            icm.getGreens(ctable[1]);
            icm.getBlues(ctable[2]);
        }
    }
View Full Code Here

Examples of java.awt.image.IndexColorModel

                    for(int j = end; j < 256; j++) {
                        band[j] = (byte)0xFF;
                    }
                }

                il.setColorModel(new IndexColorModel(8, 256,
                                                     cmap[0], cmap[1],
                                                     cmap[2]));
            }
        }
View Full Code Here

Examples of java.awt.image.IndexColorModel

        int maxX = rect.x + rect.width;
        int maxY = rect.y + rect.height;

        if(isIndexCM) {
            // Cast the CM and get the size of the ICM tables.
            IndexColorModel icm = (IndexColorModel)colorModel;
            int mapSize = icm.getMapSize();

            // Load the ICM tables.
            byte[] reds = new byte[mapSize];
            icm.getReds(reds);
            byte[] greens = new byte[mapSize];
            icm.getGreens(greens);
            byte[] blues = new byte[mapSize];
            icm.getBlues(blues);
            byte[] alphas = null;
            if(icm.hasAlpha()) {
                alphas = new byte[mapSize];
                icm.getAlphas(alphas);
            }

            // Get the index values.
            int[] indices = raster.getPixels(rect.x, rect.y,
                                             rect.width, rect.height,
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.