Examples of IndexColorModel


Examples of java.awt.image.IndexColorModel

      }

      if (ImageCodec.isIndicesForGrayscale(r, g, b))
    colorModel = ImageCodec.createComponentColorModel(sampleModel);
      else
    colorModel = new IndexColorModel(bitsPerPixel, size, r, g, b);
  } else if (bitsPerPixel == 16) {
      numBands = 3;
            sampleModel =
    new SinglePixelPackedSampleModel(DataBuffer.TYPE_USHORT,
            width, height,
View Full Code Here

Examples of java.awt.image.IndexColorModel

        decodeImage(interlaceMethod == 1);
        sampleModel = theTile.getSampleModel();

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

Examples of java.awt.image.IndexColorModel

            return new DirectColorModel(bits, rmask, gmask, bmask, amask);

        } else if (ImageUtil.isBinary(sm)) {
            byte[] comp = new byte[] { (byte)0x00, (byte)0xFF };

            return new IndexColorModel(1, 2, comp, comp, comp);

        } else // unable to create an suitable ColorModel
            return null;
        }
    }
View Full Code Here

Examples of java.awt.image.IndexColorModel

            }
            if (sampleModel.getNumBands() != 1) {
                throw new RuntimeException();
            }

            IndexColorModel icm = (IndexColorModel)colorModel;
            int size = icm.getMapSize();
           
            redPalette = new byte[size];
            greenPalette = new byte[size];
            bluePalette = new byte[size];
            alphaPalette = new byte[size];
           
            icm.getReds(redPalette);
            icm.getGreens(greenPalette);
            icm.getBlues(bluePalette);
            icm.getAlphas(alphaPalette);

            this.bpp = 1;

            if (param == null) {
                param = createGrayParam(redPalette,
View Full Code Here

Examples of java.awt.image.IndexColorModel

        if (colorModel instanceof IndexColorModel) {
            //
            // Need to expand the indexed data to components.
            // The convertToIntDiscrete method is used to perform this.
            //
            IndexColorModel icm = (IndexColorModel)colorModel;
            bi = icm.convertToIntDiscrete(bi.getRaster(), false);

            if(bi.getSampleModel().getNumBands() == 4) {
                //
                // Without copying data create a BufferedImage which has
                // only the RGB bands, not the alpha band.
View Full Code Here

Examples of java.awt.image.IndexColorModel

        isInitialized = true;

        // Transform the colormap if the operation is accelerated.
        if(isColormapAccelerated) {
            // Cast the target ColorModel.
            IndexColorModel icm = (IndexColorModel)dstCM;

            // Get the size and allocate the array.
            int mapSize = icm.getMapSize();
            byte[][] colormap = new byte[3][mapSize];

            // Load the colormap.
            icm.getReds(colormap[0]);
            icm.getGreens(colormap[1]);
            icm.getBlues(colormap[2]);

            // Transform the colormap.
            transformColormap(colormap);

            // Clamp the colormap if necessary. In the Sun implementation
            // of IndexColorModel, getComponentSize() always returns 8 so
            // no clamping will be performed.
            for(int b = 0; b < 3; b++) {
                int maxComponent = 0xFF >> (8 - icm.getComponentSize(b));
                if(maxComponent < 255) {
                    byte[] map = colormap[b];
                    for(int i = 0; i < mapSize; i++) {
                        if((map[i] & 0xFF) > maxComponent) {
                            map[i] = (byte)maxComponent;
                        }
                    }
                }
            }

            // Cache references to individual color component arrays.
            byte[] reds = colormap[0];
            byte[] greens = colormap[1];
            byte[] blues = colormap[2];

            // Create the RGB array.
            int[] rgb = new int[mapSize];

            // Copy the colormap into the RGB array.
            if(icm.hasAlpha()) {
                byte[] alphas = new byte[mapSize];
                icm.getAlphas(alphas);
                for(int i = 0; i < mapSize; i++) {
                    rgb[i] =
                        ((alphas[i] & 0xFF) << 24) |
                        ((reds[i] & 0xFF)   << 16) |
                        ((greens[i] & 0xFF) <<  8) |
                        (blues[i] & 0xFF);
                }
            } else {
                for(int i = 0; i < mapSize; i++) {
                    rgb[i] =
                        ((reds[i] & 0xFF)   << 16) |
                        ((greens[i] & 0xFF) <<  8) |
                        (blues[i] & 0xFF);
                }
            }

            // Create the new ColorModel.
            colorModel= new IndexColorModel(icm.getPixelSize(), mapSize,
                                            rgb, 0, icm.hasAlpha(),
                                            icm.getTransparentPixel(),
                                            sampleModel.getTransferType());
        }
    }
View Full Code Here

Examples of java.awt.image.IndexColorModel

        }

        // Check whether the image is white-is-zero.
        boolean isWhiteZero = false;
        if(im.getColorModel() instanceof IndexColorModel) {
            IndexColorModel icm = (IndexColorModel)im.getColorModel();
            isWhiteZero =
                (icm.getRed(0) + icm.getGreen(0) + icm.getBlue(0)) >
                (icm.getRed(1) + icm.getGreen(1) + icm.getBlue(1));
        }

        // Get the line stride, bytes per row, and data array.
        int lineStride =
            ((MultiPixelPackedSampleModel)sm).getScanlineStride();
View Full Code Here

Examples of java.awt.image.IndexColorModel

        if (!transparentColorFlag) {
            if (ImageCodec.isIndicesForGrayscale(r, g, b))
                colorModel = ImageCodec.createComponentColorModel(sampleModel);
            else
                colorModel = new IndexColorModel(bits, r.length, r, g, b);
        } else {
            colorModel =
    new IndexColorModel(bits, r.length, r, g, b, transparentColorIndex);
        }
    }
View Full Code Here

Examples of java.awt.image.IndexColorModel

  // Default is using 24 bits per pixel.
  int bitsPerPixel = 24;
  boolean isPalette = false;
  int paletteEntries = 0;
  IndexColorModel icm = null;
  SampleModel sm = im.getSampleModel();
  int numBands = sm.getNumBands();

  ColorModel cm = im.getColorModel();

  if (numBands != 1 && numBands != 3) {
      throw new
    IllegalArgumentException(JaiI18N.getString("BMPImageEncoder1"));
  }
 
  int sampleSize[] = sm.getSampleSize();
  if (sampleSize[0] > 8) {
      throw new RuntimeException(JaiI18N.getString("BMPImageEncoder2"));
  }

  for (int i=1; i<sampleSize.length; i++) {
      if (sampleSize[i] != sampleSize[0]) {
    throw
        new RuntimeException(JaiI18N.getString("BMPImageEncoder3"));
      }
  }

  // Float and Double data cannot be written in a BMP format.
  int dataType = sm.getTransferType();
        if (dataType != DataBuffer.TYPE_BYTE &&
            !CodecUtils.isPackedByteImage(im)) {
            throw new RuntimeException(JaiI18N.getString("BMPImageEncoder0"));
        }

  // Number of bytes that a scanline for the image written out will have.
  int destScanlineBytes = w * numBands;
  int compression = 0;


  byte r[] = null, g[] = null, b[] = null, a[] = null;

  if (cm instanceof IndexColorModel) {

      isPalette = true;
      icm = (IndexColorModel)cm;
      paletteEntries = icm.getMapSize();

      if (paletteEntries <= 2) {

    bitsPerPixel = 1;
    destScanlineBytes = (int)Math.ceil((double)w/8.0);

      } else if (paletteEntries <= 16) {

    bitsPerPixel = 4;
    destScanlineBytes = (int)Math.ceil((double)w/2.0);

      } else if (paletteEntries <= 256) {

    bitsPerPixel = 8;

      } else {

    // Cannot be written as a Palette image. So write out as
    // 24 bit image.
    bitsPerPixel = 24;
    isPalette = false;
    paletteEntries = 0;
    destScanlineBytes = w * 3;
      }

      if (isPalette == true) {

    r = new byte[paletteEntries];
    g = new byte[paletteEntries];
    b = new byte[paletteEntries];
    a = new byte[paletteEntries];
   
    icm.getAlphas(a);
    icm.getReds(r);
    icm.getGreens(g);
    icm.getBlues(b);
      }

  } else {
     
      // Grey scale images
View Full Code Here

Examples of java.awt.image.IndexColorModel

            colorModel instanceof IndexColorModel &&
            dataType != DataBuffer.TYPE_BYTE) {
            // Don't support (unsigned) short palette-color images.
      throw new RuntimeException(JaiI18N.getString("TIFFImageEncoder6"));
        }
  IndexColorModel icm = null;
  int sizeOfColormap = 0
  int 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(
          JaiI18N.getString("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 RuntimeException(JaiI18N.getString("TIFFImageEncoder8"));
        }

        // Check JPEG compatibility.
        if(compression == COMP_JPEG_TTN2) {
            if(imageType == TIFF_PALETTE) {
                throw new RuntimeException(JaiI18N.getString("TIFFImageEncoder11"));
            } else if(!(sampleSize[0] == 8 &&
                        (imageType == TIFF_GRAY ||
                         imageType == TIFF_RGB ||
                         imageType == TIFF_YCBCR))) {
                throw new RuntimeException(JaiI18N.getString("TIFFImageEncoder9"));
            }
        }

        // Check bilevel encoding compatibility.
        if((imageType != TIFF_BILEVEL_WHITE_IS_ZERO &&
            imageType != TIFF_BILEVEL_BLACK_IS_ZERO) &&
           (compression == COMP_GROUP3_1D ||
            compression == COMP_GROUP3_2D ||
            compression == COMP_GROUP4)) {
            throw new RuntimeException(JaiI18N.getString("TIFFImageEncoder12"));
        }
 
  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 int[sizeOfColormap * 3];
      for (int i=0; i<sizeOfColormap; i++) {
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.