git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@3415 92316355-f0b4-4df1-b90c-862c8a59935fmaster
| @@ -54,6 +54,7 @@ pipi_command_t const *pipi_get_command_list(void) | |||||
| { "gamma", 1 }, | { "gamma", 1 }, | ||||
| { "scale", 1 }, | { "scale", 1 }, | ||||
| { "crop", 1 }, | |||||
| { "geometry", 1 }, | { "geometry", 1 }, | ||||
| { "tile", 1 }, | { "tile", 1 }, | ||||
| { "dither", 1 }, | { "dither", 1 }, | ||||
| @@ -365,6 +366,29 @@ int pipi_command(pipi_context_t *ctx, char const *cmd, ...) | |||||
| pipi_free(src); | pipi_free(src); | ||||
| ctx->images[ctx->nimages - 1] = dst; | ctx->images[ctx->nimages - 1] = dst; | ||||
| } | } | ||||
| else if(!strcmp(cmd, "crop")) | |||||
| { | |||||
| pipi_image_t *tmp; | |||||
| char const *arg; | |||||
| va_list ap; | |||||
| int w, h, x = 0, y = 0; | |||||
| int ret; | |||||
| if(ctx->nimages < 1) | |||||
| return -1; | |||||
| va_start(ap, cmd); | |||||
| arg = va_arg(ap, char const *); | |||||
| va_end(ap); | |||||
| ret = sscanf(arg, "%dx%d+%d+%d", &w, &h, &x, &y); | |||||
| if(ret < 2) | |||||
| return -1; | |||||
| tmp = ctx->images[ctx->nimages - 1]; | |||||
| ctx->images[ctx->nimages - 1] = pipi_crop(tmp, w, h, x, y); | |||||
| pipi_free(tmp); | |||||
| } | |||||
| else if(!strcmp(cmd, "brightness")) | else if(!strcmp(cmd, "brightness")) | ||||
| { | { | ||||
| pipi_image_t *src, *dst; | pipi_image_t *src, *dst; | ||||
| @@ -157,6 +157,7 @@ __extern double pipi_measure_msd(pipi_image_t *, pipi_image_t *); | |||||
| __extern double pipi_measure_rmsd(pipi_image_t *, pipi_image_t *); | __extern double pipi_measure_rmsd(pipi_image_t *, pipi_image_t *); | ||||
| __extern pipi_image_t *pipi_resize(pipi_image_t *, int, int); | __extern pipi_image_t *pipi_resize(pipi_image_t *, int, int); | ||||
| __extern pipi_image_t *pipi_crop(pipi_image_t *, int, int, int, int); | |||||
| __extern pipi_image_t *pipi_render_random(int, int); | __extern pipi_image_t *pipi_render_random(int, int); | ||||
| __extern pipi_image_t *pipi_render_bayer(int, int); | __extern pipi_image_t *pipi_render_bayer(int, int); | ||||
| @@ -123,3 +123,45 @@ pipi_image_t *pipi_resize(pipi_image_t *src, int w, int h) | |||||
| return dst; | return dst; | ||||
| } | } | ||||
| pipi_image_t *pipi_crop(pipi_image_t *src, int w, int h, int dx, int dy) | |||||
| { | |||||
| float *srcdata, *dstdata; | |||||
| pipi_image_t *dst; | |||||
| pipi_pixels_t *srcp, *dstp; | |||||
| int y, off, len; | |||||
| srcp = pipi_get_pixels(src, PIPI_PIXELS_RGBA_F32); | |||||
| srcdata = (float *)srcp->pixels; | |||||
| dst = pipi_new(w, h); | |||||
| dstp = pipi_get_pixels(dst, PIPI_PIXELS_RGBA_F32); | |||||
| dstdata = (float *)dstp->pixels; | |||||
| off = dx; | |||||
| len = w; | |||||
| if(dx < 0) | |||||
| { | |||||
| len += dx; | |||||
| dx = 0; | |||||
| } | |||||
| if(dx + len > srcp->w) | |||||
| len = srcp->w - dx; | |||||
| if(len > 0) | |||||
| { | |||||
| for(y = 0; y < h; y++) | |||||
| { | |||||
| if(y + dy < 0 || y + dy >= srcp->h) | |||||
| continue; | |||||
| memcpy(dstdata + y * w * 4, | |||||
| srcdata + ((y + dy) * srcp->w + dx) * 4, | |||||
| len * 4 * sizeof(float)); | |||||
| } | |||||
| } | |||||
| return dst; | |||||
| } | |||||