Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 34 additions & 29 deletions libopendcp/codecs/opendcp_decoder_openexr.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <zlib.h>
#include "opendcp.h"
#include "opendcp_image.h"

Expand All @@ -58,11 +59,11 @@ typedef enum {
EXR_COMPRESSION_ZIPS = 2, /* zip single line (not supported) */
EXR_COMPRESSION_ZIP = 3, /* zip 16 lines */
EXR_COMPRESSION_PIZ = 4, /* piz (not supported) */
EXR_COMPRESSION_PXR24 = 5 /* pixar 24 bit (not supported) */
EXR_COMPRESSION_B44 = 6 /* b44 (not supported) */
EXR_COMPRESSION_B44A = 7 /* b44a (not supported) */
EXR_COMPRESSION_DWAA = 8 /* dwaa 32 lines (not supported) */
EXR_COMPRESSION_DWAB = 9 /* dwab 256 lines (not supported) */
EXR_COMPRESSION_PXR24 = 5, /* pixar 24 bit (not supported) */
EXR_COMPRESSION_B44 = 6, /* b44 (not supported) */
EXR_COMPRESSION_B44A = 7, /* b44a (not supported) */
EXR_COMPRESSION_DWAA = 8, /* dwaa 32 lines (not supported) */
EXR_COMPRESSION_DWAB = 9, /* dwab 256 lines (not supported) */
} exr_compression_enum;

