7222
|
1 /*
|
|
2 *
|
|
3 * LCL (LossLess Codec Library) Decoder for Mplayer
|
8972
|
4 * (c) 2002, 2003 Roberto Togni
|
7222
|
5 *
|
|
6 * Fourcc: MSZH, ZLIB
|
|
7 *
|
|
8 * Win32 dll:
|
|
9 * Ver2.23 By Kenji Oshima 2000.09.20
|
|
10 * avimszh.dll, avizlib.dll
|
|
11 *
|
|
12 * A description of the decoding algorithm can be found here:
|
|
13 * http://www.pcisys.net/~melanson/codecs
|
|
14 *
|
|
15 */
|
|
16
|
|
17 #include <stdio.h>
|
|
18 #include <stdlib.h>
|
|
19
|
|
20 #include "config.h"
|
|
21
|
|
22 #ifdef HAVE_ZLIB
|
|
23 #include <zlib.h>
|
|
24 #endif
|
|
25
|
|
26 #include "mp_msg.h"
|
|
27
|
|
28 #include "vd_internal.h"
|
|
29
|
|
30
|
|
31 static vd_info_t info = {
|
|
32 "LCL Video decoder",
|
|
33 "lcl",
|
|
34 "Roberto Togni",
|
|
35 "Roberto Togni",
|
|
36 "native codec"
|
|
37 };
|
|
38
|
|
39 LIBVD_EXTERN(lcl)
|
|
40
|
|
41
|
|
42 #define BMPTYPE_YUV 1
|
|
43 #define BMPTYPE_RGB 2
|
|
44
|
|
45 #define IMGTYPE_YUV111 0
|
|
46 #define IMGTYPE_YUV422 1
|
|
47 #define IMGTYPE_RGB24 2
|
|
48 #define IMGTYPE_YUV411 3
|
|
49 #define IMGTYPE_YUV211 4
|
|
50 #define IMGTYPE_YUV420 5
|
|
51
|
|
52 #define COMP_MSZH 0
|
|
53 #define COMP_MSZH_NOCOMP 1
|
|
54 #define COMP_ZLIB_HISPEED 1
|
|
55 #define COMP_ZLIB_HICOMP 9
|
|
56 #define COMP_ZLIB_NORMAL -1
|
|
57
|
|
58 #define FLAG_MULTITHREAD 1
|
|
59 #define FLAG_NULLFRAME 2
|
|
60 #define FLAG_PNGFILTER 4
|
|
61 #define FLAGMASK_UNUSED 0xf8
|
|
62
|
|
63 #define CODEC_MSZH 1
|
|
64 #define CODEC_ZLIB 3
|
|
65
|
|
66 #define FOURCC_MSZH mmioFOURCC('M','S','Z','H')
|
|
67 #define FOURCC_ZLIB mmioFOURCC('Z','L','I','B')
|
|
68
|
|
69 /*
|
|
70 * Decoder context
|
|
71 */
|
|
72 typedef struct {
|
|
73 // Image type
|
|
74 int imgtype;
|
|
75 // Compression type
|
|
76 int compression;
|
|
77 // Flags
|
|
78 int flags;
|
|
79 // Codec type
|
|
80 int codec;
|
|
81 // Decompressed data size
|
|
82 unsigned int decomp_size;
|
|
83 // Decompression buffer
|
|
84 unsigned char* decomp_buf;
|
|
85 #ifdef HAVE_ZLIB
|
|
86 z_stream zstream;
|
|
87 #endif
|
|
88 } lcl_context_t;
|
|
89
|
|
90
|
|
91 /*
|
|
92 * Internal function prototypes
|
|
93 */
|
|
94
|
|
95
|
|
96 // to set/get/query special features/parameters
|
|
97 static int control(sh_video_t *sh,int cmd,void* arg,...)
|
|
98 {
|
|
99 return CONTROL_UNKNOWN;
|
|
100 }
|
|
101
|
|
102
|
|
103 /*
|
|
104 *
|
|
105 * Init LCL decoder
|
|
106 *
|
|
107 */
|
|
108 static int init(sh_video_t *sh)
|
|
109 {
|
|
110 int vo_ret; // Video output init ret value
|
|
111 int zret; // Zlib return code
|
|
112 lcl_context_t *hc; // Decoder context
|
|
113 BITMAPINFOHEADER *bih = sh->bih;
|
|
114 int basesize = bih->biWidth * bih->biHeight;
|
|
115
|
|
116 if ((hc = malloc(sizeof(lcl_context_t))) == NULL) {
|
|
117 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Can't allocate memory for LCL decoder context.\n");
|
|
118 return 0;
|
|
119 }
|
|
120
|
|
121 sh->context = (void *)hc;
|
|
122
|
|
123 #ifdef HAVE_ZLIB
|
|
124 // Needed if zlib unused or init aborted before inflateInit
|
|
125 memset(&(hc->zstream), 0, sizeof(z_stream));
|
|
126 #endif
|
|
127
|
|
128 if ((bih->biCompression != FOURCC_MSZH) && (bih->biCompression != FOURCC_ZLIB)) {
|
|
129 mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[LCL] Unknown BITMAPHEADER fourcc.\n");
|
|
130 return 0;
|
|
131 }
|
|
132
|
|
133 if (bih->biSize < sizeof(BITMAPINFOHEADER) + 8) {
|
|
134 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] BITMAPHEADER size too small.\n");
|
|
135 return 0;
|
|
136 }
|
|
137
|
|
138 /* Detect codec type */
|
|
139 switch (hc->codec = *((char *)bih + sizeof(BITMAPINFOHEADER) + 7)) {
|
|
140 case CODEC_MSZH:
|
|
141 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] Codec is MSZH.\n");
|
|
142 break;
|
|
143 case CODEC_ZLIB:
|
|
144 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] Codec is ZLIB.\n");
|
|
145 break;
|
|
146 default:
|
|
147 mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[LCL] Unknown codec id %d. Trusting fourcc.\n", hc->codec);
|
|
148 switch (bih->biCompression) {
|
|
149 case FOURCC_MSZH:
|
|
150 hc->codec = CODEC_MSZH;
|
|
151 break;
|
|
152 case FOURCC_ZLIB:
|
|
153 hc->codec = CODEC_ZLIB;
|
|
154 break;
|
|
155 default:
|
|
156 mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[LCL] BUG! Unknown coded id and fourcc. Why am I here?.\n");
|
|
157 return 0;
|
|
158 }
|
|
159 }
|
|
160
|
|
161
|
|
162 /* Detect image type */
|
|
163 switch (hc->imgtype = *((char *)bih + sizeof(BITMAPINFOHEADER) + 4)) {
|
|
164 case IMGTYPE_YUV111:
|
|
165 hc->decomp_size = basesize * 3;
|
|
166 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] Image type is YUV 1:1:1.\n");
|
|
167 break;
|
|
168 case IMGTYPE_YUV422:
|
|
169 hc->decomp_size = basesize * 2;
|
|
170 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] Image type is YUV 4:2:2.\n");
|
|
171 break;
|
|
172 case IMGTYPE_RGB24:
|
|
173 hc->decomp_size = basesize * 3;
|
|
174 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] Image type is RGB 24.\n");
|
|
175 break;
|
|
176 case IMGTYPE_YUV411:
|
|
177 hc->decomp_size = basesize / 2 * 3;
|
|
178 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] Image type is YUV 4:1:1.\n");
|
|
179 break;
|
|
180 case IMGTYPE_YUV211:
|
|
181 hc->decomp_size = basesize * 2;
|
|
182 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] Image type is YUV 2:1:1.\n");
|
|
183 break;
|
|
184 case IMGTYPE_YUV420:
|
|
185 hc->decomp_size = basesize / 2 * 3;
|
|
186 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] Image type is YUV 4:2:0.\n");
|
|
187 break;
|
|
188 default:
|
|
189 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] Unsupported image format %d.\n", hc->imgtype);
|
|
190 return 0;
|
|
191 }
|
|
192
|
|
193 /* Detect compression method */
|
|
194 hc->compression = *((char *)bih + sizeof(BITMAPINFOHEADER) + 5);
|
|
195 switch (hc->codec) {
|
|
196 case CODEC_MSZH:
|
|
197 switch (hc->compression) {
|
|
198 case COMP_MSZH:
|
|
199 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] Compression enabled.\n");
|
|
200 break;
|
|
201 case COMP_MSZH_NOCOMP:
|
|
202 hc->decomp_size = 0;
|
|
203 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] No compression.\n");
|
|
204 break;
|
|
205 default:
|
|
206 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] Unsupported compression format for MSZH (%d).\n", hc->compression);
|
|
207 return 0;
|
|
208 }
|
|
209 break;
|
|
210 case CODEC_ZLIB:
|
|
211 switch (hc->compression) {
|
|
212 case COMP_ZLIB_HISPEED:
|
|
213 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] High speed compression.\n");
|
|
214 break;
|
|
215 case COMP_ZLIB_HICOMP:
|
|
216 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] High compression.\n");
|
|
217 break;
|
|
218 case COMP_ZLIB_NORMAL:
|
|
219 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] Normal compression.\n");
|
|
220 break;
|
|
221 default:
|
|
222 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] Unsupported compression format for ZLIB (%d).\n", hc->compression);
|
|
223 return 0;
|
|
224 }
|
|
225 break;
|
|
226 default:
|
|
227 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] BUG! Unknown codec in compression switch.\n");
|
|
228 return 0;
|
|
229 }
|
|
230
|
|
231 /* Allocate decompression buffer */
|
|
232 /* 4*8 max oveflow space for mszh decomp algorithm */
|
|
233 if (hc->decomp_size) {
|
|
234 if ((hc->decomp_buf = malloc(hc->decomp_size+4*8)) == NULL) {
|
|
235 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] Can't allocate decompression buffer.\n");
|
|
236 return 0;
|
|
237 }
|
|
238 }
|
|
239
|
|
240 /* Detect flags */
|
|
241 hc->flags = *((char *)bih + sizeof(BITMAPINFOHEADER) + 6);
|
|
242 if (hc->flags & FLAG_MULTITHREAD)
|
|
243 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] Multithread encoder flag set.\n");
|
|
244 if (hc->flags & FLAG_NULLFRAME)
|
|
245 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] Nullframe insertion flag set.\n");
|
|
246 if ((hc->codec == CODEC_ZLIB) && (hc->flags & FLAG_PNGFILTER))
|
|
247 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] PNG filter flag set.\n");
|
|
248 if (hc->flags & FLAGMASK_UNUSED)
|
|
249 mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[LCL] Unknown flag set (%d).\n", hc->flags);
|
|
250
|
|
251 /* If needed init zlib */
|
|
252 if (hc->codec == CODEC_ZLIB) {
|
|
253 #ifdef HAVE_ZLIB
|
|
254 hc->zstream.zalloc = Z_NULL;
|
|
255 hc->zstream.zfree = Z_NULL;
|
|
256 hc->zstream.opaque = Z_NULL;
|
|
257 zret = inflateInit(&(hc->zstream));
|
|
258 if (zret != Z_OK) {
|
|
259 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] Inflate init error: %d\n", zret);
|
|
260 return 0;
|
|
261 }
|
|
262 #else
|
|
263 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] Zlib support not compiled.\n");
|
|
264 return 0;
|
|
265 #endif
|
|
266 }
|
|
267
|
|
268 /*
|
|
269 * Initialize video output device
|
|
270 */
|
|
271 vo_ret = mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_BGR24);
|
|
272
|
|
273 return vo_ret;
|
|
274 }
|
|
275
|
|
276
|
|
277
|
|
278
|
|
279 /*
|
|
280 *
|
|
281 * Uninit LCL decoder
|
|
282 *
|
|
283 */
|
|
284 static void uninit(sh_video_t *sh)
|
|
285 {
|
|
286 lcl_context_t *hc = (lcl_context_t *) sh->context; // Decoder context
|
|
287
|
|
288 if (sh->context) {
|
|
289 #ifdef HAVE_ZLIB
|
|
290 inflateEnd(&hc->zstream);
|
|
291 #endif
|
|
292 free(sh->context);
|
|
293 }
|
|
294 }
|
|
295
|
|
296
|
|
297
|
|
298 inline unsigned char fix (int pix14)
|
|
299 {
|
|
300 int tmp;
|
|
301
|
|
302 tmp = (pix14 + 0x80000) >> 20;
|
|
303 if (tmp < 0)
|
|
304 return 0;
|
|
305 if (tmp > 255)
|
|
306 return 255;
|
|
307 return tmp;
|
|
308 }
|
|
309
|
|
310
|
|
311
|
|
312 inline unsigned char get_b (unsigned char yq, signed char bq)
|
|
313 {
|
|
314 return fix((yq << 20) + bq * 1858076);
|
|
315 }
|
|
316
|
|
317
|
|
318
|
|
319 inline unsigned char get_g (unsigned char yq, signed char bq, signed char rq)
|
|
320 {
|
|
321 return fix((yq << 20) - bq * 360857 - rq * 748830);
|
|
322 }
|
|
323
|
|
324
|
|
325
|
|
326 inline unsigned char get_r (unsigned char yq, signed char rq)
|
|
327 {
|
|
328 return fix((yq << 20) + rq * 1470103);
|
|
329 }
|
|
330
|
|
331
|
|
332 int mszh_decomp(unsigned char * srcptr, int srclen, unsigned char * destptr);
|
|
333
|
|
334 /*
|
|
335 *
|
|
336 * Decode a frame
|
|
337 *
|
|
338 */
|
|
339 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags)
|
|
340 {
|
|
341 mp_image_t* mpi;
|
|
342 int pixel_ptr;
|
|
343 int row, col;
|
|
344 unsigned char *encoded = (unsigned char *)data;
|
|
345 lcl_context_t *hc = (lcl_context_t *) sh->context; // Decoder context
|
|
346 unsigned char *outptr;
|
|
347 int width = sh->disp_w; // Real image width
|
|
348 int height = sh->disp_h; // Real image height
|
|
349 #ifdef HAVE_ZLIB
|
|
350 int zret; // Zlib return code
|
|
351 #endif
|
|
352 unsigned int mszh_dlen;
|
|
353 unsigned char yq, y1q, uq, vq;
|
|
354 int uqvq;
|
|
355 unsigned int mthread_inlen, mthread_outlen;
|
|
356
|
|
357 // Skipped frame
|
|
358 if(len <= 0)
|
|
359 return NULL;
|
|
360
|
|
361 /* Get output image buffer */
|
|
362 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, 0, sh->disp_w, sh->disp_h);
|
|
363 if (!mpi) {
|
|
364 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Can't allocate mpi image for lcl codec.\n");
|
|
365 return NULL;
|
|
366 }
|
|
367
|
|
368 outptr = mpi->planes[0]; // Output image pointer
|
|
369
|
|
370
|
|
371 /* Decompress frame */
|
|
372 switch (hc->codec) {
|
|
373 case CODEC_MSZH:
|
|
374 switch (hc->compression) {
|
|
375 case COMP_MSZH:
|
|
376 if (hc->flags & FLAG_MULTITHREAD) {
|
|
377 mthread_inlen = *((unsigned int*)encoded);
|
|
378 mthread_outlen = *((unsigned int*)(encoded+4));
|
|
379 mszh_dlen = mszh_decomp(encoded + 8, mthread_inlen, hc->decomp_buf);
|
|
380 if (mthread_outlen != mszh_dlen) {
|
|
381 mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[LCL] MSZH: mthread1 decoded size differs (%d != %d)\n",
|
|
382 mthread_outlen, mszh_dlen);
|
|
383 }
|
|
384 mszh_dlen = mszh_decomp(encoded + 8 + mthread_inlen, len - mthread_inlen,
|
|
385 hc->decomp_buf + mthread_outlen);
|
|
386 if ((hc->decomp_size - mthread_outlen) != mszh_dlen) {
|
|
387 mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[LCL] MSZH: mthread2 decoded size differs (%d != %d)\n",
|
|
388 hc->decomp_size - mthread_outlen, mszh_dlen);
|
|
389 }
|
|
390 encoded = hc->decomp_buf;
|
|
391 len = hc->decomp_size;
|
|
392 } else {
|
|
393 mszh_dlen = mszh_decomp(encoded, len, hc->decomp_buf);
|
|
394 if (hc->decomp_size != mszh_dlen) {
|
|
395 mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[LCL] MSZH: decoded size differs (%d != %d)\n",
|
|
396 hc->decomp_size, mszh_dlen);
|
|
397 }
|
|
398 encoded = hc->decomp_buf;
|
|
399 len = mszh_dlen;
|
|
400 }
|
|
401 break;
|
|
402 case COMP_MSZH_NOCOMP:
|
|
403 break;
|
|
404 default:
|
|
405 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] BUG! Unknown MSZH compression in frame decoder.\n");
|
|
406 return 0;
|
|
407 }
|
|
408 break;
|
|
409 case CODEC_ZLIB:
|
|
410 switch (hc->compression) {
|
|
411 case COMP_ZLIB_HISPEED:
|
|
412 case COMP_ZLIB_HICOMP:
|
|
413 case COMP_ZLIB_NORMAL:
|
|
414 #ifdef HAVE_ZLIB
|
|
415 zret = inflateReset(&(hc->zstream));
|
|
416 if (zret != Z_OK) {
|
|
417 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] ZLIB: inflate reset error: %d\n", zret);
|
|
418 return 0;
|
|
419 }
|
|
420 if (hc->flags & FLAG_MULTITHREAD) {
|
|
421 mthread_inlen = *((unsigned int*)encoded);
|
|
422 mthread_outlen = *((unsigned int*)(encoded+4));
|
|
423 hc->zstream.next_in = encoded + 8;
|
|
424 hc->zstream.avail_in = mthread_inlen;
|
|
425 hc->zstream.next_out = hc->decomp_buf;
|
|
426 hc->zstream.avail_out = mthread_outlen;
|
|
427 zret = inflate(&(hc->zstream), Z_FINISH);
|
|
428 if ((zret != Z_OK) && (zret != Z_STREAM_END)) {
|
|
429 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] ZLIB: mthread1 inflate error: %d\n", zret);
|
|
430 return 0;
|
|
431 }
|
|
432 if (mthread_outlen != (unsigned int)(hc->zstream.total_out)) {
|
|
433 mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[LCL] ZLIB: mthread1 decoded size differs (%d != %d)\n",
|
|
434 mthread_outlen, hc->zstream.total_out);
|
|
435 }
|
|
436 zret = inflateReset(&(hc->zstream));
|
|
437 if (zret != Z_OK) {
|
|
438 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] ZLIB: mthread2 inflate reset error: %d\n", zret);
|
|
439 return 0;
|
|
440 }
|
|
441 hc->zstream.next_in = encoded + 8 + mthread_inlen;
|
|
442 hc->zstream.avail_in = len - mthread_inlen;
|
|
443 hc->zstream.next_out = hc->decomp_buf + mthread_outlen;
|
|
444 hc->zstream.avail_out = mthread_outlen;
|
|
445 zret = inflate(&(hc->zstream), Z_FINISH);
|
|
446 if ((zret != Z_OK) && (zret != Z_STREAM_END)) {
|
|
447 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] ZLIB: mthread2 inflate error: %d\n", zret);
|
|
448 return 0;
|
|
449 }
|
|
450 if ((hc->decomp_size - mthread_outlen) != (unsigned int)(hc->zstream.total_out)) {
|
|
451 mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[LCL] ZLIB: mthread2 decoded size differs (%d != %d)\n",
|
|
452 hc->decomp_size - mthread_outlen, hc->zstream.total_out);
|
|
453 }
|
|
454 } else {
|
|
455 hc->zstream.next_in = data;
|
|
456 hc->zstream.avail_in = len;
|
|
457 hc->zstream.next_out = hc->decomp_buf;
|
|
458 hc->zstream.avail_out = hc->decomp_size;
|
|
459 zret = inflate(&(hc->zstream), Z_FINISH);
|
|
460 if ((zret != Z_OK) && (zret != Z_STREAM_END)) {
|
|
461 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] ZLIB: inflate error: %d\n", zret);
|
|
462 return 0;
|
|
463 }
|
|
464 if (hc->decomp_size != (unsigned int)(hc->zstream.total_out)) {
|
|
465 mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[LCL] ZLIB: decoded size differs (%d != %d)\n",
|
|
466 hc->decomp_size, hc->zstream.total_out);
|
|
467 }
|
|
468 }
|
|
469 encoded = hc->decomp_buf;
|
|
470 len = hc->decomp_size;;
|
|
471 #else
|
|
472 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] BUG! Zlib support not compiled in frame decoder.\n");
|
|
473 return 0;
|
|
474 #endif
|
|
475 break;
|
|
476 default:
|
|
477 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] BUG! Unknown ZLIB compression in frame decoder.\n");
|
|
478 return 0;
|
|
479 }
|
|
480 break;
|
|
481 default:
|
|
482 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] BUG! Unknown codec in frame decoder compression switch.\n");
|
|
483 return 0;
|
|
484 }
|
|
485
|
|
486
|
|
487 /* Apply PNG filter */
|
|
488 if ((hc->codec == CODEC_ZLIB) && (hc->flags & FLAG_PNGFILTER)) {
|
|
489 switch (hc->imgtype) {
|
|
490 case IMGTYPE_YUV111:
|
8972
|
491 case IMGTYPE_RGB24:
|
7222
|
492 for (row = 0; row < height; row++) {
|
|
493 pixel_ptr = row * width * 3;
|
|
494 yq = encoded[pixel_ptr++];
|
8451
|
495 uqvq = encoded[pixel_ptr++];
|
|
496 uqvq+=(encoded[pixel_ptr++] << 8);
|
7222
|
497 for (col = 1; col < width; col++) {
|
|
498 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
|
|
499 uqvq -= (encoded[pixel_ptr+1] | (encoded[pixel_ptr+2]<<8));
|
|
500 encoded[pixel_ptr+1] = (uqvq) & 0xff;
|
|
501 encoded[pixel_ptr+2] = ((uqvq)>>8) & 0xff;
|
|
502 pixel_ptr += 3;
|
|
503 }
|
|
504 }
|
|
505 break;
|
|
506 case IMGTYPE_YUV422:
|
|
507 for (row = 0; row < height; row++) {
|
|
508 pixel_ptr = row * width * 2;
|
|
509 yq = uq = vq =0;
|
|
510 for (col = 0; col < width/4; col++) {
|
|
511 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
|
|
512 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
|
|
513 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
|
|
514 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
|
|
515 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
|
|
516 encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5];
|
|
517 encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6];
|
|
518 encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7];
|
|
519 pixel_ptr += 8;
|
|
520 }
|
|
521 }
|
|
522 break;
|
|
523 case IMGTYPE_YUV411:
|
|
524 for (row = 0; row < height; row++) {
|
|
525 pixel_ptr = row * width / 2 * 3;
|
|
526 yq = uq = vq =0;
|
|
527 for (col = 0; col < width/4; col++) {
|
|
528 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
|
|
529 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
|
|
530 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
|
|
531 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
|
|
532 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
|
|
533 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
|
|
534 pixel_ptr += 6;
|
|
535 }
|
|
536 }
|
|
537 break;
|
|
538 case IMGTYPE_YUV211:
|
|
539 for (row = 0; row < height; row++) {
|
|
540 pixel_ptr = row * width * 2;
|
|
541 yq = uq = vq =0;
|
|
542 for (col = 0; col < width/2; col++) {
|
|
543 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
|
|
544 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
|
|
545 encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2];
|
|
546 encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3];
|
|
547 pixel_ptr += 4;
|
|
548 }
|
|
549 }
|
|
550 break;
|
|
551 case IMGTYPE_YUV420:
|
|
552 for (row = 0; row < height/2; row++) {
|
|
553 pixel_ptr = row * width * 3;
|
|
554 yq = y1q = uq = vq =0;
|
|
555 for (col = 0; col < width/2; col++) {
|
|
556 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
|
|
557 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
|
|
558 encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2];
|
|
559 encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3];
|
|
560 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
|
|
561 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
|
|
562 pixel_ptr += 6;
|
|
563 }
|
|
564 }
|
|
565 break;
|
|
566 break;
|
|
567 default:
|
|
568 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] BUG! Unknown imagetype in pngfilter switch.\n");
|
|
569 return 0;
|
|
570 }
|
|
571 }
|
|
572
|
|
573 /* Convert colorspace */
|
|
574 switch (hc->imgtype) {
|
|
575 case IMGTYPE_YUV111:
|
|
576 for (row = height - 1; row >= 0; row--) {
|
|
577 pixel_ptr = row * mpi->stride[0];
|
|
578 for (col = 0; col < width; col++) {
|
|
579 outptr[pixel_ptr++] = get_b(encoded[0], encoded[1]);
|
|
580 outptr[pixel_ptr++] = get_g(encoded[0], encoded[1], encoded[2]);
|
|
581 outptr[pixel_ptr++] = get_r(encoded[0], encoded[2]);
|
|
582 encoded += 3;
|
|
583 }
|
|
584 }
|
|
585 break;
|
|
586 case IMGTYPE_YUV422:
|
|
587 for (row = height - 1; row >= 0; row--) {
|
|
588 pixel_ptr = row * mpi->stride[0];
|
|
589 for (col = 0; col < width/4; col++) {
|
|
590 outptr[pixel_ptr++] = get_b(encoded[0], encoded[4]);
|
|
591 outptr[pixel_ptr++] = get_g(encoded[0], encoded[4], encoded[6]);
|
|
592 outptr[pixel_ptr++] = get_r(encoded[0], encoded[6]);
|
|
593 outptr[pixel_ptr++] = get_b(encoded[1], encoded[4]);
|
|
594 outptr[pixel_ptr++] = get_g(encoded[1], encoded[4], encoded[6]);
|
|
595 outptr[pixel_ptr++] = get_r(encoded[1], encoded[6]);
|
|
596 outptr[pixel_ptr++] = get_b(encoded[2], encoded[5]);
|
|
597 outptr[pixel_ptr++] = get_g(encoded[2], encoded[5], encoded[7]);
|
|
598 outptr[pixel_ptr++] = get_r(encoded[2], encoded[7]);
|
|
599 outptr[pixel_ptr++] = get_b(encoded[3], encoded[5]);
|
|
600 outptr[pixel_ptr++] = get_g(encoded[3], encoded[5], encoded[7]);
|
|
601 outptr[pixel_ptr++] = get_r(encoded[3], encoded[7]);
|
|
602 encoded += 8;
|
|
603 }
|
|
604 }
|
|
605 break;
|
|
606 case IMGTYPE_RGB24:
|
|
607 for (row = height - 1; row >= 0; row--) {
|
|
608 pixel_ptr = row * mpi->stride[0];
|
|
609 for (col = 0; col < width; col++) {
|
|
610 outptr[pixel_ptr++] = encoded[0];
|
|
611 outptr[pixel_ptr++] = encoded[1];
|
|
612 outptr[pixel_ptr++] = encoded[2];
|
|
613 encoded += 3;
|
|
614 }
|
|
615 }
|
|
616 break;
|
|
617 case IMGTYPE_YUV411:
|
|
618 for (row = height - 1; row >= 0; row--) {
|
|
619 pixel_ptr = row * mpi->stride[0];
|
|
620 for (col = 0; col < width/4; col++) {
|
|
621 outptr[pixel_ptr++] = get_b(encoded[0], encoded[4]);
|
|
622 outptr[pixel_ptr++] = get_g(encoded[0], encoded[4], encoded[5]);
|
|
623 outptr[pixel_ptr++] = get_r(encoded[0], encoded[5]);
|
|
624 outptr[pixel_ptr++] = get_b(encoded[1], encoded[4]);
|
|
625 outptr[pixel_ptr++] = get_g(encoded[1], encoded[4], encoded[5]);
|
|
626 outptr[pixel_ptr++] = get_r(encoded[1], encoded[5]);
|
|
627 outptr[pixel_ptr++] = get_b(encoded[2], encoded[4]);
|
|
628 outptr[pixel_ptr++] = get_g(encoded[2], encoded[4], encoded[5]);
|
|
629 outptr[pixel_ptr++] = get_r(encoded[2], encoded[5]);
|
|
630 outptr[pixel_ptr++] = get_b(encoded[3], encoded[4]);
|
|
631 outptr[pixel_ptr++] = get_g(encoded[3], encoded[4], encoded[5]);
|
|
632 outptr[pixel_ptr++] = get_r(encoded[3], encoded[5]);
|
|
633 encoded += 6;
|
|
634 }
|
|
635 }
|
|
636 break;
|
|
637 case IMGTYPE_YUV211:
|
|
638 for (row = height - 1; row >= 0; row--) {
|
|
639 pixel_ptr = row * mpi->stride[0];
|
|
640 for (col = 0; col < width/2; col++) {
|
|
641 outptr[pixel_ptr++] = get_b(encoded[0], encoded[2]);
|
|
642 outptr[pixel_ptr++] = get_g(encoded[0], encoded[2], encoded[3]);
|
|
643 outptr[pixel_ptr++] = get_r(encoded[0], encoded[3]);
|
|
644 outptr[pixel_ptr++] = get_b(encoded[1], encoded[2]);
|
|
645 outptr[pixel_ptr++] = get_g(encoded[1], encoded[2], encoded[3]);
|
|
646 outptr[pixel_ptr++] = get_r(encoded[1], encoded[3]);
|
|
647 encoded += 4;
|
|
648 }
|
|
649 }
|
|
650 break;
|
|
651 case IMGTYPE_YUV420:
|
|
652 for (row = height / 2 - 1; row >= 0; row--) {
|
|
653 pixel_ptr = 2 * row * mpi->stride[0];
|
|
654 for (col = 0; col < width/2; col++) {
|
|
655 outptr[pixel_ptr] = get_b(encoded[0], encoded[4]);
|
|
656 outptr[pixel_ptr+1] = get_g(encoded[0], encoded[4], encoded[5]);
|
|
657 outptr[pixel_ptr+2] = get_r(encoded[0], encoded[5]);
|
|
658 outptr[pixel_ptr+3] = get_b(encoded[1], encoded[4]);
|
|
659 outptr[pixel_ptr+4] = get_g(encoded[1], encoded[4], encoded[5]);
|
|
660 outptr[pixel_ptr+5] = get_r(encoded[1], encoded[5]);
|
|
661 outptr[pixel_ptr-mpi->stride[0]] = get_b(encoded[2], encoded[4]);
|
|
662 outptr[pixel_ptr-mpi->stride[0]+1] = get_g(encoded[2], encoded[4], encoded[5]);
|
|
663 outptr[pixel_ptr-mpi->stride[0]+2] = get_r(encoded[2], encoded[5]);
|
|
664 outptr[pixel_ptr-mpi->stride[0]+3] = get_b(encoded[3], encoded[4]);
|
|
665 outptr[pixel_ptr-mpi->stride[0]+4] = get_g(encoded[3], encoded[4], encoded[5]);
|
|
666 outptr[pixel_ptr-mpi->stride[0]+5] = get_r(encoded[3], encoded[5]);
|
|
667 pixel_ptr += 6;
|
|
668 encoded += 6;
|
|
669 }
|
|
670 }
|
|
671 break;
|
|
672 default:
|
|
673 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] BUG! Unknown imagetype in image decoder.\n");
|
|
674 return 0;
|
|
675 }
|
|
676
|
|
677 return mpi;
|
|
678 }
|
|
679
|
|
680
|
|
681
|
|
682 int mszh_decomp(unsigned char * srcptr, int srclen, unsigned char * destptr)
|
|
683 {
|
|
684 unsigned char *destptr_bak = destptr;
|
|
685 unsigned char mask = 0;
|
|
686 unsigned char maskbit = 0;
|
|
687 unsigned int ofs, cnt;
|
|
688
|
|
689 while (srclen > 0) {
|
|
690 if (maskbit == 0) {
|
|
691 mask = *(srcptr++);
|
|
692 maskbit = 8;
|
|
693 srclen--;
|
|
694 continue;
|
|
695 }
|
|
696 if ((mask & (1 << (--maskbit))) == 0) {
|
|
697 *(destptr++) = *(srcptr++);
|
|
698 *(destptr++) = *(srcptr++);
|
|
699 *(destptr++) = *(srcptr++);
|
|
700 *(destptr++) = *(srcptr++);
|
|
701 srclen -= 4;
|
|
702 } else {
|
|
703 ofs = *(srcptr++);
|
|
704 cnt = *(srcptr++);
|
|
705 ofs += cnt * 256;;
|
|
706 cnt = ((cnt >> 3) & 0x1f) + 1;
|
|
707 ofs &= 0x7ff;
|
|
708 srclen -= 2;
|
|
709 cnt *= 4;
|
|
710 for (; cnt > 0; cnt--) {
|
|
711 *(destptr) = *(destptr - ofs);
|
|
712 destptr++;
|
|
713 }
|
|
714 }
|
|
715 }
|
|
716
|
|
717 return (destptr - destptr_bak);
|
|
718 }
|
|
719
|