don't alloc/free colors every time splitvertical is drawn

This commit is contained in:
Dana Jansens 2007-06-13 13:48:00 +00:00
parent aaba799e1d
commit 89ade7a8c1
4 changed files with 48 additions and 28 deletions

View file

@ -421,50 +421,28 @@ static void gradient_solid(RrAppearance *l, gint w, gint h)
static void gradient_splitvertical(RrAppearance *a, gint w, gint h) static void gradient_splitvertical(RrAppearance *a, gint w, gint h)
{ {
gint x, y1, y2, y3, r, g, b; gint x, y1, y2, y3;
RrSurface *sf = &a->surface; RrSurface *sf = &a->surface;
RrPixel32 *data = sf->pixel_data; RrPixel32 *data = sf->pixel_data;
RrPixel32 current; RrPixel32 current;
RrColor *primary_light, *secondary_light;
gint y1sz, y2sz, y3sz; gint y1sz, y2sz, y3sz;
VARS(y1); VARS(y1);
VARS(y2); VARS(y2);
VARS(y3); VARS(y3);
r = sf->primary->r;
r += r >> 2;
g = sf->primary->g;
g += g >> 2;
b = sf->primary->b;
b += b >> 2;
if (r > 0xFF) r = 0xFF;
if (g > 0xFF) g = 0xFF;
if (b > 0xFF) b = 0xFF;
primary_light = RrColorNew(a->inst, r, g, b);
r = sf->secondary->r;
r += r >> 4;
g = sf->secondary->g;
g += g >> 4;
b = sf->secondary->b;
b += b >> 4;
if (r > 0xFF) r = 0xFF;
if (g > 0xFF) g = 0xFF;
if (b > 0xFF) b = 0xFF;
secondary_light = RrColorNew(a->inst, r, g, b);
y1sz = MAX(h/2 - 1, 1); y1sz = MAX(h/2 - 1, 1);
/* setup to get the colors _in between_ these other 2 */ /* setup to get the colors _in between_ these other 2 */
y2sz = (h < 3 ? 0 : (h % 2 ? 3 : 2)); y2sz = (h < 3 ? 0 : (h % 2 ? 3 : 2));
y3sz = MAX(h/2 - 1, 0); y3sz = MAX(h/2 - 1, 0);
SETUP(y1, primary_light, sf->primary, y1sz); SETUP(y1, sf->split_primary, sf->primary, y1sz);
if (y2sz) { if (y2sz) {
SETUP(y2, sf->primary, sf->secondary, y2sz); SETUP(y2, sf->primary, sf->secondary, y2sz);
NEXT(y2); /* skip the first one, its the same as the last of y1 */ NEXT(y2); /* skip the first one, its the same as the last of y1 */
} }
SETUP(y3, sf->secondary, secondary_light, y3sz); SETUP(y3, sf->secondary, sf->split_secondary, y3sz);
for (y1 = y1sz; y1 > 0; --y1) { for (y1 = y1sz; y1 > 0; --y1) {
current = COLOR(y1); current = COLOR(y1);
@ -489,9 +467,6 @@ static void gradient_splitvertical(RrAppearance *a, gint w, gint h)
NEXT(y3); NEXT(y3);
} }
RrColorFree(primary_light);
RrColorFree(secondary_light);
} }
static void gradient_horizontal(RrSurface *sf, gint w, gint h) static void gradient_horizontal(RrSurface *sf, gint w, gint h)

View file

@ -241,6 +241,20 @@ RrAppearance *RrAppearanceCopy(RrAppearance *orig)
spo->bevel_light->b); spo->bevel_light->b);
else spc->bevel_light = NULL; else spc->bevel_light = NULL;
if (spo->split_primary != NULL)
spc->split_primary = RrColorNew(copy->inst,
spo->split_primary->r,
spo->split_primary->g,
spo->split_primary->b);
else spc->split_primary = NULL;
if (spo->split_secondary != NULL)
spc->split_secondary = RrColorNew(copy->inst,
spo->split_secondary->r,
spo->split_secondary->g,
spo->split_secondary->b);
else spc->split_secondary = NULL;
spc->interlaced = spo->interlaced; spc->interlaced = spo->interlaced;
spc->bevel_light_adjust = spo->bevel_light_adjust; spc->bevel_light_adjust = spo->bevel_light_adjust;
spc->bevel_dark_adjust = spo->bevel_dark_adjust; spc->bevel_dark_adjust = spo->bevel_dark_adjust;
@ -284,6 +298,8 @@ void RrAppearanceFree(RrAppearance *a)
RrColorFree(p->interlace_color); RrColorFree(p->interlace_color);
RrColorFree(p->bevel_dark); RrColorFree(p->bevel_dark);
RrColorFree(p->bevel_light); RrColorFree(p->bevel_light);
RrColorFree(p->split_primary);
RrColorFree(p->split_secondary);
g_free(p->pixel_data); g_free(p->pixel_data);
p->pixel_data = NULL; p->pixel_data = NULL;
g_free(a); g_free(a);

View file

@ -125,6 +125,8 @@ struct _RrSurface {
RrPixel32 *pixel_data; RrPixel32 *pixel_data;
gint bevel_dark_adjust; /* 0-255, default is 64 */ gint bevel_dark_adjust; /* 0-255, default is 64 */
gint bevel_light_adjust; /* 0-255, default is 128 */ gint bevel_light_adjust; /* 0-255, default is 128 */
RrColor *split_primary;
RrColor *split_secondary;
}; };
struct _RrTextureText { struct _RrTextureText {

View file

@ -1797,6 +1797,33 @@ static gboolean read_appearance(XrmDatabase db, const RrInstance *inst,
value->surface.bevel_light_adjust = i; value->surface.bevel_light_adjust = i;
if (read_int(db, sname, &i) && i >= 0 && i <= 256) if (read_int(db, sname, &i) && i >= 0 && i <= 256)
value->surface.bevel_dark_adjust = i; value->surface.bevel_dark_adjust = i;
if (value->surface.grad == RR_SURFACE_SPLIT_VERTICAL) {
gint r, g, b;
r = value->surface.primary->r;
r += r >> 2;
g = value->surface.primary->g;
g += g >> 2;
b = value->surface.primary->b;
b += b >> 2;
if (r > 0xFF) r = 0xFF;
if (g > 0xFF) g = 0xFF;
if (b > 0xFF) b = 0xFF;
value->surface.split_primary = RrColorNew(inst, r, g, b);
r = value->surface.secondary->r;
r += r >> 4;
g = value->surface.secondary->g;
g += g >> 4;
b = value->surface.secondary->b;
b += b >> 4;
if (r > 0xFF) r = 0xFF;
if (g > 0xFF) g = 0xFF;
if (b > 0xFF) b = 0xFF;
value->surface.split_secondary = RrColorNew(inst, r, g, b);
}
ret = TRUE; ret = TRUE;
} }