X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=lib%2Fpng.c;h=bcabd4c36ff4f7f10f641c41d5423cad512e6b0d;hp=9ab0325bf3e7598a15d7a711aaababd74a5d2f45;hb=021eda01dd273614ec1bb0cc0cabfcebfcdb0680;hpb=8980ff2e3cf4865d51af1799ca7124e53cb6d709 diff --git a/lib/png.c b/lib/png.c index 9ab0325..bcabd4c 100644 --- a/lib/png.c +++ b/lib/png.c @@ -1376,7 +1376,7 @@ static int png_apply_specific_filter_32(int filtermode, unsigned char*dest, unsi } return filtermode; } - + static int*num_bits_table = 0; static void make_num_bits_table() @@ -1395,13 +1395,82 @@ static void make_num_bits_table() } } +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 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); + pairs[2] = calloc(1, 8192); + pairs[3] = calloc(1, 8192); + pairs[4] = calloc(1, 8192); + + unsigned char old[5]; + 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 x; + for(x=bytes_per_pixel;x>3; + int b = 1<<(v&7); + if(!pairs[i][p]&b) { + pairs[i][p]|=b; + different_pairs[i]++; + } + } + memcpy(old, dest, sizeof(old)); + } + int f; + int best_nr = 0; + int best_energy = INT_MAX; + for(f=0;f0?5:2; //don't apply y-direction filter in first line - int f; int best_nr = 0; +#if 0 + int f; int best_energy = INT_MAX; int w = width*(bpp/8); unsigned char* pairs = malloc(8192); @@ -1432,11 +1501,14 @@ static int png_apply_filter(unsigned char*dest, unsigned char*src, int width, in best_energy = energy; } } + free(pairs); +#else + best_nr = png_find_best_filter(src, width, bpp, y); +#endif if(bpp==8) png_apply_specific_filter_8(best_nr, dest, src, width); else png_apply_specific_filter_32(best_nr, dest, src, width); - free(pairs); return best_nr; }