Search in sources :

Example 1 with WritableRaster

use of java.awt.image.WritableRaster in project Smack by igniterealtime.

the class WholeImageFilter method filter.

@Override
public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    int width = src.getWidth();
    int height = src.getHeight();
    int type = src.getType();
    WritableRaster srcRaster = src.getRaster();
    originalSpace = new Rectangle(0, 0, width, height);
    transformedSpace = new Rectangle(0, 0, width, height);
    transformSpace(transformedSpace);
    if (dst == null) {
        ColorModel dstCM = src.getColorModel();
        dst = new BufferedImage(dstCM, dstCM.createCompatibleWritableRaster(transformedSpace.width, transformedSpace.height), dstCM.isAlphaPremultiplied(), null);
    }
    WritableRaster dstRaster = dst.getRaster();
    int[] inPixels = getRGB(src, 0, 0, width, height, null);
    inPixels = filterPixels(width, height, inPixels, transformedSpace);
    setRGB(dst, 0, 0, transformedSpace.width, transformedSpace.height, inPixels);
    return dst;
}
Also used : WritableRaster(java.awt.image.WritableRaster) ColorModel(java.awt.image.ColorModel) Rectangle(java.awt.Rectangle) BufferedImage(java.awt.image.BufferedImage)

Example 2 with WritableRaster

use of java.awt.image.WritableRaster in project AozoraEpub3 by hmdev.

the class ImageUtils method writeImage.

/** 大きすぎる画像は縮小して出力
	 * @param is 画像の入力ストリーム srcImageがあれば利用しないのでnull
	 * @param srcImage 読み込み済の場合は画像をこちらに設定 nullならisから読み込む
	 * @param zos 出力先Zipストリーム
	 * @param imageInfo 画像情報
	 * @param jpegQuality jpeg画質 (低画質 0.0-1.0 高画質)
	 * @param maxImagePixels 縮小する画素数
	 * @param maxImageW 縮小する画像幅
	 * @param maxImageH 縮小する画像高さ
	 * @param dispW 画面幅 余白除去後の縦横比補正用
	 * @param dispH 画面高さ 余白除去後の縦横比補正用
	 * @param autoMarginLimitH 余白除去 最大%
	 * @param autoMarginLimitV 余白除去 最大%
	 * @param autoMarginWhiteLevel 白画素として判別する白さ 100が白
	 * @param autoMarginPadding 余白除去後に追加するマージン */
