Permalink
Browse files

Fix blending of semi-opaque pixels in average and bilinear resamplers (

  • Loading branch information...
1 parent 51f98b0 commit fa29db4bb2b9a60d46a2c24ab67c48efbb3642f3 @tbonfort tbonfort committed Feb 25, 2014
Showing with 11 additions and 11 deletions.
  1. +1 −1 mapresample.c
  2. +9 −9 maputil.c
  3. +1 −1 msautotest
View
@@ -671,7 +671,7 @@ msAverageRasterResampler( imageObj *psSrcImage, rasterBufferObj *src_rb,
alpha = (unsigned char)
MAX(0,MIN(255,255*dfAlpha01+0.5));
- RB_SET_PIXEL(dst_rb,nDstX,nDstY,
+ RB_MIX_PIXEL(dst_rb,nDstX,nDstY,
red, green, blue, alpha );
}
#ifdef USE_GD
View
@@ -2096,19 +2096,19 @@ void msAlphaBlendPM( unsigned char red_src, unsigned char green_src,
/* Cases with actual blending. */
/* -------------------------------------------------------------------- */
if(!alpha_dst || *alpha_dst == 255) {
- int weight_dst = 256 - alpha_src;
+ int weight_dst = 255 - alpha_src;
- *red_dst = (256 * red_src + *red_dst * weight_dst) >> 8;
- *green_dst = (256 * green_src + *green_dst * weight_dst) >> 8;
- *blue_dst = (256 * blue_src + *blue_dst * weight_dst) >> 8;
+ *red_dst = (alpha_src * red_src + *red_dst * weight_dst) >> 8;
+ *green_dst = (alpha_src * green_src + *green_dst * weight_dst) >> 8;
+ *blue_dst = (alpha_src * blue_src + *blue_dst * weight_dst) >> 8;
} else {
- int weight_dst = (256 - alpha_src);
+ int weight_dst = (255 - alpha_src);
- *red_dst = (256 * red_src + *red_dst * weight_dst) >> 8;
- *green_dst = (256 * green_src + *green_dst * weight_dst) >> 8;
- *blue_dst = (256 * blue_src + *blue_dst * weight_dst) >> 8;
+ *red_dst = (alpha_src * red_src + *red_dst * weight_dst) >> 8;
+ *green_dst = (alpha_src * green_src + *green_dst * weight_dst) >> 8;
+ *blue_dst = (alpha_src * blue_src + *blue_dst * weight_dst) >> 8;
- *alpha_dst = (256 * alpha_src + *alpha_dst * weight_dst) >> 8;
+ *alpha_dst = (255 * alpha_src + *alpha_dst * weight_dst) >> 8;
}
}

0 comments on commit fa29db4

Please sign in to comment.