Adds support for utf paths on Windows.
[blender.git] / source / blender / imbuf / intern / cineon / logImageLib.c
1 /** \file blender/imbuf/intern/cineon/logImageLib.c
2  *  \ingroup imbcineon
3  */
4 /*
5  *       Cineon and DPX image file format library routines.
6  *
7  *       Copyright 1999 - 2002 David Hodson <hodsond@acm.org>
8  *
9  *       This program is free software; you can redistribute it and/or modify it
10  *       under the terms of the GNU General Public License as published by the Free
11  *       Software Foundation; either version 2 of the License, or (at your option)
12  *       any later version.
13  *
14  *       This program is distributed in the hope that it will be useful, but
15  *       WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  *       or FITNESS FOR A PARTICULAR PURPOSE.    See the GNU General Public License
17  *       for more details.
18  *
19  *       You should have received a copy of the GNU General Public License
20  *       along with this program; if not, write to the Free Software
21  *       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  *
23  */
24
25 #include "cineonlib.h"
26 #include "dpxlib.h"
27
28 #include <stdio.h>
29 #include <math.h>
30 #include <stdlib.h>
31 #include <time.h>                                /* strftime() */
32 #include <sys/types.h>
33 #ifdef WIN32
34 #include <winsock.h>
35 #else
36 #include <netinet/in.h>  /* htonl() */
37 #endif
38 #include <string.h>                      /* memset */
39 #include "BLI_fileops.h"
40
41 #define MIN_GAMMA 0.01
42 #define MAX_GAMMA 99.9
43 #define DEFAULT_GAMMA 1.0
44 #define DEFAULT_BLACK_POINT 95
45 #define DEFAULT_WHITE_POINT 685
46
47 void
48 logImageSetVerbose(int verbosity)
49 {
50         cineonSetVerbose(verbosity);
51         dpxSetVerbose(verbosity);
52 }
53
54 LogImageFile*
55 logImageOpen(const char* filename, int cineon)
56 {
57         if (cineon) {
58                 return cineonOpen(filename);
59         } else {
60                 return dpxOpen(filename);
61         }
62         return 0;
63 }
64
65 LogImageFile*
66 logImageOpenFromMem(unsigned char *buffer, unsigned int size, int cineon)
67 {
68         if (cineon) {
69                 return cineonOpenFromMem(buffer, size);
70         } else {
71                 return dpxOpenFromMem(buffer, size);
72         }
73         return 0;
74 }
75
76 LogImageFile*
77 logImageCreate(const char* filename, int cineon, int width, int height, int depth)
78 {
79         if (cineon) {
80                 return cineonCreate(filename, width, height, depth);
81         } else {
82                 return dpxCreate(filename, width, height, depth);
83         }
84         return 0;
85 }
86
87 int
88 logImageGetSize(const LogImageFile* logImage, int* width, int* height, int* depth)
89 {
90         *width = logImage->width;
91         *height = logImage->height;
92         *depth = logImage->depth;
93         return 0;
94 }
95
96 int
97 logImageGetByteConversionDefaults(LogImageByteConversionParameters* params)
98 {
99         params->gamma = DEFAULT_GAMMA;
100         params->blackPoint = DEFAULT_BLACK_POINT;
101         params->whitePoint = DEFAULT_WHITE_POINT;
102         params->doLogarithm = 0;
103         return 0;
104 }
105
106 int
107 logImageGetByteConversion(const LogImageFile* logImage, LogImageByteConversionParameters* params)
108 {
109         params->gamma = logImage->params.gamma;
110         params->blackPoint = logImage->params.blackPoint;
111         params->whitePoint = logImage->params.whitePoint;
112         params->doLogarithm = 0;
113         return 0;
114 }
115
116 int
117 logImageSetByteConversion(LogImageFile* logImage, const LogImageByteConversionParameters* params)
118 {
119         if ((params->gamma >= MIN_GAMMA) &&
120                         (params->gamma <= MAX_GAMMA) &&
121                         (params->blackPoint >= 0) &&
122                         (params->blackPoint < params->whitePoint) &&
123                         (params->whitePoint <= 1023)) {
124                 logImage->params.gamma = params->gamma;
125                 logImage->params.blackPoint = params->blackPoint;
126                 logImage->params.whitePoint = params->whitePoint;
127                 logImage->params.doLogarithm = params->doLogarithm;
128                 setupLut16(logImage);
129                 return 0;
130         }
131         return 1;
132 }
133
134 int
135 logImageGetRowBytes(LogImageFile* logImage, unsigned short* row, int y)
136 {
137         return logImage->getRow(logImage, row, y);
138 }
139
140 int
141 logImageSetRowBytes(LogImageFile* logImage, const unsigned short* row, int y)
142 {
143         return logImage->setRow(logImage, row, y);
144 }
145
146 void
147 logImageClose(LogImageFile* logImage)
148 {
149         logImage->close(logImage);
150 }
151
152 void
153 logImageDump(const char* filename)
154 {
155
156         U32 magic;
157
158         FILE* foo = BLI_fopen(filename, "rb");
159         if (foo == 0) {
160                 return;
161         }
162
163         if (fread(&magic, sizeof(magic), 1, foo) == 0) {
164                 fclose(foo);
165                 return;
166         }
167
168         fclose(foo);
169
170         if (magic == ntohl(CINEON_FILE_MAGIC)) {
171 #if 0
172                 cineonDump(filename);
173 #endif
174         } else if (magic == ntohl(DPX_FILE_MAGIC)) {
175                 dpxDump(filename);
176         }
177 }