-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtools.cpp
46 lines (42 loc) · 1.23 KB
/
tools.cpp
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
46
#include "stdafx.h"
void
rgb2file(PALLET* pal, FILE* fp) {
RGB* rgb;
size_t points = pal->info->bmiHeader.biSizeImage / sizeof(RGB);
for (size_t i = 0; i < points; ++i) {
rgb = &pal->colors[i];
fprintf(fp, "FFAddColor(0x%02x%02x%02x)\n", rgb->red, rgb->green, rgb->blue);
}
}
void
thresholding(PALLET* pal, /* I - pallet consist with many colors */
RGB *base, /* I - base color */
double variation) /* I - fault tolerant */
{
RGB *other;
size_t points = pal->info->bmiHeader.biSizeImage / sizeof(RGB);
for (size_t i = 0; i < points; ++i) {
other = &pal->colors[i];
color_cmp(base, other, variation) == 1 ?
other->blue = other->green = other->red = 0 :
other->blue = other->green = other->red = 255;
}
}
void
dotmatrix(PALLET* pal, FILE* fp)
{
RGB *color;
size_t points = pal->info->bmiHeader.biSizeImage / sizeof(RGB);
size_t rows = points / pal->info->bmiHeader.biWidth;
size_t i;
size_t r = 0;
for (size_t m = rows; m != 0; --m) {
for (size_t n = 0; n < pal->info->bmiHeader.biWidth; ++n) {
i = (m - 1) * pal->info->bmiHeader.biWidth + n;
color = &pal->colors[i];
if (color->blue == 0) fprintf(fp, "1");
else fprintf(fp, "0");
if (++r % pal->info->bmiHeader.biWidth == 0) fprintf(fp, "\n");
}
}
}