LibRaw: Data Structures and Constants [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:

1. Data structures
   1. libraw_data_t: Main Data Structure in LibRaw
   2. Structure libraw_iparams_t: Main Parameters of the Image
   3. Structure libraw_image_sizes_t: Image Dimensions
   4. Structure libraw_colordata_t: Color Information
   5. Structure libraw_imgother_t: Other Parameters of the Image
   6. Structure libraw_rawdata_t: holds unpacked RAW data
   7. Structure libraw_thumbnail_t: Description of Thumbnail
   8. Structure libraw_lensinfo_t - lens data, extracted from EXIF/Makernotes
   9. Structure libraw_output_params_t: Management of dcraw-Style Postprocessing .
   10. Structure libraw_callbacks_t: user-settable callbacks
   11. Structure libraw_processed_image_t - result set for dcraw_make_mem_image()/dcraw_make_mem_thumb() functions
2. Input abstraction layer
   - Data fields
3. Constants
   1. enum LibRaw_errors: Error Codes
   2. enum LibRaw_decoder_flags - RAW data format description
   3. enum LibRaw_progress: Current State of LibRaw Object
   4. enum LibRaw_thumbnail_formats: Thumbnail Data Formats
   5. Nonstandard Situations (Warnings) during RAW Data Processing
   6. enum LibRaw_image_formats - possible types of data, contains in libraw_processed_image_t structure
   7. enum LibRaw_processing_options - flags that affects extracted RAW data

## 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 (and other open_ calls), 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 process_warnings;
  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_lensinfo_t lens;
  The structure describes lens used for the shot. Fields of this structure are described in detail below .
libraw_makernotes_t makernotes;
  The structure contains camera/vendor specific metadata extracted from file. No description provided, sorry, if you're interested in particular tag/camera/vendor - use Exiftool documentation as a reference
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 but thumbnail itself are filled when open_file() is called. Thumbnail readed by unpack_thumb() call. The fields are described in detail below .
libraw_rawdata_t rawdata;
  Data structure with pointer to raw-data buffer. Details are described below .
ushort (*image)[4];
  The memory area that contains the image pixels per se. It is filled when raw2image() or dcraw_process() 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 .
libraw_callbacks_t callbacks;
  user-settable callbacks

### Structure libraw_iparams_t: Main Parameters of the Image

char make[64];
  Camera manufacturer.
char model[64];
  Camera model.
normalized_make[64]
  There is a huge number of identical cameras sold under different names, depending on the market (e.g. multiple Panasonic or Canon models) and even some identical cameras sold under different brands (Panasonic -> Leica, Sony -> Hasselblad). normalized_make contains primary vendor name (e.g. Panasonic for Leica re-branded cameras).
normalized_model[64]
  Primary camera model name.
unsigned maker_index
  Primary vendor name in indexed form (enum LibRaw_cameramaker_index, LIBRAW_CAMERAMAKER_* constant)
char software[64];
  Softwary name/version (mostly for DNG files, to distinguish in-camera DNGs from Adobe DNG Converter produced ones).
unsigned raw_count;
  Number of RAW images in file (0 means that the file has not been recognized).
unsigned is_foveon;
  Nonzero for Sigma Foveon images
unsigned dng_version;
  DNG version (for the DNG format).
int colors;
  Number of colors in the file.
unsigned filters;
  Bit mask describing the order of color pixels in the matrix (0 for full-color images). 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 COLOR(row,column) function, which returns the number of the active color for a given pixel.
  Values less than 1000 are reserved as special cases:
  - 1 - Leaf Catchlight with 16x16 bayer matrix;
  - 9 - Fuji X-Trans (6x6 matrix)
  - 3..8 and 10..999 - are unused.
char xtrans[6][6];
char xtrans_abs[6][6];
  These matrices contains Fuji X-Trans row/col to color mapping. First one is relative to visible area, while second is positioned relative to sensor edges.
char cdesc[5];
  Description of colors numbered from 0 to 3 (RGBG,RGBE,GMCY, or GBTG).
unsigned xmplen; char *xmpdata;
  XMP packed data length and pointer to extracted XMP packet.

### 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).
unsigned raw_pitch;
  Full size of raw data row in bytes .
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:

ushort curve[0x10000];
  Camera tone curve. May be read from file as is, or calculated, depending on file format;
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 cblack[4102];
  Per-channel black level correction. First 4 values are per-channel correction, next two are black level pattern block size, than cblack[4]*cblack[5] correction values (for indexes [6....6+cblack[4]*cblack[5]).
unsigned data_maximum;
  Maximum pixel value in current file. Calculated at raw2image or dcraw_process() calls.
unsigned maximum;
  Maximum pixel value. Calculated from the data for most cameras, hardcoded for others. This value may be changed on postprocessing stage (when black subtraction performed) and by automated maximum adjustment (this adjustment performed if params.adjust_maximum_thr is set to nonzero).
unsigned linear_max[4];
  Per-channel linear data maximum read from file metadata. If RAW file does not contains this data, linear_max[] is set to zero. Black value is not subtracted
float fmaximum;
  Maximum pixel value in real image for floating data files.
float fnorm;
  Normalization coefficient used while converting floating point raw data to integer.
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_xyz[4][3];
  Camera RGB - XYZ conversion matrix. This matrix is constant (different for different models). Last row is zero for RGB cameras and non-zero for different color models (CMYG and so on).
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];
  Camera color data read from RAW file (if any)
float rgb_cam[3][4];
  Camera to sRGB conversion matrix
float ccm[3][4];
  Camera color correction matrix readed from file metadata (uniform matrix if no such data in file)
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];
  Firmware revision (for some cameras).
