ff-utils

farbfeld tools and accessories
git clone git://nsmpr.xyz/ff-utils.git
Log | Files | Refs | README | LICENSE

commit a4d7abf14d9eb3465ab4f773e8a20e580e8c30cc
parent 0699592f5cc9552e660eaf9adf46603a2bbf1629
Author: prenev <an2qzavok@gmail.com>
Date:   Sun, 21 Mar 2021 11:47:58 +0300

boilerplate

Diffstat:
ALICENSE | 5+++++
AMakefile | 6++++++
AREADME | 5+++++
Aconfig.mk | 2++
Mff-pattern.c | 26+++++++++++++++-----------
5 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -0,0 +1,5 @@ +Copyright 2021 Pavel Renev + +Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/Makefile b/Makefile @@ -0,0 +1,6 @@ +include config.mk + +ff-pattern: ff-pattern.c + +clean: + rm -f ff-pattern diff --git a/README b/README @@ -0,0 +1,5 @@ +A 'collection' of farbfeld utilities. + +# ff-pattern +Repeat input image to fit specified dimensions. + $ ff-pattern width height diff --git a/config.mk b/config.mk @@ -0,0 +1,2 @@ +CFLAGS=-std=c99 -pedantic -Wall -Os +CC=cc diff --git a/ff-pattern.c b/ff-pattern.c @@ -1,7 +1,9 @@ +#include <arpa/inet.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> -#include <assert.h> +#include <string.h> int fid; long inx, iny, outx, outy; @@ -10,25 +12,28 @@ uint32_t hbuf[4]; char *buf; char *argv0; -void -usage(void) -{ - dprintf(2, "usage: %s width height\n", argv0); - exit(1); -} - int main(int argc, char **argv) { fid = 0; - argv0 = argv[0]; - if (argc < 3) usage(); + if (argc != 3) { + fprintf(stderr, "usage: %s width height\n", argv0); + return 1; + } + outx = strtol(argv[1], 0, 10); outy = strtol(argv[2], 0, 10); read(fid, hbuf, 16); + + if (strncmp("farbfeld", (char*)hbuf, 8) != 0) { + fprintf(stderr, "invalid magic\n"); + return 1; + } + inx = ntohl(hbuf[2]); iny = ntohl(hbuf[3]); + size = inx * iny * 8; buf = malloc(size); read(fid, buf, size); @@ -40,7 +45,6 @@ main(int argc, char **argv) y = i / outx; int d; d = x%inx + y%inx * inx; - assert(d*8<size); write(1, buf + d * 8, 8); } return 0;