Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6670ed0167 | |||
| 101c5b6de6 | |||
| f1ba3b32dc | |||
| 01e2e5376b | |||
| 2a749714e5 | |||
| 259860e998 | |||
| 7b9ab384f1 | |||
| 06cc1749a3 | |||
| 3bb2b7d2f5 | |||
| 31135b023f | |||
| 604902b398 | |||
| 3a100080c2 | |||
| 7626f99e32 | |||
| d63f3f5023 | |||
| 8f7d7aaaaa | |||
| 0172286d9a | |||
| 533960f46f | |||
| 1df9e4a468 | |||
| 4a63f3badd | |||
| 21953a0394 | |||
| 0c5ab7b44e | |||
| 022b403670 | |||
| 3d384416fa | |||
| 61d1b0f7e4 | |||
| 2a8c296b63 | |||
| 3146507c62 | |||
| 112c6738c4 | |||
| 8629b2ff05 | |||
| c8ac15891e |
+21
-1
@@ -1,4 +1,24 @@
|
|||||||
build
|
build
|
||||||
.vscode
|
.vscode
|
||||||
*.bmp
|
*.bmp
|
||||||
!images/*
|
!images/*
|
||||||
|
*.cache
|
||||||
|
.deps
|
||||||
|
Makefile
|
||||||
|
*.log
|
||||||
|
*.o
|
||||||
|
.dirstamp
|
||||||
|
aclocal.m4
|
||||||
|
compile
|
||||||
|
install-sh
|
||||||
|
missing
|
||||||
|
depcomp
|
||||||
|
Makefile.in
|
||||||
|
configure~
|
||||||
|
config.status
|
||||||
|
margen
|
||||||
|
*.tar.gz
|
||||||
|
configure
|
||||||
|
src/margen*
|
||||||
|
*.pkg.tar.zst
|
||||||
|
pkg
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
TARGET ?= margen
|
|
||||||
INSTALL_DIR ?= $(HOME)/.local/bin
|
|
||||||
TEST_ARGS ?=
|
|
||||||
SHELL := /bin/bash
|
|
||||||
|
|
||||||
.PHONY: build
|
|
||||||
clean:
|
|
||||||
@rm -rf build
|
|
||||||
|
|
||||||
build:
|
|
||||||
@mkdir -p build
|
|
||||||
gcc -Wall src/*.c src/*.h -lm -o build/$(TARGET)
|
|
||||||
|
|
||||||
.PHONY: install
|
|
||||||
install: build
|
|
||||||
cp -f build/$(TARGET) $(INSTALL_DIR)/$(TARGET)
|
|
||||||
|
|
||||||
.PHONY: time
|
|
||||||
time: build
|
|
||||||
time ./build/$(TARGET) $(TEST_ARGS)
|
|
||||||
|
|
||||||
.PHONY: valgrind
|
|
||||||
valgrind: build
|
|
||||||
valgrind --leak-check=full -s ./build/$(TARGET) $(TEST_ARGS)
|
|
||||||
@@ -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
|
||||||
|
margen_CFLAGS = -Ofast -march=native -flto -funroll-loops -fprefetch-loop-arrays -fno-exceptions -fopenmp
|
||||||
|
include_HEADERS = src/main.h src/args.h src/bmp.h src/generator.h src/rand.h src/config.h src/types.h
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
TARGET ?= margen
|
||||||
|
INSTALL_DIR ?= $(HOME)/.local/bin
|
||||||
|
TEST_ARGS ?=
|
||||||
|
SHELL := /bin/bash
|
||||||
|
|
||||||
|
.PHONY: build
|
||||||
|
clean:
|
||||||
|
@rm -rf build
|
||||||
|
|
||||||
|
build:
|
||||||
|
@mkdir -p build
|
||||||
|
gcc -Wall src/*.c src/*.h -lm -o build/$(TARGET)
|
||||||
|
|
||||||
|
.PHONY: install
|
||||||
|
install: build
|
||||||
|
cp -f build/$(TARGET) $(INSTALL_DIR)/$(TARGET)
|
||||||
|
|
||||||
|
.PHONY: time
|
||||||
|
time: build
|
||||||
|
time ./build/$(TARGET) $(TEST_ARGS)
|
||||||
|
|
||||||
|
.PHONY: valgrind
|
||||||
|
valgrind: build
|
||||||
|
valgrind --leak-check=full -s ./build/$(TARGET) $(TEST_ARGS)
|
||||||
|
|
||||||
|
.PHONY: release
|
||||||
|
release:
|
||||||
|
aclocal
|
||||||
|
autoconf
|
||||||
|
automake --add-missing
|
||||||
|
./configure
|
||||||
|
make distcheck
|
||||||
|
|
||||||
|
.PHONY: release-arch
|
||||||
|
release-arch: clean
|
||||||
|
mkdir -p build
|
||||||
|
cp PKGBUILD build
|
||||||
|
cd build && makepkg
|
||||||
|
|
||||||
|
.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
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
pkgname=margen
|
||||||
|
pkgver=1.2.3
|
||||||
|
pkgrel=1
|
||||||
|
pkgdesc="Generate a marble-like pattern bitmap image, blazing fast."
|
||||||
|
arch=('i686' 'pentium4' 'x86_64' 'arm' 'armv7h' 'armv6h' 'aarch64' 'riscv64')
|
||||||
|
url="https://github.com/klemek/margen"
|
||||||
|
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/klemek/margen/releases/download/v${pkgver}/${pkgname}-${pkgver}.tar.gz")
|
||||||
|
sha256sums=('6922843b9cd1bcbca1dc65ca2cac1e4bf590487e77a06e21969a3432dc74963b')
|
||||||
|
srcdir=build
|
||||||
|
|
||||||
|
build() {
|
||||||
|
cd "$srcdir/$pkgname-$pkgver"
|
||||||
|
./configure --prefix=/usr
|
||||||
|
make
|
||||||
|
}
|
||||||
|
|
||||||
|
package() {
|
||||||
|
cd "$srcdir/$pkgname-$pkgver"
|
||||||
|
sudo make DESTDIR="$pkgdir" install
|
||||||
|
}
|
||||||
@@ -2,25 +2,52 @@
|
|||||||
|
|
||||||
> generate a marble-like pattern bitmap image, blazing fast.
|
> 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.
|
Written in pure C without librairies.
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
You only need **gcc** and **make**.
|
### From release
|
||||||
|
|
||||||
```bash
|
See [Releases](https://github.com/klemek/margen/releases)
|
||||||
|
|
||||||
|
```sh
|
||||||
|
tar xvzf margen-x.y.z.tar.gz
|
||||||
|
cd margen-x.y.z
|
||||||
|
./configure
|
||||||
|
make
|
||||||
|
make install
|
||||||
|
```
|
||||||
|
|
||||||
|
### From repository (PKGBUILD)
|
||||||
|
|
||||||
|
```sh
|
||||||
git clone https://github.com/klemek/margen
|
git clone https://github.com/klemek/margen
|
||||||
cd margen
|
cd margen
|
||||||
make clean build install
|
makepkg -si
|
||||||
# margen is now installed in ~/.local/bin
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### From repository (dev version)
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git clone https://github.com/klemek/margen
|
||||||
|
cd margen
|
||||||
|
aclocal
|
||||||
|
autoconf
|
||||||
|
automake --add-missing
|
||||||
|
./configure
|
||||||
|
make
|
||||||
|
make install
|
||||||
```
|
```
|
||||||
|
|
||||||
## CLI arguments
|
## CLI arguments
|
||||||
|
|
||||||
```txt
|
```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.
|
generate a marble-like pattern bitmap image, blazing fast.
|
||||||
|
|
||||||
@@ -30,16 +57,31 @@ options:
|
|||||||
-w, --width image width (default: 1920)
|
-w, --width image width (default: 1920)
|
||||||
-h, --height image height (default: 1080)
|
-h, --height image height (default: 1080)
|
||||||
-o, --output output file (default: output.bmp)
|
-o, --output output file (default: output.bmp)
|
||||||
-seed random seed (default: time based)
|
--seed random seed (default: time based)
|
||||||
-p, --pixel pixel size (default: random)
|
-p, --pixel pixel size (default: random)
|
||||||
-s, --slope slope [0-255] (default: random)
|
-s, --slope slope [0-255] (default: random)
|
||||||
-c, --color base color [0-255,0-255,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)
|
||||||
-m, --monochrome black & white generation
|
-vr, --var-range random variation range [0-255] (default: 30)
|
||||||
|
-r, --rotation start corner rotation [0-3] (default: random)
|
||||||
|
-m, --monochrome grayscale generation
|
||||||
```
|
```
|
||||||
|
|
||||||
## TODO
|
## Release guide
|
||||||
|
|
||||||
- monochrome
|
```bash
|
||||||
- select corner (currently bottom left)
|
# update configure.ac with new version
|
||||||
- better starting parameters for convergeance
|
$EDITOR configure.ac
|
||||||
|
# make full build
|
||||||
|
make -f Makefile.dev release
|
||||||
|
# push to repo
|
||||||
|
git commit -am "margen vX.Y.Z"
|
||||||
|
git tag vX.Y.Z
|
||||||
|
git push origin master --tags
|
||||||
|
# create release from tag on github
|
||||||
|
# update PKGBUILD with new sha256 sum
|
||||||
|
sha256sum margen-x.y.z.tar.gz
|
||||||
|
make -f Makefile.dev release-arch
|
||||||
|
git commit -am "update arch sha256"
|
||||||
|
# add .pkg.tar.zst on the release
|
||||||
|
```
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
AC_INIT([margen], [1.2.3], [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_CONFIG_FILES([Makefile])
|
||||||
|
AC_OUTPUT
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 8.1 MiB |
Binary file not shown.
|
Before Width: | Height: | Size: 5.9 MiB |
+32
-15
@@ -1,5 +1,5 @@
|
|||||||
#include "args.h"
|
#include "args.h"
|
||||||
#include "const.h"
|
#include "config.h"
|
||||||
#include "rand.h"
|
#include "rand.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -7,9 +7,9 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
void print_help(int status_code) {
|
void print_help(int status_code) {
|
||||||
puts(NAME
|
puts(PACKAGE
|
||||||
" " VERSION "\n\n"
|
" " VERSION "\n\n"
|
||||||
"usage: " NAME " "
|
"usage: " PACKAGE " "
|
||||||
"[--help] "
|
"[--help] "
|
||||||
"[-v] "
|
"[-v] "
|
||||||
"[-q] "
|
"[-q] "
|
||||||
@@ -20,8 +20,11 @@ void print_help(int status_code) {
|
|||||||
"[-p=PIXEL_SIZE] "
|
"[-p=PIXEL_SIZE] "
|
||||||
"[-s=SLOPE] "
|
"[-s=SLOPE] "
|
||||||
"[-c=R,G,B] "
|
"[-c=R,G,B] "
|
||||||
"[--var=R,G,B] "
|
"[-va=R,G,B] "
|
||||||
"[-m]\n\n"
|
"[-vr=VAR_RANGE] "
|
||||||
|
"[-r=ROTATION] "
|
||||||
|
"[-m]"
|
||||||
|
"\n\n"
|
||||||
"generate a marble-like pattern bitmap image, blazing fast.\n\n"
|
"generate a marble-like pattern bitmap image, blazing fast.\n\n"
|
||||||
"options:\n"
|
"options:\n"
|
||||||
" --help show this help message and exit\n"
|
" --help show this help message and exit\n"
|
||||||
@@ -29,13 +32,15 @@ void print_help(int status_code) {
|
|||||||
" -w, --width image width (default: 1920)\n"
|
" -w, --width image width (default: 1920)\n"
|
||||||
" -h, --height image height (default: 1080)\n"
|
" -h, --height image height (default: 1080)\n"
|
||||||
" -o, --output output file (default: output.bmp)\n"
|
" -o, --output output file (default: output.bmp)\n"
|
||||||
" -seed random seed (default: time based)\n"
|
" --seed random seed (default: time based)\n"
|
||||||
" -p, --pixel pixel size (default: random)\n"
|
" -p, --pixel pixel size (default: random)\n"
|
||||||
" -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: "
|
" -va, --variation fixed variation [0-255,0-255,0-255] (default: "
|
||||||
"random)\n"
|
"random)\n"
|
||||||
" -m, --monochrome black & white generation");
|
" -vr, --var-range random variation range [0-255] (default: 30)\n"
|
||||||
|
" -r, --rotation start corner rotation [0-3] (default: random)\n"
|
||||||
|
" -m, --monochrome grayscale generation\n");
|
||||||
exit(status_code);
|
exit(status_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +99,7 @@ unsigned short parse_ushort(char *arg, char *value) {
|
|||||||
return (unsigned short)tmp_value;
|
return (unsigned short)tmp_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned short parse_ulong(char *arg, char *value) {
|
unsigned long parse_ulong(char *arg, char *value) {
|
||||||
if (!is_number(value)) {
|
if (!is_number(value)) {
|
||||||
invalid_value(arg, value);
|
invalid_value(arg, value);
|
||||||
}
|
}
|
||||||
@@ -121,10 +126,13 @@ parameters parse_args(int argc, char **argv) {
|
|||||||
params.file_path = "output.bmp";
|
params.file_path = "output.bmp";
|
||||||
params.monochrome = false;
|
params.monochrome = false;
|
||||||
|
|
||||||
|
unsigned char var_range = 30;
|
||||||
|
|
||||||
bool size_set = false;
|
bool size_set = false;
|
||||||
bool slope_set = false;
|
bool slope_set = false;
|
||||||
bool start_set = false;
|
bool start_set = false;
|
||||||
bool var_set = false;
|
bool var_set = false;
|
||||||
|
bool rot_set = false;
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
char *arg;
|
char *arg;
|
||||||
@@ -137,7 +145,7 @@ parameters parse_args(int argc, char **argv) {
|
|||||||
} else if (is_arg(arg, "-q") || is_arg(arg, "--quiet")) {
|
} else if (is_arg(arg, "-q") || is_arg(arg, "--quiet")) {
|
||||||
params.quiet = true;
|
params.quiet = true;
|
||||||
} else if (is_arg(arg, "-v") || is_arg(arg, "--version")) {
|
} else if (is_arg(arg, "-v") || is_arg(arg, "--version")) {
|
||||||
puts(NAME " " VERSION);
|
puts(PACKAGE " " VERSION);
|
||||||
exit(0);
|
exit(0);
|
||||||
} else if (is_arg(arg, "-w") || is_arg(arg, "--width")) {
|
} else if (is_arg(arg, "-w") || is_arg(arg, "--width")) {
|
||||||
params.width = parse_ushort(arg, value);
|
params.width = parse_ushort(arg, value);
|
||||||
@@ -171,9 +179,14 @@ parameters parse_args(int argc, char **argv) {
|
|||||||
} else if (is_arg(arg, "-c") || is_arg(arg, "--color")) {
|
} else if (is_arg(arg, "-c") || is_arg(arg, "--color")) {
|
||||||
parse_color(arg, value, params.start);
|
parse_color(arg, value, params.start);
|
||||||
start_set = true;
|
start_set = true;
|
||||||
} else if (is_arg(arg, "-v") || is_arg(arg, "--variation")) {
|
} else if (is_arg(arg, "-va") || 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, "-vr") || is_arg(arg, "--var-range")) {
|
||||||
|
var_range = parse_char(arg, value);
|
||||||
|
} 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")) {
|
} else if (is_arg(arg, "-m") || is_arg(arg, "--monochrome")) {
|
||||||
params.monochrome = true;
|
params.monochrome = true;
|
||||||
} else {
|
} else {
|
||||||
@@ -189,7 +202,7 @@ parameters parse_args(int argc, char **argv) {
|
|||||||
set_seed(params.seed);
|
set_seed(params.seed);
|
||||||
|
|
||||||
if (!size_set) {
|
if (!size_set) {
|
||||||
params.size = rand_ushort(10) + 3;
|
params.size = rand_ushort(6) + 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!slope_set) {
|
if (!slope_set) {
|
||||||
@@ -203,9 +216,13 @@ parameters parse_args(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!var_set) {
|
if (!var_set) {
|
||||||
params.var[0] = rand_uchar(20);
|
params.var[0] = rand_uchar(var_range + 1);
|
||||||
params.var[1] = rand_uchar(20);
|
params.var[1] = rand_uchar(var_range + 1);
|
||||||
params.var[2] = rand_uchar(20);
|
params.var[2] = rand_uchar(var_range + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!rot_set) {
|
||||||
|
params.rotation = rand_uchar(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
return params;
|
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 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;
|
||||||
}
|
}
|
||||||
@@ -75,7 +88,7 @@ void bmp_data_line(unsigned char *buffer, unsigned short width,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void bmp_generate(unsigned short width, unsigned short height,
|
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) {
|
line_fn generate_line) {
|
||||||
FILE *fptr;
|
FILE *fptr;
|
||||||
fptr = fopen(file_path, "w");
|
fptr = fopen(file_path, "w");
|
||||||
@@ -84,14 +97,17 @@ void bmp_generate(unsigned short width, unsigned short height,
|
|||||||
free(header);
|
free(header);
|
||||||
unsigned int data_length =
|
unsigned int data_length =
|
||||||
((unsigned int)width) * ((unsigned int)color_depth);
|
((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 *data_buffer = (unsigned char *)malloc(data_length);
|
||||||
unsigned char *line_buffer =
|
unsigned char *line_buffer = (unsigned char *)malloc(line_length);
|
||||||
(unsigned char *)malloc(bmp_data_line_length(width, color_depth));
|
unsigned short y;
|
||||||
for (y = 0; y < height; 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);
|
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(line_buffer);
|
||||||
free(data_buffer);
|
free(data_buffer);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#define BMP_H
|
#define BMP_H
|
||||||
|
|
||||||
void bmp_generate(unsigned short width, unsigned short height,
|
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);
|
line_fn generate_line);
|
||||||
|
|
||||||
#endif
|
#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.1"
|
|
||||||
|
|
||||||
#endif
|
|
||||||
+26
-14
@@ -1,10 +1,12 @@
|
|||||||
#include "args.h"
|
#include "args.h"
|
||||||
#include "bmp.h"
|
#include "bmp.h"
|
||||||
#include "const.h"
|
#include "config.h"
|
||||||
#include "rand.h"
|
#include "rand.h"
|
||||||
#include <math.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#define BMP_COLOR_DEPTH 3
|
||||||
|
|
||||||
parameters global_params;
|
parameters global_params;
|
||||||
float slope;
|
float slope;
|
||||||
@@ -15,11 +17,10 @@ unsigned char *current_line;
|
|||||||
|
|
||||||
unsigned char generate_pixel(unsigned char depth, unsigned char top_pixel,
|
unsigned char generate_pixel(unsigned char depth, unsigned char top_pixel,
|
||||||
unsigned char left_pixel) {
|
unsigned char left_pixel) {
|
||||||
float v = fminf(
|
short k = rand_uchar(global_params.var[depth] + 1);
|
||||||
255.0, fmaxf(0.0, (rand_float(2.0) - 1.0) * global_params.var[depth] +
|
short v = (rand_uchar(2) == 0 ? k : -k) + (left_pixel)*slope +
|
||||||
((float)left_pixel) * slope +
|
(top_pixel) * (1.0 - slope);
|
||||||
((float)top_pixel) * (1.0 - slope)));
|
return (unsigned char)(v < 0 ? 0 : (v > 255 ? (unsigned char)255 : v));
|
||||||
return (unsigned char)v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void generate_line() {
|
void generate_line() {
|
||||||
@@ -42,12 +43,13 @@ 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;
|
||||||
if (y > 0 && (y % global_params.size) == 0) {
|
if (y % global_params.size == 0) {
|
||||||
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[i] = current_line[x * color_depth + (i % color_depth)];
|
data_buffer[(global_params.rotation / 2) == 1 ? i : (len - i - 1)] =
|
||||||
|
current_line[x * color_depth + (i % color_depth)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,6 +60,7 @@ 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);
|
||||||
|
printf(" slope %d\n", params.slope);
|
||||||
if (params.monochrome) {
|
if (params.monochrome) {
|
||||||
printf(" color %u\n", params.start[0]);
|
printf(" color %u\n", params.start[0]);
|
||||||
printf(" var. %u\n", params.var[0]);
|
printf(" var. %u\n", params.var[0]);
|
||||||
@@ -67,6 +70,7 @@ void debug_parameters(parameters params) {
|
|||||||
printf(" var. %u,%u,%u\n", params.var[0], params.var[1],
|
printf(" var. %u,%u,%u\n", params.var[0], params.var[1],
|
||||||
params.var[2]);
|
params.var[2]);
|
||||||
}
|
}
|
||||||
|
printf(" rot. %d\n", params.rotation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +87,6 @@ void init(parameters params) {
|
|||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void clean() {
|
void clean() {
|
||||||
@@ -91,12 +94,21 @@ void clean() {
|
|||||||
free(current_line);
|
free(current_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print_time(parameters params, clock_t start) {
|
||||||
|
if (!params.quiet) {
|
||||||
|
clock_t now = clock();
|
||||||
|
printf("time: %.3fs\n", (float)(now - start) / CLOCKS_PER_SEC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void generate(parameters params) {
|
void generate(parameters params) {
|
||||||
if (!params.quiet) {
|
if (!params.quiet) {
|
||||||
puts(NAME " " VERSION);
|
puts(PACKAGE " " VERSION);
|
||||||
}
|
}
|
||||||
|
clock_t start = clock();
|
||||||
init(params);
|
init(params);
|
||||||
bmp_generate(params.width, params.height, color_depth, params.file_path,
|
bmp_generate(params.width, params.height, BMP_COLOR_DEPTH,
|
||||||
generate_bmp_line);
|
params.rotation % 2 == 1, params.file_path, generate_bmp_line);
|
||||||
clean();
|
clean();
|
||||||
|
print_time(params, start);
|
||||||
}
|
}
|
||||||
+15
-11
@@ -1,21 +1,25 @@
|
|||||||
#include <math.h>
|
static unsigned long long mcg_state = 0xcafef00dd15ea5e5u; // Must be odd
|
||||||
|
static unsigned long long const multiplier = 6364136223846793005u;
|
||||||
|
|
||||||
float seed;
|
// https://en.wikipedia.org/wiki/Permuted_congruential_generator
|
||||||
|
unsigned long rand(void) {
|
||||||
|
unsigned long long x = mcg_state;
|
||||||
|
unsigned count = (unsigned)(x >> 61);
|
||||||
|
|
||||||
void set_seed(unsigned long new_seed) { seed = (float)(new_seed % 1000000); }
|
mcg_state = x * multiplier;
|
||||||
|
x ^= x >> 22;
|
||||||
float rand(float seed) {
|
return (unsigned long)(x >> (22 + count));
|
||||||
float v = powf(seed, 6. / 7.);
|
|
||||||
v *= sinf(v) + 1.;
|
|
||||||
return v - floorf(v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float rand_float(const float max) { return rand(seed++) * max; }
|
void set_seed(unsigned long long seed) {
|
||||||
|
mcg_state = 2 * seed + 1;
|
||||||
|
(void)rand();
|
||||||
|
}
|
||||||
|
|
||||||
unsigned char rand_uchar(const unsigned int max) {
|
unsigned char rand_uchar(const unsigned int max) {
|
||||||
return (unsigned char)(rand(seed++) * max);
|
return max == 0 ? 0 : (unsigned char)(rand() % max);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned short rand_ushort(const unsigned int max) {
|
unsigned short rand_ushort(const unsigned int max) {
|
||||||
return (unsigned short)(rand(seed++) * max);
|
return max == 0 ? 0 : (unsigned short)(rand() % max);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -1,8 +1,7 @@
|
|||||||
#ifndef RAND_H
|
#ifndef RAND_H
|
||||||
#define RAND_H
|
#define RAND_H
|
||||||
|
|
||||||
void set_seed(unsigned long new_seed);
|
void set_seed(unsigned long long seed);
|
||||||
float rand_float(const float max);
|
|
||||||
unsigned char rand_uchar(unsigned int max);
|
unsigned char rand_uchar(unsigned int max);
|
||||||
unsigned short rand_ushort(unsigned int max);
|
unsigned short rand_ushort(unsigned int max);
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ struct Parameters {
|
|||||||
unsigned char slope;
|
unsigned char slope;
|
||||||
unsigned char start[3];
|
unsigned char start[3];
|
||||||
unsigned char var[3];
|
unsigned char var[3];
|
||||||
|
unsigned char rotation;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct Parameters parameters;
|
typedef struct Parameters parameters;
|
||||||
|
|||||||
Reference in New Issue
Block a user