annotate vmnc.c @ 4066:a3f06c7a0bff libavcodec

16-bit grayscale support
author kostya
date Tue, 24 Oct 2006 04:57:43 +0000
parents c8c591fe26f8
children d6f83e2f8804
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
1 /*
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
2 * VMware Screen Codec (VMnc) decoder
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
3 * Copyright (c) 2006 Konstantin Shishkov
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
4 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3920
diff changeset
5 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3920
diff changeset
6 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3920
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
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: 3920
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
11 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3920
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
15 * Lesser General Public License for more details.
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
16 *
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
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: 3920
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
20 *
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
21 */
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
22
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
23 /**
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
24 * @file vmnc.c
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
25 * VMware Screen Codec (VMnc) decoder
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
26 * As Alex Beregszaszi discovered, this is effectively RFB data dump
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
27 */
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
28
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
29 #include <stdio.h>
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
30 #include <stdlib.h>
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
31
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
32 #include "common.h"
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
33 #include "avcodec.h"
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
34
3679
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
35 enum EncTypes {
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
36 MAGIC_WMVd = 0x574D5664,
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
37 MAGIC_WMVe,
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
38 MAGIC_WMVf,
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
39 MAGIC_WMVg,
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
40 MAGIC_WMVh,
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
41 MAGIC_WMVi,
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
42 MAGIC_WMVj
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
43 };
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
44
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
45 enum HexTile_Flags {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
46 HT_RAW = 1, // tile is raw
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
47 HT_BKG = 2, // background color is present
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
48 HT_FG = 4, // foreground color is present
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
49 HT_SUB = 8, // subrects are present
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
50 HT_CLR = 16 // each subrect has own color
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
51 };
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
52
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
53 /*
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
54 * Decoder context
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
55 */
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
56 typedef struct VmncContext {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
57 AVCodecContext *avctx;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
58 AVFrame pic;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
59
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
60 int bpp;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
61 int bpp2;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
62 int bigendian;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
63 uint8_t pal[768];
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
64 int width, height;
3684
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
65
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
66 /* cursor data */
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
67 int cur_w, cur_h;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
68 int cur_x, cur_y;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
69 int cur_hx, cur_hy;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
70 uint8_t* curbits, *curmask;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
71 uint8_t* screendta;
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
72 } VmncContext;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
73
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
74 /* read pixel value from stream */
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
75 static always_inline int vmnc_get_pixel(uint8_t* buf, int bpp, int be) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
76 switch(bpp * 2 + be) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
77 case 2:
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
78 case 3: return *buf;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
79 case 4: return LE_16(buf);
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
80 case 5: return BE_16(buf);
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
81 case 8: return LE_32(buf);
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
82 case 9: return BE_32(buf);
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
83 default: return 0;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
84 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
85 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
86
3684
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
87 static void load_cursor(VmncContext *c, uint8_t *src)
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
88 {
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
89 int i, j, p;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
90 const int bpp = c->bpp2;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
91 uint8_t *dst8 = c->curbits;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
92 uint16_t *dst16 = (uint16_t*)c->curbits;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
93 uint32_t *dst32 = (uint32_t*)c->curbits;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
94
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
95 for(j = 0; j < c->cur_h; j++) {
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
96 for(i = 0; i < c->cur_w; i++) {
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
97 p = vmnc_get_pixel(src, bpp, c->bigendian);
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
98 src += bpp;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
99 if(bpp == 1) *dst8++ = p;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
100 if(bpp == 2) *dst16++ = p;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
101 if(bpp == 4) *dst32++ = p;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
102 }
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
103 }
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
104 dst8 = c->curmask;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
105 dst16 = (uint16_t*)c->curmask;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
106 dst32 = (uint32_t*)c->curmask;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
107 for(j = 0; j < c->cur_h; j++) {
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
108 for(i = 0; i < c->cur_w; i++) {
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
109 p = vmnc_get_pixel(src, bpp, c->bigendian);
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
110 src += bpp;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
111 if(bpp == 1) *dst8++ = p;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
112 if(bpp == 2) *dst16++ = p;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
113 if(bpp == 4) *dst32++ = p;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
114 }
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
115 }
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
116 }
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
117
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
118 static void put_cursor(uint8_t *dst, int stride, VmncContext *c, int dx, int dy)
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
119 {
3920
3a151ccc6ed7 Remove unused variables and the corresponding warnings along with them.
diego
parents: 3800
diff changeset
120 int i, j;
3684
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
121 int w, h, x, y;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
122 w = c->cur_w;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
123 if(c->width < c->cur_x + c->cur_w) w = c->width - c->cur_x;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
124 h = c->cur_h;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
125 if(c->height < c->cur_y + c->cur_h) h = c->height - c->cur_y;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
126 x = c->cur_x;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
127 y = c->cur_y;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
128 if(x < 0) {
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
129 w += x;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
130 x = 0;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
131 }
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
132 if(y < 0) {
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
133 h += y;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
134 y = 0;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
135 }
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
136
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
137 if((w < 1) || (h < 1)) return;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
138 dst += x * c->bpp2 + y * stride;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
139
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
140 if(c->bpp2 == 1) {
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
141 uint8_t* cd = c->curbits, *msk = c->curmask;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
142 for(j = 0; j < h; j++) {
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
143 for(i = 0; i < w; i++)
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
144 dst[i] = (dst[i] & cd[i]) ^ msk[i];
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
145 msk += c->cur_w;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
146 cd += c->cur_w;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
147 dst += stride;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
148 }
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
149 } else if(c->bpp2 == 2) {
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
150 uint16_t* cd = (uint16_t*)c->curbits, *msk = (uint16_t*)c->curmask;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
151 uint16_t* dst2;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
152 for(j = 0; j < h; j++) {
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
153 dst2 = (uint16_t*)dst;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
154 for(i = 0; i < w; i++)
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
155 dst2[i] = (dst2[i] & cd[i]) ^ msk[i];
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
156 msk += c->cur_w;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
157 cd += c->cur_w;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
158 dst += stride;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
159 }
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
160 } else if(c->bpp2 == 4) {
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
161 uint32_t* cd = (uint32_t*)c->curbits, *msk = (uint32_t*)c->curmask;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
162 uint32_t* dst2;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
163 for(j = 0; j < h; j++) {
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
164 dst2 = (uint32_t*)dst;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
165 for(i = 0; i < w; i++)
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
166 dst2[i] = (dst2[i] & cd[i]) ^ msk[i];
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
167 msk += c->cur_w;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
168 cd += c->cur_w;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
169 dst += stride;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
170 }
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
171 }
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
172 }
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
173
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
174 /* fill rectangle with given colour */
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
175 static always_inline void paint_rect(uint8_t *dst, int dx, int dy, int w, int h, int color, int bpp, int stride)
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
176 {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
177 int i, j;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
178 dst += dx * bpp + dy * stride;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
179 if(bpp == 1){
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
180 for(j = 0; j < h; j++) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
181 memset(dst, color, w);
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
182 dst += stride;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
183 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
184 }else if(bpp == 2){
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
185 uint16_t* dst2;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
186 for(j = 0; j < h; j++) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
187 dst2 = (uint16_t*)dst;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
188 for(i = 0; i < w; i++) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
189 *dst2++ = color;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
190 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
191 dst += stride;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
192 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
193 }else if(bpp == 4){
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
194 uint32_t* dst2;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
195 for(j = 0; j < h; j++) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
196 dst2 = (uint32_t*)dst;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
197 for(i = 0; i < w; i++) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
198 dst2[i] = color;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
199 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
200 dst += stride;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
201 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
202 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
203 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
204
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
205 static always_inline void paint_raw(uint8_t *dst, int w, int h, uint8_t* src, int bpp, int be, int stride)
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
206 {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
207 int i, j, p;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
208 for(j = 0; j < h; j++) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
209 for(i = 0; i < w; i++) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
210 p = vmnc_get_pixel(src, bpp, be);
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
211 src += bpp;
3678
93a961e40d65 Handle raw blocks correctly (both updating pointer and storing to memory)
kostya
parents: 3677
diff changeset
212 switch(bpp){
93a961e40d65 Handle raw blocks correctly (both updating pointer and storing to memory)
kostya
parents: 3677
diff changeset
213 case 1:
93a961e40d65 Handle raw blocks correctly (both updating pointer and storing to memory)
kostya
parents: 3677
diff changeset
214 dst[i] = p;
93a961e40d65 Handle raw blocks correctly (both updating pointer and storing to memory)
kostya
parents: 3677
diff changeset
215 break;
93a961e40d65 Handle raw blocks correctly (both updating pointer and storing to memory)
kostya
parents: 3677
diff changeset
216 case 2:
93a961e40d65 Handle raw blocks correctly (both updating pointer and storing to memory)
kostya
parents: 3677
diff changeset
217 ((uint16_t*)dst)[i] = p;
93a961e40d65 Handle raw blocks correctly (both updating pointer and storing to memory)
kostya
parents: 3677
diff changeset
218 break;
93a961e40d65 Handle raw blocks correctly (both updating pointer and storing to memory)
kostya
parents: 3677
diff changeset
219 case 4:
93a961e40d65 Handle raw blocks correctly (both updating pointer and storing to memory)
kostya
parents: 3677
diff changeset
220 ((uint32_t*)dst)[i] = p;
93a961e40d65 Handle raw blocks correctly (both updating pointer and storing to memory)
kostya
parents: 3677
diff changeset
221 break;
93a961e40d65 Handle raw blocks correctly (both updating pointer and storing to memory)
kostya
parents: 3677
diff changeset
222 }
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
223 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
224 dst += stride;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
225 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
226 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
227
3685
dd2da6e09d32 Tests for overreading input data
kostya
parents: 3684
diff changeset
228 static int decode_hextile(VmncContext *c, uint8_t* dst, uint8_t* src, int ssize, int w, int h, int stride)
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
229 {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
230 int i, j, k;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
231 int bg = 0, fg = 0, rects, color, flags, xy, wh;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
232 const int bpp = c->bpp2;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
233 uint8_t *dst2;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
234 int bw = 16, bh = 16;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
235 uint8_t *ssrc=src;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
236
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
237 for(j = 0; j < h; j += 16) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
238 dst2 = dst;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
239 bw = 16;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
240 if(j + 16 > h) bh = h - j;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
241 for(i = 0; i < w; i += 16, dst2 += 16 * bpp) {
3685
dd2da6e09d32 Tests for overreading input data
kostya
parents: 3684
diff changeset
242 if(src - ssrc >= ssize) {
dd2da6e09d32 Tests for overreading input data
kostya
parents: 3684
diff changeset
243 av_log(c->avctx, AV_LOG_ERROR, "Premature end of data!\n");
dd2da6e09d32 Tests for overreading input data
kostya
parents: 3684
diff changeset
244 return -1;
dd2da6e09d32 Tests for overreading input data
kostya
parents: 3684
diff changeset
245 }
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
246 if(i + 16 > w) bw = w - i;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
247 flags = *src++;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
248 if(flags & HT_RAW) {
3685
dd2da6e09d32 Tests for overreading input data
kostya
parents: 3684
diff changeset
249 if(src - ssrc > ssize - bw * bh * bpp) {
dd2da6e09d32 Tests for overreading input data
kostya
parents: 3684
diff changeset
250 av_log(c->avctx, AV_LOG_ERROR, "Premature end of data!\n");
dd2da6e09d32 Tests for overreading input data
kostya
parents: 3684
diff changeset
251 return -1;
dd2da6e09d32 Tests for overreading input data
kostya
parents: 3684
diff changeset
252 }
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
253 paint_raw(dst2, bw, bh, src, bpp, c->bigendian, stride);
3678
93a961e40d65 Handle raw blocks correctly (both updating pointer and storing to memory)
kostya
parents: 3677
diff changeset
254 src += bw * bh * bpp;
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
255 } else {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
256 if(flags & HT_BKG) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
257 bg = vmnc_get_pixel(src, bpp, c->bigendian); src += bpp;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
258 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
259 if(flags & HT_FG) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
260 fg = vmnc_get_pixel(src, bpp, c->bigendian); src += bpp;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
261 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
262 rects = 0;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
263 if(flags & HT_SUB)
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
264 rects = *src++;
3685
dd2da6e09d32 Tests for overreading input data
kostya
parents: 3684
diff changeset
265 color = !!(flags & HT_CLR);
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
266
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
267 paint_rect(dst2, 0, 0, bw, bh, bg, bpp, stride);
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
268
3685
dd2da6e09d32 Tests for overreading input data
kostya
parents: 3684
diff changeset
269 if(src - ssrc > ssize - rects * (color * bpp + 2)) {
dd2da6e09d32 Tests for overreading input data
kostya
parents: 3684
diff changeset
270 av_log(c->avctx, AV_LOG_ERROR, "Premature end of data!\n");
dd2da6e09d32 Tests for overreading input data
kostya
parents: 3684
diff changeset
271 return -1;
dd2da6e09d32 Tests for overreading input data
kostya
parents: 3684
diff changeset
272 }
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
273 for(k = 0; k < rects; k++) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
274 if(color) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
275 fg = vmnc_get_pixel(src, bpp, c->bigendian); src += bpp;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
276 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
277 xy = *src++;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
278 wh = *src++;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
279 paint_rect(dst2, xy >> 4, xy & 0xF, (wh>>4)+1, (wh & 0xF)+1, fg, bpp, stride);
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
280 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
281 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
282 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
283 dst += stride * 16;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
284 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
285 return src - ssrc;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
286 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
287
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
288 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size)
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
289 {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
290 VmncContext * const c = (VmncContext *)avctx->priv_data;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
291 uint8_t *outptr;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
292 uint8_t *src = buf;
3685
dd2da6e09d32 Tests for overreading input data
kostya
parents: 3684
diff changeset
293 int dx, dy, w, h, depth, enc, chunks, res, size_left;
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
294
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
295 c->pic.reference = 1;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
296 c->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
297 if(avctx->reget_buffer(avctx, &c->pic) < 0){
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
298 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
299 return -1;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
300 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
301
3679
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
302 c->pic.key_frame = 0;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
303 c->pic.pict_type = FF_P_TYPE;
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
304
3684
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
305 //restore screen after cursor
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
306 if(c->screendta) {
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
307 int i;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
308 w = c->cur_w;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
309 if(c->width < c->cur_x + w) w = c->width - c->cur_x;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
310 h = c->cur_h;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
311 if(c->height < c->cur_y + h) h = c->height - c->cur_y;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
312 dx = c->cur_x;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
313 if(dx < 0) {
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
314 w += dx;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
315 dx = 0;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
316 }
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
317 dy = c->cur_y;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
318 if(dy < 0) {
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
319 h += dy;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
320 dy = 0;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
321 }
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
322 if((w > 0) && (h > 0)) {
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
323 outptr = c->pic.data[0] + dx * c->bpp2 + dy * c->pic.linesize[0];
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
324 for(i = 0; i < h; i++) {
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
325 memcpy(outptr, c->screendta + i * c->cur_w * c->bpp2, w * c->bpp2);
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
326 outptr += c->pic.linesize[0];
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
327 }
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
328 }
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
329 }
3679
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
330 src += 2;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
331 chunks = BE_16(src); src += 2;
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
332 while(chunks--) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
333 dx = BE_16(src); src += 2;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
334 dy = BE_16(src); src += 2;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
335 w = BE_16(src); src += 2;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
336 h = BE_16(src); src += 2;
3679
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
337 enc = BE_32(src); src += 4;
3684
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
338 outptr = c->pic.data[0] + dx * c->bpp2 + dy * c->pic.linesize[0];
3685
dd2da6e09d32 Tests for overreading input data
kostya
parents: 3684
diff changeset
339 size_left = buf_size - (src - buf);
3679
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
340 switch(enc) {
3684
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
341 case MAGIC_WMVd: // cursor
3685
dd2da6e09d32 Tests for overreading input data
kostya
parents: 3684
diff changeset
342 if(size_left < 2 + w * h * c->bpp2 * 2) {
dd2da6e09d32 Tests for overreading input data
kostya
parents: 3684
diff changeset
343 av_log(avctx, AV_LOG_ERROR, "Premature end of data! (need %i got %i)\n", 2 + w * h * c->bpp2 * 2, size_left);
dd2da6e09d32 Tests for overreading input data
kostya
parents: 3684
diff changeset
344 return -1;
dd2da6e09d32 Tests for overreading input data
kostya
parents: 3684
diff changeset
345 }
3679
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
346 src += 2;
3684
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
347 c->cur_w = w;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
348 c->cur_h = h;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
349 c->cur_hx = dx;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
350 c->cur_hy = dy;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
351 if((c->cur_hx > c->cur_w) || (c->cur_hy > c->cur_h)) {
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
352 av_log(avctx, AV_LOG_ERROR, "Cursor hot spot is not in image: %ix%i of %ix%i cursor size\n", c->cur_hx, c->cur_hy, c->cur_w, c->cur_h);
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
353 c->cur_hx = c->cur_hy = 0;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
354 }
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
355 c->curbits = av_realloc(c->curbits, c->cur_w * c->cur_h * c->bpp2);
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
356 c->curmask = av_realloc(c->curmask, c->cur_w * c->cur_h * c->bpp2);
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
357 c->screendta = av_realloc(c->screendta, c->cur_w * c->cur_h * c->bpp2);
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
358 load_cursor(c, src);
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
359 src += w * h * c->bpp2 * 2;
3679
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
360 break;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
361 case MAGIC_WMVe: // unknown
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
362 src += 2;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
363 break;
3684
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
364 case MAGIC_WMVf: // update cursor position
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
365 c->cur_x = dx - c->cur_hx;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
366 c->cur_y = dy - c->cur_hy;
3679
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
367 break;
3686
5fc587a5feea Handle the rest of known blocks (by skipping them)
kostya
parents: 3685
diff changeset
368 case MAGIC_WMVg: // unknown
5fc587a5feea Handle the rest of known blocks (by skipping them)
kostya
parents: 3685
diff changeset
369 src += 10;
5fc587a5feea Handle the rest of known blocks (by skipping them)
kostya
parents: 3685
diff changeset
370 break;
5fc587a5feea Handle the rest of known blocks (by skipping them)
kostya
parents: 3685
diff changeset
371 case MAGIC_WMVh: // unknown
5fc587a5feea Handle the rest of known blocks (by skipping them)
kostya
parents: 3685
diff changeset
372 src += 4;
5fc587a5feea Handle the rest of known blocks (by skipping them)
kostya
parents: 3685
diff changeset
373 break;
3679
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
374 case MAGIC_WMVi: // ServerInitialization struct
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
375 c->pic.key_frame = 1;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
376 c->pic.pict_type = FF_I_TYPE;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
377 depth = *src++;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
378 if(depth != c->bpp) {
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
379 av_log(avctx, AV_LOG_INFO, "Depth mismatch. Container %i bpp, Frame data: %i bpp\n", c->bpp, depth);
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
380 }
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
381 src++;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
382 c->bigendian = *src++;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
383 if(c->bigendian & (~1)) {
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
384 av_log(avctx, AV_LOG_INFO, "Invalid header: bigendian flag = %i\n", c->bigendian);
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
385 return -1;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
386 }
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
387 //skip the rest of pixel format data
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
388 src += 13;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
389 break;
3686
5fc587a5feea Handle the rest of known blocks (by skipping them)
kostya
parents: 3685
diff changeset
390 case MAGIC_WMVj: // unknown
5fc587a5feea Handle the rest of known blocks (by skipping them)
kostya
parents: 3685
diff changeset
391 src += 2;
5fc587a5feea Handle the rest of known blocks (by skipping them)
kostya
parents: 3685
diff changeset
392 break;
3679
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
393 case 0x00000000: // raw rectangle data
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
394 if((dx + w > c->width) || (dy + h > c->height)) {
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
395 av_log(avctx, AV_LOG_ERROR, "Incorrect frame size: %ix%i+%ix%i of %ix%i\n", w, h, dx, dy, c->width, c->height);
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
396 return -1;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
397 }
3685
dd2da6e09d32 Tests for overreading input data
kostya
parents: 3684
diff changeset
398 if(size_left < w * h * c->bpp2) {
dd2da6e09d32 Tests for overreading input data
kostya
parents: 3684
diff changeset
399 av_log(avctx, AV_LOG_ERROR, "Premature end of data! (need %i got %i)\n", w * h * c->bpp2, size_left);
dd2da6e09d32 Tests for overreading input data
kostya
parents: 3684
diff changeset
400 return -1;
dd2da6e09d32 Tests for overreading input data
kostya
parents: 3684
diff changeset
401 }
3679
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
402 paint_raw(outptr, w, h, src, c->bpp2, c->bigendian, c->pic.linesize[0]);
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
403 src += w * h * c->bpp2;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
404 break;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
405 case 0x00000005: // HexTile encoded rectangle
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
406 if((dx + w > c->width) || (dy + h > c->height)) {
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
407 av_log(avctx, AV_LOG_ERROR, "Incorrect frame size: %ix%i+%ix%i of %ix%i\n", w, h, dx, dy, c->width, c->height);
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
408 return -1;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
409 }
3685
dd2da6e09d32 Tests for overreading input data
kostya
parents: 3684
diff changeset
410 res = decode_hextile(c, outptr, src, size_left, w, h, c->pic.linesize[0]);
3679
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
411 if(res < 0)
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
412 return -1;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
413 src += res;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
414 break;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
415 default:
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
416 av_log(avctx, AV_LOG_ERROR, "Unsupported block type 0x%08X\n", enc);
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
417 chunks = 0; // leave chunks decoding loop
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
418 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
419 }
3684
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
420 if(c->screendta){
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
421 int i;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
422 //save screen data before painting cursor
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
423 w = c->cur_w;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
424 if(c->width < c->cur_x + w) w = c->width - c->cur_x;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
425 h = c->cur_h;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
426 if(c->height < c->cur_y + h) h = c->height - c->cur_y;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
427 dx = c->cur_x;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
428 if(dx < 0) {
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
429 w += dx;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
430 dx = 0;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
431 }
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
432 dy = c->cur_y;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
433 if(dy < 0) {
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
434 h += dy;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
435 dy = 0;
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
436 }
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
437 if((w > 0) && (h > 0)) {
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
438 outptr = c->pic.data[0] + dx * c->bpp2 + dy * c->pic.linesize[0];
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
439 for(i = 0; i < h; i++) {
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
440 memcpy(c->screendta + i * c->cur_w * c->bpp2, outptr, w * c->bpp2);
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
441 outptr += c->pic.linesize[0];
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
442 }
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
443 outptr = c->pic.data[0];
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
444 put_cursor(outptr, c->pic.linesize[0], c, c->cur_x, c->cur_y);
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
445 }
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
446 }
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
447 *data_size = sizeof(AVFrame);
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
448 *(AVFrame*)data = c->pic;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
449
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
450 /* always report that the buffer was completely consumed */
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
451 return buf_size;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
452 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
453
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
454
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
455
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
456 /*
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
457 *
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
458 * Init VMnc decoder
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
459 *
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
460 */
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
461 static int decode_init(AVCodecContext *avctx)
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
462 {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
463 VmncContext * const c = (VmncContext *)avctx->priv_data;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
464
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
465 c->avctx = avctx;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
466 avctx->has_b_frames = 0;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
467
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
468 c->pic.data[0] = NULL;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
469 c->width = avctx->width;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
470 c->height = avctx->height;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
471
3800
9b75ab171fa9 1l: correct argument order in avcodec_check_dimensions
kostya
parents: 3686
diff changeset
472 if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) {
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
473 return 1;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
474 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
475 c->bpp = avctx->bits_per_sample;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
476 c->bpp2 = c->bpp/8;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
477
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
478 switch(c->bpp){
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
479 case 8:
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
480 avctx->pix_fmt = PIX_FMT_PAL8;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
481 break;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
482 case 16:
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
483 avctx->pix_fmt = PIX_FMT_RGB555;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
484 break;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
485 case 32:
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
486 avctx->pix_fmt = PIX_FMT_RGB32;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
487 break;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
488 default:
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
489 av_log(avctx, AV_LOG_ERROR, "Unsupported bitdepth %i\n", c->bpp);
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
490 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
491
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
492 return 0;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
493 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
494
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
495
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
496
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
497 /*
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
498 *
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
499 * Uninit VMnc decoder
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
500 *
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
501 */
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
502 static int decode_end(AVCodecContext *avctx)
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
503 {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
504 VmncContext * const c = (VmncContext *)avctx->priv_data;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
505
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
506 if (c->pic.data[0])
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
507 avctx->release_buffer(avctx, &c->pic);
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
508
3684
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
509 av_free(c->curbits);
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
510 av_free(c->curmask);
9f77f4f577b4 Cursor drawing support
kostya
parents: 3679
diff changeset
511 av_free(c->screendta);
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
512 return 0;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
513 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
514
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
515 AVCodec vmnc_decoder = {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
516 "VMware video",
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
517 CODEC_TYPE_VIDEO,
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
518 CODEC_ID_VMNC,
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
519 sizeof(VmncContext),
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
520 decode_init,
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
521 NULL,
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
522 decode_end,
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
523 decode_frame
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
524 };
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
525