Advertisement
Guest User

Untitled

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