Skip to content

Commit

Permalink
[Makefile] Switch to clang on macOS and fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Gumix committed Sep 4, 2021
1 parent 34a2bd1 commit 6bbca9e
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 44 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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})
Expand Down
5 changes: 1 addition & 4 deletions histogram.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#ifndef HISTOGRAM_H
#define HISTOGRAM_H
#pragma once

#include <stdlib.h>
#include "png_wrapper.h"

enum { HIST_WIDTH = 512, HIST_HEIGHT = 256, MAX_COLOR = 255 };

void histogram(struct Image in, struct Image out);

#endif
6 changes: 3 additions & 3 deletions lab1_2/lab1_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <string.h>
#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;
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions lab1_3/lab1_3.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <string.h>
#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;
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions lab1_4/lab1_4.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <string.h>
#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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lab1_5/lab1_5.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions lab1_6/lab1_6.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lab1_7/lab1_7.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion lab2_1/lab2_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lab2_2/lab2_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions lab3/lab3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions lab4_1/lab4_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -41,15 +41,15 @@ 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);
free_pixels(hist1);

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);
Expand Down
10 changes: 5 additions & 5 deletions lab4_2/lab4_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ 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] = { };

for (size_t y = 0; y < in.height; y++)
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++);

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lab4_3/lab4_3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lab5/lab5.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lab6/lab6.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions lab7/lab7.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 1 addition & 4 deletions png_wrapper.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef PNG_WRAPPER_H
#define PNG_WRAPPER_H
#pragma once

#include <png.h>

Expand All @@ -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

0 comments on commit 6bbca9e

Please sign in to comment.