git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2790 92316355-f0b4-4df1-b90c-862c8a59935fremotes/tiles
| @@ -391,6 +391,15 @@ int pipi_command(pipi_context_t *ctx, char const *cmd, ...) | |||||
| ctx->images[ctx->nimages - 1] = pipi_rotate270(tmp); | ctx->images[ctx->nimages - 1] = pipi_rotate270(tmp); | ||||
| pipi_free(tmp); | pipi_free(tmp); | ||||
| } | } | ||||
| else if(!strcmp(cmd, "order")) | |||||
| { | |||||
| pipi_image_t *tmp; | |||||
| if(ctx->nimages < 1) | |||||
| return -1; | |||||
| tmp = ctx->images[ctx->nimages - 1]; | |||||
| ctx->images[ctx->nimages - 1] = pipi_order(tmp); | |||||
| pipi_free(tmp); | |||||
| } | |||||
| else if(!strcmp(cmd, "split")) | else if(!strcmp(cmd, "split")) | ||||
| { | { | ||||
| pipi_image_t *src; | pipi_image_t *src; | ||||
| @@ -19,6 +19,8 @@ | |||||
| #include "config.h" | #include "config.h" | ||||
| #include "common.h" | #include "common.h" | ||||
| #include <stdlib.h> | |||||
| #include "pipi.h" | #include "pipi.h" | ||||
| #include "pipi_internals.h" | #include "pipi_internals.h" | ||||
| @@ -56,3 +58,58 @@ pipi_image_t *pipi_dither_ordered(pipi_image_t *img, pipi_image_t *kernel) | |||||
| return dst; | return dst; | ||||
| } | } | ||||
| typedef struct | |||||
| { | |||||
| int x, y; | |||||
| double val; | |||||
| } | |||||
| dot_t; | |||||
| static int cmpdot(const void *p1, const void *p2) | |||||
| { | |||||
| return ((dot_t const *)p1)->val > ((dot_t const *)p2)->val; | |||||
| } | |||||
| pipi_image_t *pipi_order(pipi_image_t *src) | |||||
| { | |||||
| double epsilon; | |||||
| pipi_image_t *dst; | |||||
| pipi_pixels_t *dstp, *srcp; | |||||
| float *dstdata, *srcdata; | |||||
| dot_t *circle; | |||||
| int x, y, w, h, n; | |||||
| w = src->w; | |||||
| h = src->h; | |||||
| epsilon = 1. / (w * h + 1); | |||||
| srcp = pipi_getpixels(src, PIPI_PIXELS_Y_F); | |||||
| srcdata = (float *)srcp->pixels; | |||||
| dst = pipi_new(w, h); | |||||
| dstp = pipi_getpixels(dst, PIPI_PIXELS_Y_F); | |||||
| dstdata = (float *)dstp->pixels; | |||||
| circle = malloc(w * h * sizeof(dot_t)); | |||||
| for(y = 0; y < h; y++) | |||||
| for(x = 0; x < w; x++) | |||||
| { | |||||
| circle[y * w + x].x = x; | |||||
| circle[y * w + x].y = y; | |||||
| circle[y * w + x].val = srcdata[y * w + x]; | |||||
| } | |||||
| qsort(circle, w * h, sizeof(dot_t), cmpdot); | |||||
| for(n = 0; n < w * h; n++) | |||||
| { | |||||
| x = circle[n].x; | |||||
| y = circle[n].y; | |||||
| dstdata[y * w + x] = (float)(n + 1) * epsilon; | |||||
| } | |||||
| free(circle); | |||||
| return dst; | |||||
| } | |||||
| @@ -150,6 +150,8 @@ extern pipi_image_t *pipi_median_ext(pipi_image_t *, int, int); | |||||
| extern pipi_image_t *pipi_dilate(pipi_image_t *); | extern pipi_image_t *pipi_dilate(pipi_image_t *); | ||||
| extern pipi_image_t *pipi_erode(pipi_image_t *); | extern pipi_image_t *pipi_erode(pipi_image_t *); | ||||
| extern pipi_image_t *pipi_order(pipi_image_t *); | |||||
| extern pipi_image_t *pipi_tile(pipi_image_t *, int, int); | extern pipi_image_t *pipi_tile(pipi_image_t *, int, int); | ||||
| extern int pipi_flood_fill(pipi_image_t *, | extern int pipi_flood_fill(pipi_image_t *, | ||||
| int, int, float, float, float, float); | int, int, float, float, float, float); | ||||
| @@ -115,6 +115,11 @@ int main(int argc, char *argv[]) | |||||
| if(pipi_command(ctx, "autocontrast") != 0) | if(pipi_command(ctx, "autocontrast") != 0) | ||||
| return EXIT_FAILURE; | return EXIT_FAILURE; | ||||
| } | } | ||||
| else if(!strcmp(argv[0], "--order")) | |||||
| { | |||||
| if(pipi_command(ctx, "order") != 0) | |||||
| return EXIT_FAILURE; | |||||
| } | |||||
| else if(!strcmp(argv[0], "--hflip")) | else if(!strcmp(argv[0], "--hflip")) | ||||
| { | { | ||||
| if(pipi_command(ctx, "hflip") != 0) | if(pipi_command(ctx, "hflip") != 0) | ||||