~ppsspp/ppsspp/ffmpeg

« back to all changes in this revision

Viewing changes to libavcodec/mjpegdec.c

  • Committer: Henrik Rydgård
  • Date: 2014-01-03 10:44:32 UTC
  • Revision ID: git-v1:87c6c126784b1718bfa448ecf2e6a9fef781eb4e
Update our ffmpeg snapshot to a clone of the official repository.

This is because Maxim's at3plus support has been officially merged!

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
{
88
88
    MJpegDecodeContext *s = avctx->priv_data;
89
89
 
90
 
    if (!s->picture_ptr)
91
 
        s->picture_ptr = &s->picture;
92
 
    avcodec_get_frame_defaults(&s->picture);
 
90
    if (!s->picture_ptr) {
 
91
        s->picture = av_frame_alloc();
 
92
        if (!s->picture)
 
93
            return AVERROR(ENOMEM);
 
94
        s->picture_ptr = s->picture;
 
95
    }
93
96
 
94
97
    s->avctx = avctx;
95
98
    ff_hpeldsp_init(&s->hdsp, avctx->flags);
215
218
 
216
219
int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
217
220
{
218
 
    int len, nb_components, i, width, height, pix_fmt_id;
 
221
    int len, nb_components, i, width, height, pix_fmt_id, ret;
219
222
    int h_count[MAX_COMPONENTS];
220
223
    int v_count[MAX_COMPONENTS];
221
224
 
326
329
            height *= 2;
327
330
        }
328
331
 
329
 
        avcodec_set_dimensions(s->avctx, width, height);
 
332
        ret = ff_set_dimensions(s->avctx, width, height);
 
333
        if (ret < 0)
 
334
            return ret;
330
335
 
331
336
        s->first_picture = 0;
332
337
    }
505
510
            int size = bw * bh * s->h_count[i] * s->v_count[i];
506
511
            av_freep(&s->blocks[i]);
507
512
            av_freep(&s->last_nnz[i]);
508
 
            s->blocks[i]       = av_malloc(size * sizeof(**s->blocks));
 
513
            s->blocks[i]       = av_mallocz(size * sizeof(**s->blocks));
509
514
            s->last_nnz[i]     = av_mallocz(size * sizeof(**s->last_nnz));
510
515
            if (!s->blocks[i] || !s->last_nnz[i])
511
516
                return AVERROR(ENOMEM);
823
828
        buffer[0][i] = 1 << (s->bits - 1);
824
829
 
