Revision 688cbabe

View differences:

libavcodec/mjpeg.c
836 836
    int h_max, v_max; /* maximum h and v counts */
837 837
    int quant_index[4];   /* quant table index for each component */
838 838
    int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */
839
    uint8_t *current_picture[MAX_COMPONENTS]; /* picture structure */
840
    int linesize[MAX_COMPONENTS];
839
    AVFrame picture; /* picture structure */
840
    int linesize[MAX_COMPONENTS];                   ///< linesize << interlaced
841 841
    uint8_t *qscale_table;
842 842
    DCTELEM block[64] __align8;
843 843
    ScanTable scantable;
......
1040 1040
    /* if different size, realloc/alloc picture */
1041 1041
    /* XXX: also check h_count and v_count */
1042 1042
    if (width != s->width || height != s->height) {
1043
        for(i=0;i<MAX_COMPONENTS;i++)
1044
            av_freep(&s->current_picture[i]);
1045
            
1046 1043
        av_freep(&s->qscale_table);
1047 1044
            
1048 1045
        s->width = width;
......
1056 1053
	    s->bottom_field = 0;
1057 1054
        }
1058 1055

  
1059
        if(s->rgb){
1060
            int w, h;
1061
            w = s->width;
1062
            h = s->height;
1063
            if (s->interlaced)
1064
                w *= 2;
1065
            s->linesize[0] = 4*w;
1066
            s->current_picture[0] = av_mallocz(4*w * h);
1067
            s->current_picture[1] = s->current_picture[2] = NULL;
1068
        }else{
1069
          for(i=0;i<nb_components;i++) {
1070
            int w, h;
1071
            w = (s->width  + 8 * s->h_max - 1) / (8 * s->h_max);
1072
            h = (s->height + 8 * s->v_max - 1) / (8 * s->v_max);
1073
            w = w * 8 * s->h_count[i];
1074
            h = h * 8 * s->v_count[i];
1075
            if (s->interlaced)
1076
                w *= 2;
1077
            s->linesize[i] = w;
1078
            s->current_picture[i] = av_mallocz(w * h);
1079
	    if (!s->current_picture[i])
1080
	    {
1081
		dprintf("error: no picture buffers allocated\n");
1082
		return -1;
1083
	    }
1084
          }
1085
        }
1086 1056
        s->qscale_table= av_mallocz((s->width+15)/16);
1087 1057

  
1088 1058
        s->first_picture = 0;
1089 1059
    }
1060
    
1061
    if(s->interlaced && s->bottom_field)
1062
        return 0;
1063
 
1064
    /* XXX: not complete test ! */
1065
    switch((s->h_count[0] << 4) | s->v_count[0]) {
1066
    case 0x11:
1067
        if(s->rgb){
1068
            s->avctx->pix_fmt = PIX_FMT_RGBA32;
1069
        }else
1070
            s->avctx->pix_fmt = PIX_FMT_YUV444P;
1071
        break;
1072
    case 0x21:
1073
        s->avctx->pix_fmt = PIX_FMT_YUV422P;
1074
        break;
1075
    default:
1076
    case 0x22:
1077
        s->avctx->pix_fmt = PIX_FMT_YUV420P;
1078
        break;
1079
    }
1080

  
1081
    if(s->picture.data[0])
1082
        s->avctx->release_buffer(s->avctx, &s->picture);
1083

  
1084
    s->picture.reference= 0;
1085
    if(s->avctx->get_buffer(s->avctx, &s->picture) < 0){
1086
        fprintf(stderr, "get_buffer() failed\n");
1087
        return -1;
1088
    }
1089
    s->picture.pict_type= I_TYPE;
1090
    s->picture.key_frame= 1;
1091
    
1092
    for(i=0; i<3; i++){
1093
        s->linesize[i]= s->picture.linesize[i] << s->interlaced;
1094
    }
1090 1095

  
1096
//    printf("%d %d %d %d %d %d\n", s->width, s->height, s->linesize[0], s->linesize[1], s->interlaced, s->avctx->height);
1097
    
1091 1098
    if (len != (8+(3*nb_components)))
1092 1099
    {
1093 1100
	dprintf("decode_sof0: error, len(%d) mismatch\n", len);
......
1175 1182
    }