char UniqueCameraModel[64],LocalizedCameraModel[64];
  Values from DNG tags with same names.
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.
unsigned black_stat[8];
  Black level statistics if calcluated from masked area: 4 sum of pixel values, than 4 pixel counts (per channel).
libraw_dng_color_t dng_color[2];
  Color data read from DNG: illuminant, calbiration matrix and color matrix for two light sources. (see DNG specs for details).
libraw_dng_levels_t dng_levels
  DNG black/white levels, analog balance, WB for active IFD. See DNG specs for details.
int WB_Coeffs[256][4]
  Index: EXIF color source value, [i][0..3] WB Coeffs
float WBCT_Coeffs[64][5]
  Color temperature in [i][0], WB coeffs in [i][1..4]
int as_shot_wb_applied
  Set to 1 if WB already applied in camera (multishot modes; small raw)
libraw_P1_color_t P1_color[2]
  Phase-one specific color data
unsigned raw_bps
  RAW bits per pixel (PhaseOne: Raw format used)
int ExifColorSpace
  EXIF color space parsed from EXIF tags: LIBRAW_COLORSPACE_Unknown, LIBRAW_COLORSPACE_sRGB, or LIBRAW_COLORSPACE_Adobe

### Structure libraw_imgother_t: Other Parameters of the Image

#### 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 (unparsed block, to write to output as is).
libraw_gps_info_t parsed_gps;
  Parsed GPS-data: longitude/latitude/altitude and time stamp.
char desc[512];
  Image description.
char artist[64];
  Author of image.
float FlashEC;
  Flash exposure compensation.

### Structure libraw_rawdata_t: holds unpacked RAW data

Structure libraw_rawdata_t holds:

- RAW-data from sensor, readed and unpacked by the unpack() call.
- "backup" copy of color and over data modified during postprocessing. When postprocessing calls repeats, the needed data is restored from this backup.

#### Data fields:

void *raw_alloc;
  Buffer allocated to hold RAW-data
unsigned short *raw_image;
  Pointer to buffer with one-component (bayer) data.
unsigned short (*color3_image)[3];
  Pointer to 3-component pixel array.
unsigned short (*color4_image)[4];
  Pointer to buffer with 4-component pixel data data
float *float_image;
  Pointer to buffer with one-component (bayer) data in FP-format.
float (*float3_image)[3];
  Pointer to 3-component FP pixel array.
float (*float4_image)[4];
  Pointer to buffer with 4-component pixel data data

After call to unpack() only one of these fields is non-NULL.

All other fields of this structure are for internal use and should not be touched by user code.

### 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_lensinfo_t: parsed lens data

The following parameters are extracted from Makernotes and EXIF, to help identify which lens was mounted on the camera. If the value is missing in Makernotes or EXIF, the parameter is set to zero with some exceptions noted below. In some cases the values for the fields like CameraFormat and CameraMount are set based on the camera model and/or camera ID.

#### libraw_makernotes_lens_t structure:

