removed warnings
This commit is contained in:
parent
72785e2ac7
commit
aa66c04c17
|
@ -3,7 +3,7 @@ project(Juniorcamp C)
|
|||
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
|
||||
add_executable(Juniorcamp src/main.c src/gfx.c)
|
||||
add_executable(Juniorcamp src/main.c src/distance.c src/gfx.c)
|
||||
|
||||
target_link_libraries(Juniorcamp imago m X11)
|
||||
target_include_directories(Juniorcamp PRIVATE inc)
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 888 KiB |
Binary file not shown.
After Width: | Height: | Size: 59 KiB |
|
@ -0,0 +1,15 @@
|
|||
#ifndef JUNIORCAMP_DISTANCE_H
|
||||
#define JUNIORCAMP_DISTANCE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define MASK_MULTIPLIER 500
|
||||
|
||||
typedef struct {
|
||||
int64_t distance;
|
||||
int8_t direction;
|
||||
} distance_T;
|
||||
|
||||
int64_t pixel_distance(uint32_t pixel_a, uint32_t pixel_b, uint32_t pixel_m);
|
||||
|
||||
#endif //JUNIORCAMP_DISTANCE_H
|
|
@ -0,0 +1,23 @@
|
|||
#include "distance.h"
|
||||
#include <math.h>
|
||||
|
||||
int64_t pixel_distance(uint32_t pixel_a, uint32_t pixel_b, uint32_t pixel_m) {
|
||||
uint8_t r_a = (pixel_a) & 0xFF;
|
||||
uint8_t g_a = (pixel_a >> 8) & 0xFF;
|
||||
uint8_t b_a = (pixel_a >> 16) & 0xFF;
|
||||
|
||||
uint8_t r_b = (pixel_b) & 0xFF;
|
||||
uint8_t g_b = (pixel_b >> 8) & 0xFF;
|
||||
uint8_t b_b = (pixel_b >> 16) & 0xFF;
|
||||
|
||||
uint8_t r_m = (pixel_m) & 0xFF;
|
||||
uint8_t g_m = (pixel_m >> 8) & 0xFF;
|
||||
|
||||
int64_t dist = (int64_t)sqrt(pow(r_a - r_b, 2) +
|
||||
pow(g_a - g_b, 2) +
|
||||
pow(b_a - b_b, 2)) +
|
||||
(r_m * MASK_MULTIPLIER) -
|
||||
(g_m * MASK_MULTIPLIER);
|
||||
|
||||
return dist;
|
||||
}
|
48
src/main.c
48
src/main.c
|
@ -2,18 +2,11 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <memory.h>
|
||||
#include <imago2.h>
|
||||
#include <time.h>
|
||||
#include "gfx.h"
|
||||
|
||||
#define MASK_MULTIPLIER 50
|
||||
|
||||
typedef struct {
|
||||
int32_t distance;
|
||||
int8_t direction;
|
||||
} distance_T;
|
||||
#include "distance.h"
|
||||
|
||||
typedef struct {
|
||||
uint32_t width;
|
||||
|
@ -25,38 +18,12 @@ typedef struct {
|
|||
uint32_t* mask_buffer;
|
||||
} image_T;
|
||||
|
||||
int32_t pixel_distance(uint32_t pixel_a, uint32_t pixel_b, uint32_t pixel_m) {
|
||||
uint8_t r_a = (pixel_a) & 0xFF;
|
||||
uint8_t g_a = (pixel_a >> 8) & 0xFF;
|
||||
uint8_t b_a = (pixel_a >> 16) & 0xFF;
|
||||
|
||||
uint8_t r_b = (pixel_b) & 0xFF;
|
||||
uint8_t g_b = (pixel_b >> 8) & 0xFF;
|
||||
uint8_t b_b = (pixel_b >> 16) & 0xFF;
|
||||
|
||||
uint8_t r_m = (pixel_m) & 0xFF;
|
||||
uint8_t g_m = (pixel_m >> 8) & 0xFF;
|
||||
|
||||
int32_t dist = (int32_t)sqrt(pow(r_a - r_b, 2) +
|
||||
pow(g_a - g_b, 2) +
|
||||
pow(b_a - b_b, 2)) +
|
||||
(r_m * MASK_MULTIPLIER) -
|
||||
(g_m * MASK_MULTIPLIER);
|
||||
|
||||
return dist;
|
||||
}
|
||||
|
||||
image_T* image_load(const char* filename, const char* filename_mask) {
|
||||
printf("loading '%s'...\n", filename);
|
||||
|
||||
image_T* image = malloc(sizeof(image_T));
|
||||
|
||||
if (filename_mask != NULL) {
|
||||
image->mask_buffer = img_load_pixels(filename_mask, (int*)&image->width, (int*)&image->height, IMG_FMT_RGBA32);
|
||||
} else {
|
||||
image->mask_buffer = NULL;
|
||||
}
|
||||
|
||||
image->buffer = img_load_pixels(filename, (int*)&image->width, (int*)&image->height, IMG_FMT_RGBA32);
|
||||
image->dist_buffer = calloc(image->width * image->height, sizeof(distance_T));
|
||||
image->new_width = image->width;
|
||||
|
@ -87,7 +54,7 @@ void image_calculate_dist_buffer(image_T* image) {
|
|||
for (int y = 1; y < image->new_height; y++) {
|
||||
for (int x = 0; x < image->new_width; x++) {
|
||||
|
||||
int32_t dist;
|
||||
int64_t dist;
|
||||
distance_T shortest_dist;
|
||||
|
||||
if (x > 0) {
|
||||
|
@ -157,7 +124,7 @@ void image_cut_line(image_T* image, uint32_t line_id) {
|
|||
memcpy(&image->buffer[(image->width * y) + x], &image->buffer[(image->width * y) + x + 1], (image->new_width - x) * sizeof(uint32_t));
|
||||
if (image->mask_buffer != NULL) memcpy(&image->mask_buffer[(image->width * y) + x], &image->mask_buffer[(image->width * y) + x + 1], (image->new_width - x) * sizeof(uint32_t));
|
||||
gfx_color(0, 0xFF, 0);
|
||||
gfx_point(x, y);
|
||||
gfx_point((int)x, (int)y);
|
||||
}
|
||||
image->new_width -= 1;
|
||||
|
||||
|
@ -178,7 +145,7 @@ void image_dump(image_T* image) {
|
|||
|
||||
gfx_color(0, 0, 0);
|
||||
for (int y = 0; y < image->new_height; y++) {
|
||||
gfx_point(image->new_width, y);
|
||||
gfx_point((int)image->new_width, y);
|
||||
}
|
||||
|
||||
gfx_flush();
|
||||
|
@ -188,7 +155,7 @@ void image_export(image_T* image, const char* filename) {
|
|||
printf("exporting image to '%s'\n", filename);
|
||||
struct img_pixmap img;
|
||||
img_init(&img);
|
||||
img_set_pixels(&img, image->new_width, image->new_height, IMG_FMT_RGBA32, NULL);
|
||||
img_set_pixels(&img, (int)image->new_width, (int)image->new_height, IMG_FMT_RGBA32, NULL);
|
||||
|
||||
uint32_t* out_buffer = (uint32_t*)img.pixels;
|
||||
|
||||
|
@ -200,7 +167,7 @@ void image_export(image_T* image, const char* filename) {
|
|||
}
|
||||
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
int main() {
|
||||
printf("Line Cutter - Juniorcamp Informatik\n");
|
||||
|
||||
image_T* image = image_load("../images/paris.png", "../images/paris_mask.png");
|
||||
|
@ -235,6 +202,9 @@ int main(int argc, char* argv[]) {
|
|||
running = false;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue