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 34FF844189 for ; Fri, 30 Sep 2022 17:05:54 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5224E68BBDF; Fri, 30 Sep 2022 20:05:53 +0300 (EEST) Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03olkn2035.outbound.protection.outlook.com [40.92.58.35]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0248368B9A5 for ; Fri, 30 Sep 2022 20:05:47 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Rt7NWvOm+Z5GN5W+H8LfH0uo3Blun11pgqEkdu9Q5pbFW8cVJm59Dv+m2MEBFx+Umj0X6iscJX4m4amrl3mEzYD5nxrQZh463nrbi9XYfA9Fwt7uYaxI0nqVsqfmavSbXIPfsEvlchiASvQO6+XVVeIwt3h4cNMpH/tc5F5l1GY/wnOHNZx/lL3xqlr1Pz5GfpeJ/u8eKR8YN8SdHsw1mYtL5iZ755rjZiinYiqtDWbLOjMXTXD8IvJ4Ku/R1tQ/iyglXaqAZkOer2G5Eg0MkTuLmAPmvyBbjC2fuopPgFUMugRvG1pvV8nrlA6q9x53a3P6F6U7ItTedpKGci/6Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=nbM1H1+ouE8tBqXKZVb1O5eZk8S04raVeaLFkXx8E7o=; b=H6RUb7+0u6NCm3aFs6RemOYxTqwFsa2RgWNDDsKC+yFf/I+FpOMiXIaFMQGW/ZM25N33ftiv4IUNX1T9dLN4zkhj3srzNVsSrQ0rpdLIlZKu72MtbBQfHZOIiCN7qNQbkmvsEzHlOykpuADqSoBMTeuh8Om/GgFP4gKck8fK8UPy2AhhndevQTzkG0nhmJ90itDMgJJ/P9wzekoPWasrhWIoBmKxs7DJxrX3utBB7UBIiouaLhv1b/aR009c7z5e18zNeVR44442z2V2b8Ym8ND60X5HeYQdCGfopswom9YzWhiXGfqO8dQdtoD6KkMzbry9TIgJ7JdAD0WAFXNRDA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nbM1H1+ouE8tBqXKZVb1O5eZk8S04raVeaLFkXx8E7o=; b=GFb8tMoJ3x0pmuKdigW5NJqF+4iKc4VCCg/HEULmqToO3TgepzrCv/KlmWKsCIsu3G5c9aUMJKt96Z1JcWp79Q0CSZUIA5V9n+ysI7A3Ttk0pg1I+pSoBu+wrb3a30I+BuhUZyZSHcIEd5juWuSBmajHqNoLS6nJAmkycz7+SWAFJD67gY5NfKlcYGwXspCaDJ4niICAij0ymHuzuF1mMpJuSxXyIbVUtpWTT/1LL/ob87KxwOzgmx55avAGsUQ00vQirNFSutpcp5fru9E4sXPhmTUMnS97tSw9HvJHwJDrEMrOGlPnA3FTNmWibx6AC0b3ChgSlA6FaTpnShcWCw== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by DU2P250MB0175.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:274::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.23; Fri, 30 Sep 2022 17:05:44 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::68bd:2fc7:ac52:38f8]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::68bd:2fc7:ac52:38f8%9]) with mapi id 15.20.5654.025; Fri, 30 Sep 2022 17:05:44 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 30 Sep 2022 19:05:11 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [5yWnDAi2dTevinxYI600RQ/atEUKW5LV] X-ClientProxiedBy: FR3P281CA0040.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:4a::8) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20220930170515.3648239-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|DU2P250MB0175:EE_ X-MS-Office365-Filtering-Correlation-Id: 33e91fc6-7dcb-4142-a121-08daa3060312 X-MS-Exchange-SLBlob-MailProps: AZnQBsB9XmrST/aUJU0/QUaXtXS9lKwz9oqnCCrrhFxmgAFStPK3D30N2RRGwoKkJmDldelXvMGhnUBF8HQLv7BzPgpgIEcjvLX4N01gWyY853l6tLEcrnyjgY7uPHdxod065TATPk3uvkCO306r4YGBKQtRgRz1czqjtgyyv84iGUxENUl3qbeJ0qwyzaJvadmi54iN+OGaanJanaIx8NUwBYKhQiTcqJ6VqnxIBicUacXnPd17FIRqnMWG2kl8UF6jdSujft7fZ1Ckxi73TLMD1U/YMBZGLsKVSCOv3mtYD+GhITKswhhxFX1XEQo4u5Kb8gU77XLLIiNGX4DHwBemtvYJWgqY21R7x3+sJoFly4vriBacm8JQ6H/6lbe9cqScR+L1mEXIsMQlM0WcV6k0nUvz/Q+sx5O9jNsROyesZYL4mh4Qy2nzNPVlD70OnF/oc4LfFHCIi+vgFWQU9ATVteZN40LZrtk/BQ7Syq6fWpBQp3rL13ZaX9uaoAaPk+y9nN/zsfQPzN8tJSRkfEvS8xLie5QFVTGzw3Ynfy2lCCTUnmbkO7HwCs+JP7L94Ma9FzOrG+Yh6Dd93NpkmybG3FCpo43RUt8S5y07UZDVYrWwZ6whi1Kfrv0xoN8rTV8HAduJlO61jgZOPIrUZQRNQKihqFDdIeRGVcmiW4Pyku9pBwhVvhcxE2U3Bo8Bofx86Yj/29tZBn99aEA7gu7fl+xRCUBGESBH+DImMHcmMzINno3vGvyiXWsb9jqLviutclNFobA= X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sHb/425AByVLpcYbv4KFgwet3PVa5vGWB2q0P7vQT8ytKx13AJdenDx3x2zZOc9EQlonjJ8zLR+vMYieMwXrP5XA5nYTU9YYclPvNP19F4QLytppidUiS5Rfg0YTK76il1X+vtOHFW0bxvytmjDrVvNmewPAfF8cs/xbzdLUiRTYartk2KJxdpmatAqWApuT8IEp6b8H0LK6p9f7UT7EGTIEoc2cBfeVCehughFDuYWs491OllXOAKp76x7kxdl+8HHvVU4dJU/SHPmgdpSOWyxArJV5MUBxygjl5PIltlYag7OPfSi9bGHbeOKaXb++Q0h8oMo7KtN0OEAqtbzSiEr6S6rn7HIOoGroMOAje9pzkQROZej1S3ZMPduzhRxPs4/eB+0oljpdVmdwKHpz1ST0aBvHr5Bh46finTvu27edC2Qj7Ija478ks+e1mQ+125co4qV5InzU392HqQ8cvc3JJYhiU+CgeEJ6nx/uh5NMzbDprB0alJVEt8BfIgQ8c0Cmd0nfXODjeElPQmLmOUkB4uKzSdA/el+2b/4aXux1xgz8k+ni6EXHLG4hRV/70cUKj2rbNmwRI4MqwjzpzeYF+CX9vd1H2eBYSTSbcTzqD+Vx48daBq0G/M3L9OUPxP3ljxU+cB+LaASro6RISw== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?j+qRJ7QeG+XwU6hl4Ui8prIgy4mcxPzo0Oc+nSXKOnVdtxONfgbPsq76Tx9S?= =?us-ascii?Q?Jmxc5M0xN7vZaSS/dMvwC2mUjYjH8qgyi9sYRjp4wZIDWHn9JDGf4yv2ecss?= =?us-ascii?Q?RYnPV+b42KYFNnb3KFPczqqN3TgGIB8O+asFrJ3cXX4yUBqDQlh4XlvoTNPv?= =?us-ascii?Q?Yu6+KaXfEzhtegQTfKcCuh5r7eIL6wWXp5EV4mce2vI8E/OGGwyvhSyjivSj?= =?us-ascii?Q?J3RRlFKCH555iSN6zn+0yz1NGSMYLsNZ1pzczjECWaxJsB79yJgEiFWCMzqY?= =?us-ascii?Q?gBzwn18Aa1bdPpKlIgQqtC1r3b5stfNraTM1xIeWFBOpoECKkS4BPr78RC6h?= =?us-ascii?Q?0E69rB/2taIGqwb177GvDAAsdQJ6dnXKX9RBRkHQbbKvBdXP/fICZuPgXBVc?= =?us-ascii?Q?bKNvMWUFaoPiDXqilgMt7qfCPp7BSQ92V/IKdfvdP6emdpQBBnAQjOrwyrVA?= =?us-ascii?Q?P5ghOF6QDDMP8R3PC+FcWJFW3no2jPkjdTR/+NJ1AN5Q4vOgtRDiwH6anb2u?= =?us-ascii?Q?sxUOtwv3ayaeUp6FKB6KHmJvB7PfgtI/05zkoHB9Z4lzL6fS24vqxOMZMmJm?= =?us-ascii?Q?pZpbnyyb03D8Gl0W9G1xyb1oPX2oHqiqEcVBhJya/FmJhi1IXRtLU/eD58lw?= =?us-ascii?Q?QPL6Nl/kz6MtGKGrx7bIPPsj4IB2PZpIstIgG9FcaYX7D5L89GYCqk7zW6Fw?= =?us-ascii?Q?++RxO/jMwvnnlXtmYDvu5wTZrBnkIAP97j+uokjCJ+VA8T/N7/axc0kw0Fj/?= =?us-ascii?Q?ftSsvKeLvIhu4XDTE5h/W/fBUZCgWRFkf3wBC3QrN/recqrB3K5n4FIAUWXY?= =?us-ascii?Q?DoHh4RiqamdP82wdTKaC5e40OnrLG9xyYwspKm4RRmNq9sJrFDuBnAWaB3uF?= =?us-ascii?Q?exIepnUI3mSrqzK+dae68kTOC+0op7iDQXsnjChbSN3k29udoJw2CdeuAOWV?= =?us-ascii?Q?JM6xuEXvrffDTV3RtuNgNWj9uF72qhQTow9+gTO26LZNGaeKBRmubUNIyE74?= =?us-ascii?Q?OS0eHZnzw7AeihMrzjxiM/na0CjGDJU5a/rYju4vl8iOx+L6JaeYsn4f310q?= =?us-ascii?Q?5/CqCe3kd9QIWejvQXNflXMXhCJMwfh+hAKd7NBmuq9nqaL8UwYQU9MObLZI?= =?us-ascii?Q?DYcrTixS06SUTO8akOGjj2sb1/LSW004M7zFzqHRGn1x6Q/s//Y3LWJnEvAM?= =?us-ascii?Q?vZJU59InWq/6MebuNivi3vS+qj2NPqN6l0HN02Bz5hju1J89nbeuv77M8WQX?= =?us-ascii?Q?9f6OlsLQsNCHl7jAPXYyqZsR4hfB2+oiAzCx4jzApTNUcrH3OxQaEZcOAAnC?= =?us-ascii?Q?n+w=3D?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 33e91fc6-7dcb-4142-a121-08daa3060312 X-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2022 17:05:44.5061 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2P250MB0175 Subject: [FFmpeg-devel] [PATCH 3/7] avcodec/sgidec: Avoid redundant private context 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 Cc: Andreas Rheinhardt 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: SGI is intra-frame only; the decoder therefore does not maintain any state between frames, so remove the private context. Also rename depth to nb_components. Signed-off-by: Andreas Rheinhardt --- libavcodec/sgidec.c | 158 ++++++++++++++++++++------------------------ 1 file changed, 73 insertions(+), 85 deletions(-) diff --git a/libavcodec/sgidec.c b/libavcodec/sgidec.c index a449859bf8..bd49a3510d 100644 --- a/libavcodec/sgidec.c +++ b/libavcodec/sgidec.c @@ -25,25 +25,17 @@ #include "decode.h" #include "sgi.h" -typedef struct SgiState { - AVCodecContext *avctx; - unsigned int width; - int height; - unsigned int depth; - unsigned int bytes_per_channel; - int linesize; - GetByteContext g; -} SgiState; - /** * Expand an RLE row into a channel. - * @param s the current image state + * @param logctx a logcontext * @param out_buf Points to one line after the output buffer. + * @param g GetByteContext used to read input from * @param len length of out_buf in bytes * @param pixelstride pixel stride of input buffer * @return size of output in bytes, else return error code. */ -static int expand_rle_row8(SgiState *s, uint8_t *out_buf, +static int expand_rle_row8(void *logctx, uint8_t *out_buf, + GetByteContext *g, int len, int pixelstride) { unsigned char pixel, count; @@ -51,26 +43,26 @@ static int expand_rle_row8(SgiState *s, uint8_t *out_buf, uint8_t *out_end = out_buf + len; while (out_buf < out_end) { - if (bytestream2_get_bytes_left(&s->g) < 1) + if (bytestream2_get_bytes_left(g) < 1) return AVERROR_INVALIDDATA; - pixel = bytestream2_get_byteu(&s->g); + pixel = bytestream2_get_byteu(g); if (!(count = (pixel & 0x7f))) { break; } /* Check for buffer overflow. */ if (out_end - out_buf <= pixelstride * (count - 1)) { - av_log(s->avctx, AV_LOG_ERROR, "Invalid pixel count.\n"); + av_log(logctx, AV_LOG_ERROR, "Invalid pixel count.\n"); return AVERROR_INVALIDDATA; } if (pixel & 0x80) { while (count--) { - *out_buf = bytestream2_get_byte(&s->g); + *out_buf = bytestream2_get_byte(g); out_buf += pixelstride; } } else { - pixel = bytestream2_get_byte(&s->g); + pixel = bytestream2_get_byte(g); while (count--) { *out_buf = pixel; @@ -81,7 +73,8 @@ static int expand_rle_row8(SgiState *s, uint8_t *out_buf, return (out_buf - orig) / pixelstride; } -static int expand_rle_row16(SgiState *s, uint16_t *out_buf, +static int expand_rle_row16(void *logctx, uint16_t *out_buf, + GetByteContext *g, int len, int pixelstride) { unsigned short pixel; @@ -90,26 +83,26 @@ static int expand_rle_row16(SgiState *s, uint16_t *out_buf, uint16_t *out_end = out_buf + len; while (out_buf < out_end) { - if (bytestream2_get_bytes_left(&s->g) < 2) + if (bytestream2_get_bytes_left(g) < 2) return AVERROR_INVALIDDATA; - pixel = bytestream2_get_be16u(&s->g); + pixel = bytestream2_get_be16u(g); if (!(count = (pixel & 0x7f))) break; /* Check for buffer overflow. */ if (out_end - out_buf <= pixelstride * (count - 1)) { - av_log(s->avctx, AV_LOG_ERROR, "Invalid pixel count.\n"); + av_log(logctx, AV_LOG_ERROR, "Invalid pixel count.\n"); return AVERROR_INVALIDDATA; } if (pixel & 0x80) { while (count--) { - pixel = bytestream2_get_ne16(&s->g); + pixel = bytestream2_get_ne16(g); AV_WN16A(out_buf, pixel); out_buf += pixelstride; } } else { - pixel = bytestream2_get_ne16(&s->g); + pixel = bytestream2_get_ne16(g); while (count--) { AV_WN16A(out_buf, pixel); @@ -127,34 +120,38 @@ static int expand_rle_row16(SgiState *s, uint16_t *out_buf, * @param s the current image state * @return 0 if no error, else return error code. */ -static int read_rle_sgi(uint8_t *last_line, SgiState *s) +static int read_rle_sgi(void *logctx, uint8_t *last_line, GetByteContext *g, + ptrdiff_t stride, unsigned width, unsigned height, + unsigned nb_components, unsigned bytes_per_channel) { uint8_t *dest_row; - unsigned int len = s->height * s->depth * 4; - GetByteContext g_table = s->g; + unsigned int len = height * nb_components * 4; + GetByteContext g_table = *g; unsigned int start_offset; int linesize, ret; /* size of RLE offset and length tables */ - if (len * 2 > bytestream2_get_bytes_left(&s->g)) { + if (len * 2 > bytestream2_get_bytes_left(g)) { return AVERROR_INVALIDDATA; } - for (unsigned z = 0; z < s->depth; z++) { + for (unsigned z = 0; z < nb_components; z++) { dest_row = last_line; - for (int remaining_lines = s->height;;) { - linesize = s->width * s->depth; + for (unsigned remaining_lines = height;;) { + linesize = width * nb_components; start_offset = bytestream2_get_be32(&g_table); - bytestream2_seek(&s->g, start_offset, SEEK_SET); - if (s->bytes_per_channel == 1) - ret = expand_rle_row8(s, dest_row + z, linesize, s->depth); + bytestream2_seek(g, start_offset, SEEK_SET); + if (bytes_per_channel == 1) + ret = expand_rle_row8(logctx, dest_row + z, g, + linesize, nb_components); else - ret = expand_rle_row16(s, (uint16_t *)dest_row + z, linesize, s->depth); - if (ret != s->width) + ret = expand_rle_row16(logctx, (uint16_t *)dest_row + z, g, + linesize, nb_components); + if (ret != width) return AVERROR_INVALIDDATA; if (--remaining_lines == 0) break; - dest_row -= s->linesize; + dest_row -= stride; } } return 0; @@ -166,33 +163,34 @@ static int read_rle_sgi(uint8_t *last_line, SgiState *s) * @param s the current image state * @return 0 if read success, else return error code. */ -static int read_uncompressed_sgi(unsigned char *out_buf, SgiState *s) +static int read_uncompressed_sgi(unsigned char *out_buf, GetByteContext *g, + ptrdiff_t stride, unsigned width, unsigned height, + unsigned nb_components, unsigned bytes_per_channel) { - int x, y, z; - unsigned int offset = s->height * s->width * s->bytes_per_channel; + unsigned int offset = height * width * bytes_per_channel; GetByteContext gp[4]; uint8_t *out_end; /* Test buffer size. */ - if (offset * s->depth > bytestream2_get_bytes_left(&s->g)) + if (offset * nb_components > bytestream2_get_bytes_left(g)) return AVERROR_INVALIDDATA; /* Create a reader for each plane */ - for (z = 0; z < s->depth; z++) { - gp[z] = s->g; + for (unsigned z = 0; z < nb_components; z++) { + gp[z] = *g; bytestream2_skip(&gp[z], z * offset); } - for (y = s->height - 1; y >= 0; y--) { - out_end = out_buf + (y * s->linesize); - if (s->bytes_per_channel == 1) { - for (x = s->width; x > 0; x--) - for (z = 0; z < s->depth; z++) + for (int y = height - 1; y >= 0; y--) { + out_end = out_buf + y * stride; + if (bytes_per_channel == 1) { + for (unsigned x = width; x > 0; x--) + for (unsigned z = 0; z < nb_components; z++) *out_end++ = bytestream2_get_byteu(&gp[z]); } else { uint16_t *out16 = (uint16_t *)out_end; - for (x = s->width; x > 0; x--) - for (z = 0; z < s->depth; z++) + for (unsigned x = width; x > 0; x--) + for (unsigned z = 0; z < nb_components; z++) *out16++ = bytestream2_get_ne16u(&gp[z]); } } @@ -202,31 +200,32 @@ static int read_uncompressed_sgi(unsigned char *out_buf, SgiState *s) static int decode_frame(AVCodecContext *avctx, AVFrame *p, int *got_frame, AVPacket *avpkt) { - SgiState *s = avctx->priv_data; - unsigned int dimension, rle; + GetByteContext g; + unsigned int bytes_per_channel, nb_components, dimension, rle, width; + int height; int ret = 0; uint8_t *out_buf, *last_line; - bytestream2_init(&s->g, avpkt->data, avpkt->size); - if (bytestream2_get_bytes_left(&s->g) < SGI_HEADER_SIZE) { + bytestream2_init(&g, avpkt->data, avpkt->size); + if (bytestream2_get_bytes_left(&g) < SGI_HEADER_SIZE) { av_log(avctx, AV_LOG_ERROR, "buf_size too small (%d)\n", avpkt->size); return AVERROR_INVALIDDATA; } /* Test for SGI magic. */ - if (bytestream2_get_be16u(&s->g) != SGI_MAGIC) { + if (bytestream2_get_be16u(&g) != SGI_MAGIC) { av_log(avctx, AV_LOG_ERROR, "bad magic number\n"); return AVERROR_INVALIDDATA; } - rle = bytestream2_get_byteu(&s->g); - s->bytes_per_channel = bytestream2_get_byteu(&s->g); - dimension = bytestream2_get_be16u(&s->g); - s->width = bytestream2_get_be16u(&s->g); - s->height = bytestream2_get_be16u(&s->g); - s->depth = bytestream2_get_be16u(&s->g); + rle = bytestream2_get_byteu(&g); + bytes_per_channel = bytestream2_get_byteu(&g); + dimension = bytestream2_get_be16u(&g); + width = bytestream2_get_be16u(&g); + height = bytestream2_get_be16u(&g); + nb_components = bytestream2_get_be16u(&g); - if (s->bytes_per_channel != 1 && s->bytes_per_channel != 2) { + if (bytes_per_channel != 1 && bytes_per_channel != 2) { av_log(avctx, AV_LOG_ERROR, "wrong channel number\n"); return AVERROR_INVALIDDATA; } @@ -237,18 +236,18 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p, return AVERROR_INVALIDDATA; } - if (s->depth == SGI_GRAYSCALE) { - avctx->pix_fmt = s->bytes_per_channel == 2 ? AV_PIX_FMT_GRAY16BE : AV_PIX_FMT_GRAY8; - } else if (s->depth == SGI_RGB) { - avctx->pix_fmt = s->bytes_per_channel == 2 ? AV_PIX_FMT_RGB48BE : AV_PIX_FMT_RGB24; - } else if (s->depth == SGI_RGBA) { - avctx->pix_fmt = s->bytes_per_channel == 2 ? AV_PIX_FMT_RGBA64BE : AV_PIX_FMT_RGBA; + if (nb_components == SGI_GRAYSCALE) { + avctx->pix_fmt = bytes_per_channel == 2 ? AV_PIX_FMT_GRAY16BE : AV_PIX_FMT_GRAY8; + } else if (nb_components == SGI_RGB) { + avctx->pix_fmt = bytes_per_channel == 2 ? AV_PIX_FMT_RGB48BE : AV_PIX_FMT_RGB24; + } else if (nb_components == SGI_RGBA) { + avctx->pix_fmt = bytes_per_channel == 2 ? AV_PIX_FMT_RGBA64BE : AV_PIX_FMT_RGBA; } else { av_log(avctx, AV_LOG_ERROR, "wrong picture format\n"); return AVERROR_INVALIDDATA; } - ret = ff_set_dimensions(avctx, s->width, s->height); + ret = ff_set_dimensions(avctx, width, height); if (ret < 0) return ret; @@ -259,16 +258,16 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p, p->key_frame = 1; out_buf = p->data[0]; - last_line = out_buf + p->linesize[0] * (s->height - 1); - - s->linesize = p->linesize[0]; + last_line = out_buf + p->linesize[0] * (height - 1); /* Skip header. */ - bytestream2_seek(&s->g, SGI_HEADER_SIZE, SEEK_SET); + bytestream2_seek(&g, SGI_HEADER_SIZE, SEEK_SET); if (rle) { - ret = read_rle_sgi(last_line, s); + ret = read_rle_sgi(avctx, last_line, &g, p->linesize[0], + width, height, nb_components, bytes_per_channel); } else { - ret = read_uncompressed_sgi(out_buf, s); + ret = read_uncompressed_sgi(out_buf, &g, p->linesize[0], + width, height, nb_components, bytes_per_channel); } if (ret) return ret; @@ -277,22 +276,11 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p, return avpkt->size; } -static av_cold int sgi_decode_init(AVCodecContext *avctx) -{ - SgiState *s = avctx->priv_data; - - s->avctx = avctx; - - return 0; -} - const FFCodec ff_sgi_decoder = { .p.name = "sgi", CODEC_LONG_NAME("SGI image"), .p.type = AVMEDIA_TYPE_VIDEO, .p.id = AV_CODEC_ID_SGI, - .priv_data_size = sizeof(SgiState), FF_CODEC_DECODE_CB(decode_frame), - .init = sgi_decode_init, .p.capabilities = AV_CODEC_CAP_DR1, }; -- 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".