Samples-LibRaw.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <html>
  2. <head>
  3. <meta http-equiv="content-type" content="text/html; charset=windows-1252">
  4. </head>
  5. <body>
  6. <p>LibRaw: Usage Examples<a href="index.html">[back to Index]</a></p>
  7. <h1>LibRaw: Usage Examples</h1>
  8. <h2>Overview of Examples in the Distribution Package (samples/*)</h2>
  9. <p>The LibRaw package contains several examples illustrating the use of this
  10. library. Their source codes are located in the samples/ folder, and after
  11. library build they will be in the bin/ folder:</p>
  12. <ul>
  13. <li><strong>raw-identify</strong> The only LibRaw call it uses is <a href="API-CXX.html#open_file">open_file()</a>;
  14. further code prints the values of the fields of the imgdata structure. <strong><br>
  15. </strong><strong>raw-identify -v</strong> provides extensive dump of
  16. metadata/<br>
  17. Command line key <strong>-u</strong> shows unpacking function name,
  18. while <strong>-u -f</strong> prints function name and masked are sizes.<br>
  19. <strong>raw-identify -w </strong>will print white balance tables stored
  20. in RAW file.</li>
  21. <li><strong>simple_dcraw</strong> A simple "emulation" of dcraw
  22. reproducing the behavior of <strong>dcraw [-e] [-v] [-T]</strong>.&nbsp;
  23. A simplified version of this example is <a href="#code">considered
  24. below</a>. <br>
  25. <strong>-B</strong> command-line switch turns on use of <a href="API-CXX.html#open_buffer">open_buffer()
  26. API call</a> used via mmap() of input file (Unix only).</li>
  27. <li><strong>dcraw_half</strong> Demonstrates the use of <a href="API-C.html">C
  28. API</a>. The example emulates the behavior of <strong>dcraw -h</strong>
  29. (no other control parameters can be specified in this example). </li>
  30. <li><strong>dcraw_emu</strong> Almost complete emulation of dcraw (except for
  31. keys -D -d -E -i -v -e, which are considered in other usage examples).
  32. Of most interest is processing of command line keys (copied from dcraw).
  33. <br>
  34. <p>This sample supports additional command-line parameters absent in
  35. original dcraw:</p>
  36. <dl>
  37. <dt><strong>-mmap</strong></dt>
  38. <dd>Use <a href="API-CXX.html#open_buffer">open_buffer()</a>
  39. interface. Buffer prepared by mmap() call. This option not supported
  40. under Win32.</dd>
  41. <dt><strong>-meme</strong></dt>
  42. <dd>Use <a href="API-CXX.html#open_buffer">open_buffer()</a>
  43. interface. Buffer prepared by malloc()+read() calls.</dd>
  44. <dt><strong>-c float-value</strong></dt>
  45. <dd>This key sets <strong>params.adjust_maximum_thr</strong>
  46. parameter.<br>
  47. Use -c 0 to completely disable automatic maximum calculation. <br>
  48. Default value: 0.75</dd>
  49. <dt><strong>-timing</strong></dt>
  50. <dd>Turns on detailed timing print.</dd>
  51. <dt><strong>-G</strong></dt>
  52. <dd>Turns on "green_matching" mode to suppress color mazes on cameras
  53. with different green channels.</dd>
  54. <dt><strong>-B x y w h</strong></dt>
  55. <dd>Crops output to rectangle with width w, height h and x,y
  56. coordinates of left upper corner. All coordinates applied before any
  57. image rotation.</dd>
  58. <dt><strong>-F</strong></dt>
  59. <dd>Will use FILE I/O (bigfile_datastream) instead on standard
  60. LibRaw_file_datastream.</dd>
  61. <dt><strong>-dcbi N</strong></dt>
  62. <dd>Sets number of additional DCB-demosaic iterations (option valid
  63. only for -q 4, i.e. for DCB demosaic).</dd>
  64. <dt><strong>-dcbe</strong></dt>
  65. <dd>Turns on DCB color enhance mode (only for DCB demosaic, -q 4).</dd>
  66. <dt><strong>-aexpo e p</strong></dt>
  67. <dd>Turns on exposure correction. e is exposure shift in linear scale
  68. from 0.25 (darken 2 stops) to 8.0 (lighten 3 stops). p is highlights
  69. preservation amount from 0.0 (no preservation, full clipping) to 1.0
  70. (full preservation, S-like curve in highlights).</dd>
  71. <dt><strong>-apentax4shot</strong></dt>
  72. <dd>Will merge 4 frames from Pentax 4-shot RAWs</dd>
  73. <dt><strong>-apentax4shotorder abce</strong></dt>
  74. <dd>Order of frames in pentax 4-shot files (default is 3102)</dd>
  75. <dt><strong>-mmap</strong></dt>
  76. <dd>Use mmap + memory IO instead of file IO (unix only)</dd>
  77. <dt><strong>-disars</strong></dt>
  78. <dd>Disable RawSpeed library (if compiled with this library)</dd>
  79. <dt><strong>-doutputflags N</strong></dt>
  80. <dd>set imgdata.params.output_flags to N</dd>
  81. <dt><strong>-disinterp</strong></dt>
  82. <dd>Do not run interpolation step</dd>
  83. <dt><strong>-dsrawrgb1</strong></dt>
  84. <dd>Disable YCbCr to RGB conversion for sRAW (Cb/Cr interpolation
  85. enabled)</dd>
  86. <dt><strong>-dsrawrgb2</strong></dt>
  87. <dd>Disable YCbCr to RGB conversion for sRAW (Cb/Cr interpolation
  88. disabled)</dd>
  89. </dl>
  90. </li>
  91. <li><strong>half_mt</strong> Emulation of <strong>dcraw -h</strong>. It
  92. "understands" the following keys: -a (automatic white balance over the
  93. entire image), -w (white balance of the camera), -T (output in the tiff
  94. format), and -J n (number of parallel threads launched for image
  95. processing).<br>
  96. On multiprocessor/multicore computers, the speed gain is notable in the
  97. case of mass processing. On a Win32 machine, the example is assembled
  98. from the initial file half_mt_win32.c, since work with threads under
  99. Windows is fundamentally different and it it easier to copy simple
  100. source codes than write one complex code.</li>
  101. <li><strong>mem_image</strong> This sample uses <a href="API-CXX.html#dcraw_make_mem_image">dcraw_make_mem_image</a>
  102. and <a href="API-CXX.html#dcraw_make_mem_thumb">dcraw_make_mem_thumb</a>
  103. calls, than writes data in PPM format. </li>
  104. <li><strong>unprocessed_raw</strong> This sample extracts (mostly)
  105. unaltered RAW data including masked pixels data (on supported cameras).
  106. If black frame exists and black frame extraction is supported for given
  107. format, masked pixels data is added to resulting .TIFF file. Command
  108. line options: <strong>-q</strong> - be quiet, <strong>-A</strong> -
  109. autoscale data (integer multiplier), <strong>-g</strong>
  110. gamma-correction (gamma 2.2) for data (instead of precise linear one), <strong>-B</strong>
  111. turns on black level subtraction</li>
  112. <li><strong>4channnels</strong> - splits RAW-file into four separate
  113. 16-bit grayscale TIFFs (per RAW channel).<br>
  114. Command line switches:
  115. <ul>
  116. <li><strong>-s N</strong> selects N-th image from RAW with multiple
  117. images</li>
  118. <li><strong>-g</strong> gamma correction (gamma 2.2)</li>
  119. <li><strong>-A</strong> values autoscale by auto-calculated integer
  120. factor</li>
  121. <li><strong>-B</strong> turn off black subtraction</li>
  122. <li><strong>-N</strong> no RAW curve</li>
  123. </ul>
  124. </li>
  125. <li><strong>multirender_test</strong> - very simple example of multiple
  126. rendering on one file without reopen.</li>
  127. <li><strong>postprocessing_benchmark</strong> - will print timings of RAW
  128. processing steps</li>
  129. </ul>
  130. <h2>Example of docmode</h2>
  131. <p>Below we consider the samples/simple_dcraw.cpp example, which emulates
  132. the behavior of <strong>dcraw [-e][-v][-t]</strong>. To save space, let
  133. us assume that keys -t -v are always specified (to avoid comments on
  134. command line parsing) and there is always one parameter (name of file),
  135. which is the only one and always passed to the program.</p>
  136. <pre>int main(int ac, char *av[])
  137. {
  138. int i, ret, verbose=0, output_thumbs=0;
  139. char outfn[1024],thumbfn[1024];
  140. // Creation of image processing object
  141. LibRaw RawProcessor;
  142. // The date in TIFF is written in the local format; let us specify the timezone for compatibility with dcraw
  143. putenv ((char*)"TZ=UTC");
  144. // Let us define variables for convenient access to fields of RawProcessor
  145. #define P1 RawProcessor.imgdata.idata
  146. #define S RawProcessor.imgdata.sizes
  147. #define C RawProcessor.imgdata.color
  148. #define T RawProcessor.imgdata.thumbnail
  149. #define P2 RawProcessor.imgdata.other
  150. #define OUT RawProcessor.imgdata.params
  151. OUT.output_tiff = 1; // Let us output TIFF
  152. // Let us open the file
  153. if( (ret = RawProcessor.open_file(av[1])) != LIBRAW_SUCCESS)
  154. {
  155. fprintf(stderr,"Cannot open %s: %s\n",av[i],libraw_strerror(ret));
  156. // recycle() is needed only if we want to free the resources right now.
  157. // If we process files in a cycle, the next open_file()
  158. // will also call recycle(). If a fatal error has happened, it means that recycle()
  159. // has already been called (repeated call will not cause any harm either).
  160. RawProcessor.recycle();
  161. goto end;
  162. }
  163. // Let us unpack the image
  164. if( (ret = RawProcessor.unpack() ) != LIBRAW_SUCCESS)
  165. {
  166. fprintf(stderr,"Cannot unpack_thumb %s: %s\n",av[i],libraw_strerror(ret));
  167. if(LIBRAW_FATAL_ERROR(ret))
  168. goto end;
  169. // if there has been a non-fatal error, we will try to continue
  170. }
  171. // Let us unpack the thumbnail
  172. if( (ret = RawProcessor.unpack_thumb() ) != LIBRAW_SUCCESS)
  173. {
  174. // error processing is completely similar to the previous case
  175. fprintf(stderr,"Cannot unpack_thumb %s: %s\n",av[i],libraw_strerror(ret));
  176. if(LIBRAW_FATAL_ERROR(ret))
  177. goto end;
  178. }
  179. else // We have successfully unpacked the thumbnail, now let us write it to a file
  180. {
  181. snprintf(thumbfn,sizeof(thumbfn),"%s.%s",av[i],T.tformat == LIBRAW_THUMBNAIL_JPEG ? "thumb.jpg" : "thumb.ppm");
  182. if( LIBRAW_SUCCESS != (ret = RawProcessor.dcraw_thumb_writer(thumbfn)))
  183. {
  184. fprintf(stderr,"Cannot write %s: %s\n",thumbfn,libraw_strerror(ret));
  185. // in the case of fatal error, we should terminate processing of the current file
  186. if(LIBRAW_FATAL_ERROR(ret))
  187. goto end;
  188. }
  189. }
  190. // Data unpacking
  191. ret = RawProcessor.dcraw_process();
  192. if(LIBRAW_SUCCESS != ret ) // error at the previous step
  193. {
  194. fprintf(stderr,"Cannot do postprocessing on %s: %s\n",av[i],libraw_strerror(ret));
  195. if(LIBRAW_FATAL_ERROR(ret))
  196. goto end;
  197. }
  198. else // Successful document processing
  199. {
  200. snprintf(outfn,sizeof(outfn),"%s.%s", av[i], "tiff");
  201. if( LIBRAW_SUCCESS != (ret = RawProcessor.dcraw_ppm_tiff_writer(outfn)))
  202. fprintf(stderr,"Cannot write %s: error %d\n",outfn,ret);
  203. }
  204. // we don't evoke recycle() or call the destructor; C++ will do everything for us
  205. return 0;
  206. end:
  207. // got here after an error
  208. return 1;
  209. }
  210. </pre>
  211. <p><a href="index.html">[back to Index]</a></p>
  212. </body>
  213. </html>