90 if (size <
sizeof(magicNum)) {
93 magicNum = *
static_cast<uint *
>(
const_cast<void *
>(buffer));
113 if (logImage !=
nullptr) {
114 if (logImage->
file) {
115 fclose(logImage->
file);
116 logImage->
file =
nullptr;
118 MEM_delete(logImage);
124 *width = logImage->
width;
125 *height = logImage->
height;
126 *depth = logImage->
depth;
138 return ((width * logElement.
depth - 1) / 32 + 1) * 4;
141 return ((width * logElement.
depth - 1) / 4 + 1) * 4;
145 return ((width * logElement.
depth * 10 - 1) / 32 + 1) * 4;
148 return ((width * logElement.
depth - 1) / 3 + 1) * 4;
153 return ((width * logElement.
depth * 12 - 1) / 32 + 1) * 4;
156 return width * logElement.
depth * 2;
160 return width * logElement.
depth * 2;
182 logImage->
width, logImage->
height, logImage->
depth,
sizeof(
float),
true, __func__));
183 if (elementData ==
nullptr) {
188 data, elementData, logImage, logImage->
element[0], dataIsLinearRGB) != 0)
190 MEM_delete(elementData);
197 MEM_delete(elementData);
210 if (row ==
nullptr) {
212 printf(
"Cineon: Cannot allocate row.\n");
217 for (
size_t y = 0;
y < logImage->
height;
y++) {
222 for (
size_t x = 0;
x < logImage->
width * logImage->
depth;
x++) {
238 printf(
"Cineon: Error while writing file.\n");
258 float *elementData[3] = {};
260 for (
float *element_data : elementData) {
261 MEM_delete(element_data);
272 if (elementData[i] ==
nullptr) {
274 printf(
"Cineon: Cannot allocate memory for elementData[%d]\n.", i);
281 printf(
"Cineon: Cannot read elementData[%d]\n.", i);
289 elementData[0],
data, logImage, logImage->
element[0], dataIsLinearRGB);
295 mergedElement.
depth = 3;
297 float *mergedData =
static_cast<float *
>(
299 if (mergedData ==
nullptr) {
301 printf(
"Cineon: Cannot allocate mergedData.\n");
306 const size_t numPixels = size_t(logImage->
width) * size_t(logImage->
height);
307 for (
size_t i = 0; i < numPixels; i++) {
308 for (
int c = 0; c < 3; c++) {
309 mergedData[i * 3 + c] = elementData[c][i];
314 mergedData,
data, logImage, mergedElement, dataIsLinearRGB);
315 MEM_delete(mergedData);
370 for (
size_t y = 0;
y < logImage->
height;
y++) {
371 for (
size_t x = 0;
x < logImage->
width * logElement.
depth;
x += 32) {
374 printf(
"Cineon: EOF reached\n");
379 for (
int offset = 0; offset < 32 &&
x + offset < logImage->
width; offset++) {
396 for (
size_t y = 0;
y < logImage->
height;
y++) {
400 printf(
"Cineon: Couldn't seek at %d\n",
int(logElement.
dataOffset +
y * rowLength));
405 for (
size_t x = 0;
x < logImage->
width * logElement.
depth;
x++) {
408 printf(
"Cineon: EOF reached\n");
432 for (
size_t y = 0;
y < logImage->
height;
y++) {
434 for (
size_t x = 0;
x < logImage->
width * logElement.
depth;
x++) {
440 else if (logElement.
packing == 2) {
446 printf(
"Cineon: EOF reached\n");
466 uint pixel, oldPixel;
469 for (
size_t y = 0;
y < logImage->
height;
y++) {
482 for (
size_t x = 0;
x < logImage->
width * logElement.
depth;
x++) {
484 offset = 10 - offset2;
488 else if (offset == 32) {
491 else if (offset + 10 > 32) {
493 oldPixel = (pixel >> offset);
494 offset2 = 32 - offset;
502 printf(
"Cineon: EOF reached\n");
509 float((((pixel << offset2) >> offset) & 0x3ff) | oldPixel) / 1023.0f;
535 for (sampleIndex = 0; sampleIndex < numSamples; sampleIndex++) {
538 printf(
"Cineon: EOF reached\n");
545 data[sampleIndex] =
float(pixel >> 4) / 4095.0f;
547 else if (logElement.
packing == 2) {
548 data[sampleIndex] =
float(pixel) / 4095.0f;
559 uint pixel, oldPixel;
562 for (
size_t y = 0;
y < logImage->
height;
y++) {
575 for (
size_t x = 0;
x < logImage->
width * logElement.
depth;
x++) {
577 offset = 12 - offset2;
581 else if (offset == 32) {
584 else if (offset + 12 > 32) {
586 oldPixel = (pixel >> offset);
587 offset2 = 32 - offset;
595 printf(
"Cineon: EOF reached\n");
602 float((((pixel << offset2) >> offset) & 0xfff) | oldPixel) / 4095.0f;
625 for (sampleIndex = 0; sampleIndex < numSamples; sampleIndex++) {
628 printf(
"Cineon: EOF reached\n");
633 data[sampleIndex] =
float(pixel) / 65535.0f;
646 float gain, negativeFilmGamma, offset,
step;
652 negativeFilmGamma = 0.6;
657 negativeFilmGamma * logImage->
gamma / 1.7f));
658 offset = gain - logElement.
maxValue;
660 for (i = 0; i < lutsize; i++) {
662 log10f(
powf((i + offset) / gain, 1.7f / logImage->
gamma)) /
663 (
step / negativeFilmGamma)) /
673 float breakPoint, gain, kneeGain, kneeOffset, negativeFilmGamma, offset,
step, softClip;
682 negativeFilmGamma = 0.6;
692 negativeFilmGamma * logImage->
gamma / 1.7f));
693 offset = gain - logElement.
maxValue;
694 kneeOffset =
powf(10,
696 logImage->
gamma / 1.7f) *
699 kneeGain = (logElement.
maxValue - kneeOffset) /
powf(5 * softClip, softClip / 100);
701 for (i = 0; i < lutsize; i++) {
702 if (i < logImage->referenceBlack) {
705 else if (i > breakPoint) {
706 lut[i] = (
powf(i - breakPoint, softClip / 100) * kneeGain + kneeOffset) /
712 logImage->
gamma / 1.7f) *
730 for (i = 0; i < lutsize; i++) {
732 if (col < 0.0031308f) {
733 lut[i] = (col < 0.0f) ? 0.0f : col * 12.92f;
736 lut[i] = 1.055f *
powf(col, 1.0f / 2.4f) - 0.055f;
751 for (i = 0; i < lutsize; i++) {
753 if (col < 0.04045f) {
754 lut[i] = (col < 0.0f) ? 0.0f : col * (1.0f / 12.92f);
757 lut[i] =
powf((col + 0.055f) * (1.0f / 1.055f), 2.4f);
771 const float *src_ptr = src;
772 float *dst_ptr = dst;
775 for (i = 0; i < logImage->
width * logImage->
height; i++) {
791 const float *src_ptr = src;
792 float *dst_ptr = dst;
795 for (i = 0; i < logImage->
width * logImage->
height; i++) {
813 const float *src_ptr = src;
814 float *dst_ptr = dst;
818 const float scale = 1.0f / (refHighData - refLowData);
820 for (i = 0; i < logImage->
width * logImage->
height; i++) {
822 *(dst_ptr++) = value;
823 *(dst_ptr++) = value;
824 *(dst_ptr++) = value;
853 if (dstIsLinearRGB) {
858 for (i = 0; i < logImage->
width * logImage->
height; i++) {
877 const float *srgbSrc;
878 float *srgbSrc_alloc;
880 const float *src_ptr = src;
883 if (srcIsLinearRGB != 0) {
885 srgbSrc_alloc =
static_cast<float *
>(
887 if (srgbSrc_alloc ==
nullptr) {
891 memcpy(srgbSrc_alloc,
893 4 *
size_t(logImage->
width) *
size_t(logImage->
height) *
sizeof(
float));
894 srgbSrc_ptr = srgbSrc_alloc;
898 for (i = 0; i < logImage->
width * logImage->
height; i++) {
906 srgbSrc = srgbSrc_alloc;
916 if (srcIsLinearRGB != 0) {
917 MEM_delete(srgbSrc_alloc);
#define BLI_SCOPED_DEFER(function_to_defer)
Read Blender memory allocation and freeing.
#define CINEON_FILE_MAGIC
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
float3x3 scale(float3x3 mat, float2 scale)
static float * getSrgbToLinLut(const LogImageElement &logElement)
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
size_t getRowLength(size_t width, const LogImageElement *logElement)
int logimage_fseek(LogImageFile *logFile, uintptr_t offset)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
BLI_INLINE float clamp_float(float x, float low, float high)
void logImageClose(LogImageFile *logImage)
int logImageIsCineon(const void *buffer, const uint size)
static float * getLogToLinLut(const LogImageFile *logImage, const LogImageElement &logElement)
void logImageGetSize(const LogImageFile *logImage, int *width, int *height, int *depth)
BLI_INLINE unsigned int float_uint(float value, unsigned int max)
static float * getLinToSrgbLut(const LogImageElement &logElement)
void logImageSetVerbose(int verbosity)
void * imb_alloc_pixels(unsigned int x, unsigned int y, unsigned int channels, size_t typesize, bool initialize_pixels, const char *alloc_name)
int logimage_read_ushort(ushort *x, LogImageFile *logFile)
BLI_INLINE unsigned int swap_uint(unsigned int x, int swap)
LogImageFile * logImageOpenFromMemory(const uchar *buffer, uint size)
static int logImageElementGetData10Packed(LogImageFile *logImage, const LogImageElement &logElement, float *data)
static int logImageElementGetData1(LogImageFile *logImage, const LogImageElement &logElement, float *data)
static int logImageElementGetData10(LogImageFile *logImage, const LogImageElement &logElement, float *data)
void cineonSetVerbose(int verbosity)
static int logImageElementGetData(LogImageFile *logImage, const LogImageElement &logElement, float *data)
static int logImageElementGetData12Packed(LogImageFile *logImage, const LogImageElement &logElement, float *data)
BMesh const char void * data
LogImageFile * cineonOpen(const uchar *buffer, size_t bufferSize)
LogImageFile * logImageCreate(const char *filepath, int width, int height, const char *creator)
int logImageSetDataRGBA(LogImageFile *logImage, const float *data, int dataIsLinearRGB)
static int convertLogElementToRGBA(const float *src, float *dst, const LogImageFile *logImage, const LogImageElement &logElement, int dstIsLinearRGB)
static int logImageSetData10(LogImageFile *logImage, const LogImageElement &logElement, const float *data)
static int convertRGBAToLogElement(const float *src, float *dst, const LogImageFile *logImage, const LogImageElement &logElement, int srcIsLinearRGB)
int logimage_read_uint(uint *x, LogImageFile *logFile)
static int logImageElementGetData8(LogImageFile *logImage, const LogImageElement &logElement, float *data)
int logimage_read_uchar(uchar *x, LogImageFile *logFile)
static int logImageElementGetData16(LogImageFile *logImage, const LogImageElement &logElement, float *data)
static float * getLinToLogLut(const LogImageFile *logImage, const LogImageElement &logElement)
int logImageGetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB)
static void convertLuminance_RGBA(const float *src, float *dst, const LogImageFile *logImage, const LogImageElement &logElement)
int logimage_fwrite(const void *buffer, size_t size, uint count, LogImageFile *logFile)
static void convertRGBA_RGB(const float *src, float *dst, const LogImageFile *logImage, const LogImageElement &logElement)
BLI_INLINE unsigned short swap_ushort(unsigned short x, int swap)
static int logImageElementGetData12(LogImageFile *logImage, const LogImageElement &logElement, float *data)
LogImageFile * cineonCreate(const char *filepath, int width, int height, const char *creator)
static void convertRGB_RGBA(const float *src, float *dst, const LogImageFile *logImage, const LogImageElement &logElement)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
LogImageElement element[8]