This site is no longer active and is available for archival purposes only. Registration and login is disabled.

Dithering


Dithering

Postby Digby » Sep 14, 2001 @ 11:23am

The majority of my Pocket PC programming centers around performance tuning.  Faster ways to perform alpha-blending, move sprites around, mix audio, and rasterize triangles.  Frequently in writing high performance graphics routines we will sacrifice image quality in the name of raw speed.  <br><br>Most of the time this speed vs. quality tradeoff is worth it because the images are updated several times per second and as long as objects are flying past you and you're concentrating on hitting them with some weapon of destruction you can get away with it.  However, if your game has a static background or if the player in your 3D game takes time to look around in the scene things that didn't look so bad when moving start to look a bit crufty.<br><br>Lately I've been thinking more about what to do with this with code running on my iPaq.  The iPaq is even worse as it only has a 12 bit (444) display.  Banding artifacts begin to show up in images that contain smooth gradients of color.  This is a direct result of not having enough color resolution to correctly draw the gradient.  This problem isn't specific to the iPaq (as I'll show later) as even the devices with 16 bit per pixel displays can still exhibit the banding problem with a finely gradiated image.  The bands will be smaller, but they are still present and visible.<br><br>A popular method to combat this lack of color depth resolution is dithering.  Dithering is a technique used to extend the color resolution at the expense of spatial resolution.  Instead of using a single 12 bit pixel (iPaq), you can use multiple pixels and alter the values slightly to trick the eye into summing the surrounding pixels into seeing an intermediate color value that couldn't be represented by a 12 bit value.  This tecnique was first used in printing gray-scale images on black & white (1-bpp) printers.<br><br>There are a number of dithering techniques.  Two of the most popular are ordered-dither and error-diffusion.  The technique that I've been playing around with is ordered-dither.  It provides acceptable results and is faster than the other methods that I've tried.  It has an added advantage in that you can work with a single pixel at a time and you don't need to read or write to surrounding pixels while working with that pixel (error-diffusion has this limitation).<br><br>I don't have time to go into ordered-dither algoritms here, but I'd like to share my results with you.  I've saved all these images as 256x256 uncompressed bmp files, so that any compression effects wouldn't taint the images.  I've also creating versions of the images as they would look being displayed on an iPaq (12-bpp) and a Casio/HP (16-bpp).  You can load the original 24-bpp source image on your Pocket PC and it should look the same.  Also, you should view these images in MS Paint rather than your web browser.  The reason is that IE (and maybe others) will dither images itself and that will taint the original image.<br><br> source image is a linear gradient fill from white to black.  The image is 256 lines tall, so each line is a different color value (24-bpp = 256 gray shades).  It looks pretty good on a 24-bpp display.<br><br>If you display that image on your 16-bpp device, it will look like .  If you look closely, you'll begin to see banding in the form of horizontal stripes.  This is because there are more lines in the image (256) than there are levels of gray (32).  Note: some devices that use 565 displays can toggle the green component and get 64 levels of gray, but the bands should still show up.<br><br> next image is the original gradient bitmap, saved in the equivalent of a 12-bpp image.  This is what you would see on an iPaq if you viewed the original 24-bpp gradient bitmap.  Pretty ugly.  The bands are 16 pixels high and quite obvious.<br><br>OK, is the original image that has been dithered for a 12-bpp display.  I think it looks pretty good.  If you zoom in on the image you can see the signature pattern of an ordered-dither.  I mentioned before that I wasn't going to go into the algorithm here, but it's basically 2 ANDs, 1 table lookup, and adding the value from the table to each color component (clamped to 255).  <br><br>This will help you get started understanding the process of dithering and explains ordered-dither and error-diffusion.  I'm happy to e-mail the code for the dither routine I used to generate the above image to all who request it.<br><br>One other thing worth mentioning is that the DSTN displays found in Pocket PC devices frequently have dithering implemented in hardware.  This is usually done to combat a further lack of color resolution in the actual display. Some of these displays are actually 3-3-3 and then claim to be 4-4-4 or 5-5-5 by dithering.  The reason I mention this is that in theory if you're dithering the image it can interfere with the dither in the display and can make your image wiggle as it's scrolled or repositioned on the display.  I have yet to see this on my iPaq, but I thought I'd make you aware of it.<br><br><br>
Digby
pm Insider
 
Posts: 1011
Joined: Apr 29, 2001 @ 1:53pm


Re: Dithering

Postby Paul » Sep 14, 2001 @ 6:15pm

when i'm at university this forum's gonna be a goldmine. bravo, sir.
Paul
pm Insider
 
Posts: 9835
Joined: Apr 2, 2001 @ 3:15pm
Location: California


Re: Dithering

Postby CARPEDIEM » Sep 15, 2001 @ 2:07pm

The two images are the same Digby.<br><br>Do you have ICQ or MSN?
CARPEDIEM
pm Insider
 
Posts: 514
Joined: Feb 24, 2001 @ 3:58pm


Re: Dithering

Postby Digby » Sep 15, 2001 @ 2:40pm

Thanks for reading my text.  Doesn't look like I'm getting too much feedback on this one.<br><br>One thing some folks might not realize is dithering is not restricted to 2D applications.  When rasterizing an interpolated shading across the face of a polygon, quite frequently you can run out of color precision.  This can result in some really ugly banding artifacts.<br><br>Look at image of a 3D box that I generated using Rhino3D.  Load this 24-bpp image on your iPaq or even a Casio (16-bpp) display.  The banding is atrocious and is the result of vertex color values that change less than the span of pixels that stretch across the surface of the polygons.  Things look really hideous as the box or lights animate because it changes the angle to the light sources resulting in bands that seem to slither and snake across the faces of the cube.<br><br>Now load image on your Pocket PC and note the improvement.  Looks mucho better.  This is using the same ordered-dither algorithm that I posted in the previous images.<br><br>Another nice thing about the ordered-dither algorithm is that it can be added to a 3D rasterizer quite easily.  If a pixel passes the Z and alpha tests, then you pass it to the dither routine.  The ordered-dither doesn't need to read or write to surrounding pixels (which may not be rendered yet) in order to properly dither a pixel.  Since this can be turned on/off per polygon you can allow the app to toggle dithering for only polygons where it would improve image quality.  As I hinted in my original post, you could enable dithering on surfaces when movement slows down, or if your game is displaying artwork that you know would look better dithered (gradient filled, large polys).<br><br>Enough of dithering, I might look at resurrecting my profiler work this weekend if I don't go camping.  Have fun!<br><br><br>
Digby
pm Insider
 
Posts: 1011
Joined: Apr 29, 2001 @ 1:53pm


Re: Dithering

Postby Digby » Sep 15, 2001 @ 2:44pm

DOH!  I've fixed the link in the previous post.  (<br>Darn that cut&paste!)<br><br>Make sure that you view these images on your Pocket PC rather than in IE or MS Paint.  Otherwise, unless you're running 16-bpp desktop, the images will look pretty much identical.<br><br>I have ICQ and Messenger accounts but I don't have the clients installed.  I find them too intrusive.  If you want to contact me, send e-mail to boliverk@hotmail.com, or post something in here.  I try to watch at least the developer forums with frequency.<br><br>
Digby
pm Insider
 
Posts: 1011
Joined: Apr 29, 2001 @ 1:53pm


Re: Dithering

Postby suchiaruzu » Sep 15, 2001 @ 6:07pm

digby,<br>please download the msn messenger. i've added you ages ago, but you never came online :(
<div align="center">Image<br></div>
User avatar
suchiaruzu
pm Insider
 
Posts: 2570
Joined: May 3, 2001 @ 9:29am
Location: BFE


Re: Dithering

Postby Jaybot » Sep 15, 2001 @ 6:08pm

Alright Digby, I've now decided that you know everything :)<br><br>Maybe you could answer a quick (stupid) question for me?  What is endian?  I understand it has something to do with pre-processor stuff, but I'm kind of at a loss right now.  <br><br>Besdides, Carpe is going to need to know soon anyway ;)
-------
|\\ //|
-- ^ --
|||
User avatar
Jaybot
pm Insider
 
