Lenscal API Development Guide

Overview

The Lenscal DLL provides functions to quickly find lens correction register settings that will best correct the image brightness and color shading distortion caused by the camera's optical system. For sensors with phase detect auto focus (PDAF), this includes the spacial calibration as well.
The library supports all Bayer sensors with built-in lens correction, including SOC sensors.

Sensors not supported are: MT9P001 (A-5100) and MT9P006 (A-51HD-plus).


The input to the calibration is an image of a flat, gray field. The output is a list of the lens correction registers and their values. To get a good calibration requires careful setup of the camera system under test and correct use of the Lenscal functions and their parameters. Contact your ON Semiconductor field application engineer for assistance.
Two kinds of lens correction circuits are in use on ON Semiconductor sensors, what I'll call the orthogonal type and the polynomial type. The orthogonal type uses sets of horizontal and vertical gain curves added together to create a two-dimensional gain. The polynomial type uses a two-dimensional polynomial function. The calibration algorithms and parameters are different for each. The orthogonal type sensors are MT9D111 (SOC2010), MT9D112 (SOC2020), MT9D012 (A-2020). All others are polynomial type.

Quick Start

Here is partial C/C++ code to calibrate an AR1337 sensor from a raw Bayer image file, and write the register values to a file in the DevWare .ini file format. Error checking removed for brevity:
#include "midlib2.h"
#include "lenscal.h"
void *lc;
CalibParams params = {sizeof(params), 100, 24, 1, 400, 300, 0.0, 1.0, 0};
params.nXedgeIgnore = -1;
params.nYedgeIgnore = -1;
lc = lc_Create(lc_SensorType("AR1337"), 1, -1);
lc_LoadInputImageFile(lc, "capture0001.raw", 0, -1, -1, -1);
lc_FindSolution(lc, &params);
lc_DumpRegFile(lc, "lenscal-AR1337.ini", REGFMT_DEVWARE_INI, NULL, NULL);
lc_Destroy(lc);

Here is partial C/C++ code to run a simulation of the AR1337 lens correction on a captured raw Bayer image using register settings loaded from an ini file, and write the simulated image to a file:
#include "midlib2.h"
#include "lenscal.h"
void *lc;
lc = lc_Create(lc_SensorType("AR1337"), 1, -1);
lc_LoadInputImageFile(lc, "capture0002.raw", 0, -1, -1, -1);
lc_LoadInputIniFile(lc, "lenscal-AR1337.ini", NULL);
lc_SimulateCorrectedImage(lc, "corrected.raw", RAW_UNKNOWN, -1);
lc_Destroy(lc);

lenscal API Functions

The functions provided by the lenscal API are described below.
All library functions use the Windows standard calling convention. A C/C++ header file is provided.
Lenscal, and other ON Semiconductor tools, internally represent sensor registers by their symbolic name and depend on the sensor data (*.sdat, *.xsdat) files in the sensor_data directory to translate between the symbolic names and numerical register addresses on the sensors. In order for functions that load and save register settings to work, the sensor data file for the selected sensor must be on the computer (or a mapped drive). The lc_Create() function will search the normal installation directory for the sensor data file. As long as you have installed the software and the sensor data files with the installation wizards provided by ON Semiconductor, everything is properly set up. The lc_Create2() function lets you provide the path or filename of a sensor data file if you have a custom configuration.

lc_Create()

Definition:
void *lc_Create(mi_sensor_types sensorType, int nRev, int nPolynomialOrder);
Summary:
Create a lenscal object and initialize it with the given parameters. Pass the return value to all other lenscal functions. Do not dereference the pointer.
The sensorType may be MI_UNKNOWN_SENSOR, in which case the input image will be corrected using the polynomial algorithm (you can get simulated output), but there will not be any meaningful register settings.
Parameters:

sensorType

The midlib sensor type symbol for the sensor to be calibrated, from midlib2.h. You can use lc_SensorType() to get this value from a part number.

nRev

The revision of the sensor in case there are variations in the lens correction registers between different rev's. Use 1 here since the sensor rev rarely matters.

