49 #if CONFIG_ZLIB_DECODER 64 #if CONFIG_ZLIB_DECODER 74 static unsigned int mszh_decomp(
const unsigned char * srcptr,
int srclen,
unsigned char * destptr,
unsigned int destsize)
76 unsigned char *destptr_bak = destptr;
77 unsigned char *destptr_end = destptr + destsize;
78 const unsigned char *srcptr_end = srcptr + srclen;
79 unsigned mask = *srcptr++;
80 unsigned maskbit = 0x80;
82 while (srcptr < srcptr_end && destptr < destptr_end) {
83 if (!(mask & maskbit)) {
84 memcpy(destptr, srcptr, 4);
88 unsigned ofs = bytestream_get_le16(&srcptr);
89 unsigned cnt = (ofs >> 11) + 1;
91 ofs =
FFMIN(ofs, destptr - destptr_bak);
93 cnt =
FFMIN(cnt, destptr_end - destptr);
101 if (destptr_end - destptr < 32 || srcptr_end - srcptr < 32)
break;
102 memcpy(destptr, srcptr, 32);
111 return destptr - destptr_bak;
115 #if CONFIG_ZLIB_DECODER 126 int zret = inflateReset(&c->zstream);
131 c->zstream.next_in =
src;
132 c->zstream.avail_in = src_len;
135 zret = inflate(&c->zstream, Z_FINISH);
136 if (zret != Z_OK && zret != Z_STREAM_END) {
140 if (expected != (
unsigned int)c->zstream.total_out) {
142 expected, c->zstream.total_out);
145 return c->zstream.total_out;
154 int buf_size = avpkt->
size;
156 unsigned int pixel_ptr;
158 unsigned char *encoded, *outptr;
159 uint8_t *y_out, *u_out, *v_out;
162 unsigned int mszh_dlen;
163 unsigned char yq, y1q, uq, vq;
165 unsigned int mthread_inlen, mthread_outlen;
166 unsigned int len = buf_size;
173 outptr = frame->
data[0];
182 mthread_inlen =
FFMIN(mthread_inlen, len - 8);
183 mthread_outlen =
AV_RL32(buf + 4);
186 if (mthread_outlen != mszh_dlen) {
188 mthread_outlen, mszh_dlen);
191 mszh_dlen =
mszh_decomp(buf + 8 + mthread_inlen, len - 8 - mthread_inlen,
193 if (mthread_outlen != mszh_dlen) {
195 mthread_outlen, mszh_dlen);
230 if (len < ((width * height * bppx2) >> 1))
239 #if CONFIG_ZLIB_DECODER 245 len == width * height * 3) {
254 mthread_inlen =
FFMIN(mthread_inlen, len - 8);
255 mthread_outlen =
AV_RL32(buf + 4);
257 ret = zlib_decomp(avctx, buf + 8, mthread_inlen, 0, mthread_outlen);
258 if (ret < 0)
return ret;
259 ret = zlib_decomp(avctx, buf + 8 + mthread_inlen, len - 8 - mthread_inlen,
260 mthread_outlen, mthread_outlen);
261 if (ret < 0)
return ret;
263 int ret = zlib_decomp(avctx, buf, len, 0, c->
decomp_size);
264 if (ret < 0)
return ret;
271 av_log(avctx,
AV_LOG_ERROR,
"BUG! Unknown codec in frame decoder compression switch.\n");
281 for (row = 0; row <
height; row++) {
282 pixel_ptr = row * width * 3;
283 yq = encoded[pixel_ptr++];
284 uqvq =
AV_RL16(encoded+pixel_ptr);
286 for (col = 1; col <
width; col++) {
287 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
288 uqvq -=
AV_RL16(encoded+pixel_ptr+1);
289 AV_WL16(encoded+pixel_ptr+1, uqvq);
295 for (row = 0; row <
height; row++) {
296 pixel_ptr = row * width * 2;
298 for (col = 0; col < width/4; col++) {
299 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
300 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
301 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
302 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
303 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
304 encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5];
305 encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6];
306 encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7];
312 for (row = 0; row <
height; row++) {
313 pixel_ptr = row * width / 2 * 3;
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] = vq -= encoded[pixel_ptr+5];
327 for (row = 0; row <
height; row++) {
328 pixel_ptr = row * width * 2;
330 for (col = 0; col < width/2; col++) {
331 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
332 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
333 encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2];
334 encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3];
340 for (row = 0; row < height/2; row++) {
341 pixel_ptr = row * width * 3;
342 yq = y1q = uq = vq =0;
343 for (col = 0; col < width/2; col++) {
344 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
345 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
346 encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2];
347 encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3];
348 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
349 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
361 y_out = frame->
data[0] + (height - 1) * frame->
linesize[0];
362 u_out = frame->
data[1] + (height - 1) * frame->
linesize[1];
363 v_out = frame->
data[2] + (height - 1) * frame->
linesize[2];
366 for (row = 0; row <
height; row++) {
367 for (col = 0; col <
width; col++) {
368 y_out[col] = *encoded++;
369 u_out[col] = *encoded++ + 128;
370 v_out[col] = *encoded++ + 128;
378 for (row = 0; row <
height; row++) {
379 for (col = 0; col < width - 3; col += 4) {
380 memcpy(y_out + col, encoded, 4);
382 u_out[ col >> 1 ] = *encoded++ + 128;
383 u_out[(col >> 1) + 1] = *encoded++ + 128;
384 v_out[ col >> 1 ] = *encoded++ + 128;
385 v_out[(col >> 1) + 1] = *encoded++ + 128;
393 for (row = height - 1; row >= 0; row--) {
394 pixel_ptr = row * frame->
linesize[0];
395 memcpy(outptr + pixel_ptr, encoded, 3 * width);
396 encoded += 3 *
width;
400 for (row = 0; row <
height; row++) {
401 for (col = 0; col < width - 3; col += 4) {
402 memcpy(y_out + col, encoded, 4);
404 u_out[col >> 2] = *encoded++ + 128;
405 v_out[col >> 2] = *encoded++ + 128;
413 for (row = 0; row <
height; row++) {
414 for (col = 0; col < width - 1; col += 2) {
415 memcpy(y_out + col, encoded, 2);
417 u_out[col >> 1] = *encoded++ + 128;
418 v_out[col >> 1] = *encoded++ + 128;
426 u_out = frame->
data[1] + ((height >> 1) - 1) * frame->
linesize[1];
427 v_out = frame->
data[2] + ((height >> 1) - 1) * frame->
linesize[2];
428 for (row = 0; row < height - 1; row += 2) {
429 for (col = 0; col < width - 1; col += 2) {
430 memcpy(y_out + col, encoded, 2);
432 memcpy(y_out + col - frame->
linesize[0], encoded, 2);
434 u_out[col >> 1] = *encoded++ + 128;
435 v_out[col >> 1] = *encoded++ + 128;
456 unsigned int basesize = avctx->
width * avctx->
height;
459 unsigned int max_decomp_size;
469 av_log(avctx,
AV_LOG_ERROR,
"Codec id and codec type mismatch. This should not happen.\n");
476 max_decomp_size = max_basesize * 3;
482 max_decomp_size = max_basesize * 2;
488 max_decomp_size = max_basesize * 3;
494 max_decomp_size = max_basesize / 2 * 3;
500 max_decomp_size = max_basesize * 2;
506 max_decomp_size = max_basesize / 2 * 3;
532 #if CONFIG_ZLIB_DECODER 578 #if CONFIG_ZLIB_DECODER 581 c->zstream.zalloc = Z_NULL;
582 c->zstream.zfree = Z_NULL;
583 c->zstream.opaque = Z_NULL;
584 zret = inflateInit(&c->zstream);
601 #if CONFIG_ZLIB_DECODER 603 inflateEnd(&c->zstream);
609 #if CONFIG_MSZH_DECODER 623 #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 ...
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
memory handling functions
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
#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 ...
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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.
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.
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
packed RGB 8:8:8, 24bpp, BGRBGR...
unsigned char * decomp_buf
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
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)
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.
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
#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.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.