]> git.imager.perl.org - imager.git/blobdiff - quant.c
use $Config{path_sep} instead of working it out on our own
[imager.git] / quant.c
diff --git a/quant.c b/quant.c
index dc74bebd5a9377b7d4c4bfb55205c0836fac223b..13096ccc841397298c5e3d816d26298b2291c256 100644 (file)
--- a/quant.c
+++ b/quant.c
@@ -6,6 +6,7 @@
 
 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
@@ -27,13 +28,13 @@ setcol(i_color *cl,unsigned char r,unsigned char g,unsigned char b,unsigned char
 */
 
 /*
-=item i_quant_makemap(quant, imgs, count)
+=item i_quant_makemap(C<quant>, C<imgs>, C<count>)
 
 =category Image quantization
 
-Analyzes the I<count> images in I<imgs> according to the rules in
-I<quant> to build a color map (optimal or not depending on
-quant->make_colors).
+Analyzes the C<count> images in C<imgs> according to the rules in
+C<quant> to build a color map (optimal or not depending on
+C<< quant->make_colors >>).
 
 =cut
 */
@@ -71,6 +72,10 @@ i_quant_makemap(i_quantize *quant, i_img **imgs, int count) {
     makemap_mediancut(quant, imgs, count);
     break;
 
+  case mc_mono:
+    makemap_mono(quant);
+    break;
+
   case mc_addi:
   default:
     makemap_addi(quant, imgs, count);
@@ -83,14 +88,14 @@ static void translate_errdiff(i_quantize *, i_img *, i_palidx *);
 static void translate_addi(i_quantize *, i_img *, i_palidx *);
 
 /*
-=item i_quant_translate(quant, img)
+=item i_quant_translate(C<quant>, C<img>)
 
 =category Image quantization
 
-Quantize the image given the palette in quant.
+Quantize the image given the palette in C<quant>.
 
-On success returns a pointer to a memory block of img->xsize *
-img->ysize i_palidx entries.
+On success returns a pointer to a memory block of C<< img->xsize *
+img->ysize >> C<i_palidx> entries.
 
 On failure returns NULL.
 
@@ -616,7 +621,8 @@ makemap_mediancut(i_quantize *quant, i_img **imgs, int count) {
     color_count = 1;
     
     while (color_count < quant->mc_size) {
-      int max_index, max_ch; /* index/channel with biggest spread */
+      /* initialized to avoid compiler warnings */
+      int max_index = 0, max_ch = 0; /* index/channel with biggest spread */
       int max_size;
       medcut_partition *workpart;
       int cum_total;
@@ -696,6 +702,19 @@ makemap_mediancut(i_quantize *quant, i_img **imgs, int count) {
   i_mempool_destroy(&mp);
 }
 
+static void
+makemap_mono(i_quantize *quant) {
+  quant->mc_colors[0].rgba.r = 0;
+  quant->mc_colors[0].rgba.g = 0;
+  quant->mc_colors[0].rgba.b = 0;
+  quant->mc_colors[0].rgba.a = 255;
+  quant->mc_colors[1].rgba.r = 255;
+  quant->mc_colors[1].rgba.g = 255;
+  quant->mc_colors[1].rgba.b = 255;
+  quant->mc_colors[1].rgba.a = 255;
+  quant->mc_count = 2;
+}
+
 #define pboxjump 32
 
 /* Define one of the following 4 symbols to choose a colour search method
@@ -1087,7 +1106,7 @@ 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;
+  int x, y, i, k, bst_idx = 0;
   i_color val;
   int pixdev = quant->perturb;
   CF_VARS;
@@ -1184,7 +1203,7 @@ translate_errdiff(i_quantize *quant, i_img *img, i_palidx *out) {
   int errw;
   int difftotal;
   int x, y, dx, dy;
-  int bst_idx;
+  int bst_idx = 0;
   CF_VARS;
 
   if ((quant->errdiff & ed_mask) == ed_custom) {
@@ -1467,14 +1486,14 @@ static void transparent_errdiff(i_quantize *, i_palidx *, i_img *, i_palidx);
 static void transparent_ordered(i_quantize *, i_palidx *, i_img *, i_palidx);
 
 /*
-=item i_quant_transparent(quant, data, img, trans_index)
+=item i_quant_transparent(C<quant>, C<data>, C<img>, C<trans_index>)
 
 =category Image quantization
 
-Dither the alpha channel on I<img> into the palette indexes in
-I<data>.  Pixels to be transparent are replaced with I<trans_pixel>.
+Dither the alpha channel on C<img> into the palette indexes in
+C<data>.  Pixels to be transparent are replaced with C<trans_pixel>.
 
-The method used depends on the tr_* members of quant.
+The method used depends on the tr_* members of C<quant>.
 
 =cut
 */