Rename GP_Context -> GP_Pixmap
[gfxprim.git] / include / loaders / GP_Container.h
blobb7feb7a23d0ed02a529b1c09e7c01de3abd44e23
1 /*****************************************************************************
2 * This file is part of gfxprim library. *
3 * *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
8 * *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
18 * *
19 * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz> *
20 * *
21 *****************************************************************************/
25 Container is an abstraction for file formats that can include several images
26 in one file. For example gif, tiff, apng, cbr, cbz, etc.
30 #ifndef LOADERS_GP_CONTAINER_H
31 #define LOADERS_GP_CONTAINER_H
33 #include "core/GP_Pixmap.h"
34 #include "core/GP_ProgressCallback.h"
36 #include "loaders/GP_DataStorage.h"
38 struct GP_Container;
40 enum GP_ContainerWhence {
41 GP_CONT_FIRST,
42 GP_CONT_LAST,
43 GP_CONT_CUR,
46 struct GP_ContainerOps {
48 * Loads next image from container, use the inline function defined
49 * below.
51 GP_Pixmap *(*LoadNext)(struct GP_Container *self,
52 GP_ProgressCallback *callback);
55 * Just loads current image, does not advance to the next image.
57 int (*LoadEx)(struct GP_Container *self, GP_Pixmap **img,
58 GP_DataStorage *storage, GP_ProgressCallback *callback);
61 * Close callback, use the inline function defined below.
63 void (*Close)(struct GP_Container *self);
66 * Seeks to the offset from whence.
68 * Returns 0 on success, errno on failure.
70 int (*Seek)(struct GP_Container *self, int offset,
71 enum GP_ContainerWhence whence);
74 * Container type name.
76 const char *type;
79 typedef struct GP_Container {
81 * Image counter. This is set to number of images, or to -1 if number
82 * of images in container is not known prior to parsing the whole
83 * file.
85 unsigned int img_count;
88 * Current image counter, do not change from application.
90 unsigned int cur_img;
93 * Contains container callbacks
95 const struct GP_ContainerOps *ops;
97 char priv[];
98 } GP_Container;
100 #define GP_CONTAINER_PRIV(c) ((void*)(c)->priv)
103 * Behaves just like GP_LoadImage, but takes pointer to opened container instead.
105 static inline GP_Pixmap *GP_ContainerLoadNext(GP_Container *self,
106 GP_ProgressCallback *callback)
108 return self->ops->LoadNext(self, callback);
112 * Just loads current image, does not advance to the next one.
114 int GP_ContainerLoadEx(GP_Container *self, GP_Pixmap **img,
115 GP_DataStorage *storage, GP_ProgressCallback *callback);
117 static inline GP_Pixmap *GP_ContainerLoad(GP_Container *self,
118 GP_ProgressCallback *callback)
120 GP_Pixmap *ret = NULL;
122 GP_ContainerLoadEx(self, &ret, NULL, callback);
124 return ret;
127 int GP_ContainerSeek(GP_Container *self, int offset,
128 enum GP_ContainerWhence whence);
130 static inline void GP_ContainerClose(GP_Container *self)
132 self->ops->Close(self);
135 #endif /* LOADERS_GP_CONTAINER_H */