nPolynomialOrder

Use -1 normally, or use 4 for sensors that use the polynomial LC system, 0 for all others. A non-zero value will force the library to generate a polynomial calibration, even if the sensor type uses the orthogonal curves system. The maximum value is 8. You can pass -1 to use the value appropriate to the sensor type.


Returns:

Pointer to lenscal object

NULL on failure, valid pointer on success


The lenscal object can be reused to calibrate any number of images, as long as they are all for the same sensor type.

lc_Create2()

Definition:
void *lc_Create2(const char *szSensorDataPath, mi_sensor_types sensorType, int nRev, int nPolynomialOrder);
Summary:
Like lc_Create(), except also takes a file name for a sensor data file, or directory name to search for the sensor data file to use for translating register symbolic names into numerical addresses.
If you pass a full path and filename for the sensor data file, you can pass MI_UNKNOWN_SENSOR for sensorType and the library will use the sensor type and revision from the sensor data file. If another value is passed for sensorType then that parameter and the nRev parameter override the values from the sensor data file.
Parameters:

szSensorDataPath

A filename for a sensor data file to use, or the name of a directory to search for the sensor data file based on the sensorType and nRev parameters.

sensorType

The midlib sensor type symbol for the sensor to be calibrated, from midlib2.h. You can use lc_SensorType() to get this value from a part number.

nRev

The revision of the sensor in case there are variations in the lens correction registers between different rev's. Use 1 here since the sensor rev rarely matters.

nPolynomialOrder

Use -1 normally, or use 4 for sensors that use the polynomial LC system, 0 for all others. A non-zero value will force the library to generate a polynomial calibration, even if the sensor type uses the orthogonal curves system. The maximum value is 8. Pass -1 to use the default polynomial order for the sensor type.


Returns:

Pointer to lenscal object

NULL on failure, valid pointer on success



lc_SensorType()

Definition:
void lc_SensorType(const char *szPartNumber)
Summary:
Convert a device part number string into a sensor type enum (mi_sensor_types) value suitable for lc_Create(). Enum symbols for very new parts may not be in the released header files. This function can generate the correct parameter without the symbol.
Parameters:

szPartNumber

Part number of the device


Returns:

Part type value

MI_UNKNOWN_SENSOR on failure



lc_Destroy()

Definition:
void lc_Destroy(void *lc)
Summary:
Free all memory associated with the object. The pointer is invalid after this call, and so are any other associated pointers allocated by Lenscal functions.
Parameters:

lc

The lenscal object to destroy


Returns:

none

 




lc_LoadInputImageFile()

Definition:
short *lc_LoadInputImageFile(void *lc, const char *szInFileName, int nBayerPattern, int nBlack, int nCropLeft, int nCropTop)
Summary:
Load an image from a file and subtract the black pedestal value from the pixels if it's Bayer data.
Parameters:

lc

Lenscal object.

szInFileName

Name of image file. For SOC2010 must be RGB BMP file. For all others must be Bayer data. May be NULL in which case the function will create a flat, gray image.

nBayerPattern

Value from 0 to 3 indicating the Bayer pattern, after cropping. Normally 0 is the correct value. Use -1 to have the library select an appropriate default value.

nBlack

Black pedestal value to subtract from all Bayer pixels. Use -1 to use the value from the file or the sensor's default black pedestal. You must use the appropriate value here or the calibration will be compromised.

nCropLeft

If the image has extra columns, how many columns to skip at the left side. Use -1 if it doesn't apply or to crop equally at the left and right.

nCropTop

If the image has extra rows, how many rows to skip at the top side. Use -1 if it doesn't apply or to crop equally at the top and bottom.


Returns:

Pointer to the loaded image

 


