Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Michael Niedermayer <michael@niedermayer.cc>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH 2/3] avcodec/j2kenc: Add alpha support
Date: Fri, 31 Mar 2023 01:14:40 +0200
Message-ID: <20230330231441.8868-2-michael@niedermayer.cc> (raw)
In-Reply-To: <20230330231441.8868-1-michael@niedermayer.cc>

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/j2kenc.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c
index 97b0da1c976..b23fb73770a 100644
--- a/libavcodec/j2kenc.c
+++ b/libavcodec/j2kenc.c
@@ -320,8 +320,8 @@ static int put_siz(Jpeg2000EncoderContext *s)
 
     for (i = 0; i < s->ncomponents; i++){ // Ssiz_i XRsiz_i, YRsiz_i
         bytestream_put_byte(&s->buf, s->cbps[i] - 1);
-        bytestream_put_byte(&s->buf, i?1<<s->chroma_shift[0]:1);
-        bytestream_put_byte(&s->buf, i?1<<s->chroma_shift[1]:1);
+        bytestream_put_byte(&s->buf, (i%3)?1<<s->chroma_shift[0]:1);
+        bytestream_put_byte(&s->buf, (i%3)?1<<s->chroma_shift[1]:1);
     }
     return 0;
 }
@@ -432,7 +432,7 @@ static void compute_rates(Jpeg2000EncoderContext* s)
             for (compno = 0; compno < s->ncomponents; compno++) {
                 int tilew = tile->comp[compno].coord[0][1] - tile->comp[compno].coord[0][0];
                 int tileh = tile->comp[compno].coord[1][1] - tile->comp[compno].coord[1][0];
-                int scale = (compno?1 << s->chroma_shift[0]:1) * (compno?1 << s->chroma_shift[1]:1);
+                int scale = ((compno%3)?1 << s->chroma_shift[0]:1) * ((compno%3)?1 << s->chroma_shift[1]:1);
                 for (layno = 0; layno < s->nlayers; layno++) {
                     if (s->layer_rates[layno] > 0) {
                         tile->layer_rates[layno] += (double)(tilew * tileh) * s->ncomponents * s->cbps[compno] /
@@ -484,7 +484,7 @@ static int init_tiles(Jpeg2000EncoderContext *s)
                 comp->coord[0][1] = comp->coord_o[0][1] = FFMIN((tilex+1)*s->tile_width, s->width);
                 comp->coord[1][0] = comp->coord_o[1][0] = tiley * s->tile_height;
                 comp->coord[1][1] = comp->coord_o[1][1] = FFMIN((tiley+1)*s->tile_height, s->height);
-                if (compno > 0)
+                if (compno % 3)
                     for (i = 0; i < 2; i++)
                         for (j = 0; j < 2; j++)
                             comp->coord[i][j] = comp->coord_o[i][j] = ff_jpeg2000_ceildivpow2(comp->coord[i][j], s->chroma_shift[i]);
@@ -493,8 +493,8 @@ static int init_tiles(Jpeg2000EncoderContext *s)
                                                 codsty,
                                                 qntsty,
                                                 s->cbps[compno],
-                                                compno?1<<s->chroma_shift[0]:1,
-                                                compno?1<<s->chroma_shift[1]:1,
+                                                (compno%3)?1<<s->chroma_shift[0]:1,
+                                                (compno%3)?1<<s->chroma_shift[1]:1,
                                                 s->avctx
                                                )) < 0)
                     return ret;
