chiark / gitweb /
Laxer identification for subpixel antialiasing
[ypp-sc-tools.web-live.git] / pctb / structure.c
index e86f2c51d5bd92b067b62fb5c3ebda85141b61ef..f10addc56eed9c65f77ede4809407333a4ca780a 100644 (file)
@@ -565,7 +565,7 @@ static inline Fixpt int2fixpt(int x) { return x<<FIXPT_SHIFT; }
 static inline Fixpt dbl2fixpt(double x) { return x * int2fixpt(1); }
 static inline double fixpt2dbl(Fixpt x) { return x / (1.0*int2fixpt(1)); }
 static inline Fixpt fixpt_mul(Fixpt a, Fixpt b) {
-  return (a*b + dbl2fixpt(0.5)) >> FIXPT_SHIFT;
+  return (a*b + dbl2fixpt(0.5)) / int2fixpt(1);
 }
 #define MFP(v) fprintf(stderr," %s=%lx=%f", #v,(v),fixpt2dbl((v)))
 
@@ -609,22 +609,25 @@ static inline Fixpt find_aa_density(const RgbImage *ri, Point p) {
   Fixpt alpha_mean= fixpt_mul(alpha_total, one_third);
   
   Fixpt thresh= dbl2fixpt(1.5/AAMAXVAL);
-  Fixpt alpha_min= alpha_mean - thresh;
-  Fixpt alpha_max= alpha_mean + thresh;
+  Fixpt alpha_min= alpha_mean - thresh*2;
+  Fixpt alpha_max= alpha_mean + thresh*2;
 
   for (i=0; i<3; i++)
     MUST( alpha_min <= alpha[i] && alpha[i] <= alpha_max,
          MP(p);
          MRGB(here);MRGB(aa_background);MRGB(aa_foreground);
-         MFP(aa_alpha_mean_max);
-         MFP(alpha_min); MI(i);MFP(alpha[i]);MFP(alpha_max) );
+         MFP(aa_alpha_mean_max);MFP(thresh);MFP(alpha_mean);
+         MFP(alpha_min);MI(i);MFP(alpha[i]);MFP(alpha_max) );
 
-  MUST( 0 <= alpha_mean && alpha_mean <= aa_alpha_mean_max,
+  MUST( -thresh <= alpha_mean && alpha_mean <= aa_alpha_mean_max + thresh,
        MP(p);
        MRGB(here);MRGB(aa_background);MRGB(aa_foreground);
-       MFP(aa_alpha_mean_max);
+       MFP(aa_alpha_mean_max);MFP(thresh);
        MFP(alpha_mean); MFP(alpha[0]);MFP(alpha[1]);MFP(alpha[2]); );
 
+  if (alpha_mean < 0)                 alpha_mean= 0;
+  if (alpha_mean > aa_alpha_mean_max) alpha_mean= aa_alpha_mean_max;
+
   return alpha_mean;
 }