The returned pointer is provided so you may access the pixel values. Do not free the buffer. It will be freed automatically when the lc is destroyed or when you load a new image.
The Bayer data file may be in any of a variety of formats including raw binary, ASCII text, or monochrome PNG. The filename parameter may be NULL, in which case the function will fill the buffer with gray pixels.
The Bayer pattern codes are: 0 – GR/BG; 1 – RG/GB; 2 – BG/GR; 3 – GB/RG. Unless you are using some unusual register settings, the Bayer pattern should be 0. The lenscal library requires that the image be captured without flip or mirror modes. If the image was captued with flip or mirror on then you must re-orient the image before using it with lenscal.
The raw Bayer pixel data from an ON Semiconductor sensor has an offset (black pedestal) added to all pixels so there is a small blacker-than-black margin. This value must be subtracted off correctly in order for the calibration to be accurate. The black pedestal is programmed by a register on the sensor, but there is rarely any reason to change it from its default. Assuming the sensor black pedestal register has not been changed from the default and you have not altered the data, pass -1 for nBlack. If you have already subtracted the black pedestal pass 0. If you know that the black pedestal is some specific value, pass that value.

lc_LoadInputImageFileYcbcr()

Definition:
short *lc_LoadInputImageFileYcbcr(void *lc, const char *szInFileName, YCbCrParams *ycbcrParams, int nCropLeft, int nCropTop)
Summary:
Load a YCbCr image from a file and convert it to Bayer or RGB if the calibration is for MT9D111 (SOC2010). There are several variations on YCbCr data, so the ycbcrParams structure contains the remaining parameters needed to convert the YCbCr data to RGB. Take care to fill in the parameters correctly or else the calibration will be incorrect.
Except for the MT9D111 (SOC2010), it is recommended to use raw Bayer data instead of YCbCr data for lens calibration. This function is provided only for those cases where it is impossible to get raw Bayer data from the camera system.
Parameters:

lc

Lenscal object.

szInFileName

Name of image file. Must be YCbCr data. May be NULL in which case the function will create a flat, gray image.

ycbcrParams

Parameters for the YCbCr to RGB conversion.

nCropLeft

If the image has extra columns, how many columns to skip at the left side. Use -1 if it doesn't apply or to crop equally at the left and right.

nCropTop

If the image has extra rows, how many rows to skip at the top side. Use -1 if it doesn't apply or to crop equally at the top and bottom.


Returns:

Pointer to the loaded image

 


The returned pointer is provided so you may access the pixel values. The returned image will be Bayer format data generated from the YCbCr input image. Do not free the buffer. It will be freed automatically when the lc is destroyed or when you load a new image.
The YCbCr data file should be a binary .raw file. The filename parameter may be NULL, in which case the function will fill the buffer with gray pixels.
The lenscal library requires that the image be captured without flip or mirror modes. If the image was captued with flip or mirror on then you must re-orient the image before using it with lenscal.
The YCbCrParams structure:

size_t

size

Set to sizeof(YCbCrParams), for forward compatibility.

int

nCoeffCtrl

Determines the coefficients in the YCbCr to RGB conversion. Set this to match the COEFF_CONTROL or SELECT_601 bitfield on the SOC.

int

nCb_offset,
nY0_offset,
nCr_offset,
nY1_offset

These four parameters indicate the byte order of the YCbCr data. Sensors default to Cb-Y-Cr-Y byte order, in which case set these parameters to 0, 1, 2, 3 respectively.

int

nLumaBlack

The Y component value corresponding to black. nLumaBlack, nLumaWhite and nChromaRange are normailly either 16, 235, 224 for BTU-656 compatibility, or 0, 255, 255 for JPEG compatibility.

int

nLumaWhite

The Y component value corresponding to White.

int

nChromaRange

The valid range for Cb and Cr values.

int

nC_excess

Set to 128 if the Cb and Cr components are unsigned. Set to 0 if they are 2's complement signed. Other values are undefined. This is almost always 128.

 

lc_SetInputImage()

Definition:
short *lc_SetInputImage(void *lc, short *pOriginal, int nWidth, int nHeight, int nBpp, int nBayerPattern, int nBlack, int nCropLeft, int nCropTop)
Summary:
Set the current image from a memory buffer. If it's Bayer data, convert the data to 12 bits per pixel and subtract the black pedestal value. The data in the buffer may be altered.
Parameters:

