]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/mjpegdec.c
cosmetic: align backslashes in makefiles
[ffmpeg] / libavcodec / mjpegdec.c
index 7dc0616a8f73c6cd86c54e2ef3a8326d18365de4..e8a34ef2ba94e3060bf7e4cbb901ec1ec67e8409 100644 (file)
@@ -64,16 +64,16 @@ static int build_vlc(VLC *vlc, const uint8_t *bits_table, const uint8_t *val_tab
 
 static void build_basic_mjpeg_vlc(MJpegDecodeContext * s) {
     build_vlc(&s->vlcs[0][0], ff_mjpeg_bits_dc_luminance,
-              ff_mjpeg_val_dc_luminance, 12, 0, 0);
+              ff_mjpeg_val_dc, 12, 0, 0);
     build_vlc(&s->vlcs[0][1], ff_mjpeg_bits_dc_chrominance,
-              ff_mjpeg_val_dc_chrominance, 12, 0, 0);
+              ff_mjpeg_val_dc, 12, 0, 0);
     build_vlc(&s->vlcs[1][0], ff_mjpeg_bits_ac_luminance,
               ff_mjpeg_val_ac_luminance, 251, 0, 1);
     build_vlc(&s->vlcs[1][1], ff_mjpeg_bits_ac_chrominance,
               ff_mjpeg_val_ac_chrominance, 251, 0, 1);
 }
 
-int ff_mjpeg_decode_init(AVCodecContext *avctx)
+av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx)
 {
     MJpegDecodeContext *s = avctx->priv_data;
 
@@ -284,31 +284,34 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
         return 0;
 
     /* XXX: not complete test ! */
-    pix_fmt_id = (s->h_count[0] << 20) | (s->v_count[0] << 16) |
-                 (s->h_count[1] << 12) | (s->v_count[1] <<  8) |
-                 (s->h_count[2] <<  4) |  s->v_count[2];
+    pix_fmt_id = (s->h_count[0] << 28) | (s->v_count[0] << 24) |
+                 (s->h_count[1] << 20) | (s->v_count[1] << 16) |
+                 (s->h_count[2] << 12) | (s->v_count[2] <<  8) |
+                 (s->h_count[3] <<  4) |  s->v_count[3];
     av_log(s->avctx, AV_LOG_DEBUG, "pix fmt id %x\n", pix_fmt_id);
+    if(!(pix_fmt_id & 0x10101010))
+        pix_fmt_id-= (pix_fmt_id & 0xF0F0F0F0)>>1;
+    if(!(pix_fmt_id & 0x01010101))
+        pix_fmt_id-= (pix_fmt_id & 0x0F0F0F0F)>>1;
+
     switch(pix_fmt_id){
-    case 0x222222:
-    case 0x111111:
+    case 0x11111100:
         if(s->rgb){
             s->avctx->pix_fmt = PIX_FMT_RGB32;
-        }else if(s->nb_components==3)
+        }else
             s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV444P : PIX_FMT_YUVJ444P;
-        else
-            s->avctx->pix_fmt = PIX_FMT_GRAY8;
+        assert(s->nb_components==3);
         break;
-    case 0x110000:
+    case 0x11000000:
         s->avctx->pix_fmt = PIX_FMT_GRAY8;
         break;
-    case 0x121111:
+    case 0x12111100:
         s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV440P : PIX_FMT_YUVJ440P;
         break;
-    case 0x211111:
-    case 0x221212:
+    case 0x21111100:
         s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV422P : PIX_FMT_YUVJ422P;
         break;
-    case 0x221111:
+    case 0x22111100:
         s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV420P : PIX_FMT_YUVJ420P;
         break;
     default:
@@ -332,7 +335,7 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
         av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         return -1;
     }
