Blender  V2.93
logImageCore.h
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  * Copyright 1999,2000,2001 David Hodson <hodsond@acm.org>
17  */
18 
30 #pragma once
31 
32 #include <stdio.h>
33 
34 #include "BLI_sys_types.h"
35 #include "BLI_utildefines.h"
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 /*
42  * Image structure
43  */
44 
45 /* There are some differences between DPX and Cineon
46  * so we need to know from what type of file the data came from. */
47 enum format {
50 };
51 
52 typedef struct LogImageElement {
53  int depth;
56  int packing;
57  int transfer;
59  unsigned int refLowData;
60  unsigned int refHighData;
63  float maxValue; /* = 2^bitsPerSample - 1 (used internally, doesn't come from the file header) */
65 
66 typedef struct LogImageFile {
67  /* specified in header */
68  int width;
69  int height;
71  int depth;
73 
74  /* used for log <-> lin conversion */
77  float gamma;
78 
79  /* io stuff */
80  FILE *file;
81  unsigned char *memBuffer;
83  unsigned char *memCursor;
84 
85  /* is the file LSB or MSB ? */
86  int isMSB;
87 
88  /* DPX or Cineon ? */
89  int srcFormat;
91 
92 /* The SMPTE defines this code:
93  * 0 - User-defined
94  * 1 - Printing density
95  * 2 - Linear
96  * 3 - Logarithmic
97  * 4 - Unspecified video
98  * 5 - SMPTE 240M
99  * 6 - CCIR 709-1
100  * 7 - CCIR 601-2 system B or G
101  * 8 - CCIR 601-2 system M
102  * 9 - NTSC composite video
103  * 10 - PAL composite video
104  * 11 - Z linear
105  * 12 - homogeneous
106  *
107  * Note that transfer_characteristics is U8, don't need
108  * check the byte order.
109  */
110 
111 enum transfer {
125 };
126 
127 /* The SMPTE defines this code:
128  * 0 - User-defined
129  * 1 - Red
130  * 2 - Green
131  * 3 - Blue
132  * 4 - Alpha
133  * 6 - Luminance
134  * 7 - Chrominance
135  * 8 - Depth
136  * 9 - Composite video
137  * 50 - RGB
138  * 51 - RGBA
139  * 52 - ABGR
140  * 100 - CbYCrY
141  * 101 - CbYACrYA
142  * 102 - CbYCr
143  * 103 - CbYCrA
144  * 150 - User-defined 2-component element
145  * 151 - User-defined 3-component element
146  * 152 - User-defined 4-component element
147  * 153 - User-defined 5-component element
148  * 154 - User-defined 6-component element
149  * 155 - User-defined 7-component element
150  * 156 - User-defined 8-component element
151  */
152 
159  descriptor_Luminance = 6, /* don't ask me why there's no 5 */
177  /* following descriptors are for internal use only */
179 };
180 
181 /* int functions return 0 for OK */
182 
183 void logImageSetVerbose(int verbosity);
184 int logImageIsDpx(const void *buffer, unsigned int size);
185 int logImageIsCineon(const void *buffer, unsigned int size);
186 LogImageFile *logImageOpenFromMemory(const unsigned char *buffer, unsigned int size);
187 LogImageFile *logImageOpenFromFile(const char *filename, int cineon);
188 void logImageGetSize(LogImageFile *logImage, int *width, int *height, int *depth);
189 LogImageFile *logImageCreate(const char *filename,
190  int cineon,
191  int width,
192  int height,
193  int bitsPerSample,
194  int isLogarithmic,
195  int hasAlpha,
196  int referenceWhite,
197  int referenceBlack,
198  float gamma,
199  const char *creator);
200 void logImageClose(LogImageFile *logImage);
201 
202 /* Data handling */
203 size_t getRowLength(size_t width, LogImageElement logElement);
204 int logImageSetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB);
205 int logImageGetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB);
206 
207 /*
208  * Inline routines
209  */
210 
211 /* Endianness swapping */
212 
213 BLI_INLINE unsigned short swap_ushort(unsigned short x, int swap)
214 {
215  if (swap != 0) {
216  return (x >> 8) | (x << 8);
217  }
218  else {
219  return x;
220  }
221 }
222 
223 BLI_INLINE unsigned int swap_uint(unsigned int x, int swap)
224 {
225  if (swap != 0) {
226  return (x >> 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) | (x << 24);
227  }
228  else {
229  return x;
230  }
231 }
232 
233 BLI_INLINE float swap_float(float x, int swap)
234 {
235  if (swap != 0) {
236  union {
237  float f;
238  unsigned char b[4];
239  } dat1, dat2;
240 
241  dat1.f = x;
242  dat2.b[0] = dat1.b[3];
243  dat2.b[1] = dat1.b[2];
244  dat2.b[2] = dat1.b[1];
245  dat2.b[3] = dat1.b[0];
246  return dat2.f;
247  }
248  else {
249  return x;
250  }
251 }
252 
253 /* Other */
254 
255 BLI_INLINE unsigned int clamp_uint(unsigned int x, unsigned int low, unsigned int high)
256 {
257  if (x > high) {
258  return high;
259  }
260  else if (x < low) {
261  return low;
262  }
263  else {
264  return x;
265  }
266 }
267 
268 BLI_INLINE float clamp_float(float x, float low, float high)
269 {
270  if (x > high) {
271  return high;
272  }
273  else if (x < low) {
274  return low;
275  }
276  else {
277  return x;
278  }
279 }
280 
281 BLI_INLINE unsigned int float_uint(float value, unsigned int max)
282 {
283  if (value < 0.0f) {
284  return 0;
285  }
286  else if (value > (1.0f - 0.5f / (float)max)) {
287  return max;
288  }
289  else {
290  return (unsigned int)(((float)max * value) + 0.5f);
291  }
292 }
293 
294 #ifdef __cplusplus
295 }
296 #endif
typedef float(TangentPoint)[2]
#define BLI_INLINE
void swap(T &a, T &b)
Definition: Common.h:33
_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 const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
BLI_INLINE float clamp_float(float x, float low, float high)
Definition: logImageCore.h:268
BLI_INLINE unsigned int clamp_uint(unsigned int x, unsigned int low, unsigned int high)
Definition: logImageCore.h:255
LogImageFile * logImageCreate(const char *filename, int cineon, int width, int height, int bitsPerSample, int isLogarithmic, int hasAlpha, int referenceWhite, int referenceBlack, float gamma, const char *creator)
Definition: logImageCore.c:159
int logImageIsDpx(const void *buffer, unsigned int size)
Definition: logImageCore.c:99
struct LogImageFile LogImageFile
format
Definition: logImageCore.h:47
@ format_Cineon
Definition: logImageCore.h:49
@ format_DPX
Definition: logImageCore.h:48
void logImageSetVerbose(int verbosity)
Definition: logImageCore.c:88
struct LogImageElement LogImageElement
descriptor
Definition: logImageCore.h:153
@ descriptor_Chrominance
Definition: logImageCore.h:160
@ descriptor_CbYCr
Definition: logImageCore.h:168
@ descriptor_Red
Definition: logImageCore.h:155
@ descriptor_UserDefined3Elt
Definition: logImageCore.h:171
@ descriptor_YA
Definition: logImageCore.h:178
@ descriptor_Composite
Definition: logImageCore.h:162
@ descriptor_Depth
Definition: logImageCore.h:161
@ descriptor_CbYCrA
Definition: logImageCore.h:169
@ descriptor_Luminance
Definition: logImageCore.h:159
@ descriptor_UserDefined
Definition: logImageCore.h:154
@ descriptor_UserDefined6Elt
Definition: logImageCore.h:174
@ descriptor_Green
Definition: logImageCore.h:156
@ descriptor_ABGR
Definition: logImageCore.h:165
@ descriptor_CbYCrY
Definition: logImageCore.h:166
@ descriptor_Blue
Definition: logImageCore.h:157
@ descriptor_RGB
Definition: logImageCore.h:163
@ descriptor_UserDefined5Elt
Definition: logImageCore.h:173
@ descriptor_UserDefined8Elt
Definition: logImageCore.h:176
@ descriptor_CbYACrYA
Definition: logImageCore.h:167
@ descriptor_UserDefined4Elt
Definition: logImageCore.h:172
@ descriptor_UserDefined7Elt
Definition: logImageCore.h:175
@ descriptor_UserDefined2Elt
Definition: logImageCore.h:170
@ descriptor_Alpha
Definition: logImageCore.h:158
@ descriptor_RGBA
Definition: logImageCore.h:164
LogImageFile * logImageOpenFromMemory(const unsigned char *buffer, unsigned int size)
Definition: logImageCore.c:147
BLI_INLINE float swap_float(float x, int swap)
Definition: logImageCore.h:233
transfer
Definition: logImageCore.h:111
@ transfer_PrintingDensity
Definition: logImageCore.h:113
@ transfer_Ccir6012BG
Definition: logImageCore.h:119
@ transfer_Ccir7091
Definition: logImageCore.h:118
@ transfer_ZLinear
Definition: logImageCore.h:123
@ transfer_Smpte240M
Definition: logImageCore.h:117
@ transfer_Ccir6012M
Definition: logImageCore.h:120
@ transfer_Homogeneous
Definition: logImageCore.h:124
@ transfer_UserDefined
Definition: logImageCore.h:112
@ transfer_NTSC
Definition: logImageCore.h:121
@ transfer_PAL
Definition: logImageCore.h:122
@ transfer_Linear
Definition: logImageCore.h:114
@ transfer_Logarithmic
Definition: logImageCore.h:115
@ transfer_Unspecified
Definition: logImageCore.h:116
LogImageFile * logImageOpenFromFile(const char *filename, int cineon)
Definition: logImageCore.c:119
BLI_INLINE unsigned short swap_ushort(unsigned short x, int swap)
Definition: logImageCore.h:213
void logImageClose(LogImageFile *logImage)
Definition: logImageCore.c:190
size_t getRowLength(size_t width, LogImageElement logElement)
Definition: logImageCore.c:212
BLI_INLINE unsigned int swap_uint(unsigned int x, int swap)
Definition: logImageCore.h:223
void logImageGetSize(LogImageFile *logImage, int *width, int *height, int *depth)
Definition: logImageCore.c:201
BLI_INLINE unsigned int float_uint(float value, unsigned int max)
Definition: logImageCore.h:281
int logImageSetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB)
Definition: logImageCore.c:248
int logImageGetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB)
Definition: logImageCore.c:436
int logImageIsCineon(const void *buffer, unsigned int size)
Definition: logImageCore.c:109
_W64 unsigned int uintptr_t
Definition: stdint.h:122
unsigned int refLowData
Definition: logImageCore.h:59
float refLowQuantity
Definition: logImageCore.h:61
float refHighQuantity
Definition: logImageCore.h:62
unsigned int refHighData
Definition: logImageCore.h:60
uintptr_t memBufferSize
Definition: logImageCore.h:82
float referenceWhite
Definition: logImageCore.h:76
unsigned char * memBuffer
Definition: logImageCore.h:81
unsigned char * memCursor
Definition: logImageCore.h:83
LogImageElement element[8]
Definition: logImageCore.h:72
float referenceBlack
Definition: logImageCore.h:75
float max
__forceinline ssef low(const avxf &a)
Definition: util_avxf.h:277
__forceinline ssef high(const avxf &a)
Definition: util_avxf.h:281