lc

Lenscal object.

pOriginal

Pointer to image buffer. This function may alter the data. For SOC2010 must be RGB data. For all others must be Bayer data. May be NULL in which case the function will create a flat, gray image.

nWidth

Image width in pixels.

nHeight

Image height in pixels.

nBpp

Image bits per pixel. If 8 then each pixel occupies one byte. If 10 or 12 then each pixel occupies two bytes, in little-endian format.

nBayerPattern

Value from 0 to 3 indicating the Bayer pattern. Normally 0 is the correct value.

nBlack

Black pedestal value to subtract from all Bayer pixels. Use -1 to use the sensor's default black pedestal. You must use the appropriate value here or the calibration will be compromised. See the discussion below.

nCropLeft

If the image has extra columns, how many columns to skip at the left side. Use -1 if it doesn't apply or to crop equally at the left and right.

 

nCropTop

If the image has extra rows, how many rows to skip at the top side. Use -1 if it doesn't apply or to crop equally at the top and bottom.

 


Returns:

Pointer to the image

In most cases the return value will be the pOriginal parameter, however it may not be. Returns NULL on an error.


Do not free the returned pointer if it is different from pOriginal. It will be freed when the lenscal object is destroyed or a new image is loaded.
The Bayer data must be either 8, 10 or 12 bits per pixel. If greater than 8 bits then each pixel must occupy the low bits of a 16-bit word, with little endian byte order. The function will subtract the black pedestal and convert the data to 12 bits per pixel. If the input is 8 bpp then the function will allocate a new buffer to hold the 12 bpp data, otherwise the transform will be done in place in your buffer.
RGB data must be 32 bits per pixel, 8 bits per color channel, B-G-R-x byte order.
The Bayer pattern codes are: 0 – GR/BG; 1 – RG/GB; 2 – BG/GR; 3 – GB/RG. Unless you are using some unusual register settings, the Bayer pattern should be 0. The lenscal library requires that the image be captured without flip or mirror modes. If the image was captued with flip or mirror on then you must re-orient the image before using it with lenscal.
The raw Bayer pixel data from a sensor almost always has an offset (black pedestal) added to all pixels so there is a small blacker-than-black margin. The black pedestal must be subtracted off correctly in order for the calibration to be accurate. The black pedestal is programmed by a register on the sensor, but there is rarely any reason to change it from its default. For non-SOC sensors, assuming the sensor black pedestal register has not been changed from the default and you have not altered the data, pass -1 for nBlack. For SOCs, passing -1 will subtract a value appropriate for the sensor core of the SOC, however many SOCs have a second bypass mode called LC Bypass or PGA Bypass that subtracts the pedestal already. If the image data was captured in that mode then you must pass 0 for nBlack. If you have already subtracted the black pedestal pass 0. If you know that the black pedestal is some specific value, pass that value.

lc_SetInputImageYcbcr()

Definition:
short *lc_SetInputImageYcbcr(void *lc, unsigned char *pOriginal, int nWidth, int nHeight, YCbCrParams *ycbcrParams, int nCropLeft, int nCropTop)
Summary:
Set the current image from a memory buffer containing YCbCr data. The data will be converted to Bayer (or RGB for MT9D111), and a pointer to the converted data is returned.
There are several variations on YCbCr data, so the ycbcrParams structure contains the remaining parameters needed to convert the YCbCr data to RGB. Take care to fill in the parameters correctly or else the calibration will be incorrect.
Except for the MT9D111 (SOC2010), it is recommended to use raw Bayer data instead of YCbCr data for lens calibration. This function is provided only for those cases where it is impossible to get raw Bayer data from the camera system.
Parameters:

lc

Lenscal object.

pOriginal

Pointer to image buffer. May be NULL in which case the function will create a flat, gray image.

nWidth

Image width in pixels.

nHeight

Image height in pixels.

ycbcrParams

Parameters for the YCbCr to RGB conversion. See lc_LoadInputImageFileYcbcr() for a description of these parameters.

nCropLeft

