51 #if CONFIG_ZLIB_DECODER
66 #if CONFIG_ZLIB_DECODER
76 static unsigned int mszh_decomp(
const unsigned char * srcptr,
int srclen,
unsigned char * destptr,
unsigned int destsize)
78 unsigned char *destptr_bak = destptr;
79 unsigned char *destptr_end = destptr + destsize;
80 const unsigned char *srcptr_end = srcptr + srclen;
81 unsigned mask = *srcptr++;
82 unsigned maskbit = 0x80;
84 while (srcptr < srcptr_end && destptr < destptr_end) {
85 if (!(
mask & maskbit)) {
86 memcpy(destptr, srcptr, 4);
90 unsigned ofs = bytestream_get_le16(&srcptr);
91 unsigned cnt = (ofs >> 11) + 1;
93 ofs =
FFMIN(ofs, destptr - destptr_bak);
95 cnt =
FFMIN(cnt, destptr_end - destptr);
101 memset(destptr, 0, cnt);
109 if (destptr_end - destptr < 32 || srcptr_end - srcptr < 32)
break;
110 memcpy(destptr, srcptr, 32);
119 if (destptr < destptr_end)
120 memset(destptr, 0, destptr_end - destptr);
122 return destptr - destptr_bak;
126 #if CONFIG_ZLIB_DECODER
137 int zret = inflateReset(&
c->zstream);
142 c->zstream.next_in =
src;
143 c->zstream.avail_in = src_len;
144 c->zstream.next_out =
c->decomp_buf +
offset;
145 c->zstream.avail_out =
c->decomp_size -
offset;
146 zret =
inflate(&
c->zstream, Z_FINISH);
147 if (zret != Z_OK && zret != Z_STREAM_END) {
151 if (expected != (
unsigned int)
c->zstream.total_out) {
153 expected,
c->zstream.total_out);
154 if (expected > (
unsigned int)
c->zstream.total_out) {
155 memset(
c->decomp_buf +
offset +
c->zstream.total_out, 0,
156 c->decomp_size -
offset -
c->zstream.total_out);
157 return (
unsigned int)
c->zstream.total_out;
161 return c->zstream.total_out;
171 int buf_size = avpkt->
size;
175 unsigned char *encoded = avpkt->
data, *outptr;
176 uint8_t *y_out, *u_out, *v_out;
179 unsigned int mszh_dlen;
180 unsigned char yq, y1q, uq, vq;
182 unsigned int mthread_inlen, mthread_outlen;
183 unsigned int len = buf_size;
194 switch (
c->compression) {
201 if (
len < 8 ||
len - 8 < mthread_inlen) {
205 mthread_outlen =
AV_RL32(buf + 4);
206 mthread_outlen =
FFMIN(mthread_outlen,
c->decomp_size);
207 mszh_dlen =
mszh_decomp(buf + 8, mthread_inlen,
c->decomp_buf,
c->decomp_size);
208 if (mthread_outlen != mszh_dlen) {
210 mthread_outlen, mszh_dlen);
213 mszh_dlen =
mszh_decomp(buf + 8 + mthread_inlen,
len - 8 - mthread_inlen,
214 c->decomp_buf + mthread_outlen,
c->decomp_size - mthread_outlen);
215 if (mthread_outlen != mszh_dlen) {
217 mthread_outlen, mszh_dlen);
220 encoded =
c->decomp_buf;
221 len =
c->decomp_size;
224 if (
c->decomp_size != mszh_dlen) {
226 c->decomp_size, mszh_dlen);
229 encoded =
c->decomp_buf;
235 int aligned_width =
width;
236 switch (
c->imgtype) {
255 if (
len < ((aligned_width *
height * bppx2) >> 1))
264 #if CONFIG_ZLIB_DECODER
272 memcpy(
c->decomp_buf, buf,
len);
273 encoded =
c->decomp_buf;
283 mthread_inlen =
FFMIN(mthread_inlen,
len - 8);
284 mthread_outlen =
AV_RL32(buf + 4);
285 mthread_outlen =
FFMIN(mthread_outlen,
c->decomp_size);
286 ret = zlib_decomp(avctx, buf + 8, mthread_inlen, 0, mthread_outlen);
287 if (ret < 0)
return ret;
288 ret = zlib_decomp(avctx, buf + 8 + mthread_inlen,
len - 8 - mthread_inlen,
289 mthread_outlen, mthread_outlen);
290 if (ret < 0)
return ret;
291 memset(
c->decomp_buf + mthread_outlen + ret, 0,
292 c->decomp_size - mthread_outlen - ret);
293 len =
c->decomp_size;
295 int ret = zlib_decomp(avctx, buf,
len, 0,
c->decomp_size);
296 if (ret < 0)
return ret;
299 encoded =
c->decomp_buf;
303 av_log(avctx,
AV_LOG_ERROR,
"BUG! Unknown codec in frame decoder compression switch.\n");
310 switch (
c->imgtype) {
313 for (row = 0; row <
height; row++) {
314 pixel_ptr = row *
width * 3;
315 yq = encoded[pixel_ptr++];
316 unsigned uqvq =
AV_RL16(encoded+pixel_ptr);
318 for (col = 1; col <
width; col++) {
319 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
320 uqvq -=
AV_RL16(encoded+pixel_ptr+1);
321 AV_WL16(encoded+pixel_ptr+1, uqvq);
328 for (row = 0; row <
height; row++) {
330 for (col = 0; col <
width/4; col++) {
331 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
332 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
333 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
334 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
335 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
336 encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5];
337 encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6];
338 encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7];
345 for (row = 0; row <
height; row++) {
347 for (col = 0; col <
width/4; col++) {
348 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
349 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
350 encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
351 encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
352 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
353 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
359 for (row = 0; row <
height; row++) {
360 pixel_ptr = row *
width * 2;
362 for (col = 0; col <
width/2; col++) {
363 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
364 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
365 encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2];
366 encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3];
372 for (row = 0; row <
height/2; row++) {
373 pixel_ptr = row *
width * 3;
374 yq = y1q = uq = vq =0;
375 for (col = 0; col <
width/2; col++) {
376 encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
377 encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
378 encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2];
379 encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3];
380 encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
381 encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
398 switch (
c->imgtype) {
400 for (row = 0; row <
height; row++) {
401 for (col = 0; col <
width; col++) {
402 y_out[col] = *encoded++;
403 u_out[col] = *encoded++ + 128;
404 v_out[col] = *encoded++ + 128;
412 for (row = 0; row <
height; row++) {
413 for (col = 0; col <
width - 3; col += 4) {
414 memcpy(y_out + col, encoded, 4);
416 u_out[ col >> 1 ] = *encoded++ + 128;
417 u_out[(col >> 1) + 1] = *encoded++ + 128;
418 v_out[ col >> 1 ] = *encoded++ + 128;
419 v_out[(col >> 1) + 1] = *encoded++ + 128;
421 if (col && col <
width) {
422 u_out[ col >> 1 ] = u_out[(col>>1) - 1];
423 v_out[ col >> 1 ] = v_out[(col>>1) - 1];
433 for (row =
height - 1; row >= 0; row--) {
435 memcpy(outptr + pixel_ptr, encoded, 3 *
width);
440 for (row = 0; row <
height; row++) {
441 for (col = 0; col <
width - 3; col += 4) {
442 memcpy(y_out + col, encoded, 4);
444 u_out[col >> 2] = *encoded++ + 128;
445 v_out[col >> 2] = *encoded++ + 128;
447 if (col && col <
width) {
448 u_out[col >> 2] = u_out[(col>>2) - 1];
449 v_out[col >> 2] = v_out[(col>>2) - 1];
457 for (row = 0; row <
height; row++) {
458 for (col = 0; col <
width - 1; col += 2) {
459 memcpy(y_out + col, encoded, 2);
461 u_out[col >> 1] = *encoded++ + 128;
462 v_out[col >> 1] = *encoded++ + 128;
472 for (row = 0; row <
height - 1; row += 2) {
473 for (col = 0; col <
width - 1; col += 2) {
474 memcpy(y_out + col, encoded, 2);
478 u_out[col >> 1] = *encoded++ + 128;
479 v_out[col >> 1] = *encoded++ + 128;
503 unsigned int basesize = avctx->
width * avctx->
height;
506 unsigned int max_decomp_size;
507 int subsample_h, subsample_v;
508 int partial_h_supported = 0;
518 av_log(avctx,
AV_LOG_ERROR,
"Codec id and codec type mismatch. This should not happen.\n");
524 c->decomp_size = basesize * 3;
525 max_decomp_size = max_basesize * 3;
530 c->decomp_size = (avctx->
width & ~3) * avctx->
height * 2;
531 max_decomp_size = max_basesize * 2;
534 partial_h_supported = 1;
538 max_decomp_size = max_basesize * 3;
543 c->decomp_size = (avctx->
width & ~3) * avctx->
height / 2 * 3;
544 max_decomp_size = max_basesize / 2 * 3;
547 partial_h_supported = 1;
550 c->decomp_size = basesize * 2;
551 max_decomp_size = max_basesize * 2;
556 c->decomp_size = basesize / 2 * 3;
557 max_decomp_size = max_basesize / 2 * 3;
567 if ((avctx->
width % (1<<subsample_h) && !partial_h_supported) || avctx->
height % (1<<subsample_v)) {
576 switch (
c->compression) {
585 av_log(avctx,
AV_LOG_ERROR,
"Unsupported compression format for MSZH (%d).\n",
c->compression);
589 #if CONFIG_ZLIB_DECODER
591 switch (
c->compression) {
602 if (
c->compression < Z_NO_COMPRESSION ||
c->compression > Z_BEST_COMPRESSION) {
603 av_log(avctx,
AV_LOG_ERROR,
"Unsupported compression level for ZLIB: (%d).\n",
c->compression);
616 if (
c->decomp_size) {
617 if (!(
c->decomp_buf =
av_malloc(max_decomp_size))) {
635 #if CONFIG_ZLIB_DECODER
638 c->zstream.zalloc = Z_NULL;
639 c->zstream.zfree = Z_NULL;
640 c->zstream.opaque = Z_NULL;
641 zret = inflateInit(&
c->zstream);
658 #if CONFIG_ZLIB_DECODER
660 inflateEnd(&
c->zstream);
666 #if CONFIG_MSZH_DECODER
681 #if CONFIG_ZLIB_DECODER
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
Overlapping memcpy() implementation.
@ AV_PICTURE_TYPE_I
Intra.
#define COMP_ZLIB_HISPEED
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)
static av_cold int decode_end(AVCodecContext *avctx)
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define FF_PTR_ADD(ptr, off)
static const uint16_t mask[17]
Memory handling functions.
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.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
FF_ENABLE_DEPRECATION_WARNINGS int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int key_frame
1 -> keyframe, 0-> not
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
enum AVPictureType pict_type
Picture type of the frame.
This structure stores compressed data.
unsigned char * decomp_buf
#define avpriv_request_sample(...)
static void inflate(uint8_t *dst, const uint8_t *p1, int width, int threshold, const uint8_t *coordinates[], int coord, int maxc)
static const uint8_t offset[127][2]