* pipi.c: add "--blur" and "--dither" commandline options.
* blur.c dither.c: remove these examples, pipi.c works a lot better:
pipi src.png --blur 10 dest.png
pipi src.png --dither dbs dest.png
(and of course combinations are possible)
git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2694 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
| @@ -11,9 +11,8 @@ libtool | |||
| pipi/pipi.pc | |||
| src/pipi | |||
| genethumb/genethumb | |||
| examples/blur | |||
| examples/dither | |||
| examples/edd | |||
| examples/floodfill | |||
| examples/img2rubik | |||
| examples/sharpen | |||
| test/u8tof32tou8 | |||
| @@ -2,13 +2,7 @@ | |||
| AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/pipi | |||
| bin_PROGRAMS = blur dither edd img2rubik sharpen floodfill | |||
| blur_SOURCES = blur.c | |||
| blur_LDADD = ../pipi/libpipi.la | |||
| dither_SOURCES = dither.c | |||
| dither_LDADD = ../pipi/libpipi.la | |||
| bin_PROGRAMS = edd img2rubik sharpen floodfill | |||
| edd_SOURCES = edd.c | |||
| edd_LDADD = ../pipi/libpipi.la | |||
| @@ -1,34 +0,0 @@ | |||
| #include "config.h" | |||
| #include "common.h" | |||
| #include <stdio.h> | |||
| #include <stdlib.h> | |||
| #include <string.h> | |||
| #include <pipi.h> | |||
| int main(int argc, char *argv[]) | |||
| { | |||
| char *srcname = NULL, *dstname = NULL; | |||
| pipi_image_t *img, *newimg; | |||
| if(argc < 4) | |||
| { | |||
| fprintf(stderr, "%s: too few arguments\n", argv[0]); | |||
| fprintf(stderr, "Usage: %s <src> <radius> <dest>\n", argv[0]); | |||
| return EXIT_FAILURE; | |||
| } | |||
| srcname = argv[1]; | |||
| dstname = argv[3]; | |||
| img = pipi_load(srcname); | |||
| newimg = pipi_gaussian_blur(img, atof(argv[2])); | |||
| pipi_free(img); | |||
| pipi_save(newimg, dstname); | |||
| pipi_free(newimg); | |||
| return 0; | |||
| } | |||
| @@ -1,67 +0,0 @@ | |||
| #include "config.h" | |||
| #include "common.h" | |||
| #include <stdio.h> | |||
| #include <stdlib.h> | |||
| #include <string.h> | |||
| #include <pipi.h> | |||
| int main(int argc, char *argv[]) | |||
| { | |||
| char *srcname = NULL, *dstname = NULL; | |||
| pipi_image_t *img, *newimg; | |||
| if(argc < 3) | |||
| { | |||
| fprintf(stderr, "%s: too few arguments\n", argv[0]); | |||
| fprintf(stderr, "Usage: %s <src> <method> <dest>\n", argv[0]); | |||
| fprintf(stderr, "Where <method> is one of:\n"); | |||
| fprintf(stderr, " 1 random dithering\n"); | |||
| fprintf(stderr, " 2 Floyd-Steinberg (raster)\n"); | |||
| fprintf(stderr, " 3 Floyd-Steinberg (serpentine)\n"); | |||
| fprintf(stderr, " 4 Ostromoukhov (raster)\n"); | |||
| fprintf(stderr, " 5 Ostromoukhov (serpentine)\n"); | |||
| fprintf(stderr, " 6 Direct binary search\n"); | |||
| return EXIT_FAILURE; | |||
| } | |||
| srcname = argv[1]; | |||
| dstname = argv[3]; | |||
| img = pipi_load(srcname); | |||
| switch(atoi(argv[2])) | |||
| { | |||
| case 7: | |||
| newimg = pipi_dither_dbs(img); | |||
| break; | |||
| case 6: | |||
| newimg = pipi_dither_ostromoukhov(img, PIPI_SCAN_SERPENTINE); | |||
| break; | |||
| case 5: | |||
| newimg = pipi_dither_ostromoukhov(img, PIPI_SCAN_RASTER); | |||
| break; | |||
| case 4: | |||
| newimg = pipi_dither_floydsteinberg(img, PIPI_SCAN_SERPENTINE); | |||
| break; | |||
| case 3: | |||
| newimg = pipi_dither_floydsteinberg(img, PIPI_SCAN_RASTER); | |||
| break; | |||
| case 2: | |||
| newimg = pipi_dither_ordered(img); | |||
| break; | |||
| case 1: | |||
| default: | |||
| newimg = pipi_dither_random(img); | |||
| break; | |||
| } | |||
| pipi_free(img); | |||
| pipi_save(newimg, dstname); | |||
| pipi_free(newimg); | |||
| return 0; | |||
| } | |||
| @@ -71,6 +71,56 @@ int pipi_command(pipi_context_t *ctx, char const *cmd, ...) | |||
| pipi_save(ctx->images[ctx->nimages], file); | |||
| pipi_free(ctx->images[ctx->nimages]); | |||
| } | |||
| else if(!strcmp(cmd, "dither")) | |||
| { | |||
| pipi_image_t *src, *dst; | |||
| char const *method; | |||
| va_list ap; | |||
| if(ctx->nimages <= 0) | |||
| return -1; | |||
| va_start(ap, cmd); | |||
| method = va_arg(ap, char const *); | |||
| va_end(ap); | |||
| src = ctx->images[ctx->nimages - 1]; | |||
| dst = NULL; | |||
| if(!strcmp(method, "fs")) | |||
| dst = pipi_dither_floydsteinberg(src, 0); | |||
| else if(!strcmp(method, "sfs")) | |||
| dst = pipi_dither_floydsteinberg(src, 1); | |||
| else if(!strcmp(method, "ost")) | |||
| dst = pipi_dither_ostromoukhov(src, 0); | |||
| else if(!strcmp(method, "sost")) | |||
| dst = pipi_dither_ostromoukhov(src, 1); | |||
| else if(!strcmp(method, "ordered")) | |||
| dst = pipi_dither_ordered(src); | |||
| else if(!strcmp(method, "random")) | |||
| dst = pipi_dither_random(src); | |||
| else if(!strcmp(method, "dbs")) | |||
| dst = pipi_dither_dbs(src); | |||
| if(dst == NULL) | |||
| return -1; | |||
| pipi_free(src); | |||
| ctx->images[ctx->nimages - 1] = dst; | |||
| } | |||
| else if(!strcmp(cmd, "blur")) | |||
| { | |||
| pipi_image_t *src, *dst; | |||
| char const *arg; | |||
| va_list ap; | |||
| if(ctx->nimages <= 0) | |||
| return -1; | |||
| va_start(ap, cmd); | |||
| arg = va_arg(ap, char const *); | |||
| va_end(ap); | |||
| src = ctx->images[ctx->nimages - 1]; | |||
| dst = pipi_gaussian_blur(src, atoi(arg)); | |||
| if(dst == NULL) | |||
| return -1; | |||
| pipi_free(src); | |||
| ctx->images[ctx->nimages - 1] = dst; | |||
| } | |||
| else if(!strcmp(cmd, "free")) | |||
| { | |||
| if(ctx->nimages <= 0) | |||
| @@ -15,7 +15,28 @@ int main(int argc, char *argv[]) | |||
| while(*++argv) | |||
| { | |||
| if(!strcmp(argv[0], "--output") || !strcmp(argv[0], "-o")) | |||
| if(!strcmp(argv[0], "--dup")) | |||
| { | |||
| if(pipi_command(ctx, "dup") != 0) | |||
| return EXIT_FAILURE; | |||
| } | |||
| else if(!strcmp(argv[0], "--dither")) | |||
| { | |||
| if(argv[1] == NULL) | |||
| return EXIT_FAILURE; | |||
| if(pipi_command(ctx, "dither", argv[1]) != 0) | |||
| return EXIT_FAILURE; | |||
| argv++; | |||
| } | |||
| else if(!strcmp(argv[0], "--blur")) | |||
| { | |||
| if(argv[1] == NULL) | |||
| return EXIT_FAILURE; | |||
| if(pipi_command(ctx, "blur", argv[1]) != 0) | |||
| return EXIT_FAILURE; | |||
| argv++; | |||
| } | |||
| else if(!strcmp(argv[0], "--output") || !strcmp(argv[0], "-o")) | |||
| { | |||
| if(argv[1] == NULL) | |||
| return EXIT_FAILURE; | |||