GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_container.h
1// SPDX-License-Identifier: LGPL-2.1-or-later
2/*
3 * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz>
4 */
5
6 /*
7
8 Container is an abstraction for file formats that can include several images
9 in one file. For example gif, tiff, apng, cbr, cbz, etc.
10
11 */
12
13#ifndef LOADERS_GP_CONTAINER_H
14#define LOADERS_GP_CONTAINER_H
15
16#include <core/gp_types.h>
18#include <utils/gp_seek.h>
19#include <loaders/gp_types.h>
20
21#include <loaders/gp_data_storage.h>
22
23struct gp_container_ops {
24 /*
25 * Loads next image from container, use the inline function defined
26 * below.
27 */
28 gp_pixmap *(*load_next)(gp_container *self, gp_progress_cb *callback);
29
30 /*
31 * Just loads current image, does not advance to the next image.
32 */
33 int (*load_ex)(gp_container *self, gp_pixmap **img,
34 gp_storage *storage, gp_progress_cb *callback);
35
36 /*
37 * Close callback, use the inline function defined below.
38 */
39 void (*close)(gp_container *self);
40
41 /*
42 * Seeks to the offset from whence.
43 *
44 * Returns 0 on success, errno on failure.
45 */
46 int (*seek)(gp_container *self, ssize_t offset,
47 enum gp_seek_whence whence);
48
49
50 int (*match)(const void *buf);
51
52 /*
53 * Initializes container.
54 */
55 gp_container *(*init)(gp_io *io);
56
57 /* Short format name */
58 const char *fmt_name;
59
60 /* NULL terminated list of file extensions */
61 const char *const extensions[];
62};
63
64struct gp_container {
65 /*
66 * Image counter. This is set to number of images, or to -1 if number
67 * of images in container is not known prior to parsing the whole
68 * file.
69 */
70 unsigned int img_count;
71
72 /*
73 * Current image counter, do not change from application.
74 */
75 unsigned int cur_img;
76
77 /*
78 * Contains container callbacks
79 */
80 const struct gp_container_ops *ops;
81
82 char priv[];
83};
84
85#define GP_CONTAINER_PRIV(c) ((void*)(c)->priv)
86
87/*
88 * Behaves just like gp_load_image, but takes pointer to opened container instead.
89 */
90static inline gp_pixmap *gp_container_load_next(gp_container *self,
91 gp_progress_cb *callback)
92{
93 return self->ops->load_next(self, callback);
94}
95
96/*
97 * Just loads current image, does not advance to the next one.
98 */
99int gp_container_load_ex(gp_container *self, gp_pixmap **img,
100 gp_storage *storage, gp_progress_cb *callback);
101
102static inline gp_pixmap *gp_container_load(gp_container *self,
103 gp_progress_cb *callback)
104{
105 gp_pixmap *ret = NULL;
106
107 gp_container_load_ex(self, &ret, NULL, callback);
108
109 return ret;
110}
111
112int gp_container_seek(gp_container *self, ssize_t offset,
113 enum gp_seek_whence whence);
114
115static inline void gp_container_close(gp_container *self)
116{
117 self->ops->close(self);
118}
119
120gp_container *gp_container_open(const char *path);
121
122#endif /* LOADERS_GP_CONTAINER_H */
A common types.
A progress callback.
Seek contants and transformations.
gp_seek_whence
Seek constants.
Definition gp_seek.h:24
A pixmap buffer.
Definition gp_pixmap.h:33
Progress callback.