@@ -919,21 +919,29 @@ static inline LineContribType *_gdContributionsCalc(unsigned int line_size, unsi
919
919
return res ;
920
920
}
921
921
922
+ /* Convert a double to an unsigned char, rounding to the nearest
923
+ * integer and clamping the result between 0 and max. The absolute
924
+ * value of clr must be less than the maximum value of an unsigned
925
+ * short. */
922
926
static inline unsigned char
923
- uchar_clamp (double clr ) {
927
+ uchar_clamp (double clr , unsigned char max ) {
924
928
unsigned short result ;
925
- assert (fabs (clr ) <= SHRT_MAX );
929
+
930
+ //assert(fabs(clr) <= SHRT_MAX);
931
+
926
932
/* Casting a negative float to an unsigned short is undefined.
927
933
* However, casting a float to a signed truncates toward zero and
928
934
* casting a negative signed value to an unsigned of the same size
929
935
* results in a bit-identical value (assuming twos-complement
930
936
* arithmetic). This is what we want: all legal negative values
931
937
* for clr will be greater than 255. */
938
+
932
939
/* Convert and clamp. */
933
940
result = (unsigned short )(short )(clr + 0.5 );
934
- if (result > 255 ) {
935
- result = (clr < 0 ) ? 0 : 255 ;
941
+ if (result > max ) {
942
+ result = (clr < 0 ) ? 0 : max ;
936
943
}/* if */
944
+
937
945
return result ;
938
946
}/* uchar_clamp*/
939
947
@@ -957,7 +965,9 @@ static inline void _gdScaleRow(gdImagePtr pSrc, unsigned int src_width, gdImage
957
965
b += contrib -> ContribRow [x ].Weights [left_channel ] * (double )(gdTrueColorGetBlue (p_src_row [i ]));
958
966
a += contrib -> ContribRow [x ].Weights [left_channel ] * (double )(gdTrueColorGetAlpha (p_src_row [i ]));
959
967
}
960
- p_dst_row [x ] = gdTrueColorAlpha (uchar_clamp (r ), uchar_clamp (g ), uchar_clamp (b ), uchar_clamp (a ));
968
+ p_dst_row [x ] = gdTrueColorAlpha (uchar_clamp (r , 0xFF ), uchar_clamp (g , 0xFF ),
969
+ uchar_clamp (b , 0xFF ),
970
+ uchar_clamp (a , 0x7F )); /* alpha is 0..127 */
961
971
}
962
972
}
963
973
@@ -1004,7 +1014,9 @@ static inline void _gdScaleCol (gdImagePtr pSrc, unsigned int src_width, gdImag
1004
1014
b += contrib -> ContribRow [y ].Weights [i_iLeft ] * (double )(gdTrueColorGetBlue (pCurSrc ));
1005
1015
a += contrib -> ContribRow [y ].Weights [i_iLeft ] * (double )(gdTrueColorGetAlpha (pCurSrc ));
1006
1016
}
1007
- pRes -> tpixels [y ][uCol ] = gdTrueColorAlpha (uchar_clamp (r ), uchar_clamp (g ), uchar_clamp (b ), uchar_clamp (a ));
1017
+ pRes -> tpixels [y ][uCol ] = gdTrueColorAlpha (uchar_clamp (r , 0xFF ), uchar_clamp (g , 0xFF ),
1018
+ uchar_clamp (b , 0xFF ),
1019
+ uchar_clamp (a , 0x7F )); /* alpha is 0..127 */
1008
1020
}
1009
1021
}
1010
1022
0 commit comments