[FFmpeg-devel] [PATCH 1/2] jpeg2000dec: parse CDEF

Michael Niedermayer michaelni at gmx.at
Mon Jul 8 01:01:41 CEST 2013


Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
 libavcodec/jpeg2000dec.c |   24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index 0161ff7..c2f9bf6 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -75,6 +75,7 @@ typedef struct Jpeg2000DecoderContext {
     int             precision;
     int             ncomponents;
     int             colour_space;
+    int             cdef[4];
     int             tile_width, tile_height;
     unsigned        numXtiles, numYtiles;
     int             maxtilelen;
@@ -1234,6 +1235,13 @@ static int jpeg2000_decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
     if (tile->codsty[0].mct)
         mct_decode(s, tile);
 
+    if (s->cdef[0] < 0) {
+        for (x = 0; x < s->ncomponents; x++)
+            s->cdef[x] = x + 1;
+        if (s->ncomponents % 2 == 0)
+            s->cdef[s->ncomponents-1] = 0;
+    }
+
     if (s->precision <= 8) {
         for (compno = 0; compno < s->ncomponents; compno++) {
             Jpeg2000Component *comp = tile->comp + compno;
@@ -1486,6 +1494,21 @@ static int jp2_find_codestream(Jpeg2000DecoderContext *s)
                         atom2_size -= 3;
                     }
                     bytestream2_skipu(&s->g, atom2_size);
+                } else if (atom2 == MKBETAG('c','d','e','f') && atom2_size >= 2 &&
+                    bytestream2_get_bytes_left(&s->g) >= atom2_size) {
+                    int n = bytestream2_get_be16u(&s->g);
+                    atom_size  -= 2;
+                    atom2_size -= 2;
+                    for (; n>0; n--) {
+                        int cn   = bytestream2_get_be16(&s->g);
+                        int typ  = bytestream2_get_be16(&s->g);
+                        int asoc = bytestream2_get_be16(&s->g);
+                        if (cn < 4 || asoc < 4)
+                            s->cdef[cn] = asoc;
+                        atom_size  -= 6;
+                        atom2_size -= 6;
+                    }
+                    bytestream2_skipu(&s->g, atom2_size);
                 } else if (atom2_size <= atom_size &&
                     bytestream2_get_bytes_left(&s->g) >= atom2_size) {
                     bytestream2_skipu(&s->g, atom2_size);
@@ -1519,6 +1542,7 @@ static int jpeg2000_decode_frame(AVCodecContext *avctx, void *data,
     s->avctx     = avctx;
     bytestream2_init(&s->g, avpkt->data, avpkt->size);
     s->curtileno = -1;
+    memset(s->cdef, -1, sizeof(s->cdef));
 
     if (bytestream2_get_bytes_left(&s->g) < 2) {
         ret = AVERROR_INVALIDDATA;
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list