Package com.google.code.appengine.awt.image

Examples of com.google.code.appengine.awt.image.ColorModel


    public boolean canEncodeImage(ImageTypeSpecifier type) {
        boolean canEncode = true;

        int numBands = type.getSampleModel().getNumBands();

        ColorModel colorModel = type.getColorModel();

        int bitDepth = colorModel.getPixelSize() / numBands;

        if (colorModel instanceof IndexColorModel) {
            if (bitDepth != 1 && bitDepth != 2 && bitDepth != 4
                && bitDepth != 8) {
                canEncode = false;
View Full Code Here


        ColorSpace dstCS =
            (destination instanceof ColorSpace) ?
                    (ColorSpace) destination :
                    new ICC_ColorSpace((ICC_Profile) destination);
       
        ColorModel srcCM = src.getColorModel();    
        ColorModel dstCM = new ComponentColorModel(dstCS,
                srcCM.hasAlpha(),
                srcCM.isAlphaPremultiplied(),
                srcCM.getTransparency(),
                srcCM.getTransferType());
       
        return new BufferedImage(dstCM,
                dstCM.createCompatibleWritableRaster(src.getWidth(), src.getHeight()),
                dstCM.isAlphaPremultiplied(),
                null);
    }
View Full Code Here

    public final BufferedImage filter(BufferedImage src, BufferedImage dst) {
        if (dst == null && conversionSequence.length < 1) {
            throw new IllegalArgumentException(Messages.getString("awt.262")); //$NON-NLS-1$
        }

        ColorModel srcCM = src.getColorModel();
        // First handle index color model
        if (srcCM instanceof IndexColorModel) {           
            src = ((IndexColorModel) srcCM).convertToIntDiscrete(src.getRaster(), false);
        }
        ColorSpace srcCS = srcCM.getColorSpace();       
               
        BufferedImage res;
        boolean isDstIndex = false;
        if (dst != null) {
         
          if (src.getWidth() != dst.getWidth() ||
             src.getHeight() != dst.getHeight()) {
              throw new IllegalArgumentException(Messages.getString("awt.263")); //$NON-NLS-1$
          }

            if (dst.getColorModel() instanceof IndexColorModel) {
                isDstIndex = true;
                res = createCompatibleDestImage(src, null);
            } else {               
                res = dst;
            }          
        } else {
            res = createCompatibleDestImage(src, null);
        }
        ColorModel dstCM = res.getColorModel();
        ColorSpace dstCS = dstCM.getColorSpace();
       
        ICC_Profile srcPf = null, dstPf = null;
        if (srcCS instanceof ICC_ColorSpace) {
            srcPf = ((ICC_ColorSpace)srcCS).getProfile();
        }
        if (dstCS instanceof ICC_ColorSpace) {
            dstPf = ((ICC_ColorSpace)dstCS).getProfile();
        }
       
        boolean isFullICC = isICC && srcPf != null && dstPf != null;
       
        if (isFullICC) {
            ICC_Transform t =
                    tCreator.getTransform(srcPf, dstPf, (ICC_Profile[]) conversionSequence);
            cc.translateColor(t, src, res);
        } else { // Perform non-ICC transform
            Object sequence[] = tCreator.getSequence(
                    srcPf == null ? (Object) srcCS : srcPf,
                    dstPf == null ? (Object) dstCS : dstPf);           
           
            int srcW = src.getWidth();
            int srcH = src.getHeight();
            int numPixels = srcW*srcH;

            // Load all pixel data into array tmpData
            float tmpData[][] =
                new float[numPixels][tCreator.maxComponents];
            for (int row=0, dataPos=0; row<srcW; row++) {
                for (int col=0; col<srcH; col++) {
                    tmpData[dataPos] =
                        srcCM.getNormalizedComponents(
                                src.getRaster().getDataElements(row, col, null),
                                tmpData[dataPos], 0);
                    dataPos++;
                }
            }

            // Copy alpha channel if needed
            float alpha[] = null;
            int alphaIdx = srcCM.numComponents - 1;
            if (srcCM.hasAlpha() && dstCM.hasAlpha()) {
                alpha = new float[numPixels];
                for (int i=0; i<numPixels; i++) {
                    alpha[i] = tmpData[i][alphaIdx];
                }
            }
           
            // Translate colors
            applySequence(sequence, tmpData, srcCS, dstCS);

            // Copy alpha if needed
            if (dstCM.hasAlpha()) {
                alphaIdx = dstCM.numComponents - 1;
                if (alpha != null) {
                    for (int i=0; i<numPixels; i++) {
                        tmpData[i][alphaIdx] = alpha[i];
                    }                  
                } else {
                    for (int i=0; i<numPixels; i++) {
                        tmpData[i][alphaIdx] = 1f;
                    }                                      
                }
            }
           
            // Store data back to the image           
            for (int row=0, dataPos=0; row<srcW; row++) {
                for (int col=0; col<srcH; col++) {
                    res.getRaster().setDataElements(row, col,
                            dstCM.getDataElements(tmpData[dataPos++], 0 , null));
                }
            }
        }              

        if (isDstIndex) { // Convert image into indexed color
View Full Code Here

        if (src == dst){
            // awt.25A=Source equals to destination
            throw new IllegalArgumentException(Messages.getString("awt.25A")); //$NON-NLS-1$
        }

        ColorModel srcCM = src.getColorModel();
        BufferedImage finalDst = null;

        if (srcCM instanceof IndexColorModel) {
            src = ((IndexColorModel)srcCM).convertToIntDiscrete(src.getRaster(), true);
            srcCM = src.getColorModel();
        }

        if (dst == null) {
            dst = createCompatibleDestImage(src, srcCM);
        } else {
            if (!srcCM.equals(dst.getColorModel())) {
                // Treat BufferedImage.TYPE_INT_RGB and BufferedImage.TYPE_INT_ARGB as same
                if (
                        !((src.getType() == BufferedImage.TYPE_INT_RGB ||
                           src.getType() == BufferedImage.TYPE_INT_ARGB) &&
                          (dst.getType() == BufferedImage.TYPE_INT_RGB ||
View Full Code Here

            rd = rbl.createRendering(rc);
        } else {
            rd = rbl.createDefaultRendering();
        }

        ColorModel cm = rd.getColorModel();
        if(cm == null) {
            cm = ColorModel.getRGBdefault();
        }

        Raster r = rd.getData();
        int w = r.getWidth();
        int h = r.getHeight();

        for (ImageConsumer c : consumers) {
            c.setDimensions(w, h);
            c.setHints(ImageConsumer.TOPDOWNLEFTRIGHT |
                    ImageConsumer.COMPLETESCANLINES |
                    ImageConsumer.SINGLEFRAME |
                    ImageConsumer.SINGLEPASS);
        }

        int scanLine[] = new int[w];
        int pixel[] = null;

        for(int y = 0; y < h; y++){
            for(int x = 0; x < w; x++){
                pixel = r.getPixel(x, y, pixel);
                scanLine[x] = cm.getDataElement(pixel, 0);
            }

            for (ImageConsumer c : consumers) {
                c.setPixels(0, y, w, 1, cm, scanLine, 0, w);
            }
View Full Code Here

        return dst;
    }

    public final BufferedImage filter(BufferedImage src, BufferedImage dst) {
        ColorModel srcCM = src.getColorModel();

        if (srcCM instanceof IndexColorModel) {
            // awt.220=Source should not have IndexColorModel
            throw new IllegalArgumentException(Messages.getString("awt.220")); //$NON-NLS-1$
        }

        // Check if the number of scaling factors matches the number of bands
        int nComponents = srcCM.getNumComponents();
        int nLUTComponents = lut.getNumComponents();
        boolean skipAlpha;
        if (srcCM.hasAlpha()) {
            if (nLUTComponents == 1 || nLUTComponents == nComponents-1) {
                skipAlpha = true;
            } else if (nLUTComponents == nComponents) {
                skipAlpha = false;
            } else {
                // awt.229=Number of components in the LUT does not match the number of bands
                throw new IllegalArgumentException(Messages.getString("awt.229")); //$NON-NLS-1$
            }
        } else if (nLUTComponents == 1 || nLUTComponents == nComponents) {
            skipAlpha = false;
        } else {
            // awt.229=Number of components in the LUT does not match the number of bands
            throw new IllegalArgumentException(Messages.getString("awt.229")); //$NON-NLS-1$
        }

        BufferedImage finalDst = null;
        if (dst == null) {
            dst = createCompatibleDestImage(src, null);
        } else {
            if (src.getWidth() != dst.getWidth()){
                throw new IllegalArgumentException(Messages.getString("awt.291")); //$NON-NLS-1$
            }

            if (src.getHeight() != dst.getHeight()){
                throw new IllegalArgumentException(Messages.getString("awt.292")); //$NON-NLS-1$
            }

            if (!srcCM.equals(dst.getColorModel())) {
                // Treat BufferedImage.TYPE_INT_RGB and
                // BufferedImage.TYPE_INT_ARGB as same
                if (!((src.getType() == BufferedImage.TYPE_INT_RGB || src
                        .getType() == BufferedImage.TYPE_INT_ARGB) && (dst
                        .getType() == BufferedImage.TYPE_INT_RGB || dst
View Full Code Here

                    destCM.isAlphaPremultiplied(),
                    null
            );
        }

        ColorModel cm = src.getColorModel();

        // Interpolation other than NN doesn't make any sense for index color
        if (iType != TYPE_NEAREST_NEIGHBOR && cm instanceof IndexColorModel) {
            return new BufferedImage((int)dstWidth, (int)dstHeight, BufferedImage.TYPE_INT_ARGB);
        }

        // OK, we can get source color model
        return new BufferedImage(cm,
                src.getRaster().createCompatibleWritableRaster((int)dstWidth, (int)dstHeight),
                cm.isAlphaPremultiplied(),
                null
        );
    }
View Full Code Here

        if (src == dst) {
            // awt.252=Source can't be same as the destination
            throw new IllegalArgumentException(Messages.getString("awt.252")); //$NON-NLS-1$
        }

        ColorModel srcCM = src.getColorModel();
        BufferedImage finalDst = null;

        if (
                srcCM instanceof IndexColorModel &&
                (iType != TYPE_NEAREST_NEIGHBOR || srcCM.getPixelSize() % 8 != 0)
        ) {
            src = ((IndexColorModel)srcCM).convertToIntDiscrete(src.getRaster(), true);
            srcCM = src.getColorModel();
        }

        if (dst == null) {
            dst = createCompatibleDestImage(src, srcCM);
        } else {
            if (!srcCM.equals(dst.getColorModel())) {
                // Treat BufferedImage.TYPE_INT_RGB and BufferedImage.TYPE_INT_ARGB as same
                if (
                   !(
                     (src.getType() == BufferedImage.TYPE_INT_RGB ||
                      src.getType() == BufferedImage.TYPE_INT_ARGB) &&
View Full Code Here

        if (!isCompatibleRaster(raster)) {
            // awt.265=The raster argument is not compatible with this IndexColorModel
            throw new IllegalArgumentException(Messages.getString("awt.265")); //$NON-NLS-1$
        }

        ColorModel model;
        if (forceARGB || transparency == Transparency.TRANSLUCENT) {
            model = ColorModel.getRGBdefault();
        } else if (transparency == Transparency.BITMASK) {
            model = new DirectColorModel(25, 0x00ff0000, 0x0000ff00,
                    0x000000ff, 0x01000000);
        } else {
            model = new DirectColorModel(24, 0x00ff0000, 0x0000ff00, 0x000000ff);
        }

        int w = raster.getWidth();
        int h = raster.getHeight();

        WritableRaster distRaster = model.createCompatibleWritableRaster(w, h);

        int minX = raster.getMinX();
        int minY = raster.getMinY();

        Object obj = null;
View Full Code Here

    public void imageComplete(int status) {
        if (status == STATICIMAGEDONE || status == SINGLEFRAMEDONE) {
            BufferedImage bim = new BufferedImage(cm, raster, cm.isAlphaPremultiplied, null);
            bim = op.filter(bim, null);
            DataBuffer dstDb = bim.getRaster().getDataBuffer();
            ColorModel dstCm = bim.getColorModel();
            int dstW = bim.getWidth();
            int dstH = bim.getHeight();

            consumer.setDimensions(dstW, dstH);
View Full Code Here

TOP

Related Classes of com.google.code.appengine.awt.image.ColorModel

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.