50 #if CONFIG_ZLIB_DECODER
70 #if CONFIG_ZLIB_DECODER
80 static unsigned int mszh_decomp(
const unsigned char * srcptr,
int srclen,
unsigned char * destptr,
unsigned int destsize)
82 unsigned char *destptr_bak = destptr;
83 unsigned char *destptr_end = destptr + destsize;
84 const unsigned char *srcptr_end = srcptr + srclen;
85 unsigned mask = *srcptr++;
86 unsigned maskbit = 0x80;
88 while (srcptr < srcptr_end && destptr < destptr_end) {
89 if (!(mask & maskbit)) {
90 memcpy(destptr, srcptr, 4);
94 unsigned ofs = bytestream_get_le16(&srcptr);
95 unsigned cnt = (ofs >> 11) + 1;
97 ofs =
FFMIN(ofs, destptr - destptr_bak);
99 cnt =
FFMIN(cnt, destptr_end - destptr);
105 memset(destptr, 0, cnt);
113 if (destptr_end - destptr < 32 || srcptr_end - srcptr < 32)
break;
114 memcpy(destptr, srcptr, 32);
123 return destptr - destptr_bak;
127 #if CONFIG_ZLIB_DECODER
138 int zret = inflateReset(&c->zstream);
143 c->zstream.next_in = (
uint8_t *)src;
144 c->zstream.avail_in = src_len;
147 zret = inflate(&c->zstream, Z_FINISH);
148 if (zret != Z_OK && zret != Z_STREAM_END) {
152 if (expected != (
unsigned int)c->zstream.total_out) {
154 expected, c->zstream.total_out);
157 return c->zstream.total_out;
170 int buf_size = avpkt->
size;
172 unsigned char *encoded = (
unsigned char *)buf;
173 unsigned int pixel_ptr;
175 unsigned char *outptr;
176 uint8_t *y_out, *u_out, *v_out;
179 unsigned int mszh_dlen;
180 unsigned char yq, y1q, uq, vq;
182 unsigned int mthread_inlen, mthread_outlen;
183 unsigned int len = buf_size;
205 mthread_inlen =
AV_RL32(encoded);
206 mthread_inlen =
FFMIN(mthread_inlen, len - 8);
207 mthread_outlen =
AV_RL32(encoded+4);
210 if (mthread_outlen != mszh_dlen) {
212 mthread_outlen, mszh_dlen);
215 mszh_dlen =
mszh_decomp(encoded + 8 + mthread_inlen, len - 8 - mthread_inlen,
217 if (mthread_outlen != mszh_dlen) {
219 mthread_outlen, mszh_dlen);
254 if (len < ((width * height * bppx2) >> 1))
263 #if CONFIG_ZLIB_DECODER
269 len == width * height * 3) {
278 mthread_inlen =
AV_RL32(encoded);
279 mthread_inlen =
FFMIN(mthread_inlen, len - 8);
280 mthread_outlen =
AV_RL32(encoded+4);
282 ret = zlib_decomp(avctx, encoded + 8, mthread_inlen, 0, mthread_outlen);
283 if (ret < 0)
return ret;
284 ret = zlib_decomp(avctx, encoded + 8 + mthread_inlen, len - 8 - mthread_inlen,
285 mthread_outlen, mthread_outlen);
286 if (ret < 0)
return ret;
288 int ret = zlib_decomp(avctx, encoded, len, 0, c->
decomp_size);
289 if (ret < 0)
return ret;
296 av_log(avctx,
AV_LOG_ERROR,
"BUG! Unknown codec in frame decoder compression switch.\n");
306 for (row = 0; row <
height; row++) {
307 pixel_ptr = row * width * 3;
308 yq = encoded[pixel_ptr++];
309 uqvq =
AV_RL16(encoded+pixel_ptr);
311 for (col = 1; col <
width; col++) {
312 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
313 uqvq -=
AV_RL16(encoded+pixel_ptr+1);
314 AV_WL16(encoded+pixel_ptr+1, uqvq);
320 for (row = 0; row <
height; row++) {
321 pixel_ptr = row * width * 2;
323 for (col = 0; col < width/4; col++) {
324 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
325 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
326 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
327 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
328 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
329 encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5];
330 encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6];
331 encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7];
337 for (row = 0; row <
height; row++) {
338 pixel_ptr = row * width / 2 * 3;
340 for (col = 0; col < width/4; col++) {
341 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
342 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
343 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
344 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
345 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
346 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
352 for (row = 0; row <
height; row++) {
353 pixel_ptr = row * width * 2;
355 for (col = 0; col < width/2; col++) {
356 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
357 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
358 encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2];
359 encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3];
365 for (row = 0; row < height/2; row++) {
366 pixel_ptr = row * width * 3;
367 yq = y1q = uq = vq =0;
368 for (col = 0; col < width/2; col++) {
369 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
370 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
371 encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2];
372 encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3];
373 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
374 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
391 for (row = 0; row <
height; row++) {
392 for (col = 0; col <
width; col++) {
393 y_out[col] = *encoded++;
394 u_out[col] = *encoded++ + 128;
395 v_out[col] = *encoded++ + 128;
403 for (row = 0; row <
height; row++) {
404 for (col = 0; col < width - 3; col += 4) {
405 memcpy(y_out + col, encoded, 4);
407 u_out[ col >> 1 ] = *encoded++ + 128;
408 u_out[(col >> 1) + 1] = *encoded++ + 128;
409 v_out[ col >> 1 ] = *encoded++ + 128;
410 v_out[(col >> 1) + 1] = *encoded++ + 128;
418 for (row = height - 1; row >= 0; row--) {
420 memcpy(outptr + pixel_ptr, encoded, 3 * width);
421 encoded += 3 *
width;
425 for (row = 0; row <
height; row++) {
426 for (col = 0; col < width - 3; col += 4) {
427 memcpy(y_out + col, encoded, 4);
429 u_out[col >> 2] = *encoded++ + 128;
430 v_out[col >> 2] = *encoded++ + 128;
438 for (row = 0; row <
height; row++) {
439 for (col = 0; col < width - 1; col += 2) {
440 memcpy(y_out + col, encoded, 2);
442 u_out[col >> 1] = *encoded++ + 128;
443 v_out[col >> 1] = *encoded++ + 128;
453 for (row = 0; row < height - 1; row += 2) {
454 for (col = 0; col < width - 1; col += 2) {
455 memcpy(y_out + col, encoded, 2);
457 memcpy(y_out + col - c->
pic.
linesize[0], encoded, 2);
459 u_out[col >> 1] = *encoded++ + 128;
460 v_out[col >> 1] = *encoded++ + 128;
487 unsigned int basesize = avctx->
width * avctx->
height;
490 unsigned int max_decomp_size;
501 av_log(avctx,
AV_LOG_ERROR,
"Codec id and codec type mismatch. This should not happen.\n");
508 max_decomp_size = max_basesize * 3;
514 max_decomp_size = max_basesize * 2;
520 max_decomp_size = max_basesize * 3;
526 max_decomp_size = max_basesize / 2 * 3;
532 max_decomp_size = max_basesize * 2;
538 max_decomp_size = max_basesize / 2 * 3;
564 #if CONFIG_ZLIB_DECODER
610 #if CONFIG_ZLIB_DECODER
613 c->zstream.zalloc = Z_NULL;
614 c->zstream.zfree = Z_NULL;
615 c->zstream.opaque = Z_NULL;
616 zret = inflateInit(&c->zstream);
640 #if CONFIG_ZLIB_DECODER
642 inflateEnd(&c->zstream);
648 #if CONFIG_MSZH_DECODER
662 #if CONFIG_ZLIB_DECODER