typedef enum {
Expand All @@ -73,7 +74,7 @@ typedef enum {

typedef struct {
char name[255]; /* channel name */
unsigned char dataType; /* channel data type, int, half, float */
unsigned char data_type; /* channel data type, int, half, float */
unsigned char non_linear; /* non linear, only use for B44 and B44A compression */
unsigned int sample_x; /* sample x direction, only support == 1 */
unsigned int sample_y; /* sample y direction, only support == 1 */
Expand All @@ -98,7 +99,8 @@ typedef struct {
typedef struct {
exr_channel_list channel_list; /* channel list */
unsigned char compression; /* compression */
exr_window dataWindow; /* data window */
exr_window data_window; /* data window */
exr_window display_window; /* display window */
} exr_attributes;

/* exr chunk data */
Expand Down Expand Up @@ -340,16 +342,16 @@ exr_attributes read_attributes( FILE *exr_fp ) {
else if( !strcmp( "compression", attribute_name ) )
attributes.compression = fgetc( exr_fp );
else if( !strcmp( "dataWindow", attribute_name ) ) {
fread( &(attributes.dataWindow.left), 4, 1, exr_fp );
fread( &(attributes.dataWindow.bottom), 4, 1, exr_fp );
fread( &(attributes.dataWindow.right), 4, 1, exr_fp );
fread( &(attributes.dataWindow.top), 4, 1, exr_fp );
fread( &(attributes.data_window.left), 4, 1, exr_fp );
fread( &(attributes.data_window.bottom), 4, 1, exr_fp );
fread( &(attributes.data_window.right), 4, 1, exr_fp );
fread( &(attributes.data_window.top), 4, 1, exr_fp );
}
else if( !strcmp( "displayWindow", attribute_name ) ) {
fread( &(attributes.displayWindow.left), 4, 1, exr_fp );
fread( &(attributes.displayWindow.bottom), 4, 1, exr_fp );
fread( &(attributes.displayWindow.right), 4, 1, exr_fp );
fread( &(attributes.displayWindow.top), 4, 1, exr_fp );
fread( &(attributes.display_window.left), 4, 1, exr_fp );
fread( &(attributes.display_window.bottom), 4, 1, exr_fp );
fread( &(attributes.display_window.right), 4, 1, exr_fp );
fread( &(attributes.display_window.top), 4, 1, exr_fp );
}
else
// ---- skip attribute
Expand All @@ -367,7 +369,7 @@ exr_attributes read_attributes( FILE *exr_fp ) {
exr_chunk_data read_chunk_data( FILE *exr_fp, exr_attributes *attributes ) {

exr_chunk_data chunk_data;
unsigned short num_rows = (attributes->dataWindow.top - attributes->dataWindow.bottom) + 1;
unsigned short num_rows = (attributes->data_window.top - attributes->data_window.bottom) + 1;

// ---- if EXR_COMPRESSION_ZIP, 16 rows per chunk
if( attributes->compression == EXR_COMPRESSION_ZIP ) { //
Expand Down Expand Up @@ -432,7 +434,8 @@ void unfilter_buffer( unsigned char *buffer, unsigned char *unfilteredBuffer, un
}

/* uncompress rle - from OpenEXR library */
void uncompress_rle( unsigned char *compressed_buffer, unsigned int compressed_buffer_length, unsigned char *uncompressed_buffer, unsigned int uncompressed_buffer_length) {
void uncompress_rle( unsigned char *compressed_buffer, unsigned int compressed_buffer_length,
unsigned char *uncompressed_buffer, int uncompressed_buffer_length) {

unsigned char *outStart = compressed_buffer;

Expand Down Expand Up @@ -575,7 +578,7 @@ void copy_float_data( unsigned char *buffer, float *channel_data, unsigned short
/* compression no */
void read_data_compression_no( FILE *exr_fp, exr_chunk_data *chunk_data, exr_attributes *attributes, exr_image_data *image_data ) {

unsigned int num_columns = (attributes->dataWindow.right - attributes->dataWindow.left) + 1;
unsigned int num_columns = (attributes->data_window.right - attributes->data_window.left) + 1;

unsigned short channel_data_width = attributes->channel_list.data_width;

Expand Down Expand Up @@ -621,7 +624,7 @@ void read_data_compression_no( FILE *exr_fp, exr_chunk_data *chunk_data, exr_att
/* compression RLE */
void read_data_compression_rle( FILE *exr_fp, exr_chunk_data *chunk_data, exr_attributes *attributes, exr_image_data *image_data ) {

unsigned int num_columns = (attributes->dataWindow.right - attributes->dataWindow.left) + 1;
unsigned int num_columns = (attributes->data_window.right - attributes->data_window.left) + 1;

unsigned short channel_data_width = attributes->channel_list.data_width;

Expand Down Expand Up @@ -682,7 +685,7 @@ void read_data_compression_rle( FILE *exr_fp, exr_chunk_data *chunk_data, exr_at
/* compression ZIPS an ZIP */
void read_data_compression_zip( FILE *exr_fp, exr_chunk_data *chunk_data, exr_attributes *attributes, exr_image_data *image_data ) {

unsigned int num_columns = (attributes->dataWindow.right - attributes->dataWindow.left) + 1;
unsigned int num_columns = (attributes->data_window.right - attributes->data_window.left) + 1;
unsigned char num_rows = 1;
unsigned char *compressed_buffer = NULL;
unsigned char *uncompressed_buffer = NULL;
Expand Down Expand Up @@ -785,7 +788,7 @@ int opendcp_decode_exr(opendcp_image_t **image_ptr, const char *sfile) {
magicNumber |= fgetc(exr_fp) << 8;
magicNumber |= fgetc(exr_fp);

if (readsize != MAGIC_NUMBER_EXR ) {
if ( magicNumber != MAGIC_NUMBER_EXR ) {
OPENDCP_LOG(LOG_ERROR,"%-15.15s: failed to read magic number expected 0x%08x read 0x%08x","read_exr", MAGIC_NUMBER_EXR, magicNumber );
OPENDCP_LOG(LOG_ERROR,"%s is not a valid EXR file", sfile);
return OPENDCP_FATAL;
Expand All @@ -800,7 +803,7 @@ int opendcp_decode_exr(opendcp_image_t **image_ptr, const char *sfile) {

// ---- file type: normal, deep pixel, multipart (only support normal)
unsigned char type = fgetc(exr_fp);
if( type & 0x1a != 0x00 ) {
if( (type & 0x1a) != 0x00 ) {
OPENDCP_LOG(LOG_ERROR,"Only support normal scanline exr file, no tile, deep pixel, multipart file");
return OPENDCP_FATAL;
}
Expand All @@ -810,7 +813,7 @@ int opendcp_decode_exr(opendcp_image_t **image_ptr, const char *sfile) {
fgetc(exr_fp);

// ---- read EXR attritubes need for dcp
exr_attributes attritbute = read_attributes( exr_fp );
exr_attributes attributes = read_attributes( exr_fp );

// ---- check compression
if( attributes.compression > EXR_COMPRESSION_ZIP ) {
Expand All @@ -829,8 +832,8 @@ int opendcp_decode_exr(opendcp_image_t **image_ptr, const char *sfile) {

// ---- for store image data
exr_image_data image_data;
image_data.width = attributes.dataWindow.right - attributes.dataWindow.left + 1;
image_data.height = attributes.dataWindow.top - attributes.dataWindow.bottom + 1;
image_data.width = attributes.data_window.right - attributes.data_window.left + 1;
image_data.height = attributes.data_window.top - attributes.data_window.bottom + 1;
// ---- create buffers for image data
image_data.channel_b = malloc( image_data.width*image_data.height * sizeof( float ) );
image_data.channel_g = malloc( image_data.width*image_data.height * sizeof( float ) );
Expand All @@ -848,15 +851,17 @@ int opendcp_decode_exr(opendcp_image_t **image_ptr, const char *sfile) {
fclose( exr_fp );

/* create the image (float data) */
image = opendcp_image_create_float(3, image_data.width, mage_data.height);
opendcp_image_t *image = opendcp_image_create_float(3, image_data.width, image_data.height);

unsigned int image_size = image_data.width * mage_data.height;
for (index = 0; index < image_size; index++) {
unsigned int image_size = image_data.width * image_data.height;
unsigned int index = 0;
while( index < image_size ) {
// ---- need copy float data from exr image data to float opendcp image data
// ----- correct channel order?
// ----- correct channel order? Use float data for OpenEXR
image->component[0].float_data[index] = image_data.channel_b[index];
image->component[1].float_data[index] = image_data.channel_g[index];
image->component[2].float_data[index] = image_data.channel_r[index];
index++;
}

// ---- free chunk table
Expand Down
Loading