@@ -3074,39 +3074,41 @@ box_blur(SDL_Surface *src, SDL_Surface *dst, int radius, SDL_bool repeat)
3074
3074
Uint8 * srcpx = (Uint8 * )src -> pixels ;
3075
3075
Uint8 * dstpx = (Uint8 * )dst -> pixels ;
3076
3076
Uint8 nb = src -> format -> BytesPerPixel ;
3077
- int w = dst -> w , h = dst -> h , pitch = dst -> pitch ;
3077
+ int w = dst -> w , h = dst -> h ;
3078
+ int dst_pitch = dst -> pitch ;
3079
+ int src_pitch = src -> pitch ;
3078
3080
int i , x , y , color ;
3079
- Uint32 * buf = malloc (pitch * sizeof (Uint32 ));
3080
- Uint32 * sum_v = malloc (pitch * sizeof (Uint32 ));
3081
+ Uint32 * buf = malloc (dst_pitch * sizeof (Uint32 ));
3082
+ Uint32 * sum_v = malloc (dst_pitch * sizeof (Uint32 ));
3081
3083
Uint32 * sum_h = malloc (nb * sizeof (Uint32 ));
3082
3084
3083
- memset (sum_v , 0 , pitch * sizeof (Uint32 ));
3085
+ memset (sum_v , 0 , dst_pitch * sizeof (Uint32 ));
3084
3086
for (y = 0 ; y <= radius ; y ++ ) { // y-pre
3085
- for (i = 0 ; i < pitch ; i ++ ) {
3086
- sum_v [i ] += srcpx [pitch * y + i ];
3087
+ for (i = 0 ; i < dst_pitch ; i ++ ) {
3088
+ sum_v [i ] += srcpx [src_pitch * y + i ];
3087
3089
}
3088
3090
}
3089
3091
if (repeat ) {
3090
- for (i = 0 ; i < pitch ; i ++ ) {
3092
+ for (i = 0 ; i < dst_pitch ; i ++ ) {
3091
3093
sum_v [i ] += srcpx [i ] * radius ;
3092
3094
}
3093
3095
}
3094
3096
for (y = 0 ; y < h ; y ++ ) { // y
3095
- for (i = 0 ; i < pitch ; i ++ ) {
3097
+ for (i = 0 ; i < dst_pitch ; i ++ ) {
3096
3098
buf [i ] = sum_v [i ] / (radius * 2 + 1 );
3097
3099
3098
3100
// update vertical sum
3099
3101
if (y - radius >= 0 ) {
3100
- sum_v [i ] -= srcpx [pitch * (y - radius ) + i ];
3102
+ sum_v [i ] -= srcpx [src_pitch * (y - radius ) + i ];
3101
3103
}
3102
3104
else if (repeat ) {
3103
3105
sum_v [i ] -= srcpx [i ];
3104
3106
}
3105
3107
if (y + radius + 1 < h ) {
3106
- sum_v [i ] += srcpx [pitch * (y + radius + 1 ) + i ];
3108
+ sum_v [i ] += srcpx [src_pitch * (y + radius + 1 ) + i ];
3107
3109
}
3108
3110
else if (repeat ) {
3109
- sum_v [i ] += srcpx [pitch * (h - 1 ) + i ];
3111
+ sum_v [i ] += srcpx [src_pitch * (h - 1 ) + i ];
3110
3112
}
3111
3113
}
3112
3114
@@ -3123,7 +3125,7 @@ box_blur(SDL_Surface *src, SDL_Surface *dst, int radius, SDL_bool repeat)
3123
3125
}
3124
3126
for (x = 0 ; x < w ; x ++ ) { // x
3125
3127
for (color = 0 ; color < nb ; color ++ ) {
3126
- dstpx [pitch * y + nb * x + color ] =
3128
+ dstpx [dst_pitch * y + nb * x + color ] =
3127
3129
sum_h [color ] / (radius * 2 + 1 );
3128
3130
3129
3131
// update horizontal sum
@@ -3154,10 +3156,12 @@ gaussian_blur(SDL_Surface *src, SDL_Surface *dst, int radius, SDL_bool repeat)
3154
3156
Uint8 * srcpx = (Uint8 * )src -> pixels ;
3155
3157
Uint8 * dstpx = (Uint8 * )dst -> pixels ;
3156
3158
Uint8 nb = src -> format -> BytesPerPixel ;
3157
- int w = dst -> w , h = dst -> h , pitch = dst -> pitch ;
3159
+ int w = dst -> w , h = dst -> h ;
3160
+ int dst_pitch = dst -> pitch ;
3161
+ int src_pitch = src -> pitch ;
3158
3162
int i , j , x , y , color ;
3159
- float * buf = malloc (pitch * sizeof (float ));
3160
- float * buf2 = malloc (pitch * sizeof (float ));
3163
+ float * buf = malloc (dst_pitch * sizeof (float ));
3164
+ float * buf2 = malloc (dst_pitch * sizeof (float ));
3161
3165
float * lut = malloc ((radius + 1 ) * sizeof (float ));
3162
3166
float lut_sum = 0.0 ;
3163
3167
@@ -3174,24 +3178,25 @@ gaussian_blur(SDL_Surface *src, SDL_Surface *dst, int radius, SDL_bool repeat)
3174
3178
lut [i ] /= lut_sum ;
3175
3179
}
3176
3180
3177
- for (i = 0 ; i < pitch ; i ++ ) {
3181
+ for (i = 0 ; i < dst_pitch ; i ++ ) {
3178
3182
buf [i ] = 0.0 ;
3179
3183
buf2 [i ] = 0.0 ;
3180
3184
}
3181
3185
3182
3186
for (y = 0 ; y < h ; y ++ ) {
3183
3187
for (j = - radius ; j <= radius ; j ++ ) {
3184
- for (i = 0 ; i < pitch ; i ++ ) {
3188
+ for (i = 0 ; i < dst_pitch ; i ++ ) {
3185
3189
if (y + j >= 0 && y + j < h ) {
3186
- buf [i ] += (float )srcpx [pitch * (y + j ) + i ] * lut [abs (j )];
3190
+ buf [i ] +=
3191
+ (float )srcpx [src_pitch * (y + j ) + i ] * lut [abs (j )];
3187
3192
}
3188
3193
else if (repeat ) {
3189
3194
if (y + j < 0 ) {
3190
3195
buf [i ] += (float )srcpx [i ] * lut [abs (j )];
3191
3196
}
3192
3197
else {
3193
- buf [i ] +=
3194
- ( float ) srcpx [ pitch * ( h - 1 ) + i ] * lut [abs (j )];
3198
+ buf [i ] += ( float ) srcpx [ src_pitch * ( h - 1 ) + i ] *
3199
+ lut [abs (j )];
3195
3200
}
3196
3201
}
3197
3202
}
@@ -3216,8 +3221,8 @@ gaussian_blur(SDL_Surface *src, SDL_Surface *dst, int radius, SDL_bool repeat)
3216
3221
}
3217
3222
}
3218
3223
}
3219
- for (i = 0 ; i < pitch ; i ++ ) {
3220
- dstpx [pitch * y + i ] = (Uint8 )buf2 [i ];
3224
+ for (i = 0 ; i < dst_pitch ; i ++ ) {
3225
+ dstpx [dst_pitch * y + i ] = (Uint8 )buf2 [i ];
3221
3226
buf [i ] = 0.0 ;
3222
3227
buf2 [i ] = 0.0 ;
3223
3228
}
0 commit comments