Posts: 3208
Joined: Mar 22, 2001 @ 10:04pm
Location: Desk.


Re: Dithering

Postby Digby » Sep 15, 2001 @ 7:09pm

Endian refers to how data is stored in memory.<br><br><br><br>
Digby
pm Insider
 
Posts: 1011
Joined: Apr 29, 2001 @ 1:53pm


Re: Dithering

Postby jongjungbu » Sep 15, 2001 @ 7:38pm

Digby is starting to amaze me even more than Dan East. I'm learning more and more...
User avatar
jongjungbu
Not JongJongBu
 
Posts: 3112
Joined: Jun 19, 2001 @ 4:22am
Location: USA


Re: Dithering

Postby Digby » Sep 15, 2001 @ 7:41pm

Shapeshifter,<br><br>It practially took a digital exorcism to get MSN Messenger off of my XP machines.  I'd like to keep it that way.<br><br>If you want to talk programming, just post something here.  If it's something you don't want others to see, then you may send me a piece of e-mail.  The e-mail account that I've provided for this site is checked about 3 or 4 times a week.<br><br>I don't see the reason for installing something so that people can contact me immediately, or find out when/if I'm online.  Believe it or not, I have work to do and I don't need something popping up all day long distracting me.  Some of you might find this odd, but my phone ringer is turned off while I'm working so that I don't get interrupted.<br><br>From a look at Dan's user profile, he doesn't have any of the instant messaging apps installed either.  Do you ever wonder why that is? ;)<br><br>
Digby
pm Insider
 
