50 #if CONFIG_ZLIB_DECODER
70 #if CONFIG_ZLIB_DECODER
80 static 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);
107 if (destptr_end - destptr < 32 || srcptr_end - srcptr < 32)
break;
108 memcpy(destptr, srcptr, 32);
117 return destptr - destptr_bak;
121 #if CONFIG_ZLIB_DECODER
129 static int zlib_decomp(
AVCodecContext *avctx,
const uint8_t *src,
int src_len,
int offset,
int expected)
132 int zret = inflateReset(&c->zstream);
137 c->zstream.next_in = src;
138 c->zstream.avail_in = src_len;
141 zret = inflate(&c->zstream, Z_FINISH);
142 if (zret != Z_OK && zret != Z_STREAM_END) {
146 if (expected != (
unsigned int)c->zstream.total_out) {
148 expected, c->zstream.total_out);
151 return c->zstream.total_out;
164 int buf_size = avpkt->
size;
166 unsigned char *encoded = (
unsigned char *)buf;
167 unsigned int pixel_ptr;
169 unsigned char *outptr;
170 uint8_t *y_out, *u_out, *v_out;
173 unsigned int mszh_dlen;
174 unsigned char yq, y1q, uq, vq;
176 unsigned int mthread_inlen, mthread_outlen;
177 unsigned int len = buf_size;
197 mthread_inlen =
AV_RL32(encoded);
198 mthread_inlen =
FFMIN(mthread_inlen, len - 8);
199 mthread_outlen =
AV_RL32(encoded+4);
202 if (mthread_outlen != mszh_dlen) {
204 mthread_outlen, mszh_dlen);
207 mszh_dlen =
mszh_decomp(encoded + 8 + mthread_inlen, len - 8 - mthread_inlen,
209 if (mthread_outlen != mszh_dlen) {
211 mthread_outlen, mszh_dlen);
246 if (len < ((width * height * bppx2) >> 1))
255 #if CONFIG_ZLIB_DECODER
261 len == width * height * 3) {
270 mthread_inlen =
AV_RL32(encoded);
271 mthread_inlen =
FFMIN(mthread_inlen, len - 8);
272 mthread_outlen =
AV_RL32(encoded+4);
274 ret = zlib_decomp(avctx, encoded + 8, mthread_inlen, 0, mthread_outlen);
275 if (ret < 0)
return ret;
276 ret = zlib_decomp(avctx, encoded + 8 + mthread_inlen, len - 8 - mthread_inlen,
277 mthread_outlen, mthread_outlen);
278 if (ret < 0)
return ret;
280 int ret = zlib_decomp(avctx, encoded, len, 0, c->
decomp_size);
281 if (ret < 0)
return ret;
288 av_log(avctx,
AV_LOG_ERROR,
"BUG! Unknown codec in frame decoder compression switch.\n");
298 for (row = 0; row <
height; row++) {
299 pixel_ptr = row * width * 3;
300 yq = encoded[pixel_ptr++];
301 uqvq =
AV_RL16(encoded+pixel_ptr);
303 for (col = 1; col <
width; col++) {
304 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
305 uqvq -=
AV_RL16(encoded+pixel_ptr+1);
306 AV_WL16(encoded+pixel_ptr+1, uqvq);
312 for (row = 0; row <
height; row++) {
313 pixel_ptr = row * width * 2;
315 for (col = 0; col < width/4; col++) {
316 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
317 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
318 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
319 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
320 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
321 encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5];
322 encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6];
323 encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7];
329 for (row = 0; row <
height; row++) {
330 pixel_ptr = row * width / 2 * 3;
332 for (col = 0; col < width/4; col++) {
333 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
334 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
335 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
336 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
337 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
338 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
344 for (row = 0; row <
height; row++) {
345 pixel_ptr = row * width * 2;
347 for (col = 0; col < width/2; col++) {
348 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
349 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
350 encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2];
351 encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3];
357 for (row = 0; row < height/2; row++) {
358 pixel_ptr = row * width * 3;
359 yq = y1q = uq = vq =0;
360 for (col = 0; col < width/2; col++) {
361 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
362 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
363 encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2];
364 encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3];
365 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
366 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
383 for (row = 0; row <
height; row++) {
384 for (col = 0; col <
width; col++) {
385 y_out[col] = *encoded++;
386 u_out[col] = *encoded++ + 128;
387 v_out[col] = *encoded++ + 128;
395 for (row = 0; row <
height; row++) {
396 for (col = 0; col < width - 3; col += 4) {
397 memcpy(y_out + col, encoded, 4);
399 u_out[ col >> 1 ] = *encoded++ + 128;
400 u_out[(col >> 1) + 1] = *encoded++ + 128;
401 v_out[ col >> 1 ] = *encoded++ + 128;
402 v_out[(col >> 1) + 1] = *encoded++ + 128;
410 for (row = height - 1; row >= 0; row--) {
412 memcpy(outptr + pixel_ptr, encoded, 3 * width);
413 encoded += 3 *
width;
417 for (row = 0; row <
height; row++) {
418 for (col = 0; col < width - 3; col += 4) {
419 memcpy(y_out + col, encoded, 4);
421 u_out[col >> 2] = *encoded++ + 128;
422 v_out[col >> 2] = *encoded++ + 128;
430 for (row = 0; row <
height; row++) {
431 for (col = 0; col < width - 1; col += 2) {
432 memcpy(y_out + col, encoded, 2);
434 u_out[col >> 1] = *encoded++ + 128;
435 v_out[col >> 1] = *encoded++ + 128;
445 for (row = 0; row < height - 1; row += 2) {
446 for (col = 0; col < width - 1; col += 2) {
447 memcpy(y_out + col, encoded, 2);
449 memcpy(y_out + col - c->
pic.
linesize[0], encoded, 2);
451 u_out[col >> 1] = *encoded++ + 128;
452 v_out[col >> 1] = *encoded++ + 128;
479 unsigned int basesize = avctx->
width * avctx->
height;
482 unsigned int max_decomp_size;
492 av_log(avctx,
AV_LOG_ERROR,
"Codec id and codec type mismatch. This should not happen.\n");
499 max_decomp_size = max_basesize * 3;
505 max_decomp_size = max_basesize * 2;
511 max_decomp_size = max_basesize * 3;
517 max_decomp_size = max_basesize / 2 * 3;
523 max_decomp_size = max_basesize * 2;
529 max_decomp_size = max_basesize / 2 * 3;
555 #if CONFIG_ZLIB_DECODER
601 #if CONFIG_ZLIB_DECODER
604 c->zstream.zalloc = Z_NULL;
605 c->zstream.zfree = Z_NULL;
606 c->zstream.opaque = Z_NULL;
607 zret = inflateInit(&c->zstream);
631 #if CONFIG_ZLIB_DECODER
633 inflateEnd(&c->zstream);
639 #if CONFIG_MSZH_DECODER
653 #if CONFIG_ZLIB_DECODER
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
This structure describes decoded (raw) audio or video data.
int buffer_hints
codec suggestion on buffer type if != 0
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
memory handling functions
#define COMP_ZLIB_HISPEED
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
void av_freep(void *arg)
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)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
static int init(AVCodecParserContext *s)
struct LclDecContext LclDecContext
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static const uint16_t mask[17]
int reference
is this picture used as reference The values for this are the same as the MpegEncContext.picture_structure variable, that is 1->top field, 2->bottom field, 3->frame/both fields.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int width
picture width / height.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Get a buffer for a frame.
packed RGB 8:8:8, 24bpp, BGRBGR...
unsigned char * decomp_buf
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
main external API structure.
static void close(AVCodecParserContext *s)
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)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
#define AVERROR_INVALIDDATA
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
#define FF_BUFFER_HINTS_VALID
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
deliberately overlapping memcpy implementation
This structure stores compressed data.