From 021eda01dd273614ec1bb0cc0cabfcebfcdb0680 Mon Sep 17 00:00:00 2001 From: Matthias Kramm Date: Tue, 30 Mar 2010 21:45:41 -0700 Subject: [PATCH] bugfixes in png speed optimization --- lib/png.c | 53 +++++++++++++++++++---------------------------------- 1 file changed, 19 insertions(+), 34 deletions(-) diff --git a/lib/png.c b/lib/png.c index f6edc12..bcabd4c 100644 --- a/lib/png.c +++ b/lib/png.c @@ -1395,28 +1395,17 @@ static void make_num_bits_table() } } -static int png_find_best_filter_8(unsigned char*src, int width, int y) -{ - /* - - FFFF I X X M M EEEE - F I X X MM MM E - FFF I X M M M EEE - F I X X M M E - F I X X M M EEEE - - */ - return 0; -} - -static int png_find_best_filter_32(unsigned char*src, int width, int y) +static int png_find_best_filter(unsigned char*src, int width, int bpp, int y) { make_num_bits_table(); int num_filters = y>0?5:2; //don't apply y-direction filter in first line - int srcwidth = y?width*4:0; - int x; + int bytes_per_pixel = bpp>>3; + int w = width*bytes_per_pixel; + int back_x = bytes_per_pixel; + int back_y = y?width*bytes_per_pixel:0; + unsigned char*pairs[5]; pairs[0] = calloc(1, 8192); pairs[1] = calloc(1, 8192); @@ -1425,23 +1414,23 @@ static int png_find_best_filter_32(unsigned char*src, int width, int y) pairs[4] = calloc(1, 8192); unsigned char old[5]; - - old[0] = src[3]; - old[1] = src[3]; - old[2] = src[3] - src[3-srcwidth]; - old[3] = src[3] - src[3-srcwidth]; - old[4] = src[3] - PaethPredictor(0, src[3-srcwidth], 0); + int l = bytes_per_pixel - 1; + old[0] = src[l]; + old[1] = src[l]; + old[2] = src[l] - src[l-back_y]; + old[3] = src[l] - src[l-back_y]; + old[4] = src[l] - PaethPredictor(0, src[l-back_y], 0); int different_pairs[5] = {0,0,0,0,0}; - int w = width*4; - for(x=4;x