annotate sp5xdec.c @ 12434:7915312dd862 libavcodec

Include stdint.h instead of inttypes.h, it is enough for what this file need.
author vitor
date Sun, 29 Aug 2010 15:46:38 +0000
parents ce660f4bda0d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1 /*
5042
259b58518ecc move sp5x decoder in its own file
aurel
parents: 5041
diff changeset
2 * Sunplus JPEG decoder (SP5X)
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
3 * Copyright (c) 2003 Alex Beregszaszi
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
4 *
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
5 * This file is part of FFmpeg.
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
6 *
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
11 *
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
15 * Lesser General Public License for more details.
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
16 *
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
20 */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
21
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
22 /**
11644
7dd2a45249a9 Remove explicit filename from Doxygen @file commands.
diego
parents: 11560
diff changeset
23 * @file
5042
259b58518ecc move sp5x decoder in its own file
aurel
parents: 5041
diff changeset
24 * Sunplus JPEG decoder (SP5X).
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
25 */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
26
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
27 #include "avcodec.h"
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
28 #include "mjpeg.h"
5041
01a165280429 allows to disable jpegls decoder
aurel
parents: 5039
diff changeset
29 #include "mjpegdec.h"
5042
259b58518ecc move sp5x decoder in its own file
aurel
parents: 5041
diff changeset
30 #include "sp5x.h"
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
31
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
32
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
33 static int sp5x_decode_frame(AVCodecContext *avctx,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
34 void *data, int *data_size,
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
35 AVPacket *avpkt)
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
36 {
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
37 const uint8_t *buf = avpkt->data;
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
38 int buf_size = avpkt->size;
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
39 AVPacket avpkt_recoded;
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
40 const int qscale = 5;
9593
b8140a218b1d Remove dead assignments found by CSA
banan
parents: 9355
diff changeset
41 const uint8_t *buf_ptr;
6221
michael
parents: 5818
diff changeset
42 uint8_t *recoded;
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
43 int i = 0, j = 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
44
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
45 if (!avctx->width || !avctx->height)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
46 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
47
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
48 buf_ptr = buf;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
49
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
50 recoded = av_mallocz(buf_size + 1024);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
51 if (!recoded)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
52 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
53
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
54 /* SOI */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
55 recoded[j++] = 0xFF;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
56 recoded[j++] = 0xD8;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
57
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
58 memcpy(recoded+j, &sp5x_data_dqt[0], sizeof(sp5x_data_dqt));
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
59 memcpy(recoded+j+5, &sp5x_quant_table[qscale * 2], 64);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
60 memcpy(recoded+j+70, &sp5x_quant_table[(qscale * 2) + 1], 64);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
61 j += sizeof(sp5x_data_dqt);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
62
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
63 memcpy(recoded+j, &sp5x_data_dht[0], sizeof(sp5x_data_dht));
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
64 j += sizeof(sp5x_data_dht);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
65
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
66 memcpy(recoded+j, &sp5x_data_sof[0], sizeof(sp5x_data_sof));
5089
bff60ecc02f9 Use AV_xx throughout libavcodec
ramiro
parents: 5042
diff changeset
67 AV_WB16(recoded+j+5, avctx->coded_height);
bff60ecc02f9 Use AV_xx throughout libavcodec
ramiro
parents: 5042
diff changeset
68 AV_WB16(recoded+j+7, avctx->coded_width);
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
69 j += sizeof(sp5x_data_sof);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
70
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
71 memcpy(recoded+j, &sp5x_data_sos[0], sizeof(sp5x_data_sos));
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
72 j += sizeof(sp5x_data_sos);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
73
5736
810067f2c33d AMV video decoder.
vitor
parents: 5089
diff changeset
74 if(avctx->codec_id==CODEC_ID_AMV)
810067f2c33d AMV video decoder.
vitor
parents: 5089
diff changeset
75 for (i = 2; i < buf_size-2 && j < buf_size+1024-2; i++)
810067f2c33d AMV video decoder.
vitor
parents: 5089
diff changeset
76 recoded[j++] = buf[i];
810067f2c33d AMV video decoder.
vitor
parents: 5089
diff changeset
77 else
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
78 for (i = 14; i < buf_size && j < buf_size+1024-2; i++)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
79 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
80 recoded[j++] = buf[i];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
81 if (buf[i] == 0xff)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
82 recoded[j++] = 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
83 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
84
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
85 /* EOI */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
86 recoded[j++] = 0xFF;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
87 recoded[j++] = 0xD9;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
88
5818
e0a872dd3ea1 Fix MJPEG decoder for AMV files.
voroshil
parents: 5736
diff changeset
89 avctx->flags &= ~CODEC_FLAG_EMU_EDGE;
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
90 av_init_packet(&avpkt_recoded);
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
91 avpkt_recoded.data = recoded;
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
92 avpkt_recoded.size = j;
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
93 i = ff_mjpeg_decode_frame(avctx, data, data_size, &avpkt_recoded);
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
94
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
95 av_free(recoded);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
96
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
97 return i;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
98 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
99
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
100 AVCodec sp5x_decoder = {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
101 "sp5x",
11560
8a4984c5cacc Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 9797
diff changeset
102 AVMEDIA_TYPE_VIDEO,
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
103 CODEC_ID_SP5X,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
104 sizeof(MJpegDecodeContext),
5041
01a165280429 allows to disable jpegls decoder
aurel
parents: 5039
diff changeset
105 ff_mjpeg_decode_init,
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
106 NULL,
5041
01a165280429 allows to disable jpegls decoder
aurel
parents: 5039
diff changeset
107 ff_mjpeg_decode_end,
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
108 sp5x_decode_frame,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
109 CODEC_CAP_DR1,
6710
a4104482ceef Add long names to many AVCodec declarations.
diego
parents: 6481
diff changeset
110 NULL,
12108
c35d7bc64882 Add new decoder property max_lowres and do not init decoder if requested value is higher.
cehoyos
parents: 11644
diff changeset
111 .max_lowres = 5,
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6710
diff changeset
112 .long_name = NULL_IF_CONFIG_SMALL("Sunplus JPEG (SP5X)"),
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
113 };
5736
810067f2c33d AMV video decoder.
vitor
parents: 5089
diff changeset
114
810067f2c33d AMV video decoder.
vitor
parents: 5089
diff changeset
115 AVCodec amv_decoder = {
810067f2c33d AMV video decoder.
vitor
parents: 5089
diff changeset
116 "amv",
11560
8a4984c5cacc Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 9797
diff changeset
117 AVMEDIA_TYPE_VIDEO,
5736
810067f2c33d AMV video decoder.
vitor
parents: 5089
diff changeset
118 CODEC_ID_AMV,
810067f2c33d AMV video decoder.
vitor
parents: 5089
diff changeset
119 sizeof(MJpegDecodeContext),
810067f2c33d AMV video decoder.
vitor
parents: 5089
diff changeset
120 ff_mjpeg_decode_init,
810067f2c33d AMV video decoder.
vitor
parents: 5089
diff changeset
121 NULL,
810067f2c33d AMV video decoder.
vitor
parents: 5089
diff changeset
122 ff_mjpeg_decode_end,
6710
a4104482ceef Add long names to many AVCodec declarations.
diego
parents: 6481
diff changeset
123 sp5x_decode_frame,
9797
8d60502aead2 amv decoder uses get_buffer, set CODEC_CAP_DR1
bcoudurier
parents: 9593
diff changeset
124 CODEC_CAP_DR1,
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6710
diff changeset
125 .long_name = NULL_IF_CONFIG_SMALL("AMV Video"),
5736
810067f2c33d AMV video decoder.
vitor
parents: 5089
diff changeset
126 };