2025-07-13 23:57:00
github.com
PlutoFilter is a single-header, zero-allocation image filter library written in C. It applies fast, chainable image effects without any dynamic memory allocation. Compatible with SVG and CSS filter semantics, it makes it easy to reproduce visual effects consistently across platforms.
PlutoFilter is a self-contained, single-header library written in standard C99. It can be used in two modes: header-only or implementation. In header-only mode, simply include the header in any source or header file. This exposes all API declarations but does not include the implementation.
To include the actual implementation, define PLUTOFILTER_IMPLEMENTATION
in one .c
or .cpp
file before including the header:
#define PLUTOFILTER_IMPLEMENTATION
#include "plutofilter.h"
In all other source files, include the header as usual:
The macro PLUTOFILTER_API
controls the linkage of public functions. By default, it expands to extern
, but if you define PLUTOFILTER_BUILD_STATIC
before including the header, all functions will be declared static
instead. This is useful when embedding the library in a single translation unit to avoid symbol collisions.
#define PLUTOFILTER_IMPLEMENTATION
#include "plutofilter.h"
// Replace with real image I/O implementations
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");
// filter: contrast(97%) hue-rotate(330deg) saturate(111%)
plutofilter_color_transform_contrast(surface, surface, 0.97f);
plutofilter_color_transform_hue_rotate(surface, surface, 330.0f);
plutofilter_color_transform_saturate(surface, surface, 1.11f);
write_image(surface, "output.jpg");
return 0;
}
input.jpg |
output.jpg |
---|---|
![]() |
![]() |
void plutofilter_gaussian_blur(plutofilter_surface_t in, plutofilter_surface_t out, float std_deviation_x, float std_deviation_y);
Applies a Gaussian blur to the input surface using separable convolution. The amount of blur is controlled by the standard deviation along the horizontal and vertical axes. A value of 0
applies no blur.
void plutofilter_color_transform(plutofilter_surface_t in, plutofilter_surface_t out, const float matrix[20]);
Applies a 5×4 color transformation matrix to each pixel in the input surface. The matrix operates on color and alpha channels, allowing both isolated and cross-channel transformations. The input and output surfaces may be the same for in-place filtering.
const float original[20] = {
1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f
};
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
};
const float sepia[20] = {
0.393f, 0.769f, 0.189f, 0.0f, 0.0f,
0.349f, 0.686f, 0.168f, 0.0f, 0.0f,
0.272f, 0.534f, 0.131f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f
};
const float contrast[20] = {
1.75f, 0.0f, 0.0f, 0.0f, -0.375f,
0.0f, 1.75f, 0.0f, 0.0f, -0.375f,
0.0f, 0.0f, 1.75f, 0.0f, -0.375f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f
};
original |
grayscale |
sepia |
contrast |
---|---|---|---|
![]() |
![]() |
![]() |
![]() |
void plutofilter_color_transform_grayscale(plutofilter_surface_t in, plutofilter_surface_t out, float amount);
Applies a grayscale effect to the input surface, controlled by a blending amount
between the original color and fully desaturated grayscale. A value of 0
preserves the original image, while 1
results in complete grayscale.
void plutofilter_color_transform_sepia(plutofilter_surface_t in, plutofilter_surface_t out, float amount);
Applies a sepia tone to the input surface, blending between the original image and a warm, brownish tone. The amount
controls the intensity, where 0
leaves the image unchanged and 1
applies full sepia coloration.
void plutofilter_color_transform_saturate(plutofilter_surface_t in, plutofilter_surface_t out, float amount);
Adjusts the color saturation of the input surface. The amount
controls how vivid or muted the colors become: 1
leaves the image unchanged, values less than 1
reduce saturation toward grayscale, and values greater than 1
enhance the intensity of colors.
void plutofilter_color_transform_contrast(plutofilter_surface_t in, plutofilter_surface_t out, float amount);
Adjusts the contrast of the input surface. An amount
of 1
leaves the image unchanged, values below 1
reduce contrast, and values above 1
increase it. The image is scaled around the midpoint of the color range.
void plutofilter_color_transform_brightness(plutofilter_surface_t in, plutofilter_surface_t out, float amount);
Adjusts the brightness of the input surface. An amount
of 1
preserves the original brightness, values below 1
darken the image, and values above 1
brighten it uniformly across all color channels.
void plutofilter_color_transform_opacity(plutofilter_surface_t in, plutofilter_surface_t out, float amount);
Adjusts the opacity (alpha) of the input surface. An amount
of 1
leaves opacity unchanged, while values between 0
and 1
scale the alpha channel linearly. A value of 0
makes the image fully transparent.
void plutofilter_color_transform_invert(plutofilter_surface_t in, plutofilter_surface_t out, float amount);
Applies a color inversion effect to the input surface. The amount
controls the strength of the inversion: 0
leaves the image unchanged, 1
fully inverts the RGB channels, and intermediate values blend between the original and inverted colors.
void plutofilter_color_transform_hue_rotate(plutofilter_surface_t in, plutofilter_surface_t out, float degrees);
Rotates the hue of each pixel in the input surface by the given angle in degrees. The rotation is applied in the RGB color space, preserving luminance and alpha. A value of 0
leaves colors unchanged, while 360
completes a full rotation back to the original.
void plutofilter_blend(plutofilter_surface_t in1, plutofilter_surface_t in2, plutofilter_surface_t out, plutofilter_blend_mode_t mode);
Blends two surfaces using the specified blend mode. The source surface (in1
) is blended over the backdrop (in2
), and the result is written to out
.
Keep your files stored safely and securely with the SanDisk 2TB Extreme Portable SSD. With over 69,505 ratings and an impressive 4.6 out of 5 stars, this product has been purchased over 8K+ times in the past month. At only $129.99, this Amazon’s Choice product is a must-have for secure file storage.
Help keep private content private with the included password protection featuring 256-bit AES hardware encryption. Order now for just $129.99 on Amazon!
Help Power Techcratic’s Future – Scan To Support
If Techcratic’s content and insights have helped you, consider giving back by supporting the platform with crypto. Every contribution makes a difference, whether it’s for high-quality content, server maintenance, or future updates. Techcratic is constantly evolving, and your support helps drive that progress.
As a solo operator who wears all the hats, creating content, managing the tech, and running the site, your support allows me to stay focused on delivering valuable resources. Your support keeps everything running smoothly and enables me to continue creating the content you love. I’m deeply grateful for your support, it truly means the world to me! Thank you!
BITCOIN bc1qlszw7elx2qahjwvaryh0tkgg8y68enw30gpvge Scan the QR code with your crypto wallet app |
DOGECOIN D64GwvvYQxFXYyan3oQCrmWfidf6T3JpBA Scan the QR code with your crypto wallet app |
ETHEREUM 0xe9BC980DF3d985730dA827996B43E4A62CCBAA7a Scan the QR code with your crypto wallet app |
Please read the Privacy and Security Disclaimer on how Techcratic handles your support.
Disclaimer: As an Amazon Associate, Techcratic may earn from qualifying purchases.