| 493 |
theseven |
1 |
//
|
|
|
2 |
//
|
|
|
3 |
// Copyright 2011 TheSeven
|
|
|
4 |
//
|
|
|
5 |
//
|
|
|
6 |
// This file is part of emCORE.
|
|
|
7 |
//
|
|
|
8 |
// emCORE is free software: you can redistribute it and/or
|
|
|
9 |
// modify it under the terms of the GNU General Public License as
|
|
|
10 |
// published by the Free Software Foundation, either version 2 of the
|
|
|
11 |
// License, or (at your option) any later version.
|
|
|
12 |
//
|
|
|
13 |
// emCORE is distributed in the hope that it will be useful,
|
|
|
14 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
15 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
16 |
// See the GNU General Public License for more details.
|
|
|
17 |
//
|
|
|
18 |
// You should have received a copy of the GNU General Public License along
|
|
|
19 |
// with emCORE. If not, see <http://www.gnu.org/licenses/>.
|
|
|
20 |
//
|
|
|
21 |
//
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
#include "emcorelib.h"
|
|
|
25 |
#include "blend.h"
|
|
|
26 |
|
|
|
27 |
|
|
|
28 |
void blend(int width, int height, int opacity,
|
|
|
29 |
void* outbuf, int outx, int outy, int outstride,
|
|
|
30 |
void* in1buf, int in1x, int in1y, int in1stride,
|
|
|
31 |
void* in2buf, int in2x, int in2y, int in2stride)
|
|
|
32 |
{
|
|
|
33 |
char* in1 = (char*)in1buf + (in1x + in1y * in1stride) * 3;
|
|
|
34 |
char* in2 = (char*)in2buf + (in2x + in2y * in2stride) * 4;
|
|
|
35 |
char* out = (char*)outbuf + (outx + outy * outstride) * 3;
|
|
|
36 |
int x, y;
|
|
|
37 |
for (y = 0; y < height; y++)
|
|
|
38 |
{
|
|
|
39 |
for (x = 0; x < width; x++)
|
|
|
40 |
{
|
|
|
41 |
int r1 = *in1++;
|
|
|
42 |
int g1 = *in1++;
|
|
|
43 |
int b1 = *in1++;
|
|
|
44 |
int r2 = *in2++;
|
|
|
45 |
int g2 = *in2++;
|
|
|
46 |
int b2 = *in2++;
|
|
|
47 |
int a = *in2++ * opacity;
|
|
|
48 |
*out++ = (a * r2 + (65535 - a) * r1) >> 16;
|
|
|
49 |
*out++ = (a * g2 + (65535 - a) * g1) >> 16;
|
|
|
50 |
*out++ = (a * b2 + (65535 - a) * b1) >> 16;
|
|
|
51 |
}
|
|
|
52 |
in1 += (in1stride - width) * 3;
|
|
|
53 |
in2 += (in2stride - width) * 4;
|
|
|
54 |
out += (outstride - width) * 3;
|
|
|
55 |
}
|
|
|
56 |
}
|
| 498 |
theseven |
57 |
|
|
|
58 |
void blendcolor(int width, int height, uint32_t color,
|
|
|
59 |
void* outbuf, int outx, int outy, int outstride,
|
|
|
60 |
void* inbuf, int inx, int iny, int instride)
|
|
|
61 |
{
|
|
|
62 |
char* in = (char*)inbuf + (inx + iny * instride) * 3;
|
|
|
63 |
char* out = (char*)outbuf + (outx + outy * outstride) * 3;
|
|
|
64 |
int r = (color >> 0) & 0xff;
|
|
|
65 |
int g = (color >> 8) & 0xff;
|
|
|
66 |
int b = (color >> 16) & 0xff;
|
|
|
67 |
int a = (color >> 24) & 0xff;
|
|
|
68 |
int x, y;
|
|
|
69 |
for (y = 0; y < height; y++)
|
|
|
70 |
{
|
|
|
71 |
for (x = 0; x < width; x++)
|
|
|
72 |
{
|
|
|
73 |
*out++ = (a * r + (255 - a) * *in++) >> 8;
|
|
|
74 |
*out++ = (a * g + (255 - a) * *in++) >> 8;
|
|
|
75 |
*out++ = (a * b + (255 - a) * *in++) >> 8;
|
|
|
76 |
}
|
|
|
77 |
in += (instride - width) * 3;
|
|
|
78 |
out += (outstride - width) * 3;
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
void mattecolor(int width, int height, uint32_t color,
|
|
|
83 |
void* outbuf, int outx, int outy, int outstride,
|
|
|
84 |
void* inbuf, int inx, int iny, int instride)
|
|
|
85 |
{
|
|
|
86 |
char* in = (char*)inbuf + (inx + iny * instride) * 4;
|
|
|
87 |
char* out = (char*)outbuf + (outx + outy * outstride) * 3;
|
|
|
88 |
int mr = (color >> 0) & 0xff;
|
|
|
89 |
int mg = (color >> 8) & 0xff;
|
|
|
90 |
int mb = (color >> 16) & 0xff;
|
|
|
91 |
int x, y;
|
|
|
92 |
for (y = 0; y < height; y++)
|
|
|
93 |
{
|
|
|
94 |
for (x = 0; x < width; x++)
|
|
|
95 |
{
|
|
|
96 |
int r = *in++;
|
|
|
97 |
int g = *in++;
|
|
|
98 |
int b = *in++;
|
|
|
99 |
int a = *in++;
|
|
|
100 |
*out++ = (a * r + (255 - a) * mr) >> 8;
|
|
|
101 |
*out++ = (a * g + (255 - a) * mg) >> 8;
|
|
|
102 |
*out++ = (a * b + (255 - a) * mb) >> 8;
|
|
|
103 |
}
|
|
|
104 |
in += (instride - width) * 4;
|
|
|
105 |
out += (outstride - width) * 3;
|
|
|
106 |
}
|
|
|
107 |
}
|