diff --git a/jifolator.c b/jifolator.c index 9d76e2d..56d70ea 100644 --- a/jifolator.c +++ b/jifolator.c @@ -250,6 +250,7 @@ int jifolator_push_frame(JifolatorContext *ctx, JifolatorThreadContext *thread_c AVFrame *frame; AVPacket encoded_packet; char lff_err[LFF_ERRBUF_SIZE]; + memset(palette_buffer, 0xFF, 1024 * sizeof(uint32_t)); frame_buffer = jifolator_get_frame_buffer(thread_ctx->input_stream_ctx, ctx->settings.frame_size.w, ctx->settings.frame_size.h, timestamp, &err[0]); @@ -367,7 +368,7 @@ int jifolator_push_frame(JifolatorContext *ctx, JifolatorThreadContext *thread_c /* Make pixels transparent to improve compression efficiency if they are nearly the same value as on the previous frame's. */ - if (frame_number > 0) { + /*if (frame_number > 0) { for (y = 0; y < ctx->settings.frame_size.h; y++) { size_t row_offset = y * ctx->settings.frame_size.w; @@ -383,13 +384,12 @@ int jifolator_push_frame(JifolatorContext *ctx, JifolatorThreadContext *thread_c uint32_t p_b = (uint8_t)(prev_pixel >> 16); if (color_distance(c_r, c_g, c_b, p_r, p_g, p_b) / 256 < ctx->quality.transparency_threshold) { - /* Set the current frame's pixel to fully transparent and persist the previous color. */ *((uint32_t *)frame_buffer + row_offset + x) = (p_r & 0xFF) | ((p_g & 0xFF) << 8) | ((p_b & 0xFF) << 16) | (0x00 << 24); } } } - } + }*/ /* Set the previous frame buffer to the current processed one. */ memcpy(ctx->previous_frame_buffer, frame_buffer, ctx->settings.frame_size.h * ctx->settings.frame_size.w * 4); @@ -413,13 +413,23 @@ int jifolator_push_frame(JifolatorContext *ctx, JifolatorThreadContext *thread_c liq_set_dithering_level(liq_res, ctx->quality.dithering_level); liq_write_remapped_image(liq_res, liq_img, palettized_frame_buffer, ctx->settings.frame_size.w * ctx->settings.frame_size.h); liq_pal = liq_get_palette(liq_res); - for (i = 0; i < liq_pal->count; i++) { - palette_buffer[i] = + for (i = 0; i < ctx->settings.frame_size.w * ctx->settings.frame_size.h; i++) { + if (palettized_frame_buffer[i] == liq_pal->count - 1) + palettized_frame_buffer[i] = 0; + else + palettized_frame_buffer[i] += 1; + } + for (i = 0; i < liq_pal->count - 1; i++) { + palette_buffer[i + 1] = (uint32_t)liq_pal->entries[i].a << 24 | (uint32_t)liq_pal->entries[i].r << 16 | (uint32_t)liq_pal->entries[i].g << 8 | (uint32_t)liq_pal->entries[i].b << 0; } + palette_buffer[0] = (uint32_t)liq_pal->entries[liq_pal->count - 1].a << 24 | + (uint32_t)liq_pal->entries[liq_pal->count - 1].r << 16 | + (uint32_t)liq_pal->entries[liq_pal->count - 1].g << 8 | + (uint32_t)liq_pal->entries[liq_pal->count - 1].b; liq_result_destroy(liq_res); liq_image_destroy(liq_img);