1176 1183
    for(mb_y = 0; mb_y < s->mb_height; mb_y++) {
1177 1184
        const int modified_predictor= mb_y ? predictor : 1;
1178
        uint8_t *ptr = s->current_picture[0] + (linesize * mb_y);
1185
        uint8_t *ptr = s->picture.data[0] + (linesize * mb_y);
1179 1186

  
1180 1187
        if (s->interlaced && s->bottom_field)
1181 1188
            ptr += linesize >> 1;
......
1252 1259
                    for(j=0; j<n; j++) {
1253 1260
                        int pred;
1254 1261

  
1255
                        ptr = s->current_picture[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
1262
                        ptr = s->picture.data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
1256 1263
                        if(y==0 && mb_y==0){
1257 1264
                            if(x==0 && mb_x==0){
1258 1265
                                pred= 128 << point_transform;
......
1292 1299
                    for(j=0; j<n; j++) {
1293 1300
                        int pred;
1294 1301

  
1295
                        ptr = s->current_picture[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
1302
                        ptr = s->picture.data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
1296 1303
                        PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
1297 1304
                        *ptr= pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform);
1298 1305
                        if (++x == h) {
......
1338 1345
                        return -1;
1339 1346
                    }
1340 1347
//		    dprintf("mb: %d %d processed\n", mb_y, mb_x);
1341
                    ptr = s->current_picture[c] + 
1348
                    ptr = s->picture.data[c] + 
1342 1349
                        (s->linesize[c] * (v * mb_y + y) * 8) + 
1343 1350
                        (h * mb_x + x) * 8;
1344 1351
                    if (s->interlaced && s->bottom_field)
1345 1352
                        ptr += s->linesize[c] >> 1;
1353
//printf("%d %d %d %d %d %d %d %d \n", mb_x, mb_y, x, y, c, s->bottom_field, (v * mb_y + y) * 8, (h * mb_x + x) * 8);
1346 1354
                    s->idct_put(ptr, s->linesize[c], s->block);
1347 1355
                    if (++x == h) {
1348 1356
                        x = 0;
......
1844 1852
                            if (s->bottom_field)
1845 1853
                                goto not_the_end;
1846 1854
                        }
1847
                        for(i=0;i<3;i++) {
1848
                            picture->data[i] = s->current_picture[i];
1849
			    picture->linesize[i] = (s->interlaced) ?
1850
				s->linesize[i] >> 1 : s->linesize[i];
1851
                        }
1855
                        *picture = s->picture;
1852 1856
                        *data_size = sizeof(AVFrame);
1853 1857
                        avctx->height = s->height;
1854 1858
                        if (s->interlaced)
1855 1859
                            avctx->height *= 2;
1856 1860
                        avctx->width = s->width;
1857
                        /* XXX: not complete test ! */
1858
                        switch((s->h_count[0] << 4) | s->v_count[0]) {
1859
                        case 0x11:
1860
                            if(s->rgb){
1861
                                avctx->pix_fmt = PIX_FMT_RGBA32;
1862
                            }else
1863
                                avctx->pix_fmt = PIX_FMT_YUV444P;
1864
                            break;
1865
                        case 0x21:
1866
                            avctx->pix_fmt = PIX_FMT_YUV422P;
1867
                            break;
1868
                        default:
1869
                        case 0x22:
1870
                            avctx->pix_fmt = PIX_FMT_YUV420P;
1871
                            break;
1872
                        }
1873 1861

  
1874 1862
                        if(!s->lossless){
1875 1863
                            picture->quality= FFMAX(FFMAX(s->qscale[0], s->qscale[1]), s->qscale[2]); 
......
2022 2010
    }
2023 2011

  
2024 2012
    //XXX FIXME factorize, this looks very similar to the EOI code
2025
    
2026
    for(i=0;i<3;i++) {
2027
        picture->data[i] = s->current_picture[i];
2028
        picture->linesize[i] = (s->interlaced) ?
2029
    	    s->linesize[i] >> 1 : s->linesize[i];
2030
    }
2013

  
2014
    *picture= s->picture;
2031 2015
    *data_size = sizeof(AVFrame);
2032 2016
    avctx->height = s->height;
2033 2017
    if (s->interlaced)
2034 2018
        avctx->height *= 2;
2035 2019
    avctx->width = s->width;
2036
    /* XXX: not complete test ! */
2037
    switch((s->h_count[0] << 4) | s->v_count[0]) {
2038
        case 0x11:
2039
    	    avctx->pix_fmt = PIX_FMT_YUV444P;
2040
            break;
2041
        case 0x21:
2042
            avctx->pix_fmt = PIX_FMT_YUV422P;
2043
            break;
2044
        default:
2045
	case 0x22:
2046
            avctx->pix_fmt = PIX_FMT_YUV420P;
2047
            break;
2048
    }
2049 2020
    
2050 2021
    if(!s->lossless){
2051 2022
        picture->quality= FFMAX(FFMAX(s->qscale[0], s->qscale[1]), s->qscale[2]); 
......
2068 2039

  
2069 2040
    av_free(s->buffer);
2070 2041
    av_free(s->qscale_table);
2071
    for(i=0;i<MAX_COMPONENTS;i++)
2072
        av_free(s->current_picture[i]);
2042
    avcodec_default_free_buffers(avctx);
2043
    
2073 2044
    for(i=0;i<2;i++) {
2074 2045
        for(j=0;j<4;j++)
2075 2046
            free_vlc(&s->vlcs[i][j]);
......
2086 2057
    NULL,
2087 2058
    mjpeg_decode_end,
2088 2059
    mjpeg_decode_frame,
2089
    0,
2060
    CODEC_CAP_DR1,
2090 2061
    NULL
2091 2062
};
2092 2063

  
......
2099 2070
    NULL,
2100 2071
    mjpeg_decode_end,
2101 2072
    mjpegb_decode_frame,
2102
    0,
2073
    CODEC_CAP_DR1,
2103 2074
    NULL
2104 2075
};
2105 2076

  

Also available in: Unified diff