1 /*****************************************************************************
2 * This file is part of gfxprim library. *
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. *
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. *
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 *
19 * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz> *
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"
40 enum GP_ContainerWhence
{
46 struct GP_ContainerOps
{
48 * Loads next image from container, use the inline function defined
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.
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
85 unsigned int img_count
;
88 * Current image counter, do not change from application.
93 * Contains container callbacks
95 const struct GP_ContainerOps
*ops
;
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
);
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 */