annotate zmbv.c @ 12530:63edd10ad4bc libavcodec tip

Try to fix crashes introduced by r25218 r25218 made assumptions about the existence of past reference frames that weren't necessarily true.
author darkshikari
date Tue, 28 Sep 2010 09:06:22 +0000
parents 3c5a6cc5a652
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
1 /*
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
2 * Zip Motion Blocks Video (ZMBV) decoder
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
3 * Copyright (c) 2006 Konstantin Shishkov
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
4 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3800
diff changeset
5 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3800
diff changeset
6 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3800
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3800
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
11 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3800
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
15 * Lesser General Public License for more details.
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
16 *
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3800
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
20 */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
21
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
22 /**
11644
7dd2a45249a9 Remove explicit filename from Doxygen @file commands.
diego
parents: 11584
diff changeset
23 * @file
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
24 * Zip Motion Blocks Video decoder
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
25 */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
26
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
27 #include <stdio.h>
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
28 #include <stdlib.h>
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
29
8573
2acf0ae7b041 Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents: 7823
diff changeset
30 #include "libavutil/intreadwrite.h"
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
31 #include "avcodec.h"
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
32
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
33 #include <zlib.h>
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
34
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
35 #define ZMBV_KEYFRAME 1
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
36 #define ZMBV_DELTAPAL 2
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
37
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
38 enum ZmbvFormat {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
39 ZMBV_FMT_NONE = 0,
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
40 ZMBV_FMT_1BPP = 1,
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
41 ZMBV_FMT_2BPP = 2,
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
42 ZMBV_FMT_4BPP = 3,
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
43 ZMBV_FMT_8BPP = 4,
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
44 ZMBV_FMT_15BPP = 5,
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
45 ZMBV_FMT_16BPP = 6,
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
46 ZMBV_FMT_24BPP = 7,
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
47 ZMBV_FMT_32BPP = 8
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
48 };
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
49
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
50 /*
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
51 * Decoder context
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
52 */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
53 typedef struct ZmbvContext {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
54 AVCodecContext *avctx;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
55 AVFrame pic;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
56
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
57 int bpp;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
58 unsigned int decomp_size;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
59 uint8_t* decomp_buf;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
60 uint8_t pal[768];
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
61 uint8_t *prev, *cur;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
62 int width, height;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
63 int fmt;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
64 int comp;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
65 int flags;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
66 int bw, bh, bx, by;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
67 int decomp_len;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
68 z_stream zstream;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
69 int (*decode_intra)(struct ZmbvContext *c);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
70 int (*decode_xor)(struct ZmbvContext *c);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
71 } ZmbvContext;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
72
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
73 /**
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
74 * Decode XOR'ed frame - 8bpp version
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
75 */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
76
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
77 static int zmbv_decode_xor_8(ZmbvContext *c)
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
78 {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
79 uint8_t *src = c->decomp_buf;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
80 uint8_t *output, *prev;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
81 int8_t *mvec;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
82 int x, y;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
83 int d, dx, dy, bw2, bh2;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
84 int block;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
85 int i, j;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
86 int mx, my;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
87
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
88 output = c->cur;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
89 prev = c->prev;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
90
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
91 if(c->flags & ZMBV_DELTAPAL){
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
92 for(i = 0; i < 768; i++)
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
93 c->pal[i] ^= *src++;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
94 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
95
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
96 mvec = (int8_t*)src;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
97 src += ((c->bx * c->by * 2 + 3) & ~3);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
98
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
99 block = 0;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
100 for(y = 0; y < c->height; y += c->bh) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
101 bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
102 for(x = 0; x < c->width; x += c->bw) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
103 uint8_t *out, *tprev;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
104
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
105 d = mvec[block] & 1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
106 dx = mvec[block] >> 1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
107 dy = mvec[block + 1] >> 1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
108 block += 2;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
109
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
110 bw2 = ((c->width - x) > c->bw) ? c->bw : (c->width - x);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
111
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
112 /* copy block - motion vectors out of bounds are used to zero blocks */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
113 out = output + x;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
114 tprev = prev + x + dx + dy * c->width;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
115 mx = x + dx;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
116 my = y + dy;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
117 for(j = 0; j < bh2; j++){
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
118 if((my + j < 0) || (my + j >= c->height)) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
119 memset(out, 0, bw2);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
120 } else {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
121 for(i = 0; i < bw2; i++){
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
122 if((mx + i < 0) || (mx + i >= c->width))
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
123 out[i] = 0;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
124 else
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
125 out[i] = tprev[i];
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
126 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
127 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
128 out += c->width;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
129 tprev += c->width;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
130 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
131
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
132 if(d) { /* apply XOR'ed difference */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
133 out = output + x;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
134 for(j = 0; j < bh2; j++){
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
135 for(i = 0; i < bw2; i++)
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
136 out[i] ^= *src++;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
137 out += c->width;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
138 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
139 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
140 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
141 output += c->width * c->bh;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
142 prev += c->width * c->bh;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
143 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
144 if(src - c->decomp_buf != c->decomp_len)
5153
b985439e3e15 fix some printf format specifiers
mru
parents: 5089
diff changeset
145 av_log(c->avctx, AV_LOG_ERROR, "Used %ti of %i bytes\n", src-c->decomp_buf, c->decomp_len);
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
146 return 0;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
147 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
148
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
149 /**
3134
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
150 * Decode XOR'ed frame - 15bpp and 16bpp version
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
151 */
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
152
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
153 static int zmbv_decode_xor_16(ZmbvContext *c)
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
154 {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
155 uint8_t *src = c->decomp_buf;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
156 uint16_t *output, *prev;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
157 int8_t *mvec;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
158 int x, y;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
159 int d, dx, dy, bw2, bh2;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
160 int block;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
161 int i, j;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
162 int mx, my;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
163
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
164 output = (uint16_t*)c->cur;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
165 prev = (uint16_t*)c->prev;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
166
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
167 mvec = (int8_t*)src;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
168 src += ((c->bx * c->by * 2 + 3) & ~3);
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
169
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
170 block = 0;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
171 for(y = 0; y < c->height; y += c->bh) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
172 bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y);
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
173 for(x = 0; x < c->width; x += c->bw) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
174 uint16_t *out, *tprev;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
175
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
176 d = mvec[block] & 1;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
177 dx = mvec[block] >> 1;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
178 dy = mvec[block + 1] >> 1;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
179 block += 2;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
180
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
181 bw2 = ((c->width - x) > c->bw) ? c->bw : (c->width - x);
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
182
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
183 /* copy block - motion vectors out of bounds are used to zero blocks */
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
184 out = output + x;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
185 tprev = prev + x + dx + dy * c->width;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
186 mx = x + dx;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
187 my = y + dy;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
188 for(j = 0; j < bh2; j++){
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
189 if((my + j < 0) || (my + j >= c->height)) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
190 memset(out, 0, bw2 * 2);
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
191 } else {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
192 for(i = 0; i < bw2; i++){
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
193 if((mx + i < 0) || (mx + i >= c->width))
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
194 out[i] = 0;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
195 else
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
196 out[i] = tprev[i];
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
197 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
198 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
199 out += c->width;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
200 tprev += c->width;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
201 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
202
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
203 if(d) { /* apply XOR'ed difference */
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
204 out = output + x;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
205 for(j = 0; j < bh2; j++){
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
206 for(i = 0; i < bw2; i++) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
207 out[i] ^= *((uint16_t*)src);
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
208 src += 2;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
209 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
210 out += c->width;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
211 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
212 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
213 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
214 output += c->width * c->bh;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
215 prev += c->width * c->bh;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
216 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
217 if(src - c->decomp_buf != c->decomp_len)
5153
b985439e3e15 fix some printf format specifiers
mru
parents: 5089
diff changeset
218 av_log(c->avctx, AV_LOG_ERROR, "Used %ti of %i bytes\n", src-c->decomp_buf, c->decomp_len);
3134
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
219 return 0;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
220 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
221
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
222 #ifdef ZMBV_ENABLE_24BPP
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
223 /**
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
224 * Decode XOR'ed frame - 24bpp version
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
225 */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
226
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
227 static int zmbv_decode_xor_24(ZmbvContext *c)
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
228 {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
229 uint8_t *src = c->decomp_buf;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
230 uint8_t *output, *prev;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
231 int8_t *mvec;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
232 int x, y;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
233 int d, dx, dy, bw2, bh2;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
234 int block;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
235 int i, j;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
236 int mx, my;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
237 int stride;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
238
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
239 output = c->cur;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
240 prev = c->prev;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
241
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
242 stride = c->width * 3;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
243 mvec = (int8_t*)src;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
244 src += ((c->bx * c->by * 2 + 3) & ~3);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
245
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
246 block = 0;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
247 for(y = 0; y < c->height; y += c->bh) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
248 bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
249 for(x = 0; x < c->width; x += c->bw) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
250 uint8_t *out, *tprev;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
251
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
252 d = mvec[block] & 1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
253 dx = mvec[block] >> 1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
254 dy = mvec[block + 1] >> 1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
255 block += 2;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
256
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
257 bw2 = ((c->width - x) > c->bw) ? c->bw : (c->width - x);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
258
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
259 /* copy block - motion vectors out of bounds are used to zero blocks */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
260 out = output + x * 3;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
261 tprev = prev + (x + dx) * 3 + dy * stride;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
262 mx = x + dx;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
263 my = y + dy;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
264 for(j = 0; j < bh2; j++){
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
265 if((my + j < 0) || (my + j >= c->height)) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
266 memset(out, 0, bw2 * 3);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
267 } else {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
268 for(i = 0; i < bw2; i++){
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
269 if((mx + i < 0) || (mx + i >= c->width)) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
270 out[i * 3 + 0] = 0;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
271 out[i * 3 + 1] = 0;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
272 out[i * 3 + 2] = 0;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
273 } else {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
274 out[i * 3 + 0] = tprev[i * 3 + 0];
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
275 out[i * 3 + 1] = tprev[i * 3 + 1];
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
276 out[i * 3 + 2] = tprev[i * 3 + 2];
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
277 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
278 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
279 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
280 out += stride;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
281 tprev += stride;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
282 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
283
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
284 if(d) { /* apply XOR'ed difference */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
285 out = output + x * 3;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
286 for(j = 0; j < bh2; j++){
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
287 for(i = 0; i < bw2; i++) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
288 out[i * 3 + 0] ^= *src++;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
289 out[i * 3 + 1] ^= *src++;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
290 out[i * 3 + 2] ^= *src++;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
291 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
292 out += stride;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
293 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
294 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
295 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
296 output += stride * c->bh;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
297 prev += stride * c->bh;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
298 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
299 if(src - c->decomp_buf != c->decomp_len)
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
300 av_log(c->avctx, AV_LOG_ERROR, "Used %i of %i bytes\n", src-c->decomp_buf, c->decomp_len);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
301 return 0;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
302 }
3134
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
303 #endif //ZMBV_ENABLE_24BPP
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
304
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
305 /**
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
306 * Decode XOR'ed frame - 32bpp version
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
307 */
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
308
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
309 static int zmbv_decode_xor_32(ZmbvContext *c)
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
310 {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
311 uint8_t *src = c->decomp_buf;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
312 uint32_t *output, *prev;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
313 int8_t *mvec;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
314 int x, y;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
315 int d, dx, dy, bw2, bh2;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
316 int block;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
317 int i, j;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
318 int mx, my;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
319
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
320 output = (uint32_t*)c->cur;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
321 prev = (uint32_t*)c->prev;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
322
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
323 mvec = (int8_t*)src;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
324 src += ((c->bx * c->by * 2 + 3) & ~3);
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
325
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
326 block = 0;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
327 for(y = 0; y < c->height; y += c->bh) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
328 bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y);
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
329 for(x = 0; x < c->width; x += c->bw) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
330 uint32_t *out, *tprev;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
331
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
332 d = mvec[block] & 1;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
333 dx = mvec[block] >> 1;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
334 dy = mvec[block + 1] >> 1;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
335 block += 2;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
336
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
337 bw2 = ((c->width - x) > c->bw) ? c->bw : (c->width - x);
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
338
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
339 /* copy block - motion vectors out of bounds are used to zero blocks */
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
340 out = output + x;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
341 tprev = prev + x + dx + dy * c->width;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
342 mx = x + dx;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
343 my = y + dy;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
344 for(j = 0; j < bh2; j++){
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
345 if((my + j < 0) || (my + j >= c->height)) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
346 memset(out, 0, bw2 * 4);
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
347 } else {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
348 for(i = 0; i < bw2; i++){
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
349 if((mx + i < 0) || (mx + i >= c->width))
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
350 out[i] = 0;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
351 else
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
352 out[i] = tprev[i];
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
353 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
354 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
355 out += c->width;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
356 tprev += c->width;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
357 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
358
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
359 if(d) { /* apply XOR'ed difference */
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
360 out = output + x;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
361 for(j = 0; j < bh2; j++){
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
362 for(i = 0; i < bw2; i++) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
363 out[i] ^= *((uint32_t*)src);
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
364 src += 4;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
365 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
366 out += c->width;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
367 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
368 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
369 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
370 output += c->width * c->bh;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
371 prev += c->width * c->bh;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
372 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
373 if(src - c->decomp_buf != c->decomp_len)
5153
b985439e3e15 fix some printf format specifiers
mru
parents: 5089
diff changeset
374 av_log(c->avctx, AV_LOG_ERROR, "Used %ti of %i bytes\n", src-c->decomp_buf, c->decomp_len);
3134
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
375 return 0;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
376 }
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
377
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
378 /**
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
379 * Decode intraframe
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
380 */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
381 static int zmbv_decode_intra(ZmbvContext *c)
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
382 {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
383 uint8_t *src = c->decomp_buf;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
384
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
385 /* make the palette available on the way out */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
386 if (c->fmt == ZMBV_FMT_8BPP) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
387 memcpy(c->pal, src, 768);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
388 src += 768;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
389 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
390
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
391 memcpy(c->cur, src, c->width * c->height * (c->bpp / 8));
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
392 return 0;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
393 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
394
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
395 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
396 {
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
397 const uint8_t *buf = avpkt->data;
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
398 int buf_size = avpkt->size;
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4740
diff changeset
399 ZmbvContext * const c = avctx->priv_data;
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
400 int zret = Z_OK; // Zlib return code
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
401 int len = buf_size;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
402 int hi_ver, lo_ver;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
403
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
404 if(c->pic.data[0])
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
405 avctx->release_buffer(avctx, &c->pic);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
406
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
407 c->pic.reference = 1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
408 c->pic.buffer_hints = FF_BUFFER_HINTS_VALID;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
409 if(avctx->get_buffer(avctx, &c->pic) < 0){
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
410 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
411 return -1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
412 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
413
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
414 /* parse header */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
415 c->flags = buf[0];
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
416 buf++; len--;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
417 if(c->flags & ZMBV_KEYFRAME) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
418 hi_ver = buf[0];
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
419 lo_ver = buf[1];
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
420 c->comp = buf[2];
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
421 c->fmt = buf[3];
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
422 c->bw = buf[4];
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
423 c->bh = buf[5];
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
424
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
425 buf += 6;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
426 len -= 6;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
427 av_log(avctx, AV_LOG_DEBUG, "Flags=%X ver=%i.%i comp=%i fmt=%i blk=%ix%i\n",c->flags,hi_ver,lo_ver,c->comp,c->fmt,c->bw,c->bh);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
428 if(hi_ver != 0 || lo_ver != 1) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
429 av_log(avctx, AV_LOG_ERROR, "Unsupported version %i.%i\n", hi_ver, lo_ver);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
430 return -1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
431 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
432 if(c->bw == 0 || c->bh == 0) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
433 av_log(avctx, AV_LOG_ERROR, "Unsupported block size %ix%i\n", c->bw, c->bh);
11584
3309ebc37b11 Avoid division by zero
siretart
parents: 11560
diff changeset
434 return -1;
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
435 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
436 if(c->comp != 0 && c->comp != 1) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
437 av_log(avctx, AV_LOG_ERROR, "Unsupported compression type %i\n", c->comp);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
438 return -1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
439 }
3134
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
440
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
441 switch(c->fmt) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
442 case ZMBV_FMT_8BPP:
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
443 c->bpp = 8;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
444 c->decode_intra = zmbv_decode_intra;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
445 c->decode_xor = zmbv_decode_xor_8;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
446 break;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
447 case ZMBV_FMT_15BPP:
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
448 case ZMBV_FMT_16BPP:
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
449 c->bpp = 16;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
450 c->decode_intra = zmbv_decode_intra;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
451 c->decode_xor = zmbv_decode_xor_16;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
452 break;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
453 #ifdef ZMBV_ENABLE_24BPP
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
454 case ZMBV_FMT_24BPP:
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
455 c->bpp = 24;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
456 c->decode_intra = zmbv_decode_intra;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
457 c->decode_xor = zmbv_decode_xor_24;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
458 break;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
459 #endif //ZMBV_ENABLE_24BPP
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
460 case ZMBV_FMT_32BPP:
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
461 c->bpp = 32;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
462 c->decode_intra = zmbv_decode_intra;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
463 c->decode_xor = zmbv_decode_xor_32;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
464 break;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
465 default:
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
466 c->decode_intra = NULL;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
467 c->decode_xor = NULL;
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
468 av_log(avctx, AV_LOG_ERROR, "Unsupported (for now) format %i\n", c->fmt);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
469 return -1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
470 }
5349
6a4286208743 remove useless #ifdef CONFIG_ZLIB from zmbv decoder
mru
parents: 5258
diff changeset
471
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
472 zret = inflateReset(&c->zstream);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
473 if (zret != Z_OK) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
474 av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
475 return -1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
476 }
5349
6a4286208743 remove useless #ifdef CONFIG_ZLIB from zmbv decoder
mru
parents: 5258
diff changeset
477
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
478 c->cur = av_realloc(c->cur, avctx->width * avctx->height * (c->bpp / 8));
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
479 c->prev = av_realloc(c->prev, avctx->width * avctx->height * (c->bpp / 8));
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
480 c->bx = (c->width + c->bw - 1) / c->bw;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
481 c->by = (c->height+ c->bh - 1) / c->bh;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
482 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
483
3134
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
484 if(c->decode_intra == NULL) {
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
485 av_log(avctx, AV_LOG_ERROR, "Error! Got no format or no keyframe!\n");
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
486 return -1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
487 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
488
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
489 if(c->comp == 0) { //Uncompressed data
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
490 memcpy(c->decomp_buf, buf, len);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
491 c->decomp_size = 1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
492 } else { // ZLIB-compressed data
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
493 c->zstream.total_in = c->zstream.total_out = 0;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
494 c->zstream.next_in = buf;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
495 c->zstream.avail_in = len;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
496 c->zstream.next_out = c->decomp_buf;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
497 c->zstream.avail_out = c->decomp_size;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
498 inflate(&c->zstream, Z_FINISH);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
499 c->decomp_len = c->zstream.total_out;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
500 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
501 if(c->flags & ZMBV_KEYFRAME) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
502 c->pic.key_frame = 1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
503 c->pic.pict_type = FF_I_TYPE;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
504 c->decode_intra(c);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
505 } else {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
506 c->pic.key_frame = 0;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
507 c->pic.pict_type = FF_P_TYPE;
6478
9818b6840614 Correctly handle empty frames
kostya
parents: 6301
diff changeset
508 if(c->decomp_len)
6479
863a6c0ff6ad indentation
kostya
parents: 6478
diff changeset
509 c->decode_xor(c);
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
510 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
511
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
512 /* update frames */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
513 {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
514 uint8_t *out, *src;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
515 int i, j;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
516
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
517 out = c->pic.data[0];
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
518 src = c->cur;
3134
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
519 switch(c->fmt) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
520 case ZMBV_FMT_8BPP:
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
521 for(j = 0; j < c->height; j++) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
522 for(i = 0; i < c->width; i++) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
523 out[i * 3 + 0] = c->pal[(*src) * 3 + 0];
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
524 out[i * 3 + 1] = c->pal[(*src) * 3 + 1];
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
525 out[i * 3 + 2] = c->pal[(*src) * 3 + 2];
5258
4372aeade5dc trivial warning fixes
mru
parents: 5215
diff changeset
526 src++;
3134
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
527 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
528 out += c->pic.linesize[0];
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
529 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
530 break;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
531 case ZMBV_FMT_15BPP:
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
532 for(j = 0; j < c->height; j++) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
533 for(i = 0; i < c->width; i++) {
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 3947
diff changeset
534 uint16_t tmp = AV_RL16(src);
3134
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
535 src += 2;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
536 out[i * 3 + 0] = (tmp & 0x7C00) >> 7;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
537 out[i * 3 + 1] = (tmp & 0x03E0) >> 2;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
538 out[i * 3 + 2] = (tmp & 0x001F) << 3;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
539 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
540 out += c->pic.linesize[0];
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
541 }
3134
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
542 break;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
543 case ZMBV_FMT_16BPP:
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
544 for(j = 0; j < c->height; j++) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
545 for(i = 0; i < c->width; i++) {
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 3947
diff changeset
546 uint16_t tmp = AV_RL16(src);
3134
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
547 src += 2;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
548 out[i * 3 + 0] = (tmp & 0xF800) >> 8;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
549 out[i * 3 + 1] = (tmp & 0x07E0) >> 3;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
550 out[i * 3 + 2] = (tmp & 0x001F) << 3;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
551 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
552 out += c->pic.linesize[0];
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
553 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
554 break;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
555 #ifdef ZMBV_ENABLE_24BPP
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
556 case ZMBV_FMT_24BPP:
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
557 for(j = 0; j < c->height; j++) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
558 memcpy(out, src, c->width * 3);
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
559 src += c->width * 3;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
560 out += c->pic.linesize[0];
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
561 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
562 break;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
563 #endif //ZMBV_ENABLE_24BPP
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
564 case ZMBV_FMT_32BPP:
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
565 for(j = 0; j < c->height; j++) {
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
566 for(i = 0; i < c->width; i++) {
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 3947
diff changeset
567 uint32_t tmp = AV_RL32(src);
3134
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
568 src += 4;
5089
bff60ecc02f9 Use AV_xx throughout libavcodec
ramiro
parents: 4962
diff changeset
569 AV_WB24(out+(i*3), tmp);
3134
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
570 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
571 out += c->pic.linesize[0];
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
572 }
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
573 break;
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
574 default:
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
575 av_log(avctx, AV_LOG_ERROR, "Cannot handle format %i\n", c->fmt);
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
576 }
3134
03af25454cc3 ZMBV 15-/16-/32-bit decoding. 24-bit mode is disabled because it's not
diego
parents: 3122
diff changeset
577 memcpy(c->prev, c->cur, c->width * c->height * (c->bpp / 8));
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
578 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
579 *data_size = sizeof(AVFrame);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
580 *(AVFrame*)data = c->pic;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
581
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
582 /* always report that the buffer was completely consumed */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
583 return buf_size;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
584 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
585
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
586
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
587
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
588 /*
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
589 *
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
590 * Init zmbv decoder
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
591 *
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
592 */
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6479
diff changeset
593 static av_cold int decode_init(AVCodecContext *avctx)
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
594 {
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4740
diff changeset
595 ZmbvContext * const c = avctx->priv_data;
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
596 int zret; // Zlib return code
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
597
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
598 c->avctx = avctx;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
599
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
600 c->width = avctx->width;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
601 c->height = avctx->height;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
602
7823
4525dcd81357 Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 7040
diff changeset
603 c->bpp = avctx->bits_per_coded_sample;
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
604
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
605 // Needed if zlib unused or init aborted before inflateInit
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
606 memset(&(c->zstream), 0, sizeof(z_stream));
5349
6a4286208743 remove useless #ifdef CONFIG_ZLIB from zmbv decoder
mru
parents: 5258
diff changeset
607
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
608 avctx->pix_fmt = PIX_FMT_RGB24;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
609 c->decomp_size = (avctx->width + 255) * 4 * (avctx->height + 64);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
610
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
611 /* Allocate decompression buffer */
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
612 if (c->decomp_size) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
613 if ((c->decomp_buf = av_malloc(c->decomp_size)) == NULL) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
614 av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
615 return 1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
616 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
617 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
618
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
619 c->zstream.zalloc = Z_NULL;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
620 c->zstream.zfree = Z_NULL;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
621 c->zstream.opaque = Z_NULL;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
622 zret = inflateInit(&(c->zstream));
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
623 if (zret != Z_OK) {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
624 av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
625 return 1;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
626 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
627
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
628 return 0;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
629 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
630
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
631
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
632
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
633 /*
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
634 *
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
635 * Uninit zmbv decoder
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
636 *
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
637 */
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6479
diff changeset
638 static av_cold int decode_end(AVCodecContext *avctx)
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
639 {
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4740
diff changeset
640 ZmbvContext * const c = avctx->priv_data;
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
641
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
642 av_freep(&c->decomp_buf);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
643
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
644 if (c->pic.data[0])
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
645 avctx->release_buffer(avctx, &c->pic);
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
646 inflateEnd(&(c->zstream));
3694
8765ee4eaa45 Drop unneeded checks before av_free() and change to av_freep() where it's more suitable.
kostya
parents: 3134
diff changeset
647 av_freep(&c->cur);
8765ee4eaa45 Drop unneeded checks before av_free() and change to av_freep() where it's more suitable.
kostya
parents: 3134
diff changeset
648 av_freep(&c->prev);
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
649
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
650 return 0;
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
651 }
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
652
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
653 AVCodec zmbv_decoder = {
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
654 "zmbv",
11560
8a4984c5cacc Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 10397
diff changeset
655 AVMEDIA_TYPE_VIDEO,
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
656 CODEC_ID_ZMBV,
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
657 sizeof(ZmbvContext),
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
658 decode_init,
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
659 NULL,
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
660 decode_end,
6713
f282270c589f Add long names to some AVCodec declarations.
diego
parents: 6517
diff changeset
661 decode_frame,
9816
e19113273403 zmbv decoder uses get_buffer, set CODEC_CAP_DR1
bcoudurier
parents: 9553
diff changeset
662 CODEC_CAP_DR1,
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6713
diff changeset
663 .long_name = NULL_IF_CONFIG_SMALL("Zip Motion Blocks Video"),
3120
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
664 };
1d184d61e714 dosbox native ZMBV decoder, courtesy of Kostya
melanson
parents:
diff changeset
665