annotate truemotion1.c @ 1733:b47d56b1a049 libavcodec

optimize compute_antialias() and add a floating point based alternative (2x faster)
author michael
date Thu, 08 Jan 2004 21:08:57 +0000
parents 1c123e036890
children a660ef952580
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1650
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
1 /*
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
2 * Duck TrueMotion 1.0 Decoder
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
3 * Copyright (C) 2003 Alex Beregszaszi & Mike Melanson
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
4 *
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
9 *
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
13 * Lesser General Public License for more details.
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
14 *
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
18 */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
19
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
20 /**
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
21 * @file truemotion1.c
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
22 * Duck TrueMotion v1 Video Decoder by
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
23 * Alex Beregszaszi (alex@fsn.hu) and
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
24 * Mike Melanson (melanson@pcisys.net)
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
25 *
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
26 * The TrueMotion v1 decoder presently only decodes 16-bit TM1 data and
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
27 * outputs RGB555 data. 24-bit TM1 data is not supported yet.
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
28 */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
29
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
30 #include <stdio.h>
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
31 #include <stdlib.h>
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
32 #include <string.h>
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
33 #include <unistd.h>
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
34
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
35 #include "common.h"
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
36 #include "avcodec.h"
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
37 #include "dsputil.h"
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
38
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
39 #include "truemotion1data.h"
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
40
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
41 #define LE_16(x) ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0])
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
42
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
43 typedef struct TrueMotion1Context {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
44 AVCodecContext *avctx;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
45 AVFrame frame;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
46 AVFrame prev_frame;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
47
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
48 unsigned char *buf;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
49 int size;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
50
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
51 unsigned char *mb_change_bits;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
52 int mb_change_bits_row_size;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
53 unsigned char *index_stream;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
54 int index_stream_size;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
55
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
56 int flags;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
57 int x, y, w, h;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
58
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
59 uint32_t y_predictor_table[1024];
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
60 uint32_t c_predictor_table[1024];
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
61
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
62 int compression;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
63 int block_type;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
64 int block_width;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
65 int block_height;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
66
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
67 int16_t *ydt;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
68 int16_t *cdt;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
69 int16_t *fat_ydt;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
70 int16_t *fat_cdt;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
71
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
72 int last_deltaset, last_vectable;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
73
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
74 unsigned int *vert_pred;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
75
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
76 } TrueMotion1Context;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
77
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
78 #define FLAG_SPRITE 32
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
79 #define FLAG_KEYFRAME 16
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
80 #define FLAG_INTERFRAME 8
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
81 #define FLAG_INTERPOLATED 4
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
82
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
83 struct frame_header {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
84 uint8_t header_size;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
85 uint8_t compression;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
86 uint8_t deltaset;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
87 uint8_t vectable;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
88 uint16_t ysize;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
89 uint16_t xsize;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
90 uint16_t checksum;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
91 uint8_t version;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
92 uint8_t header_type;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
93 uint8_t flags;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
94 uint8_t control;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
95 uint16_t xoffset;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
96 uint16_t yoffset;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
97 uint16_t width;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
98 uint16_t height;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
99 };
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
100
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
101 #define ALGO_NOP 0
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
102 #define ALGO_RGB16V 1
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
103 #define ALGO_RGB16H 2
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
104 #define ALGO_RGB24H 3
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
105
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
106 /* these are the various block sizes that can occupy a 4x4 block */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
107 #define BLOCK_2x2 0
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
108 #define BLOCK_2x4 1
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
109 #define BLOCK_4x2 2
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
110 #define BLOCK_4x4 3
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
111
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
112 typedef struct comp_types {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
113 int algorithm;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
114 int block_width;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
115 int block_height;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
116 int block_type;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
117 } comp_types;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
118
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
119 /* { valid for metatype }, algorithm, num of deltas, horiz res, vert res */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
120 static comp_types compression_types[17] = {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
121 { ALGO_NOP, 0, 0, 0 },
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
122
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
123 { ALGO_RGB16V, 4, 4, BLOCK_4x4 },
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
124 { ALGO_RGB16H, 4, 4, BLOCK_4x4 },
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
125 { ALGO_RGB16V, 4, 2, BLOCK_4x2 },
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
126 { ALGO_RGB16H, 4, 2, BLOCK_4x2 },
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
127
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
128 { ALGO_RGB16V, 2, 4, BLOCK_2x4 },
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
129 { ALGO_RGB16H, 2, 4, BLOCK_2x4 },
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
130 { ALGO_RGB16V, 2, 2, BLOCK_2x2 },
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
131 { ALGO_RGB16H, 2, 2, BLOCK_2x2 },
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
132
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
133 { ALGO_NOP, 4, 4, BLOCK_4x4 },
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
134 { ALGO_RGB24H, 4, 4, BLOCK_4x4 },
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
135 { ALGO_NOP, 4, 2, BLOCK_4x2 },
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
136 { ALGO_RGB24H, 4, 2, BLOCK_4x2 },
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
137
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
138 { ALGO_NOP, 2, 4, BLOCK_2x4 },
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
139 { ALGO_RGB24H, 2, 4, BLOCK_2x4 },
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
140 { ALGO_NOP, 2, 2, BLOCK_2x2 },
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
141 { ALGO_RGB24H, 2, 2, BLOCK_2x2 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
142 };
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
143
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
144 static void select_delta_tables(TrueMotion1Context *s, int delta_table_index)
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
145 {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
146 int i;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
147
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
148 if (delta_table_index > 3)
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
149 return;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
150
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
151 s->ydt = ydts[delta_table_index];
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
152 s->cdt = cdts[delta_table_index];
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
153 s->fat_ydt = fat_ydts[delta_table_index];
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
154 s->fat_cdt = fat_cdts[delta_table_index];
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
155
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
156 /* Y skinny deltas need to be halved for some reason; maybe the
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
157 * skinny Y deltas should be modified */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
158 for (i = 0; i < 8; i++)
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
159 {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
160 /* drop the lsb before dividing by 2-- net effect: round down
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
161 * when dividing a negative number (e.g., -3/2 = -2, not -1) */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
162 s->ydt[i] &= 0xFFFE;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
163 s->ydt[i] /= 2;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
164 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
165 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
166
1654
1c123e036890 this should make the decoder safe for big-endian platforms
melanson
parents: 1650
diff changeset
167 #ifdef WORDS_BIGENDIAN
1c123e036890 this should make the decoder safe for big-endian platforms
melanson
parents: 1650
diff changeset
168 static int make_ydt_entry(int p2, int p1, int16_t *ydt)
1c123e036890 this should make the decoder safe for big-endian platforms
melanson
parents: 1650
diff changeset
169 #else
1650
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
170 static int make_ydt_entry(int p1, int p2, int16_t *ydt)
1654
1c123e036890 this should make the decoder safe for big-endian platforms
melanson
parents: 1650
diff changeset
171 #endif
1650
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
172 {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
173 int lo, hi;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
174
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
175 lo = ydt[p1];
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
176 lo += (lo << 5) + (lo << 10);
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
177 hi = ydt[p2];
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
178 hi += (hi << 5) + (hi << 10);
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
179 return ((lo + (hi << 16)) << 1);
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
180 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
181
1654
1c123e036890 this should make the decoder safe for big-endian platforms
melanson
parents: 1650
diff changeset
182 #ifdef WORDS_BIGENDIAN
1c123e036890 this should make the decoder safe for big-endian platforms
melanson
parents: 1650
diff changeset
183 static int make_cdt_entry(int p2, int p1, int16_t *cdt)
1c123e036890 this should make the decoder safe for big-endian platforms
melanson
parents: 1650
diff changeset
184 #else
1650
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
185 static int make_cdt_entry(int p1, int p2, int16_t *cdt)
1654
1c123e036890 this should make the decoder safe for big-endian platforms
melanson
parents: 1650
diff changeset
186 #endif
1650
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
187 {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
188 int r, b, lo;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
189
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
190 b = cdt[p2];
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
191 r = cdt[p1] << 10;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
192 lo = b + r;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
193 return ((lo + (lo << 16)) << 1);
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
194 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
195
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
196 static void gen_vector_table(TrueMotion1Context *s, uint8_t *sel_vector_table)
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
197 {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
198 int len, i, j;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
199 unsigned char delta_pair;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
200
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
201 for (i = 0; i < 1024; i += 4)
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
202 {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
203 len = *sel_vector_table++ / 2;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
204 for (j = 0; j < len; j++)
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
205 {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
206 delta_pair = *sel_vector_table++;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
207 s->y_predictor_table[i+j] = 0xfffffffe &
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
208 make_ydt_entry(delta_pair >> 4, delta_pair & 0xf, s->ydt);
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
209 s->c_predictor_table[i+j] = 0xfffffffe &
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
210 make_cdt_entry(delta_pair >> 4, delta_pair & 0xf, s->cdt);
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
211 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
212 s->y_predictor_table[i+(j-1)] |= 1;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
213 s->c_predictor_table[i+(j-1)] |= 1;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
214 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
215 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
216
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
217 /* Returns the number of bytes consumed from the bytestream. Returns -1 if
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
218 * there was an error while decoding the header */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
219 static int truemotion1_decode_header(TrueMotion1Context *s)
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
220 {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
221 int i;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
222 struct frame_header header;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
223 uint8_t header_buffer[128]; /* logical maximum size of the header */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
224 uint8_t *sel_vector_table;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
225
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
226 /* There is 1 change bit per 4 pixels, so each change byte represents
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
227 * 32 pixels; divide width by 4 to obtain the number of change bits and
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
228 * then round up to the nearest byte. */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
229 s->mb_change_bits_row_size = ((s->avctx->width >> 2) + 7) >> 3;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
230
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
231 header.header_size = ((s->buf[0] >> 5) | (s->buf[0] << 3)) & 0x7f;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
232 if (s->buf[0] < 0x10)
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
233 {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
234 printf("invalid header size\n");
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
235 return -1;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
236 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
237
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
238 /* unscramble the header bytes with a XOR operation */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
239 memset(header_buffer, 0, 128);
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
240 for (i = 1; i < header.header_size; i++)
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
241 header_buffer[i - 1] = s->buf[i] ^ s->buf[i + 1];
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
242 header.compression = header_buffer[0];
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
243 header.deltaset = header_buffer[1];
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
244 header.vectable = header_buffer[2];
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
245 header.ysize = LE_16(&header_buffer[3]);
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
246 header.xsize = LE_16(&header_buffer[5]);
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
247 header.checksum = LE_16(&header_buffer[7]);
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
248 header.version = header_buffer[9];
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
249 header.header_type = header_buffer[10];
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
250 header.flags = header_buffer[11];
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
251 header.control = header_buffer[12];
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
252
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
253 /* Version 2 */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
254 if (header.version >= 2)
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
255 {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
256 if (header.header_type > 3)
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
257 {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
258 av_log(s->avctx, AV_LOG_ERROR, "truemotion1: invalid header type\n");
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
259 return -1;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
260 } else if ((header.header_type == 2) || (header.header_type == 3)) {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
261 s->flags = header.flags;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
262 if (!(s->flags & FLAG_INTERFRAME))
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
263 s->flags |= FLAG_KEYFRAME;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
264 } else
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
265 s->flags = FLAG_KEYFRAME;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
266 } else /* Version 1 */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
267 s->flags = FLAG_KEYFRAME;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
268
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
269 if (s->flags & FLAG_SPRITE) {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
270 s->w = header.width;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
271 s->h = header.height;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
272 s->x = header.xoffset;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
273 s->y = header.yoffset;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
274 } else {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
275 s->w = header.xsize;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
276 s->h = header.ysize;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
277 if (header.header_type < 2) {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
278 if ((s->w < 213) && (s->h >= 176))
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
279 s->flags |= FLAG_INTERPOLATED;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
280 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
281 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
282
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
283 if (header.compression > 17) {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
284 printf("invalid compression type (%d)\n", header.compression);
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
285 return -1;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
286 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
287
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
288 if ((header.deltaset != s->last_deltaset) ||
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
289 (header.vectable != s->last_vectable))
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
290 select_delta_tables(s, header.deltaset);
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
291
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
292 if ((header.compression & 1) && header.header_type)
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
293 sel_vector_table = pc_tbl2;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
294 else {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
295 if (header.vectable < 4)
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
296 sel_vector_table = tables[header.vectable - 1];
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
297 else {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
298 printf("invalid vector table id (%d)\n", header.vectable);
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
299 return -1;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
300 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
301 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
302
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
303 if ((header.deltaset != s->last_deltaset) || (header.vectable != s->last_vectable))
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
304 {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
305 if (compression_types[header.compression].algorithm == ALGO_RGB24H)
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
306 {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
307 printf("24bit compression not yet supported\n");
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
308 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
309 else
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
310 gen_vector_table(s, sel_vector_table);
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
311 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
312
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
313 /* set up pointers to the other key data chunks */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
314 s->mb_change_bits = s->buf + header.header_size;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
315 if (s->flags & FLAG_KEYFRAME) {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
316 /* no change bits specified for a keyframe; only index bytes */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
317 s->index_stream = s->mb_change_bits;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
318 } else {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
319 /* one change bit per 4x4 block */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
320 s->index_stream = s->mb_change_bits +
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
321 (s->mb_change_bits_row_size * (s->avctx->height >> 2));
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
322 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
323 s->index_stream_size = s->size - (s->index_stream - s->buf);
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
324
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
325 s->last_deltaset = header.deltaset;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
326 s->last_vectable = header.vectable;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
327 s->compression = header.compression;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
328 s->block_width = compression_types[header.compression].block_width;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
329 s->block_height = compression_types[header.compression].block_height;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
330 s->block_type = compression_types[header.compression].block_type;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
331
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
332 return header.header_size;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
333 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
334
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
335 static int truemotion1_decode_init(AVCodecContext *avctx)
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
336 {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
337 TrueMotion1Context *s = (TrueMotion1Context *)avctx->priv_data;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
338
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
339 s->avctx = avctx;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
340
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
341 avctx->pix_fmt = PIX_FMT_RGB555;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
342 avctx->has_b_frames = 0;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
343 s->frame.data[0] = s->prev_frame.data[0] = NULL;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
344
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
345 /* there is a vertical predictor for each pixel in a line; each vertical
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
346 * predictor is 0 to start with */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
347 s->vert_pred =
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
348 (unsigned int *)av_malloc(s->avctx->width * sizeof(unsigned short));
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
349
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
350 return 0;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
351 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
352
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
353 #define GET_NEXT_INDEX() \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
354 {\
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
355 if (index_stream_index >= s->index_stream_size) { \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
356 printf (" help! truemotion1 decoder went out of bounds\n"); \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
357 return; \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
358 } \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
359 index = s->index_stream[index_stream_index++] * 4; \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
360 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
361
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
362 #define APPLY_C_PREDICTOR() \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
363 predictor_pair = s->c_predictor_table[index]; \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
364 horiz_pred += (predictor_pair >> 1); \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
365 if (predictor_pair & 1) { \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
366 GET_NEXT_INDEX() \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
367 if (!index) { \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
368 GET_NEXT_INDEX() \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
369 predictor_pair = s->c_predictor_table[index]; \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
370 horiz_pred += ((predictor_pair >> 1) * 5); \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
371 if (predictor_pair & 1) \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
372 GET_NEXT_INDEX() \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
373 else \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
374 index++; \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
375 } \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
376 } else \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
377 index++;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
378
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
379 #define APPLY_Y_PREDICTOR() \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
380 predictor_pair = s->y_predictor_table[index]; \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
381 horiz_pred += (predictor_pair >> 1); \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
382 if (predictor_pair & 1) { \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
383 GET_NEXT_INDEX() \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
384 if (!index) { \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
385 GET_NEXT_INDEX() \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
386 predictor_pair = s->y_predictor_table[index]; \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
387 horiz_pred += ((predictor_pair >> 1) * 5); \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
388 if (predictor_pair & 1) \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
389 GET_NEXT_INDEX() \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
390 else \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
391 index++; \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
392 } \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
393 } else \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
394 index++;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
395
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
396 #define OUTPUT_PIXEL_PAIR() \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
397 *current_pixel_pair = *vert_pred + horiz_pred; \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
398 *vert_pred++ = *current_pixel_pair++; \
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
399 prev_pixel_pair++;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
400
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
401 static void truemotion1_decode_16bit(TrueMotion1Context *s)
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
402 {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
403 int y;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
404 int pixels_left; /* remaining pixels on this line */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
405 unsigned int predictor_pair;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
406 unsigned int horiz_pred;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
407 unsigned int *vert_pred;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
408 unsigned int *current_pixel_pair;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
409 unsigned int *prev_pixel_pair;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
410 unsigned char *current_line = s->frame.data[0];
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
411 unsigned char *prev_line = s->prev_frame.data[0];
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
412 int keyframe = s->flags & FLAG_KEYFRAME;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
413
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
414 /* these variables are for managing the stream of macroblock change bits */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
415 unsigned char *mb_change_bits = s->mb_change_bits;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
416 unsigned char mb_change_byte;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
417 unsigned char mb_change_byte_mask;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
418 int mb_change_index;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
419
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
420 /* these variables are for managing the main index stream */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
421 int index_stream_index = 0; /* yes, the index into the index stream */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
422 int index;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
423
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
424 /* clean out the line buffer */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
425 memset(s->vert_pred, 0, s->avctx->width * sizeof(unsigned short));
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
426
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
427 GET_NEXT_INDEX();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
428
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
429 for (y = 0; y < s->avctx->height; y++) {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
430
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
431 /* re-init variables for the next line iteration */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
432 horiz_pred = 0;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
433 current_pixel_pair = (unsigned int *)current_line;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
434 prev_pixel_pair = (unsigned int *)prev_line;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
435 vert_pred = s->vert_pred;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
436 mb_change_index = 0;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
437 mb_change_byte = mb_change_bits[mb_change_index++];
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
438 mb_change_byte_mask = 0x01;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
439 pixels_left = s->avctx->width;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
440
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
441 while (pixels_left > 0) {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
442
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
443 if (keyframe || ((mb_change_byte & mb_change_byte_mask) == 0)) {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
444
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
445 switch (y & 3) {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
446 case 0:
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
447 /* if macroblock width is 2, apply C-Y-C-Y; else
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
448 * apply C-Y-Y */
1654
1c123e036890 this should make the decoder safe for big-endian platforms
melanson
parents: 1650
diff changeset
449 if (s->block_width == 2) {
1650
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
450 APPLY_C_PREDICTOR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
451 APPLY_Y_PREDICTOR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
452 OUTPUT_PIXEL_PAIR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
453 APPLY_C_PREDICTOR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
454 APPLY_Y_PREDICTOR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
455 OUTPUT_PIXEL_PAIR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
456 } else {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
457 APPLY_C_PREDICTOR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
458 APPLY_Y_PREDICTOR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
459 OUTPUT_PIXEL_PAIR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
460 APPLY_Y_PREDICTOR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
461 OUTPUT_PIXEL_PAIR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
462 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
463 break;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
464
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
465 case 1:
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
466 case 3:
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
467 /* always apply 2 Y predictors on these iterations */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
468 APPLY_Y_PREDICTOR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
469 OUTPUT_PIXEL_PAIR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
470 APPLY_Y_PREDICTOR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
471 OUTPUT_PIXEL_PAIR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
472 break;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
473
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
474 case 2:
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
475 /* this iteration might be C-Y-C-Y, Y-Y, or C-Y-Y
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
476 * depending on the macroblock type */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
477 if (s->block_type == BLOCK_2x2) {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
478 APPLY_C_PREDICTOR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
479 APPLY_Y_PREDICTOR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
480 OUTPUT_PIXEL_PAIR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
481 APPLY_C_PREDICTOR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
482 APPLY_Y_PREDICTOR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
483 OUTPUT_PIXEL_PAIR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
484 } else if (s->block_type == BLOCK_4x2) {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
485 APPLY_C_PREDICTOR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
486 APPLY_Y_PREDICTOR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
487 OUTPUT_PIXEL_PAIR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
488 APPLY_Y_PREDICTOR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
489 OUTPUT_PIXEL_PAIR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
490 } else {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
491 APPLY_Y_PREDICTOR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
492 OUTPUT_PIXEL_PAIR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
493 APPLY_Y_PREDICTOR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
494 OUTPUT_PIXEL_PAIR();
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
495 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
496 break;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
497 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
498
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
499 } else {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
500
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
501 /* skip (copy) four pixels, but reassign the horizontal
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
502 * predictor */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
503 *current_pixel_pair = *prev_pixel_pair++;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
504 *vert_pred++ = *current_pixel_pair++;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
505 *current_pixel_pair = *prev_pixel_pair++;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
506 horiz_pred = *current_pixel_pair - *vert_pred;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
507 *vert_pred++ = *current_pixel_pair++;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
508
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
509 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
510
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
511 if (!keyframe) {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
512 mb_change_byte_mask <<= 1;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
513
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
514 /* next byte */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
515 if (!mb_change_byte_mask) {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
516 mb_change_byte = mb_change_bits[mb_change_index++];
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
517 mb_change_byte_mask = 0x01;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
518 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
519 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
520
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
521 pixels_left -= 4;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
522 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
523
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
524 /* next change row */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
525 if (((y + 1) & 3) == 0)
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
526 mb_change_bits += s->mb_change_bits_row_size;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
527
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
528 current_line += s->frame.linesize[0];
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
529 prev_line += s->prev_frame.linesize[0];
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
530 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
531 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
532
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
533 static int truemotion1_decode_frame(AVCodecContext *avctx,
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
534 void *data, int *data_size,
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
535 uint8_t *buf, int buf_size)
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
536 {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
537 TrueMotion1Context *s = (TrueMotion1Context *)avctx->priv_data;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
538
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
539 s->buf = buf;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
540 s->size = buf_size;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
541
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
542 s->frame.reference = 1;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
543 if (avctx->get_buffer(avctx, &s->frame) < 0) {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
544 fprintf(stderr, "truemotion1: get_buffer() failed\n");
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
545 return -1;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
546 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
547
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
548 /* no supplementary picture */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
549 if (buf_size == 0)
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
550 return 0;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
551
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
552 *data_size = 0;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
553
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
554 if (truemotion1_decode_header(s) == -1)
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
555 return -1;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
556
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
557 /* check for a do-nothing frame and copy the previous frame */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
558 if (compression_types[s->compression].algorithm == ALGO_NOP)
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
559 {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
560 memcpy(s->frame.data[0], s->prev_frame.data[0],
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
561 s->frame.linesize[0] * s->avctx->height);
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
562 } else if (compression_types[s->compression].algorithm == ALGO_RGB24H) {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
563 printf (" 24-bit Duck TrueMotion decoding not yet implemented\n");
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
564 } else {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
565 truemotion1_decode_16bit(s);
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
566 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
567
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
568 if (s->prev_frame.data[0])
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
569 avctx->release_buffer(avctx, &s->prev_frame);
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
570
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
571 /* shuffle frames */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
572 s->prev_frame = s->frame;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
573
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
574 *data_size = sizeof(AVFrame);
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
575 *(AVFrame*)data = s->frame;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
576
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
577 /* report that the buffer was completely consumed */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
578 return buf_size;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
579 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
580
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
581 static int truemotion1_decode_end(AVCodecContext *avctx)
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
582 {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
583 TrueMotion1Context *s = (TrueMotion1Context *)avctx->priv_data;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
584
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
585 /* release the last frame */
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
586 if (s->prev_frame.data[0])
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
587 avctx->release_buffer(avctx, &s->prev_frame);
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
588
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
589 av_free(s->vert_pred);
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
590
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
591 return 0;
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
592 }
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
593
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
594 AVCodec truemotion1_decoder = {
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
595 "truemotion1",
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
596 CODEC_TYPE_VIDEO,
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
597 CODEC_ID_TRUEMOTION1,
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
598 sizeof(TrueMotion1Context),
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
599 truemotion1_decode_init,
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
600 NULL,
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
601 truemotion1_decode_end,
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
602 truemotion1_decode_frame,
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
603 CODEC_CAP_DR1,
bdade3baabfc initial support for Duck TrueMotion v1 (think of it as On2 VP1); only
melanson
parents:
diff changeset
604 };