]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/libopenjpegdec.c
zmbv: remove unused variable
[ffmpeg] / libavcodec / libopenjpegdec.c
index baa516b66bb107ed36b90db3d8dcf7649ffd0e58..89bfb34913f602f604438c99e0250a36290f87d1 100644 (file)
@@ -50,11 +50,25 @@ static enum PixelFormat check_image_attributes(AVCodecContext *avctx, opj_image_
     compRatio |= c1.dx << 9  | c1.dy << 6;
     compRatio |= c2.dx << 3  | c2.dy;
 
+    if (image->numcomps == 4) {
+        if (c0.prec == 8) {
+            if (compRatio == 0112222 &&
+                image->comps[3].dx == 1 && image->comps[3].dy == 1) {
+                return PIX_FMT_YUVA420P;
+            } else {
+                return PIX_FMT_RGBA;
+            }
+        } else {
+            return PIX_FMT_RGBA64;
+        }
+    }
+
     switch (compRatio) {
     case 0111111: goto libopenjpeg_yuv444_rgb;
+    case 0111212: return PIX_FMT_YUV440P;
     case 0112121: goto libopenjpeg_yuv422;
     case 0112222: goto libopenjpeg_yuv420;
-    default: return PIX_FMT_RGB24;
+    default: goto libopenjpeg_rgb;
     }
 
 libopenjpeg_yuv420:
@@ -80,6 +94,13 @@ libopenjpeg_yuv444_rgb:
     case 10: return PIX_FMT_YUV444P10;
     case 16: return PIX_FMT_YUV444P16;
     }
+
+libopenjpeg_rgb:
+    switch (c0.prec) {
+    case 8: return PIX_FMT_RGB24;
+    default: return PIX_FMT_RGB48;
+    }
+
     return PIX_FMT_RGB24;
 }
 
@@ -107,6 +128,24 @@ static inline void libopenjpeg_copy_to_packed8(AVFrame *picture, opj_image_t *im
     }
 }
 
+static inline void libopenjpeg_copy_to_packed16(AVFrame *picture, opj_image_t *image) {
+    uint16_t *img_ptr;
+    int index, x, y, c;
+    int adjust[4];
+    for (x = 0; x < image->numcomps; x++) {
+        adjust[x] = FFMAX(FFMIN(16 - image->comps[x].prec, 8), 0);
+    }
+    for (y = 0; y < picture->height; y++) {
+        index = y*picture->width;
+        img_ptr = (uint16_t*) (picture->data[0] + y*picture->linesize[0]);
+        for (x = 0; x < picture->width; x++, index++) {
+            for (c = 0; c < image->numcomps; c++) {
+                *img_ptr++ = image->comps[c].data[index] << adjust[c];
+            }
+        }
+    }
+}
+
 static inline void libopenjpeg_copyto8(AVFrame *picture, opj_image_t *image) {
     int *comp_data;
     uint8_t *img_ptr;
@@ -114,8 +153,8 @@ static inline void libopenjpeg_copyto8(AVFrame *picture, opj_image_t *image) {
 
     for(index = 0; index < image->numcomps; index++) {
         comp_data = image->comps[index].data;
-        img_ptr = picture->data[index];
         for(y = 0; y < image->comps[index].h; y++) {
+            img_ptr = picture->data[index] + y * picture->linesize[index];
             for(x = 0; x < image->comps[index].w; x++) {
                 *img_ptr = (uint8_t) *comp_data;
                 img_ptr++;
@@ -131,8 +170,8 @@ static inline void libopenjpeg_copyto16(AVFrame *picture, opj_image_t *image) {
     int index, x, y;
     for(index = 0; index < image->numcomps; index++) {
         comp_data = image->comps[index].data;
-        img_ptr = (uint16_t*) picture->data[index];
         for(y = 0; y < image->comps[index].h; y++) {
+            img_ptr = (uint16_t*) (picture->data[index] + y * picture->linesize[index]);
             for(x = 0; x < image->comps[index].w; x++) {
                 *img_ptr = *comp_data;
                 img_ptr++;
@@ -223,11 +262,12 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
     avcodec_set_dimensions(avctx, width, height);
 
     switch (image->numcomps) {
-    case 1:  avctx->pix_fmt = PIX_FMT_GRAY8;
+    case 1:  avctx->pix_fmt = (image->comps[0].bpp == 8) ? PIX_FMT_GRAY8 : PIX_FMT_GRAY16;
              break;
-    case 3:  avctx->pix_fmt = check_image_attributes(avctx, image);
+    case 2:  avctx->pix_fmt = PIX_FMT_GRAY8A;
              break;
-    case 4:  avctx->pix_fmt = PIX_FMT_RGBA;
+    case 3:
+    case 4:  avctx->pix_fmt = check_image_attributes(avctx, image);
              break;
     default: av_log(avctx, AV_LOG_ERROR, "%d components unsupported.\n", image->numcomps);
              goto done;
@@ -241,8 +281,6 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
         return -1;
     }
 
-    ff_thread_finish_setup(avctx);
-
     ctx->dec_params.cp_limit_decoding = NO_LIMITATION;
     ctx->dec_params.cp_reduce = avctx->lowres;
     // Tie decoder with decoding parameters
@@ -270,13 +308,24 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
         }
         break;
     case 2:
-        libopenjpeg_copyto16(picture, image);
+        if (ispacked) {
+            libopenjpeg_copy_to_packed8(picture, image);
+        } else {
+            libopenjpeg_copyto16(picture, image);
+        }
         break;
     case 3:
+    case 4:
         if (ispacked) {
             libopenjpeg_copy_to_packed8(picture, image);
         }
         break;
+    case 6:
+    case 8:
+        if (ispacked) {
+            libopenjpeg_copy_to_packed16(picture, image);
+        }
+        break;
     default:
         av_log(avctx, AV_LOG_ERROR, "unsupported pixel size %d\n", pixel_size);
         goto done;