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 33DF84E446 for ; Tue, 11 Mar 2025 15:04:00 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1E4BD68E10E; Tue, 11 Mar 2025 17:03:56 +0200 (EET) Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6EB0A68DDBD for ; Tue, 11 Mar 2025 17:03:49 +0200 (EET) Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-43d0618746bso4673845e9.2 for ; Tue, 11 Mar 2025 08:03:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741705429; x=1742310229; 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=m4R6LJRCE2YDXszJ81v5BY26FwkkbyAduAu67xVHP6g=; b=Qxm8xQLK4l5MfDsQYkvfTl60XnlRSkpwUK0ukEys1a69csP2AGqBFTLRRJ1a2CPSPC yTAICSq8eJacgnFI+l/pSm/7rcmaZ5qKRqYTlXEHOkFGwlO6r4wh1vdY3ZjnXbqRV+SP EyRwXH/BugrleV5GFhKWs03Fz4Ll9F8lcSfnz35GjX+5Jkb/Z5YH76be2xnXG22v89Bp x9X1kJocYvhSEP+1pNiQz03dqe/21boag1x+oa1cFiA/+WwSEmPPABPp19ENvZvOCJR4 uFty6F3rXNBLT81gx9AksaVSGO3b6fgM+ZgJLlGfYKbP+V0Wop7khP5TrQJnoBPuiK/F Uslw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741705429; x=1742310229; 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=m4R6LJRCE2YDXszJ81v5BY26FwkkbyAduAu67xVHP6g=; b=FrcvXQJ/52GTDtTJqczOxTnT4Kt+wlFM8Cg2/TtnJ+TkYkMbzteewYymVEot41z0/e 2iekZjHYqHPsNp2WdviSbI2Ve8r4AS2dcGnxOOenBW9L0Z3RZ7plKO2i2lNeyBi1BhhM EOK1YEmuL6TAi6q9X9PGz02qP9dsQic00cYZle3suxIZBCpGJaoTrpLIzt/vEw2Ec1qp eKcJGcFObQolkkJmOpD4OBJ/+Wd7u5+WH2CBaS171kS/Frb4zchTIYzLabyI8C3P1OMs 9n6+VrQHeKBI8gdg3FWRs97B5Yxde9Gp3Z9+cITYZfMScmjZrC7T12y9TckF+gcadTMn Xh8g== X-Gm-Message-State: AOJu0YxhRWr8L72rvinkvQgGBYWxBvNrClHoqMRV4k7d8diw5t7ZxyAv ByNZmzOGSYiPRgzkzAQeE2eFR+1unB8Io5B80Qlwh5if1CchzVqhsXSkVw== X-Gm-Gg: ASbGncvBJK8YcRalQFtp8s6HuIAN+p1h1wWaiA2ncJl8IZ1ebC4tJ43UFtUup/9k47x ITPd77lZpB5rvbRKXDXVg1pBKIMACCMsT4MVwX42Xv+Q7auESCJYJ7raVuBitVz4yczXkd2aQzn g/VK1ELVJTa4n9ebK9D7pw/+m+W2zFyEF8mNbq4z+6EHpihGxPhS6zGES3yxzXcDp+Q0sJsIB8b Iro4T024NT3ACN7TU8H/z/FFwW3M/VtXL/o+iR1GLs2a9LdeC1okFt2yDgO2RA99SnPQz2eitVI +qzoxKNoQu3y5NMnvPd2+AJ0/Z6JXt+NKtFs+kXwnFFprAwV4BIGDK4AuHI9SDeI7hU1SLwowDB 7EQML2PH4XNw8JXXLV8J3PMEzoeD7aUHHLqbNF7iIRublBe8fH9ognGE= X-Google-Smtp-Source: AGHT+IEndM3bD/T4gQJNEexleCny0GSz3Nacs3rEs4pf2rju8fxZWUBlMQanl0oDySoinmAgnVHewg== X-Received: by 2002:a05:600c:5250:b0:43c:fbae:4f21 with SMTP id 5b1f17b1804b1-43cfbae5168mr82101195e9.15.1741705428024; Tue, 11 Mar 2025 08:03:48 -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.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Mar 2025 08:03:47 -0700 (PDT) From: Manuel Lauss To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Mar 2025 16:03:34 +0100 Message-ID: <20250311150341.348678-2-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 2/9] 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 as those don't exist in LucasArts titles. - some 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). Ignoring them does not impact the final image. Once known/valid dimensions have been discovered, use them and don't change them for subsequent FOBJs, rather clamp the large frame to the determined dimensions (The Dig's sq1.san). Tested with RA1, RA2, Full Throttle, Dig, Outlaws, SotE and MotS videos. Signed-off-by: Manuel Lauss --- libavcodec/sanm.c | 59 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c index cbf78f33b9..ca345bc61a 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]; @@ -1241,21 +1241,52 @@ 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 < 2 || h < 2 || w > 800 || h > 600) { + av_log(ctx->avctx, AV_LOG_WARNING, "ignoring invalid fobj dimensions.\n"); + 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. + */ + left = top = 0; + w = ctx->width; + h = ctx->height; + av_log(ctx->avctx, AV_LOG_WARNING, "resizing too large fobj.\n"); } } 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".