History

avfilter/drawutils: narrow variable scopes

Marvin Scholz committed 2 years ago

Commit 0ea83e61 parent d0bcf621 file · +39 −46Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/drawutils.c+39−46
@@ -48,8 +48,7 @@ static int fill_map(const AVPixFmtDescriptor *desc, uint8_t *map) · 47 unmodified lines
4848 } else {
4949 int had0 = 0;
5050 unsigned depthb = 0;
51− unsigned i;
52− for (i = 0; i < desc->nb_components; i++) {
51+ for (unsigned i = 0; i < desc->nb_components; i++) {
5352 /* all components must have same depth in bytes */
5453 unsigned db = (desc->comp[i].depth + 7) / 8;
5554 unsigned pos = desc->comp[i].offset / db;
@@ -100,7 +99,7 @@ int ff_draw_init2(FFDrawContext *draw, enum AVPixelFormat format, enum AVColorSp · 44 unmodified lines
10099 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(format);
101100 const AVLumaCoefficients *luma = NULL;
102101 const AVComponentDescriptor *c;
103− unsigned i, nb_planes = 0;
102+ unsigned nb_planes = 0;
104103 int pixelstep[MAX_PLANES] = { 0 };
105104 int depthb = 0;
106105
@@ -121,7 +120,7 @@ int ff_draw_init2(FFDrawContext *draw, enum AVPixelFormat format, enum AVColorSp · 14 unmodified lines
121120 ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
122121 if (range != AVCOL_RANGE_JPEG && range != AVCOL_RANGE_MPEG)
123122 return AVERROR(EINVAL);
124− for (i = 0; i < desc->nb_components; i++) {
123+ for (unsigned i = 0; i < desc->nb_components; i++) {
125124 int db;
126125 c = &desc->comp[i];
127126 /* for now, only 8-16 bits formats */
@@ -172,7 +171,6 @@ int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags) · 44 unmodified lines
172171
173172 void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
174173 {
175− unsigned i;
176174 double yuvad[4];
177175 double rgbad[4];
178176 const AVPixFmtDescriptor *desc = draw->desc;
@@ -206,7 +204,7 @@ void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4 · 27 unmodified lines
206204 if (desc->nb_components <= 2)
207205 yuvad[1] = yuvad[3];
208206
209− for (i = 0; i < desc->nb_components; i++) {
207+ for (unsigned i = 0; i < desc->nb_components; i++) {
210208 unsigned val = yuvad[i] * ((1 << (draw->desc->comp[i].depth + draw->desc->comp[i].shift)) - 1) + 0.5;
211209 if (desc->comp[i].depth > 8)
212210 color->comp[desc->comp[i].plane].u16[desc->comp[i].offset / 2] = val;
@@ -229,15 +227,15 @@ void ff_copy_rectangle2(FFDrawContext *draw, · 16 unmodified lines
229227 int dst_x, int dst_y, int src_x, int src_y,
230228 int w, int h)
231229 {
232− int plane, y, wp, hp;
230+ int wp, hp;
233231 uint8_t *p, *q;
234232
235− for (plane = 0; plane < draw->nb_planes; plane++) {
233+ for (int plane = 0; plane < draw->nb_planes; plane++) {
236234 p = pointer_at(draw, src, src_linesize, plane, src_x, src_y);
237235 q = pointer_at(draw, dst, dst_linesize, plane, dst_x, dst_y);
238236 wp = AV_CEIL_RSHIFT(w, draw->hsub[plane]) * draw->pixelstep[plane];
239237 hp = AV_CEIL_RSHIFT(h, draw->vsub[plane]);
240− for (y = 0; y < hp; y++) {
238+ for (int y = 0; y < hp; y++) {
241239 memcpy(q, p, wp);
242240 p += src_linesize[plane];
243241 q += dst_linesize[plane];
@@ -249,11 +247,11 @@ void ff_fill_rectangle(FFDrawContext *draw, FFDrawColor *color, · 5 unmodified lines
249247 uint8_t *dst[], int dst_linesize[],
250248 int dst_x, int dst_y, int w, int h)
251249 {
252− int plane, x, y, wp, hp;
250+ int wp, hp;
253251 uint8_t *p0, *p;
254252 FFDrawColor color_tmp = *color;
255253
256− for (plane = 0; plane < draw->nb_planes; plane++) {
254+ for (int plane = 0; plane < draw->nb_planes; plane++) {
257255 p0 = pointer_at(draw, dst, dst_linesize, plane, dst_x, dst_y);
258256 wp = AV_CEIL_RSHIFT(w, draw->hsub[plane]);
259257 hp = AV_CEIL_RSHIFT(h, draw->vsub[plane]);
@@ -262,19 +260,19 @@ void ff_fill_rectangle(FFDrawContext *draw, FFDrawColor *color, · 2 unmodified lines
262260 p = p0;
263261
264262 if (HAVE_BIGENDIAN && draw->desc->comp[0].depth > 8) {
265− for (x = 0; 2*x < draw->pixelstep[plane]; x++)
263+ for (int x = 0; 2*x < draw->pixelstep[plane]; x++)
266264 color_tmp.comp[plane].u16[x] = av_bswap16(color_tmp.comp[plane].u16[x]);
267265 }
268266
269267 /* copy first line from color */
270− for (x = 0; x < wp; x++) {
268+ for (int x = 0; x < wp; x++) {
271269 memcpy(p, color_tmp.comp[plane].u8, draw->pixelstep[plane]);
272270 p += draw->pixelstep[plane];
273271 }
274272 wp *= draw->pixelstep[plane];
275273 /* copy next lines from first line */
276274 p = p0 + dst_linesize[plane];
277− for (y = 1; y < hp; y++) {
275+ for (int y = 1; y < hp; y++) {
278276 memcpy(p, p0, wp);
279277 p += dst_linesize[plane];
280278 }
@@ -325,14 +323,13 @@ static void blend_line(uint8_t *dst, unsigned src, unsigned alpha, · 44 unmodified lines
325323 {
326324 unsigned asrc = alpha * src;
327325 unsigned tau = 0x1010101 - alpha;
328− int x;
329326
330327 if (left) {
331328 unsigned suba = (left * alpha) >> hsub;
332329 *dst = (*dst * (0x1010101 - suba) + src * suba) >> 24;
333330 dst += dx;
334331 }
335− for (x = 0; x < w; x++) {
332+ for (int x = 0; x < w; x++) {
336333 *dst = (*dst * tau + asrc) >> 24;
337334 dst += dx;
338335 }
@@ -347,7 +344,6 @@ static void blend_line16(uint8_t *dst, unsigned src, unsigned alpha, · 8 unmodified lines
347344 {
348345 unsigned asrc = alpha * src;
349346 unsigned tau = 0x10001 - alpha;
350− int x;
351347
352348 if (left) {
353349 unsigned suba = (left * alpha) >> hsub;
@@ -355,7 +351,7 @@ static void blend_line16(uint8_t *dst, unsigned src, unsigned alpha, · 1 unmodified line
355351 AV_WL16(dst, (value * (0x10001 - suba) + src * suba) >> 16);
356352 dst += dx;
357353 }
358− for (x = 0; x < w; x++) {
354+ for (int x = 0; x < w; x++) {
359355 uint16_t value = AV_RL16(dst);
360356 AV_WL16(dst, (value * tau + asrc) >> 16);
361357 dst += dx;
@@ -372,8 +368,8 @@ void ff_blend_rectangle(FFDrawContext *draw, FFDrawColor *color, · 10 unmodified lines
372368 int dst_w, int dst_h,
373369 int x0, int y0, int w, int h)
374370 {
375− unsigned alpha, nb_planes, nb_comp, plane, comp;
376− int w_sub, h_sub, x_sub, y_sub, left, right, top, bottom, y;
371+ unsigned alpha, nb_planes, nb_comp;
372+ int w_sub, h_sub, x_sub, y_sub, left, right, top, bottom;
377373 uint8_t *p0, *p;
378374
379375 nb_comp = draw->desc->nb_components -
@@ -393,7 +389,7 @@ void ff_blend_rectangle(FFDrawContext *draw, FFDrawColor *color, · 13 unmodified lines
393389 }
394390 nb_planes = draw->nb_planes - !!(draw->desc->flags & AV_PIX_FMT_FLAG_ALPHA && !(draw->flags & FF_DRAW_PROCESS_ALPHA));
395391 nb_planes += !nb_planes;
396− for (plane = 0; plane < nb_planes; plane++) {
392+ for (unsigned plane = 0; plane < nb_planes; plane++) {
397393 p0 = pointer_at(draw, dst, dst_linesize, plane, x0, y0);
398394 w_sub = w;
399395 h_sub = h;
@@ -401,7 +397,7 @@ void ff_blend_rectangle(FFDrawContext *draw, FFDrawColor *color, · 1 unmodified line
401397 y_sub = y0;
402398 subsampling_bounds(draw->hsub[plane], &x_sub, &w_sub, &left, &right);
403399 subsampling_bounds(draw->vsub[plane], &y_sub, &h_sub, &top, &bottom);
404− for (comp = 0; comp < nb_comp; comp++) {
400+ for (unsigned comp = 0; comp < nb_comp; comp++) {
405401 const int depth = draw->desc->comp[comp].depth;
406402 const int offset = draw->desc->comp[comp].offset;
407403 const int index = offset / ((depth + 7) / 8);
@@ -422,14 +418,14 @@ void ff_blend_rectangle(FFDrawContext *draw, FFDrawColor *color, · 14 unmodified lines
422418 p += dst_linesize[plane];
423419 }
424420 if (depth <= 8) {
425− for (y = 0; y < h_sub; y++) {
421+ for (int y = 0; y < h_sub; y++) {
426422 blend_line(p, color->comp[plane].u8[index], alpha,
427423 draw->pixelstep[plane], w_sub,
428424 draw->hsub[plane], left, right);
429425 p += dst_linesize[plane];
430426 }
431427 } else {
432− for (y = 0; y < h_sub; y++) {
428+ for (int y = 0; y < h_sub; y++) {
433429 blend_line16(p, color->comp[plane].u16[index], alpha,
434430 draw->pixelstep[plane], w_sub,
435431 draw->hsub[plane], left, right);
@@ -455,16 +451,16 @@ static void blend_pixel16(uint8_t *dst, unsigned src, unsigned alpha, · 19 unmodified lines
455451 const uint8_t *mask, int mask_linesize, int l2depth,
456452 unsigned w, unsigned h, unsigned shift, unsigned xm0)
457453 {
458− unsigned xm, x, y, t = 0;
454+ unsigned t = 0;
459455 unsigned xmshf = 3 - l2depth;
460456 unsigned xmmod = 7 >> l2depth;
461457 unsigned mbits = (1 << (1 << l2depth)) - 1;
462458 unsigned mmult = 255 / mbits;
463459 uint16_t value = AV_RL16(dst);
464460
465− for (y = 0; y < h; y++) {
466− xm = xm0;
467− for (x = 0; x < w; x++) {
461+ for (unsigned y = 0; y < h; y++) {
462+ unsigned xm = xm0;
463+ for (unsigned x = 0; x < w; x++) {
468464 t += ((mask[xm >> xmshf] >> ((~xm & xmmod) << l2depth)) & mbits)
469465 * mmult;
470466 xm++;
@@ -479,15 +475,15 @@ static void blend_pixel(uint8_t *dst, unsigned src, unsigned alpha, · 8 unmodified lines
479475 const uint8_t *mask, int mask_linesize, int l2depth,
480476 unsigned w, unsigned h, unsigned shift, unsigned xm0)
481477 {
482− unsigned xm, x, y, t = 0;
478+ unsigned t = 0;
483479 unsigned xmshf = 3 - l2depth;
484480 unsigned xmmod = 7 >> l2depth;
485481 unsigned mbits = (1 << (1 << l2depth)) - 1;
486482 unsigned mmult = 255 / mbits;
487483
488− for (y = 0; y < h; y++) {
489− xm = xm0;
490− for (x = 0; x < w; x++) {
484+ for (unsigned y = 0; y < h; y++) {
485+ unsigned xm = xm0;
486+ for (unsigned x = 0; x < w; x++) {
491487 t += ((mask[xm >> xmshf] >> ((~xm & xmmod) << l2depth)) & mbits)
492488 * mmult;
493489 xm++;
@@ -504,7 +500,6 @@ static void blend_line_hv16(uint8_t *dst, int dst_delta, · 10 unmodified lines
504500 unsigned hsub, unsigned vsub,
505501 int xm, int left, int right, int hband)
506502 {
507− int x;
508503
509504 if (left) {
510505 blend_pixel16(dst, src, alpha, mask, mask_linesize, l2depth,
@@ -512,7 +507,7 @@ static void blend_line_hv16(uint8_t *dst, int dst_delta, · 1 unmodified line
512507 dst += dst_delta;
513508 xm += left;
514509 }
515− for (x = 0; x < w; x++) {
510+ for (int x = 0; x < w; x++) {
516511 blend_pixel16(dst, src, alpha, mask, mask_linesize, l2depth,
517512 1 << hsub, hband, hsub + vsub, xm);
518513 dst += dst_delta;
@@ -529,7 +524,6 @@ static void blend_line_hv(uint8_t *dst, int dst_delta, · 10 unmodified lines
529524 unsigned hsub, unsigned vsub,
530525 int xm, int left, int right, int hband)
531526 {
532− int x;
533527
534528 if (left) {
535529 blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
@@ -537,7 +531,7 @@ static void blend_line_hv(uint8_t *dst, int dst_delta, · 1 unmodified line
537531 dst += dst_delta;
538532 xm += left;
539533 }
540− for (x = 0; x < w; x++) {
534+ for (int x = 0; x < w; x++) {
541535 blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
542536 1 << hsub, hband, hsub + vsub, xm);
543537 dst += dst_delta;
@@ -553,9 +547,9 @@ void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color, · 9 unmodified lines
553547 const uint8_t *mask, int mask_linesize, int mask_w, int mask_h,
554548 int l2depth, unsigned endianness, int x0, int y0)
555549 {
556− unsigned alpha, nb_planes, nb_comp, plane, comp;
557− int xm0, ym0, w_sub, h_sub, x_sub, y_sub, left, right, top, bottom, y;
558− uint8_t *p0, *p;
550+ unsigned alpha, nb_planes, nb_comp;
551+ int xm0, ym0, w_sub, h_sub, x_sub, y_sub, left, right, top, bottom;
552+ uint8_t *p;
559553 const uint8_t *m;
560554
561555 nb_comp = draw->desc->nb_components -
@@ -575,15 +569,15 @@ void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color, · 13 unmodified lines
575569 }
576570 nb_planes = draw->nb_planes - !!(draw->desc->flags & AV_PIX_FMT_FLAG_ALPHA && !(draw->flags & FF_DRAW_PROCESS_ALPHA));
577571 nb_planes += !nb_planes;
578− for (plane = 0; plane < nb_planes; plane++) {
579− p0 = pointer_at(draw, dst, dst_linesize, plane, x0, y0);
572+ for (unsigned plane = 0; plane < nb_planes; plane++) {
573+ uint8_t *p0 = pointer_at(draw, dst, dst_linesize, plane, x0, y0);
580574 w_sub = mask_w;
581575 h_sub = mask_h;
582576 x_sub = x0;
583577 y_sub = y0;
584578 subsampling_bounds(draw->hsub[plane], &x_sub, &w_sub, &left, &right);
585579 subsampling_bounds(draw->vsub[plane], &y_sub, &h_sub, &top, &bottom);
586− for (comp = 0; comp < nb_comp; comp++) {
580+ for (unsigned comp = 0; comp < nb_comp; comp++) {
587581 const int depth = draw->desc->comp[comp].depth;
588582 const int offset = draw->desc->comp[comp].offset;
589583 const int index = offset / ((depth + 7) / 8);
@@ -610,7 +604,7 @@ void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color, · 20 unmodified lines
610604 m += top * mask_linesize;
611605 }
612606 if (depth <= 8) {
613− for (y = 0; y < h_sub; y++) {
607+ for (int y = 0; y < h_sub; y++) {
614608 blend_line_hv(p, draw->pixelstep[plane],
615609 color->comp[plane].u8[index], alpha,
616610 m, mask_linesize, l2depth, w_sub,
@@ -620,7 +614,7 @@ void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color, · 3 unmodified lines
620614 m += mask_linesize << draw->vsub[plane];
621615 }
622616 } else {
623− for (y = 0; y < h_sub; y++) {
617+ for (int y = 0; y < h_sub; y++) {
624618 blend_line_hv16(p, draw->pixelstep[plane],
625619 color->comp[plane].u16[index], alpha,
626620 m, mask_linesize, l2depth, w_sub,
@@ -663,12 +657,11 @@ int ff_draw_round_to_sub(FFDrawContext *draw, int sub_dir, int round_dir, · 36 unmodified lines
663657
664658 AVFilterFormats *ff_draw_supported_pixel_formats(unsigned flags)
665659 {
666− enum AVPixelFormat i;
667660 FFDrawContext draw;
668661 AVFilterFormats *fmts = NULL;
669662 int ret;
670663
671− for (i = 0; av_pix_fmt_desc_get(i); i++)
664+ for (enum AVPixelFormat i = 0; av_pix_fmt_desc_get(i); i++)
672665 if (ff_draw_init(&draw, i, flags) >= 0 &&
673666 (ret = ff_add_format(&fmts, i)) < 0)
674667 return NULL;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t