Perfectly Clear SDK Documentation  9.1.1.325
Examples (C Sharp)

Sample code C# projects are provided along with the SDK. The examples below demonstrate the general usage of the Perfectly Clear SDK (class PerfectlyClear ).

Setting up License Protection

If you have been provided with a license protected SDK, then there are two ways that you can activate this license in your code. It is always safe to use the multi-threading approach, though it does take slightly more code. The scenarios below on the sections below show the single-threaded method, as it's simpler and our sample code is all single-threaded.

Single-Threaded

This method requires fewer calls to our SDK, but isn't intended for multithreaded applications where many concurrent calls will be made at once. The process is to setup the protection path when calling the class constructor.

// Instantiate class object with the path to your sdk_license folder:
PerfectlyClearAdapter.PerfectlyClear PfC = new PerfectlyClearAdapter.PerfectlyClear("C:\\PerfectlyClear\\sdk_license");
// then, just load your Presets or parameters, load the image, and apply the corrections
// this part is documented below, so it it omitted here
// ...
//
// After all processing is complete, the class destructor takes care of releasing the resources allocated by the constructor.

Multi-Threaded

// Set the protection path at application startup:
PerfectlyClearAdapter.PerfectlyClear.SetProtectionPath("C:\\PerfectlyClear\\sdk_license");
// Then, the threaded portion of the code, looping over images:
for (int i = 0; i < images.count; i++) {
// Call the constructor once per image, omitting the constructor parameters
// then, load the correction parameters and images, correct and save the results
// details of this is omitted here, see below for options on this
// ...
// Dispose of the class once done:
PfC.Dispose()
}
// Last, release the resources from the protection step:

Scenario #1 - Using 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 correcition parameters).

  1. Instantiate PerfectlyClear class instance:
    // Instantiate class object
    // if you have a license key, then call PFC_SetProtectionPath with the path
    // to your license files
  2. Perform full correction using the auto function:
    // Use fully automated function for image correction
    int ret = Pfc.AutoCorrect(ref bm, -1, null, false);

Scenario #2 - Separate Calc and 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. Instantiate PerfectlyClear class instance:
    // Instantiate class object
    // if you have a license key, then call PFC_SetProtectionPath with the path
    // to your license files
  2. Initialize parameters: The parameters are set to default values when the PerfectlyClear class is instantiated. Alternately it can be imported from a preset file.
    // Optionally, you can import process parameters from a preset file
    if (presetfile != "")
    {
    int rc = Pfc.ReadPresets(presetfile);
    if (bVerbose)
    {
    Console.WriteLine("ReadPresets returns " + rc.ToString());
    }
    }
  3. Perform pre-calculation of image specific profile:
    // Perform profile calculation on image
    PerfectlyClearAdapter.ADPTRRETURNCODE cret = Pfc.Calc(ref bm, PerfectlyClearAdapter.PFCFEATURE.CALC_ALL, -1, null);
    // Check status of precalc analysis.
    if (bVerbose)
    {
    Console.WriteLine("Precalc return code: " + cret.ToString());
    Console.WriteLine("Noise removal return code: " + Pfc.LastStatus.NR_Status.ToString());
    Console.WriteLine("Perfectly Clear core return code: " + Pfc.LastStatus.CORE_Status.ToString());
    Console.WriteLine("Face beautification return code: " + Pfc.LastStatus.FB_Status.ToString());
    Console.WriteLine("Red eye removal return code: " + Pfc.LastStatus.RE_Status.ToString());
    }
    Note: The pre-calculated profile for the source image will be store in the PerfectlyClear class instance.
  4. Apply the calculated profile (stored within the class instance) and parameters to the image.
    // Enhance image.
    PerfectlyClearAdapter.PFCAPPLYSTATUS aret = Pfc.Apply(ref bm, 100);
    // Optionally show return code of the process.
    if (bVerbose)
    {
    // Check if there's any warning
    if (aret == PerfectlyClearAdapter.PFCAPPLYSTATUS.APPLY_SUCCESS)
    {
    Console.WriteLine("Image processed successfully.");
    }
    else if (aret > 0)
    {
    // In case of error, query LastStatus for individual return code
    Console.WriteLine("Noise removal return code: " + Pfc.LastStatus.NR_Status.ToString());
    Console.WriteLine("Perfectly Clear core return code: " + Pfc.LastStatus.CORE_Status.ToString());
    Console.WriteLine("Face beautification return code: " + Pfc.LastStatus.FB_Status.ToString());
    Console.WriteLine("Red eye removal return code: " + Pfc.LastStatus.RE_Status.ToString());
    }
    else if (aret < 0)
    {
    // In case of general process error (negative return code)
    Console.WriteLine("Perfectly Clear return code: " + aret.ToString());
    }
    }