1 /*
2 * CPiA video decoder.
3 * Copyright (c) 2010 Hans de Goede <hdegoede@redhat.com>
4 *
5 * This decoder is based on the LGPL code available at
6 * https://v4l4j.googlecode.com/svn/v4l4j/trunk/libvideo/libv4lconvert/cpia1.c
7 *
8 * This file is part of FFmpeg.
9 *
10 * FFmpeg is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * FFmpeg is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with FFmpeg; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
28
29
30 #define FRAME_HEADER_SIZE 64
31 #define MAGIC_0 0x19 /**< First header byte */
32 #define MAGIC_1 0x68 /**< Second header byte */
33 #define SUBSAMPLE_420 0
34 #define SUBSAMPLE_422 1
35 #define YUVORDER_YUYV 0
36 #define YUVORDER_UYVY 1
37 #define NOT_COMPRESSED 0
39 #define NO_DECIMATION 0
40 #define DECIMATION_ENAB 1
41 #define EOL 0xfd /**< End Of Line marker */
42 #define EOI 0xff /**< End Of Image marker */
43
44
48
49
52 {
54 int i,j,ret;
55
58 int src_size;
59 uint16_t linelength;
61
63 uint8_t *y, *u, *v, *y_end, *u_end, *v_end;
64
65 // Check header
72 ) {
75 }
76
77 // currently unsupported properties
81 }
85 }
89 }
90
93
97 } else {
100 }
101
102 // Get buffer filled with previous frame
104 return ret;
105
106
107 for ( i = 0;
109 i++, src += linelength, src_size -= linelength
110 ) {
111 // Read line length, two byte little endian
113 src += 2;
114
115 if (src_size < linelength) {
118 break;
119 }
120 if (src[linelength - 1] !=
EOL) {
122 av_log(avctx,
AV_LOG_WARNING,
"Wrong line length %d or line not terminated properly (found 0x%02x)!\n", linelength, src[linelength - 1]);
123 break;
124 }
125
126 /* Update the data pointers. Y data is on every line.
127 * U and V data on every second line
128 */
135
137 /* We are on a odd line and 420 subsample is used.
138 * On this line only Y values are specified, one per pixel.
139 */
140 for (j = 0; j < linelength - 1; j++) {
141 if (y > y_end) {
144 break;
145 }
146 if ((src[j] & 1) && header[28] ==
COMPRESSED) {
147 /* It seems that odd lines are always uncompressed, but
148 * we do it according to specification anyways.
149 */
150 skip = src[j] >> 1;
151 y += skip;
152 } else {
153 *(y++) = src[j];
154 }
155 }
157 /* We are on an even line and 420 subsample is used.
158 * On this line each pair of pixels is described by four bytes.
159 */
160 for (j = 0; j < linelength - 4; ) {
161 if (y + 1 > y_end || u > u_end || v > v_end) {
164 break;
165 }
166 if ((src[j] & 1) && header[28] ==
COMPRESSED) {
167 // Skip amount of pixels and move forward one byte
168 skip = src[j] >> 1;
169 y += skip;
170 u += skip >> 1;
171 v += skip >> 1;
172 j++;
173 } else {
174 // Set image data as specified and move forward 4 bytes
175 *(y++) = src[j];
176 *(u++) = src[j+1];
177 *(y++) = src[j+2];
178 *(v++) = src[j+3];
179 j += 4;
180 }
181 }
182 }
183 }
184
185 *got_frame = 1;
187 return ret;
188
190 }
191
193 {
195
196 // output pixel format
198
199 /* The default timebase set by the v4l2 demuxer leads to probing which is buggy.
200 * Set some reasonable time_base to skip this.
201 */
205 }
206
210
211 return 0;
212 }
213
215 {
217
219
220 return 0;
221 }
222
233 };
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
#define AV_LOG_WARNING
Something somehow does not look correct.
static av_cold int init(AVCodecContext *avctx)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
#define EOL
End Of Line marker.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
#define MAGIC_0
First header byte.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define FRAME_HEADER_SIZE
static int cpia_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
bitstream reader API header.
static const uint8_t header[24]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
static av_cold int cpia_decode_init(AVCodecContext *avctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
const char * name
Name of the codec implementation.
static av_cold int cpia_decode_end(AVCodecContext *avctx)
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame)
Identical in function to av_frame_make_writable(), except it uses ff_get_buffer() to allocate the buf...
enum AVPictureType pict_type
Picture type of the frame.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
void av_frame_set_decode_error_flags(AVFrame *frame, int val)
#define FF_DECODE_ERROR_INVALID_BITSTREAM
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
#define MAGIC_1
Second header byte.
int key_frame
1 -> keyframe, 0-> not
This structure stores compressed data.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.