Package java.awt.image

Examples of java.awt.image.BandCombineOp$SampleModelInfo


                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 {
            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(srcCM,
                                      srcWr.createWritableTranslatedChild(0,0),
                                      false,
                                      null);
            ColorModel dstCM = getColorModel();
            if (!dstCM.hasAlpha()) {
                // No alpha ao we don't have to work around the bug
                // in the color convert op.
                dstBI = new BufferedImage
                    (dstCM, wr.createWritableTranslatedChild(0,0),
                     dstCM.isAlphaPremultiplied(), null);
            } else {
                // 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));
                dstWr = dstWr.createWritableChild
                    (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);

                dstBI = new BufferedImage(cmna, dstWr, false, null);
            }

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

            // I never have to 'fix' alpha premult since I take
            // it's value from my source....
            if (dstCM.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[3][0] = 1; // Blu
                matrix[4][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[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();
            BufferedImage dstBI;

            if (!dstCM.hasAlpha()) {
                // No alpha ao we don't have to work around the bug
                // in the color convert op.
                dstBI = new BufferedImage
                    (dstCM, wr.createWritableTranslatedChild(0,0),
                     dstCM.isAlphaPremultiplied(), null);
            } else {
                // All this nonsense is to work around the fact that
                // the Color convert op doesn't properly copy the
                // Alpha from src to dst.
                SinglePixelPackedSampleModel dstSM;
                dstSM = (SinglePixelPackedSampleModel)wr.getSampleModel();
                int [] masks = dstSM.getBitMasks();
                SampleModel dstSMNoA = new SinglePixelPackedSampleModel
                    (dstSM.getDataType(), dstSM.getWidth(), dstSM.getHeight(),
                     dstSM.getScanlineStride(),
                     new int[] {masks[0], masks[1], masks[2]});
                ColorModel dstCMNoA = GraphicsUtil.Linear_sRGB;

                WritableRaster dstWr;
                dstWr = Raster.createWritableRaster(dstSMNoA,
                                                    wr.getDataBuffer(),
                                                    new Point(0,0));
                dstWr = dstWr.createWritableChild
                    (wr.getMinX()-wr.getSampleModelTranslateX(),
                     wr.getMinY()-wr.getSampleModelTranslateY(),
                     wr.getWidth(), wr.getHeight(),
                     0, 0, null);

                dstBI = new BufferedImage(dstCMNoA, dstWr, false, null);
            }

            // 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;
            WritableRaster srcWr;
            if ( srcCM.hasAlpha() && srcCM.isAlphaPremultiplied() ) {
                Rectangle wrR = wr.getBounds();
                SampleModel sm = srcCM.createCompatibleSampleModel
                    (wrR.width, wrR.height);

                srcWr = Raster.createWritableRaster
                    (sm, new Point(wrR.x, wrR.y));
                src.copyData(srcWr);
                srcBICM = GraphicsUtil.coerceData(srcWr, srcCM, false);
            } else {
                Raster srcRas = src.getData(wr.getBounds());
                srcWr = GraphicsUtil.makeRasterWritable(srcRas);
            }

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

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

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

            if (dstCM.hasAlpha())
                copyBand(srcWr, srcSM.getNumBands()-1,
                         wr,    getSampleModel().getNumBands()-1);
        }
View Full Code Here

    float[][] matrix = new float[][] {new float[] {1, 2, 3},
                                      new float[] {4, 5, 6},
                                      new float[] {7, 8, 9}};
   
    Raster src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, 3, new Point(5, 5));
    BandCombineOp op = new BandCombineOp(matrix, null);
   
    try
    {
      Raster dst = op.createCompatibleDestRaster(src);
      harness.check(dst.getNumBands(), 3);
      harness.check(dst.getHeight(), src.getHeight());
      harness.check(dst.getWidth(), src.getWidth());
      harness.check(dst.getTransferType(), src.getTransferType());
      harness.check(dst.getDataBuffer().getDataType(), src.getDataBuffer().getDataType());
    }
    catch (IllegalArgumentException e)
    {
      harness.check(false);
    }
   
    // Try a different type
    src = Raster.createBandedRaster(DataBuffer.TYPE_BYTE, 25, 40, 3, new Point(5, 5));
    try
    {
      Raster dst = op.createCompatibleDestRaster(src);
      harness.check(dst.getTransferType(), src.getTransferType());
      harness.check(dst.getDataBuffer().getDataType(), src.getDataBuffer().getDataType());
      harness.check(dst.getNumBands(), 3);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(false);
    }
   
    // This is where things get messy.  The Sun API states that "The width of the matrix
    // must be equal to the number of bands in the source Raster, optionally plus one. If
    // there is one more column in the matrix than the number of bands, there is an implied
    // 1 at the end of the vector of band samples representing a pixel. The height of the matrix
    // must be equal to the number of bands in the destination", but this is NOT how their
    // implementation behaves.
    //
    // They miss one requirement, however: the number of bands in the source and destination
    // rasters must also be equal... which effectively means
    // ((width == height) || (width == height + 1)) must be true
   
    // The source (4 bands) is incompatible with the matrix (width = 3)

    src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, 4, new Point(5, 5));
    try
    {
      op.createCompatibleDestRaster(src);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
   
    // The destination raster (3 bands) would be incompatibel with the source (2 bands)
    // (the undocumented requirement)
    src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, 1, new Point(5, 5));
    try
    {
      op.createCompatibleDestRaster(src);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
View Full Code Here

    // Height still == 3, but width == 4
    float[][] matrix = new float[][] {new float[] {1, 2, 3, 1},
                                      new float[] {4, 5, 6, 1},
                                      new float[] {7, 8, 9, 1}};

    BandCombineOp op = new BandCombineOp(matrix, null);

    // Source has 3 bands, which is the width minus one (uses the implied 1), works
    Raster src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, 3, new Point(5, 5));
    try
    {
      Raster dst = op.createCompatibleDestRaster(src);
      harness.check(dst.getNumBands(), 3);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(false);
    }

    // Source has 4 bands, which is compatible with the matrix (width is 4)
    // The destination raster, however, is not compatible with the source (3 vs 4 bands)
    // (the undocumented restriction)
    src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, 4, new Point(5, 5));
    try
    {
      op.createCompatibleDestRaster(src);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }

    // Also incompatible, but this is expected according to the spec
    src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, 2, new Point(5, 5));
    try
    {
      op.createCompatibleDestRaster(src);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }

    // Also still incompatible
    src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, 5, new Point(5, 5));
    try
    {
      op.createCompatibleDestRaster(src);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
View Full Code Here

    float[][] matrix = new float[][] {new float[] {1, 2, 3, 1, 5},
                                      new float[] {4, 5, 6, 1, 5},
                                      new float[] {7, 8, 9, 1, 5},
                                      new float[] {1, 2, 3, 4, 5}};

    BandCombineOp op = new BandCombineOp(matrix, null);

    // Works using the implied 1
    Raster src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, 4, new Point(5, 5));
    try
    {
      Raster dst = op.createCompatibleDestRaster(src);
      harness.check(dst.getNumBands(), 4);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(false);
    }

    // Does not use implied 1; however source and dest would have incompabible bands
    // (undocumented restriction)
    src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, 5, new Point(5, 5));
    try
    {
      op.createCompatibleDestRaster(src);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }

    // Just for completeness
    src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, 3, new Point(5, 5));
    try
    {
      op.createCompatibleDestRaster(src);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
    src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, 6, new Point(5, 5));
    try
    {
      op.createCompatibleDestRaster(src);
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
View Full Code Here

    // ((width != height) && (width != height + 1))
    float[][] matrix = new float[][] {new float[] {1, 2, 3, 1, 5},
                                      new float[] {4, 5, 6, 1, 5},
                                      new float[] {7, 8, 9, 1, 5}};

    BandCombineOp op = new BandCombineOp(matrix, null);

    for (int i = 2; i < 6; i++)
      {
        Raster src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, i, new Point(5, 5));
        try
        {
          op.createCompatibleDestRaster(src);
          harness.check(false);
        }
        catch (IllegalArgumentException e)
        {
          harness.check(true);
        }
      }

    // Repeat the above test, but with too many rows instead of too few
    matrix = new float[][] {new float[] {1, 2, 3,},
                            new float[] {4, 5, 6,},
                            new float[] {2, 4, 6,},
                            new float[] {1, 3, 5,},
                            new float[] {7, 8, 9,}};

    op = new BandCombineOp(matrix, null);

    for (int i = 2; i < 6; i++)
      {
        Raster src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, i, new Point(5, 5));
        try
        {
          op.createCompatibleDestRaster(src);
          harness.check(false);
        }
        catch (IllegalArgumentException e)
        {
          harness.check(true);
View Full Code Here

    //  This is a simple test; the BandCombineOp should not change the
    // dimensions of the raster
   
    float[][] matrix = new float[][] {{2, 7}};
    WritableRaster src = Raster.createBandedRaster(DataBuffer.TYPE_INT, 5, 5, 1, new Point(0,0));
    BandCombineOp op = new BandCombineOp(matrix, null);
    harness.check(op.getBounds2D(src), src.getBounds());
   
    // This should throw an exception, as the bands in the source do not
    // match the rows in the matrix
    /*
     * The spec says it *MAY* throw an exception; the ref. impl does not do so...
View Full Code Here

   
    //  This is a simple test; the BandCombineOp should not change the
    // geometry of the raster
   
    float[][] matrix = new float[][] {{2, 7}};
    BandCombineOp op = new BandCombineOp(matrix, null);
    Point2D dest = null;
    dest = op.getPoint2D(new Point2D.Double(3, 3), dest);
    harness.check(dest, new Point2D.Double(3, 3));
  }
View Full Code Here

    float[][] matrix = new float[][] {new float[]{1, 2, 3},
                                      new float[]{4, 5, 6},
                                      new float[]{7, 8, 9}};
                                     
    BandCombineOp op = new BandCombineOp(matrix, null);
   
    float[][] resultMatrix = op.getMatrix();
    float[][] expectedMatrix = new float[][] {new float[]{1, 2, 3, 0},
                                              new float[]{4, 5, 6, 0},
                                              new float[]{7, 8, 9, 0}};
      // The ref impl seems to add a column of zeros, so we test against that
      // for compatibility
   
    if (expectedMatrix.length != resultMatrix.length)
      harness.check(false);
    else
      for (int i = 0; i < expectedMatrix.length; i++)
        harness.check(Arrays.equals(expectedMatrix[i], resultMatrix[i]));

    // This happens even if the (width == height + 1)
    matrix = new float[][] {new float[]{1, 2, 3, 4},
                            new float[]{4, 5, 6, 7},
                            new float[]{7, 8, 9, 1}};

    op = new BandCombineOp(matrix, null);

    resultMatrix = op.getMatrix();
    expectedMatrix = new float[][] {new float[]{1, 2, 3, 4, 0},
                                    new float[]{4, 5, 6, 7, 0},
                                    new float[]{7, 8, 9, 1, 0}};

    if (expectedMatrix.length != resultMatrix.length)
View Full Code Here

TOP

Related Classes of java.awt.image.BandCombineOp$SampleModelInfo

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.