annotate libmpcodecs/vd_zlib.c @ 7191:1eadce15446c

-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
author arpi
date Sat, 31 Aug 2002 13:09:23 +0000
parents 28677d779205
children c2ce155088b6
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 = {
7191
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
14 "AVIzlib decoder",
5262
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 "Alex",
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
17 "based on vd_ijpg.c",
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
18 "uses zlib, supports only BGR24 (as AVIzlib)"
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
19 };
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 LIBVD_EXTERN(zlib)
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
22
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
23 typedef struct {
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
24 int width;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
25 int height;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
26 int depth;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
27 z_stream zstrm;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
28 } vd_zlib_ctx;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
29
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
30 // to set/get/query special features/parameters
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
31 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
32 {
5279
652ec33400fd 10l, hopefully fixed query format
alex
parents: 5278
diff changeset
33 vd_zlib_ctx *ctx = sh->context;
5262
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 {
5279
652ec33400fd 10l, hopefully fixed query format
alex
parents: 5278
diff changeset
38 if (*((int*)arg) == (IMGFMT_BGR|ctx->depth))
5278
a11cd73811a8 fixed query format
alex
parents: 5277
diff changeset
39 return(CONTROL_TRUE);
a11cd73811a8 fixed query format
alex
parents: 5277
diff changeset
40 else
a11cd73811a8 fixed query format
alex
parents: 5277
diff changeset
41 return(CONTROL_FALSE);
5262
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
42 }
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 return(CONTROL_UNKNOWN);
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
45 }
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 // init driver
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
48 static int init(sh_video_t *sh)
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
49 {
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
50 int zret;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
51 vd_zlib_ctx *ctx;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
52
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
53 ctx = sh->context = malloc(sizeof(vd_zlib_ctx));
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
54 if (!ctx)
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
55 return(0);
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
56 memset(ctx, 0, sizeof(vd_zlib_ctx));
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
57
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
58 ctx->width = sh->bih->biWidth;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
59 ctx->height = sh->bih->biHeight;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
60 ctx->depth = sh->bih->biBitCount;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
61
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
62 ctx->zstrm.zalloc = (alloc_func)NULL;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
63 ctx->zstrm.zfree = (free_func)NULL;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
64 ctx->zstrm.opaque = (voidpf)NULL;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
65
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
66 zret = inflateInit(&ctx->zstrm);
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
67 if (zret != Z_OK)
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
68 {
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
69 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
70 zret);
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
71 return(NULL);
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
72 }
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 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
75 return(NULL);
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
76
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 return(1);
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
79 }
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 // uninit driver
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
82 static void uninit(sh_video_t *sh)
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 vd_zlib_ctx *ctx = sh->context;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
85
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
86 inflateEnd(&ctx->zstrm);
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
87 if (ctx)
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
88 free(ctx);
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
89 }
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 //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
92
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
93 // decode a frame
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
94 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
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
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
97 vd_zlib_ctx *ctx = sh->context;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
98 int zret;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
99 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
100 z_stream *zstrm = &ctx->zstrm;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
101
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
102 if (len <= 0)
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
103 return(NULL); // skipped frame
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
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
8037d34ce806 moved get_image into decoder (Arpi's request)
alex
parents: 5262
diff changeset
107
5262
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
108 zstrm->next_in = data;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
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
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
111 zstrm->avail_out = decomp_size;
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
112
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
113 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
114 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
115
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
116 zret = inflate(zstrm, Z_NO_FLUSH);
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
117 if ((zret != Z_OK) && (zret != Z_STREAM_END))
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
118 {
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
119 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
120 zret);
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
121 return(NULL);
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
122 }
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 if (decomp_size != (int)zstrm->total_out)
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
125 {
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
126 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
127 decomp_size, zstrm->total_out);
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
128 return(NULL);
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
129 }
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
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
7c1425197af0 added, supporting only BGR24 (avizlib.dll does the same)
alex
parents:
diff changeset
132 }
6335
e9bd97d5c5cc warning & newline fixes by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents: 5279
diff changeset
133 #endif