annotate cinepak.c @ 9746:e8421cfcc381 libavcodec

lclenc.c: compress directly into output buffer instead of using a pointless temporary buffer and then using put_bits to copy the data over.
author reimar
date Sun, 31 May 2009 08:49:27 +0000
parents 54bc8a2727b0
children 5da84f0d0a55
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
1 /*
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
2 * Cinepak Video Decoder
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
3 * Copyright (C) 2003 the ffmpeg project
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
4 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
5 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
6 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
11 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
15 * Lesser General Public License for more details.
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
16 *
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2967
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
20 */
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
21
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
22 /**
8718
e9d9d946f213 Use full internal pathname in doxygen @file directives.
diego
parents: 8581
diff changeset
23 * @file libavcodec/cinepak.c
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
24 * Cinepak video decoder
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
25 * by Ewald Snel <ewald@rambo.its.tudelft.nl>
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
26 * For more information on the Cinepak algorithm, visit:
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
27 * http://www.csse.monash.edu.au/~timf/
4262
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
28 * For more information on the quirky data inside Sega FILM/CPK files, visit:
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
29 * http://wiki.multimedia.cx/index.php?title=Sega_FILM
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
30 */
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
31
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
32 #include <stdio.h>
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
33 #include <stdlib.h>
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
34 #include <string.h>
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
35 #include <unistd.h>
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
36
8573
2acf0ae7b041 Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents: 8318
diff changeset
37 #include "libavutil/intreadwrite.h"
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
38 #include "avcodec.h"
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
39
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
40
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
41 typedef struct {
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
42 uint8_t y0, y1, y2, y3;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
43 uint8_t u, v;
8318
bc36a075bf35 The POSIX namespace shall be held sacrosanct. To that end,
melanson
parents: 7823
diff changeset
44 } cvid_codebook;
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
45
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
46 #define MAX_STRIPS 32
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
47
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
48 typedef struct {
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
49 uint16_t id;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
50 uint16_t x1, y1;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
51 uint16_t x2, y2;
8318
bc36a075bf35 The POSIX namespace shall be held sacrosanct. To that end,
melanson
parents: 7823
diff changeset
52 cvid_codebook v4_codebook[256];
bc36a075bf35 The POSIX namespace shall be held sacrosanct. To that end,
melanson
parents: 7823
diff changeset
53 cvid_codebook v1_codebook[256];
bc36a075bf35 The POSIX namespace shall be held sacrosanct. To that end,
melanson
parents: 7823
diff changeset
54 } cvid_strip;
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
55
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
56 typedef struct CinepakContext {
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
57
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
58 AVCodecContext *avctx;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
59 AVFrame frame;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
60
6230
michael
parents: 5215
diff changeset
61 const unsigned char *data;
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
62 int size;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
63
1572
860e44e2c20c support Cinepak files with funky (not divisible by 4) resolutions
melanson
parents: 1491
diff changeset
64 int width, height;
860e44e2c20c support Cinepak files with funky (not divisible by 4) resolutions
melanson
parents: 1491
diff changeset
65
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
66 int palette_video;
8318
bc36a075bf35 The POSIX namespace shall be held sacrosanct. To that end,
melanson
parents: 7823
diff changeset
67 cvid_strip strips[MAX_STRIPS];
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
68
4262
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
69 int sega_film_skip_bytes;
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
70
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
71 } CinepakContext;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
72
8318
bc36a075bf35 The POSIX namespace shall be held sacrosanct. To that end,
melanson
parents: 7823
diff changeset
73 static void cinepak_decode_codebook (cvid_codebook *codebook,
6230
michael
parents: 5215
diff changeset
74 int chunk_id, int size, const uint8_t *data)
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
75 {
6230
michael
parents: 5215
diff changeset
76 const uint8_t *eod = (data + size);
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
77 uint32_t flag, mask;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
78 int i, n;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
79
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
80 /* check if this chunk contains 4- or 6-element vectors */
8580
144ddb6a597c Cinepak strip and chunk sizes are 24-bit, not 16-bit as it was thought earlier.
kostya
parents: 8573
diff changeset
81 n = (chunk_id & 0x04) ? 4 : 6;
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
82 flag = 0;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
83 mask = 0;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
84
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
85 for (i=0; i < 256; i++) {
8580
144ddb6a597c Cinepak strip and chunk sizes are 24-bit, not 16-bit as it was thought earlier.
kostya
parents: 8573
diff changeset
86 if ((chunk_id & 0x01) && !(mask >>= 1)) {
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
87 if ((data + 4) > eod)
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
88 break;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
89
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4262
diff changeset
90 flag = AV_RB32 (data);
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
91 data += 4;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
92 mask = 0x80000000;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
93 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
94
8580
144ddb6a597c Cinepak strip and chunk sizes are 24-bit, not 16-bit as it was thought earlier.
kostya
parents: 8573
diff changeset
95 if (!(chunk_id & 0x01) || (flag & mask)) {
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
96 if ((data + n) > eod)
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
97 break;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
98
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
99 if (n == 6) {
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
100 codebook[i].y0 = *data++;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
101 codebook[i].y1 = *data++;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
102 codebook[i].y2 = *data++;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
103 codebook[i].y3 = *data++;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
104 codebook[i].u = 128 + *data++;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
105 codebook[i].v = 128 + *data++;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
106 } else {
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2963
diff changeset
107 /* this codebook type indicates either greyscale or
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
108 * palettized video; if palettized, U & V components will
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
109 * not be used so it is safe to set them to 128 for the
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
110 * benefit of greyscale rendering in YUV420P */
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
111 codebook[i].y0 = *data++;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
112 codebook[i].y1 = *data++;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
113 codebook[i].y2 = *data++;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
114 codebook[i].y3 = *data++;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
115 codebook[i].u = 128;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
116 codebook[i].v = 128;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
117 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
118 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
119 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
120 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
121
8318
bc36a075bf35 The POSIX namespace shall be held sacrosanct. To that end,
melanson
parents: 7823
diff changeset
122 static int cinepak_decode_vectors (CinepakContext *s, cvid_strip *strip,
6230
michael
parents: 5215
diff changeset
123 int chunk_id, int size, const uint8_t *data)
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
124 {
6230
michael
parents: 5215
diff changeset
125 const uint8_t *eod = (data + size);
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
126 uint32_t flag, mask;
8318
bc36a075bf35 The POSIX namespace shall be held sacrosanct. To that end,
melanson
parents: 7823
diff changeset
127 cvid_codebook *codebook;
2009
b13a25ac9f0c buffer hints, use reget_buffer, removed copy from previous frame
rtognimp
parents: 1881
diff changeset
128 unsigned int x, y;
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
129 uint32_t iy[4];
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
130 uint32_t iu[2];
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
131 uint32_t iv[2];
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
132
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
133 flag = 0;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
134 mask = 0;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
135
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
136 for (y=strip->y1; y < strip->y2; y+=4) {
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
137
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
138 iy[0] = strip->x1 + (y * s->frame.linesize[0]);
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
139 iy[1] = iy[0] + s->frame.linesize[0];
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
140 iy[2] = iy[1] + s->frame.linesize[0];
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
141 iy[3] = iy[2] + s->frame.linesize[0];
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
142 iu[0] = (strip->x1/2) + ((y/2) * s->frame.linesize[1]);
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
143 iu[1] = iu[0] + s->frame.linesize[1];
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
144 iv[0] = (strip->x1/2) + ((y/2) * s->frame.linesize[2]);
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
145 iv[1] = iv[0] + s->frame.linesize[2];
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
146
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
147 for (x=strip->x1; x < strip->x2; x+=4) {
8580
144ddb6a597c Cinepak strip and chunk sizes are 24-bit, not 16-bit as it was thought earlier.
kostya
parents: 8573
diff changeset
148 if ((chunk_id & 0x01) && !(mask >>= 1)) {
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
149 if ((data + 4) > eod)
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
150 return -1;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
151
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4262
diff changeset
152 flag = AV_RB32 (data);
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
153 data += 4;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
154 mask = 0x80000000;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
155 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
156
8580
144ddb6a597c Cinepak strip and chunk sizes are 24-bit, not 16-bit as it was thought earlier.
kostya
parents: 8573
diff changeset
157 if (!(chunk_id & 0x01) || (flag & mask)) {
144ddb6a597c Cinepak strip and chunk sizes are 24-bit, not 16-bit as it was thought earlier.
kostya
parents: 8573
diff changeset
158 if (!(chunk_id & 0x02) && !(mask >>= 1)) {
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
159 if ((data + 4) > eod)
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
160 return -1;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
161
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4262
diff changeset
162 flag = AV_RB32 (data);
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
163 data += 4;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
164 mask = 0x80000000;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
165 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
166
8580
144ddb6a597c Cinepak strip and chunk sizes are 24-bit, not 16-bit as it was thought earlier.
kostya
parents: 8573
diff changeset
167 if ((chunk_id & 0x02) || (~flag & mask)) {
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
168 if (data >= eod)
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
169 return -1;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
170
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
171 codebook = &strip->v1_codebook[*data++];
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
172 s->frame.data[0][iy[0] + 0] = codebook->y0;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
173 s->frame.data[0][iy[0] + 1] = codebook->y0;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
174 s->frame.data[0][iy[1] + 0] = codebook->y0;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
175 s->frame.data[0][iy[1] + 1] = codebook->y0;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
176 if (!s->palette_video) {
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
177 s->frame.data[1][iu[0]] = codebook->u;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
178 s->frame.data[2][iv[0]] = codebook->v;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
179 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
180
2089
9e0b49e1c7ff 100l fix codebook usage for v1 vectors
rtognimp
parents: 2009
diff changeset
181 s->frame.data[0][iy[0] + 2] = codebook->y1;
9e0b49e1c7ff 100l fix codebook usage for v1 vectors
rtognimp
parents: 2009
diff changeset
182 s->frame.data[0][iy[0] + 3] = codebook->y1;
9e0b49e1c7ff 100l fix codebook usage for v1 vectors
rtognimp
parents: 2009
diff changeset
183 s->frame.data[0][iy[1] + 2] = codebook->y1;
9e0b49e1c7ff 100l fix codebook usage for v1 vectors
rtognimp
parents: 2009
diff changeset
184 s->frame.data[0][iy[1] + 3] = codebook->y1;
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
185 if (!s->palette_video) {
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
186 s->frame.data[1][iu[0] + 1] = codebook->u;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
187 s->frame.data[2][iv[0] + 1] = codebook->v;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
188 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
189
2089
9e0b49e1c7ff 100l fix codebook usage for v1 vectors
rtognimp
parents: 2009
diff changeset
190 s->frame.data[0][iy[2] + 0] = codebook->y2;
9e0b49e1c7ff 100l fix codebook usage for v1 vectors
rtognimp
parents: 2009
diff changeset
191 s->frame.data[0][iy[2] + 1] = codebook->y2;
9e0b49e1c7ff 100l fix codebook usage for v1 vectors
rtognimp
parents: 2009
diff changeset
192 s->frame.data[0][iy[3] + 0] = codebook->y2;
9e0b49e1c7ff 100l fix codebook usage for v1 vectors
rtognimp
parents: 2009
diff changeset
193 s->frame.data[0][iy[3] + 1] = codebook->y2;
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
194 if (!s->palette_video) {
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
195 s->frame.data[1][iu[1]] = codebook->u;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
196 s->frame.data[2][iv[1]] = codebook->v;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
197 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
198
2089
9e0b49e1c7ff 100l fix codebook usage for v1 vectors
rtognimp
parents: 2009
diff changeset
199 s->frame.data[0][iy[2] + 2] = codebook->y3;
9e0b49e1c7ff 100l fix codebook usage for v1 vectors
rtognimp
parents: 2009
diff changeset
200 s->frame.data[0][iy[2] + 3] = codebook->y3;
9e0b49e1c7ff 100l fix codebook usage for v1 vectors
rtognimp
parents: 2009
diff changeset
201 s->frame.data[0][iy[3] + 2] = codebook->y3;
9e0b49e1c7ff 100l fix codebook usage for v1 vectors
rtognimp
parents: 2009
diff changeset
202 s->frame.data[0][iy[3] + 3] = codebook->y3;
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
203 if (!s->palette_video) {
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
204 s->frame.data[1][iu[1] + 1] = codebook->u;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
205 s->frame.data[2][iv[1] + 1] = codebook->v;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
206 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
207
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
208 } else if (flag & mask) {
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
209 if ((data + 4) > eod)
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
210 return -1;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
211
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
212 codebook = &strip->v4_codebook[*data++];
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
213 s->frame.data[0][iy[0] + 0] = codebook->y0;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
214 s->frame.data[0][iy[0] + 1] = codebook->y1;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
215 s->frame.data[0][iy[1] + 0] = codebook->y2;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
216 s->frame.data[0][iy[1] + 1] = codebook->y3;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
217 if (!s->palette_video) {
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
218 s->frame.data[1][iu[0]] = codebook->u;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
219 s->frame.data[2][iv[0]] = codebook->v;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
220 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
221
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
222 codebook = &strip->v4_codebook[*data++];
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
223 s->frame.data[0][iy[0] + 2] = codebook->y0;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
224 s->frame.data[0][iy[0] + 3] = codebook->y1;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
225 s->frame.data[0][iy[1] + 2] = codebook->y2;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
226 s->frame.data[0][iy[1] + 3] = codebook->y3;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
227 if (!s->palette_video) {
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
228 s->frame.data[1][iu[0] + 1] = codebook->u;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
229 s->frame.data[2][iv[0] + 1] = codebook->v;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
230 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
231
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
232 codebook = &strip->v4_codebook[*data++];
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
233 s->frame.data[0][iy[2] + 0] = codebook->y0;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
234 s->frame.data[0][iy[2] + 1] = codebook->y1;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
235 s->frame.data[0][iy[3] + 0] = codebook->y2;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
236 s->frame.data[0][iy[3] + 1] = codebook->y3;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
237 if (!s->palette_video) {
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
238 s->frame.data[1][iu[1]] = codebook->u;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
239 s->frame.data[2][iv[1]] = codebook->v;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
240 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
241
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
242 codebook = &strip->v4_codebook[*data++];
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
243 s->frame.data[0][iy[2] + 2] = codebook->y0;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
244 s->frame.data[0][iy[2] + 3] = codebook->y1;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
245 s->frame.data[0][iy[3] + 2] = codebook->y2;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
246 s->frame.data[0][iy[3] + 3] = codebook->y3;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
247 if (!s->palette_video) {
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
248 s->frame.data[1][iu[1] + 1] = codebook->u;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
249 s->frame.data[2][iv[1] + 1] = codebook->v;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
250 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
251
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
252 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
253 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
254
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
255 iy[0] += 4; iy[1] += 4;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
256 iy[2] += 4; iy[3] += 4;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
257 iu[0] += 2; iu[1] += 2;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
258 iv[0] += 2; iv[1] += 2;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
259 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
260 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
261
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
262 return 0;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
263 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
264
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
265 static int cinepak_decode_strip (CinepakContext *s,
8318
bc36a075bf35 The POSIX namespace shall be held sacrosanct. To that end,
melanson
parents: 7823
diff changeset
266 cvid_strip *strip, const uint8_t *data, int size)
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
267 {
6230
michael
parents: 5215
diff changeset
268 const uint8_t *eod = (data + size);
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
269 int chunk_id, chunk_size;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
270
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
271 /* coordinate sanity checks */
1572
860e44e2c20c support Cinepak files with funky (not divisible by 4) resolutions
melanson
parents: 1491
diff changeset
272 if (strip->x1 >= s->width || strip->x2 > s->width ||
860e44e2c20c support Cinepak files with funky (not divisible by 4) resolutions
melanson
parents: 1491
diff changeset
273 strip->y1 >= s->height || strip->y2 > s->height ||
860e44e2c20c support Cinepak files with funky (not divisible by 4) resolutions
melanson
parents: 1491
diff changeset
274 strip->x1 >= strip->x2 || strip->y1 >= strip->y2)
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
275 return -1;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
276
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
277 while ((data + 4) <= eod) {
8580
144ddb6a597c Cinepak strip and chunk sizes are 24-bit, not 16-bit as it was thought earlier.
kostya
parents: 8573
diff changeset
278 chunk_id = data[0];
144ddb6a597c Cinepak strip and chunk sizes are 24-bit, not 16-bit as it was thought earlier.
kostya
parents: 8573
diff changeset
279 chunk_size = AV_RB24 (&data[1]) - 4;
2787
af90d5dc83f0 fix infinite loop (suggested change by rjayne at convera dot com)
michael
parents: 2106
diff changeset
280 if(chunk_size < 0)
af90d5dc83f0 fix infinite loop (suggested change by rjayne at convera dot com)
michael
parents: 2106
diff changeset
281 return -1;
af90d5dc83f0 fix infinite loop (suggested change by rjayne at convera dot com)
michael
parents: 2106
diff changeset
282
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
283 data += 4;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
284 chunk_size = ((data + chunk_size) > eod) ? (eod - data) : chunk_size;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
285
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
286 switch (chunk_id) {
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
287
8580
144ddb6a597c Cinepak strip and chunk sizes are 24-bit, not 16-bit as it was thought earlier.
kostya
parents: 8573
diff changeset
288 case 0x20:
144ddb6a597c Cinepak strip and chunk sizes are 24-bit, not 16-bit as it was thought earlier.
kostya
parents: 8573
diff changeset
289 case 0x21:
144ddb6a597c Cinepak strip and chunk sizes are 24-bit, not 16-bit as it was thought earlier.
kostya
parents: 8573
diff changeset
290 case 0x24:
144ddb6a597c Cinepak strip and chunk sizes are 24-bit, not 16-bit as it was thought earlier.
kostya
parents: 8573
diff changeset
291 case 0x25:
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2963
diff changeset
292 cinepak_decode_codebook (strip->v4_codebook, chunk_id,
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
293 chunk_size, data);
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
294 break;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
295
8580
144ddb6a597c Cinepak strip and chunk sizes are 24-bit, not 16-bit as it was thought earlier.
kostya
parents: 8573
diff changeset
296 case 0x22:
144ddb6a597c Cinepak strip and chunk sizes are 24-bit, not 16-bit as it was thought earlier.
kostya
parents: 8573
diff changeset
297 case 0x23:
144ddb6a597c Cinepak strip and chunk sizes are 24-bit, not 16-bit as it was thought earlier.
kostya
parents: 8573
diff changeset
298 case 0x26:
144ddb6a597c Cinepak strip and chunk sizes are 24-bit, not 16-bit as it was thought earlier.
kostya
parents: 8573
diff changeset
299 case 0x27:
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2963
diff changeset
300 cinepak_decode_codebook (strip->v1_codebook, chunk_id,
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
301 chunk_size, data);
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
302 break;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
303
8580
144ddb6a597c Cinepak strip and chunk sizes are 24-bit, not 16-bit as it was thought earlier.
kostya
parents: 8573
diff changeset
304 case 0x30:
144ddb6a597c Cinepak strip and chunk sizes are 24-bit, not 16-bit as it was thought earlier.
kostya
parents: 8573
diff changeset
305 case 0x31:
144ddb6a597c Cinepak strip and chunk sizes are 24-bit, not 16-bit as it was thought earlier.
kostya
parents: 8573
diff changeset
306 case 0x32:
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2963
diff changeset
307 return cinepak_decode_vectors (s, strip, chunk_id,
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
308 chunk_size, data);
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
309 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
310
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
311 data += chunk_size;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
312 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
313
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
314 return -1;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
315 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
316
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
317 static int cinepak_decode (CinepakContext *s)
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
318 {
6230
michael
parents: 5215
diff changeset
319 const uint8_t *eod = (s->data + s->size);
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
320 int i, result, strip_size, frame_flags, num_strips;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
321 int y0 = 0;
2836
7bfea1374957 automatically detect Cinepak data from Sega FILM/CPK files
melanson
parents: 2787
diff changeset
322 int encoded_buf_size;
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
323
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
324 if (s->size < 10)
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
325 return -1;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
326
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
327 frame_flags = s->data[0];
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4262
diff changeset
328 num_strips = AV_RB16 (&s->data[8]);
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4262
diff changeset
329 encoded_buf_size = ((s->data[1] << 16) | AV_RB16 (&s->data[2]));
4262
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
330
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
331 /* if this is the first frame, check for deviant Sega FILM data */
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
332 if (s->sega_film_skip_bytes == -1) {
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
333 if (encoded_buf_size != s->size) {
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
334 /* If the encoded frame size differs from the frame size as indicated
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
335 * by the container file, this data likely comes from a Sega FILM/CPK file.
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
336 * If the frame header is followed by the bytes FE 00 00 06 00 00 then
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
337 * this is probably one of the two known files that have 6 extra bytes
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
338 * after the frame header. Else, assume 2 extra bytes. */
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
339 if ((s->data[10] == 0xFE) &&
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
340 (s->data[11] == 0x00) &&
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
341 (s->data[12] == 0x00) &&
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
342 (s->data[13] == 0x06) &&
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
343 (s->data[14] == 0x00) &&
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
344 (s->data[15] == 0x00))
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
345 s->sega_film_skip_bytes = 6;
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
346 else
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
347 s->sega_film_skip_bytes = 2;
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
348 } else
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
349 s->sega_film_skip_bytes = 0;
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
350 }
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
351
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
352 s->data += 10 + s->sega_film_skip_bytes;
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
353
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
354 if (num_strips > MAX_STRIPS)
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
355 num_strips = MAX_STRIPS;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
356
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
357 for (i=0; i < num_strips; i++) {
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
358 if ((s->data + 12) > eod)
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
359 return -1;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
360
8581
c8d93b8559fe Cinepak strip ID is a single byte
kostya
parents: 8580
diff changeset
361 s->strips[i].id = s->data[0];
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
362 s->strips[i].y1 = y0;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
363 s->strips[i].x1 = 0;
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4262
diff changeset
364 s->strips[i].y2 = y0 + AV_RB16 (&s->data[8]);
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
365 s->strips[i].x2 = s->avctx->width;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
366
8580
144ddb6a597c Cinepak strip and chunk sizes are 24-bit, not 16-bit as it was thought earlier.
kostya
parents: 8573
diff changeset
367 strip_size = AV_RB24 (&s->data[1]) - 12;
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
368 s->data += 12;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
369 strip_size = ((s->data + strip_size) > eod) ? (eod - s->data) : strip_size;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
370
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
371 if ((i > 0) && !(frame_flags & 0x01)) {
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
372 memcpy (s->strips[i].v4_codebook, s->strips[i-1].v4_codebook,
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
373 sizeof(s->strips[i].v4_codebook));
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
374 memcpy (s->strips[i].v1_codebook, s->strips[i-1].v1_codebook,
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
375 sizeof(s->strips[i].v1_codebook));
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
376 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
377
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
378 result = cinepak_decode_strip (s, &s->strips[i], s->data, strip_size);
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
379
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
380 if (result != 0)
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
381 return result;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
382
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
383 s->data += strip_size;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
384 y0 = s->strips[i].y2;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
385 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
386 return 0;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
387 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
388
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6484
diff changeset
389 static av_cold int cinepak_decode_init(AVCodecContext *avctx)
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
390 {
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4801
diff changeset
391 CinepakContext *s = avctx->priv_data;
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
392
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
393 s->avctx = avctx;
1572
860e44e2c20c support Cinepak files with funky (not divisible by 4) resolutions
melanson
parents: 1491
diff changeset
394 s->width = (avctx->width + 3) & ~3;
860e44e2c20c support Cinepak files with funky (not divisible by 4) resolutions
melanson
parents: 1491
diff changeset
395 s->height = (avctx->height + 3) & ~3;
4262
cdcfabd40101 Another hack to allow the Cinepak decoder to detect both types of deviant Cinepak
melanson
parents: 3947
diff changeset
396 s->sega_film_skip_bytes = -1; /* uninitialized state */
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
397
2105
b293b6c3a1a6 Paletted cvid support
rtognimp
parents: 2089
diff changeset
398 // check for paletted data
7823
4525dcd81357 Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 7040
diff changeset
399 if ((avctx->palctrl == NULL) || (avctx->bits_per_coded_sample == 40)) {
2105
b293b6c3a1a6 Paletted cvid support
rtognimp
parents: 2089
diff changeset
400 s->palette_video = 0;
b293b6c3a1a6 Paletted cvid support
rtognimp
parents: 2089
diff changeset
401 avctx->pix_fmt = PIX_FMT_YUV420P;
b293b6c3a1a6 Paletted cvid support
rtognimp
parents: 2089
diff changeset
402 } else {
b293b6c3a1a6 Paletted cvid support
rtognimp
parents: 2089
diff changeset
403 s->palette_video = 1;
b293b6c3a1a6 Paletted cvid support
rtognimp
parents: 2089
diff changeset
404 avctx->pix_fmt = PIX_FMT_PAL8;
b293b6c3a1a6 Paletted cvid support
rtognimp
parents: 2089
diff changeset
405 }
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
406
2009
b13a25ac9f0c buffer hints, use reget_buffer, removed copy from previous frame
rtognimp
parents: 1881
diff changeset
407 s->frame.data[0] = NULL;
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
408
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
409 return 0;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
410 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
411
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
412 static int cinepak_decode_frame(AVCodecContext *avctx,
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
413 void *data, int *data_size,
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
414 AVPacket *avpkt)
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
415 {
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
416 const uint8_t *buf = avpkt->data;
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
417 int buf_size = avpkt->size;
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4801
diff changeset
418 CinepakContext *s = avctx->priv_data;
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
419
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
420 s->data = buf;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
421 s->size = buf_size;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
422
2009
b13a25ac9f0c buffer hints, use reget_buffer, removed copy from previous frame
rtognimp
parents: 1881
diff changeset
423 s->frame.reference = 1;
b13a25ac9f0c buffer hints, use reget_buffer, removed copy from previous frame
rtognimp
parents: 1881
diff changeset
424 s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE |
b13a25ac9f0c buffer hints, use reget_buffer, removed copy from previous frame
rtognimp
parents: 1881
diff changeset
425 FF_BUFFER_HINTS_REUSABLE;
b13a25ac9f0c buffer hints, use reget_buffer, removed copy from previous frame
rtognimp
parents: 1881
diff changeset
426 if (avctx->reget_buffer(avctx, &s->frame)) {
b13a25ac9f0c buffer hints, use reget_buffer, removed copy from previous frame
rtognimp
parents: 1881
diff changeset
427 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
428 return -1;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
429 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
430
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
431 cinepak_decode(s);
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
432
2105
b293b6c3a1a6 Paletted cvid support
rtognimp
parents: 2089
diff changeset
433 if (s->palette_video) {
b293b6c3a1a6 Paletted cvid support
rtognimp
parents: 2089
diff changeset
434 memcpy (s->frame.data[1], avctx->palctrl->palette, AVPALETTE_SIZE);
b293b6c3a1a6 Paletted cvid support
rtognimp
parents: 2089
diff changeset
435 if (avctx->palctrl->palette_changed) {
b293b6c3a1a6 Paletted cvid support
rtognimp
parents: 2089
diff changeset
436 s->frame.palette_has_changed = 1;
b293b6c3a1a6 Paletted cvid support
rtognimp
parents: 2089
diff changeset
437 avctx->palctrl->palette_changed = 0;
b293b6c3a1a6 Paletted cvid support
rtognimp
parents: 2089
diff changeset
438 } else
b293b6c3a1a6 Paletted cvid support
rtognimp
parents: 2089
diff changeset
439 s->frame.palette_has_changed = 0;
b293b6c3a1a6 Paletted cvid support
rtognimp
parents: 2089
diff changeset
440 }
b293b6c3a1a6 Paletted cvid support
rtognimp
parents: 2089
diff changeset
441
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
442 *data_size = sizeof(AVFrame);
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
443 *(AVFrame*)data = s->frame;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
444
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
445 /* report that the buffer was completely consumed */
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
446 return buf_size;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
447 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
448
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6484
diff changeset
449 static av_cold int cinepak_decode_end(AVCodecContext *avctx)
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
450 {
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4801
diff changeset
451 CinepakContext *s = avctx->priv_data;
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
452
2009
b13a25ac9f0c buffer hints, use reget_buffer, removed copy from previous frame
rtognimp
parents: 1881
diff changeset
453 if (s->frame.data[0])
b13a25ac9f0c buffer hints, use reget_buffer, removed copy from previous frame
rtognimp
parents: 1881
diff changeset
454 avctx->release_buffer(avctx, &s->frame);
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
455
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
456 return 0;
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
457 }
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
458
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
459 AVCodec cinepak_decoder = {
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
460 "cinepak",
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
461 CODEC_TYPE_VIDEO,
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
462 CODEC_ID_CINEPAK,
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
463 sizeof(CinepakContext),
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
464 cinepak_decode_init,
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
465 NULL,
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
466 cinepak_decode_end,
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
467 cinepak_decode_frame,
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
468 CODEC_CAP_DR1,
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6710
diff changeset
469 .long_name = NULL_IF_CONFIG_SMALL("Cinepak"),
1491
222643544cf1 New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
diff changeset
470 };