colors

extract colors from pictures
git clone git://git.2f30.org/colors
Log | Files | Refs | README | LICENSE

commit 84dc9084406b594ad55ff13642d2637430f4fafd
parent 2b6913eb20d2a4876bad35c67c224a2d751cd25a
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun,  5 Nov 2017 13:13:30 +0100

read data from stdin

Diffstat:
Mcolors.1 | 10+++++-----
Mcolors.c | 6+++---
Mcolors.h | 2+-
Mpng.c | 8+-------
4 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/colors.1 b/colors.1 @@ -9,12 +9,11 @@ .Op Fl erv .Op Fl h | Fl p .Op Fl n Ar clusters -.Ar file .Sh DESCRIPTION .Nm -is a simple tool to extract colors from pictures. By default it selects -initial clusters based on greyscale -steps. +is a simple tool to extract colors from pictures. +By default it selects initial clusters based on greyscale steps. +It reads the data from stdin. .Sh OPTIONS .Bl -tag -width "-n clusters" .It Fl e @@ -28,7 +27,8 @@ Select initial clusters from the hue domain. .It Fl p Select initial clusters from the image pixel space. .It Fl n Ar clusters -Set the number of clusters. It defaults to 8. +Set the number of clusters. +It defaults to 8. .El .Sh AUTHORS .An Dimitris Papastamos Aq Mt sin@2f30.org , diff --git a/colors.c b/colors.c @@ -311,7 +311,7 @@ printstatistics(void) void usage(void) { - fprintf(stderr, "usage: %s [-erv] [-h | -p] [-n clusters] file\n", argv0); + fprintf(stderr, "usage: %s [-erv] [-h | -p] [-n clusters]\n", argv0); exit(1); } @@ -348,11 +348,11 @@ main(int argc, char *argv[]) usage(); } ARGEND; - if (argc != 1) + if (argc != 0) usage(); RB_INIT(&pointhead); - parseimg(argv[0], fillpoints); + parseimg(stdin, fillpoints); initcluster = initcluster_greyscale; initspace = 256; diff --git a/colors.h b/colors.h @@ -1,2 +1,2 @@ /* See LICENSE file for copyright and license details. */ -void parseimg(char *, void (*)(int, int, int)); +void parseimg(FILE *, void (*)(int, int, int)); diff --git a/png.c b/png.c @@ -6,17 +6,13 @@ #include "colors.h" void -parseimg(char *f, void (*fn)(int, int, int)) +parseimg(FILE *fp, void (*fn)(int, int, int)) { png_structp png_struct_p; png_infop png_info_p; png_bytepp png_row_p; png_uint_32 y, x, width, height; int depth, color, interlace; - FILE *fp; - - if (!(fp = fopen(f, "r"))) - err(1, "fopen %s", f); png_struct_p = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); png_info_p = png_create_info_struct(png_struct_p); @@ -44,6 +40,4 @@ parseimg(char *f, void (*fn)(int, int, int)) png_free_data(png_struct_p, png_info_p, PNG_FREE_ALL, -1); png_destroy_read_struct(&png_struct_p, &png_info_p, NULL); - - fclose(fp); }