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 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;
188 outptr = frame->
data[0];
198 mthread_inlen =
AV_RL32(encoded);
203 mthread_inlen =
FFMIN(mthread_inlen, len - 8);
204 mthread_outlen =
AV_RL32(encoded+4);
207 if (mthread_outlen != mszh_dlen) {
209 mthread_outlen, mszh_dlen);
212 mszh_dlen =
mszh_decomp(encoded + 8 + mthread_inlen, len - 8 - mthread_inlen,
214 if (mthread_outlen != mszh_dlen) {
216 mthread_outlen, mszh_dlen);
251 if (len < ((width * height * bppx2) >> 1))
260 #if CONFIG_ZLIB_DECODER
266 len == width * height * 3) {
274 mthread_inlen =
AV_RL32(encoded);
275 mthread_inlen =
FFMIN(mthread_inlen, len - 8);
276 mthread_outlen =
AV_RL32(encoded+4);
278 ret = zlib_decomp(avctx, encoded + 8, mthread_inlen, 0, mthread_outlen);
279 if (ret < 0)
return ret;
280 ret = zlib_decomp(avctx, encoded + 8 + mthread_inlen, len - 8 - mthread_inlen,
281 mthread_outlen, mthread_outlen);
282 if (ret < 0)
return ret;
284 int ret = zlib_decomp(avctx, encoded, len, 0, c->
decomp_size);
285 if (ret < 0)
return ret;
292 av_log(avctx,
AV_LOG_ERROR,
"BUG! Unknown codec in frame decoder compression switch.\n");
302 for (row = 0; row <
height; row++) {
303 pixel_ptr = row * width * 3;
304 yq = encoded[pixel_ptr++];
305 uqvq =
AV_RL16(encoded+pixel_ptr);
307 for (col = 1; col <
width; col++) {
308 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
309 uqvq -=
AV_RL16(encoded+pixel_ptr+1);
310 AV_WL16(encoded+pixel_ptr+1, uqvq);
316 for (row = 0; row <
height; row++) {
317 pixel_ptr = row * width * 2;
319 for (col = 0; col < width/4; col++) {
320 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
321 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
322 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
323 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
324 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
325 encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5];
326 encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6];
327 encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7];
333 for (row = 0; row <
height; row++) {
334 pixel_ptr = row * width / 2 * 3;
336 for (col = 0; col < width/4; col++) {
337 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
338 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
339 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
340 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
341 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
342 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
348 for (row = 0; row <
height; row++) {
349 pixel_ptr = row * width * 2;
351 for (col = 0; col < width/2; col++) {
352 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
353 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
354 encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2];
355 encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3];
361 for (row = 0; row < height/2; row++) {
362 pixel_ptr = row * width * 3;
363 yq = y1q = uq = vq =0;
364 for (col = 0; col < width/2; col++) {
365 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
366 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
367 encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2];
368 encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3];
369 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
370 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
382 y_out = frame->
data[0] + (height - 1) * frame->
linesize[0];
383 u_out = frame->
data[1] + (height - 1) * frame->
linesize[1];
384 v_out = frame->
data[2] + (height - 1) * frame->
linesize[2];
387 for (row = 0; row <
height; row++) {
388 for (col = 0; col <
width; col++) {
389 y_out[col] = *encoded++;
390 u_out[col] = *encoded++ + 128;
391 v_out[col] = *encoded++ + 128;
399 for (row = 0; row <
height; row++) {
400 for (col = 0; col < width - 3; col += 4) {
401 memcpy(y_out + col, encoded, 4);
403 u_out[ col >> 1 ] = *encoded++ + 128;
404 u_out[(col >> 1) + 1] = *encoded++ + 128;
405 v_out[ col >> 1 ] = *encoded++ + 128;
406 v_out[(col >> 1) + 1] = *encoded++ + 128;
414 for (row = height - 1; row >= 0; row--) {
415 pixel_ptr = row * frame->
linesize[0];
416 memcpy(outptr + pixel_ptr, encoded, 3 * width);
417 encoded += 3 *
width;
421 for (row = 0; row <
height; row++) {
422 for (col = 0; col < width - 3; col += 4) {
423 memcpy(y_out + col, encoded, 4);
425 u_out[col >> 2] = *encoded++ + 128;
426 v_out[col >> 2] = *encoded++ + 128;
434 for (row = 0; row <
height; row++) {
435 for (col = 0; col < width - 1; col += 2) {
436 memcpy(y_out + col, encoded, 2);
438 u_out[col >> 1] = *encoded++ + 128;
439 v_out[col >> 1] = *encoded++ + 128;
447 u_out = frame->
data[1] + ((height >> 1) - 1) * frame->
linesize[1];
448 v_out = frame->
data[2] + ((height >> 1) - 1) * frame->
linesize[2];
449 for (row = 0; row < height - 1; row += 2) {
450 for (col = 0; col < width - 1; col += 2) {
451 memcpy(y_out + col, encoded, 2);
453 memcpy(y_out + col - frame->
linesize[0], encoded, 2);
455 u_out[col >> 1] = *encoded++ + 128;
456 v_out[col >> 1] = *encoded++ + 128;
482 unsigned int basesize = avctx->
width * avctx->
height;
485 unsigned int max_decomp_size;
486 int subsample_h, subsample_v;
496 av_log(avctx,
AV_LOG_ERROR,
"Codec id and codec type mismatch. This should not happen.\n");
503 max_decomp_size = max_basesize * 3;
509 max_decomp_size = max_basesize * 2;
512 if (avctx->
width % 4) {
519 max_decomp_size = max_basesize * 3;
525 max_decomp_size = max_basesize / 2 * 3;
531 max_decomp_size = max_basesize * 2;
537 max_decomp_size = max_basesize / 2 * 3;
547 if (avctx->
width % (1<<subsample_h) || avctx->
height % (1<<subsample_v)) {
569 #if CONFIG_ZLIB_DECODER
615 #if CONFIG_ZLIB_DECODER
618 c->zstream.zalloc = Z_NULL;
619 c->zstream.zfree = Z_NULL;
620 c->zstream.opaque = Z_NULL;
621 zret = inflateInit(&c->zstream);
643 #if CONFIG_ZLIB_DECODER
645 inflateEnd(&c->zstream);
651 #if CONFIG_MSZH_DECODER
665 #if CONFIG_ZLIB_DECODER