Java Code Examples for java.awt.image.ColorConvertOp#filter()

The following examples show how to use java.awt.image.ColorConvertOp#filter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ColConvCCMTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
static boolean testImage(int dataType, int rBits, int gBits, int bBits,
                          int cs, BufferedImage gldImage,
                          double accuracy)
 {
    BufferedImage src = ImageFactory.createCCMImage(cs, dataType);
    BufferedImage dst = ImageFactory.createDstImage(
        BufferedImage.TYPE_INT_RGB);
    ColorConvertOp op = new ColorConvertOp(null);
    op.filter(src, dst);

    ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
                                              bBits);
    boolean result = cmp.compare(gldImage, dst);
    if (!result) {
        System.err.println(cmp.getStat());
    }
    return result;
}
 
Example 2
Source File: ConvertUtil.java    From jclic with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Converts the source image to 4-bit colour
 * using the given colour map.  No transparency.
 * @param src the source image to convert
 * @param cmap the colour map, which should contain no more than 16 entries
 * The entries are in the form RRGGBB (hex).
 * @return a copy of the source image with a 4-bit colour depth, with the custom colour pallette
 */
public static BufferedImage convert4(BufferedImage src, int[] cmap) {
  IndexColorModel icm = new IndexColorModel(
      4, cmap.length, cmap, 0, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE
      );
  BufferedImage dest = new BufferedImage(
      src.getWidth(), src.getHeight(),
      BufferedImage.TYPE_BYTE_BINARY,
      icm
      );
  ColorConvertOp cco = new ColorConvertOp(
      src.getColorModel().getColorSpace(),
      dest.getColorModel().getColorSpace(),
      null
      );
  cco.filter(src, dest);
  
  return dest;
}
 
Example 3
Source File: ColConvDCMTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static boolean testImage(int type, int rBits, int gBits, int bBits,
                          int cs, BufferedImage gldImage,
                          double accuracy)
{
    BufferedImage src = ImageFactory.createDCMImage(type, cs);
    BufferedImage dst = ImageFactory.createDstImage(
        BufferedImage.TYPE_INT_RGB);
    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(src, dst);

    ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
                                              bBits);
    boolean result = cmp.compare(gldImage, dst);
    if (!result) {
        System.err.println(cmp.getStat());
    }
    return result;
}
 
Example 4
Source File: InvalidRenderIntentTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    ICC_Profile pSRGB = ICC_Profile.getInstance(CS_sRGB);

    byte[] raw_data = pSRGB.getData();

    setRenderingIntent(0x1000000, raw_data);

    ICC_Profile p = ICC_Profile.getInstance(raw_data);

    ICC_ColorSpace cs = new ICC_ColorSpace(p);

    // perfrom test color conversion
    ColorConvertOp op = new ColorConvertOp(cs,
            ColorSpace.getInstance(CS_sRGB), null);
    BufferedImage src = new BufferedImage(1, 1, TYPE_3BYTE_BGR);
    BufferedImage dst = new BufferedImage(1, 1, TYPE_3BYTE_BGR);

    try {
        op.filter(src.getRaster(), dst.getRaster());
    } catch (CMMException e) {
        throw new RuntimeException("Test failed.", e);
    }
    System.out.println("Test passed.");
}
 
Example 5
Source File: ColConvCCMTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static boolean testImage(int dataType, int rBits, int gBits, int bBits,
                          int cs, BufferedImage gldImage,
                          double accuracy)
 {
    BufferedImage src = ImageFactory.createCCMImage(cs, dataType);
    BufferedImage dst = ImageFactory.createDstImage(
        BufferedImage.TYPE_INT_RGB);
    ColorConvertOp op = new ColorConvertOp(null);
    op.filter(src, dst);

    ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
                                              bBits);
    boolean result = cmp.compare(gldImage, dst);
    if (!result) {
        System.err.println(cmp.getStat());
    }
    return result;
}
 
Example 6
Source File: InvalidRenderIntentTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    ICC_Profile pSRGB = ICC_Profile.getInstance(CS_sRGB);

    byte[] raw_data = pSRGB.getData();

    setRenderingIntent(0x1000000, raw_data);

    ICC_Profile p = ICC_Profile.getInstance(raw_data);

    ICC_ColorSpace cs = new ICC_ColorSpace(p);

    // perfrom test color conversion
    ColorConvertOp op = new ColorConvertOp(cs,
            ColorSpace.getInstance(CS_sRGB), null);
    BufferedImage src = new BufferedImage(1, 1, TYPE_3BYTE_BGR);
    BufferedImage dst = new BufferedImage(1, 1, TYPE_3BYTE_BGR);

    try {
        op.filter(src.getRaster(), dst.getRaster());
    } catch (CMMException e) {
        throw new RuntimeException("Test failed.", e);
    }
    System.out.println("Test passed.");
}
 
