2a168f894746f753889a4ee110371a774887e287
LibIMG
A "powerful" library that I have worked on allowing you to take a PPM image and apply filters and transformations and download the file. It also works for JPEG which you can also convert to PPM and vice versa
[Note] All documentation is in the code and files itself. So to save myself time I would recommend going through the code itself.
[Warning] There are a lot of changes you can make to an image but this is not an extensive library to use mainstream. I would hope you understood that already. This Is for a self made project learning bitwise for c originally and now has become bigger and cooler than expected.
Example
/*
* Keep in mind any function that creates a new buffer and returns it can
* overwrite the old one, however it is lost. SO create a new variable and free
* the old one after use.
*/
int
main()
{
// Init base image containers
PPM img;
JPEG jimg;
// Add a file location of image to modify
img.name = "../assets/test_2.ppm";
// Load the PPM image
unsigned int* buf = ppm_load(img.name, &img);
// Check for null image load. In case image doesnt exist or fails to
// load
if (!buf)
{
LOGERROR(ERR_BUF_NULL);
return ERR_BUF_NULL;
}
// Blur image and save to new pointer
unsigned int* blur = box_blur(buf, &img, 20);
// Free old buffer. MUST DO THIS. Maybe not immediately but before
// ending or possibly leaking. Also it stays in heap and a large image
// can take a lot of memory so better to clear anyways.
free(buf);
// Check for null image load. In case image doesnt exist or fails to
// load
if (!blur)
{
LOGERROR(ERR_BUF_NULL);
return ERR_BUF_NULL;
}
// Loop image and apply filter to each pixel.
for (int i = 0; i < img.len; i++)
{
blur[i] = u32_rotl(blur[i], 4);
}
// Take the attributes from ppm image so jpeg file can be saved
jimg = inherit_from_ppm(&img);
// Saves jpeg to location specified
jpeg_save(blur, &jimg, "../assets/test_2_new.jpg");
// Make sure to free any buffer still active
free(blur);
return 0;
}
Languages
C
97.5%
CMake
2.5%