annotate libmpcodecs/vd_zlib.c @ 5300:5d7bd47b46ef

OS2 support
author arpi
date Sun, 24 Mar 2002 01:09:08 +0000
parents 652ec33400fd
children e9bd97d5c5cc
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 {
5279
652ec33400fd 10l, hopefully fixed query format
alex
parents: 5278
diff changeset
34 vd_zlib_ctx *ctx = sh->context;
5262
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
35 switch(cmd)
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
36 {
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
37 case VDCTRL_QUERY_FORMAT:
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
38 {
5279
652ec33400fd 10l, hopefully fixed query format
alex
parents: 5278
diff changeset
39 if (*((int*)arg) == (IMGFMT_BGR|ctx->depth))
5278
a11cd73811a8 fixed query format
alex
parents: 5277
diff changeset
40 return(CONTROL_TRUE);
a11cd73811a8 fixed query format
alex
parents: 5277
diff changeset
41 else
a11cd73811a8 fixed query format
alex
parents: 5277
diff changeset
42 return(CONTROL_FALSE);
5262
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 return(CONTROL_UNKNOWN);
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
46 }
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 // init driver
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
49 static int init(sh_video_t *sh)
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 int zret;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
52 vd_zlib_ctx *ctx;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
53
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
54 ctx = sh->context = malloc(sizeof(vd_zlib_ctx));
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
55 if (!ctx)
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
56 return(0);
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
57 memset(ctx, 0, sizeof(vd_zlib_ctx));
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
58
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
59 ctx->width = sh->bih->biWidth;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
60 ctx->height = sh->bih->biHeight;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
61 ctx->depth = sh->bih->biBitCount;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
62
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
63 ctx->zstrm.zalloc = (alloc_func)NULL;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
64 ctx->zstrm.zfree = (free_func)NULL;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
65 ctx->zstrm.opaque = (voidpf)NULL;
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 zret = inflateInit(&ctx->zstrm);
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
68 if (zret != Z_OK)
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
69 {
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
70 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
71 zret);
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
72 return(NULL);
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
73 }
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 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
76 return(NULL);
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 return(1);
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
80 }
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 // uninit driver
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
83 static void uninit(sh_video_t *sh)
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
84 {
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
85 vd_zlib_ctx *ctx = sh->context;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
86
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
87 inflateEnd(&ctx->zstrm);
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
88 if (ctx)
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
89 free(ctx);
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
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
92 //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
93
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
94 // decode a frame
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
95 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
96 {
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
97 mp_image_t *mpi;
5262
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
98 vd_zlib_ctx *ctx = sh->context;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
99 int zret;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
100 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
101 z_stream *zstrm = &ctx->zstrm;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
102
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
103 if (len <= 0)
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
104 return(NULL); // skipped frame
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
105
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
106 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
107 if (!mpi) return(NULL);
5276
8037d34ce806 moved get_image into decoder (Arpi's request)
alex
parents: 5262
diff changeset
108
5262
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
109 zstrm->next_in = data;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
110 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
111 zstrm->next_out = mpi->planes[0];
5262
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
112 zstrm->avail_out = decomp_size;
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 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
115 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
116
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
117 zret = inflate(zstrm, Z_NO_FLUSH);
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
118 if ((zret != Z_OK) && (zret != Z_STREAM_END))
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
119 {
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
120 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
121 zret);
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
122 return(NULL);
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
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
125 if (decomp_size != (int)zstrm->total_out)
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
126 {
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
127 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
128 decomp_size, zstrm->total_out);
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
129 return(NULL);
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
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
132 return mpi;
5262
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
133 }
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
134 #endif