Example 7
Source File: ColConvDCMTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
static boolean testSubImage(int x0, int y0, int dx, int dy, int type,
                            int rBits, int gBits, int bBits,
                            int cs, BufferedImage gldImage,
                            double accuracy)
{
   BufferedImage src = ImageFactory.createDCMImage(type, cs);
   BufferedImage subSrc = src.getSubimage(x0, y0, dx, dy);
   BufferedImage dst = ImageFactory.createDstImage(
       BufferedImage.TYPE_INT_RGB);
   BufferedImage subDst = dst.getSubimage(x0, y0, dx, dy);

   ColorConvertOp op = new ColorConvertOp(null);

   op.filter(subSrc, subDst);

   ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
                                             bBits);
   boolean result = cmp.compare(subDst, gldImage, x0, y0, dx, dy);
   if (!result) {
       System.err.println(cmp.getStat());
   }
   return result;
}
 
Example 8
Source File: ImageResource.java    From freecol with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Gets a grayscale version of the image of the given size.
 * 
 * @param d The requested size.
 * @return The {@code BufferedImage}.
 */
private BufferedImage getGrayscaleImage(Dimension d) {
    final BufferedImage im = getColorImage(d); // Get the scaled image
    if (im == null) return null;

    int width = im.getWidth();
    int height = im.getHeight();
    // TODO: Find out why making a copy is necessary here to prevent
    //       images from getting too dark.
    BufferedImage srcImage = new BufferedImage(width, height,
        BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = srcImage.createGraphics();
    g.drawImage(im, 0, 0, null);
    g.dispose();
    ColorConvertOp filter = new ColorConvertOp(
        ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
    return filter.filter(srcImage, null);
}
 
Example 9
Source File: ColConvCCMTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
static boolean testSubImage(int x0, int y0, int dx, int dy,
                             int dataType, int rBits, int gBits,
                             int bBits, int cs, BufferedImage gldImage,
                             double accuracy)
 {
    BufferedImage src = ImageFactory.createCCMImage(cs, dataType);
    BufferedImage subSrc = src.getSubimage(x0, y0, dx, dy);
    BufferedImage dst = ImageFactory.createDstImage(
        BufferedImage.TYPE_INT_RGB);
    BufferedImage subDst = dst.getSubimage(x0, y0, dx, dy);
    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(subSrc, subDst);
    ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
                                              bBits);
    boolean result = cmp.compare(subDst, gldImage, x0, y0, dx, dy);
    if (!result) {
        System.err.println(cmp.getStat());
    }
    return result;
}
 
Example 10
Source File: ColConvDCMTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
static boolean testImage(int type, int rBits, int gBits, int bBits,
                          int cs, BufferedImage gldImage,
                          double accuracy)
{
    BufferedImage src = ImageFactory.createDCMImage(type, cs);
    BufferedImage dst = ImageFactory.createDstImage(
        BufferedImage.TYPE_INT_RGB);
    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(src, dst);

    ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
                                              bBits);
    boolean result = cmp.compare(gldImage, dst);
    if (!result) {
        System.err.println(cmp.getStat());
    }
    return result;
}
 
Example 11
Source File: ColConvDCMTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static boolean testSubImage(int x0, int y0, int dx, int dy, int type,
                            int rBits, int gBits, int bBits,
                            int cs, BufferedImage gldImage,
                            double accuracy)
{
   BufferedImage src = ImageFactory.createDCMImage(type, cs);
   BufferedImage subSrc = src.getSubimage(x0, y0, dx, dy);
   BufferedImage dst = ImageFactory.createDstImage(
       BufferedImage.TYPE_INT_RGB);
   BufferedImage subDst = dst.getSubimage(x0, y0, dx, dy);

   ColorConvertOp op = new ColorConvertOp(null);

   op.filter(subSrc, subDst);

   ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
                                             bBits);
   boolean result = cmp.compare(subDst, gldImage, x0, y0, dx, dy);
   if (!result) {
       System.err.println(cmp.getStat());
   }
   return result;
}
 
Example 12
Source File: ColorConvertOpTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object octx, int numReps) {
    final Context ctx = (Context)octx;
    final ColorConvertOp op = ctx.op_rst;

    final Raster src = ctx.rsrc;
    WritableRaster dst = ctx.rdst;
    do {
        try {
            dst = op.filter(src, dst);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } while (--numReps >= 0);
}
 
Example 13
Source File: ColCvtAlpha.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    BufferedImage src
        = new BufferedImage(1, 10, BufferedImage.TYPE_INT_ARGB);

    // Set src pixel values
    Color pelColor = new Color(100, 100, 100, 128);
    for (int i = 0; i < 10; i++) {
        src.setRGB(0, i, pelColor.getRGB());
    }

    ColorModel cm = new ComponentColorModel
        (ColorSpace.getInstance(ColorSpace.CS_GRAY),
         new int [] {8,8}, true,
         src.getColorModel().isAlphaPremultiplied(),
         Transparency.TRANSLUCENT,
         DataBuffer.TYPE_BYTE);

    SampleModel sm = new PixelInterleavedSampleModel
        (DataBuffer.TYPE_BYTE, 100, 100, 2, 200,
         new int [] { 0, 1 });

    WritableRaster wr = Raster.createWritableRaster(sm, new Point(0,0));

    BufferedImage dst =
        new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);
    dst = dst.getSubimage(0, 0, 1, 10);

    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(src, dst);

    for (int i = 0; i < 10; i++) {
        if (((dst.getRGB(0, i) >> 24) & 0xff) != 128) {
            throw new RuntimeException(
                "Incorrect destination alpha value.");
        }
    }

}
 
