Package java.awt.image

Examples of java.awt.image.DirectColorModel


          int off,
          int scansize) {
        if (model instanceof DirectColorModel) {
          // see if we can just directly copy the data because its
          // already laid out the way we want
          DirectColorModel dcm = (DirectColorModel) model;
          if (dcm.getBlueMask()  == 0x000000ff &
            dcm.getGreenMask() == 0x0000ff00 &
            dcm.getRedMask()   == 0x00ff0000) {
            int[] nData = this.rgb.getData();
            for (int i=0; i<h; i++) {
              System.arraycopy(
                  pixels,
                  i*scansize + off,
View Full Code Here


            WritableRaster newRaster = raster.createWritableChild(
                0, 0, raster.getWidth(), raster.getHeight(),
                0, 0, new int[] {0, 1, 2 }
            );
            // create a ColorModel that represents the one of the ARGB except the alpha channel:
            DirectColorModel cm = (DirectColorModel) bi.getColorModel();
            DirectColorModel newCM = new DirectColorModel(
                cm.getPixelSize(), cm.getRedMask(),
                cm.getGreenMask(), cm.getBlueMask());
            // now create the new buffer that is used ot write the image:
            BufferedImage rgbBuffer = new BufferedImage(newCM,
                newRaster, false, null);
View Full Code Here

          int off,
          int scansize) {
        if (model instanceof DirectColorModel) {
          // see if we can just directly copy the data because its
          // already laid out the way we want
          DirectColorModel dcm = (DirectColorModel) model;
          if (dcm.getBlueMask()  == 0x000000ff &
            dcm.getGreenMask() == 0x0000ff00 &
            dcm.getRedMask()   == 0x00ff0000) {
            int[] nData = this.rgb.getData();
            for (int i=0; i<h; i++) {
              System.arraycopy(
                  pixels,
                  i*scansize + off,
View Full Code Here

        else if (bitsPerPixel == 8)
        {
          final DataBufferByte db = new DataBufferByte(new byte[][] {bytes}, bytes.length);
          final SampleModel sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_BYTE, w, h, lineStride, new int[] {redMask, greenMask, blueMask});
          final WritableRaster r = Raster.createWritableRaster(sm, db, new Point(0, 0));
                  final ColorModel colorModel = new DirectColorModel(bitsPerPixel, redMask, greenMask, blueMask);
                  final BufferedImage bi = new BufferedImage(colorModel, r, false, null);
          return bi;
        }
        else
        {
          final BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
          final int [] pixels = new int[w * h];
          int pixelIndex = 0;
          int lineOffset = 0;
          if (flipped)
            lineOffset = (h - 1) * lineStride;
         
          for (int y = 0; y < h; ++y)
          {
            int off = lineOffset;
            for (int x = 0; x < w; ++x)
            {
              final byte r = bytes[off + redMask - 1];
              final byte g = bytes[off + greenMask - 1];
              final byte b = bytes[off + blueMask - 1];
              int pixel = 0;
              pixel += r & 0xff// red
              pixel *= 256;
              pixel += g & 0xff; // green
              pixel *= 256;
              pixel += b & 0xff// blue
              pixels[pixelIndex++] = pixel;
              off += pixelStride;
            }
            if (flipped)
              lineOffset -= lineStride;
            else
              lineOffset += lineStride;
          }
         
          bi.setRGB(0,0,w,h,pixels,0,w);
          return bi;
        }

       
      }else if (dataType == Format.shortArray) {
        final short[] shorts = (short[]) buffer.getData();
        if (bitsPerPixel == 16)
        {
          final DataBufferUShort db = new DataBufferUShort(new short[][] {shorts}, shorts.length);
          final SampleModel sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_USHORT, w, h, lineStride, new int[] {redMask, greenMask, blueMask});
          final WritableRaster r = Raster.createWritableRaster(sm, db, new Point(0, 0));
                  final ColorModel colorModel = new DirectColorModel(bitsPerPixel, redMask, greenMask, blueMask);
                  final BufferedImage bi = new BufferedImage(colorModel, r, false, null);
          return bi;
        }else{
          throw new UnsupportedOperationException()// TODO
        }
      }
      else if (dataType == Format.intArray)
      {
//        if (true)
        {
          // optimized, don't copy data or iterate through pixels:
          final int[] bytes = (int[]) buffer.getData();
          final DataBufferInt db = new DataBufferInt(new int[][] {bytes}, bytes.length);
          final SinglePixelPackedSampleModel sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT, w, h, new int[] {redMask, greenMask, blueMask});
          final WritableRaster r = Raster.createWritableRaster(sm, db, new Point(0, 0));
         
                  final ColorModel colorModel = new DirectColorModel(24,
                            redMask,   // Red
                            greenMask,  // Green
                            blueMask,   // Blue
                            0x0         // Alpha
                            );
View Full Code Here

          throw new IllegalArgumentException("Unsupported buffered image type: " + bufferedImageType);
      }
      else if (bi.getColorModel() instanceof DirectColorModel)
      {
        // TODO: untested
        final DirectColorModel directColorModel = (DirectColorModel) bi.getColorModel();
        if (dataBuffer instanceof DataBufferInt)
        {
          bitsPerPixel = 32
          red = directColorModel.getRedMask();
          green = directColorModel.getGreenMask();
          blue = directColorModel.getBlueMask();
        }
        else
          throw new IllegalArgumentException("Unsupported buffered image type: " + bufferedImageType);
      }
      else
View Full Code Here

            int[] preds = new int[sofnSegment.numberOfComponents];
            ColorModel colorModel;
            WritableRaster raster;
            if (sofnSegment.numberOfComponents == 3)
            {
                colorModel = new DirectColorModel(24,
                        0x00ff0000, 0x0000ff00, 0x000000ff);
                raster = WritableRaster.createPackedRaster(DataBuffer.TYPE_INT,
                        sofnSegment.width, sofnSegment.height,
                        new int[]{0x00ff0000,0x0000ff00,0x000000ff}, null);
            }
            else if (sofnSegment.numberOfComponents == 1)
            {
                colorModel = new DirectColorModel(24,
                        0x00ff0000, 0x0000ff00, 0x000000ff);
                raster = WritableRaster.createPackedRaster(DataBuffer.TYPE_INT,
                        sofnSegment.width, sofnSegment.height,
                        new int[]{0x00ff0000,0x0000ff00,0x000000ff}, null);
                // FIXME: why do images come out too bright with CS_GRAY?
View Full Code Here

            else
                return new ComponentColorModel(cs, ccm.hasAlpha(), ccm
                        .isAlphaPremultiplied(), ccm.getTransparency(), ccm
                        .getTransferType());
        } else if (old_cm instanceof DirectColorModel) {
            DirectColorModel dcm = (DirectColorModel) old_cm;

            int old_mask = dcm.getRedMask() | dcm.getGreenMask()
                    | dcm.getBlueMask() | dcm.getAlphaMask();

            int old_bits = count_bits_in_mask(old_mask);

            return new DirectColorModel(cs, old_bits, dcm.getRedMask(), dcm
                    .getGreenMask(), dcm.getBlueMask(), dcm.getAlphaMask(), dcm
                    .isAlphaPremultiplied(), dcm.getTransferType());
        }
        // else if (old_cm instanceof PackedColorModel)
        // {
        // PackedColorModel pcm = (PackedColorModel) old_cm;
        //
View Full Code Here

                    xpmHeader.width, xpmHeader.height, 1, null);
            bpp = 16;
        }
        else
        {
            colorModel = new DirectColorModel(32, 0x00ff0000, 0x0000ff00,
                    0x000000ff, 0xff000000);
            raster = WritableRaster.createPackedRaster(DataBuffer.TYPE_INT,
                    xpmHeader.width, xpmHeader.height,
                    new int[]{0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000}, null);
            bpp = 32;
View Full Code Here

    height = component.getHeight();
    size = width * height;
    pixels = new int[size];
    zBuffer = new float[size];
    image = Toolkit.getDefaultToolkit().createImage(this);
    colormodel = new DirectColorModel(32, 0x000000FF, 0x0000FF00,
        0x00FF0000, 0xFF000000);
    consumer = null;
    lastColor = new N3ColorRGBA(1, 1, 1);
    lastUV = new N3TexCoord2D(0, 0);
    lastVertex = null;
View Full Code Here

            // Create a SampleModel to get the transferType. This is
            // absurd but is the only apparent way to retrieve this value.
            SampleModel sm = cm.createCompatibleSampleModel(1, 1);
            out.writeInt(sm.getTransferType());
        } else if(colorModel instanceof DirectColorModel) {
            DirectColorModel cm = (DirectColorModel)colorModel;
            out.writeInt(COLORMODEL_DIRECT);
            boolean csSerialized =
                serializeColorSpace(cm.getColorSpace(), out);
            if(!csSerialized) {
                out.writeBoolean(cm.hasAlpha());
            }
            out.writeInt(cm.getPixelSize());
            out.writeInt(cm.getRedMask());
            out.writeInt(cm.getGreenMask());
            out.writeInt(cm.getBlueMask());
            if(csSerialized || cm.hasAlpha()) {
                out.writeInt(cm.getAlphaMask());
            }
            if(csSerialized) {
                out.writeBoolean(cm.isAlphaPremultiplied());
                // Create a SampleModel to get the transferType. This is
                // absurd but is the only apparent way to retrieve this
                // value.
                SampleModel sm = cm.createCompatibleSampleModel(1, 1);
                out.writeInt(sm.getTransferType());
            }
        } else {
            throw new RuntimeException(JaiI18N.getString("ColorModelState0"));
        }
View Full Code Here

TOP

Related Classes of java.awt.image.DirectColorModel

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.