- LensID (if not -1) and CamID (camera id, if non-zero) values are compatible with those used in exiftool, like |0x0010 CanonModelID| and |22 LensType| see http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Canon.html or 0x0207/CameraType and 0x0201/LensType (see http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Olympus.html )
- Lens string, if not empty, contains the lens name present in Makernotes.
- LensFormat and CameraFormat currently provide one of value from enum LibRaw_camera_formats;
- In a similar manner, values for LensMount and CameraMount follow the enum LibRaw_camera_mounts;
- In some cases, the Makernotes for MF cameras contain either an id for the body, or a string containing the name of the body. The name is copied to body field, while the id is converted to the appropriate body name and also copied to 'body' field. In other cases the 'body' field is empty.
- FocalType is set based on Makernotes tag, if present. The values are:

- -1 Undefined
- 0 Unknown;
- 1 Fixed focal length lens
- 2 Zoom lens

- LensFeatures_pre - lens name prefix and LensFeatures_suf - lens name suffix: (if not empty) some cameras record alphabet soup that characterizes the lens in separate Makernote tags (see, for example, 0xb02a LensSpec at http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Sony.html ), and for some lenses those acronyms can be derived from the 'Lens' field itself (see processCanonCameraInfo). Those can also help better lens identification.
- MinFocal and MaxFocal , if non-zero, contain the minimum and maximum focal lengths for the lens mounted on the camera.
- MaxAp4MinFocal, MaxAp4MaxFocal, MinAp4MinFocal, MinAp4MaxFocal - if non-zero, contain maximum aperture available at minimal focal length, maximum aperture available at maximum focal length, minimum aperture available at minimal focal length, minimum aperture available at maximum focal length, respectively.
- MaxAp and MinAp, if non-zero, contain the maximum aperture for the lens (usually it is the maximum aperture for minimal focal length) and the minimum aperture across the focal length range. For zooms with variable maximum aperture this is usually the minimum aperture for the maximum focal length.
- CurFocal, if non-zero, is current focal length - that is the focal length used to take the shot.
- CurAp, if non-zero, is current aperture.
- MaxAp4CurFocal and MinAp4CurFocal, if non-zero, contain the minimum and maximum apertures for the current focal length.
- LensFStops - if non-zero, contains the number of aperture "clicks" or the number of f-stops, depending on the model of the camera.
- TeleconverterID, AdapterID, AttachmentID, if non-zero, are the numbers extracted from Makernotes to identify lens accessories used to take the shot.
- Teleconverter, Adapter, Attachment, if non-empty, are the strings containing the names of the accessories as they appear in Makernotes, or for some cameras, decoded from a numeric field in Makernotes.
- FocalUnits - an auxiliary field, should not be needed most of the cases. See Canon.pm module in exiftool for more information on this value.
- FocalLengthIn35mmFormat, if non-zero: for some reason certain Samsung cameras record this value in Makernotes instead of the EXIF proper. Also used for Sigma cameras.

#### libraw_nikonlens_t structure:

Contains additional parameters needed to identify the lens on a Nikon camera using a table - please see Nikon LensID Values at http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html

#### libraw_dnglens_t structure:

Contains minimum focal length, maximum focal length, maximum aperture available at minimal focal length, and maximum aperture available at maximum focal length, extracted from EXIF field of a DNG raw file.

#### libraw_lensinfo_t structure:

Contains all the structures described above, plus parameters extracted directly from EXIF fields:

- MinFocal and MaxFocal , if non-zero, contain the minimum and maximum focal lengths for the lens mounted on the camera.
- MaxAp4MinFocal, MaxAp4MaxFocal - if non-zero, contain maximum aperture available at minimal focal length and maximum aperture available at maximum focal length
- LensMake, if not empty, contains a string with the lens manufacturer name.
- Lens, if not empty, contains the lens name as recorded in EXIF
- FocalLengthIn35mmFormat - if non-zero, same as FocalLengthIn35mmFilm in EXIF standard, tag 0xa405.
- EXIF_MaxAp - if non-zero, contains the value derived from EXIF tag 0x9205.

### 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(), and dcraw_thumb_writer(). Fields of this structure correspond to command line keys of dcraw.

#### Data fields:

unsigned greybox[4];
  dcraw keys: -A x y w h
  4 numbers corresponding to the coordinates (in pixels) of the rectangle that is used to calculate the white balance. X and Y are coordinates of the left-top rectangle corner; w and h are the rectangle's width and height, respectively.
unsigned cropbox[4];
  dcraw keys: none
  This field sets the image cropping rectangle. Cropbox[0] and cropbox[1] are the rectangle's top-left corner coordinates, remaining two values are width and height respectively. All coordinates are applied before any image rotation.
