From patchwork Fri Sep 30 17:05:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 38482 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp1839652pzh; Fri, 30 Sep 2022 10:06:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7L3zjVI6Th6eZ5pL6TXcXOV9UmT9ZBWs3FxImf965Bh8qWXTNdazRlog1TBLdKvnEDe4xF X-Received: by 2002:a05:6402:538f:b0:444:c17b:1665 with SMTP id ew15-20020a056402538f00b00444c17b1665mr8713018edb.98.1664557565208; Fri, 30 Sep 2022 10:06:05 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id k17-20020a1709060cb100b007316843d58bsi1758387ejh.925.2022.09.30.10.06.04; Fri, 30 Sep 2022 10:06:05 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b="TL/3xzZZ"; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 685C268BBF0; Fri, 30 Sep 2022 20:05:58 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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 28A0268BA02 for ; Fri, 30 Sep 2022 20:05:52 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AX0Gqs7tLrKIfl01QDWWTEzVAuvdCbatVzq8aPBuA9N+i9DoAlgFSRJoIpVYNr6As7MWenazqtPyj4n3a38lTIMMKD0RgkrMkggJcYLnDbNiUUvP9ipkqO3EOypHhhYTzW0FbSUD/bEUy7B6hsNC8LB7npT8qeYfneDIKVDtQbkAfYJ69bEV8w/6sAH3aHKICv0uhRXAFAtRUZ3B6lD+cYFrPOuwzMWrNA718Gm5aW8xDmhF5Zs/UvjHpdd7zqZARz5r4DgkhlGhygiVXRoa1q+VY4NfHy5BRvBKZXWKKu8IThgVJtWd2ICgnvTBoguIQn03KZeC5mMJTakZ/RaMHw== 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=ooabRpLAZ9079T3bPi8aA1KilBEljaU/khs1lq1gxds=; b=W29k1/UliDq2LrhcDaomaiuzCti7iUgKWd0pnoVPK8IgE1V5yDVNu0zN3s0Ccs1Ey0m/4WiWv0SHPorMgK7xVKQi55WfY225HBFS9K7CGw1YFhcjl3GX6etzMwgS1qjsXF6scrp5gKb0dWOHMp5oxFHMlspX25bAIyF3D/hNg9fZeCbldAjdEIeJadJLY+4JLZ5SPG+bIiQhF5m3Y+NLLj3W5bHf+9wWCCfcONrLXR6p84DGl72yK1o3sxCMyoqAjVi0oPVnP4A9UH98+GZqqn1AcTy+b29WqEbbUhL5Uj8Fe18b7KPWDGWafhdL5HHsI7zAgv5dCaAj2Gu8Z/HqbQ== 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=ooabRpLAZ9079T3bPi8aA1KilBEljaU/khs1lq1gxds=; b=TL/3xzZZpHL4nlDWcPEd1DUeTeHSnyh8wEb3/U6JSXh3KAvqL/3MCUycsqCAGHq5zV6DJS1xrvSZaxETckohmZZg4fiO/UFn0BMdbhaZziCnMxCxc5QEWWB35ykJOsipIbMe81JiawHlWo5SA22Ud3h86KYbrqtxsTZ/WkXTlfU30QQ7uF9iI8IVJZf1ZI+XE0TcZLcPV/Aww+KKNUXa5C99rw4EbjAs2ADj+uwcsQbRcVmlaGySY/zeE6t+Y1vEA5FzDkIfl3GXxRV9+Z5gkh1otv3gs+qrlnZrNEzJtGvQqqSXybYgdZiGqVD2aBxziMOywppJxsqnE2Widm03Zg== 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:45 +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:45 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 30 Sep 2022 19:05:12 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [QT7znFn8a8eUInof+hE9RTO0+zWZ2qYR] 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-3-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: b9f175da-e6f2-44d6-a909-08daa30603a1 X-MS-Exchange-SLBlob-MailProps: feAVlmA1hHWt4DLVZWJFH70LntyHTKMV6NQiUfVccTvF4F1I8Bor5HjCZrOj6TPvAYkF/UAv0QU/xbI9UevWwQFgRMrGUC1lYkAwmHZA3A2+7P+u5DWT0SHbH0vML3L097zUvr5hw7TUcjZm7UibhySzKYvaOQ+i12WturvK4+4kM6wSmM/KDG8AJ7T9/paYh4EnSLyQq3L+Tt4kNQuiJUeZOP43u3MIvvYuDocea9a19nx9r5mFTLEhIl1laHEQkmglsdo4PUtimpEppgZIK58GnZ0ZS8mdPCERWk71Llh+PZTRlX1BLZOa8tgDBvK7roDwZicgYPK2u1o9MEBrbefaxKgT6c/ymgNoIyErLfbdh4NYA7NMAWNmz0wV10lj3U7wQTadl0Cbu/5/k+nG5LuObUTzHX8ONA0CNhtmXtID5ibbpBl93e+WRhuVadJvEKFojqohWN1SkTmkPvh7X0ZIppRDJYuBH/Ec8Mhl8dPu89CZRUTjILoSwS51EFocAcKcCxqGHTMSrxfgPdOu3mdi7BlyOMusnnfEH1VJoKWSuPTi4ul5Lu10iSR6V0xoYAnCGb/XGOjF/fhX//MmBD50voEUY/LGKAa9uVjz93AlKlDzPDedMWcRKONa7/KA5K26wIgT2c1RosjNfvamtiljrZmvIuO5OLfVdebk7HhVyedqFv+BAPUyhD6hsKTbDM66Mvm+moByrkcFX2KRnA== X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VKzf+PtRaoesIRIF5krmrXEvvifwYeXFGQwk3kjkUbTtBPK0+mEPqfhP526hdCKfDawUKi5supp/SiEah1/t6L2HSNG+DyRHTjgUC5xlT0mAuNCqmSLLC1w0aH1o5L4c3cpCqZQqT/wV7fT8ChA0IYVtg7P3+N6aQIOJIuGNZRsCVynpnXONBXNEMudkPWtygzcRX+sl/kHWQIZV4kUPje/5bEMiuRPuniQfAMKd8lOdborlofOpdSMCUsQjQdPaeeP8xgEM3VrScMkUKNSv2jFPRWh/ar3mpTDIt2jHnQgNl5vlCeNFJDwJ/kCc9oF25i24V4/qJOLMKPrKgCTrb7PqOKs5UVMNxf4P7S7U+3pI0etGWaBj56ZKnFU4XDCKBZFELxRaGhKrmGpOF62vy9T9XlfwkvemXdoUtWh+9XOjr5tIKWebboyXZiSc6Gd2qh0zDtTqmf0ieAuTheAhN23x82tBYDZ0TgmlqZwvNa2D7eV82hST4qGnkULaNsoTssYPzPp5HxJ7dKRhPmjfCPTFzFIn+1SXk+5Y8cs2INXwOat+73s1YNjow4QAcs57o+sk8m8leNPQa1OlMhhSaDPFH9OZ9nqwTl6Cr+6IQC5HN9Rvb+qUhOJZpeYT1HFN7koeFh1w1q44r4mfECimCQ== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: mtE+VL5Yf/nB2+cpJ9zOAi8sXjYyP8X6z6KAMbRswtuy36y+/jPW9rA/2LafY63OSwWgTgM/YQjV7qYsYx/Uatm76r3kkqu9Nm3muY+P+Wl9pKkApV+FMip2wHL+FwOp2m5OdDEHq4IlP2JmhzdXcBwkPE7gqkdVnBsFDdsDIco/QxbM6qdyyn2hnrk5GMkl83eAiNtTX9ny4rViUSgyrAvHgCVgd37HdvKCs58jNfrepc6OKiGloC6YJz8oOtDcA9N56HQ8+Nawitn9Bygn30KvGlF8MpBcbQyk2cfqKY/Sv7M/NJ7pWW3wkIHJ6y0ECYKvuUwLYttLCE4csaMxLbzZJmLJ9Ng0a4aN/y5J0B6Grc/zC0TAo682LMFMHfw5A2aZq4XhnKvGTjPQP0fu2is+LYnKwuovt2w7afV5dDW3+kQzvDVWuKS6isWA4xoEsEmbfiwMPPOcQjF7znVMhTro1a3Nal/xGKFhOXAgswQoy1GIOPNrzrPBaQIC+YgSrT64YcZJycpdNeRD59YE7IJ+5D3ZhUUF1IXcdWcoj9YjxSA3Osrn0a64/In0UBtl04jnqhH6pGxLrS5nzOXWA109TKL3IAvbAezAjvUFSWHPfCmS3VtXt4yaWVBJE7Ga64EszcZwYCOXN+MGjn+FbHj63eHmWjiuq/k2tcAcN2PL6rNLUoVLI5iyx7G2V0gH7mrAxvChiFS1xWb2xKblQmW4urIFAZakxWoxjTaClHKNsQlm0eQ6XR5weaFDAn5qQZiCdoEMQ6WPDrv3Y0P1htN1qSUUvcqL+MYNf8Y7JoNt48Ig6QdOlw2OrviG+2/XUPB7AD4NgWn+Wwgx+zyX+zo8Baf0UK/rgHXlnHpyrlnbihCAQmpkCR1RkPQ4x8KrvmZ8r6LDssAL1ERjQ7eEQscI/GuRglAPl22ePtqQzFlRaa6MRnqW9GWQTC317dODlgkArt6XwFzXmhHOOQ2+jTJz6WSz5eAUT2/QrErAj9ZJr1lsxA3tqoaQI+hNaLN1fgXIdXXeIdroHtRiFZfsK9jItLfxEjVFEpnWU2TUpHL49+H5LHYeH33iM3OyLaoO9TUGa5HAGvkgqoQgwR5E8xz2yJJzB2C7IruIGyZ3JThrOtVm7XhsQuaEM4zfTXYMTEamlJTJe7qSux9I8fvyOfggV6fgJhsQjdu3HomoS6D0soUkzLd8pPsG2FVBVt4ECsgNz0Jkv83YMQAmoJaY7G+YF0cFRVIxjaOG1zkG7W0xd3CGtE9k9jtcAX5uYnq3/RgmuhAPD01McJXHfHI/f9yinUEF4uU3vs/6cR47yZc= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: b9f175da-e6f2-44d6-a909-08daa30603a1 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:45.4446 (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 4/7] avcodec/sgidec: Use planar pixel formats 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: PiIRAxOWc1Jk The data in SGI images is stored planar, so exporting it via planar pixel formats is natural. Signed-off-by: Andreas Rheinhardt --- libavcodec/sgidec.c | 123 ++++++++++++++++------------------ tests/ref/fate/sgi-rgb24 | 2 +- tests/ref/fate/sgi-rgb24-rle | 2 +- tests/ref/fate/sgi-rgb48 | 2 +- tests/ref/fate/sgi-rgb48-rle | 2 +- tests/ref/fate/sgi-rgba | 2 +- tests/ref/fate/sgi-rgba-rle | 2 +- tests/ref/fate/sgi-rgba64 | 2 +- tests/ref/fate/sgi-rgba64-rle | 2 +- tests/ref/lavf/sgi | 2 +- 10 files changed, 66 insertions(+), 75 deletions(-) diff --git a/libavcodec/sgidec.c b/libavcodec/sgidec.c index bd49a3510d..6ff2ee97f6 100644 --- a/libavcodec/sgidec.c +++ b/libavcodec/sgidec.c @@ -30,17 +30,15 @@ * @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. + * @param width length of out_buf in nb of elements + * @return nb of elements written, else return error code. */ static int expand_rle_row8(void *logctx, uint8_t *out_buf, - GetByteContext *g, - int len, int pixelstride) + GetByteContext *g, unsigned width) { unsigned char pixel, count; unsigned char *orig = out_buf; - uint8_t *out_end = out_buf + len; + uint8_t *out_end = out_buf + width; while (out_buf < out_end) { if (bytestream2_get_bytes_left(g) < 1) @@ -51,36 +49,31 @@ static int expand_rle_row8(void *logctx, uint8_t *out_buf, } /* Check for buffer overflow. */ - if (out_end - out_buf <= pixelstride * (count - 1)) { + if (out_end - out_buf < count) { av_log(logctx, AV_LOG_ERROR, "Invalid pixel count.\n"); return AVERROR_INVALIDDATA; } if (pixel & 0x80) { - while (count--) { - *out_buf = bytestream2_get_byte(g); - out_buf += pixelstride; - } + while (count--) + *out_buf++ = bytestream2_get_byte(g); } else { pixel = bytestream2_get_byte(g); - while (count--) { - *out_buf = pixel; - out_buf += pixelstride; - } + while (count--) + *out_buf++ = pixel; } } - return (out_buf - orig) / pixelstride; + return out_buf - orig; } static int expand_rle_row16(void *logctx, uint16_t *out_buf, - GetByteContext *g, - int len, int pixelstride) + GetByteContext *g, unsigned width) { unsigned short pixel; unsigned char count; unsigned short *orig = out_buf; - uint16_t *out_end = out_buf + len; + uint16_t *out_end = out_buf + width; while (out_buf < out_end) { if (bytestream2_get_bytes_left(g) < 2) @@ -90,7 +83,7 @@ static int expand_rle_row16(void *logctx, uint16_t *out_buf, break; /* Check for buffer overflow. */ - if (out_end - out_buf <= pixelstride * (count - 1)) { + if (out_end - out_buf < count) { av_log(logctx, AV_LOG_ERROR, "Invalid pixel count.\n"); return AVERROR_INVALIDDATA; } @@ -99,18 +92,18 @@ static int expand_rle_row16(void *logctx, uint16_t *out_buf, while (count--) { pixel = bytestream2_get_ne16(g); AV_WN16A(out_buf, pixel); - out_buf += pixelstride; + out_buf++; } } else { pixel = bytestream2_get_ne16(g); while (count--) { AV_WN16A(out_buf, pixel); - out_buf += pixelstride; + out_buf++; } } } - return (out_buf - orig) / pixelstride; + return out_buf - orig; } @@ -120,15 +113,14 @@ static int expand_rle_row16(void *logctx, uint16_t *out_buf, * @param s the current image state * @return 0 if no error, else return error code. */ -static int read_rle_sgi(void *logctx, uint8_t *last_line, GetByteContext *g, - ptrdiff_t stride, unsigned width, unsigned height, +static int read_rle_sgi(void *logctx, uint8_t *out[4], ptrdiff_t stride[4], + GetByteContext *g, unsigned width, int height, unsigned nb_components, unsigned bytes_per_channel) { - uint8_t *dest_row; unsigned int len = height * nb_components * 4; GetByteContext g_table = *g; unsigned int start_offset; - int linesize, ret; + int ret; /* size of RLE offset and length tables */ if (len * 2 > bytestream2_get_bytes_left(g)) { @@ -136,22 +128,19 @@ static int read_rle_sgi(void *logctx, uint8_t *last_line, GetByteContext *g, } for (unsigned z = 0; z < nb_components; z++) { - dest_row = last_line; - for (unsigned remaining_lines = height;;) { - linesize = width * nb_components; + uint8_t *dest_row = out[z] + (height - 1) * stride[z]; + while (1) { start_offset = bytestream2_get_be32(&g_table); bytestream2_seek(g, start_offset, SEEK_SET); if (bytes_per_channel == 1) - ret = expand_rle_row8(logctx, dest_row + z, g, - linesize, nb_components); + ret = expand_rle_row8(logctx, dest_row, g, width); else - ret = expand_rle_row16(logctx, (uint16_t *)dest_row + z, g, - linesize, nb_components); + ret = expand_rle_row16(logctx, (uint16_t *)dest_row, g, width); if (ret != width) return AVERROR_INVALIDDATA; - if (--remaining_lines == 0) + if (dest_row == out[z]) break; - dest_row -= stride; + dest_row -= stride[z]; } } return 0; @@ -163,35 +152,23 @@ static int read_rle_sgi(void *logctx, uint8_t *last_line, GetByteContext *g, * @param s the current image state * @return 0 if read success, else return error code. */ -static int read_uncompressed_sgi(unsigned char *out_buf, GetByteContext *g, - ptrdiff_t stride, unsigned width, unsigned height, +static int read_uncompressed_sgi(uint8_t *const out[4], const ptrdiff_t stride[4], + GetByteContext *g, unsigned width, int height, unsigned nb_components, unsigned bytes_per_channel) { - unsigned int offset = height * width * bytes_per_channel; - GetByteContext gp[4]; - uint8_t *out_end; + unsigned rowsize = width * bytes_per_channel; /* Test buffer size. */ - if (offset * nb_components > bytestream2_get_bytes_left(g)) + if (rowsize * (int64_t)height > bytestream2_get_bytes_left(g)) return AVERROR_INVALIDDATA; - /* Create a reader for each plane */ for (unsigned z = 0; z < nb_components; z++) { - gp[z] = *g; - bytestream2_skip(&gp[z], z * offset); - } - - 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 (unsigned x = width; x > 0; x--) - for (unsigned z = 0; z < nb_components; z++) - *out16++ = bytestream2_get_ne16u(&gp[z]); + uint8_t *cur_row = out[z] + (height - 1) * stride[z]; + while (1) { + bytestream2_get_bufferu(g, cur_row, rowsize); + if (cur_row == out[z]) + break; + cur_row -= stride[z]; } } return 0; @@ -202,9 +179,10 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p, { GetByteContext g; unsigned int bytes_per_channel, nb_components, dimension, rle, width; + uint8_t *out[4]; + ptrdiff_t linesize[4]; int height; int ret = 0; - uint8_t *out_buf, *last_line; bytestream2_init(&g, avpkt->data, avpkt->size); if (bytestream2_get_bytes_left(&g) < SGI_HEADER_SIZE) { @@ -239,9 +217,9 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p, 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; + avctx->pix_fmt = bytes_per_channel == 2 ? AV_PIX_FMT_GBRP16BE : AV_PIX_FMT_GBRP; } else if (nb_components == SGI_RGBA) { - avctx->pix_fmt = bytes_per_channel == 2 ? AV_PIX_FMT_RGBA64BE : AV_PIX_FMT_RGBA; + avctx->pix_fmt = bytes_per_channel == 2 ? AV_PIX_FMT_GBRAP16BE : AV_PIX_FMT_GBRAP; } else { av_log(avctx, AV_LOG_ERROR, "wrong picture format\n"); return AVERROR_INVALIDDATA; @@ -254,19 +232,32 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p, if ((ret = ff_get_buffer(avctx, p, 0)) < 0) return ret; + switch (nb_components) { +#define MAP(in_idx, out_idx) \ + out[(in_idx)] = p->data[(out_idx)]; \ + linesize[(in_idx)] = p->linesize[(out_idx)] + case SGI_GRAYSCALE: + MAP(0, 0); + break; + case SGI_RGBA: + MAP(3, 3); + /* fallthrough */ + case SGI_RGB: + MAP(0, 2); + MAP(1, 0); + MAP(2, 1); + break; + } p->pict_type = AV_PICTURE_TYPE_I; p->key_frame = 1; - out_buf = p->data[0]; - - last_line = out_buf + p->linesize[0] * (height - 1); /* Skip header. */ bytestream2_seek(&g, SGI_HEADER_SIZE, SEEK_SET); if (rle) { - ret = read_rle_sgi(avctx, last_line, &g, p->linesize[0], + ret = read_rle_sgi(avctx, out, linesize, &g, width, height, nb_components, bytes_per_channel); } else { - ret = read_uncompressed_sgi(out_buf, &g, p->linesize[0], + ret = read_uncompressed_sgi(out, linesize, &g, width, height, nb_components, bytes_per_channel); } if (ret) diff --git a/tests/ref/fate/sgi-rgb24 b/tests/ref/fate/sgi-rgb24 index 4326cabe00..238e3a1f26 100644 --- a/tests/ref/fate/sgi-rgb24 +++ b/tests/ref/fate/sgi-rgb24 @@ -3,4 +3,4 @@ #codec_id 0: rawvideo #dimensions 0: 512x256 #sar 0: 0/1 -0, 0, 0, 1, 393216, 0xa9b28fd9 +0, 0, 0, 1, 393216, 0xc8478fd9 diff --git a/tests/ref/fate/sgi-rgb24-rle b/tests/ref/fate/sgi-rgb24-rle index d21bde15ba..25cc5f4737 100644 --- a/tests/ref/fate/sgi-rgb24-rle +++ b/tests/ref/fate/sgi-rgb24-rle @@ -3,4 +3,4 @@ #codec_id 0: rawvideo #dimensions 0: 512x256 #sar 0: 0/1 -0, 0, 0, 1, 393216, 0xe96e1de2 +0, 0, 0, 1, 393216, 0x7e231de2 diff --git a/tests/ref/fate/sgi-rgb48 b/tests/ref/fate/sgi-rgb48 index 29fe302514..3c59c782e5 100644 --- a/tests/ref/fate/sgi-rgb48 +++ b/tests/ref/fate/sgi-rgb48 @@ -3,4 +3,4 @@ #codec_id 0: rawvideo #dimensions 0: 512x256 #sar 0: 0/1 -0, 0, 0, 1, 786432, 0xee4aa667 +0, 0, 0, 1, 786432, 0xf9a2a667 diff --git a/tests/ref/fate/sgi-rgb48-rle b/tests/ref/fate/sgi-rgb48-rle index 49fc973017..377f4577f1 100644 --- a/tests/ref/fate/sgi-rgb48-rle +++ b/tests/ref/fate/sgi-rgb48-rle @@ -3,4 +3,4 @@ #codec_id 0: rawvideo #dimensions 0: 512x256 #sar 0: 0/1 -0, 0, 0, 1, 786432, 0xbc743bc4 +0, 0, 0, 1, 786432, 0xec343bc4 diff --git a/tests/ref/fate/sgi-rgba b/tests/ref/fate/sgi-rgba index 6a2d176582..dcdaf84ab2 100644 --- a/tests/ref/fate/sgi-rgba +++ b/tests/ref/fate/sgi-rgba @@ -3,4 +3,4 @@ #codec_id 0: rawvideo #dimensions 0: 512x256 #sar 0: 0/1 -0, 0, 0, 1, 524288, 0x4ee5adbb +0, 0, 0, 1, 524288, 0x7401adbb diff --git a/tests/ref/fate/sgi-rgba-rle b/tests/ref/fate/sgi-rgba-rle index 6a2d176582..dcdaf84ab2 100644 --- a/tests/ref/fate/sgi-rgba-rle +++ b/tests/ref/fate/sgi-rgba-rle @@ -3,4 +3,4 @@ #codec_id 0: rawvideo #dimensions 0: 512x256 #sar 0: 0/1 -0, 0, 0, 1, 524288, 0x4ee5adbb +0, 0, 0, 1, 524288, 0x7401adbb diff --git a/tests/ref/fate/sgi-rgba64 b/tests/ref/fate/sgi-rgba64 index 00181dcb3b..4a28a29169 100644 --- a/tests/ref/fate/sgi-rgba64 +++ b/tests/ref/fate/sgi-rgba64 @@ -3,4 +3,4 @@ #codec_id 0: rawvideo #dimensions 0: 512x256 #sar 0: 0/1 -0, 0, 0, 1, 1048576, 0xc657e22b +0, 0, 0, 1, 1048576, 0x1b61e22b diff --git a/tests/ref/fate/sgi-rgba64-rle b/tests/ref/fate/sgi-rgba64-rle index 354d391826..5610fc7fe6 100644 --- a/tests/ref/fate/sgi-rgba64-rle +++ b/tests/ref/fate/sgi-rgba64-rle @@ -3,4 +3,4 @@ #codec_id 0: rawvideo #dimensions 0: 512x256 #sar 0: 0/1 -0, 0, 0, 1, 1048576, 0xb619d0f1 +0, 0, 0, 1, 1048576, 0x6122d0f1 diff --git a/tests/ref/lavf/sgi b/tests/ref/lavf/sgi index ad27b805f0..bfab92c8a8 100644 --- a/tests/ref/lavf/sgi +++ b/tests/ref/lavf/sgi @@ -1,3 +1,3 @@ d446e540a7c18da5fd3cc0e9942cd46f *tests/data/images/sgi/02.sgi 307287 tests/data/images/sgi/02.sgi -tests/data/images/sgi/%02d.sgi CRC=0x6da01946 +tests/data/images/sgi/%02d.sgi CRC=0x36e71946