DOCS: Added basic explaination to example code.

README: Added readme with copy of example code and first push of readme.
This commit is contained in:
2026-09-03 14:36:46 -04:00
parent 56d26fe723
commit 7745967382
2 changed files with 91 additions and 38 deletions
+28 -38
View File
@@ -16,62 +16,52 @@
int
main()
{
// JPEG out_1 = {
// .name = "../MF8jno.jpg",
//
// };
// JPEG img_j = {
// .name = "../assets/test_2.jpg",
// };
//
// Init base image containers
PPM img;
JPEG jimg;
// unsigned int* buffer = jpeg_load(&img_j);
// PPM out = inherit_from_jpeg(&img_j, '3');
// print_attr(&out);
//
// ppm_save(buffer, out, "../assets/test_2.ppm");
// free(buffer);
PPM img = {
.name = "../assets/test_2.ppm",
};
// Add a file location of image to modify
img.name = "../assets/test_2.ppm";
// unsigned int* buf = ppm_load(img.name, &img);
// unsigned int* box = box_blur(buf, &img, 20);
// free(buf);
img.fmt = '3';
// 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);
}
ppm_save(blur, img, "../assets/test_2_new.ppm");
// 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);
// // buf = u32_rotate(buf, &img);
// ppm_save(box, img, "../assets/test_new.ppm");
// free(box);
// PPM out_2 = inherit_from_jpeg(&out_1, '6');
//
//
// PPM out = inherit_from_jpeg(&out_1, '6');
// print_attr(&out);
// unsigned int* src_buf = ppm_load("../assets/8ktest.ppm", &out_2);
// unsigned int* blurred = box_blur(src_buf, &out_2, 10);
// unsigned int* flip = u32_rotate(src_buf_jpeg, );
// ppm_save(blurred, out_2);
// free(src_buf);
// free(blurred);
return 0;
}