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-17 07:17:24 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-04-17 07:21:24 +0300
commite12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch)
tree8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/imbuf/intern/cineon
parentb3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff)
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211. For details on usage and instructions for migrating branches without conflicts, see: https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/imbuf/intern/cineon')
-rw-r--r--source/blender/imbuf/intern/cineon/CMakeLists.txt36
-rw-r--r--source/blender/imbuf/intern/cineon/cineon_dpx.c266
-rw-r--r--source/blender/imbuf/intern/cineon/cineonlib.c688
-rw-r--r--source/blender/imbuf/intern/cineon/cineonlib.h158
-rw-r--r--source/blender/imbuf/intern/cineon/dpxlib.c905
-rw-r--r--source/blender/imbuf/intern/cineon/dpxlib.h197
-rw-r--r--source/blender/imbuf/intern/cineon/logImageCore.c2650
-rw-r--r--source/blender/imbuf/intern/cineon/logImageCore.h248
-rw-r--r--source/blender/imbuf/intern/cineon/logmemfile.c131
-rw-r--r--source/blender/imbuf/intern/cineon/logmemfile.h3
10 files changed, 2774 insertions, 2508 deletions
diff --git a/source/blender/imbuf/intern/cineon/CMakeLists.txt b/source/blender/imbuf/intern/cineon/CMakeLists.txt
index 2f6ca2793e3..d740b080c35 100644
--- a/source/blender/imbuf/intern/cineon/CMakeLists.txt
+++ b/source/blender/imbuf/intern/cineon/CMakeLists.txt
@@ -19,13 +19,13 @@
# ***** END GPL LICENSE BLOCK *****
set(INC
- .
- ..
- ../..
- ../../../blenkernel
- ../../../blenlib
- ../../../makesdna
- ../../../../../intern/guardedalloc
+ .
+ ..
+ ../..
+ ../../../blenkernel
+ ../../../blenlib
+ ../../../makesdna
+ ../../../../../intern/guardedalloc
)
set(INC_SYS
@@ -33,23 +33,23 @@ set(INC_SYS
)
set(SRC
- cineonlib.h
- dpxlib.h
- logImageCore.h
- logmemfile.h
-
- cineon_dpx.c
- cineonlib.c
- dpxlib.c
- logImageCore.c
- logmemfile.c
+ cineonlib.h
+ dpxlib.h
+ logImageCore.h
+ logmemfile.h
+
+ cineon_dpx.c
+ cineonlib.c
+ dpxlib.c
+ logImageCore.c
+ logmemfile.c
)
set(LIB
)
if(WITH_IMAGE_CINEON)
- add_definitions(-DWITH_CINEON)
+ add_definitions(-DWITH_CINEON)
endif()
blender_add_lib(bf_imbuf_cineon "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
diff --git a/source/blender/imbuf/intern/cineon/cineon_dpx.c b/source/blender/imbuf/intern/cineon/cineon_dpx.c
index 2db7668c0ca..8f3829ee91e 100644
--- a/source/blender/imbuf/intern/cineon/cineon_dpx.c
+++ b/source/blender/imbuf/intern/cineon/cineon_dpx.c
@@ -20,7 +20,6 @@
* \ingroup imbcineon
*/
-
#include <stdio.h>
#include <string.h>
#include <math.h>
@@ -37,164 +36,183 @@
#include "MEM_guardedalloc.h"
-static struct ImBuf *imb_load_dpx_cineon(
- const unsigned char *mem, size_t size, int use_cineon, int flags,
- char colorspace[IM_MAX_SPACE])
+static struct ImBuf *imb_load_dpx_cineon(const unsigned char *mem,
+ size_t size,
+ int use_cineon,
+ int flags,
+ char colorspace[IM_MAX_SPACE])
{
- ImBuf *ibuf;
- LogImageFile *image;
- int width, height, depth;
+ ImBuf *ibuf;
+ LogImageFile *image;
+ int width, height, depth;
- colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_FLOAT);
+ colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_FLOAT);
- logImageSetVerbose((G.debug & G_DEBUG) ? 1 : 0);
+ logImageSetVerbose((G.debug & G_DEBUG) ? 1 : 0);
- image = logImageOpenFromMemory(mem, size);
+ image = logImageOpenFromMemory(mem, size);
- if (image == NULL) {
- printf("DPX/Cineon: error opening image.\n");
- return NULL;
- }
+ if (image == NULL) {
+ printf("DPX/Cineon: error opening image.\n");
+ return NULL;
+ }
- logImageGetSize(image, &width, &height, &depth);
+ logImageGetSize(image, &width, &height, &depth);
- ibuf = IMB_allocImBuf(width, height, 32, IB_rectfloat | flags);
- if (ibuf == NULL) {
- logImageClose(image);
- return NULL;
- }
+ ibuf = IMB_allocImBuf(width, height, 32, IB_rectfloat | flags);
+ if (ibuf == NULL) {
+ logImageClose(image);
+ return NULL;
+ }
- if (!(flags & IB_test)) {
- if (logImageGetDataRGBA(image, ibuf->rect_float, 1) != 0) {
- logImageClose(image);
- IMB_freeImBuf(ibuf);
- return NULL;
- }
- IMB_flipy(ibuf);
- }
+ if (!(flags & IB_test)) {
+ if (logImageGetDataRGBA(image, ibuf->rect_float, 1) != 0) {
+ logImageClose(image);
+ IMB_freeImBuf(ibuf);
+ return NULL;
+ }
+ IMB_flipy(ibuf);
+ }
- logImageClose(image);
- ibuf->ftype = use_cineon ? IMB_FTYPE_CINEON : IMB_FTYPE_DPX;
+ logImageClose(image);
+ ibuf->ftype = use_cineon ? IMB_FTYPE_CINEON : IMB_FTYPE_DPX;
- if (flags & IB_alphamode_detect)
- ibuf->flags |= IB_alphamode_premul;
+ if (flags & IB_alphamode_detect)
+ ibuf->flags |= IB_alphamode_premul;
- return ibuf;
+ return ibuf;
}
static int imb_save_dpx_cineon(ImBuf *ibuf, const char *filename, int use_cineon, int flags)
{
- LogImageFile *logImage;
- float *fbuf;
- float *fbuf_ptr;
- unsigned char *rect_ptr;
- int x, y, depth, bitspersample, rvalue;
-
- if (flags & IB_mem) {
- printf("DPX/Cineon: saving in memory is not supported.\n");
- return 0;
- }
-
- logImageSetVerbose((G.debug & G_DEBUG) ? 1 : 0);
-
- depth = (ibuf->planes + 7) >> 3;
- if (depth > 4 || depth < 3) {
- printf("DPX/Cineon: unsupported depth: %d for file: '%s'\n", depth, filename);
- return 0;
- }
-
- if (ibuf->foptions.flag & CINEON_10BIT)
- bitspersample = 10;
- else if (ibuf->foptions.flag & CINEON_12BIT)
- bitspersample = 12;
- else if (ibuf->foptions.flag & CINEON_16BIT)
- bitspersample = 16;
- else
- bitspersample = 8;
-
- logImage = logImageCreate(filename, use_cineon, ibuf->x, ibuf->y, bitspersample, (depth == 4),
- (ibuf->foptions.flag & CINEON_LOG), -1, -1, -1, "Blender");
-
- if (logImage == NULL) {
- printf("DPX/Cineon: error creating file.\n");
- return 0;
- }
-
- if (ibuf->rect_float != NULL && bitspersample != 8) {
- /* don't use the float buffer to save 8 bpp picture to prevent color banding
- * (there's no dithering algorithm behing the logImageSetDataRGBA function) */
-
- fbuf = (float *)MEM_mallocN(ibuf->x * ibuf->y * 4 * sizeof(float), "fbuf in imb_save_dpx_cineon");
-
- for (y = 0; y < ibuf->y; y++) {
- float *dst_ptr = fbuf + 4 * ((ibuf->y - y - 1) * ibuf->x);
- float *src_ptr = ibuf->rect_float + 4 * (y * ibuf->x);
-
- memcpy(dst_ptr, src_ptr, 4 * ibuf->x * sizeof(float));
- }
-
- rvalue = (logImageSetDataRGBA(logImage, fbuf, 1) == 0);
-
- MEM_freeN(fbuf);
- }
- else {
- 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");
- if (fbuf == NULL) {
- printf("DPX/Cineon: error allocating memory.\n");
- logImageClose(logImage);
- return 0;
- }
- for (y = 0; y < ibuf->y; y++) {
- for (x = 0; x < ibuf->x; x++) {
- fbuf_ptr = fbuf + 4 * ((ibuf->y - y - 1) * ibuf->x + x);
- rect_ptr = (unsigned char *)ibuf->rect + 4 * (y * ibuf->x + x);
- fbuf_ptr[0] = (float)rect_ptr[0] / 255.0f;
- fbuf_ptr[1] = (float)rect_ptr[1] / 255.0f;
- fbuf_ptr[2] = (float)rect_ptr[2] / 255.0f;
- fbuf_ptr[3] = (depth == 4) ? ((float)rect_ptr[3] / 255.0f) : 1.0f;
- }
- }
- rvalue = (logImageSetDataRGBA(logImage, fbuf, 0) == 0);
- MEM_freeN(fbuf);
- }
-
- logImageClose(logImage);
- return rvalue;
+ LogImageFile *logImage;
+ float *fbuf;
+ float *fbuf_ptr;
+ unsigned char *rect_ptr;
+ int x, y, depth, bitspersample, rvalue;
+
+ if (flags & IB_mem) {
+ printf("DPX/Cineon: saving in memory is not supported.\n");
+ return 0;
+ }
+
+ logImageSetVerbose((G.debug & G_DEBUG) ? 1 : 0);
+
+ depth = (ibuf->planes + 7) >> 3;
+ if (depth > 4 || depth < 3) {
+ printf("DPX/Cineon: unsupported depth: %d for file: '%s'\n", depth, filename);
+ return 0;
+ }
+
+ if (ibuf->foptions.flag & CINEON_10BIT)
+ bitspersample = 10;
+ else if (ibuf->foptions.flag & CINEON_12BIT)
+ bitspersample = 12;
+ else if (ibuf->foptions.flag & CINEON_16BIT)
+ bitspersample = 16;
+ else
+ bitspersample = 8;
+
+ logImage = logImageCreate(filename,
+ use_cineon,
+ ibuf->x,
+ ibuf->y,
+ bitspersample,
+ (depth == 4),
+ (ibuf->foptions.flag & CINEON_LOG),
+ -1,
+ -1,
+ -1,
+ "Blender");
+
+ if (logImage == NULL) {
+ printf("DPX/Cineon: error creating file.\n");
+ return 0;
+ }
+
+ if (ibuf->rect_float != NULL && bitspersample != 8) {
+ /* don't use the float buffer to save 8 bpp picture to prevent color banding
+ * (there's no dithering algorithm behing the logImageSetDataRGBA function) */
+
+ fbuf = (float *)MEM_mallocN(ibuf->x * ibuf->y * 4 * sizeof(float),
+ "fbuf in imb_save_dpx_cineon");
+
+ for (y = 0; y < ibuf->y; y++) {
+ float *dst_ptr = fbuf + 4 * ((ibuf->y - y - 1) * ibuf->x);
+ float *src_ptr = ibuf->rect_float + 4 * (y * ibuf->x);
+
+ memcpy(dst_ptr, src_ptr, 4 * ibuf->x * sizeof(float));
+ }
+
+ rvalue = (logImageSetDataRGBA(logImage, fbuf, 1) == 0);
+
+ MEM_freeN(fbuf);
+ }
+ else {
+ 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");
+ if (fbuf == NULL) {
+ printf("DPX/Cineon: error allocating memory.\n");
+ logImageClose(logImage);
+ return 0;
+ }
+ for (y = 0; y < ibuf->y; y++) {
+ for (x = 0; x < ibuf->x; x++) {
+ fbuf_ptr = fbuf + 4 * ((ibuf->y - y - 1) * ibuf->x + x);
+ rect_ptr = (unsigned char *)ibuf->rect + 4 * (y * ibuf->x + x);
+ fbuf_ptr[0] = (float)rect_ptr[0] / 255.0f;
+ fbuf_ptr[1] = (float)rect_ptr[1] / 255.0f;
+ fbuf_ptr[2] = (float)rect_ptr[2] / 255.0f;
+ fbuf_ptr[3] = (depth == 4) ? ((float)rect_ptr[3] / 255.0f) : 1.0f;
+ }
+ }
+ rvalue = (logImageSetDataRGBA(logImage, fbuf, 0) == 0);
+ MEM_freeN(fbuf);
+ }
+
+ logImageClose(logImage);
+ return rvalue;
}
int imb_save_cineon(struct ImBuf *buf, const char *myfile, int flags)
{
- return imb_save_dpx_cineon(buf, myfile, 1, flags);
+ return imb_save_dpx_cineon(buf, myfile, 1, flags);
}
int imb_is_cineon(const unsigned char *buf)
{
- return logImageIsCineon(buf);
+ return logImageIsCineon(buf);
}
-ImBuf *imb_load_cineon(const unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
+ImBuf *imb_load_cineon(const unsigned char *mem,
+ size_t size,
+ int flags,
+ char colorspace[IM_MAX_SPACE])
{
- if (imb_is_cineon(mem))
- return imb_load_dpx_cineon(mem, size, 1, flags, colorspace);
- return NULL;
+ if (imb_is_cineon(mem))
+ return imb_load_dpx_cineon(mem, size, 1, flags, colorspace);
+ return NULL;
}
int imb_save_dpx(struct ImBuf *buf, const char *myfile, int flags)
{
- return imb_save_dpx_cineon(buf, myfile, 0, flags);
+ return imb_save_dpx_cineon(buf, myfile, 0, flags);
}
int imb_is_dpx(const unsigned char *buf)
{
- return logImageIsDpx(buf);
+ return logImageIsDpx(buf);
}
-ImBuf *imb_load_dpx(const unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
+ImBuf *imb_load_dpx(const unsigned char *mem,
+ size_t size,
+ int flags,
+ char colorspace[IM_MAX_SPACE])
{
- if (imb_is_dpx(mem))
- return imb_load_dpx_cineon(mem, size, 0, flags, colorspace);
- return NULL;
+ 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 14389a566fd..79f419e747c 100644
--- a/source/blender/imbuf/intern/cineon/cineonlib.c
+++ b/source/blender/imbuf/intern/cineon/cineonlib.c
@@ -22,7 +22,6 @@
* Cineon image file format library routines.
*/
-
#include "cineonlib.h"
#include "logmemfile.h"
@@ -46,342 +45,373 @@ static int verbose = 0;
void cineonSetVerbose(int verbosity)
{
- verbose = verbosity;
+ verbose = verbosity;
}
-static void fillCineonMainHeader(LogImageFile *cineon, CineonMainHeader *header,
- const char *filename, const char *creator)
+static void fillCineonMainHeader(LogImageFile *cineon,
+ CineonMainHeader *header,
+ const char *filename,
+ const char *creator)
{
- time_t fileClock;
- struct tm *fileTime;
- int i;
-
- memset(header, 0, sizeof(CineonMainHeader));
-
- /* --- File header --- */
- header->fileHeader.magic_num = swap_uint(CINEON_FILE_MAGIC, cineon->isMSB);
- header->fileHeader.offset = swap_uint(cineon->element[0].dataOffset, cineon->isMSB);
- header->fileHeader.gen_hdr_size = swap_uint(sizeof(CineonFileHeader) + sizeof(CineonImageHeader) +
- sizeof(CineonOriginationHeader), cineon->isMSB);
- header->fileHeader.ind_hdr_size = 0;
- header->fileHeader.user_data_size = 0;
- header->fileHeader.file_size = swap_uint(cineon->element[0].dataOffset + cineon->height * getRowLength(cineon->width, cineon->element[0]), cineon->isMSB);
- strcpy(header->fileHeader.version, "v4.5");
- strncpy(header->fileHeader.file_name, filename, 99);
- header->fileHeader.file_name[99] = 0;
- fileClock = time(NULL);
- fileTime = localtime(&fileClock);
- strftime(header->fileHeader.creation_date, 12, "%Y:%m:%d", fileTime);
- strftime(header->fileHeader.creation_time, 12, "%H:%M:%S%Z", fileTime);
- header->fileHeader.creation_time[11] = 0;
-
- /* --- Image header --- */
- header->imageHeader.orientation = 0;
- header->imageHeader.elements_per_image = cineon->depth;
-
- for (i = 0; i < 3; i++) {
- header->imageHeader.element[i].descriptor1 = 0;
- header->imageHeader.element[i].descriptor2 = i;
- header->imageHeader.element[i].bits_per_sample = cineon->element[0].bitsPerSample;
- header->imageHeader.element[i].pixels_per_line = swap_uint(cineon->width, cineon->isMSB);
- header->imageHeader.element[i].lines_per_image = swap_uint(cineon->height, cineon->isMSB);
- header->imageHeader.element[i].ref_low_data = swap_uint(cineon->element[0].refLowData, cineon->isMSB);
- header->imageHeader.element[i].ref_low_quantity = swap_float(cineon->element[0].refLowQuantity, cineon->isMSB);
- header->imageHeader.element[i].ref_high_data = swap_uint(cineon->element[0].refHighData, cineon->isMSB);
- header->imageHeader.element[i].ref_high_quantity = swap_float(cineon->element[0].refHighQuantity, cineon->isMSB);
- }
-
- header->imageHeader.white_point_x = swap_float(0.0f, cineon->isMSB);
- header->imageHeader.white_point_y = swap_float(0.0f, cineon->isMSB);
- header->imageHeader.red_primary_x = swap_float(0.0f, cineon->isMSB);
- header->imageHeader.red_primary_y = swap_float(0.0f, cineon->isMSB);
- header->imageHeader.green_primary_x = swap_float(0.0f, cineon->isMSB);
- header->imageHeader.green_primary_y = swap_float(0.0f, cineon->isMSB);
- header->imageHeader.blue_primary_x = swap_float(0.0f, cineon->isMSB);
- header->imageHeader.blue_primary_y = swap_float(0.0f, cineon->isMSB);
- strncpy(header->imageHeader.label, creator, 199);
- header->imageHeader.label[199] = 0;
- header->imageHeader.interleave = 0;
- header->imageHeader.data_sign = 0;
- header->imageHeader.sense = 0;
- header->imageHeader.line_padding = swap_uint(0, cineon->isMSB);
- header->imageHeader.element_padding = swap_uint(0, cineon->isMSB);
-
- switch (cineon->element[0].packing) {
- case 0:
- header->imageHeader.packing = 0;
- break;
-
- case 1:
- header->imageHeader.packing = 5;
- break;
-
- case 2:
- header->imageHeader.packing = 6;
- break;
- }
-
- /* --- Origination header --- */
- /* we leave it blank */
-
- /* --- Film header --- */
- /* we leave it blank */
+ time_t fileClock;
+ struct tm *fileTime;
+ int i;
+
+ memset(header, 0, sizeof(CineonMainHeader));
+
+ /* --- File header --- */
+ header->fileHeader.magic_num = swap_uint(CINEON_FILE_MAGIC, cineon->isMSB);
+ header->fileHeader.offset = swap_uint(cineon->element[0].dataOffset, cineon->isMSB);
+ header->fileHeader.gen_hdr_size = swap_uint(
+ sizeof(CineonFileHeader) + sizeof(CineonImageHeader) + sizeof(CineonOriginationHeader),
+ cineon->isMSB);
+ header->fileHeader.ind_hdr_size = 0;
+ header->fileHeader.user_data_size = 0;
+ header->fileHeader.file_size = swap_uint(cineon->element[0].dataOffset +
+ cineon->height *
+ getRowLength(cineon->width, cineon->element[0]),
+ cineon->isMSB);
+ strcpy(header->fileHeader.version, "v4.5");
+ strncpy(header->fileHeader.file_name, filename, 99);
+ header->fileHeader.file_name[99] = 0;
+ fileClock = time(NULL);
+ fileTime = localtime(&fileClock);
+ strftime(header->fileHeader.creation_date, 12, "%Y:%m:%d", fileTime);
+ strftime(header->fileHeader.creation_time, 12, "%H:%M:%S%Z", fileTime);
+ header->fileHeader.creation_time[11] = 0;
+
+ /* --- Image header --- */
+ header->imageHeader.orientation = 0;
+ header->imageHeader.elements_per_image = cineon->depth;
+
+ for (i = 0; i < 3; i++) {
+ header->imageHeader.element[i].descriptor1 = 0;
+ header->imageHeader.element[i].descriptor2 = i;
+ header->imageHeader.element[i].bits_per_sample = cineon->element[0].bitsPerSample;
+ header->imageHeader.element[i].pixels_per_line = swap_uint(cineon->width, cineon->isMSB);
+ header->imageHeader.element[i].lines_per_image = swap_uint(cineon->height, cineon->isMSB);
+ header->imageHeader.element[i].ref_low_data = swap_uint(cineon->element[0].refLowData,
+ cineon->isMSB);
+ header->imageHeader.element[i].ref_low_quantity = swap_float(cineon->element[0].refLowQuantity,
+ cineon->isMSB);
+ header->imageHeader.element[i].ref_high_data = swap_uint(cineon->element[0].refHighData,
+ cineon->isMSB);
+ header->imageHeader.element[i].ref_high_quantity = swap_float(
+ cineon->element[0].refHighQuantity, cineon->isMSB);
+ }
+
+ header->imageHeader.white_point_x = swap_float(0.0f, cineon->isMSB);
+ header->imageHeader.white_point_y = swap_float(0.0f, cineon->isMSB);
+ header->imageHeader.red_primary_x = swap_float(0.0f, cineon->isMSB);
+ header->imageHeader.red_primary_y = swap_float(0.0f, cineon->isMSB);
+ header->imageHeader.green_primary_x = swap_float(0.0f, cineon->isMSB);
+ header->imageHeader.green_primary_y = swap_float(0.0f, cineon->isMSB);
+ header->imageHeader.blue_primary_x = swap_float(0.0f, cineon->isMSB);
+ header->imageHeader.blue_primary_y = swap_float(0.0f, cineon->isMSB);
+ strncpy(header->imageHeader.label, creator, 199);
+ header->imageHeader.label[199] = 0;
+ header->imageHeader.interleave = 0;
+ header->imageHeader.data_sign = 0;
+ header->imageHeader.sense = 0;
+ header->imageHeader.line_padding = swap_uint(0, cineon->isMSB);
+ header->imageHeader.element_padding = swap_uint(0, cineon->isMSB);
+
+ switch (cineon->element[0].packing) {
+ case 0:
+ header->imageHeader.packing = 0;
+ break;
+
+ case 1:
+ header->imageHeader.packing = 5;
+ break;
+
+ case 2:
+ header->imageHeader.packing = 6;
+ break;
+ }
+
+ /* --- Origination header --- */
+ /* we leave it blank */
+
+ /* --- Film header --- */
+ /* we leave it blank */
}
LogImageFile *cineonOpen(const unsigned char *byteStuff, int fromMemory, size_t bufferSize)
{
- CineonMainHeader header;
- LogImageFile *cineon = (LogImageFile *)MEM_mallocN(sizeof(LogImageFile), __func__);
- const char *filename = (const char *)byteStuff;
- int i;
- unsigned int dataOffset;
-
- if (cineon == NULL) {
- if (verbose) printf("Cineon: Failed to malloc cineon file structure.\n");
- return NULL;
- }
-
- /* zero the header */
- memset(&header, 0, sizeof(CineonMainHeader));
-
- /* for close routine */
- cineon->file = NULL;
-
- if (fromMemory == 0) {
- /* byteStuff is then the filename */
- cineon->file = BLI_fopen(filename, "rb");
- if (cineon->file == NULL) {
- if (verbose) printf("Cineon: Failed to open file \"%s\".\n", filename);
- logImageClose(cineon);
- return NULL;
- }
- /* not used in this case */
- cineon->memBuffer = NULL;
- cineon->memCursor = NULL;
- cineon->memBufferSize = 0;
- }
- else {
- cineon->memBuffer = (unsigned char *)byteStuff;
- cineon->memCursor = (unsigned char *)byteStuff;
- cineon->memBufferSize = bufferSize;
- }
-
- if (logimage_fread(&header, sizeof(header), 1, cineon) == 0) {
- if (verbose) printf("Cineon: Not enough data for header in \"%s\".\n", byteStuff);
- logImageClose(cineon);
- return NULL;
- }
-
- /* endianness determination */
- if (header.fileHeader.magic_num == swap_uint(CINEON_FILE_MAGIC, 1)) {
- cineon->isMSB = 1;
- if (verbose) printf("Cineon: File is MSB.\n");
- }
- else if (header.fileHeader.magic_num == CINEON_FILE_MAGIC) {
- cineon->isMSB = 0;
- if (verbose) printf("Cineon: File is LSB.\n");
- }
- else {
- if (verbose) {
- printf("Cineon: Bad magic number %lu in \"%s\".\n",
- (unsigned long)header.fileHeader.magic_num, byteStuff);
- }
- logImageClose(cineon);
- return NULL;
- }
-
- cineon->width = swap_uint(header.imageHeader.element[0].pixels_per_line, cineon->isMSB);
- cineon->height = swap_uint(header.imageHeader.element[0].lines_per_image, cineon->isMSB);
-
- if (cineon->width == 0 || cineon->height == 0) {
- if (verbose) printf("Cineon: Wrong image dimension: %dx%d\n", cineon->width, cineon->height);
- logImageClose(cineon);
- return NULL;
- }
-
- cineon->depth = header.imageHeader.elements_per_image;
- cineon->srcFormat = format_Cineon;
-
- if (header.imageHeader.interleave == 0)
- cineon->numElements = 1;
- else if (header.imageHeader.interleave == 2)
- cineon->numElements = header.imageHeader.elements_per_image;
- else {
- if (verbose) printf("Cineon: Data interleave not supported: %d\n", header.imageHeader.interleave);
- logImageClose(cineon);
- return NULL;
- }
-
- if (cineon->depth == 1) {
- /* Grayscale image */
- cineon->element[0].descriptor = descriptor_Luminance;
- cineon->element[0].transfer = transfer_Linear;
- cineon->element[0].depth = 1;
- }
- else if (cineon->depth == 3) {
- /* RGB image */
- if (cineon->numElements == 1) {
- cineon->element[0].descriptor = descriptor_RGB;
- cineon->element[0].transfer = transfer_PrintingDensity;
- cineon->element[0].depth = 3;
- }
- else if (cineon->numElements == 3) {
- cineon->element[0].descriptor = descriptor_Red;
- cineon->element[0].transfer = transfer_PrintingDensity;
- cineon->element[0].depth = 1;
- cineon->element[1].descriptor = descriptor_Green;
- cineon->element[1].transfer = transfer_PrintingDensity;
- cineon->element[1].depth = 1;
- cineon->element[2].descriptor = descriptor_Blue;
- cineon->element[2].transfer = transfer_PrintingDensity;
- cineon->element[2].depth = 1;
- }
- }
- else {
- if (verbose) printf("Cineon: Cineon image depth unsupported: %d\n", cineon->depth);
- logImageClose(cineon);
- return NULL;
- }
-
- dataOffset = swap_uint(header.fileHeader.offset, cineon->isMSB);
-
- for (i = 0; i < cineon->numElements; i++) {
- cineon->element[i].bitsPerSample = header.imageHeader.element[i].bits_per_sample;
- cineon->element[i].maxValue = powf(2, cineon->element[i].bitsPerSample) - 1.0f;
- cineon->element[i].refLowData = swap_uint(header.imageHeader.element[i].ref_low_data, cineon->isMSB);
- cineon->element[i].refLowQuantity = swap_float(header.imageHeader.element[i].ref_low_quantity, cineon->isMSB);
- cineon->element[i].refHighData = swap_uint(header.imageHeader.element[i].ref_high_data, cineon->isMSB);
- cineon->element[i].refHighQuantity = swap_float(header.imageHeader.element[i].ref_high_quantity, cineon->isMSB);
-
- switch (header.imageHeader.packing) {
- case 0:
- cineon->element[i].packing = 0;
- break;
-
- case 5:
- cineon->element[i].packing = 1;
- break;
-
- case 6:
- cineon->element[i].packing = 2;
- break;
-
- default:
- /* Not supported */
- if (verbose) printf("Cineon: packing unsupported: %d\n", header.imageHeader.packing);
- logImageClose(cineon);
- return NULL;
- }
-
- if (cineon->element[i].refLowData == CINEON_UNDEFINED_U32)
- cineon->element[i].refLowData = 0;
-
- 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))
- 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)
- cineon->element[i].refHighQuantity = 2.048f;
- else
- cineon->element[i].refHighQuantity = cineon->element[i].maxValue;
- }
-
- cineon->element[i].dataOffset = dataOffset;
- dataOffset += cineon->height * getRowLength(cineon->width, cineon->element[i]);
- }
-
- cineon->referenceBlack = 95.0f / 1023.0f * cineon->element[0].maxValue;
- cineon->referenceWhite = 685.0f / 1023.0f * cineon->element[0].maxValue;
- cineon->gamma = 1.7f;
-
- if (verbose) {
- printf("size %d x %d x %d elements\n", cineon->width, cineon->height, cineon->numElements);
- for (i = 0; i < cineon->numElements; i++) {
- printf(" Element %d:\n", i);
- printf(" Bits per sample: %d\n", cineon->element[i].bitsPerSample);
- printf(" Depth: %d\n", cineon->element[i].depth);
- printf(" Transfer characteristics: %d\n", cineon->element[i].transfer);
- printf(" Packing: %d\n", cineon->element[i].packing);
- printf(" Descriptor: %d\n", cineon->element[i].descriptor);
- printf(" Data offset: %d\n", cineon->element[i].dataOffset);
- printf(" Reference low data: %u\n", cineon->element[i].refLowData);
- printf(" Reference low quantity: %f\n", cineon->element[i].refLowQuantity);
- printf(" Reference high data: %u\n", cineon->element[i].refHighData);
- printf(" Reference high quantity: %f\n", cineon->element[i].refHighQuantity);
- printf("\n");
- }
-
- printf("Gamma: %f\n", cineon->gamma);
- printf("Reference black: %f\n", cineon->referenceBlack);
- printf("Reference white: %f\n", cineon->referenceWhite);
- printf("Orientation: %d\n", header.imageHeader.orientation);
- printf("----------------------------\n");
- }
- return cineon;
+ CineonMainHeader header;
+ LogImageFile *cineon = (LogImageFile *)MEM_mallocN(sizeof(LogImageFile), __func__);
+ const char *filename = (const char *)byteStuff;
+ int i;
+ unsigned int dataOffset;
+
+ if (cineon == NULL) {
+ if (verbose)
+ printf("Cineon: Failed to malloc cineon file structure.\n");
+ return NULL;
+ }
+
+ /* zero the header */
+ memset(&header, 0, sizeof(CineonMainHeader));
+
+ /* for close routine */
+ cineon->file = NULL;
+
+ if (fromMemory == 0) {
+ /* byteStuff is then the filename */
+ cineon->file = BLI_fopen(filename, "rb");
+ if (cineon->file == NULL) {
+ if (verbose)
+ printf("Cineon: Failed to open file \"%s\".\n", filename);
+ logImageClose(cineon);
+ return NULL;
+ }
+ /* not used in this case */
+ cineon->memBuffer = NULL;
+ cineon->memCursor = NULL;
+ cineon->memBufferSize = 0;
+ }
+ else {
+ cineon->memBuffer = (unsigned char *)byteStuff;
+ cineon->memCursor = (unsigned char *)byteStuff;
+ cineon->memBufferSize = bufferSize;
+ }
+
+ if (logimage_fread(&header, sizeof(header), 1, cineon) == 0) {
+ if (verbose)
+ printf("Cineon: Not enough data for header in \"%s\".\n", byteStuff);
+ logImageClose(cineon);
+ return NULL;
+ }
+
+ /* endianness determination */
+ if (header.fileHeader.magic_num == swap_uint(CINEON_FILE_MAGIC, 1)) {
+ cineon->isMSB = 1;
+ if (verbose)
+ printf("Cineon: File is MSB.\n");
+ }
+ else if (header.fileHeader.magic_num == CINEON_FILE_MAGIC) {
+ cineon->isMSB = 0;
+ if (verbose)
+ printf("Cineon: File is LSB.\n");
+ }
+ else {
+ if (verbose) {
+ printf("Cineon: Bad magic number %lu in \"%s\".\n",
+ (unsigned long)header.fileHeader.magic_num,
+ byteStuff);
+ }
+ logImageClose(cineon);
+ return NULL;
+ }
+
+ cineon->width = swap_uint(header.imageHeader.element[0].pixels_per_line, cineon->isMSB);
+ cineon->height = swap_uint(header.imageHeader.element[0].lines_per_image, cineon->isMSB);
+
+ if (cineon->width == 0 || cineon->height == 0) {
+ if (verbose)
+ printf("Cineon: Wrong image dimension: %dx%d\n", cineon->width, cineon->height);
+ logImageClose(cineon);
+ return NULL;
+ }
+
+ cineon->depth = header.imageHeader.elements_per_image;
+ cineon->srcFormat = format_Cineon;
+
+ if (header.imageHeader.interleave == 0)
+ cineon->numElements = 1;
+ else if (header.imageHeader.interleave == 2)
+ cineon->numElements = header.imageHeader.elements_per_image;
+ else {
+ if (verbose)
+ printf("Cineon: Data interleave not supported: %d\n", header.imageHeader.interleave);
+ logImageClose(cineon);
+ return NULL;
+ }
+
+ if (cineon->depth == 1) {
+ /* Grayscale image */
+ cineon->element[0].descriptor = descriptor_Luminance;
+ cineon->element[0].transfer = transfer_Linear;
+ cineon->element[0].depth = 1;
+ }
+ else if (cineon->depth == 3) {
+ /* RGB image */
+ if (cineon->numElements == 1) {
+ cineon->element[0].descriptor = descriptor_RGB;
+ cineon->element[0].transfer = transfer_PrintingDensity;
+ cineon->element[0].depth = 3;
+ }
+ else if (cineon->numElements == 3) {
+ cineon->element[0].descriptor = descriptor_Red;
+ cineon->element[0].transfer = transfer_PrintingDensity;
+ cineon->element[0].depth = 1;
+ cineon->element[1].descriptor = descriptor_Green;
+ cineon->element[1].transfer = transfer_PrintingDensity;
+ cineon->element[1].depth = 1;
+ cineon->element[2].descriptor = descriptor_Blue;
+ cineon->element[2].transfer = transfer_PrintingDensity;
+ cineon->element[2].depth = 1;
+ }
+ }
+ else {
+ if (verbose)
+ printf("Cineon: Cineon image depth unsupported: %d\n", cineon->depth);
+ logImageClose(cineon);
+ return NULL;
+ }
+
+ dataOffset = swap_uint(header.fileHeader.offset, cineon->isMSB);
+
+ for (i = 0; i < cineon->numElements; i++) {
+ cineon->element[i].bitsPerSample = header.imageHeader.element[i].bits_per_sample;
+ cineon->element[i].maxValue = powf(2, cineon->element[i].bitsPerSample) - 1.0f;
+ cineon->element[i].refLowData = swap_uint(header.imageHeader.element[i].ref_low_data,
+ cineon->isMSB);
+ cineon->element[i].refLowQuantity = swap_float(header.imageHeader.element[i].ref_low_quantity,
+ cineon->isMSB);
+ cineon->element[i].refHighData = swap_uint(header.imageHeader.element[i].ref_high_data,
+ cineon->isMSB);
+ cineon->element[i].refHighQuantity = swap_float(
+ header.imageHeader.element[i].ref_high_quantity, cineon->isMSB);
+
+ switch (header.imageHeader.packing) {
+ case 0:
+ cineon->element[i].packing = 0;
+ break;
+
+ case 5:
+ cineon->element[i].packing = 1;
+ break;
+
+ case 6:
+ cineon->element[i].packing = 2;
+ break;
+
+ default:
+ /* Not supported */
+ if (verbose)
+ printf("Cineon: packing unsupported: %d\n", header.imageHeader.packing);
+ logImageClose(cineon);
+ return NULL;
+ }
+
+ if (cineon->element[i].refLowData == CINEON_UNDEFINED_U32)
+ cineon->element[i].refLowData = 0;
+
+ 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))
+ 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)
+ cineon->element[i].refHighQuantity = 2.048f;
+ else
+ cineon->element[i].refHighQuantity = cineon->element[i].maxValue;
+ }
+
+ cineon->element[i].dataOffset = dataOffset;
+ dataOffset += cineon->height * getRowLength(cineon->width, cineon->element[i]);
+ }
+
+ cineon->referenceBlack = 95.0f / 1023.0f * cineon->element[0].maxValue;
+ cineon->referenceWhite = 685.0f / 1023.0f * cineon->element[0].maxValue;
+ cineon->gamma = 1.7f;
+
+ if (verbose) {
+ printf("size %d x %d x %d elements\n", cineon->width, cineon->height, cineon->numElements);
+ for (i = 0; i < cineon->numElements; i++) {
+ printf(" Element %d:\n", i);
+ printf(" Bits per sample: %d\n", cineon->element[i].bitsPerSample);
+ printf(" Depth: %d\n", cineon->element[i].depth);
+ printf(" Transfer characteristics: %d\n", cineon->element[i].transfer);
+ printf(" Packing: %d\n", cineon->element[i].packing);
+ printf(" Descriptor: %d\n", cineon->element[i].descriptor);
+ printf(" Data offset: %d\n", cineon->element[i].dataOffset);
+ printf(" Reference low data: %u\n", cineon->element[i].refLowData);
+ printf(" Reference low quantity: %f\n", cineon->element[i].refLowQuantity);
+ printf(" Reference high data: %u\n", cineon->element[i].refHighData);
+ printf(" Reference high quantity: %f\n", cineon->element[i].refHighQuantity);
+ printf("\n");
+ }
+
+ printf("Gamma: %f\n", cineon->gamma);
+ printf("Reference black: %f\n", cineon->referenceBlack);
+ printf("Reference white: %f\n", cineon->referenceWhite);
+ printf("Orientation: %d\n", header.imageHeader.orientation);
+ printf("----------------------------\n");
+ }
+ return cineon;
}
-LogImageFile *cineonCreate(const char *filename, int width, int height, int bitsPerSample, const char *creator)
+LogImageFile *cineonCreate(
+ const char *filename, int width, int height, int bitsPerSample, const char *creator)
{
- CineonMainHeader header;
- const char *shortFilename = NULL;
- /* unsigned char pad[6044]; */
-
- LogImageFile *cineon = (LogImageFile *)MEM_mallocN(sizeof(LogImageFile), __func__);
- if (cineon == NULL) {
- if (verbose) printf("cineon: Failed to malloc cineon file structure.\n");
- return NULL;
- }
-
- /* Only 10 bits Cineon are supported */
- if (bitsPerSample != 10) {
- if (verbose) printf("cineon: Only 10 bits Cineon are supported.\n");
- logImageClose(cineon);
- return NULL;
- }
-
- cineon->width = width;
- cineon->height = height;
- cineon->element[0].bitsPerSample = 10;
- cineon->element[0].dataOffset = sizeof(CineonMainHeader);
- cineon->element[0].maxValue = 1023;
- cineon->isMSB = 1;
- cineon->numElements = 1;
- cineon->element[0].packing = 1;
- cineon->depth = 3;
- cineon->element[0].depth = 3;
- cineon->element[0].descriptor = descriptor_RGB;
- cineon->element[0].transfer = transfer_PrintingDensity;
- cineon->element[0].refHighQuantity = 2.048f;
- cineon->element[0].refLowQuantity = 0;
- cineon->element[0].refLowData = 0;
- cineon->element[0].refHighData = cineon->element[0].maxValue;
- cineon->referenceWhite = 685.0f;
- cineon->referenceBlack = 95.0f;
- cineon->gamma = 1.7f;
-
- shortFilename = strrchr(filename, '/');
- if (shortFilename == NULL)
- shortFilename = filename;
- else
- shortFilename++;
-
- cineon->file = BLI_fopen(filename, "wb");
- if (cineon->file == NULL) {
- if (verbose) printf("cineon: Couldn't open file %s\n", filename);
- logImageClose(cineon);
- return NULL;
- }
-
- fillCineonMainHeader(cineon, &header, shortFilename, creator);
-
- if (fwrite(&header, sizeof(header), 1, cineon->file) == 0) {
- if (verbose) printf("cineon: Couldn't write image header\n");
- logImageClose(cineon);
- return NULL;
- }
-
- return cineon;
+ CineonMainHeader header;
+ const char *shortFilename = NULL;
+ /* unsigned char pad[6044]; */
+
+ LogImageFile *cineon = (LogImageFile *)MEM_mallocN(sizeof(LogImageFile), __func__);
+ if (cineon == NULL) {
+ if (verbose)
+ printf("cineon: Failed to malloc cineon file structure.\n");
+ return NULL;
+ }
+
+ /* Only 10 bits Cineon are supported */
+ if (bitsPerSample != 10) {
+ if (verbose)
+ printf("cineon: Only 10 bits Cineon are supported.\n");
+ logImageClose(cineon);
+ return NULL;
+ }
+
+ cineon->width = width;
+ cineon->height = height;
+ cineon->element[0].bitsPerSample = 10;
+ cineon->element[0].dataOffset = sizeof(CineonMainHeader);
+ cineon->element[0].maxValue = 1023;
+ cineon->isMSB = 1;
+ cineon->numElements = 1;
+ cineon->element[0].packing = 1;
+ cineon->depth = 3;
+ cineon->element[0].depth = 3;
+ cineon->element[0].descriptor = descriptor_RGB;
+ cineon->element[0].transfer = transfer_PrintingDensity;
+ cineon->element[0].refHighQuantity = 2.048f;
+ cineon->element[0].refLowQuantity = 0;
+ cineon->element[0].refLowData = 0;
+ cineon->element[0].refHighData = cineon->element[0].maxValue;
+ cineon->referenceWhite = 685.0f;
+ cineon->referenceBlack = 95.0f;
+ cineon->gamma = 1.7f;
+
+ shortFilename = strrchr(filename, '/');
+ if (shortFilename == NULL)
+ shortFilename = filename;
+ else
+ shortFilename++;
+
+ cineon->file = BLI_fopen(filename, "wb");
+ if (cineon->file == NULL) {
+ if (verbose)
+ printf("cineon: Couldn't open file %s\n", filename);
+ logImageClose(cineon);
+ return NULL;
+ }
+
+ fillCineonMainHeader(cineon, &header, shortFilename, creator);
+
+ if (fwrite(&header, sizeof(header), 1, cineon->file) == 0) {
+ if (verbose)
+ printf("cineon: Couldn't write image header\n");
+ logImageClose(cineon);
+ return NULL;
+ }
+
+ return cineon;
}
diff --git a/source/blender/imbuf/intern/cineon/cineonlib.h b/source/blender/imbuf/intern/cineon/cineonlib.h
index fddef8e658f..461407fcf25 100644
--- a/source/blender/imbuf/intern/cineon/cineonlib.h
+++ b/source/blender/imbuf/intern/cineon/cineonlib.h
@@ -23,7 +23,6 @@
* Also handles DPX files (almost)
*/
-
#ifndef __CINEONLIB_H__
#define __CINEONLIB_H__
@@ -33,107 +32,108 @@ extern "C" {
#include "logImageCore.h"
-#define CINEON_FILE_MAGIC 0x802A5FD7
-#define CINEON_UNDEFINED_U8 0xFF
-#define CINEON_UNDEFINED_U16 0xFFFF
-#define CINEON_UNDEFINED_U32 0xFFFFFFFF
-#define CINEON_UNDEFINED_R32 0x7F800000
-#define CINEON_UNDEFINED_CHAR 0
+#define CINEON_FILE_MAGIC 0x802A5FD7
+#define CINEON_UNDEFINED_U8 0xFF
+#define CINEON_UNDEFINED_U16 0xFFFF
+#define CINEON_UNDEFINED_U32 0xFFFFFFFF
+#define CINEON_UNDEFINED_R32 0x7F800000
+#define CINEON_UNDEFINED_CHAR 0
typedef struct {
- unsigned int magic_num;
- unsigned int offset;
- unsigned int gen_hdr_size;
- unsigned int ind_hdr_size;
- unsigned int user_data_size;
- unsigned int file_size;
- char version[8];
- char file_name[100];
- char creation_date[12];
- char creation_time[12];
- char reserved[36];
+ unsigned int magic_num;
+ unsigned int offset;
+ unsigned int gen_hdr_size;
+ unsigned int ind_hdr_size;
+ unsigned int user_data_size;
+ unsigned int file_size;
+ char version[8];
+ char file_name[100];
+ char creation_date[12];
+ char creation_time[12];
+ char reserved[36];
} CineonFileHeader;
typedef struct {
- unsigned char descriptor1;
- unsigned char descriptor2;
- unsigned char bits_per_sample;
- unsigned char filler;
- unsigned int pixels_per_line;
- unsigned int lines_per_image;
- unsigned int ref_low_data;
- float ref_low_quantity;
- unsigned int ref_high_data;
- float ref_high_quantity;
+ unsigned char descriptor1;
+ unsigned char descriptor2;
+ unsigned char bits_per_sample;
+ unsigned char filler;
+ unsigned int pixels_per_line;
+ unsigned int lines_per_image;
+ unsigned int ref_low_data;
+ float ref_low_quantity;
+ unsigned int ref_high_data;
+ float ref_high_quantity;
} CineonElementHeader;
typedef struct {
- unsigned char orientation;
- unsigned char elements_per_image;
- unsigned short filler;
- CineonElementHeader element[8];
- float white_point_x;
- float white_point_y;
- float red_primary_x;
- float red_primary_y;
- float green_primary_x;
- float green_primary_y;
- float blue_primary_x;
- float blue_primary_y;
- char label[200];
- char reserved[28];
- unsigned char interleave;
- unsigned char packing;
- unsigned char data_sign;
- unsigned char sense;
- unsigned int line_padding;
- unsigned int element_padding;
- char reserved2[20];
+ unsigned char orientation;
+ unsigned char elements_per_image;
+ unsigned short filler;
+ CineonElementHeader element[8];
+ float white_point_x;
+ float white_point_y;
+ float red_primary_x;
+ float red_primary_y;
+ float green_primary_x;
+ float green_primary_y;
+ float blue_primary_x;
+ float blue_primary_y;
+ char label[200];
+ char reserved[28];
+ unsigned char interleave;
+ unsigned char packing;
+ unsigned char data_sign;
+ unsigned char sense;
+ unsigned int line_padding;
+ unsigned int element_padding;
+ char reserved2[20];
} CineonImageHeader;
typedef struct {
- int x_offset;
- int y_offset;
- char file_name[100];
- char creation_date[12];
- char creation_time[12];
- char input_device[64];
- char model_number[32];
- char input_serial_number[32];
- float x_input_samples_per_mm;
- float y_input_samples_per_mm;
- float input_device_gamma;
- char reserved[40];
+ int x_offset;
+ int y_offset;
+ char file_name[100];
+ char creation_date[12];
+ char creation_time[12];
+ char input_device[64];
+ char model_number[32];
+ char input_serial_number[32];
+ float x_input_samples_per_mm;
+ float y_input_samples_per_mm;
+ float input_device_gamma;
+ char reserved[40];
} CineonOriginationHeader;
typedef struct {
- unsigned char film_code;
- unsigned char film_type;
- unsigned char edge_code_perforation_offset;
- unsigned char filler;
- unsigned int prefix;
- unsigned int count;
- char format[32];
- unsigned int frame_position;
- float frame_rate;
- char attribute[32];
- char slate[200];
- char reserved[740];
+ unsigned char film_code;
+ unsigned char film_type;
+ unsigned char edge_code_perforation_offset;
+ unsigned char filler;
+ unsigned int prefix;
+ unsigned int count;
+ char format[32];
+ unsigned int frame_position;
+ float frame_rate;
+ char attribute[32];
+ char slate[200];
+ char reserved[740];
} CineonFilmHeader;
typedef struct {
- CineonFileHeader fileHeader;
- CineonImageHeader imageHeader;
- CineonOriginationHeader originationHeader;
- CineonFilmHeader filmHeader;
+ CineonFileHeader fileHeader;
+ CineonImageHeader imageHeader;
+ CineonOriginationHeader originationHeader;
+ CineonFilmHeader filmHeader;
} CineonMainHeader;
void cineonSetVerbose(int);
LogImageFile *cineonOpen(const unsigned char *byteStuff, int fromMemory, size_t bufferSize);
-LogImageFile *cineonCreate(const char *filename, int width, int height, int bitsPerSample, const char *creator);
+LogImageFile *cineonCreate(
+ const char *filename, int width, int height, int bitsPerSample, const char *creator);
#ifdef __cplusplus
}
#endif
-#endif /* __CINEONLIB_H__ */
+#endif /* __CINEONLIB_H__ */
diff --git a/source/blender/imbuf/intern/cineon/dpxlib.c b/source/blender/imbuf/intern/cineon/dpxlib.c
index 7ffe259186d..8c0cd88f256 100644
--- a/source/blender/imbuf/intern/cineon/dpxlib.c
+++ b/source/blender/imbuf/intern/cineon/dpxlib.c
@@ -22,7 +22,6 @@
* Dpx image file format library routines.
*/
-
#include "dpxlib.h"
#include "logmemfile.h"
@@ -46,452 +45,490 @@ static int verbose = 0;
void dpxSetVerbose(int verbosity)
{
- verbose = verbosity;
+ verbose = verbosity;
}
-
/*
* Headers
*/
-static void fillDpxMainHeader(LogImageFile *dpx, DpxMainHeader *header, const char *filename, const char *creator)
+static void fillDpxMainHeader(LogImageFile *dpx,
+ DpxMainHeader *header,
+ const char *filename,
+ const char *creator)
{
- time_t fileClock;
- struct tm *fileTime;
-
- memset(header, 0, sizeof(DpxMainHeader));
-
- /* --- File header --- */
- header->fileHeader.magic_num = swap_uint(DPX_FILE_MAGIC, dpx->isMSB);
- header->fileHeader.offset = swap_uint(dpx->element[0].dataOffset, dpx->isMSB);
- strcpy(header->fileHeader.version, "V2.0");
- header->fileHeader.file_size = swap_uint(dpx->element[0].dataOffset + dpx->height * getRowLength(dpx->width, dpx->element[0]), dpx->isMSB);
- header->fileHeader.ditto_key = 0;
- header->fileHeader.gen_hdr_size = swap_uint(sizeof(DpxFileHeader) + sizeof(DpxImageHeader) + sizeof(DpxOrientationHeader), dpx->isMSB);
- header->fileHeader.ind_hdr_size = swap_uint(sizeof(DpxFilmHeader) + sizeof(DpxTelevisionHeader), dpx->isMSB);
- header->fileHeader.user_data_size = DPX_UNDEFINED_U32;
- strncpy(header->fileHeader.file_name, filename, 99);
- header->fileHeader.file_name[99] = 0;
- fileClock = time(NULL);
- fileTime = localtime(&fileClock);
- strftime(header->fileHeader.creation_date, 24, "%Y:%m:%d:%H:%M:%S%Z", fileTime);
- header->fileHeader.creation_date[23] = 0;
- strncpy(header->fileHeader.creator, creator, 99);
- header->fileHeader.creator[99] = 0;
- header->fileHeader.project[0] = 0;
- header->fileHeader.copyright[0] = 0;
- header->fileHeader.key = 0xFFFFFFFF;
-
- /* --- Image header --- */
- header->imageHeader.orientation = 0;
- header->imageHeader.elements_per_image = swap_ushort(1, dpx->isMSB);
- header->imageHeader.pixels_per_line = swap_uint(dpx->width, dpx->isMSB);
- header->imageHeader.lines_per_element = swap_uint(dpx->height, dpx->isMSB);
-
- /* Fills element */
- header->imageHeader.element[0].data_sign = 0;
- header->imageHeader.element[0].ref_low_data = swap_uint(dpx->element[0].refLowData, dpx->isMSB);
- header->imageHeader.element[0].ref_low_quantity = swap_float(dpx->element[0].refLowQuantity, dpx->isMSB);
- header->imageHeader.element[0].ref_high_data = swap_uint(dpx->element[0].refHighData, dpx->isMSB);
- header->imageHeader.element[0].ref_high_quantity = swap_float(dpx->element[0].refHighQuantity, dpx->isMSB);
- header->imageHeader.element[0].descriptor = dpx->element[0].descriptor;
- header->imageHeader.element[0].transfer = dpx->element[0].transfer;
- header->imageHeader.element[0].colorimetric = 0;
- header->imageHeader.element[0].bits_per_sample = dpx->element[0].bitsPerSample;
- header->imageHeader.element[0].packing = swap_ushort(dpx->element[0].packing, dpx->isMSB);
- header->imageHeader.element[0].encoding = 0;
- header->imageHeader.element[0].data_offset = swap_uint(dpx->element[0].dataOffset, dpx->isMSB);
- header->imageHeader.element[0].line_padding = 0;
- header->imageHeader.element[0].element_padding = 0;
- header->imageHeader.element[0].description[0] = 0;
-
- /* --- Orientation header --- */
- /* we leave it blank */
-
- /* --- Television header --- */
- header->televisionHeader.time_code = DPX_UNDEFINED_U32;
- header->televisionHeader.user_bits = DPX_UNDEFINED_U32;
- header->televisionHeader.interlace = DPX_UNDEFINED_U8;
- header->televisionHeader.field_number = DPX_UNDEFINED_U8;
- header->televisionHeader.video_signal = DPX_UNDEFINED_U8;
- header->televisionHeader.padding = DPX_UNDEFINED_U8;
- header->televisionHeader.horizontal_sample_rate = DPX_UNDEFINED_R32;
- header->televisionHeader.vertical_sample_rate = DPX_UNDEFINED_R32;
- header->televisionHeader.frame_rate = DPX_UNDEFINED_R32;
- header->televisionHeader.time_offset = DPX_UNDEFINED_R32;
- header->televisionHeader.gamma = swap_float(dpx->gamma, dpx->isMSB);
- header->televisionHeader.black_level = swap_float(dpx->referenceBlack, dpx->isMSB);
- header->televisionHeader.black_gain = DPX_UNDEFINED_R32;
- header->televisionHeader.breakpoint = DPX_UNDEFINED_R32;
- header->televisionHeader.white_level = swap_float(dpx->referenceWhite, dpx->isMSB);
- header->televisionHeader.integration_times = DPX_UNDEFINED_R32;
+ time_t fileClock;
+ struct tm *fileTime;
+
+ memset(header, 0, sizeof(DpxMainHeader));
+
+ /* --- File header --- */
+ header->fileHeader.magic_num = swap_uint(DPX_FILE_MAGIC, dpx->isMSB);
+ header->fileHeader.offset = swap_uint(dpx->element[0].dataOffset, dpx->isMSB);
+ strcpy(header->fileHeader.version, "V2.0");
+ header->fileHeader.file_size = swap_uint(
+ dpx->element[0].dataOffset + dpx->height * getRowLength(dpx->width, dpx->element[0]),
+ dpx->isMSB);
+ header->fileHeader.ditto_key = 0;
+ header->fileHeader.gen_hdr_size = swap_uint(
+ sizeof(DpxFileHeader) + sizeof(DpxImageHeader) + sizeof(DpxOrientationHeader), dpx->isMSB);
+ header->fileHeader.ind_hdr_size = swap_uint(sizeof(DpxFilmHeader) + sizeof(DpxTelevisionHeader),
+ dpx->isMSB);
+ header->fileHeader.user_data_size = DPX_UNDEFINED_U32;
+ strncpy(header->fileHeader.file_name, filename, 99);
+ header->fileHeader.file_name[99] = 0;
+ fileClock = time(NULL);
+ fileTime = localtime(&fileClock);
+ strftime(header->fileHeader.creation_date, 24, "%Y:%m:%d:%H:%M:%S%Z", fileTime);
+ header->fileHeader.creation_date[23] = 0;
+ strncpy(header->fileHeader.creator, creator, 99);
+ header->fileHeader.creator[99] = 0;
+ header->fileHeader.project[0] = 0;
+ header->fileHeader.copyright[0] = 0;
+ header->fileHeader.key = 0xFFFFFFFF;
+
+ /* --- Image header --- */
+ header->imageHeader.orientation = 0;
+ header->imageHeader.elements_per_image = swap_ushort(1, dpx->isMSB);
+ header->imageHeader.pixels_per_line = swap_uint(dpx->width, dpx->isMSB);
+ header->imageHeader.lines_per_element = swap_uint(dpx->height, dpx->isMSB);
+
+ /* Fills element */
+ header->imageHeader.element[0].data_sign = 0;
+ header->imageHeader.element[0].ref_low_data = swap_uint(dpx->element[0].refLowData, dpx->isMSB);
+ header->imageHeader.element[0].ref_low_quantity = swap_float(dpx->element[0].refLowQuantity,
+ dpx->isMSB);
+ header->imageHeader.element[0].ref_high_data = swap_uint(dpx->element[0].refHighData,
+ dpx->isMSB);
+ header->imageHeader.element[0].ref_high_quantity = swap_float(dpx->element[0].refHighQuantity,
+ dpx->isMSB);
+ header->imageHeader.element[0].descriptor = dpx->element[0].descriptor;
+ header->imageHeader.element[0].transfer = dpx->element[0].transfer;
+ header->imageHeader.element[0].colorimetric = 0;
+ header->imageHeader.element[0].bits_per_sample = dpx->element[0].bitsPerSample;
+ header->imageHeader.element[0].packing = swap_ushort(dpx->element[0].packing, dpx->isMSB);
+ header->imageHeader.element[0].encoding = 0;
+ header->imageHeader.element[0].data_offset = swap_uint(dpx->element[0].dataOffset, dpx->isMSB);
+ header->imageHeader.element[0].line_padding = 0;
+ header->imageHeader.element[0].element_padding = 0;
+ header->imageHeader.element[0].description[0] = 0;
+
+ /* --- Orientation header --- */
+ /* we leave it blank */
+
+ /* --- Television header --- */
+ header->televisionHeader.time_code = DPX_UNDEFINED_U32;
+ header->televisionHeader.user_bits = DPX_UNDEFINED_U32;
+ header->televisionHeader.interlace = DPX_UNDEFINED_U8;
+ header->televisionHeader.field_number = DPX_UNDEFINED_U8;
+ header->televisionHeader.video_signal = DPX_UNDEFINED_U8;
+ header->televisionHeader.padding = DPX_UNDEFINED_U8;
+ header->televisionHeader.horizontal_sample_rate = DPX_UNDEFINED_R32;
+ header->televisionHeader.vertical_sample_rate = DPX_UNDEFINED_R32;
+ header->televisionHeader.frame_rate = DPX_UNDEFINED_R32;
+ header->televisionHeader.time_offset = DPX_UNDEFINED_R32;
+ header->televisionHeader.gamma = swap_float(dpx->gamma, dpx->isMSB);
+ header->televisionHeader.black_level = swap_float(dpx->referenceBlack, dpx->isMSB);
+ header->televisionHeader.black_gain = DPX_UNDEFINED_R32;
+ header->televisionHeader.breakpoint = DPX_UNDEFINED_R32;
+ header->televisionHeader.white_level = swap_float(dpx->referenceWhite, dpx->isMSB);
+ header->televisionHeader.integration_times = DPX_UNDEFINED_R32;
}
LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t bufferSize)
{
- DpxMainHeader header;
- LogImageFile *dpx = (LogImageFile *)MEM_mallocN(sizeof(LogImageFile), __func__);
- const char *filename = (const char *)byteStuff;
- int i;
-
- if (dpx == NULL) {
- if (verbose) printf("DPX: Failed to malloc dpx file structure.\n");
- return NULL;
- }
-
- /* zero the header */
- memset(&header, 0, sizeof(DpxMainHeader));
-
- /* for close routine */
- dpx->file = NULL;
-
- if (fromMemory == 0) {
- /* byteStuff is then the filename */
- dpx->file = BLI_fopen(filename, "rb");
- if (dpx->file == NULL) {
- if (verbose) printf("DPX: Failed to open file \"%s\".\n", filename);
- logImageClose(dpx);
- return NULL;
- }
- /* not used in this case */
- dpx->memBuffer = NULL;
- dpx->memCursor = NULL;
- dpx->memBufferSize = 0;
- }
- else {
- dpx->memBuffer = (unsigned char *)byteStuff;
- dpx->memCursor = (unsigned char *)byteStuff;
- dpx->memBufferSize = bufferSize;
- }
-
- if (logimage_fread(&header, sizeof(header), 1, dpx) == 0) {
- if (verbose) printf("DPX: Not enough data for header in \"%s\".\n", byteStuff);
- logImageClose(dpx);
- return NULL;
- }
-
- /* endianness determination */
- if (header.fileHeader.magic_num == swap_uint(DPX_FILE_MAGIC, 1)) {
- dpx->isMSB = 1;
- if (verbose) printf("DPX: File is MSB.\n");
- }
- else if (header.fileHeader.magic_num == DPX_FILE_MAGIC) {
- dpx->isMSB = 0;
- if (verbose) printf("DPX: File is LSB.\n");
- }
- else {
- if (verbose) {
- printf("DPX: Bad magic number %u in \"%s\".\n",
- header.fileHeader.magic_num, byteStuff);
- }
- logImageClose(dpx);
- return NULL;
- }
-
- dpx->srcFormat = format_DPX;
- 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) printf("DPX: Wrong number of elements: %d\n", dpx->numElements);
- logImageClose(dpx);
- return NULL;
- }
-
- dpx->width = swap_uint(header.imageHeader.pixels_per_line, dpx->isMSB);
- dpx->height = swap_uint(header.imageHeader.lines_per_element, dpx->isMSB);
-
- if (dpx->width == 0 || dpx->height == 0) {
- if (verbose) printf("DPX: Wrong image dimension: %dx%d\n", dpx->width, dpx->height);
- logImageClose(dpx);
- return NULL;
- }
-
- dpx->depth = 0;
-
- for (i = 0; i < dpx->numElements; i++) {
- dpx->element[i].descriptor = header.imageHeader.element[i].descriptor;
-
- switch (dpx->element[i].descriptor) {
- case descriptor_Red:
- case descriptor_Green:
- case descriptor_Blue:
- case descriptor_Alpha:
- case descriptor_Luminance:
- case descriptor_Chrominance:
- dpx->depth++;
- dpx->element[i].depth = 1;
- break;
-
- case descriptor_CbYCrY:
- dpx->depth += 2;
- dpx->element[i].depth = 2;
- break;
-
- case descriptor_RGB:
- case descriptor_CbYCr:
- case descriptor_CbYACrYA:
- dpx->depth += 3;
- dpx->element[i].depth = 3;
- break;
-
- case descriptor_RGBA:
- case descriptor_ABGR:
- case descriptor_CbYCrA:
- dpx->depth += 4;
- dpx->element[i].depth = 4;
- break;
-
- case descriptor_Depth:
- case descriptor_Composite:
- /* unsupported */
- break;
- }
-
- if (dpx->depth == 0 || dpx->depth > 4) {
- if (verbose) printf("DPX: Unsupported image depth: %d\n", dpx->depth);
- logImageClose(dpx);
- return NULL;
- }
-
- dpx->element[i].bitsPerSample = header.imageHeader.element[i].bits_per_sample;
- 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) printf("DPX: Unsupported bitsPerSample for elements %d: %d\n", i, dpx->element[i].bitsPerSample);
- logImageClose(dpx);
- return NULL;
- }
-
- dpx->element[i].maxValue = powf(2, dpx->element[i].bitsPerSample) - 1.0f;
-
- dpx->element[i].packing = swap_ushort(header.imageHeader.element[i].packing, dpx->isMSB);
- if (dpx->element[i].packing > 2) {
- 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)
- dpx->element[i].dataOffset = swap_uint(header.fileHeader.offset, dpx->isMSB);
-
- if (dpx->element[i].dataOffset == 0) {
- if (verbose) printf("DPX: Image header is corrupted.\n");
- logImageClose(dpx);
- return NULL;
- }
-
- dpx->element[i].transfer = header.imageHeader.element[i].transfer;
-
- /* if undefined, assign default */
- dpx->element[i].refLowData = swap_uint(header.imageHeader.element[i].ref_low_data, dpx->isMSB);
- dpx->element[i].refLowQuantity = swap_float(header.imageHeader.element[i].ref_low_quantity, dpx->isMSB);
- dpx->element[i].refHighData = swap_uint(header.imageHeader.element[i].ref_high_data, dpx->isMSB);
- dpx->element[i].refHighQuantity = swap_float(header.imageHeader.element[i].ref_high_quantity, dpx->isMSB);
-
- switch (dpx->element[i].descriptor) {
- case descriptor_Red:
- case descriptor_Green:
- case descriptor_Blue:
- case descriptor_Alpha:
- case descriptor_RGB:
- case descriptor_RGBA:
- case descriptor_ABGR:
- if (dpx->element[i].refLowData == DPX_UNDEFINED_U32)
- dpx->element[i].refLowData = 0;
-
- 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))
- 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].refHighQuantity = 2.048f;
- else
- dpx->element[i].refHighQuantity = dpx->element[i].maxValue;
- }
-
- break;
-
- case descriptor_Luminance:
- case descriptor_Chrominance:
- case descriptor_CbYCrY:
- case descriptor_CbYCr:
- case descriptor_CbYACrYA:
- case descriptor_CbYCrA:
- 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)
- 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))
- dpx->element[i].refLowQuantity = 0.0f;
-
- if (dpx->element[i].refHighQuantity == DPX_UNDEFINED_R32 || isnan(dpx->element[i].refHighQuantity))
- dpx->element[i].refHighQuantity = 0.7f;
-
- break;
-
- default:
- break;
- }
- }
-
- dpx->referenceBlack = swap_float(header.televisionHeader.black_level, dpx->isMSB);
- dpx->referenceWhite = swap_float(header.televisionHeader.white_level, dpx->isMSB);
- dpx->gamma = swap_float(header.televisionHeader.gamma, dpx->isMSB);
-
- if ((dpx->referenceBlack == DPX_UNDEFINED_R32 || isnan(dpx->referenceBlack)) ||
- (dpx->referenceWhite == DPX_UNDEFINED_R32 || dpx->referenceWhite <= dpx->referenceBlack || isnan(dpx->referenceWhite)) ||
- (dpx->gamma == DPX_UNDEFINED_R32 || dpx->gamma <= 0 || isnan(dpx->gamma)))
- {
- dpx->referenceBlack = 95.0f / 1023.0f * dpx->element[0].maxValue;
- dpx->referenceWhite = 685.0f / 1023.0f * dpx->element[0].maxValue;
- dpx->gamma = 1.7f;
- }
-
- if (verbose) {
- printf("size %d x %d x %d elements\n", dpx->width, dpx->height, dpx->numElements);
- for (i = 0; i < dpx->numElements; i++) {
- printf(" Element %d:\n", i);
- printf(" Bits per sample: %d\n", dpx->element[i].bitsPerSample);
- printf(" Depth: %d\n", dpx->element[i].depth);
- printf(" Transfer characteristics: %d\n", dpx->element[i].transfer);
- printf(" Packing: %d\n", dpx->element[i].packing);
- printf(" Descriptor: %d\n", dpx->element[i].descriptor);
- printf(" Data offset: %d\n", dpx->element[i].dataOffset);
- printf(" Reference low data: %u\n", dpx->element[i].refLowData);
- printf(" Reference low quantity: %f\n", dpx->element[i].refLowQuantity);
- printf(" Reference high data: %u\n", dpx->element[i].refHighData);
- printf(" Reference high quantity: %f\n", dpx->element[i].refHighQuantity);
- printf("\n");
- }
-
- printf("Gamma: %f\n", dpx->gamma);
- printf("Reference black: %f\n", dpx->referenceBlack);
- printf("Reference white: %f\n", dpx->referenceWhite);
- printf("Orientation: %d\n", header.imageHeader.orientation);
- printf("----------------------------\n");
- }
- return dpx;
+ DpxMainHeader header;
+ LogImageFile *dpx = (LogImageFile *)MEM_mallocN(sizeof(LogImageFile), __func__);
+ const char *filename = (const char *)byteStuff;
+ int i;
+
+ if (dpx == NULL) {
+ if (verbose)
+ printf("DPX: Failed to malloc dpx file structure.\n");
+ return NULL;
+ }
+
+ /* zero the header */
+ memset(&header, 0, sizeof(DpxMainHeader));
+
+ /* for close routine */
+ dpx->file = NULL;
+
+ if (fromMemory == 0) {
+ /* byteStuff is then the filename */
+ dpx->file = BLI_fopen(filename, "rb");
+ if (dpx->file == NULL) {
+ if (verbose)
+ printf("DPX: Failed to open file \"%s\".\n", filename);
+ logImageClose(dpx);
+ return NULL;
+ }
+ /* not used in this case */
+ dpx->memBuffer = NULL;
+ dpx->memCursor = NULL;
+ dpx->memBufferSize = 0;
+ }
+ else {
+ dpx->memBuffer = (unsigned char *)byteStuff;
+ dpx->memCursor = (unsigned char *)byteStuff;
+ dpx->memBufferSize = bufferSize;
+ }
+
+ if (logimage_fread(&header, sizeof(header), 1, dpx) == 0) {
+ if (verbose)
+ printf("DPX: Not enough data for header in \"%s\".\n", byteStuff);
+ logImageClose(dpx);
+ return NULL;
+ }
+
+ /* endianness determination */
+ if (header.fileHeader.magic_num == swap_uint(DPX_FILE_MAGIC, 1)) {
+ dpx->isMSB = 1;
+ if (verbose)
+ printf("DPX: File is MSB.\n");
+ }
+ else if (header.fileHeader.magic_num == DPX_FILE_MAGIC) {
+ dpx->isMSB = 0;
+ if (verbose)
+ printf("DPX: File is LSB.\n");
+ }
+ else {
+ if (verbose) {
+ printf("DPX: Bad magic number %u in \"%s\".\n", header.fileHeader.magic_num, byteStuff);
+ }
+ logImageClose(dpx);
+ return NULL;
+ }
+
+ dpx->srcFormat = format_DPX;
+ 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)
+ printf("DPX: Wrong number of elements: %d\n", dpx->numElements);
+ logImageClose(dpx);
+ return NULL;
+ }
+
+ dpx->width = swap_uint(header.imageHeader.pixels_per_line, dpx->isMSB);
+ dpx->height = swap_uint(header.imageHeader.lines_per_element, dpx->isMSB);
+
+ if (dpx->width == 0 || dpx->height == 0) {
+ if (verbose)
+ printf("DPX: Wrong image dimension: %dx%d\n", dpx->width, dpx->height);
+ logImageClose(dpx);
+ return NULL;
+ }
+
+ dpx->depth = 0;
+
+ for (i = 0; i < dpx->numElements; i++) {
+ dpx->element[i].descriptor = header.imageHeader.element[i].descriptor;
+
+ switch (dpx->element[i].descriptor) {
+ case descriptor_Red:
+ case descriptor_Green:
+ case descriptor_Blue:
+ case descriptor_Alpha:
+ case descriptor_Luminance:
+ case descriptor_Chrominance:
+ dpx->depth++;
+ dpx->element[i].depth = 1;
+ break;
+
+ case descriptor_CbYCrY:
+ dpx->depth += 2;
+ dpx->element[i].depth = 2;
+ break;
+
+ case descriptor_RGB:
+ case descriptor_CbYCr:
+ case descriptor_CbYACrYA:
+ dpx->depth += 3;
+ dpx->element[i].depth = 3;
+ break;
+
+ case descriptor_RGBA:
+ case descriptor_ABGR:
+ case descriptor_CbYCrA:
+ dpx->depth += 4;
+ dpx->element[i].depth = 4;
+ break;
+
+ case descriptor_Depth:
+ case descriptor_Composite:
+ /* unsupported */
+ break;
+ }
+
+ if (dpx->depth == 0 || dpx->depth > 4) {
+ if (verbose)
+ printf("DPX: Unsupported image depth: %d\n", dpx->depth);
+ logImageClose(dpx);
+ return NULL;
+ }
+
+ dpx->element[i].bitsPerSample = header.imageHeader.element[i].bits_per_sample;
+ 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)
+ printf("DPX: Unsupported bitsPerSample for elements %d: %d\n",
+ i,
+ dpx->element[i].bitsPerSample);
+ logImageClose(dpx);
+ return NULL;
+ }
+
+ dpx->element[i].maxValue = powf(2, dpx->element[i].bitsPerSample) - 1.0f;
+
+ dpx->element[i].packing = swap_ushort(header.imageHeader.element[i].packing, dpx->isMSB);
+ if (dpx->element[i].packing > 2) {
+ 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)
+ dpx->element[i].dataOffset = swap_uint(header.fileHeader.offset, dpx->isMSB);
+
+ if (dpx->element[i].dataOffset == 0) {
+ if (verbose)
+ printf("DPX: Image header is corrupted.\n");
+ logImageClose(dpx);
+ return NULL;
+ }
+
+ dpx->element[i].transfer = header.imageHeader.element[i].transfer;
+
+ /* if undefined, assign default */
+ dpx->element[i].refLowData = swap_uint(header.imageHeader.element[i].ref_low_data, dpx->isMSB);
+ dpx->element[i].refLowQuantity = swap_float(header.imageHeader.element[i].ref_low_quantity,
+ dpx->isMSB);
+ dpx->element[i].refHighData = swap_uint(header.imageHeader.element[i].ref_high_data,
+ dpx->isMSB);
+ dpx->element[i].refHighQuantity = swap_float(header.imageHeader.element[i].ref_high_quantity,
+ dpx->isMSB);
+
+ switch (dpx->element[i].descriptor) {
+ case descriptor_Red:
+ case descriptor_Green:
+ case descriptor_Blue:
+ case descriptor_Alpha:
+ case descriptor_RGB:
+ case descriptor_RGBA:
+ case descriptor_ABGR:
+ if (dpx->element[i].refLowData == DPX_UNDEFINED_U32)
+ dpx->element[i].refLowData = 0;
+
+ 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))
+ 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].refHighQuantity = 2.048f;
+ else
+ dpx->element[i].refHighQuantity = dpx->element[i].maxValue;
+ }
+
+ break;
+
+ case descriptor_Luminance:
+ case descriptor_Chrominance:
+ case descriptor_CbYCrY:
+ case descriptor_CbYCr:
+ case descriptor_CbYACrYA:
+ case descriptor_CbYCrA:
+ 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)
+ 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))
+ dpx->element[i].refLowQuantity = 0.0f;
+
+ if (dpx->element[i].refHighQuantity == DPX_UNDEFINED_R32 ||
+ isnan(dpx->element[i].refHighQuantity))
+ dpx->element[i].refHighQuantity = 0.7f;
+
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ dpx->referenceBlack = swap_float(header.televisionHeader.black_level, dpx->isMSB);
+ dpx->referenceWhite = swap_float(header.televisionHeader.white_level, dpx->isMSB);
+ dpx->gamma = swap_float(header.televisionHeader.gamma, dpx->isMSB);
+
+ if ((dpx->referenceBlack == DPX_UNDEFINED_R32 || isnan(dpx->referenceBlack)) ||
+ (dpx->referenceWhite == DPX_UNDEFINED_R32 || dpx->referenceWhite <= dpx->referenceBlack ||
+ isnan(dpx->referenceWhite)) ||
+ (dpx->gamma == DPX_UNDEFINED_R32 || dpx->gamma <= 0 || isnan(dpx->gamma))) {
+ dpx->referenceBlack = 95.0f / 1023.0f * dpx->element[0].maxValue;
+ dpx->referenceWhite = 685.0f / 1023.0f * dpx->element[0].maxValue;
+ dpx->gamma = 1.7f;
+ }
+
+ if (verbose) {
+ printf("size %d x %d x %d elements\n", dpx->width, dpx->height, dpx->numElements);
+ for (i = 0; i < dpx->numElements; i++) {
+ printf(" Element %d:\n", i);
+ printf(" Bits per sample: %d\n", dpx->element[i].bitsPerSample);
+ printf(" Depth: %d\n", dpx->element[i].depth);
+ printf(" Transfer characteristics: %d\n", dpx->element[i].transfer);
+ printf(" Packing: %d\n", dpx->element[i].packing);
+ printf(" Descriptor: %d\n", dpx->element[i].descriptor);
+ printf(" Data offset: %d\n", dpx->element[i].dataOffset);
+ printf(" Reference low data: %u\n", dpx->element[i].refLowData);
+ printf(" Reference low quantity: %f\n", dpx->element[i].refLowQuantity);
+ printf(" Reference high data: %u\n", dpx->element[i].refHighData);
+ printf(" Reference high quantity: %f\n", dpx->element[i].refHighQuantity);
+ printf("\n");
+ }
+
+ printf("Gamma: %f\n", dpx->gamma);
+ printf("Reference black: %f\n", dpx->referenceBlack);
+ printf("Reference white: %f\n", dpx->referenceWhite);
+ printf("Orientation: %d\n", header.imageHeader.orientation);
+ printf("----------------------------\n");
+ }
+ return dpx;
}
-LogImageFile *dpxCreate(const char *filename, int width, int height, int bitsPerSample, int hasAlpha,
- int isLogarithmic, int referenceWhite, int referenceBlack, float gamma,
+LogImageFile *dpxCreate(const char *filename,
+ int width,
+ int height,
+ int bitsPerSample,
+ int hasAlpha,
+ int isLogarithmic,
+ int referenceWhite,
+ int referenceBlack,
+ float gamma,
const char *creator)
{
- DpxMainHeader header;
- const char *shortFilename = NULL;
- unsigned char pad[6044];
-
- LogImageFile *dpx = (LogImageFile *)MEM_mallocN(sizeof(LogImageFile), __func__);
- if (dpx == NULL) {
- if (verbose) printf("DPX: Failed to malloc dpx file structure.\n");
- return NULL;
- }
-
- dpx->width = width;
- dpx->height = height;
- dpx->element[0].bitsPerSample = bitsPerSample;
- dpx->element[0].dataOffset = 8092;
- dpx->element[0].maxValue = powf(2, dpx->element[0].bitsPerSample) - 1.0f;
- dpx->isMSB = 1;
- dpx->numElements = 1;
-
- switch (bitsPerSample) {
- case 8:
- case 16:
- dpx->element[0].packing = 0;
- break;
-
- case 10:
- case 12:
- /* Packed Type A padding is the most common 10/12 bits format */
- dpx->element[0].packing = 1;
- break;
-
- default:
- if (verbose) printf("DPX: bitsPerSample not supported: %d\n", bitsPerSample);
- logImageClose(dpx);
- return NULL;
- }
-
- if (hasAlpha == 0) {
- dpx->depth = 3;
- dpx->element[0].depth = 3;
- dpx->element[0].descriptor = descriptor_RGB;
- }
- else {
- dpx->depth = 4;
- dpx->element[0].depth = 4;
- dpx->element[0].descriptor = descriptor_RGBA;
- }
-
- if (isLogarithmic == 0) {
- dpx->element[0].transfer = transfer_Linear;
- dpx->element[0].refHighQuantity = dpx->element[0].maxValue;
- }
- else {
- dpx->element[0].transfer = transfer_PrintingDensity;
- dpx->element[0].refHighQuantity = 2.048f;
-
- }
-
- dpx->element[0].refLowQuantity = 0;
- dpx->element[0].refLowData = 0;
- dpx->element[0].refHighData = dpx->element[0].maxValue;
-
- if (referenceWhite > 0)
- dpx->referenceWhite = referenceWhite;
- else
- dpx->referenceWhite = 685.0f / 1023.0f * dpx->element[0].maxValue;
-
- if (referenceBlack > 0)
- dpx->referenceBlack = referenceBlack;
- else
- dpx->referenceBlack = 95.0f / 1023.0f * dpx->element[0].maxValue;
-
- if (gamma > 0.0f)
- dpx->gamma = gamma;
- else
- dpx->gamma = 1.7f;
-
-
- shortFilename = strrchr(filename, '/');
- if (shortFilename == NULL)
- shortFilename = filename;
- else
- shortFilename++;
-
- dpx->file = BLI_fopen(filename, "wb");
-
- if (dpx->file == NULL) {
- if (verbose) printf("DPX: Couldn't open file %s\n", filename);
- logImageClose(dpx);
- return NULL;
- }
-
- fillDpxMainHeader(dpx, &header, shortFilename, creator);
-
- if (fwrite(&header, sizeof(header), 1, dpx->file) == 0) {
- if (verbose) printf("DPX: Couldn't write image header\n");
- logImageClose(dpx);
- return NULL;
- }
-
- /* Header should be rounded to next 8k block
- * 6044 = 8092 - sizeof(DpxMainHeader) */
- memset(&pad, 0, 6044);
- if (fwrite(&pad, 6044, 1, dpx->file) == 0) {
- if (verbose) printf("DPX: Couldn't write image header\n");
- logImageClose(dpx);
- return NULL;
- }
-
- return dpx;
+ DpxMainHeader header;
+ const char *shortFilename = NULL;
+ unsigned char pad[6044];
+
+ LogImageFile *dpx = (LogImageFile *)MEM_mallocN(sizeof(LogImageFile), __func__);
+ if (dpx == NULL) {
+ if (verbose)
+ printf("DPX: Failed to malloc dpx file structure.\n");
+ return NULL;
+ }
+
+ dpx->width = width;
+ dpx->height = height;
+ dpx->element[0].bitsPerSample = bitsPerSample;
+ dpx->element[0].dataOffset = 8092;
+ dpx->element[0].maxValue = powf(2, dpx->element[0].bitsPerSample) - 1.0f;
+ dpx->isMSB = 1;
+ dpx->numElements = 1;
+
+ switch (bitsPerSample) {
+ case 8:
+ case 16:
+ dpx->element[0].packing = 0;
+ break;
+
+ case 10:
+ case 12:
+ /* Packed Type A padding is the most common 10/12 bits format */
+ dpx->element[0].packing = 1;
+ break;
+
+ default:
+ if (verbose)
+ printf("DPX: bitsPerSample not supported: %d\n", bitsPerSample);
+ logImageClose(dpx);
+ return NULL;
+ }
+
+ if (hasAlpha == 0) {
+ dpx->depth = 3;
+ dpx->element[0].depth = 3;
+ dpx->element[0].descriptor = descriptor_RGB;
+ }
+ else {
+ dpx->depth = 4;
+ dpx->element[0].depth = 4;
+ dpx->element[0].descriptor = descriptor_RGBA;
+ }
+
+ if (isLogarithmic == 0) {
+ dpx->element[0].transfer = transfer_Linear;
+ dpx->element[0].refHighQuantity = dpx->element[0].maxValue;
+ }
+ else {
+ dpx->element[0].transfer = transfer_PrintingDensity;
+ dpx->element[0].refHighQuantity = 2.048f;
+ }
+
+ dpx->element[0].refLowQuantity = 0;
+ dpx->element[0].refLowData = 0;
+ dpx->element[0].refHighData = dpx->element[0].maxValue;
+
+ if (referenceWhite > 0)
+ dpx->referenceWhite = referenceWhite;
+ else
+ dpx->referenceWhite = 685.0f / 1023.0f * dpx->element[0].maxValue;
+
+ if (referenceBlack > 0)
+ dpx->referenceBlack = referenceBlack;
+ else
+ dpx->referenceBlack = 95.0f / 1023.0f * dpx->element[0].maxValue;
+
+ if (gamma > 0.0f)
+ dpx->gamma = gamma;
+ else
+ dpx->gamma = 1.7f;
+
+ shortFilename = strrchr(filename, '/');
+ if (shortFilename == NULL)
+ shortFilename = filename;
+ else
+ shortFilename++;
+
+ dpx->file = BLI_fopen(filename, "wb");
+
+ if (dpx->file == NULL) {
+ if (verbose)
+ printf("DPX: Couldn't open file %s\n", filename);
+ logImageClose(dpx);
+ return NULL;
+ }
+
+ fillDpxMainHeader(dpx, &header, shortFilename, creator);
+
+ if (fwrite(&header, sizeof(header), 1, dpx->file) == 0) {
+ if (verbose)
+ printf("DPX: Couldn't write image header\n");
+ logImageClose(dpx);
+ return NULL;
+ }
+
+ /* Header should be rounded to next 8k block
+ * 6044 = 8092 - sizeof(DpxMainHeader) */
+ memset(&pad, 0, 6044);
+ if (fwrite(&pad, 6044, 1, dpx->file) == 0) {
+ if (verbose)
+ printf("DPX: Couldn't write image header\n");
+ logImageClose(dpx);
+ return NULL;
+ }
+
+ return dpx;
}
diff --git a/source/blender/imbuf/intern/cineon/dpxlib.h b/source/blender/imbuf/intern/cineon/dpxlib.h
index fe9f34901b8..bf07b8e329d 100644
--- a/source/blender/imbuf/intern/cineon/dpxlib.h
+++ b/source/blender/imbuf/intern/cineon/dpxlib.h
@@ -22,7 +22,6 @@
* DPX image file format library definitions.
*/
-
#ifndef __DPXLIB_H__
#define __DPXLIB_H__
@@ -32,126 +31,134 @@ extern "C" {
#include "logImageCore.h"
-#define DPX_FILE_MAGIC 0x53445058
-#define DPX_UNDEFINED_U8 0xFF
-#define DPX_UNDEFINED_U16 0xFFFF
-#define DPX_UNDEFINED_U32 0xFFFFFFFF
-#define DPX_UNDEFINED_R32 0xFFFFFFFF
-#define DPX_UNDEFINED_CHAR 0
+#define DPX_FILE_MAGIC 0x53445058
+#define DPX_UNDEFINED_U8 0xFF
+#define DPX_UNDEFINED_U16 0xFFFF
+#define DPX_UNDEFINED_U32 0xFFFFFFFF
+#define DPX_UNDEFINED_R32 0xFFFFFFFF
+#define DPX_UNDEFINED_CHAR 0
typedef struct {
- unsigned int magic_num;
- unsigned int offset;
- char version[8];
- unsigned int file_size;
- unsigned int ditto_key;
- unsigned int gen_hdr_size;
- unsigned int ind_hdr_size;
- unsigned int user_data_size;
- char file_name[100];
- char creation_date[24];
- char creator[100];
- char project[200];
- char copyright[200];
- unsigned int key;
- char reserved[104];
+ unsigned int magic_num;
+ unsigned int offset;
+ char version[8];
+ unsigned int file_size;
+ unsigned int ditto_key;
+ unsigned int gen_hdr_size;
+ unsigned int ind_hdr_size;
+ unsigned int user_data_size;
+ char file_name[100];
+ char creation_date[24];
+ char creator[100];
+ char project[200];
+ char copyright[200];
+ unsigned int key;
+ char reserved[104];
} DpxFileHeader;
typedef struct {
- unsigned int data_sign;
- unsigned int ref_low_data;
- float ref_low_quantity;
- unsigned int ref_high_data;
- float ref_high_quantity;
- unsigned char descriptor;
- unsigned char transfer;
- unsigned char colorimetric;
- unsigned char bits_per_sample;
- unsigned short packing;
- unsigned short encoding;
- unsigned int data_offset;
- unsigned int line_padding;
- unsigned int element_padding;
- char description[32];
+ unsigned int data_sign;
+ unsigned int ref_low_data;
+ float ref_low_quantity;
+ unsigned int ref_high_data;
+ float ref_high_quantity;
+ unsigned char descriptor;
+ unsigned char transfer;
+ unsigned char colorimetric;
+ unsigned char bits_per_sample;
+ unsigned short packing;
+ unsigned short encoding;
+ unsigned int data_offset;
+ unsigned int line_padding;
+ unsigned int element_padding;
+ char description[32];
} DpxElementHeader;
typedef struct {
- unsigned short orientation;
- unsigned short elements_per_image;
- unsigned int pixels_per_line;
- unsigned int lines_per_element;
- DpxElementHeader element[8];
- char reserved[52];
+ unsigned short orientation;
+ unsigned short elements_per_image;
+ unsigned int pixels_per_line;
+ unsigned int lines_per_element;
+ DpxElementHeader element[8];
+ char reserved[52];
} DpxImageHeader;
typedef struct {
- unsigned int x_offset;
- unsigned int y_offset;
- float x_center;
- float y_center;
- unsigned int x_original_size;
- unsigned int y_original_size;
- char file_name[100];
- char creation_time[24];
- char input_device[32];
- char input_serial_number[32];
- unsigned short border_validity[4];
- unsigned int pixel_aspect_ratio[2];
- char reserved[28];
+ unsigned int x_offset;
+ unsigned int y_offset;
+ float x_center;
+ float y_center;
+ unsigned int x_original_size;
+ unsigned int y_original_size;
+ char file_name[100];
+ char creation_time[24];
+ char input_device[32];
+ char input_serial_number[32];
+ unsigned short border_validity[4];
+ unsigned int pixel_aspect_ratio[2];
+ char reserved[28];
} DpxOrientationHeader;
typedef struct {
- char film_manufacturer_id[2];
- char film_type[2];
- char edge_code_perforation_offset[2];
- char edge_code_prefix[6];
- char edge_code_count[4];
- char film_format[32];
- unsigned int frame_position;
- unsigned int sequence_length;
- unsigned int held_count;
- float frame_rate;
- float shutter_angle;
- char frame_identification[32];
- char slate_info[100];
- char reserved[56];
+ char film_manufacturer_id[2];
+ char film_type[2];
+ char edge_code_perforation_offset[2];
+ char edge_code_prefix[6];
+ char edge_code_count[4];
+ char film_format[32];
+ unsigned int frame_position;
+ unsigned int sequence_length;
+ unsigned int held_count;
+ float frame_rate;
+ float shutter_angle;
+ char frame_identification[32];
+ char slate_info[100];
+ char reserved[56];
} DpxFilmHeader;
typedef struct {
- unsigned int time_code;
- unsigned int user_bits;
- unsigned char interlace;
- unsigned char field_number;
- unsigned char video_signal;
- unsigned char padding;
- float horizontal_sample_rate;
- float vertical_sample_rate;
- float frame_rate;
- float time_offset;
- float gamma;
- float black_level;
- float black_gain;
- float breakpoint;
- float white_level;
- float integration_times;
- unsigned char reserved[76];
+ unsigned int time_code;
+ unsigned int user_bits;
+ unsigned char interlace;
+ unsigned char field_number;
+ unsigned char video_signal;
+ unsigned char padding;
+ float horizontal_sample_rate;
+ float vertical_sample_rate;
+ float frame_rate;
+ float time_offset;
+ float gamma;
+ float black_level;
+ float black_gain;
+ float breakpoint;
+ float white_level;
+ float integration_times;
+ unsigned char reserved[76];
} DpxTelevisionHeader;
-
typedef struct {
- DpxFileHeader fileHeader;
- DpxImageHeader imageHeader;
- DpxOrientationHeader orientationHeader;
- DpxFilmHeader filmHeader;
- DpxTelevisionHeader televisionHeader;
+ DpxFileHeader fileHeader;
+ DpxImageHeader imageHeader;
+ DpxOrientationHeader orientationHeader;
+ DpxFilmHeader filmHeader;
+ DpxTelevisionHeader televisionHeader;
} DpxMainHeader;
void dpxSetVerbose(int verbosity);
LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t bufferSize);
-LogImageFile *dpxCreate(const char *filename, int width, int height, int bitsPerSample, int hasAlpha, int isLogarithmic, int referenceWhite, int referenceBlack, float gamma, const char *creator);
+LogImageFile *dpxCreate(const char *filename,
+ int width,
+ int height,
+ int bitsPerSample,
+ int hasAlpha,
+ int isLogarithmic,
+ int referenceWhite,
+ int referenceBlack,
+ float gamma,
+ const char *creator);
#ifdef __cplusplus
}
#endif
-#endif /* __DPXLIB_H__ */
+#endif /* __DPXLIB_H__ */
diff --git a/source/blender/imbuf/intern/cineon/logImageCore.c b/source/blender/imbuf/intern/cineon/logImageCore.c
index 3dcf1814f27..2169665cf78 100644
--- a/source/blender/imbuf/intern/cineon/logImageCore.c
+++ b/source/blender/imbuf/intern/cineon/logImageCore.c
@@ -22,7 +22,6 @@
* Cineon image file format library routines.
*/
-
#include "logmemfile.h"
#include "logImageCore.h"
#include "dpxlib.h"
@@ -51,13 +50,24 @@ static int logImageElementGetData(LogImageFile *dpx, LogImageElement logElement,
static int logImageElementGetData1(LogImageFile *dpx, LogImageElement logElement, float *data);
static int logImageElementGetData8(LogImageFile *dpx, LogImageElement logElement, float *data);
static int logImageElementGetData10(LogImageFile *dpx, LogImageElement logElement, float *data);
-static int logImageElementGetData10Packed(LogImageFile *dpx, LogImageElement logElement, float *data);
+static int logImageElementGetData10Packed(LogImageFile *dpx,
+ LogImageElement logElement,
+ float *data);
static int logImageElementGetData12(LogImageFile *dpx, LogImageElement logElement, float *data);
-static int logImageElementGetData12Packed(LogImageFile *dpx, LogImageElement logElement, float *data);
+static int logImageElementGetData12Packed(LogImageFile *dpx,
+ LogImageElement logElement,
+ float *data);
static int logImageElementGetData16(LogImageFile *dpx, LogImageElement logElement, float *data);
-static int convertLogElementToRGBA(float *src, float *dst, LogImageFile *logImage, LogImageElement logElement, int dstIsLinearRGB);
-static int convertRGBAToLogElement(float *src, float *dst, LogImageFile *logImage, LogImageElement logElement, int srcIsLinearRGB);
-
+static int convertLogElementToRGBA(float *src,
+ float *dst,
+ LogImageFile *logImage,
+ LogImageElement logElement,
+ int dstIsLinearRGB);
+static int convertRGBAToLogElement(float *src,
+ float *dst,
+ LogImageFile *logImage,
+ LogImageElement logElement,
+ int srcIsLinearRGB);
/*
* For debug purpose
@@ -67,1409 +77,1569 @@ static int verbose = 0;
void logImageSetVerbose(int verbosity)
{
- verbose = verbosity;
- cineonSetVerbose(verbosity);
- dpxSetVerbose(verbosity);
+ verbose = verbosity;
+ cineonSetVerbose(verbosity);
+ dpxSetVerbose(verbosity);
}
-
/*
* IO stuff
*/
int logImageIsDpx(const void *buffer)
{
- unsigned int magicNum = *(unsigned int *)buffer;
- return (magicNum == DPX_FILE_MAGIC || magicNum == swap_uint(DPX_FILE_MAGIC, 1));
+ unsigned int magicNum = *(unsigned int *)buffer;
+ return (magicNum == DPX_FILE_MAGIC || magicNum == swap_uint(DPX_FILE_MAGIC, 1));
}
int logImageIsCineon(const void *buffer)
{
- unsigned int magicNum = *(unsigned int *)buffer;
- return (magicNum == CINEON_FILE_MAGIC || magicNum == swap_uint(CINEON_FILE_MAGIC, 1));
+ unsigned int magicNum = *(unsigned int *)buffer;
+ return (magicNum == CINEON_FILE_MAGIC || magicNum == swap_uint(CINEON_FILE_MAGIC, 1));
}
LogImageFile *logImageOpenFromFile(const char *filename, int cineon)
{
- unsigned int magicNum;
- FILE *f = BLI_fopen(filename, "rb");
+ unsigned int magicNum;
+ FILE *f = BLI_fopen(filename, "rb");
- (void)cineon;
+ (void)cineon;
- if (f == NULL)
- return NULL;
+ if (f == NULL)
+ return NULL;
- if (fread(&magicNum, sizeof(unsigned int), 1, f) != 1) {
- fclose(f);
- return NULL;
- }
+ if (fread(&magicNum, sizeof(unsigned int), 1, f) != 1) {
+ fclose(f);
+ return NULL;
+ }
- fclose(f);
+ fclose(f);
- if (logImageIsDpx(&magicNum))
- return dpxOpen((const unsigned char *)filename, 0, 0);
- else if (logImageIsCineon(&magicNum))
- return cineonOpen((const unsigned char *)filename, 0, 0);
+ if (logImageIsDpx(&magicNum))
+ return dpxOpen((const unsigned char *)filename, 0, 0);
+ else if (logImageIsCineon(&magicNum))
+ return cineonOpen((const unsigned char *)filename, 0, 0);
- return NULL;
+ return NULL;
}
LogImageFile *logImageOpenFromMemory(const unsigned char *buffer, unsigned int size)
{
- if (logImageIsDpx(buffer))
- return dpxOpen(buffer, 1, size);
- else if (logImageIsCineon(buffer))
- return cineonOpen(buffer, 1, size);
+ if (logImageIsDpx(buffer))
+ return dpxOpen(buffer, 1, size);
+ else if (logImageIsCineon(buffer))
+ return cineonOpen(buffer, 1, size);
- return NULL;
+ return NULL;
}
-LogImageFile *logImageCreate(const char *filename, int cineon, int width, int height, int bitsPerSample,
- int isLogarithmic, int hasAlpha, int referenceWhite, int referenceBlack,
- float gamma, const char *creator)
+LogImageFile *logImageCreate(const char *filename,
+ int cineon,
+ int width,
+ int height,
+ int bitsPerSample,
+ int isLogarithmic,
+ int hasAlpha,
+ int referenceWhite,
+ int referenceBlack,
+ float gamma,
+ const char *creator)
{
- /* referenceWhite, referenceBlack and gamma values are only supported for DPX file */
- if (cineon)
- return cineonCreate(filename, width, height, bitsPerSample, creator);
- else
- return dpxCreate(filename, width, height, bitsPerSample, isLogarithmic, hasAlpha,
- referenceWhite, referenceBlack, gamma, creator);
-
- return NULL;
+ /* referenceWhite, referenceBlack and gamma values are only supported for DPX file */
+ if (cineon)
+ return cineonCreate(filename, width, height, bitsPerSample, creator);
+ else
+ return dpxCreate(filename,
+ width,
+ height,
+ bitsPerSample,
+ isLogarithmic,
+ hasAlpha,
+ referenceWhite,
+ referenceBlack,
+ gamma,
+ creator);
+
+ return NULL;
}
void logImageClose(LogImageFile *logImage)
{
- if (logImage != NULL) {
- if (logImage->file) {
- fclose(logImage->file);
- logImage->file = NULL;
- }
- MEM_freeN(logImage);
- }
+ if (logImage != NULL) {
+ if (logImage->file) {
+ fclose(logImage->file);
+ logImage->file = NULL;
+ }
+ MEM_freeN(logImage);
+ }
}
void logImageGetSize(LogImageFile *logImage, int *width, int *height, int *depth)
{
- *width = logImage->width;
- *height = logImage->height;
- *depth = logImage->depth;
+ *width = logImage->width;
+ *height = logImage->height;
+ *depth = logImage->depth;
}
-
/*
* Helper
*/
size_t getRowLength(size_t width, LogImageElement logElement)
{
- /* return the row length in bytes according to width and packing method */
- switch (logElement.bitsPerSample) {
- case 1:
- return ((width * logElement.depth - 1) / 32 + 1) * 4;
-
- case 8:
- return ((width * logElement.depth - 1) / 4 + 1) * 4;
-
- case 10:
- if (logElement.packing == 0)
- return ((width * logElement.depth * 10 - 1) / 32 + 1) * 4;
- else if (logElement.packing == 1 || logElement.packing == 2)
- return ((width * logElement.depth - 1) / 3 + 1) * 4;
- break;
- case 12:
- if (logElement.packing == 0)
- return ((width * logElement.depth * 12 - 1) / 32 + 1) * 4;
- else if (logElement.packing == 1 || logElement.packing == 2)
- return width * logElement.depth * 2;
- break;
- case 16:
- return width * logElement.depth * 2;
-
- }
- return 0;
+ /* return the row length in bytes according to width and packing method */
+ switch (logElement.bitsPerSample) {
+ case 1:
+ return ((width * logElement.depth - 1) / 32 + 1) * 4;
+
+ case 8:
+ return ((width * logElement.depth - 1) / 4 + 1) * 4;
+
+ case 10:
+ if (logElement.packing == 0)
+ return ((width * logElement.depth * 10 - 1) / 32 + 1) * 4;
+ else if (logElement.packing == 1 || logElement.packing == 2)
+ return ((width * logElement.depth - 1) / 3 + 1) * 4;
+ break;
+ case 12:
+ if (logElement.packing == 0)
+ return ((width * logElement.depth * 12 - 1) / 32 + 1) * 4;
+ else if (logElement.packing == 1 || logElement.packing == 2)
+ return width * logElement.depth * 2;
+ break;
+ case 16:
+ return width * logElement.depth * 2;
+ }
+ return 0;
}
-
/*
* Data writing
*/
int logImageSetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB)
{
- float *elementData;
- int returnValue;
-
- elementData = (float *)imb_alloc_pixels(logImage->width, logImage->height, logImage->depth, sizeof(float), __func__);
- if (elementData == NULL)
- return 1;
-
- if (convertRGBAToLogElement(data, elementData, logImage, logImage->element[0], dataIsLinearRGB) != 0) {
- MEM_freeN(elementData);
- return 1;
- }
-
- switch (logImage->element[0].bitsPerSample) {
- case 8:
- returnValue = logImageSetData8(logImage, logImage->element[0], elementData);
- break;
-
- case 10:
- returnValue = logImageSetData10(logImage, logImage->element[0], elementData);
- break;
-
- case 12:
- returnValue = logImageSetData12(logImage, logImage->element[0], elementData);
- break;
-
- case 16:
- returnValue = logImageSetData16(logImage, logImage->element[0], elementData);
- break;
-
- default:
- returnValue = 1;
- break;
- }
-
- MEM_freeN(elementData);
- return returnValue;
+ float *elementData;
+ int returnValue;
+
+ elementData = (float *)imb_alloc_pixels(
+ logImage->width, logImage->height, logImage->depth, sizeof(float), __func__);
+ if (elementData == NULL)
+ return 1;
+
+ if (convertRGBAToLogElement(
+ data, elementData, logImage, logImage->element[0], dataIsLinearRGB) != 0) {
+ MEM_freeN(elementData);
+ return 1;
+ }
+
+ switch (logImage->element[0].bitsPerSample) {
+ case 8:
+ returnValue = logImageSetData8(logImage, logImage->element[0], elementData);
+ break;
+
+ case 10:
+ returnValue = logImageSetData10(logImage, logImage->element[0], elementData);
+ break;
+
+ case 12:
+ returnValue = logImageSetData12(logImage, logImage->element[0], elementData);
+ break;
+
+ case 16:
+ returnValue = logImageSetData16(logImage, logImage->element[0], elementData);
+ break;
+
+ default:
+ returnValue = 1;
+ break;
+ }
+
+ MEM_freeN(elementData);
+ return returnValue;
}
static int logImageSetData8(LogImageFile *logImage, LogImageElement logElement, float *data)
{
- size_t rowLength = getRowLength(logImage->width, logElement);
- unsigned char *row;
-
- row = (unsigned char *)MEM_mallocN(rowLength, __func__);
- if (row == NULL) {
- 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++)
- row[x] = (unsigned char)float_uint(data[y * logImage->width * logImage->depth + x], 255);
-
- if (logimage_fwrite(row, rowLength, 1, logImage) == 0) {
- if (verbose) printf("DPX/Cineon: Error while writing file.\n");
- MEM_freeN(row);
- return 1;
- }
- }
- MEM_freeN(row);
- return 0;
+ size_t rowLength = getRowLength(logImage->width, logElement);
+ unsigned char *row;
+
+ row = (unsigned char *)MEM_mallocN(rowLength, __func__);
+ if (row == NULL) {
+ 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++)
+ row[x] = (unsigned char)float_uint(data[y * logImage->width * logImage->depth + x], 255);
+
+ if (logimage_fwrite(row, rowLength, 1, logImage) == 0) {
+ if (verbose)
+ printf("DPX/Cineon: Error while writing file.\n");
+ MEM_freeN(row);
+ return 1;
+ }
+ }
+ MEM_freeN(row);
+ return 0;
}
static int logImageSetData10(LogImageFile *logImage, LogImageElement logElement, float *data)
{
- size_t rowLength = getRowLength(logImage->width, logElement);
- unsigned int pixel, index;
- unsigned int *row;
-
- row = (unsigned int *)MEM_mallocN(rowLength, __func__);
- if (row == NULL) {
- if (verbose) printf("DPX/Cineon: Cannot allocate row.\n");
- return 1;
- }
-
- for (size_t y = 0; y < logImage->height; y++) {
- int offset = 22;
- index = 0;
- pixel = 0;
-
- for (size_t x = 0; x < logImage->width * logImage->depth; x++) {
- pixel |= (unsigned int)float_uint(data[y * logImage->width * logImage->depth + x], 1023) << offset;
- offset -= 10;
- if (offset < 0) {
- row[index] = swap_uint(pixel, logImage->isMSB);
- index++;
- pixel = 0;
- offset = 22;
- }
- }
- if (pixel != 0)
- row[index] = swap_uint(pixel, logImage->isMSB);
-
- if (logimage_fwrite(row, rowLength, 1, logImage) == 0) {
- if (verbose) {
- printf("DPX/Cineon: Error while writing file.\n");
- }
- MEM_freeN(row);
- return 1;
- }
- }
- MEM_freeN(row);
- return 0;
+ size_t rowLength = getRowLength(logImage->width, logElement);
+ unsigned int pixel, index;
+ unsigned int *row;
+
+ row = (unsigned int *)MEM_mallocN(rowLength, __func__);
+ if (row == NULL) {
+ if (verbose)
+ printf("DPX/Cineon: Cannot allocate row.\n");
+ return 1;
+ }
+
+ for (size_t y = 0; y < logImage->height; y++) {
+ int offset = 22;
+ index = 0;
+ pixel = 0;
+
+ for (size_t x = 0; x < logImage->width * logImage->depth; x++) {
+ pixel |= (unsigned int)float_uint(data[y * logImage->width * logImage->depth + x], 1023)
+ << offset;
+ offset -= 10;
+ if (offset < 0) {
+ row[index] = swap_uint(pixel, logImage->isMSB);
+ index++;
+ pixel = 0;
+ offset = 22;
+ }
+ }
+ if (pixel != 0)
+ row[index] = swap_uint(pixel, logImage->isMSB);
+
+ if (logimage_fwrite(row, rowLength, 1, logImage) == 0) {
+ if (verbose) {
+ printf("DPX/Cineon: Error while writing file.\n");
+ }
+ MEM_freeN(row);
+ return 1;
+ }
+ }
+ MEM_freeN(row);
+ return 0;
}
static int logImageSetData12(LogImageFile *logImage, LogImageElement logElement, float *data)
{
- size_t rowLength = getRowLength(logImage->width, logElement);
- unsigned short *row;
-
- row = (unsigned short *)MEM_mallocN(rowLength, __func__);
- if (row == NULL) {
- 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++)
- 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) printf("DPX/Cineon: Error while writing file.\n");
- MEM_freeN(row);
- return 1;
- }
- }
- MEM_freeN(row);
- return 0;
+ size_t rowLength = getRowLength(logImage->width, logElement);
+ unsigned short *row;
+
+ row = (unsigned short *)MEM_mallocN(rowLength, __func__);
+ if (row == NULL) {
+ 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++)
+ 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)
+ printf("DPX/Cineon: Error while writing file.\n");
+ MEM_freeN(row);
+ return 1;
+ }
+ }
+ MEM_freeN(row);
+ return 0;
}
static int logImageSetData16(LogImageFile *logImage, LogImageElement logElement, float *data)
{
- size_t rowLength = getRowLength(logImage->width, logElement);
- unsigned short *row;
-
- row = (unsigned short *)MEM_mallocN(rowLength, __func__);
- if (row == NULL) {
- 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++)
- 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) printf("DPX/Cineon: Error while writing file.\n");
- MEM_freeN(row);
- return 1;
- }
- }
- MEM_freeN(row);
- return 0;
+ size_t rowLength = getRowLength(logImage->width, logElement);
+ unsigned short *row;
+
+ row = (unsigned short *)MEM_mallocN(rowLength, __func__);
+ if (row == NULL) {
+ 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++)
+ 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)
+ printf("DPX/Cineon: Error while writing file.\n");
+ MEM_freeN(row);
+ return 1;
+ }
+ }
+ MEM_freeN(row);
+ return 0;
}
-
/*
* Data reading
*/
int logImageGetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB)
{
- /* Fills data with 32 bits float RGBA values */
- int i, j, returnValue, sortedElementData[8], hasAlpha;
- float *elementData[8];
- float *elementData_ptr[8];
- float *mergedData;
- unsigned int sampleIndex;
- LogImageElement mergedElement;
-
- /* Determine the depth of the picture and if there's a separate alpha element.
- * If the element is supported, load it into an unsigned ints array. */
- memset(&elementData, 0, 8 * sizeof(float *));
- hasAlpha = 0;
-
- for (i = 0; i < logImage->numElements; i++) {
- /* descriptor_Depth and descriptor_Composite are not supported */
- if (logImage->element[i].descriptor != descriptor_Depth && logImage->element[i].descriptor != descriptor_Composite) {
- /* Allocate memory */
- elementData[i] = imb_alloc_pixels(logImage->width, logImage->height, logImage->element[i].depth, sizeof(float), __func__);
- if (elementData[i] == NULL) {
- if (verbose) printf("DPX/Cineon: Cannot allocate memory for elementData[%d]\n.", i);
- 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) printf("DPX/Cineon: Cannot read elementData[%d]\n.", i);
- for (j = 0; j < i; j++)
- if (elementData[j] != NULL)
- MEM_freeN(elementData[j]);
- return 1;
- }
- }
-
- if (logImage->element[i].descriptor == descriptor_Alpha)
- hasAlpha = 1;
- }
-
- /* only one element, easy case, no need to do anything */
- if (logImage->numElements == 1) {
- returnValue = convertLogElementToRGBA(elementData[0], data, logImage, logImage->element[0], dataIsLinearRGB);
- MEM_freeN(elementData[0]);
- }
- else {
- /* The goal here is to merge every elements into only one
- * to recreate a classic 16 bits RGB, RGBA or YCbCr element.
- * Unsupported elements are skipped (depth, composite) */
-
- memcpy(&mergedElement, &logImage->element[0], sizeof(LogImageElement));
- mergedElement.descriptor = -1;
- mergedElement.depth = logImage->depth;
- memset(&sortedElementData, -1, 8 * sizeof(int));
-
- /* Try to know how to assemble the elements */
- for (i = 0; i < logImage->numElements; i++) {
- switch (logImage->element[i].descriptor) {
- case descriptor_Red:
- case descriptor_RGB:
- if (hasAlpha == 0)
- mergedElement.descriptor = descriptor_RGB;
- else
- mergedElement.descriptor = descriptor_RGBA;
-
- sortedElementData[0] = i;
- break;
-
- case descriptor_Green:
- if (hasAlpha == 0)
- mergedElement.descriptor = descriptor_RGB;
- else
- mergedElement.descriptor = descriptor_RGBA;
-
- sortedElementData[1] = i;
- break;
-
- case descriptor_Blue:
- if (hasAlpha == 0)
- mergedElement.descriptor = descriptor_RGB;
- else
- mergedElement.descriptor = descriptor_RGBA;
-
- sortedElementData[2] = i;
- break;
-
- case descriptor_Alpha:
- /* Alpha component is always the last one */
- sortedElementData[mergedElement.depth - 1] = i;
- break;
-
- case descriptor_Luminance:
- if (mergedElement.descriptor == -1)
- if (hasAlpha == 0)
- mergedElement.descriptor = descriptor_Luminance;
- else
- mergedElement.descriptor = descriptor_YA;
- else if (mergedElement.descriptor == descriptor_Chrominance) {
- if (mergedElement.depth == 2)
- mergedElement.descriptor = descriptor_CbYCrY;
- else if (mergedElement.depth == 3)
- if (hasAlpha == 0)
- mergedElement.descriptor = descriptor_CbYCr;
- else
- mergedElement.descriptor = descriptor_CbYACrYA;
- 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))
- sortedElementData[0] = i;
- else
- sortedElementData[1] = i;
- break;
-
- case descriptor_Chrominance:
- if (mergedElement.descriptor == -1)
- mergedElement.descriptor = descriptor_Chrominance;
- else if (mergedElement.descriptor == descriptor_Luminance) {
- if (mergedElement.depth == 2)
- mergedElement.descriptor = descriptor_CbYCrY;
- else if (mergedElement.depth == 3)
- if (hasAlpha == 0)
- mergedElement.descriptor = descriptor_CbYCr;
- else
- mergedElement.descriptor = descriptor_CbYACrYA;
- else if (mergedElement.depth == 4)
- mergedElement.descriptor = descriptor_CbYCrA;
- }
-
- /* Cb and Cr always in 0 or 2 */
- if (sortedElementData[0] == -1)
- sortedElementData[0] = i;
- else
- sortedElementData[2] = i;
- break;
-
- case descriptor_CbYCr:
- if (hasAlpha == 0)
- mergedElement.descriptor = descriptor_CbYCr;
- else
- mergedElement.descriptor = descriptor_CbYCrA;
-
- sortedElementData[0] = i;
- break;
-
- case descriptor_RGBA:
- case descriptor_ABGR:
- case descriptor_CbYACrYA:
- case descriptor_CbYCrY:
- case descriptor_CbYCrA:
- /* I don't think these ones can be seen in a planar image */
- mergedElement.descriptor = logImage->element[i].descriptor;
- sortedElementData[0] = i;
- break;
-
- case descriptor_Depth:
- case descriptor_Composite:
- /* Not supported */
- break;
- }
- }
-
- mergedData = (float *)imb_alloc_pixels(logImage->width, logImage->height, mergedElement.depth, sizeof(float), __func__);
- if (mergedData == NULL) {
- if (verbose) printf("DPX/Cineon: Cannot allocate mergedData.\n");
- 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++)
- mergedData[sampleIndex++] = *(elementData_ptr[sortedElementData[i]]++);
- }
-
- /* Done with elements data, clean-up */
- for (i = 0; i < logImage->numElements; i++)
- if (elementData[i] != NULL)
- MEM_freeN(elementData[i]);
-
- returnValue = convertLogElementToRGBA(mergedData, data, logImage, mergedElement, dataIsLinearRGB);
- MEM_freeN(mergedData);
- }
- return returnValue;
+ /* Fills data with 32 bits float RGBA values */
+ int i, j, returnValue, sortedElementData[8], hasAlpha;
+ float *elementData[8];
+ float *elementData_ptr[8];
+ float *mergedData;
+ unsigned int sampleIndex;
+ LogImageElement mergedElement;
+
+ /* Determine the depth of the picture and if there's a separate alpha element.
+ * If the element is supported, load it into an unsigned ints array. */
+ memset(&elementData, 0, 8 * sizeof(float *));
+ hasAlpha = 0;
+
+ for (i = 0; i < logImage->numElements; i++) {
+ /* descriptor_Depth and descriptor_Composite are not supported */
+ if (logImage->element[i].descriptor != descriptor_Depth &&
+ logImage->element[i].descriptor != descriptor_Composite) {
+ /* Allocate memory */
+ elementData[i] = imb_alloc_pixels(
+ logImage->width, logImage->height, logImage->element[i].depth, sizeof(float), __func__);
+ if (elementData[i] == NULL) {
+ if (verbose)
+ printf("DPX/Cineon: Cannot allocate memory for elementData[%d]\n.", i);
+ 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)
+ printf("DPX/Cineon: Cannot read elementData[%d]\n.", i);
+ for (j = 0; j < i; j++)
+ if (elementData[j] != NULL)
+ MEM_freeN(elementData[j]);
+ return 1;
+ }
+ }
+
+ if (logImage->element[i].descriptor == descriptor_Alpha)
+ hasAlpha = 1;
+ }
+
+ /* only one element, easy case, no need to do anything */
+ if (logImage->numElements == 1) {
+ returnValue = convertLogElementToRGBA(
+ elementData[0], data, logImage, logImage->element[0], dataIsLinearRGB);
+ MEM_freeN(elementData[0]);
+ }
+ else {
+ /* The goal here is to merge every elements into only one
+ * to recreate a classic 16 bits RGB, RGBA or YCbCr element.
+ * Unsupported elements are skipped (depth, composite) */
+
+ memcpy(&mergedElement, &logImage->element[0], sizeof(LogImageElement));
+ mergedElement.descriptor = -1;
+ mergedElement.depth = logImage->depth;
+ memset(&sortedElementData, -1, 8 * sizeof(int));
+
+ /* Try to know how to assemble the elements */
+ for (i = 0; i < logImage->numElements; i++) {
+ switch (logImage->element[i].descriptor) {
+ case descriptor_Red:
+ case descriptor_RGB:
+ if (hasAlpha == 0)
+ mergedElement.descriptor = descriptor_RGB;
+ else
+ mergedElement.descriptor = descriptor_RGBA;
+
+ sortedElementData[0] = i;
+ break;
+
+ case descriptor_Green:
+ if (hasAlpha == 0)
+ mergedElement.descriptor = descriptor_RGB;
+ else
+ mergedElement.descriptor = descriptor_RGBA;
+
+ sortedElementData[1] = i;
+ break;
+
+ case descriptor_Blue:
+ if (hasAlpha == 0)
+ mergedElement.descriptor = descriptor_RGB;
+ else
+ mergedElement.descriptor = descriptor_RGBA;
+
+ sortedElementData[2] = i;
+ break;
+
+ case descriptor_Alpha:
+ /* Alpha component is always the last one */
+ sortedElementData[mergedElement.depth - 1] = i;
+ break;
+
+ case descriptor_Luminance:
+ if (mergedElement.descriptor == -1)
+ if (hasAlpha == 0)
+ mergedElement.descriptor = descriptor_Luminance;
+ else
+ mergedElement.descriptor = descriptor_YA;
+ else if (mergedElement.descriptor == descriptor_Chrominance) {
+ if (mergedElement.depth == 2)
+ mergedElement.descriptor = descriptor_CbYCrY;
+ else if (mergedElement.depth == 3)
+ if (hasAlpha == 0)
+ mergedElement.descriptor = descriptor_CbYCr;
+ else
+ mergedElement.descriptor = descriptor_CbYACrYA;
+ 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))
+ sortedElementData[0] = i;
+ else
+ sortedElementData[1] = i;
+ break;
+
+ case descriptor_Chrominance:
+ if (mergedElement.descriptor == -1)
+ mergedElement.descriptor = descriptor_Chrominance;
+ else if (mergedElement.descriptor == descriptor_Luminance) {
+ if (mergedElement.depth == 2)
+ mergedElement.descriptor = descriptor_CbYCrY;
+ else if (mergedElement.depth == 3)
+ if (hasAlpha == 0)
+ mergedElement.descriptor = descriptor_CbYCr;
+ else
+ mergedElement.descriptor = descriptor_CbYACrYA;
+ else if (mergedElement.depth == 4)
+ mergedElement.descriptor = descriptor_CbYCrA;
+ }
+
+ /* Cb and Cr always in 0 or 2 */
+ if (sortedElementData[0] == -1)
+ sortedElementData[0] = i;
+ else
+ sortedElementData[2] = i;
+ break;
+
+ case descriptor_CbYCr:
+ if (hasAlpha == 0)
+ mergedElement.descriptor = descriptor_CbYCr;
+ else
+ mergedElement.descriptor = descriptor_CbYCrA;
+
+ sortedElementData[0] = i;
+ break;
+
+ case descriptor_RGBA:
+ case descriptor_ABGR:
+ case descriptor_CbYACrYA:
+ case descriptor_CbYCrY:
+ case descriptor_CbYCrA:
+ /* I don't think these ones can be seen in a planar image */
+ mergedElement.descriptor = logImage->element[i].descriptor;
+ sortedElementData[0] = i;
+ break;
+
+ case descriptor_Depth:
+ case descriptor_Composite:
+ /* Not supported */
+ break;
+ }
+ }
+
+ mergedData = (float *)imb_alloc_pixels(
+ logImage->width, logImage->height, mergedElement.depth, sizeof(float), __func__);
+ if (mergedData == NULL) {
+ if (verbose)
+ printf("DPX/Cineon: Cannot allocate mergedData.\n");
+ 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++)
+ mergedData[sampleIndex++] = *(elementData_ptr[sortedElementData[i]]++);
+ }
+
+ /* Done with elements data, clean-up */
+ for (i = 0; i < logImage->numElements; i++)
+ if (elementData[i] != NULL)
+ MEM_freeN(elementData[i]);
+
+ returnValue = convertLogElementToRGBA(
+ mergedData, data, logImage, mergedElement, dataIsLinearRGB);
+ MEM_freeN(mergedData);
+ }
+ return returnValue;
}
static int logImageElementGetData(LogImageFile *logImage, LogImageElement logElement, float *data)
{
- switch (logElement.bitsPerSample) {
- case 1:
- return logImageElementGetData1(logImage, logElement, data);
-
- case 8:
- return logImageElementGetData8(logImage, logElement, data);
-
- case 10:
- if (logElement.packing == 0)
- return logImageElementGetData10Packed(logImage, logElement, data);
- else if (logElement.packing == 1 || logElement.packing == 2)
- return logImageElementGetData10(logImage, logElement, data);
- break;
-
- case 12:
- if (logElement.packing == 0)
- return logImageElementGetData12Packed(logImage, logElement, data);
- else if (logElement.packing == 1 || logElement.packing == 2)
- return logImageElementGetData12(logImage, logElement, data);
- break;
-
- case 16:
- return logImageElementGetData16(logImage, logElement, data);
- }
- /* format not supported */
- return 1;
+ switch (logElement.bitsPerSample) {
+ case 1:
+ return logImageElementGetData1(logImage, logElement, data);
+
+ case 8:
+ return logImageElementGetData8(logImage, logElement, data);
+
+ case 10:
+ if (logElement.packing == 0)
+ return logImageElementGetData10Packed(logImage, logElement, data);
+ else if (logElement.packing == 1 || logElement.packing == 2)
+ return logImageElementGetData10(logImage, logElement, data);
+ break;
+
+ case 12:
+ if (logElement.packing == 0)
+ return logImageElementGetData12Packed(logImage, logElement, data);
+ else if (logElement.packing == 1 || logElement.packing == 2)
+ return logImageElementGetData12(logImage, logElement, data);
+ break;
+
+ case 16:
+ return logImageElementGetData16(logImage, logElement, data);
+ }
+ /* format not supported */
+ return 1;
}
static int logImageElementGetData1(LogImageFile *logImage, LogImageElement logElement, float *data)
{
- unsigned int pixel;
-
- /* seek at the right place */
- if (logimage_fseek(logImage, logElement.dataOffset, SEEK_SET) != 0) {
- if (verbose) printf("DPX/Cineon: Couldn't seek at %d\n", logElement.dataOffset);
- return 1;
- }
-
- /* read 1 bit data padded to 32 bits */
- 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) 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++)
- data[y * logImage->width * logElement.depth + x + offset] = (float)((pixel >> offset) & 0x01);
- }
- }
- return 0;
+ unsigned int pixel;
+
+ /* seek at the right place */
+ if (logimage_fseek(logImage, logElement.dataOffset, SEEK_SET) != 0) {
+ if (verbose)
+ printf("DPX/Cineon: Couldn't seek at %d\n", logElement.dataOffset);
+ return 1;
+ }
+
+ /* read 1 bit data padded to 32 bits */
+ 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)
+ 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++)
+ data[y * logImage->width * logElement.depth + x + offset] = (float)((pixel >> offset) &
+ 0x01);
+ }
+ }
+ return 0;
}
static int logImageElementGetData8(LogImageFile *logImage, LogImageElement logElement, float *data)
{
- size_t rowLength = getRowLength(logImage->width, logElement);
- unsigned char pixel;
-
- /* extract required pixels */
- 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) 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) printf("DPX/Cineon: EOF reached\n");
- return 1;
- }
- data[y * logImage->width * logElement.depth + x] = (float)pixel / 255.0f;
- }
- }
- return 0;
+ size_t rowLength = getRowLength(logImage->width, logElement);
+ unsigned char pixel;
+
+ /* extract required pixels */
+ 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)
+ 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)
+ printf("DPX/Cineon: EOF reached\n");
+ return 1;
+ }
+ data[y * logImage->width * logElement.depth + x] = (float)pixel / 255.0f;
+ }
+ }
+ return 0;
}
-static int logImageElementGetData10(LogImageFile *logImage, LogImageElement logElement, float *data)
+static int logImageElementGetData10(LogImageFile *logImage,
+ LogImageElement logElement,
+ float *data)
{
- unsigned int pixel;
-
- /* seek to data */
- if (logimage_fseek(logImage, logElement.dataOffset, SEEK_SET) != 0) {
- if (verbose) printf("DPX/Cineon: Couldn't seek at %d\n", logElement.dataOffset);
- return 1;
- }
-
- if (logImage->depth == 1 && logImage->srcFormat == format_DPX) {
- for (size_t y = 0; y < logImage->height; y++) {
- int offset = 32;
- 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)
- offset = 2;
- else if (logElement.packing == 2)
- offset = 0;
-
- if (logimage_read_uint(&pixel, logImage) != 0) {
- if (verbose) printf("DPX/Cineon: EOF reached\n");
- return 1;
- }
- pixel = swap_uint(pixel, logImage->isMSB);
- }
- data[y * logImage->width * logElement.depth + x] = (float)((pixel >> offset) & 0x3ff) / 1023.0f;
- offset += 10;
- }
- }
- }
- else {
- for (size_t y = 0; y < logImage->height; y++) {
- int offset = -1;
- 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)
- offset = 22;
- else if (logElement.packing == 2)
- offset = 20;
-
- if (logimage_read_uint(&pixel, logImage) != 0) {
- if (verbose) printf("DPX/Cineon: EOF reached\n");
- return 1;
- }
- pixel = swap_uint(pixel, logImage->isMSB);
- }
- data[y * logImage->width * logElement.depth + x] = (float)((pixel >> offset) & 0x3ff) / 1023.0f;
- offset -= 10;
- }
- }
- }
-
- return 0;
+ unsigned int pixel;
+
+ /* seek to data */
+ if (logimage_fseek(logImage, logElement.dataOffset, SEEK_SET) != 0) {
+ if (verbose)
+ printf("DPX/Cineon: Couldn't seek at %d\n", logElement.dataOffset);
+ return 1;
+ }
+
+ if (logImage->depth == 1 && logImage->srcFormat == format_DPX) {
+ for (size_t y = 0; y < logImage->height; y++) {
+ int offset = 32;
+ 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)
+ offset = 2;
+ else if (logElement.packing == 2)
+ offset = 0;
+
+ if (logimage_read_uint(&pixel, logImage) != 0) {
+ if (verbose)
+ printf("DPX/Cineon: EOF reached\n");
+ return 1;
+ }
+ pixel = swap_uint(pixel, logImage->isMSB);
+ }
+ data[y * logImage->width * logElement.depth + x] = (float)((pixel >> offset) & 0x3ff) /
+ 1023.0f;
+ offset += 10;
+ }
+ }
+ }
+ else {
+ for (size_t y = 0; y < logImage->height; y++) {
+ int offset = -1;
+ 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)
+ offset = 22;
+ else if (logElement.packing == 2)
+ offset = 20;
+
+ if (logimage_read_uint(&pixel, logImage) != 0) {
+ if (verbose)
+ printf("DPX/Cineon: EOF reached\n");
+ return 1;
+ }
+ pixel = swap_uint(pixel, logImage->isMSB);
+ }
+ data[y * logImage->width * logElement.depth + x] = (float)((pixel >> offset) & 0x3ff) /
+ 1023.0f;
+ offset -= 10;
+ }
+ }
+ }
+
+ return 0;
}
-static int logImageElementGetData10Packed(LogImageFile *logImage, LogImageElement logElement, float *data)
+static int logImageElementGetData10Packed(LogImageFile *logImage,
+ LogImageElement logElement,
+ float *data)
{
- size_t rowLength = getRowLength(logImage->width, logElement);
- unsigned int pixel, oldPixel;
-
- /* converting bytes to pixels */
- 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) printf("DPX/Cineon: Couldn't seek at %u\n", (unsigned int)(y * rowLength + logElement.dataOffset));
- return 1;
- }
-
- oldPixel = 0;
- int offset = 0;
- int offset2 = 0;
-
- for (size_t x = 0; x < logImage->width * logElement.depth; x++) {
- if (offset2 != 0) {
- offset = 10 - offset2;
- offset2 = 0;
- oldPixel = 0;
- }
- else if (offset == 32) {
- offset = 0;
- }
- else if (offset + 10 > 32) {
- /* next pixel is on two different longs */
- oldPixel = (pixel >> offset);
- offset2 = 32 - offset;
- offset = 0;
- }
-
- if (offset == 0) {
- /* we need to read the next long */
- if (logimage_read_uint(&pixel, logImage) != 0) {
- if (verbose) printf("DPX/Cineon: EOF reached\n");
- return 1;
- }
- pixel = swap_uint(pixel, logImage->isMSB);
- }
- data[y * logImage->width * logElement.depth + x] = (float)((((pixel << offset2) >> offset) & 0x3ff) | oldPixel) / 1023.0f;
- offset += 10;
- }
- }
- return 0;
+ size_t rowLength = getRowLength(logImage->width, logElement);
+ unsigned int pixel, oldPixel;
+
+ /* converting bytes to pixels */
+ 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)
+ printf("DPX/Cineon: Couldn't seek at %u\n",
+ (unsigned int)(y * rowLength + logElement.dataOffset));
+ return 1;
+ }
+
+ oldPixel = 0;
+ int offset = 0;
+ int offset2 = 0;
+
+ for (size_t x = 0; x < logImage->width * logElement.depth; x++) {
+ if (offset2 != 0) {
+ offset = 10 - offset2;
+ offset2 = 0;
+ oldPixel = 0;
+ }
+ else if (offset == 32) {
+ offset = 0;
+ }
+ else if (offset + 10 > 32) {
+ /* next pixel is on two different longs */
+ oldPixel = (pixel >> offset);
+ offset2 = 32 - offset;
+ offset = 0;
+ }
+
+ if (offset == 0) {
+ /* we need to read the next long */
+ if (logimage_read_uint(&pixel, logImage) != 0) {
+ if (verbose)
+ printf("DPX/Cineon: EOF reached\n");
+ return 1;
+ }
+ pixel = swap_uint(pixel, logImage->isMSB);
+ }
+ data[y * logImage->width * logElement.depth + x] =
+ (float)((((pixel << offset2) >> offset) & 0x3ff) | oldPixel) / 1023.0f;
+ offset += 10;
+ }
+ }
+ return 0;
}
-static int logImageElementGetData12(LogImageFile *logImage, LogImageElement logElement, float *data)
+static int logImageElementGetData12(LogImageFile *logImage,
+ LogImageElement logElement,
+ float *data)
{
- unsigned int sampleIndex;
- unsigned int numSamples = logImage->width * logImage->height * logElement.depth;
- unsigned short pixel;
-
- /* seek to data */
- if (logimage_fseek(logImage, logElement.dataOffset, SEEK_SET) != 0) {
- if (verbose) printf("DPX/Cineon: Couldn't seek at %d\n", logElement.dataOffset);
- return 1;
- }
-
- /* convert bytes to pixels */
- sampleIndex = 0;
-
- for (sampleIndex = 0; sampleIndex < numSamples; sampleIndex++) {
- if (logimage_read_ushort(&pixel, logImage) != 0) {
- if (verbose) printf("DPX/Cineon: EOF reached\n");
- return 1;
- }
- pixel = swap_ushort(pixel, logImage->isMSB);
-
- if (logElement.packing == 1) /* padded to the right */
- data[sampleIndex] = (float)(pixel >> 4) / 4095.0f;
- else if (logElement.packing == 2) /* padded to the left */
- data[sampleIndex] = (float)pixel / 4095.0f;
- }
- return 0;
+ unsigned int sampleIndex;
+ unsigned int numSamples = logImage->width * logImage->height * logElement.depth;
+ unsigned short pixel;
+
+ /* seek to data */
+ if (logimage_fseek(logImage, logElement.dataOffset, SEEK_SET) != 0) {
+ if (verbose)
+ printf("DPX/Cineon: Couldn't seek at %d\n", logElement.dataOffset);
+ return 1;
+ }
+
+ /* convert bytes to pixels */
+ sampleIndex = 0;
+
+ for (sampleIndex = 0; sampleIndex < numSamples; sampleIndex++) {
+ if (logimage_read_ushort(&pixel, logImage) != 0) {
+ if (verbose)
+ printf("DPX/Cineon: EOF reached\n");
+ return 1;
+ }
+ pixel = swap_ushort(pixel, logImage->isMSB);
+
+ if (logElement.packing == 1) /* padded to the right */
+ data[sampleIndex] = (float)(pixel >> 4) / 4095.0f;
+ else if (logElement.packing == 2) /* padded to the left */
+ data[sampleIndex] = (float)pixel / 4095.0f;
+ }
+ return 0;
}
-static int logImageElementGetData12Packed(LogImageFile *logImage, LogImageElement logElement, float *data)
+static int logImageElementGetData12Packed(LogImageFile *logImage,
+ LogImageElement logElement,
+ float *data)
{
- size_t rowLength = getRowLength(logImage->width, logElement);
- unsigned int pixel, oldPixel;
-
- /* converting bytes to pixels */
- 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) printf("DPX/Cineon: Couldn't seek at %u\n", (unsigned int)(y * rowLength + logElement.dataOffset));
- return 1;
- }
-
- oldPixel = 0;
- int offset = 0;
- int offset2 = 0;
-
- for (size_t x = 0; x < logImage->width * logElement.depth; x++) {
- if (offset2 != 0) {
- offset = 12 - offset2;
- offset2 = 0;
- oldPixel = 0;
- }
- else if (offset == 32) {
- offset = 0;
- }
- else if (offset + 12 > 32) {
- /* next pixel is on two different longs */
- oldPixel = (pixel >> offset);
- offset2 = 32 - offset;
- offset = 0;
- }
-
- if (offset == 0) {
- /* we need to read the next long */
- if (logimage_read_uint(&pixel, logImage) != 0) {
- if (verbose) printf("DPX/Cineon: EOF reached\n");
- return 1;
- }
- pixel = swap_uint(pixel, logImage->isMSB);
- }
- data[y * logImage->width * logElement.depth + x] = (float)((((pixel << offset2) >> offset) & 0xfff) | oldPixel) / 4095.0f;
- offset += 12;
- }
- }
- return 0;
+ size_t rowLength = getRowLength(logImage->width, logElement);
+ unsigned int pixel, oldPixel;
+
+ /* converting bytes to pixels */
+ 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)
+ printf("DPX/Cineon: Couldn't seek at %u\n",
+ (unsigned int)(y * rowLength + logElement.dataOffset));
+ return 1;
+ }
+
+ oldPixel = 0;
+ int offset = 0;
+ int offset2 = 0;
+
+ for (size_t x = 0; x < logImage->width * logElement.depth; x++) {
+ if (offset2 != 0) {
+ offset = 12 - offset2;
+ offset2 = 0;
+ oldPixel = 0;
+ }
+ else if (offset == 32) {
+ offset = 0;
+ }
+ else if (offset + 12 > 32) {
+ /* next pixel is on two different longs */
+ oldPixel = (pixel >> offset);
+ offset2 = 32 - offset;
+ offset = 0;
+ }
+
+ if (offset == 0) {
+ /* we need to read the next long */
+ if (logimage_read_uint(&pixel, logImage) != 0) {
+ if (verbose)
+ printf("DPX/Cineon: EOF reached\n");
+ return 1;
+ }
+ pixel = swap_uint(pixel, logImage->isMSB);
+ }
+ data[y * logImage->width * logElement.depth + x] =
+ (float)((((pixel << offset2) >> offset) & 0xfff) | oldPixel) / 4095.0f;
+ offset += 12;
+ }
+ }
+ return 0;
}
-static int logImageElementGetData16(LogImageFile *logImage, LogImageElement logElement, float *data)
+static int logImageElementGetData16(LogImageFile *logImage,
+ LogImageElement logElement,
+ float *data)
{
- unsigned int numSamples = logImage->width * logImage->height * logElement.depth;
- unsigned int sampleIndex;
- unsigned short pixel;
-
- /* seek to data */
- if (logimage_fseek(logImage, logElement.dataOffset, SEEK_SET) != 0) {
- 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) printf("DPX/Cineon: EOF reached\n");
- return 1;
- }
- pixel = swap_ushort(pixel, logImage->isMSB);
- data[sampleIndex] = (float)pixel / 65535.0f;
- }
-
- return 0;
+ unsigned int numSamples = logImage->width * logImage->height * logElement.depth;
+ unsigned int sampleIndex;
+ unsigned short pixel;
+
+ /* seek to data */
+ if (logimage_fseek(logImage, logElement.dataOffset, SEEK_SET) != 0) {
+ 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)
+ printf("DPX/Cineon: EOF reached\n");
+ return 1;
+ }
+ pixel = swap_ushort(pixel, logImage->isMSB);
+ data[sampleIndex] = (float)pixel / 65535.0f;
+ }
+
+ return 0;
}
-
/*
* Color conversion
*/
static int getYUVtoRGBMatrix(float *matrix, LogImageElement logElement)
{
- float scaleY, scaleCbCr;
- float refHighData = (float)logElement.refHighData / logElement.maxValue;
- float refLowData = (float)logElement.refLowData / logElement.maxValue;
-
- scaleY = 1.0f / (refHighData - refLowData);
- scaleCbCr = scaleY * ((940.0f - 64.0f) / (960.0f - 64.0f));
-
- switch (logElement.transfer) {
- case 2: /* linear */
- matrix[0] = 1.0f * scaleY;
- matrix[1] = 1.0f * scaleCbCr;
- matrix[2] = 1.0f * scaleCbCr;
- matrix[3] = 1.0f * scaleY;
- matrix[4] = 1.0f * scaleCbCr;
- matrix[5] = 1.0f * scaleCbCr;
- matrix[6] = 1.0f * scaleY;
- matrix[7] = 1.0f * scaleCbCr;
- matrix[8] = 1.0f * scaleCbCr;
- return 0;
-
- case 5: /* SMPTE 240M */
- matrix[0] = 1.0000f * scaleY;
- matrix[1] = 0.0000f * scaleCbCr;
- matrix[2] = 1.5756f * scaleCbCr;
- matrix[3] = 1.0000f * scaleY;
- matrix[4] = -0.2253f * scaleCbCr;
- matrix[5] = -0.5000f * scaleCbCr;
- matrix[6] = 1.0000f * scaleY;
- matrix[7] = 1.8270f * scaleCbCr;
- matrix[8] = 0.0000f * scaleCbCr;
- return 0;
-
- case 6: /* CCIR 709-1 */
- matrix[0] = 1.000000f * scaleY;
- matrix[1] = 0.000000f * scaleCbCr;
- matrix[2] = 1.574800f * scaleCbCr;
- matrix[3] = 1.000000f * scaleY;
- matrix[4] = -0.187324f * scaleCbCr;
- matrix[5] = -0.468124f * scaleCbCr;
- matrix[6] = 1.000000f * scaleY;
- matrix[7] = 1.855600f * scaleCbCr;
- matrix[8] = 0.000000f * scaleCbCr;
- return 0;
-
- case 7: /* CCIR 601 */
- case 8: /* I'm not sure 7 and 8 should share the same matrix */
- matrix[0] = 1.000000f * scaleY;
- matrix[1] = 0.000000f * scaleCbCr;
- matrix[2] = 1.402000f * scaleCbCr;
- matrix[3] = 1.000000f * scaleY;
- matrix[4] = -0.344136f * scaleCbCr;
- matrix[5] = -0.714136f * scaleCbCr;
- matrix[6] = 1.000000f * scaleY;
- matrix[7] = 1.772000f * scaleCbCr;
- matrix[8] = 0.000000f * scaleCbCr;
- return 0;
-
- default:
- return 1;
- }
+ float scaleY, scaleCbCr;
+ float refHighData = (float)logElement.refHighData / logElement.maxValue;
+ float refLowData = (float)logElement.refLowData / logElement.maxValue;
+
+ scaleY = 1.0f / (refHighData - refLowData);
+ scaleCbCr = scaleY * ((940.0f - 64.0f) / (960.0f - 64.0f));
+
+ switch (logElement.transfer) {
+ case 2: /* linear */
+ matrix[0] = 1.0f * scaleY;
+ matrix[1] = 1.0f * scaleCbCr;
+ matrix[2] = 1.0f * scaleCbCr;
+ matrix[3] = 1.0f * scaleY;
+ matrix[4] = 1.0f * scaleCbCr;
+ matrix[5] = 1.0f * scaleCbCr;
+ matrix[6] = 1.0f * scaleY;
+ matrix[7] = 1.0f * scaleCbCr;
+ matrix[8] = 1.0f * scaleCbCr;
+ return 0;
+
+ case 5: /* SMPTE 240M */
+ matrix[0] = 1.0000f * scaleY;
+ matrix[1] = 0.0000f * scaleCbCr;
+ matrix[2] = 1.5756f * scaleCbCr;
+ matrix[3] = 1.0000f * scaleY;
+ matrix[4] = -0.2253f * scaleCbCr;
+ matrix[5] = -0.5000f * scaleCbCr;
+ matrix[6] = 1.0000f * scaleY;
+ matrix[7] = 1.8270f * scaleCbCr;
+ matrix[8] = 0.0000f * scaleCbCr;
+ return 0;
+
+ case 6: /* CCIR 709-1 */
+ matrix[0] = 1.000000f * scaleY;
+ matrix[1] = 0.000000f * scaleCbCr;
+ matrix[2] = 1.574800f * scaleCbCr;
+ matrix[3] = 1.000000f * scaleY;
+ matrix[4] = -0.187324f * scaleCbCr;
+ matrix[5] = -0.468124f * scaleCbCr;
+ matrix[6] = 1.000000f * scaleY;
+ matrix[7] = 1.855600f * scaleCbCr;
+ matrix[8] = 0.000000f * scaleCbCr;
+ return 0;
+
+ case 7: /* CCIR 601 */
+ case 8: /* I'm not sure 7 and 8 should share the same matrix */
+ matrix[0] = 1.000000f * scaleY;
+ matrix[1] = 0.000000f * scaleCbCr;
+ matrix[2] = 1.402000f * scaleCbCr;
+ matrix[3] = 1.000000f * scaleY;
+ matrix[4] = -0.344136f * scaleCbCr;
+ matrix[5] = -0.714136f * scaleCbCr;
+ matrix[6] = 1.000000f * scaleY;
+ matrix[7] = 1.772000f * scaleCbCr;
+ matrix[8] = 0.000000f * scaleCbCr;
+ return 0;
+
+ default:
+ return 1;
+ }
}
static float *getLinToLogLut(LogImageFile *logImage, LogImageElement logElement)
{
- float *lut;
- float gain, negativeFilmGamma, offset, step;
- unsigned int lutsize = (unsigned int)(logElement.maxValue + 1);
- unsigned int i;
-
- lut = MEM_mallocN(sizeof(float) * lutsize, "getLinToLogLut");
-
- negativeFilmGamma = 0.6;
- step = logElement.refHighQuantity / logElement.maxValue;
- gain = logElement.maxValue / (1.0f - powf(10, (logImage->referenceBlack - logImage->referenceWhite) * step / negativeFilmGamma * logImage->gamma / 1.7f));
- offset = gain - logElement.maxValue;
-
- 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;
+ float *lut;
+ float gain, negativeFilmGamma, offset, step;
+ unsigned int lutsize = (unsigned int)(logElement.maxValue + 1);
+ unsigned int i;
+
+ lut = MEM_mallocN(sizeof(float) * lutsize, "getLinToLogLut");
+
+ negativeFilmGamma = 0.6;
+ step = logElement.refHighQuantity / logElement.maxValue;
+ gain = logElement.maxValue /
+ (1.0f - powf(10,
+ (logImage->referenceBlack - logImage->referenceWhite) * step /
+ negativeFilmGamma * logImage->gamma / 1.7f));
+ offset = gain - logElement.maxValue;
+
+ 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;
}
static float *getLogToLinLut(LogImageFile *logImage, LogImageElement logElement)
{
- float *lut;
- float breakPoint, gain, kneeGain, kneeOffset, negativeFilmGamma, offset, step, softClip;
- /* float filmGamma; unused */
- unsigned int lutsize = (unsigned int)(logElement.maxValue + 1);
- unsigned int i;
-
- lut = MEM_mallocN(sizeof(float) * lutsize, "getLogToLinLut");
-
- /* Building the Log -> Lin LUT */
- step = logElement.refHighQuantity / logElement.maxValue;
- negativeFilmGamma = 0.6;
-
- /* these are default values */
- /* filmGamma = 2.2f; unused */
- softClip = 0;
-
- breakPoint = logImage->referenceWhite - softClip;
- gain = logElement.maxValue / (1.0f - powf(10, (logImage->referenceBlack - logImage->referenceWhite) * step / negativeFilmGamma * logImage->gamma / 1.7f));
- offset = gain - logElement.maxValue;
- kneeOffset = powf(10, (breakPoint - logImage->referenceWhite) * step / negativeFilmGamma * logImage->gamma / 1.7f) * gain - offset;
- kneeGain = (logElement.maxValue - kneeOffset) / powf(5 * softClip, softClip / 100);
-
- for (i = 0; i < lutsize; i++) {
- if (i < logImage->referenceBlack)
- lut[i] = 0.0f;
- else if (i > breakPoint)
- lut[i] = (powf(i - breakPoint, softClip / 100) * kneeGain + kneeOffset) / logElement.maxValue;
- else
- lut[i] = (powf(10, ((float)i - logImage->referenceWhite) * step / negativeFilmGamma * logImage->gamma / 1.7f) * gain - offset) / logElement.maxValue;
- }
-
- return lut;
+ float *lut;
+ float breakPoint, gain, kneeGain, kneeOffset, negativeFilmGamma, offset, step, softClip;
+ /* float filmGamma; unused */
+ unsigned int lutsize = (unsigned int)(logElement.maxValue + 1);
+ unsigned int i;
+
+ lut = MEM_mallocN(sizeof(float) * lutsize, "getLogToLinLut");
+
+ /* Building the Log -> Lin LUT */
+ step = logElement.refHighQuantity / logElement.maxValue;
+ negativeFilmGamma = 0.6;
+
+ /* these are default values */
+ /* filmGamma = 2.2f; unused */
+ softClip = 0;
+
+ breakPoint = logImage->referenceWhite - softClip;
+ gain = logElement.maxValue /
+ (1.0f - powf(10,
+ (logImage->referenceBlack - logImage->referenceWhite) * step /
+ negativeFilmGamma * logImage->gamma / 1.7f));
+ offset = gain - logElement.maxValue;
+ kneeOffset = powf(10,
+ (breakPoint - logImage->referenceWhite) * step / negativeFilmGamma *
+ logImage->gamma / 1.7f) *
+ gain -
+ offset;
+ kneeGain = (logElement.maxValue - kneeOffset) / powf(5 * softClip, softClip / 100);
+
+ for (i = 0; i < lutsize; i++) {
+ if (i < logImage->referenceBlack)
+ lut[i] = 0.0f;
+ else if (i > breakPoint)
+ lut[i] = (powf(i - breakPoint, softClip / 100) * kneeGain + kneeOffset) /
+ logElement.maxValue;
+ else
+ lut[i] = (powf(10,
+ ((float)i - logImage->referenceWhite) * step / negativeFilmGamma *
+ logImage->gamma / 1.7f) *
+ gain -
+ offset) /
+ logElement.maxValue;
+ }
+
+ return lut;
}
static float *getLinToSrgbLut(LogImageElement logElement)
{
- float col, *lut;
- unsigned int lutsize = (unsigned int)(logElement.maxValue + 1);
- unsigned int i;
+ float col, *lut;
+ unsigned int lutsize = (unsigned int)(logElement.maxValue + 1);
+ unsigned int i;
- lut = MEM_mallocN(sizeof(float) * lutsize, "getLogToLinLut");
+ lut = MEM_mallocN(sizeof(float) * lutsize, "getLogToLinLut");
- for (i = 0; i < lutsize; i++) {
- col = (float)i / logElement.maxValue;
- if (col < 0.0031308f)
- lut[i] = (col < 0.0f) ? 0.0f : col * 12.92f;
- else
- lut[i] = 1.055f * powf(col, 1.0f / 2.4f) - 0.055f;
- }
+ for (i = 0; i < lutsize; i++) {
+ col = (float)i / logElement.maxValue;
+ if (col < 0.0031308f)
+ lut[i] = (col < 0.0f) ? 0.0f : col * 12.92f;
+ else
+ lut[i] = 1.055f * powf(col, 1.0f / 2.4f) - 0.055f;
+ }
- return lut;
+ return lut;
}
static float *getSrgbToLinLut(LogImageElement logElement)
{
- float col, *lut;
- unsigned int lutsize = (unsigned int)(logElement.maxValue + 1);
- unsigned int i;
+ float col, *lut;
+ unsigned int lutsize = (unsigned int)(logElement.maxValue + 1);
+ unsigned int i;
- lut = MEM_mallocN(sizeof(float) * lutsize, "getLogToLinLut");
+ lut = MEM_mallocN(sizeof(float) * lutsize, "getLogToLinLut");
- for (i = 0; i < lutsize; i++) {
- col = (float)i / logElement.maxValue;
- if (col < 0.04045f)
- lut[i] = (col < 0.0f) ? 0.0f : col * (1.0f / 12.92f);
- else
- lut[i] = powf((col + 0.055f) * (1.0f / 1.055f), 2.4f);
- }
+ for (i = 0; i < lutsize; i++) {
+ col = (float)i / logElement.maxValue;
+ if (col < 0.04045f)
+ lut[i] = (col < 0.0f) ? 0.0f : col * (1.0f / 12.92f);
+ else
+ lut[i] = powf((col + 0.055f) * (1.0f / 1.055f), 2.4f);
+ }
- return lut;
+ return lut;
}
-static int convertRGBA_RGB(float *src, float *dst, LogImageFile *logImage,
- LogImageElement logElement, int elementIsSource)
+static int convertRGBA_RGB(float *src,
+ float *dst,
+ LogImageFile *logImage,
+ LogImageElement logElement,
+ int elementIsSource)
{
- unsigned int i;
- float *src_ptr = src;
- float *dst_ptr = dst;
-
- switch (logElement.transfer) {
- case transfer_Unspecified:
- case transfer_UserDefined:
- case transfer_Linear:
- case transfer_Logarithmic: {
- for (i = 0; i < logImage->width * logImage->height; i++) {
- *(dst_ptr++) = *(src_ptr++);
- *(dst_ptr++) = *(src_ptr++);
- *(dst_ptr++) = *(src_ptr++);
- src_ptr++;
- }
-
- return 0;
- }
-
- case transfer_PrintingDensity: {
- float *lut;
-
- if (elementIsSource == 1)
- lut = getLogToLinLut(logImage, logElement);
- else
- lut = getLinToLogLut(logImage, logElement);
-
- for (i = 0; i < logImage->width * logImage->height; i++) {
- *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
- *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
- *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
- src_ptr++;
- }
-
- MEM_freeN(lut);
-
- return 0;
- }
-
- default:
- if (verbose) printf("DPX/Cineon: Unknown transfer %d.\n", logElement.transfer);
- return 1;
- }
+ unsigned int i;
+ float *src_ptr = src;
+ float *dst_ptr = dst;
+
+ switch (logElement.transfer) {
+ case transfer_Unspecified:
+ case transfer_UserDefined:
+ case transfer_Linear:
+ case transfer_Logarithmic: {
+ for (i = 0; i < logImage->width * logImage->height; i++) {
+ *(dst_ptr++) = *(src_ptr++);
+ *(dst_ptr++) = *(src_ptr++);
+ *(dst_ptr++) = *(src_ptr++);
+ src_ptr++;
+ }
+
+ return 0;
+ }
+
+ case transfer_PrintingDensity: {
+ float *lut;
+
+ if (elementIsSource == 1)
+ lut = getLogToLinLut(logImage, logElement);
+ else
+ lut = getLinToLogLut(logImage, logElement);
+
+ for (i = 0; i < logImage->width * logImage->height; i++) {
+ *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
+ *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
+ *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
+ src_ptr++;
+ }
+
+ MEM_freeN(lut);
+
+ return 0;
+ }
+
+ default:
+ if (verbose)
+ printf("DPX/Cineon: Unknown transfer %d.\n", logElement.transfer);
+ return 1;
+ }
}
-static int convertRGB_RGBA(float *src, float *dst, LogImageFile *logImage,
- LogImageElement logElement, int elementIsSource)
+static int convertRGB_RGBA(float *src,
+ float *dst,
+ LogImageFile *logImage,
+ LogImageElement logElement,
+ int elementIsSource)
{
- unsigned int i;
- float *src_ptr = src;
- float *dst_ptr = dst;
-
- switch (logElement.transfer) {
- case transfer_Unspecified:
- case transfer_UserDefined:
- case transfer_Linear:
- case transfer_Logarithmic: {
- for (i = 0; i < logImage->width * logImage->height; i++) {
- *(dst_ptr++) = *(src_ptr++);
- *(dst_ptr++) = *(src_ptr++);
- *(dst_ptr++) = *(src_ptr++);
- *(dst_ptr++) = 1.0f;
- }
-
- return 0;
- }
-
- case transfer_PrintingDensity: {
- float *lut;
-
- if (elementIsSource == 1)
- lut = getLogToLinLut(logImage, logElement);
- else
- lut = getLinToLogLut(logImage, logElement);
-
- for (i = 0; i < logImage->width * logImage->height; i++) {
- *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
- *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
- *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
- *(dst_ptr++) = 1.0f;
- }
-
- MEM_freeN(lut);
-
- return 0;
- }
-
- default:
- if (verbose) printf("DPX/Cineon: Unknown transfer %d.\n", logElement.transfer);
- return 1;
- }
+ unsigned int i;
+ float *src_ptr = src;
+ float *dst_ptr = dst;
+
+ switch (logElement.transfer) {
+ case transfer_Unspecified:
+ case transfer_UserDefined:
+ case transfer_Linear:
+ case transfer_Logarithmic: {
+ for (i = 0; i < logImage->width * logImage->height; i++) {
+ *(dst_ptr++) = *(src_ptr++);
+ *(dst_ptr++) = *(src_ptr++);
+ *(dst_ptr++) = *(src_ptr++);
+ *(dst_ptr++) = 1.0f;
+ }
+
+ return 0;
+ }
+
+ case transfer_PrintingDensity: {
+ float *lut;
+
+ if (elementIsSource == 1)
+ lut = getLogToLinLut(logImage, logElement);
+ else
+ lut = getLinToLogLut(logImage, logElement);
+
+ for (i = 0; i < logImage->width * logImage->height; i++) {
+ *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
+ *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
+ *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
+ *(dst_ptr++) = 1.0f;
+ }
+
+ MEM_freeN(lut);
+
+ return 0;
+ }
+
+ default:
+ if (verbose)
+ printf("DPX/Cineon: Unknown transfer %d.\n", logElement.transfer);
+ return 1;
+ }
}
-static int convertRGBA_RGBA(float *src, float *dst, LogImageFile *logImage,
- LogImageElement logElement, int elementIsSource)
+static int convertRGBA_RGBA(float *src,
+ float *dst,
+ LogImageFile *logImage,
+ LogImageElement logElement,
+ int elementIsSource)
{
- unsigned int i;
- float *src_ptr = src;
- float *dst_ptr = dst;
-
- switch (logElement.transfer) {
- case transfer_UserDefined:
- case transfer_Linear:
- case transfer_Logarithmic: {
- memcpy(dst, src, 4 * (size_t)logImage->width * (size_t)logImage->height * sizeof(float));
- return 0;
- }
-
- case transfer_PrintingDensity: {
- float *lut;
-
- if (elementIsSource == 1)
- lut = getLogToLinLut(logImage, logElement);
- else
- lut = getLinToLogLut(logImage, logElement);
-
- for (i = 0; i < logImage->width * logImage->height; i++) {
- *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
- *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
- *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
- *(dst_ptr++) = *(src_ptr++);
- }
-
- MEM_freeN(lut);
-
- return 0;
- }
-
- default:
- return 1;
- }
+ unsigned int i;
+ float *src_ptr = src;
+ float *dst_ptr = dst;
+
+ switch (logElement.transfer) {
+ case transfer_UserDefined:
+ case transfer_Linear:
+ case transfer_Logarithmic: {
+ memcpy(dst, src, 4 * (size_t)logImage->width * (size_t)logImage->height * sizeof(float));
+ return 0;
+ }
+
+ case transfer_PrintingDensity: {
+ float *lut;
+
+ if (elementIsSource == 1)
+ lut = getLogToLinLut(logImage, logElement);
+ else
+ lut = getLinToLogLut(logImage, logElement);
+
+ for (i = 0; i < logImage->width * logImage->height; i++) {
+ *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
+ *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
+ *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
+ *(dst_ptr++) = *(src_ptr++);
+ }
+
+ MEM_freeN(lut);
+
+ return 0;
+ }
+
+ default:
+ return 1;
+ }
}
-static int convertABGR_RGBA(float *src, float *dst, LogImageFile *logImage,
- LogImageElement logElement, int elementIsSource)
+static int convertABGR_RGBA(float *src,
+ float *dst,
+ LogImageFile *logImage,
+ LogImageElement logElement,
+ int elementIsSource)
{
- unsigned int i;
- float *src_ptr = src;
- float *dst_ptr = dst;
-
- switch (logElement.transfer) {
- case transfer_UserDefined:
- case transfer_Linear:
- case transfer_Logarithmic: {
- for (i = 0; i < logImage->width * logImage->height; i++) {
- src_ptr += 4;
- *(dst_ptr++) = *(src_ptr--);
- *(dst_ptr++) = *(src_ptr--);
- *(dst_ptr++) = *(src_ptr--);
- *(dst_ptr++) = *(src_ptr--);
- src_ptr += 4;
- }
- return 0;
- }
-
- case transfer_PrintingDensity: {
- float *lut;
-
- if (elementIsSource == 1)
- lut = getLogToLinLut(logImage, logElement);
- else
- lut = getLinToLogLut(logImage, logElement);
-
- for (i = 0; i < logImage->width * logImage->height; i++) {
- src_ptr += 4;
- *(dst_ptr++) = lut[float_uint(*(src_ptr--), logElement.maxValue)];
- *(dst_ptr++) = lut[float_uint(*(src_ptr--), logElement.maxValue)];
- *(dst_ptr++) = lut[float_uint(*(src_ptr--), logElement.maxValue)];
- *(dst_ptr++) = *(src_ptr--);
- src_ptr += 4;
- }
-
- MEM_freeN(lut);
-
- return 0;
- }
-
- default:
- return 1;
- }
+ unsigned int i;
+ float *src_ptr = src;
+ float *dst_ptr = dst;
+
+ switch (logElement.transfer) {
+ case transfer_UserDefined:
+ case transfer_Linear:
+ case transfer_Logarithmic: {
+ for (i = 0; i < logImage->width * logImage->height; i++) {
+ src_ptr += 4;
+ *(dst_ptr++) = *(src_ptr--);
+ *(dst_ptr++) = *(src_ptr--);
+ *(dst_ptr++) = *(src_ptr--);
+ *(dst_ptr++) = *(src_ptr--);
+ src_ptr += 4;
+ }
+ return 0;
+ }
+
+ case transfer_PrintingDensity: {
+ float *lut;
+
+ if (elementIsSource == 1)
+ lut = getLogToLinLut(logImage, logElement);
+ else
+ lut = getLinToLogLut(logImage, logElement);
+
+ for (i = 0; i < logImage->width * logImage->height; i++) {
+ src_ptr += 4;
+ *(dst_ptr++) = lut[float_uint(*(src_ptr--), logElement.maxValue)];
+ *(dst_ptr++) = lut[float_uint(*(src_ptr--), logElement.maxValue)];
+ *(dst_ptr++) = lut[float_uint(*(src_ptr--), logElement.maxValue)];
+ *(dst_ptr++) = *(src_ptr--);
+ src_ptr += 4;
+ }
+
+ MEM_freeN(lut);
+
+ return 0;
+ }
+
+ default:
+ return 1;
+ }
}
-static int convertCbYCr_RGBA(float *src, float *dst, LogImageFile *logImage, LogImageElement logElement)
+static int convertCbYCr_RGBA(float *src,
+ float *dst,
+ LogImageFile *logImage,
+ LogImageElement logElement)
{
- unsigned int i;
- float conversionMatrix[9], refLowData, y, cb, cr;
- float *src_ptr = src;
- float *dst_ptr = dst;
-
- if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0)
- return 1;
-
- refLowData = (float)logElement.refLowData / logElement.maxValue;
-
- for (i = 0; i < logImage->width * logImage->height; i++) {
- cb = *(src_ptr++) - 0.5f;
- y = *(src_ptr++) - refLowData;
- cr = *(src_ptr++) - 0.5f;
-
- *(dst_ptr++) = clamp_float(y * conversionMatrix[0] + cb * conversionMatrix[1] + cr * conversionMatrix[2], 0.0f, 1.0f);
- *(dst_ptr++) = clamp_float(y * conversionMatrix[3] + cb * conversionMatrix[4] + cr * conversionMatrix[5], 0.0f, 1.0f);
- *(dst_ptr++) = clamp_float(y * conversionMatrix[6] + cb * conversionMatrix[7] + cr * conversionMatrix[8], 0.0f, 1.0f);
- *(dst_ptr++) = 1.0f;
- }
- return 0;
+ unsigned int i;
+ float conversionMatrix[9], refLowData, y, cb, cr;
+ float *src_ptr = src;
+ float *dst_ptr = dst;
+
+ if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0)
+ return 1;
+
+ refLowData = (float)logElement.refLowData / logElement.maxValue;
+
+ for (i = 0; i < logImage->width * logImage->height; i++) {
+ cb = *(src_ptr++) - 0.5f;
+ y = *(src_ptr++) - refLowData;
+ cr = *(src_ptr++) - 0.5f;
+
+ *(dst_ptr++) = clamp_float(
+ y * conversionMatrix[0] + cb * conversionMatrix[1] + cr * conversionMatrix[2], 0.0f, 1.0f);
+ *(dst_ptr++) = clamp_float(
+ y * conversionMatrix[3] + cb * conversionMatrix[4] + cr * conversionMatrix[5], 0.0f, 1.0f);
+ *(dst_ptr++) = clamp_float(
+ y * conversionMatrix[6] + cb * conversionMatrix[7] + cr * conversionMatrix[8], 0.0f, 1.0f);
+ *(dst_ptr++) = 1.0f;
+ }
+ return 0;
}
-static int convertCbYCrA_RGBA(float *src, float *dst, LogImageFile *logImage, LogImageElement logElement)
+static int convertCbYCrA_RGBA(float *src,
+ float *dst,
+ LogImageFile *logImage,
+ LogImageElement logElement)
{
- unsigned int i;
- float conversionMatrix[9], refLowData, y, cb, cr, a;
- float *src_ptr = src;
- float *dst_ptr = dst;
-
- if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0)
- return 1;
-
- refLowData = (float)logElement.refLowData / logElement.maxValue;
-
- for (i = 0; i < logImage->width * logImage->height; i++) {
- cb = *(src_ptr++) - 0.5f;
- y = *(src_ptr++) - refLowData;
- cr = *(src_ptr++) - 0.5f;
- a = *(src_ptr++);
-
- *(dst_ptr++) = clamp_float(y * conversionMatrix[0] + cb * conversionMatrix[1] + cr * conversionMatrix[2], 0.0f, 1.0f);
- *(dst_ptr++) = clamp_float(y * conversionMatrix[3] + cb * conversionMatrix[4] + cr * conversionMatrix[5], 0.0f, 1.0f);
- *(dst_ptr++) = clamp_float(y * conversionMatrix[6] + cb * conversionMatrix[7] + cr * conversionMatrix[8], 0.0f, 1.0f);
- *(dst_ptr++) = a;
- }
- return 0;
+ unsigned int i;
+ float conversionMatrix[9], refLowData, y, cb, cr, a;
+ float *src_ptr = src;
+ float *dst_ptr = dst;
+
+ if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0)
+ return 1;
+
+ refLowData = (float)logElement.refLowData / logElement.maxValue;
+
+ for (i = 0; i < logImage->width * logImage->height; i++) {
+ cb = *(src_ptr++) - 0.5f;
+ y = *(src_ptr++) - refLowData;
+ cr = *(src_ptr++) - 0.5f;
+ a = *(src_ptr++);
+
+ *(dst_ptr++) = clamp_float(
+ y * conversionMatrix[0] + cb * conversionMatrix[1] + cr * conversionMatrix[2], 0.0f, 1.0f);
+ *(dst_ptr++) = clamp_float(
+ y * conversionMatrix[3] + cb * conversionMatrix[4] + cr * conversionMatrix[5], 0.0f, 1.0f);
+ *(dst_ptr++) = clamp_float(
+ y * conversionMatrix[6] + cb * conversionMatrix[7] + cr * conversionMatrix[8], 0.0f, 1.0f);
+ *(dst_ptr++) = a;
+ }
+ return 0;
}
-static int convertCbYCrY_RGBA(float *src, float *dst, LogImageFile *logImage, LogImageElement logElement)
+static int convertCbYCrY_RGBA(float *src,
+ float *dst,
+ LogImageFile *logImage,
+ LogImageElement logElement)
{
- unsigned int i;
- float conversionMatrix[9], refLowData, y1, y2, cb, cr;
- float *src_ptr = src;
- float *dst_ptr = dst;
-
- if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0)
- return 1;
-
- refLowData = (float)logElement.refLowData / logElement.maxValue;
-
- for (i = 0; i < logImage->width * logImage->height / 2; i++) {
- cb = *(src_ptr++) - 0.5f;
- y1 = *(src_ptr++) - refLowData;
- cr = *(src_ptr++) - 0.5f;
- y2 = *(src_ptr++) - refLowData;
-
- *(dst_ptr++) = clamp_float(y1 * conversionMatrix[0] + cb * conversionMatrix[1] + cr * conversionMatrix[2], 0.0f, 1.0f);
- *(dst_ptr++) = clamp_float(y1 * conversionMatrix[3] + cb * conversionMatrix[4] + cr * conversionMatrix[5], 0.0f, 1.0f);
- *(dst_ptr++) = clamp_float(y1 * conversionMatrix[6] + cb * conversionMatrix[7] + cr * conversionMatrix[8], 0.0f, 1.0f);
- *(dst_ptr++) = 1.0f;
- *(dst_ptr++) = clamp_float(y2 * conversionMatrix[0] + cb * conversionMatrix[1] + cr * conversionMatrix[2], 0.0f, 1.0f);
- *(dst_ptr++) = clamp_float(y2 * conversionMatrix[3] + cb * conversionMatrix[4] + cr * conversionMatrix[5], 0.0f, 1.0f);
- *(dst_ptr++) = clamp_float(y2 * conversionMatrix[6] + cb * conversionMatrix[7] + cr * conversionMatrix[8], 0.0f, 1.0f);
- *(dst_ptr++) = 1.0f;
- }
- return 0;
+ unsigned int i;
+ float conversionMatrix[9], refLowData, y1, y2, cb, cr;
+ float *src_ptr = src;
+ float *dst_ptr = dst;
+
+ if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0)
+ return 1;
+
+ refLowData = (float)logElement.refLowData / logElement.maxValue;
+
+ for (i = 0; i < logImage->width * logImage->height / 2; i++) {
+ cb = *(src_ptr++) - 0.5f;
+ y1 = *(src_ptr++) - refLowData;
+ cr = *(src_ptr++) - 0.5f;
+ y2 = *(src_ptr++) - refLowData;
+
+ *(dst_ptr++) = clamp_float(y1 * conversionMatrix[0] + cb * conversionMatrix[1] +
+ cr * conversionMatrix[2],
+ 0.0f,
+ 1.0f);
+ *(dst_ptr++) = clamp_float(y1 * conversionMatrix[3] + cb * conversionMatrix[4] +
+ cr * conversionMatrix[5],
+ 0.0f,
+ 1.0f);
+ *(dst_ptr++) = clamp_float(y1 * conversionMatrix[6] + cb * conversionMatrix[7] +
+ cr * conversionMatrix[8],
+ 0.0f,
+ 1.0f);
+ *(dst_ptr++) = 1.0f;
+ *(dst_ptr++) = clamp_float(y2 * conversionMatrix[0] + cb * conversionMatrix[1] +
+ cr * conversionMatrix[2],
+ 0.0f,
+ 1.0f);
+ *(dst_ptr++) = clamp_float(y2 * conversionMatrix[3] + cb * conversionMatrix[4] +
+ cr * conversionMatrix[5],
+ 0.0f,
+ 1.0f);
+ *(dst_ptr++) = clamp_float(y2 * conversionMatrix[6] + cb * conversionMatrix[7] +
+ cr * conversionMatrix[8],
+ 0.0f,
+ 1.0f);
+ *(dst_ptr++) = 1.0f;
+ }
+ return 0;
}
-static int convertCbYACrYA_RGBA(float *src, float *dst, LogImageFile *logImage, LogImageElement logElement)
+static int convertCbYACrYA_RGBA(float *src,
+ float *dst,
+ LogImageFile *logImage,
+ LogImageElement logElement)
{
- unsigned int i;
- float conversionMatrix[9], refLowData, y1, y2, cb, cr, a1, a2;
- float *src_ptr = src;
- float *dst_ptr = dst;
-
- if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0)
- return 1;
-
- refLowData = (float)logElement.refLowData / logElement.maxValue;
-
- for (i = 0; i < logImage->width * logImage->height / 2; i++) {
- cb = *(src_ptr++) - 0.5f;
- y1 = *(src_ptr++) - refLowData;
- a1 = *(src_ptr++);
- cr = *(src_ptr++) - 0.5f;
- y2 = *(src_ptr++) - refLowData;
- a2 = *(src_ptr++);
-
- *(dst_ptr++) = clamp_float(y1 * conversionMatrix[0] + cb * conversionMatrix[1] + cr * conversionMatrix[2], 0.0f, 1.0f);
- *(dst_ptr++) = clamp_float(y1 * conversionMatrix[3] + cb * conversionMatrix[4] + cr * conversionMatrix[5], 0.0f, 1.0f);
- *(dst_ptr++) = clamp_float(y1 * conversionMatrix[6] + cb * conversionMatrix[7] + cr * conversionMatrix[8], 0.0f, 1.0f);
- *(dst_ptr++) = a1;
- *(dst_ptr++) = clamp_float(y2 * conversionMatrix[0] + cb * conversionMatrix[1] + cr * conversionMatrix[2], 0.0f, 1.0f);
- *(dst_ptr++) = clamp_float(y2 * conversionMatrix[3] + cb * conversionMatrix[4] + cr * conversionMatrix[5], 0.0f, 1.0f);
- *(dst_ptr++) = clamp_float(y2 * conversionMatrix[6] + cb * conversionMatrix[7] + cr * conversionMatrix[8], 0.0f, 1.0f);
- *(dst_ptr++) = a2;
- }
- return 0;
+ unsigned int i;
+ float conversionMatrix[9], refLowData, y1, y2, cb, cr, a1, a2;
+ float *src_ptr = src;
+ float *dst_ptr = dst;
+
+ if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0)
+ return 1;
+
+ refLowData = (float)logElement.refLowData / logElement.maxValue;
+
+ for (i = 0; i < logImage->width * logImage->height / 2; i++) {
+ cb = *(src_ptr++) - 0.5f;
+ y1 = *(src_ptr++) - refLowData;
+ a1 = *(src_ptr++);
+ cr = *(src_ptr++) - 0.5f;
+ y2 = *(src_ptr++) - refLowData;
+ a2 = *(src_ptr++);
+
+ *(dst_ptr++) = clamp_float(y1 * conversionMatrix[0] + cb * conversionMatrix[1] +
+ cr * conversionMatrix[2],
+ 0.0f,
+ 1.0f);
+ *(dst_ptr++) = clamp_float(y1 * conversionMatrix[3] + cb * conversionMatrix[4] +
+ cr * conversionMatrix[5],
+ 0.0f,
+ 1.0f);
+ *(dst_ptr++) = clamp_float(y1 * conversionMatrix[6] + cb * conversionMatrix[7] +
+ cr * conversionMatrix[8],
+ 0.0f,
+ 1.0f);
+ *(dst_ptr++) = a1;
+ *(dst_ptr++) = clamp_float(y2 * conversionMatrix[0] + cb * conversionMatrix[1] +
+ cr * conversionMatrix[2],
+ 0.0f,
+ 1.0f);
+ *(dst_ptr++) = clamp_float(y2 * conversionMatrix[3] + cb * conversionMatrix[4] +
+ cr * conversionMatrix[5],
+ 0.0f,
+ 1.0f);
+ *(dst_ptr++) = clamp_float(y2 * conversionMatrix[6] + cb * conversionMatrix[7] +
+ cr * conversionMatrix[8],
+ 0.0f,
+ 1.0f);
+ *(dst_ptr++) = a2;
+ }
+ return 0;
}
-static int convertLuminance_RGBA(float *src, float *dst, LogImageFile *logImage, LogImageElement logElement)
+static int convertLuminance_RGBA(float *src,
+ float *dst,
+ LogImageFile *logImage,
+ LogImageElement logElement)
{
- unsigned int i;
- float conversionMatrix[9], value, refLowData;
- float *src_ptr = src;
- float *dst_ptr = dst;
-
- if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0)
- return 1;
-
- refLowData = (float)logElement.refLowData / logElement.maxValue;
-
- for (i = 0; i < logImage->width * logImage->height; i++) {
- value = clamp_float((*(src_ptr++) - refLowData) * conversionMatrix[0], 0.0f, 1.0f);
- *(dst_ptr++) = value;
- *(dst_ptr++) = value;
- *(dst_ptr++) = value;
- *(dst_ptr++) = 1.0f;
- }
- return 0;
+ unsigned int i;
+ float conversionMatrix[9], value, refLowData;
+ float *src_ptr = src;
+ float *dst_ptr = dst;
+
+ if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0)
+ return 1;
+
+ refLowData = (float)logElement.refLowData / logElement.maxValue;
+
+ for (i = 0; i < logImage->width * logImage->height; i++) {
+ value = clamp_float((*(src_ptr++) - refLowData) * conversionMatrix[0], 0.0f, 1.0f);
+ *(dst_ptr++) = value;
+ *(dst_ptr++) = value;
+ *(dst_ptr++) = value;
+ *(dst_ptr++) = 1.0f;
+ }
+ return 0;
}
-static int convertYA_RGBA(float *src, float *dst, LogImageFile *logImage, LogImageElement logElement)
+static int convertYA_RGBA(float *src,
+ float *dst,
+ LogImageFile *logImage,
+ LogImageElement logElement)
{
- unsigned int i;
- float conversionMatrix[9], value, refLowData;
- float *src_ptr = src;
- float *dst_ptr = dst;
-
- if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0)
- return 1;
-
- refLowData = (float)logElement.refLowData / logElement.maxValue;
-
- for (i = 0; i < logImage->width * logImage->height; i++) {
- value = clamp_float((*(src_ptr++) - refLowData) * conversionMatrix[0], 0.0f, 1.0f);
- *(dst_ptr++) = value;
- *(dst_ptr++) = value;
- *(dst_ptr++) = value;
- *(dst_ptr++) = *(src_ptr++);
- }
- return 0;
+ unsigned int i;
+ float conversionMatrix[9], value, refLowData;
+ float *src_ptr = src;
+ float *dst_ptr = dst;
+
+ if (getYUVtoRGBMatrix((float *)&conversionMatrix, logElement) != 0)
+ return 1;
+
+ refLowData = (float)logElement.refLowData / logElement.maxValue;
+
+ for (i = 0; i < logImage->width * logImage->height; i++) {
+ value = clamp_float((*(src_ptr++) - refLowData) * conversionMatrix[0], 0.0f, 1.0f);
+ *(dst_ptr++) = value;
+ *(dst_ptr++) = value;
+ *(dst_ptr++) = value;
+ *(dst_ptr++) = *(src_ptr++);
+ }
+ return 0;
}
-static int convertLogElementToRGBA(float *src, float *dst, LogImageFile *logImage,
- LogImageElement logElement, int dstIsLinearRGB)
+static int convertLogElementToRGBA(
+ float *src, float *dst, LogImageFile *logImage, LogImageElement logElement, int dstIsLinearRGB)
{
- int rvalue;
- unsigned int i;
- float *src_ptr;
- float *dst_ptr;
-
- /* Convert data in src to linear RGBA in dst */
- switch (logElement.descriptor) {
- case descriptor_RGB:
- rvalue = convertRGB_RGBA(src, dst, logImage, logElement, 1);
- break;
-
- case descriptor_RGBA:
- rvalue = convertRGBA_RGBA(src, dst, logImage, logElement, 1);
- break;
-
- case descriptor_ABGR:
- rvalue = convertABGR_RGBA(src, dst, logImage, logElement, 1);
- break;
-
- case descriptor_Luminance:
- rvalue = convertLuminance_RGBA(src, dst, logImage, logElement);
- break;
-
- case descriptor_CbYCr:
- rvalue = convertCbYCr_RGBA(src, dst, logImage, logElement);
- break;
-
- case descriptor_CbYCrY:
- rvalue = convertCbYCrY_RGBA(src, dst, logImage, logElement);
- break;
-
- case descriptor_CbYACrYA:
- rvalue = convertCbYACrYA_RGBA(src, dst, logImage, logElement);
- break;
-
- case descriptor_CbYCrA:
- rvalue = convertCbYCrA_RGBA(src, dst, logImage, logElement);
- break;
-
- case descriptor_YA: /* this descriptor is for internal use only */
- rvalue = convertYA_RGBA(src, dst, logImage, logElement);
- break;
-
- default:
- return 1;
- }
-
- if (rvalue == 1)
- return 1;
- else if (dstIsLinearRGB) {
- /* convert data from sRGB to Linear RGB via lut */
- float *lut = getSrgbToLinLut(logElement);
- src_ptr = dst; // no error here
- dst_ptr = dst;
- for (i = 0; i < logImage->width * logImage->height; i++) {
- *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
- *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
- *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
- dst_ptr++; src_ptr++;
- }
- MEM_freeN(lut);
- }
- return 0;
+ int rvalue;
+ unsigned int i;
+ float *src_ptr;
+ float *dst_ptr;
+
+ /* Convert data in src to linear RGBA in dst */
+ switch (logElement.descriptor) {
+ case descriptor_RGB:
+ rvalue = convertRGB_RGBA(src, dst, logImage, logElement, 1);
+ break;
+
+ case descriptor_RGBA:
+ rvalue = convertRGBA_RGBA(src, dst, logImage, logElement, 1);
+ break;
+
+ case descriptor_ABGR:
+ rvalue = convertABGR_RGBA(src, dst, logImage, logElement, 1);
+ break;
+
+ case descriptor_Luminance:
+ rvalue = convertLuminance_RGBA(src, dst, logImage, logElement);
+ break;
+
+ case descriptor_CbYCr:
+ rvalue = convertCbYCr_RGBA(src, dst, logImage, logElement);
+ break;
+
+ case descriptor_CbYCrY:
+ rvalue = convertCbYCrY_RGBA(src, dst, logImage, logElement);
+ break;
+
+ case descriptor_CbYACrYA:
+ rvalue = convertCbYACrYA_RGBA(src, dst, logImage, logElement);
+ break;
+
+ case descriptor_CbYCrA:
+ rvalue = convertCbYCrA_RGBA(src, dst, logImage, logElement);
+ break;
+
+ case descriptor_YA: /* this descriptor is for internal use only */
+ rvalue = convertYA_RGBA(src, dst, logImage, logElement);
+ break;
+
+ default:
+ return 1;
+ }
+
+ if (rvalue == 1)
+ return 1;
+ else if (dstIsLinearRGB) {
+ /* convert data from sRGB to Linear RGB via lut */
+ float *lut = getSrgbToLinLut(logElement);
+ src_ptr = dst; // no error here
+ dst_ptr = dst;
+ for (i = 0; i < logImage->width * logImage->height; i++) {
+ *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
+ *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
+ *(dst_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
+ dst_ptr++;
+ src_ptr++;
+ }
+ MEM_freeN(lut);
+ }
+ return 0;
}
-static int convertRGBAToLogElement(float *src, float *dst, LogImageFile *logImage,
- LogImageElement logElement, int srcIsLinearRGB)
+static int convertRGBAToLogElement(
+ float *src, float *dst, LogImageFile *logImage, LogImageElement logElement, int srcIsLinearRGB)
{
- unsigned int i;
- int rvalue;
- float *srgbSrc;
- float *srgbSrc_ptr;
- float *src_ptr = src;
- float *lut;
-
- if (srcIsLinearRGB != 0) {
- /* we need to convert src to sRGB */
- srgbSrc = (float *)imb_alloc_pixels(logImage->width, logImage->height, 4, sizeof(float), __func__);
- if (srgbSrc == NULL)
- return 1;
-
- memcpy(srgbSrc, src, 4 * (size_t)logImage->width * (size_t)logImage->height * sizeof(float));
- srgbSrc_ptr = srgbSrc;
-
- /* convert data from Linear RGB to sRGB via lut */
- lut = getLinToSrgbLut(logElement);
- for (i = 0; i < logImage->width * logImage->height; i++) {
- *(srgbSrc_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
- *(srgbSrc_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
- *(srgbSrc_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
- srgbSrc_ptr++; src_ptr++;
- }
- MEM_freeN(lut);
- }
- else
- srgbSrc = src;
-
- /* Convert linear RGBA data in src to format described by logElement in dst */
- switch (logElement.descriptor) {
- case descriptor_RGB:
- rvalue = convertRGBA_RGB(srgbSrc, dst, logImage, logElement, 0);
- break;
-
- case descriptor_RGBA:
- rvalue = convertRGBA_RGBA(srgbSrc, dst, logImage, logElement, 0);
- break;
-
- /* these ones are not supported for the moment */
- case descriptor_ABGR:
- case descriptor_Luminance:
- case descriptor_CbYCr:
- case descriptor_CbYCrY:
- case descriptor_CbYACrYA:
- case descriptor_CbYCrA:
- case descriptor_YA: /* this descriptor is for internal use only */
- default:
- rvalue = 1;
- break;
- }
-
- if (srcIsLinearRGB != 0) {
- MEM_freeN(srgbSrc);
- }
-
- return rvalue;
+ unsigned int i;
+ int rvalue;
+ float *srgbSrc;
+ float *srgbSrc_ptr;
+ float *src_ptr = src;
+ float *lut;
+
+ if (srcIsLinearRGB != 0) {
+ /* we need to convert src to sRGB */
+ srgbSrc = (float *)imb_alloc_pixels(
+ logImage->width, logImage->height, 4, sizeof(float), __func__);
+ if (srgbSrc == NULL)
+ return 1;
+
+ memcpy(srgbSrc, src, 4 * (size_t)logImage->width * (size_t)logImage->height * sizeof(float));
+ srgbSrc_ptr = srgbSrc;
+
+ /* convert data from Linear RGB to sRGB via lut */
+ lut = getLinToSrgbLut(logElement);
+ for (i = 0; i < logImage->width * logImage->height; i++) {
+ *(srgbSrc_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
+ *(srgbSrc_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
+ *(srgbSrc_ptr++) = lut[float_uint(*(src_ptr++), logElement.maxValue)];
+ srgbSrc_ptr++;
+ src_ptr++;
+ }
+ MEM_freeN(lut);
+ }
+ else
+ srgbSrc = src;
+
+ /* Convert linear RGBA data in src to format described by logElement in dst */
+ switch (logElement.descriptor) {
+ case descriptor_RGB:
+ rvalue = convertRGBA_RGB(srgbSrc, dst, logImage, logElement, 0);
+ break;
+
+ case descriptor_RGBA:
+ rvalue = convertRGBA_RGBA(srgbSrc, dst, logImage, logElement, 0);
+ break;
+
+ /* these ones are not supported for the moment */
+ case descriptor_ABGR:
+ case descriptor_Luminance:
+ case descriptor_CbYCr:
+ case descriptor_CbYCrY:
+ case descriptor_CbYACrYA:
+ case descriptor_CbYCrA:
+ case descriptor_YA: /* this descriptor is for internal use only */
+ default:
+ rvalue = 1;
+ break;
+ }
+
+ if (srcIsLinearRGB != 0) {
+ MEM_freeN(srgbSrc);
+ }
+
+ return rvalue;
}
diff --git a/source/blender/imbuf/intern/cineon/logImageCore.h b/source/blender/imbuf/intern/cineon/logImageCore.h
index 07fe6e22d40..e01c2e0f117 100644
--- a/source/blender/imbuf/intern/cineon/logImageCore.h
+++ b/source/blender/imbuf/intern/cineon/logImageCore.h
@@ -45,51 +45,50 @@ extern "C" {
/* There are some differences between DPX and Cineon so we need to know from what type of file the datas come from */
enum format {
- format_DPX,
- format_Cineon,
+ format_DPX,
+ format_Cineon,
};
typedef struct LogImageElement {
- int depth;
- int bitsPerSample;
- int dataOffset;
- int packing;
- int transfer;
- int descriptor;
- unsigned int refLowData;
- unsigned int refHighData;
- float refLowQuantity;
- float refHighQuantity;
- float maxValue; /* = 2^bitsPerSample - 1 (used internally, doesn't come from the file header) */
+ int depth;
+ int bitsPerSample;
+ int dataOffset;
+ int packing;
+ int transfer;
+ int descriptor;
+ unsigned int refLowData;
+ unsigned int refHighData;
+ float refLowQuantity;
+ float refHighQuantity;
+ float maxValue; /* = 2^bitsPerSample - 1 (used internally, doesn't come from the file header) */
} LogImageElement;
typedef struct LogImageFile {
- /* specified in header */
- int width;
- int height;
- int numElements;
- int depth;
- LogImageElement element[8];
-
- /* used for log <-> lin conversion */
- float referenceBlack;
- float referenceWhite;
- float gamma;
-
- /* io stuff */
- FILE *file;
- unsigned char *memBuffer;
- uintptr_t memBufferSize;
- unsigned char *memCursor;
-
- /* is the file LSB or MSB ? */
- int isMSB;
-
- /* DPX or Cineon ? */
- int srcFormat;
+ /* specified in header */
+ int width;
+ int height;
+ int numElements;
+ int depth;
+ LogImageElement element[8];
+
+ /* used for log <-> lin conversion */
+ float referenceBlack;
+ float referenceWhite;
+ float gamma;
+
+ /* io stuff */
+ FILE *file;
+ unsigned char *memBuffer;
+ uintptr_t memBufferSize;
+ unsigned char *memCursor;
+
+ /* is the file LSB or MSB ? */
+ int isMSB;
+
+ /* DPX or Cineon ? */
+ int srcFormat;
} LogImageFile;
-
/* The SMPTE defines this code:
* 0 - User-defined
* 1 - Printing density
@@ -110,19 +109,19 @@ typedef struct LogImageFile {
*/
enum transfer {
- transfer_UserDefined,
- transfer_PrintingDensity,
- transfer_Linear,
- transfer_Logarithmic,
- transfer_Unspecified,
- transfer_Smpte240M,
- transfer_Ccir7091,
- transfer_Ccir6012BG,
- transfer_Ccir6012M,
- transfer_NTSC,
- transfer_PAL,
- transfer_ZLinear,
- transfer_Homogeneous,
+ transfer_UserDefined,
+ transfer_PrintingDensity,
+ transfer_Linear,
+ transfer_Logarithmic,
+ transfer_Unspecified,
+ transfer_Smpte240M,
+ transfer_Ccir7091,
+ transfer_Ccir6012BG,
+ transfer_Ccir6012M,
+ transfer_NTSC,
+ transfer_PAL,
+ transfer_ZLinear,
+ transfer_Homogeneous,
};
/* The SMPTE defines this code:
@@ -152,31 +151,31 @@ enum transfer {
*/
enum descriptor {
- descriptor_UserDefined,
- descriptor_Red,
- descriptor_Green,
- descriptor_Blue,
- descriptor_Alpha,
- descriptor_Luminance = 6, /* don't ask me why there's no 5 */
- descriptor_Chrominance,
- descriptor_Depth,
- descriptor_Composite,
- descriptor_RGB = 50,
- descriptor_RGBA,
- descriptor_ABGR,
- descriptor_CbYCrY = 100,
- descriptor_CbYACrYA,
- descriptor_CbYCr,
- descriptor_CbYCrA,
- descriptor_UserDefined2Elt = 150,
- descriptor_UserDefined3Elt,
- descriptor_UserDefined4Elt,
- descriptor_UserDefined5Elt,
- descriptor_UserDefined6Elt,
- descriptor_UserDefined7Elt,
- descriptor_UserDefined8Elt,
- /* following descriptors are for internal use only */
- descriptor_YA,
+ descriptor_UserDefined,
+ descriptor_Red,
+ descriptor_Green,
+ descriptor_Blue,
+ descriptor_Alpha,
+ descriptor_Luminance = 6, /* don't ask me why there's no 5 */
+ descriptor_Chrominance,
+ descriptor_Depth,
+ descriptor_Composite,
+ descriptor_RGB = 50,
+ descriptor_RGBA,
+ descriptor_ABGR,
+ descriptor_CbYCrY = 100,
+ descriptor_CbYACrYA,
+ descriptor_CbYCr,
+ descriptor_CbYCrA,
+ descriptor_UserDefined2Elt = 150,
+ descriptor_UserDefined3Elt,
+ descriptor_UserDefined4Elt,
+ descriptor_UserDefined5Elt,
+ descriptor_UserDefined6Elt,
+ descriptor_UserDefined7Elt,
+ descriptor_UserDefined8Elt,
+ /* following descriptors are for internal use only */
+ descriptor_YA,
};
/* int functions return 0 for OK */
@@ -187,9 +186,17 @@ int logImageIsCineon(const void *buffer);
LogImageFile *logImageOpenFromMemory(const unsigned char *buffer, unsigned int size);
LogImageFile *logImageOpenFromFile(const char *filename, int cineon);
void logImageGetSize(LogImageFile *logImage, int *width, int *height, int *depth);
-LogImageFile *logImageCreate(const char *filename, int cineon, int width, int height, int bitsPerSample,
- int isLogarithmic, int hasAlpha, int referenceWhite, int referenceBlack,
- float gamma, const char *creator);
+LogImageFile *logImageCreate(const char *filename,
+ int cineon,
+ int width,
+ int height,
+ int bitsPerSample,
+ int isLogarithmic,
+ int hasAlpha,
+ int referenceWhite,
+ int referenceBlack,
+ float gamma,
+ const char *creator);
void logImageClose(LogImageFile *logImage);
/* Data handling */
@@ -205,74 +212,73 @@ int logImageGetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB
BLI_INLINE unsigned short swap_ushort(unsigned short x, int swap)
{
- if (swap != 0)
- return (x >> 8) | (x << 8);
- else
- return x;
+ if (swap != 0)
+ return (x >> 8) | (x << 8);
+ else
+ return x;
}
BLI_INLINE unsigned int swap_uint(unsigned int x, int swap)
{
- if (swap != 0)
- return (x >> 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) | (x << 24);
- else
- return x;
+ if (swap != 0)
+ return (x >> 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) | (x << 24);
+ else
+ return x;
}
BLI_INLINE float swap_float(float x, int swap)
{
- if (swap != 0) {
- union {
- float f;
- unsigned char b[4];
- } dat1, dat2;
-
- dat1.f = x;
- dat2.b[0] = dat1.b[3];
- dat2.b[1] = dat1.b[2];
- dat2.b[2] = dat1.b[1];
- dat2.b[3] = dat1.b[0];
- return dat2.f;
- }
- else
- return x;
+ if (swap != 0) {
+ union {
+ float f;
+ unsigned char b[4];
+ } dat1, dat2;
+
+ dat1.f = x;
+ dat2.b[0] = dat1.b[3];
+ dat2.b[1] = dat1.b[2];
+ dat2.b[2] = dat1.b[1];
+ dat2.b[3] = dat1.b[0];
+ return dat2.f;
+ }
+ else
+ return x;
}
/* Other */
BLI_INLINE unsigned int clamp_uint(unsigned int x, unsigned int low, unsigned int high)
{
- if (x > high)
- return high;
- else if (x < low)
- return low;
- else
- return x;
+ if (x > high)
+ return high;
+ else if (x < low)
+ return low;
+ else
+ return x;
}
BLI_INLINE float clamp_float(float x, float low, float high)
{
- if (x > high)
- return high;
- else if (x < low)
- return low;
- else
- return x;
+ if (x > high)
+ return high;
+ else if (x < low)
+ return low;
+ else
+ return x;
}
BLI_INLINE unsigned int float_uint(float value, unsigned int max)
{
- if (value < 0.0f)
- return 0;
- else if (value > (1.0f - 0.5f / (float)max))
- return max;
- else
- return (unsigned int)(((float)max * value) + 0.5f);
+ if (value < 0.0f)
+ return 0;
+ else if (value > (1.0f - 0.5f / (float)max))
+ return max;
+ else
+ return (unsigned int)(((float)max * value) + 0.5f);
}
-
#ifdef __cplusplus
}
#endif
-#endif /* __LOGIMAGECORE_H__ */
+#endif /* __LOGIMAGECORE_H__ */
diff --git a/source/blender/imbuf/intern/cineon/logmemfile.c b/source/blender/imbuf/intern/cineon/logmemfile.c
index e67ef74951b..d7ab2855ea3 100644
--- a/source/blender/imbuf/intern/cineon/logmemfile.c
+++ b/source/blender/imbuf/intern/cineon/logmemfile.c
@@ -22,7 +22,6 @@
* Cineon image file format library routines.
*/
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -32,92 +31,92 @@
int logimage_fseek(LogImageFile *logFile, intptr_t offset, int origin)
{
- if (logFile->file)
- fseek(logFile->file, offset, origin);
- else { /* we're seeking in memory */
- if (origin == SEEK_SET) {
- if (offset > logFile->memBufferSize)
- return 1;
- logFile->memCursor = logFile->memBuffer + offset;
- }
- else if (origin == SEEK_END) {
- 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)
- return 1;
-
- logFile->memCursor += offset;
- }
- }
- return 0;
+ if (logFile->file)
+ fseek(logFile->file, offset, origin);
+ else { /* we're seeking in memory */
+ if (origin == SEEK_SET) {
+ if (offset > logFile->memBufferSize)
+ return 1;
+ logFile->memCursor = logFile->memBuffer + offset;
+ }
+ else if (origin == SEEK_END) {
+ 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)
+ return 1;
+
+ logFile->memCursor += offset;
+ }
+ }
+ return 0;
}
int logimage_fwrite(void *buffer, size_t size, unsigned int count, LogImageFile *logFile)
{
- 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;
- }
+ 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;
+ }
}
int logimage_fread(void *buffer, size_t size, unsigned int count, LogImageFile *logFile)
{
- if (logFile->file) {
- return fread(buffer, size, count, logFile->file);
- }
- else { /* we're reading from memory */
- unsigned char *buf = (unsigned char *)buffer;
- uintptr_t pos = (uintptr_t)logFile->memCursor - (uintptr_t)logFile->memBuffer;
- size_t total_size = size * count;
- if (pos + total_size > logFile->memBufferSize) {
- /* how many elements can we read without overflow ? */
- count = (logFile->memBufferSize - pos) / size;
- /* recompute the size */
- total_size = size * count;
- }
-
- if (total_size != 0)
- memcpy(buf, logFile->memCursor, total_size);
-
- return count;
- }
+ if (logFile->file) {
+ return fread(buffer, size, count, logFile->file);
+ }
+ else { /* we're reading from memory */
+ unsigned char *buf = (unsigned char *)buffer;
+ uintptr_t pos = (uintptr_t)logFile->memCursor - (uintptr_t)logFile->memBuffer;
+ size_t total_size = size * count;
+ if (pos + total_size > logFile->memBufferSize) {
+ /* how many elements can we read without overflow ? */
+ count = (logFile->memBufferSize - pos) / size;
+ /* recompute the size */
+ total_size = size * count;
+ }
+
+ if (total_size != 0)
+ memcpy(buf, logFile->memCursor, total_size);
+
+ return count;
+ }
}
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)
- return 1;
+ uintptr_t pos = (uintptr_t)logFile->memCursor - (uintptr_t)logFile->memBuffer;
+ if (pos + sizeof(unsigned char) > logFile->memBufferSize)
+ return 1;
- *x = *(unsigned char *)logFile->memCursor;
- logFile->memCursor += sizeof(unsigned char);
- return 0;
+ *x = *(unsigned char *)logFile->memCursor;
+ logFile->memCursor += sizeof(unsigned char);
+ return 0;
}
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)
- return 1;
+ uintptr_t pos = (uintptr_t)logFile->memCursor - (uintptr_t)logFile->memBuffer;
+ if (pos + sizeof(unsigned short) > logFile->memBufferSize)
+ return 1;
- *x = *(unsigned short *)logFile->memCursor;
- logFile->memCursor += sizeof(unsigned short);
- return 0;
+ *x = *(unsigned short *)logFile->memCursor;
+ logFile->memCursor += sizeof(unsigned short);
+ return 0;
}
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)
- return 1;
+ uintptr_t pos = (uintptr_t)logFile->memCursor - (uintptr_t)logFile->memBuffer;
+ if (pos + sizeof(unsigned int) > logFile->memBufferSize)
+ return 1;
- *x = *(unsigned int *)logFile->memCursor;
- logFile->memCursor += sizeof(unsigned int);
- return 0;
+ *x = *(unsigned int *)logFile->memCursor;
+ logFile->memCursor += sizeof(unsigned int);
+ return 0;
}
diff --git a/source/blender/imbuf/intern/cineon/logmemfile.h b/source/blender/imbuf/intern/cineon/logmemfile.h
index 9b6def2a617..d0ca03193e5 100644
--- a/source/blender/imbuf/intern/cineon/logmemfile.h
+++ b/source/blender/imbuf/intern/cineon/logmemfile.h
@@ -22,7 +22,6 @@
* Cineon image file format library routines.
*/
-
#ifndef __LOGMEMFILE_H__
#define __LOGMEMFILE_H__
@@ -37,4 +36,4 @@ int logimage_read_uchar(unsigned char *x, LogImageFile *logFile);
int logimage_read_ushort(unsigned short *x, LogImageFile *logFile);
int logimage_read_uint(unsigned int *x, LogImageFile *logFile);
-#endif /* __LOGMEMFILE_H__ */
+#endif /* __LOGMEMFILE_H__ */