Package java.awt.image

Examples of java.awt.image.WritableRaster


        // if bi has type ARGB and alpha is false, we have to tell the writer to not use the alpha channel:
        // this is especially needed for jpeg files where imageio seems to produce wrong jpeg files right now...
        if (bi.getType() == BufferedImage.TYPE_INT_ARGB
            && !alpha) {
            // create a new BufferedImage that uses a WritableRaster of bi, with all the bands except the alpha band:
            WritableRaster raster = bi.getRaster();
            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();
View Full Code Here


            } else {
                outname = fileName + ".jpg";
            }
            RenderedOp img = JAI.create("fileload", fileName);
            ColorModel cm = img.getColorModel();
            WritableRaster imgRaster = img.copyData();
            BufferedImage bi = new BufferedImage(cm, imgRaster, false, new Hashtable());
            ImageIO.write((RenderedImage) bi, "jpg", new File(outname));
            System.out.println("...done, " + outname);
        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

     * @param texture The texture to store the data into
     * @return A buffer containing the data
     */
    private ByteBuffer convertImageData(BufferedImage bufferedImage,Texture texture) {
        ByteBuffer imageBuffer;
        WritableRaster raster;
        BufferedImage texImage;

        int texWidth = 2;
        int texHeight = 2;

View Full Code Here

    else
    {
      final ColorModel cm = img.getColorModel();
      final int width = img.getWidth();
      final int height = img.getHeight();
      final WritableRaster raster = cm.createCompatibleWritableRaster(width, height);
      final boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
      final Hashtable properties = new Hashtable();
      final String[] keys = img.getPropertyNames();
      if (keys != null)
      {
View Full Code Here

                 * allocated for every pixel. Maybe the memory usage is
                 * optimized for that, but it goes through a call stack for
                 * every pixel to do it. Let's just cycle through the data and
                 * write the pixels directly into the raster.
                 */
                WritableRaster raster = (WritableRaster) ((BufferedImage) bitmap).getRaster();
                raster.setDataElements(0, 0, width, height, pixels);
            }

            // REPLACING bitmap with the filtered version - keep a
            // copy
            // yourself if you need the original!!! i.e. for
View Full Code Here

        int width = bi.getWidth();
        int height = bi.getHeight();
        int[][] pixels = new int[width][height];
        boolean[][] transparent = new boolean[width][height];

        WritableRaster r1 = bi.getRaster();
        int[] argb = new int[4];
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                // this is easier than bi.getRGB, but still heavy
                argb = r1.getPixel(x, y, argb);
                int a = argb[3];
                int r = argb[0];
                int g = argb[1];
                int b = argb[2];
                pixels[x][y] = (a << 24) | (r << 16) | (g << 8) | (b);

                // decide if pixel is transparent or not
                transparent[x][y] = (a < 128) ? true : false;
            }
        }

        int[] palette = Quantize.quantizeImage(pixels, colors - 1);

        byte[] r = new byte[colors];
        byte[] g = new byte[colors];
        byte[] b = new byte[colors];
        byte[] a = new byte[colors];

        // need to have full(256) size array to get rid of ugly rare erros msg
        // from GIFImageWriter. We also need the *first* entry to be
        // transparent.
        Arrays.fill(r, (byte) OMColor.clear.getRed());
        Arrays.fill(g, (byte) OMColor.clear.getGreen());
        Arrays.fill(b, (byte) OMColor.clear.getBlue());
        Arrays.fill(a, (byte) OMColor.clear.getAlpha());

        for (int i = 0; i < palette.length; i++) {
            Color c = new Color(palette[i], true);
            r[i + 1] = (byte) c.getRed();
            g[i + 1] = (byte) c.getGreen();
            b[i + 1] = (byte) c.getBlue();
            a[i + 1] = (byte) c.getAlpha();
        }

        IndexColorModel colorModel = new IndexColorModel(8, r.length, r, g, b, a);

        // create a image with the reduced colors
        BufferedImage reducedImage = new BufferedImage(width, height,
                BufferedImage.TYPE_BYTE_INDEXED, colorModel);

        // manipulate raster directly for best performance & color match
        WritableRaster raster = reducedImage.getRaster();
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                // add 1 as transparent is first
                int value = transparent[x][y] ? 0 : (pixels[x][y] + 1);
                raster.setSample(x, y, 0, value);
            }
        }

        return reducedImage;
    }
