54#define PREAMBLE_SIZE 4096
67 for (
i = 0;
i < 2;
i++) {
68 for (j = 0; j < 256; j++) {
69 for (k = 0; k < 8; k++) {
70 gdv->
frame[
i * 2048 + j * 8 + k] = j;
81 for (x = 0; x <
w - 7; x+=8) {
83 dst[x + 1] =
src[(x>>1) + 0];
85 dst[x + 3] =
src[(x>>1) + 1];
87 dst[x + 5] =
src[(x>>1) + 2];
89 dst[x + 7] =
src[(x>>1) + 3];
100 for (x =
w - 1; (x+1) & 7; x--) {
103 for (x -= 7; x >= 0; x -= 8) {
105 dst[x + 7] =
src[(x>>1) + 3];
107 dst[x + 5] =
src[(x>>1) + 2];
109 dst[x + 3] =
src[(x>>1) + 1];
111 dst[x + 1] =
src[(x>>1) + 0];
118 for (x = 0; x <
w - 7; x+=8) {
119 dst[x + 0] =
src[2*x + 0];
120 dst[x + 1] =
src[2*x + 2];
121 dst[x + 2] =
src[2*x + 4];
122 dst[x + 3] =
src[2*x + 6];
123 dst[x + 4] =
src[2*x + 8];
124 dst[x + 5] =
src[2*x +10];
125 dst[x + 6] =
src[2*x +12];
126 dst[x + 7] =
src[2*x +14];
142 for (j = 0; j <
h; j++) {
150 for (j = 0; j <
h; j++) {
154 memcpy(dst1,
src1,
w);
158 if (scale_h && scale_v) {
159 for (y = 0; y < (
h>>1); y++) {
164 }
else if (scale_h) {
165 for (y = 0; y < (
h>>1); y++) {
168 memcpy(dst1,
src1,
w);
170 }
else if (scale_v) {
171 for (y = 0; y <
h; y++) {
185 if (
bits->fill == 0) {
186 bits->queue |= bytestream2_get_byte(gb);
189 res =
bits->queue >> 6;
198 bits->queue = bytestream2_get_le32(gb);
204 int res =
bits->queue & ((1 << nbits) - 1);
206 bits->queue >>= nbits;
208 if (
bits->fill <= 16) {
209 bits->queue |= bytestream2_get_le16(gb) <<
bits->fill;
224 c = bytestream2_get_byte(g2);
225 for (
i = 0;
i <
len;
i++) {
226 bytestream2_put_byte(pb,
c);
232 for (
i = 0;
i <
len;
i++) {
233 bytestream2_put_byte(pb, bytestream2_get_byte(g2));
239 for (
i = 0;
i <
len;
i++) {
240 bytestream2_put_byte(pb, bytestream2_get_byte(g2));
257 for (
c = 0;
c < 256;
c++) {
258 for (
i = 0;
i < 16;
i++) {
266 bytestream2_put_byte(pb, bytestream2_get_byte(gb));
267 }
else if (
tag == 1) {
268 int b = bytestream2_get_byte(gb);
269 int len = (
b & 0xF) + 3;
270 int top = (
b >> 4) & 0xF;
271 int off = (bytestream2_get_byte(gb) << 4) + top - 4096;
273 }
else if (
tag == 2) {
274 int len = (bytestream2_get_byte(gb)) + 2;
303 bytestream2_put_byte(pb, bytestream2_get_byte(gb));
304 }
else if (
tag == 1) {
305 int b = bytestream2_get_byte(gb);
306 int len = (
b & 0xF) + 3;
308 int off = (bytestream2_get_byte(gb) << 4) + top - 4096;
310 }
else if (
tag == 2) {
312 int b = bytestream2_get_byte(gb);
319 len = bytestream2_get_le16(gb);
323 int b = bytestream2_get_byte(gb);
324 int len = (
b & 0x3) + 2;
325 int off = -(
b >> 2) - 1;
351 bytestream2_put_byte(pb, bytestream2_get_byte(gb));
361 if (
val != ((1 << lbits) - 1)) {
367 for (
i = 0;
i <
len;
i++) {
368 bytestream2_put_byte(pb, bytestream2_get_byte(gb));
371 }
else if (
tag == 1) {
378 int bb = bytestream2_get_byte(gb);
379 if ((bb & 0x80) == 0) {
382 int top = (bb & 0x7F) << 8;
383 len = top + bytestream2_get_byte(gb) + 146;
387 }
else if (
tag == 2) {
392 int offs = top + bytestream2_get_byte(gb);
393 if ((subtag != 0) || (offs <= 0xF80)) {
394 int len = (subtag) + 3;
403 real_off = ((offs >> 4) & 0x7) + 1;
404 len = ((offs & 0xF) + 2) * 2;
407 for (
i = 0;
i <
len/2;
i++) {
408 bytestream2_put_byte(pb,
c1);
409 bytestream2_put_byte(pb,
c2);
413 int b = bytestream2_get_byte(gb);
414 int off = ((
b & 0x7F)) + 1;
415 int len = ((
b & 0x80) == 0) ? 2 : 3;
423 int q,
b = bytestream2_get_byte(gb);
424 if ((
b & 0xC0) == 0xC0) {
425 len = ((
b & 0x3F)) + 8;
427 off = (q << 8) + (bytestream2_get_byte(gb)) + 1;
430 if ((
b & 0x80) == 0) {
431 len = ((
b >> 4)) + 6;
434 len = ((
b & 0x3F)) + 14;
437 off = (ofs1 << 8) + (bytestream2_get_byte(gb)) - 4096;
440 int ofs1,
b = bytestream2_get_byte(gb);
442 if ((
b >> 4) == 0xF) {
443 len = bytestream2_get_byte(gb) + 21;
448 off = (ofs1 << 8) + bytestream2_get_byte(gb) - 4096;
474 flags = bytestream2_get_le32(gb);
475 compression =
flags & 0xF;
477 if (compression == 4 || compression == 7 || compression > 8)
489 switch (compression) {
494 for (
i = 0;
i < 256;
i++) {
495 unsigned r = bytestream2_get_byte(gb);
496 unsigned g = bytestream2_get_byte(gb);
497 unsigned b = bytestream2_get_byte(gb);
498 gdv->
pal[
i] = 0xFFU << 24 |
r << 18 |
g << 10 |
b << 2;
528 for (y = 0; y < avctx->
height; y++) {
530 sidx += avctx->
width;
531 didx +=
frame->linesize[0];
537 for (y = 0; y < avctx->
height; y++) {
541 uint8_t *dst2 =
dst + didx;
546 if (!gdv->
scale_h || ((y & 1) == 1)) {
549 didx +=
frame->linesize[0];
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static double val(void *priv, double ch)
const FFCodec ff_gdv_decoder
static av_cold void close(AVCodecParserContext *s)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
static void BS_FUNC skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
static av_always_inline int bytestream2_tell_p(const PutByteContext *p)
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
static av_always_inline void bytestream2_skip_p(PutByteContext *p, unsigned int size)
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
static av_always_inline int bytestream2_get_bytes_left_p(const PutByteContext *p)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
common internal and external API header
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int ff_copy_palette(void *dst, const AVPacket *src, void *logctx)
Check whether the side-data of src contains a palette of size AVPALETTE_SIZE; if so,...
int(* init)(AVBSFContext *ctx)
static const uint8_t bits[8]
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static av_cold int gdv_decode_close(AVCodecContext *avctx)
static int read_bits32(Bits32 *bits, GetByteContext *gb, int nbits)
static void lz_copy(PutByteContext *pb, GetByteContext *g2, int offset, unsigned len)
static void scaledown(uint8_t *dst, const uint8_t *src, int w)
static void scaleup_rev(uint8_t *dst, const uint8_t *src, int w)
static av_cold int gdv_decode_init(AVCodecContext *avctx)
static void scaleup(uint8_t *dst, const uint8_t *src, int w)
static void rescale(GDVContext *gdv, uint8_t *dst, int w, int h, int scale_v, int scale_h)
static int decompress_68(AVCodecContext *avctx, unsigned skip, unsigned use8)
static int gdv_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
static void fill_bits32(Bits32 *bits, GetByteContext *gb)
static int decompress_2(AVCodecContext *avctx)
static int read_bits2(Bits8 *bits, GetByteContext *gb)
static int decompress_5(AVCodecContext *avctx, unsigned skip)
Macro definitions for various function/variable attributes.
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
@ 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.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.