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