X-Git-Url: http://git.imager.perl.org/imager.git/blobdiff_plain/59c150a421ec77a73a5891aefa859c5af0c87499..5e795fcc42c699ff2e3d9a08ccfe7b187f7f0909:/quant.c diff --git a/quant.c b/quant.c index 32938ac0..e831abf3 100644 --- a/quant.c +++ b/quant.c @@ -9,6 +9,7 @@ static void makemap_webmap(i_quantize *); static void makemap_addi(i_quantize *, i_img **imgs, int count); static void makemap_mediancut(i_quantize *, i_img **imgs, int count); static void makemap_mono(i_quantize *); +static void makemap_gray(i_quantize *, int step); static int makemap_palette(i_quantize *, i_img **imgs, int count); @@ -72,6 +73,18 @@ i_quant_makemap(i_quantize *quant, i_img **imgs, int count) { makemap_mono(quant); break; + case mc_gray: + makemap_gray(quant, 1); + break; + + case mc_gray4: + makemap_gray(quant, 85); + break; + + case mc_gray16: + makemap_gray(quant, 17); + break; + case mc_addi: default: makemap_addi(quant, imgs, count); @@ -105,7 +118,7 @@ This function will fail if the supplied palette contains no colors. i_palidx * i_quant_translate(i_quantize *quant, i_img *img) { i_palidx *result; - int bytes; + size_t bytes; mm_log((1, "quant_translate(quant %p, img %p)\n", quant, img)); @@ -283,12 +296,13 @@ for each side of the cube, but this will require even more memory. static void makemap_addi(i_quantize *quant, i_img **imgs, int count) { cvec *clr; - int cnum, i, x, y, bst_idx=0, ld, cd, iter, currhb, img_num; + int cnum, i, bst_idx=0, ld, cd, iter, currhb, img_num; + i_img_dim x, y; i_sample_t *val; float dlt, accerr; hashbox *hb; i_mempool mp; - int maxwidth = 0; + i_img_dim maxwidth = 0; i_sample_t *line; const int *sample_indices; @@ -471,7 +485,7 @@ typedef struct { i_sample_t max[3]; /* maximum for each channel */ i_sample_t width[3]; /* width for each channel */ int start, size; /* beginning and size of the partition */ - int pixels; /* number of pixels represented by this partition */ + i_img_dim pixels; /* number of pixels represented by this partition */ } medcut_partition; /* @@ -537,11 +551,11 @@ static void makemap_mediancut(i_quantize *quant, i_img **imgs, int count) { quant_color_entry *colors; i_mempool mp; - int imgn, x, y, i, ch; - int max_width; + int imgn, i, ch; + i_img_dim x, y, max_width; i_color *line; int color_count; - int total_pixels; + i_img_dim total_pixels; medcut_partition *parts; int part_num; int in, out; @@ -725,6 +739,19 @@ makemap_mono(i_quantize *quant) { quant->mc_count = 2; } +static void +makemap_gray(i_quantize *quant, int step) { + int gray = 0; + int i = 0; + + while (gray < 256) { + setcol(quant->mc_colors+i, gray, gray, gray, 255); + ++i; + gray += step; + } + quant->mc_count = i; +} + static void makemap_webmap(i_quantize *quant) { int r, g, b; @@ -790,7 +817,7 @@ makemap_palette(i_quantize *quant, i_img **imgs, int count) { if (eliminate_unused) { i_palidx *line = mymalloc(sizeof(i_palidx) * imgs[imgn]->xsize); - int x, y; + i_img_dim x, y; memset(used, 0, sizeof(used)); for (y = 0; y < imgs[imgn]->ysize; ++y) { @@ -1239,7 +1266,8 @@ static int rand2dist_find(i_color val, i_quantize *quant, i_dists *dists, int in #endif static void translate_addi(i_quantize *quant, i_img *img, i_palidx *out) { - int x, y, i, k, bst_idx = 0; + i_img_dim x, y, k; + int i, bst_idx = 0; i_color val; int pixdev = quant->perturb; CF_VARS; @@ -1333,9 +1361,9 @@ translate_errdiff(i_quantize *quant, i_img *img, i_palidx *out) { int mapw, maph, mapo; int i; errdiff_t *err; - int errw; + i_img_dim errw; int difftotal; - int x, y, dx, dy; + i_img_dim x, y, dx, dy; int bst_idx = 0; int is_gray = is_gray_map(quant); CF_VARS; @@ -1376,7 +1404,6 @@ translate_errdiff(i_quantize *quant, i_img *img, i_palidx *out) { for (y = 0; y < img->ysize; ++y) { for (x = 0; x < img->xsize; ++x) { i_color val; - long ld, cd; errdiff_t perr; i_gpix(img, x, y, &val); if (img->channels < 3) { @@ -1423,7 +1450,8 @@ translate_errdiff(i_quantize *quant, i_img *img, i_palidx *out) { static void prescan(i_img **imgs,int count, int cnum, cvec *clr, i_sample_t *line) { - int i,k,j,x,y; + int i,k,j; + i_img_dim x,y; i_sample_t *val; const int *chans; @@ -1546,7 +1574,7 @@ static void cr_hashindex(cvec clr[256],int cnum,hashbox hb[512]) { - int bx,mind,cd,cumcnt,bst_idx,i; + int bx,mind,cd,cumcnt,i; /* printf("indexing... \n");*/ cumcnt=0; @@ -1554,7 +1582,7 @@ cr_hashindex(cvec clr[256],int cnum,hashbox hb[512]) { mind=196608; for(i=0; ixsize * sizeof(i_sample_t)); int trans_chan = img->channels > 2 ? 3 : 1; @@ -1688,7 +1716,8 @@ transparent_errdiff(i_quantize *quant, i_palidx *data, i_img *img, int mapw, maph, mapo; int errw, *err, *errp; int difftotal, out, error; - int x, y, dx, dy, i; + i_img_dim x, y, dx, dy; + int i; i_sample_t *line; int trans_chan = img->channels > 2 ? 3 : 1; @@ -1847,7 +1876,7 @@ transparent_ordered(i_quantize *quant, i_palidx *data, i_img *img, i_palidx trans_index) { unsigned char *spot; - int x, y; + i_img_dim x, y; i_sample_t *line; int trans_chan = img->channels > 2 ? 3 : 1; if (quant->tr_orddith == od_custom)