Package java.awt.image

Examples of java.awt.image.MultiPixelPackedSampleModel


            if (bitsPerSample[0] == 1) {

                image_type = XTIFF.TYPE_BILEVEL_WHITE_IS_ZERO;

                // Keep pixels packed, use IndexColorModel
                sampleModel = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, tileWidth, tileHeight, 1);

                // Set up the palette
                byte r[] = new byte[] { (byte) 255, (byte) 0 };
                byte g[] = new byte[] { (byte) 255, (byte) 0 };
                byte b[] = new byte[] { (byte) 255, (byte) 0 };

                colorModel = new IndexColorModel(1, 2, r, g, b);

            } else {

                image_type = XTIFF.TYPE_GREYSCALE_WHITE_IS_ZERO;

                if (bitsPerSample[0] == 4) {
                    sampleModel = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, tileWidth, tileHeight, 4);

                    colorModel = ImageCodec.createGrayIndexColorModel(sampleModel,
                            false);

                } else if (bitsPerSample[0] == 8) {
                    sampleModel = RasterFactory.createPixelInterleavedSampleModel(DataBuffer.TYPE_BYTE,
                            tileWidth,
                            tileHeight,
                            bands);

                    colorModel = ImageCodec.createGrayIndexColorModel(sampleModel,
                            false);

                } else if (bitsPerSample[0] == 16) {

                    sampleModel = RasterFactory.createPixelInterleavedSampleModel(dataType,
                            tileWidth,
                            tileHeight,
                            bands);

                    colorModel = ImageCodec.createComponentColorModel(sampleModel);

                } else {
                    throw new IllegalArgumentException(JaiI18N.getString("XTIFFImageDecoder14"));
                }
            }

            break;

        case XTIFF.PHOTOMETRIC_BLACK_IS_ZERO:

            bands = 1;

            // Bilevel or Grayscale - BlackIsZero
            if (bitsPerSample[0] == 1) {

                image_type = XTIFF.TYPE_BILEVEL_BLACK_IS_ZERO;

                // Keep pixels packed, use IndexColorModel
                sampleModel = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, tileWidth, tileHeight, 1);

                // Set up the palette
                byte r[] = new byte[] { (byte) 0, (byte) 255 };
                byte g[] = new byte[] { (byte) 0, (byte) 255 };
                byte b[] = new byte[] { (byte) 0, (byte) 255 };

                // 1 Bit pixels packed into a byte, use IndexColorModel
                colorModel = new IndexColorModel(1, 2, r, g, b);

            } else {

                image_type = XTIFF.TYPE_GREYSCALE_BLACK_IS_ZERO;

                if (bitsPerSample[0] == 4) {
                    sampleModel = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, tileWidth, tileHeight, 4);
                    colorModel = ImageCodec.createGrayIndexColorModel(sampleModel,
                            true);
                } else if (bitsPerSample[0] == 8) {
                    sampleModel = RasterFactory.createPixelInterleavedSampleModel(DataBuffer.TYPE_BYTE,
                            tileWidth,
                            tileHeight,
                            bands);
                    colorModel = ImageCodec.createComponentColorModel(sampleModel);

                } else if (bitsPerSample[0] == 16) {

                    sampleModel = RasterFactory.createPixelInterleavedSampleModel(dataType,
                            tileWidth,
                            tileHeight,
                            bands);
                    colorModel = ImageCodec.createComponentColorModel(sampleModel);

                } else {
                    throw new IllegalArgumentException(JaiI18N.getString("XTIFFImageDecoder14"));
                }
            }

            break;

        case XTIFF.PHOTOMETRIC_RGB:

            bands = samplesPerPixel;

            // RGB full color image
            if (bitsPerSample[0] == 8) {

                sampleModel = RasterFactory.createPixelInterleavedSampleModel(DataBuffer.TYPE_BYTE,
                        tileWidth,
                        tileHeight,
                        bands);
            } else if (bitsPerSample[0] == 16) {

                sampleModel = RasterFactory.createPixelInterleavedSampleModel(dataType,
                        tileWidth,
                        tileHeight,
                        bands);
            } else {
                throw new RuntimeException(JaiI18N.getString("XTIFFImageDecoder15"));
            }

            if (samplesPerPixel < 3) {
                throw new RuntimeException(JaiI18N.getString("XTIFFImageDecoder1"));

            } else if (samplesPerPixel == 3) {

                image_type = XTIFF.TYPE_RGB;
                // No alpha
                colorModel = ImageCodec.createComponentColorModel(sampleModel);

            } else if (samplesPerPixel == 4) {

                if (extraSamples == 0) {

                    image_type = XTIFF.TYPE_ORGB;
                    // 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.
                    colorModel = createAlphaComponentColorModel(dataType,
                            true,
                            false,
                            Transparency.OPAQUE);

                } else if (extraSamples == 1) {

                    image_type = XTIFF.TYPE_ARGB_PRE;
                    // Pre multiplied alpha.
                    colorModel = createAlphaComponentColorModel(dataType,
                            true,
                            true,
                            Transparency.TRANSLUCENT);

                } else if (extraSamples == 2) {

                    image_type = XTIFF.TYPE_ARGB;
                    // The extra sample here is unassociated alpha, usually a
                    // transparency mask, also called soft matte.
                    colorModel = createAlphaComponentColorModel(dataType,
                            true,
                            false,
                            Transparency.BITMASK);
                }

            } else {
                image_type = XTIFF.TYPE_RGB_EXTRA;

                // For this case we can't display the image, so there is no
                // point in trying to reformat the data to be BGR followed by
                // the ExtraSamples, the way Java2D would like it, because
                // Java2D can't display it anyway. Therefore create a sample
                // model with increasing bandOffsets, and keep the colorModel
                // as null, as there is no appropriate ColorModel.

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

                if (bitsPerSample[0] == 8) {

                    sampleModel = new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, tileWidth, tileHeight, bands, bands
                            * tileWidth, bandOffsets);
                    colorModel = null;

                } else if (bitsPerSample[0] == 16) {

                    sampleModel = new PixelInterleavedSampleModel(dataType, tileWidth, tileHeight, bands, bands
                            * tileWidth, bandOffsets);
                    colorModel = null;
                }
            }

            break;

        case XTIFF.PHOTOMETRIC_PALETTE:

            image_type = XTIFF.TYPE_PALETTE;

            // Get the colormap
            XTIFFField cfield = dir.getField(XTIFF.TIFFTAG_COLORMAP);
            if (cfield == null) {
                throw new RuntimeException(JaiI18N.getString("XTIFFImageDecoder2"));
            } else {
                colormap = cfield.getAsChars();
            }

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

                if (bitsPerSample[0] != 4 && bitsPerSample[0] != 8
                        && bitsPerSample[0] != 16) {
                    throw new RuntimeException(JaiI18N.getString("XTIFFImageDecoder13"));
                }

                // If no SampleFormat tag was specified and if the
                // bitsPerSample are 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,
                        bands);
                colorModel = ImageCodec.createComponentColorModel(sampleModel);

            } else {

                bands = 1;

                if (bitsPerSample[0] == 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, bitsPerSample[0]);
                } else if (bitsPerSample[0] == 8) {
                    sampleModel = RasterFactory.createPixelInterleavedSampleModel(DataBuffer.TYPE_BYTE,
                            tileWidth,
                            tileHeight,
                            bands);
View Full Code Here


        boolean writeOptimal = false;
        if (variant == PBM_RAW &&
            sampleModel.getTransferType() == DataBuffer.TYPE_BYTE &&
            sampleModel instanceof MultiPixelPackedSampleModel) {

            MultiPixelPackedSampleModel mppsm =
                (MultiPixelPackedSampleModel)sampleModel;

            // Must have left-aligned bytes with unity bit stride.
            if(mppsm.getDataBitOffset() == 0 &&
               mppsm.getPixelBitStride() == 1) {

                writeOptimal = true;
            }
        } else if ((variant == PGM_RAW || variant == PPM_RAW) &&
                   sampleModel instanceof ComponentSampleModel &&
View Full Code Here

        ImageLayout layout = (il == null) ?
            new ImageLayout() : (ImageLayout)il.clone();

        SampleModel sm = layout.getSampleModel(source);
        if(!ImageUtil.isBinary(sm)) {
            sm = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
                                                 layout.getTileWidth(source),
                                                 layout.getTileHeight(source),
                                                 1);
            layout.setSampleModel(sm);
        }
View Full Code Here

                 width, height,
                 numBands);
      } else {
    // 1 and 4 bit pixels can be stored in a packed format.
    sampleModel =
        new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
                width, height,
                bitsPerPixel);
      }

      // Create IndexColorModel from the palette.
