@@ -115,12 +115,9 @@ vips_rank_stop(void *vseq, void *a, void *b)
115
115
VIPS_FREE (seq -> sort );
116
116
117
117
if (seq -> hist &&
118
- in ) {
119
- int i ;
120
-
121
- for (i = 0 ; i < in -> Bands ; i ++ )
118
+ in )
119
+ for (int i = 0 ; i < in -> Bands ; i ++ )
122
120
VIPS_FREE (seq -> hist [i ]);
123
- }
124
121
VIPS_FREE (seq -> hist );
125
122
126
123
return 0 ;
@@ -147,17 +144,13 @@ vips_rank_start(VipsImage *out, void *a, void *b)
147
144
}
148
145
149
146
if (rank -> hist_path ) {
150
- int i ;
151
-
152
- if (!(seq -> hist =
153
- VIPS_ARRAY (NULL , in -> Bands , unsigned int * ))) {
147
+ if (!(seq -> hist = VIPS_ARRAY (NULL , in -> Bands , unsigned int * ))) {
154
148
vips_rank_stop (seq , in , rank );
155
149
return NULL ;
156
150
}
157
151
158
- for (i = 0 ; i < in -> Bands ; i ++ )
159
- if (!(seq -> hist [i ] =
160
- VIPS_ARRAY (NULL , 256 , unsigned int ))) {
152
+ for (int i = 0 ; i < in -> Bands ; i ++ )
153
+ if (!(seq -> hist [i ] = VIPS_ARRAY (NULL , 256 , unsigned int ))) {
161
154
vips_rank_stop (seq , in , rank );
162
155
return NULL ;
163
156
}
@@ -175,62 +168,58 @@ vips_rank_generate_uchar(VipsRegion *out_region,
175
168
VipsImage * in = seq -> ir -> im ;
176
169
VipsRect * r = & out_region -> valid ;
177
170
const int bands = in -> Bands ;
178
- const int last = bands * ( rank -> width - 1 );
171
+ const int lsk = VIPS_REGION_LSKIP ( seq -> ir );
179
172
180
173
/* Get input and output pointers for this line.
181
174
*/
182
- VipsPel * restrict p =
183
- VIPS_REGION_ADDR (seq -> ir , r -> left , r -> top + y );
184
- VipsPel * restrict q =
185
- VIPS_REGION_ADDR (out_region , r -> left , r -> top + y );
175
+ VipsPel * restrict p = VIPS_REGION_ADDR (seq -> ir , r -> left , r -> top + y );
176
+ VipsPel * restrict q = VIPS_REGION_ADDR (out_region , r -> left , r -> top + y );
186
177
187
178
VipsPel * restrict p1 ;
188
- int lsk ;
189
- int x , i , j , b ;
190
-
191
- lsk = VIPS_REGION_LSKIP (seq -> ir );
192
179
193
180
/* Find histogram for the first output pixel.
194
181
*/
195
- for (b = 0 ; b < bands ; b ++ )
182
+ for (int b = 0 ; b < bands ; b ++ )
196
183
memset (seq -> hist [b ], 0 , 256 * sizeof (unsigned int ));
197
184
p1 = p ;
198
- for (j = 0 ; j < rank -> height ; j ++ ) {
199
- for (i = 0 , x = 0 ; x < rank -> width ; x ++ )
200
- for (b = 0 ; b < bands ; b ++ , i ++ )
185
+ for (int j = 0 ; j < rank -> height ; j ++ ) {
186
+ int i ;
187
+
188
+ i = 0 ;
189
+ for (int x = 0 ; x < rank -> width ; x ++ )
190
+ for (int b = 0 ; b < bands ; b ++ , i ++ )
201
191
seq -> hist [b ][p1 [i ]] += 1 ;
202
192
203
193
p1 += lsk ;
204
194
}
205
195
206
196
/* Loop for output pels.
207
197
*/
208
- for (x = 0 ; x < r -> width ; x ++ ) {
209
- for (b = 0 ; b < bands ; b ++ ) {
198
+ for (int x = 0 ; x < r -> width ; x ++ ) {
199
+ for (int b = 0 ; b < bands ; b ++ ) {
210
200
/* Calculate cumulative histogram -- the value is the
211
201
* index at which we pass the rank.
212
202
*/
213
203
unsigned int * restrict hist = seq -> hist [b ];
214
204
215
205
int sum ;
216
- int i ;
217
-
206
+ int value ;
218
207
sum = 0 ;
219
- for (i = 0 ; i < 256 ; i ++ ) {
220
- sum += hist [i ];
208
+ for (value = 0 ; value < 256 ; value ++ ) {
209
+ sum += hist [value ];
221
210
if (sum > rank -> index )
222
211
break ;
223
212
}
224
- q [b ] = i ;
213
+ q [b ] = value ;
225
214
226
- /* Adapt histogram -- remove the pels from
227
- * the left hand column, add in pels for a
228
- * new right-hand column.
215
+ /* Adapt histogram -- remove the pels from the left hand column,
216
+ * add in pels for a new right-hand column.
229
217
*/
218
+ const int next = bands * rank -> width ;
230
219
p1 = p + b ;
231
- for (j = 0 ; j < rank -> height ; j ++ ) {
220
+ for (int j = 0 ; j < rank -> height ; j ++ ) {
232
221
hist [p1 [0 ]] -= 1 ;
233
- hist [p1 [last ]] += 1 ;
222
+ hist [p1 [next ]] += 1 ;
234
223
235
224
p1 += lsk ;
236
225
}
@@ -437,7 +426,7 @@ vips_rank_generate(VipsRegion *out_region,
437
426
VipsRect s ;
438
427
int ls ;
439
428
440
- int x , y ;
429
+ int x ;
441
430
int i , j , k ;
442
431
int upper , lower , mid ;
443
432
@@ -451,7 +440,7 @@ vips_rank_generate(VipsRegion *out_region,
451
440
return -1 ;
452
441
ls = VIPS_REGION_LSKIP (ir ) / VIPS_IMAGE_SIZEOF_ELEMENT (in );
453
442
454
- for (y = 0 ; y < r -> height ; y ++ ) {
443
+ for (int y = 0 ; y < r -> height ; y ++ ) {
455
444
if (rank -> hist_path )
456
445
vips_rank_generate_uchar (out_region , seq , rank , y );
457
446
else if (rank -> index == 0 )
@@ -492,7 +481,8 @@ vips_rank_build(VipsObject *object)
492
481
return -1 ;
493
482
}
494
483
rank -> n = rank -> width * rank -> height ;
495
- if (rank -> index < 0 || rank -> index > rank -> n - 1 ) {
484
+ if (rank -> index < 0 ||
485
+ rank -> index > rank -> n - 1 ) {
496
486
vips_error (class -> nickname , "%s" , _ ("index out of range" ));
497
487
return -1 ;
498
488
}
0 commit comments