double aber[4];
  dcraw keys: -C
  Correction of chromatic aberrations; the only specified values are
  aber[0], the red multiplier
  aber[2], the blue multiplier. For some formats, it affects RAW data reading , since correction of aberrations changes the output size.
double gamm[6];
  dcraw keys: -g power toe_slope
  Sets user gamma-curve. Library user should set first two fields of gamm array:
  gamm[0] - inverted gamma value)
  gamm[1] - slope for linear part (so called toe slope). Set to zero for simple power curve.
  Remaining 4 values are filled automatically.
  By default settings for rec. BT.709 are used: power 2.222 (i.e. gamm[0]=1/2.222) and slope 4.5. For sRGB curve use gamm[0]=1/2.4 and gamm[1]=12.92, for linear curve set gamm[0]/gamm[1] to 1.0.
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;
  dcraw keys: -s
  Selection of image number for processing (for formats that contain several RAW images in one file).
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 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.

  If camera-recorded WB is not available, dcraw_process() will fallback to:

  - Auto-WB if bit LIBRAW_PROCESSING_CAMERAWB_FALLBACK_TO_DAYLIGHT is not set in params.raw_processing_options (or for the rare specific case: no valid WB index was parsed from CRW file)
  - Daylight-WB if abovementioned bit is not set.
int use_camera_matrix;
  dcraw keys: +M/-M
  - 0: do not use embedded color profile
  - 1 (default): use embedded color profile (if present) for DNG files (always); for other files only if use_camera_wb is set;
  - 3: use embedded color data (if present) regardless of white balance setting.
int output_color;
  dcraw keys: -o
  [0-6] Output colorspace (raw, sRGB, Adobe, Wide, ProPhoto, XYZ, ACES).
char* output_profile;
  dcraw keys: -o filename
  Path to output profile ICC file (used only if LibRaw compiled with LCMS support)
char* camera_profile;
  dcraw keys: -p file
  Path to input (camera) profile ICC file (or 'embed' for embedded profile). Used only if LCMS support compiled in.
char* bad_pixels;
  dcraw keys: -P file
  Path to file with bad pixels map (in dcraw format: "column row date-of-pixel-death-in-UNIX-format", one pixel per row).
char* dark_frame;
  dcraw keys: -K file
  Path to dark frame file (in 16-bit PGM format)
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-10: interpolation quality:
  - 0 - linear interpolation
  - 1 - VNG interpolation
  - 2 - PPG interpolation
  - 3 - AHD interpolation
  - 4 - DCB interpolation
  - 11 - DHT intepolation
  - 12 - Modified AHD intepolation (by Anton Petrusevich)
int user_black;
  dcraw keys: -k
  User black level.
int user_cblack[4];
  dcraw keys: none
  Per-channel corrections to user_black.
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.
float auto_bright_thr;
  dcraw keys: none
  Portion of clipped pixels when auto brighness increase is used. Default value is 0.01 (1%) for dcraw compatibility. Recommended value for modern low-noise multimegapixel cameras depends on shooting style. Values in 0.001-0.00003 range looks reasonable.
float adjust_maximum_thr;
  dcraw keys: none
  This parameters controls auto-adjusting of maximum value based on channel_maximum[] data, calculated from real frame data. If calculated maximum is greater than adjust_maximum_thr*maximum, than maximum is set to calculated_maximum.
  Default: 0.75. If you set this value above 0.99999, than default value will be used. If you set this value below 0.00001, than no maximum adjustment will be performed.
  Adjusting maximum should not damage any picture (esp. if you use default value) and is very useful for correcting channel overflow problems (magenta clouds on landscape shots, green-blue highlights for indoor shots).
int use_fuji_rotate;
  dcraw keys: -j
  Default -1 (use), 0 - don't use rotation for cameras on a Fuji sensor.
int green_matching;
  Turns on fixing of green channels disbalance. dcraw keys: none
  Default: 0 (not use), 1 - turns on this postprocessing stage. green_matching requires additional memory for image data.
int dcb_iterations
  dcraw keys: none
  Number of DCB correction passes. Default is -1 (no correction). Useful only for DCB interpolation.
int dcb_enhance_fl
  dcraw keys: none
  nonzero: DCB interpolation with enhance interpolated colors.