public static void writeImage(InputStream is, BufferedImage srcImage, ZipArchiveOutputStream zos, ImageInfo imageInfo, float jpegQuality, LookupOp gammaOp, int maxImagePixels, int maxImageW, int maxImageH, int dispW, int dispH, int autoMarginLimitH, int autoMarginLimitV, int autoMarginWhiteLevel, float autoMarginPadding, int autoMarginNombre, float nombreSize) throws IOException {
    try {
        String ext = imageInfo.getExt();
        int imgW = imageInfo.getWidth();
        int imgH = imageInfo.getHeight();
        int w = imgW;
        int h = imgH;
        imageInfo.setOutWidth(imgW);
        imageInfo.setOutHeight(imgH);
        //余白チェック時に読み込んだ画像のバッファ
        byte[] imgBuf = null;
        //回転とコントラスト調整なら読み込んでおく
        if (srcImage == null && (imageInfo.rotateAngle != 0 || gammaOp != null))
            srcImage = readImage(ext, is);
        int[] margin = null;
        if (autoMarginLimitH > 0 || autoMarginLimitV > 0) {
            //1%
            int startPixel = (int) (w * 0.01);
            //3%
            int ignoreEdge = (int) (w * 0.03);
            //1%
            int dustSize = (int) (w * 0.01);
            //画像がなければ読み込み 変更なしの時にそのまま出力できるように一旦バッファに読み込む
            if (srcImage == null) {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                IOUtils.copy(is, baos);
                imgBuf = baos.toByteArray();
                ByteArrayInputStream bais = new ByteArrayInputStream(imgBuf);
                try {
                    srcImage = readImage(ext, bais);
                } finally {
                    bais.close();
                }
            }
            margin = getPlainMargin(srcImage, autoMarginLimitH / 100f, autoMarginLimitV / 100f, autoMarginWhiteLevel / 100f, autoMarginPadding / 100f, startPixel, ignoreEdge, dustSize, autoMarginNombre, nombreSize);
            if (margin[0] == 0 && margin[1] == 0 && margin[2] == 0 && margin[3] == 0)
                margin = null;
            if (margin != null) {
                //元画像が幅か高さかチェック
                int mw = w - margin[0] - margin[2];
                int mh = h - margin[1] - margin[3];
                double dWH = dispW / (double) dispH;
                double mWH = mw / (double) mh;
                //縦横比で画面の横か縦に合わせる方向が変わらないようにマージンを調整する
                if (w / (double) h < dWH) {
                    //元が縦
                    if (mWH > dWH && mw > dispW) {
                        //余白除去で横にはみ出す
                        mh = (int) (mw / dWH);
                        //下マージンを伸ばす
                        margin[3] = h - margin[1] - mh;
                        if (margin[3] < 0) {
                            margin[3] = 0;
                            margin[1] = h - mh;
                        }
                    }
                } else {
                    //元が横
                    if (mWH < dWH && mh > dispH) {
                        //余白除去で縦にはみ出す
                        mw = (int) (mh * dWH);
                        double mLR = margin[0] + margin[2];
                        margin[0] = (int) ((w - mw) * margin[0] / mLR);
                        margin[2] = (int) ((w - mw) * margin[2] / mLR);
                    }
                }
                w = mw;
                h = mh;
            }
        }
        //倍率取得
        double scale = 1;
        //最大画素数指定
        if (maxImagePixels >= 10000)
            scale = Math.sqrt((double) maxImagePixels / (w * h));
        //最大幅指定
        if (maxImageW > 0)
            scale = Math.min(scale, (double) maxImageW / w);
        //最大高さ指定
        if (maxImageH > 0)
            scale = Math.min(scale, (double) maxImageH / h);
        if (scale >= 1 && (gammaOp == null || srcImage.getType() == BufferedImage.TYPE_INT_RGB)) {
            if (srcImage == null) {
                //変更なしならそのままファイル出力
                IOUtils.copy(is, zos);
            } else {
                if (margin == null && imgBuf != null && imageInfo.rotateAngle == 0) {
                    //余白除去が無く画像も編集されていなければバッファからそのまま出力
                    ByteArrayInputStream bais = new ByteArrayInputStream(imgBuf);
                    try {
                        IOUtils.copy(bais, zos);
                    } finally {
                        bais.close();
                    }
                } else {
                    //編集済の画像なら同じ画像形式で書き出し 余白があれば切り取る
                    if (imageInfo.rotateAngle != 0) {
                        BufferedImage outImage = new BufferedImage(h, w, srcImage.getType());
                        Graphics2D g = outImage.createGraphics();
                        try {
                            g.setColor(Color.WHITE);
                            g.fillRect(0, 0, h, w);
                            g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
                            g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
                            int x = 0;
                            int y = 0;
                            AffineTransform at;
                            if (imageInfo.rotateAngle == 90) {
                                at = AffineTransform.getQuadrantRotateInstance(1, 0, 0);
                                at.translate(0, -imgH);
                                if (margin != null) {
                                    x = -margin[3];
                                    y = -margin[0];
                                }
                            } else {
                                at = AffineTransform.getQuadrantRotateInstance(-1, 0, 0);
                                at.translate(-imgW, 0);
                                if (margin != null) {
                                    x = -margin[1];
                                    y = -margin[2];
                                }
                            }
                            AffineTransformOp ato = new AffineTransformOp(at, AffineTransformOp.TYPE_BICUBIC);
                            g.drawImage(srcImage, ato, x, y);
                        } finally {
                            g.dispose();
                        }
                        //入れ替え
                        srcImage = outImage;
                    } else if (margin != null)
                        srcImage = srcImage.getSubimage(margin[0], margin[1], srcImage.getWidth() - margin[2] - margin[0], srcImage.getHeight() - margin[3] - margin[1]);
                    if (gammaOp != null) {
                        BufferedImage filterdImage = new BufferedImage(srcImage.getWidth(), srcImage.getHeight(), BufferedImage.TYPE_INT_RGB);
                        srcImage = gammaOp.filter(srcImage, filterdImage);
                        srcImage = filterdImage;
                    }
                    _writeImage(zos, srcImage, ext, jpegQuality);
                    imageInfo.setOutWidth(srcImage.getWidth());
                    imageInfo.setOutHeight(srcImage.getHeight());
                    if (imageInfo.rotateAngle != 0)
                        LogAppender.println("画像回転" + ": " + imageInfo.getOutFileName() + " (" + h + "," + w + ")");
                }
            }
        } else {
            //縮小
            int scaledW = (int) (w * scale + 0.5);
            int scaledH = (int) (h * scale + 0.5);
            if (imageInfo.rotateAngle != 0) {
                scaledW = (int) (h * scale + 0.5);
                scaledH = (int) (w * scale + 0.5);
            }
            //画像がなければ読み込み
            if (srcImage == null)
                srcImage = readImage(ext, is);
            int imageType = srcImage.getType();
            BufferedImage outImage;
            ColorModel colorModel;
            WritableRaster raster;
            switch(gammaOp == null ? imageType : BufferedImage.TYPE_INT_RGB) {
                case BufferedImage.TYPE_BYTE_BINARY:
                    colorModel = srcImage.getColorModel();
                    colorModel = getGray16ColorModel();
                    raster = colorModel.createCompatibleWritableRaster(scaledW, scaledH);
                    outImage = new BufferedImage(colorModel, raster, true, null);
                    break;
                case BufferedImage.TYPE_BYTE_INDEXED:
                    colorModel = srcImage.getColorModel();
                    raster = colorModel.createCompatibleWritableRaster(scaledW, scaledH);
                    outImage = new BufferedImage(colorModel, raster, true, null);
                    break;
                /*case BufferedImage.TYPE_BYTE_GRAY:
				//PngEncoderのGRAYが薄くなるのでindexにする
				colorModel = srcImage.getColorModel();
				if (colorModel.getPixelSize() <= 4) colorModel = getGray16ColorModel();
				else colorModel = getGray256ColorModel();
				raster = colorModel.createCompatibleWritableRaster(scaledW, scaledH);
				outImage = new BufferedImage(colorModel, raster, true, null);
				break;*/
                case BufferedImage.TYPE_BYTE_GRAY:
                    outImage = new BufferedImage(scaledW, scaledH, BufferedImage.TYPE_BYTE_GRAY);
                    break;
                case BufferedImage.TYPE_USHORT_GRAY:
                    outImage = new BufferedImage(scaledW, scaledH, BufferedImage.TYPE_USHORT_GRAY);
                    break;
                default:
                    outImage = new BufferedImage(scaledW, scaledH, BufferedImage.TYPE_INT_RGB);
            }
            Graphics2D g = outImage.createGraphics();
            try {
                if (imageType == BufferedImage.TYPE_BYTE_BINARY && imageType == BufferedImage.TYPE_BYTE_INDEXED && imageType == BufferedImage.TYPE_INT_ARGB) {
                    g.setColor(Color.WHITE);
                    g.fillRect(0, 0, scaledW, scaledH);
                }
                g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
                g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
                AffineTransform at = AffineTransform.getScaleInstance(scale, scale);
                int x = 0;
                int y = 0;
                if (imageInfo.rotateAngle == 0) {
                    if (margin != null) {
                        x = (int) (-margin[0] * scale + 0.5);
                        y = (int) (-margin[1] * scale + 0.5);
                    }
                } else if (imageInfo.rotateAngle == 90) {
                    at.rotate(Math.toRadians(imageInfo.rotateAngle), 0, 0);
                    at.translate(0, -imgH);
                    if (margin != null) {
                        x = (int) (-margin[3] * scale + 0.5);
                        y = (int) (-margin[0] * scale + 0.5);
                    }
                } else {
                    at.quadrantRotate(-1, 0, 0);
                    at.translate(-imgW, 0);
                    if (margin != null) {
                        x = (int) (-margin[1] * scale + 0.5);
                        y = (int) (-margin[2] * scale + 0.5);
                    }
                }
                AffineTransformOp ato = new AffineTransformOp(at, AffineTransformOp.TYPE_BICUBIC);
                g.drawImage(srcImage, ato, x, y);
            } finally {
                g.dispose();
            }
            //コントラスト調整
            if (gammaOp != null) {
                BufferedImage filterdImage = new BufferedImage(outImage.getWidth(), outImage.getHeight(), BufferedImage.TYPE_INT_RGB);
                outImage = gammaOp.filter(outImage, filterdImage);
                outImage = filterdImage;
                filterdImage = null;
                //インデックス化
                switch(imageType) {
                    case BufferedImage.TYPE_BYTE_BINARY:
                        colorModel = srcImage.getColorModel();
                        colorModel = getGray16ColorModel();
                        raster = colorModel.createCompatibleWritableRaster(scaledW, scaledH);
                        filterdImage = new BufferedImage(colorModel, raster, true, null);
                        break;
                    case BufferedImage.TYPE_BYTE_INDEXED:
                        colorModel = srcImage.getColorModel();
                        raster = colorModel.createCompatibleWritableRaster(scaledW, scaledH);
                        filterdImage = new BufferedImage(colorModel, raster, true, null);
                        break;
                    case BufferedImage.TYPE_BYTE_GRAY:
                        filterdImage = new BufferedImage(scaledW, scaledH, BufferedImage.TYPE_BYTE_GRAY);
                        break;
                    case BufferedImage.TYPE_USHORT_GRAY:
                        filterdImage = new BufferedImage(scaledW, scaledH, BufferedImage.TYPE_USHORT_GRAY);
                        break;
                }
                if (filterdImage != null) {
                    g = filterdImage.createGraphics();
                    try {
                        g.drawImage(outImage, 0, 0, null);
                    } finally {
                        g.dispose();
                    }
                    outImage = filterdImage;
                }
            }
            _writeImage(zos, outImage, ext, jpegQuality);
            imageInfo.setOutWidth(outImage.getWidth());
            imageInfo.setOutHeight(outImage.getHeight());
            if (scale < 1) {
                LogAppender.append("画像縮小");
                if (imageInfo.rotateAngle != 0)
                    LogAppender.append("回転");
                LogAppender.println(": " + imageInfo.getOutFileName() + " (" + w + "," + h + ")→(" + scaledW + "," + scaledH + ")");
            }
            zos.flush();
        }
    } catch (Exception e) {
        LogAppender.println("画像読み込みエラー: " + imageInfo.getOutFileName());
        e.printStackTrace();
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedImage(java.awt.image.BufferedImage) IOException(java.io.IOException) Graphics2D(java.awt.Graphics2D) AffineTransformOp(java.awt.image.AffineTransformOp) ByteArrayInputStream(java.io.ByteArrayInputStream) IndexColorModel(java.awt.image.IndexColorModel) ColorModel(java.awt.image.ColorModel) WritableRaster(java.awt.image.WritableRaster) AffineTransform(java.awt.geom.AffineTransform)

Example 3 with WritableRaster

use of java.awt.image.WritableRaster in project processing by processing.

the class Mode method makeGradient.

public Image makeGradient(String attribute, int wide, int high) {
    int top = getColor(attribute + ".gradient.top").getRGB();
    int bot = getColor(attribute + ".gradient.bottom").getRGB();
    //    float r1 = (top >> 16) & 0xff;
    //    float g1 = (top >> 8) & 0xff;
    //    float b1 = top & 0xff;
    //    float r2 = (bot >> 16) & 0xff;
    //    float g2 = (bot >> 8) & 0xff;
    //    float b2 = bot & 0xff;
    BufferedImage outgoing = new BufferedImage(wide, high, BufferedImage.TYPE_INT_RGB);
    int[] row = new int[wide];
    WritableRaster wr = outgoing.getRaster();
    for (int i = 0; i < high; i++) {
        //      Arrays.fill(row, (255 - (i + GRADIENT_TOP)) << 24);
        //      int r = (int) PApplet.map(i, 0, high-1, r1, r2);
        int rgb = PApplet.lerpColor(top, bot, i / (float) (high - 1), PConstants.RGB);
        Arrays.fill(row, rgb);
        //      System.out.println(PApplet.hex(row[0]));
        wr.setDataElements(0, i, wide, 1, row);
    }
    //    }
    return outgoing;
}
Also used : WritableRaster(java.awt.image.WritableRaster) BufferedImage(java.awt.image.BufferedImage)

Example 4 with WritableRaster

use of java.awt.image.WritableRaster in project processing by processing.

the class QuickTimeWriter method writeFrame.

/**
     * Encodes an image as a video frame and writes it into a video track.
     * <p>
     * Only the video encodings listed below are supported by this method.
     * For other encodings, you have to encode the image by yourself and then
     * call one of the {@code writeSample} methods.
     * <ul>
     * <li>RAW</li>
     * <li>JPG</li>
     * <li>PNG</li>
     * </ul>
     *
     * @param track The track index.
     * @param image The image of the video frame.
     * @param duration The duration of the video frame in media time scale units.
     *
     * @throws IndexOutofBoundsException if the track index is out of bounds.
     * @throws if the duration is less than 1, or if the dimension of the frame
     * does not match the dimension of the video.
     * @throws UnsupportedOperationException if the QuickTimeWriter does not have
     * a built-in encoder for this video format.
     * @throws IOException if writing the sample data failed.
     */
public void writeFrame(int track, BufferedImage image, long duration) throws IOException {
    if (duration <= 0) {
        throw new IllegalArgumentException("Duration must be greater 0.");
    }
    // throws index out of bounds exception if illegal track index
    VideoTrack t = (VideoTrack) tracks.get(track);
    if (t.mediaType != MediaType.VIDEO) {
        throw new IllegalArgumentException("Track " + track + " is not a video track");
    }
    if (t.videoEncoding == null) {
        throw new UnsupportedOperationException("Encoding not supported.");
    }
    ensureStarted();
    // The dimension of the image must match the dimension of the video track
    if (t.videoWidth != image.getWidth() || t.videoHeight != image.getHeight()) {
        throw new IllegalArgumentException("Dimensions of frame[" + tracks.get(track).getSampleCount() + "] (width=" + image.getWidth() + ", height=" + image.getHeight() + ") differs from video dimension (width=" + t.videoWidth + ", height=" + t.videoHeight + ") in track " + track + ".");
    }
    long offset = getRelativeStreamPosition();
    boolean isSync;
    switch(t.videoEncoding) {
        case RAW:
            {
                isSync = true;
                switch(t.videoDepth) {
                    case 8:
                        {
                            if (image.getType() != BufferedImage.TYPE_BYTE_INDEXED) {
                                throw new IllegalArgumentException("BufferedImage type " + image.getType() + " does not match track type " + BufferedImage.TYPE_BYTE_INDEXED + ".");
                            }
                            // Handle sub-image
                            WritableRaster raster = image.getRaster();
                            int sw = raster.getSampleModel().getWidth();
                            //                        int sh = raster.getSampleModel().getHeight();
                            Rectangle r = raster.getBounds();
                            r.x -= raster.getSampleModelTranslateX();
                            r.y -= raster.getSampleModelTranslateY();
                            DataBufferByte buf = (DataBufferByte) raster.getDataBuffer();
                            byte[] bytes = buf.getData();
                            // Write the samples
                            for (int xy = r.x + r.y * sw, ymax = r.x + (r.y + r.height) * sw; xy < ymax; xy += sw) {
                                mdatAtom.getOutputStream().write(bytes, xy, r.width);
                            }
                            break;
                        }
                    case 24:
                        {
                            WritableRaster raster = image.getRaster();
                            // holds a scanline of raw image data with 3 channels of 32 bit data
                            int[] rgb = new int[t.videoWidth * 3];
                            // holds a scanline of raw image data with 3 channels of 8 bit data
                            byte[] bytes = new byte[t.videoWidth * 3];
                            for (int y = 0; y < t.videoHeight; y++) {
                                // Note: Method getPixels is very slow as it does sample conversions for us
                                rgb = raster.getPixels(0, y, t.videoWidth, 1, rgb);
                                for (int k = 0, n = t.videoWidth * 3; k < n; k++) {
                                    bytes[k] = (byte) rgb[k];
                                }
                                mdatAtom.getOutputStream().write(bytes);
                            }
                            break;
                        }
                    default:
                        throw new UnsupportedOperationException("Encoding not supported.");
                }
                break;
            }
        case JPG:
            {
                isSync = true;
                ImageWriter iw = ImageIO.getImageWritersByMIMEType("image/jpeg").next();
                ImageWriteParam iwParam = iw.getDefaultWriteParam();
                iwParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
                iwParam.setCompressionQuality(t.videoQuality);
                MemoryCacheImageOutputStream imgOut = new MemoryCacheImageOutputStream(mdatAtom.getOutputStream());
                iw.setOutput(imgOut);
                IIOImage img = new IIOImage(image, null, null);
                iw.write(null, img, iwParam);
                iw.dispose();
                break;
            }
        case PNG:
            {
                isSync = true;
                ImageWriter iw = ImageIO.getImageWritersByMIMEType("image/png").next();
                ImageWriteParam iwParam = iw.getDefaultWriteParam();
                // FIXME - Detect number of bits per pixel, ensure that correct value is written into video media header atom.
                // FIXME - Maybe we should quietly enforce 24 bits per pixel
                MemoryCacheImageOutputStream imgOut = new MemoryCacheImageOutputStream(mdatAtom.getOutputStream());
                iw.setOutput(imgOut);
                IIOImage img = new IIOImage(image, null, null);
                iw.write(null, img, iwParam);
                iw.dispose();
                break;
            }
        case RLE:
            {
                isSync = t.previousData == null || t.syncInterval != 0 && t.sampleCount % t.syncInterval == 0;
                // Handle sub-image
                WritableRaster raster = image.getRaster();
                int sw = raster.getSampleModel().getWidth();
                //                int sh = raster.getSampleModel().getHeight();
                Rectangle r = raster.getBounds();
                r.x -= raster.getSampleModelTranslateX();
                r.y -= raster.getSampleModelTranslateY();
                if (t.encoder == null) {
                    t.encoder = new AppleRLEEncoder();
                }
                AppleRLEEncoder enc = t.encoder;
                switch(t.videoDepth) {
                    case 16:
                        {
                            DataBufferUShort buf = (DataBufferUShort) raster.getDataBuffer();
                            short[] data = buf.getData();
                            if (isSync) {
                                enc.writeKey16(mdatAtom.getOutputStream(), data, r.width, r.height, r.x + r.y * sw, sw);
                            } else {
                                // FIXME - We blindly assume that the sub-image of the previous image is the same as the current one
                                enc.writeDelta16(mdatAtom.getOutputStream(), data, (short[]) t.previousData, r.width, r.height, r.x + r.y * sw, sw);
                            }
                            if (t.previousData == null) {
                                t.previousData = new short[data.length];
                            }
                            System.arraycopy(data, 0, t.previousData, 0, data.length);
                            break;
                        }
                    case 24:
                        {
                            DataBufferInt buf = (DataBufferInt) raster.getDataBuffer();
                            int[] data = buf.getData();
                            if (isSync) {
                                enc.writeKey24(mdatAtom.getOutputStream(), data, r.width, r.height, r.x + r.y * sw, sw);
                            } else {
                                // FIXME - We blindly assume that the sub-image of the previous image is the same as the current one
                                enc.writeDelta24(mdatAtom.getOutputStream(), data, (int[]) t.previousData, r.width, r.height, r.x + r.y * sw, sw);
                            }
                            if (t.previousData == null) {
                                t.previousData = new int[data.length];
                            }
                            System.arraycopy(data, 0, t.previousData, 0, data.length);
                            break;
                        }
                    case 32:
                        {
                            DataBufferInt buf = (DataBufferInt) raster.getDataBuffer();
                            int[] data = buf.getData();
                            if (isSync) {
                                enc.writeKey32(mdatAtom.getOutputStream(), data, image.getWidth(), image.getHeight(), 0, image.getWidth());
                            } else {
                                // FIXME - We blindly assume that the sub-image of the previous image is the same as the current one
                                enc.writeDelta32(mdatAtom.getOutputStream(), data, (int[]) t.previousData, image.getWidth(), image.getHeight(), 0, image.getWidth());
                            }
                            if (t.previousData == null) {
                                t.previousData = new int[data.length];
                            }
                            System.arraycopy(data, 0, t.previousData, 0, data.length);
                            break;
                        }
                    default:
                        throw new UnsupportedOperationException("Encoding not supported.");
                }
                break;
            }
        default:
            {
                throw new UnsupportedOperationException("Encoding not supported.");
            }
    }
    long length = getRelativeStreamPosition() - offset;
    t.addSample(new Sample(duration, offset, length), 1, isSync);
}
Also used : Rectangle(java.awt.Rectangle) DataBufferInt(java.awt.image.DataBufferInt) DataBufferByte(java.awt.image.DataBufferByte) WritableRaster(java.awt.image.WritableRaster) DataBufferUShort(java.awt.image.DataBufferUShort)

Example 5 with WritableRaster

use of java.awt.image.WritableRaster in project intellij-code-outline by sitano.

the class CodeOutlineImage method moveDataUp.

/**
     * Copies data between the given images, starting at the top of the images
     * and copying then moving downwards line by line. This method is
     * suitable for when the two given images are subimages of the same image,
     * and their data may overlap.
     *
     * @param from the source image
     * @param to the destination image
     */
private static void moveDataUp(BufferedImage from, BufferedImage to) {
    Raster raster = from.getRaster();
    WritableRaster outRaster = to.getRaster();
    int width = outRaster.getWidth();
    int height = Math.min(raster.getHeight(), outRaster.getHeight());
    int startX = outRaster.getMinX();
    int startY = outRaster.getMinY();
    Object tdata = null;
    for (int i = startY; i < startY + height; i++) {
        tdata = raster.getDataElements(raster.getMinX(), i, width, 1, tdata);
        outRaster.setDataElements(startX, i, width, 1, tdata);
    }
}
Also used : WritableRaster(java.awt.image.WritableRaster) Raster(java.awt.image.Raster) WritableRaster(java.awt.image.WritableRaster)

Aggregations

WritableRaster (java.awt.image.WritableRaster)96 BufferedImage (java.awt.image.BufferedImage)64 ColorModel (java.awt.image.ColorModel)31 DirectColorModel (java.awt.image.DirectColorModel)16 Raster (java.awt.image.Raster)15 IndexColorModel (java.awt.image.IndexColorModel)14 DataBufferByte (java.awt.image.DataBufferByte)13 Graphics2D (java.awt.Graphics2D)12 Rectangle (java.awt.Rectangle)12 ComponentColorModel (java.awt.image.ComponentColorModel)11 Point (java.awt.Point)9 DataBuffer (java.awt.image.DataBuffer)8 SampleModel (java.awt.image.SampleModel)8 ColorSpace (java.awt.color.ColorSpace)7 IOException (java.io.IOException)7 Color (java.awt.Color)6 DataBufferInt (java.awt.image.DataBufferInt)6 Iterator (java.util.Iterator)6 AffineTransform (java.awt.geom.AffineTransform)5 MultiPixelPackedSampleModel (java.awt.image.MultiPixelPackedSampleModel)5