diff --git a/include/image/filters.h b/include/image/filters.h index 0229609..2078aa5 100644 --- a/include/image/filters.h +++ b/include/image/filters.h @@ -107,11 +107,11 @@ u32_mask(const unsigned int clr, const char keep); * it is just rotated back to original position. Cannot be greater than 8 * because the calculations would result in a negative. * @param[in] clr Packed Pixel - * @param[in] n Amount of times to move bits to left. + * @param[in] dist Distance from original position to move each bit to the left. * @return unsigned int Packed Pixel with newly moved bits */ unsigned int -u32_rotl(const unsigned int clr, const int n); +u32_rotl(const unsigned int clr, const int dist); /** * @brief Raises Color Vibrance @@ -139,13 +139,13 @@ u32_avg_gb(const unsigned int clr); * them. Then it moves to the next pixel doing the same. Then it does the second * loop from top to bottom doing the same principle. This can take some time * depending on hardware, image size, radius, etc. - * @param[in] src_buf The image buffer to be blurred - * @param[in] img the PPM image container + * @param[in] buf The image buffer to be blurred + * @param[in] metadata the PPM image container * @param[in] radius The amount of pixels around the left and right, then top * and bottom to mix with the currently selected pixel * @return unsigned int Pointer to new created image buffer. */ unsigned int* -u32_box_blur(const unsigned int* src_buf, const PPM* img, const int radius); +u32_box_blur(const unsigned int* buf, const PPM* metadata, const int radius); #endif diff --git a/include/image/imgio.h b/include/image/imgio.h index 732def5..809a6bc 100644 --- a/include/image/imgio.h +++ b/include/image/imgio.h @@ -5,67 +5,66 @@ /** * @brief Open and Fill buffer from .ppm file - * @param [in] file Char pointer use to locate the image to be modified lays. - * @param [in,out] m_attr PPM pointer to store image information + * @param [in] filename Location of the image to be modified + * @param [in,out] metadata PPM pointer to store image information */ unsigned int* -read_ppm(const char* file, PPM* m_attr); +read_ppm(const char* filename, PPM* metadata); /** * @brief Open and write buffer to file - * @param [in] buf Information of pixels - * @param [in] img PPM pointer to store image information - * @param [in] char Name/Location for file + * @param [in] buffer Information of pixels + * @param [in] metadata PPM pointer to store image information + * @param [in] filename Name/Location for file */ int -write_ppm(const unsigned int* buf, const PPM img, const char* name); +write_ppm(const unsigned int* buffer, const PPM metadata, const char* filename); /** * @brief Open and Fill buffer from .jpg file * @details Opens a .jpg file, creates a new buffer and extracts the pixels into * said buffer as integers. - * @param [in] file Char pointer use to locate the image to be modified lays. - * @param [in,out] m_attr JPEG pointer to store image information + * @param [in,out] metadata JPEG pointer to store image information */ unsigned int* -read_jpeg(JPEG* m_attr); +read_jpeg(JPEG* metadata); /** * @brief Open and write buffer to file * @param [in] buf Information of pixels - * @param [in] attr JPEG pointer to store image information - * @param [in] char Name/Location for file + * @param [in] metadata JPEG pointer to store image information + * @param [in] filename Name/Location for file */ int -write_jpeg(const unsigned int* src_buf, const JPEG* attr, const char* name); +write_jpeg(const unsigned int* buf, const JPEG* metadata, const char* filename); /** * @brief Converts PPM to JPEG - * @param [in] in Pointer to PPM container + * @param [in] location points to file to use */ void -transcode_to_jpeg(PPM* in); +transcode_to_jpeg(const char* location); /** * @brief Converts JPEG to PPM - * @param [in] in Pointer to JPEG container + * @param [in] location Pointer to JPEG container */ void -transcode_to_ppm(JPEG* in); +transcode_to_ppm(const char* location); /** * @brief Inherits the attributes from JPEG container - * @param [in] in Pointer to JPEG container + * @param [in] metadata Pointer to JPEG container * @param [in] fmt Character for type of PPM image, binary or raw */ PPM -inherit_from_jpeg(const JPEG* in, const char fmt); +inherit_from_jpeg(const JPEG* metadata, const char fmt); /** * @brief Inherits the attributes from PPM container - * @param [in] in Pointer to PPM container + * @param [in] metadata Pointer to PPM container */ JPEG -inherit_from_ppm(const PPM* in); +inherit_from_ppm(const PPM* metadata); #endif diff --git a/include/image/transformations.h b/include/image/transformations.h index 914ab3c..25cb8cd 100644 --- a/include/image/transformations.h +++ b/include/image/transformations.h @@ -38,6 +38,6 @@ u32_flip(const unsigned int* buf, const int width, const int height); * new buffer fails to create and is invalid * */ unsigned int* -u32_rotate(const unsigned int* buf, PPM* m_img); +u32_rotate(const unsigned int* buf, PPM* metadata); #endif diff --git a/include/image/utils.h b/include/image/utils.h index ba31113..77b6a1a 100644 --- a/include/image/utils.h +++ b/include/image/utils.h @@ -158,27 +158,27 @@ u64to_u32(const unsigned long clr, const unsigned long u64_div); * @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 + * @param[in] metadata Pointer to information of a PPM image */ void __attribute__((overloadable)) -print_attr(const PPM* src); +print_attr(const PPM* metadata); /** * @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 + * @param[in] metadata Pointer to information of a JPEG image */ void __attribute__((overloadable)) -print_attr(const JPEG* src); +print_attr(const JPEG* metadata); /** * @brief Finds start of extension in image name * @details Loops through the character array starting from the end to find the * start of the extension. - * @param[in] n Char array (str) + * @param[in] str Char array to loop through */ size_t -find_extension(const char* n); +find_extension(const char* str); #endif diff --git a/src/filters.c b/src/filters.c index 902d220..f87c209 100644 --- a/src/filters.c +++ b/src/filters.c @@ -27,9 +27,6 @@ u32_swap_rb(const unsigned int clr) unsigned int u32_grayscale(const unsigned int clr) { - unsigned int red = DECODE_R(clr); - unsigned int green = DECODE_G(clr); - unsigned int blue = DECODE_B(clr); /* * WHY: The colors use the REC 601 Standard: In layman's terms they are * weighed in how the human eye perceives color. So green is the largest @@ -37,8 +34,9 @@ u32_grayscale(const unsigned int clr) * The Shift_8 is to divide 256 to bring the color value back into range of 0 - 255 */ - unsigned int gray = - ((red * 77) + (green * 150) + (blue * 29)) >> SHIFT_8; + unsigned int gray = ((DECODE_R(clr) * 77) + (DECODE_G(clr) * 150) + + (DECODE_B(clr) * 29)) >> + SHIFT_8; return (clr & BYTE_A) | (gray << SHIFT_16) | (gray << SHIFT_8) | gray; } @@ -56,6 +54,7 @@ u32_step(const unsigned int clr, const unsigned char max) unsigned int u32_brighten(const unsigned int clr, const float factor) { + // NOTE: keep definition for readability unsigned int red = CLAMP_MAX(DECODE_R(clr) * factor); unsigned int green = CLAMP_MAX(DECODE_G(clr) * factor); unsigned int blue = CLAMP_MAX(DECODE_B(clr) * factor); @@ -65,6 +64,7 @@ u32_brighten(const unsigned int clr, const float factor) unsigned int u32_mix(const unsigned int clr_a, const unsigned int clr_b) { + // NOTE: keep definition for readability unsigned char blue = (DECODE_B(clr_a) + DECODE_B(clr_b)) / 2; unsigned char green = (DECODE_G(clr_a) + DECODE_G(clr_b)) / 2; unsigned char red = (DECODE_R(clr_a) + DECODE_R(clr_b)) / 2; @@ -81,6 +81,7 @@ u32_lerp(const unsigned int clr_a, const unsigned int clr_b, const float ratio) * because they are whole number pixels. So JPEG are better because the * numbers result in floating point colors. * */ + // NOTE: keep definition for readability unsigned char blue = ((DECODE_B(clr_a) * (1 - ratio)) + ((DECODE_B(clr_b) * ratio))); unsigned char green = @@ -112,9 +113,9 @@ u32_mask(const unsigned int clr, const char keep) } unsigned int -u32_rotl(const unsigned int clr, const int n) +u32_rotl(const unsigned int clr, const int dist) { - if (n > 8) + if (dist > 8) { LOGERROR(ERR_INVALID_SIZE); return ERR_INVALID_SIZE; @@ -148,15 +149,16 @@ u32_rotl(const unsigned int clr, const int n) * the pixels being the same as they are just rotated back to their * original spot. * */ - red = ((red << n) | (red >> (SHIFT_8 - n))) & BYTE; - green = ((green << n) | (green >> (SHIFT_8 - n))) & BYTE; - blue = ((blue << n) | (blue >> (SHIFT_8 - n))) & BYTE; + red = ((red << dist) | (red >> (SHIFT_8 - dist))) & BYTE; + green = ((green << dist) | (green >> (SHIFT_8 - dist))) & BYTE; + blue = ((blue << dist) | (blue >> (SHIFT_8 - dist))) & BYTE; return ENCODE_RGB(red, green, blue); } unsigned int u32_contrast(const unsigned int clr, const float factor) { + // NOTE: keep definition for readability int red = CLAMP_MIN(CLAMP_MAX( (int)(factor * (float)(int)(DECODE_R(clr) - HALF_MAX)) + HALF_MAX)); int green = CLAMP_MIN(CLAMP_MAX( @@ -255,38 +257,38 @@ blur_row(const unsigned int* src, const int x, const int y, const PPM* img, } unsigned int* -u32_box_blur(const unsigned int* src_buf, const PPM* img, const int radius) +u32_box_blur(const unsigned int* buf, const PPM* metadata, const int radius) { - unsigned int* first_pass = malloc(img->len * sizeof(unsigned int)); - if (!first_pass) + unsigned int* col_buf = malloc(metadata->len * sizeof(unsigned int)); + if (!col_buf) { LOGERROR(ERR_BUF_NULL); return NULL; } - unsigned int* dst_buf = malloc(img->len * sizeof(unsigned int)); + unsigned int* dst_buf = malloc(metadata->len * sizeof(unsigned int)); if (!dst_buf) { - free(first_pass); + free(col_buf); LOGERROR(ERR_BUF_NULL); return NULL; } - for (int y = 0; y < img->height; y++) + for (int y = 0; y < metadata->height; y++) { - for (int x = 0; x < img->width; x++) + for (int x = 0; x < metadata->width; x++) { - first_pass[y * img->width + x] = - blur_col(src_buf, x, y, img, radius); + col_buf[y * metadata->width + x] = + blur_col(buf, x, y, metadata, radius); } } - for (int y = 0; y < img->height; y++) + for (int y = 0; y < metadata->height; y++) { - for (int x = 0; x < img->width; x++) + for (int x = 0; x < metadata->width; x++) { - dst_buf[y * img->width + x] = - blur_row(first_pass, x, y, img, radius); + dst_buf[y * metadata->width + x] = + blur_row(col_buf, x, y, metadata, radius); } } - free(first_pass); - free((void*)src_buf); + free(col_buf); + free((void*)buf); return dst_buf; } diff --git a/src/imgio.c b/src/imgio.c index 82c2d50..674170d 100644 --- a/src/imgio.c +++ b/src/imgio.c @@ -8,52 +8,52 @@ #include "image/utils.h" unsigned int* -read_ppm(const char* file, PPM* m_attr) +read_ppm(const char* filename, PPM* metadata) { LOG("Decoding"); unsigned char red, green, blue; char fmt[3]; int max_val; FILE* fptr; - fptr = fopen(file, "r"); + fptr = fopen(filename, "r"); if (!fptr) { LOGERROR(ERR_IMG_NAME_INVALID); - LOG(file); + LOG(filename); return NULL; } fscanf(fptr, "%s", fmt); - m_attr->fmt = fmt[1]; - fscanf(fptr, "%d %d", &m_attr->width, &m_attr->height); - m_attr->len = m_attr->width * m_attr->height; + metadata->fmt = fmt[1]; + fscanf(fptr, "%d %d", &metadata->width, &metadata->height); + metadata->len = metadata->width * metadata->height; fscanf(fptr, "%d", &max_val); fgetc(fptr); - unsigned char* img_buf = malloc(m_attr->len * 3); + unsigned char* img_buf = malloc(metadata->len * 3); if (!img_buf) { LOGERROR(ERR_BUF_NULL); return NULL; } - unsigned int* clr_buf = malloc(m_attr->len * sizeof(unsigned int)); + unsigned int* clr_buf = malloc(metadata->len * sizeof(unsigned int)); if (!clr_buf) { free(img_buf); LOGERROR(ERR_BUF_NULL); return NULL; } - if (m_attr->fmt == '3') + if (metadata->fmt == '3') { - for (int i = 0; i < m_attr->len; i++) + for (int i = 0; i < metadata->len; i++) { fscanf(fptr, "%hhu %hhu %hhu", &red, &green, &blue); clr_buf[i] = ENCODE_RGB(red, green, blue); } } - else if (m_attr->fmt == '6') + else if (metadata->fmt == '6') { - fread(img_buf, 3, m_attr->len, fptr); + fread(img_buf, 3, metadata->len, fptr); - for (int i = 0; i < m_attr->len; i++) + for (int i = 0; i < metadata->len; i++) { red = img_buf[i * 3]; green = img_buf[i * 3 + 1]; @@ -69,14 +69,14 @@ read_ppm(const char* file, PPM* m_attr) } int -write_ppm(const unsigned int* buf, const PPM img, const char* name) +write_ppm(const unsigned int* buf, const PPM metadata, const char* filename) { if (!buf) { LOGERROR(ERR_BUF_NULL); return ERR_BUF_NULL; } - unsigned char* dst_buf = malloc(img.len * 3); + unsigned char* dst_buf = malloc(metadata.len * 3); if (!dst_buf) { LOGERROR(ERR_BUF_NULL); @@ -85,14 +85,14 @@ write_ppm(const unsigned int* buf, const PPM img, const char* name) LOG("Encoding"); FILE* fptr; - if (img.fmt == '3') + if (metadata.fmt == '3') { - fptr = fopen(name, "w"); + fptr = fopen(filename, "w"); } - if (img.fmt == '6') + if (metadata.fmt == '6') { - fptr = fopen(name, "wb"); + fptr = fopen(filename, "wb"); } if (!fptr) @@ -102,10 +102,11 @@ write_ppm(const unsigned int* buf, const PPM img, const char* name) return ERR_FILE_NULL; } - fprintf(fptr, "P%c\n%d %d\n255\n", img.fmt, img.width, img.height); - if (img.fmt == '3') + fprintf(fptr, "P%c\n%d %d\n255\n", metadata.fmt, metadata.width, + metadata.height); + if (metadata.fmt == '3') { - for (int i = 0; i < img.len; i++) + for (int i = 0; i < metadata.len; i++) { fprintf(fptr, "%d %d %d ", DECODE_R(buf[i]), DECODE_G(buf[i]), DECODE_B(buf[i])); @@ -116,15 +117,15 @@ write_ppm(const unsigned int* buf, const PPM img, const char* name) } } - if (img.fmt == '6') + if (metadata.fmt == '6') { - for (int i = 0; i < img.len; i++) + for (int i = 0; i < metadata.len; i++) { dst_buf[i * 3] = DECODE_R(buf[i]); dst_buf[i * 3 + 1] = DECODE_G(buf[i]); dst_buf[i * 3 + 2] = DECODE_B(buf[i]); } - fwrite(dst_buf, 1, img.len * 3, fptr); + fwrite(dst_buf, 1, metadata.len * 3, fptr); } fclose(fptr); free(dst_buf); @@ -133,41 +134,41 @@ write_ppm(const unsigned int* buf, const PPM img, const char* name) } unsigned int* -read_jpeg(JPEG* m_attr) +read_jpeg(JPEG* metadata) { LOG("Decoding"); tjhandle tjdecompress = tj3Init(TJINIT_DECOMPRESS); unsigned char* jpeg_buf = NULL; - FILE* infile = fopen(m_attr->name, "rb"); + FILE* infile = fopen(metadata->name, "rb"); if (!infile) { LOGERROR(ERR_FILE_NULL); return NULL; } fseek(infile, 0, SEEK_END); - m_attr->len = ftell(infile); + metadata->len = ftell(infile); fseek(infile, 0, SEEK_SET); - jpeg_buf = (unsigned char*)malloc(m_attr->len); - fread(jpeg_buf, 1, m_attr->len, infile); + jpeg_buf = (unsigned char*)malloc(metadata->len); + fread(jpeg_buf, 1, metadata->len, infile); fclose(infile); - if (tj3DecompressHeader(tjdecompress, jpeg_buf, m_attr->len) < 0) + if (tj3DecompressHeader(tjdecompress, jpeg_buf, metadata->len) < 0) { LOGERROR(ERR_JHEADER); LOG(tj3GetErrorStr(tjdecompress)); free(jpeg_buf); return NULL; } - m_attr->width = tj3Get(tjdecompress, TJPARAM_JPEGWIDTH); - m_attr->height = tj3Get(tjdecompress, TJPARAM_JPEGHEIGHT); - m_attr->len = m_attr->width * m_attr->height; + metadata->width = tj3Get(tjdecompress, TJPARAM_JPEGWIDTH); + metadata->height = tj3Get(tjdecompress, TJPARAM_JPEGHEIGHT); + metadata->len = metadata->width * metadata->height; unsigned int* pixels = - malloc(m_attr->width * m_attr->height * sizeof(unsigned int)); + malloc(metadata->width * metadata->height * sizeof(unsigned int)); if (!pixels) { LOGERROR(ERR_BUF_NULL); return NULL; } - tj3Decompress8(tjdecompress, jpeg_buf, m_attr->len, + tj3Decompress8(tjdecompress, jpeg_buf, metadata->len, (unsigned char*)pixels, 0, TJPF_BGRA); tj3Destroy(tjdecompress); free(jpeg_buf); @@ -176,7 +177,7 @@ read_jpeg(JPEG* m_attr) } int -write_jpeg(const unsigned int* src_buf, const JPEG* attr, const char* name) +write_jpeg(const unsigned int* buf, const JPEG* metadata, const char* filename) { LOG("Encoding"); tjhandle tjcompress = tj3Init(TJINIT_COMPRESS); @@ -184,21 +185,21 @@ write_jpeg(const unsigned int* src_buf, const JPEG* attr, const char* name) size_t dst_size = 0; tj3Set(tjcompress, TJPARAM_QUALITY, 80); tj3Set(tjcompress, TJPARAM_SUBSAMP, TJSAMP_420); - if (tj3Compress8(tjcompress, (unsigned char*)src_buf, attr->width, 0, - attr->height, TJPF_BGRA, &dst_buf, &dst_size) < 0) + if (tj3Compress8(tjcompress, (unsigned char*)buf, metadata->width, 0, + metadata->height, TJPF_BGRA, &dst_buf, &dst_size) < 0) { LOGERROR(ERR_JHEADER); LOG(tj3GetErrorStr(tjcompress)); return ERR_JHEADER; } - FILE* fptr = fopen(name, "wb"); + FILE* fptr = fopen(filename, "wb"); if (!fptr) { tj3Free(dst_buf); LOGERROR(ERR_FILE_NULL); return ERR_FILE_NULL; } - if (dst_buf == NULL) + if (!dst_buf) { tj3Free(dst_buf); LOGERROR(ERR_BUF_NULL); @@ -220,115 +221,108 @@ write_jpeg(const unsigned int* src_buf, const JPEG* attr, const char* name) } void -transcode_to_jpeg(PPM* in) +transcode_to_jpeg(const char* location) { - size_t length = find_extension(in->name); - char str2[length]; + JPEG dst; + PPM src; + if (!location) + { + LOGERROR(ERR_IMG_NAME_INVALID); + return; + } + size_t length = find_extension(location); + char stem[length]; for (int i = 0; i < length; i++) { - str2[i] = in->name[i]; + stem[i] = location[i]; } - char* str3 = ".jpg"; - char* result = malloc(strlen(str2) + strlen(str3) + 1); - if (result != NULL) - { - strcat(result, str2); - strcat(result, str3); - } - else + char* ext = ".jpg"; + char* result = malloc(strlen(stem) + strlen(ext) + 1); + if (!result) { LOGERROR(ERR_MALLOC_NULL); return; } - JPEG img; - if (!in) - { - LOGERROR(ERR_IMG_NULL); - return; - } - unsigned int* dst = read_ppm(in->name, in); - if (!dst) + strcat(result, stem); + strcat(result, ext); + unsigned int* dst_buf = read_ppm(location, &src); + if (!dst_buf) { LOGERROR(ERR_BUF_NULL); return; } - img.width = in->width; - img.height = in->height; - write_jpeg(dst, &img, result); - free(dst); + dst = inherit_from_ppm(&src); + write_jpeg(dst_buf, &dst, result); + free(dst_buf); free(result); } void -transcode_to_ppm(JPEG* in) +transcode_to_ppm(const char* location) { - size_t length = find_extension(in->name); + JPEG src; + PPM dst; + if (!location) + { + LOGERROR(ERR_IMG_NAME_INVALID); + return; + } + src.name = (void*)location; + size_t length = find_extension(location); char str2[length]; for (int i = 0; i < length; i++) { - str2[i] = in->name[i]; + str2[i] = location[i]; } char* str3 = ".ppm"; char* result = malloc(strlen(str2) + strlen(str3) + 1); - if (result != NULL) - { - strcat(result, str2); - strcat(result, str3); - } - else + if (!result) { LOGERROR(ERR_MALLOC_NULL); return; } - PPM img; - if (!in) - { - LOGERROR(ERR_IMG_NULL); - return; - } - unsigned int* dst = read_jpeg(in); - if (!dst) + strcat(result, str2); + strcat(result, str3); + unsigned int* dst_buf = read_jpeg(&src); + if (!dst_buf) { LOGERROR(ERR_BUF_NULL); return; } - img.width = in->width; - img.height = in->height; - img.len = img.width * img.height; - write_ppm(dst, img, result); - free(dst); + + dst = inherit_from_jpeg(&src, '6'); + write_ppm(dst_buf, dst, result); free(result); + free(dst_buf); } PPM -inherit_from_jpeg(const JPEG* in, const char fmt) +inherit_from_jpeg(const JPEG* metadata, const char fmt) { - PPM img; - if (!in) + PPM image; + if (!metadata) { LOGERROR(ERR_IMG_NULL); - return img; + return image; } - PPM image = { .width = in->width, - .height = in->height, - .len = in->len, - .fmt = fmt }; + image.width = metadata->width; + image.height = metadata->height; + image.len = metadata->len; + image.fmt = fmt; return image; } JPEG -inherit_from_ppm(const PPM* in) +inherit_from_ppm(const PPM* metadata) { - JPEG blank; - if (!in) + JPEG image; + if (!metadata) { LOGERROR(ERR_IMG_NULL); - return blank; + return image; } - JPEG image = { - .width = in->width, - .height = in->height, - .len = in->len, - }; + image.width = metadata->width; + image.height = metadata->height; + image.len = metadata->len; return image; } diff --git a/src/main.c b/src/main.c index 7ce3aa8..66809a4 100644 --- a/src/main.c +++ b/src/main.c @@ -18,9 +18,8 @@ int main() { - PPM img; - img.name = "../assets/IMG_1649_new.ppm"; - transcode_to_jpeg(&img); + char img[] = "../assets/IMG_1649_new.ppm"; + transcode_to_jpeg(img); return 0; } diff --git a/src/transformations.c b/src/transformations.c index 96dd1c5..a64ad22 100644 --- a/src/transformations.c +++ b/src/transformations.c @@ -8,19 +8,20 @@ unsigned int* u32_flop(const unsigned int* buf, const int width, const int height) { + int len, idx; if (!buf) { LOGERROR(ERR_BUF_NULL); return NULL; } - int len = width * height; + len = width * height; unsigned int* flip = malloc(len * sizeof(unsigned int)); if (!flip) { LOGERROR(ERR_CREATION_FAIL); return NULL; } - int idx = 0; + idx = 0; for (int i = 0; i < height; i++) { for (int k = width - 1; k >= 0; k--) @@ -37,12 +38,13 @@ u32_flop(const unsigned int* buf, const int width, const int height) unsigned int* u32_flip(const unsigned int* buf, const int width, const int height) { + int len, idx; if (!buf) { LOGERROR(ERR_BUF_NULL); return NULL; } - int len = width * height; + len = width * height; unsigned int* flip = malloc(len * sizeof(unsigned int)); if (!flip) { @@ -50,7 +52,7 @@ u32_flip(const unsigned int* buf, const int width, const int height) return NULL; } - int idx = 0; + idx = 0; for (int i = height - 1; i >= 0; i--) { for (int k = 0; k < width; k++) @@ -65,26 +67,26 @@ u32_flip(const unsigned int* buf, const int width, const int height) } unsigned int* -u32_rotate(const unsigned int* buf, PPM* m_img) +u32_rotate(const unsigned int* buf, PPM* metadata) { if (!buf) { LOGERROR(ERR_BUF_NULL); return NULL; } - if (!m_img) + if (!metadata) { LOGERROR(ERR_IMG_NULL); return NULL; } - unsigned int* mask = malloc(m_img->len * sizeof(unsigned int)); + unsigned int* mask = malloc(metadata->len * sizeof(unsigned int)); if (!mask) { LOGERROR(ERR_BUF_NULL); return NULL; } - int old_width = m_img->width; - int old_height = m_img->height; + int old_width = metadata->width; + int old_height = metadata->height; for (int row = 0; row < old_height; row++) { for (int col = 0; col < old_width; col++) @@ -96,8 +98,8 @@ u32_rotate(const unsigned int* buf, PPM* m_img) buf[(row * old_width) + col]; } } - m_img->width = old_height; - m_img->height = old_width; + metadata->width = old_height; + metadata->height = old_width; free((void*)buf); return mask; } diff --git a/src/utils.c b/src/utils.c index 5d4c227..129db28 100644 --- a/src/utils.c +++ b/src/utils.c @@ -37,26 +37,27 @@ u64to_u32(const unsigned long clr, const unsigned long u64_div) } void __attribute__((overloadable)) -print_attr(const PPM* src) +print_attr(const PPM* metadata) { printf("Name: %s\nFMT: %c\nWidth: %i, Height: %i\nLength: %i\n", - src->name, src->fmt, src->width, src->height, src->len); + metadata->name, metadata->fmt, metadata->width, metadata->height, + metadata->len); } void __attribute__((overloadable)) -print_attr(const JPEG* src) +print_attr(const JPEG* metadata) { - printf("Name: %s\nWidth: %i, Height: %i\nLength: %i\n", src->name, - src->width, src->height, src->len); + printf("Name: %s\nWidth: %i, Height: %i\nLength: %i\n", metadata->name, + metadata->width, metadata->height, metadata->len); } size_t -find_extension(const char* n) +find_extension(const char* str) { - size_t length = strlen(n); + size_t length = strlen(str); for (int i = length; i >= 0; i--) { - if (n[i] == '.') + if (str[i] == '.') { return i; }