Package java.awt.image

Examples of java.awt.image.ComponentColorModel


                    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


     * rgb+alpha <code>ColorModel</code> is returned.
     */
    public static ColorModel createComponentColorModel(SampleModel sm) {
        int type = sm.getDataType();
        int bands = sm.getNumBands();
        ComponentColorModel cm = null;

        if (type == DataBuffer.TYPE_BYTE) {
            switch (bands) {
            case 1:
                cm = colorModelGray8;
View Full Code Here

                   ColorSpace cp) {
  if (cp == null)
      return createComponentColorModel(sm);
        int type = sm.getDataType();
  int bands = sm.getNumBands();
  ComponentColorModel cm = null;

  int[] bits = null;
        int transferType = -1;
        boolean hasAlpha = (bands % 2 == 0);
  if (cp instanceof SimpleCMYKColorSpace)
      hasAlpha = false;
        int transparency = hasAlpha ? Transparency.TRANSLUCENT
                                        : Transparency.OPAQUE;
        if (type == DataBuffer.TYPE_BYTE) {
            transferType = DataBuffer.TYPE_BYTE;
            switch (bands) {
                case 1:
        bits = GrayBits8;
        break;
                case 2:
        bits = GrayAlphaBits8;
        break;
                case 3:
        bits = RGBBits8;
        break;
                case 4:
        bits = RGBABits8;
        break;
            }
        } else if (type == DataBuffer.TYPE_USHORT) {
            transferType = DataBuffer.TYPE_USHORT;
            switch (bands) {
                case 1:
        bits = GrayBits16;
        break;
                case 2:
        bits = GrayAlphaBits16;
        break;
                case 3:
        bits = RGBBits16;
        break;
                case 4:
        bits = RGBABits16;
        break;
            }
        } else if (type == DataBuffer.TYPE_INT) {
            transferType = DataBuffer.TYPE_INT;
            switch (bands) {
                case 1:
        bits = GrayBits32;
        break;
                case 2:
        bits = GrayAlphaBits32;
        break;
                case 3:
        bits = RGBBits32;
        break;
                case 4:
        bits = RGBABits32;
        break;
            }
        }

        if (type == DataBuffer.TYPE_FLOAT &&
                   bands >= 1 && bands <= 4) {
            cm = new FloatDoubleColorModel(cp, hasAlpha, false,
                                           transparency,
                                           DataBuffer.TYPE_FLOAT);
        } else {
            cm = new ComponentColorModel(cp, bits, hasAlpha,
                                         false, transparency, transferType);
        }

  return cm;
    }
View Full Code Here

        for(int i = 0; i < numBands; i++) {
            bits[i] = dtSize;
        }
        int transparency = hasAlpha ?
            Transparency.TRANSLUCENT : Transparency.OPAQUE;
        ColorModel cm = new ComponentColorModel(cs, bits,
                                                hasAlpha, isAlphaPremultiplied,
                                                transparency,
                                                DataBuffer.TYPE_BYTE);
        il.setColorModel(cm);
View Full Code Here

            bits[i] = dataTypeSize;
        }

        switch (dataType) {
        case DataBuffer.TYPE_BYTE:
            return new ComponentColorModel(colorSpace,
                                           bits,
                                           useAlpha,
                                           premultiplied,
                                           transparency,
                                           dataType);
        case DataBuffer.TYPE_USHORT:
            return new ComponentColorModel(colorSpace,
                                           bits,
                                           useAlpha,
                                           premultiplied,
                                           transparency,
                                           dataType);
        /// case DataBuffer.TYPE_SHORT:
            /// return new ShortComponentColorModel(colorSpace,
                                                /// bits,
                                                /// useAlpha,
                                                /// premultiplied,
                                                /// transparency);
        case DataBuffer.TYPE_INT:
            return new ComponentColorModel(colorSpace,
                                           bits,
                                           useAlpha,
                                           premultiplied,
                                           transparency,
                                           dataType);
View Full Code Here

  } else {
      cm = dstParam.getColorModel();
      sm = dstParam.getSampleModel();
  }

  cm  = new ComponentColorModel(rgbColorSpace,
              cm.getComponentSize(),
              cm.hasAlpha() ,
              cm.isAlphaPremultiplied(),
              cm.getTransparency(),
              sm.getDataType())
View Full Code Here

     *
     * @param src The image to convert to an alpha channel (mask image)
     */
    public FilterAsAlphaRed(CachableRed src) {
        super(new Any2LumRed(src),src.getBounds(),
              new ComponentColorModel
                  (ColorSpace.getInstance(ColorSpace.CS_GRAY),
                   new int [] {8}, false, false,
                   Transparency.OPAQUE,
                   DataBuffer.TYPE_BYTE),
              new PixelInterleavedSampleModel
View Full Code Here

                    (wr.getMinX()-wr.getSampleModelTranslateX(),
                     wr.getMinY()-wr.getSampleModelTranslateY(),
                     wr.getWidth(), wr.getHeight(),
                     0, 0, null);
               
                ColorModel cmna = new ComponentColorModel
                    (ColorSpace.getInstance(ColorSpace.CS_GRAY),
                     new int [] {8}, false, false,
                     Transparency.OPAQUE,
                     DataBuffer.TYPE_BYTE);
View Full Code Here

     */
    protected static ColorModel fixColorModel(CachableRed src) {
        ColorModel  cm = src.getColorModel();
        if (cm != null) {
            if (cm.hasAlpha())
                return new ComponentColorModel
                    (ColorSpace.getInstance(ColorSpace.CS_GRAY),
                     new int [] {8,8}, true,
                     cm.isAlphaPremultiplied(),
                     Transparency.TRANSLUCENT,
                     DataBuffer.TYPE_BYTE);

            return new ComponentColorModel
                (ColorSpace.getInstance(ColorSpace.CS_GRAY),
                 new int [] {8}, false, false,
                 Transparency.OPAQUE,
                 DataBuffer.TYPE_BYTE);
        }
        else {
            // No ColorModel so try to make some intelligent
            // decisions based just on the number of bands...
            // 1 bands -> lum
            // 2 bands -> lum (Band 0) & alpha (Band 1)
            // >2 bands -> lum (Band 0) - No color conversion...
            SampleModel sm = src.getSampleModel();

            if (sm.getNumBands() == 2)
                return new ComponentColorModel
                    (ColorSpace.getInstance(ColorSpace.CS_GRAY),
                     new int [] {8,8}, true,
                     true, Transparency.TRANSLUCENT,
                     DataBuffer.TYPE_BYTE);

            return new ComponentColorModel
                (ColorSpace.getInstance(ColorSpace.CS_GRAY),
                 new int [] {8}, false, false,
                 Transparency.OPAQUE,
                 DataBuffer.TYPE_BYTE);
        }
View Full Code Here

     * rgb+alpha <code>ColorModel</code> is returned.
     */
    public static ColorModel createComponentColorModel(SampleModel sm) {
        int type = sm.getDataType();
        int bands = sm.getNumBands();
        ComponentColorModel cm = null;

        if (type == DataBuffer.TYPE_BYTE) {
            switch (bands) {
            case 1:
                cm = colorModelGray8;
View Full Code Here

TOP

Related Classes of java.awt.image.ComponentColorModel

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.