annotate src/video/SDL_rendercopy.c @ 3789:e2f68b579a01 SDL-ryan-multiple-audio-device

Added testaudioinfo.c ...
author Ryan C. Gordon <icculus@icculus.org>
date Tue, 03 Oct 2006 20:05:33 +0000
parents 7387e0514595
children
rev   line source
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /* DO NOT EDIT! This file is generated by sdlgenblit.pl */
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 /*
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 SDL - Simple DirectMedia Layer
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4 Copyright (C) 1997-2006 Sam Lantinga
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 This library is free software; you can redistribute it and/or
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 modify it under the terms of the GNU Lesser General Public
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 License as published by the Free Software Foundation; either
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9 version 2.1 of the License, or (at your option) any later version.
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 This library is distributed in the hope that it will be useful,
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14 Lesser General Public License for more details.
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 You should have received a copy of the GNU Lesser General Public
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 License along with this library; if not, write to the Free Software
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 Sam Lantinga
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 slouken@libsdl.org
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 */
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 #include "SDL_config.h"
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 /* *INDENT-OFF* */
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 #include "SDL_video.h"
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 #include "SDL_rendercopy.h"
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 static struct {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 Uint32 src_format;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 Uint32 dst_format;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 int modMode;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 int blendMode;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 int scaleMode;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 SDL_RenderCopyFunc func;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 } SDL_RenderCopyFuncTable[] = {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, 0, 0, SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_RGB888_RGB888_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, 0, (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), 0, SDL_RenderCopy_RGB888_RGB888_Blend },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, 0, (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_RGB888_RGB888_Blend_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), 0, 0, SDL_RenderCopy_RGB888_RGB888_Modulate },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), 0, SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_RGB888_RGB888_Modulate_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), 0, SDL_RenderCopy_RGB888_RGB888_Modulate_Blend },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_RGB888_RGB888_Modulate_Blend_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, 0, 0, SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_RGB888_BGR888_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, 0, (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), 0, SDL_RenderCopy_RGB888_BGR888_Blend },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, 0, (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_RGB888_BGR888_Blend_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), 0, 0, SDL_RenderCopy_RGB888_BGR888_Modulate },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), 0, SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_RGB888_BGR888_Modulate_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), 0, SDL_RenderCopy_RGB888_BGR888_Modulate_Blend },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_RGB888_BGR888_Modulate_Blend_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, 0, 0, SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_BGR888_RGB888_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, 0, (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), 0, SDL_RenderCopy_BGR888_RGB888_Blend },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, 0, (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_BGR888_RGB888_Blend_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), 0, 0, SDL_RenderCopy_BGR888_RGB888_Modulate },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), 0, SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_BGR888_RGB888_Modulate_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), 0, SDL_RenderCopy_BGR888_RGB888_Modulate_Blend },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_BGR888_RGB888_Modulate_Blend_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, 0, 0, SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_BGR888_BGR888_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, 0, (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), 0, SDL_RenderCopy_BGR888_BGR888_Blend },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, 0, (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_BGR888_BGR888_Blend_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), 0, 0, SDL_RenderCopy_BGR888_BGR888_Modulate },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), 0, SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_BGR888_BGR888_Modulate_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), 0, SDL_RenderCopy_BGR888_BGR888_Modulate_Blend },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_BGR888_BGR888_Modulate_Blend_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, 0, 0, SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_ARGB8888_RGB888_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, 0, (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), 0, SDL_RenderCopy_ARGB8888_RGB888_Blend },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, 0, (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_ARGB8888_RGB888_Blend_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), 0, 0, SDL_RenderCopy_ARGB8888_RGB888_Modulate },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), 0, SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_ARGB8888_RGB888_Modulate_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), 0, SDL_RenderCopy_ARGB8888_RGB888_Modulate_Blend },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_ARGB8888_RGB888_Modulate_Blend_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, 0, 0, SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_ARGB8888_BGR888_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, 0, (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), 0, SDL_RenderCopy_ARGB8888_BGR888_Blend },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, 0, (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_ARGB8888_BGR888_Blend_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), 0, 0, SDL_RenderCopy_ARGB8888_BGR888_Modulate },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), 0, SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_ARGB8888_BGR888_Modulate_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), 0, SDL_RenderCopy_ARGB8888_BGR888_Modulate_Blend },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_ARGB8888_BGR888_Modulate_Blend_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, 0, 0, SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_RGBA8888_RGB888_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, 0, (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), 0, SDL_RenderCopy_RGBA8888_RGB888_Blend },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, 0, (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_RGBA8888_RGB888_Blend_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), 0, 0, SDL_RenderCopy_RGBA8888_RGB888_Modulate },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), 0, SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_RGBA8888_RGB888_Modulate_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), 0, SDL_RenderCopy_RGBA8888_RGB888_Modulate_Blend },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_RGBA8888_RGB888_Modulate_Blend_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, 0, 0, SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_RGBA8888_BGR888_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, 0, (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), 0, SDL_RenderCopy_RGBA8888_BGR888_Blend },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, 0, (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_RGBA8888_BGR888_Blend_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), 0, 0, SDL_RenderCopy_RGBA8888_BGR888_Modulate },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), 0, SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_RGBA8888_BGR888_Modulate_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), 0, SDL_RenderCopy_RGBA8888_BGR888_Modulate_Blend },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_RGBA8888_BGR888_Modulate_Blend_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, 0, 0, SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_ABGR8888_RGB888_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, 0, (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), 0, SDL_RenderCopy_ABGR8888_RGB888_Blend },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, 0, (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_ABGR8888_RGB888_Blend_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), 0, 0, SDL_RenderCopy_ABGR8888_RGB888_Modulate },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), 0, SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_ABGR8888_RGB888_Modulate_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), 0, SDL_RenderCopy_ABGR8888_RGB888_Modulate_Blend },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_ABGR8888_RGB888_Modulate_Blend_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, 0, 0, SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_ABGR8888_BGR888_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, 0, (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), 0, SDL_RenderCopy_ABGR8888_BGR888_Blend },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, 0, (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_ABGR8888_BGR888_Blend_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), 0, 0, SDL_RenderCopy_ABGR8888_BGR888_Modulate },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), 0, SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_ABGR8888_BGR888_Modulate_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), 0, SDL_RenderCopy_ABGR8888_BGR888_Modulate_Blend },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_ABGR8888_BGR888_Modulate_Blend_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, 0, 0, SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_BGRA8888_RGB888_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, 0, (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), 0, SDL_RenderCopy_BGRA8888_RGB888_Blend },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, 0, (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_BGRA8888_RGB888_Blend_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), 0, 0, SDL_RenderCopy_BGRA8888_RGB888_Modulate },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), 0, SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_BGRA8888_RGB888_Modulate_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), 0, SDL_RenderCopy_BGRA8888_RGB888_Modulate_Blend },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_BGRA8888_RGB888_Modulate_Blend_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, 0, 0, SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_BGRA8888_BGR888_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, 0, (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), 0, SDL_RenderCopy_BGRA8888_BGR888_Blend },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, 0, (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_BGRA8888_BGR888_Blend_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), 0, 0, SDL_RenderCopy_BGRA8888_BGR888_Modulate },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), 0, SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_BGRA8888_BGR888_Modulate_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), 0, SDL_RenderCopy_BGRA8888_BGR888_Modulate_Blend },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), SDL_TEXTURESCALEMODE_FAST, SDL_RenderCopy_BGRA8888_BGR888_Modulate_Blend_Scale },
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 };
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 SDL_RenderCopyFunc SDL_GetRenderCopyFunc(Uint32 src_format, Uint32 dst_format, int modMode, int blendMode, int scaleMode)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 int i;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 for (i = 0; i < SDL_arraysize(SDL_RenderCopyFuncTable); ++i) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 if (src_format != SDL_RenderCopyFuncTable[i].src_format) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 continue;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 if (dst_format != SDL_RenderCopyFuncTable[i].dst_format) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 continue;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 if ((modMode & SDL_RenderCopyFuncTable[i].modMode) != modMode) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 continue;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 if ((blendMode & SDL_RenderCopyFuncTable[i].blendMode) != blendMode) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 continue;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 if ((scaleMode & SDL_RenderCopyFuncTable[i].scaleMode) != scaleMode) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 continue;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 return SDL_RenderCopyFuncTable[i].func;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 return NULL;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 int SDL_RenderCopy_RGB888_RGB888_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 *dst = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 int SDL_RenderCopy_RGB888_RGB888_Blend(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
208 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
209 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
210 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
211 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
212 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
213 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
214 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
215 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
216 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
217 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
218 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
219 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
220 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
221 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
237 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238 dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249 int SDL_RenderCopy_RGB888_RGB888_Blend_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
255 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
256 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
257 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
273 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
274 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
276 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
277 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
278 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
279 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
280 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
281 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
282 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
283 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
284 srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
285 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
286 dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
287 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
288 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
289 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
290 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
291 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
292 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
293 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
294 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
295 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
296 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
297 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
298 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
299 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
300 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
301 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
302 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
303 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
304 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
305 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
306 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
307 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
308 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
309 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
310 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
311 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
313 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
314 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
315 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
316 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
317 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
318 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
319 dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
320 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
321 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
322 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
323 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
324 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
325 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
326 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
327 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
328 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
329
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
330 int SDL_RenderCopy_RGB888_RGB888_Modulate(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
331 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
332 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
333 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
334 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
335 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
336 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
337 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
338 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
339
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
340 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
341 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
342 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
343 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
344 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
345 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
346 R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
347 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
348 R = (R * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
349 G = (G * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
350 B = (B * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
351 }
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
352 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
353 A = (A * modulateA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
354 }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
355 pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
356 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
357 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
358 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
359 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
360 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
361 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
362 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
363 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
364 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
365
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
366 int SDL_RenderCopy_RGB888_RGB888_Modulate_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
367 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
368 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
369 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
370 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
371 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
372 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
373 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
374 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
375 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
376 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
377 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
378
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
379 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
380 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
381 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
382 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
383
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
384 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
385 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
386 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
387 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
388 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
389 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
390 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
391 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
392 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
393 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
394 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
395 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
396 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
397 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
398 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
399 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
400 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
401 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
402 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
403 R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
404 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
405 R = (R * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
406 G = (G * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
407 B = (B * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
408 }
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
409 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
410 A = (A * modulateA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
411 }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
412 pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
413 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
414 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
415 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
416 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
417 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
418 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
419 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
420 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
421 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
422
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
423 int SDL_RenderCopy_RGB888_RGB888_Modulate_Blend(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
424 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
425 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
426 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
427 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
428 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
429 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
430 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
431 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
432 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
433 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
434
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
435 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
436 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
437 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
438 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
439 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
440 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
441 srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
442 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
443 dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
444 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
445 srcR = (srcR * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
446 srcG = (srcG * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
447 srcB = (srcB * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
448 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
449 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
450 srcA = (srcA * modulateA) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
451 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
452 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
453 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
454 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
455 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
456 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
457 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
458 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
459 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
460 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
461 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
462 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
463 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
464 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
465 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
466 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
467 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
468 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
469 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
470 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
471 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
472 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
473 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
474 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
475 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
476 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
477 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
478 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
479 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
480 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
481 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
482 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
483 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
484 dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
485 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
486 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
487 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
488 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
489 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
490 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
491 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
492 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
493 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
494
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
495 int SDL_RenderCopy_RGB888_RGB888_Modulate_Blend_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
496 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
497 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
498 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
499 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
500 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
501 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
502 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
503 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
504 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
505 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
506 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
507 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
508 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
509
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
510 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
511 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
512 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
513 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
514
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
515 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
516 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
517 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
518 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
519 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
520 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
521 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
522 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
523 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
524 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
525 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
526 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
527 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
528 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
529 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
530 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
531 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
532 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
533 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
534 srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
535 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
536 dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
537 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
538 srcR = (srcR * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
539 srcG = (srcG * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
540 srcB = (srcB * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
541 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
542 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
543 srcA = (srcA * modulateA) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
544 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
545 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
546 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
547 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
548 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
549 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
550 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
551 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
552 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
553 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
554 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
555 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
556 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
557 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
558 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
559 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
560 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
561 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
562 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
563 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
564 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
565 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
566 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
567 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
568 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
569 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
570 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
571 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
572 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
573 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
574 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
575 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
576 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
577 dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
578 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
579 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
580 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
581 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
582 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
583 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
584 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
585 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
586 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
587
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
588 int SDL_RenderCopy_RGB888_BGR888_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
589 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
590 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
591 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
592 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
593 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
594 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
595 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
596
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
597 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
598 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
599 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
600 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
601
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
602 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
603 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
604 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
605 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
606 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
607 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
608 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
609 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
610 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
611 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
612 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
613 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
614 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
615 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
616 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
617 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
618 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
619 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
620 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
621 R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
622 pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
623 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
624 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
625 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
626 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
627 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
628 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
629 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
630 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
631 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
632
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
633 int SDL_RenderCopy_RGB888_BGR888_Blend(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
634 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
635 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
636 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
637 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
638 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
639 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
640
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
641 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
642 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
643 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
644 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
645 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
646 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
647 srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
648 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
649 dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
650 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
651 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
652 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
653 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
654 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
655 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
656 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
657 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
658 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
659 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
660 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
661 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
662 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
663 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
664 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
665 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
666 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
667 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
668 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
669 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
670 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
671 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
672 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
673 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
674 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
675 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
676 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
677 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
678 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
679 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
680 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
681 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
682 dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
683 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
684 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
685 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
686 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
687 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
688 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
689 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
690 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
691 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
692
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
693 int SDL_RenderCopy_RGB888_BGR888_Blend_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
694 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
695 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
696 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
697 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
698 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
699 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
700 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
701 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
702 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
703
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
704 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
705 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
706 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
707 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
708
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
709 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
710 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
711 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
712 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
713 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
714 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
715 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
716 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
717 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
718 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
719 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
720 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
721 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
722 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
723 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
724 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
725 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
726 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
727 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
728 srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
729 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
730 dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
731 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
732 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
733 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
734 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
735 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
736 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
737 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
738 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
739 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
740 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
741 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
742 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
743 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
744 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
745 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
746 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
747 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
748 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
749 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
750 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
751 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
752 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
753 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
754 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
755 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
756 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
757 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
758 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
759 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
760 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
761 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
762 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
763 dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
764 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
765 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
766 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
767 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
768 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
769 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
770 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
771 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
772 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
773
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
774 int SDL_RenderCopy_RGB888_BGR888_Modulate(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
775 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
776 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
777 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
778 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
779 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
780 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
781 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
782 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
783
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
784 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
785 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
786 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
787 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
788 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
789 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
790 R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
791 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
792 R = (R * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
793 G = (G * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
794 B = (B * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
795 }
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
796 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
797 A = (A * modulateA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
798 }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
799 pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
800 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
801 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
802 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
803 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
804 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
805 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
806 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
807 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
808 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
809
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
810 int SDL_RenderCopy_RGB888_BGR888_Modulate_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
811 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
812 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
813 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
814 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
815 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
816 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
817 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
818 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
819 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
820 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
821 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
822
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
823 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
824 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
825 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
826 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
827
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
828 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
829 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
830 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
831 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
832 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
833 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
834 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
835 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
836 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
837 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
838 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
839 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
840 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
841 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
842 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
843 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
844 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
845 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
846 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
847 R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
848 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
849 R = (R * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
850 G = (G * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
851 B = (B * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
852 }
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
853 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
854 A = (A * modulateA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
855 }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
856 pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
857 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
858 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
859 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
860 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
861 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
862 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
863 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
864 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
865 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
866
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
867 int SDL_RenderCopy_RGB888_BGR888_Modulate_Blend(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
868 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
869 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
870 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
871 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
872 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
873 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
874 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
875 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
876 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
877 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
878
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
879 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
880 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
881 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
882 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
883 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
884 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
885 srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
886 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
887 dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
888 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
889 srcR = (srcR * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
890 srcG = (srcG * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
891 srcB = (srcB * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
892 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
893 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
894 srcA = (srcA * modulateA) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
895 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
896 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
897 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
898 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
899 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
900 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
901 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
902 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
903 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
904 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
905 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
906 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
907 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
908 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
909 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
910 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
911 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
912 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
913 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
914 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
915 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
916 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
917 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
918 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
919 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
920 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
921 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
922 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
923 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
924 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
925 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
926 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
927 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
928 dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
929 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
930 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
931 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
932 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
933 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
934 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
935 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
936 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
937 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
938
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
939 int SDL_RenderCopy_RGB888_BGR888_Modulate_Blend_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
940 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
941 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
942 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
943 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
944 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
945 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
946 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
947 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
948 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
949 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
950 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
951 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
952 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
953
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
954 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
955 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
956 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
957 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
958
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
959 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
960 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
961 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
962 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
963 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
964 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
965 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
966 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
967 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
968 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
969 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
970 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
971 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
972 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
973 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
974 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
975 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
976 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
977 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
978 srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
979 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
980 dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
981 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
982 srcR = (srcR * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
983 srcG = (srcG * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
984 srcB = (srcB * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
985 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
986 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
987 srcA = (srcA * modulateA) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
988 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
989 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
990 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
991 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
992 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
993 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
994 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
995 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
996 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
997 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
998 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
999 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1000 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1001 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1002 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1003 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1004 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1005 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1006 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1007 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1008 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1009 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1010 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1011 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1012 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1013 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1014 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1015 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1016 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1017 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1018 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1019 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1020 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1021 dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1022 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1023 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1024 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1025 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1026 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1027 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1028 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1029 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1030 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1031
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1032 int SDL_RenderCopy_BGR888_RGB888_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1033 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1034 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1035 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1036 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1037 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1038 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1039 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1040
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1041 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1042 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1043 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1044 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1045
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1046 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1047 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1048 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1049 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1050 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1051 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1052 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1053 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1054 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1055 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1056 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1057 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1058 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1059 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1060 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1061 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1062 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1063 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1064 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1065 B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1066 pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1067 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1068 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1069 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1070 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1071 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1072 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1073 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1074 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1075 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1076
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1077 int SDL_RenderCopy_BGR888_RGB888_Blend(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1078 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1079 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1080 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1081 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1082 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1083 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1084
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1085 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1086 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1087 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1088 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1089 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1090 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1091 srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1092 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1093 dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1094 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1095 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1096 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1097 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1098 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1099 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1100 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1101 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1102 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1103 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1104 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1105 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1106 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1107 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1108 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1109 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1110 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1111 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1112 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1113 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1114 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1115 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1116 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1117 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1118 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1119 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1120 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1121 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1122 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1123 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1124 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1125 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1126 dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1127 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1128 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1129 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1130 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1131 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1132 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1133 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1134 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1135 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1136
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1137 int SDL_RenderCopy_BGR888_RGB888_Blend_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1138 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1139 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1140 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1141 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1142 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1143 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1144 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1145 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1146 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1147
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1148 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1149 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1150 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1151 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1152
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1153 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1154 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1155 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1156 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1157 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1158 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1159 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1160 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1161 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1162 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1163 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1164 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1165 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1166 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1167 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1168 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1169 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1170 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1171 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1172 srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1173 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1174 dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1175 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1176 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1177 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1178 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1179 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1180 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1181 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1182 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1183 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1184 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1185 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1186 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1187 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1188 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1189 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1190 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1191 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1192 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1193 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1194 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1195 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1196 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1197 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1198 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1199 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1200 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1201 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1202 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1203 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1204 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1205 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1206 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1207 dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1208 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1209 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1210 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1211 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1212 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1213 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1214 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1215 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1216 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1217
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1218 int SDL_RenderCopy_BGR888_RGB888_Modulate(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1219 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1220 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1221 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1222 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1223 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1224 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1225 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1226 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1227
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1228 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1229 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1230 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1231 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1232 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1233 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1234 B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1235 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1236 R = (R * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1237 G = (G * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1238 B = (B * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1239 }
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1240 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1241 A = (A * modulateA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1242 }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1243 pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1244 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1245 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1246 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1247 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1248 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1249 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1250 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1251 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1252 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1253
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1254 int SDL_RenderCopy_BGR888_RGB888_Modulate_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1255 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1256 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1257 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1258 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1259 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1260 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1261 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1262 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1263 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1264 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1265 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1266
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1267 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1268 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1269 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1270 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1271
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1272 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1273 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1274 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1275 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1276 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1277 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1278 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1279 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1280 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1281 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1282 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1283 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1284 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1285 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1286 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1287 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1288 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1289 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1290 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1291 B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1292 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1293 R = (R * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1294 G = (G * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1295 B = (B * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1296 }
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1297 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1298 A = (A * modulateA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1299 }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1300 pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1301 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1302 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1303 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1304 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1305 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1306 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1307 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1308 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1309 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1310
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1311 int SDL_RenderCopy_BGR888_RGB888_Modulate_Blend(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1312 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1313 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1314 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1315 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1316 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1317 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1318 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1319 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1320 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1321 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1322
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1323 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1324 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1325 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1326 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1327 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1328 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1329 srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1330 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1331 dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1332 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1333 srcR = (srcR * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1334 srcG = (srcG * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1335 srcB = (srcB * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1336 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1337 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1338 srcA = (srcA * modulateA) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1339 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1340 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1341 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1342 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1343 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1344 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1345 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1346 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1347 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1348 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1349 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1350 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1351 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1352 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1353 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1354 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1355 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1356 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1357 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1358 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1359 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1360 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1361 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1362 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1363 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1364 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1365 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1366 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1367 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1368 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1369 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1370 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1371 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1372 dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1373 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1374 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1375 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1376 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1377 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1378 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1379 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1380 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1381 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1382
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1383 int SDL_RenderCopy_BGR888_RGB888_Modulate_Blend_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1384 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1385 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1386 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1387 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1388 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1389 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1390 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1391 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1392 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1393 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1394 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1395 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1396 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1397
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1398 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1399 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1400 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1401 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1402
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1403 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1404 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1405 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1406 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1407 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1408 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1409 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1410 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1411 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1412 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1413 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1414 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1415 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1416 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1417 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1418 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1419 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1420 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1421 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1422 srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1423 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1424 dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1425 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1426 srcR = (srcR * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1427 srcG = (srcG * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1428 srcB = (srcB * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1429 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1430 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1431 srcA = (srcA * modulateA) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1432 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1433 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1434 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1435 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1436 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1437 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1438 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1439 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1440 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1441 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1442 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1443 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1444 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1445 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1446 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1447 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1448 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1449 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1450 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1451 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1452 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1453 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1454 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1455 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1456 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1457 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1458 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1459 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1460 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1461 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1462 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1463 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1464 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1465 dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1466 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1467 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1468 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1469 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1470 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1471 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1472 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1473 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1474 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1475
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1476 int SDL_RenderCopy_BGR888_BGR888_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1477 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1478 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1479 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1480 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1481 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1482
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1483 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1484 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1485 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1486 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1487
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1488 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1489 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1490 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1491 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1492 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1493 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1494 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1495 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1496 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1497 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1498 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1499 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1500 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1501 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1502 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1503 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1504 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1505 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1506 *dst = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1507 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1508 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1509 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1510 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1511 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1512 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1513 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1514 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1515
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1516 int SDL_RenderCopy_BGR888_BGR888_Blend(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1517 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1518 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1519 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1520 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1521 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1522 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1523
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1524 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1525 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1526 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1527 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1528 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1529 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1530 srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1531 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1532 dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1533 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1534 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1535 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1536 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1537 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1538 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1539 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1540 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1541 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1542 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1543 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1544 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1545 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1546 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1547 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1548 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1549 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1550 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1551 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1552 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1553 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1554 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1555 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1556 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1557 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1558 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1559 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1560 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1561 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1562 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1563 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1564 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1565 dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1566 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1567 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1568 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1569 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1570 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1571 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1572 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1573 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1574 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1575
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1576 int SDL_RenderCopy_BGR888_BGR888_Blend_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1577 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1578 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1579 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1580 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1581 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1582 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1583 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1584 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1585 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1586
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1587 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1588 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1589 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1590 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1591
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1592 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1593 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1594 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1595 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1596 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1597 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1598 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1599 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1600 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1601 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1602 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1603 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1604 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1605 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1606 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1607 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1608 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1609 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1610 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1611 srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1612 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1613 dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1614 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1615 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1616 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1617 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1618 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1619 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1620 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1621 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1622 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1623 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1624 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1625 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1626 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1627 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1628 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1629 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1630 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1631 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1632 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1633 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1634 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1635 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1636 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1637 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1638 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1639 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1640 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1641 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1642 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1643 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1644 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1645 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1646 dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1647 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1648 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1649 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1650 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1651 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1652 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1653 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1654 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1655 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1656
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1657 int SDL_RenderCopy_BGR888_BGR888_Modulate(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1658 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1659 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1660 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1661 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1662 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1663 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1664 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1665 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1666
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1667 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1668 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1669 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1670 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1671 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1672 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1673 B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1674 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1675 R = (R * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1676 G = (G * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1677 B = (B * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1678 }
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1679 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1680 A = (A * modulateA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1681 }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1682 pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1683 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1684 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1685 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1686 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1687 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1688 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1689 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1690 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1691 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1692
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1693 int SDL_RenderCopy_BGR888_BGR888_Modulate_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1694 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1695 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1696 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1697 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1698 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1699 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1700 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1701 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1702 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1703 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1704 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1705
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1706 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1707 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1708 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1709 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1710
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1711 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1712 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1713 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1714 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1715 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1716 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1717 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1718 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1719 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1720 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1721 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1722 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1723 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1724 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1725 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1726 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1727 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1728 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1729 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1730 B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1731 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1732 R = (R * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1733 G = (G * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1734 B = (B * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1735 }
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1736 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1737 A = (A * modulateA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1738 }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1739 pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1740 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1741 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1742 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1743 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1744 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1745 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1746 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1747 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1748 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1749
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1750 int SDL_RenderCopy_BGR888_BGR888_Modulate_Blend(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1751 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1752 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1753 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1754 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1755 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1756 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1757 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1758 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1759 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1760 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1761
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1762 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1763 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1764 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1765 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1766 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1767 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1768 srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1769 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1770 dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1771 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1772 srcR = (srcR * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1773 srcG = (srcG * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1774 srcB = (srcB * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1775 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1776 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1777 srcA = (srcA * modulateA) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1778 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1779 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1780 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1781 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1782 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1783 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1784 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1785 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1786 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1787 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1788 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1789 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1790 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1791 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1792 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1793 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1794 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1795 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1796 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1797 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1798 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1799 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1800 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1801 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1802 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1803 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1804 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1805 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1806 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1807 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1808 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1809 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1810 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1811 dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1812 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1813 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1814 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1815 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1816 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1817 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1818 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1819 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1820 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1821
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1822 int SDL_RenderCopy_BGR888_BGR888_Modulate_Blend_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1823 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1824 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1825 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1826 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1827 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1828 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1829 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1830 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1831 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1832 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1833 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1834 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1835 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1836
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1837 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1838 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1839 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1840 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1841
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1842 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1843 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1844 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1845 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1846 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1847 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1848 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1849 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1850 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1851 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1852 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1853 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1854 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1855 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1856 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1857 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1858 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1859 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1860 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1861 srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1862 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1863 dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1864 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1865 srcR = (srcR * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1866 srcG = (srcG * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1867 srcB = (srcB * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1868 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1869 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1870 srcA = (srcA * modulateA) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1871 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1872 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1873 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1874 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1875 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1876 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1877 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1878 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1879 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1880 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1881 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1882 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1883 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1884 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1885 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1886 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1887 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1888 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1889 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1890 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1891 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1892 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1893 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1894 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1895 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1896 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1897 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1898 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1899 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1900 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1901 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1902 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1903 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1904 dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1905 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1906 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1907 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1908 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1909 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1910 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1911 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1912 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1913 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1914
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1915 int SDL_RenderCopy_ARGB8888_RGB888_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1916 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1917 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1918 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1919 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1920 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1921 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1922 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1923
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1924 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1925 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1926 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1927 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1928
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1929 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1930 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1931 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1932 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1933 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1934 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1935 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1936 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1937 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1938 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1939 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1940 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1941 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1942 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1943 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1944 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1945 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1946 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1947 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1948 A = (Uint8)(pixel >> 24); R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1949 pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1950 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1951 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1952 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1953 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1954 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1955 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1956 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1957 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1958 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1959
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1960 int SDL_RenderCopy_ARGB8888_RGB888_Blend(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1961 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1962 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1963 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1964 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1965 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1966 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1967
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1968 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1969 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1970 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1971 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1972 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1973 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1974 srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1975 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1976 dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1977 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1978 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1979 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1980 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1981 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1982 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1983 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1984 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1985 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1986 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1987 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1988 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1989 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1990 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1991 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
1992 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1993 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1994 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1995 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1996 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1997 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1998 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1999 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2000 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2001 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2002 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2003 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2004 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2005 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2006 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2007 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2008 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2009 dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2010 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2011 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2012 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2013 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2014 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2015 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2016 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2017 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2018 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2019
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2020 int SDL_RenderCopy_ARGB8888_RGB888_Blend_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2021 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2022 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2023 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2024 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2025 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2026 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2027 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2028 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2029 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2030
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2031 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2032 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2033 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2034 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2035
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2036 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2037 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2038 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2039 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2040 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2041 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2042 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2043 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2044 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2045 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2046 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2047 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2048 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2049 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2050 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2051 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2052 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2053 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2054 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2055 srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2056 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2057 dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2058 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2059 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2060 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2061 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2062 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2063 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2064 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2065 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2066 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2067 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2068 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2069 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2070 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2071 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2072 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2073 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2074 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2075 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2076 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2077 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2078 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2079 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2080 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2081 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2082 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2083 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2084 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2085 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2086 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2087 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2088 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2089 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2090 dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2091 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2092 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2093 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2094 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2095 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2096 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2097 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2098 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2099 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2100
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2101 int SDL_RenderCopy_ARGB8888_RGB888_Modulate(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2102 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2103 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2104 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2105 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2106 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2107 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2108 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2109 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2110
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2111 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2112 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2113 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2114 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2115 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2116 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2117 A = (Uint8)(pixel >> 24); R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2118 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2119 R = (R * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2120 G = (G * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2121 B = (B * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2122 }
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2123 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2124 A = (A * modulateA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2125 }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2126 pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2127 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2128 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2129 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2130 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2131 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2132 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2133 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2134 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2135 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2136
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2137 int SDL_RenderCopy_ARGB8888_RGB888_Modulate_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2138 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2139 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2140 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2141 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2142 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2143 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2144 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2145 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2146 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2147 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2148 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2149
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2150 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2151 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2152 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2153 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2154
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2155 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2156 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2157 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2158 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2159 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2160 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2161 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2162 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2163 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2164 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2165 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2166 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2167 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2168 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2169 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2170 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2171 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2172 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2173 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2174 A = (Uint8)(pixel >> 24); R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2175 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2176 R = (R * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2177 G = (G * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2178 B = (B * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2179 }
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2180 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2181 A = (A * modulateA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2182 }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2183 pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2184 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2185 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2186 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2187 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2188 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2189 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2190 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2191 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2192 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2193
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2194 int SDL_RenderCopy_ARGB8888_RGB888_Modulate_Blend(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2195 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2196 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2197 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2198 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2199 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2200 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2201 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2202 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2203 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2204 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2205
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2206 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2207 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2208 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2209 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2210 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2211 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2212 srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2213 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2214 dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2215 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2216 srcR = (srcR * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2217 srcG = (srcG * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2218 srcB = (srcB * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2219 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2220 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2221 srcA = (srcA * modulateA) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2222 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2223 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2224 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2225 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2226 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2227 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2228 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2229 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2230 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2231 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2232 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2233 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2234 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2235 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2236 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2237 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2238 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2239 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2240 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2241 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2242 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2243 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2244 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2245 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2246 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2247 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2248 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2249 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2250 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2251 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2252 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2253 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2254 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2255 dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2256 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2257 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2258 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2259 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2260 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2261 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2262 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2263 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2264 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2265
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2266 int SDL_RenderCopy_ARGB8888_RGB888_Modulate_Blend_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2267 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2268 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2269 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2270 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2271 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2272 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2273 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2274 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2275 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2276 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2277 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2278 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2279 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2280
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2281 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2282 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2283 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2284 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2285
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2286 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2287 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2288 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2289 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2290 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2291 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2292 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2293 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2294 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2295 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2296 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2297 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2298 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2299 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2300 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2301 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2302 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2303 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2304 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2305 srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2306 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2307 dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2308 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2309 srcR = (srcR * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2310 srcG = (srcG * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2311 srcB = (srcB * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2312 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2313 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2314 srcA = (srcA * modulateA) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2315 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2316 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2317 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2318 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2319 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2320 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2321 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2322 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2323 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2324 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2325 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2326 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2327 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2328 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2329 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2330 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2331 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2332 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2333 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2334 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2335 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2336 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2337 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2338 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2339 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2340 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2341 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2342 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2343 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2344 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2345 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2346 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2347 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2348 dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2349 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2350 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2351 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2352 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2353 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2354 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2355 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2356 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2357 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2358
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2359 int SDL_RenderCopy_ARGB8888_BGR888_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2360 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2361 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2362 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2363 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2364 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2365 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2366 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2367
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2368 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2369 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2370 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2371 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2372
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2373 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2374 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2375 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2376 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2377 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2378 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2379 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2380 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2381 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2382 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2383 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2384 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2385 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2386 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2387 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2388 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2389 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2390 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2391 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2392 A = (Uint8)(pixel >> 24); R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2393 pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2394 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2395 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2396 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2397 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2398 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2399 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2400 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2401 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2402 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2403
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2404 int SDL_RenderCopy_ARGB8888_BGR888_Blend(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2405 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2406 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2407 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2408 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2409 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2410 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2411
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2412 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2413 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2414 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2415 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2416 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2417 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2418 srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2419 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2420 dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2421 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2422 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2423 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2424 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2425 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2426 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2427 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2428 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2429 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2430 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2431 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2432 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2433 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2434 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2435 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2436 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2437 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2438 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2439 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2440 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2441 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2442 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2443 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2444 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2445 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2446 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2447 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2448 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2449 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2450 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2451 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2452 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2453 dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2454 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2455 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2456 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2457 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2458 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2459 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2460 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2461 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2462 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2463
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2464 int SDL_RenderCopy_ARGB8888_BGR888_Blend_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2465 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2466 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2467 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2468 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2469 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2470 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2471 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2472 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2473 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2474
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2475 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2476 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2477 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2478 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2479
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2480 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2481 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2482 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2483 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2484 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2485 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2486 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2487 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2488 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2489 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2490 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2491 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2492 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2493 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2494 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2495 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2496 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2497 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2498 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2499 srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2500 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2501 dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2502 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2503 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2504 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2505 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2506 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2507 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2508 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2509 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2510 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2511 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2512 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2513 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2514 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2515 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2516 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2517 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2518 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2519 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2520 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2521 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2522 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2523 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2524 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2525 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2526 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2527 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2528 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2529 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2530 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2531 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2532 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2533 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2534 dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2535 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2536 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2537 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2538 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2539 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2540 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2541 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2542 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2543 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2544
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2545 int SDL_RenderCopy_ARGB8888_BGR888_Modulate(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2546 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2547 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2548 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2549 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2550 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2551 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2552 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2553 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2554
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2555 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2556 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2557 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2558 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2559 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2560 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2561 A = (Uint8)(pixel >> 24); R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2562 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2563 R = (R * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2564 G = (G * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2565 B = (B * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2566 }
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2567 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2568 A = (A * modulateA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2569 }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2570 pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2571 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2572 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2573 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2574 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2575 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2576 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2577 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2578 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2579 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2580
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2581 int SDL_RenderCopy_ARGB8888_BGR888_Modulate_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2582 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2583 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2584 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2585 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2586 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2587 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2588 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2589 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2590 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2591 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2592 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2593
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2594 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2595 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2596 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2597 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2598
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2599 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2600 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2601 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2602 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2603 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2604 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2605 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2606 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2607 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2608 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2609 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2610 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2611 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2612 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2613 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2614 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2615 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2616 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2617 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2618 A = (Uint8)(pixel >> 24); R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2619 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2620 R = (R * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2621 G = (G * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2622 B = (B * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2623 }
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2624 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2625 A = (A * modulateA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2626 }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2627 pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2628 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2629 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2630 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2631 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2632 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2633 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2634 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2635 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2636 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2637
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2638 int SDL_RenderCopy_ARGB8888_BGR888_Modulate_Blend(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2639 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2640 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2641 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2642 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2643 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2644 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2645 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2646 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2647 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2648 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2649
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2650 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2651 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2652 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2653 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2654 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2655 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2656 srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2657 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2658 dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2659 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2660 srcR = (srcR * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2661 srcG = (srcG * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2662 srcB = (srcB * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2663 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2664 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2665 srcA = (srcA * modulateA) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2666 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2667 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2668 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2669 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2670 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2671 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2672 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2673 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2674 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2675 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2676 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2677 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2678 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2679 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2680 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2681 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2682 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2683 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2684 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2685 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2686 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2687 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2688 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2689 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2690 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2691 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2692 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2693 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2694 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2695 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2696 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2697 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2698 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2699 dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2700 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2701 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2702 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2703 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2704 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2705 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2706 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2707 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2708 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2709
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2710 int SDL_RenderCopy_ARGB8888_BGR888_Modulate_Blend_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2711 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2712 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2713 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2714 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2715 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2716 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2717 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2718 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2719 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2720 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2721 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2722 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2723 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2724
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2725 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2726 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2727 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2728 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2729
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2730 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2731 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2732 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2733 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2734 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2735 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2736 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2737 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2738 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2739 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2740 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2741 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2742 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2743 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2744 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2745 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2746 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2747 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2748 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2749 srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2750 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2751 dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2752 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2753 srcR = (srcR * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2754 srcG = (srcG * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2755 srcB = (srcB * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2756 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2757 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2758 srcA = (srcA * modulateA) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2759 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2760 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2761 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2762 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2763 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2764 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2765 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2766 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2767 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2768 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2769 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2770 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2771 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2772 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2773 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2774 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2775 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2776 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2777 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2778 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2779 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2780 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2781 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2782 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2783 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2784 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2785 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2786 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2787 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2788 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2789 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2790 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2791 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2792 dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2793 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2794 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2795 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2796 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2797 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2798 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2799 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2800 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2801 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2802
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2803 int SDL_RenderCopy_RGBA8888_RGB888_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2804 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2805 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2806 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2807 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2808 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2809 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2810 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2811
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2812 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2813 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2814 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2815 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2816
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2817 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2818 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2819 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2820 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2821 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2822 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2823 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2824 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2825 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2826 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2827 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2828 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2829 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2830 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2831 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2832 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2833 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2834 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2835 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2836 R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8); A = (Uint8)pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2837 pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2838 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2839 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2840 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2841 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2842 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2843 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2844 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2845 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2846 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2847
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2848 int SDL_RenderCopy_RGBA8888_RGB888_Blend(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2849 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2850 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2851 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2852 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2853 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2854 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2855
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2856 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2857 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2858 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2859 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2860 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2861 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2862 srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2863 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2864 dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2865 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2866 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2867 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2868 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2869 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2870 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2871 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2872 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2873 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2874 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2875 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2876 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2877 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2878 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2879 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2880 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2881 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2882 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2883 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2884 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2885 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2886 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2887 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2888 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2889 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2890 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2891 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2892 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2893 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2894 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2895 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2896 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2897 dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2898 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2899 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2900 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2901 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2902 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2903 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2904 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2905 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2906 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2907
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2908 int SDL_RenderCopy_RGBA8888_RGB888_Blend_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2909 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2910 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2911 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2912 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2913 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2914 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2915 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2916 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2917 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2918
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2919 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2920 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2921 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2922 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2923
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2924 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2925 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2926 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2927 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2928 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2929 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2930 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2931 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2932 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2933 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2934 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2935 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2936 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2937 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2938 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2939 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2940 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2941 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2942 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2943 srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2944 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2945 dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2946 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2947 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2948 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2949 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2950 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2951 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2952 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2953 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2954 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2955 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2956 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2957 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2958 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2959 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2960 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
2961 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2962 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2963 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2964 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2965 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2966 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2967 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2968 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2969 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2970 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2971 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2972 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2973 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2974 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2975 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2976 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2977 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2978 dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2979 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2980 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2981 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2982 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2983 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2984 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2985 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2986 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2987 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2988
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2989 int SDL_RenderCopy_RGBA8888_RGB888_Modulate(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2990 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2991 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2992 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2993 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2994 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2995 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2996 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2997 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2998
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2999 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3000 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3001 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3002 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3003 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3004 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3005 R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8); A = (Uint8)pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3006 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3007 R = (R * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3008 G = (G * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3009 B = (B * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3010 }
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3011 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3012 A = (A * modulateA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3013 }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3014 pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3015 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3016 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3017 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3018 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3019 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3020 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3021 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3022 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3023 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3024
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3025 int SDL_RenderCopy_RGBA8888_RGB888_Modulate_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3026 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3027 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3028 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3029 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3030 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3031 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3032 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3033 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3034 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3035 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3036 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3037
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3038 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3039 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3040 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3041 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3042
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3043 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3044 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3045 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3046 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3047 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3048 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3049 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3050 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3051 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3052 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3053 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3054 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3055 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3056 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3057 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3058 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3059 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3060 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3061 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3062 R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8); A = (Uint8)pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3063 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3064 R = (R * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3065 G = (G * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3066 B = (B * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3067 }
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3068 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3069 A = (A * modulateA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3070 }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3071 pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3072 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3073 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3074 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3075 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3076 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3077 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3078 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3079 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3080 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3081
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3082 int SDL_RenderCopy_RGBA8888_RGB888_Modulate_Blend(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3083 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3084 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3085 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3086 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3087 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3088 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3089 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3090 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3091 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3092 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3093
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3094 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3095 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3096 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3097 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3098 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3099 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3100 srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3101 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3102 dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3103 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3104 srcR = (srcR * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3105 srcG = (srcG * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3106 srcB = (srcB * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3107 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3108 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3109 srcA = (srcA * modulateA) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3110 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3111 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3112 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3113 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3114 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3115 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3116 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3117 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3118 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3119 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3120 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3121 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3122 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3123 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3124 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3125 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3126 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3127 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3128 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3129 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3130 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3131 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3132 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3133 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3134 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3135 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3136 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3137 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3138 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3139 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3140 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3141 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3142 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3143 dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3144 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3145 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3146 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3147 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3148 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3149 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3150 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3151 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3152 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3153
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3154 int SDL_RenderCopy_RGBA8888_RGB888_Modulate_Blend_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3155 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3156 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3157 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3158 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3159 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3160 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3161 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3162 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3163 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3164 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3165 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3166 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3167 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3168
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3169 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3170 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3171 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3172 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3173
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3174 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3175 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3176 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3177 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3178 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3179 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3180 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3181 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3182 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3183 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3184 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3185 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3186 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3187 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3188 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3189 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3190 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3191 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3192 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3193 srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3194 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3195 dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3196 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3197 srcR = (srcR * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3198 srcG = (srcG * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3199 srcB = (srcB * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3200 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3201 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3202 srcA = (srcA * modulateA) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3203 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3204 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3205 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3206 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3207 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3208 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3209 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3210 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3211 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3212 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3213 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3214 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3215 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3216 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3217 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3218 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3219 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3220 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3221 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3222 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3223 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3224 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3225 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3226 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3227 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3228 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3229 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3230 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3231 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3232 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3233 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3234 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3235 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3236 dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3237 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3238 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3239 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3240 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3241 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3242 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3243 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3244 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3245 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3246
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3247 int SDL_RenderCopy_RGBA8888_BGR888_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3248 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3249 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3250 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3251 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3252 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3253 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3254 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3255
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3256 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3257 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3258 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3259 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3260
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3261 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3262 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3263 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3264 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3265 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3266 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3267 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3268 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3269 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3270 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3271 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3272 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3273 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3274 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3275 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3276 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3277 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3278 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3279 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3280 R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8); A = (Uint8)pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3281 pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3282 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3283 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3284 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3285 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3286 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3287 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3288 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3289 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3290 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3291
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3292 int SDL_RenderCopy_RGBA8888_BGR888_Blend(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3293 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3294 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3295 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3296 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3297 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3298 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3299
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3300 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3301 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3302 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3303 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3304 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3305 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3306 srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3307 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3308 dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3309 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3310 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3311 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3312 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3313 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3314 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3315 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3316 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3317 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3318 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3319 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3320 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3321 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3322 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3323 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3324 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3325 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3326 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3327 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3328 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3329 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3330 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3331 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3332 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3333 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3334 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3335 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3336 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3337 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3338 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3339 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3340 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3341 dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3342 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3343 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3344 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3345 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3346 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3347 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3348 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3349 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3350 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3351
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3352 int SDL_RenderCopy_RGBA8888_BGR888_Blend_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3353 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3354 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3355 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3356 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3357 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3358 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3359 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3360 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3361 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3362
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3363 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3364 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3365 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3366 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3367
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3368 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3369 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3370 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3371 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3372 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3373 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3374 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3375 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3376 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3377 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3378 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3379 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3380 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3381 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3382 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3383 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3384 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3385 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3386 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3387 srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3388 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3389 dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3390 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3391 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3392 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3393 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3394 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3395 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3396 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3397 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3398 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3399 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3400 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3401 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3402 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3403 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3404 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3405 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3406 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3407 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3408 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3409 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3410 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3411 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3412 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3413 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3414 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3415 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3416 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3417 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3418 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3419 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3420 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3421 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3422 dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3423 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3424 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3425 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3426 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3427 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3428 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3429 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3430 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3431 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3432
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3433 int SDL_RenderCopy_RGBA8888_BGR888_Modulate(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3434 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3435 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3436 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3437 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3438 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3439 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3440 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3441 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3442
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3443 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3444 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3445 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3446 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3447 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3448 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3449 R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8); A = (Uint8)pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3450 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3451 R = (R * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3452 G = (G * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3453 B = (B * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3454 }
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3455 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3456 A = (A * modulateA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3457 }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3458 pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3459 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3460 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3461 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3462 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3463 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3464 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3465 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3466 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3467 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3468
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3469 int SDL_RenderCopy_RGBA8888_BGR888_Modulate_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3470 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3471 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3472 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3473 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3474 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3475 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3476 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3477 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3478 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3479 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3480 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3481
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3482 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3483 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3484 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3485 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3486
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3487 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3488 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3489 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3490 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3491 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3492 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3493 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3494 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3495 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3496 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3497 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3498 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3499 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3500 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3501 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3502 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3503 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3504 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3505 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3506 R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8); A = (Uint8)pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3507 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3508 R = (R * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3509 G = (G * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3510 B = (B * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3511 }
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3512 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3513 A = (A * modulateA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3514 }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3515 pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3516 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3517 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3518 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3519 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3520 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3521 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3522 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3523 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3524 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3525
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3526 int SDL_RenderCopy_RGBA8888_BGR888_Modulate_Blend(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3527 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3528 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3529 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3530 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3531 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3532 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3533 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3534 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3535 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3536 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3537
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3538 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3539 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3540 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3541 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3542 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3543 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3544 srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3545 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3546 dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3547 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3548 srcR = (srcR * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3549 srcG = (srcG * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3550 srcB = (srcB * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3551 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3552 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3553 srcA = (srcA * modulateA) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3554 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3555 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3556 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3557 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3558 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3559 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3560 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3561 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3562 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3563 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3564 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3565 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3566 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3567 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3568 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3569 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3570 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3571 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3572 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3573 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3574 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3575 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3576 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3577 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3578 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3579 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3580 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3581 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3582 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3583 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3584 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3585 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3586 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3587 dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3588 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3589 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3590 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3591 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3592 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3593 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3594 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3595 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3596 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3597
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3598 int SDL_RenderCopy_RGBA8888_BGR888_Modulate_Blend_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3599 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3600 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3601 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3602 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3603 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3604 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3605 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3606 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3607 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3608 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3609 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3610 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3611 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3612
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3613 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3614 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3615 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3616 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3617
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3618 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3619 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3620 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3621 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3622 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3623 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3624 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3625 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3626 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3627 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3628 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3629 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3630 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3631 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3632 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3633 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3634 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3635 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3636 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3637 srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3638 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3639 dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3640 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3641 srcR = (srcR * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3642 srcG = (srcG * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3643 srcB = (srcB * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3644 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3645 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3646 srcA = (srcA * modulateA) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3647 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3648 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3649 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3650 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3651 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3652 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3653 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3654 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3655 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3656 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3657 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3658 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3659 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3660 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3661 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3662 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3663 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3664 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3665 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3666 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3667 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3668 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3669 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3670 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3671 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3672 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3673 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3674 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3675 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3676 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3677 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3678 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3679 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3680 dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3681 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3682 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3683 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3684 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3685 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3686 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3687 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3688 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3689 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3690
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3691 int SDL_RenderCopy_ABGR8888_RGB888_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3692 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3693 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3694 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3695 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3696 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3697 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3698 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3699
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3700 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3701 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3702 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3703 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3704
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3705 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3706 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3707 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3708 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3709 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3710 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3711 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3712 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3713 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3714 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3715 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3716 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3717 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3718 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3719 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3720 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3721 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3722 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3723 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3724 A = (Uint8)(pixel >> 24); B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3725 pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3726 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3727 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3728 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3729 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3730 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3731 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3732 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3733 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3734 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3735
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3736 int SDL_RenderCopy_ABGR8888_RGB888_Blend(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3737 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3738 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3739 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3740 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3741 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3742 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3743
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3744 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3745 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3746 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3747 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3748 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3749 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3750 srcA = (Uint8)(srcpixel >> 24); srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3751 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3752 dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3753 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3754 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3755 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3756 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3757 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3758 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3759 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3760 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3761 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3762 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3763 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3764 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3765 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3766 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3767 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3768 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3769 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3770 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3771 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3772 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3773 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3774 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3775 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3776 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3777 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3778 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3779 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3780 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3781 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3782 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3783 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3784 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3785 dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3786 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3787 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3788 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3789 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3790 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3791 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3792 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3793 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3794 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3795
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3796 int SDL_RenderCopy_ABGR8888_RGB888_Blend_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3797 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3798 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3799 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3800 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3801 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3802 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3803 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3804 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3805 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3806
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3807 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3808 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3809 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3810 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3811
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3812 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3813 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3814 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3815 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3816 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3817 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3818 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3819 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3820 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3821 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3822 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3823 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3824 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3825 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3826 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3827 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3828 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3829 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3830 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3831 srcA = (Uint8)(srcpixel >> 24); srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3832 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3833 dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3834 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3835 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3836 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3837 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3838 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3839 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3840 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3841 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3842 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3843 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3844 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3845 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3846 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3847 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3848 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3849 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3850 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3851 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3852 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3853 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3854 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3855 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3856 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3857 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3858 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3859 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3860 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3861 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3862 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3863 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3864 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3865 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3866 dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3867 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3868 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3869 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3870 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3871 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3872 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3873 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3874 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3875 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3876
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3877 int SDL_RenderCopy_ABGR8888_RGB888_Modulate(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3878 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3879 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3880 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3881 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3882 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3883 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3884 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3885 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3886
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3887 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3888 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3889 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3890 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3891 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3892 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3893 A = (Uint8)(pixel >> 24); B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3894 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3895 R = (R * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3896 G = (G * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3897 B = (B * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3898 }
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3899 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3900 A = (A * modulateA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3901 }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3902 pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3903 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3904 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3905 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3906 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3907 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3908 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3909 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3910 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3911 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3912
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3913 int SDL_RenderCopy_ABGR8888_RGB888_Modulate_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3914 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3915 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3916 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3917 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3918 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3919 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3920 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3921 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3922 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3923 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3924 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3925
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3926 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3927 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3928 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3929 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3930
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3931 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3932 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3933 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3934 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3935 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3936 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3937 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3938 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3939 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3940 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3941 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3942 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3943 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3944 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3945 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3946 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3947 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3948 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3949 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3950 A = (Uint8)(pixel >> 24); B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3951 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3952 R = (R * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3953 G = (G * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3954 B = (B * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3955 }
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3956 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3957 A = (A * modulateA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
3958 }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3959 pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3960 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3961 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3962 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3963 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3964 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3965 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3966 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3967 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3968 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3969
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3970 int SDL_RenderCopy_ABGR8888_RGB888_Modulate_Blend(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3971 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3972 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3973 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3974 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3975 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3976 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3977 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3978 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3979 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3980 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3981
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3982 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3983 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3984 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3985 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3986 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3987 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3988 srcA = (Uint8)(srcpixel >> 24); srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3989 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3990 dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3991 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3992 srcR = (srcR * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3993 srcG = (srcG * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3994 srcB = (srcB * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3995 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3996 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3997 srcA = (srcA * modulateA) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3998 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3999 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4000 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4001 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4002 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4003 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4004 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4005 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4006 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4007 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4008 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4009 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4010 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4011 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4012 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4013 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4014 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4015 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4016 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4017 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4018 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4019 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4020 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4021 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4022 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4023 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4024 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4025 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4026 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4027 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4028 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4029 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4030 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4031 dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4032 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4033 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4034 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4035 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4036 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4037 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4038 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4039 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4040 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4041
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4042 int SDL_RenderCopy_ABGR8888_RGB888_Modulate_Blend_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4043 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4044 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4045 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4046 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4047 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4048 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4049 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4050 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4051 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4052 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4053 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4054 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4055 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4056
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4057 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4058 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4059 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4060 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4061
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4062 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4063 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4064 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4065 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4066 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4067 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4068 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4069 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4070 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4071 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4072 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4073 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4074 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4075 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4076 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4077 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4078 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4079 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4080 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4081 srcA = (Uint8)(srcpixel >> 24); srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4082 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4083 dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4084 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4085 srcR = (srcR * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4086 srcG = (srcG * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4087 srcB = (srcB * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4088 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4089 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4090 srcA = (srcA * modulateA) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4091 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4092 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4093 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4094 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4095 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4096 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4097 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4098 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4099 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4100 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4101 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4102 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4103 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4104 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4105 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4106 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4107 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4108 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4109 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4110 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4111 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4112 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4113 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4114 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4115 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4116 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4117 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4118 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4119 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4120 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4121 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4122 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4123 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4124 dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4125 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4126 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4127 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4128 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4129 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4130 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4131 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4132 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4133 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4134
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4135 int SDL_RenderCopy_ABGR8888_BGR888_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4136 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4137 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4138 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4139 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4140 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4141 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4142 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4143
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4144 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4145 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4146 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4147 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4148
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4149 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4150 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4151 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4152 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4153 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4154 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4155 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4156 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4157 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4158 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4159 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4160 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4161 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4162 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4163 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4164 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4165 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4166 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4167 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4168 A = (Uint8)(pixel >> 24); B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4169 pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4170 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4171 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4172 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4173 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4174 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4175 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4176 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4177 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4178 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4179
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4180 int SDL_RenderCopy_ABGR8888_BGR888_Blend(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4181 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4182 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4183 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4184 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4185 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4186 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4187
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4188 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4189 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4190 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4191 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4192 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4193 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4194 srcA = (Uint8)(srcpixel >> 24); srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4195 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4196 dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4197 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4198 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4199 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4200 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4201 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4202 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4203 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4204 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4205 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4206 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4207 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4208 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4209 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4210 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4211 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4212 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4213 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4214 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4215 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4216 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4217 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4218 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4219 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4220 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4221 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4222 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4223 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4224 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4225 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4226 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4227 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4228 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4229 dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4230 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4231 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4232 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4233 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4234 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4235 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4236 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4237 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4238 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4239
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4240 int SDL_RenderCopy_ABGR8888_BGR888_Blend_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4241 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4242 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4243 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4244 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4245 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4246 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4247 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4248 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4249 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4250
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4251 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4252 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4253 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4254 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4255
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4256 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4257 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4258 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4259 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4260 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4261 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4262 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4263 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4264 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4265 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4266 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4267 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4268 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4269 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4270 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4271 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4272 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4273 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4274 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4275 srcA = (Uint8)(srcpixel >> 24); srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4276 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4277 dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4278 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4279 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4280 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4281 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4282 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4283 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4284 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4285 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4286 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4287 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4288 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4289 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4290 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4291 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4292 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4293 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4294 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4295 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4296 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4297 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4298 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4299 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4300 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4301 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4302 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4303 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4304 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4305 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4306 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4307 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4308 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4309 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4310 dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4311 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4312 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4313 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4314 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4315 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4316 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4317 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4318 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4319 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4320
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4321 int SDL_RenderCopy_ABGR8888_BGR888_Modulate(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4322 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4323 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4324 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4325 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4326 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4327 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4328 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4329 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4330
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4331 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4332 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4333 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4334 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4335 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4336 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4337 A = (Uint8)(pixel >> 24); B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4338 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4339 R = (R * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4340 G = (G * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4341 B = (B * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4342 }
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4343 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4344 A = (A * modulateA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4345 }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4346 pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4347 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4348 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4349 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4350 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4351 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4352 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4353 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4354 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4355 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4356
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4357 int SDL_RenderCopy_ABGR8888_BGR888_Modulate_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4358 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4359 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4360 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4361 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4362 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4363 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4364 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4365 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4366 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4367 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4368 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4369
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4370 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4371 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4372 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4373 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4374
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4375 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4376 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4377 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4378 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4379 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4380 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4381 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4382 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4383 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4384 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4385 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4386 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4387 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4388 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4389 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4390 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4391 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4392 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4393 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4394 A = (Uint8)(pixel >> 24); B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4395 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4396 R = (R * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4397 G = (G * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4398 B = (B * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4399 }
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4400 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4401 A = (A * modulateA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4402 }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4403 pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4404 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4405 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4406 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4407 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4408 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4409 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4410 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4411 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4412 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4413
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4414 int SDL_RenderCopy_ABGR8888_BGR888_Modulate_Blend(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4415 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4416 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4417 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4418 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4419 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4420 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4421 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4422 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4423 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4424 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4425
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4426 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4427 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4428 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4429 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4430 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4431 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4432 srcA = (Uint8)(srcpixel >> 24); srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4433 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4434 dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4435 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4436 srcR = (srcR * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4437 srcG = (srcG * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4438 srcB = (srcB * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4439 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4440 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4441 srcA = (srcA * modulateA) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4442 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4443 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4444 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4445 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4446 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4447 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4448 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4449 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4450 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4451 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4452 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4453 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4454 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4455 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4456 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4457 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4458 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4459 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4460 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4461 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4462 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4463 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4464 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4465 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4466 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4467 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4468 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4469 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4470 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4471 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4472 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4473 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4474 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4475 dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4476 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4477 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4478 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4479 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4480 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4481 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4482 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4483 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4484 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4485
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4486 int SDL_RenderCopy_ABGR8888_BGR888_Modulate_Blend_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4487 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4488 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4489 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4490 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4491 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4492 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4493 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4494 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4495 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4496 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4497 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4498 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4499 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4500
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4501 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4502 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4503 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4504 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4505
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4506 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4507 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4508 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4509 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4510 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4511 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4512 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4513 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4514 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4515 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4516 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4517 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4518 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4519 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4520 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4521 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4522 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4523 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4524 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4525 srcA = (Uint8)(srcpixel >> 24); srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4526 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4527 dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4528 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4529 srcR = (srcR * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4530 srcG = (srcG * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4531 srcB = (srcB * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4532 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4533 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4534 srcA = (srcA * modulateA) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4535 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4536 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4537 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4538 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4539 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4540 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4541 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4542 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4543 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4544 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4545 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4546 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4547 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4548 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4549 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4550 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4551 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4552 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4553 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4554 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4555 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4556 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4557 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4558 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4559 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4560 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4561 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4562 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4563 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4564 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4565 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4566 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4567 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4568 dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4569 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4570 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4571 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4572 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4573 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4574 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4575 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4576 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4577 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4578
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4579 int SDL_RenderCopy_BGRA8888_RGB888_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4580 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4581 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4582 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4583 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4584 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4585 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4586 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4587
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4588 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4589 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4590 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4591 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4592
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4593 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4594 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4595 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4596 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4597 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4598 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4599 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4600 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4601 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4602 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4603 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4604 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4605 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4606 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4607 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4608 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4609 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4610 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4611 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4612 B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8); A = (Uint8)pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4613 pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4614 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4615 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4616 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4617 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4618 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4619 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4620 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4621 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4622 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4623
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4624 int SDL_RenderCopy_BGRA8888_RGB888_Blend(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4625 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4626 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4627 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4628 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4629 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4630 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4631
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4632 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4633 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4634 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4635 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4636 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4637 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4638 srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4639 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4640 dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4641 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4642 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4643 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4644 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4645 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4646 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4647 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4648 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4649 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4650 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4651 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4652 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4653 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4654 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4655 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4656 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4657 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4658 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4659 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4660 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4661 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4662 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4663 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4664 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4665 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4666 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4667 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4668 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4669 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4670 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4671 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4672 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4673 dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4674 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4675 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4676 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4677 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4678 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4679 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4680 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4681 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4682 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4683
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4684 int SDL_RenderCopy_BGRA8888_RGB888_Blend_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4685 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4686 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4687 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4688 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4689 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4690 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4691 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4692 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4693 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4694
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4695 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4696 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4697 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4698 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4699
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4700 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4701 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4702 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4703 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4704 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4705 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4706 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4707 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4708 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4709 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4710 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4711 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4712 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4713 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4714 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4715 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4716 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4717 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4718 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4719 srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4720 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4721 dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4722 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4723 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4724 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4725 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4726 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4727 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4728 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4729 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4730 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4731 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4732 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4733 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4734 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4735 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4736 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4737 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4738 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4739 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4740 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4741 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4742 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4743 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4744 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4745 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4746 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4747 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4748 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4749 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4750 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4751 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4752 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4753 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4754 dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4755 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4756 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4757 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4758 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4759 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4760 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4761 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4762 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4763 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4764
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4765 int SDL_RenderCopy_BGRA8888_RGB888_Modulate(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4766 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4767 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4768 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4769 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4770 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4771 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4772 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4773 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4774
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4775 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4776 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4777 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4778 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4779 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4780 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4781 B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8); A = (Uint8)pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4782 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4783 R = (R * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4784 G = (G * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4785 B = (B * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4786 }
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4787 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4788 A = (A * modulateA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4789 }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4790 pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4791 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4792 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4793 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4794 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4795 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4796 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4797 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4798 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4799 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4800
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4801 int SDL_RenderCopy_BGRA8888_RGB888_Modulate_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4802 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4803 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4804 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4805 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4806 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4807 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4808 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4809 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4810 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4811 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4812 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4813
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4814 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4815 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4816 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4817 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4818
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4819 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4820 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4821 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4822 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4823 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4824 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4825 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4826 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4827 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4828 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4829 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4830 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4831 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4832 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4833 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4834 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4835 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4836 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4837 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4838 B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8); A = (Uint8)pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4839 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4840 R = (R * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4841 G = (G * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4842 B = (B * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4843 }
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4844 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4845 A = (A * modulateA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4846 }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4847 pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4848 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4849 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4850 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4851 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4852 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4853 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4854 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4855 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4856 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4857
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4858 int SDL_RenderCopy_BGRA8888_RGB888_Modulate_Blend(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4859 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4860 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4861 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4862 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4863 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4864 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4865 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4866 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4867 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4868 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4869
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4870 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4871 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4872 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4873 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4874 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4875 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4876 srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4877 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4878 dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4879 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4880 srcR = (srcR * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4881 srcG = (srcG * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4882 srcB = (srcB * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4883 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4884 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4885 srcA = (srcA * modulateA) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4886 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4887 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4888 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4889 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4890 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4891 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4892 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4893 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4894 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4895 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4896 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4897 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4898 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4899 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4900 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4901 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4902 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4903 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4904 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4905 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4906 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4907 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4908 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4909 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4910 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4911 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4912 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4913 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4914 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4915 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4916 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4917 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4918 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4919 dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4920 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4921 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4922 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4923 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4924 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4925 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4926 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4927 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4928 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4929
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4930 int SDL_RenderCopy_BGRA8888_RGB888_Modulate_Blend_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4931 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4932 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4933 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4934 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4935 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4936 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4937 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4938 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4939 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4940 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4941 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4942 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4943 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4944
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4945 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4946 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4947 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4948 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4949
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4950 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4951 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4952 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4953 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4954 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4955 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4956 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4957 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4958 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4959 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4960 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4961 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4962 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4963 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4964 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4965 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4966 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4967 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4968 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4969 srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4970 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4971 dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4972 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4973 srcR = (srcR * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4974 srcG = (srcG * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4975 srcB = (srcB * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4976 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4977 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4978 srcA = (srcA * modulateA) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4979 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4980 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4981 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4982 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4983 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4984 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4985 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4986 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4987 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4988 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4989 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4990 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4991 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4992 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4993 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4994 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
4995 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4996 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4997 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4998 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4999 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5000 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5001 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5002 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5003 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5004 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5005 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5006 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5007 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5008 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5009 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5010 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5011 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5012 dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5013 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5014 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5015 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5016 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5017 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5018 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5019 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5020 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5021 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5022
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5023 int SDL_RenderCopy_BGRA8888_BGR888_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5024 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5025 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5026 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5027 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5028 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5029 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5030 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5031
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5032 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5033 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5034 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5035 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5036
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5037 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5038 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5039 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5040 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5041 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5042 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5043 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5044 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5045 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5046 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5047 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5048 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5049 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5050 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5051 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5052 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5053 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5054 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5055 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5056 B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8); A = (Uint8)pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5057 pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5058 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5059 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5060 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5061 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5062 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5063 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5064 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5065 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5066 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5067
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5068 int SDL_RenderCopy_BGRA8888_BGR888_Blend(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5069 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5070 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5071 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5072 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5073 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5074 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5075
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5076 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5077 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5078 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5079 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5080 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5081 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5082 srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5083 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5084 dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5085 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5086 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5087 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5088 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5089 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5090 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5091 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5092 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5093 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5094 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5095 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5096 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5097 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5098 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5099 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5100 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5101 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5102 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5103 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5104 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5105 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5106 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5107 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5108 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5109 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5110 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5111 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5112 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5113 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5114 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5115 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5116 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5117 dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5118 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5119 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5120 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5121 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5122 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5123 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5124 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5125 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5126 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5127
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5128 int SDL_RenderCopy_BGRA8888_BGR888_Blend_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5129 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5130 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5131 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5132 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5133 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5134 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5135 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5136 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5137 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5138
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5139 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5140 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5141 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5142 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5143
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5144 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5145 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5146 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5147 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5148 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5149 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5150 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5151 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5152 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5153 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5154 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5155 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5156 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5157 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5158 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5159 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5160 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5161 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5162 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5163 srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5164 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5165 dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5166 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5167 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5168 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5169 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5170 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5171 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5172 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5173 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5174 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5175 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5176 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5177 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5178 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5179 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5180 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5181 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5182 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5183 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5184 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5185 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5186 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5187 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5188 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5189 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5190 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5191 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5192 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5193 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5194 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5195 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5196 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5197 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5198 dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5199 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5200 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5201 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5202 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5203 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5204 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5205 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5206 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5207 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5208
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5209 int SDL_RenderCopy_BGRA8888_BGR888_Modulate(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5210 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5211 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5212 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5213 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5214 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5215 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5216 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5217 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5218
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5219 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5220 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5221 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5222 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5223 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5224 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5225 B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8); A = (Uint8)pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5226 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5227 R = (R * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5228 G = (G * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5229 B = (B * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5230 }
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5231 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5232 A = (A * modulateA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5233 }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5234 pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5235 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5236 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5237 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5238 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5239 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5240 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5241 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5242 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5243 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5244
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5245 int SDL_RenderCopy_BGRA8888_BGR888_Modulate_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5246 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5247 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5248 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5249 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5250 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5251 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5252 Uint32 pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5253 Uint32 R, G, B, A;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5254 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5255 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5256 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5257
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5258 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5259 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5260 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5261 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5262
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5263 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5264 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5265 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5266 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5267 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5268 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5269 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5270 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5271 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5272 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5273 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5274 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5275 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5276 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5277 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5278 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5279 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5280 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5281 pixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5282 B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8); A = (Uint8)pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5283 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5284 R = (R * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5285 G = (G * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5286 B = (B * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5287 }
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5288 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5289 A = (A * modulateA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5290 }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5291 pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5292 *dst = pixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5293 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5294 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5295 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5296 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5297 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5298 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5299 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5300 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5301
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5302 int SDL_RenderCopy_BGRA8888_BGR888_Modulate_Blend(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5303 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5304 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5305 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5306 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5307 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5308 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5309 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5310 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5311 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5312 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5313
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5314 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5315 Uint32 *src = (Uint32 *)data->src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5316 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5317 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5318 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5319 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5320 srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5321 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5322 dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5323 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5324 srcR = (srcR * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5325 srcG = (srcG * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5326 srcB = (srcB * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5327 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5328 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5329 srcA = (srcA * modulateA) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5330 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5331 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5332 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5333 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5334 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5335 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5336 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5337 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5338 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5339 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5340 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5341 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5342 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5343 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5344 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5345 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5346 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5347 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5348 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5349 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5350 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5351 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5352 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5353 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5354 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5355 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5356 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5357 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5358 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5359 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5360 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5361 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5362 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5363 dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5364 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5365 ++src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5366 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5367 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5368 data->src += data->src_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5369 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5370 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5371 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5372 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5373
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5374 int SDL_RenderCopy_BGRA8888_BGR888_Modulate_Blend_Scale(SDL_RenderCopyData *data)
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5375 {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5376 const int flags = data->flags;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5377 const Uint32 modulateR = data->r;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5378 const Uint32 modulateG = data->g;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5379 const Uint32 modulateB = data->b;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5380 const Uint32 modulateA = data->a;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5381 Uint32 srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5382 Uint32 srcR, srcG, srcB, srcA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5383 Uint32 dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5384 Uint32 dstR, dstG, dstB, dstA;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5385 int srcy, srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5386 int posy, posx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5387 int incy, incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5388
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5389 srcy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5390 posy = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5391 incy = (data->src_h << 16) / data->dst_h;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5392 incx = (data->src_w << 16) / data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5393
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5394 while (data->dst_h--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5395 Uint32 *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5396 Uint32 *dst = (Uint32 *)data->dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5397 int n = data->dst_w;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5398 srcx = -1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5399 posx = 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5400 while (posy >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5401 ++srcy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5402 posy -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5403 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5404 while (n--) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5405 if (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5406 while (posx >= 0x10000L) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5407 ++srcx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5408 posx -= 0x10000L;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5409 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5410 src = (Uint32 *)(data->src + (srcy * data->src_pitch) + (srcx * 4));
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5411 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5412 srcpixel = *src;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5413 srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5414 dstpixel = *dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5415 dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5416 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5417 srcR = (srcR * modulateR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5418 srcG = (srcG * modulateG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5419 srcB = (srcB * modulateB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5420 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5421 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5422 srcA = (srcA * modulateA) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5423 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5424 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5425 /* This goes away if we ever use premultiplied alpha */
1989
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5426 if (srcA < 255) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5427 srcR = (srcR * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5428 srcG = (srcG * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5429 srcB = (srcB * srcA) / 255;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5430 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5431 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5432 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5433 case SDL_RENDERCOPY_MASK:
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5434 if (srcA) {
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5435 dstR = srcR;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5436 dstG = srcG;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5437 dstB = srcB;
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5438 }
5b5f5de5433f Optimized the copy blitters a little bit
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
5439 break;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5440 case SDL_RENDERCOPY_BLEND:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5441 dstR = srcR + ((255 - srcA) * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5442 dstG = srcG + ((255 - srcA) * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5443 dstB = srcB + ((255 - srcA) * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5444 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5445 case SDL_RENDERCOPY_ADD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5446 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5447 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5448 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5449 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5450 case SDL_RENDERCOPY_MOD:
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5451 dstR = (srcR * dstR) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5452 dstG = (srcG * dstG) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5453 dstB = (srcB * dstB) / 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5454 break;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5455 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5456 dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5457 *dst = dstpixel;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5458 posx += incx;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5459 ++dst;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5460 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5461 posy += incy;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5462 data->dst += data->dst_pitch;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5463 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5464 return 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5465 }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5466
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5467 /* *INDENT-ON* */
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5468
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5469 /* vi: set ts=4 sw=4 expandtab: */