diff mbox series

[FFmpeg-devel,3/5] libavcodec/jpeg2000dec.c Fixed WRITE_FRAME and tile co-ordinates:

Message ID 20200621184208.27665-3-gautamramk@gmail.com
State Accepted
Commit 42fdf402a79a1af4c500757106abfb9154bbcd42
Headers show
Series [FFmpeg-devel,1/5] libavcodec/jpeg2000.c: Precinct size check removed
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Gautam Ramakrishnan June 21, 2020, 6:42 p.m. UTC
From: Gautam Ramakrishnan <gautamramk@gmail.com>

libopenjpeg2000 uses ceiling division while dividing tile
co-ordinates with the sample separation. Also, corrections
were made to the WRITE_FRAME macro.
---
 libavcodec/jpeg2000dec.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

Comments

Michael Niedermayer June 22, 2020, 9:18 p.m. UTC | #1
On Mon, Jun 22, 2020 at 12:12:06AM +0530, gautamramk@gmail.com wrote:
> From: Gautam Ramakrishnan <gautamramk@gmail.com>
> 
> libopenjpeg2000 uses ceiling division while dividing tile
> co-ordinates with the sample separation. Also, corrections
> were made to the WRITE_FRAME macro.
> ---
>  libavcodec/jpeg2000dec.c | 24 ++++++++++++++----------
>  1 file changed, 14 insertions(+), 10 deletions(-)

is there a jpeg2000 file for which this makes a difference ?

thx

[...]
Gautam Ramakrishnan June 23, 2020, 2:20 a.m. UTC | #2
On Tue, Jun 23, 2020 at 2:48 AM Michael Niedermayer
<michael@niedermayer.cc> wrote:
>
> On Mon, Jun 22, 2020 at 12:12:06AM +0530, gautamramk@gmail.com wrote:
> > From: Gautam Ramakrishnan <gautamramk@gmail.com>
> >
> > libopenjpeg2000 uses ceiling division while dividing tile
> > co-ordinates with the sample separation. Also, corrections
> > were made to the WRITE_FRAME macro.
> > ---
> >  libavcodec/jpeg2000dec.c | 24 ++++++++++++++----------
> >  1 file changed, 14 insertions(+), 10 deletions(-)
>
> is there a jpeg2000 file for which this makes a difference ?
>
> thx
>
> [...]
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Awnsering whenever a program halts or runs forever is
> On a turing machine, in general impossible (turings halting problem).
> On any real computer, always possible as a real computer has a finite number
> of states N, and will either halt in less than N cycles or never halt.
> _______________________________________________
> 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".

This patch was also mainly for p1_01.j2k and p1_07.j2k. I did not mention
these two files in the commit messages as it needed the pixel format selection
change to work and the files could be decoded only if that path was applied.


--
-------------
Gautam |
Michael Niedermayer June 27, 2020, 10:43 a.m. UTC | #3
On Tue, Jun 23, 2020 at 07:50:11AM +0530, Gautam Ramakrishnan wrote:
> On Tue, Jun 23, 2020 at 2:48 AM Michael Niedermayer
> <michael@niedermayer.cc> wrote:
> >
> > On Mon, Jun 22, 2020 at 12:12:06AM +0530, gautamramk@gmail.com wrote:
> > > From: Gautam Ramakrishnan <gautamramk@gmail.com>
> > >
> > > libopenjpeg2000 uses ceiling division while dividing tile
> > > co-ordinates with the sample separation. Also, corrections
> > > were made to the WRITE_FRAME macro.
> > > ---
> > >  libavcodec/jpeg2000dec.c | 24 ++++++++++++++----------
> > >  1 file changed, 14 insertions(+), 10 deletions(-)
> >
> > is there a jpeg2000 file for which this makes a difference ?
> >
> > thx
> >
> > [...]
> > --
> > Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> >
> > Awnsering whenever a program halts or runs forever is
> > On a turing machine, in general impossible (turings halting problem).
> > On any real computer, always possible as a real computer has a finite number
> > of states N, and will either halt in less than N cycles or never halt.
> > _______________________________________________
> > 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".
> 
> This patch was also mainly for p1_01.j2k and p1_07.j2k. I did not mention
> these two files in the commit messages as it needed the pixel format selection
> change to work and the files could be decoded only if that path was applied.

