Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Wang Chuan <ouchuanm@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH] Correct space color when using libopenjpeg
Date: Sun, 12 Mar 2023 15:58:19 +0800
Message-ID: <ME3PR01MB5624D1F839EC031926965774DAB89@ME3PR01MB5624.ausprd01.prod.outlook.com> (raw)

When decoding jp2 with palette, [color space] is determined when calling
[opj_decode]. Because of this, [pix_fmt] should be set after decoding.
Otherwise, [pix_fmt] will be set to AV_PIX_FMT_GRAY8 and output an wrong
image.

Signed-off-by: Wang Chuan <ouchuanm@outlook.com>
---
  libavcodec/libopenjpegdec.c | 35 ++++++++++++++++++-----------------
  1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/libavcodec/libopenjpegdec.c b/libavcodec/libopenjpegdec.c
index 206db07ec7..1a8d599840 100644
--- a/libavcodec/libopenjpegdec.c
+++ b/libavcodec/libopenjpegdec.c
@@ -399,6 +399,23 @@ static int libopenjpeg_decode_frame(AVCodecContext 
*avctx, AVFrame *picture,
      if (ret < 0)
          goto done;
  +    ret = !opj_decode(dec, stream, image);
+
+    if (ret) {
+        av_log(avctx, AV_LOG_ERROR, "Error decoding codestream.\n");
+        ret = AVERROR_EXTERNAL;
+        goto done;
+    }
+
+    for (i = 0; i < image->numcomps; i++) {
+        if (!image->comps[i].data) {
+            av_log(avctx, AV_LOG_ERROR,
+                   "Image component %d contains no data.\n", i);
+            ret = AVERROR_INVALIDDATA;
+            goto done;
+        }
+    }
+
      if (avctx->pix_fmt != AV_PIX_FMT_NONE)
          if (!libopenjpeg_matches_pix_fmt(image, avctx->pix_fmt))
              avctx->pix_fmt = AV_PIX_FMT_NONE;
@@ -411,6 +428,7 @@ static int libopenjpeg_decode_frame(AVCodecContext 
*avctx, AVFrame *picture,
          ret = AVERROR_UNKNOWN;
          goto done;
      }
+
      for (i = 0; i < image->numcomps; i++)
          if (image->comps[i].prec > avctx->bits_per_raw_sample)
              avctx->bits_per_raw_sample = image->comps[i].prec;
@@ -418,23 +436,6 @@ static int libopenjpeg_decode_frame(AVCodecContext 
*avctx, AVFrame *picture,
      if ((ret = ff_thread_get_buffer(avctx, picture, 0)) < 0)
          goto done;
  -    ret = !opj_decode(dec, stream, image);
-
-    if (ret) {
-        av_log(avctx, AV_LOG_ERROR, "Error decoding codestream.\n");
-        ret = AVERROR_EXTERNAL;
-        goto done;
-    }
-
-    for (i = 0; i < image->numcomps; i++) {
-        if (!image->comps[i].data) {
-            av_log(avctx, AV_LOG_ERROR,
-                   "Image component %d contains no data.\n", i);
-            ret = AVERROR_INVALIDDATA;
-            goto done;
-        }
-    }
-
      desc       = av_pix_fmt_desc_get(avctx->pix_fmt);
      pixel_size = desc->comp[0].step;
      ispacked   = libopenjpeg_ispacked(avctx->pix_fmt);
-- 
2.37.1 (Apple Git-137.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".

             reply	other threads:[~2023-03-12  7:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-12  7:58 Wang Chuan [this message]
2023-03-17  8:35 ` Wang Chuan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ME3PR01MB5624D1F839EC031926965774DAB89@ME3PR01MB5624.ausprd01.prod.outlook.com \
    --to=ouchuanm@outlook.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git