summaryrefslogtreecommitdiff
path: root/effects_software.cpp
blob: 27023e65c3ecee1801f0181701ab83da23c1fdd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

static void
Effect_Software_DrawColor(int Width, int Height, int BytesPerPixel, void *EffectBitmapAddress, v4 Color, blend_mode BlendMode)
{
    render_byte_info Bits = Bitmap_ByteInfo(BytesPerPixel);
    rectangle RenderRegion = {0, 0, Width, Height};
    transform_info T;
    T.BlendMode = BlendMode;
    for (int32 Y = RenderRegion.Min.y; Y < RenderRegion.Max.y; Y++) {
        for (int32 X = RenderRegion.Min.x; X < RenderRegion.Max.x; X++) {
            uint32 Offset = Y*Width*BytesPerPixel + X*BytesPerPixel;
            uint8 *LayerPixel = (uint8 *)EffectBitmapAddress + Offset;

            uint32 *R_DestAddress = (uint32 *)(LayerPixel + Bits.ByteOffset * 0);
            uint32 *G_DestAddress = (uint32 *)(LayerPixel + Bits.ByteOffset * 1);
            uint32 *B_DestAddress = (uint32 *)(LayerPixel + Bits.ByteOffset * 2);
            uint32 *A_DestAddress = (uint32 *)(LayerPixel + Bits.ByteOffset * 3);

            real32 R_Dest = (real32)(*R_DestAddress & Bits.MaskPixel) * Bits.Normalized;
            real32 G_Dest = (real32)(*G_DestAddress & Bits.MaskPixel) * Bits.Normalized;
            real32 B_Dest = (real32)(*B_DestAddress & Bits.MaskPixel) * Bits.Normalized;
            real32 A_Dest = (real32)(*A_DestAddress & Bits.MaskPixel) * Bits.Normalized;

            real32 R_Col = Color.r;
            real32 G_Col = Color.g;
            real32 B_Col = Color.b;
            real32 A_Col = Color.a;

            real32 LayerAlpha = A_Col * 1;

            real32 R_Blend = R_Col;
            real32 G_Blend = G_Col;
            real32 B_Blend = B_Col;
            real32 A_Blend = A_Col;

            Fallback_Blend();

            uint32 R_Out = (uint32)(Normalize(R_Blend) * Bits.Bits);
            uint32 G_Out = (uint32)(Normalize(G_Blend) * Bits.Bits);
            uint32 B_Out = (uint32)(Normalize(B_Blend) * Bits.Bits);
            uint32 A_Out = (uint32)(Normalize(A_Blend) * Bits.Bits);

            *R_DestAddress = (*R_DestAddress & ~Bits.MaskPixel) | R_Out;
            *G_DestAddress = (*G_DestAddress & ~Bits.MaskPixel) | G_Out;
            *B_DestAddress = (*B_DestAddress & ~Bits.MaskPixel) | B_Out;
            *A_DestAddress = (*A_DestAddress & ~Bits.MaskPixel) | A_Out;
        }
    }
}