51 #if CONFIG_ZLIB_DECODER
69 #if CONFIG_ZLIB_DECODER
79 static unsigned int mszh_decomp(
const unsigned char * srcptr,
int srclen,
unsigned char * destptr,
unsigned int destsize)
81 unsigned char *destptr_bak = destptr;
82 unsigned char *destptr_end = destptr + destsize;
83 const unsigned char *srcptr_end = srcptr + srclen;
84 unsigned mask = *srcptr++;
85 unsigned maskbit = 0x80;
87 while (srcptr < srcptr_end && destptr < destptr_end) {
88 if (!(mask & maskbit)) {
89 memcpy(destptr, srcptr, 4);
93 unsigned ofs = bytestream_get_le16(&srcptr);
94 unsigned cnt = (ofs >> 11) + 1;
96 ofs =
FFMIN(ofs, destptr - destptr_bak);
98 cnt =
FFMIN(cnt, destptr_end - destptr);
104 memset(destptr, 0, cnt);
112 if (destptr_end - destptr < 32 || srcptr_end - srcptr < 32)
break;
113 memcpy(destptr, srcptr, 32);
122 return destptr - destptr_bak;
126 #if CONFIG_ZLIB_DECODER
137 int zret = inflateReset(&c->zstream);
142 c->zstream.next_in = (
uint8_t *)src;
143 c->zstream.avail_in = src_len;
146 zret = inflate(&c->zstream, Z_FINISH);
147 if (zret != Z_OK && zret != Z_STREAM_END) {
151 if (expected != (
unsigned int)c->zstream.total_out) {
153 expected, c->zstream.total_out);
156 return c->zstream.total_out;
170 int buf_size = avpkt->
size;
172 unsigned int pixel_ptr;
174 unsigned char *encoded = avpkt->
data, *outptr;
175 uint8_t *y_out, *u_out, *v_out;
178 unsigned int mszh_dlen;
179 unsigned char yq, y1q, uq, vq;
181 unsigned int mthread_inlen, mthread_outlen;
182 unsigned int len = buf_size;
188 outptr = frame->
data[0];
204 mthread_inlen =
FFMIN(mthread_inlen, len - 8);
205 mthread_outlen =
AV_RL32(buf + 4);
208 if (mthread_outlen != mszh_dlen) {
210 mthread_outlen, mszh_dlen);
213 mszh_dlen =
mszh_decomp(buf + 8 + mthread_inlen, len - 8 - mthread_inlen,
215 if (mthread_outlen != mszh_dlen) {
217 mthread_outlen, mszh_dlen);
252 if (len < ((width * height * bppx2) >> 1))
261 #if CONFIG_ZLIB_DECODER
267 len == width * height * 3) {
276 mthread_inlen =
FFMIN(mthread_inlen, len - 8);
277 mthread_outlen =
AV_RL32(buf + 4);
279 ret = zlib_decomp(avctx, buf + 8, mthread_inlen, 0, mthread_outlen);
280 if (ret < 0)
return ret;
281 ret = zlib_decomp(avctx, buf + 8 + mthread_inlen, len - 8 - mthread_inlen,
282 mthread_outlen, mthread_outlen);
283 if (ret < 0)
return ret;
285 int ret = zlib_decomp(avctx, buf, len, 0, c->
decomp_size);
286 if (ret < 0)
return ret;
293 av_log(avctx,
AV_LOG_ERROR,
"BUG! Unknown codec in frame decoder compression switch.\n");
303 for (row = 0; row <
height; row++) {
304 pixel_ptr = row * width * 3;
305 yq = encoded[pixel_ptr++];
306 uqvq =
AV_RL16(encoded+pixel_ptr);
308 for (col = 1; col <
width; col++) {
309 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
310 uqvq -=
AV_RL16(encoded+pixel_ptr+1);
311 AV_WL16(encoded+pixel_ptr+1, uqvq);
317 for (row = 0; row <
height; row++) {
318 pixel_ptr = row * width * 2;
320 for (col = 0; col < width/4; col++) {
321 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
322 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
323 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
324 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
325 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
326 encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5];
327 encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6];
328 encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7];
334 for (row = 0; row <
height; row++) {
335 pixel_ptr = row * width / 2 * 3;
337 for (col = 0; col < width/4; col++) {
338 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
339 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
340 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
341 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
342 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
343 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
349 for (row = 0; row <
height; row++) {
350 pixel_ptr = row * width * 2;
352 for (col = 0; col < width/2; col++) {
353 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
354 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
355 encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2];
356 encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3];
362 for (row = 0; row < height/2; row++) {
363 pixel_ptr = row * width * 3;
364 yq = y1q = uq = vq =0;
365 for (col = 0; col < width/2; col++) {
366 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
367 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
368 encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2];
369 encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3];
370 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
371 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
383 y_out = frame->
data[0] + (height - 1) * frame->
linesize[0];
384 u_out = frame->
data[1] + (height - 1) * frame->
linesize[1];
385 v_out = frame->
data[2] + (height - 1) * frame->
linesize[2];
388 for (row = 0; row <
height; row++) {
389 for (col = 0; col <
width; col++) {
390 y_out[col] = *encoded++;
391 u_out[col] = *encoded++ + 128;
392 v_out[col] = *encoded++ + 128;
400 for (row = 0; row <
height; row++) {
401 for (col = 0; col < width - 3; col += 4) {
402 memcpy(y_out + col, encoded, 4);
404 u_out[ col >> 1 ] = *encoded++ + 128;
405 u_out[(col >> 1) + 1] = *encoded++ + 128;
406 v_out[ col >> 1 ] = *encoded++ + 128;
407 v_out[(col >> 1) + 1] = *encoded++ + 128;
415 linesize = len <
FFALIGN(3 * width, 4) * height ? 3 * width :
FFALIGN(3 * width, 4);
416 for (row = height - 1; row >= 0; row--) {
417 pixel_ptr = row * frame->
linesize[0];
418 memcpy(outptr + pixel_ptr, encoded, 3 * width);
423 for (row = 0; row <
height; row++) {
424 for (col = 0; col < width - 3; col += 4) {
425 memcpy(y_out + col, encoded, 4);
427 u_out[col >> 2] = *encoded++ + 128;
428 v_out[col >> 2] = *encoded++ + 128;
436 for (row = 0; row <
height; row++) {
437 for (col = 0; col < width - 1; col += 2) {
438 memcpy(y_out + col, encoded, 2);
440 u_out[col >> 1] = *encoded++ + 128;
441 v_out[col >> 1] = *encoded++ + 128;
449 u_out = frame->
data[1] + ((height >> 1) - 1) * frame->
linesize[1];
450 v_out = frame->
data[2] + ((height >> 1) - 1) * frame->
linesize[2];
451 for (row = 0; row < height - 1; row += 2) {
452 for (col = 0; col < width - 1; col += 2) {
453 memcpy(y_out + col, encoded, 2);
455 memcpy(y_out + col - frame->
linesize[0], encoded, 2);
457 u_out[col >> 1] = *encoded++ + 128;
458 v_out[col >> 1] = *encoded++ + 128;
484 unsigned int basesize = avctx->
width * avctx->
height;
487 unsigned int max_decomp_size;
488 int subsample_h, subsample_v;
498 av_log(avctx,
AV_LOG_ERROR,
"Codec id and codec type mismatch. This should not happen.\n");
505 max_decomp_size = max_basesize * 3;
511 max_decomp_size = max_basesize * 2;
514 if (avctx->
width % 4) {
521 max_decomp_size = max_basesize * 3;
527 max_decomp_size = max_basesize / 2 * 3;
533 max_decomp_size = max_basesize * 2;
539 max_decomp_size = max_basesize / 2 * 3;
549 if (avctx->
width % (1<<subsample_h) || avctx->
height % (1<<subsample_v)) {
571 #if CONFIG_ZLIB_DECODER
617 #if CONFIG_ZLIB_DECODER
620 c->zstream.zalloc = Z_NULL;
621 c->zstream.zfree = Z_NULL;
622 c->zstream.opaque = Z_NULL;
623 zret = inflateInit(&c->zstream);
645 #if CONFIG_ZLIB_DECODER
647 inflateEnd(&c->zstream);
653 #if CONFIG_MSZH_DECODER
667 #if CONFIG_ZLIB_DECODER