If the image has extra columns, how many columns to skip at the left side. Use -1 if it doesn't apply or to crop equally at the left and right.

 

nCropTop

If the image has extra rows, how many rows to skip at the top side. Use -1 if it doesn't apply or to crop equally at the top and bottom.

 


Returns:

Pointer to the converted image

Returns NULL on an error.


Do not free the returned pointer. It will be freed when the lenscal object is destroyed or a new image is loaded.
The lenscal library requires that the image be captured without flip or mirror modes. If the image was captued with flip or mirror on then you must re-orient the image before using it with lenscal.

lc_LoadInputIniFile()

Definition:
int lc_LoadInputIniFile(void *lc, const char *szInFileNameIni, const char *szSection);
Summary:
Load a DevWare style ini file with lens correction register settings. If you load an image from a file or a memory buffer, you can simulate the lens correction on the image with lc_SimulateCorrectedImage(). The register settings have to be for the sensor type used to create the lc object, of course.
Parameters:

lc

lenscal object

szInFileNameIni

Name of file containing register settings. Can be NULL in which case the function does nothing.

szSection

Which section to load. Can be NULL in which case the first section is loaded.


Returns:

LCRET_OK

NULL filename, or file load encountered no errors.

LCRET_ERROR

File could not be opened, or the section could not be found.



lc_LoadBasisSetting()

Definition:
int lc_LoadBasisSetting(void *lc, const char *szBasisFileNameIni);
Summary:
Load a lens correction register setting to be used as the "basis" for the new register settings generated by lc_FindSolution(). The center coordinate, zone boundaries and scale factors will be carried from the basis setting to the new setting.
Parameters:

lc

lenscal object

szIBasisFileNameIni

Name of file containing register settings. Passing NULL does nothing and is not an error.


Returns:

LCRET_OK

NULL filename or file load encountered no errors.

LCRET_ERROR

File could not be opened, or the section could not be found.


There is no way to unload a basis setting. You would have to destroy the lenscal object and create a new one.

lc_LoadBandsFile()

Definition:
int lc_LoadBandsFile(void lc, const char *szBandsFileName);
Summary:
Load a file specifying the areas of the image to use in the calibration. (Corresponds to the Analysis Bands dialog page in DevWare.) This information is only used for the orthogonal type of lens correction, the polynomial calibration always uses the whole image.
Parameters:

lc

lenscal object

szBandsFileName

Filename. Passing NULL does nothing and is not an error.


Returns:

LCRET_OK

NULL filename or no errors

LCRET_ERROR

Couldn't open file


For complete control over the analysis band positions and weights, put the data in a text file and load it with this function. In the file, for each analysis band put 'H' for a horizontal band or 'V' for a vertical band, followed by the position of the band as a fraction of the image width or height and the weight in arbitrary units. Up to three horizontal bands and three vertical bands may be specified. Example:
H 0.333 1
H 0.667 1
V 0.25 1
V 0.50 2
V 0.75 1
Defines two horizontal bands a 1/3rd and 2/3rd of the image height, at equal weight, and three vertical bands at 1/4 1/2 and 3/4 of the image width, with the center band having greater weight. The default is:
H 0.25 1
H 0.50 1
H 0.75 1
V 0.25 1
V 0.50 1
V 0.75 1
There is no unloading of analysis band parameters. To go back to the defaults, you must destroy the lenscal object and create a new one.

lc_SetImageTransform()

Definition:
int lc_SetImageTransform(void *lc, float *pTransform, int nWidth, int nHeight)
Summary:
Set the current image transform surface from a memory buffer. A transform surface is an array of single-precision floating point values, one for each pixel in the input image. Each pixel in the input image will be multiplied by the corresponding value from the file prior to calibration. It only applies to Bayer images.
Parameters:

lc

Lenscal object.

pTransform

Pointer to transform multipliers. May be NULL in which case no transform will be performed on the next calibration.

nWidth

Array width

nHeight

Array height


Returns:

LCRET_OK

 


