From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 2290946571 for ; Tue, 16 Jul 2024 17:17:13 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0E02E68DA83; Tue, 16 Jul 2024 20:16:41 +0300 (EEST) Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9BBFE68D918 for ; Tue, 16 Jul 2024 20:16:31 +0300 (EEST) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=DtwdwGWl; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 195504E13 for ; Tue, 16 Jul 2024 19:16:30 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id ih--nmnolcQa for ; Tue, 16 Jul 2024 19:16:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150186; bh=x2haSI6SIJQwLj8sQBfXkMJXYWgs//6BrasNXQb1fEw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=DtwdwGWle9bsBNdWtCbihkVz413yozTgQpqyF5wt+P36rDOKLrX9L8TdUVwE0JRUf y1gPTj9U0OtOmB/w6NKmAePoMXatVAPHD4VaE12PvbbdsPK5J6QRGGsORESXrWJvBZ XM3FHTdQjbAu2k6vjOKC6CeY9RltFGiYeV5D9l+3hpGzZFnbrcDMo+J7lyFCAhHeAr EQ81OoXpSyjn6sUDMQ/FDfdFCje6/01O4z3ksgKYSuutltRcBUQtHy3UlCQE89chxF sOl82XCBWTvOaR5tlt5utbF8HG5xZKC18kVvYWbcuH/XHn0mDglQzq+QjYHymEKxF7 uF6empSiMTxcw== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 8CD44998 for ; Tue, 16 Jul 2024 19:16:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 3E08A3A031C for ; Tue, 16 Jul 2024 19:16:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:17 +0200 Message-ID: <20240716171155.31838-2-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/39] lavc/ffv1dec: declare loop variables in the loop where possible X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --- libavcodec/ffv1dec.c | 45 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 7a0d1909aa..5c515e97b6 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -46,7 +46,7 @@ static inline av_flatten int get_symbol_inline(RangeCoder *c, uint8_t *state, if (get_rac(c, state + 0)) return 0; else { - int i, e; + int e; unsigned a; e = 0; while (get_rac(c, state + 1 + FFMIN(e, 9))) { // 1..10 @@ -56,7 +56,7 @@ static inline av_flatten int get_symbol_inline(RangeCoder *c, uint8_t *state, } a = 1; - for (i = e - 1; i >= 0; i--) + for (int i = e - 1; i >= 0; i--) a += a + get_rac(c, state + 22 + FFMIN(i, 9)); // 22..31 e = -(is_signed && get_rac(c, state + 11 + FFMIN(e, 10))); // 11..21 @@ -167,7 +167,7 @@ static int decode_slice_header(const FFV1Context *f, FFV1Context *fs) { RangeCoder *c = &fs->c; uint8_t state[CONTEXT_SIZE]; - unsigned ps, i, context_count; + unsigned ps, context_count; int sx, sy, sw, sh; memset(state, 128, sizeof(state)); @@ -197,7 +197,7 @@ static int decode_slice_header(const FFV1Context *f, FFV1Context *fs) if (fs->ac == AC_GOLOMB_RICE && fs->slice_width >= (1<<23)) return AVERROR_INVALIDDATA; - for (i = 0; i < f->plane_count; i++) { + for (unsigned i = 0; i < f->plane_count; i++) { PlaneContext * const p = &fs->plane[i]; int idx = get_symbol(c, state, 0); if (idx >= (unsigned)f->quant_table_count) { @@ -259,7 +259,7 @@ static int decode_slice(AVCodecContext *c, void *arg) int width, height, x, y, ret; const int ps = av_pix_fmt_desc_get(c->pix_fmt)->comp[0].step; AVFrame * const p = f->cur; - int i, si; + int si; for( si=0; fs != f->slice_context[si]; si ++) ; @@ -276,7 +276,7 @@ static int decode_slice(AVCodecContext *c, void *arg) if (!(p->flags & AV_FRAME_FLAG_KEY)) fsdst->slice_damaged |= fssrc->slice_damaged; - for (i = 0; i < f->plane_count; i++) { + for (int i = 0; i < f->plane_count; i++) { PlaneContext *psrc = &fssrc->plane[i]; PlaneContext *pdst = &fsdst->plane[i]; @@ -424,7 +424,7 @@ static int read_extra_header(FFV1Context *f) { RangeCoder *const c = &f->c; uint8_t state[CONTEXT_SIZE]; - int i, j, k, ret; + int ret; uint8_t state2[32][CONTEXT_SIZE]; unsigned crc = 0; @@ -453,7 +453,7 @@ static int read_extra_header(FFV1Context *f) f->ac = get_symbol(c, state, 0); if (f->ac == AC_RANGE_CUSTOM_TAB) { - for (i = 1; i < 256; i++) + for (int i = 1; i < 256; i++) f->state_transition[i] = get_symbol(c, state, 1) + c->one_state[i]; } @@ -492,7 +492,7 @@ static int read_extra_header(FFV1Context *f) return AVERROR_INVALIDDATA; } - for (i = 0; i < f->quant_table_count; i++) { + for (int i = 0; i < f->quant_table_count; i++) { f->context_count[i] = read_quant_tables(c, f->quant_tables[i]); if (f->context_count[i] < 0) { av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n"); @@ -502,10 +502,10 @@ static int read_extra_header(FFV1Context *f) if ((ret = ff_ffv1_allocate_initial_states(f)) < 0) return ret; - for (i = 0; i < f->quant_table_count; i++) + for (int i = 0; i < f->quant_table_count; i++) if (get_rac(c, state)) { - for (j = 0; j < f->context_count[i]; j++) - for (k = 0; k < CONTEXT_SIZE; k++) { + for (int j = 0; j < f->context_count[i]; j++) + for (int k = 0; k < CONTEXT_SIZE; k++) { int pred = j ? f->initial_states[i][j - 1][k] : 128; f->initial_states[i][j][k] = (pred + get_symbol(c, state2[k], 1)) & 0xFF; @@ -550,7 +550,7 @@ static int read_extra_header(FFV1Context *f) static int read_header(FFV1Context *f) { uint8_t state[CONTEXT_SIZE]; - int i, j, context_count = -1; //-1 to avoid warning + int context_count = -1; //-1 to avoid warning RangeCoder *const c = &f->slice_context[0]->c; memset(state, 128, sizeof(state)); @@ -566,7 +566,7 @@ static int read_header(FFV1Context *f) f->ac = get_symbol(c, state, 0); if (f->ac == AC_RANGE_CUSTOM_TAB) { - for (i = 1; i < 256; i++) { + for (int i = 1; i < 256; i++) { int st = get_symbol(c, state, 1) + c->one_state[i]; if (st < 1 || st > 255) { av_log(f->avctx, AV_LOG_ERROR, "invalid state transition %d\n", st); @@ -790,7 +790,7 @@ static int read_header(FFV1Context *f) return AVERROR_INVALIDDATA; } - for (j = 0; j < f->slice_count; j++) { + for (int j = 0; j < f->slice_count; j++) { FFV1Context *fs = f->slice_context[j]; fs->ac = f->ac; fs->packed_at_lsb = f->packed_at_lsb; @@ -819,7 +819,7 @@ static int read_header(FFV1Context *f) && (unsigned)fs->slice_y + (uint64_t)fs->slice_height <= f->height); } - for (i = 0; i < f->plane_count; i++) { + for (int i = 0; i < f->plane_count; i++) { PlaneContext *const p = &fs->plane[i]; if (f->version == 2) { @@ -874,7 +874,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, int buf_size = avpkt->size; FFV1Context *f = avctx->priv_data; RangeCoder *const c = &f->slice_context[0]->c; - int i, ret, key_frame; + int ret, key_frame; uint8_t keystate = 128; uint8_t *buf_p; AVFrame *p; @@ -908,6 +908,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, } else { int w = avctx->width; int s = 1 + w / (1<<23); + int i; w /= s; @@ -941,7 +942,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, ff_thread_finish_setup(avctx); buf_p = buf + buf_size; - for (i = f->slice_count - 1; i >= 0; i--) { + for (int i = f->slice_count - 1; i >= 0; i--) { FFV1Context *fs = f->slice_context[i]; int trailer = 3 + 5*!!f->ec; int v; @@ -991,15 +992,14 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, f->slice_count, sizeof(void*)); - for (i = f->slice_count - 1; i >= 0; i--) { + for (int i = f->slice_count - 1; i >= 0; i--) { FFV1Context *fs = f->slice_context[i]; - int j; if (fs->slice_damaged && f->last_picture.f) { const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt); const uint8_t *src[4]; uint8_t *dst[4]; ff_progress_frame_await(&f->last_picture, INT_MAX); - for (j = 0; j < desc->nb_components; j++) { + for (int j = 0; j < desc->nb_components; j++) { int pixshift = desc->comp[j].depth > 8; int sh = (j == 1 || j == 2) ? f->chroma_h_shift : 0; int sv = (j == 1 || j == 2) ? f->chroma_v_shift : 0; @@ -1064,7 +1064,6 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) { FFV1Context *fsrc = src->priv_data; FFV1Context *fdst = dst->priv_data; - int i; if (dst == src) return 0; @@ -1075,7 +1074,7 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) sizeof(fdst->state_transition)); memcpy(fdst->quant_table, fsrc->quant_table, sizeof(fsrc->quant_table)); - for (i = 0; i < fdst->num_h_slices * fdst->num_v_slices; i++) { + for (int i = 0; i < fdst->num_h_slices * fdst->num_v_slices; i++) { FFV1Context *fssrc = fsrc->slice_context[i]; FFV1Context *fsdst = fdst->slice_context[i]; copy_fields(fsdst, fssrc, fsrc); -- 2.43.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".