-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.h
45 lines (36 loc) · 1.01 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#pragma once
#include "bmp.h"
#include "stdlib.h"
RGB make_rgb(uint32_t red, uint32_t green, uint32_t blue){
RGB rgb;
rgb.R = red;
rgb.G = green;
rgb.B = blue;
return rgb;
}
RGB make_rgb_mono(uint32_t color){
RGB rgb = make_rgb(color, color, color);
return rgb;
}
// different ways to convert to grayscale
// but taking the average magnitude of each
// value is probably the simplest
int brightness_from_rgb(RGB rgb){
int brightness = (rgb.R + rgb.G + rgb.B) / 3;
return brightness;
}
RGB** deep_region_copy_img24(IMAGE img24, int fx, int fy, int lx, int ly){
int x_range = lx - fx + 1;
int y_range = ly - fy + 1;
RGB** deep_region_copy;
deep_region_copy = (RGB**) malloc(y_range*sizeof(void*));
for(int y = 0; y < y_range; y++){
deep_region_copy[y] = (RGB*) malloc(x_range*sizeof(RGB));
for(int x = 0; x < x_range; x++){
int original_x = x + fx;
int original_y = y + fy;
deep_region_copy[y][x] = img24.pixels[original_y][original_x];
}
}
return deep_region_copy;
}