The transform surface is applied to the input image in lc_FindSolution(), so it doesn't matter in which order you call lc_SetInputImage() and lc_SetImageTransform(). The transform doesn't change the input image buffer, so you can apply multiple transforms to the same input image.
As of this writing, the width and height of the transform surface must match exactly the input image dimensions or else lc_FindSolution() will fail (this function will not fail). Be informed that this function only keeps a copy of the pointer, not of the array, so you must not free the array memory until after you call lc_FindSolution().
The purpose of this feature is to simulate multiple illuminant responses from a single flat field image.

lc_FindSolution()

Definition:
int lc_FindSolution(void *lc, CalibParams *pCalibParams);
Summary:
Run a calibration algorithm on the input image to find good lens correction and PDAF spatial calibration register settings. You must provide an input image with lc_LoadInputImageFile() or lc_SetInputImage() prior to calling this function. To get the results use lc_DumpRegList() or lc_DumpRegFile().
Parameters:

lc

lenscal object

pCalibParams

Additional parameters for the calibration algorithm. See below.


Returns:

LCRET_OK

The calibration algorithm ran to completion. This does not guarantee that it converged to a good solution.

LCRET_IMAGESIZE

The dimensions of the input image do not match the sensor array.

LCRET_RECONCILE_*

These return values only happen if lc_LoadBasisSetting() was called. Negative codes are errors, positive codes are warnings.


The CalibParams structure:

size_t

size

Set to sizeof(CalibParams), for forward compatibility.

int

nFalloff

How much image brightness falloff to allow at the edges. 100 means try for a flat corrected image; 90 means allow a 10% falloff at the left and right edges; and so on.

int

nIterations

Orthogonal LC only; how many iterations to perform. 24 is normally enough. More might give a better result at the expense of execution time.

int

bOuterBands

Orthogonal LC only; if 1 then use all analysis bands, if 0 then use center bands only. Normally set to 1.

int

nPolyFitGridX

Polynomial LC only; how many times to sample the image horizontally. Along with nPolyFitGridY, defines the grid of points that are used by the polynomial fit function. Using more points gives better noise immunity at the expense of execution time. Try 400 x 300 (120000 total points).

int

nPolyFitGridY

Polynomial LC only; how many times to sample the image vertically.

double

dMargin

Polynomial LC only; a little extra gain. Example: 1.02. You can set this to zero and the library will use an appropriate default value. If dGuaranteeMinGain is used, the library might adjust this value.

double

dGuaranteeMinGain

Polynomial LC only. If this value is non-zero then the library will guarantee that the LC gain will never be less. This may require significant extra computation time.

int

nCoeffPrec

Polynomial LC only. If non-zero then round off the floating point register values to the specified number of bits, including 5 exponent and 1 sign bit.

int

nLensRadius

If you are using a lens that does not illuminate the entire sensor pixel array then use this parameter to inform the calibration algorithm of the radius of the usable image area, measured in device pixels. Otherwise use 0, which means use the whole image for calibration.
Note: In previous versions of the API this field was nWideAngle, and a value of 1 would exclude dark areas. A value of 1 for nLensRadius is accepted and sets the radius to half the width of the pixel array, thereby excluding the corner areas.

int

nXcenter_min

Constraint on calculated lens center horizontal coordinate.

Int

nXcenter_max

Constraint on calculated lens center horizontal coordinate. Ignored if 0. You can set nXcenter_min and nXcenter_max to the same value to force a particular coordinate.

Int

nYcenter_min

Constraint on calculated lens center vertical coordinate.

int

nYcenter_max

Constraint on calculated lens center vertical coordinate. Ignored if 0. You can set nXcenter_min and nXcenter_max to the same value to force a particular coordinate.

int

nFalloff4 [3]

This allows setting the falloff parameter separately for each of the four Bayer color channels. If these are 0 they are ignored and nFalloff is used for all color channels. Otherwise nFalloff is used for the red channel, and nFalloff4[0], nFalloff4[1] and nFalloff4[2] are the green1, green2, and blue channels respectively.

int

nLumaOnly

