24bit to xbit dithering

Does anyone know of a library that will convert 24 bit images to any bitdepth,
while dithering them?–
Patrick “Diablo-D3” McFarland || unknown at panax.com
"Computer games don’t affect kids; I mean if Pac-Man affected us as kids, we’d
all be running around in darkened rooms, munching magic pills and listening to
repetitive electronic music." – Kristian Wilson, Nintendo, Inc, 1989

ImageMagick
http://www.imagemagick.org/

Julian.On Sat, 08 Mar 2003 4:39 pm NZDT, Patrick McFarland wrote:

Does anyone know of a library that will convert 24 bit images to any
bitdepth, while dithering them?


Remember, there’s a big difference between kneeling down and bending over.
– Frank Zappa

I should have been more explicit: One that operates on sdl surfaces.On 08-Mar-2003, Julian Peterson wrote:

On Sat, 08 Mar 2003 4:39 pm NZDT, Patrick McFarland wrote:

Does anyone know of a library that will convert 24 bit images to any
bitdepth, while dithering them?

ImageMagick
http://www.imagemagick.org/


Patrick “Diablo-D3” McFarland || unknown at panax.com
"Computer games don’t affect kids; I mean if Pac-Man affected us as kids, we’d
all be running around in darkened rooms, munching magic pills and listening to
repetitive electronic music." – Kristian Wilson, Nintendo, Inc, 1989

“The Spitfire Engine” used in Kobo Deluxe does that (and scaling and
some simple adjustments), but only with a simple 4x4 filter. (A bit
retro locking, sort of, but I prefer that for low resolutions.)

It operates on SDL surface, but I frankly can’t remember if there is a
public API on that level. (The engine uses banks of SDL surfaces, for
tiles, animations and stuff.) It’s wrapped in C++, but the part you’d
need is 100% C, and is found in graphics/sprite.[ch], IIRC. (Not
released separately.)

http://olofson.net/skobo

//David Olofson - Programmer, Composer, Open Source Advocate

.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Saturday 08 March 2003 04.39, Patrick McFarland wrote:

Does anyone know of a library that will convert 24 bit images to
any bitdepth, while dithering them?

I wrote code to do this for StepMania:

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/checkout/stepmania/stepmania/src/SDL_dither.cpp?rev=1.7
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/checkout/stepmania/stepmania/src/SDL_utils.cpp?rev=1.11

The project is GPL, but SDL_dither is public domain and SDL_utils is
LGPL (since it pulls a few functions from SDL; feel free to rewrite the
one or two trivial functions needed if you want a fully PD dither).

Create the destination surface in the desired RGBA format and call
SM_SDL_OrderedDither(src, dst). Note that it never dithers the alpha
channel (which almost always looks horrible).

I wish there was a place to put code like this. I’ve posted this before,
I believe (which received a resounding crickets), but it’s hard to dig
code out of mailing lists, and I hate the idea of people wasting time
re-implementing boring code like this.On Fri, Mar 07, 2003 at 10:39:08PM -0500, Patrick McFarland wrote:

Does anyone know of a library that will convert 24 bit images to any bitdepth,
while dithering them?


Glenn Maynard

Wow! But exactly which functions in SDL_utils isnt BSD?On 08-Mar-2003, Glenn Maynard wrote:

The project is GPL, but SDL_dither is public domain and SDL_utils is
LGPL (since it pulls a few functions from SDL; feel free to rewrite the
one or two trivial functions needed if you want a fully PD dither).


Patrick “Diablo-D3” McFarland || unknown at panax.com
"Computer games don’t affect kids; I mean if Pac-Man affected us as kids, we’d
all be running around in darkened rooms, munching magic pills and listening to
repetitive electronic music." – Kristian Wilson, Nintendo, Inc, 1989

I wish there was a place to put code like this. I’ve posted this before,
I believe (which received a resounding crickets), but it’s hard to dig
code out of mailing lists, and I hate the idea of people wasting time
re-implementing boring code like this.

You can always package it up and add it to the SDL demos page. :slight_smile:

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Heh, well, I just ported it to C. Its actually quite a nice function, but I
wouldnt want to use it on 8bit depths…On 08-Mar-2003, Sam Lantinga wrote:

You can always package it up and add it to the SDL demos page. :slight_smile:


Patrick “Diablo-D3” McFarland || unknown at panax.com
"Computer games don’t affect kids; I mean if Pac-Man affected us as kids, we’d
all be running around in darkened rooms, munching magic pills and listening to
repetitive electronic music." – Kristian Wilson, Nintendo, Inc, 1989

Er, public domain, not BSD. (I don’t see any need to assert copyright at all
on something as boringly mundane as an ordered dither; use it as you want,
just don’t blame me if it explodes.)

I don’t recall what code in SDL_utils was pulled from SDL (or SDL docs,
and so on), so I’m playing it safe and saying the whole file is LGPL.

A few functions I’m quite certain I wrote: SetAlphaRGB, FindAlphaRGB,
SDL_CreateRGBSurfaceSane [sorry, I consider the endian-sensitivity of
the SDL function quite insane], and ConvertSDLSurface; they’re public
domain, too, then. (Actually, that’s most of the file, but none of
those are the functions used by the dither. :slight_smile:

However, the functions used by SDL_dither are just simple pixel decodes/
encodes. f you need to be source-release-requirement-free, it shouldn’t
take but a few minutes to rewrite those functions.On Sat, Mar 08, 2003 at 11:41:57PM -0500, Patrick McFarland wrote:

The project is GPL, but SDL_dither is public domain and SDL_utils is
LGPL (since it pulls a few functions from SDL; feel free to rewrite the
one or two trivial functions needed if you want a fully PD dither).

Wow! But exactly which functions in SDL_utils isnt BSD?


Glenn Maynard

8-bit formats are paletted, and converting from RGBA to paletted is a
completely different beast (palette matching).On Sun, Mar 09, 2003 at 02:53:10AM -0500, Patrick McFarland wrote:

You can always package it up and add it to the SDL demos page. :slight_smile:

Heh, well, I just ported it to C. Its actually quite a nice function, but I
wouldnt want to use it on 8bit depths…


Glenn Maynard