Sample source code is provided in this SDK for three applications that are ready to build on linux systems. These three examples each show different usage models and provide a starting point for adapting these into ready-for-production command line applications. These example applications are:
Sample1 - AutoCorrect
This is the most simple way to get started with this SDK. This sample application will correct the JPG or PNG file with one of 5 build-in presets. This sample uses the PFC_AutoCorrect() function.
Sample2 - Reading .preset files
This sample allows reading .preset files created with Perfectly Clear Workbench or Perfectly Clear Complete, and will apply the parameters found in that .preset file to the image provided in the first command line argument. This sample uses separate PFC_Calc() and PFC_Apply() function calls, so it is slightly less efficient if only a single correction will be applied to the image.
Resize Sample - Correct and Resize the image
Scenario #1 - Using PCF_AutoCorrect
The simplest way to use Perfectly Clear library suite.
- Setup the license protection
if (bVerbose)
printf("License Code Status is %d\n", code);
- Populate image data into PFCIMAGE structure:
im.
width = originalImageFile.width;
im.
height = originalImageFile.height;
im.
stride = originalImageFile.stride;
im.
data = originalImageFile.raw_image;
- Initialize the parameter structure:
- Perform full correction using the auto function:
int status =
PFC_AutoCorrect(&im, NULL, param, -1, NULL, FALSE, bVerbose? myStatus : NULL);
if (bVerbose)
{
if (status == 0)
{
printf("Image processed successfully\n");
}
else if (status > 0)
{
printf(
" Pre-calculation on noise returns %d\n",
PFCNR_STATUS(status));
printf(
" Pre-calculation on face details returns %d\n",
PFCFB_STATUS(status));
printf(
" Pre-calculation on red eye returns %d\n",
PFCRE_STATUS(status));
}
else if (status < 0)
{
printf("Image processed failed with return code: %d\n", status);
}
}
Scenario #2 - Separate PFC_Calc and PFC_Apply
More advanced way to use Perfectly Clear library suite.
- Setup the license protection
if (bVerbose)
printf("License Code Status is %d\n", code);
- Create a single engine that can be re-used on many images:
if (bVerbose)
{
{
printf("Engine created successfully.\n");
}
else
{
{
printf("Face Beautification library not available.");
}
}
}
- Initialize the parameter structure (using default parameter values): The parameters can be imported from a preset file.
if (bVerbose)
printf("PFC_ReadPresets returns %d\n", ret);
Alternatively the parameters can be initialized using PFC_SetParam() function. Example: if (profilename != NULL)
{
if (bVerbose)
printf("PFC_ReadPresets returns %d\n", ret);
if (ret != 0)
{
if (ret == -2)
{
printf("Unable to open preset file %s. Using default settings.\n", argv[3]);
}
else
{
printf("Unable to read preset file.\n");
exit(1);
}
}
}
else
{
}
- Populate image data into PFCIMAGE structure:
im.
width = originalImageFile.width;
im.
height = originalImageFile.height;
im.
stride = originalImageFile.stride;
im.
data = originalImageFile.raw_image;
- Perform pre-calculation of image specific profile. pEngine is created from step 1 and used here in the PFC_Calc function
if (bVerbose)
{
if (pProfile->Status != 0)
{
{
printf(" Pre-calculation on noise returns %d\n", pProfile->NR_Status);
}
{
printf(" Core pre-calculation returns %d\n", pProfile->CORE_Status);
}
{
printf(" Pre-calculation on face details returns %d\n", pProfile->FB_Status);
}
{
printf(" Pre-calculation on red eye returns %d\n", pProfile->RE_Status);
}
}
printf("Calc returns %d\n", pProfile->Status);
}
- Apply the calculated profile and parameters to the image.
{
printf("Image processed successfully.\n");
}
{
printf(
"Noise removal status %d\n",
NRRETCODE(status));
printf(
"Perfectly Clear correction status %d\n",
CORERETCODE(status));
printf(
"Face beautification status %d\n",
FBRETCODE(status));
printf(
"Red eye removal status %d\n",
RERETCODE(status));
}
{
printf("Image processing failed with return code: %d\n", status);
}
- Release resources used by PFCPROFILE:
- Release the engine to release resource. Or, keep the engine around for use on another image.
Scenario #3 - Resize and Correct
This sample loads and corrects the image exactly like in Sample 1, but this resized the output images:
imageResized.
width = fileResized.width;
imageResized.
height = fileResized.height;
imageResized.
stride = fileResized.stride;
imageResized.
data = fileResized.raw_image;
char outResized[1000];
sprintf(outResized,
"%s.%dx%d.jpg", inname, imageResized.
width, imageResized.
height);
fileResized.SaveImageFile(outResized, 90, false, false);
}
- Copyright
- Copyright (C) 2021 EyeQ Imaging Inc