int fbdd_noiserd
  dcraw keys: none
  Controls FBDD noise reduction before demosaic.
  - 0 - do not use FBDD noise reduction
  - 1 - light FBDD reduction
  - 2 (and more) - full FBDD reduction
int exp_correc; float exp_shift,exp_preser;
  Exposure correction before demosaic.
  - exp_correc: positive value turns the feature on (default: off).
  - exp_shift: exposure shift in linear scale. Usable range from 0.25 (2-stop darken) to 8.0 (3-stop lighter). Default: 1.0 (no exposure shift).
  - exp_preser: preserve highlights when lighten the image. Usable range from 0.0 (no preservation) to 1.0 (full preservation). 0.0 is the default value.
int use_rawspeed;
  Turns on using RawSpeed library for data unpacking (only if RawSpeed support compiled in).
int use_dng_sdk;
  Turns on using Adobe DNG SDK (if compiled with it and dng host is set:
  - 0 - do not use
  - 1 - use for speciality formats (Float, Linear DNG, deflate compression, 8 bit)
  - 2 - use for all DNG files
int no_auto_scale;
  Disables pixel values scaling (call to LibRaw::scale_colors()) in LibRaw::dcraw_process().
  This is special use value because white balance is performed in scale_colors(), so skipping it will result in non-balanced image.
  This setting is targeted to use with no_interpolation, or with own interpolation callback call.
int no_interpolation;
  Disables call to demosaic code in LibRaw::dcraw_process()
int raw_processing_options
  Processing options used on unpack() phase for specific image formats, see below for possible values: LibRaw_processing_options
int max_raw_memory_mb
  Stop processing if raw buffer size grows larger than that value (in megabytes). Default is LIBRAW_MAX_ALLOC_MB_DEFAULT (2048Mb)
int sony_arw2_posterization_thr
  If LIBRAW_PROCESSING_SONYARW2_DELTATOVALUE used for raw_processing_options, sets the level to suppress posterization display in shadows.
float coolscan_nef_gamma;
  Gamma value for Coolscan NEF decoding (no way to get if from file, it should be set by calling application).
char p4shot_order[5];
  Shot order for Pentax 4shot files. Default is "3102".

### Structure libraw_callbacks_t: user-settable callbacks

memory_callback mem_cb
  Called on memory allocation error. Settable via set_memerror_handler. See C++ API for details.
data_callback data_cb
  Called on data error, settable via set_dataerror_handler. See C++ API for details.
progress_callback progress_cb
  Called on process callback, settable via set_progress_handler. See C++ API for details.
exif_parser_callback exif_cb, params: (void *context, int tag, int type, int len, unsigned int ord, void *ifp)
  Called by EXIF/TIFF IFD parsers on each processed tag.
  Parameters:
  - context: user-specified context, set via set_exifparser_handler()
  - tag: 16-bit of TIFF/EXIF tag or'ed with
    - 0 - for EXIF parsing
    - 0x20000 - for Kodak makernotes parsing
    - 0x30000 - for Panasonic makernotes parsing
    - 0x40000 - for EXIF Interop IFD parsing
    - 0x50000 - for EXIF GPS IFD parsing
    - (ifdN + 1) << 20) - for TIFF ifdN
  - type: tag type (see TIFF/EXIF specs)
  - len: tag length
  - ord: byte order: 0x4949 for intel, 0x4d4d for motorola
  - ifp: pointer to LibRaw_abstract_datastream input stream, positioned to start of data. There is no need to restore data position in callback.
int pre_identify_cb(void *)
  Called with this pointer as the only arg before calling to LibRaw::identify. If this callback return non-zero value, that means that identify() is not needed and all internal data fields are filled with values.
void post_identify_cb(void *)
  Called after identify() from open_datastream(). May be used to tune internal variables after metadata parse.
dcraw_process() callbacks
  These callbacks are called before/after dcraw_process phases, the only passed parameter is this pointer
  - pre_subtractblack_cb - called before black subtraction
  - pre_scalecolors_cb - called before scale_colors() call
  - pre_preinterpolate_cb - called before interpolaton (demosaic)
  - interpolate_bayer_cb - if set, called for bayer demosaic (regardless of params.user_qual value)
  - interpolate_xtrans_cb - if set, called for X-Trans demosaic
  - post_interpolate_cb - called after demosaic step. Note: if this callback is set, standard median_filter() is not called. So, if you need median filtering you should call it from callback function.
  - pre_converttorgb_cb - called after convert_to_rgb()
  - post_converttorgb_cb - called after convert_to_rgb(), so very last processing step.

