50 #if CONFIG_ZLIB_DECODER
65 #if CONFIG_ZLIB_DECODER
75 static unsigned int mszh_decomp(
const unsigned char * srcptr,
int srclen,
unsigned char * destptr,
unsigned int destsize)
77 unsigned char *destptr_bak = destptr;
78 unsigned char *destptr_end = destptr + destsize;
79 const unsigned char *srcptr_end = srcptr + srclen;
80 unsigned mask = *srcptr++;
81 unsigned maskbit = 0x80;
83 while (srcptr < srcptr_end && destptr < destptr_end) {
84 if (!(mask & maskbit)) {
85 memcpy(destptr, srcptr, 4);
89 unsigned ofs = bytestream_get_le16(&srcptr);
90 unsigned cnt = (ofs >> 11) + 1;
92 ofs =
FFMIN(ofs, destptr - destptr_bak);
94 cnt =
FFMIN(cnt, destptr_end - destptr);
100 memset(destptr, 0, cnt);
108 if (destptr_end - destptr < 32 || srcptr_end - srcptr < 32)
break;
109 memcpy(destptr, srcptr, 32);
118 return destptr - destptr_bak;
122 #if CONFIG_ZLIB_DECODER
133 int zret = inflateReset(&c->zstream);
138 c->zstream.next_in = (
uint8_t *)src;
139 c->zstream.avail_in = src_len;
142 zret =
inflate(&c->zstream, Z_FINISH);
143 if (zret != Z_OK && zret != Z_STREAM_END) {
147 if (expected != (
unsigned int)c->zstream.total_out) {
149 expected, c->zstream.total_out);
152 return c->zstream.total_out;
161 int buf_size = avpkt->
size;
163 unsigned int pixel_ptr;
165 unsigned char *encoded = avpkt->
data, *outptr;
166 uint8_t *y_out, *u_out, *v_out;
169 unsigned int mszh_dlen;
170 unsigned char yq, y1q, uq, vq;
172 unsigned int mthread_inlen, mthread_outlen;
173 unsigned int len = buf_size;
179 outptr = frame->
data[0];
195 mthread_inlen =
FFMIN(mthread_inlen, len - 8);
196 mthread_outlen =
AV_RL32(buf + 4);
199 if (mthread_outlen != mszh_dlen) {
201 mthread_outlen, mszh_dlen);
204 mszh_dlen =
mszh_decomp(buf + 8 + mthread_inlen, len - 8 - mthread_inlen,
206 if (mthread_outlen != mszh_dlen) {
208 mthread_outlen, mszh_dlen);
243 if (len < ((width * height * bppx2) >> 1))
252 #if CONFIG_ZLIB_DECODER
258 len == width * height * 3) {
267 mthread_inlen =
FFMIN(mthread_inlen, len - 8);
268 mthread_outlen =
AV_RL32(buf + 4);
270 ret = zlib_decomp(avctx, buf + 8, mthread_inlen, 0, mthread_outlen);
271 if (ret < 0)
return ret;
272 ret = zlib_decomp(avctx, buf + 8 + mthread_inlen, len - 8 - mthread_inlen,
273 mthread_outlen, mthread_outlen);
274 if (ret < 0)
return ret;
276 int ret = zlib_decomp(avctx, buf, len, 0, c->
decomp_size);
277 if (ret < 0)
return ret;
284 av_log(avctx,
AV_LOG_ERROR,
"BUG! Unknown codec in frame decoder compression switch.\n");
294 for (row = 0; row <
height; row++) {
295 pixel_ptr = row * width * 3;
296 yq = encoded[pixel_ptr++];
297 uqvq =
AV_RL16(encoded+pixel_ptr);
299 for (col = 1; col <
width; col++) {
300 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
301 uqvq -=
AV_RL16(encoded+pixel_ptr+1);
302 AV_WL16(encoded+pixel_ptr+1, uqvq);
308 for (row = 0; row <
height; row++) {
309 pixel_ptr = row * width * 2;
311 for (col = 0; col < width/4; col++) {
312 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
313 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
314 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
315 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
316 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
317 encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5];
318 encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6];
319 encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7];
325 for (row = 0; row <
height; row++) {
326 pixel_ptr = row * width / 2 * 3;
328 for (col = 0; col < width/4; col++) {
329 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
330 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
331 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
332 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
333 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
334 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
340 for (row = 0; row <
height; row++) {
341 pixel_ptr = row * width * 2;
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] = uq -= encoded[pixel_ptr+2];
347 encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3];
353 for (row = 0; row < height/2; row++) {
354 pixel_ptr = row * width * 3;
355 yq = y1q = uq = vq =0;
356 for (col = 0; col < width/2; col++) {
357 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
358 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
359 encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2];
360 encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3];
361 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
362 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
374 y_out = frame->
data[0] + (height - 1) * frame->
linesize[0];
375 u_out = frame->
data[1] + (height - 1) * frame->
linesize[1];
376 v_out = frame->
data[2] + (height - 1) * frame->
linesize[2];
379 for (row = 0; row <
height; row++) {
380 for (col = 0; col <
width; col++) {
381 y_out[col] = *encoded++;
382 u_out[col] = *encoded++ + 128;
383 v_out[col] = *encoded++ + 128;
391 for (row = 0; row <
height; row++) {
392 for (col = 0; col < width - 3; col += 4) {
393 memcpy(y_out + col, encoded, 4);
395 u_out[ col >> 1 ] = *encoded++ + 128;
396 u_out[(col >> 1) + 1] = *encoded++ + 128;
397 v_out[ col >> 1 ] = *encoded++ + 128;
398 v_out[(col >> 1) + 1] = *encoded++ + 128;
406 linesize = len <
FFALIGN(3 * width, 4) * height ? 3 * width :
FFALIGN(3 * width, 4);
407 for (row = height - 1; row >= 0; row--) {
408 pixel_ptr = row * frame->
linesize[0];
409 memcpy(outptr + pixel_ptr, encoded, 3 * width);
414 for (row = 0; row <
height; row++) {
415 for (col = 0; col < width - 3; col += 4) {
416 memcpy(y_out + col, encoded, 4);
418 u_out[col >> 2] = *encoded++ + 128;
419 v_out[col >> 2] = *encoded++ + 128;
427 for (row = 0; row <
height; row++) {
428 for (col = 0; col < width - 1; col += 2) {
429 memcpy(y_out + col, encoded, 2);
431 u_out[col >> 1] = *encoded++ + 128;
432 v_out[col >> 1] = *encoded++ + 128;
440 u_out = frame->
data[1] + ((height >> 1) - 1) * frame->
linesize[1];
441 v_out = frame->
data[2] + ((height >> 1) - 1) * frame->
linesize[2];
442 for (row = 0; row < height - 1; row += 2) {
443 for (col = 0; col < width - 1; col += 2) {
444 memcpy(y_out + col, encoded, 2);
446 memcpy(y_out + col - frame->
linesize[0], encoded, 2);
448 u_out[col >> 1] = *encoded++ + 128;
449 v_out[col >> 1] = *encoded++ + 128;
470 unsigned int basesize = avctx->
width * avctx->
height;
473 unsigned int max_decomp_size;
474 int subsample_h, subsample_v;
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;
500 if (avctx->
width % 4) {
507 max_decomp_size = max_basesize * 3;
513 max_decomp_size = max_basesize / 2 * 3;
519 max_decomp_size = max_basesize * 2;
525 max_decomp_size = max_basesize / 2 * 3;
535 if (avctx->
width % (1<<subsample_h) || avctx->
height % (1<<subsample_v)) {
557 #if CONFIG_ZLIB_DECODER
603 #if CONFIG_ZLIB_DECODER
606 c->zstream.zalloc = Z_NULL;
607 c->zstream.zfree = Z_NULL;
608 c->zstream.opaque = Z_NULL;
609 zret = inflateInit(&c->zstream);
626 #if CONFIG_ZLIB_DECODER
628 inflateEnd(&c->zstream);
634 #if CONFIG_MSZH_DECODER
648 #if CONFIG_ZLIB_DECODER
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Memory handling functions.
static av_cold int init(AVCodecContext *avctx)
#define COMP_ZLIB_HISPEED
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
static void inflate(uint8_t *dst, const uint8_t *p1, int width, int threshold, const uint8_t *coordinates[], int coord)
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
Overlapping memcpy() implementation.
#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]
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
#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.
static const uint8_t offset[127][2]
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int width
picture width / height.
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 int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
This structure stores compressed data.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.