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