View Full Code Here

      return PlanarImage.wrapRenderedImage(bi);

  } else {

      SampleModel sm =
    new MultiPixelPackedSampleModel(
      DataBuffer.TYPE_BYTE, r.width, r.height, 1);

      // Create a TiledImage into which to write.
      return new TiledImage(r.x, r.y, r.width, r.height, r.x, r.y,
        sm, PlanarImage.createColorModel(sm));
View Full Code Here

        if(sampleModel instanceof ComponentSampleModel) {
            ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
            numBanks = getNumBanksCSM(csm);
            size = getBufferSizeCSM(csm);
        } else if(sampleModel instanceof MultiPixelPackedSampleModel) {
            MultiPixelPackedSampleModel mppsm =
                (MultiPixelPackedSampleModel)sampleModel;
            numBanks = 1;
            int dataTypeSize = DataBuffer.getDataTypeSize(type);
            size = mppsm.getScanlineStride()*mppsm.getHeight() +
                (mppsm.getDataBitOffset() + dataTypeSize - 1)/dataTypeSize;
        } else if(sampleModel instanceof SinglePixelPackedSampleModel) {
            SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
            numBanks = 1;
            size = sppsm.getScanlineStride()*(sppsm.getHeight() - 1) +
View Full Code Here

        }

        // Choose an appropriate SampleModel.
        if ((variant == PBM_ASCII) || (variant == PBM_RAW)) {
            // Each pixel takes 1 bit, pack 8 pixels into a byte.
            sampleModel = new MultiPixelPackedSampleModel(
                              DataBuffer.TYPE_BYTE, width, height, 1);
            colorModel =
                ImageCodec.createGrayIndexColorModel(sampleModel, false);
        } else {
            int[] bandOffsets = numBands == 1 ?
View Full Code Here

        // If the data are not formatted nominally then reformat.
        if(sm.getDataType() != DataBuffer.TYPE_BYTE ||
           !(sm instanceof MultiPixelPackedSampleModel) ||
           ((MultiPixelPackedSampleModel)sm).getDataBitOffset() != 0) {
            MultiPixelPackedSampleModel mppsm =
                new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
                                                width, height, 1,
                                                (width + 7)/8, 0);
            WritableRaster raster =
                Raster.createWritableRaster(mppsm,
                                            new Point(im.getMinX(),
View Full Code Here

        // Get the image tile.
        WritableRaster tile = bi.getWritableTile(0, 0);

        // Get the SampleModel.
        MultiPixelPackedSampleModel sm =
            (MultiPixelPackedSampleModel)bi.getSampleModel();

        // Read the data.
        input.readFully(((DataBufferByte)tile.getDataBuffer()).getData(),
                   0, height*sm.getScanlineStride());

        return bi;
    }
View Full Code Here

                    Arrays.equals(csm1.getBankIndices(),
                                  csm2.getBankIndices()) &&
                    Arrays.equals(csm1.getBandOffsets(),
                                  csm2.getBandOffsets());
            } else if(sm1 instanceof MultiPixelPackedSampleModel) {
                MultiPixelPackedSampleModel mpp1 =
                    (MultiPixelPackedSampleModel)sm1;
                MultiPixelPackedSampleModel mpp2 =
                    (MultiPixelPackedSampleModel)sm2;
                return mpp1.getPixelBitStride() == mpp2.getPixelBitStride() &&
                    mpp1.getScanlineStride() == mpp2.getScanlineStride() &&
                    mpp1.getDataBitOffset() == mpp2.getDataBitOffset();
            } else if(sm1 instanceof SinglePixelPackedSampleModel) {
                SinglePixelPackedSampleModel spp1 =
                    (SinglePixelPackedSampleModel)sm1;
                SinglePixelPackedSampleModel spp2 =
                    (SinglePixelPackedSampleModel)sm2;
View Full Code Here

TOP

Related Classes of java.awt.image.MultiPixelPackedSampleModel

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.