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);
210 mthread_inlen =
FFMIN(mthread_inlen, len - 8);
211 mthread_outlen =
AV_RL32(encoded+4);
214 if (mthread_outlen != mszh_dlen) {
216 mthread_outlen, mszh_dlen);
219 mszh_dlen =
mszh_decomp(encoded + 8 + mthread_inlen, len - 8 - mthread_inlen,
221 if (mthread_outlen != mszh_dlen) {
223 mthread_outlen, mszh_dlen);
258 if (len < ((width * height * bppx2) >> 1))
267 #if CONFIG_ZLIB_DECODER
273 len == width * height * 3) {
281 mthread_inlen =
AV_RL32(encoded);
282 mthread_inlen =
FFMIN(mthread_inlen, len - 8);
283 mthread_outlen =
AV_RL32(encoded+4);
285 ret = zlib_decomp(avctx, encoded + 8, mthread_inlen, 0, mthread_outlen);
286 if (ret < 0)
return ret;
287 ret = zlib_decomp(avctx, encoded + 8 + mthread_inlen, len - 8 - mthread_inlen,
288 mthread_outlen, mthread_outlen);
289 if (ret < 0)
return ret;
291 int ret = zlib_decomp(avctx, encoded, len, 0, c->
decomp_size);
292 if (ret < 0)
return ret;
299 av_log(avctx,
AV_LOG_ERROR,
"BUG! Unknown codec in frame decoder compression switch.\n");
309 for (row = 0; row <
height; row++) {
310 pixel_ptr = row * width * 3;
311 yq = encoded[pixel_ptr++];
312 uqvq =
AV_RL16(encoded+pixel_ptr);
314 for (col = 1; col <
width; col++) {
315 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
316 uqvq -=
AV_RL16(encoded+pixel_ptr+1);
317 AV_WL16(encoded+pixel_ptr+1, uqvq);
323 for (row = 0; row <
height; row++) {
324 pixel_ptr = row * width * 2;
326 for (col = 0; col < width/4; col++) {
327 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
328 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
329 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
330 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
331 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
332 encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5];
333 encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6];
334 encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7];
340 for (row = 0; row <
height; row++) {
341 pixel_ptr = row * width / 2 * 3;
343 for (col = 0; col < width/4; col++) {
344 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
345 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
346 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
347 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
348 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
349 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
355 for (row = 0; row <
height; row++) {
356 pixel_ptr = row * width * 2;
358 for (col = 0; col < width/2; col++) {
359 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
360 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
361 encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2];
362 encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3];
368 for (row = 0; row < height/2; row++) {
369 pixel_ptr = row * width * 3;
370 yq = y1q = uq = vq =0;
371 for (col = 0; col < width/2; col++) {
372 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
373 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
374 encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2];
375 encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3];
376 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
377 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
394 for (row = 0; row <
height; row++) {
395 for (col = 0; col <
width; col++) {
396 y_out[col] = *encoded++;
397 u_out[col] = *encoded++ + 128;
398 v_out[col] = *encoded++ + 128;
406 for (row = 0; row <
height; row++) {
407 for (col = 0; col < width - 3; col += 4) {
408 memcpy(y_out + col, encoded, 4);
410 u_out[ col >> 1 ] = *encoded++ + 128;
411 u_out[(col >> 1) + 1] = *encoded++ + 128;
412 v_out[ col >> 1 ] = *encoded++ + 128;
413 v_out[(col >> 1) + 1] = *encoded++ + 128;
421 for (row = height - 1; row >= 0; row--) {
423 memcpy(outptr + pixel_ptr, encoded, 3 * width);
424 encoded += 3 *
width;
428 for (row = 0; row <
height; row++) {
429 for (col = 0; col < width - 3; col += 4) {
430 memcpy(y_out + col, encoded, 4);
432 u_out[col >> 2] = *encoded++ + 128;
433 v_out[col >> 2] = *encoded++ + 128;
441 for (row = 0; row <
height; row++) {
442 for (col = 0; col < width - 1; col += 2) {
443 memcpy(y_out + col, encoded, 2);
445 u_out[col >> 1] = *encoded++ + 128;
446 v_out[col >> 1] = *encoded++ + 128;
456 for (row = 0; row < height - 1; row += 2) {
457 for (col = 0; col < width - 1; col += 2) {
458 memcpy(y_out + col, encoded, 2);
460 memcpy(y_out + col - c->
pic.
linesize[0], encoded, 2);
462 u_out[col >> 1] = *encoded++ + 128;
463 v_out[col >> 1] = *encoded++ + 128;
490 unsigned int basesize = avctx->
width * avctx->
height;
493 unsigned int max_decomp_size;
504 av_log(avctx,
AV_LOG_ERROR,
"Codec id and codec type mismatch. This should not happen.\n");
511 max_decomp_size = max_basesize * 3;
517 max_decomp_size = max_basesize * 2;
523 max_decomp_size = max_basesize * 3;
529 max_decomp_size = max_basesize / 2 * 3;
535 max_decomp_size = max_basesize * 2;
541 max_decomp_size = max_basesize / 2 * 3;
567 #if CONFIG_ZLIB_DECODER
613 #if CONFIG_ZLIB_DECODER
616 c->zstream.zalloc = Z_NULL;
617 c->zstream.zfree = Z_NULL;
618 c->zstream.opaque = Z_NULL;
619 zret = inflateInit(&c->zstream);
643 #if CONFIG_ZLIB_DECODER
645 inflateEnd(&c->zstream);
651 #if CONFIG_MSZH_DECODER
665 #if CONFIG_ZLIB_DECODER