Version: 1.0
Loading...
Searching...
No Matches
Color Balance Example

#include <stdio.h>
#include <stdlib.h>
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image/stb_image.h"
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image/stb_image_write.h"
int main(void) {
int width, height, channels;
unsigned char* inputImage = stbi_load("test.jpg", &width, &height, &channels, 0);
if (inputImage) {
unsigned char* outputImage = (unsigned char*)calloc(width * channels * height * sizeof(unsigned char), 1);
if (outputImage) {
int stride = width * channels;
int redBalance = 23; // Range: -100 to 100
int greenBalance = 0; // Range: -100 to 100
int blueBalance = 14; // Range: -100 to 100
OcToneBalanceMode mode = SHADOWS; // [SHADOWS, MIDTONES, HIGHLIGHTS]
bool preserveLuminosity = true;
OC_STATUS status = ocularColorBalance(input, output, width, height, stride,
redBalance, greenBalance, blueBalance,
mode, preserveLuminosity);
if (status == OC_STATUS_OK) {
stbi_write_jpg("test_out.jpg", width, height, channels, outputImage, 100);
}
}
free(outputImage);
}
stbi_image_free(inputImage);
}
OC_STATUS ocularColorBalance(unsigned char *Input, unsigned char *Output, int Width, int Height, int Stride, int redBalance, int greenBalance, int blueBalance, OcToneBalanceMode Mode, bool preserveLuminosity)
Allows changing the overall mixture of colors in an image to correct color casts.

Before

After