-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathnikon_curve.h
199 lines (157 loc) · 6.16 KB
/
nikon_curve.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/***************************************************
nikon_curve.h - read Nikon NTC/NCV files
Copyright 2004-2016 by Shawn Freeman, Udi Fuchs
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
****************************************************/
/***************************************************
This program reads in a Nikon NTC/NCV file,
interperates it's tone curve, and writes out a
simple ascii file containing a table of interpolation
values.
You'll note that this has been written in way that can be used in a
standalone program or incorporated into another program. You can use the
functions seperately or you can just call ConvertNikonCurveData with
an input and output file.
I've tried to document the code as clearly as possible. Let me know if you
have any problems!
Thanks goes out to Udi Fuchs for wanting to incorporate nikon curve loading
into his program. This will make GIMP just that much better. :)
@author: Shawn Freeman 1/06/2005
@liscense: GNU GPL
****************************************************/
#ifndef _NIKON_CURVE_H
#define _NIKON_CURVE_H
#define NC_VERSION "1.2"
#define NC_DATE "2005-08-06"
#define NIKON_MAX_ANCHORS 20
//file types
#define NTC_FILE 0
#define NCV_FILE 1
#define NUM_FILE_TYPES 2
//Curve Types
#define TONE_CURVE 0
#define RED_CURVE 1
#define GREEN_CURVE 2
#define BLUE_CURVE 3
#define NUM_CURVE_TYPES 4
////////////////////////
//ERROR HANDLING
////////////////////////
#define NC_SUCCESS 0
#define NC_ERROR 100
#define NC_WARNING 104
#define NC_SET_ERROR 200
//////////////////////////////////////////////////////////////////////////////
//DATA STRUCTURES
//////////////////////////////////////////////////////////////////////////////
/**********************************************************
CurveData:
Structure for the curve data inside a NTC/NCV file.
***********************************************************/
typedef struct {
double x;
double y;
} CurveAnchorPoint;
typedef struct {
char name[80];
//Type for this curve
unsigned int m_curveType;
//Box data
double m_min_x;
double m_max_x;
double m_min_y;
double m_max_y;
double m_gamma;
//Number of anchor points
unsigned char m_numAnchors;
//contains a list of anchors, 2 doubles per each point, x-y format
//max is 20 points
CurveAnchorPoint m_anchors[NIKON_MAX_ANCHORS];
} CurveData;
typedef struct {
//Number of samples to use for the curve.
unsigned int m_samplingRes;
unsigned int m_outputRes;
//Sampling array
unsigned int *m_Samples;
} CurveSample;
/*********************************************
NikonData:
Overall data structure for Nikon file data
**********************************************/
typedef struct {
//Number of output points
int m_fileType;
unsigned short m_patch_version;
CurveData curves[4];
} NikonData;
//////////////////////////////////////////////////////////////////////////////
//FUNCTIONS
//////////////////////////////////////////////////////////////////////////////
/*********************************************
CurveDataSample:
Samples from a spline curve constructed from
the curve data.
curve - Pointer to curve struct to hold the data.
sample - Pointer to sample struct to hold the data.
**********************************************/
int CurveDataSample(CurveData *curve, CurveSample *sample);
/*********************************************
* CurveDataReset:
* Reset curve to straight line but don't touch the curve name.
**********************************************/
void CurveDataReset(CurveData *curve);
/*********************************************
* CurveDataIsTrivial:
* Check if the curve is a trivial linear curve.
***********************************************/
int CurveDataIsTrivial(CurveData *curve);
/*********************************************
CurveDataSetPoint:
Change the position of point to the new (x,y) coordinate.
The end-points get a special treatment. When these are moved all the
other points are moved together, keeping their relative position constant.
**********************************************/
void CurveDataSetPoint(CurveData *curve, int point, double x, double y);
/*******************************************************
CurveSampleInit:
Init and allocate curve sample.
********************************************************/
CurveSample *CurveSampleInit(unsigned int samplingRes, unsigned int outputRes);
/*******************************************************
CurveSampleFree:
Frees memory allocated for this curve sample.
********************************************************/
int CurveSampleFree(CurveSample *sample);
/*********************************************
LoadNikonData:
Loads a curve from a Nikon ntc or ncv file.
fileName - The filename.
curve - Pointer to curve struct to hold the data.
resolution - How many data points to sample from the curve
**********************************************/
int LoadNikonData(char *fileName, NikonData *data);
/************************************************************
SaveNikonDataFile:
Savess a curve to a Nikon ntc or ncv file.
data - A NikonData structure containing info of all the curves.
fileName - The filename.
filetype - Indicator for an NCV or NTC file.
**************************************************************/
int SaveNikonDataFile(NikonData *data, char *outfile, int filetype);
/*******************************************************
RipNikonNEFCurve:
The actual retriever for the curve data from the NEF
file.
file - The input file.
infile - Offset to retrieve the data
curve - data structure to hold curve in.
sample_p - pointer to the curve sample reference.
can be NULL if curve sample is not needed.
********************************************************/
int RipNikonNEFCurve(void *file, int offset, CurveData *data,
CurveSample **sample_p);
#endif