Mercurial > libavcodec.hg
comparison fraps.c @ 2967:ef2149182f1c libavcodec
COSMETICS: Remove all trailing whitespace.
author | diego |
---|---|
date | Sat, 17 Dec 2005 18:14:38 +0000 |
parents | 6a22fbe16d6d |
children | 0b546eab515d |
comparison
equal
deleted
inserted
replaced
2966:564788471dd4 | 2967:ef2149182f1c |
---|---|
15 * You should have received a copy of the GNU Lesser General Public | 15 * You should have received a copy of the GNU Lesser General Public |
16 * License along with this library; if not, write to the Free Software | 16 * License along with this library; if not, write to the Free Software |
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 * | 18 * |
19 */ | 19 */ |
20 | 20 |
21 /** | 21 /** |
22 * @file fraps.c | 22 * @file fraps.c |
23 * Lossless Fraps 'FPS1' decoder | 23 * Lossless Fraps 'FPS1' decoder |
24 * @author Roine Gustafsson <roine at users sf net> | 24 * @author Roine Gustafsson <roine at users sf net> |
25 * | 25 * |
26 * Only decodes version 0 and 1 files. | 26 * Only decodes version 0 and 1 files. |
27 * Codec algorithm for version 0 is taken from Transcode <www.transcoding.org> | 27 * Codec algorithm for version 0 is taken from Transcode <www.transcoding.org> |
28 * | 28 * |
29 * Version 2 files, which are the most commonly found Fraps files, cannot be | 29 * Version 2 files, which are the most commonly found Fraps files, cannot be |
30 * decoded yet. | 30 * decoded yet. |
31 */ | 31 */ |
32 | 32 |
33 #include "avcodec.h" | 33 #include "avcodec.h" |
34 | 34 |
35 #define FPS_TAG MKTAG('F', 'P', 'S', 'x') | 35 #define FPS_TAG MKTAG('F', 'P', 'S', 'x') |
36 | 36 |
37 /** | 37 /** |
55 avctx->coded_frame = (AVFrame*)&s->frame; | 55 avctx->coded_frame = (AVFrame*)&s->frame; |
56 avctx->has_b_frames = 0; | 56 avctx->has_b_frames = 0; |
57 avctx->pix_fmt= PIX_FMT_NONE; /* set in decode_frame */ | 57 avctx->pix_fmt= PIX_FMT_NONE; /* set in decode_frame */ |
58 | 58 |
59 s->avctx = avctx; | 59 s->avctx = avctx; |
60 s->frame.data[0] = NULL; | 60 s->frame.data[0] = NULL; |
61 | 61 |
62 return 0; | 62 return 0; |
63 } | 63 } |
64 | 64 |
65 | 65 |
70 * @param data_size size of output data or 0 if no picture is returned | 70 * @param data_size size of output data or 0 if no picture is returned |
71 * @param buf input data frame | 71 * @param buf input data frame |
72 * @param buf_size size of input data frame | 72 * @param buf_size size of input data frame |
73 * @return number of consumed bytes on success or negative if decode fails | 73 * @return number of consumed bytes on success or negative if decode fails |
74 */ | 74 */ |
75 static int decode_frame(AVCodecContext *avctx, | 75 static int decode_frame(AVCodecContext *avctx, |
76 void *data, int *data_size, | 76 void *data, int *data_size, |
77 uint8_t *buf, int buf_size) | 77 uint8_t *buf, int buf_size) |
78 { | 78 { |
79 FrapsContext * const s = avctx->priv_data; | 79 FrapsContext * const s = avctx->priv_data; |
80 AVFrame *frame = data; | 80 AVFrame *frame = data; |
89 header = LE_32(buf); | 89 header = LE_32(buf); |
90 version = header & 0xff; | 90 version = header & 0xff; |
91 header_size = (header & (1<<30))? 8 : 4; /* bit 30 means pad to 8 bytes */ | 91 header_size = (header & (1<<30))? 8 : 4; /* bit 30 means pad to 8 bytes */ |
92 | 92 |
93 if (version > 1) { | 93 if (version > 1) { |
94 av_log(avctx, AV_LOG_ERROR, | 94 av_log(avctx, AV_LOG_ERROR, |
95 "This file is encoded with Fraps version %d. " \ | 95 "This file is encoded with Fraps version %d. " \ |
96 "This codec can only decode version 0 and 1.\n", version); | 96 "This codec can only decode version 0 and 1.\n", version); |
97 return -1; | 97 return -1; |
98 } | 98 } |
99 | 99 |
100 buf+=4; | 100 buf+=4; |
101 if (header_size == 8) | 101 if (header_size == 8) |
102 buf+=4; | 102 buf+=4; |
103 | 103 |
104 switch(version) { | 104 switch(version) { |
105 case 0: | 105 case 0: |
106 default: | 106 default: |
107 /* Fraps v0 is a reordered YUV420 */ | 107 /* Fraps v0 is a reordered YUV420 */ |
108 avctx->pix_fmt = PIX_FMT_YUV420P; | 108 avctx->pix_fmt = PIX_FMT_YUV420P; |
109 | 109 |
110 if ( (buf_size != avctx->width*avctx->height*3/2+header_size) && | 110 if ( (buf_size != avctx->width*avctx->height*3/2+header_size) && |
111 (buf_size != header_size) ) { | 111 (buf_size != header_size) ) { |
112 av_log(avctx, AV_LOG_ERROR, | 112 av_log(avctx, AV_LOG_ERROR, |
113 "Invalid frame length %d (should be %d)\n", | 113 "Invalid frame length %d (should be %d)\n", |
114 buf_size, avctx->width*avctx->height*3/2+header_size); | 114 buf_size, avctx->width*avctx->height*3/2+header_size); |
115 return -1; | 115 return -1; |
116 } | 116 } |
117 | 117 |
118 if (( (avctx->width % 8) != 0) || ( (avctx->height % 2) != 0 )) { | 118 if (( (avctx->width % 8) != 0) || ( (avctx->height % 2) != 0 )) { |
119 av_log(avctx, AV_LOG_ERROR, "Invalid frame size %dx%d\n", | 119 av_log(avctx, AV_LOG_ERROR, "Invalid frame size %dx%d\n", |
120 avctx->width, avctx->height); | 120 avctx->width, avctx->height); |
121 return -1; | 121 return -1; |
122 } | 122 } |
123 | 123 |
124 f->reference = 1; | 124 f->reference = 1; |
125 f->buffer_hints = FF_BUFFER_HINTS_VALID | | 125 f->buffer_hints = FF_BUFFER_HINTS_VALID | |
126 FF_BUFFER_HINTS_PRESERVE | | 126 FF_BUFFER_HINTS_PRESERVE | |
127 FF_BUFFER_HINTS_REUSABLE; | 127 FF_BUFFER_HINTS_REUSABLE; |
128 if (avctx->reget_buffer(avctx, f)) { | 128 if (avctx->reget_buffer(avctx, f)) { |
129 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); | 129 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); |
130 return -1; | 130 return -1; |
131 } | 131 } |
132 /* bit 31 means same as previous pic */ | 132 /* bit 31 means same as previous pic */ |
133 f->pict_type = (header & (1<<31))? FF_P_TYPE : FF_I_TYPE; | 133 f->pict_type = (header & (1<<31))? FF_P_TYPE : FF_I_TYPE; |
134 f->key_frame = f->pict_type == FF_I_TYPE; | 134 f->key_frame = f->pict_type == FF_I_TYPE; |
135 | 135 |
136 if (f->pict_type == FF_I_TYPE) { | 136 if (f->pict_type == FF_I_TYPE) { |
137 buf32=(uint32_t*)buf; | 137 buf32=(uint32_t*)buf; |
138 for(y=0; y<avctx->height/2; y++){ | 138 for(y=0; y<avctx->height/2; y++){ |
139 luma1=(uint32_t*)&f->data[0][ y*2*f->linesize[0] ]; | 139 luma1=(uint32_t*)&f->data[0][ y*2*f->linesize[0] ]; |
140 luma2=(uint32_t*)&f->data[0][ (y*2+1)*f->linesize[0] ]; | 140 luma2=(uint32_t*)&f->data[0][ (y*2+1)*f->linesize[0] ]; |
141 cr=(uint32_t*)&f->data[1][ y*f->linesize[1] ]; | 141 cr=(uint32_t*)&f->data[1][ y*f->linesize[1] ]; |
154 | 154 |
155 case 1: | 155 case 1: |
156 /* Fraps v1 is an upside-down BGR24 */ | 156 /* Fraps v1 is an upside-down BGR24 */ |
157 avctx->pix_fmt = PIX_FMT_BGR24; | 157 avctx->pix_fmt = PIX_FMT_BGR24; |
158 | 158 |
159 if ( (buf_size != avctx->width*avctx->height*3+header_size) && | 159 if ( (buf_size != avctx->width*avctx->height*3+header_size) && |
160 (buf_size != header_size) ) { | 160 (buf_size != header_size) ) { |
161 av_log(avctx, AV_LOG_ERROR, | 161 av_log(avctx, AV_LOG_ERROR, |
162 "Invalid frame length %d (should be %d)\n", | 162 "Invalid frame length %d (should be %d)\n", |
163 buf_size, avctx->width*avctx->height*3+header_size); | 163 buf_size, avctx->width*avctx->height*3+header_size); |
164 return -1; | 164 return -1; |
165 } | 165 } |
166 | 166 |