[back to Index]
LibRaw: Data Structures and Constants
LibRaw data structures are defined in header file libraw/libraw_types.h
Constants used in its work are defined in file libraw/libraw_const.h
Contents:
- Data structures
- libraw_data_t: Main Data Structure in LibRaw
- Structure libraw_iparams_t: Main Parameters of the Image
- Structure libraw_image_sizes_t: Image Dimensions
- Structure libraw_colordata_t: Color Information
- Structure color_data_state_t: Description of Color Data Source
- Structure libraw_imgother_t: Other Parameters of the Image
- Structure libraw_thumbnail_t: Description of Thumbnail
- Structure libraw_output_params_t: Management of dcraw-Style Postprocessing.
- Constants
- enum LibRaw_errors: Error Codes
- enum LibRaw_progress: Current State of LibRaw Object
- enum LibRaw_thumbnail_formats: Thumbnail Data Formats
- Nonstandard Situations (Warnings) during RAW Data Processing
- enum LibRaw_colorstate: Type of Color Data Source.
Data Structures
libraw_data_t: Main Data Structure of LibRaw
Structure libraw_data_t is a "wrapping" for data structures accessible to the user of the library.
When one uses C++ API, it is accessible as LibRaw::imgdata (class_instance.imgdata). The data in this structure appear after
a file is opened through open_file, except for the image itself (filled by unpack()) and data containing
the preview information (filled by calling unpack_thumb()).
Data fields:
- unsigned int progress_flags;
-
This field records the past phases of image processing.
- unsigned int progress_flags;
-
This field records suspicious situations (warnings) that have emerged during image processing.
- libraw_iparams_t idata;
-
The structure describes the main image parameters retrieved from the RAW file. Fields of this structure
are described in detail below.
- libraw_image_sizes_t sizes;
-
The structure describes the geometrical parameters of the image. Fields of this structure
are described in detail below.
- libraw_colordata_t color;
-
The structure contains color data retrieved from the file. Fields of this structure
are described in detail below.
- libraw_imgother_t other;
-
Data structure for information purposes: it contains the image parameters that have been extracted from the file but are
not needed in further file processing. Fields of this structure are described in detail below.
- libraw_thumbnail_t thumbnail;
-
Data structure containing information on the preview and the preview data themselves. All fields of this
structure are filled when open_file() is called. The fields are described in detail below.
- ushort (*image)[4];
-
The memory area that contains the image pixels per se. It is filled when unpack() is called.
- libraw_output_params_t params;
-
Data structure intended for management of image postprocessing (using the dcraw emulator).
Fields of this structure are described in detail below.
Structure libraw_iparams_t: Main Parameters of the Image
- char make[64];
-
Camera manufacturer.
- char model[64];
-
Camera model.
- unsigned raw_count;
-
Number of RAW images in file (0 means that the file has not been recognized).
- unsigned dng_version;
-
DNG version (for the DNG format).
- unsigned is_foveon;
-
1 for Foveon matrices, 0 for others.
- int colors;
-
Number of colors in the file.
- unsigned filters;
-
Bit mask describing the order of color pixels in the matrix (0 for Foveon). 32 bits of this field describe 16 pixels
(8 rows with two pixels in each, from left to right and from top to bottom). Each two bits have values 0 to 3, which
correspond to four possible colors. Convenient work with this field is ensured by the FC(row,column) function,
which returns the number of the active color for a given pixel.
- char cdesc[5];
-
Description of colors numbered from 0 to 3 (RGBG,RGBE,GMCY, or GBTG).
Structure libraw_image_sizes_t: Image Dimensions
Structure libraw_image_sizes_t is a collection of all file data that describe the size of the image.
Data fields:
- ushort raw_height, raw_width;
-
Full size of RAW image (including the frame) in pixels.
- ushort height, width;
-
Size of visible ("meaningful") part of the image (without the frame).
- ushort top_margin, left_margin;
-
Coordinates of the top left corner of the frame (the second corner is calculated from the full size of the image and size of its visible part).
- ushort iheight, iwidth;
-
Size of the output image (may differ from height/width for cameras that require image rotation or have non-square pixels).
- double pixel_aspect;
-
Pixel width/height ratio. If it is not unity, scaling of the image along one of the axes is required during output.
- int flip;
-
Image orientation (0 if does not require rotation; 3 if requires 180-deg rotation; 5 if 90 deg counterclockwise, 6 if 90 deg clockwise).
Structure libraw_colordata_t: Color Information
Structure libraw_colordata_t unites all color data, both retrieved from the RAW file and calculated on the basis of the
image itself. For different cameras, there are different ways of color handling.
Data fields:
- color_data_state_t color_flags;
-
Data structure describing the sources of color data. Described below in more detail.
- ushort white[8][8];
-
Block of white pixels extracted from files CIFF/CRW. Not extracted for other formats. Used to calculate white
balance coefficients.
- float cam_mul[4];
-
White balance coefficients (as shot). Either read from file or calculated.
- float pre_mul[4];
-
White balance coefficients for daylight (daylight balance). Either read from file, or calculated on the basis of file data,
or taken from hardcoded constants.
- float cmatrix[3][4];
-
White balance matrix. Read from file for some cameras, calculated for others.
- float rgb_cam[3][4];
-
Another white balance matrix, read from file for Leaf and Kodak cameras.
- ushort curve[0x4001];
-
Camera tone curve, read from file for Nikon, Sony and some other cameras.
- unsigned black;
-
Black level. Depending on the camera, it may be zero (this means that black has been subtracted at the unpacking stage
or by the camera itself), calculated at the unpacking stage, read from the RAW file, or hardcoded.
- unsigned maximum;
-
Maximum pixel value. Calculated from the data for some cameras, hardcoded for others.
- ph1_t phase_one_data;
-
Color data block that is read for Phase One cameras.
- float flash_used;
- float canon_ev;
-
Fields used for white balance calculations (for some P&S Canon cameras).
- char model2[64];
-
White balance description for Foveon cameras.
- void *profile;
-
Pointer to the retrieved ICC profile (if it is present in the RAW file).
- unsigned profile_length;
-
Length of ICC profile in bytes.
Structure color_data_state_t: Description of Color Data Source
This structure (actually, a bit field) describes the source of color data for each field of structure libraw_colordata_t, which may be obtained from different data sources.
Data fields:
unsigned curve_state : 3;
unsigned rgb_cam_state : 3;
unsigned cmatrix_state : 3;
unsigned pre_mul_state : 3;
unsigned cam_mul_state : 3;
Each field assumes one of the values that are possible for enum LibRaw_colorstate.
Structure libraw_imgother_t: Other Parameters of the Image
Structure libraw_imgother_t is a collection of data that have been read from the RAW file but are not needed for image postprocessing.
Data fields:
- float iso_speed;
-
ISO sensitivity.
- float shutter;
-
Shutter speed.
- float aperture;
-
Aperture.
- float focal_len;
-
Focal length.
- time_t timestamp;
-
Date of shooting.
- unsigned shot_order;
-
Serial number of image.
- unsigned gpsdata[32];
-
GPS data.
- char desc[512];
-
Image description.
- char artist[64];
-
Author of image.
Structure libraw_thumbnail_t: Description of Thumbnail
Structure libraw_thumbnail_t describes all parameters associated with the preview saved in the RAW file.
Data fields:
- LibRaw_thumbnail_formats tformat;
-
Thumbnail data format. One of the values among enum LibRaw_thumbnail_formats.
- ushort twidth, theight;
-
Dimensions of the preview image in pixels.
- unsigned tlength;
-
Thumbnail length in bytes.
- int tcolors;
-
Number of colors in the preview.
- char *thumb;
-
Pointer to thumbmail, extracted from the data file.
Structure libraw_output_params_t: Management of dcraw-Style Postprocessing
Structure libraw_output_params_t is used for management of dcraw-compatible calls dcraw_process(),
dcraw_ppm_tiff_writer(), dcraw_thumb_writer(), and dcraw_document_mode_processing(). Fields of this structure
correspond to command line keys of dcraw.
Data fields:
- unsigned greybox[4];
-
dcraw keys: -A x1 y1 x2 y2
4 numbers corresponding to the coordinates (in pixels) of the rectangle that is used to calculate the white balance.
- double aber[4];
-
dcraw keys: -C
Correction of chromatic aberrations; the only specified values are
aber[0], the red multiplier
aber[2], the green multiplier.
For some formats, it affects RAW data reading, since correction of aberrations
changes the output size.
- float user_mul[4];
-
dcraw keys: -r mul0 mul1 mul2 mul3
4 multipliers (r,g,b,g) of the user's white balance.
- unsigned shot_select, multi_out;
-
dcraw keys: -s
Selection of image number for processing (for formats that contain several RAW images in one file). The
multi_out ( -s all) mode should be programmed by the user, since dcraw_process() does not support it.
- float bright;
-
dcraw keys: -b
Brightness (default 1.0).
- float threshold;
-
dcraw keys: -n
Parameter for noise reduction through wavelet denoising.
- int half_size;
-
dcraw keys: -h
Outputs the image in 50% size. For some formats, it affects RAW data reading.
- int four_color_rgb;
-
dcraw keys: -f
Switches on separate interpolations for two green components.
- int document_mode;
-
dcraw keys: -d/-D
0: standard processing (with white balance)
1: corresponds to -d (without color processing or debayer)
2: corresponds to -D (-d without white balance).
- int highlight;
-
dcraw keys: -H
0-9: Highlight mode (0=clip, 1=unclip, 2=blend, 3+=rebuild).
- int use_auto_wb;
-
dcraw keys: -a
Use automatic white balance obtained after averaging over the entire image.
- int use_camera_wb;
-
dcraw keys: -w
If possible, use the white balance from the camera.
- int use_camera_matrix;
-
dcraw keys: +M/-M
Use (1)/don't use camera color matrix.
- int output_color;
-
dcraw keys: -o
[0-5] Output colorspace (raw, sRGB, Adobe, Wide, ProPhoto, XYZ).
- int output_bps;
-
dcraw keys: -4
8 bit (default)/16 bit (key -4).
- int output_tiff;
-
dcraw keys: -T
0/1: output PPM/TIFF.
- int user_flip;
-
dcraw keys: -t
[0-7] Flip image (0=none, 3=180, 5=90CCW, 6=90CW).
Default -1, which means taking the corresponding value from RAW.
For some formats, affects RAW data reading, e.g., unpacking of thumbnails
from Kodak cameras.
- int user_qual;
-
dcraw keys: -q
0-3: interpolation quality (0 - linear, 1- VNG, 2 - PPG, 3 - AHD).
- int user_black;
-
dcraw keys: -k
User black level.
- int user_sat;
-
dcraw keys: -S
Saturation adjustment.
- int med_passes;
-
dcraw keys: -m
Number of median filter passes.
- int no_auto_bright;
-
dcraw keys: -W
Don't use automatic increase of brightness by histogram.
- int use_fuji_rotate;
-
dcraw keys: -j
Default -1 (use), 0 - don't use rotation for cameras on a Fuji sensor.
- char *bpfile;
-
dcraw keys: -P
Name of file with bad pixel map.
- char *dark_frame;
-
dcraw keys: -K
Name of file with dark frame.
Constants
enum LibRaw_errors: Error Codes
All functions returning integer numbers must return either errno or one of the following error codes (see also error code conventions).
Fatal errors (return of such an error code implies that file processing has to be terminated, since
the state of data structures is unknown).
- LIBRAW_UNSUFFICIENT_MEMORY
- Attempt to get memory from the system has failed.
All allocated resources will be freed, recycle() will be called, and the LibRaw
object will be brought to the state "right after creation."
- LIBRAW_DATA_ERROR
- A fatal error emerged during data unpacking.
All allocated resources will be freed, recycle() will be called, and the LibRaw
object will be brought to the state "right after creation."
- LIBRAW_IO_ERROR
- A fatal error emerged during file reading (premature end-of-file encountered or file is corrupt).
All allocated resources will be freed, recycle() will be called, and the LibRaw
object will be brought to the state "right after creation."
Non-Fatal Errors
- LIBRAW_SUCCESS=0
- No error; function terminated successfully.
- LIBRAW_UNSPECIFIED_ERROR
- An unknown error has been encountered. This code should never be generated.
- LIBRAW_FILE_UNSUPPORTED
- Unsupported file format (attempt to open a RAW file with a format unknown to the program).
- LIBRAW_REQUEST_FOR_NONEXISTENT_IMAGE
- Attempt to retrieve a RAW image with a number absent in the data file (only for formats supporting storage
of several images in a file).
- LIBRAW_OUT_OF_ORDER_CALL
- API functions have been called in wrong order (e.g., unpack() before
open_file()) or the previous stage has ended with an error (e.g.,
unpack() is called after open_file() has returned an error).
- LIBRAW_NO_THUMBNAIL
- Returned upon an attempt to retrieve a thumbnail from a file containing no preview.
- LIBRAW_UNSUPPORTED_THUMBNAIL
- RAW file contains a preview of unsupported format.
enum LibRaw_progress: Current State of LibRaw Object
LibRaw::imgdata.progress_flags contains a bit mask describing all stages of file processing that have already been performed.
File opening and RAW data extraction phase.
- LIBRAW_PROGRESS_START=0
-
Object just created, no processing carried out.
- LIBRAW_PROGRESS_OPEN
-
File to be processed has been opened.
- LIBRAW_PROGRESS_IDENTIFY
-
Data identification performed, format recognized, metadata extracted.
- LIBRAW_PROGRESS_SIZE_ADJUST
-
Data sizes adjusted (for files that require such adjustment, namely, certain files from Kodak cameras).
- LIBRAW_PROGRESS_LOAD_RAW
-
RAW data loaded.
The following flags are set during usage of image processing that has been taken from dcraw.
- LIBRAW_PROGRESS_REMOVE_ZEROES
-
Zero values removed for cameras that require such removal (Panasonic cameras).
- LIBRAW_PROGRESS_RESERVED_PRE1-LIBRAW_PROGRESS_RESERVED_PRE2
-
Reserved for possible future "pre-debayer" processing stages.
- LIBRAW_PROGRESS_FOVEON_INTERPOLATE
-
Interpolation for cameras with a Foveon sensor performed.
- LIBRAW_PROGRESS_SCALE_COLORS
-
White balance performed.
- LIBRAW_PROGRESS_PRE_INTERPOLATE
-
Image size reduction (for the half_size mode) performed, as well as copying of 2nd green channel to the 1st one in points
where the second channel is present and the first one is absent.
- LIBRAW_PROGRESS_INTERPOLATE
-
Interpolation (debayer) performed.
- LIBRAW_PROGRESS_MIX_GREEN
-
Averaging of green channels performed.
- LIBRAW_PROGRESS_MEDIAN_FILTER
-
Median filtration performed.
- LIBRAW_PROGRESS_HIGHLIGHTS
-
Work with highlights performed.
- LIBRAW_PROGRESS_FUJI_ROTATE
-
For images from Fuji cameras, rotation performed (or adjust_sizes_info_only() called).
- LIBRAW_PROGRESS_FLIP
-
Dimensions recalculated for images shot with a rotated camera (sizes.iwidth/sizes.iheight swapped).
- LIBRAW_PROGRESS_CONVERT_RGB
-
Conversion into output RGB space performed.
- LIBRAW_PROGRESS_STRETCH
-
Image dimensions changed for cameras with non-square pixels.
- LIBRAW_PROGRESS_STAGE17 - LIBRAW_PROGRESS_STAGE27
-
Reserved for possible appearance of other processing stages.
The following flags are set during loading of thumbnails.
LIBRAW_PROGRESS_THUMB_LOAD
Thumbnail data have been loaded (for Kodak cameras, the necessary conversions have also been made).
LIBRAW_PROGRESS_TRESERVED1 - LIBRAW_PROGRESS_TRESERVED3
Reserved for possible future processing stages.
enum LibRaw_thumbnail_formats: Thumbnail Data Formats
Thumbnail data format is written in the imgdata.thumbnail.tformat data field.
Presently LibRaw knows about four thumbnail formats, among which two are unpacked:
- LIBRAW_THUMBNAIL_UNKNOWN
- Format unknown or thumbnail not yet read.
- LIBRAW_THUMBNAIL_JPEG
- The thumbnail buffer contains a JPEG file (read from the RAW file "as is," without any manipulations performed on it).
- LIBRAW_THUMBNAIL_BITMAP
-
The thumbnail buffer contains the gamma-adjusted RGB bitmap (for Kodak cameras, the gamma correction is performed with allowance
for maximum values and the white balance is set in accordance with the camera settings).
In this format, each pixel of the image is represented by a 8-bit RGB triplet.
- LIBRAW_THUMBNAIL_LAYER
-
Data format is presently recognized upon opening of RAW file but not supported: not unpacked into LibRaw::unpack_thumb.
- LIBRAW_THUMBNAIL_ROLLEI
-
Data format is presently recognized upon opening of RAW file but not supported: not unpacked into LibRaw::unpack_thumb.
Nonstandard Situations (Warnings) during RAW Data Processing
Some suspicious situations emerging during image processing are not fatal but may affect the result of data
retrieval or postprocessing. Such states are indicated by setting a bit in the imgdata.process_warnings field.
- LIBRAW_WARN_FOVEON_NOMATRIX
-
Only for cameras with Foveon: extraction of one of data matrices has failed.
- LIBRAW_WARN_FOVEON_INVALIDWB
-
Only for cameras with Foveon: extraction of white balance data has failed.
- LIBRAW_WARN_BAD_CAMERA_WB
-
Postprocessing must use white balance of the camera but this balance is not suitable for use.
- LIBRAW_WARN_NO_METADATA
-
Only for cameras where the metadata are taken from an external JPEG file: metadata extraction has failed.
- LIBRAW_WARN_NO_JPEGLIB
-
Only for P&S Kodak cameras: data in JPEG format. At the same time, open_file() will return LIBRAW_FILE_UNSUPPORTED.
enum LibRaw_colorstate: Types of Color Data Source
For each type of retrieved color information (see above for description of structure imgdata.color.color_flags), the
data source is recorded. The possible values are listed below.
- LIBRAW_COLORSTATE_UNKNOWN
-
Data source unknown.
- LIBRAW_COLORSTATE_INIT
-
Data field initialized by default (the same value for all cameras) before opening the RAW file.
- LIBRAW_COLORSTATE_CONST
-
Data source is a hardcoded constant.
- LIBRAW_COLORSTATE_LOADED
-
Data loaded from RAW file.
- LIBRAW_COLORSTATE_CALCULATED
-
Data calculated on the basis of RAW data.
- LIBRAW_COLORSTATE_RESERVED1-LIBRAW_COLORSTATE_RESERVED3
-
Reserved.
[back to Index]
Alex Tutubalin
Last modified: Tue Mar 25 23:06:04 MSK 2008