EyeQ Docs

I/O patterns

Work with streams, buffers, and the PFCImageFile class

The SDK supports multiple input/output patterns beyond simple file operations. These samples demonstrate how to process images from stdin/stdout, work with .NET MemoryStream objects, and use the PFCImageFile helper class.

PFCImageFile class

The PFCImageFile class handles image loading, color space conversion, and metadata preservation. It's available in both C++ and C# and is the recommended way to work with images in the SDK.

C++ usage

In C++, use LoadImageFile and SaveImageFile for file operations.

#include "PFCImageFile.h"

// Load from file
PFCImageFile imageFile;
bool convertToSRGB = true;
PFC_FILE_LOAD_STATUS status = imageFile.LoadImageFile(
    "input.jpg", 
    convertToSRGB, 
    NULL
);

// Access image properties
int width = imageFile.width;
int height = imageFile.height;
int stride = imageFile.stride;
unsigned char* pixels = imageFile.raw_image;

// Save to file
imageFile.SaveImageFile(
    "output.jpg", 
    90,     // quality
    true,   // convert to original color space
    true    // preserve metadata
);

C# usage

In C#, the API is similar but uses .NET conventions.

using PerfectlyClearAdapter;

// Load from file
PFCImageFile file = new PFCImageFile();
file.LoadImage(inputPath);

// Process with PerfectlyClear
PerfectlyClear Pfc = new PerfectlyClear("C:\\path\\to\\sdk_license");
Pfc.AutoCorrect(ref file, "preset.preset");

// Save to file
file.SaveImage(outputPath, 90);

Standard I/O (C/C++)

The Standard-IO sample shows how to read compressed image data from stdin and write the corrected image to stdout. This is useful for integration with shell pipelines or other processes.

Read from stdin

Read the compressed image data into a buffer, then expand it into raw pixel data for processing.

// Read compressed image from stdin
fseek(stdin, 0, SEEK_END);
const long inSize = ftell(stdin);
fseek(stdin, 0, SEEK_SET);

char* inBuffer = (char*)malloc(inSize);
fread(inBuffer, inSize, 1, stdin);

// Expand compressed data to raw pixels
PFCImageFile originalImageFile;
bool bConvertToSRGB = true;

PFC_FILE_LOAD_STATUS st = originalImageFile.ExpandImageBuffer(
    inBuffer, 
    inSize, 
    PFCImageFile::PFC_JPEG,  // or PFC_PNG, PFC_WEBP
    bConvertToSRGB, 
    NULL
);

free(inBuffer);

Write to stdout

After correction, compress the image and write to stdout.

unsigned char* outBuffer = NULL;
unsigned long outSize = originalImageFile.CompressImageBuffer(
    &outBuffer, 
    PFCImageFile::PFC_JPEG,  // output format
    90,                       // quality
    true,                     // convert to original color space
    true                      // preserve metadata
);

fwrite(outBuffer, outSize, 1, stdout);
free(outBuffer);

Usage example

Use the sample in a shell pipeline to correct images on the fly.

# Pipe image through correction
cat input.jpg | ./Standard-IO -i jpeg -o jpeg > output.jpg

# Convert format while correcting
cat input.png | ./Standard-IO -i png -o jpeg > output.jpg

MemoryStream I/O (C#)

The DotNetCore_MemoryStream sample demonstrates reading and writing image data using .NET MemoryStream objects. This is useful when your application already has image data in memory.

Read from MemoryStream

Create a PFCImageFile and expand compressed data from a MemoryStream.

// Create PFCImageFile to hold the expanded image
PerfectlyClearAdapter.PFCImageFile file = new PerfectlyClearAdapter.PFCImageFile();

// Your application's MemoryStream containing compressed image data
MemoryStream inMemoryCopy = new MemoryStream();
using (FileStream fs = File.OpenRead(inputPath))
{
    fs.CopyTo(inMemoryCopy);
}

// Reset position before reading
inMemoryCopy.Position = 0;

// Expand the compressed data
if (file.ExpandImageBuffer(inMemoryCopy, PFCImageFile.PFC_FILETYPE.PFC_JPEG, true, "") 
    != PFCImageFile.PFC_FILE_LOAD_STATUS.LOAD_OK)
{
    Console.WriteLine("Unable to open image");
    return;
}

Process and write to MemoryStream

After processing, compress the image back to a MemoryStream.

// Process the image (Calc and Apply as usual)
Pfc.Calc(ref file, PFCFEATURE.CALC_ALL, -1, null);
Pfc.Apply(ref file);

// Compress and write to MemoryStream
using (MemoryStream outStream = file.CompressImageBuffer(
    PFCImageFile.PFC_FILETYPE.PFC_JPEG, 
    90,     // quality
    false,  // don't convert color space
    true))  // preserve metadata
{
    outStream.Seek(0, SeekOrigin.Begin);
    
    // Write to file or pass to another operation
    FileStream outFile = File.Create(outputPath);
    outStream.CopyTo(outFile);
}

Loading from Bitmap (C#)

For applications already using System.Drawing, you can work directly with Bitmap objects.

// Load as Bitmap
Bitmap bm = new Bitmap(inputPath);

// Process
Pfc.AutoCorrect(ref bm);

// Save
bm.Save(outputPath);

The PFCImageFile class is recommended when you need automatic color space conversion and metadata handling. Use Bitmap directly for simpler workflows.

Source files

You can find the code snippets in the following files:

PatternPlatformPath
Standard I/OLinux/macOSLinux/Standard-IO/Standard-IO.cpp
MemoryStreamWindows (.NET)Win/DotNetCore_MemoryStream/Program.cs
PFCImageFileWindows (C++)Win/Sample-PFCImageFile/Sample-PFCImageFile.cpp
PFCImageFileWindows (.NET)Win/DotNetCore_PFCImageFile/Program.cs

PFC-SDK Version 10.7.2.1269 built from 4fa849d8101945eea725a08dd0dae5101f090fa0 on 11-10-2025.

Copyright © 2026 EyeQ Imaging Inc. All rights reserved.

On this page