2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program 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
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): none yet.
25 * ***** END GPL LICENSE BLOCK *****
28 #ifndef __IMB_IMBUF_TYPES_H__
29 #define __IMB_IMBUF_TYPES_H__
31 #include "DNA_vec_types.h" /* for rcti */
34 * \file IMB_imbuf_types.h
36 * \brief Contains defines and structs used throughout the imbuf module.
37 * \todo Clean up includes.
39 * Types needed for using the image buffer.
41 * Imbuf is external code, slightly adapted to live in the Blender
42 * context. It requires an external jpeg module, and the avi-module
43 * (also external code) in order to function correctly.
45 * This file contains types and some constants that go with them. Most
46 * are self-explanatory (e.g. IS_amiga tests whether the buffer
47 * contains an Amiga-format file).
50 #define IMB_MIPMAP_LEVELS 20
51 #define IMB_FILENAME_SIZE 1024
53 typedef struct DDSData {
54 unsigned int fourcc; /* DDS fourcc info */
55 unsigned int nummipmaps; /* The number of mipmaps in the dds file */
56 unsigned char *data; /* The compressed image data */
57 unsigned int size; /* The size of the compressed data */
62 * This is the abstraction of an image. ImBuf is the basic type used for all
65 * Also; add new variables to the end to save pain!
69 /* ibuf->ftype flag, main image types */
70 /* Warning: Keep explicit value assignements here, this file is included in areas where not all format defines
71 * are set (e.g. intern/dds only get WITH_DDS, even if TIFF, HDR etc are also defined). See T46524. */
77 IMB_FTYPE_OPENEXR = 5,
79 #ifdef WITH_OPENIMAGEIO
92 IMB_FTYPE_CINEON = 11,
101 /* ibuf->foptions flag, type specific options.
102 * Some formats include compression rations on some bits */
104 #define OPENEXR_HALF (1 << 8 )
105 /* careful changing this, it's used in DNA as well */
106 #define OPENEXR_COMPRESS (15)
109 #define CINEON_LOG (1 << 8)
110 #define CINEON_16BIT (1 << 7)
111 #define CINEON_12BIT (1 << 6)
112 #define CINEON_10BIT (1 << 5)
116 #define JP2_12BIT (1 << 9)
117 #define JP2_16BIT (1 << 8)
118 #define JP2_YCC (1 << 7)
119 #define JP2_CINE (1 << 6)
120 #define JP2_CINE_48FPS (1 << 5)
121 #define JP2_JP2 (1 << 4)
122 #define JP2_J2K (1 << 3)
125 #define PNG_16BIT (1 << 10)
130 #define TIF_16BIT (1 << 8)
131 #define TIF_COMPRESS_NONE (1 << 7)
132 #define TIF_COMPRESS_DEFLATE (1 << 6)
133 #define TIF_COMPRESS_LZW (1 << 5)
134 #define TIF_COMPRESS_PACKBITS (1 << 4)
137 typedef struct ImbFormatOptions {
139 char quality; /* quality serves dual purpose as quality number for jpeg or compression amount for png */
142 typedef struct ImBuf {
143 struct ImBuf *next, *prev; /**< allow lists of ImBufs, for caches or flipbooks */
146 int x, y; /* width and Height of our image buffer.
147 * Should be 'unsigned int' since most formats use this.
148 * but this is problematic with texture math in imagetexture.c
149 * avoid problems and use int. - campbell */
151 unsigned char planes; /* Active amount of bits/bitplanes */
152 int channels; /* amount of channels in rect_float (0 = 4 channel default) */
155 int flags; /* Controls which components should exist. */
156 int mall; /* what is malloced internal, and can be freed */
160 /** Image pixel buffer (8bit representation):
161 * - color space defaults to `sRGB`.
162 * - alpha defaults to 'straight'.
165 /** Image pixel buffer (float representation):
166 * - color space defaults to 'linear' (`rec709`).
167 * - alpha defaults to 'premul'.
168 * \note May need gamma correction to `sRGB` when generating 8bit representations.
169 * \note Formats that support higher more than 8 but channels load as floats.
173 /* resolution - pixels per meter */
176 /* tiled pixel storage */
179 unsigned int **tiles;
182 int *zbuf; /* z buffer data, original zbuffer */
183 float *zbuf_float; /* z buffer data, camera coordinates */
185 /* parameters used by conversion between byte and float */
186 float dither; /* random dither value, for conversion from float -> byte rect */
189 struct ImBuf *mipmap[IMB_MIPMAP_LEVELS]; /* MipMap levels, a series of halved images */
190 int miptot, miplevel;
192 /* externally used data */
193 int index; /* reference index for ImBuf lists */
194 int userflags; /* used to set imbuf to dirty and other stuff */
195 struct IDProperty *metadata; /* image metadata */
196 void *userdata; /* temporary storage */
198 /* file information */
199 enum eImbTypes ftype; /* file type we are going to save as */
200 ImbFormatOptions foptions; /* file format specific flags */
201 char name[IMB_FILENAME_SIZE]; /* filename associated with this image */
202 char cachename[IMB_FILENAME_SIZE]; /* full filename used for reading from cache */
204 /* memory cache limiter */
205 struct MEM_CacheLimiterHandle_s *c_handle; /* handle for cache limiter */
206 int refcounter; /* reference counter for multiple users */
208 /* some parameters to pass along for packing images */
209 unsigned char *encodedbuffer; /* Compressed image only used with png currently */
210 unsigned int encodedsize; /* Size of data written to encodedbuffer */
211 unsigned int encodedbuffersize; /* Size of encodedbuffer */
213 /* color management */
214 struct ColorSpace *rect_colorspace; /* color space of byte buffer */
215 struct ColorSpace *float_colorspace; /* color space of float buffer, used by sequencer only */
216 unsigned int *display_buffer_flags; /* array of per-display display buffers dirty flags */
217 struct ColormanageCache *colormanage_cache; /* cache used by color management */
218 int colormanage_flag;
221 /* information for compressed textures */
222 struct DDSData dds_data;
225 /* Moved from BKE_bmfont_types.h because it is a userflag bit mask. */
227 * \brief userflags: Flags used internally by blender for imagebuffers
230 #define IB_BITMAPFONT (1 << 0) /* this image is a font */
231 #define IB_BITMAPDIRTY (1 << 1) /* image needs to be saved is not the same as filename */
232 #define IB_MIPMAP_INVALID (1 << 2) /* image mipmaps are invalid, need recreate */
233 #define IB_RECT_INVALID (1 << 3) /* float buffer changed, needs recreation of byte rect */
234 #define IB_DISPLAY_BUFFER_INVALID (1 << 4) /* either float or byte buffer changed, need to re-calculate display buffers */
235 #define IB_PERSISTENT (1 << 5) /* image buffer is persistent in the memory and should never be removed from the cache */
238 * \name Imbuf Component flags
239 * \brief These flags determine the components of an ImBuf struct.
243 #define IB_rect (1 << 0)
244 #define IB_test (1 << 1)
245 #define IB_fields (1 << 2)
246 #define IB_zbuf (1 << 3)
247 #define IB_mem (1 << 4)
248 #define IB_rectfloat (1 << 5)
249 #define IB_zbuffloat (1 << 6)
250 #define IB_multilayer (1 << 7)
251 #define IB_metadata (1 << 8)
252 #define IB_animdeinterlace (1 << 9)
253 #define IB_tiles (1 << 10)
254 #define IB_tilecache (1 << 11)
255 #define IB_alphamode_premul (1 << 12) /* indicates whether image on disk have premul alpha */
256 #define IB_alphamode_detect (1 << 13) /* if this flag is set, alpha mode would be guessed from file */
257 #define IB_ignore_alpha (1 << 14) /* ignore alpha on load and substitude it with 1.0f */
258 #define IB_thumbnail (1 << 15)
259 #define IB_multiview (1 << 16)
264 * \name Imbuf preset profile tags
265 * \brief Some predefined color space profiles that 8 bit imbufs can represent
268 #define IB_PROFILE_NONE 0
269 #define IB_PROFILE_LINEAR_RGB 1
270 #define IB_PROFILE_SRGB 2
271 #define IB_PROFILE_CUSTOM 3
277 #ifndef DDS_MAKEFOURCC
278 #define DDS_MAKEFOURCC(ch0, ch1, ch2, ch3)\
279 ((unsigned long)(unsigned char)(ch0) | \
280 ((unsigned long)(unsigned char)(ch1) << 8) | \
281 ((unsigned long)(unsigned char)(ch2) << 16) | \
282 ((unsigned long)(unsigned char)(ch3) << 24))
283 #endif /* DDS_MAKEFOURCC */
286 * FOURCC codes for DX compressed-texture pixel formats
289 #define FOURCC_DDS (DDS_MAKEFOURCC('D','D','S',' '))
290 #define FOURCC_DXT1 (DDS_MAKEFOURCC('D','X','T','1'))
291 #define FOURCC_DXT2 (DDS_MAKEFOURCC('D','X','T','2'))
292 #define FOURCC_DXT3 (DDS_MAKEFOURCC('D','X','T','3'))
293 #define FOURCC_DXT4 (DDS_MAKEFOURCC('D','X','T','4'))
294 #define FOURCC_DXT5 (DDS_MAKEFOURCC('D','X','T','5'))
297 extern const char *imb_ext_image[];
298 extern const char *imb_ext_movie[];
299 extern const char *imb_ext_audio[];
301 /* image formats that can only be loaded via filepath */
302 extern const char *imb_ext_image_filepath_only[];
305 * \name Imbuf Color Management Flag
306 * \brief Used with #ImBuf.colormanage_flag
311 IMB_COLORMANAGE_IS_DATA = (1 << 0)
316 #endif /* __IMB_IMBUF_TYPES_H__ */