Package java.awt.image

Examples of java.awt.image.BandCombineOp


        final int srcMinX = srcRI.getMinX();
        final int srcMinY = srcRI.getMinY();

        RenderingHints hints = rc.getRenderingHints();
        BandCombineOp op = new BandCombineOp(matrix, null);

        //
        // Wrap source in buffered image
        //
        ColorModel cm = srcRI.getColorModel();
        Raster srcRR = srcRI.getData();
        Point origin = new Point(0, 0);
        WritableRaster srcWR = Raster.createWritableRaster(srcRR.getSampleModel(),
                                                           srcRR.getDataBuffer(),
                                                           origin);
        /*
        BufferedImage srcBI = new BufferedImage(cm,
                                                srcWR,
                                                cm.isAlphaPremultiplied(),
                                                null);*/

        WritableRaster dstWR = op.filter(srcWR, srcWR);

        BufferedImage dstBI = new BufferedImage(cm,
                                                dstWR,
                                                cm.isAlphaPremultiplied(),
                                                null);
View Full Code Here


                matrix = new float[sm.getNumBands()][1];
                matrix[0][0] = 1;
            }

            Raster srcRas = src.getData(wr.getBounds());
            BandCombineOp op = new BandCombineOp(matrix, null);
            op.filter(srcRas, wr);
        } else {
            // REVIEW: Alpha handling may not be correct through here.
            // Since the colorconversion may not be a linear op it
            // is probably required to divide out the alpha before
            // doing the color conversion.
            //
            // This might be especially tricky since there are bugs
            // in the ColorConvert Ops handling of alpha...

            ColorConvertOp op = new ColorConvertOp(null);
            Raster srcRas = src.getData(wr.getBounds());
            Point pt = new Point(srcRas.getMinX(), srcRas.getMinY());

            WritableRaster srcWr = (WritableRaster)srcRas;
            // srcWr = Raster.createWritableRaster(srcRas.getSampleModel(),
            //                                     srcRas.getDataBuffer(),
            //                                     pt);

            BufferedImage srcBI, dstBI;
            srcBI = new BufferedImage(cm,
                                      srcWr.createWritableTranslatedChild(0,0),
                                      cm.isAlphaPremultiplied(),
                                      null);

            // All this nonsense is to work around the fact that the
            // Color convert op doesn't properly copy the Alpha from
            // src to dst.
            PixelInterleavedSampleModel dstSM;
            dstSM = (PixelInterleavedSampleModel)wr.getSampleModel();
            SampleModel smna = new PixelInterleavedSampleModel
                (dstSM.getDataType(),   
                 dstSM.getWidth(),       dstSM.getHeight(),
                 dstSM.getPixelStride(), dstSM.getScanlineStride(),
                 new int [] { 0 });

            WritableRaster dstWr;
            dstWr = Raster.createWritableRaster(smna,
                                                wr.getDataBuffer(),
                                                new Point(0,0));

            ColorModel cmna = new ComponentColorModel
                (ColorSpace.getInstance(ColorSpace.CS_GRAY),
                 new int [] {8}, false, false,
                 Transparency.OPAQUE,
                 DataBuffer.TYPE_BYTE);

            dstBI = new BufferedImage(cmna, dstWr, false, null);
            op.filter(srcBI, dstBI);

            // I never have to 'fix' alpha premult since I take
            // it's value from my source....
            if (cm.hasAlpha() && getColorModel().hasAlpha())
                copyBand(srcWr, sm.getNumBands()-1,
View Full Code Here

                matrix[2][2] = 1; // Blu
                matrix[3][3] = 1; // Alpha
                break;
            }
            Raster srcRas = src.getData(wr.getBounds());
            BandCombineOp op = new BandCombineOp(matrix, null);
            op.filter(srcRas, wr);
            return wr;
        }

        if (srcCM.getColorSpace() ==
            ColorSpace.getInstance(ColorSpace.CS_GRAY)) {

            // This is a little bit of a hack.  There is only
            // a linear grayscale ICC profile in the JDK so
            // many things use this when the data _really_
            // has sRGB gamma applied.
            try {
                float [][] matrix = null;
                switch (srcSM.getNumBands()) {
                case 1:
                    matrix = new float[3][1];
                    matrix[0][0] = 1; // Red
                    matrix[1][0] = 1; // Grn
                    matrix[2][0] = 1; // Blu
                    break;
                case 2:
                default:
                    matrix = new float[4][2];
                    matrix[0][0] = 1; // Red
                    matrix[1][0] = 1; // Grn
                    matrix[2][0] = 1; // Blu
                    matrix[3][1] = 1; // Alpha
                    break;
                }
                Raster srcRas = src.getData(wr.getBounds());
                BandCombineOp op = new BandCombineOp(matrix, null);
                op.filter(srcRas, wr);
            } catch (Throwable t) {
                t.printStackTrace();
            }
            return wr;
        }

        ColorModel dstCM = getColorModel();
        if (srcCM.getColorSpace() == dstCM.getColorSpace()) {
            // No transform needed, just reformat data...
            // System.out.println("Bypassing");

            if (is_INT_PACK_COMP(srcSM))
                src.copyData(wr);
            else
                GraphicsUtil.copyData(src.getData(wr.getBounds()), wr);

            return wr;
        }

        Raster srcRas = src.getData(wr.getBounds());
        WritableRaster srcWr  = (WritableRaster)srcRas;

        // Divide out alpha if we have it.  We need to do this since
        // the color convert may not be a linear operation which may
        // lead to out of range values.
        ColorModel srcBICM = srcCM;
        if (srcCM.hasAlpha())
            srcBICM = GraphicsUtil.coerceData(srcWr, srcCM, false);

        BufferedImage srcBI, dstBI;
        srcBI = new BufferedImage(srcBICM,
                                  srcWr.createWritableTranslatedChild(0,0),
                                  false,
                                  null);

        // System.out.println("src: " + srcBI.getWidth() + "x" +
        //                    srcBI.getHeight());

        ColorConvertOp op = new ColorConvertOp(dstCM.getColorSpace(),
                                               null);
        dstBI = op.filter(srcBI, null);

        // System.out.println("After filter:");

        WritableRaster wr00 = wr.createWritableTranslatedChild(0,0);
        for (int i=0; i<dstCM.getColorSpace().getNumComponents(); i++)