### Structure libraw_decoder_info_t: RAW decoder name and data format

This structure describes RAW format decoder name and data format:

const char *decoder_name
  Decoder function name
unsigned decoder_flags
  Decoder data format. See list of LibRaw_decoder_flags for details.

### Structure libraw_processed_image_t - result set for dcraw_make_mem_image()/dcraw_make_mem_thumb() functions

Structure libraw_processed_image_t is produced by call of dcraw_make_mem_image()/dcraw_make_mem_thumb() and contains in-memory image of interpolated data or thumbnail.

#### Data fields:

LibRaw_image_formats type
  This field records type of data, containing in remaining fields of structure.
  - LIBRAW_IMAGE_BITMAP - structure contains RGB bitmap. All metadata fields (see below) are valid and describes image data.
  - LIBRAW_IMAGE_JPEG - structure contain in-memory image of JPEG file. Only type, data_size and data fields are valid (and nonzero);
ushort height,width
  Image size (in pixels). Valid only if type==LIBRAW_IMAGE_BITMAP.
ushort colors, bits
  Number of colors components (1 or 3) and color depth in bits (8 or 16). These fields are valid only if type==LIBRAW_IMAGE_BITMAP.
ushort gamma_corrected
  Is bitmap data gamma-corrected (always 1 for 8-bit data, may be 0 or 1 for 16-bit). Valid only if type==LIBRAW_IMAGE_BITMAP.
unsigned int data_size
  Size of data field (in bytes). For bitmap image equal to (height*width*colors * (bits/8)). For JPEG image - exact JPEG size (i.e. extracted thnumbnail size + JPEG header + EXIF header).
unsigned char data[]
  Data array itself. Should be interpreted as RGB triplets for bitmap type and as JPEG file for JPEG type.

## Input abstraction layer

RAW data input (read) in LibRaw implemented by calling methods of object derived from LibRaw_abstract_datastream abstract class. Full list of methods is described in href="API-CXX.html#datastream">C++ API reference.

There is two ready to use implementations of datastream objects:

- LibRaw_file_datastream - file input (filename provided to LibRaw).
- LibRaw_buffer_datastream - input from memory buffer.

LibRaw user can create own datastream object derived from LibRaw_abstract_datastream . For example, such object may implement reading RAW data directly from camera (by remote interface). LibRaw can use these objects via LibRaw::open_datastream() interface.

Datastreams can be used either via LibRaw::open_datastream() call (in this case datastream object should be created an maintained by user) or via LibRaw::open_file() and LibRaw::open_buffer() shortcuts.

Only C++ API users may use object-oriented interface and implement own input interfaces. For C API users only built-on libraw_open_file()/libraw_open_buffer() shortcuts are available.

#### Data fields

Definition:

    	class LibRaw_abstract_datastream {...protected: LibRaw_abstract_datastream *substream;}

Description: Ojects derived from LibRaw_abstract_datastream always contains pointer to secondary data stream (substream). This substream initialized internally when needed (really used only for Sony RAW data) and used for temporary switch input stream to temporary memory buffer allocated internally in LibRaw.

Substream usage details described more precisely in own datastream objects creation guide .

## 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."
LIBRAW_CANCELLED_BY_CALLBACK
  Processing cancelled due to calling application demand (by returning nonzero code from progress callback ).
  All allocated resources will be freed, recycle() will be called, and the LibRaw object will be brought to the state "right after creation."
LIBRAW_BAD_CROP
  The incorrect cropping coordinates are set via params.cropbox[]: the left-top corner of cropping rectangle is outside the image. The processing will be cancelled, all allocated resources will be freed, <a <dt=""> LIBRAW_TOO_BIG
  <a <dt="">Raw data size exceeds data limit.
<a <dt="">

<a <dt="">

Non-Fatal Errors

<a <dt="">
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
  <a <dt="">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_decoder_flags - RAW data format description

Depending of capabilities of given data format, the buffer with RAW data may have different layouts:

LIBRAW_DECODER_HASCURVE
  This flag is set if decoder uses RAW tone curve and curve data may be modified before call to decoder (i.e. curve values are not read or calculated within decoder).
LIBRAW_DECODER_SONYARW2
  This flag is set if file format is Sony ARW2.3, so sony_arw2_options is applicable.
LIBRAW_DECODER_TRYRAWSPEED
  This flag is set if file format is (possibly) supported by RawSpeed library, so unpack() will try to use it.
