working generator
This commit is contained in:
+7
-2
@@ -16,7 +16,8 @@ void print_help(int status_code) {
|
|||||||
"[-p=PIXEL_SIZE] "
|
"[-p=PIXEL_SIZE] "
|
||||||
"[-s=SLOPE] "
|
"[-s=SLOPE] "
|
||||||
"[-c=R,G,B] "
|
"[-c=R,G,B] "
|
||||||
"[-v=R,G,B]\n\n"
|
"[-v=R,G,B] "
|
||||||
|
"[-m]\n\n"
|
||||||
"generates a marble-like pattern bitmap image.\n\n"
|
"generates a marble-like pattern bitmap image.\n\n"
|
||||||
"options:\n"
|
"options:\n"
|
||||||
" --help show this help message and exit\n"
|
" --help show this help message and exit\n"
|
||||||
@@ -29,7 +30,8 @@ void print_help(int status_code) {
|
|||||||
" -s, --slope slope [0-255] (default: random)\n"
|
" -s, --slope slope [0-255] (default: random)\n"
|
||||||
" -c, --color base color [0-255,0-255,0-255] (default: random)\n"
|
" -c, --color base color [0-255,0-255,0-255] (default: random)\n"
|
||||||
" -v, --variation base variation [0-255,0-255,0-255] (default: "
|
" -v, --variation base variation [0-255,0-255,0-255] (default: "
|
||||||
"random)");
|
"random)"
|
||||||
|
" -m, --monochrome black & white generation");
|
||||||
exit(status_code);
|
exit(status_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,6 +121,7 @@ parameters parse_args(int argc, char **argv) {
|
|||||||
params.width = 0;
|
params.width = 0;
|
||||||
params.height = 0;
|
params.height = 0;
|
||||||
params.file_path = "output.bmp";
|
params.file_path = "output.bmp";
|
||||||
|
params.monochrome = false;
|
||||||
|
|
||||||
bool size_set = false;
|
bool size_set = false;
|
||||||
bool slope_set = false;
|
bool slope_set = false;
|
||||||
@@ -170,6 +173,8 @@ parameters parse_args(int argc, char **argv) {
|
|||||||
} else if (is_arg(arg, "-v") || is_arg(arg, "--variation")) {
|
} else if (is_arg(arg, "-v") || is_arg(arg, "--variation")) {
|
||||||
parse_color(arg, value, params.var);
|
parse_color(arg, value, params.var);
|
||||||
var_set = true;
|
var_set = true;
|
||||||
|
} else if (is_arg(arg, "-m") || is_arg(arg, "--monochrome")) {
|
||||||
|
params.monochrome = true;
|
||||||
} else {
|
} else {
|
||||||
invalid_arg(arg);
|
invalid_arg(arg);
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-18
@@ -5,10 +5,9 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define COLOR_DEPTH 3
|
|
||||||
|
|
||||||
parameters global_params;
|
parameters global_params;
|
||||||
float global_fslope;
|
float slope;
|
||||||
|
unsigned char color_depth;
|
||||||
unsigned int line_width;
|
unsigned int line_width;
|
||||||
unsigned char *last_line;
|
unsigned char *last_line;
|
||||||
unsigned char *current_line;
|
unsigned char *current_line;
|
||||||
@@ -17,8 +16,8 @@ unsigned char generate_pixel(unsigned char depth, unsigned char top_pixel,
|
|||||||
unsigned char left_pixel) {
|
unsigned char left_pixel) {
|
||||||
float v = fminf(
|
float v = fminf(
|
||||||
255.0, fmaxf(0.0, (rand_float(2.0) - 1.0) * global_params.var[depth] +
|
255.0, fmaxf(0.0, (rand_float(2.0) - 1.0) * global_params.var[depth] +
|
||||||
((float)left_pixel) * global_fslope +
|
((float)left_pixel) * slope +
|
||||||
((float)top_pixel) * (1.0 - global_fslope)));
|
((float)top_pixel) * (1.0 - slope)));
|
||||||
return (unsigned char)v;
|
return (unsigned char)v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,12 +27,12 @@ void generate_line() {
|
|||||||
last_line[i] = current_line[i];
|
last_line[i] = current_line[i];
|
||||||
}
|
}
|
||||||
for (i = 0; i < line_width; i++) {
|
for (i = 0; i < line_width; i++) {
|
||||||
if (i < COLOR_DEPTH) {
|
if (i < color_depth) {
|
||||||
current_line[i] = generate_pixel(i % COLOR_DEPTH, last_line[i],
|
current_line[i] = generate_pixel(i % color_depth, last_line[i],
|
||||||
global_params.start[i % COLOR_DEPTH]);
|
global_params.start[i % color_depth]);
|
||||||
} else {
|
} else {
|
||||||
current_line[i] = generate_pixel(i % COLOR_DEPTH, last_line[i],
|
current_line[i] = generate_pixel(i % color_depth, last_line[i],
|
||||||
current_line[i - COLOR_DEPTH]);
|
current_line[i - color_depth]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,12 +41,12 @@ void generate_bmp_line(unsigned short y, unsigned char *data_buffer,
|
|||||||
unsigned int len) {
|
unsigned int len) {
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
unsigned int x;
|
unsigned int x;
|
||||||
for (i = 0; i < len; i++) {
|
if (y > 0 && (y % global_params.size) == 0) {
|
||||||
if (y > 0 && y % global_params.size == 0) {
|
|
||||||
generate_line();
|
generate_line();
|
||||||
}
|
}
|
||||||
x = i / (COLOR_DEPTH * global_params.size);
|
for (i = 0; i < len; i++) {
|
||||||
data_buffer[i] = current_line[x * COLOR_DEPTH + (i % COLOR_DEPTH)];
|
x = i / (color_depth * global_params.size);
|
||||||
|
data_buffer[i] = current_line[x * color_depth + (i % color_depth)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,22 +57,28 @@ void debug_parameters(parameters params) {
|
|||||||
printf("width %d\n", params.width);
|
printf("width %d\n", params.width);
|
||||||
printf("height %d\n", params.height);
|
printf("height %d\n", params.height);
|
||||||
printf("pixel %d\n", params.size);
|
printf("pixel %d\n", params.size);
|
||||||
|
if (params.monochrome) {
|
||||||
|
printf("color %u\n", params.start[0]);
|
||||||
|
printf("var. %u\n", params.var[0]);
|
||||||
|
} else {
|
||||||
printf("color %u,%u,%u\n", params.start[0], params.start[1],
|
printf("color %u,%u,%u\n", params.start[0], params.start[1],
|
||||||
params.start[2]);
|
params.start[2]);
|
||||||
printf("var. %u,%u,%u\n", params.var[0], params.var[1], params.var[2]);
|
printf("var. %u,%u,%u\n", params.var[0], params.var[1], params.var[2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void init(parameters params) {
|
void init(parameters params) {
|
||||||
global_params = params;
|
global_params = params;
|
||||||
global_fslope = ((float)params.slope) / 255.0;
|
slope = ((float)params.slope) / 255.0;
|
||||||
|
color_depth = params.monochrome ? 1 : 3;
|
||||||
debug_parameters(params);
|
debug_parameters(params);
|
||||||
line_width = ((params.width / params.size) + 1) * COLOR_DEPTH;
|
line_width = ((params.width / params.size) + 1) * color_depth;
|
||||||
last_line = (unsigned char *)malloc(line_width);
|
last_line = (unsigned char *)malloc(line_width);
|
||||||
current_line = (unsigned char *)malloc(line_width);
|
current_line = (unsigned char *)malloc(line_width);
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
for (i = 0; i < line_width; i++) {
|
for (i = 0; i < line_width; i++) {
|
||||||
current_line[i] = params.start[i % COLOR_DEPTH];
|
current_line[i] = params.start[i % color_depth];
|
||||||
}
|
}
|
||||||
set_seed(params.seed);
|
set_seed(params.seed);
|
||||||
generate_line();
|
generate_line();
|
||||||
@@ -86,7 +91,7 @@ void clean() {
|
|||||||
|
|
||||||
void generate(parameters params) {
|
void generate(parameters params) {
|
||||||
init(params);
|
init(params);
|
||||||
bmp_generate(params.width, params.height, COLOR_DEPTH, params.file_path,
|
bmp_generate(params.width, params.height, color_depth, params.file_path,
|
||||||
generate_bmp_line);
|
generate_bmp_line);
|
||||||
clean();
|
clean();
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
struct Parameters {
|
struct Parameters {
|
||||||
bool quiet;
|
bool quiet;
|
||||||
|
bool monochrome;
|
||||||
unsigned long seed;
|
unsigned long seed;
|
||||||
unsigned short width;
|
unsigned short width;
|
||||||
unsigned short height;
|
unsigned short height;
|
||||||
|
|||||||
Reference in New Issue
Block a user