|
|
|
@ -115,9 +115,9 @@ static unsigned int mszh_decomp(unsigned char * srcptr, int srclen, unsigned cha |
|
|
|
|
unsigned char maskbit = 0; |
|
|
|
|
unsigned int ofs, cnt; |
|
|
|
|
|
|
|
|
|
while ((srclen > 0) && (destptr < destptr_end)) { |
|
|
|
|
while (srclen > 0 && destptr < destptr_end) { |
|
|
|
|
if (maskbit == 0) { |
|
|
|
|
mask = *(srcptr++); |
|
|
|
|
mask = *srcptr++; |
|
|
|
|
maskbit = 8; |
|
|
|
|
srclen--; |
|
|
|
|
continue; |
|
|
|
@ -130,8 +130,8 @@ static unsigned int mszh_decomp(unsigned char * srcptr, int srclen, unsigned cha |
|
|
|
|
destptr += 4; |
|
|
|
|
srcptr += 4; |
|
|
|
|
} else { |
|
|
|
|
ofs = *(srcptr++); |
|
|
|
|
cnt = *(srcptr++); |
|
|
|
|
ofs = *srcptr++; |
|
|
|
|
cnt = *srcptr++; |
|
|
|
|
ofs += cnt * 256; |
|
|
|
|
cnt = ((cnt >> 3) & 0x1f) + 1; |
|
|
|
|
ofs &= 0x7ff; |
|
|
|
@ -141,13 +141,13 @@ static unsigned int mszh_decomp(unsigned char * srcptr, int srclen, unsigned cha |
|
|
|
|
cnt = destptr_end - destptr; |
|
|
|
|
} |
|
|
|
|
for (; cnt > 0; cnt--) { |
|
|
|
|
*(destptr) = *(destptr - ofs); |
|
|
|
|
*destptr = *(destptr - ofs); |
|
|
|
|
destptr++; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return (destptr - destptr_bak); |
|
|
|
|
return destptr - destptr_bak; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -195,8 +195,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac |
|
|
|
|
switch (c->compression) { |
|
|
|
|
case COMP_MSZH: |
|
|
|
|
if (c->flags & FLAG_MULTITHREAD) { |
|
|
|
|
mthread_inlen = *((unsigned int*)encoded); |
|
|
|
|
mthread_outlen = *((unsigned int*)(encoded+4)); |
|
|
|
|
mthread_inlen = *(unsigned int*)encoded; |
|
|
|
|
mthread_outlen = *(unsigned int*)(encoded+4); |
|
|
|
|
if (mthread_outlen > c->decomp_size) // this should not happen
|
|
|
|
|
mthread_outlen = c->decomp_size; |
|
|
|
|
mszh_dlen = mszh_decomp(encoded + 8, mthread_inlen, c->decomp_buf, c->decomp_size); |
|
|
|
@ -237,34 +237,34 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac |
|
|
|
|
/* Using the original dll with normal compression (-1) and RGB format
|
|
|
|
|
* gives a file with ZLIB fourcc, but frame is really uncompressed. |
|
|
|
|
* To be sure that's true check also frame size */ |
|
|
|
|
if ((c->compression == COMP_ZLIB_NORMAL) && (c->imgtype == IMGTYPE_RGB24) && |
|
|
|
|
(len == width * height * 3)) |
|
|
|
|
if (c->compression == COMP_ZLIB_NORMAL && c->imgtype == IMGTYPE_RGB24 && |
|
|
|
|
len == width * height * 3) |
|
|
|
|
break; |
|
|
|
|
zret = inflateReset(&(c->zstream)); |
|
|
|
|
zret = inflateReset(&c->zstream); |
|
|
|
|
if (zret != Z_OK) { |
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret); |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
if (c->flags & FLAG_MULTITHREAD) { |
|
|
|
|
mthread_inlen = *((unsigned int*)encoded); |
|
|
|
|
mthread_outlen = *((unsigned int*)(encoded+4)); |
|
|
|
|
mthread_inlen = *(unsigned int*)encoded; |
|
|
|
|
mthread_outlen = *(unsigned int*)(encoded+4); |
|
|
|
|
if (mthread_outlen > c->decomp_size) |
|
|
|
|
mthread_outlen = c->decomp_size; |
|
|
|
|
c->zstream.next_in = encoded + 8; |
|
|
|
|
c->zstream.avail_in = mthread_inlen; |
|
|
|
|
c->zstream.next_out = c->decomp_buf; |
|
|
|
|
c->zstream.avail_out = c->decomp_size; |
|
|
|
|
zret = inflate(&(c->zstream), Z_FINISH); |
|
|
|
|
if ((zret != Z_OK) && (zret != Z_STREAM_END)) { |
|
|
|
|
zret = inflate(&c->zstream, Z_FINISH); |
|
|
|
|
if (zret != Z_OK && zret != Z_STREAM_END) { |
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Mthread1 inflate error: %d\n", zret); |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
if (mthread_outlen != (unsigned int)(c->zstream.total_out)) { |
|
|
|
|
if (mthread_outlen != (unsigned int)c->zstream.total_out) { |
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Mthread1 decoded size differs (%u != %lu)\n", |
|
|
|
|
mthread_outlen, c->zstream.total_out); |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
zret = inflateReset(&(c->zstream)); |
|
|
|
|
zret = inflateReset(&c->zstream); |
|
|
|
|
if (zret != Z_OK) { |
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Mthread2 inflate reset error: %d\n", zret); |
|
|
|
|
return -1; |
|
|
|
@ -273,12 +273,12 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac |
|
|
|
|
c->zstream.avail_in = len - mthread_inlen; |
|
|
|
|
c->zstream.next_out = c->decomp_buf + mthread_outlen; |
|
|
|
|
c->zstream.avail_out = c->decomp_size - mthread_outlen; |
|
|
|
|
zret = inflate(&(c->zstream), Z_FINISH); |
|
|
|
|
if ((zret != Z_OK) && (zret != Z_STREAM_END)) { |
|
|
|
|
zret = inflate(&c->zstream, Z_FINISH); |
|
|
|
|
if (zret != Z_OK && zret != Z_STREAM_END) { |
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Mthread2 inflate error: %d\n", zret); |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
if (mthread_outlen != (unsigned int)(c->zstream.total_out)) { |
|
|
|
|
if (mthread_outlen != (unsigned int)c->zstream.total_out) { |
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Mthread2 decoded size differs (%d != %lu)\n", |
|
|
|
|
mthread_outlen, c->zstream.total_out); |
|
|
|
|
return -1; |
|
|
|
@ -288,12 +288,12 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac |
|
|
|
|
c->zstream.avail_in = len; |
|
|
|
|
c->zstream.next_out = c->decomp_buf; |
|
|
|
|
c->zstream.avail_out = c->decomp_size; |
|
|
|
|
zret = inflate(&(c->zstream), Z_FINISH); |
|
|
|
|
if ((zret != Z_OK) && (zret != Z_STREAM_END)) { |
|
|
|
|
zret = inflate(&c->zstream, Z_FINISH); |
|
|
|
|
if (zret != Z_OK && zret != Z_STREAM_END) { |
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", zret); |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
if (c->decomp_size != (unsigned int)(c->zstream.total_out)) { |
|
|
|
|
if (c->decomp_size != (unsigned int)c->zstream.total_out) { |
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %lu)\n", |
|
|
|
|
c->decomp_size, c->zstream.total_out); |
|
|
|
|
return -1; |
|
|
|
@ -313,7 +313,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Apply PNG filter */ |
|
|
|
|
if ((avctx->codec_id == CODEC_ID_ZLIB) && (c->flags & FLAG_PNGFILTER)) { |
|
|
|
|
if (avctx->codec_id == CODEC_ID_ZLIB && (c->flags & FLAG_PNGFILTER)) { |
|
|
|
|
switch (c->imgtype) { |
|
|
|
|
case IMGTYPE_YUV111: |
|
|
|
|
case IMGTYPE_RGB24: |
|
|
|
@ -524,7 +524,7 @@ static av_cold int decode_init(AVCodecContext *avctx) |
|
|
|
|
|
|
|
|
|
#if CONFIG_ZLIB |
|
|
|
|
// Needed if zlib unused or init aborted before inflateInit
|
|
|
|
|
memset(&(c->zstream), 0, sizeof(z_stream)); |
|
|
|
|
memset(&c->zstream, 0, sizeof(z_stream)); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
if (avctx->extradata_size < 8) { |
|
|
|
@ -537,8 +537,8 @@ static av_cold int decode_init(AVCodecContext *avctx) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Check codec type */ |
|
|
|
|
if (((avctx->codec_id == CODEC_ID_MSZH) && (*((char *)avctx->extradata + 7) != CODEC_MSZH)) || |
|
|
|
|
((avctx->codec_id == CODEC_ID_ZLIB) && (*((char *)avctx->extradata + 7) != CODEC_ZLIB))) { |
|
|
|
|
if ((avctx->codec_id == CODEC_ID_MSZH && *((char *)avctx->extradata + 7) != CODEC_MSZH) || |
|
|
|
|
(avctx->codec_id == CODEC_ID_ZLIB && *((char *)avctx->extradata + 7) != CODEC_ZLIB)) { |
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Codec id and codec type mismatch. This should not happen.\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -609,7 +609,7 @@ static av_cold int decode_init(AVCodecContext *avctx) |
|
|
|
|
av_log(avctx, AV_LOG_INFO, "Normal compression.\n"); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
if ((c->compression < Z_NO_COMPRESSION) || (c->compression > Z_BEST_COMPRESSION)) { |
|
|
|
|
if (c->compression < Z_NO_COMPRESSION || c->compression > Z_BEST_COMPRESSION) { |
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Unsupported compression level for ZLIB: (%d).\n", c->compression); |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
@ -650,7 +650,7 @@ static av_cold int decode_init(AVCodecContext *avctx) |
|
|
|
|
c->zstream.zalloc = Z_NULL; |
|
|
|
|
c->zstream.zfree = Z_NULL; |
|
|
|
|
c->zstream.opaque = Z_NULL; |
|
|
|
|
zret = inflateInit(&(c->zstream)); |
|
|
|
|
zret = inflateInit(&c->zstream); |
|
|
|
|
if (zret != Z_OK) { |
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); |
|
|
|
|
return 1; |
|
|
|
@ -678,7 +678,7 @@ static av_cold int decode_end(AVCodecContext *avctx) |
|
|
|
|
if (c->pic.data[0]) |
|
|
|
|
avctx->release_buffer(avctx, &c->pic); |
|
|
|
|
#if CONFIG_ZLIB |
|
|
|
|
inflateEnd(&(c->zstream)); |
|
|
|
|
inflateEnd(&c->zstream); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|