|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- /*
- * libpipi Pathetic image processing interface 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.
- */
-
- /*
- * mulscreen.c: multiply and screen computation functions
- */
-
- #include "config.h"
-
- #include <stdlib.h>
-
- #include "pipi.h"
- #include "pipi_internals.h"
-
- pipi_image_t *pipi_multiply(pipi_image_t *img1, pipi_image_t *img2)
- {
- pipi_image_t *dst;
- pipi_pixels_t *img1p, *img2p, *dstp;
- float *img1data, *img2data, *dstdata;
- int x, y, w, h;
-
- if(img1->w != img2->w || img1->h != img2->h)
- return NULL;
-
- w = img1->w;
- h = img1->h;
-
- dst = pipi_new(w, h);
- dstp = pipi_get_pixels(dst, PIPI_PIXELS_RGBA_F32);
- dstdata = (float *)dstp->pixels;
-
- img1p = pipi_get_pixels(img1, PIPI_PIXELS_RGBA_F32);
- img1data = (float *)img1p->pixels;
- img2p = pipi_get_pixels(img2, PIPI_PIXELS_RGBA_F32);
- img2data = (float *)img2p->pixels;
-
- for(y = 0; y < h; y++)
- {
- for(x = 0; x < w; x++)
- {
- float p, q;
-
- p = img1data[4 * (y * w + x)];
- q = img2data[4 * (y * w + x)];
- dstdata[4 * (y * w + x)] = p * q;
-
- p = img1data[4 * (y * w + x) + 1];
- q = img2data[4 * (y * w + x) + 1];
- dstdata[4 * (y * w + x) + 1] = p * q;
-
- p = img1data[4 * (y * w + x) + 2];
- q = img2data[4 * (y * w + x) + 2];
- dstdata[4 * (y * w + x) + 2] = p * q;
-
- p = img1data[4 * (y * w + x) + 3];
- q = img2data[4 * (y * w + x) + 3];
- dstdata[4 * (y * w + x) + 3] = p * q;
- }
- }
-
- return dst;
- }
-
- pipi_image_t *pipi_divide(pipi_image_t *img1, pipi_image_t *img2)
- {
- pipi_image_t *dst;
- pipi_pixels_t *img1p, *img2p, *dstp;
- float *img1data, *img2data, *dstdata;
- int x, y, w, h;
-
- if(img1->w != img2->w || img1->h != img2->h)
- return NULL;
-
- w = img1->w;
- h = img1->h;
-
- dst = pipi_new(w, h);
- dstp = pipi_get_pixels(dst, PIPI_PIXELS_RGBA_F32);
- dstdata = (float *)dstp->pixels;
-
- img1p = pipi_get_pixels(img1, PIPI_PIXELS_RGBA_F32);
- img1data = (float *)img1p->pixels;
- img2p = pipi_get_pixels(img2, PIPI_PIXELS_RGBA_F32);
- img2data = (float *)img2p->pixels;
-
- for(y = 0; y < h; y++)
- {
- for(x = 0; x < w; x++)
- {
- float p, q;
-
- p = img1data[4 * (y * w + x)];
- q = img2data[4 * (y * w + x)];
- dstdata[4 * (y * w + x)] = p >= q ? 1. : p / q;
-
- p = img1data[4 * (y * w + x) + 1];
- q = img2data[4 * (y * w + x) + 1];
- dstdata[4 * (y * w + x) + 1] = p >= q ? 1. : p / q;
-
- p = img1data[4 * (y * w + x) + 2];
- q = img2data[4 * (y * w + x) + 2];
- dstdata[4 * (y * w + x) + 2] = p >= q ? 1. : p / q;
-
- p = img1data[4 * (y * w + x) + 3];
- q = img2data[4 * (y * w + x) + 3];
- dstdata[4 * (y * w + x) + 3] = p >= q ? 1. : p / q;
- }
- }
-
- return dst;
- }
-
- pipi_image_t *pipi_screen(pipi_image_t *img1, pipi_image_t *img2)
- {
- pipi_image_t *dst;
- pipi_pixels_t *img1p, *img2p, *dstp;
- float *img1data, *img2data, *dstdata;
- int x, y, w, h;
-
- if(img1->w != img2->w || img1->h != img2->h)
- return NULL;
-
- w = img1->w;
- h = img1->h;
-
- dst = pipi_new(w, h);
- dstp = pipi_get_pixels(dst, PIPI_PIXELS_RGBA_F32);
- dstdata = (float *)dstp->pixels;
-
- img1p = pipi_get_pixels(img1, PIPI_PIXELS_RGBA_F32);
- img1data = (float *)img1p->pixels;
- img2p = pipi_get_pixels(img2, PIPI_PIXELS_RGBA_F32);
- img2data = (float *)img2p->pixels;
-
- for(y = 0; y < h; y++)
- {
- for(x = 0; x < w; x++)
- {
- float p, q;
-
- p = img1data[4 * (y * w + x)];
- q = img2data[4 * (y * w + x)];
- dstdata[4 * (y * w + x)] = p + q - p * q;
-
- p = img1data[4 * (y * w + x) + 1];
- q = img2data[4 * (y * w + x) + 1];
- dstdata[4 * (y * w + x) + 1] = p + q - p * q;
-
- p = img1data[4 * (y * w + x) + 2];
- q = img2data[4 * (y * w + x) + 2];
- dstdata[4 * (y * w + x) + 2] = p + q - p * q;
-
- p = img1data[4 * (y * w + x) + 3];
- q = img2data[4 * (y * w + x) + 3];
- dstdata[4 * (y * w + x) + 3] = p + q - p * q;
- }
- }
-
- return dst;
- }
-
- pipi_image_t *pipi_overlay(pipi_image_t *img1, pipi_image_t *img2)
- {
- pipi_image_t *dst;
- pipi_pixels_t *img1p, *img2p, *dstp;
- float *img1data, *img2data, *dstdata;
- int x, y, w, h;
-
- if(img1->w != img2->w || img1->h != img2->h)
- return NULL;
-
- w = img1->w;
- h = img1->h;
-
- dst = pipi_new(w, h);
- dstp = pipi_get_pixels(dst, PIPI_PIXELS_RGBA_F32);
- dstdata = (float *)dstp->pixels;
-
- img1p = pipi_get_pixels(img1, PIPI_PIXELS_RGBA_F32);
- img1data = (float *)img1p->pixels;
- img2p = pipi_get_pixels(img2, PIPI_PIXELS_RGBA_F32);
- img2data = (float *)img2p->pixels;
-
- for(y = 0; y < h; y++)
- {
- for(x = 0; x < w; x++)
- {
- float p, q;
-
- p = img1data[4 * (y * w + x)];
- q = img2data[4 * (y * w + x)];
- dstdata[4 * (y * w + x)] = p * (p + 2. * q * (1. - p));
-
- p = img1data[4 * (y * w + x) + 1];
- q = img2data[4 * (y * w + x) + 1];
- dstdata[4 * (y * w + x) + 1] = p * (p + 2. * q * (1. - p));
-
- p = img1data[4 * (y * w + x) + 2];
- q = img2data[4 * (y * w + x) + 2];
- dstdata[4 * (y * w + x) + 2] = p * (p + 2. * q * (1. - p));
-
- p = img1data[4 * (y * w + x) + 3];
- q = img2data[4 * (y * w + x) + 3];
- dstdata[4 * (y * w + x) + 3] = p * (p + 2. * q * (1. - p));
- }
- }
-
- return dst;
- }
-
|