825
830
    for (mb_y = 0; mb_y < s->mb_height; mb_y++) {
826
 
        uint8_t *ptr = s->picture.data[0] + (linesize * mb_y);
 
831
        uint8_t *ptr = s->picture_ptr->data[0] + (linesize * mb_y);
827
832
 
828
833
        if (s->interlaced && s->bottom_field)
829
834
            ptr += linesize >> 1;
957
962
                        if(dc == 0xFFFFF)
958
963
                            return -1;
959
964
                        if(bits<=8){
960
 
                        ptr = s->picture.data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
 
965
                        ptr = s->picture_ptr->data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
961
966
                        if(y==0 && toprow){
962
967
                            if(x==0 && leftcol){
963
968
                                pred= 1 << (bits - 1);
977
982
                        pred &= mask;
978
983
                        *ptr= pred + (dc << point_transform);
979
984
                        }else{
980
 
                            ptr16 = (uint16_t*)(s->picture.data[c] + 2*(linesize * (v * mb_y + y)) + 2*(h * mb_x + x)); //FIXME optimize this crap
 
985
                            ptr16 = (uint16_t*)(s->picture_ptr->data[c] + 2*(linesize * (v * mb_y + y)) + 2*(h * mb_x + x)); //FIXME optimize this crap
981
986
                            if(y==0 && toprow){
982
987
                                if(x==0 && leftcol){
983
988
                                    pred= 1 << (bits - 1);
1025
1030
                        if(dc == 0xFFFFF)
1026
1031
                            return -1;
1027
1032
                        if(bits<=8){
1028
 
                            ptr = s->picture.data[c] +
 
1033
                            ptr = s->picture_ptr->data[c] +
1029
1034
                              (linesize * (v * mb_y + y)) +
1030
1035
                              (h * mb_x + x); //FIXME optimize this crap
1031
1036
                            PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
1033
1038
                            pred &= mask;
1034
1039
                            *ptr = pred + (dc << point_transform);
1035
1040
                        }else{
1036
 
                            ptr16 = (uint16_t*)(s->picture.data[c] + 2*(linesize * (v * mb_y + y)) + 2*(h * mb_x + x)); //FIXME optimize this crap
 
1041
                            ptr16 = (uint16_t*)(s->picture_ptr->data[c] + 2*(linesize * (v * mb_y + y)) + 2*(h * mb_x + x)); //FIXME optimize this crap
1037
1042
                            PREDICT(pred, ptr16[-linesize-1], ptr16[-linesize], ptr16[-1], predictor);
1038
1043
 
1039
1044
                            pred &= mask;
1207
1212
    int mb_x, mb_y;
1208
1213
    int EOBRUN = 0;
1209
1214
    int c = s->comp_index[0];
1210
 
    uint8_t *data = s->picture.data[c];
 
1215
    uint8_t *data = s->picture_ptr->data[c];
1211
1216
    int linesize  = s->linesize[c];
1212
1217
    int last_scan = 0;
1213
1218
    int16_t *quant_matrix = s->quant_matrixes[s->quant_sindex[0]];
1368
1373
        s->last_dc[i] = (4 << s->bits);
1369
1374
 
1370
1375
    if (s->lossless) {
1371
 
        av_assert0(s->picture_ptr == &s->picture);
 
1376
        av_assert0(s->picture_ptr == s->picture);
1372
1377
        if (CONFIG_JPEGLS_DECODER && s->ls) {
1373
1378
//            for () {
1374
1379
//            reset_ls_coding_parameters(s, 0);
1389
1394
        }
1390
1395
    } else {
1391
1396
        if (s->progressive && predictor) {
1392
 
            av_assert0(s->picture_ptr == &s->picture);
 
1397
            av_assert0(s->picture_ptr == s->picture);
1393
1398
            if ((ret = mjpeg_decode_scan_progressive_ac(s, predictor,
1394
1399
                                                        ilv, prev_shift,
1395
1400
                                                        point_transform)) < 0)
1441
1446
    int len, id, i;
1442
1447
 
1443
1448
    len = get_bits(&s->gb, 16);
1444
 
    if (len < 5)
 
1449
    if (len < 6)
1445
1450
        return AVERROR_INVALIDDATA;
1446
1451
    if (8 * len > get_bits_left(&s->gb))
1447
1452
        return AVERROR_INVALIDDATA;
1555
1560
    }
1556
1561
 
1557
1562
    /* EXIF metadata */
1558
 
    if (s->start_code == APP1 && id == AV_RB32("Exif")) {
 
1563
    if (s->start_code == APP1 && id == AV_RB32("Exif") && len >= 2) {
1559
1564
        GetByteContext gbytes;
1560
1565
        int ret, le, ifd_offset, bytes_read;
1561
1566
        const uint8_t *aligned;
2035
2040
        av_log(avctx, AV_LOG_INFO, "Single field\n");
2036
2041
    }
2037
2042
 
2038
 
    if (s->picture_ptr)
 
2043
    if (s->picture) {
 
2044
        av_frame_free(&s->picture);
 
2045
        s->picture_ptr = NULL;
 
2046
    } else if (s->picture_ptr)
2039
2047
        av_frame_unref(s->picture_ptr);
2040
2048
 
2041
2049
    av_free(s->buffer);