Many changes just look at the new documentation and such

This commit is contained in:
Andrew Haynes
2026-08-31 22:18:42 -04:00
parent 5367c71c34
commit 854f5c2ba6
7 changed files with 139 additions and 47 deletions
Vendored
BIN
View File
Binary file not shown.
+3 -3
View File
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.16)
project(image_processor LANGUAGES C)
project(libimg LANGUAGES C)
set(CMAKE_C_STANDARD 23)
set(CMAKE_C_STANDARD_REQUIRED ON)
@@ -31,6 +31,6 @@ target_link_libraries(PROCESSOR PUBLIC PkgConfig::TURBOJPEG)
set_target_properties(PROCESSOR PROPERTIES EXPORT_NAME PROCESSOR)
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
add_executable(image_processor src/main.c) # Assuming you have a main.c
target_link_libraries(image_processor PRIVATE PROCESSOR)
add_executable(libimg src/main.c) # Assuming you have a main.c
target_link_libraries(libimg PRIVATE PROCESSOR)
endif()
-8
View File
@@ -1,8 +0,0 @@
[
{
"directory": "/Users/andrew/personal/Projects/C/image_processor",
"command": "/usr/bin/cc -I/Users/andrew/personal/Projects/C/image_processor/include -I/opt/homebrew/include -g -std=gnu2x -arch arm64 -o CMakeFiles/image_processor.dir/src/main.c.o -c /Users/andrew/personal/Projects/C/image_processor/src/main.c",
"file": "/Users/andrew/personal/Projects/C/image_processor/src/main.c",
"output": "CMakeFiles/image_processor.dir/src/main.c.o"
}
]
+1 -1
View File
@@ -7,7 +7,7 @@ unsigned int*
ppm_load(const char* file, PPM* m_attr);
int
ppm_save(const unsigned int* buf, const PPM img);
ppm_save(const unsigned int* buf, const PPM img, char* name);
unsigned int*
jpeg_load(JPEG* m_attr);
+111 -26
View File
@@ -1,69 +1,154 @@
#ifndef UTILS_H
#define UTILS_H
#define BYTE_A 0xFF000000u
#define BYTE_R 0x00FF0000u
#define BYTE_G 0x0000FF00u
#define BYTE_B 0x000000FFu
#define BYTE_RGB 0x00FFFFFFu
#define BYTE 0xFFu
#define LONG_BYTE 0xFFFFu
/*
* 0 0 0 0 0 0 0 0
* ^ - Starting Bit for all calculations
* ^ - Starting bit for when I talk about sets of bits
*/
#define SHIFT_8 8
#define SHIFT_16 16
#define SHIFT_24 24
// The u in the BYTE Macros are for unsigned calls so colors are not changed to
// signed and the values cut in half
#define BYTE_A 0xFF000000u /**< Isolates the First Byte for alpha */
#define BYTE_R 0x00FF0000u /**< Isolates the Second Byte for red */
#define BYTE_G 0x0000FF00u /**< Isolates the Third Byte for green */
#define BYTE_B 0x000000FFu /**< Isolates the Fourth Byte for blue */
#define BYTE_RGB 0x00FFFFFFu /**< Isolates 24-Bits from end (RGB) */
#define BYTE 0xFFu /**< Pulls out 8 shifted Bits */
#define LONG_BYTE 0xFFFFu /**< Pulls out 16 shifted Bits */
#define SHIFT_8 8 /**< Constant shift of 8-Bits */
#define SHIFT_16 16 /**< Constant shift of 16-Bits */
#define SHIFT_24 24 /**< Constant shift of 24-Bits */
/**
*
* @brief Max value for any channel
* @details For alpha channel this is the max opacity setting and 0 is fully
* transparent, 255 is white for any color and 0 is black.
* */
#define MAX 255
#define HALF_MAX ((int)(MAX / 2) + 1)
#define HALF_MAX \
((int)(MAX / 2) + 1) /**< Half Max Color Value for any channel */
/**< Func to isolate alpha channel into variable */
#define DECODE_A(clr) (((clr) >> SHIFT_24) & BYTE)
/**< Func to isolate red channel into variable */
#define DECODE_R(clr) (((clr) >> SHIFT_16) & BYTE)
/**< Func to isolate green channel into variable */
#define DECODE_G(clr) (((clr) >> SHIFT_8) & BYTE)
/**< Func to isolate blue channel into variable */
#define DECODE_B(clr) ((clr) & BYTE)
/**
* @brief Packs RGB channels into int
* @details Takes R, G, B char channels and packs them into a singular integer
* with the first 8 Bits reserved for alpha channel (set to MAX by default). See
* diagram at top for my thinking of starting bits
* @param[in] r The red channel stored as char and packed into int
* @param[in] g The green channel stored as char and packed into int
* @param[in] b The blue channel stored as char and packed into int
*
* */
#define ENCODE_RGB(r, g, b) \
(((unsigned int)(MAX) << SHIFT_24) | ((unsigned int)(r) << SHIFT_16) | \
((unsigned int)(g) << SHIFT_8) | (unsigned int)(b))
/**
* @brief Packs ARGB channels into int
* @details Takes A, R, G, B char channels and packs them into a singular
* integer with the first 8 Bits reserved for alpha channel. See diagram at top
* for my thinking of starting bits
* @param[in] a The alpha channel stored as char and packed into int
* @param[in] r The red channel stored as char and packed into int
* @param[in] g The green channel stored as char and packed into int
* @param[in] b The blue channel stored as char and packed into int
*
* */
#define ENCODE_ARGB(a, r, g, b) \
(((unsigned int)(a) << SHIFT_24) | ((unsigned int)(r) << SHIFT_16) | \
((unsigned int)(g) << SHIFT_8) | (unsigned int)(b))
// #define ENCODE_BGRA(b, g, r, a) \
// (((unsigned int)(b) << SHIFT_24) | ((unsigned int)(g) << SHIFT_16) | \
// ((unsigned int)(r) << SHIFT_8) | (unsigned int)(a))
/**
* @brief Stops values exiting 0 - 255 range
* @details Takes in a value of X and checks if it is Above the Max of 255. If
* so, then set to Max. If not, then simply set back to whatever X was before.
* @param[in] x Color channel: char
* */
#define CLAMP_MAX(x) (((x) > MAX) ? MAX : (x))
/**
* @brief Stops values exiting 0 - 255 range
* @details Takes in a value of X and checks if it is Below 0. If so, then set
* to 0. If not, then simply set back to whatever X was before.
* @param[in] x Color channel: char
* */
#define CLAMP_MIN(x) (((x) < 0) ? 0 : (x))
/**
* @brief Contains values for PPM Image
* @details Can be defined with just a name and filled later with ppm_load
* as it stores information for header of file not the pixels of the image
* */
typedef struct
{
int width, height;
int len;
char* name;
char fmt;
int width; /**< Image width in pixels */
int height; /**< Image height in pixels */
int len; /**< Image length in pixels, width * height */
char* name; /**< File name and location, relative */
char fmt; /**< Raw or Binary values, P3 or P6 respectively*/
} PPM;
/**
* @brief Contains values for JPEG Image
* @details Can be defined with just a name and filled later with jpeg_load as
* it stores information for header of file not the pixels of the image
* */
typedef struct
{
int width, height;
int len;
char* name;
int width; /**< Image width in pixels */
int height; /**< Image height in pixels */
int len; /**< Image length in pixels, width * height */
char* name; /**< File name and location, relative */
} JPEG;
/**
* @brief Converts an int to long
* @details Takes in 32-Bit packed color and separates the 4 color values into a
* 64-Bit packed color for JPEG translations.
* @param[in] clr Takes a packed color, unsigned int
* @return unsigned long Packed color in 4 ints instead of one
* */
unsigned long
u32to_u64(const unsigned int clr);
/**
* @brief Converts a long to int
* @details Takes in a full packed color and compresses it back into 1 ints for
* ppm translations.
* @param[in] clr Takes a packed color, unsigned long
* @param[in] u64_div Takes a divisor to break down to raw color
* @return unsigned int Packed color in 1 int instead of 4
* */
unsigned int
u64to_u32(const unsigned long clr, const unsigned long u64_div);
/**
* Pretty Self Explanitory but prints the attributes of PPM images
* @brief Prints quick debug info of container
* @details Prints metadata like Name, Format, Width, Height and Length
* important for debugging errors
* @param[in] src Pointer to src metadata of a PPM image
* */
void __attribute__((overloadable)) print_attr(const PPM *src);
void __attribute__((overloadable))
print_attr(const PPM* src);
/**
* Pretty Self Explanitory but prints the attributes of JPEG images
* @brief Prints quick debug info of container
* @details Prints metadata like Name, Width, Height and Length
* important for debugging errors
* @param[in] src Pointer to src metadata of a JPEG image
* */
void __attribute__((overloadable)) print_attr(const JPEG *src);
void __attribute__((overloadable))
print_attr(const JPEG* src);
#endif
+5 -4
View File
@@ -65,7 +65,7 @@ ppm_load(const char* file, PPM* m_attr)
}
int
ppm_save(const unsigned int* buf, const PPM img)
ppm_save(const unsigned int* buf, const PPM img, char* name)
{
if (!buf)
{
@@ -82,12 +82,12 @@ ppm_save(const unsigned int* buf, const PPM img)
if (img.fmt == '3')
{
fptr = fopen(img.name, "w");
fptr = fopen(name, "w");
}
if (img.fmt == '6')
{
fptr = fopen(img.name, "wb");
fptr = fopen(name, "wb");
}
if (!fptr)
@@ -125,6 +125,7 @@ ppm_save(const unsigned int* buf, const PPM img)
fclose(fptr);
free(dst_buf);
printf("Encode Done!\n");
printf("Image: %s is saved.\n", name);
return 1;
}
@@ -209,7 +210,7 @@ transcode_to_ppm(JPEG* input, PPM* out)
out->width = input->width;
out->height = input->height;
out->len = out->width * out->height;
ppm_save(dst, *out);
ppm_save(dst, *out, out->name);
free(dst);
}
+19 -5
View File
@@ -1,4 +1,6 @@
#include <stdlib.h>
#include "image/filters.h"
#include "image/utils.h"
// #include "image/filters.h"
// #include "image/transformations.h"
@@ -7,16 +9,28 @@
int
main()
{
JPEG out_1 = {
.name = "../MF8jno.jpg",
// JPEG out_1 = {
// .name = "../MF8jno.jpg",
//
// };
PPM img = {
.name = "../IMG_1649.ppm",
};
};
unsigned int* buf = ppm_load(img.name, &img);
for (int i = 0; i < img.len; i++)
{
// you need to replace the old value with the new updated value
buf[i] = u32_grayscale(buf[i]);
}
ppm_save(buf, img, "../IMG_1649_new.ppm");
// PPM out_2 = inherit_from_jpeg(&out_1, '6');
//
//
PPM out = inherit_from_jpeg(&out_1, '6');
// print_attr(&out);
// 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, );