Mercurial > mplayer.hg
annotate libmpcodecs/vd_zlib.c @ 7194:6df5abe8d967
fix flip handling bug
author | alex |
---|---|
date | Sat, 31 Aug 2002 13:29:26 +0000 |
parents | 1eadce15446c |
children | c2ce155088b6 |
rev | line source |
---|---|
5262 | 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 = { | |
7191
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
14 "AVIzlib decoder", |
5262 | 15 "zlib", |
16 "Alex", | |
17 "based on vd_ijpg.c", | |
18 "uses zlib, supports only BGR24 (as AVIzlib)" | |
19 }; | |
20 | |
21 LIBVD_EXTERN(zlib) | |
22 | |
23 typedef struct { | |
24 int width; | |
25 int height; | |
26 int depth; | |
27 z_stream zstrm; | |
28 } vd_zlib_ctx; | |
29 | |
30 // to set/get/query special features/parameters | |
31 static int control(sh_video_t *sh, int cmd, void *arg, ...) | |
32 { | |
5279 | 33 vd_zlib_ctx *ctx = sh->context; |
5262 | 34 switch(cmd) |
35 { | |
36 case VDCTRL_QUERY_FORMAT: | |
37 { | |
5279 | 38 if (*((int*)arg) == (IMGFMT_BGR|ctx->depth)) |
5278 | 39 return(CONTROL_TRUE); |
40 else | |
41 return(CONTROL_FALSE); | |
5262 | 42 } |
43 } | |
44 return(CONTROL_UNKNOWN); | |
45 } | |
46 | |
47 // init driver | |
48 static int init(sh_video_t *sh) | |
49 { | |
50 int zret; | |
51 vd_zlib_ctx *ctx; | |
52 | |
53 ctx = sh->context = malloc(sizeof(vd_zlib_ctx)); | |
54 if (!ctx) | |
55 return(0); | |
56 memset(ctx, 0, sizeof(vd_zlib_ctx)); | |
57 | |
58 ctx->width = sh->bih->biWidth; | |
59 ctx->height = sh->bih->biHeight; | |
60 ctx->depth = sh->bih->biBitCount; | |
61 | |
62 ctx->zstrm.zalloc = (alloc_func)NULL; | |
63 ctx->zstrm.zfree = (free_func)NULL; | |
64 ctx->zstrm.opaque = (voidpf)NULL; | |
65 | |
66 zret = inflateInit(&ctx->zstrm); | |
67 if (zret != Z_OK) | |
68 { | |
69 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[vd_zlib] inflate init error: %d\n", | |
70 zret); | |
71 return(NULL); | |
72 } | |
73 | |
74 if (!mpcodecs_config_vo(sh, ctx->width, ctx->height, IMGFMT_BGR|ctx->depth)) | |
75 return(NULL); | |
76 | |
77 | |
78 return(1); | |
79 } | |
80 | |
81 // uninit driver | |
82 static void uninit(sh_video_t *sh) | |
83 { | |
84 vd_zlib_ctx *ctx = sh->context; | |
85 | |
86 inflateEnd(&ctx->zstrm); | |
87 if (ctx) | |
88 free(ctx); | |
89 } | |
90 | |
91 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h); | |
92 | |
93 // decode a frame | |
94 static mp_image_t* decode(sh_video_t *sh, void* data, int len, int flags) | |
95 { | |
5277
7df9fc3308ac
10l. IMGFLAG_ALLOCATED shouldn't be set from vd driver\! - it's for internal use by the core
arpi
parents:
5276
diff
changeset
|
96 mp_image_t *mpi; |
5262 | 97 vd_zlib_ctx *ctx = sh->context; |
98 int zret; | |
99 int decomp_size = ctx->width*ctx->height*((ctx->depth+7)/8); | |
100 z_stream *zstrm = &ctx->zstrm; | |
101 | |
102 if (len <= 0) | |
103 return(NULL); // skipped frame | |
104 | |
5277
7df9fc3308ac
10l. IMGFLAG_ALLOCATED shouldn't be set from vd driver\! - it's for internal use by the core
arpi
parents:
5276
diff
changeset
|
105 mpi = mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, 0, ctx->width, ctx->height); |
7df9fc3308ac
10l. IMGFLAG_ALLOCATED shouldn't be set from vd driver\! - it's for internal use by the core
arpi
parents:
5276
diff
changeset
|
106 if (!mpi) return(NULL); |
5276 | 107 |
5262 | 108 zstrm->next_in = data; |
109 zstrm->avail_in = len; | |
5277
7df9fc3308ac
10l. IMGFLAG_ALLOCATED shouldn't be set from vd driver\! - it's for internal use by the core
arpi
parents:
5276
diff
changeset
|
110 zstrm->next_out = mpi->planes[0]; |
5262 | 111 zstrm->avail_out = decomp_size; |
112 | |
113 mp_dbg(MSGT_DECVIDEO, MSGL_DBG2, "[vd_zlib] input: %p (%d bytes), output: %p (%d bytes)\n", | |
114 zstrm->next_in, zstrm->avail_in, zstrm->next_out, zstrm->avail_out); | |
115 | |
116 zret = inflate(zstrm, Z_NO_FLUSH); | |
117 if ((zret != Z_OK) && (zret != Z_STREAM_END)) | |
118 { | |
119 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[vd_zlib] inflate error: %d\n", | |
120 zret); | |
121 return(NULL); | |
122 } | |
123 | |
124 if (decomp_size != (int)zstrm->total_out) | |
125 { | |
126 mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[vd_zlib] decoded size differs (%d != %d)\n", | |
127 decomp_size, zstrm->total_out); | |
128 return(NULL); | |
129 } | |
130 | |
5277
7df9fc3308ac
10l. IMGFLAG_ALLOCATED shouldn't be set from vd driver\! - it's for internal use by the core
arpi
parents:
5276
diff
changeset
|
131 return mpi; |
5262 | 132 } |
6335
e9bd97d5c5cc
warning & newline fixes by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents:
5279
diff
changeset
|
133 #endif |