diff --git a/pipi/combine/rgb.c b/pipi/combine/rgb.c index 4f00725..1d1553d 100644 --- a/pipi/combine/rgb.c +++ b/pipi/combine/rgb.c @@ -60,3 +60,75 @@ pipi_image_t *pipi_rgb(pipi_image_t *i1, pipi_image_t *i2, pipi_image_t *i3) return dst; } +pipi_image_t *pipi_red(pipi_image_t *src) +{ + pipi_image_t *dst; + pipi_pixels_t *srcp, *dstp; + float *srcdata, *dstdata; + int x, y, w, h; + + w = src->w; + h = src->h; + + dst = pipi_new(w, h); + dstp = pipi_getpixels(dst, PIPI_PIXELS_Y_F); + dstdata = (float *)dstp->pixels; + + srcp = pipi_getpixels(src, PIPI_PIXELS_RGBA_F); + srcdata = (float *)srcp->pixels; + + for(y = 0; y < h; y++) + for(x = 0; x < w; x++) + dstdata[y * w + x] = srcdata[4 * (y * w + x)]; + + return dst; +} + +pipi_image_t *pipi_green(pipi_image_t *src) +{ + pipi_image_t *dst; + pipi_pixels_t *srcp, *dstp; + float *srcdata, *dstdata; + int x, y, w, h; + + w = src->w; + h = src->h; + + dst = pipi_new(w, h); + dstp = pipi_getpixels(dst, PIPI_PIXELS_Y_F); + dstdata = (float *)dstp->pixels; + + srcp = pipi_getpixels(src, PIPI_PIXELS_RGBA_F); + srcdata = (float *)srcp->pixels; + + for(y = 0; y < h; y++) + for(x = 0; x < w; x++) + dstdata[y * w + x] = srcdata[4 * (y * w + x) + 1]; + + return dst; +} + +pipi_image_t *pipi_blue(pipi_image_t *src) +{ + pipi_image_t *dst; + pipi_pixels_t *srcp, *dstp; + float *srcdata, *dstdata; + int x, y, w, h; + + w = src->w; + h = src->h; + + dst = pipi_new(w, h); + dstp = pipi_getpixels(dst, PIPI_PIXELS_Y_F); + dstdata = (float *)dstp->pixels; + + srcp = pipi_getpixels(src, PIPI_PIXELS_RGBA_F); + srcdata = (float *)srcp->pixels; + + for(y = 0; y < h; y++) + for(x = 0; x < w; x++) + dstdata[y * w + x] = srcdata[4 * (y * w + x) + 2]; + + return dst; +} + diff --git a/pipi/pipi.h b/pipi/pipi.h index 41fd07a..840b6ab 100644 --- a/pipi/pipi.h +++ b/pipi/pipi.h @@ -106,6 +106,9 @@ 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_rgb(pipi_image_t *, pipi_image_t *, pipi_image_t *); +extern pipi_image_t *pipi_red(pipi_image_t *); +extern pipi_image_t *pipi_green(pipi_image_t *); +extern pipi_image_t *pipi_blue(pipi_image_t *); extern pipi_image_t *pipi_mean(pipi_image_t *, pipi_image_t *); extern pipi_image_t *pipi_min(pipi_image_t *, pipi_image_t *); extern pipi_image_t *pipi_max(pipi_image_t *, pipi_image_t *);