|
Blender V2.27
|
00001 /* 00002 * Cineon and DPX image file format library routines. 00003 * 00004 * Copyright 1999 - 2002 David Hodson <hodsond@acm.org> 00005 * 00006 * This program is free software; you can redistribute it and/or modify it 00007 * under the terms of the GNU General Public License as published by the Free 00008 * Software Foundation; either version 2 of the License, or (at your option) 00009 * any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, but 00012 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00013 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00014 * for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 */ 00021 00022 #include "cineonlib.h" 00023 #include "dpxlib.h" 00024 00025 #include <stdio.h> 00026 #include <math.h> 00027 #include <stdlib.h> 00028 #include <time.h> /* strftime() */ 00029 #include <sys/types.h> 00030 #ifdef WIN32 00031 #include <winsock.h> 00032 #else 00033 #include <netinet/in.h> /* htonl() */ 00034 #endif 00035 #include <string.h> /* memset */ 00036 00037 #define MIN_GAMMA 0.01 00038 #define MAX_GAMMA 99.9 00039 #define DEFAULT_GAMMA 1.0 00040 #define DEFAULT_BLACK_POINT 95 00041 #define DEFAULT_WHITE_POINT 685 00042 00043 void 00044 logImageSetVerbose(int verbosity) { 00045 cineonSetVerbose(verbosity); 00046 dpxSetVerbose(verbosity); 00047 } 00048 00049 LogImageFile* 00050 logImageOpen(const char* filename, int cineon) { 00051 if (cineon) { 00052 return cineonOpen(filename); 00053 } else { 00054 return dpxOpen(filename); 00055 } 00056 return 0; 00057 } 00058 00059 LogImageFile* 00060 logImageOpenFromMem(unsigned char *buffer, unsigned int size, int cineon) { 00061 if (cineon) { 00062 return cineonOpenFromMem(buffer, size); 00063 } else { 00064 return dpxOpenFromMem(buffer, size); 00065 } 00066 return 0; 00067 } 00068 00069 LogImageFile* 00070 logImageCreate(const char* filename, int cineon, int width, int height, int depth) { 00071 if (cineon) { 00072 return cineonCreate(filename, width, height, depth); 00073 } else { 00074 return dpxCreate(filename, width, height, depth); 00075 } 00076 return 0; 00077 } 00078 00079 int 00080 logImageGetSize(const LogImageFile* logImage, int* width, int* height, int* depth) { 00081 *width = logImage->width; 00082 *height = logImage->height; 00083 *depth = logImage->depth; 00084 return 0; 00085 } 00086 00087 int 00088 logImageGetByteConversionDefaults(LogImageByteConversionParameters* params) { 00089 params->gamma = DEFAULT_GAMMA; 00090 params->blackPoint = DEFAULT_BLACK_POINT; 00091 params->whitePoint = DEFAULT_WHITE_POINT; 00092 params->doLogarithm = 0; 00093 return 0; 00094 } 00095 00096 int 00097 logImageGetByteConversion(const LogImageFile* logImage, LogImageByteConversionParameters* params) { 00098 params->gamma = logImage->params.gamma; 00099 params->blackPoint = logImage->params.blackPoint; 00100 params->whitePoint = logImage->params.whitePoint; 00101 params->doLogarithm = 0; 00102 return 0; 00103 } 00104 00105 int 00106 logImageSetByteConversion(LogImageFile* logImage, const LogImageByteConversionParameters* params) { 00107 if ((params->gamma >= MIN_GAMMA) && 00108 (params->gamma <= MAX_GAMMA) && 00109 (params->blackPoint >= 0) && 00110 (params->blackPoint < params->whitePoint) && 00111 (params->whitePoint <= 1023)) { 00112 logImage->params.gamma = params->gamma; 00113 logImage->params.blackPoint = params->blackPoint; 00114 logImage->params.whitePoint = params->whitePoint; 00115 logImage->params.doLogarithm = params->doLogarithm; 00116 setupLut16(logImage); 00117 return 0; 00118 } 00119 return 1; 00120 } 00121 00122 int 00123 logImageGetRowBytes(LogImageFile* logImage, unsigned short* row, int y) { 00124 return logImage->getRow(logImage, row, y); 00125 } 00126 00127 int 00128 logImageSetRowBytes(LogImageFile* logImage, const unsigned short* row, int y) { 00129 return logImage->setRow(logImage, row, y); 00130 } 00131 00132 void 00133 logImageClose(LogImageFile* logImage) { 00134 logImage->close(logImage); 00135 } 00136 00137 void 00138 logImageDump(const char* filename) { 00139 00140 U32 magic; 00141 00142 FILE* foo = fopen(filename, "rb"); 00143 if (foo == 0) { 00144 return; 00145 } 00146 00147 if (fread(&magic, sizeof(magic), 1, foo) == 0) { 00148 fclose(foo); 00149 return; 00150 } 00151 00152 fclose(foo); 00153 00154 if (magic == ntohl(CINEON_FILE_MAGIC)) { 00155 #if 0 00156 cineonDump(filename); 00157 #endif 00158 } else if (magic == ntohl(DPX_FILE_MAGIC)) { 00159 dpxDump(filename); 00160 } 00161 }
1.7.3