Perfectly Clear SDK Documentation  8.3.0.143
Examples (Windows)

Sample code for both C and C# projects are provided along with the SDK. The examples below demonstrate the general usage of the Perfectly Clear SDK.

Scenario #1 - Using PCF_AutoCorrect

This is the simplest way to use Perfectly Clear library suite. This protocol is more suitable for developing a server type software project or in scenarios where every image will be corrected with one set of parameters (no user-facing option to adjust correction parameters).

  1. Initialize parameters:
    PFCPARAM param;
    // Initialize PFCPARAM structure with user select preset.
    PFC_SetParam(param, presetID);
  2. Populate image data into PFCIMAGE structure:
    // Populate image information into PFCIMAGE structure.
    im.width = width; // Width of image.
    im.height = height; // Height of image.
    im.stride = pbd->Stride; // Stride of image.
    im.format = ((pbd->PixelFormat == PixelFormat24bppRGB) ? PFC_PixelFormat24bppRGB : PFC_PixelFormat32bppARGB);
    im.data = (unsigned char*)pbd->Scan0; // Location of image data.
  3. Perform full correction using the auto function:
    // Process image with Auto Correct function.
    int status = PFC_AutoCorrectPreset(&im, NULL, presetID);
    // Optionally you can check return status of the correction.
    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(" Core pre-calculation returns %d\n", PFCCORE_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. This protocol is more suitable for developing a desktop photo editing type software where user parameters will vary under the same session of an image.

  1. Create process engine:
    // Create PFCENGINE instance for use in this session.
    if (bVerbose)
    {
    // Optionally, check status of the created engine instance.
    if (pEngine->status == ENGINESTATUS_OK)
    {
    printf("Engine created successfully.\n");
    }
    else
    {
    {
    printf("Face Beautification library not available.");
    }
    }
    }
  2. Initialize the parameter structure (using default parameter values): The parameters can be imported from a preset file.
    // Optionally, the process parameters can be imported from a .preset file.
    // (The .preset file can be exported from Athentech's desktop applications. e.g. Workbench.)
    int ret = PFC_ReadPresets(param, profilename);
    if (bVerbose)
    printf("PFC_ReadPresets returns %d\n", ret);
    Alternatively the parameters can be initialized using PFC_SetParam() function.
    // Use default parameters.
    PFC_SetParam(param);
    Example:
    // Set process parameters.
    PFCPARAM param;
    if (profilename != NULL)
    {
    // Optionally, the process parameters can be imported from a .preset file.
    // (The .preset file can be exported from Athentech's desktop applications. e.g. Workbench.)
    int ret = PFC_ReadPresets(param, profilename);
    if (bVerbose)
    printf("PFC_ReadPresets returns %d\n", ret);
    if (ret != 0)
    {
    if (ret == -2) // preset file not found
    {
    // Use default parameters if preset file not found.
    PFC_SetParam(param);
    printf("Unable to open preset file %s. Using default settings.\n", profilename);
    }
    else if (ret == -8)
    {
    printf("Invalid preset file.\n");
    exit(0);
    }
    else
    {
    printf("Unable to read preset file.\n");
    exit(0);
    }
    }
    }
    else
    {
    // Use default parameters.
    PFC_SetParam(param);
    }
  3. Populate image data into PFCIMAGE structure:
    // Populate image information into PFCIMAGE structure.
    im.width = width; // Width of image.
    im.height = height; // Height of image.
    im.stride = pbd->Stride; // Stride of image.
    im.format = ((pbd->PixelFormat == PixelFormat24bppRGB) ? PFC_PixelFormat24bppRGB : PFC_PixelFormat32bppARGB);
    im.data = (unsigned char*)pbd->Scan0; // Location of image data.
  4. Perform pre-calculation of image specific profile:
    // Analyze image and obtain image specific profile.
    PFCPROFILE pProfile = PFC_Calc(&im, NULL, pEngine, CALC_ALL, -1, NULL, NULL, bVerbose ? myStatus : NULL);
    // Optinally, check precalc status.
    if (bVerbose)
    {
    if (pProfile->Status != 0)
    {
    if (pProfile->Status & CALC_NR)
    {
    printf(" Pre-calculation on noise returns %d\n", pProfile->NR_Status);
    }
    if (pProfile->Status & CALC_CORE)
    {
    printf(" Core pre-calculation returns %d\n", pProfile->CORE_Status);
    }
    if (pProfile->Status & CALC_FB)
    {
    printf(" Pre-calculation on face details returns %d\n", pProfile->FB_Status);
    }
    if (pProfile->Status & CALC_RE)
    {
    printf(" Pre-calculation on red eye returns %d\n", pProfile->RE_Status);
    }
    }
    printf("Calc returns %d\n", pProfile->Status);
    }
    (pEngine is created from step 1.)
  5. Apply the calculated profile and parameters to the image.
    // Process image with parameters.
    PFCAPPLYSTATUS status = PFC_Apply(&im, pEngine, pProfile, param, bVerbose ? myStatus : NULL);
    // Optionally, check process status.
    if (bVerbose)
    {
    if (status == APPLY_SUCCESS)
    {
    printf("Image processed successfully.\n");
    }
    else if (status > APPLY_SUCCESS)
    {
    int code;
    // Check return code for Noise Removal
    code = NRRETCODE(status);
    printf("Noise removal status %d\n", code);
    // Check return code for Perfectly Clear Core correction
    code = CORERETCODE(status);
    printf("Perfectly Clear correction status %d\n", code);
    // Check return code for Face Beautification
    code = FBRETCODE(status);
    printf("Face beautification status %d\n", code);
    // Check return code for Red Eye Removal
    code = RERETCODE(status);
    printf("Red eye removal status %d\n", code);
    }
    else
    {
    printf("Image processing failed with return code: %d\n", status);
    }
    }
  6. Release resources used by PFCPROFILE:
    // Release Profile
    PFC_ReleaseProfile(pProfile);
  7. Release the engine to release resource:
    // Destroy engine. It is important that PFCENGINE is destroyed after
    // all the profiles are released.