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:
authorCampbell Barton <ideasman42@gmail.com>2019-04-23 04:01:30 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-04-23 04:22:22 +0300
commit64b4b719ebd5201d27aa25d7fa2d765eabded9b0 (patch)
treec6e1147f3b81b90193d3acaa0df3f8c5c93db328 /source/blender/imbuf/intern/cineon
parentac53291e1ff79144ca41d63b0787bfe04da21677 (diff)
Cleanup: style, use braces for imbuf
Diffstat (limited to 'source/blender/imbuf/intern/cineon')
-rw-r--r--source/blender/imbuf/intern/cineon/cineon_dpx.c24
-rw-r--r--source/blender/imbuf/intern/cineon/cineonlib.c66
-rw-r--r--source/blender/imbuf/intern/cineon/dpxlib.c102
-rw-r--r--source/blender/imbuf/intern/cineon/logImageCore.c348
-rw-r--r--source/blender/imbuf/intern/cineon/logImageCore.h42
-rw-r--r--source/blender/imbuf/intern/cineon/logmemfile.c27
6 files changed, 406 insertions, 203 deletions
diff --git a/source/blender/imbuf/intern/cineon/cineon_dpx.c b/source/blender/imbuf/intern/cineon/cineon_dpx.c
index 8f3829ee91e..77c04fd3358 100644
--- a/source/blender/imbuf/intern/cineon/cineon_dpx.c
+++ b/source/blender/imbuf/intern/cineon/cineon_dpx.c
@@ -77,8 +77,9 @@ static struct ImBuf *imb_load_dpx_cineon(const unsigned char *mem,
logImageClose(image);
ibuf->ftype = use_cineon ? IMB_FTYPE_CINEON : IMB_FTYPE_DPX;
- if (flags & IB_alphamode_detect)
+ if (flags & IB_alphamode_detect) {
ibuf->flags |= IB_alphamode_premul;
+ }
return ibuf;
}
@@ -104,14 +105,18 @@ static int imb_save_dpx_cineon(ImBuf *ibuf, const char *filename, int use_cineon
return 0;
}
- if (ibuf->foptions.flag & CINEON_10BIT)
+ if (ibuf->foptions.flag & CINEON_10BIT) {
bitspersample = 10;
- else if (ibuf->foptions.flag & CINEON_12BIT)
+ }
+ else if (ibuf->foptions.flag & CINEON_12BIT) {
bitspersample = 12;
- else if (ibuf->foptions.flag & CINEON_16BIT)
+ }
+ else if (ibuf->foptions.flag & CINEON_16BIT) {
bitspersample = 16;
- else
+ }
+ else {
bitspersample = 8;
+ }
logImage = logImageCreate(filename,
use_cineon,
@@ -149,8 +154,9 @@ static int imb_save_dpx_cineon(ImBuf *ibuf, const char *filename, int use_cineon
MEM_freeN(fbuf);
}
else {
- if (ibuf->rect == NULL)
+ if (ibuf->rect == NULL) {
IMB_rect_from_float(ibuf);
+ }
fbuf = (float *)MEM_mallocN(ibuf->x * ibuf->y * 4 * sizeof(float),
"fbuf in imb_save_dpx_cineon");
@@ -192,8 +198,9 @@ ImBuf *imb_load_cineon(const unsigned char *mem,
int flags,
char colorspace[IM_MAX_SPACE])
{
- if (imb_is_cineon(mem))
+ if (imb_is_cineon(mem)) {
return imb_load_dpx_cineon(mem, size, 1, flags, colorspace);
+ }
return NULL;
}
@@ -212,7 +219,8 @@ ImBuf *imb_load_dpx(const unsigned char *mem,
int flags,
char colorspace[IM_MAX_SPACE])
{
- if (imb_is_dpx(mem))
+ if (imb_is_dpx(mem)) {
return imb_load_dpx_cineon(mem, size, 0, flags, colorspace);
+ }
return NULL;
}
diff --git a/source/blender/imbuf/intern/cineon/cineonlib.c b/source/blender/imbuf/intern/cineon/cineonlib.c
index 79f419e747c..63014919dfb 100644
--- a/source/blender/imbuf/intern/cineon/cineonlib.c
+++ b/source/blender/imbuf/intern/cineon/cineonlib.c
@@ -146,8 +146,9 @@ LogImageFile *cineonOpen(const unsigned char *byteStuff, int fromMemory, size_t
unsigned int dataOffset;
if (cineon == NULL) {
- if (verbose)
+ if (verbose) {
printf("Cineon: Failed to malloc cineon file structure.\n");
+ }
return NULL;
}
@@ -161,8 +162,9 @@ LogImageFile *cineonOpen(const unsigned char *byteStuff, int fromMemory, size_t
/* byteStuff is then the filename */
cineon->file = BLI_fopen(filename, "rb");
if (cineon->file == NULL) {
- if (verbose)
+ if (verbose) {
printf("Cineon: Failed to open file \"%s\".\n", filename);
+ }
logImageClose(cineon);
return NULL;
}
@@ -178,8 +180,9 @@ LogImageFile *cineonOpen(const unsigned char *byteStuff, int fromMemory, size_t
}
if (logimage_fread(&header, sizeof(header), 1, cineon) == 0) {
- if (verbose)
+ if (verbose) {
printf("Cineon: Not enough data for header in \"%s\".\n", byteStuff);
+ }
logImageClose(cineon);
return NULL;
}
@@ -187,13 +190,15 @@ LogImageFile *cineonOpen(const unsigned char *byteStuff, int fromMemory, size_t
/* endianness determination */
if (header.fileHeader.magic_num == swap_uint(CINEON_FILE_MAGIC, 1)) {
cineon->isMSB = 1;
- if (verbose)
+ if (verbose) {
printf("Cineon: File is MSB.\n");
+ }
}
else if (header.fileHeader.magic_num == CINEON_FILE_MAGIC) {
cineon->isMSB = 0;
- if (verbose)
+ if (verbose) {
printf("Cineon: File is LSB.\n");
+ }
}
else {
if (verbose) {
@@ -209,8 +214,9 @@ LogImageFile *cineonOpen(const unsigned char *byteStuff, int fromMemory, size_t
cineon->height = swap_uint(header.imageHeader.element[0].lines_per_image, cineon->isMSB);
if (cineon->width == 0 || cineon->height == 0) {
- if (verbose)
+ if (verbose) {
printf("Cineon: Wrong image dimension: %dx%d\n", cineon->width, cineon->height);
+ }
logImageClose(cineon);
return NULL;
}
@@ -218,13 +224,16 @@ LogImageFile *cineonOpen(const unsigned char *byteStuff, int fromMemory, size_t
cineon->depth = header.imageHeader.elements_per_image;
cineon->srcFormat = format_Cineon;
- if (header.imageHeader.interleave == 0)
+ if (header.imageHeader.interleave == 0) {
cineon->numElements = 1;
- else if (header.imageHeader.interleave == 2)
+ }
+ else if (header.imageHeader.interleave == 2) {
cineon->numElements = header.imageHeader.elements_per_image;
+ }
else {
- if (verbose)
+ if (verbose) {
printf("Cineon: Data interleave not supported: %d\n", header.imageHeader.interleave);
+ }
logImageClose(cineon);
return NULL;
}
@@ -255,8 +264,9 @@ LogImageFile *cineonOpen(const unsigned char *byteStuff, int fromMemory, size_t
}
}
else {
- if (verbose)
+ if (verbose) {
printf("Cineon: Cineon image depth unsupported: %d\n", cineon->depth);
+ }
logImageClose(cineon);
return NULL;
}
@@ -290,28 +300,34 @@ LogImageFile *cineonOpen(const unsigned char *byteStuff, int fromMemory, size_t
default:
/* Not supported */
- if (verbose)
+ if (verbose) {
printf("Cineon: packing unsupported: %d\n", header.imageHeader.packing);
+ }
logImageClose(cineon);
return NULL;
}
- if (cineon->element[i].refLowData == CINEON_UNDEFINED_U32)
+ if (cineon->element[i].refLowData == CINEON_UNDEFINED_U32) {
cineon->element[i].refLowData = 0;
+ }
- if (cineon->element[i].refHighData == CINEON_UNDEFINED_U32)
+ if (cineon->element[i].refHighData == CINEON_UNDEFINED_U32) {
cineon->element[i].refHighData = (unsigned int)cineon->element[i].maxValue;
+ }
if (cineon->element[i].refLowQuantity == CINEON_UNDEFINED_R32 ||
- isnan(cineon->element[i].refLowQuantity))
+ isnan(cineon->element[i].refLowQuantity)) {
cineon->element[i].refLowQuantity = 0.0f;
+ }
if (cineon->element[i].refHighQuantity == CINEON_UNDEFINED_R32 ||
isnan(cineon->element[i].refHighQuantity)) {
- if (cineon->element[i].transfer == transfer_PrintingDensity)
+ if (cineon->element[i].transfer == transfer_PrintingDensity) {
cineon->element[i].refHighQuantity = 2.048f;
- else
+ }
+ else {
cineon->element[i].refHighQuantity = cineon->element[i].maxValue;
+ }
}
cineon->element[i].dataOffset = dataOffset;
@@ -357,15 +373,17 @@ LogImageFile *cineonCreate(
LogImageFile *cineon = (LogImageFile *)MEM_mallocN(sizeof(LogImageFile), __func__);
if (cineon == NULL) {
- if (verbose)
+ if (verbose) {
printf("cineon: Failed to malloc cineon file structure.\n");
+ }
return NULL;
}
/* Only 10 bits Cineon are supported */
if (bitsPerSample != 10) {
- if (verbose)
+ if (verbose) {
printf("cineon: Only 10 bits Cineon are supported.\n");
+ }
logImageClose(cineon);
return NULL;
}
@@ -391,15 +409,18 @@ LogImageFile *cineonCreate(
cineon->gamma = 1.7f;
shortFilename = strrchr(filename, '/');
- if (shortFilename == NULL)
+ if (shortFilename == NULL) {
shortFilename = filename;
- else
+ }
+ else {
shortFilename++;
+ }
cineon->file = BLI_fopen(filename, "wb");
if (cineon->file == NULL) {
- if (verbose)
+ if (verbose) {
printf("cineon: Couldn't open file %s\n", filename);
+ }
logImageClose(cineon);
return NULL;
}
@@ -407,8 +428,9 @@ LogImageFile *cineonCreate(
fillCineonMainHeader(cineon, &header, shortFilename, creator);
if (fwrite(&header, sizeof(header), 1, cineon->file) == 0) {
- if (verbose)
+ if (verbose) {
printf("cineon: Couldn't write image header\n");
+ }
logImageClose(cineon);
return NULL;
}
diff --git a/source/blender/imbuf/intern/cineon/dpxlib.c b/source/blender/imbuf/intern/cineon/dpxlib.c
index 8c0cd88f256..00d59643967 100644
--- a/source/blender/imbuf/intern/cineon/dpxlib.c
+++ b/source/blender/imbuf/intern/cineon/dpxlib.c
@@ -143,8 +143,9 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf
int i;
if (dpx == NULL) {
- if (verbose)
+ if (verbose) {
printf("DPX: Failed to malloc dpx file structure.\n");
+ }
return NULL;
}
@@ -158,8 +159,9 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf
/* byteStuff is then the filename */
dpx->file = BLI_fopen(filename, "rb");
if (dpx->file == NULL) {
- if (verbose)
+ if (verbose) {
printf("DPX: Failed to open file \"%s\".\n", filename);
+ }
logImageClose(dpx);
return NULL;
}
@@ -175,8 +177,9 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf
}
if (logimage_fread(&header, sizeof(header), 1, dpx) == 0) {
- if (verbose)
+ if (verbose) {
printf("DPX: Not enough data for header in \"%s\".\n", byteStuff);
+ }
logImageClose(dpx);
return NULL;
}
@@ -184,13 +187,15 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf
/* endianness determination */
if (header.fileHeader.magic_num == swap_uint(DPX_FILE_MAGIC, 1)) {
dpx->isMSB = 1;
- if (verbose)
+ if (verbose) {
printf("DPX: File is MSB.\n");
+ }
}
else if (header.fileHeader.magic_num == DPX_FILE_MAGIC) {
dpx->isMSB = 0;
- if (verbose)
+ if (verbose) {
printf("DPX: File is LSB.\n");
+ }
}
else {
if (verbose) {
@@ -204,8 +209,9 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf
dpx->numElements = swap_ushort(header.imageHeader.elements_per_image, dpx->isMSB);
size_t max_elements = sizeof(header.imageHeader.element) / sizeof(header.imageHeader.element[0]);
if (dpx->numElements == 0 || dpx->numElements >= max_elements) {
- if (verbose)
+ if (verbose) {
printf("DPX: Wrong number of elements: %d\n", dpx->numElements);
+ }
logImageClose(dpx);
return NULL;
}
@@ -214,8 +220,9 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf
dpx->height = swap_uint(header.imageHeader.lines_per_element, dpx->isMSB);
if (dpx->width == 0 || dpx->height == 0) {
- if (verbose)
+ if (verbose) {
printf("DPX: Wrong image dimension: %dx%d\n", dpx->width, dpx->height);
+ }
logImageClose(dpx);
return NULL;
}
@@ -262,8 +269,9 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf
}
if (dpx->depth == 0 || dpx->depth > 4) {
- if (verbose)
+ if (verbose) {
printf("DPX: Unsupported image depth: %d\n", dpx->depth);
+ }
logImageClose(dpx);
return NULL;
}
@@ -272,10 +280,11 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf
if (dpx->element[i].bitsPerSample != 1 && dpx->element[i].bitsPerSample != 8 &&
dpx->element[i].bitsPerSample != 10 && dpx->element[i].bitsPerSample != 12 &&
dpx->element[i].bitsPerSample != 16) {
- if (verbose)
+ if (verbose) {
printf("DPX: Unsupported bitsPerSample for elements %d: %d\n",
i,
dpx->element[i].bitsPerSample);
+ }
logImageClose(dpx);
return NULL;
}
@@ -284,20 +293,23 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf
dpx->element[i].packing = swap_ushort(header.imageHeader.element[i].packing, dpx->isMSB);
if (dpx->element[i].packing > 2) {
- if (verbose)
+ if (verbose) {
printf("DPX: Unsupported packing for element %d: %d\n", i, dpx->element[i].packing);
+ }
logImageClose(dpx);
return NULL;
}
/* Sometimes, the offset is not set correctly in the header */
dpx->element[i].dataOffset = swap_uint(header.imageHeader.element[i].data_offset, dpx->isMSB);
- if (dpx->element[i].dataOffset == 0 && dpx->numElements == 1)
+ if (dpx->element[i].dataOffset == 0 && dpx->numElements == 1) {
dpx->element[i].dataOffset = swap_uint(header.fileHeader.offset, dpx->isMSB);
+ }
if (dpx->element[i].dataOffset == 0) {
- if (verbose)
+ if (verbose) {
printf("DPX: Image header is corrupted.\n");
+ }
logImageClose(dpx);
return NULL;
}
@@ -321,23 +333,28 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf
case descriptor_RGB:
case descriptor_RGBA:
case descriptor_ABGR:
- if (dpx->element[i].refLowData == DPX_UNDEFINED_U32)
+ if (dpx->element[i].refLowData == DPX_UNDEFINED_U32) {
dpx->element[i].refLowData = 0;
+ }
- if (dpx->element[i].refHighData == DPX_UNDEFINED_U32)
+ if (dpx->element[i].refHighData == DPX_UNDEFINED_U32) {
dpx->element[i].refHighData = (unsigned int)dpx->element[i].maxValue;
+ }
if (dpx->element[i].refLowQuantity == DPX_UNDEFINED_R32 ||
- isnan(dpx->element[i].refLowQuantity))
+ isnan(dpx->element[i].refLowQuantity)) {
dpx->element[i].refLowQuantity = 0.0f;
+ }
if (dpx->element[i].refHighQuantity == DPX_UNDEFINED_R32 ||
isnan(dpx->element[i].refHighQuantity)) {
if (dpx->element[i].transfer == transfer_PrintingDensity ||
- dpx->element[i].transfer == transfer_Logarithmic)
+ dpx->element[i].transfer == transfer_Logarithmic) {
dpx->element[i].refHighQuantity = 2.048f;
- else
+ }
+ else {
dpx->element[i].refHighQuantity = dpx->element[i].maxValue;
+ }
}
break;
@@ -348,19 +365,23 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf
case descriptor_CbYCr:
case descriptor_CbYACrYA:
case descriptor_CbYCrA:
- if (dpx->element[i].refLowData == DPX_UNDEFINED_U32)
+ if (dpx->element[i].refLowData == DPX_UNDEFINED_U32) {
dpx->element[i].refLowData = 16.0f / 255.0f * dpx->element[i].maxValue;
+ }
- if (dpx->element[i].refHighData == DPX_UNDEFINED_U32)
+ if (dpx->element[i].refHighData == DPX_UNDEFINED_U32) {
dpx->element[i].refHighData = 235.0f / 255.0f * dpx->element[i].maxValue;
+ }
if (dpx->element[i].refLowQuantity == DPX_UNDEFINED_R32 ||
- isnan(dpx->element[i].refLowQuantity))
+ isnan(dpx->element[i].refLowQuantity)) {
dpx->element[i].refLowQuantity = 0.0f;
+ }
if (dpx->element[i].refHighQuantity == DPX_UNDEFINED_R32 ||
- isnan(dpx->element[i].refHighQuantity))
+ isnan(dpx->element[i].refHighQuantity)) {
dpx->element[i].refHighQuantity = 0.7f;
+ }
break;
@@ -425,8 +446,9 @@ LogImageFile *dpxCreate(const char *filename,
LogImageFile *dpx = (LogImageFile *)MEM_mallocN(sizeof(LogImageFile), __func__);
if (dpx == NULL) {
- if (verbose)
+ if (verbose) {
printf("DPX: Failed to malloc dpx file structure.\n");
+ }
return NULL;
}
@@ -451,8 +473,9 @@ LogImageFile *dpxCreate(const char *filename,
break;
default:
- if (verbose)
+ if (verbose) {
printf("DPX: bitsPerSample not supported: %d\n", bitsPerSample);
+ }
logImageClose(dpx);
return NULL;
}
@@ -481,32 +504,41 @@ LogImageFile *dpxCreate(const char *filename,
dpx->element[0].refLowData = 0;
dpx->element[0].refHighData = dpx->element[0].maxValue;
- if (referenceWhite > 0)
+ if (referenceWhite > 0) {
dpx->referenceWhite = referenceWhite;
- else
+ }
+ else {
dpx->referenceWhite = 685.0f / 1023.0f * dpx->element[0].maxValue;
+ }
- if (referenceBlack > 0)
+ if (referenceBlack > 0) {
dpx->referenceBlack = referenceBlack;
- else
+ }
+ else {
dpx->referenceBlack = 95.0f / 1023.0f * dpx->element[0].maxValue;
+ }
- if (gamma > 0.0f)
+ if (gamma > 0.0f) {
dpx->gamma = gamma;
- else
+ }
+ else {
dpx->gamma = 1.7f;
+ }
shortFilename = strrchr(filename, '/');
- if (shortFilename == NULL)
+ if (shortFilename == NULL) {
shortFilename = filename;
- else
+ }
+ else {
shortFilename++;
+ }
dpx->file = BLI_fopen(filename, "wb");
if (dpx->file == NULL) {
- if (verbose)
+ if (verbose) {
printf("DPX: Couldn't open file %s\n", filename);
+ }
logImageClose(dpx);
return NULL;
}
@@ -514,8 +546,9 @@ LogImageFile *dpxCreate(const char *filename,
fillDpxMainHeader(dpx, &header, shortFilename, creator);
if (fwrite(&header, sizeof(header), 1, dpx->file) == 0) {
- if (verbose)
+ if (verbose) {
printf("DPX: Couldn't write image header\n");
+ }
logImageClose(dpx);
return NULL;
}
@@ -524,8 +557,9 @@ LogImageFile *dpxCreate(const char *filename,
* 6044 = 8092 - sizeof(DpxMainHeader) */
memset(&pad, 0, 6044);
if (fwrite(&pad, 6044, 1, dpx->file) == 0) {
- if (verbose)
+ if (verbose) {
printf("DPX: Couldn't write image header\n");
+ }
logImageClose(dpx);
return NULL;
}
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) {
diff --git a/source/blender/imbuf/intern/cineon/logImageCore.h b/source/blender/imbuf/intern/cineon/logImageCore.h
index 3f09effa839..80e32ffe77e 100644
--- a/source/blender/imbuf/intern/cineon/logImageCore.h
+++ b/source/blender/imbuf/intern/cineon/logImageCore.h
@@ -213,18 +213,22 @@ int logImageGetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB
BLI_INLINE unsigned short swap_ushort(unsigned short x, int swap)
{
- if (swap != 0)
+ if (swap != 0) {
return (x >> 8) | (x << 8);
- else
+ }
+ else {
return x;
+ }
}
BLI_INLINE unsigned int swap_uint(unsigned int x, int swap)
{
- if (swap != 0)
+ if (swap != 0) {
return (x >> 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) | (x << 24);
- else
+ }
+ else {
return x;
+ }
}
BLI_INLINE float swap_float(float x, int swap)
@@ -242,40 +246,50 @@ BLI_INLINE float swap_float(float x, int swap)
dat2.b[3] = dat1.b[0];
return dat2.f;
}
- else
+ else {
return x;
+ }
}
/* Other */
BLI_INLINE unsigned int clamp_uint(unsigned int x, unsigned int low, unsigned int high)
{
- if (x > high)
+ if (x > high) {
return high;
- else if (x < low)
+ }
+ else if (x < low) {
return low;
- else
+ }
+ else {
return x;
+ }
}
BLI_INLINE float clamp_float(float x, float low, float high)
{
- if (x > high)
+ if (x > high) {
return high;
- else if (x < low)
+ }
+ else if (x < low) {
return low;
- else
+ }
+ else {
return x;
+ }
}
BLI_INLINE unsigned int float_uint(float value, unsigned int max)
{
- if (value < 0.0f)
+ if (value < 0.0f) {
return 0;
- else if (value > (1.0f - 0.5f / (float)max))
+ }
+ else if (value > (1.0f - 0.5f / (float)max)) {
return max;
- else
+ }
+ else {
return (unsigned int)(((float)max * value) + 0.5f);
+ }
}
#ifdef __cplusplus
diff --git a/source/blender/imbuf/intern/cineon/logmemfile.c b/source/blender/imbuf/intern/cineon/logmemfile.c
index d7ab2855ea3..91351d309de 100644
--- a/source/blender/imbuf/intern/cineon/logmemfile.c
+++ b/source/blender/imbuf/intern/cineon/logmemfile.c
@@ -31,23 +31,27 @@
int logimage_fseek(LogImageFile *logFile, intptr_t offset, int origin)
{
- if (logFile->file)
+ if (logFile->file) {
fseek(logFile->file, offset, origin);
+ }
else { /* we're seeking in memory */
if (origin == SEEK_SET) {
- if (offset > logFile->memBufferSize)
+ if (offset > logFile->memBufferSize) {
return 1;
+ }
logFile->memCursor = logFile->memBuffer + offset;
}
else if (origin == SEEK_END) {
- if (offset > logFile->memBufferSize)
+ if (offset > logFile->memBufferSize) {
return 1;
+ }
logFile->memCursor = (logFile->memBuffer + logFile->memBufferSize) - offset;
}
else if (origin == SEEK_CUR) {
uintptr_t pos = (uintptr_t)logFile->memCursor - (uintptr_t)logFile->memBuffer;
- if (pos + offset > logFile->memBufferSize)
+ if (pos + offset > logFile->memBufferSize) {
return 1;
+ }
logFile->memCursor += offset;
}
@@ -57,8 +61,9 @@ int logimage_fseek(LogImageFile *logFile, intptr_t offset, int origin)
int logimage_fwrite(void *buffer, size_t size, unsigned int count, LogImageFile *logFile)
{
- if (logFile->file)
+ if (logFile->file) {
return fwrite(buffer, size, count, logFile->file);
+ }
else { /* we're writing to memory */
/* do nothing as this isn't supported yet */
return count;
@@ -81,8 +86,9 @@ int logimage_fread(void *buffer, size_t size, unsigned int count, LogImageFile *
total_size = size * count;
}
- if (total_size != 0)
+ if (total_size != 0) {
memcpy(buf, logFile->memCursor, total_size);
+ }
return count;
}
@@ -91,8 +97,9 @@ int logimage_fread(void *buffer, size_t size, unsigned int count, LogImageFile *
int logimage_read_uchar(unsigned char *x, LogImageFile *logFile)
{
uintptr_t pos = (uintptr_t)logFile->memCursor - (uintptr_t)logFile->memBuffer;
- if (pos + sizeof(unsigned char) > logFile->memBufferSize)
+ if (pos + sizeof(unsigned char) > logFile->memBufferSize) {
return 1;
+ }
*x = *(unsigned char *)logFile->memCursor;
logFile->memCursor += sizeof(unsigned char);
@@ -102,8 +109,9 @@ int logimage_read_uchar(unsigned char *x, LogImageFile *logFile)
int logimage_read_ushort(unsigned short *x, LogImageFile *logFile)
{
uintptr_t pos = (uintptr_t)logFile->memCursor - (uintptr_t)logFile->memBuffer;
- if (pos + sizeof(unsigned short) > logFile->memBufferSize)
+ if (pos + sizeof(unsigned short) > logFile->memBufferSize) {
return 1;
+ }
*x = *(unsigned short *)logFile->memCursor;
logFile->memCursor += sizeof(unsigned short);
@@ -113,8 +121,9 @@ int logimage_read_ushort(unsigned short *x, LogImageFile *logFile)
int logimage_read_uint(unsigned int *x, LogImageFile *logFile)
{
uintptr_t pos = (uintptr_t)logFile->memCursor - (uintptr_t)logFile->memBuffer;
- if (pos + sizeof(unsigned int) > logFile->memBufferSize)
+ if (pos + sizeof(unsigned int) > logFile->memBufferSize) {
return 1;
+ }
*x = *(unsigned int *)logFile->memCursor;
logFile->memCursor += sizeof(unsigned int);