View Full Code Here

                matrix[2][2] = 1; // Blu
                matrix[3][3] = 1; // Alpha
                break;
            }
            Raster srcRas = src.getData(wr.getBounds());
            BandCombineOp op = new BandCombineOp(matrix, null);
            op.filter(srcRas, wr);
        } else {
            ColorModel dstCM = getColorModel();
            if (srcCM.getColorSpace() == dstCM.getColorSpace()) {
                // No transform needed, just reformat data...
                // System.out.println("Bypassing");

                if (is_INT_PACK_COMP(srcSM))
                    src.copyData(wr);
                else
                    GraphicsUtil.copyData(src.getData(wr.getBounds()), wr);

                return wr;
            }

            Raster srcRas = src.getData(wr.getBounds());
            WritableRaster srcWr  = (WritableRaster)srcRas;

            // Divide out alpha if we have it.  We need to do this since
            // the color convert may not be a linear operation which may
            // lead to out of range values.
            ColorModel srcBICM = srcCM;
            if (srcCM.hasAlpha())
                srcBICM = GraphicsUtil.coerceData(srcWr, srcCM, false);

            BufferedImage srcBI, dstBI;
            srcBI = new BufferedImage(srcBICM,
                                      srcWr.createWritableTranslatedChild(0,0),
                                      false,
                                      null);

            // System.out.println("src: " + srcBI.getWidth() + "x" +
            //                    srcBI.getHeight());

            ColorConvertOp op = new ColorConvertOp(dstCM.getColorSpace(),
                                                   null);
            dstBI = op.filter(srcBI, null);

            // System.out.println("After filter:");
           
            WritableRaster wr00 = wr.createWritableTranslatedChild(0,0);
            for (int i=0; i<dstCM.getColorSpace().getNumComponents(); i++)
View Full Code Here

TOP

Related Classes of java.awt.image.BandCombineOp

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.