blob: 4a60447bfcc8f375b3073a390592c555230e1b2d [file] [log] [blame]
#pragma once
#include <cstdint>
namespace eskia {
struct RGB_565 {
uint16_t r : 5;
uint16_t g : 6;
uint16_t b : 5;
};
struct BGR_565 {
uint16_t b : 5;
uint16_t g : 6;
uint16_t r : 5;
};
struct RGB_888 {
uint8_t r,g,b;
};
struct alignas(4) RGBA_8888 {
uint8_t r,g,b,a;
};
struct alignas(4) BGRA_8888 {
uint8_t b,g,r,a;
};
// Blend n RGBA_8888 pixels from src over dst,
// returning the pointer just past the last dst touched.
using BlendFn = void*(void* dst, const RGBA_8888* src, float coverage, int n);
// Shade a run of n destination pixels (x,y), (x+1,y) ...
// by calling paint.blend(dst, ..., coverage, ...).
using ShadeFn = void(const struct Paint&,
int x, int y, int n,
float coverage, void* dst);
struct Paint {
RGBA_8888 color = {0,0,0,0};
int unused = 0;
ShadeFn* shade = nullptr;
BlendFn* blend = nullptr;
};
// Src and SrcOver blends for each pixel format above as the destination.
BlendFn src_RGB_565, srcover_RGB_565,
src_BGR_565, srcover_BGR_565,
src_RGB_888, srcover_RGB_888,
src_RGBA_8888, srcover_RGBA_8888,
src_BGRA_8888, srcover_BGRA_8888;
// Shade a single color, Paint::color.
ShadeFn single_color;
// An affine tranform matrix.
//
// |x'| | sx kx tx | | x |
// |y'| = | ky sy ty | × | y |
// | 1 |
struct Affine {
float sx = 1.0f, kx = 0.0f, tx = 0.0f,
ky = 0.0f, sy = 1.0f, ty = 0.0f;
};
struct Rect { float l,t,r,b; };
struct Frame {
void* const dst;
const int width,
height,
bpp,
stride;
void fill(const Rect&, const Paint&);
void fill(const Rect&, const Paint&, const Affine&);
};
}