Posts: 1011
Joined: Apr 29, 2001 @ 1:53pm


Re: Dithering

Postby Paul » Sep 15, 2001 @ 7:44pm

did you know they can be turned off? pretty cool, huh?
Paul
pm Insider
 
Posts: 9835
Joined: Apr 2, 2001 @ 3:15pm
Location: California


Re: Dithering

Postby jongjungbu » Sep 15, 2001 @ 7:45pm

Smartass ;)
User avatar
jongjungbu
Not JongJongBu
 
Posts: 3112
Joined: Jun 19, 2001 @ 4:22am
Location: USA


Re: Dithering

Postby Paul » Sep 15, 2001 @ 7:47pm

and you have xp? why?
Paul
pm Insider
 
Posts: 9835
Joined: Apr 2, 2001 @ 3:15pm
Location: California


Re: Dithering

Postby Digby » Sep 15, 2001 @ 8:42pm

Paul,<br><br>If I turn off ICQ/AIM/MSNM/etc. and never use it, what's the point of having it on the machine?<br><br>I develop software that must run on MS operating systems.  XP is just another target OS.<br><br>What does any of this have to do with dithering?<br><br><br>
Digby
pm Insider
 
Posts: 1011
Joined: Apr 29, 2001 @ 1:53pm


Re: Dithering

Postby Jaybot » Sep 16, 2001 @ 5:44am

Thanks Dig, I appreciate it.<br><br>I'm positive that endian is the same for mips, sh3,  and arm processors now. :) Thanks!
-------
|\\ //|
-- ^ --
|||
User avatar
Jaybot
pm Insider
 
Posts: 3208
Joined: Mar 22, 2001 @ 10:04pm
Location: Desk.


Next

Return to Windows Mobile


Sort


Forum Description

A discussion forum for mobile device developers on the Windows Mobile platform. Any platform specific topics are welcome.

Moderators:

Dan East, sponge, Digby, David Horn, Kevin Gelso, RICoder

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron