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>
17#include <core/gp_compiler.h>
19#include <utils/gp_seek.h>
20#include <loaders/gp_types.h>
21
23
24struct gp_container_ops {
25 /*
26 * Loads next image from container, use the inline function defined
27 * below.
28 */
29 gp_pixmap *(*load_next)(gp_container *self, gp_progress_cb *callback);
30
31 /*
32 * Just loads current image, does not advance to the next image.
33 */
34 int (*load_ex)(gp_container *self, gp_pixmap **img,
35 gp_storage *storage, gp_progress_cb *callback);
36
37 /*
38 * Close callback, use the inline function defined below.
39 */
40 void (*close)(gp_container *self);
41
42 /*
43 * Seeks to the offset from whence.
44 *
45 * Returns 0 on success, errno on failure.
46 */
47 int (*seek)(gp_container *self, ssize_t offset,
48 enum gp_seek_whence whence);
49
50
51 int (*match)(const void *buf);
52
53 /*
54 * Initializes container.
55 */
56 gp_container *(*init)(gp_io *io);
57
58 /* Short format name */
59 const char *fmt_name;
60
61 /* NULL terminated list of file extensions */
62 const char *const extensions[];
63};
64
65struct gp_container {
66 /*
67 * Image counter. This is set to number of images, or to -1 if number
68 * of images in container is not known prior to parsing the whole
69 * file.
70 */
71 unsigned int img_count;
72
73 /*
74 * Current image counter, do not change from application.
75 */
76 unsigned int cur_img;
77
78 /*
79 * Contains container callbacks
80 */
81 const struct gp_container_ops *ops;
82
83 char priv[] GP_ALIGNED;
84};
85
86#define GP_CONTAINER_PRIV(c) ((void*)(c)->priv)
87
88/*
89 * Behaves just like gp_load_image, but takes pointer to opened container instead.
90 */
91static inline gp_pixmap *gp_container_load_next(gp_container *self,
92 gp_progress_cb *callback)
93{
94 return self->ops->load_next(self, callback);
95}
96
97/*
98 * Just loads current image, does not advance to the next one.
99 */
100int gp_container_load_ex(gp_container *self, gp_pixmap **img,
101 gp_storage *storage, gp_progress_cb *callback);
102
103static inline gp_pixmap *gp_container_load(gp_container *self,
104 gp_progress_cb *callback)
105{
106 gp_pixmap *ret = NULL;
107
108 gp_container_load_ex(self, &ret, NULL, callback);
109
110 return ret;
111}
112
113int gp_container_seek(gp_container *self, ssize_t offset,
114 enum gp_seek_whence whence);
115
116static inline void gp_container_close(gp_container *self)
117{
118 self->ops->close(self);
119}
120
121gp_container *gp_container_open(const char *path);
122
123#endif /* LOADERS_GP_CONTAINER_H */
A common types.
A compiler dependent macros.
Typed recursive storage for key value pairs.
A progress callback.
Seek contants and transformations.
gp_seek_whence
Seek constants.
Definition gp_seek.h:24
An I/O abstraction.
Definition gp_io.h:23
A pixmap buffer.
Definition gp_pixmap.h:33
Progress callback.