]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/libopenjpegdec.c
libopenjpeg: make .long_name usefull
[ffmpeg] / libavcodec / libopenjpegdec.c
index 07cca2547b76ff2dd4ecb57e1859611121fc8743..29724a2f9f4b05933e2d8b3d35ccabde69841c7a 100644 (file)
@@ -50,6 +50,19 @@ 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;
@@ -91,15 +104,6 @@ libopenjpeg_rgb:
     return PIX_FMT_RGB24;
 }
 
-static int is_yuva420(opj_image_t *image)
-{
-    return image->numcomps == 4 &&
-           image->comps[0].dx == 1 && image->comps[0].dy == 1 &&
-           image->comps[1].dx == 2 && image->comps[1].dy == 2 &&
-           image->comps[2].dx == 2 && image->comps[2].dy == 2 &&
-           image->comps[3].dx == 1 && image->comps[3].dy == 1;
-}
-
 static inline int libopenjpeg_ispacked(enum PixelFormat pix_fmt) {
     int i, component_plane;
     component_plane = av_pix_fmt_descriptors[pix_fmt].comp[0].plane;
@@ -258,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 = is_yuva420(image) ? PIX_FMT_YUVA420P : 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;
@@ -303,7 +308,11 @@ 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:
@@ -312,6 +321,7 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
         }
         break;
     case 6:
+    case 8:
         if (ispacked) {
             libopenjpeg_copy_to_packed16(picture, image);
         }
@@ -351,6 +361,6 @@ AVCodec ff_libopenjpeg_decoder = {
     .decode         = libopenjpeg_decode_frame,
     .capabilities   = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS,
     .max_lowres     = 5,
-    .long_name      = NULL_IF_CONFIG_SMALL("OpenJPEG based JPEG 2000 decoder"),
+    .long_name      = NULL_IF_CONFIG_SMALL("OpenJPEG JPEG 2000"),
     .init_thread_copy = ONLY_IF_THREADS_ENABLED(libopenjpeg_decode_init_thread_copy)
 };