diff --git a/pipi/pipi.h b/pipi/pipi.h index 9a564d9..8e872d8 100644 --- a/pipi/pipi.h +++ b/pipi/pipi.h @@ -34,8 +34,9 @@ extern void pipi_save(pipi_image_t *img, const char *name); extern int pipi_getgray(pipi_image_t const *img, int x, int y, int *g); extern int pipi_getpixel(pipi_image_t const *img, - int x, int y, int *r, int *g, int *b); -extern int pipi_setpixel(pipi_image_t *img, int x, int y, int r, int g, int b); + int x, int y, double *r, double *g, double *b); +extern int pipi_setpixel(pipi_image_t *img, int x, int y, + double r, double g, double b); extern pipi_image_t *pipi_resize(pipi_image_t const *, int, int); diff --git a/pipi/pixels.c b/pipi/pixels.c index d1b0286..fed1662 100644 --- a/pipi/pixels.c +++ b/pipi/pixels.c @@ -25,11 +25,11 @@ #include -#include "pipi_internals.h" #include "pipi.h" +#include "pipi_internals.h" -#define C2I(p) ((int)255.999*pow(((double)p)/255., 2.2)) -#define I2C(p) ((int)255.999*pow(((double)p)/255., 1./2.2)) +#define C2I(p) (pow(((double)p)/255., 2.2)) +#define I2C(p) ((int)255.999*pow(((double)p), 1./2.2)) int pipi_getgray(pipi_image_t const *img, int x, int y, int *g) { @@ -45,15 +45,13 @@ int pipi_getgray(pipi_image_t const *img, int x, int y, int *g) } int pipi_getpixel(pipi_image_t const *img, - int x, int y, int *r, int *g, int *b) + int x, int y, double *r, double *g, double *b) { uint8_t *pixel; if(x < 0 || y < 0 || x >= img->width || y >= img->height) { - *r = 255; - *g = 255; - *b = 255; + *r = *g = *b = 1.; return -1; } @@ -66,7 +64,7 @@ int pipi_getpixel(pipi_image_t const *img, return 0; } -int pipi_setpixel(pipi_image_t *img, int x, int y, int r, int g, int b) +int pipi_setpixel(pipi_image_t *img, int x, int y, double r, double g, double b) { uint8_t *pixel; diff --git a/pipi/resize.c b/pipi/resize.c index afbd5a8..2cc1ea4 100644 --- a/pipi/resize.c +++ b/pipi/resize.c @@ -22,12 +22,12 @@ #include #include -#include "pipi_internals.h" #include "pipi.h" +#include "pipi_internals.h" pipi_image_t *pipi_resize(pipi_image_t const *src, int w, int h) { - int *aline, *line; + double *aline, *line; pipi_image_t *dst; int x, y, x0, y0, sw, dw, sh, dh, remy; @@ -36,28 +36,28 @@ pipi_image_t *pipi_resize(pipi_image_t const *src, int w, int h) sw = src->width; sh = src->height; dw = dst->width; dh = dst->height; - aline = malloc(3 * dw * sizeof(int)); - line = malloc(3 * dw * sizeof(int)); + aline = malloc(3 * dw * sizeof(double)); + line = malloc(3 * dw * sizeof(double)); - memset(line, 0, 3 * dw * sizeof(int)); + memset(line, 0, 3 * dw * sizeof(double)); remy = 0; for(y = 0, y0 = 0; y < dst->height; y++) { int toty = 0, ny; - memset(aline, 0, 3 * dw * sizeof(int)); + memset(aline, 0, 3 * dw * sizeof(double)); while(toty < sh) { if(remy == 0) { - int r = 0, g = 0, b = 0; + double r = 0, g = 0, b = 0; int remx = 0; for(x = 0, x0 = 0; x < dst->width; x++) { - int ar = 0, ag = 0, ab = 0; + double ar = 0, ag = 0, ab = 0; int totx = 0, nx; while(totx < sw)