Statistics
| Branch: | Revision:

ffmpeg / libavcodec / sp5xdec.c @ 70892657

History | View | Annotate | Download (3.24 KB)

1
/*
2
 * Sunplus JPEG decoder (SP5X)
3
 * Copyright (c) 2003 Alex Beregszaszi
4
 *
5
 * This file is part of Libav.
6
 *
7
 * Libav is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * Libav is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with Libav; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 */
21

    
22
/**
23
 * @file
24
 * Sunplus JPEG decoder (SP5X).
25
 */
26

    
27
#include "avcodec.h"
28
#include "mjpeg.h"
29
#include "mjpegdec.h"
30
#include "sp5x.h"
31

    
32

    
33
static int sp5x_decode_frame(AVCodecContext *avctx,
34
                              void *data, int *data_size,
35
                              AVPacket *avpkt)
36
{
37
    const uint8_t *buf = avpkt->data;
38
    int buf_size = avpkt->size;
39
    AVPacket avpkt_recoded;
40
    const int qscale = 5;
41
    const uint8_t *buf_ptr;
42
    uint8_t *recoded;
43
    int i = 0, j = 0;
44

    
45
    if (!avctx->width || !avctx->height)
46
        return -1;
47

    
48
    buf_ptr = buf;
49

    
50
    recoded = av_mallocz(buf_size + 1024);
51
    if (!recoded)
52
        return -1;
53

    
54
    /* SOI */
55
    recoded[j++] = 0xFF;
56
    recoded[j++] = 0xD8;
57

    
58
    memcpy(recoded+j, &sp5x_data_dqt[0], sizeof(sp5x_data_dqt));
59
    memcpy(recoded+j+5, &sp5x_quant_table[qscale * 2], 64);
60
    memcpy(recoded+j+70, &sp5x_quant_table[(qscale * 2) + 1], 64);
61
    j += sizeof(sp5x_data_dqt);
62

    
63
    memcpy(recoded+j, &sp5x_data_dht[0], sizeof(sp5x_data_dht));
64
    j += sizeof(sp5x_data_dht);
65

    
66
    memcpy(recoded+j, &sp5x_data_sof[0], sizeof(sp5x_data_sof));
67
    AV_WB16(recoded+j+5, avctx->coded_height);
68
    AV_WB16(recoded+j+7, avctx->coded_width);
69
    j += sizeof(sp5x_data_sof);
70

    
71
    memcpy(recoded+j, &sp5x_data_sos[0], sizeof(sp5x_data_sos));
72
    j += sizeof(sp5x_data_sos);
73

    
74
    if(avctx->codec_id==CODEC_ID_AMV)
75
        for (i = 2; i < buf_size-2 && j < buf_size+1024-2; i++)
76
            recoded[j++] = buf[i];
77
    else
78
    for (i = 14; i < buf_size && j < buf_size+1024-2; i++)
79
    {
80
        recoded[j++] = buf[i];
81
        if (buf[i] == 0xff)
82
            recoded[j++] = 0;
83
    }
84

    
85
    /* EOI */
86
    recoded[j++] = 0xFF;
87
    recoded[j++] = 0xD9;
88

    
89
    av_init_packet(&avpkt_recoded);
90
    avpkt_recoded.data = recoded;
91
    avpkt_recoded.size = j;
92
    i = ff_mjpeg_decode_frame(avctx, data, data_size, &avpkt_recoded);
93

    
94
    av_free(recoded);
95

    
96
    return i;
97
}
98

    
99
AVCodec ff_sp5x_decoder = {
100
    "sp5x",
101
    AVMEDIA_TYPE_VIDEO,
102
    CODEC_ID_SP5X,
103
    sizeof(MJpegDecodeContext),
104
    ff_mjpeg_decode_init,
105
    NULL,
106
    ff_mjpeg_decode_end,
107
    sp5x_decode_frame,
108
    CODEC_CAP_DR1,
109
    NULL,
110
    .max_lowres = 5,
111
    .long_name = NULL_IF_CONFIG_SMALL("Sunplus JPEG (SP5X)"),
112
};
113

    
114
AVCodec ff_amv_decoder = {
115
    "amv",
116
    AVMEDIA_TYPE_VIDEO,
117
    CODEC_ID_AMV,
118
    sizeof(MJpegDecodeContext),
119
    ff_mjpeg_decode_init,
120
    NULL,
121
    ff_mjpeg_decode_end,
122
    sp5x_decode_frame,
123
    0,
124
    .long_name = NULL_IF_CONFIG_SMALL("AMV Video"),
125
};