-    s->picture.pict_type= I_TYPE;
+    s->picture.pict_type= FF_I_TYPE;
     s->picture.key_frame= 1;
 
     for(i=0; i<3; i++){
@@ -669,6 +672,12 @@ static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int ss, i
         int c = s->comp_index[i];
         data[c] = s->picture.data[c];
         linesize[c]=s->linesize[c];
+        if(s->avctx->codec->id==CODEC_ID_AMV) {
+            //picture should be flipped upside-down for this codec
+            assert(!(s->avctx->flags & CODEC_FLAG_EMU_EDGE));
+            data[c] += (linesize[c] * (s->v_scount[i] * (8 * s->mb_height -((s->height/s->v_max)&7)) - 1 ));
+            linesize[c] *= -1;
+        }
     }
 
     for(mb_y = 0; mb_y < s->mb_height; mb_y++) {
@@ -828,7 +837,8 @@ int ff_mjpeg_decode_sos(MJpegDecodeContext *s)
 //            for(){
 //            reset_ls_coding_parameters(s, 0);
 
-            ff_jpegls_decode_picture(s, predictor, point_transform, ilv);
+            if(ff_jpegls_decode_picture(s, predictor, point_transform, ilv) < 0)
+                return -1;
         }else{
             if(s->rgb){
                 if(ljpeg_decode_rgb_scan(s, predictor, point_transform) < 0)
@@ -1067,9 +1077,9 @@ static int valid_marker_list[] =
 
 /* return the 8 bit start code value and update the search
    state. Return -1 if no start code found */
-static int find_marker(uint8_t **pbuf_ptr, uint8_t *buf_end)
+static int find_marker(const uint8_t **pbuf_ptr, const uint8_t *buf_end)
 {
-    uint8_t *buf_ptr;
+    const uint8_t *buf_ptr;
     unsigned int v, v2;
     int val;
 #ifdef DEBUG
@@ -1099,10 +1109,10 @@ found:
 
 int ff_mjpeg_decode_frame(AVCodecContext *avctx,
                               void *data, int *data_size,
-                              uint8_t *buf, int buf_size)
+                              const uint8_t *buf, int buf_size)
 {
     MJpegDecodeContext *s = avctx->priv_data;
-    uint8_t *buf_end, *buf_ptr;
+    const uint8_t *buf_end, *buf_ptr;
     int start_code;
     AVFrame *picture = data;
 
@@ -1130,7 +1140,7 @@ int ff_mjpeg_decode_frame(AVCodecContext *avctx,
                 /* unescape buffer of SOS, use special treatment for JPEG-LS */
                 if (start_code == SOS && !s->ls)
                 {
-                    uint8_t *src = buf_ptr;
+                    const uint8_t *src = buf_ptr;
                     uint8_t *dst = s->buffer;
 
                     while (src<buf_end)
@@ -1157,7 +1167,7 @@ int ff_mjpeg_decode_frame(AVCodecContext *avctx,
                            (buf_end - buf_ptr) - (dst - s->buffer));
                 }
                 else if(start_code == SOS && s->ls){
-                    uint8_t *src = buf_ptr;
+                    const uint8_t *src = buf_ptr;
                     uint8_t *dst = s->buffer;
                     int bit_count = 0;
                     int t = 0, b = 0;
@@ -1278,7 +1288,7 @@ eoi_parser:
                         *data_size = sizeof(AVFrame);
 
                         if(!s->lossless){
-                            picture->quality= FFMAX(FFMAX(s->qscale[0], s->qscale[1]), s->qscale[2]);
+                            picture->quality= FFMAX3(s->qscale[0], s->qscale[1], s->qscale[2]);
                             picture->qstride= 0;
                             picture->qscale_table= s->qscale_table;
                             memset(picture->qscale_table, picture->quality, (s->width+15)/16);
@@ -1332,7 +1342,7 @@ the_end:
     return buf_ptr - buf;
 }
 
-int ff_mjpeg_decode_end(AVCodecContext *avctx)
+av_cold int ff_mjpeg_decode_end(AVCodecContext *avctx)
 {
     MJpegDecodeContext *s = avctx->priv_data;
     int i, j;
@@ -1357,7 +1367,8 @@ AVCodec mjpeg_decoder = {
     ff_mjpeg_decode_end,
     ff_mjpeg_decode_frame,
     CODEC_CAP_DR1,
-    NULL
+    NULL,
+    .long_name = NULL_IF_CONFIG_SMALL("MJPEG (Motion JPEG)"),
 };
 
 AVCodec thp_decoder = {
@@ -1370,5 +1381,6 @@ AVCodec thp_decoder = {
     ff_mjpeg_decode_end,
     ff_mjpeg_decode_frame,
     CODEC_CAP_DR1,
-    NULL
+    NULL,
+    .long_name = NULL_IF_CONFIG_SMALL("Nintendo Gamecube THP video"),
 };