freemyipod r498 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r497‎ | r498 | r499 >
Date:21:53, 31 January 2011
Author:theseven
Status:new
Tags:
Comment:
libUI: Add blendcolor and mattecolor functions
Modified paths:
  • /libs/ui/blend.c (modified) (history)
  • /libs/ui/blend.h (modified) (history)
  • /libs/ui/export/libui.h (modified) (history)
  • /libs/ui/main.c (modified) (history)

Diff [purge]

Index: libs/ui/export/libui.h
@@ -46,6 +46,8 @@
4747 struct libui_api
4848 {
4949 typeof(blend)* blend;
 50+ typeof(blendcolor)* blendcolor;
 51+ typeof(mattecolor)* mattecolor;
5052 };
5153
5254 #endif
Index: libs/ui/blend.c
@@ -54,3 +54,54 @@
5555 out += (outstride - width) * 3;
5656 }
5757 }
 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 @@
2828
2929 struct libui_api apitable =
3030 {
31 - .blend = blend
 31+ .blend = blend,
 32+ .blendcolor = blendcolor,
 33+ .mattecolor = mattecolor,
3234 };
3335
3436 EMCORE_LIB_HEADER(0x49554365, LIBUI_API_VERSION, LIBUI_MIN_API_VERSION, NULL, NULL, apitable)
Index: libs/ui/blend.h
@@ -31,6 +31,12 @@
3232 void* outbuf, int outx, int outy, int outstride,
3333 void* in1buf, int in1x, int in1y, int in1stride,
3434 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);
3541
3642
3743 #endif