80static 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 if (destptr < destptr_end)
124 memset(destptr, 0, destptr_end - destptr);
126 return destptr - destptr_bak;
174 const uint8_t *buf = avpkt->
data;
175 int buf_size = avpkt->
size;
179 unsigned char *encoded = avpkt->
data, *outptr;
180 uint8_t *y_out, *u_out, *v_out;
183 unsigned int mszh_dlen;
184 unsigned char yq, y1q, uq, vq;
186 unsigned int mthread_inlen, mthread_outlen;
187 unsigned int len = buf_size;
193 outptr =
frame->data[0];
198 switch (
c->compression) {
205 if (
len < 8 ||
len - 8 < mthread_inlen) {
209 mthread_outlen =
AV_RL32(buf + 4);
210 mthread_outlen =
FFMIN(mthread_outlen,
c->decomp_size);
211 mszh_dlen =
mszh_decomp(buf + 8, mthread_inlen,
c->decomp_buf,
c->decomp_size);
212 if (mthread_outlen != mszh_dlen) {
214 mthread_outlen, mszh_dlen);
217 mszh_dlen =
mszh_decomp(buf + 8 + mthread_inlen,
len - 8 - mthread_inlen,
218 c->decomp_buf + mthread_outlen,
c->decomp_size - mthread_outlen);
219 if (mthread_outlen != mszh_dlen) {
221 mthread_outlen, mszh_dlen);
224 encoded =
c->decomp_buf;
225 len =
c->decomp_size;
228 if (
c->decomp_size != mszh_dlen) {
230 c->decomp_size, mszh_dlen);
231 if (
c->decomp_size != mszh_dlen &&
232 c->decomp_size != mszh_dlen + 2)
235 encoded =
c->decomp_buf;
241 int aligned_width =
width;
242 switch (
c->imgtype) {
263 if (
len < ((aligned_width *
height * bppx2) >> 1))
272#if CONFIG_ZLIB_DECODER
280 memcpy(
c->decomp_buf, buf,
len);
281 encoded =
c->decomp_buf;
287 mthread_inlen =
FFMIN(mthread_inlen,
len - 8);
288 mthread_outlen =
AV_RL32(buf + 4);
289 mthread_outlen =
FFMIN(mthread_outlen,
c->decomp_size);
290 ret = zlib_decomp(avctx, buf + 8, mthread_inlen, 0, mthread_outlen);
291 if (ret < 0)
return ret;
292 ret = zlib_decomp(avctx, buf + 8 + mthread_inlen,
len - 8 - mthread_inlen,
293 mthread_outlen, mthread_outlen);
294 if (ret < 0)
return ret;
295 memset(
c->decomp_buf + mthread_outlen + ret, 0,
296 c->decomp_size - mthread_outlen - ret);
297 len =
c->decomp_size;
299 int ret = zlib_decomp(avctx, buf,
len, 0,
c->decomp_size);
300 if (ret < 0)
return ret;
303 encoded =
c->decomp_buf;
307 av_log(avctx,
AV_LOG_ERROR,
"BUG! Unknown codec in frame decoder compression switch.\n");
314 switch (
c->imgtype) {
317 for (row = 0; row <
height; row++) {
318 pixel_ptr = row *
width * 3;
319 yq = encoded[pixel_ptr++];
320 unsigned uqvq =
AV_RL16(encoded+pixel_ptr);
322 for (col = 1; col <
width; col++) {
323 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
324 uqvq -=
AV_RL16(encoded+pixel_ptr+1);
325 AV_WL16(encoded+pixel_ptr+1, uqvq);
332 for (row = 0; row <
height; row++) {
334 for (col = 0; col <
width/4; col++) {
335 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
336 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
337 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
338 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
339 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
340 encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5];
341 encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6];
342 encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7];
349 for (row = 0; row <
height; row++) {
351 for (col = 0; col <
width/4; col++) {
352 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
353 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
354 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
355 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
356 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
357 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
363 for (row = 0; row <
height; row++) {
364 pixel_ptr = row *
width * 2;
366 for (col = 0; col <
width/2; col++) {
367 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
368 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
369 encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2];
370 encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3];
376 for (row = 0; row <
height/2; row++) {
377 pixel_ptr = row *
width * 3;
378 yq = y1q = uq = vq =0;
379 for (col = 0; col <
width/2; col++) {
380 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
381 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
382 encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2];
383 encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3];
384 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
385 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
402 switch (
c->imgtype) {
404 for (row = 0; row <
height; row++) {
405 for (col = 0; col <
width; col++) {
406 y_out[col] = *encoded++;
407 u_out[col] = *encoded++ + 128;
408 v_out[col] = *encoded++ + 128;
410 y_out -=
frame->linesize[0];
411 u_out -=
frame->linesize[1];
412 v_out -=
frame->linesize[2];
416 for (row = 0; row <
height; row++) {
417 for (col = 0; col <
width - 3; col += 4) {
418 memcpy(y_out + col, encoded, 4);
420 u_out[ col >> 1 ] = *encoded++ + 128;
421 u_out[(col >> 1) + 1] = *encoded++ + 128;
422 v_out[ col >> 1 ] = *encoded++ + 128;
423 v_out[(col >> 1) + 1] = *encoded++ + 128;
425 if (col && col <
width) {
426 u_out[ col >> 1 ] = u_out[(col>>1) - 1];
427 v_out[ col >> 1 ] = v_out[(col>>1) - 1];
430 y_out -=
frame->linesize[0];
431 u_out -=
frame->linesize[1];
432 v_out -=
frame->linesize[2];
437 for (row =
height - 1; row >= 0; row--) {
438 pixel_ptr = row *
frame->linesize[0];
439 memcpy(outptr + pixel_ptr, encoded, 3 *
width);
444 for (row = 0; row <
height; row++) {
445 for (col = 0; col <
width - 3; col += 4) {
446 memcpy(y_out + col, encoded, 4);
448 u_out[col >> 2] = *encoded++ + 128;
449 v_out[col >> 2] = *encoded++ + 128;
451 if (col && col <
width) {
452 u_out[col >> 2] = u_out[(col>>2) - 1];
453 v_out[col >> 2] = v_out[(col>>2) - 1];
455 y_out -=
frame->linesize[0];
456 u_out -=
frame->linesize[1];
457 v_out -=
frame->linesize[2];
461 for (row = 0; row <
height; row++) {
462 for (col = 0; col <
width - 1; col += 2) {
463 memcpy(y_out + col, encoded, 2);
465 u_out[col >> 1] = *encoded++ + 128;
466 v_out[col >> 1] = *encoded++ + 128;
468 y_out -=
frame->linesize[0];
469 u_out -=
frame->linesize[1];
470 v_out -=
frame->linesize[2];
476 for (row = 0; row <
height - 1; row += 2) {
477 for (col = 0; col <
width - 1; col += 2) {
478 memcpy(y_out + col, encoded, 2);
480 memcpy(y_out + col -
frame->linesize[0], encoded, 2);
482 u_out[col >> 1] = *encoded++ + 128;
483 v_out[col >> 1] = *encoded++ + 128;
485 y_out -=
frame->linesize[0] << 1;
486 u_out -=
frame->linesize[1];
487 v_out -=
frame->linesize[2];
504 unsigned int basesize = avctx->
width * avctx->
height;
507 unsigned int max_decomp_size;
508 int subsample_h, subsample_v;
509 int partial_h_supported = 0;
519 av_log(avctx,
AV_LOG_ERROR,
"Codec id and codec type mismatch. This should not happen.\n");
525 c->decomp_size = basesize * 3;
526 max_decomp_size = max_basesize * 3;
531 c->decomp_size = (avctx->
width & ~3) * avctx->
height * 2;
532 max_decomp_size = max_basesize * 2;
535 partial_h_supported = 1;
539 max_decomp_size = max_basesize * 3;
544 c->decomp_size = (avctx->
width & ~3) * avctx->
height / 2 * 3;
545 max_decomp_size = max_basesize / 2 * 3;
548 partial_h_supported = 1;
551 c->decomp_size = basesize * 2;
552 max_decomp_size = max_basesize * 2;
557 c->decomp_size = basesize / 2 * 3;
558 max_decomp_size = max_basesize / 2 * 3;
568 if ((avctx->
width % (1<<subsample_h) && !partial_h_supported) || avctx->
height % (1<<subsample_v)) {
577 switch (
c->compression) {
586 av_log(avctx,
AV_LOG_ERROR,
"Unsupported compression format for MSZH (%d).\n",
c->compression);
590#if CONFIG_ZLIB_DECODER
592 switch (
c->compression) {
603 if (
c->compression < Z_NO_COMPRESSION ||
c->compression > Z_BEST_COMPRESSION) {
604 av_log(avctx,
AV_LOG_ERROR,
"Unsupported compression level for ZLIB: (%d).\n",
c->compression);
617 if (
c->decomp_size) {
618 if (!(
c->decomp_buf =
av_malloc(max_decomp_size))) {
636#if CONFIG_ZLIB_DECODER
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.