Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 489a08e102 | |||
| 4c8c587970 | |||
| fd1af94480 | |||
| a02e79d8af | |||
| dcf30ee389 | |||
| e79fa7fdd1 | |||
| 1ad17076a8 | |||
| c54e4efaec | |||
| e65cf7e37c | |||
| 8cc23ce9e6 | |||
| 3064501543 | |||
| 0efbcc092b | |||
| 6725ce9b2d | |||
| eb1136702b | |||
| 34a6ac328b | |||
| 1dec3e5ee9 | |||
| e383f84d29 | |||
| 9426f4267b | |||
| bb82ae6458 | |||
| 70c2f02b0b | |||
| 6670ed0167 | |||
| 101c5b6de6 | |||
| f1ba3b32dc | |||
| 01e2e5376b | |||
| 2a749714e5 | |||
| 259860e998 | |||
| 7b9ab384f1 | |||
| 06cc1749a3 | |||
| 3bb2b7d2f5 | |||
| 31135b023f | |||
| 604902b398 | |||
| 3a100080c2 | |||
| 7626f99e32 |
@@ -0,0 +1,16 @@
|
|||||||
|
# EditorConfig is awesome: https://EditorConfig.org
|
||||||
|
|
||||||
|
# top-most EditorConfig file
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
end_of_line = lf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[{Makefile.*,Makefile}]
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = 2
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
name: Clang Build CI
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: build-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
paths:
|
||||||
|
- '.github/workflows/build.yml'
|
||||||
|
- 'src/*.c'
|
||||||
|
- 'src/*.h'
|
||||||
|
- 'configure.ac'
|
||||||
|
- 'Makefile.am'
|
||||||
|
|
||||||
|
env:
|
||||||
|
GCC_ARGS: src/*.c src/*.h -Ofast
|
||||||
|
TARGET: margen
|
||||||
|
TEST_ARGS: ""
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: aclocal
|
||||||
|
run: aclocal
|
||||||
|
- name: autoconf
|
||||||
|
run: autoconf
|
||||||
|
- name: automake
|
||||||
|
run: automake --add-missing
|
||||||
|
- name: configure
|
||||||
|
run: ./configure
|
||||||
|
- name: make
|
||||||
|
run: make
|
||||||
|
- name: make distcheck
|
||||||
|
run: make distcheck
|
||||||
|
|
||||||
|
run:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
- name: gcc
|
||||||
|
run: mkdir -p build && gcc $GCC_ARGS -o build/$TARGET
|
||||||
|
- name: run program
|
||||||
|
run: ./build/$TARGET $TEST_ARGS
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
name: Clang Lint CI
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: lint-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
paths:
|
||||||
|
- '.github/workflows/lint.yml'
|
||||||
|
- 'src/*.c'
|
||||||
|
- 'src/*.h'
|
||||||
|
|
||||||
|
env:
|
||||||
|
GCC_ARGS: src/*.c src/*.h -Ofast
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
- name: gcc
|
||||||
|
run: gcc -v -Wall -Wextra -Werror $GCC_ARGS
|
||||||
+23
@@ -2,3 +2,26 @@ build
|
|||||||
.vscode
|
.vscode
|
||||||
*.bmp
|
*.bmp
|
||||||
!images/*
|
!images/*
|
||||||
|
*.cache
|
||||||
|
.deps
|
||||||
|
Makefile
|
||||||
|
*.log
|
||||||
|
*.o
|
||||||
|
*.h.gch
|
||||||
|
*.out
|
||||||
|
.dirstamp
|
||||||
|
aclocal.m4
|
||||||
|
compile
|
||||||
|
install-sh
|
||||||
|
missing
|
||||||
|
depcomp
|
||||||
|
Makefile.in
|
||||||
|
configure~
|
||||||
|
config.status
|
||||||
|
margen
|
||||||
|
*.tar.gz
|
||||||
|
configure
|
||||||
|
src/margen*
|
||||||
|
*.pkg.tar.zst
|
||||||
|
pkg
|
||||||
|
margen-*
|
||||||
|
|||||||
@@ -1,44 +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)
|
|
||||||
|
|
||||||
.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
|
|
||||||
|
|
||||||
.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,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,84 @@
|
|||||||
|
TARGET ?= margen
|
||||||
|
INSTALL_DIR ?= $(HOME)/.local/bin
|
||||||
|
TEST_ARGS ?=
|
||||||
|
SHELL := /bin/bash
|
||||||
|
|
||||||
|
.PHONY: build
|
||||||
|
clean:
|
||||||
|
@rm -rf build
|
||||||
|
|
||||||
|
build:
|
||||||
|
@mkdir -p build
|
||||||
|
gcc -Wall -Wextra -Og -g src/*.c src/*.h -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: clean
|
||||||
|
aclocal
|
||||||
|
autoconf
|
||||||
|
automake --add-missing
|
||||||
|
./configure
|
||||||
|
make distcheck
|
||||||
|
mkdir -p build
|
||||||
|
cp $(TARGET)-*.tar.gz build
|
||||||
|
@rm -rf \
|
||||||
|
autom4te.cache \
|
||||||
|
aclocal.m4 \
|
||||||
|
compile \
|
||||||
|
config.* \
|
||||||
|
configure \
|
||||||
|
depcomp \
|
||||||
|
$(TARGET) \
|
||||||
|
$(TARGET)-*.tar.gz \
|
||||||
|
$(TARGET)-*.pkg.tar.zst \
|
||||||
|
install-sh \
|
||||||
|
Makefile \
|
||||||
|
Makefile.in \
|
||||||
|
missing \
|
||||||
|
src/.* \
|
||||||
|
src/*.o
|
||||||
|
|
||||||
|
.PHONY: release
|
||||||
|
release-clean:
|
||||||
|
@rm -rf \
|
||||||
|
autom4te.cache \
|
||||||
|
aclocal.m4 \
|
||||||
|
compile \
|
||||||
|
config.* \
|
||||||
|
configure \
|
||||||
|
depcomp \
|
||||||
|
$(TARGET) \
|
||||||
|
$(TARGET)-*.tar.gz \
|
||||||
|
$(TARGET)-*.pkg.tar.zst \
|
||||||
|
install-sh \
|
||||||
|
Makefile \
|
||||||
|
Makefile.in \
|
||||||
|
missing \
|
||||||
|
src/.* \
|
||||||
|
src/*.o
|
||||||
|
|
||||||
|
.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/$(TARGET) -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.6
|
||||||
|
pkgrel=1
|
||||||
|
pkgdesc="Generate a marble-like pattern bitmap image, blazing fast."
|
||||||
|
arch=('i686' 'pentium4' 'x86_64' 'arm' 'armv7h' 'armv6h' 'aarch64' 'riscv64')
|
||||||
|
url="https://git.klemek.fr/klemek/margen"
|
||||||
|
source=("${pkgname}-${pkgver}.tar.gz::https://git.klemek.fr/klemek/margen/releases/download/v${pkgver}/${pkgname}-${pkgver}.tar.gz")
|
||||||
|
sha256sums=('e35368e963dbc81e94c4fab50cf2aa5d0f56caf6079e204ca4608eb9835670bc')
|
||||||
|
srcdir=build
|
||||||
|
|
||||||
|
build() {
|
||||||
|
cd "$srcdir/$pkgname-$pkgver"
|
||||||
|
./configure --prefix=/usr
|
||||||
|
make
|
||||||
|
}
|
||||||
|
|
||||||
|
package() {
|
||||||
|
cd "$srcdir/$pkgname-$pkgver"
|
||||||
|
sudo make DESTDIR="$pkgdir" install
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
[](https://git.klemek.fr/klemek/margen/actions?workflow=lint.yml) [](https://git.klemek.fr/klemek/margen/actions?workflow=build.yml)
|
||||||
|
|
||||||
# margen
|
# margen
|
||||||
|
|
||||||
> generate a marble-like pattern bitmap image, blazing fast.
|
> generate a marble-like pattern bitmap image, blazing fast.
|
||||||
@@ -10,13 +12,38 @@ Written in pure C without librairies.
|
|||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
You only need **gcc** and **make**.
|
### From release
|
||||||
|
|
||||||
```bash
|
See [Releases](https://git.klemek.fr/klemek/margen/releases)
|
||||||
git clone https://github.com/klemek/margen
|
|
||||||
|
```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://git.klemek.fr/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://git.klemek.fr/klemek/margen
|
||||||
|
cd margen
|
||||||
|
aclocal
|
||||||
|
autoconf
|
||||||
|
automake --add-missing
|
||||||
|
./configure
|
||||||
|
make
|
||||||
|
make install
|
||||||
```
|
```
|
||||||
|
|
||||||
## CLI arguments
|
## CLI arguments
|
||||||
@@ -28,11 +55,12 @@ generate a marble-like pattern bitmap image, blazing fast.
|
|||||||
|
|
||||||
options:
|
options:
|
||||||
--help show this help message and exit
|
--help show this help message and exit
|
||||||
|
-v, --version print version
|
||||||
-q, --quiet do not print to console
|
-q, --quiet do not print to console
|
||||||
-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)
|
||||||
@@ -42,6 +70,24 @@ options:
|
|||||||
-m, --monochrome grayscale generation
|
-m, --monochrome grayscale generation
|
||||||
```
|
```
|
||||||
|
|
||||||
## TODO
|
## Release guide
|
||||||
|
|
||||||
- configure, make, make install
|
```bash
|
||||||
|
# get latest version
|
||||||
|
git pull origin master
|
||||||
|
# update configure.ac with new version
|
||||||
|
$EDITOR configure.ac
|
||||||
|
# make full build
|
||||||
|
make -f Makefile.dev release
|
||||||
|
# update PKGBUILD with new version and sha256 sum
|
||||||
|
sha256sum build/margen-x.y.z.tar.gz
|
||||||
|
$EDITOR PKGBUILD
|
||||||
|
# push to repo
|
||||||
|
git commit -am "margen vX.Y.Z"
|
||||||
|
git tag vX.Y.Z -m "margen vX.Y.Z"
|
||||||
|
git push origin master --tags
|
||||||
|
# create release from tag on github
|
||||||
|
# attach .tar.gz to the github release
|
||||||
|
make -f Makefile.dev release-arch
|
||||||
|
# attach .pkg.tar.zst to the github release
|
||||||
|
```
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
AC_INIT([margen], [1.2.6], [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([limits.h])
|
||||||
|
AC_CONFIG_FILES([Makefile])
|
||||||
|
AC_OUTPUT
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 7.6 MiB After Width: | Height: | Size: 8.1 MiB |
+70
-68
@@ -1,38 +1,43 @@
|
|||||||
#include "args.h"
|
#include <limits.h>
|
||||||
#include "const.h"
|
#include <stdbool.h>
|
||||||
#include "rand.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
void print_help(int status_code) {
|
#include "args.h"
|
||||||
puts(NAME
|
#include "config.h"
|
||||||
|
#include "rand.h"
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
static void print_help(int status_code) {
|
||||||
|
puts(PACKAGE
|
||||||
" " VERSION "\n\n"
|
" " VERSION "\n\n"
|
||||||
"usage: " NAME " "
|
"usage: " PACKAGE " "
|
||||||
"[--help] "
|
"[--help] "
|
||||||
"[-v] "
|
"[-v] "
|
||||||
"[-q] "
|
"[-q] "
|
||||||
"[-w=WIDTH] "
|
"[-w=WIDTH] "
|
||||||
"[-h=HEIGHT] "
|
"[-h=HEIGHT] "
|
||||||
"[-o=PATH] "
|
"[-o=PATH] "
|
||||||
"[--seed=SEED]"
|
"[--seed=SEED] "
|
||||||
"[-p=PIXEL_SIZE] "
|
"[-p=PIXEL_SIZE] "
|
||||||
"[-s=SLOPE] "
|
"[-s=SLOPE] "
|
||||||
"[-c=R,G,B] "
|
"[-c=R,G,B] "
|
||||||
"[-va=R,G,B] "
|
"[-va=R,G,B] "
|
||||||
"[-vr=VAR_RANGE] "
|
"[-vr=VAR_RANGE] "
|
||||||
"[-r=ROTATION] "
|
"[-r=ROTATION] "
|
||||||
// "[-m]"
|
"[-m]"
|
||||||
"\n\n"
|
"\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"
|
||||||
|
" -v, --version print version\n"
|
||||||
" -q, --quiet do not print to console\n"
|
" -q, --quiet do not print to console\n"
|
||||||
" -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"
|
||||||
@@ -44,80 +49,80 @@ void print_help(int status_code) {
|
|||||||
exit(status_code);
|
exit(status_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
void invalid_arg(char *arg) {
|
static void invalid_arg(char *arg) {
|
||||||
fprintf(stderr, "invalid argument: '%s'\n\n", arg);
|
fprintf(stderr, "invalid argument: '%s'\n\n", arg);
|
||||||
print_help(1);
|
print_help(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void invalid_value(char *arg, char *value) {
|
static void invalid_value(char *arg, char *value) {
|
||||||
fprintf(stderr, "invalid value for argument '%s': '%s'\n\n", arg, value);
|
fprintf(stderr, "invalid value for argument '%s': '%s'\n\n", arg, value);
|
||||||
print_help(1);
|
print_help(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_arg(char *arg, char *ref) { return strcoll(arg, ref) == 0; }
|
static bool is_arg(char *arg, char *ref) { return strcoll(arg, ref) == 0; }
|
||||||
|
|
||||||
char *split_arg_value(char *arg) {
|
static char *split_arg_value(char *arg) {
|
||||||
strtok(arg, "=");
|
strtok(arg, "=");
|
||||||
return strtok(NULL, "=");
|
return strtok(NULL, "=");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_digit(char c) { return c >= '0' && c <= '9'; }
|
static bool is_digit(char c) { return c >= '0' && c <= '9'; }
|
||||||
|
|
||||||
|
static bool is_number(char *value) {
|
||||||
|
unsigned long value_len;
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
bool is_number(char *value) {
|
|
||||||
if (value == NULL) {
|
if (value == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
unsigned long value_len = strlen(value);
|
value_len = strlen(value);
|
||||||
int i;
|
|
||||||
for (i = 0; i < value_len; i++) {
|
for (i = 0; i < value_len; i++) {
|
||||||
if (!is_digit(value[i])) {
|
if (!is_digit(value[i])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char parse_char(char *arg, char *value) {
|
static unsigned int parse_uint(char *arg, char *value) {
|
||||||
|
unsigned long long tmp_value;
|
||||||
|
|
||||||
if (!is_number(value)) {
|
if (!is_number(value)) {
|
||||||
invalid_value(arg, value);
|
invalid_value(arg, value);
|
||||||
}
|
}
|
||||||
unsigned long long tmp_value = (unsigned long long)atoll(value);
|
tmp_value = (unsigned long long)atoll(value);
|
||||||
if (tmp_value >= 256) {
|
if (tmp_value >= UINT_MAX) {
|
||||||
invalid_value(arg, value);
|
invalid_value(arg, value);
|
||||||
}
|
}
|
||||||
return (unsigned char)tmp_value;
|
|
||||||
|
return (unsigned int)tmp_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned short parse_ushort(char *arg, char *value) {
|
static unsigned long parse_ulong(char *arg, char *value) {
|
||||||
if (!is_number(value)) {
|
|
||||||
invalid_value(arg, value);
|
|
||||||
}
|
|
||||||
unsigned long long tmp_value = (unsigned long long)atoll(value);
|
|
||||||
if (tmp_value >= 65536) {
|
|
||||||
invalid_value(arg, value);
|
|
||||||
}
|
|
||||||
return (unsigned short)tmp_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned short parse_ulong(char *arg, char *value) {
|
|
||||||
if (!is_number(value)) {
|
if (!is_number(value)) {
|
||||||
invalid_value(arg, value);
|
invalid_value(arg, value);
|
||||||
}
|
}
|
||||||
return (unsigned long)atoll(value);
|
return (unsigned long)atoll(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse_color(char *arg, char *value, unsigned char color[3]) {
|
static void parse_color(char *arg, char *value, unsigned int color[3]) {
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
tmp = strtok(value, ",");
|
tmp = strtok(value, ",");
|
||||||
color[0] = parse_char(arg, tmp);
|
color[0] = parse_uint(arg, tmp);
|
||||||
tmp = strtok(NULL, ",");
|
tmp = strtok(NULL, ",");
|
||||||
color[1] = parse_char(arg, tmp);
|
color[1] = parse_uint(arg, tmp);
|
||||||
tmp = strtok(NULL, ",");
|
tmp = strtok(NULL, ",");
|
||||||
color[2] = parse_char(arg, tmp);
|
color[2] = parse_uint(arg, tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
parameters parse_args(int argc, char **argv) {
|
Parameters args_parse(int argc, char **argv) {
|
||||||
parameters params;
|
Parameters params;
|
||||||
|
unsigned char var_range;
|
||||||
|
bool size_set, slope_set, start_set, var_set, rot_set;
|
||||||
|
int i;
|
||||||
|
char *arg, *value;
|
||||||
|
|
||||||
params.quiet = false;
|
params.quiet = false;
|
||||||
params.seed = (unsigned long)time(NULL);
|
params.seed = (unsigned long)time(NULL);
|
||||||
@@ -126,29 +131,26 @@ 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;
|
var_range = 30;
|
||||||
|
|
||||||
bool size_set = false;
|
size_set = false;
|
||||||
bool slope_set = false;
|
slope_set = false;
|
||||||
bool start_set = false;
|
start_set = false;
|
||||||
bool var_set = false;
|
var_set = false;
|
||||||
bool rot_set = false;
|
rot_set = false;
|
||||||
|
|
||||||
int i;
|
|
||||||
char *arg;
|
|
||||||
char *value;
|
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
arg = argv[i];
|
arg = argv[i];
|
||||||
value = split_arg_value(arg);
|
value = split_arg_value(arg);
|
||||||
if (is_arg(arg, "--help")) {
|
if (is_arg(arg, "--help")) {
|
||||||
print_help(0);
|
print_help(EXIT_SUCCESS);
|
||||||
} 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_uint(arg, value);
|
||||||
if (params.width == 0) {
|
if (params.width == 0) {
|
||||||
invalid_value(arg, value);
|
invalid_value(arg, value);
|
||||||
}
|
}
|
||||||
@@ -156,7 +158,7 @@ parameters parse_args(int argc, char **argv) {
|
|||||||
params.height = params.width;
|
params.height = params.width;
|
||||||
}
|
}
|
||||||
} else if (is_arg(arg, "-h") || is_arg(arg, "--height")) {
|
} else if (is_arg(arg, "-h") || is_arg(arg, "--height")) {
|
||||||
params.height = parse_ushort(arg, value);
|
params.height = parse_uint(arg, value);
|
||||||
if (params.height == 0) {
|
if (params.height == 0) {
|
||||||
invalid_value(arg, value);
|
invalid_value(arg, value);
|
||||||
}
|
}
|
||||||
@@ -168,13 +170,13 @@ parameters parse_args(int argc, char **argv) {
|
|||||||
} else if (is_arg(arg, "-o") || is_arg(arg, "--output")) {
|
} else if (is_arg(arg, "-o") || is_arg(arg, "--output")) {
|
||||||
params.file_path = value;
|
params.file_path = value;
|
||||||
} else if (is_arg(arg, "-p") || is_arg(arg, "--pixel")) {
|
} else if (is_arg(arg, "-p") || is_arg(arg, "--pixel")) {
|
||||||
params.size = parse_ushort(arg, value);
|
params.size = parse_uint(arg, value);
|
||||||
if (params.size == 0) {
|
if (params.size == 0) {
|
||||||
invalid_value(arg, value);
|
invalid_value(arg, value);
|
||||||
}
|
}
|
||||||
size_set = true;
|
size_set = true;
|
||||||
} else if (is_arg(arg, "-s") || is_arg(arg, "--slope")) {
|
} else if (is_arg(arg, "-s") || is_arg(arg, "--slope")) {
|
||||||
params.slope = parse_char(arg, value);
|
params.slope = parse_uint(arg, value);
|
||||||
slope_set = true;
|
slope_set = true;
|
||||||
} 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);
|
||||||
@@ -183,9 +185,9 @@ parameters parse_args(int argc, char **argv) {
|
|||||||
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")) {
|
} else if (is_arg(arg, "-vr") || is_arg(arg, "--var-range")) {
|
||||||
var_range = parse_char(arg, value);
|
var_range = parse_uint(arg, value);
|
||||||
} else if (is_arg(arg, "-r") || is_arg(arg, "--rotation")) {
|
} else if (is_arg(arg, "-r") || is_arg(arg, "--rotation")) {
|
||||||
params.rotation = parse_char(arg, value) % 4;
|
params.rotation = parse_uint(arg, value) % 4;
|
||||||
rot_set = true;
|
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;
|
||||||
@@ -199,30 +201,30 @@ parameters parse_args(int argc, char **argv) {
|
|||||||
params.height = 1080;
|
params.height = 1080;
|
||||||
}
|
}
|
||||||
|
|
||||||
set_seed(params.seed);
|
rand_seed(params.seed);
|
||||||
|
|
||||||
if (!size_set) {
|
if (!size_set) {
|
||||||
params.size = rand_ushort(6) + 6;
|
params.size = rand_uint(6) + 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!slope_set) {
|
if (!slope_set) {
|
||||||
params.slope = rand_uchar(50) + 100;
|
params.slope = rand_uint(50) + 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!start_set) {
|
if (!start_set) {
|
||||||
params.start[0] = rand_uchar(256);
|
params.start[0] = rand_uint(256);
|
||||||
params.start[1] = rand_uchar(256);
|
params.start[1] = rand_uint(256);
|
||||||
params.start[2] = rand_uchar(256);
|
params.start[2] = rand_uint(256);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!var_set) {
|
if (!var_set) {
|
||||||
params.var[0] = rand_uchar(var_range);
|
params.var[0] = rand_uint(var_range + 1);
|
||||||
params.var[1] = rand_uchar(var_range);
|
params.var[1] = rand_uint(var_range + 1);
|
||||||
params.var[2] = rand_uchar(var_range);
|
params.var[2] = rand_uint(var_range + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rot_set) {
|
if (!rot_set) {
|
||||||
params.rotation = rand_uchar(4);
|
params.rotation = rand_uint(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
return params;
|
return params;
|
||||||
|
|||||||
+1
-1
@@ -3,6 +3,6 @@
|
|||||||
#ifndef ARGS_H
|
#ifndef ARGS_H
|
||||||
#define ARGS_H
|
#define ARGS_H
|
||||||
|
|
||||||
parameters parse_args(int argc, char **argv);
|
Parameters args_parse(int argc, char **argv);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,37 +1,45 @@
|
|||||||
#include "bmp.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "bmp.h"
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
#define HEADER_SIZE 54
|
#define HEADER_SIZE 54
|
||||||
|
|
||||||
void write_str(unsigned char *buffer, unsigned int offset, unsigned int size,
|
static void write_str(unsigned char *buffer, unsigned int offset,
|
||||||
unsigned char *value) {
|
unsigned int size, unsigned char *value) {
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i < size; i++) {
|
for (i = 0; i < size; i++) {
|
||||||
buffer[offset + i] = (unsigned char)value[i];
|
buffer[offset + i] = (unsigned char)value[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_num(unsigned char *buffer, unsigned int offset, unsigned int size,
|
static void write_num(unsigned char *buffer, unsigned int offset,
|
||||||
unsigned int value) {
|
unsigned int size, unsigned int value) {
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i < size; i++) {
|
for (i = 0; i < size; i++) {
|
||||||
buffer[offset + i] = (unsigned char)((value >> (8 * i)) & 0xFFu);
|
buffer[offset + i] = (unsigned char)((value >> (8 * i)) & 0xFFu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_nul(unsigned char *buffer, unsigned int offset, unsigned int size) {
|
static void write_nul(unsigned char *buffer, unsigned int offset,
|
||||||
|
unsigned int size) {
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i < size; i++) {
|
for (i = 0; i < size; i++) {
|
||||||
buffer[offset + i] = 0;
|
buffer[offset + i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *bmp_header(unsigned short width, unsigned short height,
|
static unsigned char *bmp_header(unsigned int width, unsigned int height,
|
||||||
unsigned char color_depth) {
|
unsigned int color_depth) {
|
||||||
unsigned char *output = (unsigned char *)malloc(HEADER_SIZE);
|
unsigned char *output;
|
||||||
unsigned int data_length = ((unsigned int)width) * ((unsigned int)height) *
|
unsigned int data_length;
|
||||||
((unsigned int)color_depth);
|
|
||||||
|
output = malloc(HEADER_SIZE * sizeof(unsigned char));
|
||||||
|
data_length = width * height * color_depth;
|
||||||
// 0x00(2) BM
|
// 0x00(2) BM
|
||||||
write_str(output, 0x00, 0x02, (unsigned char *)"BM");
|
write_str(output, 0x00, 0x02, (unsigned char *)"BM");
|
||||||
// 0x02(4) file size
|
// 0x02(4) file size
|
||||||
@@ -66,41 +74,45 @@ unsigned char *bmp_header(unsigned short width, unsigned short height,
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int bmp_data_line_length(unsigned short width,
|
static unsigned int bmp_data_line_length(unsigned int width,
|
||||||
unsigned char color_depth) {
|
unsigned int color_depth) {
|
||||||
unsigned int data_length =
|
unsigned int data_length, line_offset, line_padding;
|
||||||
((unsigned int)width) * ((unsigned int)color_depth);
|
|
||||||
unsigned int line_offset = data_length % 4;
|
data_length = width * color_depth;
|
||||||
unsigned short line_padding = line_offset > 0 ? 4 - line_offset : 0;
|
line_offset = data_length % 4;
|
||||||
|
line_padding = line_offset > 0 ? 4 - line_offset : 0;
|
||||||
|
|
||||||
return data_length + line_padding;
|
return data_length + line_padding;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bmp_data_line(unsigned char *buffer, unsigned short width,
|
static void bmp_data_line(unsigned char *buffer, unsigned int width,
|
||||||
unsigned char color_depth, unsigned char *data) {
|
unsigned int color_depth, unsigned char *data) {
|
||||||
unsigned int data_length =
|
unsigned int data_length, line_offset, line_padding;
|
||||||
((unsigned int)width) * ((unsigned int)color_depth);
|
|
||||||
unsigned int line_offset = data_length % 4;
|
data_length = width * color_depth;
|
||||||
unsigned short line_padding = line_offset > 0 ? 4 - line_offset : 0;
|
line_offset = data_length % 4;
|
||||||
|
line_padding = line_offset > 0 ? 4 - line_offset : 0;
|
||||||
write_str(buffer, 0, data_length, data);
|
write_str(buffer, 0, data_length, data);
|
||||||
if (line_padding > 0) {
|
if (line_padding > 0) {
|
||||||
write_nul(buffer, width * color_depth, line_padding);
|
write_nul(buffer, width * color_depth, line_padding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void bmp_generate(unsigned short width, unsigned short height,
|
void bmp_generate(unsigned int width, unsigned int height,
|
||||||
unsigned char color_depth, bool descending, char *file_path,
|
unsigned int color_depth, bool descending, char *file_path,
|
||||||
line_fn generate_line) {
|
line_fn generate_line) {
|
||||||
FILE *fptr;
|
FILE *fptr;
|
||||||
|
unsigned char *header, *data_buffer, *line_buffer;
|
||||||
|
unsigned int data_length, line_length, y;
|
||||||
|
|
||||||
fptr = fopen(file_path, "w");
|
fptr = fopen(file_path, "w");
|
||||||
unsigned char *header = bmp_header(width, height, color_depth);
|
header = bmp_header(width, height, color_depth);
|
||||||
fwrite(header, HEADER_SIZE, 1, fptr);
|
fwrite(header, HEADER_SIZE, 1, fptr);
|
||||||
free(header);
|
free(header);
|
||||||
unsigned int data_length =
|
data_length = width * color_depth;
|
||||||
((unsigned int)width) * ((unsigned int)color_depth);
|
line_length = bmp_data_line_length(width, color_depth);
|
||||||
unsigned int line_length = bmp_data_line_length(width, color_depth);
|
data_buffer = malloc(data_length * sizeof(unsigned char));
|
||||||
unsigned char *data_buffer = (unsigned char *)malloc(data_length);
|
line_buffer = malloc(line_length * sizeof(unsigned char));
|
||||||
unsigned char *line_buffer = (unsigned char *)malloc(line_length);
|
|
||||||
unsigned short y;
|
|
||||||
for (y = 0; y < height; y++) {
|
for (y = 0; y < height; y++) {
|
||||||
generate_line(y, 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);
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
#ifndef BMP_H
|
#ifndef BMP_H
|
||||||
#define BMP_H
|
#define BMP_H
|
||||||
|
|
||||||
void bmp_generate(unsigned short width, unsigned short height,
|
void bmp_generate(unsigned int width, unsigned int height,
|
||||||
unsigned char color_depth, bool descending, char *file_path,
|
unsigned int 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.1.0"
|
|
||||||
|
|
||||||
#endif
|
|
||||||
+39
-30
@@ -1,32 +1,36 @@
|
|||||||
#include "args.h"
|
|
||||||
#include "bmp.h"
|
|
||||||
#include "const.h"
|
|
||||||
#include "rand.h"
|
|
||||||
#include <math.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "args.h"
|
||||||
|
#include "bmp.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include "rand.h"
|
||||||
|
|
||||||
#define BMP_COLOR_DEPTH 3
|
#define BMP_COLOR_DEPTH 3
|
||||||
|
|
||||||
parameters global_params;
|
static Parameters global_params;
|
||||||
float slope;
|
static float slope;
|
||||||
unsigned char color_depth;
|
static unsigned char color_depth;
|
||||||
unsigned int line_width;
|
static unsigned int line_width;
|
||||||
unsigned char *last_line;
|
static unsigned char *last_line;
|
||||||
unsigned char *current_line;
|
static unsigned char *current_line;
|
||||||
|
|
||||||
unsigned char generate_pixel(unsigned char depth, unsigned char top_pixel,
|
static unsigned char generate_pixel(unsigned char depth,
|
||||||
|
unsigned char top_pixel,
|
||||||
unsigned char left_pixel) {
|
unsigned char left_pixel) {
|
||||||
float v = fminf(
|
int k, v;
|
||||||
255.0, fmaxf(0.0, (rand_float(2.0) - 1.0) * global_params.var[depth] +
|
|
||||||
((float)left_pixel) * slope +
|
k = rand_uint(global_params.var[depth] + 1);
|
||||||
((float)top_pixel) * (1.0 - slope)));
|
v = (rand_uint(2) == 0 ? k : -k) + (left_pixel)*slope +
|
||||||
return (unsigned char)v;
|
(top_pixel) * (1.0 - slope);
|
||||||
|
|
||||||
|
return (unsigned char)(v < 0 ? 0 : (v > 255 ? (unsigned char)255 : v));
|
||||||
}
|
}
|
||||||
|
|
||||||
void generate_line() {
|
static void generate_line() {
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i < line_width; i++) {
|
for (i = 0; i < line_width; i++) {
|
||||||
last_line[i] = current_line[i];
|
last_line[i] = current_line[i];
|
||||||
}
|
}
|
||||||
@@ -41,10 +45,11 @@ void generate_line() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void generate_bmp_line(unsigned short y, unsigned char *data_buffer,
|
static void generate_bmp_line(unsigned int 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 % global_params.size == 0) {
|
if (y % global_params.size == 0) {
|
||||||
generate_line();
|
generate_line();
|
||||||
}
|
}
|
||||||
@@ -55,13 +60,14 @@ void generate_bmp_line(unsigned short y, unsigned char *data_buffer,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void debug_parameters(parameters params) {
|
static void debug_parameters(Parameters params) {
|
||||||
if (!params.quiet) {
|
if (!params.quiet) {
|
||||||
printf(" output %s\n", params.file_path);
|
printf(" output %s\n", params.file_path);
|
||||||
printf(" seed %ld\n", params.seed);
|
printf(" seed %ld\n", params.seed);
|
||||||
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]);
|
||||||
@@ -75,38 +81,41 @@ void debug_parameters(parameters params) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void init(parameters params) {
|
static void init(Parameters params) {
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
global_params = params;
|
global_params = params;
|
||||||
slope = ((float)params.slope) / 255.0;
|
slope = ((float)params.slope) / 255.0;
|
||||||
color_depth = params.monochrome ? 1 : 3;
|
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 = malloc(line_width * sizeof(unsigned char));
|
||||||
current_line = (unsigned char *)malloc(line_width);
|
current_line = malloc(line_width * sizeof(unsigned char));
|
||||||
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);
|
rand_seed(params.seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clean() {
|
static void clean() {
|
||||||
free(last_line);
|
free(last_line);
|
||||||
free(current_line);
|
free(current_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_time(parameters params, clock_t start) {
|
static void print_time(Parameters params, clock_t start) {
|
||||||
if (!params.quiet) {
|
if (!params.quiet) {
|
||||||
clock_t now = clock();
|
clock_t now = clock();
|
||||||
printf("time: %.3fs\n", (float)(now - start) / CLOCKS_PER_SEC);
|
printf("time: %.3fs\n", (float)(now - start) / CLOCKS_PER_SEC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void generate(parameters params) {
|
void generator_run(Parameters params) {
|
||||||
|
clock_t start;
|
||||||
|
|
||||||
if (!params.quiet) {
|
if (!params.quiet) {
|
||||||
puts(NAME " " VERSION);
|
puts(PACKAGE " " VERSION);
|
||||||
}
|
}
|
||||||
clock_t start = clock();
|
start = clock();
|
||||||
init(params);
|
init(params);
|
||||||
bmp_generate(params.width, params.height, BMP_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);
|
||||||
|
|||||||
+1
-1
@@ -3,6 +3,6 @@
|
|||||||
#ifndef GENERATOR_H
|
#ifndef GENERATOR_H
|
||||||
#define GENERATOR_H
|
#define GENERATOR_H
|
||||||
|
|
||||||
void generate(parameters params);
|
void generator_run(Parameters params);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+10
-4
@@ -1,9 +1,15 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "args.h"
|
#include "args.h"
|
||||||
#include "generator.h"
|
#include "generator.h"
|
||||||
|
#include "main.h"
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
parameters params;
|
Parameters params;
|
||||||
params = parse_args(argc, argv);
|
|
||||||
generate(params);
|
params = args_parse(argc, argv);
|
||||||
return 0;
|
generator_run(params);
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
#ifndef MAIN_H
|
#ifndef MAIN_H
|
||||||
#define MAIN_H
|
#define MAIN_H
|
||||||
|
|
||||||
|
int main(int argc, char **argv);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+19
-13
@@ -1,21 +1,27 @@
|
|||||||
#include <math.h>
|
#include "rand.h"
|
||||||
|
|
||||||
float seed;
|
static unsigned long long mcg_state = 0xcafef00dd15ea5e5u; // Must be odd
|
||||||
|
static unsigned long long const multiplier = 6364136223846793005u;
|
||||||
|
|
||||||
void set_seed(unsigned long new_seed) { seed = (float)(new_seed % 1000000); }
|
// https://en.wikipedia.org/wiki/Permuted_congruential_generator
|
||||||
|
static unsigned long rand(void) {
|
||||||
|
unsigned long long x;
|
||||||
|
unsigned count;
|
||||||
|
|
||||||
float rand(float seed) {
|
x = mcg_state;
|
||||||
float v = powf(seed, 6. / 7.);
|
count = (unsigned)(x >> 61);
|
||||||
v *= sinf(v) + 1.;
|
|
||||||
return v - floorf(v);
|
mcg_state = x * multiplier;
|
||||||
|
x ^= x >> 22;
|
||||||
|
|
||||||
|
return (unsigned long)(x >> (22 + count));
|
||||||
}
|
}
|
||||||
|
|
||||||
float rand_float(const float max) { return rand(seed++) * max; }
|
void rand_seed(unsigned long long seed) {
|
||||||
|
mcg_state = 2 * seed + 1;
|
||||||
unsigned char rand_uchar(const unsigned int max) {
|
(void)rand();
|
||||||
return (unsigned char)(rand(seed++) * max);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned short rand_ushort(const unsigned int max) {
|
unsigned int rand_uint(unsigned int max) {
|
||||||
return (unsigned short)(rand(seed++) * max);
|
return max == 0 ? 0 : (unsigned int)(rand() % max);
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-4
@@ -1,9 +1,7 @@
|
|||||||
#ifndef RAND_H
|
#ifndef RAND_H
|
||||||
#define RAND_H
|
#define RAND_H
|
||||||
|
|
||||||
void set_seed(unsigned long new_seed);
|
void rand_seed(unsigned long long seed);
|
||||||
float rand_float(const float max);
|
unsigned int rand_uint(unsigned int max);
|
||||||
unsigned char rand_uchar(unsigned int max);
|
|
||||||
unsigned short rand_ushort(unsigned int max);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+10
-12
@@ -3,23 +3,21 @@
|
|||||||
#ifndef TYPES_H
|
#ifndef TYPES_H
|
||||||
#define TYPES_H
|
#define TYPES_H
|
||||||
|
|
||||||
struct Parameters {
|
typedef struct Parameters {
|
||||||
bool quiet;
|
bool quiet;
|
||||||
bool monochrome;
|
bool monochrome;
|
||||||
unsigned long seed;
|
unsigned long seed;
|
||||||
unsigned short width;
|
unsigned int width;
|
||||||
unsigned short height;
|
unsigned int height;
|
||||||
char *file_path;
|
char *file_path;
|
||||||
unsigned short size;
|
unsigned int size;
|
||||||
unsigned char slope;
|
unsigned int slope;
|
||||||
unsigned char start[3];
|
unsigned int start[3];
|
||||||
unsigned char var[3];
|
unsigned int var[3];
|
||||||
unsigned char rotation;
|
unsigned int rotation;
|
||||||
};
|
} Parameters;
|
||||||
|
|
||||||
typedef struct Parameters parameters;
|
typedef void line_fn(unsigned int y, unsigned char *data_buffer,
|
||||||
|
|
||||||
typedef void line_fn(unsigned short y, unsigned char *data_buffer,
|
|
||||||
unsigned int len);
|
unsigned int len);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user