From 39911cd662ed671f7d6659162f261ac9e451c2ae Mon Sep 17 00:00:00 2001 From: Andrew Haynes Date: Wed, 9 Sep 2026 17:26:02 -0400 Subject: [PATCH] REFACTOR: I forgot to actually change the function logic after rename; The functions take in {width,height} to use instead of PPM image containers. The function only pulled len, width and height so I just imported them instead for all image types to be used. --- include/image/transformations.h | 4 ++-- src/transformations.c | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/include/image/transformations.h b/include/image/transformations.h index 15f5070..914ab3c 100644 --- a/include/image/transformations.h +++ b/include/image/transformations.h @@ -13,7 +13,7 @@ * @retval NULL If original buffer is invalid or if new buffer fails to create * */ unsigned int* -u32_flop(const unsigned int* buf, const PPM img); +u32_flop(const unsigned int* buf, const int width, const int height); /** * @brief Flips image on Y-Axis @@ -25,7 +25,7 @@ u32_flop(const unsigned int* buf, const PPM img); * @retval NULL If original buffer is invalid or if new buffer fails to create * */ unsigned int* -ppm_flip(const unsigned int* buf, const PPM img); +u32_flip(const unsigned int* buf, const int width, const int height); /** * @brief Rotates image on 90 Clockwise diff --git a/src/transformations.c b/src/transformations.c index fa42212..96dd1c5 100644 --- a/src/transformations.c +++ b/src/transformations.c @@ -6,25 +6,26 @@ #include "image/utils.h" unsigned int* -u32_flop(const unsigned int* buf, const PPM img) +u32_flop(const unsigned int* buf, const int width, const int height) { if (!buf) { LOGERROR(ERR_BUF_NULL); return NULL; } - unsigned int* flip = malloc(img.len * sizeof(unsigned int)); + int len = width * height; + unsigned int* flip = malloc(len * sizeof(unsigned int)); if (!flip) { LOGERROR(ERR_CREATION_FAIL); return NULL; } int idx = 0; - for (int i = 0; i < img.height; i++) + for (int i = 0; i < height; i++) { - for (int k = img.width - 1; k >= 0; k--) + for (int k = width - 1; k >= 0; k--) { - flip[idx] = buf[(i * img.width) + k]; + flip[idx] = buf[(i * width) + k]; idx++; } } @@ -34,14 +35,15 @@ u32_flop(const unsigned int* buf, const PPM img) } unsigned int* -u32_flip(const unsigned int* buf, const PPM img) +u32_flip(const unsigned int* buf, const int width, const int height) { if (!buf) { LOGERROR(ERR_BUF_NULL); return NULL; } - unsigned int* flip = malloc(img.len * sizeof(unsigned int)); + int len = width * height; + unsigned int* flip = malloc(len * sizeof(unsigned int)); if (!flip) { LOGERROR(ERR_FILE_NULL); @@ -49,11 +51,11 @@ u32_flip(const unsigned int* buf, const PPM img) } int idx = 0; - for (int i = img.height - 1; i >= 0; i--) + for (int i = height - 1; i >= 0; i--) { - for (int k = 0; k < img.width; k++) + for (int k = 0; k < width; k++) { - flip[idx] = buf[(i * img.width) + k]; + flip[idx] = buf[(i * width) + k]; idx++; } }