* [FFmpeg-devel] [PATCH] Correct space color when using libopenjpeg
@ 2023-03-12 7:58 Wang Chuan
2023-03-17 8:35 ` Wang Chuan
0 siblings, 1 reply; 2+ messages in thread
From: Wang Chuan @ 2023-03-12 7:58 UTC (permalink / raw)
To: ffmpeg-devel
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".
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [FFmpeg-devel] [PATCH] Correct space color when using libopenjpeg
2023-03-12 7:58 [FFmpeg-devel] [PATCH] Correct space color when using libopenjpeg Wang Chuan
@ 2023-03-17 8:35 ` Wang Chuan
0 siblings, 0 replies; 2+ messages in thread
From: Wang Chuan @ 2023-03-17 8:35 UTC (permalink / raw)
To: ffmpeg-devel
ping ?
On 3/12/2023 3:58 PM, Wang Chuan wrote:
> 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);
_______________________________________________
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".
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-03-17 8:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-12 7:58 [FFmpeg-devel] [PATCH] Correct space color when using libopenjpeg Wang Chuan
2023-03-17 8:35 ` Wang Chuan
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