Blender  V2.93
filetype.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include <stddef.h>
22 
23 #include "BLI_utildefines.h"
24 
25 #include "IMB_filetype.h"
26 #include "IMB_imbuf.h"
27 #include "IMB_imbuf_types.h"
28 
29 #include "IMB_colormanagement.h"
30 
31 #ifdef WITH_OPENIMAGEIO
32 # include "oiio/openimageio_api.h"
33 #endif
34 
35 #ifdef WITH_OPENEXR
36 # include "openexr/openexr_api.h"
37 #endif
38 
39 #ifdef WITH_DDS
40 # include "dds/dds_api.h"
41 #endif
42 
44  {
45  .init = NULL,
46  .exit = NULL,
47  .is_a = imb_is_a_jpeg,
48  .load = imb_load_jpeg,
49  .load_filepath = NULL,
50  .save = imb_savejpeg,
51  .load_tile = NULL,
52  .flag = 0,
53  .filetype = IMB_FTYPE_JPG,
54  .default_save_role = COLOR_ROLE_DEFAULT_BYTE,
55  },
56  {
57  .init = NULL,
58  .exit = NULL,
59  .is_a = imb_is_a_png,
60  .load = imb_loadpng,
61  .load_filepath = NULL,
62  .save = imb_savepng,
63  .load_tile = NULL,
64  .flag = 0,
65  .filetype = IMB_FTYPE_PNG,
66  .default_save_role = COLOR_ROLE_DEFAULT_BYTE,
67  },
68  {
69  .init = NULL,
70  .exit = NULL,
71  .is_a = imb_is_a_bmp,
72  .load = imb_bmp_decode,
73  .load_filepath = NULL,
74  .save = imb_savebmp,
75  .load_tile = NULL,
76  .flag = 0,
77  .filetype = IMB_FTYPE_BMP,
78  .default_save_role = COLOR_ROLE_DEFAULT_BYTE,
79  },
80  {
81  .init = NULL,
82  .exit = NULL,
83  .is_a = imb_is_a_targa,
84  .load = imb_loadtarga,
85  .load_filepath = NULL,
86  .save = imb_savetarga,
87  .load_tile = NULL,
88  .flag = 0,
89  .filetype = IMB_FTYPE_TGA,
90  .default_save_role = COLOR_ROLE_DEFAULT_BYTE,
91  },
92  {
93  .init = NULL,
94  .exit = NULL,
95  .is_a = imb_is_a_iris,
96  .load = imb_loadiris,
97  .load_filepath = NULL,
98  .save = imb_saveiris,
99  .load_tile = NULL,
100  .flag = 0,
101  .filetype = IMB_FTYPE_IMAGIC,
102  .default_save_role = COLOR_ROLE_DEFAULT_BYTE,
103  },
104 #ifdef WITH_CINEON
105  {
106  .init = NULL,
107  .exit = NULL,
108  .is_a = imb_is_a_dpx,
109  .load = imb_load_dpx,
110  .load_filepath = NULL,
111  .save = imb_save_dpx,
112  .load_tile = NULL,
113  .flag = IM_FTYPE_FLOAT,
114  .filetype = IMB_FTYPE_DPX,
115  .default_save_role = COLOR_ROLE_DEFAULT_FLOAT,
116  },
117  {
118  .init = NULL,
119  .exit = NULL,
120  .is_a = imb_is_a_cineon,
121  .load = imb_load_cineon,
122  .load_filepath = NULL,
123  .save = imb_save_cineon,
124  .load_tile = NULL,
125  .flag = IM_FTYPE_FLOAT,
126  .filetype = IMB_FTYPE_CINEON,
127  .default_save_role = COLOR_ROLE_DEFAULT_FLOAT,
128  },
129 #endif
130 #ifdef WITH_TIFF
131  {
132  .init = imb_inittiff,
133  .exit = NULL,
134  .is_a = imb_is_a_tiff,
135  .load = imb_loadtiff,
136  .load_filepath = NULL,
137  .save = imb_savetiff,
138  .load_tile = imb_loadtiletiff,
139  .flag = 0,
140  .filetype = IMB_FTYPE_TIF,
141  .default_save_role = COLOR_ROLE_DEFAULT_BYTE,
142  },
143 #endif
144 #ifdef WITH_HDR
145  {
146  .init = NULL,
147  .exit = NULL,
148  .is_a = imb_is_a_hdr,
149  .load = imb_loadhdr,
150  .load_filepath = NULL,
151  .save = imb_savehdr,
152  .load_tile = NULL,
153  .flag = IM_FTYPE_FLOAT,
154  .filetype = IMB_FTYPE_RADHDR,
155  .default_save_role = COLOR_ROLE_DEFAULT_FLOAT,
156  },
157 #endif
158 #ifdef WITH_OPENEXR
159  {
160  .init = imb_initopenexr,
161  .exit = imb_exitopenexr,
162  .is_a = imb_is_a_openexr,
163  .load = imb_load_openexr,
164  .load_filepath = NULL,
165  .save = imb_save_openexr,
166  .load_tile = NULL,
167  .flag = IM_FTYPE_FLOAT,
168  .filetype = IMB_FTYPE_OPENEXR,
169  .default_save_role = COLOR_ROLE_DEFAULT_FLOAT,
170  },
171 #endif
172 #ifdef WITH_OPENJPEG
173  {
174  .init = NULL,
175  .exit = NULL,
176  .is_a = imb_is_a_jp2,
177  .load = imb_load_jp2,
178  .load_filepath = NULL,
179  .save = imb_save_jp2,
180  .load_tile = NULL,
181  .flag = IM_FTYPE_FLOAT,
182  .filetype = IMB_FTYPE_JP2,
183  .default_save_role = COLOR_ROLE_DEFAULT_BYTE,
184  },
185 #endif
186 #ifdef WITH_DDS
187  {
188  .init = NULL,
189  .exit = NULL,
190  .is_a = imb_is_a_dds,
191  .load = imb_load_dds,
192  .load_filepath = NULL,
193  .save = NULL,
194  .load_tile = NULL,
195  .flag = 0,
196  .filetype = IMB_FTYPE_DDS,
197  .default_save_role = COLOR_ROLE_DEFAULT_BYTE,
198  },
199 #endif
200 #ifdef WITH_OPENIMAGEIO
201  {
202  .init = NULL,
203  .exit = NULL,
204  .is_a = imb_is_a_photoshop,
205  .load = NULL,
206  .load_filepath = imb_load_photoshop,
207  .save = NULL,
208  .load_tile = NULL,
209  .flag = IM_FTYPE_FLOAT,
210  .filetype = IMB_FTYPE_PSD,
211  .default_save_role = COLOR_ROLE_DEFAULT_FLOAT,
212  },
213 #endif
214  {NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0},
215 };
216 
218 
220 {
222  if (ftype == type->filetype) {
223  return type;
224  }
225  }
226  return NULL;
227 }
228 
230 {
231  return IMB_file_type_from_ftype(ibuf->ftype);
232 }
233 
235 {
236  const ImFileType *type;
237 
239  if (type->init) {
240  type->init();
241  }
242  }
243 }
244 
246 {
247  const ImFileType *type;
248 
250  if (type->exit) {
251  type->exit();
252  }
253  }
254 }
#define ARRAY_SIZE(arr)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
@ COLOR_ROLE_DEFAULT_FLOAT
@ COLOR_ROLE_DEFAULT_BYTE
bool imb_is_a_iris(const unsigned char *mem, const size_t size)
Definition: iris.c:246
#define IM_FTYPE_FLOAT
Definition: IMB_filetype.h:29
bool imb_save_jp2(struct ImBuf *ibuf, const char *filepath, int flags)
Definition: jp2.c:1201
void imb_inittiff(void)
Definition: tiff.c:548
bool imb_saveiris(struct ImBuf *ibuf, const char *filepath, int flags)
Definition: iris.c:977
bool imb_is_a_tiff(const unsigned char *buf, const size_t size)
Definition: tiff.c:319
struct ImBuf * imb_load_jpeg(const unsigned char *buffer, size_t size, int flags, char colorspace[IM_MAX_SPACE])
Definition: jpeg.c:437
bool imb_savepng(struct ImBuf *ibuf, const char *filepath, int flags)
Definition: png.c:126
bool imb_savejpeg(struct ImBuf *ibuf, const char *filepath, int flags)
Definition: jpeg.c:659
struct ImBuf * imb_loadhdr(const unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
Definition: radiance_hdr.c:218
bool imb_is_a_hdr(const unsigned char *buf, const size_t size)
Definition: radiance_hdr.c:200
bool imb_is_a_jp2(const unsigned char *buf, const size_t size)
Definition: jp2.c:85
bool imb_is_a_png(const unsigned char *mem, const size_t size)
Definition: png.c:64
struct ImBuf * imb_loadpng(const unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
Definition: png.c:540
struct ImBuf * imb_load_jp2(const unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
Definition: jp2.c:317
struct ImBuf * imb_loadtiff(const unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
Definition: tiff.c:564
struct ImBuf * imb_loadiris(const unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
Definition: iris.c:260
bool imb_savehdr(struct ImBuf *ibuf, const char *filepath, int flags)
Definition: radiance_hdr.c:435
bool imb_is_a_targa(const unsigned char *buf, const size_t size)
Definition: targa.c:416
bool imb_savetarga(struct ImBuf *ibuf, const char *filepath, int flags)
bool imb_savetiff(struct ImBuf *ibuf, const char *filepath, int flags)
Definition: tiff.c:761
void imb_loadtiletiff(struct ImBuf *ibuf, const unsigned char *mem, size_t size, int tx, int ty, unsigned int *rect)
Definition: tiff.c:689
struct ImBuf * imb_loadtarga(const unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
Definition: targa.c:628
bool imb_is_a_jpeg(const unsigned char *mem, const size_t size)
Definition: jpeg.c:62
Contains defines and structs used throughout the imbuf module.
bool imb_savebmp(ImBuf *ibuf, const char *filepath, int UNUSED(flags))
Definition: bmp.c:311
ImBuf * imb_bmp_decode(const uchar *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
Definition: bmp.c:121
bool imb_is_a_bmp(const uchar *buf, size_t size)
Definition: bmp.c:109
bool imb_save_dpx(struct ImBuf *buf, const char *filepath, int flags)
Definition: cineon_dpx.c:207
ImBuf * imb_load_dpx(const unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
Definition: cineon_dpx.c:217
bool imb_is_a_cineon(const unsigned char *buf, size_t size)
Definition: cineon_dpx.c:191
bool imb_is_a_dpx(const unsigned char *buf, size_t size)
Definition: cineon_dpx.c:212
bool imb_save_cineon(struct ImBuf *buf, const char *filepath, int flags)
Definition: cineon_dpx.c:186
ImBuf * imb_load_cineon(const unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
Definition: cineon_dpx.c:196
bool imb_is_a_dds(const unsigned char *mem, const size_t size)
Definition: dds_api.cpp:75
struct ImBuf * imb_load_dds(const unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
Definition: dds_api.cpp:92
const ImFileType * IMB_file_type_from_ftype(int ftype)
Definition: filetype.c:219
const ImFileType IMB_FILE_TYPES[]
Definition: filetype.c:43
void imb_filetypes_init(void)
Definition: filetype.c:234
const ImFileType * IMB_file_type_from_ibuf(const ImBuf *ibuf)
Definition: filetype.c:229
void imb_filetypes_exit(void)
Definition: filetype.c:245
const ImFileType * IMB_FILE_TYPES_LAST
Definition: filetype.c:217
@ IMB_FTYPE_BMP
@ IMB_FTYPE_IMAGIC
@ IMB_FTYPE_JPG
@ IMB_FTYPE_TGA
@ IMB_FTYPE_OPENEXR
@ IMB_FTYPE_PNG
struct ImBuf * imb_load_openexr(const unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
void imb_initopenexr(void)
bool imb_is_a_openexr(const unsigned char *mem, const size_t size)
bool imb_save_openexr(struct ImBuf *ibuf, const char *name, int flags)
void imb_exitopenexr(void)
struct ImBuf * imb_load_photoshop(const char *filename, int flags, char colorspace[IM_MAX_SPACE])
bool imb_is_a_photoshop(const unsigned char *mem, size_t size)
enum eImbFileType ftype
void(* init)(void)
Definition: IMB_filetype.h:33