View Full Code Here

    public static BufferedImage reduce32(BufferedImage bi, int colors) {
        int width = bi.getWidth();
        int height = bi.getHeight();
        int[][] pixels = new int[width][height];

        WritableRaster r1 = bi.getRaster();
        int[] argb = new int[4];
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                // this is easier than bi.getRGB, but still heavy
                argb = r1.getPixel(x, y, argb);
                int a = argb[3];
                int r = argb[0];
                int g = argb[1];
                int b = argb[2];
                pixels[x][y] = (a << 24) | (r << 16) | (g << 8) | (b);
            }
        }

        int[] palette = Quantize32.quantizeImage(pixels, colors);
        colors = palette.length;
       
        // ImageIO (at least on Mac) does not like to *read* png images with
        // only a single color in the color index
        boolean useExtraColors = false;
        int minimumColors = 2;
        if (colors < minimumColors) {
            colors = minimumColors;
            useExtraColors = true;
        }

        byte[] r = new byte[colors];
        byte[] g = new byte[colors];
        byte[] b = new byte[colors];
        byte[] a = new byte[colors];
       
        if (useExtraColors) {
            // can not be clear as ArcGIS does not handle PNG with multiple
            // clear entries in the color index
            Arrays.fill(r, (byte) OMColor.green.getRed());
            Arrays.fill(g, (byte) OMColor.green.getGreen());
            Arrays.fill(b, (byte) OMColor.green.getBlue());
            Arrays.fill(a, (byte) OMColor.green.getAlpha());
        }

        for (int i = 0; i < palette.length; i++) {
            Color c = new Color(palette[i], true);
            r[i] = (byte) c.getRed();
            g[i] = (byte) c.getGreen();
            b[i] = (byte) c.getBlue();
            a[i] = (byte) c.getAlpha();
        }

        IndexColorModel colorModel = new IndexColorModel(8, r.length, r, g, b, a);

        // create a image with the reduced colors
        BufferedImage reducedImage = new BufferedImage(width, height,
                BufferedImage.TYPE_BYTE_INDEXED, colorModel);

        // manipulate raster directly for best performance & color match
        WritableRaster raster = reducedImage.getRaster();
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                int value = pixels[x][y];
                raster.setSample(x, y, 0, value);
            }
        }

        return reducedImage;
    }
View Full Code Here

         * allocated for every pixel. Maybe the memory usage is
         * optimized for that, but it goes through a call stack for
         * every pixel to do it. Let's just cycle through the data and
         * write the pixels directly into the raster.
         */
        WritableRaster raster = (WritableRaster) bi.getRaster();
        raster.setDataElements(0, 0, w, h, pixels);
       
        if (Debug.debugging("imagehelper")) {
            Debug.output("BufferedImageHelper.getBufferedImage(): set pixels in image...");
        }

View Full Code Here

          image = (BufferedImage)img;
      } else {
          ColorModel cm = img.getColorModel();
          int width = img.getWidth();
          int height = img.getHeight();
          WritableRaster raster = cm.createCompatibleWritableRaster(width, height);
          boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
          Hashtable<String, Object> properties = new Hashtable<String, Object>();
          String[] keys = img.getPropertyNames();
          if (keys!=null) {
              for (int i = 0; i < keys.length; i++) {
View Full Code Here

        Rectangle newRect = tileRect.intersection(getBounds());

        // file setup2

        byte data[] = new byte[byteCount];
        WritableRaster tile = null;
        try {
            stream.readFully(data, 0, byteCount);
            tile = codec.decode(this, newRect, data);
            stream.seek(save_offset);
        } catch (IOException e) {
View Full Code Here

TOP

Related Classes of java.awt.image.WritableRaster

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.