0 or 1. If 1, calibrates all Bayer color channels to the same calculated luma channel. For sensors using DxO DPP features, for example AR1330.

intnXedgeIgnorePixels at the left and right of the image to ignore for calibration. If -1 then use default, which varies per sensor type. 0 means use all pixels.
intnYedgeIgnorePixels at the top and bottom of the image to ignore for calibration. If -1 then use default, which varies per sensor type. 0 means use all pixels.



lc_FindApga()

Definition:
int lc_FindApga(void *lc, ApgaParams *pApgaParams);
Summary:
Calibrate APGA (Adaptive Positional Gain Adjustment) register settings. APGA is an additional refinement to the lens correction.
You can call this function following lc_FindSolution() to get an even better calibration.
Alternately you can load another uncorrected image and use an existing lens calibration setting with lc_FindApga() to get the APGA refinement to that setting that best corrects the input image.
This is useful when the lens calibration varies with illuminant type. To more easily correct under different illumination conditions create one full lens calibration setting with lc_FindSolution(), then generate APGA refinements to that setting for other illuminants using lc_FindApga().
Like lc_FindSolution(), you must provide an input image with lc_LoadInputImageFile() or lc_SetInputImage() prior to calling this function. You must also provide a lens correction setting, either implicitly with a previous call to lc_FindSolution() or by loading from a file with lc_LoadInputIniFile(). To get the results use lc_DumpRegList() or lc_DumpRegFile().
Parameters:

lc

lenscal object

pApgaParams

Additional parameters for the calibration algorithm. See below.


Returns:

LCRET_OK

The calibration algorithm ran to completion. This does not guarantee that it converged to a good solution.

LCRET_IMAGESIZE

The dimensions of the input image do not match the sensor array.


The ApgaParams structure:

size_t

size

Set to sizeof(CalibParams), for forward compatibility.

int

nXcenter

Center X coordinate register value if there is no LC setting loaded. If there is an LC setting then set this to 0.

Int

nYcenter

Center Y coordinate register value if there is no LC setting loaded. If there is an LC setting then set this to 0.

int

nFalloff

How much image brightness falloff to allow at the edges. 100 means try for a flat corrected image; 90 means allow a 10% falloff at the left and right edges; and so on. Must match the falloff used in lc_FindSolution().

int

nIterations

Currently not used.

int

nPolyFitGridX

Same as CalibParams, above.

int

nPolyFitGridY

Same as CalibParams, above.

int

nWideAngle

Same as CalibParams, above.



lc_ResetPga()

Definition:
int lc_ResetPga(void *lc);
Summary:
The non-APGA registers will not be included by lc_DumpRegList() or lc_DumpRegFile().

Parameters:

lc

lenscal object


Returns:

LCRET_OK

Always.



lc_ResetApga()

Definition:
int lc_ResetApga(void *lc);
Summary:
Set the APGA coefficients in the lc object to 0.
Useful, for example, if you want to run a simulation without APGA.
Parameters:

lc

lenscal object


Returns:

LCRET_OK

Always.



lc_DumpRegList()

Definition:
RegList * lc_DumpRegList(void *lc);
Summary:
Return the current register settings in a RegList structure. The register settings can come from lc_FindSolution() or lc_LoadInputIniFile().
Parameters:

lc

lenscal object


Returns:

Pointer to RegList structure

NULL if the sensor data file was not found.


The RegList structure:

int

count

Number of registers in the list.

RegValue*

pRegValues

Pointer to array of register value structures as follows:

 

int nPage

On sensors that use multiple pages of registers, this is the value to write into the register page select register. On sensors that use 16-bit register addresses or only have one page of registers this field has no meaning.

 

int nReg

The address of the register.

 

int nValue

The value of the register.


Do not free the returned pointer. It will be freed when the lenscal object is destroyed.
This function depends on the sensor data file for the sensor being present on the computer in order to generate numerical register addresses in the output.

lc_DumpRegFile()

Definition:
int lc_DumpRegFile(void *lc, const char *szOutFileName, enum RegFormat format, const char *szHeader, const char *szFooter);
Summary:
Write the current register settings to a file.
Parameters:

