Blender V5.0
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
15
16#pragma once
17
18#include <cstdio>
19
20#include "BLI_compiler_compat.h"
21#include "BLI_sys_types.h"
22
23#ifdef _WIN32
24# define PATHSEP_CHAR '\\'
25#else
26# define PATHSEP_CHAR '/'
27#endif
28
29/*
30 * Image structure
31 */
32
33/* There are some differences between DPX and Cineon
34 * so we need to know from what type of file the data came from. */
39
41 int depth;
47 unsigned int refLowData;
48 unsigned int refHighData;
51 float maxValue; /* = 2^bitsPerSample - 1 (used internally, doesn't come from the file header) */
52};
53
55 /* specified in header */
56 int width;
57 int height;
59 int depth;
61
62 /* used for log <-> lin conversion */
65 float gamma;
66
67 /* IO stuff. */
68 FILE *file;
69 unsigned char *memBuffer;
70 uintptr_t memBufferSize;
71 unsigned char *memCursor;
72
73 /* is the file LSB or MSB ? */
74 int isMSB;
75
76 /* DPX or Cineon ? */
78};
79
80/* The SMPTE defines this code:
81 * 0 - User-defined
82 * 1 - Printing density
83 * 2 - Linear
84 * 3 - Logarithmic
85 * 4 - Unspecified video
86 * 5 - SMPTE 240M
87 * 6 - CCIR 709-1
88 * 7 - CCIR 601-2 system B or G
89 * 8 - CCIR 601-2 system M
90 * 9 - NTSC composite video
91 * 10 - PAL composite video
92 * 11 - Z linear
93 * 12 - homogeneous
94 *
95 * Note that transfer_characteristics is U8, don't need
96 * check the byte order.
97 */
98
114
115/* The SMPTE defines this code:
116 * 0 - User-defined
117 * 1 - Red
118 * 2 - Green
119 * 3 - Blue
120 * 4 - Alpha
121 * 6 - Luminance
122 * 7 - Chrominance
123 * 8 - Depth
124 * 9 - Composite video
125 * 50 - RGB
126 * 51 - RGBA
127 * 52 - ABGR
128 * 100 - CbYCrY
129 * 101 - CbYACrYA
130 * 102 - CbYCr
131 * 103 - CbYCrA
132 * 150 - User-defined 2-component element
133 * 151 - User-defined 3-component element
134 * 152 - User-defined 4-component element
135 * 153 - User-defined 5-component element
136 * 154 - User-defined 6-component element
137 * 155 - User-defined 7-component element
138 * 156 - User-defined 8-component element
139 */
140
168
169/* int functions return 0 for OK */
170
171void logImageSetVerbose(int verbosity);
172int logImageIsDpx(const void *buffer, unsigned int size);
173int logImageIsCineon(const void *buffer, unsigned int size);
174LogImageFile *logImageOpenFromMemory(const unsigned char *buffer, unsigned int size);
175LogImageFile *logImageOpenFromFile(const char *filepath, int cineon);
176void logImageGetSize(const LogImageFile *logImage, int *width, int *height, int *depth);
177LogImageFile *logImageCreate(const char *filepath,
178 int cineon,
179 int width,
180 int height,
181 int bitsPerSample,
182 int isLogarithmic,
183 int hasAlpha,
184 int referenceWhite,
185 int referenceBlack,
186 float gamma,
187 const char *creator);
188void logImageClose(LogImageFile *logImage);
189
190/* Data handling */
191size_t getRowLength(size_t width, const LogImageElement *logElement);
192int logImageSetDataRGBA(LogImageFile *logImage, const float *data, int dataIsLinearRGB);
193int logImageGetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB);
194
195/*
196 * Inline routines
197 */
198
199/* Endianness swapping */
200
201BLI_INLINE unsigned short swap_ushort(unsigned short x, int swap)
202{
203 if (swap != 0) {
204 return (x >> 8) | (x << 8);
205 }
206 return x;
207}
208
209BLI_INLINE unsigned int swap_uint(unsigned int x, int swap)
210{
211 if (swap != 0) {
212 return (x >> 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) | (x << 24);
213 }
214 return x;
215}
216
217BLI_INLINE float swap_float(float x, int swap)
218{
219 if (swap != 0) {
220 union {
221 float f;
222 unsigned char b[4];
223 } dat1, dat2;
224
225 dat1.f = x;
226 dat2.b[0] = dat1.b[3];
227 dat2.b[1] = dat1.b[2];
228 dat2.b[2] = dat1.b[1];
229 dat2.b[3] = dat1.b[0];
230 return dat2.f;
231 }
232 return x;
233}
234
235/* Other */
236
237BLI_INLINE unsigned int clamp_uint(unsigned int x, unsigned int low, unsigned int high)
238{
239 if (x > high) {
240 return high;
241 }
242 if (x < low) {
243 return low;
244 }
245 return x;
246}
247
248BLI_INLINE float clamp_float(float x, float low, float high)
249{
250 if (x > high) {
251 return high;
252 }
253 if (x < low) {
254 return low;
255 }
256 return x;
257}
258
259BLI_INLINE unsigned int float_uint(float value, unsigned int max)
260{
261 if (value < 0.0f) {
262 return 0;
263 }
264 if (value > (1.0f - 0.5f / (float)max)) {
265 return max;
266 }
267 return (unsigned int)(((float)max * value) + 0.5f);
268}
#define BLI_INLINE
BMesh const char void * data
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
nullptr 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)
format
@ format_Cineon
@ format_DPX
void logImageSetVerbose(int verbosity)
int logImageSetDataRGBA(LogImageFile *logImage, const float *data, int dataIsLinearRGB)
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)
#define swap(a, b)
Definition sort.cc:59
unsigned int refLowData
unsigned int refHighData
uintptr_t memBufferSize
float referenceWhite
unsigned char * memBuffer
unsigned char * memCursor
LogImageElement element[8]
float referenceBlack
max
Definition text_draw.cc:251