From patchwork Sun May 2 13:59:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 27558 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a11:cc:0:0:0:0 with SMTP id m12csp1256174pxt; Sun, 2 May 2021 07:07:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4IVJdYxEwS2OXpgKGgaxWcOpIn1ae1+2fhaZwKTP1s4V+N3U9NZwuU+ZcjW/913deo6qG X-Received: by 2002:a05:6402:cb0:: with SMTP id cn16mr6126283edb.15.1619964435913; Sun, 02 May 2021 07:07:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619964435; cv=none; d=google.com; s=arc-20160816; b=rH5BHPT3HIQjCVbzDS2yWvN84zJ/h9E/mgcVL4usG9uy3Irf3ti1CnjETdG3UKIIx3 evSj2W0V7E3LjJbTC28Xx2fCNJLf73Rqw/YCZJViXOMIuFEhhTD05GqxRkSvBkFYFJ/2 fWx6IuOLiOU9+CJQca8V0T8Rnvik8akty20w8nKQHDISM9EGeBAFNpvvanX6+RTJY6A9 hTY8DAlj3JzIF+fe919IQBU2jVEzWYnh7iKKhh3mKw706bAi41iBLMMb46OKzyRG2041 uQygn7EjNVNFJE61q7n7yXnVnlEsvfqXlgBHx+d6w8YwmHegi0itm9II4q9CvdOIkzvD Bwkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to; bh=BgX43dFk1pepDT7aOOt/wgxGmE6GYo3I0m+KPFkDQSs=; b=hVkN8MKld1DjSlNZX5C4r5kIg7L4vKDH7mjDYDJER3kJmgNCJxHGretnzXg7TLI1rR e5k+t+4yWtXILn2o+5ICVQ1t/L1LojwCe76hBw/zVhSpHFfFO2YaakoiCN3qDZY7/WAn VgHR6eyk62tI2pn+7fm3LR3Pw1cW+aQ+OERNDnsRUdzcHFfkFUiNfFGLrqF5aqIr7Xov FQX2tBtHpW/5Sy9z/5zTq5GzU8wLp/DpW3ZR32IGUz+fje602xpN+NAK/K5PA/2nIMhk lcR0xbVOJx6X18Xio5/M+XkSyx3MF7lufVfQAXKWQWBvXXmmVZgkyE39bo3wgqFWj5rK buYg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id h14si8279046ejj.626.2021.05.02.07.07.15; Sun, 02 May 2021 07:07:15 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A293D68834D; Sun, 2 May 2021 17:07:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe06-1.mx.upcmail.net (vie01a-dmta-pe06-1.mx.upcmail.net [84.116.36.14]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1E82D68834D for ; Sun, 2 May 2021 17:07:07 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe06.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1ldCdj-004Uc8-0J for ffmpeg-devel@ffmpeg.org; Sun, 02 May 2021 16:00:07 +0200 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id dCckleYa8ljeHdCcklCfd0; Sun, 02 May 2021 15:59:07 +0200 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.3 cv=BoHjPrf5 c=1 sm=1 tr=0 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=NcpgZ5gT5NfQhL8WVjoA:9 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 2 May 2021 15:59:03 +0200 Message-Id: <20210502135906.12288-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 X-CMAE-Envelope: MS4wfLEjznkJP89Ee2LVuKwi4XEdFTiwqTlBGhX6YORoOps1LBepz5uJscnGt9UNO0YwKL/zLALQzMHv2Zvma24K7zsLPkz6wQyLfzjrGhSA/EAYVBlqhV74 AgGOfP7oy4nNwLmljczZ0K0+mUwyhRDrXL49wWmMwEzcXPiuXYuU82Sa Subject: [FFmpeg-devel] [PATCH 1/4] Revert "avcodec/mjpegdec: fix SOF check in EOI" 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 6YFkZdqUYux+ This reverts commit fb5e2d71127ccae19c3f80ec363bb67d1871cb74. --- libavcodec/mjpegdec.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index c829172200..16aed078f6 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -2560,16 +2560,11 @@ eoi_parser: s->progressive && s->cur_scan && s->got_picture) mjpeg_idct_scan_progressive_ac(s); s->cur_scan = 0; - if (!s->seen_sof) { + if (!s->got_picture) { av_log(avctx, AV_LOG_WARNING, "Found EOI before any SOF, ignoring\n"); break; } - if (!s->got_picture && avctx->skip_frame != AVDISCARD_ALL) { - av_log(avctx, AV_LOG_WARNING, - "Found EOI before any SOS, ignoring\n"); - break; - } if (s->interlaced) { s->bottom_field ^= 1; /* if not bottom field, do not output image yet */ From patchwork Sun May 2 13:59:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 27559 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a11:cc:0:0:0:0 with SMTP id m12csp1255112pxt; Sun, 2 May 2021 07:06:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxWzEdXYVnWXH2c5gUahu/fD80M0BsGs7yA6nSpvIKw1xb6gJH3OGDBBpAMLOEeTsCc8dW X-Received: by 2002:a05:6402:1bc9:: with SMTP id ch9mr15836185edb.136.1619964363610; Sun, 02 May 2021 07:06:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619964363; cv=none; d=google.com; s=arc-20160816; b=TidjBtY/nlSWjjZ7o64q2bYO3FkIENVkt4tNklRypN4pnU3xh3XxE08nattB7xz62Q 6ftAMrUL6mnRz+PKEp5Hx3kYAxia5xrf3i9mrxNaLnMJAS6iTRVMZNRvB/QsTHgKPVTt f+RoES3d+LCwc3Nc9e8bRKu2rUhR7y/wnAWXxZySvpfpHeILKmCK3HRKQ+x2++/E1fho QsuWzTbWysB1NgSPT23KwcJmNe1te7qWH7I8S9c1igqP6JlT8PfKqDNMVLlW+tq74ddT ISiBVgpSfErUGScKb1YnXlLmnL7ZI/8Ur+S/66hNdBNKuUhv/AKhpMNyjgu/vbp8u0km DOiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=VhllzeDuqcK6lXPe/xSKDhM4aeyQAZEdAZzrgglnkIY=; b=utEp/LFqU3/6N6RVyIUVUGA00tKnTl9H9QDXh3vGXJjGDckv724nEPk9R3lPPBTrSt cWCEKZ9KawU4lJbR4NqEuACpLMCjfLN2zM4YoAoNPS/GeZPvFK7iuYDIfq7oNdoSkE57 WOPqiAEvaw/1VmduHKq9bMv7hKe8LgQifZlxiu/BNoRBii+/x6aollZPElBF8J6kyyDn 6Efr3XOPf2Hygeb8U5OOWlxV43S4svnwyXSHc1l1dolnsblzodnBgEKBYS7F6O5YeiIv sXC8lclFv32YwxCa1XYm2m5SppEVJg+zBx4o1DkjAYVPPD/yT5+gp7pt9TZm64K1Swm2 xb2g== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id k9si6850726edo.197.2021.05.02.07.06.03; Sun, 02 May 2021 07:06:03 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 965F06883B3; Sun, 2 May 2021 17:06:00 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe01-2.mx.upcmail.net (vie01a-dmta-pe01-2.mx.upcmail.net [62.179.121.155]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 81E2B687FF6 for ; Sun, 2 May 2021 17:05:53 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe01.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1ldCdj-00ADRq-0E for ffmpeg-devel@ffmpeg.org; Sun, 02 May 2021 16:00:07 +0200 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id dCclleYeNljeHdCcllCfgL; Sun, 02 May 2021 15:59:07 +0200 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.3 cv=BoHjPrf5 c=1 sm=1 tr=0 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=CkTuOyF4UGb0I1VDOWEA:9 a=pHzHmUro8NiASowvMSCR:22 a=Ew2E2A-JSTLzCXPT_086:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 2 May 2021 15:59:04 +0200 Message-Id: <20210502135906.12288-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210502135906.12288-1-michael@niedermayer.cc> References: <20210502135906.12288-1-michael@niedermayer.cc> X-CMAE-Envelope: MS4wfLEjznkJP89Ee2LVuKwi4XEdFTiwqTlBGhX6YORoOps1LBepz5uJscnGt9UNO0YwKL/zLALQzMHv2Zvma24K7zsLPkz6wQyLfzjrGhSA/EAYVBlqhV74 AgGOfP7oy4nNwLmljczZ0K0+mUwyhRDrXL49wWmMwEzcXPiuXYuU82Sa Subject: [FFmpeg-devel] [PATCH 2/4] Revert "avcodec/mjpegdec: postpone calling ff_get_buffer() until the SOS marker" 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: DY4Rdu0EC+ZF This reverts commit c8197f73e684b0edc450f3dc2b2b4b3fb9dedd0d. --- libavcodec/jpeglsdec.c | 6 ++- libavcodec/mjpegbdec.c | 1 - libavcodec/mjpegdec.c | 83 +++++++++++++++++------------------------- libavcodec/mjpegdec.h | 3 -- libavcodec/mxpegdec.c | 2 +- 5 files changed, 39 insertions(+), 56 deletions(-) diff --git a/libavcodec/jpeglsdec.c b/libavcodec/jpeglsdec.c index bf51d63c3a..d79bbe1ee3 100644 --- a/libavcodec/jpeglsdec.c +++ b/libavcodec/jpeglsdec.c @@ -108,8 +108,9 @@ int ff_jpegls_decode_lse(MJpegDecodeContext *s) if (s->palette_index > maxtab) return AVERROR_INVALIDDATA; - if (s->avctx->pix_fmt == AV_PIX_FMT_GRAY8 || s->avctx->pix_fmt == AV_PIX_FMT_PAL8) { - uint32_t *pal = s->palette; + if ((s->avctx->pix_fmt == AV_PIX_FMT_GRAY8 || s->avctx->pix_fmt == AV_PIX_FMT_PAL8) && + (s->picture_ptr->format == AV_PIX_FMT_GRAY8 || s->picture_ptr->format == AV_PIX_FMT_PAL8)) { + uint32_t *pal = (uint32_t *)s->picture_ptr->data[1]; int shift = 0; if (s->avctx->bits_per_raw_sample > 0 && s->avctx->bits_per_raw_sample < 8) { @@ -117,6 +118,7 @@ int ff_jpegls_decode_lse(MJpegDecodeContext *s) shift = 8 - s->avctx->bits_per_raw_sample; } + s->picture_ptr->format = s->avctx->pix_fmt = AV_PIX_FMT_PAL8; for (i=s->palette_index; i<=maxtab; i++) { uint8_t k = i << shift; diff --git a/libavcodec/mjpegbdec.c b/libavcodec/mjpegbdec.c index abc607176a..87eebb8771 100644 --- a/libavcodec/mjpegbdec.c +++ b/libavcodec/mjpegbdec.c @@ -55,7 +55,6 @@ static int mjpegb_decode_frame(AVCodecContext *avctx, buf_ptr = buf; buf_end = buf + buf_size; - s->seen_sof = 0; s->got_picture = 0; s->adobe_transform = -1; diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 16aed078f6..7c66ff8637 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -138,7 +138,6 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx) s->buffer = NULL; s->start_code = -1; s->first_picture = 1; - s->seen_sof = 0; s->got_picture = 0; s->orig_height = avctx->coded_height; avctx->chroma_sample_location = AVCHROMA_LOC_CENTER; @@ -430,7 +429,6 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) memcpy(s->h_count, h_count, sizeof(h_count)); memcpy(s->v_count, v_count, sizeof(v_count)); s->interlaced = 0; - s->seen_sof = 0; s->got_picture = 0; /* test interlaced mode */ @@ -683,13 +681,11 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) } else if (s->nb_components != 1) { av_log(s->avctx, AV_LOG_ERROR, "Unsupported number of components %d\n", s->nb_components); return AVERROR_PATCHWELCOME; - } else if (s->bits <= 8) { - avpriv_set_systematic_pal2(s->palette, s->avctx->pix_fmt); - if (s->palette_index) - s->avctx->pix_fmt = AV_PIX_FMT_PAL8; - else - s->avctx->pix_fmt = AV_PIX_FMT_GRAY8; - } else + } else if (s->palette_index && s->bits <= 8) + s->avctx->pix_fmt = AV_PIX_FMT_PAL8; + else if (s->bits <= 8) + s->avctx->pix_fmt = AV_PIX_FMT_GRAY8; + else s->avctx->pix_fmt = AV_PIX_FMT_GRAY16; } @@ -723,12 +719,25 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) if (s->avctx->skip_frame == AVDISCARD_ALL) { s->picture_ptr->pict_type = AV_PICTURE_TYPE_I; s->picture_ptr->key_frame = 1; - s->seen_sof = 1; + s->got_picture = 1; return 0; } - } - s->seen_sof = 1; + av_frame_unref(s->picture_ptr); + if (ff_get_buffer(s->avctx, s->picture_ptr, AV_GET_BUFFER_FLAG_REF) < 0) + return -1; + s->picture_ptr->pict_type = AV_PICTURE_TYPE_I; + s->picture_ptr->key_frame = 1; + s->got_picture = 1; + + for (i = 0; i < 4; i++) + s->linesize[i] = s->picture_ptr->linesize[i] << s->interlaced; + + ff_dlog(s->avctx, "%d %d %d %d %d %d\n", + s->width, s->height, s->linesize[0], s->linesize[1], + s->interlaced, s->avctx->height); + + } if ((s->rgb && !s->lossless && !s->ls) || (!s->rgb && s->ls && s->nb_components > 1) || @@ -755,6 +764,18 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) memset(s->coefs_finished, 0, sizeof(s->coefs_finished)); } + if (s->avctx->hwaccel) { + s->hwaccel_picture_private = + av_mallocz(s->avctx->hwaccel->frame_priv_data_size); + if (!s->hwaccel_picture_private) + return AVERROR(ENOMEM); + + ret = s->avctx->hwaccel->start_frame(s->avctx, s->raw_image_buffer, + s->raw_image_buffer_size); + if (ret < 0) + return ret; + } + return 0; } @@ -1609,44 +1630,12 @@ int ff_mjpeg_decode_sos(MJpegDecodeContext *s, const uint8_t *mb_bitmask, const int block_size = s->lossless ? 1 : 8; int ilv, prev_shift; - if (!s->seen_sof) { + if (!s->got_picture) { av_log(s->avctx, AV_LOG_WARNING, "Can not process SOS before SOF, skipping\n"); return -1; } - if (!s->got_picture || !s->interlaced || !(s->bottom_field == !s->interlace_polarity)) { - av_frame_unref(s->picture_ptr); - if (ff_get_buffer(s->avctx, s->picture_ptr, AV_GET_BUFFER_FLAG_REF) < 0) - return -1; - s->picture_ptr->pict_type = AV_PICTURE_TYPE_I; - s->picture_ptr->key_frame = 1; - - for (i = 0; i < 4; i++) - s->linesize[i] = s->picture_ptr->linesize[i] << s->interlaced; - - if (s->picture_ptr->format == AV_PIX_FMT_PAL8) - memcpy(s->picture_ptr->data[1], s->palette, sizeof(s->palette)); - - s->got_picture = 1; - - ff_dlog(s->avctx, "%d %d %d %d %d %d\n", - s->width, s->height, s->linesize[0], s->linesize[1], - s->interlaced, s->avctx->height); - - if (s->avctx->hwaccel && !s->hwaccel_picture_private) { - s->hwaccel_picture_private = - av_mallocz(s->avctx->hwaccel->frame_priv_data_size); - if (!s->hwaccel_picture_private) - return AVERROR(ENOMEM); - - ret = s->avctx->hwaccel->start_frame(s->avctx, s->raw_image_buffer, - s->raw_image_buffer_size); - if (ret < 0) - return ret; - } - } - if (reference) { if (reference->width != s->picture_ptr->width || reference->height != s->picture_ptr->height || @@ -2572,7 +2561,6 @@ eoi_parser: break; } if (avctx->skip_frame == AVDISCARD_ALL) { - s->seen_sof = 0; s->got_picture = 0; ret = AVERROR(EAGAIN); goto the_end_no_picture; @@ -2586,7 +2574,6 @@ eoi_parser: } if ((ret = av_frame_ref(frame, s->picture_ptr)) < 0) return ret; - s->seen_sof = 0; s->got_picture = 0; frame->pkt_dts = s->pkt->dts; @@ -2647,7 +2634,6 @@ skip: av_log(avctx, AV_LOG_FATAL, "No JPEG data found in image\n"); return AVERROR_INVALIDDATA; fail: - s->seen_sof = 0; s->got_picture = 0; return ret; the_end: @@ -2938,7 +2924,6 @@ av_cold int ff_mjpeg_decode_end(AVCodecContext *avctx) static void decode_flush(AVCodecContext *avctx) { MJpegDecodeContext *s = avctx->priv_data; - s->seen_sof = 0; s->got_picture = 0; s->smv_next_frame = 0; diff --git a/libavcodec/mjpegdec.h b/libavcodec/mjpegdec.h index 71cacb0b27..2400a179f1 100644 --- a/libavcodec/mjpegdec.h +++ b/libavcodec/mjpegdec.h @@ -109,7 +109,6 @@ typedef struct MJpegDecodeContext { int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */ AVFrame *picture; /* picture structure */ AVFrame *picture_ptr; /* pointer to picture structure */ - int seen_sof; ///< we found a SOF. int got_picture; ///< we found a SOF and picture is valid, too. int linesize[MAX_COMPONENTS]; ///< linesize << interlaced int8_t *qscale_table; @@ -166,9 +165,7 @@ typedef struct MJpegDecodeContext { enum AVPixelFormat hwaccel_sw_pix_fmt; enum AVPixelFormat hwaccel_pix_fmt; void *hwaccel_picture_private; - struct JLSState *jls_state; - uint32_t palette[AVPALETTE_COUNT]; } MJpegDecodeContext; int ff_mjpeg_build_vlc(VLC *vlc, const uint8_t *bits_table, diff --git a/libavcodec/mxpegdec.c b/libavcodec/mxpegdec.c index 8283a3976a..7c97a9340e 100644 --- a/libavcodec/mxpegdec.c +++ b/libavcodec/mxpegdec.c @@ -197,7 +197,7 @@ static int mxpeg_decode_frame(AVCodecContext *avctx, buf_end = buf + buf_size; jpg->got_picture = 0; s->got_mxm_bitmask = 0; - jpg->seen_sof = s->got_sof_data = !!s->got_sof_data; + s->got_sof_data = !!s->got_sof_data; while (buf_ptr < buf_end) { start_code = ff_mjpeg_find_marker(jpg, &buf_ptr, buf_end, &unescaped_buf_ptr, &unescaped_buf_size); From patchwork Sun May 2 13:59:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 27555 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a11:cc:0:0:0:0 with SMTP id m12csp1250295pxt; Sun, 2 May 2021 07:00:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyv+pFnx1QovDPLAt63CsSpPlifE6bp6LWcoitv/9sIyIfjUlHNzt/TFP5txsFdJTFnYzwi X-Received: by 2002:a17:906:b156:: with SMTP id bt22mr12823832ejb.181.1619964024614; Sun, 02 May 2021 07:00:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619964024; cv=none; d=google.com; s=arc-20160816; b=gVyRsXftNe7+oNZuWtxR42xLbDlQUGmcbnNGfMb41rzZcGFihsMdRbkoRDRbi72Oz4 +SFtpWECVEh73sDBEV6IgV/ywmK63x5KBCMjpRKmuOA75Z6PfkS3oYwVS9RxhztOXO3I Q3Wv2YAnhVoLf1MkGX11Ak8n5lOZ1HjoWlU5Yohw1we79NOJoZpJsKWR7yenFwJJtFMC dwLHKXdDvhQBWH4qPGOt3ugPRur3o9DNAmb/85Pw8ocH4UT/5Qqt2pjAm1ckQ8WUyzo+ xuNR6WjB5Sca6sthopAtax8zU7wcuCoLaZrM92ec/C7orwRAlnzXHV+NDkFmANj75MLV LFZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=G9+U6TMh+jHj5r4sns7epse0ZkvS+2qob2/1AEKJX5E=; b=YnJuRecFmAsv5LET4evAb6ESqBWfIq6eKGAHsVE3o4Yh2KKC8LCeRMfHxC9oEDfazx NOIIXgmeQF907/x0uGMv2ODOudfd3y7LXE3AfVAV3jpHmfT10DbhoxoGtbJtD89fU9Zw TL1sJnbN1cUQLRZtPaFSw/KdHiJ8mDnEMwLgZ9e+Z9QYKGK9ipGn0hwCeo8J0IFoVsbq +aFYRbSb3NqJ/2oZFruPKKIbQiYzjf5G3kmpwZPDpPE7QY3tQPDGwXUszp305vccFVPJ pI+SnCqhFWDlVZkJeNHG72c7sup8tvooWjXlnf9DmTeUrXI443wdz/KQqip+ONYLUuhj kvAw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e12si8222197ejz.266.2021.05.02.07.00.24; Sun, 02 May 2021 07:00:24 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 019CB6897DE; Sun, 2 May 2021 17:00:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe03-1.mx.upcmail.net (vie01a-dmta-pe03-1.mx.upcmail.net [62.179.121.160]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 89F3668805F for ; Sun, 2 May 2021 17:00:07 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe03.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1ldCdj-00AwyN-0I for ffmpeg-devel@ffmpeg.org; Sun, 02 May 2021 16:00:07 +0200 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id dCclleYfOljeHdCcllCfh5; Sun, 02 May 2021 15:59:07 +0200 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.3 cv=BoHjPrf5 c=1 sm=1 tr=0 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=9GHDQ7sCeqCSBFeNCJEA:9 a=pHzHmUro8NiASowvMSCR:22 a=Ew2E2A-JSTLzCXPT_086:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 2 May 2021 15:59:05 +0200 Message-Id: <20210502135906.12288-3-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210502135906.12288-1-michael@niedermayer.cc> References: <20210502135906.12288-1-michael@niedermayer.cc> X-CMAE-Envelope: MS4wfLEjznkJP89Ee2LVuKwi4XEdFTiwqTlBGhX6YORoOps1LBepz5uJscnGt9UNO0YwKL/zLALQzMHv2Zvma24K7zsLPkz6wQyLfzjrGhSA/EAYVBlqhV74 AgGOfP7oy4nNwLmljczZ0K0+mUwyhRDrXL49wWmMwEzcXPiuXYuU82Sa Subject: [FFmpeg-devel] [PATCH 3/4] avcodec/mjpegdec: Decode to PAL8 independant of the location of LSE 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 9oD5EyCBcRya This simply performs a 2nd pass if a LSE is encountered with GRAY8 Fixes: tickets/3933/128.jls Signed-off-by: Michael Niedermayer --- libavcodec/jpeglsdec.c | 6 ++++-- libavcodec/mjpegdec.c | 10 +++++++--- libavcodec/mjpegdec.h | 1 + 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/libavcodec/jpeglsdec.c b/libavcodec/jpeglsdec.c index d79bbe1ee3..bd9224d97d 100644 --- a/libavcodec/jpeglsdec.c +++ b/libavcodec/jpeglsdec.c @@ -118,8 +118,10 @@ int ff_jpegls_decode_lse(MJpegDecodeContext *s) shift = 8 - s->avctx->bits_per_raw_sample; } - s->picture_ptr->format = - s->avctx->pix_fmt = AV_PIX_FMT_PAL8; + s->force_pal8 = 1; + if (!pal) + return 1; + for (i=s->palette_index; i<=maxtab; i++) { uint8_t k = i << shift; pal[k] = 0; diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 7c66ff8637..0691148027 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -582,7 +582,7 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) case 0x43000000: case 0x44000000: if(s->bits <= 8) - s->avctx->pix_fmt = AV_PIX_FMT_GRAY8; + s->avctx->pix_fmt = s->force_pal8 ? AV_PIX_FMT_PAL8 : AV_PIX_FMT_GRAY8; else s->avctx->pix_fmt = AV_PIX_FMT_GRAY16; break; @@ -681,7 +681,7 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) } else if (s->nb_components != 1) { av_log(s->avctx, AV_LOG_ERROR, "Unsupported number of components %d\n", s->nb_components); return AVERROR_PATCHWELCOME; - } else if (s->palette_index && s->bits <= 8) + } else if (s->palette_index && s->bits <= 8 || s->force_pal8) s->avctx->pix_fmt = AV_PIX_FMT_PAL8; else if (s->bits <= 8) s->avctx->pix_fmt = AV_PIX_FMT_GRAY8; @@ -2398,6 +2398,8 @@ int ff_mjpeg_receive_frame(AVCodecContext *avctx, AVFrame *frame) int ret = 0; int is16bit; + s->force_pal8 = 0; + if (avctx->codec_id == AV_CODEC_ID_SMVJPEG && s->smv_next_frame > 0) return smv_process_frame(avctx, frame); @@ -2411,7 +2413,7 @@ int ff_mjpeg_receive_frame(AVCodecContext *avctx, AVFrame *frame) ret = mjpeg_get_packet(avctx); if (ret < 0) return ret; - +redo_for_pal8: buf_ptr = s->pkt->data; buf_end = s->pkt->data + s->pkt->size; while (buf_ptr < buf_end) { @@ -2542,6 +2544,8 @@ int ff_mjpeg_receive_frame(AVCodecContext *avctx, AVFrame *frame) if (!CONFIG_JPEGLS_DECODER || (ret = ff_jpegls_decode_lse(s)) < 0) goto fail; + if (ret == 1) + goto redo_for_pal8; break; case EOI: eoi_parser: diff --git a/libavcodec/mjpegdec.h b/libavcodec/mjpegdec.h index 2400a179f1..648dd714e1 100644 --- a/libavcodec/mjpegdec.h +++ b/libavcodec/mjpegdec.h @@ -117,6 +117,7 @@ typedef struct MJpegDecodeContext { uint8_t *last_nnz[MAX_COMPONENTS]; uint64_t coefs_finished[MAX_COMPONENTS]; ///< bitmask of which coefs have been completely decoded (progressive mode) int palette_index; + int force_pal8; ScanTable scantable; BlockDSPContext bdsp; HpelDSPContext hdsp; From patchwork Sun May 2 13:59:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 27556 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a11:cc:0:0:0:0 with SMTP id m12csp1250224pxt; Sun, 2 May 2021 07:00:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBlv/V7mbfrBVU12RuVOF8wwtY3vJ0EBDjcCzJ4J0Q8j4GQ0QI7iJU5BV4fwyj+Hi/cRvG X-Received: by 2002:a17:906:c218:: with SMTP id d24mr12456605ejz.363.1619964017512; Sun, 02 May 2021 07:00:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619964017; cv=none; d=google.com; s=arc-20160816; b=qYHu5Nas/Nbtc+B2s5ujIHyDxKdBSlkMbVvwNBKdDSdPScoW3l3+uAOJlxUNQ8ZkUi k9455QHBOtNC3Eemy8es5UIn6ehdxoOVX60XoDHLJRpGiNnnkEWI4KGTsGk72geNc9M1 sJcSKZt1hyedPjnrL8uzu19A5sSlJyuQSpPC8j1qc92nW/96o/zxLL8YXxTJivoEFReX 3ODPkc7VtKIOY7L9Yu9gPrfl2Pit4Rj3KnyIexJHasJJa6FGDObJKMi5AahKJIlMrPKP lBG1G6UB6b+Akw5yIEhAbiguTbLo86OClIjdAc+VdHW/wI1PrJ9uYnhkeurVUDbPI2jl H4Aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=Y3AR3aTrOWiff3JXpku5QXECE6ySpnHMVqzXNOAyHD4=; b=duqEwGjk1EyKGKXRiZafNE/VSHjDNzX7bbtV1FZ+ATmPmSel4A3S+EZWliQZcw2i+0 ni8GkTfeVJKkoxlkh+6tBwd62ZYCgdAercQJIlhSyGgUDTu2z3QgL/WA5MpSNmjhEYvO aSl23aCEMnf/f0xYshnPPKVMZ8jaIlvjrl9yicEtmqnlwp3D3vDOKZG5nvosLzeMTilp Dab4iwzWRKg5UF+vL8EJnjJJp+/KpDkIFeEIuWFPkxY1sHqJG4v51/XOspB9U8OLwXAi NSJ291oBtR0lQUruvS6qP0ShaGHGoboMHH5CGsX+QlnbSUVTHb7+xEeHvVHuAZRJr1l0 IBqQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id d1si8066849ejy.218.2021.05.02.07.00.16; Sun, 02 May 2021 07:00:17 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 11E5D689721; Sun, 2 May 2021 17:00:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe03-1.mx.upcmail.net (vie01a-dmta-pe03-1.mx.upcmail.net [62.179.121.160]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8AC4168834D for ; Sun, 2 May 2021 17:00:07 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe03.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1ldCdj-00AwyP-0I for ffmpeg-devel@ffmpeg.org; Sun, 02 May 2021 16:00:07 +0200 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id dCclleYgMljeHdCcllCfhz; Sun, 02 May 2021 15:59:07 +0200 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.3 cv=BoHjPrf5 c=1 sm=1 tr=0 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=4a7iF7jn6RHxki7Wrw4A:9 a=pHzHmUro8NiASowvMSCR:22 a=Ew2E2A-JSTLzCXPT_086:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 2 May 2021 15:59:06 +0200 Message-Id: <20210502135906.12288-4-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210502135906.12288-1-michael@niedermayer.cc> References: <20210502135906.12288-1-michael@niedermayer.cc> X-CMAE-Envelope: MS4wfLEjznkJP89Ee2LVuKwi4XEdFTiwqTlBGhX6YORoOps1LBepz5uJscnGt9UNO0YwKL/zLALQzMHv2Zvma24K7zsLPkz6wQyLfzjrGhSA/EAYVBlqhV74 AgGOfP7oy4nNwLmljczZ0K0+mUwyhRDrXL49wWmMwEzcXPiuXYuU82Sa Subject: [FFmpeg-devel] [PATCH 4/4] avcodec/jpeglsdec: Set alpha plane in PAL8 so image is not 100% transparent 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: rc2TsDO7tIGi Fixes: tickets/3933/128.jls Signed-off-by: Michael Niedermayer --- libavcodec/jpeglsdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/jpeglsdec.c b/libavcodec/jpeglsdec.c index bd9224d97d..c61cb14f49 100644 --- a/libavcodec/jpeglsdec.c +++ b/libavcodec/jpeglsdec.c @@ -124,7 +124,7 @@ int ff_jpegls_decode_lse(MJpegDecodeContext *s) for (i=s->palette_index; i<=maxtab; i++) { uint8_t k = i << shift; - pal[k] = 0; + pal[k] = wt < 4 ? 0xFF000000 : 0; for (j=0; jgb, 8) << (8*(wt-j-1)); }