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:
@@ -0,0 +1,63 @@
|
|||||||
|
|
||||||
|
```c
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
+28
-38
@@ -16,62 +16,52 @@
|
|||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
// JPEG out_1 = {
|
// Init base image containers
|
||||||
// .name = "../MF8jno.jpg",
|
PPM img;
|
||||||
//
|
JPEG jimg;
|
||||||
// };
|
|
||||||
// JPEG img_j = {
|
|
||||||
// .name = "../assets/test_2.jpg",
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
|
|
||||||
// unsigned int* buffer = jpeg_load(&img_j);
|
// Add a file location of image to modify
|
||||||
// PPM out = inherit_from_jpeg(&img_j, '3');
|
img.name = "../assets/test_2.ppm";
|
||||||
// print_attr(&out);
|
|
||||||
//
|
|
||||||
// ppm_save(buffer, out, "../assets/test_2.ppm");
|
|
||||||
// free(buffer);
|
|
||||||
PPM img = {
|
|
||||||
.name = "../assets/test_2.ppm",
|
|
||||||
};
|
|
||||||
|
|
||||||
// unsigned int* buf = ppm_load(img.name, &img);
|
// Load the PPM image
|
||||||
// unsigned int* box = box_blur(buf, &img, 20);
|
|
||||||
// free(buf);
|
|
||||||
img.fmt = '3';
|
|
||||||
unsigned int* buf = ppm_load(img.name, &img);
|
unsigned int* buf = ppm_load(img.name, &img);
|
||||||
|
|
||||||
|
// Check for null image load. In case image doesnt exist or fails to
|
||||||
|
// load
|
||||||
if (!buf)
|
if (!buf)
|
||||||
{
|
{
|
||||||
|
LOGERROR(ERR_BUF_NULL);
|
||||||
return ERR_BUF_NULL;
|
return ERR_BUF_NULL;
|
||||||
}
|
}
|
||||||
|
// Blur image and save to new pointer
|
||||||
unsigned int* blur = box_blur(buf, &img, 20);
|
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);
|
free(buf);
|
||||||
|
// Check for null image load. In case image doesnt exist or fails to
|
||||||
|
// load
|
||||||
if (!blur)
|
if (!blur)
|
||||||
{
|
{
|
||||||
|
LOGERROR(ERR_BUF_NULL);
|
||||||
return ERR_BUF_NULL;
|
return ERR_BUF_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Loop image and apply filter to each pixel.
|
||||||
for (int i = 0; i < img.len; i++)
|
for (int i = 0; i < img.len; i++)
|
||||||
{
|
{
|
||||||
blur[i] = u32_rotl(blur[i], 4);
|
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);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user