PlutoFilter: A Zero Memory Allocation Image Filter Library in C

Introduction

In the field of image processing, performance and simplicity are always the goals pursued by developers. Today, we introduce an open-source project—PlutoFilter—which is a lightweight, high-performance, and feature-rich image filter library. It is written in pure C language, consists of a single header file, and does not use dynamic memory allocation at all, making it a boon for embedded and resource-sensitive projects.

Moreover, its interface design is very user-friendly, supporting method chaining, compatible with SVG and CSS filter semantics, and providing consistent cross-platform performance, truly representing the idea of “small size, big energy”.

Next, let’s take a closer look!

What is PlutoFilter?

PlutoFilter is a single-header, zero memory allocation image filter library created by developer sammycage, written in standard C99. It can achieve various common image filter effects without any dynamic memory allocation, such as:

  • Gaussian Blur
  • Color Transform: Grayscale, Saturation Adjustment, Contrast Enhancement, etc.
  • Blend Mode: Overlay, Soft Light, Difference, etc.
  • Composite Operations

These features not only meet the needs of daily image processing but also seamlessly integrate with SVG and CSS filter specifications, truly achieving “one coding, multi-end reuse”.

Why Choose PlutoFilter?

✅ Single Header File, Extremely Simple Integration

As a single-header library, integrating PlutoFilter is extremely simple. Just include the <span>plutofilter.h</span> header file in your project to use its API. You can even choose to compile it as static functions to avoid naming conflicts.

#define PLUTOFILTER_IMPLEMENTATION
#include "plutofilter.h"

With just this line of code, you can bring the entire image processing engine into your project.

⚡ Zero Memory Allocation, Ultimate Performance

PlutoFilter does not perform any dynamic memory allocation during runtime, which means its memory usage is predictable, making it very suitable for embedded systems or real-time image processing scenarios.

🧩 Comprehensive Features, Strong Extensibility

Although small in size, the features provided by PlutoFilter are not lacking at all. From basic color transformations to complex blend modes, and future planned morphological filters, lighting effects, etc., it has great potential for expansion.

Quick Start: A Simple Example

Here is a complete example of using PlutoFilter to implement image filters:

#define PLUTOFILTER_IMPLEMENTATION
#include "plutofilter.h"

// Assume you have implemented image loading and saving functions
extern plutofilter_surface_t load_image(const char* filename);
extern void write_image(plutofilter_surface_t surface, const char* filename);

int main(void)
{
    plutofilter_surface_t surface = load_image("input.jpg");

    // Apply multiple filter effects
    plutofilter_color_transform_contrast(surface, surface, 0.97f);   // Contrast adjustment
    plutofilter_color_transform_hue_rotate(surface, surface, 330.0f); // Hue rotation
    plutofilter_color_transform_saturate(surface, surface, 1.11f);    // Saturation enhancement

    write_image(surface, "output.jpg");
    return 0;
}

Isn’t it intuitive? With just a few function calls, you can easily achieve chained application of image filters.

Core Features Overview

Gaussian Blur

void plutofilter_gaussian_blur(plutofilter_surface_t in, plutofilter_surface_t out, float std_deviation_x, float std_deviation_y);

Supports setting blur intensity separately for horizontal and vertical directions, with a value of 0 indicating no blur.

Color Transform

By passing a 5×4 color matrix, you can customize various color transformation effects, such as grayscaling, inversion, hue shifting, etc.

const float grayscale[20] = {
    0.2126f, 0.7152f, 0.0722f, 0.0f, 0.0f,
    0.2126f, 0.7152f, 0.0722f, 0.0f, 0.0f,
    0.2126f, 0.7152f, 0.0722f, 0.0f, 0.0f,
    0.0f,    0.0f,    0.0f,    1.0f, 0.0f
};

plutofilter_color_transform(in, out, grayscale);

Blend Mode

Supports up to 18 blend modes, including common Photoshop modes like Multiply, Screen, Overlay, etc.

plutofilter_blend_multiply(in1, in2, out);

Composite Operations

Supports Over, In, Out, Atop, and other composite modes, suitable for layer composition and visual effects development.

Project Structure Overview

The repository structure is also very clear, suitable for quick onboarding:

├── .github/
├── .gitignore
├── LICENSE
├── README.md
├── examples/
├── meson.build
├── plutofilter.h
└── tests/

All core logic is encapsulated in <span>plutofilter.h</span>, making it easy to port and redevelop.

Future Development: A Sneak Peek at the Roadmap

Currently, PlutoFilter has implemented most common filters, but there are still many new features in planning, including:

  • Morphological Filters
  • Diffuse Lighting
  • Specular Lighting
  • Convolve Matrix
  • Displacement Map
  • Turbulence

These advanced filters will greatly expand the application scenarios of PlutoFilter, making it not limited to basic image processing.

Conclusion

PlutoFilter is a highly potential small image processing library, especially suitable for projects that pursue extreme performance and a simple architecture. It is not only feature-rich but also easy to integrate, with a very user-friendly API design.

If you are looking for a lightweight filter library that can be used in embedded devices, game engines, or image editors, then PlutoFilter is definitely worth a try!

GitHub Address

🔗 https://github.com/sammycage/plutofilter[1]

📌 One-Sentence Recommendation

“One header file to handle image filters? PlutoFilter is your next performance champion!”

References

[1]

https://github.com/sammycage/plutofilter: https://github.com/sammycage/plutofilter

Leave a Comment