comparison libmpcodecs/vd_zlib.c @ 5262:7c1425197af0

added, supporting only BGR24 (avizlib.dll does the same)
author alex
date Fri, 22 Mar 2002 21:20:50 +0000
parents
children 8037d34ce806
comparison
equal deleted inserted replaced
5261:9e80ac615570 5262:7c1425197af0
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 #include "config.h"
5
6 #ifdef HAVE_ZLIB
7 #include "mp_msg.h"
8
9 #include <zlib.h>
10
11 #include "vd_internal.h"
12
13 static vd_info_t info = {
14 "zlib decoder (avizlib)",
15 "zlib",
16 VFM_ZLIB,
17 "Alex",
18 "based on vd_ijpg.c",
19 "uses zlib, supports only BGR24 (as AVIzlib)"
20 };
21
22 LIBVD_EXTERN(zlib)
23
24 typedef struct {
25 int width;
26 int height;
27 int depth;
28 z_stream zstrm;
29 mp_image_t *mpi;
30 } vd_zlib_ctx;
31
32 // to set/get/query special features/parameters
33 static int control(sh_video_t *sh, int cmd, void *arg, ...)
34 {
35 switch(cmd)
36 {
37 case VDCTRL_QUERY_FORMAT:
38 {
39 *((int*)arg) = IMGFMT_BGR24;
40 return(CONTROL_TRUE);
41 }
42 }
43 return(CONTROL_UNKNOWN);
44 }
45
46 // init driver
47 static int init(sh_video_t *sh)
48 {
49 int zret;
50 vd_zlib_ctx *ctx;
51
52 ctx = sh->context = malloc(sizeof(vd_zlib_ctx));
53 if (!ctx)
54 return(0);
55 memset(ctx, 0, sizeof(vd_zlib_ctx));
56
57 ctx->width = sh->bih->biWidth;
58 ctx->height = sh->bih->biHeight;
59 ctx->depth = sh->bih->biBitCount;
60
61 ctx->zstrm.zalloc = (alloc_func)NULL;
62 ctx->zstrm.zfree = (free_func)NULL;
63 ctx->zstrm.opaque = (voidpf)NULL;
64
65 zret = inflateInit(&ctx->zstrm);
66 if (zret != Z_OK)
67 {
68 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[vd_zlib] inflate init error: %d\n",
69 zret);
70 return(NULL);
71 }
72
73 if (!mpcodecs_config_vo(sh, ctx->width, ctx->height, IMGFMT_BGR|ctx->depth))
74 return(NULL);
75
76 ctx->mpi = mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, MP_IMGFLAG_ALLOCATED,
77 ctx->width, ctx->height);
78 if (!ctx->mpi)
79 return(NULL);
80
81 return(1);
82 }
83
84 // uninit driver
85 static void uninit(sh_video_t *sh)
86 {
87 vd_zlib_ctx *ctx = sh->context;
88
89 inflateEnd(&ctx->zstrm);
90 if (ctx)
91 free(ctx);
92 }
93
94 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h);
95
96 // decode a frame
97 static mp_image_t* decode(sh_video_t *sh, void* data, int len, int flags)
98 {
99 vd_zlib_ctx *ctx = sh->context;
100 int zret;
101 int decomp_size = ctx->width*ctx->height*((ctx->depth+7)/8);
102 z_stream *zstrm = &ctx->zstrm;
103
104 if (len <= 0)
105 return(NULL); // skipped frame
106
107 zstrm->next_in = data;
108 zstrm->avail_in = len;
109 zstrm->next_out = ctx->mpi->planes[0];
110 zstrm->avail_out = decomp_size;
111
112 mp_dbg(MSGT_DECVIDEO, MSGL_DBG2, "[vd_zlib] input: %p (%d bytes), output: %p (%d bytes)\n",
113 zstrm->next_in, zstrm->avail_in, zstrm->next_out, zstrm->avail_out);
114
115 zret = inflate(zstrm, Z_NO_FLUSH);
116 if ((zret != Z_OK) && (zret != Z_STREAM_END))
117 {
118 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[vd_zlib] inflate error: %d\n",
119 zret);
120 return(NULL);
121 }
122
123 if (decomp_size != (int)zstrm->total_out)
124 {
125 mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[vd_zlib] decoded size differs (%d != %d)\n",
126 decomp_size, zstrm->total_out);
127 return(NULL);
128 }
129
130 return(ctx->mpi);
131 }
132 #endif