44 #include "libavutil/mem.h"
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 int pixel_ptr;
167 unsigned char *encoded, *outptr;
168 uint8_t *y_out, *u_out, *v_out;
171 unsigned int mszh_dlen;
172 unsigned char yq, y1q, uq, vq;
174 unsigned int mthread_inlen, mthread_outlen;
175 unsigned int len = buf_size;
182 outptr = frame->
data[0];
191 mthread_inlen =
FFMIN(mthread_inlen, len - 8);
192 mthread_outlen =
AV_RL32(buf + 4);
195 if (mthread_outlen != mszh_dlen) {
197 mthread_outlen, mszh_dlen);
200 mszh_dlen =
mszh_decomp(buf + 8 + mthread_inlen, len - 8 - mthread_inlen,
202 if (mthread_outlen != mszh_dlen) {
204 mthread_outlen, mszh_dlen);
239 if (len < ((width * height * bppx2) >> 1))
248 #if CONFIG_ZLIB_DECODER
254 len == width * height * 3) {
263 mthread_inlen =
FFMIN(mthread_inlen, len - 8);
264 mthread_outlen =
AV_RL32(buf + 4);
266 ret = zlib_decomp(avctx, buf + 8, mthread_inlen, 0, mthread_outlen);
267 if (ret < 0)
return ret;
268 ret = zlib_decomp(avctx, buf + 8 + mthread_inlen, len - 8 - mthread_inlen,
269 mthread_outlen, mthread_outlen);
270 if (ret < 0)
return ret;
272 int ret = zlib_decomp(avctx, buf, len, 0, c->
decomp_size);
273 if (ret < 0)
return ret;
280 av_log(avctx,
AV_LOG_ERROR,
"BUG! Unknown codec in frame decoder compression switch.\n");
290 for (row = 0; row <
height; row++) {
291 pixel_ptr = row * width * 3;
292 yq = encoded[pixel_ptr++];
293 uqvq =
AV_RL16(encoded+pixel_ptr);
295 for (col = 1; col <
width; col++) {
296 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
297 uqvq -=
AV_RL16(encoded+pixel_ptr+1);
298 AV_WL16(encoded+pixel_ptr+1, uqvq);
304 for (row = 0; row <
height; row++) {
305 pixel_ptr = row * width * 2;
307 for (col = 0; col < width/4; col++) {
308 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
309 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
310 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
311 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
312 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
313 encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5];
314 encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6];
315 encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7];
321 for (row = 0; row <
height; row++) {
322 pixel_ptr = row * width / 2 * 3;
324 for (col = 0; col < width/4; col++) {
325 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
326 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
327 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
328 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
329 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
330 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
336 for (row = 0; row <
height; row++) {
337 pixel_ptr = row * width * 2;
339 for (col = 0; col < width/2; col++) {
340 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
341 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
342 encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2];
343 encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3];
349 for (row = 0; row < height/2; row++) {
350 pixel_ptr = row * width * 3;
351 yq = y1q = uq = vq =0;
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] = y1q -= encoded[pixel_ptr+2];
356 encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3];
357 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
358 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
370 y_out = frame->
data[0] + (height - 1) * frame->
linesize[0];
371 u_out = frame->
data[1] + (height - 1) * frame->
linesize[1];
372 v_out = frame->
data[2] + (height - 1) * frame->
linesize[2];
375 for (row = 0; row <
height; row++) {
376 for (col = 0; col <
width; col++) {
377 y_out[col] = *encoded++;
378 u_out[col] = *encoded++ + 128;
379 v_out[col] = *encoded++ + 128;
387 for (row = 0; row <
height; row++) {
388 for (col = 0; col < width - 3; col += 4) {
389 memcpy(y_out + col, encoded, 4);
391 u_out[ col >> 1 ] = *encoded++ + 128;
392 u_out[(col >> 1) + 1] = *encoded++ + 128;
393 v_out[ col >> 1 ] = *encoded++ + 128;
394 v_out[(col >> 1) + 1] = *encoded++ + 128;
402 for (row = height - 1; row >= 0; row--) {
403 pixel_ptr = row * frame->
linesize[0];
404 memcpy(outptr + pixel_ptr, encoded, 3 * width);
405 encoded += 3 *
width;
409 for (row = 0; row <
height; row++) {
410 for (col = 0; col < width - 3; col += 4) {
411 memcpy(y_out + col, encoded, 4);
413 u_out[col >> 2] = *encoded++ + 128;
414 v_out[col >> 2] = *encoded++ + 128;
422 for (row = 0; row <
height; row++) {
423 for (col = 0; col < width - 1; col += 2) {
424 memcpy(y_out + col, encoded, 2);
426 u_out[col >> 1] = *encoded++ + 128;
427 v_out[col >> 1] = *encoded++ + 128;
435 u_out = frame->
data[1] + ((height >> 1) - 1) * frame->
linesize[1];
436 v_out = frame->
data[2] + ((height >> 1) - 1) * frame->
linesize[2];
437 for (row = 0; row < height - 1; row += 2) {
438 for (col = 0; col < width - 1; col += 2) {
439 memcpy(y_out + col, encoded, 2);
441 memcpy(y_out + col - frame->
linesize[0], encoded, 2);
443 u_out[col >> 1] = *encoded++ + 128;
444 v_out[col >> 1] = *encoded++ + 128;
470 unsigned int basesize = avctx->
width * avctx->
height;
473 unsigned int max_decomp_size;
483 av_log(avctx,
AV_LOG_ERROR,
"Codec id and codec type mismatch. This should not happen.\n");
490 max_decomp_size = max_basesize * 3;
496 max_decomp_size = max_basesize * 2;
502 max_decomp_size = max_basesize * 3;
508 max_decomp_size = max_basesize / 2 * 3;
514 max_decomp_size = max_basesize * 2;
520 max_decomp_size = max_basesize / 2 * 3;
546 #if CONFIG_ZLIB_DECODER
592 #if CONFIG_ZLIB_DECODER
595 c->zstream.zalloc = Z_NULL;
596 c->zstream.zfree = Z_NULL;
597 c->zstream.opaque = Z_NULL;
598 zret = inflateInit(&c->zstream);
620 #if CONFIG_ZLIB_DECODER
622 inflateEnd(&c->zstream);
628 #if CONFIG_MSZH_DECODER
642 #if CONFIG_ZLIB_DECODER
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
#define COMP_ZLIB_HISPEED
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
const char * name
Name of the codec implementation.
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static const uint16_t mask[17]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Libavcodec external API header.
int width
picture width / height.
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
unsigned char * decomp_buf
main external API structure.
static void close(AVCodecParserContext *s)
packed RGB 8:8:8, 24bpp, BGRBGR...
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static av_cold int decode_end(AVCodecContext *avctx)
static unsigned int mszh_decomp(const unsigned char *srcptr, int srclen, unsigned char *destptr, unsigned int destsize)
static av_cold int decode_init(AVCodecContext *avctx)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
common internal api header.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
static av_cold int init(AVCodecParserContext *s)
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
deliberately overlapping memcpy implementation
This structure stores compressed data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.