@@ -1021,7 +1021,7 @@ static inline void _gdScaleRow(gdImagePtr pSrc, unsigned int src_width, gdImage
1021
1021
}
1022
1022
}
1023
1023
1024
- static inline void _gdScaleHoriz (gdImagePtr pSrc , unsigned int src_width , unsigned int src_height , gdImagePtr pDst , unsigned int dst_width , unsigned int dst_height )
1024
+ static inline int _gdScaleHoriz (gdImagePtr pSrc , unsigned int src_width , unsigned int src_height , gdImagePtr pDst , unsigned int dst_width , unsigned int dst_height )
1025
1025
{
1026
1026
unsigned int u ;
1027
1027
LineContribType * contrib ;
@@ -1036,13 +1036,14 @@ static inline void _gdScaleHoriz(gdImagePtr pSrc, unsigned int src_width, unsign
1036
1036
1037
1037
contrib = _gdContributionsCalc (dst_width , src_width , (double )dst_width / (double )src_width , pSrc -> interpolation );
1038
1038
if (contrib == NULL ) {
1039
- return ;
1039
+ return 0 ;
1040
1040
}
1041
1041
/* Scale each row */
1042
1042
for (u = 0 ; u < dst_height - 1 ; u ++ ) {
1043
1043
_gdScaleRow (pSrc , src_width , pDst , dst_width , u , contrib );
1044
1044
}
1045
1045
_gdContributionsFree (contrib );
1046
+ return 1 ;
1046
1047
}
1047
1048
1048
1049
static inline void _gdScaleCol (gdImagePtr pSrc , unsigned int src_width , gdImagePtr pRes , unsigned int dst_width , unsigned int dst_height , unsigned int uCol , LineContribType * contrib )
@@ -1068,7 +1069,7 @@ static inline void _gdScaleCol (gdImagePtr pSrc, unsigned int src_width, gdImag
1068
1069
}
1069
1070
}
1070
1071
1071
- static inline void _gdScaleVert (const gdImagePtr pSrc , const unsigned int src_width , const unsigned int src_height , const gdImagePtr pDst , const unsigned int dst_width , const unsigned int dst_height )
1072
+ static inline int _gdScaleVert (const gdImagePtr pSrc , const unsigned int src_width , const unsigned int src_height , const gdImagePtr pDst , const unsigned int dst_width , const unsigned int dst_height )
1072
1073
{
1073
1074
unsigned int u ;
1074
1075
LineContribType * contrib ;
@@ -1083,19 +1084,21 @@ static inline void _gdScaleVert (const gdImagePtr pSrc, const unsigned int src_w
1083
1084
1084
1085
contrib = _gdContributionsCalc (dst_height , src_height , (double )(dst_height ) / (double )(src_height ), pSrc -> interpolation );
1085
1086
if (contrib == NULL ) {
1086
- return ;
1087
+ return 0 ;
1087
1088
}
1088
1089
/* scale each column */
1089
1090
for (u = 0 ; u < dst_width - 1 ; u ++ ) {
1090
1091
_gdScaleCol (pSrc , src_width , pDst , dst_width , dst_height , u , contrib );
1091
1092
}
1092
1093
_gdContributionsFree (contrib );
1094
+ return 1 ;
1093
1095
}
1094
1096
1095
1097
gdImagePtr gdImageScaleTwoPass (const gdImagePtr src , const unsigned int src_width , const unsigned int src_height , const unsigned int new_width , const unsigned int new_height )
1096
1098
{
1097
1099
gdImagePtr tmp_im ;
1098
1100
gdImagePtr dst ;
1101
+ int scale_pass_res ;
1099
1102
1100
1103
if (new_width == 0 || new_height == 0 ) {
1101
1104
return NULL ;
@@ -1111,38 +1114,26 @@ gdImagePtr gdImageScaleTwoPass(const gdImagePtr src, const unsigned int src_widt
1111
1114
return NULL ;
1112
1115
}
1113
1116
gdImageSetInterpolationMethod (tmp_im , src -> interpolation_id );
1114
- _gdScaleHoriz (src , src_width , src_height , tmp_im , new_width , src_height );
1117
+ scale_pass_res = _gdScaleHoriz (src , src_width , src_height , tmp_im , new_width , src_height );
1118
+ if (scale_pass_res != 1 ) {
1119
+ gdImageDestroy (tmp_im );
1120
+ return NULL ;
1121
+ }
1115
1122
1116
1123
dst = gdImageCreateTrueColor (new_width , new_height );
1117
1124
if (dst == NULL ) {
1118
1125
gdImageDestroy (tmp_im );
1119
1126
return NULL ;
1120
1127
}
1121
1128
gdImageSetInterpolationMethod (dst , src -> interpolation_id );
1122
- _gdScaleVert (tmp_im , new_width , src_height , dst , new_width , new_height );
1123
- gdImageDestroy (tmp_im );
1124
-
1125
- return dst ;
1126
- }
1127
-
1128
- gdImagePtr Scale (const gdImagePtr src , const unsigned int src_width , const unsigned int src_height , const gdImagePtr dst , const unsigned int new_width , const unsigned int new_height )
1129
- {
1130
- gdImagePtr tmp_im ;
1131
-
1132
- if (new_width == 0 || new_height == 0 ) {
1133
- return NULL ;
1134
- }
1135
-
1136
- tmp_im = gdImageCreateTrueColor (new_width , src_height );
1137
- if (tmp_im == NULL ) {
1129
+ scale_pass_res = _gdScaleVert (tmp_im , new_width , src_height , dst , new_width , new_height );
1130
+ if (scale_pass_res != 1 ) {
1131
+ gdImageDestroy (dst );
1132
+ gdImageDestroy (tmp_im );
1138
1133
return NULL ;
1139
1134
}
1140
- gdImageSetInterpolationMethod (tmp_im , src -> interpolation_id );
1141
-
1142
- _gdScaleHoriz (src , src_width , src_height , tmp_im , new_width , src_height );
1143
- _gdScaleVert (tmp_im , new_width , src_height , dst , new_width , new_height );
1144
-
1145
1135
gdImageDestroy (tmp_im );
1136
+
1146
1137
return dst ;
1147
1138
}
1148
1139
0 commit comments