summaryrefslogtreecommitdiffstats
path: root/libmpcodecs
diff options
context:
space:
mode:
authoralex <alex@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-09-01 15:10:01 +0000
committeralex <alex@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-09-01 15:10:01 +0000
commitc4560b672e5f0db67a110b5a6fe843310e2a4b21 (patch)
treed4cefa5f69b5dc234006d491959b778bcd19cded /libmpcodecs
parent688e04de22a7b78fab164b8cc0d08f914a735937 (diff)
downloadmpv-c4560b672e5f0db67a110b5a6fe843310e2a4b21.tar.bz2
mpv-c4560b672e5f0db67a110b5a6fe843310e2a4b21.tar.xz
added LCL decoder by Roberto Togni <r_togni@libero.it>, removed my old vd_zlib
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@7223 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libmpcodecs')
-rw-r--r--libmpcodecs/Makefile2
-rw-r--r--libmpcodecs/vd.c8
-rw-r--r--libmpcodecs/vd_lcl.c738
-rw-r--r--libmpcodecs/vd_zlib.c182
4 files changed, 742 insertions, 188 deletions
diff --git a/libmpcodecs/Makefile b/libmpcodecs/Makefile
index 059970d95e..68a13c1403 100644
--- a/libmpcodecs/Makefile
+++ b/libmpcodecs/Makefile
@@ -5,7 +5,7 @@ LIBNAME = libmpcodecs.a
LIBNAME2 = libmpencoders.a
AUDIO_SRCS=dec_audio.c ad.c ad_liba52.c ad_acm.c ad_alaw.c ad_dk3adpcm.c ad_dshow.c ad_dvdpcm.c ad_ffmpeg.c ad_hwac3.c ad_imaadpcm.c ad_mp3lib.c ad_msadpcm.c ad_pcm.c ad_roqaudio.c ad_msgsm.c ad_faad.c ad_libvorbis.c ad_libmad.c ad_realaud.c ad_libdv.c
-VIDEO_SRCS=dec_video.c vd.c vd_null.c vd_realvid.c vd_cinepak.c vd_qtrpza.c vd_ffmpeg.c vd_dshow.c vd_vfw.c vd_vfwex.c vd_odivx.c vd_divx4.c vd_raw.c vd_xanim.c vd_msvidc.c vd_fli.c vd_qtrle.c vd_qtsmc.c vd_roqvideo.c vd_cyuv.c vd_nuv.c vd_libmpeg2.c vd_msrle.c vd_huffyuv.c vd_zlib.c vd_mpegpes.c vd_svq1.c vd_xvid.c vd_libdv.c
+VIDEO_SRCS=dec_video.c vd.c vd_null.c vd_realvid.c vd_cinepak.c vd_qtrpza.c vd_ffmpeg.c vd_dshow.c vd_vfw.c vd_vfwex.c vd_odivx.c vd_divx4.c vd_raw.c vd_xanim.c vd_msvidc.c vd_fli.c vd_qtrle.c vd_qtsmc.c vd_roqvideo.c vd_cyuv.c vd_nuv.c vd_libmpeg2.c vd_msrle.c vd_huffyuv.c vd_mpegpes.c vd_svq1.c vd_xvid.c vd_libdv.c vd_lcl.c
VFILTER_SRCS=vf.c vf_vo.c vf_crop.c vf_expand.c vf_pp.c vf_scale.c vf_format.c vf_yuy2.c vf_flip.c vf_rgb2bgr.c vf_rotate.c vf_mirror.c vf_palette.c vf_lavc.c vf_dvbscale.c vf_cropdetect.c vf_test.c vf_noise.c vf_yvu9.c vf_rectangle.c vf_lavcdeint.c vf_eq.c vf_halfpack.c
ENCODER_SRCS=ve.c ve_divx4.c ve_lavc.c ve_vfw.c ve_rawrgb.c ve_libdv.c
NATIVE_SRCS=native/RTjpegN.c native/cinepak.c native/cyuv.c native/fli.c native/minilzo.c native/msvidc.c native/nuppelvideo.c native/qtrle.c native/qtrpza.c native/qtsmc.c native/roqav.c native/xa_gsm.c native/svq1.c
diff --git a/libmpcodecs/vd.c b/libmpcodecs/vd.c
index 34ceeb0d8d..23e6afc7ce 100644
--- a/libmpcodecs/vd.c
+++ b/libmpcodecs/vd.c
@@ -48,12 +48,12 @@ extern vd_functions_t mpcodecs_vd_mpng;
extern vd_functions_t mpcodecs_vd_ijpg;
extern vd_functions_t mpcodecs_vd_libmpeg2;
extern vd_functions_t mpcodecs_vd_huffyuv;
-extern vd_functions_t mpcodecs_vd_zlib;
extern vd_functions_t mpcodecs_vd_mpegpes;
extern vd_functions_t mpcodecs_vd_realvid;
extern vd_functions_t mpcodecs_vd_svq1;
extern vd_functions_t mpcodecs_vd_xvid;
extern vd_functions_t mpcodecs_vd_libdv;
+extern vd_functions_t mpcodecs_vd_lcl;
vd_functions_t* mpcodecs_vd_drivers[] = {
&mpcodecs_vd_null,
@@ -95,9 +95,6 @@ vd_functions_t* mpcodecs_vd_drivers[] = {
#endif
&mpcodecs_vd_libmpeg2,
&mpcodecs_vd_huffyuv,
-#ifdef HAVE_ZLIB
- &mpcodecs_vd_zlib,
-#endif
&mpcodecs_vd_mpegpes,
#ifdef USE_REALCODECS
&mpcodecs_vd_realvid,
@@ -107,8 +104,9 @@ vd_functions_t* mpcodecs_vd_drivers[] = {
&mpcodecs_vd_xvid,
#endif
#ifdef HAVE_LIBDV095
- &mpcodecs_vd_libdv,
+ &mpcodecs_vd_libdv,
#endif
+ &mpcodecs_vd_lcl,
NULL
};
diff --git a/libmpcodecs/vd_lcl.c b/libmpcodecs/vd_lcl.c
new file mode 100644
index 0000000000..5e0ea824d0
--- /dev/null
+++ b/libmpcodecs/vd_lcl.c
@@ -0,0 +1,738 @@
+/*
+ *
+ * LCL (LossLess Codec Library) Decoder for Mplayer
+ * (c) 2002 Roberto Togni
+ *
+ * Fourcc: MSZH, ZLIB
+ *
+ * Win32 dll:
+ * Ver2.23 By Kenji Oshima 2000.09.20
+ * avimszh.dll, avizlib.dll
+ *
+ * A description of the decoding algorithm can be found here:
+ * http://www.pcisys.net/~melanson/codecs
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "config.h"
+
+#ifdef HAVE_ZLIB
+#include <zlib.h>
+#endif
+
+#include "mp_msg.h"
+
+#include "vd_internal.h"
+
+
+static vd_info_t info = {
+ "LCL Video decoder",
+ "lcl",
+ "Roberto Togni",
+ "Roberto Togni",
+ "native codec"
+};
+
+LIBVD_EXTERN(lcl)
+
+
+#define BMPTYPE_YUV 1
+#define BMPTYPE_RGB 2
+
+#define IMGTYPE_YUV111 0
+#define IMGTYPE_YUV422 1
+#define IMGTYPE_RGB24 2
+#define IMGTYPE_YUV411 3
+#define IMGTYPE_YUV211 4
+#define IMGTYPE_YUV420 5
+
+#define COMP_MSZH 0
+#define COMP_MSZH_NOCOMP 1
+#define COMP_ZLIB_HISPEED 1
+#define COMP_ZLIB_HICOMP 9
+#define COMP_ZLIB_NORMAL -1
+
+#define FLAG_MULTITHREAD 1
+#define FLAG_NULLFRAME 2
+#define FLAG_PNGFILTER 4
+#define FLAGMASK_UNUSED 0xf8
+
+#define CODEC_MSZH 1
+#define CODEC_ZLIB 3
+
+#define FOURCC_MSZH mmioFOURCC('M','S','Z','H')
+#define FOURCC_ZLIB mmioFOURCC('Z','L','I','B')
+
+/*
+ * Decoder context
+ */
+typedef struct {
+ // Image type
+ int imgtype;
+ // Compression type
+ int compression;
+ // Flags
+ int flags;
+ // Codec type
+ int codec;
+ // Decompressed data size
+ unsigned int decomp_size;
+ // Decompression buffer
+ unsigned char* decomp_buf;
+#ifdef HAVE_ZLIB
+ z_stream zstream;
+#endif
+} lcl_context_t;
+
+
+/*
+ * Internal function prototypes
+ */
+
+
+// to set/get/query special features/parameters
+static int control(sh_video_t *sh,int cmd,void* arg,...)
+{
+ switch(cmd) {
+ case VDCTRL_QUERY_FORMAT:
+ if (*((int*)arg) == IMGFMT_BGR24)
+ return CONTROL_TRUE;
+ else
+ return CONTROL_FALSE;
+ }
+ return CONTROL_UNKNOWN;
+}
+
+
+/*
+ *
+ * Init LCL decoder
+ *
+ */
+static int init(sh_video_t *sh)
+{
+ int vo_ret; // Video output init ret value
+ int zret; // Zlib return code
+ lcl_context_t *hc; // Decoder context
+ BITMAPINFOHEADER *bih = sh->bih;
+ int basesize = bih->biWidth * bih->biHeight;
+
+ if ((hc = malloc(sizeof(lcl_context_t))) == NULL) {
+ mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Can't allocate memory for LCL decoder context.\n");
+ return 0;
+ }
+
+ sh->context = (void *)hc;
+
+#ifdef HAVE_ZLIB
+ // Needed if zlib unused or init aborted before inflateInit
+ memset(&(hc->zstream), 0, sizeof(z_stream));
+#endif
+
+ if ((bih->biCompression != FOURCC_MSZH) && (bih->biCompression != FOURCC_ZLIB)) {
+ mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[LCL] Unknown BITMAPHEADER fourcc.\n");
+ return 0;
+ }
+
+ if (bih->biSize < sizeof(BITMAPINFOHEADER) + 8) {
+ mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] BITMAPHEADER size too small.\n");
+ return 0;
+ }
+
+ /* Detect codec type */
+ switch (hc->codec = *((char *)bih + sizeof(BITMAPINFOHEADER) + 7)) {
+ case CODEC_MSZH:
+ mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] Codec is MSZH.\n");
+ break;
+ case CODEC_ZLIB:
+ mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] Codec is ZLIB.\n");
+ break;
+ default:
+ mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[LCL] Unknown codec id %d. Trusting fourcc.\n", hc->codec);
+ switch (bih->biCompression) {
+ case FOURCC_MSZH:
+ hc->codec = CODEC_MSZH;
+ break;
+ case FOURCC_ZLIB:
+ hc->codec = CODEC_ZLIB;
+ break;
+ default:
+ mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[LCL] BUG! Unknown coded id and fourcc. Why am I here?.\n");
+ return 0;
+ }
+ }
+
+
+ /* Detect image type */
+ switch (hc->imgtype = *((char *)bih + sizeof(BITMAPINFOHEADER) + 4)) {
+ case IMGTYPE_YUV111:
+ hc->decomp_size = basesize * 3;
+ mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] Image type is YUV 1:1:1.\n");
+ break;
+ case IMGTYPE_YUV422:
+ hc->decomp_size = basesize * 2;
+ mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] Image type is YUV 4:2:2.\n");
+ break;
+ case IMGTYPE_RGB24:
+ hc->decomp_size = basesize * 3;
+ mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] Image type is RGB 24.\n");
+ break;
+ case IMGTYPE_YUV411:
+ hc->decomp_size = basesize / 2 * 3;
+ mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] Image type is YUV 4:1:1.\n");
+ break;
+ case IMGTYPE_YUV211:
+ hc->decomp_size = basesize * 2;
+ mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] Image type is YUV 2:1:1.\n");
+ break;
+ case IMGTYPE_YUV420:
+ hc->decomp_size = basesize / 2 * 3;
+ mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] Image type is YUV 4:2:0.\n");
+ break;
+ default:
+ mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] Unsupported image format %d.\n", hc->imgtype);
+ return 0;
+ }
+
+ /* Detect compression method */
+ hc->compression = *((char *)bih + sizeof(BITMAPINFOHEADER) + 5);
+ switch (hc->codec) {
+ case CODEC_MSZH:
+ switch (hc->compression) {
+ case COMP_MSZH:
+ mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] Compression enabled.\n");
+ break;
+ case COMP_MSZH_NOCOMP:
+ hc->decomp_size = 0;
+ mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] No compression.\n");
+ break;
+ default:
+ mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] Unsupported compression format for MSZH (%d).\n", hc->compression);
+ return 0;
+ }
+ break;
+ case CODEC_ZLIB:
+ switch (hc->compression) {
+ case COMP_ZLIB_HISPEED:
+ mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] High speed compression.\n");
+ break;
+ case COMP_ZLIB_HICOMP:
+ mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] High compression.\n");
+ break;
+ case COMP_ZLIB_NORMAL:
+ mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] Normal compression.\n");
+ break;
+ default:
+ mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] Unsupported compression format for ZLIB (%d).\n", hc->compression);
+ return 0;
+ }
+ break;
+ default:
+ mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] BUG! Unknown codec in compression switch.\n");
+ return 0;
+ }
+
+ /* Allocate decompression buffer */
+ /* 4*8 max oveflow space for mszh decomp algorithm */
+ if (hc->decomp_size) {
+ if ((hc->decomp_buf = malloc(hc->decomp_size+4*8)) == NULL) {
+ mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] Can't allocate decompression buffer.\n");
+ return 0;
+ }
+ }
+
+ /* Detect flags */
+ hc->flags = *((char *)bih + sizeof(BITMAPINFOHEADER) + 6);
+ if (hc->flags & FLAG_MULTITHREAD)
+ mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] Multithread encoder flag set.\n");
+ if (hc->flags & FLAG_NULLFRAME)
+ mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] Nullframe insertion flag set.\n");
+ if ((hc->codec == CODEC_ZLIB) && (hc->flags & FLAG_PNGFILTER))
+ mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[LCL] PNG filter flag set.\n");
+ if (hc->flags & FLAGMASK_UNUSED)
+ mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[LCL] Unknown flag set (%d).\n", hc->flags);
+
+ /* If needed init zlib */
+ if (hc->codec == CODEC_ZLIB) {
+#ifdef HAVE_ZLIB
+ hc->zstream.zalloc = Z_NULL;
+ hc->zstream.zfree = Z_NULL;
+ hc->zstream.opaque = Z_NULL;
+ zret = inflateInit(&(hc->zstream));
+ if (zret != Z_OK) {
+ mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] Inflate init error: %d\n", zret);
+ return 0;
+ }
+#else
+ mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] Zlib support not compiled.\n");
+ return 0;
+#endif
+ }
+
+ /*
+ * Initialize video output device
+ */
+ vo_ret = mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_BGR24);
+
+ return vo_ret;
+}
+
+
+
+
+/*
+ *
+ * Uninit LCL decoder
+ *
+ */
+static void uninit(sh_video_t *sh)
+{
+ lcl_context_t *hc = (lcl_context_t *) sh->context; // Decoder context
+
+ if (sh->context) {
+#ifdef HAVE_ZLIB
+ inflateEnd(&hc->zstream);
+#endif
+ free(sh->context);
+ }
+}
+
+
+
+inline unsigned char fix (int pix14)
+{
+ int tmp;
+
+ tmp = (pix14 + 0x80000) >> 20;
+ if (tmp < 0)
+ return 0;
+ if (tmp > 255)
+ return 255;
+ return tmp;
+}
+
+
+
+inline unsigned char get_b (unsigned char yq, signed char bq)
+{
+ return fix((yq << 20) + bq * 1858076);
+}
+
+
+
+inline unsigned char get_g (unsigned char yq, signed char bq, signed char rq)
+{
+ return fix((yq << 20) - bq * 360857 - rq * 748830);
+}
+
+
+
+inline unsigned char get_r (unsigned char yq, signed char rq)
+{
+ return fix((yq << 20) + rq * 1470103);
+}
+
+
+int mszh_decomp(unsigned char * srcptr, int srclen, unsigned char * destptr);
+
+/*
+ *
+ * Decode a frame
+ *
+ */
+static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags)
+{
+ mp_image_t* mpi;
+ int pixel_ptr;
+ int row, col;
+ unsigned char *encoded = (unsigned char *)data;
+ lcl_context_t *hc = (lcl_context_t *) sh->context; // Decoder context
+ unsigned char *outptr;
+ int width = sh->disp_w; // Real image width
+ int height = sh->disp_h; // Real image height
+#ifdef HAVE_ZLIB
+ int zret; // Zlib return code
+#endif
+ unsigned int mszh_dlen;
+ unsigned char yq, y1q, uq, vq;
+ int uqvq;
+ unsigned int mthread_inlen, mthread_outlen;
+
+ // Skipped frame
+ if(len <= 0)
+ return NULL;
+
+ /* Get output image buffer */
+ mpi=mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, 0, sh->disp_w, sh->disp_h);
+ if (!mpi) {
+ mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Can't allocate mpi image for lcl codec.\n");
+ return NULL;
+ }
+
+ outptr = mpi->planes[0]; // Output image pointer
+
+
+ /* Decompress frame */
+ switch (hc->codec) {
+ case CODEC_MSZH:
+ switch (hc->compression) {
+ case COMP_MSZH:
+ if (hc->flags & FLAG_MULTITHREAD) {
+ mthread_inlen = *((unsigned int*)encoded);
+ mthread_outlen = *((unsigned int*)(encoded+4));
+ mszh_dlen = mszh_decomp(encoded + 8, mthread_inlen, hc->decomp_buf);
+ if (mthread_outlen != mszh_dlen) {
+ mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[LCL] MSZH: mthread1 decoded size differs (%d != %d)\n",
+ mthread_outlen, mszh_dlen);
+ }
+ mszh_dlen = mszh_decomp(encoded + 8 + mthread_inlen, len - mthread_inlen,
+ hc->decomp_buf + mthread_outlen);
+ if ((hc->decomp_size - mthread_outlen) != mszh_dlen) {
+ mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[LCL] MSZH: mthread2 decoded size differs (%d != %d)\n",
+ hc->decomp_size - mthread_outlen, mszh_dlen);
+ }
+ encoded = hc->decomp_buf;
+ len = hc->decomp_size;
+ } else {
+ mszh_dlen = mszh_decomp(encoded, len, hc->decomp_buf);
+ if (hc->decomp_size != mszh_dlen) {
+ mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[LCL] MSZH: decoded size differs (%d != %d)\n",
+ hc->decomp_size, mszh_dlen);
+ }
+ encoded = hc->decomp_buf;
+ len = mszh_dlen;
+ }
+ break;
+ case COMP_MSZH_NOCOMP:
+ break;
+ default:
+ mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] BUG! Unknown MSZH compression in frame decoder.\n");
+ return 0;
+ }
+ break;
+ case CODEC_ZLIB:
+ switch (hc->compression) {
+ case COMP_ZLIB_HISPEED:
+ case COMP_ZLIB_HICOMP:
+ case COMP_ZLIB_NORMAL:
+#ifdef HAVE_ZLIB
+ zret = inflateReset(&(hc->zstream));
+ if (zret != Z_OK) {
+ mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] ZLIB: inflate reset error: %d\n", zret);
+ return 0;
+ }
+ if (hc->flags & FLAG_MULTITHREAD) {
+ mthread_inlen = *((unsigned int*)encoded);
+ mthread_outlen = *((unsigned int*)(encoded+4));
+ hc->zstream.next_in = encoded + 8;
+ hc->zstream.avail_in = mthread_inlen;
+ hc->zstream.next_out = hc->decomp_buf;
+ hc->zstream.avail_out = mthread_outlen;
+ zret = inflate(&(hc->zstream), Z_FINISH);
+ if ((zret != Z_OK) && (zret != Z_STREAM_END)) {
+ mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] ZLIB: mthread1 inflate error: %d\n", zret);
+ return 0;
+ }
+ if (mthread_outlen != (unsigned int)(hc->zstream.total_out)) {
+ mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[LCL] ZLIB: mthread1 decoded size differs (%d != %d)\n",
+ mthread_outlen, hc->zstream.total_out);
+ }
+ zret = inflateReset(&(hc->zstream));
+ if (zret != Z_OK) {
+ mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] ZLIB: mthread2 inflate reset error: %d\n", zret);
+ return 0;
+ }
+ hc->zstream.next_in = encoded + 8 + mthread_inlen;
+ hc->zstream.avail_in = len - mthread_inlen;
+ hc->zstream.next_out = hc->decomp_buf + mthread_outlen;
+ hc->zstream.avail_out = mthread_outlen;
+ zret = inflate(&(hc->zstream), Z_FINISH);
+ if ((zret != Z_OK) && (zret != Z_STREAM_END)) {
+ mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] ZLIB: mthread2 inflate error: %d\n", zret);
+ return 0;
+ }
+ if ((hc->decomp_size - mthread_outlen) != (unsigned int)(hc->zstream.total_out)) {
+ mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[LCL] ZLIB: mthread2 decoded size differs (%d != %d)\n",
+ hc->decomp_size - mthread_outlen, hc->zstream.total_out);
+ }
+ } else {
+ hc->zstream.next_in = data;
+ hc->zstream.avail_in = len;
+ hc->zstream.next_out = hc->decomp_buf;
+ hc->zstream.avail_out = hc->decomp_size;
+ zret = inflate(&(hc->zstream), Z_FINISH);
+ if ((zret != Z_OK) && (zret != Z_STREAM_END)) {
+ mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] ZLIB: inflate error: %d\n", zret);
+ return 0;
+ }
+ if (hc->decomp_size != (unsigned int)(hc->zstream.total_out)) {
+ mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[LCL] ZLIB: decoded size differs (%d != %d)\n",
+ hc->decomp_size, hc->zstream.total_out);
+ }
+ }
+ encoded = hc->decomp_buf;
+ len = hc->decomp_size;;
+#else
+ mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] BUG! Zlib support not compiled in frame decoder.\n");
+ return 0;
+#endif
+ break;
+ default:
+ mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] BUG! Unknown ZLIB compression in frame decoder.\n");
+ return 0;
+ }
+ break;
+ default:
+ mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] BUG! Unknown codec in frame decoder compression switch.\n");
+ return 0;
+ }
+
+
+ /* Apply PNG filter */
+ if ((hc->codec == CODEC_ZLIB) && (hc->flags & FLAG_PNGFILTER)) {
+ switch (hc->imgtype) {
+ case IMGTYPE_YUV111:
+ for (row = 0; row < height; row++) {
+ pixel_ptr = row * width * 3;
+ yq = encoded[pixel_ptr++];
+ uqvq = encoded[pixel_ptr++] + (encoded[pixel_ptr++] << 8);
+ for (col = 1; col < width; col++) {
+ encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
+ uqvq -= (encoded[pixel_ptr+1] | (encoded[pixel_ptr+2]<<8));
+ encoded[pixel_ptr+1] = (uqvq) & 0xff;
+ encoded[pixel_ptr+2] = ((uqvq)>>8) & 0xff;
+ pixel_ptr += 3;
+ }
+ }
+ break;
+ case IMGTYPE_RGB24: // No
+ for (row = 0; row < height; row++) {
+ pixel_ptr = row * width * 3;
+ yq = encoded[pixel_ptr++];
+ uqvq = encoded[pixel_ptr++] + (encoded[pixel_ptr++] << 8);
+ for (col = 1; col < width; col++) {
+ encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
+ uqvq -= (encoded[pixel_ptr+1] | (encoded[pixel_ptr+2]<<8));
+ encoded[pixel_ptr+1] = (uqvq) & 0xff;
+ encoded[pixel_ptr+2] = ((uqvq)>>8) & 0xff;
+ pixel_ptr += 3;
+ }
+ }
+ break;
+ case IMGTYPE_YUV422:
+ for (row = 0; row < height; row++) {
+ pixel_ptr = row * width * 2;
+ yq = uq = vq =0;
+ for (col = 0; col < width/4; col++) {
+ encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
+ encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
+ encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
+ encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
+ encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
+ encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5];
+ encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6];
+ encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7];
+ pixel_ptr += 8;
+ }
+ }
+ break;
+ case IMGTYPE_YUV411:
+ for (row = 0; row < height; row++) {
+ pixel_ptr = row * width / 2 * 3;
+ yq = uq = vq =0;
+ for (col = 0; col < width/4; col++) {
+ encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
+ encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
+ encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
+ encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
+ encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
+ encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
+ pixel_ptr += 6;
+ }
+ }
+ break;
+ case IMGTYPE_YUV211:
+ for (row = 0; row < height; row++) {
+ pixel_ptr = row * width * 2;
+ yq = uq = vq =0;
+ for (col = 0; col < width/2; col++) {
+ encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
+ encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
+ encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2];
+ encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3];
+ pixel_ptr += 4;
+ }
+ }
+ break;
+ case IMGTYPE_YUV420:
+ for (row = 0; row < height/2; row++) {
+ pixel_ptr = row * width * 3;
+ yq = y1q = uq = vq =0;
+ for (col = 0; col < width/2; col++) {
+ encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
+ encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
+ encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2];
+ encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3];
+ encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
+ encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
+ pixel_ptr += 6;
+ }
+ }
+ break;
+ break;
+ default:
+ mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] BUG! Unknown imagetype in pngfilter switch.\n");
+ return 0;
+ }
+ }
+
+ /* Convert colorspace */
+ switch (hc->imgtype) {
+ case IMGTYPE_YUV111:
+ for (row = height - 1; row >= 0; row--) {
+ pixel_ptr = row * mpi->stride[0];
+ for (col = 0; col < width; col++) {
+ outptr[pixel_ptr++] = get_b(encoded[0], encoded[1]);
+ outptr[pixel_ptr++] = get_g(encoded[0], encoded[1], encoded[2]);
+ outptr[pixel_ptr++] = get_r(encoded[0], encoded[2]);
+ encoded += 3;
+ }
+ }
+ break;
+ case IMGTYPE_YUV422:
+ for (row = height - 1; row >= 0; row--) {
+ pixel_ptr = row * mpi->stride[0];
+ for (col = 0; col < width/4; col++) {
+ outptr[pixel_ptr++] = get_b(encoded[0], encoded[4]);
+ outptr[pixel_ptr++] = get_g(encoded[0], encoded[4], encoded[6]);
+ outptr[pixel_ptr++] = get_r(encoded[0], encoded[6]);
+ outptr[pixel_ptr++] = get_b(encoded[1], encoded[4]);
+ outptr[pixel_ptr++] = get_g(encoded[1], encoded[4], encoded[6]);
+ outptr[pixel_ptr++] = get_r(encoded[1], encoded[6]);
+ outptr[pixel_ptr++] = get_b(encoded[2], encoded[5]);
+ outptr[pixel_ptr++] = get_g(encoded[2], encoded[5], encoded[7]);
+ outptr[pixel_ptr++] = get_r(encoded[2], encoded[7]);
+ outptr[pixel_ptr++] = get_b(encoded[3], encoded[5]);
+ outptr[pixel_ptr++] = get_g(encoded[3], encoded[5], encoded[7]);
+ outptr[pixel_ptr++] = get_r(encoded[3], encoded[7]);
+ encoded += 8;
+ }
+ }
+ break;
+ case IMGTYPE_RGB24:
+ for (row = height - 1; row >= 0; row--) {
+ pixel_ptr = row * mpi->stride[0];
+ for (col = 0; col < width; col++) {
+ outptr[pixel_ptr++] = encoded[0];
+ outptr[pixel_ptr++] = encoded[1];
+ outptr[pixel_ptr++] = encoded[2];
+ encoded += 3;
+ }
+ }
+ break;
+ case IMGTYPE_YUV411:
+ for (row = height - 1; row >= 0; row--) {
+ pixel_ptr = row * mpi->stride[0];
+ for (col = 0; col < width/4; col++) {
+ outptr[pixel_ptr++] = get_b(encoded[0], encoded[4]);
+ outptr[pixel_ptr++] = get_g(encoded[0], encoded[4], encoded[5]);
+ outptr[pixel_ptr++] = get_r(encoded[0], encoded[5]);
+ outptr[pixel_ptr++] = get_b(encoded[1], encoded[4]);
+ outptr[pixel_ptr++] = get_g(encoded[1], encoded[4], encoded[5]);
+ outptr[pixel_ptr++] = get_r(encoded[1], encoded[5]);
+ outptr[pixel_ptr++] = get_b(encoded[2], encoded[4]);
+ outptr[pixel_ptr++] = get_g(encoded[2], encoded[4], encoded[5]);
+ outptr[pixel_ptr++] = get_r(encoded[2], encoded[5]);
+ outptr[pixel_ptr++] = get_b(encoded[3], encoded[4]);
+ outptr[pixel_ptr++] = get_g(encoded[3], encoded[4], encoded[5]);
+ outptr[pixel_ptr++] = get_r(encoded[3], encoded[5]);
+ encoded += 6;
+ }
+ }
+ break;
+ case IMGTYPE_YUV211:
+ for (row = height - 1; row >= 0; row--) {
+ pixel_ptr = row * mpi->stride[0];
+ for (col = 0; col < width/2; col++) {
+ outptr[pixel_ptr++] = get_b(encoded[0], encoded[2]);
+ outptr[pixel_ptr++] = get_g(encoded[0], encoded[2], encoded[3]);
+ outptr[pixel_ptr++] = get_r(encoded[0], encoded[3]);
+ outptr[pixel_ptr++] = get_b(encoded[1], encoded[2]);
+ outptr[pixel_ptr++] = get_g(encoded[1], encoded[2], encoded[3]);
+ outptr[pixel_ptr++] = get_r(encoded[1], encoded[3]);
+ encoded += 4;
+ }
+ }
+ break;
+ case IMGTYPE_YUV420:
+ for (row = height / 2 - 1; row >= 0; row--) {
+ pixel_ptr = 2 * row * mpi->stride[0];
+ for (col = 0; col < width/2; col++) {
+ outptr[pixel_ptr] = get_b(encoded[0], encoded[4]);
+ outptr[pixel_ptr+1] = get_g(encoded[0], encoded[4], encoded[5]);
+ outptr[pixel_ptr+2] = get_r(encoded[0], encoded[5]);
+ outptr[pixel_ptr+3] = get_b(encoded[1], encoded[4]);
+ outptr[pixel_ptr+4] = get_g(encoded[1], encoded[4], encoded[5]);
+ outptr[pixel_ptr+5] = get_r(encoded[1], encoded[5]);
+ outptr[pixel_ptr-mpi->stride[0]] = get_b(encoded[2], encoded[4]);
+ outptr[pixel_ptr-mpi->stride[0]+1] = get_g(encoded[2], encoded[4], encoded[5]);
+ outptr[pixel_ptr-mpi->stride[0]+2] = get_r(encoded[2], encoded[5]);
+ outptr[pixel_ptr-mpi->stride[0]+3] = get_b(encoded[3], encoded[4]);
+ outptr[pixel_ptr-mpi->stride[0]+4] = get_g(encoded[3], encoded[4], encoded[5]);
+ outptr[pixel_ptr-mpi->stride[0]+5] = get_r(encoded[3], encoded[5]);
+ pixel_ptr += 6;
+ encoded += 6;
+ }
+ }
+ break;
+ default:
+ mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[LCL] BUG! Unknown imagetype in image decoder.\n");
+ return 0;
+ }
+
+ return mpi;
+}
+
+
+
+int mszh_decomp(unsigned char * srcptr, int srclen, unsigned char * destptr)
+{
+ unsigned char *destptr_bak = destptr;
+ unsigned char mask = 0;
+ unsigned char maskbit = 0;
+ unsigned int ofs, cnt;
+
+ while (srclen > 0) {
+ if (maskbit == 0) {
+ mask = *(srcptr++);
+ maskbit = 8;
+ srclen--;
+ continue;
+ }
+ if ((mask & (1 << (--maskbit))) == 0) {
+ *(destptr++) = *(srcptr++);
+ *(destptr++) = *(srcptr++);
+ *(destptr++) = *(srcptr++);
+ *(destptr++) = *(srcptr++);
+ srclen -= 4;
+ } else {
+ ofs = *(srcptr++);
+ cnt = *(srcptr++);
+ ofs += cnt * 256;;
+ cnt = ((cnt >> 3) & 0x1f) + 1;
+ ofs &= 0x7ff;
+ srclen -= 2;
+ cnt *= 4;
+ for (; cnt > 0; cnt--) {
+ *(destptr) = *(destptr - ofs);
+ destptr++;
+ }
+ }
+ }
+
+ return (destptr - destptr_bak);
+}
+
diff --git a/libmpcodecs/vd_zlib.c b/libmpcodecs/vd_zlib.c
deleted file mode 100644
index c22be627cc..0000000000
--- a/libmpcodecs/vd_zlib.c
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- AVIzlib decoder
-
- http://www.pcisys.net/~melanson/codecs/lcl.txt
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "config.h"
-
-#ifdef HAVE_ZLIB
-#include "mp_msg.h"
-
-#include <zlib.h>
-
-#include "vd_internal.h"
-
-static vd_info_t info = {
- "AVIzlib decoder",
- "zlib",
- "Alex",
- "Alex",
- "based on vd_ijpg.c, uses zlib, supports only BGR24 (as AVIzlib)"
-};
-
-LIBVD_EXTERN(zlib)
-
-typedef struct {
- int width;
- int height;
- int imgformat;
- int decompsize;
- z_stream zstrm;
-} vd_zlib_ctx;
-
-/* BITMAPINFOHEADER LCL Extension */
-typedef struct {
- unsigned char filler[sizeof(BITMAPINFOHEADER)];
- unsigned char unknown[4];
- unsigned char imgtype;
- unsigned char compression;
- unsigned char flags;
- unsigned char codec;
-} bih_lcl_ext;
-
-// to set/get/query special features/parameters
-static int control(sh_video_t *sh, int cmd, void *arg, ...)
-{
- vd_zlib_ctx *ctx = sh->context;
- switch(cmd)
- {
- case VDCTRL_QUERY_FORMAT:
- {
- if (*((int*)arg) == (ctx->imgformat))
- return(CONTROL_TRUE);
- else
- return(CONTROL_FALSE);
- }
- }
- return(CONTROL_UNKNOWN);
-}
-
-// init driver
-static int init(sh_video_t *sh)
-{
- int zret;
- vd_zlib_ctx *ctx;
- bih_lcl_ext *ext;
-
- ctx = sh->context = malloc(sizeof(vd_zlib_ctx));
- if (!ctx)
- return(0);
- memset(ctx, 0, sizeof(vd_zlib_ctx));
-
- ctx->width = sh->bih->biWidth;
- ctx->height = sh->bih->biHeight;
- ctx->imgformat = IMGFMT_BGR24;
- ctx->decompsize = ctx->width*ctx->height*((24+7)/8);
-
- if (sh->bih->biSize > sizeof(BITMAPINFOHEADER))
- {
- ext = sh->bih;
- if (ext->codec != 3) /* 1 == MSZH, 3 == ZLIB */
- return(0);
- switch(ext->imgtype)
- {
- case 2: /* RGB24 */
- ctx->imgformat = IMGFMT_BGR24;
- ctx->decompsize = ctx->width*ctx->height*((24+7)/8);
- break;
- case 0: /* YUV411 */
-// ctx->imgformat = IMGFMT_YVU9;
-// ctx->decompsize = ctx->width*(ctx->height+2)/8*9;
-// break;
- case 1: /* YUV422 */
-// ctx->imgformat = IMGFMT_YUY2;
-// ctx->decompsize = ctx->width*(ctx->height+2)/8*16;
-// break;
- case 5: /* YUV420 */
-// ctx->imgformat = IMGFMT_YV12;
-// ctx->decompsize = ctx->width*(ctx->height+2)/8*12;
-// break;
- case 3: /* YUV411 */
- case 4: /* YUV211 */
- default:
- printf("Unknown imgtype\n");
- return(0);
- }
- }
-
- ctx->zstrm.zalloc = (alloc_func)NULL;
- ctx->zstrm.zfree = (free_func)NULL;
- ctx->zstrm.opaque = (voidpf)NULL;
-
- zret = inflateInit(&ctx->zstrm);
- if (zret != Z_OK)
- {
- mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[vd_zlib] inflate init error: %d\n",
- zret);
- return(NULL);
- }
-
- if (!mpcodecs_config_vo(sh, ctx->width, ctx->height, ctx->imgformat))
- return(NULL);
-
-
- return(1);
-}
-
-// uninit driver
-static void uninit(sh_video_t *sh)
-{
- vd_zlib_ctx *ctx = sh->context;
-
- inflateEnd(&ctx->zstrm);
- if (ctx)
- free(ctx);
-}
-
-//mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h);
-
-// decode a frame
-static mp_image_t* decode(sh_video_t *sh, void* data, int len, int flags)
-{
- mp_image_t *mpi;
- vd_zlib_ctx *ctx = sh->context;
- int zret;
- z_stream *zstrm = &ctx->zstrm;
-
- if (len <= 0)
- return(NULL); // skipped frame
-
- mpi = mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, 0, ctx->width, ctx->height);
- if (!mpi) return(NULL);
-
- zstrm->next_in = data;
- zstrm->avail_in = len;
- zstrm->next_out = mpi->planes[0];
- zstrm->avail_out = ctx->decompsize;
-
- mp_dbg(MSGT_DECVIDEO, MSGL_DBG2, "[vd_zlib] input: %p (%d bytes), output: %p (%d bytes)\n",
- zstrm->next_in, zstrm->avail_in, zstrm->next_out, zstrm->avail_out);
-
- zret = inflate(zstrm, Z_NO_FLUSH);
- if ((zret != Z_OK) && (zret != Z_STREAM_END))
- {
- mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[vd_zlib] inflate error: %d\n",
- zret);
- return(NULL);
- }
-
- if (ctx->decompsize != (int)zstrm->total_out)
- {
- mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[vd_zlib] decoded size differs (%d != %d)\n",
- ctx->decompsize, zstrm->total_out);
- return(NULL);
- }
-
- return mpi;
-}
-#endif