LIBRAW_DECODER_FIXEDMAXC
  Do not use automated maximum calculation for this data format.
LIBRAW_DECODER_OWNALLOC
  Decoder allocates data, no need to pass allocated memory to decoder.
LIBRAW_DECODER_ADOBECOPYPIXEL
  Internal flag, special to adobe DNG decoder.
LIBRAW_DECODER_LEGACY_WITH_MARGINS
  Special flag uset for 4-channel (legacy) decoders with black/masked areas
LIBRAW_DECODER_3CHANNEL
  3-component full-color data (not usual 4-component)

### 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_RAW2_IMAGE
  imgdata.image array allocated and filled with data.
LIBRAW_PROGRESS_REMOVE_ZEROES
  Zero values removed for cameras that require such removal (Panasonic cameras).
LIBRAW_PROGRESS_BAD_PIXELS
  Bad (dead) pixels removed.
LIBRAW_PROGRESS_DARK_FRAME
  Dark frame subtracted from RAW data.
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_whitebalance_code - names for standard light sources

LIBRAW_WBI_lightsource_name, where name and value are standard EXIF light sources.

### enum LibRaw_camera_mounts - codes for camera mounts

Constant name (e.g. LIBRAW_MOUNT_Leica_SL) speaks for itself

### enum LibRaw_runtime_capabilities - libraw capabilities set at build

- LIBRAW_CAPS_RAWSPEED - compiled with RawSpeed
- LIBRAW_CAPS_DNGSDK - compiled with Adobe DNG SDK
- LIBRAW_CAPS_GPRSDK - compiled w/ GoPro GPR SDK
- LIBRAW_CAPS_UNICODEPATHS - compiled with Windows unicode (wchar_t*) filenames support

### 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_BITMAP16
  The thumbnail buffer contains the gamma-adjusted 16-bit RGB bitmap. To get this format instead of LIBRAW_THUMBNAIL_BITMAP you need to set LIBRAW_PROCESSING_USE_PPM16_THUMBS in processing options.
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_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.
LIBRAW_WARN_NO_EMBEDDED_PROFILE
  (only if LCMS support compiled in). Caller set embedded input profile use, but no such profile exists in RAW.
LIBRAW_WARN_NO_INPUT_PROFILE
  (only if LCMS support compiled in). Error when opening input profile ICC file.
LIBRAW_WARN_BAD_OUTPUT_PROFILE
  (only if LCMS support compiled in). Error when opening output profile ICC file.
LIBRAW_WARN_NO_BADPIXELMAP
  Error when opening bad pixels map file.
LIBRAW_WARN_BAD_DARKFRAME_FILE
  Error when opening dark frame file.
LIBRAW_WARN_BAD_DARKFRAME_DIM
  Dark frame file either differs in dimensions from RAW-file processed, or have wrong format. Dark frame should be in 16-bit PGM format (one can generate it using simple_dcraw -4 -D).
LIBRAW_WARN_RAWSPEED_PROBLEM
  Problems detected in RawSpeed decompressor. The image data processed by LibRaw own decoder.
LIBRAW_WARN_RAWSPEED_UNSUPPORTED
  This file not supported by RawSpeed (although compatible decoder exists).
LIBRAW_WARN_RAWSPEED_PROCESSED
  Not warning, but information. The file was decoded by RawSpeed.
LIBRAW_WARN_FALLBACK_TO_AHD
  Incorrect/unsupported user_qual was set, AHD demosaic used instead.
LIBRAW_WARN_PARSEFUJI_PROCESSED
  Not really a warning, but flag that fuji parser was used.
LIBRAW_DNGSDK_PROCESSED
  Not really a warning: image was decoded by DNG SDK
LIBRAW_DNG_IMAGES_REORDERED
  DNG sub0images was reordered
LIBRAW_DNG_STAGE2_APPLIED
  DNG Stage2 conversion was performed
LIBRAW_DNG_STAGE3_APPLIED
  DNG Stage3 conversion was performed

### enum LibRaw_image_formats - possible types of data, contains in libraw_processed_image_t structure

type field of libraw_processed_image_t structure may have one of these values:

LIBRAW_IMAGE_BITMAP
  The structure contains RGB-bitmap, metadata described in other fields of libraw_processed_image_t.
LIBRAW_IMAGE_JPEG
  libraw_processed_image_t structure contains JPEG image (in memory). Only data_size field is meaningful.

