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 ESMTPS id AEDCD4E459 for ; Tue, 11 Mar 2025 15:05:42 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7BEBC68E14D; Tue, 11 Mar 2025 17:04:06 +0200 (EET) Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3F30368E11E for ; Tue, 11 Mar 2025 17:03:54 +0200 (EET) Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-43690d4605dso34907365e9.0 for ; Tue, 11 Mar 2025 08:03:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741705433; x=1742310233; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bRt0XjDnXElRYHSURpx0Zc9D2muxoonjm1RjIZ4rkdg=; b=FVtzlC/BS07Ij8T0+2JhGnNQUKk8ciYA4HltV7J6kbjek4gdghDtrdqwAgByT7ybhe Qo1iWHrPmBgJTLCDA0lx95T+p6vT8/GJWuZ/DWcBEbttB2cQXWmpMCOEpwqXOHIwBQBc jS/iyX/mr7NqYuRIk+EzFJns3abhOfvgSaCcp3WWhLHqC+Mm7aNVHfowA2s5JIMCf8Lw fOC22rpCZDwhTBdrM29en8JLLU6oRM3mbaPODCoLwZ07XFf12soeMOplZGCYRlrYMeSK oBKX96SrwYUnH9Iw3R574qbkwYc3aTo6oel5s6AEIqsR6K/LUvmuXOAoGyTYB4qTpDJh BHYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741705433; x=1742310233; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bRt0XjDnXElRYHSURpx0Zc9D2muxoonjm1RjIZ4rkdg=; b=iAmey8VCdKHQfrKdAgOieBvnyFV5IRJPz8bLI0GdKamprBhovq4cPwy4Fh24BlHYpJ g1V2iiQNg8jctui530fJoMClYd8rAgHLpvGm++wrILT0jMU4TS0kAQkdAjHHy10vAsWZ axbzD3rtqt9IsDOcBnGVDteIPxhrWMX4nStD5V0i07zJp+JueaRt31zesFUEM8OaIwD7 S0S7MxtJatWy8S3WIKuF7D9xLkIE4LSiWjLe5h3t+JB9GFcn9xFGQIqQs9Nv+o6aQWl5 sLFWtAYW6VfcUDM3P2axCMf4kPgV39ehGmtjfnwfyN8vudssQAvYLlR3WuzHTMDSwgZe 2iMg== X-Gm-Message-State: AOJu0YzZIcibDymPchqBtcwO4pB2dYi0mKyqMNz5FpmL65FQ/Mp6/eRW MGTqVOHJWWn8YoffgK/hHuHF3HZHNwr7fZbJb2TCybVFXJE+FFlQIaJVdw== X-Gm-Gg: ASbGncvmeM1MlFfAoEinOhps3J4agXhz7Sw9CA3HTUz9y/rXV8XKjG7gh1RSDazgg10 Yl0FPf67s42lX7uVMrF1qbq3zDc8MkC6KrPxT3W4Xa1/FIAIQ5PK9y++sHDQliCTWlSwRK30/lj X4ImW1XRzfk7q217ofdGk8xV55D4kaTJ4PlM+M0HyDoX2XRVEg9fZhAIfNUZCyvi4aMAr3KWNLm fUaK4M9y4hTbpClfSW88ZNi2MRS/8UJgkFUkVWRGs0kEBqVqgZ65h6o04iVgxox3XEn2uEZGij4 f10GVmBWMPjWPGy3qzL26jyf5GM9q9wMPgo1wU/VqsIMdYTKep5OJFRCJPT0iynVE+QwlYWcroY ing/+XtBMvpgz30K2kV0wXSzk5/G4ikW9HMprnddWN1ie2EZjy+T+7qQ= X-Google-Smtp-Source: AGHT+IECmcd4+JxUztpO7x8tWWy7Zrkpi0UDQ2MMwt259kszoK2l6Jh2JxqK+/uHe/sm4RbCWu+43w== X-Received: by 2002:a5d:64a4:0:b0:391:a74:d7dc with SMTP id ffacd0b85a97d-39132db7543mr14250264f8f.50.1741705433119; Tue, 11 Mar 2025 08:03:53 -0700 (PDT) Received: from flagship3.deu.mlau.at (p200300c0271f29004c5623f045c27bca.dip0.t-ipconnect.de. [2003:c0:271f:2900:4c56:23f0:45c2:7bca]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43ceaac390bsm115259215e9.35.2025.03.11.08.03.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Mar 2025 08:03:52 -0700 (PDT) From: Manuel Lauss To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Mar 2025 16:03:40 +0100 Message-ID: <20250311150341.348678-8-manuel.lauss@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250311150341.348678-1-manuel.lauss@gmail.com> References: <20250311150341.348678-1-manuel.lauss@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 8/9] avcodec/sanm: codec23 decoder 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: Manuel Lauss 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: This codec alternatingly skips and changes existing pixels. A second 16bit parameter in the FOBJ header indicates how to do the pixel changes: either by specifying a LUT in the codec datastream or by adding a constant value to the pixel. Signed-off-by: Manuel Lauss --- libavcodec/sanm.c | 66 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c index 8c0b76aed6..dbd78de0bc 100644 --- a/libavcodec/sanm.c +++ b/libavcodec/sanm.c @@ -292,6 +292,7 @@ typedef struct SANMVideoContext { int8_t p4x4glyphs[NGLYPHS][16]; int8_t p8x8glyphs[NGLYPHS][64]; uint8_t c47itbl[0x10000]; + uint8_t c23lut[256]; } SANMVideoContext; typedef struct SANMFrameHeader { @@ -555,6 +556,62 @@ static int rle_decode(SANMVideoContext *ctx, uint8_t *dst, const int out_size) return 0; } +static int old_codec23(SANMVideoContext *ctx, int top, int left, int width, + int height, uint8_t param, uint16_t param2) +{ + const uint32_t maxpxo = ctx->height * ctx->pitch; + uint8_t *dst, lut[256], c; + int i, j, k, pc, sk; + int32_t pxoff; + + if (ctx->subversion < 2) { + /* Rebel Assault 1: constant offset + 0xd0 */ + for (i = 0; i < 256; i++) + lut[i] = (i + param + 0xd0) & 0xff; + } else if (param2 == 256) { + if (bytestream2_get_bytes_left(&ctx->gb) < 256) + return AVERROR_INVALIDDATA; + bytestream2_get_bufferu(&ctx->gb, ctx->c23lut, 256); + } else if (param2 < 256) { + for (i = 0; i < 256; i++) + lut[i] = (i + param2) & 0xff; + } else { + memcpy(lut, ctx->c23lut, 256); + } + if (bytestream2_get_bytes_left(&ctx->gb) < 1) + return 0; /* some c23 frames just set up the LUT */ + + dst = (uint8_t *)ctx->frm0; + for (i = 0; i < height; i++) { + if (bytestream2_get_bytes_left(&ctx->gb) < 2) + return 0; + pxoff = left + ((top + i) * ctx->pitch); + k = bytestream2_get_le16u(&ctx->gb); + sk = 1; + pc = 0; + while (k > 0 && pc <= width) { + if (bytestream2_get_bytes_left(&ctx->gb) < 1) + return AVERROR_INVALIDDATA; + j = bytestream2_get_byteu(&ctx->gb); + if (sk) { + pxoff += j; + pc += j; + } else { + while (j--) { + if (pxoff >=0 && pxoff < maxpxo) { + c = *(dst + pxoff); + *(dst + pxoff) = lut[c]; + } + pxoff++; + pc++; + } + } + sk ^= 1; + } + } + return 0; +} + static int old_codec1(SANMVideoContext *ctx, int top, int left, int width, int height, int opaque) { @@ -1253,11 +1310,15 @@ static int old_codec48(SANMVideoContext *ctx, int width, int height) static int process_frame_obj(SANMVideoContext *ctx) { - uint16_t codec = bytestream2_get_le16u(&ctx->gb); + uint16_t parm2; + uint8_t codec = bytestream2_get_byteu(&ctx->gb); + uint8_t param = bytestream2_get_byteu(&ctx->gb); int16_t left = bytestream2_get_le16u(&ctx->gb); int16_t top = bytestream2_get_le16u(&ctx->gb); uint16_t w = bytestream2_get_le16u(&ctx->gb); uint16_t h = bytestream2_get_le16u(&ctx->gb); + bytestream2_skip(&ctx->gb, 2); + parm2 = bytestream2_get_le16u(&ctx->gb); if (w < 2 || h < 2 || w > 800 || h > 600) { av_log(ctx->avctx, AV_LOG_WARNING, "ignoring invalid fobj dimensions.\n"); @@ -1315,7 +1376,6 @@ static int process_frame_obj(SANMVideoContext *ctx) */ left = top = 0; } - bytestream2_skip(&ctx->gb, 4); switch (codec) { case 1: @@ -1323,6 +1383,8 @@ static int process_frame_obj(SANMVideoContext *ctx) return old_codec1(ctx, top, left, w, h, codec != 1); case 2: return old_codec2(ctx, top, left, w, h); + case 23: + return old_codec23(ctx, top, left, w, h, param, parm2); case 37: return old_codec37(ctx, w, h); case 47: -- 2.48.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".