10 Commits

Author SHA1 Message Date
klemek 01e2e5376b margen v1.2.2 2025-07-03 12:14:01 +02:00
klemek 2a749714e5 fix seed parsing and help text 2025-07-03 12:12:50 +02:00
klemek 259860e998 PKGBUILD 2025-06-06 00:00:18 +02:00
klemek 7b9ab384f1 new gif 2025-06-05 17:54:45 +02:00
klemek 06cc1749a3 margen v1.2.1 2025-06-05 17:52:37 +02:00
klemek 3bb2b7d2f5 feat: remove math (#11)
* feat: remove math

* working

* remove unused stdint

* small fix
2025-06-05 17:52:02 +02:00
klemek 31135b023f remove configure for dev 2025-06-05 15:27:23 +02:00
klemek 604902b398 clear install 2025-06-05 15:23:09 +02:00
klemek 3a100080c2 margen v1.2.0 2025-06-05 15:06:58 +02:00
klemek 7626f99e32 feat: autotools (#10)
* start configure

* ignore some files

* wip configure

* working configure

* working with dev tools

* rename automake -> release

* update readme

* update Makefile.dev
2025-06-05 15:06:06 +02:00
13 changed files with 137 additions and 58 deletions
+21 -1
View File
@@ -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
+4
View File
@@ -0,0 +1,4 @@
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
+7 -10
View File
@@ -24,15 +24,12 @@ valgrind: build
valgrind --leak-check=full -s ./build/$(TARGET) $(TEST_ARGS) valgrind --leak-check=full -s ./build/$(TARGET) $(TEST_ARGS)
.PHONY: release .PHONY: release
release: clean build time release:
@echo -n "Version (x.y.z): " aclocal
@read VERSION; \ autoconf
sed -i "s/#define VERSION.*/#define VERSION \"v$$VERSION\"/g" ./src/const.h; \ automake --add-missing
git add ./src/const.h; \ ./configure
git diff origin/master; \ make distcheck
git commit -m "$(TARGET) v$$VERSION"; \
git tag v$$VERSION -m "$(TARGET) v$$VERSION"
@echo updated ./src/const.h and tagged version
.PHONY: gif .PHONY: gif
gif: build gif: build
@@ -41,4 +38,4 @@ gif: build
./build/margen -w=1920 -h=720 --seed=$$i$$i -o=tmp/image$$i.bmp ; \ ./build/margen -w=1920 -h=720 --seed=$$i$$i -o=tmp/image$$i.bmp ; \
done done
ffmpeg -y -f image2 -framerate 1 -i tmp/image%d.bmp -vf scale=960x360 images/sample.gif ffmpeg -y -f image2 -framerate 1 -i tmp/image%d.bmp -vf scale=960x360 images/sample.gif
rm -rf tmp rm -rf tmp
+20
View File
@@ -0,0 +1,20 @@
pkgname=margen
pkgver=1.2.2
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=('41523e3c1250c4026e4914e757c4e137397d115568ed3f72691631ddd97777a1')
srcdir=build
build() {
cd "$srcdir/$pkgname-$pkgver"
./configure --prefix=/usr
make
}
package() {
cd "$srcdir/$pkgname-$pkgver"
sudo make DESTDIR="$pkgdir" install
}
+30 -9
View File
@@ -10,13 +10,38 @@ 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 PKGBrepository (PKGBUILD)
```sh
git clone https://github.com/klemek/margen git clone https://github.com/klemek/margen
cd margen cd margen
make clean build install pkbuild -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
@@ -32,7 +57,7 @@ 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)
@@ -41,7 +66,3 @@ options:
-r, --rotation start corner rotation [0-3] (default: random) -r, --rotation start corner rotation [0-3] (default: random)
-m, --monochrome grayscale generation -m, --monochrome grayscale generation
``` ```
## TODO
- configure, make, make install
+10
View File
@@ -0,0 +1,10 @@
AC_INIT([margen], [1.2.2], [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
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.6 MiB

After

Width:  |  Height:  |  Size: 8.1 MiB

+10 -10
View File
@@ -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] "
@@ -23,7 +23,7 @@ void print_help(int status_code) {
"[-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"
@@ -32,7 +32,7 @@ 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"
@@ -99,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);
} }
@@ -145,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);
@@ -216,9 +216,9 @@ parameters parse_args(int argc, char **argv) {
} }
if (!var_set) { if (!var_set) {
params.var[0] = rand_uchar(var_range); params.var[0] = rand_uchar(var_range + 1);
params.var[1] = rand_uchar(var_range); params.var[1] = rand_uchar(var_range + 1);
params.var[2] = rand_uchar(var_range); params.var[2] = rand_uchar(var_range + 1);
} }
if (!rot_set) { if (!rot_set) {
+12
View File
@@ -0,0 +1,12 @@
#ifndef CONFIG_H
#define CONFIG_H
#ifndef PACKAGE
#define PACKAGE "margen"
#endif
#ifndef VERSION
#define VERSION "(dev)"
#endif
#endif
-7
View File
@@ -1,7 +0,0 @@
#ifndef CONST_H
#define CONST_H
#define NAME "margen"
#define VERSION "v1.1.0"
#endif
+7 -8
View File
@@ -1,8 +1,7 @@
#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> #include <time.h>
@@ -18,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() {
@@ -62,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]);
@@ -104,7 +103,7 @@ void print_time(parameters params, clock_t start) {
void generate(parameters params) { void generate(parameters params) {
if (!params.quiet) { if (!params.quiet) {
puts(NAME " " VERSION); puts(PACKAGE " " VERSION);
} }
clock_t start = clock(); clock_t start = clock();
init(params); init(params);
+15 -11
View File
@@ -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
View File
@@ -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);