### enum enum LibRaw_processing_options - bit that affects RAW data extraction

These flags could be OR'ed with imgdata.params.raw_processing_options:

Sony ARW2.3 processing options: (for more details see http://www.rawdigger.com/howtouse/sony-craw-arw2-posterization-detection)

- LIBRAW_PROCESSING_SONYARW2_BASEONLY - decode only base pixels, leave delta pixels as zero;
- LIBRAW_PROCESSING_SONYARW2_DELTAONLY - decode only delta pixels with base pixels zeroed;
- LIBRAW_PROCESSING_SONYARW2_DELTAZEROBASE - decode delta pixels, do not add base value;
- LIBRAW_PROCESSING_SONYARW2_DELTATOVALUE - show possible posterization areas;

Sigma Quattro decoding flags:

- LIBRAW_DP2Q_INTERPOLATERG - turn on R/G channels interpolation
- LIBRAW_DP2Q_INTERPOLATEAF - turn on data interpolation of low-sensitivity (AF or overexposure control) points on Quattro sensors.

Pentax 4-shot options:

- LIBRAW_PROCESSING_PENTAX_PS_ALLFRAMES - merge all frames for Pentax 4-shot files

Floating point DNG files:

- LIBRAW_PROCESSING_CONVERTFLOAT_TO_INT - convert FP data to 16-bit integer

Canon/Nikon small RAW (YCC) decoding flags (do not use both at same time):

- LIBRAW_PROCESSING_SRAW_NO_RGB - disable YCC to RGB conversion
- LIBRAW_PROCESSING_SRAW_NO_INTERPOLATE - disable missing color values interpolation

DNG processing flags:

- LIBRAW_PROCESSING_USE_DNG_DEFAULT_CROP - use DNG DefaultCrop* tags for cropping
- LIBRAW_PROCESSING_DONT_CHECK_DNG_ILLUMINANT - skip DNG illuminant check when parsing DNG color data (use for compatibility w/ older LibRaw versions).
- LIBRAW_PROCESSING_DNGSDK_ZEROCOPY - do not copy data extracted by Adobe DNG SDK into separate buffer, but use DNG SDK buffer as is.
- LIBRAW_PROCESSING_DNG_ADD_ENHANCED - if set, LibRaw will add Enhanced DNG frame (NewSubfileType == 16) to the list of available frames.
- LIBRAW_PROCESSING_DNG_ADD_PREVIEWS - if set, LibRaw will add previews (NewSubfileType == 1) to the frames list.
- LIBRAW_PROCESSING_DNG_PREFER_LARGEST_IMAGE- By default, DNG frames are not reordered and are available in same order as in DNG (LibRaw traverses IFD/Sub-IFD trees in deep-first order).This bit will prioritize the largest image
- LIBRAW_PROCESSING_DNG_STAGE2 - request DNG Stage2 processing (by DNG SDK)
- LIBRAW_PROCESSING_DNG_STAGE3 - request DNG Stage3 processing
- LIBRAW_PROCESSING_DNG_ALLOWSIZECHANGE - by default, if image size parsed by DNG SDK does not match image dimensions parsed by LibRaw, processing will stop with LIBRAW_DATA_ERROR code. This flags allows size change in LibRaw::unpack() stage.
- LIBRAW_PROCESSING_DNG_DISABLEWBADJUST - by default, for DNG images with different per-channel maximums WB adjustment procedure is performed. This flag disables such adjustment.

Other flags

- LIBRAW_PROCESSING_NO_ROTATE_FOR_KODAK_THUMBNAILS - disable auto-rotation for Kodak PPM bitmaps
- LIBRAW_PROCESSING_USE_PPM16_THUMBS - enable 16-bit PPM thumbnails
- LIBRAW_PROCESSING_SKIP_MAKERNOTES - if this flag is set, LibRaw will perform only basic metadata parsing (Note: this flag is scheduled for removal in future versions).
- LIBRAW_PROCESSING_ZEROFILTERS_FOR_MONOCHROMETIFFS - by default, LibRaw assigns bayer pattern for Monochrome TIFF files (e.g. images from Kodak 760).This does not work as expected if input file is really monochrome (e.g. scan from Imacon X1 in monochrome mode).This flag will force monochrome mode for TIFF RAWs w/o bayer filter tags (so, it will break old Kodak processing). It is better to make it settable via user interaction.

[back to Index]