git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2718 92316355-f0b4-4df1-b90c-862c8a59935fremotes/tiles
@@ -52,8 +52,8 @@ combine_sources = \ | |||||
filter_sources = \ | filter_sources = \ | ||||
filter/autocontrast.c \ | filter/autocontrast.c \ | ||||
filter/blur.c \ | filter/blur.c \ | ||||
filter/convolution.c \ | |||||
filter/convolution.h | |||||
filter/convolution.c filter/convolution_template.h \ | |||||
filter/color.c | |||||
dither_sources = \ | dither_sources = \ | ||||
dither/floydsteinberg.c \ | dither/floydsteinberg.c \ | ||||
@@ -383,6 +383,15 @@ int pipi_command(pipi_context_t *ctx, char const *cmd, ...) | |||||
ctx->images[ctx->nimages - 1] = pipi_autocontrast(tmp); | ctx->images[ctx->nimages - 1] = pipi_autocontrast(tmp); | ||||
pipi_free(tmp); | pipi_free(tmp); | ||||
} | } | ||||
else if(!strcmp(cmd, "invert")) | |||||
{ | |||||
pipi_image_t *tmp; | |||||
if(ctx->nimages < 1) | |||||
return -1; | |||||
tmp = ctx->images[ctx->nimages - 1]; | |||||
ctx->images[ctx->nimages - 1] = pipi_invert(tmp); | |||||
pipi_free(tmp); | |||||
} | |||||
else if(!strcmp(cmd, "gray")) | else if(!strcmp(cmd, "gray")) | ||||
{ | { | ||||
if(ctx->nimages < 1) | if(ctx->nimages < 1) | ||||
@@ -0,0 +1,73 @@ | |||||
/* | |||||
* libpipi Proper image processing implementation library | |||||
* Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org> | |||||
* All Rights Reserved | |||||
* | |||||
* $Id$ | |||||
* | |||||
* This library is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://sam.zoy.org/wtfpl/COPYING for more details. | |||||
*/ | |||||
/* | |||||
* color.c: colour manipulation functions | |||||
*/ | |||||
#include "config.h" | |||||
#include "common.h" | |||||
#include <stdlib.h> | |||||
#include <stdio.h> | |||||
#include <string.h> | |||||
#include <math.h> | |||||
#include "pipi.h" | |||||
#include "pipi_internals.h" | |||||
pipi_image_t *pipi_invert(pipi_image_t *src) | |||||
{ | |||||
pipi_image_t *dst; | |||||
pipi_pixels_t *srcp, *dstp; | |||||
float *srcdata, *dstdata; | |||||
int x, y, w, h, gray; | |||||
w = src->w; | |||||
h = src->h; | |||||
gray = (src->last_modified == PIPI_PIXELS_Y_F); | |||||
srcp = gray ? pipi_getpixels(src, PIPI_PIXELS_Y_F) | |||||
: pipi_getpixels(src, PIPI_PIXELS_RGBA_F); | |||||
srcdata = (float *)srcp->pixels; | |||||
dst = pipi_new(w, h); | |||||
dstp = gray ? pipi_getpixels(dst, PIPI_PIXELS_Y_F) | |||||
: pipi_getpixels(dst, PIPI_PIXELS_RGBA_F); | |||||
dstdata = (float *)dstp->pixels; | |||||
for(y = 0; y < h; y++) | |||||
{ | |||||
for(x = 0; x < w; x++) | |||||
{ | |||||
if(gray) | |||||
{ | |||||
dstdata[y * w + x] = 1. - srcdata[y * w + x]; | |||||
} | |||||
else | |||||
{ | |||||
int d = 4 * (y * w + x); | |||||
dstdata[d] = 1. - srcdata[d]; | |||||
dstdata[d + 1] = 1. - srcdata[d + 1]; | |||||
dstdata[d + 2] = 1. - srcdata[d + 2]; | |||||
dstdata[d + 3] = 1. - srcdata[d + 3]; | |||||
} | |||||
} | |||||
} | |||||
return dst; | |||||
} | |||||
@@ -103,6 +103,7 @@ extern pipi_image_t *pipi_gaussian_blur_ext(pipi_image_t *, | |||||
extern pipi_image_t *pipi_box_blur(pipi_image_t *, int); | extern pipi_image_t *pipi_box_blur(pipi_image_t *, int); | ||||
extern pipi_image_t *pipi_box_blur_ext(pipi_image_t *, int, int); | extern pipi_image_t *pipi_box_blur_ext(pipi_image_t *, int, int); | ||||
extern pipi_image_t *pipi_autocontrast(pipi_image_t *); | extern pipi_image_t *pipi_autocontrast(pipi_image_t *); | ||||
extern pipi_image_t *pipi_invert(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 *, | ||||
@@ -75,6 +75,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], "--invert")) | |||||
{ | |||||
if(pipi_command(ctx, "invert") != 0) | |||||
return EXIT_FAILURE; | |||||
} | |||||
else if(!strcmp(argv[0], "--wrap")) | else if(!strcmp(argv[0], "--wrap")) | ||||
{ | { | ||||
if(pipi_command(ctx, "wrap") != 0) | if(pipi_command(ctx, "wrap") != 0) | ||||