Skip to content

Commit e733876

Browse files
committed
dither in x/y, not i/j
The easiest thing to implement was to use the i/j numbers, but they were not directly related to image x/y coordinates. This may slow things down a tiny little bit, but it looks much better.
1 parent ef4623d commit e733876

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

shared-module/gifio/GifWriter.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ void shared_module_gifio_gifwriter_add_frame(gifio_gifwriter_t *self, const mp_b
231231
mp_get_index(&mp_type_memoryview, bufinfo->len, MP_OBJ_NEW_SMALL_INT(2 * pixel_count - 1), false);
232232

233233
uint16_t *pixels = bufinfo->buf;
234+
int x = 0, y = 0;
234235
for (int i = 0; i < blocks; i++) {
235236
int block_size = MIN(BLOCK_SIZE, pixel_count);
236237
pixel_count -= block_size;
@@ -246,9 +247,14 @@ void shared_module_gifio_gifwriter_add_frame(gifio_gifwriter_t *self, const mp_b
246247
int green = (pixel >> 3) & 0xfc;
247248
int blue = (pixel << 3) & 0xf8;
248249

249-
red = MAX(0, red - rb_bayer[i % 4][j % 4]);
250-
green = MAX(0, green - g_bayer[i % 4][j % 4]);
251-
blue = MAX(0, blue - rb_bayer[i % 4][j % 4]);
250+
red = MAX(0, red - rb_bayer[x % 4][y % 4]);
251+
green = MAX(0, green - g_bayer[x % 4][(y + 2) % 4]);
252+
blue = MAX(0, blue - rb_bayer[(x + 2) % 4][y % 4]);
253+
x++;
254+
if (x == self->width) {
255+
x = 0;
256+
y++;
257+
}
252258

253259
*data++ = ((red >> 1) & 0x60) | ((green >> 3) & 0x1c) | (blue >> 6);
254260
}

0 commit comments

Comments
 (0)