Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3a100080c2 | |||
| 7626f99e32 | |||
| d63f3f5023 | |||
| 8f7d7aaaaa | |||
| 0172286d9a | |||
| 533960f46f | |||
| 1df9e4a468 | |||
| 4a63f3badd | |||
| 21953a0394 |
+17
-1
@@ -1,4 +1,20 @@
|
||||
build
|
||||
.vscode
|
||||
*.bmp
|
||||
!images/*
|
||||
!images/*
|
||||
*.cache
|
||||
.deps
|
||||
Makefile
|
||||
*.log
|
||||
*.o
|
||||
.dirstamp
|
||||
aclocal.m4
|
||||
compile
|
||||
install-sh
|
||||
missing
|
||||
depcomp
|
||||
Makefile.in
|
||||
configure~
|
||||
config.status
|
||||
margen
|
||||
*.tar.gz
|
||||
@@ -0,0 +1,5 @@
|
||||
AUTOMAKE_OPTIONS = foreign subdir-objects -Wall
|
||||
bin_PROGRAMS = margen
|
||||
margen_SOURCES = src/main.c src/args.c src/bmp.c src/generator.c src/rand.c
|
||||
include_HEADERS = src/main.h src/args.h src/bmp.h src/generator.h src/rand.h src/config.h src/types.h
|
||||
margen_LDADD = -lm
|
||||
+15
-9
@@ -24,12 +24,18 @@ valgrind: build
|
||||
valgrind --leak-check=full -s ./build/$(TARGET) $(TEST_ARGS)
|
||||
|
||||
.PHONY: release
|
||||
release: clean build time
|
||||
@echo -n "Version (x.y.z): "
|
||||
@read VERSION; \
|
||||
sed -i "s/#define VERSION.*/#define VERSION \"v$$VERSION\"/g" ./src/const.h; \
|
||||
git add ./src/const.h; \
|
||||
git diff origin/master; \
|
||||
git commit -m "$(TARGET) v$$VERSION"; \
|
||||
git tag v$$VERSION -m "$(TARGET) v$$VERSION"
|
||||
@echo updated ./src/const.h and tagged version
|
||||
release:
|
||||
aclocal
|
||||
autoconf
|
||||
automake --add-missing
|
||||
./configure
|
||||
make distcheck
|
||||
|
||||
.PHONY: gif
|
||||
gif: build
|
||||
mkdir -p tmp
|
||||
for i in {1..50}; do \
|
||||
./build/margen -w=1920 -h=720 --seed=$$i$$i -o=tmp/image$$i.bmp ; \
|
||||
done
|
||||
ffmpeg -y -f image2 -framerate 1 -i tmp/image%d.bmp -vf scale=960x360 images/sample.gif
|
||||
rm -rf tmp
|
||||
@@ -2,25 +2,26 @@
|
||||
|
||||
> generate a marble-like pattern bitmap image, blazing fast.
|
||||
|
||||

