| Index: libs/ui/export/libui.h | 
| — | — | @@ -46,6 +46,8 @@ | 
| 47 | 47 | struct libui_api | 
| 48 | 48 | { | 
| 49 | 49 | typeof(blend)* blend; | 
|  | 50 | +    typeof(blendcolor)* blendcolor; | 
|  | 51 | +    typeof(mattecolor)* mattecolor; | 
| 50 | 52 | }; | 
| 51 | 53 |  | 
| 52 | 54 | #endif | 
| Index: libs/ui/blend.c | 
| — | — | @@ -54,3 +54,54 @@ | 
| 55 | 55 | out += (outstride - width) * 3; | 
| 56 | 56 | } | 
| 57 | 57 | } | 
|  | 58 | + | 
|  | 59 | +void blendcolor(int width, int height, uint32_t color, | 
|  | 60 | +                void* outbuf, int outx, int outy, int outstride, | 
|  | 61 | +                void* inbuf, int inx, int iny, int instride) | 
|  | 62 | +{ | 
|  | 63 | +    char* in = (char*)inbuf + (inx + iny * instride) * 3; | 
|  | 64 | +    char* out = (char*)outbuf + (outx + outy * outstride) * 3; | 
|  | 65 | +    int r = (color >> 0) & 0xff; | 
|  | 66 | +    int g = (color >> 8) & 0xff; | 
|  | 67 | +    int b = (color >> 16) & 0xff; | 
|  | 68 | +    int a = (color >> 24) & 0xff; | 
|  | 69 | +    int x, y; | 
|  | 70 | +    for (y = 0; y < height; y++) | 
|  | 71 | +    { | 
|  | 72 | +        for (x = 0; x < width; x++) | 
|  | 73 | +        { | 
|  | 74 | +            *out++ = (a * r + (255 - a) * *in++) >> 8; | 
|  | 75 | +            *out++ = (a * g + (255 - a) * *in++) >> 8; | 
|  | 76 | +            *out++ = (a * b + (255 - a) * *in++) >> 8; | 
|  | 77 | +        } | 
|  | 78 | +        in += (instride - width) * 3; | 
|  | 79 | +        out += (outstride - width) * 3; | 
|  | 80 | +    } | 
|  | 81 | +} | 
|  | 82 | + | 
|  | 83 | +void mattecolor(int width, int height, uint32_t color, | 
|  | 84 | +                void* outbuf, int outx, int outy, int outstride, | 
|  | 85 | +                void* inbuf, int inx, int iny, int instride) | 
|  | 86 | +{ | 
|  | 87 | +    char* in = (char*)inbuf + (inx + iny * instride) * 4; | 
|  | 88 | +    char* out = (char*)outbuf + (outx + outy * outstride) * 3; | 
|  | 89 | +    int mr = (color >> 0) & 0xff; | 
|  | 90 | +    int mg = (color >> 8) & 0xff; | 
|  | 91 | +    int mb = (color >> 16) & 0xff; | 
|  | 92 | +    int x, y; | 
|  | 93 | +    for (y = 0; y < height; y++) | 
|  | 94 | +    { | 
|  | 95 | +        for (x = 0; x < width; x++) | 
|  | 96 | +        { | 
|  | 97 | +            int r = *in++; | 
|  | 98 | +            int g = *in++; | 
|  | 99 | +            int b = *in++; | 
|  | 100 | +            int a = *in++; | 
|  | 101 | +            *out++ = (a * r + (255 - a) * mr) >> 8; | 
|  | 102 | +            *out++ = (a * g + (255 - a) * mg) >> 8; | 
|  | 103 | +            *out++ = (a * b + (255 - a) * mb) >> 8; | 
|  | 104 | +        } | 
|  | 105 | +        in += (instride - width) * 4; | 
|  | 106 | +        out += (outstride - width) * 3; | 
|  | 107 | +    } | 
|  | 108 | +} | 
| Index: libs/ui/main.c | 
| — | — | @@ -27,7 +27,9 @@ | 
| 28 | 28 |  | 
| 29 | 29 | struct libui_api apitable = | 
| 30 | 30 | { | 
| 31 |  | -    .blend = blend
 | 
|  | 31 | +    .blend = blend, | 
|  | 32 | +    .blendcolor = blendcolor, | 
|  | 33 | +    .mattecolor = mattecolor, | 
| 32 | 34 | }; | 
| 33 | 35 |  | 
| 34 | 36 | EMCORE_LIB_HEADER(0x49554365, LIBUI_API_VERSION, LIBUI_MIN_API_VERSION, NULL, NULL, apitable) | 
| Index: libs/ui/blend.h | 
| — | — | @@ -31,6 +31,12 @@ | 
| 32 | 32 | void* outbuf, int outx, int outy, int outstride, | 
| 33 | 33 | void* in1buf, int in1x, int in1y, int in1stride, | 
| 34 | 34 | void* in2buf, int in2x, int in2y, int in2stride); | 
|  | 35 | +void blendcolor(int width, int height, uint32_t color, | 
|  | 36 | +                void* outbuf, int outx, int outy, int outstride, | 
|  | 37 | +                void* inbuf, int inx, int iny, int instride); | 
|  | 38 | +void mattecolor(int width, int height, uint32_t color, | 
|  | 39 | +                void* outbuf, int outx, int outy, int outstride, | 
|  | 40 | +                void* inbuf, int inx, int iny, int instride); | 
| 35 | 41 |  | 
| 36 | 42 |  | 
| 37 | 43 | #endif |