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