@@ -929,21 +929,29 @@ static inline LineContribType *_gdContributionsCalc(unsigned int line_size, unsi
929
929
return res ;
930
930
}
931
931
932
+ /* Convert a double to an unsigned char, rounding to the nearest
933
+ * integer and clamping the result between 0 and max. The absolute
934
+ * value of clr must be less than the maximum value of an unsigned
935
+ * short. */
932
936
static inline unsigned char
933
- uchar_clamp (double clr ) {
937
+ uchar_clamp (double clr , unsigned char max ) {
934
938
unsigned short result ;
935
- assert (fabs (clr ) <= SHRT_MAX );
939
+
940
+ //assert(fabs(clr) <= SHRT_MAX);
941
+
936
942
/* Casting a negative float to an unsigned short is undefined.
937
943
* However, casting a float to a signed truncates toward zero and
938
944
* casting a negative signed value to an unsigned of the same size
939
945
* results in a bit-identical value (assuming twos-complement
940
946
* arithmetic). This is what we want: all legal negative values
941
947
* for clr will be greater than 255. */
948
+
942
949
/* Convert and clamp. */
943
950
result = (unsigned short )(short )(clr + 0.5 );
944
- if (result > 255 ) {
945
- result = (clr < 0 ) ? 0 : 255 ;
951
+ if (result > max ) {
952
+ result = (clr < 0 ) ? 0 : max ;
946
953
}/* if */
954
+
947
955
return result ;
948
956
}/* uchar_clamp*/
949
957
@@ -967,7 +975,9 @@ static inline void _gdScaleRow(gdImagePtr pSrc, unsigned int src_width, gdImage
967
975
b += contrib -> ContribRow [x ].Weights [left_channel ] * (double )(gdTrueColorGetBlue (p_src_row [i ]));
968
976
a += contrib -> ContribRow [x ].Weights [left_channel ] * (double )(gdTrueColorGetAlpha (p_src_row [i ]));
969
977
}
970
- p_dst_row [x ] = gdTrueColorAlpha (uchar_clamp (r ), uchar_clamp (g ), uchar_clamp (b ), uchar_clamp (a ));
978
+ p_dst_row [x ] = gdTrueColorAlpha (uchar_clamp (r , 0xFF ), uchar_clamp (g , 0xFF ),
979
+ uchar_clamp (b , 0xFF ),
980
+ uchar_clamp (a , 0x7F )); /* alpha is 0..127 */
971
981
}
972
982
}
973
983
@@ -1014,7 +1024,9 @@ static inline void _gdScaleCol (gdImagePtr pSrc, unsigned int src_width, gdImag
1014
1024
b += contrib -> ContribRow [y ].Weights [i_iLeft ] * (double )(gdTrueColorGetBlue (pCurSrc ));
1015
1025
a += contrib -> ContribRow [y ].Weights [i_iLeft ] * (double )(gdTrueColorGetAlpha (pCurSrc ));
1016
1026
}
1017
- pRes -> tpixels [y ][uCol ] = gdTrueColorAlpha (uchar_clamp (r ), uchar_clamp (g ), uchar_clamp (b ), uchar_clamp (a ));
1027
+ pRes -> tpixels [y ][uCol ] = gdTrueColorAlpha (uchar_clamp (r , 0xFF ), uchar_clamp (g , 0xFF ),
1028
+ uchar_clamp (b , 0xFF ),
1029
+ uchar_clamp (a , 0x7F )); /* alpha is 0..127 */
1018
1030
}
1019
1031
}
1020
1032
0 commit comments