50 #if CONFIG_ZLIB_DECODER
68 #if CONFIG_ZLIB_DECODER
78 static unsigned int mszh_decomp(
const unsigned char * srcptr,
int srclen,
unsigned char * destptr,
unsigned int destsize)
80 unsigned char *destptr_bak = destptr;
81 unsigned char *destptr_end = destptr + destsize;
82 const unsigned char *srcptr_end = srcptr + srclen;
83 unsigned mask = *srcptr++;
84 unsigned maskbit = 0x80;
86 while (srcptr < srcptr_end && destptr < destptr_end) {
87 if (!(mask & maskbit)) {
88 memcpy(destptr, srcptr, 4);
92 unsigned ofs = bytestream_get_le16(&srcptr);
93 unsigned cnt = (ofs >> 11) + 1;
95 ofs =
FFMIN(ofs, destptr - destptr_bak);
97 cnt =
FFMIN(cnt, destptr_end - destptr);
105 if (destptr_end - destptr < 32 || srcptr_end - srcptr < 32)
break;
106 memcpy(destptr, srcptr, 32);
115 return destptr - destptr_bak;
119 #if CONFIG_ZLIB_DECODER
127 static int zlib_decomp(
AVCodecContext *avctx,
const uint8_t *src,
int src_len,
int offset,
int expected)
130 int zret = inflateReset(&c->zstream);
135 c->zstream.next_in = src;
136 c->zstream.avail_in = src_len;
139 zret = inflate(&c->zstream, Z_FINISH);
140 if (zret != Z_OK && zret != Z_STREAM_END) {
144 if (expected != (
unsigned int)c->zstream.total_out) {
146 expected, c->zstream.total_out);
149 return c->zstream.total_out;
163 int buf_size = avpkt->
size;
165 unsigned char *encoded = (
unsigned char *)buf;
166 unsigned int pixel_ptr;
168 unsigned char *outptr;
169 uint8_t *y_out, *u_out, *v_out;
172 unsigned int mszh_dlen;
173 unsigned char yq, y1q, uq, vq;
175 unsigned int mthread_inlen, mthread_outlen;
176 unsigned int len = buf_size;
183 outptr = frame->
data[0];
191 mthread_inlen =
AV_RL32(encoded);
192 mthread_inlen =
FFMIN(mthread_inlen, len - 8);
193 mthread_outlen =
AV_RL32(encoded+4);
196 if (mthread_outlen != mszh_dlen) {
198 mthread_outlen, mszh_dlen);
201 mszh_dlen =
mszh_decomp(encoded + 8 + mthread_inlen, len - 8 - mthread_inlen,
203 if (mthread_outlen != mszh_dlen) {
205 mthread_outlen, mszh_dlen);
240 if (len < ((width * height * bppx2) >> 1))
249 #if CONFIG_ZLIB_DECODER
255 len == width * height * 3) {
263 mthread_inlen =
AV_RL32(encoded);
264 mthread_inlen =
FFMIN(mthread_inlen, len - 8);
265 mthread_outlen =
AV_RL32(encoded+4);
267 ret = zlib_decomp(avctx, encoded + 8, mthread_inlen, 0, mthread_outlen);
268 if (ret < 0)
return ret;
269 ret = zlib_decomp(avctx, encoded + 8 + mthread_inlen, len - 8 - mthread_inlen,
270 mthread_outlen, mthread_outlen);
271 if (ret < 0)
return ret;
273 int ret = zlib_decomp(avctx, encoded, len, 0, c->
decomp_size);
274 if (ret < 0)
return ret;
281 av_log(avctx,
AV_LOG_ERROR,
"BUG! Unknown codec in frame decoder compression switch.\n");
291 for (row = 0; row <
height; row++) {
292 pixel_ptr = row * width * 3;
293 yq = encoded[pixel_ptr++];
294 uqvq =
AV_RL16(encoded+pixel_ptr);
296 for (col = 1; col <
width; col++) {
297 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
298 uqvq -=
AV_RL16(encoded+pixel_ptr+1);
299 AV_WL16(encoded+pixel_ptr+1, uqvq);
305 for (row = 0; row <
height; row++) {
306 pixel_ptr = row * width * 2;
308 for (col = 0; col < width/4; col++) {
309 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
310 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
311 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
312 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
313 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
314 encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5];
315 encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6];
316 encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7];
322 for (row = 0; row <
height; row++) {
323 pixel_ptr = row * width / 2 * 3;
325 for (col = 0; col < width/4; col++) {
326 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
327 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
328 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
329 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
330 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
331 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
337 for (row = 0; row <
height; row++) {
338 pixel_ptr = row * width * 2;
340 for (col = 0; col < width/2; col++) {
341 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
342 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
343 encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2];
344 encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3];
350 for (row = 0; row < height/2; row++) {
351 pixel_ptr = row * width * 3;
352 yq = y1q = uq = vq =0;
353 for (col = 0; col < width/2; col++) {
354 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
355 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
356 encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2];
357 encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3];
358 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
359 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
371 y_out = frame->
data[0] + (height - 1) * frame->
linesize[0];
372 u_out = frame->
data[1] + (height - 1) * frame->
linesize[1];
373 v_out = frame->
data[2] + (height - 1) * frame->
linesize[2];
376 for (row = 0; row <
height; row++) {
377 for (col = 0; col <
width; col++) {
378 y_out[col] = *encoded++;
379 u_out[col] = *encoded++ + 128;
380 v_out[col] = *encoded++ + 128;
388 for (row = 0; row <
height; row++) {
389 for (col = 0; col < width - 3; col += 4) {
390 memcpy(y_out + col, encoded, 4);
392 u_out[ col >> 1 ] = *encoded++ + 128;
393 u_out[(col >> 1) + 1] = *encoded++ + 128;
394 v_out[ col >> 1 ] = *encoded++ + 128;
395 v_out[(col >> 1) + 1] = *encoded++ + 128;
403 for (row = height - 1; row >= 0; row--) {
404 pixel_ptr = row * frame->
linesize[0];
405 memcpy(outptr + pixel_ptr, encoded, 3 * width);
406 encoded += 3 *
width;
410 for (row = 0; row <
height; row++) {
411 for (col = 0; col < width - 3; col += 4) {
412 memcpy(y_out + col, encoded, 4);
414 u_out[col >> 2] = *encoded++ + 128;
415 v_out[col >> 2] = *encoded++ + 128;
423 for (row = 0; row <
height; row++) {
424 for (col = 0; col < width - 1; col += 2) {
425 memcpy(y_out + col, encoded, 2);
427 u_out[col >> 1] = *encoded++ + 128;
428 v_out[col >> 1] = *encoded++ + 128;
436 u_out = frame->
data[1] + ((height >> 1) - 1) * frame->
linesize[1];
437 v_out = frame->
data[2] + ((height >> 1) - 1) * frame->
linesize[2];
438 for (row = 0; row < height - 1; row += 2) {
439 for (col = 0; col < width - 1; col += 2) {
440 memcpy(y_out + col, encoded, 2);
442 memcpy(y_out + col - frame->
linesize[0], encoded, 2);
444 u_out[col >> 1] = *encoded++ + 128;
445 v_out[col >> 1] = *encoded++ + 128;
471 unsigned int basesize = avctx->
width * avctx->
height;
474 unsigned int max_decomp_size;
484 av_log(avctx,
AV_LOG_ERROR,
"Codec id and codec type mismatch. This should not happen.\n");
491 max_decomp_size = max_basesize * 3;
497 max_decomp_size = max_basesize * 2;
503 max_decomp_size = max_basesize * 3;
509 max_decomp_size = max_basesize / 2 * 3;
515 max_decomp_size = max_basesize * 2;
521 max_decomp_size = max_basesize / 2 * 3;
547 #if CONFIG_ZLIB_DECODER
593 #if CONFIG_ZLIB_DECODER
596 c->zstream.zalloc = Z_NULL;
597 c->zstream.zfree = Z_NULL;
598 c->zstream.opaque = Z_NULL;
599 zret = inflateInit(&c->zstream);
621 #if CONFIG_ZLIB_DECODER
623 inflateEnd(&c->zstream);
629 #if CONFIG_MSZH_DECODER
643 #if CONFIG_ZLIB_DECODER