Blender V2.61 - r43446

logImageLib.c

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