ok will apply

thx
[...]
diff mbox series

Patch

diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index 05e85f4317..546a646668 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -978,12 +978,11 @@  static int init_tile(Jpeg2000DecoderContext *s, int tileno)
         comp->coord_o[0][1] = tile->coord[0][1];
         comp->coord_o[1][0] = tile->coord[1][0];
         comp->coord_o[1][1] = tile->coord[1][1];
-        if (compno) {
-            comp->coord_o[0][0] /= s->cdx[compno];
-            comp->coord_o[0][1] /= s->cdx[compno];
-            comp->coord_o[1][0] /= s->cdy[compno];
-            comp->coord_o[1][1] /= s->cdy[compno];
-        }
+
+        comp->coord_o[0][0] = ff_jpeg2000_ceildiv(comp->coord_o[0][0], s->cdx[compno]);
+        comp->coord_o[0][1] = ff_jpeg2000_ceildiv(comp->coord_o[0][1], s->cdx[compno]);
+        comp->coord_o[1][0] = ff_jpeg2000_ceildiv(comp->coord_o[1][0], s->cdy[compno]);
+        comp->coord_o[1][1] = ff_jpeg2000_ceildiv(comp->coord_o[1][1], s->cdy[compno]);
 
         comp->coord[0][0] = ff_jpeg2000_ceildivpow2(comp->coord_o[0][0], s->reduction_factor);
         comp->coord[0][1] = ff_jpeg2000_ceildivpow2(comp->coord_o[0][1], s->reduction_factor);
@@ -1936,18 +1935,23 @@  static inline void tile_codeblocks(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile
             float *datap     = comp->f_data;                                                      \
             int32_t *i_datap = comp->i_data;                                                      \
             int cbps         = s->cbps[compno];                                                   \
-            int w            = tile->comp[compno].coord[0][1] - s->image_offset_x;                \
+            int w            = tile->comp[compno].coord[0][1] -                                   \
+                               ff_jpeg2000_ceildiv(s->image_offset_x, s->cdx[compno]);            \
+            int h            = tile->comp[compno].coord[1][1] -                                   \
+                               ff_jpeg2000_ceildiv(s->image_offset_y, s->cdy[compno]);            \
             int plane        = 0;                                                                 \
                                                                                                   \
             if (planar)                                                                           \
                 plane = s->cdef[compno] ? s->cdef[compno]-1 : (s->ncomponents-1);                 \
                                                                                                   \
-            y    = tile->comp[compno].coord[1][0] - s->image_offset_y / s->cdy[compno];           \
+            y    = tile->comp[compno].coord[1][0] -                                               \
+                   ff_jpeg2000_ceildiv(s->image_offset_y, s->cdy[compno]);                        \
             line = (PIXEL *)picture->data[plane] + y * (picture->linesize[plane] / sizeof(PIXEL));\
-            for (; y < tile->comp[compno].coord[1][1] - s->image_offset_y; y++) {                 \
+            for (; y < h; y++) {                                                                  \
                 PIXEL *dst;                                                                       \
                                                                                                   \
-                x   = tile->comp[compno].coord[0][0] - s->image_offset_x / s->cdx[compno];        \
+                x   = tile->comp[compno].coord[0][0] -                                            \
+                      ff_jpeg2000_ceildiv(s->image_offset_x, s->cdx[compno]);                     \
                 dst = line + x * pixelsize + compno*!planar;                                      \
                                                                                                   \
                 if (codsty->transform == FF_DWT97) {                                              \