2003-03-16 21:11:39 +00:00
|
|
|
#include "render.h"
|
|
|
|
#include "gradient.h"
|
|
|
|
#include "color.h"
|
2003-06-20 07:58:51 +00:00
|
|
|
#include <glib.h>
|
2003-03-16 21:11:39 +00:00
|
|
|
|
2003-06-21 02:39:55 +00:00
|
|
|
static void highlight(RrPixel32 *x, RrPixel32 *y, gboolean raised);
|
|
|
|
static void gradient_solid(RrAppearance *l, int w, int h);
|
|
|
|
static void gradient_vertical(RrSurface *sf, int w, int h);
|
|
|
|
static void gradient_horizontal(RrSurface *sf, int w, int h);
|
|
|
|
static void gradient_diagonal(RrSurface *sf, int w, int h);
|
|
|
|
static void gradient_crossdiagonal(RrSurface *sf, int w, int h);
|
|
|
|
static void gradient_pyramid(RrSurface *sf, int inw, int inh);
|
|
|
|
|
|
|
|
void RrRender(RrAppearance *a, int w, int h)
|
2003-03-16 21:11:39 +00:00
|
|
|
{
|
2003-06-21 02:39:55 +00:00
|
|
|
RrPixel32 *data = a->surface.RrPixel_data;
|
2003-06-21 02:00:42 +00:00
|
|
|
RrPixel32 current;
|
2003-05-20 07:30:27 +00:00
|
|
|
unsigned int r,g,b;
|
|
|
|
int off, x;
|
|
|
|
|
2003-06-21 02:39:55 +00:00
|
|
|
switch (a->surface.grad) {
|
|
|
|
case RR_SURFACE_SOLID:
|
|
|
|
gradient_solid(a, w, h);
|
2003-05-20 07:30:27 +00:00
|
|
|
return;
|
2003-06-20 07:58:51 +00:00
|
|
|
case RR_SURFACE_VERTICAL:
|
2003-06-21 02:39:55 +00:00
|
|
|
gradient_vertical(&a->surface, w, h);
|
2003-05-20 07:30:27 +00:00
|
|
|
break;
|
2003-06-20 07:58:51 +00:00
|
|
|
case RR_SURFACE_HORIZONTAL:
|
2003-06-21 02:39:55 +00:00
|
|
|
gradient_horizontal(&a->surface, w, h);
|
2003-05-20 07:30:27 +00:00
|
|
|
break;
|
2003-06-20 07:58:51 +00:00
|
|
|
case RR_SURFACE_DIAGONAL:
|
2003-06-21 02:39:55 +00:00
|
|
|
gradient_diagonal(&a->surface, w, h);
|
2003-05-20 07:30:27 +00:00
|
|
|
break;
|
2003-06-20 07:58:51 +00:00
|
|
|
case RR_SURFACE_CROSS_DIAGONAL:
|
2003-06-21 02:39:55 +00:00
|
|
|
gradient_crossdiagonal(&a->surface, w, h);
|
2003-05-20 07:30:27 +00:00
|
|
|
break;
|
2003-06-20 07:58:51 +00:00
|
|
|
case RR_SURFACE_PYRAMID:
|
2003-06-21 02:39:55 +00:00
|
|
|
gradient_pyramid(&a->surface, w, h);
|
2003-05-20 07:30:27 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_message("unhandled gradient");
|
|
|
|
return;
|
|
|
|
}
|
2003-03-16 21:11:39 +00:00
|
|
|
|
2003-06-21 02:39:55 +00:00
|
|
|
if (a->surface.relief == RR_RELIEF_FLAT && a->surface.border) {
|
|
|
|
r = a->surface.border_color->r;
|
|
|
|
g = a->surface.border_color->g;
|
|
|
|
b = a->surface.border_color->b;
|
2003-06-21 02:26:50 +00:00
|
|
|
current = (r << RrDefaultRedOffset)
|
|
|
|
+ (g << RrDefaultGreenOffset)
|
|
|
|
+ (b << RrDefaultBlueOffset);
|
2003-05-20 07:30:27 +00:00
|
|
|
for (off = 0, x = 0; x < w; ++x, off++) {
|
|
|
|
*(data + off) = current;
|
|
|
|
*(data + off + ((h-1) * w)) = current;
|
|
|
|
}
|
|
|
|
for (off = 0, x = 0; x < h; ++x, off++) {
|
|
|
|
*(data + (off * w)) = current;
|
|
|
|
*(data + (off * w) + w - 1) = current;
|
|
|
|
}
|
2003-03-16 21:11:39 +00:00
|
|
|
}
|
|
|
|
|
2003-06-21 02:39:55 +00:00
|
|
|
if (a->surface.relief != RR_RELIEF_FLAT) {
|
|
|
|
if (a->surface.bevel == RR_BEVEL_1) {
|
2003-05-20 07:30:27 +00:00
|
|
|
for (off = 1, x = 1; x < w - 1; ++x, off++)
|
|
|
|
highlight(data + off,
|
|
|
|
data + off + (h-1) * w,
|
2003-06-21 02:39:55 +00:00
|
|
|
a->surface.relief==RR_RELIEF_RAISED);
|
2003-05-20 07:30:27 +00:00
|
|
|
for (off = 0, x = 0; x < h; ++x, off++)
|
|
|
|
highlight(data + off * w,
|
|
|
|
data + off * w + w - 1,
|
2003-06-21 02:39:55 +00:00
|
|
|
a->surface.relief==RR_RELIEF_RAISED);
|
2003-05-20 07:30:27 +00:00
|
|
|
}
|
|
|
|
|
2003-06-21 02:39:55 +00:00
|
|
|
if (a->surface.bevel == RR_BEVEL_2) {
|
2003-05-20 07:30:27 +00:00
|
|
|
for (off = 2, x = 2; x < w - 2; ++x, off++)
|
|
|
|
highlight(data + off + w,
|
|
|
|
data + off + (h-2) * w,
|
2003-06-21 02:39:55 +00:00
|
|
|
a->surface.relief==RR_RELIEF_RAISED);
|
2003-05-20 07:30:27 +00:00
|
|
|
for (off = 1, x = 1; x < h-1; ++x, off++)
|
|
|
|
highlight(data + off * w + 1,
|
|
|
|
data + off * w + w - 2,
|
2003-06-21 02:39:55 +00:00
|
|
|
a->surface.relief==RR_RELIEF_RAISED);
|
2003-05-20 07:30:27 +00:00
|
|
|
}
|
2003-03-16 21:11:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-21 02:39:55 +00:00
|
|
|
static void highlight(RrPixel32 *x, RrPixel32 *y, gboolean raised)
|
2003-03-16 21:11:39 +00:00
|
|
|
{
|
2003-05-20 07:30:27 +00:00
|
|
|
int r, g, b;
|
|
|
|
|
2003-06-21 02:00:42 +00:00
|
|
|
RrPixel32 *up, *down;
|
2003-05-20 07:30:27 +00:00
|
|
|
if (raised) {
|
|
|
|
up = x;
|
|
|
|
down = y;
|
|
|
|
} else {
|
|
|
|
up = y;
|
|
|
|
down = x;
|
|
|
|
}
|
2003-06-21 02:26:50 +00:00
|
|
|
r = (*up >> RrDefaultRedOffset) & 0xFF;
|
2003-05-20 07:30:27 +00:00
|
|
|
r += r >> 1;
|
2003-06-21 02:26:50 +00:00
|
|
|
g = (*up >> RrDefaultGreenOffset) & 0xFF;
|
2003-05-20 07:30:27 +00:00
|
|
|
g += g >> 1;
|
2003-06-21 02:26:50 +00:00
|
|
|
b = (*up >> RrDefaultBlueOffset) & 0xFF;
|
2003-05-20 07:30:27 +00:00
|
|
|
b += b >> 1;
|
|
|
|
if (r > 0xFF) r = 0xFF;
|
|
|
|
if (g > 0xFF) g = 0xFF;
|
|
|
|
if (b > 0xFF) b = 0xFF;
|
2003-06-21 02:26:50 +00:00
|
|
|
*up = (r << RrDefaultRedOffset) + (g << RrDefaultGreenOffset)
|
|
|
|
+ (b << RrDefaultBlueOffset);
|
2003-03-16 21:11:39 +00:00
|
|
|
|
2003-06-21 02:26:50 +00:00
|
|
|
r = (*down >> RrDefaultRedOffset) & 0xFF;
|
2003-05-20 07:30:27 +00:00
|
|
|
r = (r >> 1) + (r >> 2);
|
2003-06-21 02:26:50 +00:00
|
|
|
g = (*down >> RrDefaultGreenOffset) & 0xFF;
|
2003-05-20 07:30:27 +00:00
|
|
|
g = (g >> 1) + (g >> 2);
|
2003-06-21 02:26:50 +00:00
|
|
|
b = (*down >> RrDefaultBlueOffset) & 0xFF;
|
2003-05-20 07:30:27 +00:00
|
|
|
b = (b >> 1) + (b >> 2);
|
2003-06-21 02:26:50 +00:00
|
|
|
*down = (r << RrDefaultRedOffset) + (g << RrDefaultGreenOffset)
|
|
|
|
+ (b << RrDefaultBlueOffset);
|
2003-03-16 21:11:39 +00:00
|
|
|
}
|
|
|
|
|
2003-06-20 07:58:51 +00:00
|
|
|
static void create_bevel_colors(RrAppearance *l)
|
2003-05-20 07:30:27 +00:00
|
|
|
{
|
|
|
|
int r, g, b;
|
|
|
|
|
|
|
|
/* light color */
|
2003-06-20 00:05:51 +00:00
|
|
|
r = l->surface.primary->r;
|
2003-05-20 07:30:27 +00:00
|
|
|
r += r >> 1;
|
2003-06-20 00:05:51 +00:00
|
|
|
g = l->surface.primary->g;
|
2003-05-20 07:30:27 +00:00
|
|
|
g += g >> 1;
|
2003-06-20 00:05:51 +00:00
|
|
|
b = l->surface.primary->b;
|
2003-05-20 07:30:27 +00:00
|
|
|
b += b >> 1;
|
|
|
|
if (r > 0xFF) r = 0xFF;
|
|
|
|
if (g > 0xFF) g = 0xFF;
|
|
|
|
if (b > 0xFF) b = 0xFF;
|
2003-06-20 00:05:51 +00:00
|
|
|
g_assert(!l->surface.bevel_light);
|
2003-06-20 07:58:51 +00:00
|
|
|
l->surface.bevel_light = RrColorNew(l->inst, r, g, b);
|
2003-06-21 02:30:14 +00:00
|
|
|
RrColorAllocateGC(l->surface.bevel_light);
|
2003-05-20 07:30:27 +00:00
|
|
|
|
|
|
|
/* dark color */
|
2003-06-20 00:05:51 +00:00
|
|
|
r = l->surface.primary->r;
|
2003-05-20 07:30:27 +00:00
|
|
|
r = (r >> 1) + (r >> 2);
|
2003-06-20 00:05:51 +00:00
|
|
|
g = l->surface.primary->g;
|
2003-05-20 07:30:27 +00:00
|
|
|
g = (g >> 1) + (g >> 2);
|
2003-06-20 00:05:51 +00:00
|
|
|
b = l->surface.primary->b;
|
2003-05-20 07:30:27 +00:00
|
|
|
b = (b >> 1) + (b >> 2);
|
2003-06-20 00:05:51 +00:00
|
|
|
g_assert(!l->surface.bevel_dark);
|
2003-06-20 07:58:51 +00:00
|
|
|
l->surface.bevel_dark = RrColorNew(l->inst, r, g, b);
|
2003-06-21 02:30:14 +00:00
|
|
|
RrColorAllocateGC(l->surface.bevel_dark);
|
2003-05-20 07:30:27 +00:00
|
|
|
}
|
|
|
|
|
2003-06-21 02:39:55 +00:00
|
|
|
static void gradient_solid(RrAppearance *l, int w, int h)
|
2003-03-16 21:11:39 +00:00
|
|
|
{
|
2003-06-21 02:00:42 +00:00
|
|
|
RrPixel32 pix;
|
2003-05-20 07:30:27 +00:00
|
|
|
int i, a, b;
|
2003-06-20 07:58:51 +00:00
|
|
|
RrSurface *sp = &l->surface;
|
2003-06-21 02:39:55 +00:00
|
|
|
int left = 0, top = 0, right = w - 1, bottom = h - 1;
|
2003-05-20 07:30:27 +00:00
|
|
|
|
|
|
|
if (sp->primary->gc == None)
|
2003-06-21 02:30:14 +00:00
|
|
|
RrColorAllocateGC(sp->primary);
|
2003-06-21 02:26:50 +00:00
|
|
|
pix = (sp->primary->r << RrDefaultRedOffset)
|
|
|
|
+ (sp->primary->g << RrDefaultGreenOffset)
|
|
|
|
+ (sp->primary->b << RrDefaultBlueOffset);
|
2003-05-20 07:30:27 +00:00
|
|
|
|
2003-06-20 02:17:23 +00:00
|
|
|
for (a = 0; a < w; a++)
|
|
|
|
for (b = 0; b < h; b++)
|
2003-06-21 02:00:42 +00:00
|
|
|
sp->RrPixel_data[a + b * w] = pix;
|
2003-05-20 07:30:27 +00:00
|
|
|
|
2003-06-20 07:58:51 +00:00
|
|
|
XFillRectangle(RrDisplay(l->inst), l->pixmap, sp->primary->gc,
|
2003-06-21 02:39:55 +00:00
|
|
|
0, 0, w, h);
|
2003-05-20 07:30:27 +00:00
|
|
|
|
|
|
|
if (sp->interlaced) {
|
|
|
|
if (sp->secondary->gc == None)
|
2003-06-21 02:30:14 +00:00
|
|
|
RrColorAllocateGC(sp->secondary);
|
2003-06-21 02:39:55 +00:00
|
|
|
for (i = 0; i < h; i += 2)
|
2003-06-20 07:58:51 +00:00
|
|
|
XDrawLine(RrDisplay(l->inst), l->pixmap, sp->secondary->gc,
|
2003-06-21 02:39:55 +00:00
|
|
|
0, i, w, i);
|
2003-03-16 21:11:39 +00:00
|
|
|
}
|
2003-05-20 07:30:27 +00:00
|
|
|
|
|
|
|
switch (sp->relief) {
|
2003-06-20 07:58:51 +00:00
|
|
|
case RR_RELIEF_RAISED:
|
2003-05-20 07:30:27 +00:00
|
|
|
if (!sp->bevel_dark)
|
|
|
|
create_bevel_colors(l);
|
|
|
|
|
|
|
|
switch (sp->bevel) {
|
2003-06-20 07:58:51 +00:00
|
|
|
case RR_BEVEL_1:
|
|
|
|
XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_dark->gc,
|
2003-05-20 07:30:27 +00:00
|
|
|
left, bottom, right, bottom);
|
2003-06-20 07:58:51 +00:00
|
|
|
XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_dark->gc,
|
2003-05-20 07:30:27 +00:00
|
|
|
right, bottom, right, top);
|
|
|
|
|
2003-06-20 07:58:51 +00:00
|
|
|
XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_light->gc,
|
2003-05-20 07:30:27 +00:00
|
|
|
left, top, right, top);
|
2003-06-20 07:58:51 +00:00
|
|
|
XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_light->gc,
|
2003-05-20 07:30:27 +00:00
|
|
|
left, bottom, left, top);
|
|
|
|
break;
|
2003-06-20 07:58:51 +00:00
|
|
|
case RR_BEVEL_2:
|
|
|
|
XDrawLine(RrDisplay(l->inst), l->pixmap,
|
2003-05-20 07:30:27 +00:00
|
|
|
sp->bevel_dark->gc,
|
|
|
|
left + 1, bottom - 2, right - 2, bottom - 2);
|
2003-06-20 07:58:51 +00:00
|
|
|
XDrawLine(RrDisplay(l->inst), l->pixmap,
|
2003-05-20 07:30:27 +00:00
|
|
|
sp->bevel_dark->gc,
|
|
|
|
right - 2, bottom - 2, right - 2, top + 1);
|
|
|
|
|
2003-06-20 07:58:51 +00:00
|
|
|
XDrawLine(RrDisplay(l->inst), l->pixmap,
|
2003-05-20 07:30:27 +00:00
|
|
|
sp->bevel_light->gc,
|
|
|
|
left + 1, top + 1, right - 2, top + 1);
|
2003-06-20 07:58:51 +00:00
|
|
|
XDrawLine(RrDisplay(l->inst), l->pixmap,
|
2003-05-20 07:30:27 +00:00
|
|
|
sp->bevel_light->gc,
|
|
|
|
left + 1, bottom - 2, left + 1, top + 1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached(); /* unhandled BevelType */
|
|
|
|
}
|
|
|
|
break;
|
2003-06-20 07:58:51 +00:00
|
|
|
case RR_RELIEF_SUNKEN:
|
2003-05-20 07:30:27 +00:00
|
|
|
if (!sp->bevel_dark)
|
|
|
|
create_bevel_colors(l);
|
|
|
|
|
|
|
|
switch (sp->bevel) {
|
2003-06-20 07:58:51 +00:00
|
|
|
case RR_BEVEL_1:
|
|
|
|
XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_light->gc,
|
2003-05-20 07:30:27 +00:00
|
|
|
left, bottom, right, bottom);
|
2003-06-20 07:58:51 +00:00
|
|
|
XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_light->gc,
|
2003-05-20 07:30:27 +00:00
|
|
|
right, bottom, right, top);
|
2003-03-16 21:11:39 +00:00
|
|
|
|
2003-06-20 07:58:51 +00:00
|
|
|
XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_dark->gc,
|
2003-05-20 07:30:27 +00:00
|
|
|
left, top, right, top);
|
2003-06-20 07:58:51 +00:00
|
|
|
XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_dark->gc,
|
2003-05-20 07:30:27 +00:00
|
|
|
left, bottom, left, top);
|
|
|
|
break;
|
2003-06-20 07:58:51 +00:00
|
|
|
case RR_BEVEL_2:
|
|
|
|
XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_light->gc,
|
2003-05-20 07:30:27 +00:00
|
|
|
left + 1, bottom - 2, right - 2, bottom - 2);
|
2003-06-20 07:58:51 +00:00
|
|
|
XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_light->gc,
|
2003-05-20 07:30:27 +00:00
|
|
|
right - 2, bottom - 2, right - 2, top + 1);
|
2003-03-16 21:11:39 +00:00
|
|
|
|
2003-06-20 07:58:51 +00:00
|
|
|
XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_dark->gc,
|
2003-05-20 07:30:27 +00:00
|
|
|
left + 1, top + 1, right - 2, top + 1);
|
2003-06-20 07:58:51 +00:00
|
|
|
XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_dark->gc,
|
2003-05-20 07:30:27 +00:00
|
|
|
left + 1, bottom - 2, left + 1, top + 1);
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached(); /* unhandled BevelType */
|
|
|
|
}
|
|
|
|
break;
|
2003-06-20 07:58:51 +00:00
|
|
|
case RR_RELIEF_FLAT:
|
2003-05-21 02:59:02 +00:00
|
|
|
if (sp->border) {
|
|
|
|
if (sp->border_color->gc == None)
|
2003-06-21 02:30:14 +00:00
|
|
|
RrColorAllocateGC(sp->border_color);
|
2003-06-20 07:58:51 +00:00
|
|
|
XDrawRectangle(RrDisplay(l->inst), l->pixmap, sp->border_color->gc,
|
2003-05-20 07:30:27 +00:00
|
|
|
left, top, right, bottom);
|
2003-05-21 02:59:02 +00:00
|
|
|
}
|
2003-05-20 07:30:27 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached(); /* unhandled ReliefType */
|
2003-03-16 21:11:39 +00:00
|
|
|
}
|
|
|
|
}
|
2003-04-15 02:21:00 +00:00
|
|
|
|
2003-06-24 18:16:23 +00:00
|
|
|
/* * * * * * * * * * * * * * GRADIENT MAGIC WOOT * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
#define VARS(x) \
|
|
|
|
unsigned int color##x[3]; \
|
|
|
|
int len##x, cdelta##x[3], error##x[3] = { 0, 0, 0 }, inc##x[3]; \
|
|
|
|
gboolean bigslope##x[3] /* color slope > 1 */
|
|
|
|
|
|
|
|
#define SETUP(x, from, to, w) \
|
|
|
|
len##x = w; \
|
|
|
|
\
|
|
|
|
color##x[0] = from->r; \
|
|
|
|
color##x[1] = from->g; \
|
|
|
|
color##x[2] = from->b; \
|
|
|
|
\
|
|
|
|
cdelta##x[0] = to->r - from->r; \
|
|
|
|
cdelta##x[1] = to->g - from->g; \
|
|
|
|
cdelta##x[2] = to->b - from->b; \
|
|
|
|
\
|
|
|
|
if (cdelta##x[0] < 0) { \
|
|
|
|
cdelta##x[0] = -cdelta##x[0]; \
|
|
|
|
inc##x[0] = -1; \
|
|
|
|
} else \
|
|
|
|
inc##x[0] = 1; \
|
|
|
|
if (cdelta##x[1] < 0) { \
|
|
|
|
cdelta##x[1] = -cdelta##x[1]; \
|
|
|
|
inc##x[1] = -1; \
|
|
|
|
} else \
|
|
|
|
inc##x[1] = 1; \
|
|
|
|
if (cdelta##x[2] < 0) { \
|
|
|
|
cdelta##x[2] = -cdelta##x[2]; \
|
|
|
|
inc##x[2] = -1; \
|
|
|
|
} else \
|
|
|
|
inc##x[2] = 1; \
|
|
|
|
bigslope##x[0] = cdelta##x[0] > w;\
|
|
|
|
bigslope##x[1] = cdelta##x[1] > w;\
|
|
|
|
bigslope##x[2] = cdelta##x[2] > w
|
|
|
|
|
|
|
|
#define COLOR_RR(x, c) \
|
|
|
|
c->r = color##x[0]; \
|
|
|
|
c->g = color##x[1]; \
|
|
|
|
c->b = color##x[2]
|
|
|
|
|
|
|
|
#define COLOR(x) \
|
|
|
|
((color##x[0] << RrDefaultRedOffset) + \
|
|
|
|
(color##x[1] << RrDefaultGreenOffset) + \
|
|
|
|
(color##x[2] << RrDefaultBlueOffset))
|
|
|
|
|
|
|
|
#define NEXT(x) \
|
|
|
|
{ \
|
|
|
|
int i; \
|
|
|
|
for (i = 2; i >= 0; --i) { \
|
|
|
|
if (!cdelta##x[i]) continue; \
|
|
|
|
\
|
|
|
|
if (!bigslope##x[i]) { \
|
|
|
|
/* Y (color) is dependant on X */ \
|
|
|
|
error##x[i] += cdelta##x[i]; \
|
|
|
|
if ((error##x[i] << 1) >= len##x) { \
|
|
|
|
color##x[i] += inc##x[i]; \
|
|
|
|
error##x[i] -= len##x; \
|
|
|
|
} \
|
|
|
|
} else { \
|
|
|
|
/* X is dependant on Y (color) */ \
|
|
|
|
while (1) { \
|
|
|
|
color##x[i] += inc##x[i]; \
|
|
|
|
error##x[i] += len##x; \
|
|
|
|
if ((error##x[i] << 1) >= cdelta##x[i]) { \
|
|
|
|
error##x[i] -= cdelta##x[i]; \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gradient_horizontal(RrSurface *sf, int w, int h)
|
|
|
|
{
|
|
|
|
int x, y;
|
2003-06-24 18:56:47 +00:00
|
|
|
RrPixel32 *data = sf->RrPixel_data, *datav;
|
2003-06-24 18:16:23 +00:00
|
|
|
RrPixel32 current;
|
|
|
|
|
|
|
|
VARS(x);
|
|
|
|
SETUP(x, sf->primary, sf->secondary, w);
|
|
|
|
|
|
|
|
for (x = w - 1; x > 0; --x) { /* 0 -> w-1 */
|
|
|
|
current = COLOR(x);
|
2003-06-24 18:56:47 +00:00
|
|
|
datav = data;
|
|
|
|
for (y = h - 1; y >= 0; --y) { /* 0 -> h */
|
|
|
|
*datav = current;
|
|
|
|
datav += w;
|
|
|
|
}
|
2003-06-24 18:16:23 +00:00
|
|
|
++data;
|
|
|
|
|
|
|
|
NEXT(x);
|
|
|
|
}
|
|
|
|
current = COLOR(x);
|
|
|
|
for (y = h - 1; y >= 0; --y) /* 0 -> h */
|
|
|
|
*(data + y * w) = current;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gradient_vertical(RrSurface *sf, int w, int h)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
RrPixel32 *data = sf->RrPixel_data;
|
|
|
|
RrPixel32 current;
|
|
|
|
|
|
|
|
VARS(y);
|
|
|
|
SETUP(y, sf->primary, sf->secondary, h);
|
|
|
|
|
|
|
|
for (y = h - 1; y > 0; --y) { /* 0 -> h-1 */
|
|
|
|
current = COLOR(y);
|
|
|
|
for (x = w - 1; x >= 0; --x) /* 0 -> w */
|
|
|
|
*(data++) = current;
|
|
|
|
|
|
|
|
NEXT(y);
|
|
|
|
}
|
|
|
|
current = COLOR(y);
|
|
|
|
for (x = w - 1; x >= 0; --x) /* 0 -> w */
|
|
|
|
*(data++) = current;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void gradient_diagonal(RrSurface *sf, int w, int h)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
RrPixel32 *data = sf->RrPixel_data;
|
|
|
|
RrColor left, right;
|
|
|
|
RrColor extracorner;
|
|
|
|
|
|
|
|
VARS(lefty);
|
|
|
|
VARS(righty);
|
|
|
|
VARS(x);
|
|
|
|
|
|
|
|
extracorner.r = (sf->primary->r + sf->secondary->r) / 2;
|
|
|
|
extracorner.g = (sf->primary->g + sf->secondary->g) / 2;
|
|
|
|
extracorner.b = (sf->primary->b + sf->secondary->b) / 2;
|
|
|
|
|
|
|
|
SETUP(lefty, sf->primary, (&extracorner), h);
|
|
|
|
SETUP(righty, (&extracorner), sf->secondary, h);
|
|
|
|
|
|
|
|
for (y = h - 1; y > 0; --y) { /* 0 -> h-1 */
|
|
|
|
COLOR_RR(lefty, (&left));
|
|
|
|
COLOR_RR(righty, (&right));
|
|
|
|
|
|
|
|
SETUP(x, (&left), (&right), w);
|
|
|
|
|
|
|
|
for (x = w - 1; x > 0; --x) { /* 0 -> w-1 */
|
|
|
|
*(data++) = COLOR(x);
|
|
|
|
|
|
|
|
NEXT(x);
|
|
|
|
}
|
|
|
|
*(data++) = COLOR(x);
|
|
|
|
|
|
|
|
NEXT(lefty);
|
|
|
|
NEXT(righty);
|
|
|
|
}
|
|
|
|
COLOR_RR(lefty, (&left));
|
|
|
|
COLOR_RR(righty, (&right));
|
|
|
|
|
|
|
|
SETUP(x, (&left), (&right), w);
|
|
|
|
|
|
|
|
for (x = w - 1; x > 0; --x) { /* 0 -> w-1 */
|
|
|
|
*(data++) = COLOR(x);
|
|
|
|
|
|
|
|
NEXT(x);
|
|
|
|
}
|
|
|
|
*data = COLOR(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gradient_crossdiagonal(RrSurface *sf, int w, int h)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
RrPixel32 *data = sf->RrPixel_data;
|
|
|
|
RrColor left, right;
|
|
|
|
RrColor extracorner;
|
|
|
|
|
|
|
|
VARS(lefty);
|
|
|
|
VARS(righty);
|
|
|
|
VARS(x);
|
|
|
|
|
|
|
|
extracorner.r = (sf->primary->r + sf->secondary->r) / 2;
|
|
|
|
extracorner.g = (sf->primary->g + sf->secondary->g) / 2;
|
|
|
|
extracorner.b = (sf->primary->b + sf->secondary->b) / 2;
|
|
|
|
|
|
|
|
SETUP(lefty, (&extracorner), sf->secondary, h);
|
|
|
|
SETUP(righty, sf->primary, (&extracorner), h);
|
|
|
|
|
|
|
|
for (y = h - 1; y > 0; --y) { /* 0 -> h-1 */
|
|
|
|
COLOR_RR(lefty, (&left));
|
|
|
|
COLOR_RR(righty, (&right));
|
|
|
|
|
|
|
|
SETUP(x, (&left), (&right), w);
|
|
|
|
|
|
|
|
for (x = w - 1; x > 0; --x) { /* 0 -> w-1 */
|
|
|
|
*(data++) = COLOR(x);
|
|
|
|
|
|
|
|
NEXT(x);
|
|
|
|
}
|
|
|
|
*(data++) = COLOR(x);
|
|
|
|
|
|
|
|
NEXT(lefty);
|
|
|
|
NEXT(righty);
|
|
|
|
}
|
|
|
|
COLOR_RR(lefty, (&left));
|
|
|
|
COLOR_RR(righty, (&right));
|
|
|
|
|
|
|
|
SETUP(x, (&left), (&right), w);
|
|
|
|
|
|
|
|
for (x = w - 1; x > 0; --x) { /* 0 -> w-1 */
|
|
|
|
*(data++) = COLOR(x);
|
|
|
|
|
|
|
|
NEXT(x);
|
|
|
|
}
|
|
|
|
*data = COLOR(x);
|
|
|
|
}
|
|
|
|
|
2003-06-21 02:39:55 +00:00
|
|
|
static void gradient_pyramid(RrSurface *sf, int inw, int inh)
|
2003-04-15 02:21:00 +00:00
|
|
|
{
|
2003-06-24 18:16:23 +00:00
|
|
|
int x, y, w = (inw >> 1) + 1, h = (inh >> 1) + 1;
|
2003-06-21 02:00:42 +00:00
|
|
|
RrPixel32 *data = sf->RrPixel_data;
|
|
|
|
RrPixel32 *end = data + inw*inh - 1;
|
|
|
|
RrPixel32 current;
|
2003-06-24 18:16:23 +00:00
|
|
|
RrColor left, right;
|
|
|
|
RrColor extracorner;
|
2003-05-20 07:30:27 +00:00
|
|
|
|
2003-06-24 18:16:23 +00:00
|
|
|
VARS(lefty);
|
|
|
|
VARS(righty);
|
|
|
|
VARS(x);
|
|
|
|
|
|
|
|
extracorner.r = (sf->primary->r + sf->secondary->r) / 2;
|
|
|
|
extracorner.g = (sf->primary->g + sf->secondary->g) / 2;
|
|
|
|
extracorner.b = (sf->primary->b + sf->secondary->b) / 2;
|
|
|
|
|
|
|
|
SETUP(lefty, (&extracorner), sf->secondary, h);
|
|
|
|
SETUP(righty, sf->primary, (&extracorner), h);
|
|
|
|
|
|
|
|
for (y = h - 1; y > 0; --y) { /* 0 -> h-1 */
|
|
|
|
COLOR_RR(lefty, (&left));
|
|
|
|
COLOR_RR(righty, (&right));
|
2003-05-20 07:30:27 +00:00
|
|
|
|
2003-06-24 18:16:23 +00:00
|
|
|
SETUP(x, (&left), (&right), w);
|
|
|
|
|
|
|
|
for (x = w - 1; x > 0; --x) { /* 0 -> w-1 */
|
|
|
|
current = COLOR(x);
|
2003-05-20 07:30:27 +00:00
|
|
|
*(data+x) = current;
|
|
|
|
*(data+inw-x) = current;
|
|
|
|
*(end-x) = current;
|
|
|
|
*(end-(inw-x)) = current;
|
2003-06-24 18:16:23 +00:00
|
|
|
|
|
|
|
NEXT(x);
|
2003-05-20 07:30:27 +00:00
|
|
|
}
|
2003-06-24 18:16:23 +00:00
|
|
|
current = COLOR(x);
|
|
|
|
*(data+x) = current;
|
|
|
|
*(data+inw-x) = current;
|
|
|
|
*(end-x) = current;
|
|
|
|
*(end-(inw-x)) = current;
|
|
|
|
|
2003-05-20 07:30:27 +00:00
|
|
|
data+=inw;
|
|
|
|
end-=inw;
|
2003-06-24 18:16:23 +00:00
|
|
|
|
|
|
|
NEXT(lefty);
|
|
|
|
NEXT(righty);
|
|
|
|
}
|
|
|
|
COLOR_RR(lefty, (&left));
|
|
|
|
COLOR_RR(righty, (&right));
|
|
|
|
|
|
|
|
SETUP(x, (&left), (&right), w);
|
|
|
|
|
|
|
|
for (x = w - 1; x > 0; --x) { /* 0 -> w-1 */
|
|
|
|
current = COLOR(x);
|
|
|
|
*(data+x) = current;
|
|
|
|
*(data+inw-x) = current;
|
|
|
|
*(end-x) = current;
|
|
|
|
*(end-(inw-x)) = current;
|
|
|
|
|
|
|
|
NEXT(x);
|
2003-04-15 02:21:00 +00:00
|
|
|
}
|
2003-06-24 18:16:23 +00:00
|
|
|
*(data+x) = current;
|
|
|
|
*(data+inw-x) = current;
|
|
|
|
*(end-x) = current;
|
|
|
|
*(end-(inw-x)) = current;
|
2003-04-15 02:21:00 +00:00
|
|
|
}
|
|
|
|
|