From 6bbca9ef319d5e19ba3a4661d7f2a9447e28a1bb Mon Sep 17 00:00:00 2001 From: Ilya Verbin Date: Mon, 23 Aug 2021 00:42:20 +0300 Subject: [PATCH] [Makefile] Switch to clang on macOS and fix warnings --- Makefile | 3 +-- histogram.h | 5 +---- lab1_2/lab1_2.c | 6 +++--- lab1_3/lab1_3.c | 6 +++--- lab1_4/lab1_4.c | 6 +++--- lab1_5/lab1_5.c | 4 ++-- lab1_6/lab1_6.c | 4 ++-- lab1_7/lab1_7.c | 4 ++-- lab2_1/lab2_1.c | 2 +- lab2_2/lab2_2.c | 2 +- lab3/lab3.c | 6 +++--- lab4_1/lab4_1.c | 8 ++++---- lab4_2/lab4_2.c | 10 +++++----- lab4_3/lab4_3.c | 2 +- lab5/lab5.c | 2 +- lab6/lab6.c | 2 +- lab7/lab7.c | 4 ++-- png_wrapper.h | 5 +---- 18 files changed, 37 insertions(+), 44 deletions(-) diff --git a/Makefile b/Makefile index f6a5168..b2d0a53 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,7 @@ -CC = gcc IDIR = /opt/local/include/libpng16/ LDIR = /opt/local/lib/ LIBS = -lc -lpng16 -CFLAGS = -Wall -march=native -Ofast -Wa,-q +CFLAGS = -Wall -Wextra -Werror -O0 -g OUT_DIR = build LABS = lab1_1 lab1_2 lab1_3 lab1_4 lab1_5 lab1_6 lab1_7 lab1_8 lab2_1 lab2_2 lab3 lab4_1 lab4_2 lab4_3 lab5 lab6 lab7 BINS = $(addprefix $(OUT_DIR)/,${LABS}) diff --git a/histogram.h b/histogram.h index d4a1eda..b664310 100644 --- a/histogram.h +++ b/histogram.h @@ -1,5 +1,4 @@ -#ifndef HISTOGRAM_H -#define HISTOGRAM_H +#pragma once #include #include "png_wrapper.h" @@ -7,5 +6,3 @@ enum { HIST_WIDTH = 512, HIST_HEIGHT = 256, MAX_COLOR = 255 }; void histogram(struct Image in, struct Image out); - -#endif diff --git a/lab1_2/lab1_2.c b/lab1_2/lab1_2.c index df9071e..94c1d85 100644 --- a/lab1_2/lab1_2.c +++ b/lab1_2/lab1_2.c @@ -2,7 +2,7 @@ #include #include "png_wrapper.h" -static inline void add_sat(struct Image img, int x, int y, double a) +static inline void add_sat(struct Image img, size_t x, size_t y, double a) { if (x < 0 || y < 0 || x >= img.width || y >= img.height) return; @@ -19,8 +19,8 @@ static inline void add_sat(struct Image img, int x, int y, double a) static void process_image(struct Image img) { - for (int y = 0; y < img.height; y++) - for (int x = 0; x < img.width; x++) + for (size_t y = 0; y < img.height; y++) + for (size_t x = 0; x < img.width; x++) { unsigned char old_val = img.pixels[y][x]; unsigned char new_val = (old_val / 128) * 255; diff --git a/lab1_3/lab1_3.c b/lab1_3/lab1_3.c index f5bceff..5d6ab60 100644 --- a/lab1_3/lab1_3.c +++ b/lab1_3/lab1_3.c @@ -2,7 +2,7 @@ #include #include "png_wrapper.h" -static inline void add_sat(struct Image img, int x, int y, double a) +static inline void add_sat(struct Image img, size_t x, size_t y, double a) { if (x < 0 || y < 0 || x >= img.width || y >= img.height) return; @@ -19,8 +19,8 @@ static inline void add_sat(struct Image img, int x, int y, double a) static void process_image(struct Image img) { - for (int y = 0; y < img.height; y++) - for (int x = 0; x < img.width; x++) + for (size_t y = 0; y < img.height; y++) + for (size_t x = 0; x < img.width; x++) { unsigned char old_val = img.pixels[y][x]; unsigned char new_val = (old_val / 128) * 255; diff --git a/lab1_4/lab1_4.c b/lab1_4/lab1_4.c index c05bae3..ee13544 100644 --- a/lab1_4/lab1_4.c +++ b/lab1_4/lab1_4.c @@ -2,7 +2,7 @@ #include #include "png_wrapper.h" -static inline void add_sat(struct Image img, int x, int y, double a) +static inline void add_sat(struct Image img, size_t x, size_t y, double a) { if (x < 0 || y < 0 || x >= img.width || y >= img.height) return; @@ -19,8 +19,8 @@ static inline void add_sat(struct Image img, int x, int y, double a) static void process_image(struct Image img) { - for (int y = 0; y < img.height; y++) - for (int x = 0; x < img.width; x++) + for (size_t y = 0; y < img.height; y++) + for (size_t x = 0; x < img.width; x++) { unsigned char old_val = img.pixels[y][x]; unsigned char new_val = (old_val / 128) * 255; diff --git a/lab1_5/lab1_5.c b/lab1_5/lab1_5.c index 46644f1..998789f 100644 --- a/lab1_5/lab1_5.c +++ b/lab1_5/lab1_5.c @@ -26,8 +26,8 @@ static void process_image(struct Image img) for (int x = 0; x < N; x++) T[y][x] = 255 * (M44[y][x] + 0.5) / (N * N); - for (int y = 0; y < img.height; y++) - for (int x = 0; x < img.width; x++) + for (size_t y = 0; y < img.height; y++) + for (size_t x = 0; x < img.width; x++) img.pixels[y][x] = img.pixels[y][x] > T[y % N][x % N] ? 255 : 0; } diff --git a/lab1_6/lab1_6.c b/lab1_6/lab1_6.c index 7da2639..4f47acc 100644 --- a/lab1_6/lab1_6.c +++ b/lab1_6/lab1_6.c @@ -13,8 +13,8 @@ static int rnd(int a) static void process_image(struct Image img, unsigned char threshold, unsigned char noise) { - for (int y = 0; y < img.height; y++) - for (int x = 0; x < img.width; x++) + for (size_t y = 0; y < img.height; y++) + for (size_t x = 0; x < img.width; x++) { int new = img.pixels[y][x] + rnd(noise); img.pixels[y][x] = new >= threshold ? 255 : 0; diff --git a/lab1_7/lab1_7.c b/lab1_7/lab1_7.c index 6abf125..e3467cd 100644 --- a/lab1_7/lab1_7.c +++ b/lab1_7/lab1_7.c @@ -21,8 +21,8 @@ static void process_image(struct Image img) for (int x = 0; x < N; x++) T[y][x] = 255 * (M[y][x] + 0.5) / (N * N); - for (int y = 0; y < img.height; y++) - for (int x = 0; x < img.width; x++) + for (size_t y = 0; y < img.height; y++) + for (size_t x = 0; x < img.width; x++) img.pixels[y][x] = img.pixels[y][x] > T[y % N][x % N] ? 255 : 0; } diff --git a/lab2_1/lab2_1.c b/lab2_1/lab2_1.c index 5cdd8d7..5bf3368 100644 --- a/lab2_1/lab2_1.c +++ b/lab2_1/lab2_1.c @@ -47,7 +47,7 @@ int main(int argc, char * const argv[]) printf("Input file \"%s\" opened (width = %u, height = %u)\n", input_filename, in.width, in.height); - struct Image out = { in.width * N + 0.5, in.height * N + 0.5 }; + struct Image out = { in.width * N + 0.5, in.height * N + 0.5, NULL }; alloc_pixels(&out); process_image(in, out, N); diff --git a/lab2_2/lab2_2.c b/lab2_2/lab2_2.c index b1ebb1d..11f83b1 100644 --- a/lab2_2/lab2_2.c +++ b/lab2_2/lab2_2.c @@ -62,7 +62,7 @@ int main(int argc, char * const argv[]) printf("Input file \"%s\" opened (width = %u, height = %u)\n", input_filename, in.width, in.height); - struct Image out = { in.width * N + 0.5, in.height * N + 0.5 }; + struct Image out = { in.width * N + 0.5, in.height * N + 0.5, NULL }; alloc_pixels(&out); process_image(in, out, N); diff --git a/lab3/lab3.c b/lab3/lab3.c index a00bc90..2cbfce9 100644 --- a/lab3/lab3.c +++ b/lab3/lab3.c @@ -5,8 +5,8 @@ static void process_images(struct Image top, struct Image bot, struct Image alpha, struct Image out) { - for (int y = 0; y < out.height; y++) - for (int x = 0; x < out.width; x++) + for (size_t y = 0; y < out.height; y++) + for (size_t x = 0; x < out.width; x++) { double a = alpha.pixels[y][x] / 255.0; @@ -50,7 +50,7 @@ int main(int argc, char * const argv[]) printf("Alpha channel input file \"%s\" opened (width = %u, height = %u)\n", input3_filename, in3.width, in3.height); - struct Image out = { in1.width, in2.height }; + struct Image out = { in1.width, in2.height, NULL }; alloc_pixels(&out); process_images(in1, in2, in3, out); diff --git a/lab4_1/lab4_1.c b/lab4_1/lab4_1.c index 28b781a..a49092b 100644 --- a/lab4_1/lab4_1.c +++ b/lab4_1/lab4_1.c @@ -6,8 +6,8 @@ static void process_image(struct Image img, double c, double gamma) { - for (int y = 0; y < img.height; y++) - for (int x = 0; x < img.width; x++) + for (size_t y = 0; y < img.height; y++) + for (size_t x = 0; x < img.width; x++) { double in = img.pixels[y][x] / 255.0; int out = c * pow(in, gamma) * 255.0 + 0.5; @@ -41,7 +41,7 @@ int main(int argc, char * const argv[]) printf("Input file \"%s\" opened (width = %u, height = %u)\n", input_filename, img.width, img.height); - struct Image hist1 = { HIST_WIDTH, HIST_HEIGHT }; + struct Image hist1 = { HIST_WIDTH, HIST_HEIGHT, NULL }; alloc_pixels(&hist1); histogram(img, hist1); write_grayscale_png(hist1, hist1_filename); @@ -49,7 +49,7 @@ int main(int argc, char * const argv[]) process_image(img, c, gamma); - struct Image hist2 = { HIST_WIDTH, HIST_HEIGHT }; + struct Image hist2 = { HIST_WIDTH, HIST_HEIGHT, NULL }; alloc_pixels(&hist2); histogram(img, hist2); write_grayscale_png(hist2, hist2_filename); diff --git a/lab4_2/lab4_2.c b/lab4_2/lab4_2.c index d844ad9..7fcc63c 100644 --- a/lab4_2/lab4_2.c +++ b/lab4_2/lab4_2.c @@ -14,7 +14,7 @@ void precalculate(unsigned char *lut, size_t s1, size_t s2) lut[c] = MAX_COLOR; } -static void process_image(struct Image in, struct Image out, int delta) +static void process_image(struct Image in, struct Image out, size_t delta) { size_t pixels_count[MAX_COLOR + 1] = { }; @@ -22,7 +22,7 @@ static void process_image(struct Image in, struct Image out, int delta) for (size_t x = 0; x < in.width; x++) pixels_count[in.pixels[y][x]]++; - int s1, s2; + size_t s1, s2; for (s1 = 0; (pixels_count[s1] <= delta) && (s1 <= MAX_COLOR); s1++); @@ -56,19 +56,19 @@ int main(int argc, char * const argv[]) printf("Input file \"%s\" opened (width = %u, height = %u)\n", input_filename, in.width, in.height); - struct Image hist1 = { HIST_WIDTH, HIST_HEIGHT }; + struct Image hist1 = { HIST_WIDTH, HIST_HEIGHT, NULL }; alloc_pixels(&hist1); histogram(in, hist1); write_grayscale_png(hist1, hist1_filename); free_pixels(hist1); - struct Image out = { in.width, in.height }; + struct Image out = { in.width, in.height, NULL }; alloc_pixels(&out); process_image(in, out, delta); free_pixels(in); write_grayscale_png(out, output_filename); - struct Image hist2 = { HIST_WIDTH, HIST_HEIGHT }; + struct Image hist2 = { HIST_WIDTH, HIST_HEIGHT, NULL }; alloc_pixels(&hist2); histogram(out, hist2); free_pixels(out); diff --git a/lab4_3/lab4_3.c b/lab4_3/lab4_3.c index cbc6cfd..73a8220 100644 --- a/lab4_3/lab4_3.c +++ b/lab4_3/lab4_3.c @@ -43,7 +43,7 @@ int main(int argc, char * const argv[]) printf("Input file \"%s\" opened (width = %u, height = %u)\n", input_filename, img.width, img.height); - struct Image hist = { HIST_WIDTH, HIST_HEIGHT }; + struct Image hist = { HIST_WIDTH, HIST_HEIGHT, NULL }; alloc_pixels(&hist); histogram(img, hist); write_grayscale_png(hist, hist1_filename); diff --git a/lab5/lab5.c b/lab5/lab5.c index 153b110..893dccd 100644 --- a/lab5/lab5.c +++ b/lab5/lab5.c @@ -85,7 +85,7 @@ int main(int argc, char * const argv[]) kernel_filename, kernel.size, kernel.size); struct Image out = { in.width - kernel.size + 1, - in.height - kernel.size + 1 }; + in.height - kernel.size + 1, NULL }; alloc_pixels(&out); process_image(in, kernel, out); diff --git a/lab6/lab6.c b/lab6/lab6.c index 3696532..e61f52f 100644 --- a/lab6/lab6.c +++ b/lab6/lab6.c @@ -87,7 +87,7 @@ int main(int argc, char * const argv[]) aperture_filename, aperture.size, aperture.size); struct Image out = { in.width - aperture.size + 1, - in.height - aperture.size + 1 }; + in.height - aperture.size + 1, NULL }; alloc_pixels(&out); process_image(in, aperture, out); diff --git a/lab7/lab7.c b/lab7/lab7.c index 7471bcb..d028e01 100644 --- a/lab7/lab7.c +++ b/lab7/lab7.c @@ -38,7 +38,7 @@ static size_t segmentation(struct Image in, struct Image out) { unsigned char new_color = prev_color + 50 <= 255 ? prev_color + 50 : 50; - struct Image front = { in.width, in.height }; + struct Image front = { in.width, in.height, NULL }; alloc_pixels(&front); for (size_t y = 0; y < front.height; y++) @@ -115,7 +115,7 @@ int main(int argc, char * const argv[]) binarization(in, (unsigned char) threshold); - struct Image out = { in.width, in.height }; + struct Image out = { in.width, in.height, NULL }; alloc_pixels(&out); size_t s = segmentation(in, out); diff --git a/png_wrapper.h b/png_wrapper.h index 1d40d22..7c10209 100644 --- a/png_wrapper.h +++ b/png_wrapper.h @@ -1,5 +1,4 @@ -#ifndef PNG_WRAPPER_H -#define PNG_WRAPPER_H +#pragma once #include @@ -15,5 +14,3 @@ void free_pixels(struct Image img); struct Image read_grayscale_png(const char *file_name); void write_grayscale_png(struct Image img, const char *file_name); - -#endif