2 * Sunplus JPEG decoder (SP5X)
3 * Copyright (c) 2003 Alex Beregszaszi
5 * This file is part of FFmpeg.
7 * FFmpeg 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.
12 * FFmpeg 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.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 * Sunplus JPEG decoder (SP5X).
34 static int sp5x_decode_frame(AVCodecContext *avctx,
35 void *data, int *got_frame,
38 const uint8_t *buf = avpkt->data;
39 int buf_size = avpkt->size;
40 AVPacket avpkt_recoded;
45 if (!avctx->width || !avctx->height)
48 recoded = av_mallocz(buf_size + 1024);
56 memcpy(recoded+j, &sp5x_data_dqt[0], sizeof(sp5x_data_dqt));
57 memcpy(recoded+j+5, &sp5x_quant_table[qscale * 2], 64);
58 memcpy(recoded+j+70, &sp5x_quant_table[(qscale * 2) + 1], 64);
59 j += sizeof(sp5x_data_dqt);
61 memcpy(recoded+j, &sp5x_data_dht[0], sizeof(sp5x_data_dht));
62 j += sizeof(sp5x_data_dht);
64 memcpy(recoded+j, &sp5x_data_sof[0], sizeof(sp5x_data_sof));
65 AV_WB16(recoded+j+5, avctx->coded_height);
66 AV_WB16(recoded+j+7, avctx->coded_width);
67 j += sizeof(sp5x_data_sof);
69 memcpy(recoded+j, &sp5x_data_sos[0], sizeof(sp5x_data_sos));
70 j += sizeof(sp5x_data_sos);
72 if(avctx->codec_id==AV_CODEC_ID_AMV)
73 for (i = 2; i < buf_size-2 && j < buf_size+1024-2; i++)
74 recoded[j++] = buf[i];
76 for (i = 14; i < buf_size && j < buf_size+1024-3; i++)
78 recoded[j++] = buf[i];
87 av_init_packet(&avpkt_recoded);
88 avpkt_recoded.data = recoded;
89 avpkt_recoded.size = j;
90 i = ff_mjpeg_decode_frame(avctx, data, got_frame, &avpkt_recoded);
94 return i < 0 ? i : avpkt->size;
97 #if CONFIG_SP5X_DECODER
98 AVCodec ff_sp5x_decoder = {
100 .long_name = NULL_IF_CONFIG_SMALL("Sunplus JPEG (SP5X)"),
101 .type = AVMEDIA_TYPE_VIDEO,
102 .id = AV_CODEC_ID_SP5X,
103 .priv_data_size = sizeof(MJpegDecodeContext),
104 .init = ff_mjpeg_decode_init,
105 .close = ff_mjpeg_decode_end,
106 .decode = sp5x_decode_frame,
107 .capabilities = AV_CODEC_CAP_DR1,
109 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
112 #if CONFIG_AMV_DECODER
113 AVCodec ff_amv_decoder = {
115 .long_name = NULL_IF_CONFIG_SMALL("AMV Video"),
116 .type = AVMEDIA_TYPE_VIDEO,
117 .id = AV_CODEC_ID_AMV,
118 .priv_data_size = sizeof(MJpegDecodeContext),
119 .init = ff_mjpeg_decode_init,
120 .close = ff_mjpeg_decode_end,
121 .decode = sp5x_decode_frame,
123 .capabilities = AV_CODEC_CAP_DR1,
124 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,