Mercurial > libavcodec.hg
annotate qpeg.c @ 2973:bb0222145083 libavcodec
forgot
author | michael |
---|---|
date | Mon, 19 Dec 2005 03:08:08 +0000 |
parents | ef2149182f1c |
children | bfabfdf9ce55 |
rev | line source |
---|---|
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
1 /* |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
2 * QPEG codec |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
3 * Copyright (c) 2004 Konstantin Shishkov |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
4 * |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
5 * This library is free software; you can redistribute it and/or |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
6 * modify it under the terms of the GNU Lesser General Public |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
7 * License as published by the Free Software Foundation; either |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
8 * version 2 of the License, or (at your option) any later version. |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
9 * |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
10 * This library is distributed in the hope that it will be useful, |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
13 * Lesser General Public License for more details. |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
14 * |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
15 * You should have received a copy of the GNU Lesser General Public |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
16 * License along with this library; if not, write to the Free Software |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
18 * |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
19 */ |
2967 | 20 |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
21 /** |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
22 * @file qpeg.c |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
23 * QPEG codec. |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
24 */ |
2967 | 25 |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
26 #include "avcodec.h" |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
27 #include "mpegvideo.h" |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
28 |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
29 typedef struct QpegContext{ |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
30 AVCodecContext *avctx; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
31 AVFrame pic; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
32 uint8_t *refdata; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
33 } QpegContext; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
34 |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
35 static void qpeg_decode_intra(uint8_t *src, uint8_t *dst, int size, |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
36 int stride, int width, int height) |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
37 { |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
38 int i; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
39 int code; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
40 int c0, c1; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
41 int run, copy; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
42 int filled = 0; |
2823 | 43 int rows_to_go; |
2967 | 44 |
2823 | 45 rows_to_go = height; |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
46 height--; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
47 dst = dst + height * stride; |
2967 | 48 |
2823 | 49 while((size > 0) && (rows_to_go > 0)) { |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
50 code = *src++; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
51 size--; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
52 run = copy = 0; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
53 if(code == 0xFC) /* end-of-picture code */ |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
54 break; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
55 if(code >= 0xF8) { /* very long run */ |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
56 c0 = *src++; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
57 c1 = *src++; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
58 size -= 2; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
59 run = ((code & 0x7) << 16) + (c0 << 8) + c1 + 2; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
60 } else if (code >= 0xF0) { /* long run */ |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
61 c0 = *src++; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
62 size--; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
63 run = ((code & 0xF) << 8) + c0 + 2; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
64 } else if (code >= 0xE0) { /* short run */ |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
65 run = (code & 0x1F) + 2; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
66 } else if (code >= 0xC0) { /* very long copy */ |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
67 c0 = *src++; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
68 c1 = *src++; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
69 size -= 2; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
70 copy = ((code & 0x3F) << 16) + (c0 << 8) + c1 + 1; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
71 } else if (code >= 0x80) { /* long copy */ |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
72 c0 = *src++; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
73 size--; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
74 copy = ((code & 0x7F) << 8) + c0 + 1; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
75 } else { /* short copy */ |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
76 copy = code + 1; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
77 } |
2967 | 78 |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
79 /* perform actual run or copy */ |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
80 if(run) { |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
81 int p; |
2967 | 82 |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
83 p = *src++; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
84 size--; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
85 for(i = 0; i < run; i++) { |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
86 dst[filled++] = p; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
87 if (filled >= width) { |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
88 filled = 0; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
89 dst -= stride; |
2823 | 90 rows_to_go--; |
91 if(rows_to_go <= 0) | |
92 break; | |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
93 } |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
94 } |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
95 } else { |
2823 | 96 size -= copy; |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
97 for(i = 0; i < copy; i++) { |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
98 dst[filled++] = *src++; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
99 if (filled >= width) { |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
100 filled = 0; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
101 dst -= stride; |
2823 | 102 rows_to_go--; |
103 if(rows_to_go <= 0) | |
104 break; | |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
105 } |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
106 } |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
107 } |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
108 } |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
109 } |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
110 |
2967 | 111 static int qpeg_table_h[16] = |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
112 { 0x00, 0x20, 0x20, 0x20, 0x18, 0x10, 0x10, 0x20, 0x10, 0x08, 0x18, 0x08, 0x08, 0x18, 0x10, 0x04}; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
113 static int qpeg_table_w[16] = |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
114 { 0x00, 0x20, 0x18, 0x08, 0x18, 0x10, 0x20, 0x10, 0x08, 0x10, 0x20, 0x20, 0x08, 0x10, 0x18, 0x04}; |
2967 | 115 |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
116 /* Decodes delta frames */ |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
117 static void qpeg_decode_inter(uint8_t *src, uint8_t *dst, int size, |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
118 int stride, int width, int height, |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
119 int delta, uint8_t *ctable, uint8_t *refdata) |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
120 { |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
121 int i, j; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
122 int code; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
123 int filled = 0; |
2823 | 124 int orig_height; |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
125 uint8_t *blkdata; |
2967 | 126 |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
127 /* copy prev frame */ |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
128 for(i = 0; i < height; i++) |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
129 memcpy(refdata + (i * width), dst + (i * stride), width); |
2967 | 130 |
2823 | 131 orig_height = height; |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
132 blkdata = src - 0x86; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
133 height--; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
134 dst = dst + height * stride; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
135 |
2823 | 136 while((size > 0) && (height >= 0)) { |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
137 code = *src++; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
138 size--; |
2967 | 139 |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
140 if(delta) { |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
141 /* motion compensation */ |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
142 while((code & 0xF0) == 0xF0) { |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
143 if(delta == 1) { |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
144 int me_idx; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
145 int me_w, me_h, me_x, me_y; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
146 uint8_t *me_plane; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
147 int corr, val; |
2967 | 148 |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
149 /* get block size by index */ |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
150 me_idx = code & 0xF; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
151 me_w = qpeg_table_w[me_idx]; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
152 me_h = qpeg_table_h[me_idx]; |
2967 | 153 |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
154 /* extract motion vector */ |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
155 corr = *src++; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
156 size--; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
157 |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
158 val = corr >> 4; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
159 if(val > 7) |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
160 val -= 16; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
161 me_x = val; |
2967 | 162 |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
163 val = corr & 0xF; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
164 if(val > 7) |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
165 val -= 16; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
166 me_y = val; |
2967 | 167 |
2823 | 168 /* check motion vector */ |
169 if ((me_x + filled < 0) || (me_x + me_w + filled > width) || | |
170 (height - me_y - me_h < 0) || (height - me_y > orig_height) || | |
171 (filled + me_w > width) || (height - me_h < 0)) | |
172 av_log(NULL, AV_LOG_ERROR, "Bogus motion vector (%i,%i), block size %ix%i at %i,%i\n", | |
173 me_x, me_y, me_w, me_h, filled, height); | |
174 else { | |
175 /* do motion compensation */ | |
176 me_plane = refdata + (filled + me_x) + (height - me_y) * width; | |
177 for(j = 0; j < me_h; j++) { | |
178 for(i = 0; i < me_w; i++) | |
179 dst[filled + i - (j * stride)] = me_plane[i - (j * width)]; | |
180 } | |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
181 } |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
182 } |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
183 code = *src++; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
184 size--; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
185 } |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
186 } |
2967 | 187 |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
188 if(code == 0xE0) /* end-of-picture code */ |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
189 break; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
190 if(code > 0xE0) { /* run code: 0xE1..0xFF */ |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
191 int p; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
192 |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
193 code &= 0x1F; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
194 p = *src++; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
195 size--; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
196 for(i = 0; i <= code; i++) { |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
197 dst[filled++] = p; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
198 if(filled >= width) { |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
199 filled = 0; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
200 dst -= stride; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
201 height--; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
202 } |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
203 } |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
204 } else if(code >= 0xC0) { /* copy code: 0xC0..0xDF */ |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
205 code &= 0x1F; |
2967 | 206 |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
207 for(i = 0; i <= code; i++) { |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
208 dst[filled++] = *src++; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
209 if(filled >= width) { |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
210 filled = 0; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
211 dst -= stride; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
212 height--; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
213 } |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
214 } |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
215 size -= code + 1; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
216 } else if(code >= 0x80) { /* skip code: 0x80..0xBF */ |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
217 int skip; |
2967 | 218 |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
219 code &= 0x3F; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
220 /* codes 0x80 and 0x81 are actually escape codes, |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
221 skip value minus constant is in the next byte */ |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
222 if(!code) |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
223 skip = (*src++) + 64; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
224 else if(code == 1) |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
225 skip = (*src++) + 320; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
226 else |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
227 skip = code; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
228 filled += skip; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
229 while( filled >= width) { |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
230 filled -= width; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
231 dst -= stride; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
232 height--; |
2823 | 233 if(height < 0) |
234 break; | |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
235 } |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
236 } else { |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
237 /* zero code treated as one-pixel skip */ |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
238 if(code) |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
239 dst[filled++] = ctable[code & 0x7F]; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
240 else |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
241 filled++; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
242 if(filled >= width) { |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
243 filled = 0; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
244 dst -= stride; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
245 height--; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
246 } |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
247 } |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
248 } |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
249 } |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
250 |
2967 | 251 static int decode_frame(AVCodecContext *avctx, |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
252 void *data, int *data_size, |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
253 uint8_t *buf, int buf_size) |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
254 { |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
255 QpegContext * const a = avctx->priv_data; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
256 AVFrame * const p= (AVFrame*)&a->pic; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
257 uint8_t* outdata; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
258 int delta; |
2967 | 259 |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
260 if(p->data[0]) |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
261 avctx->release_buffer(avctx, p); |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
262 |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
263 p->reference= 0; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
264 if(avctx->get_buffer(avctx, p) < 0){ |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
265 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
266 return -1; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
267 } |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
268 outdata = a->pic.data[0]; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
269 if(buf[0x85] == 0x10) { |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
270 qpeg_decode_intra(buf+0x86, outdata, buf_size - 0x86, a->pic.linesize[0], avctx->width, avctx->height); |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
271 } else { |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
272 delta = buf[0x85]; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
273 qpeg_decode_inter(buf+0x86, outdata, buf_size - 0x86, a->pic.linesize[0], avctx->width, avctx->height, delta, buf + 4, a->refdata); |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
274 } |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
275 |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
276 /* make the palette available on the way out */ |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
277 memcpy(a->pic.data[1], a->avctx->palctrl->palette, AVPALETTE_SIZE); |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
278 if (a->avctx->palctrl->palette_changed) { |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
279 a->pic.palette_has_changed = 1; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
280 a->avctx->palctrl->palette_changed = 0; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
281 } |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
282 |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
283 *data_size = sizeof(AVFrame); |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
284 *(AVFrame*)data = a->pic; |
2967 | 285 |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
286 return buf_size; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
287 } |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
288 |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
289 static int decode_init(AVCodecContext *avctx){ |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
290 QpegContext * const a = avctx->priv_data; |
2967 | 291 |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
292 a->avctx = avctx; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
293 avctx->pix_fmt= PIX_FMT_PAL8; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
294 avctx->has_b_frames = 0; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
295 a->pic.data[0] = NULL; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
296 a->refdata = av_malloc(avctx->width * avctx->height); |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
297 |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
298 return 0; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
299 } |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
300 |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
301 static int decode_end(AVCodecContext *avctx){ |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
302 QpegContext * const a = avctx->priv_data; |
2586 | 303 AVFrame * const p= (AVFrame*)&a->pic; |
2967 | 304 |
2586 | 305 if(p->data[0]) |
306 avctx->release_buffer(avctx, p); | |
2355
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
307 |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
308 av_free(a->refdata); |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
309 return 0; |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
310 } |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
311 |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
312 AVCodec qpeg_decoder = { |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
313 "qpeg", |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
314 CODEC_TYPE_VIDEO, |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
315 CODEC_ID_QPEG, |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
316 sizeof(QpegContext), |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
317 decode_init, |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
318 NULL, |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
319 decode_end, |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
320 decode_frame, |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
321 CODEC_CAP_DR1, |
69fcdad5f7d5
native QPEG video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
322 }; |