Repository navigation
Expand file tree
/
Copy pathBlendSpans.hpp
More file actions
50 lines (45 loc) · 2.43 KB
/
Copy pathBlendSpans.hpp
File metadata and controls
50 lines (45 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef JET_BLEND_SPANS_HPP
#define JET_BLEND_SPANS_HPP
#include <cstdint>
namespace Renderer {
enum class RGB565BlendMode : uint8_t { Alpha256, Alpha255, Add, AddAlpha256 };
enum RGB565BlendFlags : uint8_t {
BlendSwapDestination = 1,
BlendColorKey = 2,
BlendConstantBackground = 4
};
// Forward span blend. A null source means a solid foreground; with
// BlendConstantBackground, solidColor is the background instead (water).
// Alpha255 preserves sprite /255 rounding; Alpha256 preserves triangle /256.
// Add is the sprite's unscaled saturating add; AddAlpha256 scales source by
// (alpha+1)/256 before adding. Byte-swapped destinations are supported.
void blendRGB565Span(uint16_t* dst, const uint16_t* src, int count,
uint16_t solidColor, uint8_t alpha, RGB565BlendMode mode,
uint8_t flags = 0, uint16_t key = 0);
// Prepared /256 blend with one uniform colour. The variable pixels are
// foreground for water, or destination for a solid translucent triangle.
// Caller may reuse this state across spans with the same colour and alpha.
// Call prepare() before blend(). Source is required only for background=true;
// both modes accept native RGB565 and preserve forward framebuffer feedback.
struct alignas(16) RGB565ConstantBlend {
uint32_t lanes[20];
uint16_t color;
uint8_t alpha;
bool background;
void prepare(uint16_t solidColor, uint8_t a, bool constantBackground);
void blend(uint16_t* dst, const uint16_t* src, int count) const;
};
// Nearest-neighbour sprite row, using the compositor's original 8-bit fixed
// point source coordinate and signed step (negative for horizontal flips).
// Overlapping spans retain forward destination write order in either direction.
void blendRGB565ScaledSpan(uint16_t* dst, const uint16_t* src, int count,
int sourceX256, int step256, uint8_t alpha,
RGB565BlendMode mode, uint8_t flags = 0, uint16_t key = 0);
// Sample a row followed by its horizontal reflection. Coordinates address the
// expanded row (2 * sourceWidth texels); step256 must be non-negative.
// The two halves share one staging tile and SIMD blend, including at the seam.
void blendRGB565MirroredSpan(uint16_t* dst, const uint16_t* src, int sourceWidth,
int count, int sourceX256, int step256, uint8_t alpha,
RGB565BlendMode mode, uint8_t flags = 0, uint16_t key = 0);
}
#endif