From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: ffmpeg-devel@ffmpeg.org Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Subject: [FFmpeg-devel] [PATCH 5/7] avcodec/iff: Reindent after the previous commits Date: Tue, 12 Jul 2022 12:27:49 +0200 Message-ID: <DB6PR0101MB2214A066D27A2F26DF07A85A8F869@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com> (raw) In-Reply-To: <DB6PR0101MB2214E432F3B66D3F955C55668F869@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/iff.c | 260 +++++++++++++++++++++++------------------------ 1 file changed, 128 insertions(+), 132 deletions(-) diff --git a/libavcodec/iff.c b/libavcodec/iff.c index 453e910982..00d0105be3 100644 --- a/libavcodec/iff.c +++ b/libavcodec/iff.c @@ -207,7 +207,7 @@ static int extract_header(AVCodecContext *const avctx, IffContext *s = avctx->priv_data; const uint8_t *buf = extradata; unsigned buf_size = 0; - int i, palette_size; + int palette_size; if (extradata_size < 2) { av_log(avctx, AV_LOG_ERROR, "not enough extradata\n"); @@ -215,109 +215,109 @@ static int extract_header(AVCodecContext *const avctx, } palette_size = extradata_size - AV_RB16(extradata); - buf_size = bytestream_get_be16(&buf); - if (buf_size <= 1 || palette_size < 0) { - av_log(avctx, AV_LOG_ERROR, - "Invalid palette size received: %u -> palette data offset: %d\n", - buf_size, palette_size); - return AVERROR_INVALIDDATA; - } + buf_size = bytestream_get_be16(&buf); + if (buf_size <= 1 || palette_size < 0) { + av_log(avctx, AV_LOG_ERROR, + "Invalid palette size received: %u -> palette data offset: %d\n", + buf_size, palette_size); + return AVERROR_INVALIDDATA; + } if (buf_size < 41) return 0; - s->compression = bytestream_get_byte(&buf); - s->bpp = bytestream_get_byte(&buf); - s->ham = bytestream_get_byte(&buf); - s->flags = bytestream_get_byte(&buf); - s->transparency = bytestream_get_be16(&buf); - s->masking = bytestream_get_byte(&buf); - for (i = 0; i < 16; i++) - s->tvdc[i] = bytestream_get_be16(&buf); - - if (s->ham) { - if (s->bpp > 8) { - av_log(avctx, AV_LOG_ERROR, "Invalid number of hold bits for HAM: %u\n", s->ham); - return AVERROR_INVALIDDATA; - } else if (s->ham != (s->bpp > 6 ? 6 : 4)) { - av_log(avctx, AV_LOG_ERROR, "Invalid number of hold bits for HAM: %u, BPP: %u\n", s->ham, s->bpp); - return AVERROR_INVALIDDATA; - } + s->compression = bytestream_get_byte(&buf); + s->bpp = bytestream_get_byte(&buf); + s->ham = bytestream_get_byte(&buf); + s->flags = bytestream_get_byte(&buf); + s->transparency = bytestream_get_be16(&buf); + s->masking = bytestream_get_byte(&buf); + for (int i = 0; i < 16; i++) + s->tvdc[i] = bytestream_get_be16(&buf); + + if (s->ham) { + if (s->bpp > 8) { + av_log(avctx, AV_LOG_ERROR, "Invalid number of hold bits for HAM: %u\n", s->ham); + return AVERROR_INVALIDDATA; + } else if (s->ham != (s->bpp > 6 ? 6 : 4)) { + av_log(avctx, AV_LOG_ERROR, "Invalid number of hold bits for HAM: %u, BPP: %u\n", s->ham, s->bpp); + return AVERROR_INVALIDDATA; } + } - if (s->masking == MASK_HAS_MASK) { - if (s->bpp >= 8 && !s->ham) { - avctx->pix_fmt = AV_PIX_FMT_RGB32; - if (s->bpp > 16) { - av_log(avctx, AV_LOG_ERROR, "bpp %d too large for palette\n", s->bpp); - return AVERROR(ENOMEM); - } - s->mask_buf = av_malloc((s->planesize * 32) + AV_INPUT_BUFFER_PADDING_SIZE); - if (!s->mask_buf) - return AVERROR(ENOMEM); - s->mask_palbuf = av_malloc((2 << s->bpp) * sizeof(uint32_t) + AV_INPUT_BUFFER_PADDING_SIZE); - if (!s->mask_palbuf) - return AVERROR(ENOMEM); + if (s->masking == MASK_HAS_MASK) { + if (s->bpp >= 8 && !s->ham) { + avctx->pix_fmt = AV_PIX_FMT_RGB32; + if (s->bpp > 16) { + av_log(avctx, AV_LOG_ERROR, "bpp %d too large for palette\n", s->bpp); + return AVERROR(ENOMEM); } - s->bpp++; - } else if (s->masking != MASK_NONE && s->masking != MASK_HAS_TRANSPARENT_COLOR) { - av_log(avctx, AV_LOG_ERROR, "Masking not supported\n"); - return AVERROR_PATCHWELCOME; - } - if (!s->bpp || s->bpp > 32) { - av_log(avctx, AV_LOG_ERROR, "Invalid number of bitplanes: %u\n", s->bpp); - return AVERROR_INVALIDDATA; + s->mask_buf = av_malloc((s->planesize * 32) + AV_INPUT_BUFFER_PADDING_SIZE); + if (!s->mask_buf) + return AVERROR(ENOMEM); + s->mask_palbuf = av_malloc((2 << s->bpp) * sizeof(uint32_t) + AV_INPUT_BUFFER_PADDING_SIZE); + if (!s->mask_palbuf) + return AVERROR(ENOMEM); } - if (s->video_size && s->planesize * s->bpp * avctx->height > s->video_size) - return AVERROR_INVALIDDATA; + s->bpp++; + } else if (s->masking != MASK_NONE && s->masking != MASK_HAS_TRANSPARENT_COLOR) { + av_log(avctx, AV_LOG_ERROR, "Masking not supported\n"); + return AVERROR_PATCHWELCOME; + } + if (!s->bpp || s->bpp > 32) { + av_log(avctx, AV_LOG_ERROR, "Invalid number of bitplanes: %u\n", s->bpp); + return AVERROR_INVALIDDATA; + } + if (s->video_size && s->planesize * s->bpp * avctx->height > s->video_size) + return AVERROR_INVALIDDATA; - if (s->ham) { - int i, count = FFMIN(palette_size / 3, 1 << s->ham); - int ham_count; - const uint8_t *const palette = extradata + AV_RB16(extradata); - int extra_space = 1; + if (s->ham) { + int count = FFMIN(palette_size / 3, 1 << s->ham); + int ham_count; + const uint8_t *const palette = extradata + AV_RB16(extradata); + int extra_space = 1; - if (avctx->codec_tag == MKTAG('P', 'B', 'M', ' ') && s->ham == 4) - extra_space = 4; + if (avctx->codec_tag == MKTAG('P', 'B', 'M', ' ') && s->ham == 4) + extra_space = 4; - s->ham_buf = av_malloc((s->planesize * 8) + AV_INPUT_BUFFER_PADDING_SIZE); - if (!s->ham_buf) - return AVERROR(ENOMEM); + s->ham_buf = av_malloc((s->planesize * 8) + AV_INPUT_BUFFER_PADDING_SIZE); + if (!s->ham_buf) + return AVERROR(ENOMEM); - ham_count = 8 * (1 << s->ham); - s->ham_palbuf = av_malloc(extra_space * (ham_count << !!(s->masking == MASK_HAS_MASK)) * sizeof (uint32_t) + AV_INPUT_BUFFER_PADDING_SIZE); - if (!s->ham_palbuf) - return AVERROR(ENOMEM); + ham_count = 8 * (1 << s->ham); + s->ham_palbuf = av_malloc(extra_space * (ham_count << !!(s->masking == MASK_HAS_MASK)) * sizeof (uint32_t) + AV_INPUT_BUFFER_PADDING_SIZE); + if (!s->ham_palbuf) + return AVERROR(ENOMEM); - if (count) { // HAM with color palette attached - // prefill with black and palette and set HAM take direct value mask to zero - memset(s->ham_palbuf, 0, (1 << s->ham) * 2 * sizeof (uint32_t)); - for (i=0; i < count; i++) { - s->ham_palbuf[i*2+1] = 0xFF000000 | AV_RL24(palette + i*3); - } - count = 1 << s->ham; - } else { // HAM with grayscale color palette - count = 1 << s->ham; - for (i=0; i < count; i++) { - s->ham_palbuf[i*2] = 0xFF000000; // take direct color value from palette - s->ham_palbuf[i*2+1] = 0xFF000000 | av_le2ne32(gray2rgb((i * 255) >> s->ham)); - } - } - for (i=0; i < count; i++) { - uint32_t tmp = i << (8 - s->ham); - tmp |= tmp >> s->ham; - s->ham_palbuf[(i+count)*2] = 0xFF00FFFF; // just modify blue color component - s->ham_palbuf[(i+count*2)*2] = 0xFFFFFF00; // just modify red color component - s->ham_palbuf[(i+count*3)*2] = 0xFFFF00FF; // just modify green color component - s->ham_palbuf[(i+count)*2+1] = 0xFF000000 | tmp << 16; - s->ham_palbuf[(i+count*2)*2+1] = 0xFF000000 | tmp; - s->ham_palbuf[(i+count*3)*2+1] = 0xFF000000 | tmp << 8; + if (count) { // HAM with color palette attached + // prefill with black and palette and set HAM take direct value mask to zero + memset(s->ham_palbuf, 0, (1 << s->ham) * 2 * sizeof (uint32_t)); + for (int i = 0; i < count; i++) { + s->ham_palbuf[i*2+1] = 0xFF000000 | AV_RL24(palette + i*3); } - if (s->masking == MASK_HAS_MASK) { - for (i = 0; i < ham_count; i++) - s->ham_palbuf[(1 << s->bpp) + i] = s->ham_palbuf[i] | 0xFF000000; + count = 1 << s->ham; + } else { // HAM with grayscale color palette + count = 1 << s->ham; + for (int i = 0; i < count; i++) { + s->ham_palbuf[i*2] = 0xFF000000; // take direct color value from palette + s->ham_palbuf[i*2+1] = 0xFF000000 | av_le2ne32(gray2rgb((i * 255) >> s->ham)); } } + for (int i = 0; i < count; i++) { + uint32_t tmp = i << (8 - s->ham); + tmp |= tmp >> s->ham; + s->ham_palbuf[(i+count)*2] = 0xFF00FFFF; // just modify blue color component + s->ham_palbuf[(i+count*2)*2] = 0xFFFFFF00; // just modify red color component + s->ham_palbuf[(i+count*3)*2] = 0xFFFF00FF; // just modify green color component + s->ham_palbuf[(i+count)*2+1] = 0xFF000000 | tmp << 16; + s->ham_palbuf[(i+count*2)*2+1] = 0xFF000000 | tmp; + s->ham_palbuf[(i+count*3)*2+1] = 0xFF000000 | tmp << 8; + } + if (s->masking == MASK_HAS_MASK) { + for (int i = 0; i < ham_count; i++) + s->ham_palbuf[(1 << s->bpp) + i] = s->ham_palbuf[i] | 0xFF000000; + } + } return 0; } @@ -1470,57 +1470,53 @@ static int parse_packet_header(AVCodecContext *const avctx, GetByteContext *gb) { IffContext *s = avctx->priv_data; - int i; - - uint32_t chunk_id; - uint64_t data_size; if (avctx->codec_tag != MKTAG('A', 'N', 'I', 'M')) return 0; - bytestream2_skip(gb, 4); - while (bytestream2_get_bytes_left(gb) >= 1) { - chunk_id = bytestream2_get_le32(gb); - data_size = bytestream2_get_be32(gb); - - if (chunk_id == MKTAG('B', 'M', 'H', 'D')) { - bytestream2_skip(gb, data_size + (data_size & 1)); - } else if (chunk_id == MKTAG('A', 'N', 'H', 'D')) { - unsigned extra; - if (data_size < 40) - return AVERROR_INVALIDDATA; - - s->compression = (bytestream2_get_byte(gb) << 8) | (s->compression & 0xFF); - bytestream2_skip(gb, 19); - extra = bytestream2_get_be32(gb); - s->is_short = !(extra & 1); - s->is_brush = extra == 2; - s->is_interlaced = !!(extra & 0x40); - data_size -= 24; - bytestream2_skip(gb, data_size + (data_size & 1)); - } else if (chunk_id == MKTAG('D', 'L', 'T', 'A') || - chunk_id == MKTAG('B', 'O', 'D', 'Y')) { - if (chunk_id == MKTAG('B','O','D','Y')) - s->compression &= 0xFF; - break; - } else if (chunk_id == MKTAG('C', 'M', 'A', 'P')) { - int count = data_size / 3; - uint32_t *pal = s->pal; - - if (count > 256) - return AVERROR_INVALIDDATA; - if (s->ham) { - for (i = 0; i < count; i++) - pal[i] = 0xFF000000 | bytestream2_get_le24(gb); - } else { - for (i = 0; i < count; i++) - pal[i] = 0xFF000000 | bytestream2_get_be24(gb); - } - bytestream2_skip(gb, data_size & 1); + bytestream2_skip(gb, 4); + while (bytestream2_get_bytes_left(gb) >= 1) { + uint32_t chunk_id = bytestream2_get_le32(gb); + uint64_t data_size = bytestream2_get_be32(gb); + + if (chunk_id == MKTAG('B', 'M', 'H', 'D')) { + bytestream2_skip(gb, data_size + (data_size & 1)); + } else if (chunk_id == MKTAG('A', 'N', 'H', 'D')) { + unsigned extra; + if (data_size < 40) + return AVERROR_INVALIDDATA; + + s->compression = (bytestream2_get_byte(gb) << 8) | (s->compression & 0xFF); + bytestream2_skip(gb, 19); + extra = bytestream2_get_be32(gb); + s->is_short = !(extra & 1); + s->is_brush = extra == 2; + s->is_interlaced = !!(extra & 0x40); + data_size -= 24; + bytestream2_skip(gb, data_size + (data_size & 1)); + } else if (chunk_id == MKTAG('D', 'L', 'T', 'A') || + chunk_id == MKTAG('B', 'O', 'D', 'Y')) { + if (chunk_id == MKTAG('B','O','D','Y')) + s->compression &= 0xFF; + break; + } else if (chunk_id == MKTAG('C', 'M', 'A', 'P')) { + int count = data_size / 3; + uint32_t *pal = s->pal; + + if (count > 256) + return AVERROR_INVALIDDATA; + if (s->ham) { + for (int i = 0; i < count; i++) + pal[i] = 0xFF000000 | bytestream2_get_le24(gb); } else { - bytestream2_skip(gb, data_size + (data_size&1)); + for (int i = 0; i < count; i++) + pal[i] = 0xFF000000 | bytestream2_get_be24(gb); } + bytestream2_skip(gb, data_size & 1); + } else { + bytestream2_skip(gb, data_size + (data_size&1)); } + } return 0; } -- 2.34.1 _______________________________________________ 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".
next prev parent reply other threads:[~2022-07-12 10:28 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-07-12 10:26 [FFmpeg-devel] [PATCH 1/7] avcodec/iff: Split extract_header into extradata and packet part Andreas Rheinhardt 2022-07-12 10:27 ` [FFmpeg-devel] [PATCH 2/7] avcodec/iff: Avoid redundant frees Andreas Rheinhardt 2022-07-12 10:27 ` [FFmpeg-devel] [PATCH 3/7] avcodec/iff: Return early when possible Andreas Rheinhardt 2022-07-12 10:27 ` [FFmpeg-devel] [PATCH 4/7] avcodec/iff: Pass extradata and extradata_size explicitly Andreas Rheinhardt 2022-07-12 10:27 ` Andreas Rheinhardt [this message] 2022-07-12 10:27 ` [FFmpeg-devel] [PATCH 6/7] avcodec/iff: Remove transient objects from the context Andreas Rheinhardt 2022-07-12 10:27 ` [FFmpeg-devel] [PATCH 7/7] avcodec/iff: Use unsigned to avoid compiler warning Andreas Rheinhardt 2022-09-15 0:52 ` [FFmpeg-devel] [PATCH 1/7] avcodec/iff: Split extract_header into extradata and packet part Andreas Rheinhardt
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=DB6PR0101MB2214A066D27A2F26DF07A85A8F869@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com \ --to=andreas.rheinhardt@outlook.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git