]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/jpeg2000dec.c
v210enc: Add SIMD optimised 8-bit and 10-bit encoders
[ffmpeg] / libavcodec / jpeg2000dec.c
index cc154c3522dc1f335f163880448dcfe0ca58da15..51352979e79464f8f8418980fa6c9dd6c85dc0d7 100644 (file)
@@ -25,6 +25,9 @@
  * JPEG 2000 image decoder
  */
 
+#include <inttypes.h>
+
+#include "libavutil/attributes.h"
 #include "libavutil/common.h"
 #include "libavutil/opt.h"
 #include "avcodec.h"
@@ -32,6 +35,7 @@
 #include "internal.h"
 #include "thread.h"
 #include "jpeg2000.h"
+#include "jpeg2000dsp.h"
 
 #define JP2_SIG_TYPE    0x6A502020
 #define JP2_SIG_VALUE   0x0D0A870A
@@ -82,6 +86,7 @@ typedef struct Jpeg2000DecoderContext {
 
     int16_t         curtileno;
     Jpeg2000Tile    *tile;
+    Jpeg2000DSPContext dsp;
 
     /*options parameters*/
     int             reduction_factor;
@@ -178,7 +183,7 @@ static int get_siz(Jpeg2000DecoderContext *s)
         return AVERROR_INVALIDDATA;
     }
 
