raysan5 / raylib

A simple and easy-to-use library to enjoy videogames programming
http://www.raylib.com
zlib License
22.64k stars 2.27k forks source link

[textures] Implement Floyd-Steinberg dithering for 16 bpp formats conversion #45

Closed raysan5 closed 8 years ago

raysan5 commented 9 years ago

When converting our texture to a 16 bpp format, support Floyd-Steinberg dithering algorithm.

Related functions [textures.c]:

void ImageFormat(Image *image, int newFormat);

Dithering should be available (or automatically applied) when converting from UNCOMPRESSED_R8G8B8 or UNCOMPRESSED_R8G8B8A8 to the following formats:

UNCOMPRESSED_R5G6B5,            // 16 bpp (no-alpha)
UNCOMPRESSED_R5G5B5A1,          // 16 bpp (1 bit alpha)
UNCOMPRESSED_R4G4B4A4,          // 16 bpp (4 bit alpha)

And additional function could be defined, here it is declaration proposal:

unsigned short *ImageDataDither(Color *pixels, int rBpp, int gBpp, int bBpp, int aBpp);
raysan5 commented 8 years ago

New function implemented:

void *ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp);

Merged in commit https://github.com/raysan5/raylib/commit/5dbb93dbb476c35d8f8aab24d9c3507640b171e8