lc

lenscal object

szOutFileName

Filename.

format

Select file format; DevWare ini format, or a "C" array.
REGFMT_DEVWARE_INI
REGFMT_DEVWARE_INI_FIELDWR
REGFMT_C_ARRAY

szHeader

Optional string to output at the top of the register list.

szFooter

Optional string to output at the end of the register list.


Returns:

LCRET_OK

No errors.

LCREG_ERROR

File could not be opened.


This function depends on the sensor data file for the sensor being present on the computer in order to generate numerical register addresses in the output file. If the sensor data file is not present, using the DevWare ini format will still work, but the file will conatain FIELD_WR= commands instead of REG= commands. REGFMT_DEVWARE_INI_FIELDWR forces the output to use FIELD_WR= commands with register names instead of addresses. In that case the sensor data file is not needed.

lc_DumpRegFileAppend()

Definition:
int lc_DumpRegFileAppend(void *lc, const char *szOutFileName, enum RegFormat format, const char *szHeader, const char *szFooter);
Summary:
Same as lc_DumpRegFile() except appends to the file if it already exists.
Parameters:

lc

lenscal object

szOutFileName

Filename.

format

See lc_DumpRegFile().

szHeader

Optional string to output at the top of the register list.

szFooter

Optional string to output at the end of the register list.


Returns:

LCRET_OK

No errors.

LCREG_ERROR

File could not be opened.



lc_SimulateCorrectedImage()

Definition:
short * lc_SimulateCorrectedImage(void *lc, const char *szOutFileName, enum RawFormat outFormat, int nBlack);
Summary:
Run a simulation of the current register settings on the current input image, add a black pedestal value, and write the image out to a file. You must provide an input image with lc_LoadInputImageFile() or lc_SetInputImage(), and a set of register values with lc_LoadInputIniFile() or lc_FindSolution() prior to calling this function.
Parameters:

lc

lenscal object

szOutFileName

Filename to save simulated image to. May be NULL in which case the image is not written to a file.

outFormat

The format of the output file is normally determined by the extension of the file name. This parameter can override that format. Use 0 (RAW_UNKNOWN) to use the filename extension to determine the file format, other values to override.

nBlack

Black pedestal value to add to Bayer pixels. Pass -1 to use the sensor default black pedestal.


Returns:

Pointer to simulated image

NULL if there is an error, no input image or memory error.


Do not free the returned pointer. It will be freed when the lenscal object is destroyed.

lc_CalculateCorrectedSbl()

Definition:
int lc_CalculateCorrectedSbl(void *lc, double *pResults, int nLength);
Summary:
Calculate the shading balance results for the corrected image. You must provide an input image with lc_LoadInputImageFile() or lc_SetInputImage(), and a set of register values with lc_LoadInputIniFile() or lc_FindSolution() prior to calling this function. It is not necessary to call lc_SimulateCorrectedImage() first.
Parameters:

lc

lenscal object

pResults

Pointer to an array of doubles to receive the SBL results.

nLength

The length of the pResults array.


Returns:

LCRET_OK

No errors

LCRET_ERROR

Not ready to run SBL analysis


pResults[0] will be shading balance value. pResults[1] will be the non-radial shading balance value. If there are more than two elements in the pResults array, the remainder are undefined.

lc_CalculateCorrectedAvgColor()

Definition:
int lc_CalculateCorrectedAvgColor(void *lc, double *pResults, int nLength);
Summary:
Calculate the average color of the corrected image. You must call lc_SimulateCorrectedImage() first. The results are normalized to 0.0… 1.0 range.
Parameters:

lc

lenscal object

pResults

Pointer to an array of doubles to receive the color values.

nLength

The length of the pResults array.


Returns:

LCRET_OK

No errors

LCRET_ERROR

No simulated image, or parameter error


pResults[0] through pResults[3] will be the Red, Gr, Gb, and Blue average values respectively. If there are more than four elements in the pResults array, the remainder are undefined.

Related pages