fix: monochrome (#9)

* fix: monochrome

* update doc

* update doc
This commit is contained in:
2025-06-05 12:05:49 +02:00
committed by GitHub
parent 0172286d9a
commit 8f7d7aaaaa
4 changed files with 38 additions and 23 deletions
+3 -2
View File
@@ -22,7 +22,7 @@ make clean build install
## CLI arguments ## CLI arguments
```txt ```txt
usage: margen [--help] [-v] [-q] [-w=WIDTH] [-h=HEIGHT] [-o=PATH] [--seed=SEED][-p=PIXEL_SIZE] [-s=SLOPE] [-c=R,G,B] [-va=R,G,B] [-vr=VAR_RANGE] [-r=ROTATION] usage: margen [--help] [-v] [-q] [-w=WIDTH] [-h=HEIGHT] [-o=PATH] [--seed=SEED][-p=PIXEL_SIZE] [-s=SLOPE] [-c=R,G,B] [-va=R,G,B] [-vr=VAR_RANGE] [-r=ROTATION] [-m]
generate a marble-like pattern bitmap image, blazing fast. generate a marble-like pattern bitmap image, blazing fast.
@@ -39,8 +39,9 @@ options:
-va, --variation fixed variation [0-255,0-255,0-255] (default: random) -va, --variation fixed variation [0-255,0-255,0-255] (default: random)
-vr, --var-range random variation range [0-255] (default: 30) -vr, --var-range random variation range [0-255] (default: 30)
-r, --rotation start corner rotation [0-3] (default: random) -r, --rotation start corner rotation [0-3] (default: random)
-m, --monochrome grayscale generation
``` ```
## TODO ## TODO
- fix monochrome - configure, make, make install
+1 -2
View File
@@ -40,8 +40,7 @@ void print_help(int status_code) {
"random)\n" "random)\n"
" -vr, --var-range random variation range [0-255] (default: 30)\n" " -vr, --var-range random variation range [0-255] (default: 30)\n"
" -r, --rotation start corner rotation [0-3] (default: random)\n" " -r, --rotation start corner rotation [0-3] (default: random)\n"
// " -m, --monochrome black & white generation\n" " -m, --monochrome grayscale generation\n");
);
exit(status_code); exit(status_code);
} }
+30 -17
View File
@@ -32,23 +32,36 @@ unsigned char *bmp_header(unsigned short width, unsigned short height,
unsigned char *output = (unsigned char *)malloc(HEADER_SIZE); unsigned char *output = (unsigned char *)malloc(HEADER_SIZE);
unsigned int data_length = ((unsigned int)width) * ((unsigned int)height) * unsigned int data_length = ((unsigned int)width) * ((unsigned int)height) *
((unsigned int)color_depth); ((unsigned int)color_depth);
write_str(output, 0x00, 0x02, (unsigned char *)"BM"); // 0x00(2) BM // 0x00(2) BM
write_num(output, 0x02, 0x04, write_str(output, 0x00, 0x02, (unsigned char *)"BM");
HEADER_SIZE + data_length); // 0x02(4) file size // 0x02(4) file size
write_nul(output, 0x06, 0x04); // 0x06(4) application reserved write_num(output, 0x02, 0x04, HEADER_SIZE + data_length);
write_num(output, 0x0A, 0x04, HEADER_SIZE); // 0x0A(4) data offset // 0x06(4) application reserved
write_num(output, 0x0E, 0x04, 40); // 0x0E(4) DIB header size write_nul(output, 0x06, 0x04);
write_num(output, 0x12, 0x04, width); // 0x12(4) width // 0x0A(4) data offset
write_num(output, 0x16, 0x04, height); // 0x16(4) height write_num(output, 0x0A, 0x04, HEADER_SIZE);
write_num(output, 0x1A, 0x04, 1); // 0x1A(2) color panes // 0x0E(4) DIB header size
write_num(output, 0x1C, 0x02, color_depth * 8); // 0x1C(2) bits per pixel write_num(output, 0x0E, 0x04, 40);
write_nul(output, 0x1E, 0x04); // 0x1E(4) BI_RGB, no compression // 0x12(4) width
write_num(output, 0x22, 0x04, write_num(output, 0x12, 0x04, width);
data_length); // 0x22(4) size of raw bitmap data // 0x16(4) height
write_num(output, 0x26, 0x04, 2835); // 0x26(4) horizontal print resolution write_num(output, 0x16, 0x04, height);
write_num(output, 0x2A, 0x04, 2835); // 0x2A(4) vertical print resolution // 0x1A(2) color panes
write_nul(output, 0x2E, 0x04); // 0x2E(4) color in palette write_num(output, 0x1A, 0x04, 1);
write_nul(output, 0x32, 0x04); // 0x32(4) 0 important colors // 0x1C(2) bits per pixel
write_num(output, 0x1C, 0x02, color_depth * 8);
// 0x1E(4) BI_RGB, no compression
write_nul(output, 0x1E, 0x04);
// 0x22(4) size of raw bitmap data
write_num(output, 0x22, 0x04, data_length);
// 0x26(4) horizontal print resolution
write_num(output, 0x26, 0x04, 2835);
// 0x2A(4) vertical print resolution
write_num(output, 0x2A, 0x04, 2835);
// 0x2E(4) color in palette (0)
write_nul(output, 0x2E, 0x04);
// 0x32(4) important colors (0)
write_nul(output, 0x32, 0x04);
return output; return output;
} }
+4 -2
View File
@@ -7,6 +7,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#define BMP_COLOR_DEPTH 3
parameters global_params; parameters global_params;
float slope; float slope;
unsigned char color_depth; unsigned char color_depth;
@@ -47,7 +49,7 @@ void generate_bmp_line(unsigned short y, unsigned char *data_buffer,
generate_line(); generate_line();
} }
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
x = i / (color_depth * global_params.size); x = i / (BMP_COLOR_DEPTH * global_params.size);
data_buffer[(global_params.rotation / 2) == 1 ? i : (len - i - 1)] = data_buffer[(global_params.rotation / 2) == 1 ? i : (len - i - 1)] =
current_line[x * color_depth + (i % color_depth)]; current_line[x * color_depth + (i % color_depth)];
} }
@@ -106,7 +108,7 @@ void generate(parameters params) {
} }
clock_t start = clock(); clock_t start = clock();
init(params); init(params);
bmp_generate(params.width, params.height, color_depth, bmp_generate(params.width, params.height, BMP_COLOR_DEPTH,
params.rotation % 2 == 1, params.file_path, generate_bmp_line); params.rotation % 2 == 1, params.file_path, generate_bmp_line);
clean(); clean();
print_time(params, start); print_time(params, start);