@@ -1009,7 +1009,7 @@ static int encode_packets(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile, int til
                     Jpeg2000Component *comp     = tile->comp + compno;
                     uint8_t reducedresno = codsty->nreslevels - 1 -reslevelno; //  ==> N_L - r
                     Jpeg2000ResLevel *reslevel = comp->reslevel + reslevelno;
-                    int log_subsampling[2] = { compno?s->chroma_shift[0]:0, compno?s->chroma_shift[1]:0};
+                    int log_subsampling[2] = { (compno%3)?s->chroma_shift[0]:0, (compno%3)?s->chroma_shift[1]:0};
                     unsigned prcx, prcy;
                     int trx0, try0;
 
@@ -1070,7 +1070,7 @@ static int encode_packets(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile, int til
             for (x = tile_coord[0][0]; x < tile_coord[0][1]; x = (x/step_x + 1)*step_x) {
                 for (compno = 0; compno < s->ncomponents; compno++) {
                     Jpeg2000Component *comp     = tile->comp + compno;
-                    int log_subsampling[2] = { compno?s->chroma_shift[0]:0, compno?s->chroma_shift[1]:0};
+                    int log_subsampling[2] = { (compno%3)?s->chroma_shift[0]:0, (compno%3)?s->chroma_shift[1]:0};
 
                     for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++) {
                         unsigned prcx, prcy;
@@ -1116,7 +1116,7 @@ static int encode_packets(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile, int til
     case JPEG2000_PGOD_CPRL:
         for (compno = 0; compno < s->ncomponents; compno++) {
             Jpeg2000Component *comp     = tile->comp + compno;
-            int log_subsampling[2] = { compno?s->chroma_shift[0]:0, compno?s->chroma_shift[1]:0};
+            int log_subsampling[2] = { (compno%3)?s->chroma_shift[0]:0, (compno%3)?s->chroma_shift[1]:0};
             step_x = 32;
             step_y = 32;
 
@@ -1763,7 +1763,7 @@ static av_cold int j2kenc_init(AVCodecContext *avctx)
     s->height = avctx->height;
 
     s->ncomponents = desc->nb_components;
-    for (i = 0; i < 3; i++) {
+    for (i = 0; i < 4; i++) {
         s->cbps[i] = desc->comp[i].depth;
         s->comp_remap[i] = i; //default
     }
@@ -1853,6 +1853,14 @@ const FFCodec ff_jpeg2000_encoder = {
         AV_PIX_FMT_YUV440P,                      AV_PIX_FMT_YUV440P10, AV_PIX_FMT_YUV440P12,
         AV_PIX_FMT_YUV411P,
         AV_PIX_FMT_YUV410P,
+        AV_PIX_FMT_YUVA420P,
+
+        AV_PIX_FMT_RGBA,                                          AV_PIX_FMT_RGBA64,
+        AV_PIX_FMT_GBRAP, AV_PIX_FMT_GBRAP10, AV_PIX_FMT_GBRAP12, AV_PIX_FMT_GBRAP16,
+        AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUVA420P9, AV_PIX_FMT_YUVA420P10, AV_PIX_FMT_YUVA420P16,
+        AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA422P16,
+        AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA444P16,
+
         AV_PIX_FMT_PAL8,
         AV_PIX_FMT_NONE
     },
-- 
2.17.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-30 23:15 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-30 23:14 [FFmpeg-devel] [PATCH 1/3] avcodec/j2kenc: Add forgotten yuv440 variants Michael Niedermayer
2023-03-30 23:14 ` Michael Niedermayer [this message]
2023-04-02 21:34   ` [FFmpeg-devel] [PATCH 2/3] avcodec/j2kenc: Add alpha support Michael Niedermayer
2023-04-05 12:50     ` Tomas Härdin
2023-04-05 23:36       ` Michael Niedermayer
2023-04-06 14:15     ` Leo Izen
2023-04-06 19:18       ` Michael Niedermayer
2023-03-30 23:14 ` [FFmpeg-devel] [PATCH 3/3] [RFC] Remove libopenjpegenc Michael Niedermayer
2023-03-30 23:26   ` Pierre-Anthony Lemieux
2023-03-30 23:31   ` Michael Bradshaw
2023-04-01 23:37     ` Stefano Sabatini
2023-04-05 12:55   ` Tomas Härdin
2023-04-12  1:48     ` Pierre-Anthony Lemieux
2023-04-02 21:24 ` [FFmpeg-devel] [PATCH 1/3] avcodec/j2kenc: Add forgotten yuv440 variants Michael Niedermayer

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=20230330231441.8868-2-michael@niedermayer.cc \
    --to=michael@niedermayer.cc \
    --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