annotate libmpcodecs/vd_zlib.c @ 5277:7df9fc3308ac

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