85 n = (chunk_id & 0x04) ? 4 : 6;
90 for (
i=0;
i < 256;
i++) {
91 if ((chunk_id & 0x01) && !(
mask >>= 1)) {
100 if (!(chunk_id & 0x01) || (
flag &
mask)) {
103 if ((
data + n) > eod)
106 for (k = 0; k < 4; ++k) {
108 for (kk = 0; kk < 3; ++kk)
113 u = *(int8_t *)
data++;
114 v = *(int8_t *)
data++;
118 g = *p++ - (
u/2) - v;
137 uint8_t *cb0, *cb1, *cb2, *cb3;
139 char *ip0, *ip1, *ip2, *ip3;
144 for (y=strip->
y1; y < strip->y2; y+=4) {
147 ip0 = ip1 = ip2 = ip3 =
s->frame->data[0] +
148 (
s->palette_video?strip->
x1:strip->
x1*3) + (y *
s->frame->linesize[0]);
149 if(
s->avctx->height - y > 1) {
150 ip1 = ip0 +
s->frame->linesize[0];
151 if(
s->avctx->height - y > 2) {
152 ip2 = ip1 +
s->frame->linesize[0];
153 if(
s->avctx->height - y > 3) {
154 ip3 = ip2 +
s->frame->linesize[0];
163 for (x=strip->
x1; x < strip->x2; x+=4) {
164 if ((chunk_id & 0x01) && !(
mask >>= 1)) {
165 if ((
data + 4) > eod)
173 if (!(chunk_id & 0x01) || (
flag &
mask)) {
174 if (!(chunk_id & 0x02) && !(
mask >>= 1)) {
175 if ((
data + 4) > eod)
183 if ((chunk_id & 0x02) || (~
flag &
mask)) {
189 if (
s->palette_video) {
190 ip3[0] = ip3[1] = ip2[0] = ip2[1] = p[6];
191 ip3[2] = ip3[3] = ip2[2] = ip2[3] = p[9];
192 ip1[0] = ip1[1] = ip0[0] = ip0[1] = p[0];
193 ip1[2] = ip1[3] = ip0[2] = ip0[3] = p[3];
196 memcpy(ip3 + 0, p, 3); memcpy(ip3 + 3, p, 3);
197 memcpy(ip2 + 0, p, 3); memcpy(ip2 + 3, p, 3);
199 memcpy(ip3 + 6, p, 3); memcpy(ip3 + 9, p, 3);
200 memcpy(ip2 + 6, p, 3); memcpy(ip2 + 9, p, 3);
202 memcpy(ip1 + 0, p, 3); memcpy(ip1 + 3, p, 3);
203 memcpy(ip0 + 0, p, 3); memcpy(ip0 + 3, p, 3);
205 memcpy(ip1 + 6, p, 3); memcpy(ip1 + 9, p, 3);
206 memcpy(ip0 + 6, p, 3); memcpy(ip0 + 9, p, 3);
210 if ((
data + 4) > eod)
217 if (
s->palette_video) {
240 memcpy(ip3 + 0, cb2 + 6, 6);
241 memcpy(ip3 + 6, cb3 + 6, 6);
242 memcpy(ip2 + 0, cb2 + 0, 6);
243 memcpy(ip2 + 6, cb3 + 0, 6);
244 memcpy(ip1 + 0, cb0 + 6, 6);
245 memcpy(ip1 + 6, cb1 + 6, 6);
246 memcpy(ip0 + 0, cb0 + 0, 6);
247 memcpy(ip0 + 6, cb1 + 0, 6);
253 if (
s->palette_video) {
257 ip0 += 12; ip1 += 12;
258 ip2 += 12; ip3 += 12;
270 int chunk_id, chunk_size;
273 if (strip->
x2 >
s->width ||
274 strip->
y2 >
s->height ||
275 strip->
x1 >= strip->
x2 || strip->
y1 >= strip->
y2)
278 while ((
data + 4) <= eod) {
285 chunk_size = ((
data + chunk_size) > eod) ? (eod -
data) : chunk_size;
321 int encoded_buf_size;
324 encoded_buf_size =
AV_RB24(&
s->data[1]);
326 if (
s->size < encoded_buf_size * (int64_t)(100 -
s->avctx->discard_damaged_percentage) / 100)
330 if (
s->sega_film_skip_bytes == -1) {
331 if (!encoded_buf_size) {
335 if (encoded_buf_size !=
s->size && (
s->size % encoded_buf_size) != 0) {
343 (
s->data[10] == 0xFE) &&
344 (
s->data[11] == 0x00) &&
345 (
s->data[12] == 0x00) &&
346 (
s->data[13] == 0x06) &&
347 (
s->data[14] == 0x00) &&
348 (
s->data[15] == 0x00))
349 s->sega_film_skip_bytes = 6;
351 s->sega_film_skip_bytes = 2;
353 s->sega_film_skip_bytes = 0;
356 if (
s->size < 10 +
s->sega_film_skip_bytes + num_strips * 12)
360 const uint8_t *
data =
s->data + 10 +
s->sega_film_skip_bytes;
362 if (strip_size < 12 || strip_size > encoded_buf_size)
371 const uint8_t *eod = (
s->data +
s->size);
372 int i, result, strip_size, frame_flags, num_strips;
375 frame_flags =
s->data[0];
378 s->data += 10 +
s->sega_film_skip_bytes;
382 s->frame->key_frame = 0;
384 for (
i=0;
i < num_strips;
i++) {
385 if ((
s->data + 12) > eod)
388 s->strips[
i].id =
s->data[0];
390 if (!(
s->strips[
i].y1 =
AV_RB16 (&
s->data[4])))
391 s->strips[
i].y2 = (
s->strips[
i].y1 = y0) +
AV_RB16 (&
s->data[8]);
397 if (
s->strips[
i].id == 0x10)
398 s->frame->key_frame = 1;
400 strip_size =
AV_RB24 (&
s->data[1]) - 12;
404 strip_size = ((
s->data + strip_size) > eod) ? (eod -
s->data) : strip_size;
406 if ((
i > 0) && !(frame_flags & 0x01)) {
407 memcpy (
s->strips[
i].v4_codebook,
s->strips[
i-1].v4_codebook,
408 sizeof(
s->strips[
i].v4_codebook));
409 memcpy (
s->strips[
i].v1_codebook,
s->strips[
i-1].v1_codebook,
410 sizeof(
s->strips[
i].v1_codebook));
418 s->data += strip_size;
419 y0 =
s->strips[
i].y2;
429 s->width = (avctx->
width + 3) & ~3;
430 s->height = (avctx->
height + 3) & ~3;
432 s->sega_film_skip_bytes = -1;
436 s->palette_video = 0;
439 s->palette_video = 1;
451 void *
data,
int *got_frame,
455 int ret = 0, buf_size = avpkt->
size;
479 if (
s->palette_video) {
483 s->frame->palette_has_changed = 1;
494 if (
s->palette_video)
Libavcodec external API header.
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, buffer_size_t *size)
static av_cold int init(AVCodecContext *avctx)
#define u(width, name, range_min, range_max)
static const unsigned codebook[256][2]
static void cinepak_decode_codebook(cvid_codebook *codebook, int chunk_id, int size, const uint8_t *data)
static av_cold int cinepak_decode_init(AVCodecContext *avctx)
static av_cold int cinepak_decode_end(AVCodecContext *avctx)
uint8_t cvid_codebook[12]
static int cinepak_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static int cinepak_decode_strip(CinepakContext *s, cvid_strip *strip, const uint8_t *data, int size)
static int cinepak_decode_vectors(CinepakContext *s, cvid_strip *strip, int chunk_id, int size, const uint8_t *data)
static int cinepak_decode(CinepakContext *s)
static int cinepak_predecode_check(CinepakContext *s)
AVCodec ff_cinepak_decoder
common internal and external API header
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Identical in function to ff_get_buffer(), except it reuses the existing buffer if available.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
@ AV_PKT_DATA_PALETTE
An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE bytes worth of palette.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static const uint16_t mask[17]
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
const unsigned char * data
cvid_strip strips[MAX_STRIPS]
cvid_codebook v1_codebook[256]
cvid_codebook v4_codebook[256]
#define avpriv_request_sample(...)