1 | /* |
---|
2 | * libpipi Pathetic image processing interface library |
---|
3 | * Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org> |
---|
4 | * All Rights Reserved |
---|
5 | * |
---|
6 | * $Id: blit.c 3560 2009-07-22 07:14:03Z sam $ |
---|
7 | * |
---|
8 | * This library is free software. It comes without any warranty, to |
---|
9 | * the extent permitted by applicable law. You can redistribute it |
---|
10 | * and/or modify it under the terms of the Do What The Fuck You Want |
---|
11 | * To Public License, Version 2, as published by Sam Hocevar. See |
---|
12 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
---|
13 | */ |
---|
14 | |
---|
15 | /* |
---|
16 | * mean.c: Mean computation function |
---|
17 | */ |
---|
18 | |
---|
19 | #include "config.h" |
---|
20 | |
---|
21 | #include <stdlib.h> |
---|
22 | |
---|
23 | #include "pipi.h" |
---|
24 | #include "pipi_internals.h" |
---|
25 | |
---|
26 | pipi_image_t *pipi_blit(pipi_image_t *img1, pipi_image_t *img2, int x, int y) |
---|
27 | { |
---|
28 | pipi_image_t *dst; |
---|
29 | pipi_pixels_t *img1p, *img2p, *dstp; |
---|
30 | float *img1data, *img2data, *dstdata; |
---|
31 | int dx, dy, w1, h1, w2, h2; |
---|
32 | |
---|
33 | w1 = img1->w; |
---|
34 | h1 = img1->h; |
---|
35 | w2 = img2->w; |
---|
36 | h2 = img2->h; |
---|
37 | |
---|
38 | dst = pipi_copy(img1); |
---|
39 | dstp = pipi_get_pixels(dst, PIPI_PIXELS_RGBA_F32); |
---|
40 | dstdata = (float *)dstp->pixels; |
---|
41 | |
---|
42 | img1p = pipi_get_pixels(img1, PIPI_PIXELS_RGBA_F32); |
---|
43 | img1data = (float *)img1p->pixels; |
---|
44 | img2p = pipi_get_pixels(img2, PIPI_PIXELS_RGBA_F32); |
---|
45 | img2data = (float *)img2p->pixels; |
---|
46 | |
---|
47 | for(dy = 0; dy < h2; dy++) |
---|
48 | { |
---|
49 | if (y + dy < 0) |
---|
50 | continue; |
---|
51 | |
---|
52 | if (y + dy >= h1) |
---|
53 | break; |
---|
54 | |
---|
55 | for(dx = 0; dx < w2; dx++) |
---|
56 | { |
---|
57 | float p, q; |
---|
58 | double t1, t2; |
---|
59 | |
---|
60 | if (x + dx < 0) |
---|
61 | continue; |
---|
62 | |
---|
63 | if (x + dx >= w1) |
---|
64 | break; |
---|
65 | |
---|
66 | t1 = img2data[4 * (dy * w2 + dx) + 3]; |
---|
67 | t2 = 1.0 - t1; |
---|
68 | |
---|
69 | p = img1data[4 * ((y + dy) * w1 + (x + dx))]; |
---|
70 | q = img2data[4 * (dy * w2 + dx)]; |
---|
71 | dstdata[4 * ((y + dy) * w1 + (x + dx))] = t2 * p + t1 * q; |
---|
72 | |
---|
73 | p = img1data[4 * ((y + dy) * w1 + (x + dx)) + 1]; |
---|
74 | q = img2data[4 * (dy * w2 + dx) + 1]; |
---|
75 | dstdata[4 * ((y + dy) * w1 + (x + dx)) + 1] = t2 * p + t1 * q; |
---|
76 | |
---|
77 | p = img1data[4 * ((y + dy) * w1 + (x + dx)) + 2]; |
---|
78 | q = img2data[4 * (dy * w2 + dx) + 2]; |
---|
79 | dstdata[4 * ((y + dy) * w1 + (x + dx)) + 2] = t2 * p + t1 * q; |
---|
80 | |
---|
81 | p = img1data[4 * ((y + dy) * w1 + (x + dx)) + 3]; |
---|
82 | q = img2data[4 * (dy * w2 + dx) + 3]; |
---|
83 | dstdata[4 * ((y + dy) * w1 + (x + dx)) + 3] = t2 * p + t1 * q; |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | return dst; |
---|
88 | } |
---|
89 | |
---|