diff --git a/include/cammy/photo.h b/include/cammy/photo.h index fcbaac2..89e2aea 100644 --- a/include/cammy/photo.h +++ b/include/cammy/photo.h @@ -38,4 +38,10 @@ void cammy_photo_export(cammy_photo *src, uint8_t *dest, int stride); void cammy_photo_import(cammy_photo *dest, uint8_t *src, int stride); +void cammy_photo_dither(uint8_t *dest, + uint8_t *src, + int width, + int height, + int stride); + #endif /* _CAMMY_PHOTO_H */ diff --git a/src/photo.c b/src/photo.c index a5846ee..0ffa566 100644 --- a/src/photo.c +++ b/src/photo.c @@ -134,3 +134,39 @@ void cammy_photo_import(cammy_photo *dest, uint8_t *src, int stride) { } } } + +void cammy_photo_dither(uint8_t *dest, + uint8_t *src, + int width, + int height, + int stride) { + size_t x, y; + + for (y=0; y> 24; + uint32_t to = (slot & 0x00030000) >> 16; + uint8_t value; + + if (slot & (0x8000 >> ((y & 3) << 2) >> (x & 3))) { + value = to ^ 0x03; + } else { + value = from ^ 0x03; + } + + dest[stride*CAMMY_PHOTO_WIDTH*y+stride*x] = value; + dest[stride*CAMMY_PHOTO_WIDTH*y+stride*x+1] = value; + dest[stride*CAMMY_PHOTO_WIDTH*y+stride*x+2] = value; + } + } +}