-    if (ncomponents > 3) {
+    if (ncomponents > 4) {
         avpriv_request_sample(s->avctx, "Support for %d components",
                               s->ncomponents);
         return AVERROR_PATCHWELCOME;
@@ -345,7 +350,7 @@ static int get_cod(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c,
 
     if (tmp.mct && s->ncomponents < 3) {
         av_log(s->avctx, AV_LOG_ERROR,
-               "MCT %d with too few components (%d)\n",
+               "MCT %"PRIu8" with too few components (%d)\n",
                tmp.mct, s->ncomponents);
         return AVERROR_INVALIDDATA;
     }
@@ -497,12 +502,12 @@ static int get_sot(Jpeg2000DecoderContext *s, int n)
     bytestream2_get_byteu(&s->g);               // TNsot
 
     if (Psot > bytestream2_get_bytes_left(&s->g) + n + 2) {
-        av_log(s->avctx, AV_LOG_ERROR, "Psot %d too big\n", Psot);
+        av_log(s->avctx, AV_LOG_ERROR, "Psot %"PRIu32" too big\n", Psot);
         return AVERROR_INVALIDDATA;
     }
 
     if (TPsot >= FF_ARRAY_ELEMS(s->tile[Isot].tile_part)) {
-        avpriv_request_sample(s->avctx, "Support for %d components", TPsot);
+        avpriv_request_sample(s->avctx, "Support for %"PRIu8" components", TPsot);
         return AVERROR_PATCHWELCOME;
     }
 
@@ -718,7 +723,7 @@ static int jpeg2000_decode_packet(Jpeg2000DecoderContext *s,
 
             if (cblk->length > sizeof(cblk->data)) {
                 av_log(s->avctx, AV_LOG_ERROR,
-                       "Block length %d > data size %zd\n",
+                       "Block length %"PRIu16" > data size %zd\n",
                        cblk->length, sizeof(cblk->data));
                 return AVERROR_INVALIDDATA;
             }
@@ -1038,69 +1043,21 @@ static void dequantization_int(int x, int y, Jpeg2000Cblk *cblk,
     }
 }
 
-/* Inverse ICT parameters in float and integer.
- * int value = (float value) * (1<<16) */
-static const float f_ict_params[4] = {
-    1.402f,
-    0.34413f,
-    0.71414f,
-    1.772f
-};
-static const int   i_ict_params[4] = {
-     91881,
-     22553,
-     46802,
-    116130
-};
-
-static void mct_decode(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
+static inline void mct_decode(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
 {
     int i, csize = 1;
-    int32_t *src[3],  i0,  i1,  i2;
-    float   *srcf[3], i0f, i1f, i2f;
+    void *src[3];
 
     for (i = 0; i < 3; i++)
         if (tile->codsty[0].transform == FF_DWT97)
-            srcf[i] = tile->comp[i].f_data;
+            src[i] = tile->comp[i].f_data;
         else
-            src [i] = tile->comp[i].i_data;
+            src[i] = tile->comp[i].i_data;
 
     for (i = 0; i < 2; i++)
         csize *= tile->comp[0].coord[i][1] - tile->comp[0].coord[i][0];
-    switch (tile->codsty[0].transform) {
-    case FF_DWT97:
-        for (i = 0; i < csize; i++) {
-            i0f = *srcf[0] + (f_ict_params[0] * *srcf[2]);
-            i1f = *srcf[0] - (f_ict_params[1] * *srcf[1])
-                           - (f_ict_params[2] * *srcf[2]);
-            i2f = *srcf[0] + (f_ict_params[3] * *srcf[1]);
-            *srcf[0]++ = i0f;
-            *srcf[1]++ = i1f;
-            *srcf[2]++ = i2f;
-        }
-        break;
-    case FF_DWT97_INT:
-        for (i = 0; i < csize; i++) {
-            i0 = *src[0] + (((i_ict_params[0] * *src[2]) + (1 << 15)) >> 16);
-            i1 = *src[0] - (((i_ict_params[1] * *src[1]) + (1 << 15)) >> 16)
-                         - (((i_ict_params[2] * *src[2]) + (1 << 15)) >> 16);
-            i2 = *src[0] + (((i_ict_params[3] * *src[1]) + (1 << 15)) >> 16);
-            *src[0]++ = i0;
-            *src[1]++ = i1;
-            *src[2]++ = i2;
-        }
-        break;
-    case FF_DWT53:
-        for (i = 0; i < csize; i++) {
-            i1 = *src[0] - (*src[2] + *src[1] >> 2);
-            i0 = i1 + *src[2];
-            i2 = i1 + *src[1];
-            *src[0]++ = i0;
-            *src[1]++ = i1;
-            *src[2]++ = i2;
-        }
-        break;
-    }
+
+    s->dsp.mct_decode[tile->codsty[0].transform](src[0], src[1], src[2], csize);
 }
 
 static int jpeg2000_decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
@@ -1343,14 +1300,15 @@ static int jpeg2000_read_main_headers(Jpeg2000DecoderContext *s)
             break;
         default:
             av_log(s->avctx, AV_LOG_ERROR,
-                   "unsupported marker 0x%.4X at pos 0x%X\n",
+                   "unsupported marker 0x%.4"PRIX16" at pos 0x%X\n",
                    marker, bytestream2_tell(&s->g) - 4);
             bytestream2_skip(&s->g, len - 2);
             break;
         }
         if (bytestream2_tell(&s->g) - oldpos != len || ret) {
             av_log(s->avctx, AV_LOG_ERROR,
-                   "error during processing marker segment %.4x\n", marker);
+                   "error during processing marker segment %.4"PRIx16"\n",
+                   marker);
             return ret ? ret : -1;
         }
     }
@@ -1402,6 +1360,15 @@ static int jp2_find_codestream(Jpeg2000DecoderContext *s)
     return 0;
 }
 
+static av_cold int jpeg2000_decode_init(AVCodecContext *avctx)
+{
+    Jpeg2000DecoderContext *s = avctx->priv_data;
+
+    ff_jpeg2000dsp_init(&s->dsp);
+
+    return 0;
+}
+
 static int jpeg2000_decode_frame(AVCodecContext *avctx, void *data,
                                  int *got_frame, AVPacket *avpkt)
 {
@@ -1467,7 +1434,7 @@ end:
     return ret;
 }
 
-static void jpeg2000_init_static_data(AVCodec *codec)
+static av_cold void jpeg2000_init_static_data(AVCodec *codec)
 {
     ff_jpeg2000_init_tier1_luts();
     ff_mqc_init_context_tables();
@@ -1506,6 +1473,7 @@ AVCodec ff_jpeg2000_decoder = {
     .capabilities     = CODEC_CAP_FRAME_THREADS,
     .priv_data_size   = sizeof(Jpeg2000DecoderContext),
     .init_static_data = jpeg2000_init_static_data,
+    .init             = jpeg2000_decode_init,
     .decode           = jpeg2000_decode_frame,
     .priv_class       = &class,
     .profiles         = NULL_IF_CONFIG_SMALL(profiles)