GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_loader.h
1// SPDX-License-Identifier: LGPL-2.1-or-later
2/*
3 * Copyright (C) 2009-2014 Cyril Hrubis <metan@ucw.cz>
4 */
5
6 /*
7
8 Core include file for loaders API.
9
10 */
11
12#ifndef LOADERS_GP_LOADER_H
13#define LOADERS_GP_LOADER_H
14
15#include "core/gp_pixmap.h"
17
18#include <loaders/gp_io.h>
19#include <loaders/gp_data_storage.h>
20
21/*
22 * Reads an image from a I/O stream.
23 *
24 * The image format is matched from the file signature (first few bytes of the
25 * I/O stream).
26 */
27gp_pixmap *gp_read_image(gp_io *io, gp_progress_cb *callback);
28
29int gp_read_image_ex(gp_io *io, gp_pixmap **img, gp_storage *meta_data,
30 gp_progress_cb *callback);
31
32/*
33 * Tries to load image accordingly to the file extension.
34 *
35 * If operation fails NULL is returned and errno is filled.
36 */
37gp_pixmap *gp_load_image(const char *src_path, gp_progress_cb *callback);
38
39int gp_load_image_ex(const char *src_path,
40 gp_pixmap **img, gp_storage *meta_data,
41 gp_progress_cb *callback);
42
43/*
44 * Loads image Meta Data (if possible).
45 */
46int gp_load_meta_data(const char *src_path, gp_storage *storage);
47
48/*
49 * Simple saving function, the image format is matched by file extension.
50 *
51 * Retruns zero on success.
52 *
53 * On failure non-zero is returned.
54 *
55 * When file type wasn't recognized by extension or if support for requested
56 * image format wasn't compiled in non-zero is returned and errno is set to
57 * ENOSYS.
58 *
59 * The resulting errno may also be set to any possible error from fopen(3), open(3),
60 * write(3), fwrite(3), seek(3), etc..
61 */
62int gp_save_image(const gp_pixmap *src, const char *dst_path,
63 gp_progress_cb *callback);
64
65typedef struct gp_loader gp_loader;
66
67/*
68 * Describes image loader/saver.
69 */
70struct gp_loader {
71 /*
72 * Reads image and/or metadata from an I/O stream.
73 */
74 int (*read)(gp_io *io, gp_pixmap **img, gp_storage *storage,
75 gp_progress_cb *callback);
76
77 /*
78 * Writes an image into an I/O stream.
79 *
80 * Returns zero on success, non-zero on failure and errno must be set.
81 */
82 int (*write)(const gp_pixmap *src, gp_io *io,
83 gp_progress_cb *callback);
84
85 /*
86 * GP_PIXEL_UNKNOWN terminated array of formats loader supports for save.
87 *
88 * This is _NOT_ a complete list loaders is able to save, due to automatic
89 * conversions (i.e. RGB888 vs BRG888).
90 */
91 const gp_pixel_type *save_ptypes;
92
93 /*
94 * The buffer is filled with 32 bytes from an image start, returns 1 if
95 * image signature was found zero otherwise.
96 */
97 int (*match)(const void *buf);
98
99 /*
100 * Short format name.
101 */
102 const char *fmt_name;
103
104 /*
105 * NULL terminated array of file extensions.
106 */
107 const char *extensions[];
108};
109
110/*
111 * Takes pointer to buffer at least 32 bytes long and returns a pointer to
112 * matched loader or NULL.
113 */
114const gp_loader *gp_loader_by_signature(const void *buf);
115
116/*
117 * Tries to match loader by filename extension. Returns NULL if no loader was
118 * found.
119 */
120const gp_loader *gp_loader_by_filename(const char *path);
121
122/*
123 * Registers additional loader.
124 *
125 * Returns zero on success, non-zero if table of loaders was is full.
126 */
127int gp_loader_register(const gp_loader *self);
128
129/*
130 * Unregisters a loader.
131 *
132 * All library loaders are registered by default.
133 *
134 * You can unregister them using this function if you want.
135 */
136void gp_loader_unregister(const gp_loader *self);
137
138/*
139 * Generic LoadImage for a given loader.
140 *
141 * The function prepares the I/O from file, calls the loader Read() method,
142 * closes the I/O and returns the pixmap.
143 */
144gp_pixmap *gp_loader_load_image(const gp_loader *self, const char *src_path,
145 gp_progress_cb *callback);
146
147/*
148 * Generic ReadImage for a given loader.
149 *
150 * The function calls the loader Read() method for a given I/O.
151 */
152gp_pixmap *gp_loader_read_image(const gp_loader *self, gp_io *io,
153 gp_progress_cb *callback);
154
155/*
156 * Generic ReadImageEx for a given loader.
157 *
158 * The function calls the loader Read() method for a given I/O.
159 */
160int gp_loader_read_image_ex(const gp_loader *self, gp_io *io,
161 gp_pixmap **img, gp_storage *data,
162 gp_progress_cb *callback);
163
164/*
165 * Generic LoadImageEx for a given loader.
166 *
167 * The function prepares the I/O from file, calls the loader ReadEx() method,
168 * closes the I/O and returns the pixmap.
169 */
170int gp_loader_load_image_ex(const gp_loader *self, const char *src_path,
171 gp_pixmap **img, gp_storage *data,
172 gp_progress_cb *callback);
173
174/*
175 * Generic SaveImage for a given loader.
176 *
177 * The function/ prepares the I/O from file, calls the loader Write() method
178 * and closes the I/O.
179 */
180int gp_loader_save_image(const gp_loader *self, const gp_pixmap *src,
181 const char *dst_path, gp_progress_cb *callback);
182
183/*
184 * List loaders into the stdout
185 */
186void gp_loaders_list(void);
187
188#endif /* LOADERS_GP_LOADER_H */
gp_pixel_type
List of all pixel types.
A pixel buffer.
A progress callback.
A pixmap buffer.
Definition gp_pixmap.h:33
Progress callback.