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 878A44E5E3 for ; Thu, 13 Mar 2025 11:15:34 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9CE0F68E776; Thu, 13 Mar 2025 13:15:17 +0200 (EET) Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B99C968D5B4 for ; Thu, 13 Mar 2025 13:15:10 +0200 (EET) Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-43cebe06e9eso5047195e9.3 for ; Thu, 13 Mar 2025 04:15:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741864510; x=1742469310; 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=NDVEE8PY+/ywnmC2q3nElfhFCIuHitnJMGtO3QHXxF4=; b=Axa3+PECHrPCdevXVmhK1pKgTtTLdtUSCaoa4Ga3KWBKW/AontuOPESMcuctvxbVU7 U2F7d6S+6Vt7apwVDNLpiYttYOONKAYqt4BR3FsMIlrk7+yoI4o4/1WCCefKhUNNaRd/ Q9qqVnIopanaG92zScG+a4A6Rx/Do3K/ilg+7ePqsW6c7fhNwa30TafjL8dGNlTQGRFq F+3NlpcPOTBHmu9ygrUnRqTonzbK8lLvLQ4dca90pxbOiyiLhMBoD2TDFI1+fZYglySm 6hMavjm+SY74eyh3FB+IGBIJO/ARV7tOFBzj633MXCg9Nxh41N7DdBgkbsajlpr5G66k ymmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741864510; x=1742469310; 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=NDVEE8PY+/ywnmC2q3nElfhFCIuHitnJMGtO3QHXxF4=; b=tEvQxA7dIiOZnPztjWFfUUijIYcA2UZc/zDTnUDyFFGz5Di68oqjc7mS2T43LlUrPL 1bIJVEtIUdlMYLat/yZufhybT2NnxRZ+WxZIV46RGAG1ncgpuHtnqnrwmGExupvTW8Nj p+p6jM0gSqOaHRKdd5hWZgY1hd6mLDIyWbHLFsDfGHLbLVuhPlezFdSgcilkDRYzU2ht kqm5cq9c0M2I0vycIjfX9Jwzky6NQ25le9MXcJdqIU3Nh+SGiDqb0WILYf2wQVGKlua6 SIY6yjY4cBi+pIdGpKuK4U1cW89AfCgjKklcQSCVtu90aOqWNVHlHYox4VIbDGDFW9P5 LnOg== X-Gm-Message-State: AOJu0YzxERDTp1gRiyS1omwz5JGqNuiYlvR1qO2lXksuTSU22IeH5i5/ OJOxME/l4PCWGtvq5g9C8/J3OaOlwZMTJujRoCeSqFhD4A/bdxnjOlW9jg== X-Gm-Gg: ASbGncsY77M6bzRLQ/WLVDH54RuqcNu4wC16o/9cfgJk+BYme+8veyBcx4xHa1exEpP y8Yxbf0NQPSHajO8FQPDqZes0SasHvg1qvDQiVqbNDnYcZfonuygpV2SP80uJQpy/HJlWP/fPTu lbHFAuVqzPsE3k8s+lqh2N0SUXlyw6SXICRraI9FRn2LWF6WbPaQCioLHrFY18st7U/zJYv7oyD ffLC421a9HOEBls+C4qAAacxfeSrI847Ad87Z0/0CuhWwUsL1K+KSzBH5A+xErRMcC9vq2nXaTu CgE32FOcZI1zyth0SlRR9zsdAoNtDc4wp3mz1C/T8S4MkHVopCeT0JhTD9B9BYFi2U4nJVZEBwB IVxfg0QEtDlQmQv/qgs/2tdZd/LVZ4uY4Cz/rRpuwpVxvq7jyJiuJZ/w= X-Google-Smtp-Source: AGHT+IE/SsP6kTxjCT5C4RXwdbpH6/RbKUsACk5SNCSsYvabXNdyBMzOOCWWYKR21ZmF3XdP5GW2sg== X-Received: by 2002:a05:600c:3b1f:b0:43c:f6c6:578c with SMTP id 5b1f17b1804b1-43cf6c6588bmr143356875e9.15.1741864509739; Thu, 13 Mar 2025 04:15:09 -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-43d0a75b324sm50153795e9.24.2025.03.13.04.15.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Mar 2025 04:15:09 -0700 (PDT) From: Manuel Lauss To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Mar 2025 12:14:54 +0100 Message-ID: <20250313111505.166786-2-manuel.lauss@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250313111505.166786-1-manuel.lauss@gmail.com> References: <20250313111505.166786-1-manuel.lauss@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/12] avcodec/sanm: better frame size detection for old codecs 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: The size of the video frame (FOBJ) of the old codecs (ANIMv0/1/2) can very reliably be determined: - ANIMv0/1 (=Rebel Assault 1) uses a 384x242 internal buffer for everything. The codec parameters only describe the size and offset of the specific FOBJ on that buffer. - ANIMv2 titles usually use one of the fullscreen codecs (37/47/48) as first FOBJ, and their dimensions can generally be trusted. - RA2 uses 424x260 as internal buffer, use that if encountered. - ignore sizes smaller than 2x2 or larger than 800x600. - some game videos have an initial fobj with either 1x1 or -1x-1 pixels in size, ignore them with a warning (Full Throttle and the Rebel Assault 2 xxRETRY.SAN videos). Once a known/valid dimension set has been discovered, use it and don't change it for subsequent FOBJs, rather clamp the large frame to the determined dimensions. Tested with RA1, RA2, Full Throttle, Dig, Outlaws, SotE and MotS videos. Signed-off-by: Manuel Lauss --- libavcodec/sanm.c | 63 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c index a4f0a28c7c..0795d664fa 100644 --- a/libavcodec/sanm.c +++ b/libavcodec/sanm.c @@ -264,7 +264,7 @@ typedef struct SANMVideoContext { AVCodecContext *avctx; GetByteContext gb; - int version, subversion; + int version, subversion, have_dimensions; uint32_t pal[PALETTE_SIZE]; int16_t delta_pal[PALETTE_DELTA]; @@ -1243,21 +1243,56 @@ static int process_frame_obj(SANMVideoContext *ctx) uint16_t w = bytestream2_get_le16u(&ctx->gb); uint16_t h = bytestream2_get_le16u(&ctx->gb); - if (!w || !h) { - av_log(ctx->avctx, AV_LOG_ERROR, "Dimensions are invalid.\n"); - return AVERROR_INVALIDDATA; + if (w < 1 || h < 1 || w > 800 || h > 600 || left > 800 || top > 600) { + av_log(ctx->avctx, AV_LOG_WARNING, + "ignoring invalid fobj dimensions: c%d %d %d @ %d %d\n", + codec, w, h, left, top); + return 0; } - if (ctx->width < left + w || ctx->height < top + h) { - int ret = ff_set_dimensions(ctx->avctx, FFMAX(left + w, ctx->width), - FFMAX(top + h, ctx->height)); - if (ret < 0) - return ret; - init_sizes(ctx, FFMAX(left + w, ctx->width), - FFMAX(top + h, ctx->height)); - if (init_buffers(ctx)) { - av_log(ctx->avctx, AV_LOG_ERROR, "Error resizing buffers.\n"); - return AVERROR(ENOMEM); + if (!ctx->have_dimensions) { + int xres, yres; + if (ctx->subversion < 2) { + /* Rebel Assault 1: 384x242 internal size */ + xres = 384; + yres = 242; + ctx->have_dimensions = 1; + } else if (codec == 37 || codec == 47 || codec == 48) { + /* these codecs work on full frames, trust their dimensions */ + xres = w; + yres = h; + ctx->have_dimensions = 1; + } else { + /* Rebel Assault 2: 424x260 internal size */ + if (((left + w) == 424) && ((top + h) == 260)) + ctx->have_dimensions = 1; + + xres = FFMAX(left + w, ctx->width); + yres = FFMAX(top + h, ctx->height); + } + + if (ctx->width < xres || ctx->height < yres) { + int ret = ff_set_dimensions(ctx->avctx, xres, yres); + if (ret < 0) + return ret; + init_sizes(ctx, xres, yres); + if (init_buffers(ctx)) { + av_log(ctx->avctx, AV_LOG_ERROR, "Error resizing buffers.\n"); + return AVERROR(ENOMEM); + } + } + } else { + if ((left + w > ctx->width) || (top + h > ctx->height)) { + /* correct unexpected overly large frames: this happens + * for instance with The Dig's sq1.san video: it has a few + * (all black) 640x480 frames halfway in, while the rest is + * 320x200. + */ + av_log(ctx->avctx, AV_LOG_WARNING, + "resizing too large fobj: %d %d @ %d %d c %d\n", w, h, left, top, codec); + left = top = 0; + w = ctx->width; + h = ctx->height; } } bytestream2_skip(&ctx->gb, 4); -- 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".