| 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 |
|
| 527 |
theseven |
28 |
void fill(int width, int height, uint32_t color,
|
|
|
29 |
void* buf, int outx, int outy, int stride)
|
| 493 |
theseven |
30 |
{
|
| 527 |
theseven |
31 |
char* out = (char*)buf + (outx + outy * stride) * 3;
|
|
|
32 |
int r = (color >> 0) & 0xff;
|
|
|
33 |
int g = (color >> 8) & 0xff;
|
|
|
34 |
int b = (color >> 16) & 0xff;
|
| 493 |
theseven |
35 |
int x, y;
|
|
|
36 |
for (y = 0; y < height; y++)
|
|
|
37 |
{
|
|
|
38 |
for (x = 0; x < width; x++)
|
|
|
39 |
{
|
| 527 |
theseven |
40 |
*out++ = r;
|
|
|
41 |
*out++ = g;
|
|
|
42 |
*out++ = b;
|
| 493 |
theseven |
43 |
}
|
| 527 |
theseven |
44 |
out += (stride - width) * 3;
|
| 493 |
theseven |
45 |
}
|
|
|
46 |
}
|
| 498 |
theseven |
47 |
|
| 527 |
theseven |
48 |
void blit(int width, int height, int pixelbytes,
|
|
|
49 |
void* outbuf, int outx, int outy, int outstride,
|
|
|
50 |
void* inbuf, int inx, int iny, int instride)
|
|
|
51 |
{
|
|
|
52 |
int i;
|
|
|
53 |
char* in = (char*)inbuf + (inx + iny * instride) * pixelbytes;
|
|
|
54 |
char* out = (char*)outbuf + (outx + outy * outstride) * pixelbytes;
|
|
|
55 |
int rowsize = width * pixelbytes;
|
|
|
56 |
while (height--)
|
|
|
57 |
{
|
|
|
58 |
memcpy(out, in, rowsize);
|
|
|
59 |
in += instride * pixelbytes;
|
|
|
60 |
out += outstride * pixelbytes;
|
|
|
61 |
}
|
|
|
62 |
}
|
|
|
63 |
|
| 498 |
theseven |
64 |
void blendcolor(int width, int height, uint32_t color,
|
|
|
65 |
void* outbuf, int outx, int outy, int outstride,
|
|
|
66 |
void* inbuf, int inx, int iny, int instride)
|
|
|
67 |
{
|
|
|
68 |
char* in = (char*)inbuf + (inx + iny * instride) * 3;
|
|
|
69 |
char* out = (char*)outbuf + (outx + outy * outstride) * 3;
|
|
|
70 |
int r = (color >> 0) & 0xff;
|
|
|
71 |
int g = (color >> 8) & 0xff;
|
|
|
72 |
int b = (color >> 16) & 0xff;
|
|
|
73 |
int a = (color >> 24) & 0xff;
|
|
|
74 |
int x, y;
|
|
|
75 |
for (y = 0; y < height; y++)
|
|
|
76 |
{
|
|
|
77 |
for (x = 0; x < width; x++)
|
|
|
78 |
{
|
|
|
79 |
*out++ = (a * r + (255 - a) * *in++) >> 8;
|
|
|
80 |
*out++ = (a * g + (255 - a) * *in++) >> 8;
|
|
|
81 |
*out++ = (a * b + (255 - a) * *in++) >> 8;
|
|
|
82 |
}
|
|
|
83 |
in += (instride - width) * 3;
|
|
|
84 |
out += (outstride - width) * 3;
|
|
|
85 |
}
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
void mattecolor(int width, int height, uint32_t color,
|
|
|
89 |
void* outbuf, int outx, int outy, int outstride,
|
|
|
90 |
void* inbuf, int inx, int iny, int instride)
|
|
|
91 |
{
|
|
|
92 |
char* in = (char*)inbuf + (inx + iny * instride) * 4;
|
|
|
93 |
char* out = (char*)outbuf + (outx + outy * outstride) * 3;
|
|
|
94 |
int mr = (color >> 0) & 0xff;
|
|
|
95 |
int mg = (color >> 8) & 0xff;
|
|
|
96 |
int mb = (color >> 16) & 0xff;
|
|
|
97 |
int x, y;
|
|
|
98 |
for (y = 0; y < height; y++)
|
|
|
99 |
{
|
|
|
100 |
for (x = 0; x < width; x++)
|
|
|
101 |
{
|
|
|
102 |
int r = *in++;
|
|
|
103 |
int g = *in++;
|
|
|
104 |
int b = *in++;
|
|
|
105 |
int a = *in++;
|
|
|
106 |
*out++ = (a * r + (255 - a) * mr) >> 8;
|
|
|
107 |
*out++ = (a * g + (255 - a) * mg) >> 8;
|
|
|
108 |
*out++ = (a * b + (255 - a) * mb) >> 8;
|
|
|
109 |
}
|
|
|
110 |
in += (instride - width) * 4;
|
|
|
111 |
out += (outstride - width) * 3;
|
|
|
112 |
}
|
|
|
113 |
}
|
| 504 |
theseven |
114 |
|
| 527 |
theseven |
115 |
void blend(int width, int height, int opacity,
|
|
|
116 |
void* outbuf, int outx, int outy, int outstride,
|
|
|
117 |
void* in1buf, int in1x, int in1y, int in1stride,
|
|
|
118 |
void* in2buf, int in2x, int in2y, int in2stride)
|
| 504 |
theseven |
119 |
{
|
| 527 |
theseven |
120 |
char* in1 = (char*)in1buf + (in1x + in1y * in1stride) * 3;
|
|
|
121 |
char* in2 = (char*)in2buf + (in2x + in2y * in2stride) * 3;
|
|
|
122 |
char* out = (char*)outbuf + (outx + outy * outstride) * 3;
|
|
|
123 |
int x, y;
|
|
|
124 |
for (y = 0; y < height; y++)
|
| 504 |
theseven |
125 |
{
|
| 527 |
theseven |
126 |
for (x = 0; x < width; x++)
|
|
|
127 |
{
|
|
|
128 |
int r1 = *in1++;
|
|
|
129 |
int g1 = *in1++;
|
|
|
130 |
int b1 = *in1++;
|
|
|
131 |
int r2 = *in2++;
|
|
|
132 |
int g2 = *in2++;
|
|
|
133 |
int b2 = *in2++;
|
|
|
134 |
*out++ = (opacity * r2 + (255 - opacity) * r1) >> 8;
|
|
|
135 |
*out++ = (opacity * g2 + (255 - opacity) * g1) >> 8;
|
|
|
136 |
*out++ = (opacity * b2 + (255 - opacity) * b1) >> 8;
|
|
|
137 |
}
|
|
|
138 |
in1 += (in1stride - width) * 3;
|
|
|
139 |
in2 += (in2stride - width) * 3;
|
|
|
140 |
out += (outstride - width) * 3;
|
| 504 |
theseven |
141 |
}
|
|
|
142 |
}
|
|
|
143 |
|
| 527 |
theseven |
144 |
void blenda(int width, int height, int opacity,
|
|
|
145 |
void* outbuf, int outx, int outy, int outstride,
|
|
|
146 |
void* in1buf, int in1x, int in1y, int in1stride,
|
|
|
147 |
void* in2buf, int in2x, int in2y, int in2stride)
|
| 504 |
theseven |
148 |
{
|
| 527 |
theseven |
149 |
char* in1 = (char*)in1buf + (in1x + in1y * in1stride) * 3;
|
|
|
150 |
char* in2 = (char*)in2buf + (in2x + in2y * in2stride) * 4;
|
|
|
151 |
char* out = (char*)outbuf + (outx + outy * outstride) * 3;
|
| 504 |
theseven |
152 |
int x, y;
|
|
|
153 |
for (y = 0; y < height; y++)
|
|
|
154 |
{
|
|
|
155 |
for (x = 0; x < width; x++)
|
|
|
156 |
{
|
| 527 |
theseven |
157 |
int r1 = *in1++;
|
|
|
158 |
int g1 = *in1++;
|
|
|
159 |
int b1 = *in1++;
|
|
|
160 |
int r2 = *in2++;
|
|
|
161 |
int g2 = *in2++;
|
|
|
162 |
int b2 = *in2++;
|
|
|
163 |
int a = *in2++ * opacity;
|
|
|
164 |
*out++ = (a * r2 + (65535 - a) * r1) >> 16;
|
|
|
165 |
*out++ = (a * g2 + (65535 - a) * g1) >> 16;
|
|
|
166 |
*out++ = (a * b2 + (65535 - a) * b1) >> 16;
|
| 504 |
theseven |
167 |
}
|
| 527 |
theseven |
168 |
in1 += (in1stride - width) * 3;
|
|
|
169 |
in2 += (in2stride - width) * 4;
|
|
|
170 |
out += (outstride - width) * 3;
|
| 504 |
theseven |
171 |
}
|
|
|
172 |
}
|