Subversion Repositories freemyipod

Rev

Rev 498 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
}