[JAVA2D] Dithering
Hi, In a certain piece of code we were using Jai to dither a rendering of our chart objects, however this caused some performance issues and we noticed the RenderingHints.KEY_DITHERING so we tried moving the dithering into the rendering of the chart that was already using the graphics2D of a bufferedImage. While very performant, it doesn't yield the expected result. Instead of dithered it gives us a thresholded black and white image. I found very little information about the dithering hint while googling and searching the forums, except people asking how to turn it off ;-) Now my question is, should the pseudo code below work ? --- code snippet --- byte[] map = {(byte)0xFF, (byte)0x00}; final BufferedImage buf = new BufferedImage(Math.round(fWidth*scale), Math.round(fHeight*scale), BufferedImage.TYPE_BYTE_BINARY, new IndexColorModel(1,2,map,map,map)); final Graphics2D g2 = (Graphics2D)buf.getGraphics(); g2.setRenderingHint(RenderingHints.KEY_DITHERING,RenderingHints.VALUE_DITHER_ENABLE); g2.scale(scale,scale); fChart.setGraphics2D(g2); fChart.render(); return buf; --- code snippet --- For reference we are using jdk 1.4.2_08 and any solution should work in java.awt.headless mode. Any feedback is highly appreciated Best regards, Erik - Erik Vanherck - Product Delivery Manager Inventive Designers Visit http://www.inventivedesigners.com Visit http://www.inventivedesigners.com/scriptura for Scriptura information ! Phone: +32 - 3 - 8210170 Fax: +32 - 3 - 8210171 Email: [EMAIL PROTECTED] Computers in the future may weigh no more than 1.5 tons. - Popular Mechanics, forecasting the relentless march of science, 1949 Inventive Designers' Email Disclaimer:http://www.inventivedesigners.com/email-disclaimer === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA2D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
Re: [JAVA2D] Dithering
Hi Eric, final BufferedImage buf = new BufferedImage(Math.round(fWidth*scale), Math.round(fHeight*scale), BufferedImage.TYPE_BYTE_BINARY, new Well, here's you problem. You're creating a binary image, with only two possible colors. So the dithering can't be smooth by definition - each color can only be black or white. Thanks, Dmitri On Thu, May 11, 2006 at 09:00:27AM +0200, Erik Vanherck wrote: Hi, In a certain piece of code we were using Jai to dither a rendering of our chart objects, however this caused some performance issues and we noticed the RenderingHints.KEY_DITHERING so we tried moving the dithering into the rendering of the chart that was already using the graphics2D of a bufferedImage. While very performant, it doesn't yield the expected result. Instead of dithered it gives us a thresholded black and white image. I found very little information about the dithering hint while googling and searching the forums, except people asking how to turn it off ;-) Now my question is, should the pseudo code below work ? --- code snippet --- byte[] map = {(byte)0xFF, (byte)0x00}; final BufferedImage buf = new BufferedImage(Math.round(fWidth*scale), Math.round(fHeight*scale), BufferedImage.TYPE_BYTE_BINARY, new IndexColorModel(1,2,map,map,map)); final Graphics2D g2 = (Graphics2D)buf.getGraphics(); g2.setRenderingHint(RenderingHints.KEY_DITHERING,RenderingHints.VALUE_DITHER_ENABLE); g2.scale(scale,scale); fChart.setGraphics2D(g2); fChart.render(); return buf; --- code snippet --- For reference we are using jdk 1.4.2_08 and any solution should work in java.awt.headless mode. Any feedback is highly appreciated Best regards, Erik Erik Vanherck - Product Delivery Manager Inventive Designers Visit http://www.inventivedesigners.com Visit http://www.inventivedesigners.com/scriptura for Scriptura information ! Phone: +32 - 3 - 8210170 Fax: +32 - 3 - 8210171 Email: [EMAIL PROTECTED] Computers in the future may weigh no more than 1.5 tons. - Popular Mechanics, forecasting the relentless march of science, 1949 Inventive Designers' Email Disclaimer: http://www.inventivedesigners.com/email-disclaimer === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help. === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help.
Re: [JAVA2D] Dithering
Hi Erik, There are likely 2 different issues that you are dealing with here. First is the issue of dithering during drawing vs. during imaging. We currently do dithering when rendering an image into a lower color resolution destination, but we don't do any dithering at all when we do draw and fill types of rendering. So, if you are using draw/fillGeometry(...) types of calls then you would be seeing thresholding of the solid color. This is something that we always meant to go back and fix, but there isn't much call for high quality rendering to low color resolution destinations in today's world of high memory and deep color displays. To force some dithering you could use a workaround to force the geometry calls to use imaging operations. One workaround would be to render to a higher color destination and then copy the high color image into the B/W destination using a drawImage(). That should force dithering. Another workaround would be to use a custom Paint which simply returns a raster containing a solid color. We currently implement Paint rendering as a series of imaging operations so that would invoke our dithering as well. You could use your own custom Paint or you could use a GradientPaint with both colors the same for example. A color with an alpha value of less than 1.0 (.f for float constructors or 254 for int constructors) might also trigger a slower dithering algorithm. On the other hand, even if you do use one of those workarounds, I'm afraid our dithering implementation is optimized more for a decent performance and acceptable quality compromise on 8-bit destinations than it is for lower color destinations. There isn't much call for rendering to lower color destinations these days given the wide prevalence of full color screens and imagery so this has been a low priority. The low priority of this type of rendering is perhaps reflected by the fact that I couldn't find any open bugs against this problem, though I know that anyone who would try to render into a monochrome image would run into this. Please submit a bug with some example code so that we can track the issue and provide a place for others to vote if they are affected by this problem as well... ...jim Erik Vanherck wrote: Hi, In a certain piece of code we were using Jai to dither a rendering of our chart objects, however this caused some performance issues and we noticed the RenderingHints.KEY_DITHERING so we tried moving the dithering into the rendering of the chart that was already using the graphics2D of a bufferedImage. While very performant, it doesn't yield the expected result. Instead of dithered it gives us a thresholded black and white image. I found very little information about the dithering hint while googling and searching the forums, except people asking how to turn it off ;-) Now my question is, should the pseudo code below work ? --- code snippet --- byte[] map = {(byte)0xFF, (byte)0x00}; final BufferedImage buf = new BufferedImage(Math.round(fWidth*scale), Math.round(fHeight*scale), BufferedImage.TYPE_BYTE_BINARY, new IndexColorModel(1,2,map,map,map)); final Graphics2D g2 = (Graphics2D)buf.getGraphics(); g2.setRenderingHint(RenderingHints.KEY_DITHERING,RenderingHints.VALUE_DITHER_ENABLE); g2.scale(scale,scale); fChart.setGraphics2D(g2); fChart.render(); return buf; --- code snippet --- For reference we are using jdk 1.4.2_08 and any solution should work in java.awt.headless mode. Any feedback is highly appreciated Best regards, Erik - Erik Vanherck - Product Delivery Manager Inventive Designers Visit http://www.inventivedesigners.com Visit http://www.inventivedesigners.com/scriptura for Scriptura information ! Phone: +32 - 3 - 8210170 Fax: +32 - 3 - 8210171 Email: [EMAIL PROTECTED] Computers in the future may weigh no more than 1.5 tons. - Popular Mechanics, forecasting the relentless march of science, 1949 -- Inventive Designers' Email Disclaimer: http://www.inventivedesigners.com/email-disclaimer === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help. === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help.
Re: [JAVA2D] Dithering to black-and-white (monochrome) image
Hi Samo, On Thu, Nov 29, 2001 at 11:03:0p +0100, Samo Pitamic wrote: Hi all! I have the following problem: I have a Buffered image, then I want to transcode it into as small as possible format for wireless transfer. The most suitable format is PNG and since the wireless devices usually only support monochrome images, I want to encode the image in this mode. Therefore I create an IndexColorModel with two palette entries, black and white. Then I call a colorConvertOp.filter(srcImg,destImg), where destImage has the aforementioned monochrome IndexColorModel. While this works procedure, it is still missing a piece. The problem is the destImg looks quite bad, the light parts of the image are totally white, while others are totally black. What I want is a dithered BW image that would show some grayness. You'd need to use a color model with more than just two colors. There are predefined image formats in BufferedImage class which may suit you: TYPE_BYTE_GRAY- 256 gray values TYPE_BYTE_BINARY - 1, 2 or 4 bit Here is an example on how to use one of the default BufferedImage formats: (suppose srcImg is your source BufferedImage) BufferedImage dstImg = new BufferedImage(srcImg.getWidth(), srcImg.getHeight(), BufferedImage.TYPE_BYTE_GRAY); Graphics g = dstImg.getGraphics(); g.drawImage(srcImg, 0, 0, null); Thank you, Dmitri The question is: how do I dither an image? Specifically, how do I dither the image to two colors? I'm not familiar with the dithering algorithm, so I was wondering if there is some BufferedImageOp or RasterOp that can be configured to pose as dithering operation? Can dithering be expressed as a convolution or is it a totally another kind of operation? If yes, can someone point me to an appropriate kernel, if not, does someone have this operation implemented? I need a Java algorithm, preferebly something that works hand-in-hand with BufferedImage concepts. Thanks in advance, Samo === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help. === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help.
[JAVA2D] Dithering to black-and-white (monochrome) image
Hi all! I have the following problem: I have a Buffered image, then I want to transcode it into as small as possible format for wireless transfer. The most suitable format is PNG and since the wireless devices usually only support monochrome images, I want to encode the image in this mode. Therefore I create an IndexColorModel with two palette entries, black and white. Then I call a colorConvertOp.filter(srcImg,destImg), where destImage has the aforementioned monochrome IndexColorModel. While this works procedure, it is still missing a piece. The problem is the destImg looks quite bad, the light parts of the image are totally white, while others are totally black. What I want is a dithered BW image that would show some "grayness". The question is: how do I dither an image? Specifically, how do I dither the image to two colors? I'm not familiar with the dithering algorithm, so I was wondering if there is some BufferedImageOp or RasterOp that can be configured to pose as dithering operation? Can dithering be expressed as a convolution or is it a totally another kind of operation? If yes, can someone point me to an appropriate kernel, if not, does someone have this operation implemented? I need a Java algorithm, preferebly something that works hand-in-hand with BufferedImage concepts. Thanks in advance, Samo === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA2D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
Re: [JAVA2D] Dithering to black-and-white (monochrome) image
Samo, While this does not directly reply to your question please note that 8-to-1 bit dithering is possible using Java Advanced Imaging. Sample code for dithering using the ErrorDiffusion and OrderedDither operations is provided at http://swjscmail1.java.sun.com/cgi-bin/wa?A2=ind0110L=jai-interestP=R28205 Note that in the example a BufferedImage could be used as the source image of either operation. Brian I have the following problem: I have a Buffered image, then I want to transcode it into as small as possible format for wireless transfer. The most suitable format is PNG and since the wireless devices usually only support monochrome images, I want to encode the image in this mode. Therefore I create an IndexColorModel with two palette entries, black and white. Then I call a colorConvertOp.filter(srcImg,destImg), where destImage has the aforementioned monochrome IndexColorModel. While this works procedure, it is still missing a piece. The problem is the destImg looks quite bad, the light parts of the image are totally white, while others are totally black. What I want is a dithered BW image that would show some grayness. The question is: how do I dither an image? Specifically, how do I dither the image to two colors? I'm not familiar with the dithering algorithm, so I was wondering if there is some BufferedImageOp or RasterOp that can be configured to pose as dithering operation? Can dithering be expressed as a convolution or is it a totally another kind of operation? If yes, can someone point me to an appropriate kernel, if not, does someone have this operation implemented? I need a Java algorithm, preferebly something that works hand-in-hand with BufferedImage concepts. === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help.