Example 14
Source File: ColCvtAlpha.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    BufferedImage src
        = new BufferedImage(1, 10, BufferedImage.TYPE_INT_ARGB);

    // Set src pixel values
    Color pelColor = new Color(100, 100, 100, 128);
    for (int i = 0; i < 10; i++) {
        src.setRGB(0, i, pelColor.getRGB());
    }

    ColorModel cm = new ComponentColorModel
        (ColorSpace.getInstance(ColorSpace.CS_GRAY),
         new int [] {8,8}, true,
         src.getColorModel().isAlphaPremultiplied(),
         Transparency.TRANSLUCENT,
         DataBuffer.TYPE_BYTE);

    SampleModel sm = new PixelInterleavedSampleModel
        (DataBuffer.TYPE_BYTE, 100, 100, 2, 200,
         new int [] { 0, 1 });

    WritableRaster wr = Raster.createWritableRaster(sm, new Point(0,0));

    BufferedImage dst =
        new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);
    dst = dst.getSubimage(0, 0, 1, 10);

    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(src, dst);

    for (int i = 0; i < 10; i++) {
        if (((dst.getRGB(0, i) >> 24) & 0xff) != 128) {
            throw new RuntimeException(
                "Incorrect destination alpha value.");
        }
    }

}
 
Example 15
Source File: AlphaTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);

    ColorConvertOp op = new ColorConvertOp(cs, null);
    // create source image filled with an opaque color
    BufferedImage src = createSrc();
    int srcAlpha = getAlpha(src);

    System.out.printf("Src alpha: 0x%02x\n", srcAlpha);

    // create clear (transparent black) destination image
    BufferedImage dst = createDst();
    int dstAlpha = getAlpha(dst);
    System.out.printf("Dst alpha: 0x%02x\n", dstAlpha);


    dst = op.filter(src, dst);
    dstAlpha = getAlpha(dst);
    // we expect that destination image is opaque
    // i.e. alpha is transferred from source to
    // the destination
    System.out.printf("Result alpha: 0x%02x\n", dstAlpha);

    if (srcAlpha != dstAlpha) {
        throw new RuntimeException("Test failed!");
    }
    System.out.println("Test passed");
}
 
Example 16
Source File: ColorConvertOpTests.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object octx, int numReps) {
    final Context ctx = (Context)octx;
    final ColorConvertOp op = ctx.op_img;

    final BufferedImage src = ctx.src;
    BufferedImage dst = ctx.dst;
    do {
        try {
            dst = op.filter(src, dst);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } while (--numReps >= 0);
}
 
Example 17
Source File: ColorConvertOpTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object octx, int numReps) {
    final Context ctx = (Context)octx;
    final ColorConvertOp op = ctx.op_rst;

    final Raster src = ctx.rsrc;
    WritableRaster dst = ctx.rdst;
    do {
        try {
            dst = op.filter(src, dst);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } while (--numReps >= 0);
}
 
Example 18
Source File: ImageConvert.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static BufferedImage cmyk2rgb(Raster cmykRaster,
        ICC_Profile cmykProfile) throws IOException {
    if (cmykProfile == null) {
        cmykProfile = ImageValue.eciCmykProfile();
    }
    ICC_ColorSpace cmykCS = new ICC_ColorSpace(cmykProfile);
    BufferedImage rgbImage = new BufferedImage(cmykRaster.getWidth(), cmykRaster.getHeight(), BufferedImage.TYPE_INT_RGB);
    WritableRaster rgbRaster = rgbImage.getRaster();
    ColorSpace rgbCS = rgbImage.getColorModel().getColorSpace();
    ColorConvertOp cmykToRgb = new ColorConvertOp(cmykCS, rgbCS, null);
    cmykToRgb.filter(cmykRaster, rgbRaster);
    return rgbImage;
}
 
Example 19
Source File: BumpMapFilter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public BufferedImage filter(BufferedImage sourceImage, Object... args) {
    float a = (Float) args[0];
    BufferedImage heightMap = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
    BufferedImage bumpMap = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
    ColorConvertOp gscale = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
    gscale.filter(sourceImage, heightMap);
    for (int x = 0; x < bumpMap.getWidth(); x++) {
        for (int y = 0; y < bumpMap.getHeight(); y++) {
            bumpMap.setRGB(x, y, generateBumpPixel(heightMap, x, y, a));
        }
    }
    return bumpMap;
}
 
Example 20
Source File: ImageUtils.java    From StormCV with Apache License 2.0 2 votes vote down vote up
/**
 * Converts a given image into grayscalse
 * @param src
 * @return
 */
public static BufferedImage convertToGray(BufferedImage src){
       ColorConvertOp grayOp = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
       return grayOp.filter(src,null);
   }