1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4
<title>LibRaw C++ API</title>
5
<meta http-equiv="content-type" content="text/html; charset=windows-1251">
9
<a href=index-eng.html>[back to Index]</a>
10
<h1>LibRaw C++ API</h1>
13
<li><a href="#LibRaw">LibRaw Objects</a> </li>
14
<li><a href="#return">Returned values</a></li>
15
<li><a href="#dataload">Methods Loading Data from a File</a>
17
<li><a href="#open_datastream">int LibRaw::open_datastream(LibRaw_abstract_datastream *stream)</a></li>
18
<li><a href="#open_file">int LibRaw::open_file(const char *rawfile)</a></li>
19
<li><a href="#open_buffer">int LibRaw::open_buffer(void *buffer, size_t bufsize)</a></li>
20
<li><a href="#unpack">int LibRaw::unpack(void)</a></li>
21
<li><a href="#unpack_thumb">int LibRaw::unpack_thumb(void)</a></li>
24
<li><a href="#utility">Auxiliary Functions</a>
26
<li>Library version info
28
<li><a href="#version">const char* LibRaw::version()</a></li>
29
<li><a href="#versionNumber">int LibRaw::versionNumber()</a></li>
30
<li><a href="#LIBRAW_CHECK_VERSION">bool LIBRAW_CHECK_VERSION(major,minor,patch)</a>
33
<li>List of supported cameras
35
<li><a href="#cameraCount">int LibRaw::cameraCount()</a></li>
36
<li><a href="#cameraList">const char** LibRaw::cameraList()</a></li>
39
<li<<a href="#unpack_function_name">const char* LibRaw::unpack_function_name()</a></li>
40
<li><a href="#add_masked_borders_to_bitmap">void LibRaw::add_masked_borders_to_bitmap</a></li>
41
<li><a href="#rotate_fuji_raw">int LibRaw:: rotate_fuji_raw()</a>
42
<li><a href="#recycle">void LibRaw::recycle(void)</a></li>
43
<li><a href="#~LibRaw">LibRaw::~LibRaw()</a></li>
44
<li><a href="#strprogress">const char* LibRaw::strprogress(enum LibRaw_progress code)</a></li>
45
<li><a href="#libraw_strerror">const char* LibRaw::strerror(int errorcode)</a></li>
46
<li><a href="#callbacks">Setting Error Notification Functions</a>
48
<li><a href="#progress">User callback for progress indication/interruption</a></li>
49
<li><a href="#memerror">Out-of-Memory Notifier</a></li>
50
<li><a href="#dataerror">File Reading Notifier</a></li>
55
<li><a href="#dcrawemu">Data Postprocessing: Emulation of dcraw Behavior</a>
57
<li><a href="#dcraw_params">Parameter Setting</a></li>
58
<li><a href="#adjust_sizes_info_only">int LibRaw::adjust_sizes_info_only(void)</a></li>
59
<li><a href="#dcraw_document_mode_processing">int LibRaw::dcraw_document_mode_processing(void)</a></li>
60
<li><a href="#dcraw_process">int LibRaw::dcraw_process(void)</a></li>
63
<li><a href="#dcrawrite">Data Output to Files: Emulation of dcraw Behavior</a>
65
<li><a href="#dcraw_ppm_tiff_writer">int LibRaw::dcraw_ppm_tiff_writer(const char *outfile)</a></li>
66
<li><a href="#dcraw_thumb_writer">int LibRaw::dcraw_thumb_writer(const char *thumbfile)</a></li>
70
<a href="#memwrite">Copying unpacked data into memory buffer</a>
73
<a href="#dcraw_make_mem_image">libraw_processed_image_t *dcraw_make_mem_image(int *errorcode)</a>
76
<a href="#dcraw_make_mem_thumb">libraw_processed_image_t *dcraw_make_mem_thumb(int *errorcode)</a>
80
<li><a href="#datastream">Input layer abstraction</a>
82
<li><a href="LibRaw_abstract_datastream">class LibRaw_abstract_datastream - abstract RAW read interface<a>
84
<li><a href="#datastream_methods">LibRaw_abstract_datastream class methods</a>
86
<li><a href="#datastream_methods_utility">Object verification</a></li>
87
<li><a href="#datastream_methods_read">Stream read and positioning</a></li>
88
<li><a href="#datastream_methods_other">Other methods</a></li>
93
<li><a href="#datastream_derived">Derived input classes included in LibRaw</a>
95
<li><a href="#file_datastream">class LibRaw_file_datastream - file input interface</a></li>
98
<li><a href="#own_datastreams">Own datastream derived classes</a>
100
<li><a href="#substream">substream field: secondary input stream</a></li>
107
<a name="LibRaw"></a>
108
<h2>LibRaw Objects</h2>
110
The main LibRaw object (class) is created either without parameters or with flags determining the object behavior.
113
#include "libraw/libraw.h"
116
LibRaw ImageProcessor(unsigned int flags=0);
119
<p>Flags (several flags are combined via operator |, i.e., bitwise OR):</P>
121
<li><b>LIBRAW_OPTIONS_NO_MEMERR_CALLBACK</b>: do not set the standard
122
<a href="#callbacks">out-of-memory error handler</a> (standard handler outputs the error report in stderr);</li>
123
<li><b>LIBRAW_OPTIONS_NO_DATAERR_CALLBACK</b>: do not set the standard
124
<a href="#callbacks">file read error handler</a> (standard handler outputs the error report in stderr).</li>
127
Three groups of methods are used for image processing
130
<li><a href="#dataload">Data loading from the RAW file</a></li>
131
<li><a href="#dcrawemu">Postprocessing functions emulating the dcraw behavior</a></li>
132
<li><a href="#dcrawrite">File output functions emulating the dcraw behavior</a>.</li>
135
The results of processing are placed in the imgdata field of type <a
136
href=API-datastruct-eng.html>libraw_data_t</a>; the same data set contains fields that control the postprocessing
139
<a name="return"></a>
140
<h2>Returned Values</h2>
142
All LibRaw API functions return an integer number in accordance with the
143
<a href=API-notes-eng.html#errors>return code convention</a>. Please read the descriptions of
144
<a href=API-notes-eng.html#errors>this convention</a> and <a href="#callbacks">LibRaw behavior
145
in cases of fatal errors</a>.
148
<a name="dataload"></a>
149
<h2>Methods Loading Data from a File</h2>
150
<a name=open_datastream></a>
151
<h3>int LibRaw::open_datastream(LibRaw_abstract_datastream *stream)</h3>
152
<p>Opens a datastream with RAW data, reads metadata (EXIF) from it, and fills the following structures:
155
<li>imgdata.idata (<a href="API-datastruct-eng.html#libraw_iparams_t">libraw_iparams_t</a>),</li>
156
<li>imgdata.sizes (<a href="API-datastruct-eng.html#libraw_image_sizes_t">libraw_image_sizes_t</a>),</li>
157
<li>imgdata.color (<a href="API-datastruct-eng.html#libraw_colordata_t">libraw_colordata_t</a>),</li>
158
<li>imgdata.other (<a href="API-datastruct-eng.html#libraw_imgother_t">libraw_imgother_t</a>), and </li>
159
<li>imgdata.thumbnail (<a href="API-datastruct-eng.html#libraw_thumbnail_t">libraw_thumbnail_t</a>).</li>
161
<p>The function returns an integer number in accordance with the <a href=API-notes-eng.html#errors>return
162
code convention</a>: positive if any system call has returned an error, negative
163
(from the <a href=API-datastruct-eng.html#LibRaw_errors>LibRaw error list</a>) if there has been an error
164
situation within LibRaw.
166
<p>Before file opening, <a href="#recycle">recycle()</a> is always called; hence, if several images
167
are processed in the batch mode, there is no need to call recycle() at the end of each processing cycle.
169
<p><b>Input data</b>: pointer to object, derived from <a href="#datastream">LibRaw_abstract_datastream</a> class.
170
This object should be initialized and ready to read. This object should be destroyed in calling application
173
<a name=open_file></a>
174
<h3>int LibRaw::open_file(const char *filename)</h3>
176
Creates an <a href="#file_datastream">LibRaw_file_datastream</a> object, calls
177
<a href="#open_datastream">open_datastream()</a>. If succeed, sets internal flag which signals
178
to destroy internal datastream object on <a href="#recycle">recycle()</a>. On failure,
179
just created file_datastream destroyed immediately.
181
<p>The function returns an integer number in accordance with the
182
<a href=API-notes-eng.html#errors>return code convention</a>: positive if any system call has returned an error, negative
183
(from the <a href=API-datastruct-eng.html#LibRaw_errors>LibRaw error list</a>) if there has been an error
184
situation within LibRaw.
187
<a name=open_buffer></a>
188
<h3>int LibRaw::open_buffer(void *buffer, size_t bufsize)</h3>
190
Created an <a href="#buffer_datastream">LibRaw_buffer_datastream</a> object, calls
191
<a href="#open_datastream">open_datastream()</a>. If succeed, sets internal flag which signals
192
to destroy internal datastream object on <a href="#recycle">recycle()</a>. On failure,
193
just created file_datastream destroyed immediately.
195
<p>The function returns an integer number in accordance with the
196
<a href=API-notes-eng.html#errors>return code convention</a>: positive if any system call has returned an error, negative
197
(from the <a href=API-datastruct-eng.html#LibRaw_errors>LibRaw error list</a>) if there has been an error
198
situation within LibRaw.
201
<a name="unpack"></a>
202
<h3> int LibRaw::unpack(void)</h3>
204
Unpacks the RAW files of the image, calculates the black level (not for all formats), subtracts black
205
(not for all formats). The results are placed in imgdata.image.
208
Data reading is sometimes (not frequently) affected by settings made in imgdata.params (<a
209
href="API-datastruct-eng.html#libraw_output_params_t">libraw_output_params_t</a>); see <a
210
href=API-notes-eng.html>API notes</a> for details.
212
<p>The function returns an integer number in accordance with the <a href=API-notes-eng.html#errors>return code
213
convention</a>: positive if any system call has returned an error, negative (from the
214
<a href=API-datastruct-eng.html#LibRaw_errors>LibRaw error list</a>) if there has been an error
215
situation within LibRaw.
218
<a name="unpack_thumb"></a>
219
<h3>int LibRaw::unpack_thumb(void)</h3>
221
Reads (or unpacks) the image preview (thumbnail), placing the result into the imgdata.thumbnail.thumb buffer.<br/>
222
JPEG previews are placed into this buffer without any changes (with the header etc.). Other preview
223
formats are placed into the buffer in the form of the unpacked bitmap image (three components, 8 bits per component).<br/>
224
The thumbnail format is written to the imgdata.thumbnail.tformat field; for the possible values, see
225
<a href="API-datastruct-eng.html#LibRaw_thumbnail_formats">description of constants and data structures</a>.
228
<p>The function returns an integer number in accordance with the <a href=API-notes-eng.html#errors>return code
229
convention</a>: positive if any system call has returned an error, negative (from the
230
<a href=API-datastruct-eng.html#LibRaw_errors>LibRaw error list</a>) if there has been an error situation within
233
<a name="utility"></a>
234
<h2>Auxiliary Functions</h2>
235
<h3>Library version check</h3>
236
<a name="version"></a>
237
<h4>const char* LibRaw::version()</h4>
239
Returns string representation of LibRaw version in MAJOR.MINOR.PATCH-Status format (i.e. 0.6.0-Alpha2
242
<a name="versionNumber"></a>
243
<h4>int LibRaw::versionNumber()</h4>
245
Returns integer representation of LibRaw version. During LibRaw development, the version number is always
248
<a name="LIBRAW_CHECK_VERSION"></a>
249
<h4>bool LIBRAW_CHECK_VERSION(major,minor,patch)</h4>
251
Macro for version check in caller applications. Returns 'true' if current library version is greater or equal to
252
set in macro parameters. This macro executes at runtime (not at compile time) and may be used for checking
253
version of dynamically loaded LibRaw (from DLL/shared library).
255
<h3>List of supported RAW formats (cameras)</h3>
256
<a name="cameraCount"></a>
257
<h4>int LibRaw::cameraCount()</h4>
259
Returns count of cameras supported.
261
<a name="cameraList"></a>
262
<h4>const char** LibRaw::cameraList()</h4>
264
Returns list of supported cameras. Latest item of list is set to NULL (for easy printing).
266
<a name="unpack_function_name"></a>
267
<h3>const char* LibRaw::unpack_function_name()</h3>
269
Returns function name of file unpacking function. Intended only for LibRaw test suite designers to use in test
273
<a name="add_masked_borders_to_bitmap"></a>
274
<h3>void LibRaw::add_masked_borders_to_bitmap</h3>
276
This call rebuilds <b>imgdata.image</b> bitmap and makes full bitmap, contains both image data (active
277
pixels) and 'black border' (masked pixels). If no masked pixels data present, then this call does nothing.
278
Function call changes data fields <b>sizes.width,sizes.height,sizes.iwidth,sizes.iheight</b> to full image
279
size (i.e. raw_width/raw_height).<br/>
280
This call does nothing:
283
<li>for images containing more than one color component per pixel (full-color DNG,
284
already demosaiced files: Canon sRAW, Sinar 4-shot etc).</li>
285
<li>for images, unpacked with half resolution (one of parameters set in options: half_mode, wavelet denoising
286
threshold, aberration fixing data).
289
<p>The function returns an integer number in accordance with the <a href=API-notes-eng.html#errors>return code
290
convention</a>: positive if any system call has returned an error, negative (from the
291
<a href=API-datastruct-eng.html#LibRaw_errors>LibRaw error list</a>) if there has been an error situation within
294
<a name="rotate_fuji_raw"></a>
295
<h3> int LibRaw:: rotate_fuji_raw()</h3>
297
This function rotates non-interpolated RAW bitmap from FujiCCD sensors into 45-degree-rotated position,
298
compatible with old LibRaw versions (prior to LibRaw 0.7). This call is intended for applications,
299
which works with non-interpolated/non-demosaiced RAW data itself. If
300
dcraw_process/dcraw_document_mode_processing calls are used, these call make the rotation internally.
302
<p>The function returns an integer number in accordance with the <a href=API-notes-eng.html#errors>return code
303
convention</a>: positive if any system call has returned an error, negative (from the
304
<a href=API-datastruct-eng.html#LibRaw_errors>LibRaw error list</a>) if there has been an error situation within
308
<a name="recycle"></a>
309
<h3>void LibRaw::recycle(void)</h3>
310
<p>Frees the allocated data of LibRaw instance, enabling one to process the next file using
311
the same processor. Repeated calls of recycle() are quite possible and do not conflict with anything.
314
<a name="~LibRaw"></a>
315
<h3>LibRaw::~LibRaw()</h3>
316
<p>Destructor, which consists in calling recycle().</p>
318
<a name="strprogress"></a>
319
<h3>const char* LibRaw::strprogress(enum LibRaw_progress code)</h3>
320
<p>Converts progress stage code to description string (in English).</p>
322
<a name="libraw_strerror"></a>
323
<h3>const char* LibRaw::strerror(int errorcode)</h3>
324
<p>Analog of strerror(3) function: outputs the text descriptions of LibRaw error codes (in English).</p>
326
<a name="callbacks"></a>
327
<h3>Setting Error Notification Functions</h3>
329
In process of RAW conversion LibRaw can call user-setted callback. This callback can be used for:
332
<li>Dynamic status update (progress bar and so on).</li>
333
<li>Cancel of processing (for example, user pressed Cancel button).</li>
335
<p>Also, work of the library may cause two types of exceptional situations that require notification of the calling application:
338
<li>Memory shortage</li>
339
<li>Data read error.</li>
342
An application may set its own callbacks that will be called in the cases mentioned above to notify the user (or the calling program).
344
<a name="progress"></a>
345
<h4>Progress indication/processing termination</h4>
347
typedef int (*progress_callback)(void *callback_data,enum LibRaw_progress stage, int iteration, int expected);
348
void LibRaw::set_progress_handler(progress_callback func,void *callback_data);
351
LibRaw user can set own callback which will be called 10-50 times during RAW postprocessing
352
by dcraw_process()/dcraw_document_mode_processing();
355
This callback may terminate current image processing by returning of non-zero value. In such case all processing
356
will be cancelled immediately and all resources will be returned to system by recycle() call.
357
Current call of dcraw_process()/dcraw_document_mode_processing() will return error code
358
LIBRAW_CANCELLED_BY_CALLBACK.
363
<dt>void *callback_data</dt>
364
<dd>void*-pointer, passed as 2nd argument to set_progress_handler(). This pointer should be used to pass
365
additional data to callback (i.e. thread local data and so on).
367
<dt>enum LibRaw_progress stage</dt>
368
<dd>Current processing stage. This number can be converted to string by call to
369
<a href="#strprogress">LibRaw::strprogress</a>. Not all processing stages are covered by callback calls.
371
<dt>int iteration</dt>
372
<dd>Iteration number within current stage (from 0 to expected-1).
374
<dt>int expected</dt>
375
<dd>Expected number of iterations on current stage.</dd>
377
Callback should return value of: <b>0</b> for continue processing and <b>non-zero</b> for immediate cancel of processing.
380
If LibRaw compiled with OpenMP support, iteration parameter may not always increase within one stage. Out of
381
order callback calls are possible.
384
Callback code sample:
386
int my_progress_callback(void *data,enum LibRaw_progress p,int iteration, int expected)
388
char *passed_string = (char *data);
389
printf("Callback: %s pass %d of %d, data passed: %s\n",libraw_strprogress(p),iteration,expected,passed_string);
390
if(timeout || key_pressed )
391
return 1; // cancel processing immediately
393
return 0; // can continue
398
<a name="memerror"></a>
399
<h4>Out-of-Memory Notifier</h4>
401
typedef void (* memory_callback)(void *callback_data,const char *file, const char *where);
402
void LibRaw::set_memerror_handler(memory_callback func,void *callback_data);
404
<p>The user may set his or her own function called in the case of memory shortage. It is a void function
405
receiving two string parameters:
408
<li><b>void *callback_data</b> - void*-pointer, passed as 2nd argument to set_progress_handler(). This pointer
409
should be used to pass additional data to callback (i.e. thread local data and so on).</li>
410
<li><b>file</b> is the name of the RAW file whose processing evoked the out-of-memory error.
411
This name <b>can be NULL</b> if underlying data input layer does not know the name. So, if calling
412
application sets own callback, this callback should work with NULL file name.
414
<li><b>where</b> is the name of the function where memory shortage occurred.</li>
416
<p>The callback function is intended for information purposes: it notifies the user
417
or the program code that processing is impossible.</p>
418
<p>If the user does not set his or her own handler, the standard one (output of error message in stderr) will be used.</p>
419
<p>One can set the null handler by passing NULL to set_memerror_handler; then no notifier
420
function will be called. The same effect can be achieved by creating a LibRaw object with the LIBRAW_OPTIONS_NO_MEMERR_CALLBACK
421
flag in the contructor.
423
<p>In the case of memory shortage, processing of the current file is terminated and a notifier is called; all
424
allocated resources are freed, and <a href="#recycle">recycle()</a> is performed. The current call will return
425
LIBRAW_UNSUFFICIENT_MEMORY.
427
At an attempt to continue data processing, all subsequent calls will return LIBRAW_OUT_OF_ORDER_CALL.
428
Processing of a new file may be started in the usual way, by calling LibRaw::open_file().
430
<a name="dataerror"></a>
431
<h4>File Read Error Notifier</h4>
433
typedef void (*data_callback)(void *callback_data,const char *file, const int offset);
434
void LibRaw::set_dataerror_handler(data_callback func, void *callback_data);
437
The user can define his or her own function to be called in the case of error in the input data. It is a void function receiving
441
<li><b>void *callback_data</b> - void*-pointer, passed as 2nd argument to set_progress_handler(). This pointer
442
should be used to pass additional data to callback (i.e. thread local data and so on).</li>
443
<li><b>file</b> is the name of the RAW file whose processing evoked the file read error.
444
This name <b>can be NULL</b> if underlying data input layer does not know the name. So, if calling
445
application sets own callback, this callback should work with NULL file name.
447
<li><b>offset</b> is -1 at end-of-file (if LibRaw expects more data) or a positive number equal to
448
the file position (bytes from file beginning) where the unpacking error occurred.</li>
450
<p>The callback function is intended for information purposes: it notifies the user
451
or the program code that processing is impossible.</p>
452
<p>If the user does not set his or her own handler, the standard one (output of error message in stderr) will be used.</p>
453
<p>One can set the null handler by passing NULL to set_memerror_handler; then no notifier
454
function will be called. The same effect can be achieved by creating a LibRaw object with the LIBRAW_OPTIONS_NO_DATAERR_CALLBACK
455
flag in the contructor. </p>
456
<p>In the case of error in the input data, processing of the current file is terminated and a notifier is called; all
457
allocated resources are freed, and <a href="#recycle">recycle()</a> is performed. The current call will return
460
At an attempt to continue data processing, all subsequent calls will return LIBRAW_OUT_OF_ORDER_CALL.
461
Processing of a new file may be started in the usual way, by calling LibRaw::open_file().
464
<a name="dcrawemu"></a>
465
<h2>Data Postprocessing: Emulation of dcraw Behavior</h2>
467
Instead of writing one's own Bayer pattern postprocessing, one can use the dcraw functions, which are called
468
after the calls of open_file() + unpack() /+ unpack_thumb()/
470
<a name="dcraw_params"></a>
471
<h3>Parameter Setting</h3>
473
Virtually all parameters that can be set through the dcraw command line are specified by assigning values to
474
fields of the <b>LibRaw::imgdata.params</b> structure. The type of this structure is <b>libraw_output_params_t</b>;
475
all fields are listed and described in sufficient detail in the <a href="API-datastruct-eng.html#libraw_output_params_t">description
476
of data structures</a>.
479
<a name="adjust_sizes_info_only"></a>
480
<h3>int LibRaw::adjust_sizes_info_only(void)</h3>
482
The function calculates the correct size of the output image (imgdata.sizes.iwidth and imgdata.sizes.iheight) for the
486
<li>Files from Fuji cameras (with a 45-degree rotation)</li>
487
<li>Files from cameras with non-square pixels</li>
488
<li>Images shot by a rotated camera.</li>
491
In the aforementioned cases, the function changes the fields of the image output size; note that
492
this change cannot be repeated again.
495
The function should be used for information purposes; it is incompatible with <a
496
href="#dcraw_document_mode_processing">dcraw_document_mode_processing()</a> and <a
497
href="#dcraw_process">dcraw_process()</a> calls.
500
<a name="dcraw_document_mode_processing"></a>
501
<h3>int LibRaw::dcraw_document_mode_processing(void)</h3>
503
The function emulates <b>dcraw -D</b>: no interpolation, white balance, and color conversion.<br/>
504
It is called after calling LibRaw::unpack();
506
<p>The function returns an integer number in accordance with the <a href=API-notes-eng.html#errors>error
507
code convention</a>: positive if any system call has returned an error, negative (from the
508
<a href=API-datastruct-eng.html#LibRaw_errors>LibRaw error list</a>) if there has been an error situation within
512
<a name="dcraw_process"></a>
513
<h3>int LibRaw::dcraw_process(void)</h3>
515
The function emulates the postprocessing capabilities available in <b>dcraw</b>.<br/>
516
Called after calling LibRaw::unpack();
518
<p>The entire functionality of dcraw (set via the field values in <a
519
href="API-datastruct-eng.html#libraw_output_params_t">imgdata.params</a>) is supported, except for
522
<li>Dark frame subtraction</li>
523
<li>Work with bad pixels.</li>
525
<p>The function is intended solely for demonstration and testing purposes; it is assumed that its source code
526
will be used in most real applications as the reference material concerning the order of RAW data processing.
528
<p>The function returns an integer number in accordance with the <a href=API-notes-eng.html#errors>error
529
code convention</a>: positive if any system call has returned an error, negative (from the
530
<a href=API-datastruct-eng.html#LibRaw_errors>LibRaw error list</a>) if there has been an error situation within
533
<a name="dcrawrite"></a>
534
<h2>Data Output to Files: Emulation of dcraw Behavior</h2>
535
<p>In spite of the abundance of libraries for file output in any formats, LibRaw includes calls that emulate
536
the file output provided by dcraw. This is done primarily for easier verification of library work: the resultant
537
files must be binary identical.
540
<a name="dcraw_ppm_tiff_writer"></a>
541
<h3>int LibRaw::dcraw_ppm_tiff_writer(const char *outfile)</h3>
543
The function outputs the postprocessing results to a file in the PPM/PGM or TIFF format (the format is set via
544
imgdata.params.output_tiff). The results are binary identical to those provided by dcraw.
546
<p>The function returns an integer number in accordance with the <a href=API-notes-eng.html#errors>error
547
code convention</a>: positive if any system call has returned an error, negative (from the
548
<a href=API-datastruct-eng.html#LibRaw_errors>LibRaw error list</a>) if there has been an error situation within
551
<a name="dcraw_thumb_writer"></a>
552
<h3>int LibRaw::dcraw_thumb_writer(const char *thumbfile)</h3>
553
<p>Writes the thumbnail to a file in the PPM format for bitmap thumbnails and in the JPEG format for JPEG thumbnails, i.e.,
554
in the format completely identical to the results provided by dcraw.
556
<p>The function returns an integer number in accordance with the <a href=API-notes-eng.html#errors>error
557
code convention</a>: positive if any system call has returned an error, negative (from the
558
<a href=API-datastruct-eng.html#LibRaw_errors>LibRaw error list</a>) if there has been an error situation within
561
<a name="memwrite"></a>
562
<h2>Copying unpacked data into memory buffer</h2>
564
There is two function calls for store unpacked data into memory buffer (after using dcraw_process() and so on):
566
<li><b>dcraw_make_mem_image</b> - store processed image data into allocated buffer;
568
<li><b>dcraw_make_mem_thumb</b> - store extracted thumbnail into buffer as JPEG-file image (for most cameras)
572
For usage primer see samples/mem_image.c sample.
574
<a name="dcraw_make_mem_image"></a>
575
<h3>libraw_processed_image_t *dcraw_make_mem_image(int *errorcode=NULL) - store unpacked and processed image into
576
memory buffer as RGB-bitmap</h3>
578
This function allocates memory buffer and stores unpacked-preprocessed image into this buffer. Function returns
579
allocated structure <a href="API-datastruct-eng.html#libraw_processed_image_t">libraw_processed_image_t</a> with
580
filled fields. Always returns data as RGB bitmap (i.e. <b>type</b> field is equal to LIBRAW_IMAGE_BITMAP).
584
dcraw_process() or dcraw_document_mode_processing() should be called before dcraw_make_mem_image();
587
Returns NULL in case of an error. If caller has passed not-NULL value as errorcode parameter, than *errorcode
588
will be set to error code according to <a href="API-notes-eng.html#errors">error code convention</a>.
590
<p><b>NOTE!</b> Memory, allocated for return value will not be fried at destructor or <b>LibRaw::recycle</b>
591
calls. Caller of dcraw_make_mem_image should free this memory by call to free().
594
<a name="dcraw_make_mem_thumb"></a>
595
<h3>libraw_processed_image_t *dcraw_make_mem_thumb(int *errorcode=NULL) - store unpacked thumbnail into memory buffer</h3>
597
This function allocates memory buffer and stores thumbnail data in it. Function returns allocated
598
structure <a href="API-datastruct-eng.html#libraw_processed_image_t">libraw_processed_image_t</a> with
599
filled fields. For most RAW images allocated structure will contains JPEG image (i.e. <b>type</b>
600
field is equal to LIBRAW_IMAGE_JPEG). For some cameras with RGB-bitmap thumbnail (Kodak SLRs)
601
returned structure contains RGB bitmap (<b>type</b> field is equal to LIBRAW_IMAGE_JPEG, see structure
602
description for details).
605
unpack_thumb() should be called before dcraw_make_mem_thumb();
608
Returns NULL in case of an error. If caller has passed not-NULL value as errorcode parameter, than *errorcode
609
will be set to error code according to � <a href=API-notes-eng.html#errors>error code convention</a>.
611
<p><b>NOTE!</b> Memory, allocated for return value will not be fried at destructor or <b>LibRaw::recycle</b>
612
calls. Caller of dcraw_make_mem_image should free this memory by call to free().
615
<a name="datastream"></a>
616
<h2>Input layer abstraction</h2>
617
<a name="LibRaw_abstract_datastream"></a>
618
<h3>class LibRaw_abstract_datastream - abstract RAW read interface</h3>
620
LibRaw reads RAW-data by calling (virtual) methods of C++ object derived from
621
<b>LibRaw_abstract_datastream</b>. This C++ class does not implement any read, but defines interface to be
622
called. Call to base class methods always results in error.
624
<a name="datastream_methods"></a>
625
<h4>LibRaw_abstract_datastream class methods</h4>
626
<a name="datastream_methods_utility"></a>
627
<h5>Object verification</h5>
629
<dt><b> virtual int valid()</b></dt>
630
<dd>Checks input datastream validity. Returns 1 on valid stream and 0 if datastream was created on non-valid
631
input parameters (wrong filename for file stream and so on).
633
<a name="datastream_methods_read"></a>
634
<h5>Stream read and positioning</h5>
635
<p>This group of methods implements file object (FILE*) semantics.</p>
637
<dt><b>virtual int read(void * ptr,size_t size, size_t nmemb)</b></dt>
639
Similar to fread(ptr,size,nmemb,file).
641
<dt><b>virtual int seek(off_t o, int whence)</b></dt>
643
Similar to fseek(file,o,whence).
645
<dt><b>virtual int tell(</b></dt>
647
Similar to ftell(file).
649
<dt><b>virtual int get_char()</b></dt>
651
Similar to getc(file)/fgetc(file).
653
<dt><b>virtual char* gets(char *s, int n)</b></dt>
655
Similar to fgets(s,n,file).
657
<dt><b>virtual int eof()</b></dt>
659
Similar to feof(file).
661
<dt><b>virtual int scanf_one(const char *fmt, void *val)</b></dt>
663
Simplified variant of fscanf(file,fmt,val): format string is always contains one argument to read. So,
664
variable args call is not needed and only one pointer to data passed.
667
<a name="datastream_methods_other"></a>
668
<h5>Other methods</h5>
669
<p>This group of methods includes several supplementary calls. These calls are used to temporary switch to another
670
data stream (file and/or memory buffer).
673
<dt><b>virtual const char* fname()</b></dt>
675
Returns name of opened file if datastream object knows it (for example,
676
<b>LibRaw_file_datastream</b> used). Filename used in:
678
<li>error notofocation callbacks;</li>
679
<li>generation of filename of JPEG-file with metadata when needed (i.e. cameras with 'Diag RAW hack').
682
<dt><b>virtual int subfile_open(const char *fn)</b></dt>
684
This call temporary switches input to file <b>fn</b>. Returns 0 on success and error code on error.<br/>
685
The function used to read metadata from external JPEG file (on cameras with "Diag RAW hack").
687
This call is not implemented for <a href="#buffer_datastream">LibRaw_buffer_datastream</a>, so
688
external JPEG processing is not possible when buffer datastream used.
690
This functon should be implemented in real input class, base class call always return error.
692
Working implementation sample can be found in
693
<a href="#file_datastream">LibRaw_file_datastream</a> implementation in <b>libraw/libraw_datastream.h</b> file.
695
<dt><b> virtual void subfile_close()</b></dt>
697
This call switches input stream from temporary open file back to main data stream.
699
<dt><b> virtual int tempbuffer_open(void *buf, size_t size)</b></dt>
701
This call temporary switches input to <a href="#buffer_datastream">LibRaw_buffer_datastream</a> object,
702
created from <b>buf</b>.<br/>
703
This method is needed for Sony encrypted metadata parser.
705
This call implemented in base class (<b>LibRaw_abstract_datastream</b>), there is no need to
706
reimplement in in derived classes.<br/>
707
Possible activity of temporary datastream requires very accurate programming when implementing
708
datastreams derived from base <b>LibRaw_abstract_datastream</b>. See <a href="#substream">below</a>
711
<dt><b> virtual void tempbuffer_close()</b></dt>
713
This call switch input back from temporary datastream to main stream. This call implemented
714
in base <b>LibRaw_abstract_datastream</b> class.
718
<a name="datastream_derived"></a>
719
<h3>Derived input classes included in LibRaw</h3>
721
There is two "standard" input classes in LibRaw distribution:
724
<li><a href="#file_datastream">LibRaw_file_datastream</a> implements input from file (in filesystem).</li>
725
<li><a href="#buffer_datastream">LibRaw_buffer_datastream</a> implements input from memory buffer.</li>
728
LibRaw C++ interface users can implement their own input classes and use them via
729
<a href="#open_datastream">LibRaw::open_datastream</a> call. Requirements and implementation specifics are
732
<a name="file_datastream"></a>
733
<h4>class LibRaw_file_datastream - file input interface</h4>
735
This class implements input from file.
737
<p><b>Class methods:</b></p>
739
<dt><b> LibRaw_file_datastream(const char *fname) </b></dt>
741
This constructor creates <b>LibRaw_file_datastream</b> object from file <b>fname</b>.<br/>
742
Unfortunately, C++ constructor cannot return an error. So if bad filename passed (e.g. nonexistent file)
743
object is created as non-valid (valid() call returns zero).
747
All other class methods are <a href="#datastream_methods">described above</a>.<br/>
748
This class implements all possble methods, including fname() and subfile_open().
750
<a name="buffer_datastream"></a>
751
<h4>class LibRaw_buffer_datastream - memory buffer input interface</h4>
753
This class implements input from memory buffer.
755
<p><b>Class methods:</b></p>
757
<dt><b> LibRaw_buffer_datastream(void *buffer, size_t bsize)</b></dt>
759
This constructor creates datastream object from <b>buffer</b> with size <b>bsize</b>.<br/>
760
It is not possibly to verify the pointer passed, so buffer address is checked against 0 and -1 only.
764
All other class methods are <a href="#datastream_methods">described above</a>.<br/>
765
This class does not implement fname() and subfile_open() calls, so external JPEG metadata parsing
768
<a name="own_datastreams"></a>
769
<h3>Own datastream derived classes</h3>
771
To create own read interface LibRaw user should implement C++ class derived from
772
<b>LibRaw_abstract_datastream</b> with all read methods.<br/>
773
LibRaw standard implementations may be used as reference. See <b>libraw/libraw_datastream.h</b> file for details
774
(all standard LibRaw input classes are implemented using inline functions only).
776
<a name="substream"></a>
777
<h4>substream field: secondary input stream</h4>
779
<b>substream</b> field, defined in base LibRaw_abstract_datastream class requires some additional notes.
780
This field is used when input switched to temporary buffer (used for Sony metadata processing). Unfortunately,
781
there is now ideal C++ way to hide this functionality into base class internals. So, any read call in
782
derived class should include 1-line statement like this:<br/>
783
<b>int method(...args...){ if(substream) return substream->method(...args...)</b>. For example:
787
if(substream) return substream->eof();
789
virtual int scanf_one(const char *fmt, void* val)
791
if(substream) return substream->scanf_one(fmt,val);
796
<a href=index-eng.html>[back to Index]</a>
798
<address><a href="mailto:info@libraw.org">LibRaw Team</a></address>
799
<!-- Created: Sun Mar 16 10:08:29 MSK 2008 -->
801
Last modified: Fri Apr 9 11:34:30 MSD 2010