Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/imbuf/intern/cineon/logImageCore.c')
-rw-r--r--source/blender/imbuf/intern/cineon/logImageCore.c348
1 files changed, 232 insertions, 116 deletions
diff --git a/source/blender/imbuf/intern/cineon/logImageCore.c b/source/blender/imbuf/intern/cineon/logImageCore.c
index 2169665cf78..5d1623374d4 100644
--- a/source/blender/imbuf/intern/cineon/logImageCore.c
+++ b/source/blender/imbuf/intern/cineon/logImageCore.c
@@ -105,8 +105,9 @@ LogImageFile *logImageOpenFromFile(const char *filename, int cineon)
(void)cineon;
- if (f == NULL)
+ if (f == NULL) {
return NULL;
+ }
if (fread(&magicNum, sizeof(unsigned int), 1, f) != 1) {
fclose(f);
@@ -115,20 +116,24 @@ LogImageFile *logImageOpenFromFile(const char *filename, int cineon)
fclose(f);
- if (logImageIsDpx(&magicNum))
+ if (logImageIsDpx(&magicNum)) {
return dpxOpen((const unsigned char *)filename, 0, 0);
- else if (logImageIsCineon(&magicNum))
+ }
+ else if (logImageIsCineon(&magicNum)) {
return cineonOpen((const unsigned char *)filename, 0, 0);
+ }
return NULL;
}
LogImageFile *logImageOpenFromMemory(const unsigned char *buffer, unsigned int size)
{
- if (logImageIsDpx(buffer))
+ if (logImageIsDpx(buffer)) {
return dpxOpen(buffer, 1, size);
- else if (logImageIsCineon(buffer))
+ }
+ else if (logImageIsCineon(buffer)) {
return cineonOpen(buffer, 1, size);
+ }
return NULL;
}
@@ -146,9 +151,10 @@ LogImageFile *logImageCreate(const char *filename,
const char *creator)
{
/* referenceWhite, referenceBlack and gamma values are only supported for DPX file */
- if (cineon)
+ if (cineon) {
return cineonCreate(filename, width, height, bitsPerSample, creator);
- else
+ }
+ else {
return dpxCreate(filename,
width,
height,
@@ -159,6 +165,7 @@ LogImageFile *logImageCreate(const char *filename,
referenceBlack,
gamma,
creator);
+ }
return NULL;
}
@@ -196,16 +203,20 @@ size_t getRowLength(size_t width, LogImageElement logElement)
return ((width * logElement.depth - 1) / 4 + 1) * 4;
case 10:
- if (logElement.packing == 0)
+ if (logElement.packing == 0) {
return ((width * logElement.depth * 10 - 1) / 32 + 1) * 4;
- else if (logElement.packing == 1 || logElement.packing == 2)
+ }
+ else if (logElement.packing == 1 || logElement.packing == 2) {
return ((width * logElement.depth - 1) / 3 + 1) * 4;
+ }
break;
case 12:
- if (logElement.packing == 0)
+ if (logElement.packing == 0) {
return ((width * logElement.depth * 12 - 1) / 32 + 1) * 4;
- else if (logElement.packing == 1 || logElement.packing == 2)
+ }
+ else if (logElement.packing == 1 || logElement.packing == 2) {
return width * logElement.depth * 2;
+ }
break;
case 16:
return width * logElement.depth * 2;
@@ -224,8 +235,9 @@ int logImageSetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB
elementData = (float *)imb_alloc_pixels(
logImage->width, logImage->height, logImage->depth, sizeof(float), __func__);
- if (elementData == NULL)
+ if (elementData == NULL) {
return 1;
+ }
if (convertRGBAToLogElement(
data, elementData, logImage, logImage->element[0], dataIsLinearRGB) != 0) {
@@ -266,19 +278,22 @@ static int logImageSetData8(LogImageFile *logImage, LogImageElement logElement,
row = (unsigned char *)MEM_mallocN(rowLength, __func__);
if (row == NULL) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Cannot allocate row.\n");
+ }
return 1;
}
memset(row, 0, rowLength);
for (size_t y = 0; y < logImage->height; y++) {
- for (size_t x = 0; x < logImage->width * logImage->depth; x++)
+ for (size_t x = 0; x < logImage->width * logImage->depth; x++) {
row[x] = (unsigned char)float_uint(data[y * logImage->width * logImage->depth + x], 255);
+ }
if (logimage_fwrite(row, rowLength, 1, logImage) == 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Error while writing file.\n");
+ }
MEM_freeN(row);
return 1;
}
@@ -295,8 +310,9 @@ static int logImageSetData10(LogImageFile *logImage, LogImageElement logElement,
row = (unsigned int *)MEM_mallocN(rowLength, __func__);
if (row == NULL) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Cannot allocate row.\n");
+ }
return 1;
}
@@ -316,8 +332,9 @@ static int logImageSetData10(LogImageFile *logImage, LogImageElement logElement,
offset = 22;
}
}
- if (pixel != 0)
+ if (pixel != 0) {
row[index] = swap_uint(pixel, logImage->isMSB);
+ }
if (logimage_fwrite(row, rowLength, 1, logImage) == 0) {
if (verbose) {
@@ -338,20 +355,23 @@ static int logImageSetData12(LogImageFile *logImage, LogImageElement logElement,
row = (unsigned short *)MEM_mallocN(rowLength, __func__);
if (row == NULL) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Cannot allocate row.\n");
+ }
return 1;
}
for (size_t y = 0; y < logImage->height; y++) {
- for (size_t x = 0; x < logImage->width * logImage->depth; x++)
+ for (size_t x = 0; x < logImage->width * logImage->depth; x++) {
row[x] = swap_ushort(
((unsigned short)float_uint(data[y * logImage->width * logImage->depth + x], 4095)) << 4,
logImage->isMSB);
+ }
if (logimage_fwrite(row, rowLength, 1, logImage) == 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Error while writing file.\n");
+ }
MEM_freeN(row);
return 1;
}
@@ -367,20 +387,23 @@ static int logImageSetData16(LogImageFile *logImage, LogImageElement logElement,
row = (unsigned short *)MEM_mallocN(rowLength, __func__);
if (row == NULL) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Cannot allocate row.\n");
+ }
return 1;
}
for (size_t y = 0; y < logImage->height; y++) {
- for (size_t x = 0; x < logImage->width * logImage->depth; x++)
+ for (size_t x = 0; x < logImage->width * logImage->depth; x++) {
row[x] = swap_ushort(
(unsigned short)float_uint(data[y * logImage->width * logImage->depth + x], 65535),
logImage->isMSB);
+ }
if (logimage_fwrite(row, rowLength, 1, logImage) == 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Error while writing file.\n");
+ }
MEM_freeN(row);
return 1;
}
@@ -416,28 +439,35 @@ int logImageGetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB
elementData[i] = imb_alloc_pixels(
logImage->width, logImage->height, logImage->element[i].depth, sizeof(float), __func__);
if (elementData[i] == NULL) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Cannot allocate memory for elementData[%d]\n.", i);
- for (j = 0; j < i; j++)
- if (elementData[j] != NULL)
+ }
+ for (j = 0; j < i; j++) {
+ if (elementData[j] != NULL) {
MEM_freeN(elementData[j]);
+ }
+ }
return 1;
}
elementData_ptr[i] = elementData[i];
/* Load data */
if (logImageElementGetData(logImage, logImage->element[i], elementData[i]) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Cannot read elementData[%d]\n.", i);
- for (j = 0; j < i; j++)
- if (elementData[j] != NULL)
+ }
+ for (j = 0; j < i; j++) {
+ if (elementData[j] != NULL) {
MEM_freeN(elementData[j]);
+ }
+ }
return 1;
}
}
- if (logImage->element[i].descriptor == descriptor_Alpha)
+ if (logImage->element[i].descriptor == descriptor_Alpha) {
hasAlpha = 1;
+ }
}
/* only one element, easy case, no need to do anything */
@@ -461,28 +491,34 @@ int logImageGetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB
switch (logImage->element[i].descriptor) {
case descriptor_Red:
case descriptor_RGB:
- if (hasAlpha == 0)
+ if (hasAlpha == 0) {
mergedElement.descriptor = descriptor_RGB;
- else
+ }
+ else {
mergedElement.descriptor = descriptor_RGBA;
+ }
sortedElementData[0] = i;
break;
case descriptor_Green:
- if (hasAlpha == 0)
+ if (hasAlpha == 0) {
mergedElement.descriptor = descriptor_RGB;
- else
+ }
+ else {
mergedElement.descriptor = descriptor_RGBA;
+ }
sortedElementData[1] = i;
break;
case descriptor_Blue:
- if (hasAlpha == 0)
+ if (hasAlpha == 0) {
mergedElement.descriptor = descriptor_RGB;
- else
+ }
+ else {
mergedElement.descriptor = descriptor_RGBA;
+ }
sortedElementData[2] = i;
break;
@@ -493,57 +529,77 @@ int logImageGetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB
break;
case descriptor_Luminance:
- if (mergedElement.descriptor == -1)
- if (hasAlpha == 0)
+ if (mergedElement.descriptor == -1) {
+ if (hasAlpha == 0) {
mergedElement.descriptor = descriptor_Luminance;
- else
+ }
+ else {
mergedElement.descriptor = descriptor_YA;
+ }
+ }
else if (mergedElement.descriptor == descriptor_Chrominance) {
- if (mergedElement.depth == 2)
+ if (mergedElement.depth == 2) {
mergedElement.descriptor = descriptor_CbYCrY;
- else if (mergedElement.depth == 3)
- if (hasAlpha == 0)
+ }
+ else if (mergedElement.depth == 3) {
+ if (hasAlpha == 0) {
mergedElement.descriptor = descriptor_CbYCr;
- else
+ }
+ else {
mergedElement.descriptor = descriptor_CbYACrYA;
- else if (mergedElement.depth == 4)
+ }
+ }
+ else if (mergedElement.depth == 4) {
mergedElement.descriptor = descriptor_CbYCrA;
+ }
}
/* Y component always in 1 except if it's alone or with alpha */
- if (mergedElement.depth == 1 || (mergedElement.depth == 2 && hasAlpha == 1))
+ if (mergedElement.depth == 1 || (mergedElement.depth == 2 && hasAlpha == 1)) {
sortedElementData[0] = i;
- else
+ }
+ else {
sortedElementData[1] = i;
+ }
break;
case descriptor_Chrominance:
- if (mergedElement.descriptor == -1)
+ if (mergedElement.descriptor == -1) {
mergedElement.descriptor = descriptor_Chrominance;
+ }
else if (mergedElement.descriptor == descriptor_Luminance) {
- if (mergedElement.depth == 2)
+ if (mergedElement.depth == 2) {
mergedElement.descriptor = descriptor_CbYCrY;
- else if (mergedElement.depth == 3)
- if (hasAlpha == 0)
+ }
+ else if (mergedElement.depth == 3) {
+ if (hasAlpha == 0) {
mergedElement.descriptor = descriptor_CbYCr;
- else
+ }
+ else {
mergedElement.descriptor = descriptor_CbYACrYA;
- else if (mergedElement.depth == 4)
+ }
+ }
+ else if (mergedElement.depth == 4) {
mergedElement.descriptor = descriptor_CbYCrA;
+ }
}
/* Cb and Cr always in 0 or 2 */
- if (sortedElementData[0] == -1)
+ if (sortedElementData[0] == -1) {
sortedElementData[0] = i;
- else
+ }
+ else {
sortedElementData[2] = i;
+ }
break;
case descriptor_CbYCr:
- if (hasAlpha == 0)
+ if (hasAlpha == 0) {
mergedElement.descriptor = descriptor_CbYCr;
- else
+ }
+ else {
mergedElement.descriptor = descriptor_CbYCrA;
+ }
sortedElementData[0] = i;
break;
@@ -568,25 +624,32 @@ int logImageGetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB
mergedData = (float *)imb_alloc_pixels(
logImage->width, logImage->height, mergedElement.depth, sizeof(float), __func__);
if (mergedData == NULL) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Cannot allocate mergedData.\n");
- for (i = 0; i < logImage->numElements; i++)
- if (elementData[i] != NULL)
+ }
+ for (i = 0; i < logImage->numElements; i++) {
+ if (elementData[i] != NULL) {
MEM_freeN(elementData[i]);
+ }
+ }
return 1;
}
sampleIndex = 0;
while (sampleIndex < logImage->width * logImage->height * mergedElement.depth) {
- for (i = 0; i < logImage->numElements; i++)
- for (j = 0; j < logImage->element[sortedElementData[i]].depth; j++)
+ for (i = 0; i < logImage->numElements; i++) {
+ for (j = 0; j < logImage->element[sortedElementData[i]].depth; j++) {
mergedData[sampleIndex++] = *(elementData_ptr[sortedElementData[i]]++);
+ }
+ }
}
/* Done with elements data, clean-up */
- for (i = 0; i < logImage->numElements; i++)
- if (elementData[i] != NULL)
+ for (i = 0; i < logImage->numElements; i++) {
+ if (elementData[i] != NULL) {
MEM_freeN(elementData[i]);
+ }
+ }
returnValue = convertLogElementToRGBA(
mergedData, data, logImage, mergedElement, dataIsLinearRGB);
@@ -605,17 +668,21 @@ static int logImageElementGetData(LogImageFile *logImage, LogImageElement logEle
return logImageElementGetData8(logImage, logElement, data);
case 10:
- if (logElement.packing == 0)
+ if (logElement.packing == 0) {
return logImageElementGetData10Packed(logImage, logElement, data);
- else if (logElement.packing == 1 || logElement.packing == 2)
+ }
+ else if (logElement.packing == 1 || logElement.packing == 2) {
return logImageElementGetData10(logImage, logElement, data);
+ }
break;
case 12:
- if (logElement.packing == 0)
+ if (logElement.packing == 0) {
return logImageElementGetData12Packed(logImage, logElement, data);
- else if (logElement.packing == 1 || logElement.packing == 2)
+ }
+ else if (logElement.packing == 1 || logElement.packing == 2) {
return logImageElementGetData12(logImage, logElement, data);
+ }
break;
case 16:
@@ -631,8 +698,9 @@ static int logImageElementGetData1(LogImageFile *logImage, LogImageElement logEl
/* seek at the right place */
if (logimage_fseek(logImage, logElement.dataOffset, SEEK_SET) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Couldn't seek at %d\n", logElement.dataOffset);
+ }
return 1;
}
@@ -640,14 +708,16 @@ static int logImageElementGetData1(LogImageFile *logImage, LogImageElement logEl
for (size_t y = 0; y < logImage->height; y++) {
for (size_t x = 0; x < logImage->width * logElement.depth; x += 32) {
if (logimage_read_uint(&pixel, logImage) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: EOF reached\n");
+ }
return 1;
}
pixel = swap_uint(pixel, logImage->isMSB);
- for (int offset = 0; offset < 32 && x + offset < logImage->width; offset++)
+ for (int offset = 0; offset < 32 && x + offset < logImage->width; offset++) {
data[y * logImage->width * logElement.depth + x + offset] = (float)((pixel >> offset) &
0x01);
+ }
}
}
return 0;
@@ -662,15 +732,17 @@ static int logImageElementGetData8(LogImageFile *logImage, LogImageElement logEl
for (size_t y = 0; y < logImage->height; y++) {
/* 8 bits are 32-bits padded so we need to seek at each row */
if (logimage_fseek(logImage, logElement.dataOffset + y * rowLength, SEEK_SET) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Couldn't seek at %d\n", (int)(logElement.dataOffset + y * rowLength));
+ }
return 1;
}
for (size_t x = 0; x < logImage->width * logElement.depth; x++) {
if (logimage_read_uchar(&pixel, logImage) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: EOF reached\n");
+ }
return 1;
}
data[y * logImage->width * logElement.depth + x] = (float)pixel / 255.0f;
@@ -687,8 +759,9 @@ static int logImageElementGetData10(LogImageFile *logImage,
/* seek to data */
if (logimage_fseek(logImage, logElement.dataOffset, SEEK_SET) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Couldn't seek at %d\n", logElement.dataOffset);
+ }
return 1;
}
@@ -698,14 +771,17 @@ static int logImageElementGetData10(LogImageFile *logImage,
for (size_t x = 0; x < logImage->width * logElement.depth; x++) {
/* we need to read the next long */
if (offset >= 30) {
- if (logElement.packing == 1)
+ if (logElement.packing == 1) {
offset = 2;
- else if (logElement.packing == 2)
+ }
+ else if (logElement.packing == 2) {
offset = 0;
+ }
if (logimage_read_uint(&pixel, logImage) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: EOF reached\n");
+ }
return 1;
}
pixel = swap_uint(pixel, logImage->isMSB);
@@ -722,14 +798,17 @@ static int logImageElementGetData10(LogImageFile *logImage,
for (size_t x = 0; x < logImage->width * logElement.depth; x++) {
/* we need to read the next long */
if (offset < 0) {
- if (logElement.packing == 1)
+ if (logElement.packing == 1) {
offset = 22;
- else if (logElement.packing == 2)
+ }
+ else if (logElement.packing == 2) {
offset = 20;
+ }
if (logimage_read_uint(&pixel, logImage) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: EOF reached\n");
+ }
return 1;
}
pixel = swap_uint(pixel, logImage->isMSB);
@@ -755,9 +834,10 @@ static int logImageElementGetData10Packed(LogImageFile *logImage,
for (size_t y = 0; y < logImage->height; y++) {
/* seek to data */
if (logimage_fseek(logImage, y * rowLength + logElement.dataOffset, SEEK_SET) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Couldn't seek at %u\n",
(unsigned int)(y * rowLength + logElement.dataOffset));
+ }
return 1;
}
@@ -784,8 +864,9 @@ static int logImageElementGetData10Packed(LogImageFile *logImage,
if (offset == 0) {
/* we need to read the next long */
if (logimage_read_uint(&pixel, logImage) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: EOF reached\n");
+ }
return 1;
}
pixel = swap_uint(pixel, logImage->isMSB);
@@ -808,8 +889,9 @@ static int logImageElementGetData12(LogImageFile *logImage,
/* seek to data */
if (logimage_fseek(logImage, logElement.dataOffset, SEEK_SET) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Couldn't seek at %d\n", logElement.dataOffset);
+ }
return 1;
}
@@ -818,16 +900,19 @@ static int logImageElementGetData12(LogImageFile *logImage,
for (sampleIndex = 0; sampleIndex < numSamples; sampleIndex++) {
if (logimage_read_ushort(&pixel, logImage) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: EOF reached\n");
+ }
return 1;
}
pixel = swap_ushort(pixel, logImage->isMSB);
- if (logElement.packing == 1) /* padded to the right */
+ if (logElement.packing == 1) { /* padded to the right */
data[sampleIndex] = (float)(pixel >> 4) / 4095.0f;
- else if (logElement.packing == 2) /* padded to the left */
+ }
+ else if (logElement.packing == 2) { /* padded to the left */
data[sampleIndex] = (float)pixel / 4095.0f;
+ }
}
return 0;
}
@@ -843,9 +928,10 @@ static int logImageElementGetData12Packed(LogImageFile *logImage,
for (size_t y = 0; y < logImage->height; y++) {
/* seek to data */
if (logimage_fseek(logImage, y * rowLength + logElement.dataOffset, SEEK_SET) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Couldn't seek at %u\n",
(unsigned int)(y * rowLength + logElement.dataOffset));
+ }
return 1;
}
@@ -872,8 +958,9 @@ static int logImageElementGetData12Packed(LogImageFile *logImage,
if (offset == 0) {
/* we need to read the next long */
if (logimage_read_uint(&pixel, logImage) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: EOF reached\n");
+ }
return 1;
}
pixel = swap_uint(pixel, logImage->isMSB);
@@ -896,15 +983,17 @@ static int logImageElementGetData16(LogImageFile *logImage,
/* seek to data */
if (logimage_fseek(logImage, logElement.dataOffset, SEEK_SET) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Couldn't seek at %d\n", logElement.dataOffset);
+ }
return 1;
}
for (sampleIndex = 0; sampleIndex < numSamples; sampleIndex++) {
if (logimage_read_ushort(&pixel, logImage) != 0) {
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: EOF reached\n");
+ }
return 1;
}
pixel = swap_ushort(pixel, logImage->isMSB);
@@ -999,11 +1088,12 @@ static float *getLinToLogLut(LogImageFile *logImage, LogImageElement logElement)
negativeFilmGamma * logImage->gamma / 1.7f));
offset = gain - logElement.maxValue;
- for (i = 0; i < lutsize; i++)
+ for (i = 0; i < lutsize; i++) {
lut[i] = (logImage->referenceWhite +
log10f(powf((i + offset) / gain, 1.7f / logImage->gamma)) /
(step / negativeFilmGamma)) /
logElement.maxValue;
+ }
return lut;
}
@@ -1040,18 +1130,21 @@ static float *getLogToLinLut(LogImageFile *logImage, LogImageElement logElement)
kneeGain = (logElement.maxValue - kneeOffset) / powf(5 * softClip, softClip / 100);
for (i = 0; i < lutsize; i++) {
- if (i < logImage->referenceBlack)
+ if (i < logImage->referenceBlack) {
lut[i] = 0.0f;
- else if (i > breakPoint)
+ }
+ else if (i > breakPoint) {
lut[i] = (powf(i - breakPoint, softClip / 100) * kneeGain + kneeOffset) /
logElement.maxValue;
- else
+ }
+ else {
lut[i] = (powf(10,
((float)i - logImage->referenceWhite) * step / negativeFilmGamma *
logImage->gamma / 1.7f) *
gain -
offset) /
logElement.maxValue;
+ }
}
return lut;
@@ -1067,10 +1160,12 @@ static float *getLinToSrgbLut(LogImageElement logElement)
for (i = 0; i < lutsize; i++) {
col = (float)i / logElement.maxValue;
- if (col < 0.0031308f)
+ if (col < 0.0031308f) {
lut[i] = (col < 0.0f) ? 0.0f : col * 12.92f;
- else
+ }
+ else {
lut[i] = 1.055f * powf(col, 1.0f / 2.4f) - 0.055f;
+ }
}
return lut;
@@ -1086,10 +1181,12 @@ static float *getSrgbToLinLut(LogImageElement logElement)
for (i = 0; i < lutsize; i++) {
col = (float)i / logElement.maxValue;
- if (col < 0.04045f)
+ if (col < 0.04045f) {
lut[i] = (col < 0.0f) ? 0.0f : col * (1.0f / 12.92f);
- else
+ }
+ else {
lut[i] = powf((col + 0.055f) * (1.0f / 1.055f), 2.4f);
+ }
}
return lut;
@@ -1123,10 +1220,12 @@ static int convertRGBA_RGB(float *src,
case transfer_PrintingDensity: {
float *lut;
- if (elementIsSource == 1)
+ if (elementIsSource == 1) {
lut = getLogToLinLut(logImage, logElement);
- else
+ }
+ else {
lut = getLinToLogLut(logImage, logElement);
+ }
for (i = 0; i < logImage->width * logImage->height; i++) {
*(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
@@ -1141,8 +1240,9 @@ static int convertRGBA_RGB(float *src,
}
default:
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Unknown transfer %d.\n", logElement.transfer);
+ }
return 1;
}
}
@@ -1175,10 +1275,12 @@ static int convertRGB_RGBA(float *src,
case transfer_PrintingDensity: {
float *lut;
- if (elementIsSource == 1)
+ if (elementIsSource == 1) {
lut = getLogToLinLut(logImage, logElement);
- else
+ }
+ else {
lut = getLinToLogLut(logImage, logElement);
+ }
for (i = 0; i < logImage->width * logImage->height; i++) {
*(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
@@ -1193,8 +1295,9 @@ static int convertRGB_RGBA(float *src,
}
default:
- if (verbose)
+ if (verbose) {
printf("DPX/Cineon: Unknown transfer %d.\n", logElement.transfer);
+ }
return 1;
}
}
@@ -1220,10 +1323,12 @@ static int convertRGBA_RGBA(float *src,
case transfer_PrintingDensity: {
float *lut;
- if (elementIsSource == 1)
+ if (elementIsSource == 1) {
lut = getLogToLinLut(logImage, logElement);
- else
+ }
+ else {
lut = getLinToLogLut(logImage, logElement);
+ }
for (i = 0; i < logImage->width * logImage->height; i++) {
*(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
@@ -1270,10 +1375,12 @@ static int convertABGR_RGBA(float *src,
case transfer_PrintingDensity: {
float *lut;
- if (elementIsSource == 1)
+ if (elementIsSource == 1) {
lut = getLogToLinLut(logImage, logElement);
- else
+ }
+ else {
lut = getLinToLogLut(logImage, logElement);
+ }
for (i = 0; i < logImage->width * logImage->height; i++) {
src_ptr += 4;
@@ -1304,8 +1411,9 @@ static int convertCbYCr_RGBA(float *src,
float *src_ptr = src;
float *dst_ptr = dst;
- if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0)
+ if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0) {
return 1;
+ }
refLowData = (float)logElement.refLowData / logElement.maxValue;
@@ -1335,8 +1443,9 @@ static int convertCbYCrA_RGBA(float *src,
float *src_ptr = src;
float *dst_ptr = dst;
- if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0)
+ if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0) {
return 1;
+ }
refLowData = (float)logElement.refLowData / logElement.maxValue;
@@ -1367,8 +1476,9 @@ static int convertCbYCrY_RGBA(float *src,
float *src_ptr = src;
float *dst_ptr = dst;
- if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0)
+ if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0) {
return 1;
+ }
refLowData = (float)logElement.refLowData / logElement.maxValue;
@@ -1418,8 +1528,9 @@ static int convertCbYACrYA_RGBA(float *src,
float *src_ptr = src;
float *dst_ptr = dst;
- if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0)
+ if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0) {
return 1;
+ }
refLowData = (float)logElement.refLowData / logElement.maxValue;
@@ -1471,8 +1582,9 @@ static int convertLuminance_RGBA(float *src,
float *src_ptr = src;
float *dst_ptr = dst;
- if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0)
+ if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0) {
return 1;
+ }
refLowData = (float)logElement.refLowData / logElement.maxValue;
@@ -1496,8 +1608,9 @@ static int convertYA_RGBA(float *src,
float *src_ptr = src;
float *dst_ptr = dst;
- if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0)
+ if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0) {
return 1;
+ }
refLowData = (float)logElement.refLowData / logElement.maxValue;
@@ -1561,8 +1674,9 @@ static int convertLogElementToRGBA(
return 1;
}
- if (rvalue == 1)
+ if (rvalue == 1) {
return 1;
+ }
else if (dstIsLinearRGB) {
/* convert data from sRGB to Linear RGB via lut */
float *lut = getSrgbToLinLut(logElement);
@@ -1594,8 +1708,9 @@ static int convertRGBAToLogElement(
/* we need to convert src to sRGB */
srgbSrc = (float *)imb_alloc_pixels(
logImage->width, logImage->height, 4, sizeof(float), __func__);
- if (srgbSrc == NULL)
+ if (srgbSrc == NULL) {
return 1;
+ }
memcpy(srgbSrc, src, 4 * (size_t)logImage->width * (size_t)logImage->height * sizeof(float));
srgbSrc_ptr = srgbSrc;
@@ -1611,8 +1726,9 @@ static int convertRGBAToLogElement(
}
MEM_freeN(lut);
}
- else
+ else {
srgbSrc = src;
+ }
/* Convert linear RGBA data in src to format described by logElement in dst */
switch (logElement.descriptor) {