|
||||
<p align="center">
|
||||
<img width="960" height="360" src="./images/sample.gif">
|
||||
</p>
|
||||
|
||||
Written in pure C without librairies.
|
||||
|
||||
## Install
|
||||
|
||||
You only need **gcc** and **make**.
|
||||
|
||||
```bash
|
||||
git clone https://github.com/klemek/margen
|
||||
cd margen
|
||||
make clean build install
|
||||
# margen is now installed in ~/.local/bin
|
||||
./configure
|
||||
make
|
||||
make install
|
||||
```
|
||||
|
||||
## CLI arguments
|
||||
|
||||
```txt
|
||||
usage: margen [--help] [-q] [-w=WIDTH] [-h=HEIGHT] [-o=PATH] [--seed=SEED][-p=PIXEL_SIZE] [-s=SLOPE] [-c=R,G,B] [-v=R,G,B] [-m]
|
||||
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.
|
||||
|
||||
@@ -34,13 +35,8 @@ options:
|
||||
-p, --pixel pixel size (default: random)
|
||||
-s, --slope slope [0-255] (default: random)
|
||||
-c, --color base color [0-255,0-255,0-255] (default: random)
|
||||
-v, --variation base 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)
|
||||
-r, --rotation start corner rotation [0-3] (default: random)
|
||||
-m, --monochrome grayscale generation
|
||||
```
|
||||
|
||||
## TODO
|
||||
|
||||
- fix monochrome
|
||||
- select corner (currently bottom left)
|
||||
- better starting parameters for convergeance
|
||||
- add range arg for variation
|
||||
- add timer
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
AC_INIT([margen], [1.2.0], [klemek.dev@proton.me])
|
||||
AM_INIT_AUTOMAKE
|
||||
AC_PROG_CC
|
||||
AC_CHECK_HEADERS([stdio.h])
|
||||
AC_CHECK_HEADERS([stdlib.h])
|
||||
AC_CHECK_HEADERS([stdbool.h])
|
||||
AC_CHECK_HEADERS([string.h])
|
||||
AC_CHECK_HEADERS([time.h])
|
||||
AC_CHECK_HEADERS([math.h])
|
||||
AC_CONFIG_FILES([Makefile])
|
||||
AC_OUTPUT
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 7.6 MiB |
Binary file not shown.
|
Before Width: | Height: | Size: 5.9 MiB |
+19
-10
@@ -1,5 +1,5 @@
|
||||
#include "args.h"
|
||||
#include "const.h"
|
||||
#include "config.h"
|
||||
#include "rand.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -7,9 +7,9 @@
|
||||
#include <time.h>
|
||||
|
||||
void print_help(int status_code) {
|
||||
puts(NAME
|
||||
puts(PACKAGE
|
||||
" " VERSION "\n\n"
|
||||
"usage: " NAME " "
|
||||
"usage: " PACKAGE " "
|
||||
"[--help] "
|
||||
"[-v] "
|
||||
"[-q] "
|
||||
@@ -20,8 +20,9 @@ void print_help(int status_code) {
|
||||
"[-p=PIXEL_SIZE] "
|
||||
"[-s=SLOPE] "
|
||||
"[-c=R,G,B] "
|
||||
"[--var=R,G,B] "
|
||||
"[-vr=VAR_RANGE]"
|
||||
"[-va=R,G,B] "
|
||||
"[-vr=VAR_RANGE] "
|
||||
"[-r=ROTATION] "
|
||||
// "[-m]"
|
||||
"\n\n"
|
||||
"generate a marble-like pattern bitmap image, blazing fast.\n\n"
|
||||
@@ -38,8 +39,8 @@ void print_help(int status_code) {
|
||||
" -va, --variation fixed variation [0-255,0-255,0-255] (default: "
|
||||
"random)\n"
|
||||
" -vr, --var-range random variation range [0-255] (default: 30)\n"
|
||||
// " -m, --monochrome black & white generation\n"
|
||||
);
|
||||
" -r, --rotation start corner rotation [0-3] (default: random)\n"
|
||||
" -m, --monochrome grayscale generation\n");
|
||||
exit(status_code);
|
||||
}
|
||||
|
||||
@@ -131,6 +132,7 @@ parameters parse_args(int argc, char **argv) {
|
||||
bool slope_set = false;
|
||||
bool start_set = false;
|
||||
bool var_set = false;
|
||||
bool rot_set = false;
|
||||
|
||||
int i;
|
||||
char *arg;
|
||||
@@ -143,7 +145,7 @@ parameters parse_args(int argc, char **argv) {
|
||||
} else if (is_arg(arg, "-q") || is_arg(arg, "--quiet")) {
|
||||
params.quiet = true;
|
||||
} else if (is_arg(arg, "-v") || is_arg(arg, "--version")) {
|
||||
puts(NAME " " VERSION);
|
||||
puts(PACKAGE " " VERSION);
|
||||
exit(0);
|
||||
} else if (is_arg(arg, "-w") || is_arg(arg, "--width")) {
|
||||
params.width = parse_ushort(arg, value);
|
||||
@@ -182,8 +184,11 @@ parameters parse_args(int argc, char **argv) {
|
||||
var_set = true;
|
||||
} else if (is_arg(arg, "-vr") || is_arg(arg, "--var-range")) {
|
||||
var_range = parse_char(arg, value);
|
||||
// } else if (is_arg(arg, "-m") || is_arg(arg, "--monochrome")) {
|
||||
// params.monochrome = true;
|
||||
} else if (is_arg(arg, "-r") || is_arg(arg, "--rotation")) {
|
||||
params.rotation = parse_char(arg, value) % 4;
|
||||
rot_set = true;
|
||||
} else if (is_arg(arg, "-m") || is_arg(arg, "--monochrome")) {
|
||||
params.monochrome = true;
|
||||
} else {
|
||||
invalid_arg(arg);
|
||||
}
|
||||
@@ -216,5 +221,9 @@ parameters parse_args(int argc, char **argv) {
|
||||
params.var[2] = rand_uchar(var_range);
|
||||
}
|
||||
|
||||
if (!rot_set) {
|
||||
params.rotation = rand_uchar(4);
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
@@ -32,23 +32,36 @@ unsigned char *bmp_header(unsigned short width, unsigned short height,
|
||||
unsigned char *output = (unsigned char *)malloc(HEADER_SIZE);
|
||||
unsigned int data_length = ((unsigned int)width) * ((unsigned int)height) *
|
||||
((unsigned int)color_depth);
|
||||
write_str(output, 0x00, 0x02, (unsigned char *)"BM"); // 0x00(2) BM
|
||||
write_num(output, 0x02, 0x04,
|
||||
HEADER_SIZE + data_length); // 0x02(4) file size
|
||||
write_nul(output, 0x06, 0x04); // 0x06(4) application reserved
|
||||
write_num(output, 0x0A, 0x04, HEADER_SIZE); // 0x0A(4) data offset
|
||||
write_num(output, 0x0E, 0x04, 40); // 0x0E(4) DIB header size
|
||||
write_num(output, 0x12, 0x04, width); // 0x12(4) width
|
||||
write_num(output, 0x16, 0x04, height); // 0x16(4) height
|
||||
write_num(output, 0x1A, 0x04, 1); // 0x1A(2) color panes
|
||||
write_num(output, 0x1C, 0x02, color_depth * 8); // 0x1C(2) bits per pixel
|
||||
write_nul(output, 0x1E, 0x04); // 0x1E(4) BI_RGB, no compression
|
||||
write_num(output, 0x22, 0x04,
|
||||
data_length); // 0x22(4) size of raw bitmap data
|
||||
write_num(output, 0x26, 0x04, 2835); // 0x26(4) horizontal print resolution
|
||||
write_num(output, 0x2A, 0x04, 2835); // 0x2A(4) vertical print resolution
|
||||
write_nul(output, 0x2E, 0x04); // 0x2E(4) color in palette
|
||||
write_nul(output, 0x32, 0x04); // 0x32(4) 0 important colors
|
||||
// 0x00(2) BM
|
||||
write_str(output, 0x00, 0x02, (unsigned char *)"BM");
|
||||
// 0x02(4) file size
|
||||
write_num(output, 0x02, 0x04, HEADER_SIZE + data_length);
|
||||
// 0x06(4) application reserved
|
||||
write_nul(output, 0x06, 0x04);
|
||||
// 0x0A(4) data offset
|
||||
write_num(output, 0x0A, 0x04, HEADER_SIZE);
|
||||
// 0x0E(4) DIB header size
|
||||
write_num(output, 0x0E, 0x04, 40);
|
||||
// 0x12(4) width
|
||||
write_num(output, 0x12, 0x04, width);
|
||||
// 0x16(4) height
|
||||
write_num(output, 0x16, 0x04, height);
|
||||
// 0x1A(2) color panes
|
||||
write_num(output, 0x1A, 0x04, 1);
|
||||
// 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;
|
||||
}
|
||||
@@ -75,7 +88,7 @@ void bmp_data_line(unsigned char *buffer, unsigned short width,
|
||||
}
|
||||
|
||||
void bmp_generate(unsigned short width, unsigned short height,
|
||||
unsigned char color_depth, char *file_path,
|
||||
unsigned char color_depth, bool descending, char *file_path,
|
||||
line_fn generate_line) {
|
||||
FILE *fptr;
|
||||
fptr = fopen(file_path, "w");
|
||||
@@ -84,14 +97,17 @@ void bmp_generate(unsigned short width, unsigned short height,
|
||||
free(header);
|
||||
unsigned int data_length =
|
||||
((unsigned int)width) * ((unsigned int)color_depth);
|
||||
unsigned short y;
|
||||
unsigned int line_length = bmp_data_line_length(width, color_depth);
|
||||
unsigned char *data_buffer = (unsigned char *)malloc(data_length);
|
||||
unsigned char *line_buffer =
|
||||
(unsigned char *)malloc(bmp_data_line_length(width, color_depth));
|
||||
unsigned char *line_buffer = (unsigned char *)malloc(line_length);
|
||||
unsigned short y;
|
||||
for (y = 0; y < height; y++) {
|
||||
generate_line(height - y - 1, data_buffer, data_length);
|
||||
generate_line(y, data_buffer, data_length);
|
||||
bmp_data_line(line_buffer, width, color_depth, data_buffer);
|
||||
fwrite(line_buffer, bmp_data_line_length(width, color_depth), 1, fptr);
|
||||
if (descending) {
|
||||
fseek(fptr, HEADER_SIZE + (height - y - 1) * line_length, SEEK_SET);
|
||||
}
|
||||
fwrite(line_buffer, line_length, 1, fptr);
|
||||
}
|
||||
free(line_buffer);
|
||||
free(data_buffer);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#define BMP_H
|
||||
|
||||
void bmp_generate(unsigned short width, unsigned short height,
|
||||
unsigned char color_depth, char *file_path,
|
||||
unsigned char color_depth, bool descending, char *file_path,
|
||||
line_fn generate_line);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#ifndef PACKAGE
|
||||
#define PACKAGE "margen"
|
||||
#endif
|
||||
|
||||
#ifndef VERSION
|
||||
#define VERSION "(dev)"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,7 +0,0 @@
|
||||
#ifndef CONST_H
|
||||
#define CONST_H
|
||||
|
||||
#define NAME "margen"
|
||||
#define VERSION "v1.0.2"
|
||||
|
||||
#endif
|
||||
+11
-8
@@ -1,12 +1,14 @@
|
||||
#include "args.h"
|
||||
#include "bmp.h"
|
||||
#include "const.h"
|
||||
#include "config.h"
|
||||
#include "rand.h"
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#define BMP_COLOR_DEPTH 3
|
||||
|
||||
parameters global_params;
|
||||
float slope;
|
||||
unsigned char color_depth;
|
||||
@@ -43,12 +45,13 @@ void generate_bmp_line(unsigned short y, unsigned char *data_buffer,
|
||||
unsigned int len) {
|
||||
unsigned int i;
|
||||
unsigned int x;
|
||||
if (y > 0 && (y % global_params.size) == 0) {
|
||||
if (y % global_params.size == 0) {
|
||||
generate_line();
|
||||
}
|
||||
for (i = 0; i < len; i++) {
|
||||
x = i / (color_depth * global_params.size);
|
||||
data_buffer[i] = current_line[x * color_depth + (i % color_depth)];
|
||||
x = i / (BMP_COLOR_DEPTH * global_params.size);
|
||||
data_buffer[(global_params.rotation / 2) == 1 ? i : (len - i - 1)] =
|
||||
current_line[x * color_depth + (i % color_depth)];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +71,7 @@ void debug_parameters(parameters params) {
|
||||
printf(" var. %u,%u,%u\n", params.var[0], params.var[1],
|
||||
params.var[2]);
|
||||
}
|
||||
printf(" rot. %d\n", params.rotation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +88,6 @@ void init(parameters params) {
|
||||
current_line[i] = params.start[i % color_depth];
|
||||
}
|
||||
set_seed(params.seed);
|
||||
generate_line();
|
||||
}
|
||||
|
||||
void clean() {
|
||||
@@ -101,12 +104,12 @@ void print_time(parameters params, clock_t start) {
|
||||
|
||||
void generate(parameters params) {
|
||||
if (!params.quiet) {
|
||||
puts(NAME " " VERSION);
|
||||
puts(PACKAGE " " VERSION);
|
||||
}
|
||||
clock_t start = clock();
|
||||
init(params);
|
||||
bmp_generate(params.width, params.height, color_depth, params.file_path,
|
||||
generate_bmp_line);
|
||||
bmp_generate(params.width, params.height, BMP_COLOR_DEPTH,
|
||||
params.rotation % 2 == 1, params.file_path, generate_bmp_line);
|
||||
clean();
|
||||
print_time(params, start);
|
||||
}
|
||||
@@ -14,6 +14,7 @@ struct Parameters {
|
||||
unsigned char slope;
|
||||
unsigned char start[3];
|
||||
unsigned char var[3];
|
||||
unsigned char rotation;
|
||||
};
|
||||
|
||||
typedef struct Parameters parameters;
|
||||
|
||||
Reference in New Issue
Block a user