forked from old/legacy-imlib2
parent
65dc01f834
commit
0776d7ff0d
144
src/rgbadraw.c
144
src/rgbadraw.c
|
@ -1632,9 +1632,8 @@ imlib_clip_line(int x0, int y0, int x1, int y1, int xmin, int xmax, int ymin,
|
|||
return accept;
|
||||
}
|
||||
|
||||
ImlibOutCode
|
||||
__imlib_comp_outcode(double x, double y, double xmin, double xmax,
|
||||
double ymin, double ymax)
|
||||
ImlibOutCode __imlib_comp_outcode(double x, double y, double xmin,
|
||||
double xmax, double ymin, double ymax)
|
||||
{
|
||||
ImlibOutCode code = 0;
|
||||
|
||||
|
@ -1649,7 +1648,8 @@ __imlib_comp_outcode(double x, double y, double xmin, double xmax,
|
|||
return code;
|
||||
}
|
||||
|
||||
ImlibPoly __imlib_polygon_new()
|
||||
ImlibPoly
|
||||
__imlib_polygon_new()
|
||||
{
|
||||
ImlibPoly poly;
|
||||
|
||||
|
@ -1738,7 +1738,7 @@ void
|
|||
__imlib_polygon_get_bounds(ImlibPoly poly, int *px1, int *py1, int *px2,
|
||||
int *py2)
|
||||
{
|
||||
int x1, y1, x2, y2;
|
||||
int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
|
||||
int i;
|
||||
|
||||
if (!poly || !poly->points || (poly->pointcount < 2))
|
||||
|
@ -1799,7 +1799,7 @@ __imlib_fill_ellipse(ImlibImage * im, int xc, int yc, int aa, int bb,
|
|||
int b2 = bb * bb;
|
||||
int y;
|
||||
int x, dec;
|
||||
int miny, maxy, iy1;
|
||||
int miny, maxy;
|
||||
|
||||
edgeRec *table1, *table2;
|
||||
|
||||
|
@ -1808,8 +1808,8 @@ __imlib_fill_ellipse(ImlibImage * im, int xc, int yc, int aa, int bb,
|
|||
memset(table1, 0, sizeof(edgeRec) * (im->h + 1));
|
||||
memset(table2, 0, sizeof(edgeRec) * (im->h + 1));
|
||||
|
||||
miny = yc - bb;
|
||||
maxy = yc + bb;
|
||||
miny = yc - bb - 1;
|
||||
maxy = yc + bb + 1;
|
||||
|
||||
for (x = 0, y = bb, dec = 2 * b2 + a2 * (1 - 2 * bb); b2 * x <= a2 * y;
|
||||
x++)
|
||||
|
@ -1854,7 +1854,7 @@ __imlib_fill_ellipse(ImlibImage * im, int xc, int yc, int aa, int bb,
|
|||
spanAA(im, miny, table1, table2, r, g, b, a, op);
|
||||
miny++;
|
||||
}
|
||||
while (miny <= maxy);
|
||||
while (miny < maxy);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1864,7 +1864,7 @@ __imlib_fill_ellipse(ImlibImage * im, int xc, int yc, int aa, int bb,
|
|||
span(im, miny, &table1[miny], &table2[miny], r, g, b, a, op);
|
||||
miny++;
|
||||
}
|
||||
while (miny <= maxy);
|
||||
while (miny < maxy);
|
||||
}
|
||||
free(table1);
|
||||
free(table2);
|
||||
|
@ -2012,7 +2012,7 @@ spanAA(ImlibImage * im, int y, edgeRec * pt1, edgeRec * pt2, DATA8 r, DATA8 g,
|
|||
double upramp_gradient = 0.0, downramp_gradient = 0.0;
|
||||
int upramp_len = 0, downramp_len = 0;
|
||||
int upramp_len1 = 0, downramp_len1 = 0;
|
||||
int ux1, ux2, top = 0, bottom = 0;
|
||||
int ux1, top = 0, bottom = 0;
|
||||
|
||||
x1 = pt1[y].x;
|
||||
x2 = pt2[y].x;
|
||||
|
@ -2022,81 +2022,29 @@ spanAA(ImlibImage * im, int y, edgeRec * pt1, edgeRec * pt2, DATA8 r, DATA8 g,
|
|||
/* see if there is a line above this one */
|
||||
if ((y > 0) && (pt1[y - 1].x != pt2[y - 1].x))
|
||||
{
|
||||
if (pt1[y - 1].x > pt1[y].x)
|
||||
{
|
||||
upramp_len = pt1[y - 1].x - pt1[y].x;
|
||||
upramp_len = (int) pt1[y - 1].x - (int) pt1[y].x;
|
||||
if (upramp_len != 0)
|
||||
upramp_gradient = 1.0 / (pt1[y - 1].x - pt1[y].x);
|
||||
downramp_len = (int) pt2[y].x - (int) pt2[y - 1].x;
|
||||
if (downramp_len != 0)
|
||||
downramp_gradient = 1.0 / (pt2[y].x - pt2[y - 1].x);
|
||||
}
|
||||
if (pt2[y].x > pt2[y - 1].x)
|
||||
{
|
||||
downramp_len = pt2[y].x - pt2[y - 1].x;
|
||||
downramp_gradient = 1.0 / (pt2[y - 1].x - pt2[y].x);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* there isn't - this is a special case for the top of a shape */
|
||||
top = 1;
|
||||
}
|
||||
|
||||
/* see if there is a line below this one */
|
||||
if ((pt1[y + 1].x != pt2[y + 1].x))
|
||||
else if ((pt1[y + 1].x != pt2[y + 1].x))
|
||||
{
|
||||
if (pt1[y + 1].x > pt1[y].x)
|
||||
{
|
||||
upramp_len1 = pt1[y + 1].x - pt1[y].x;
|
||||
if (upramp_gradient != 0.0)
|
||||
upramp_len = (int) pt1[y].x - (int) pt1[y + 1].x;
|
||||
if (upramp_len != 0 && upramp_gradient == 0.0)
|
||||
upramp_gradient = 1.0 / (pt1[y].x - pt1[y + 1].x);
|
||||
}
|
||||
if (pt2[y].x > pt2[y + 1].x)
|
||||
{
|
||||
downramp_len1 = pt2[y].x - pt2[y + 1].x;
|
||||
if (downramp_gradient != 0.0)
|
||||
downramp_len = (int) pt2[y].x - (int) pt2[y + 1].x;
|
||||
if (downramp_len != 0 && downramp_gradient == 0.0)
|
||||
downramp_gradient = 1.0 / (pt2[y].x - pt2[y + 1].x);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* there isn't - this is a special case for the bottom of a shape */
|
||||
bottom = 1;
|
||||
}
|
||||
|
||||
upramp_len = MAX(upramp_len, upramp_len1);
|
||||
downramp_len = MAX(downramp_len, downramp_len1);
|
||||
if (upramp_len < 0)
|
||||
upramp_len = 0 - upramp_len;
|
||||
if (downramp_len < 0)
|
||||
downramp_len = 0 - downramp_len;
|
||||
|
||||
if (top && !upramp_len && !downramp_len)
|
||||
{
|
||||
if ((pt1[y + 1].x != pt2[y + 1].x))
|
||||
{
|
||||
if (pt1[y + 1].x < pt1[y].x)
|
||||
{
|
||||
upramp_len = pt1[y].x - pt1[y + 1].x;
|
||||
upramp_gradient = 1.0 / (pt1[y + 1].x - pt1[y].x);
|
||||
}
|
||||
if (pt2[y].x < pt2[y + 1].x)
|
||||
{
|
||||
downramp_len = pt2[y + 1].x - pt2[y].x;
|
||||
downramp_gradient = 1.0 / (pt2[y + 1].x - pt2[y].x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bottom && !upramp_len && !downramp_len)
|
||||
{
|
||||
if ((pt1[y - 1].x != pt2[y - 1].x))
|
||||
{
|
||||
if (pt1[y - 1].x < pt1[y].x)
|
||||
{
|
||||
upramp_len = pt1[y].x - pt1[y - 1].x;
|
||||
upramp_gradient = 1.0 / (pt1[y - 1].x - pt1[y].x);
|
||||
}
|
||||
if (pt2[y].x < pt2[y - 1].x)
|
||||
{
|
||||
downramp_len = pt2[y - 1].x - pt2[y].x;
|
||||
downramp_gradient = 1.0 / (pt2[y - 1].x - pt2[y].x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (upramp_len > 0)
|
||||
{
|
||||
|
@ -2104,13 +2052,12 @@ spanAA(ImlibImage * im, int y, edgeRec * pt1, edgeRec * pt2, DATA8 r, DATA8 g,
|
|||
if (upramp_gradient >= 1.0 || upramp_gradient <= -1.0)
|
||||
{
|
||||
/* it's mostly vertical */
|
||||
double aa, x;
|
||||
double aa;
|
||||
DATA8 alpha;
|
||||
|
||||
x = pt1[y].x;
|
||||
aa = x - (double) ((int) x);
|
||||
aa = pt1[y].x - (double) ((int) pt1[y].x);
|
||||
alpha = (1.0 - aa) * a;
|
||||
p = &(im->data[(im->w * y) + (int) x]);
|
||||
p = &(im->data[(im->w * y) + (int) pt1[y].x]);
|
||||
switch (op)
|
||||
{
|
||||
case OP_RESHADE:
|
||||
|
@ -2129,7 +2076,7 @@ spanAA(ImlibImage * im, int y, edgeRec * pt1, edgeRec * pt2, DATA8 r, DATA8 g,
|
|||
break;
|
||||
}
|
||||
/* the final span start is shifted right */
|
||||
x1 += 2;
|
||||
x1++;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2143,7 +2090,7 @@ spanAA(ImlibImage * im, int y, edgeRec * pt1, edgeRec * pt2, DATA8 r, DATA8 g,
|
|||
da = a / (upramp_len);
|
||||
alpha = da;
|
||||
/* draw the upramp */
|
||||
for (ux1 = pt1[y].x; ux1 <= (pt1[y].x + upramp_len); ux1++)
|
||||
for (ux1 = pt1[y].x; ux1 < (int) (pt1[y].x + upramp_len); ux1++)
|
||||
{
|
||||
p = &(im->data[(im->w * y) + ux1]);
|
||||
switch (op)
|
||||
|
@ -2169,7 +2116,7 @@ spanAA(ImlibImage * im, int y, edgeRec * pt1, edgeRec * pt2, DATA8 r, DATA8 g,
|
|||
alpha += da;
|
||||
}
|
||||
/* the final span start is shifted */
|
||||
x1 += upramp_len + 1;
|
||||
x1 += upramp_len;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2179,13 +2126,12 @@ spanAA(ImlibImage * im, int y, edgeRec * pt1, edgeRec * pt2, DATA8 r, DATA8 g,
|
|||
if (downramp_gradient <= -1.0 || downramp_gradient >= 1.0)
|
||||
{
|
||||
/* it's mostly vertical */
|
||||
double aa, x;
|
||||
double aa;
|
||||
DATA8 alpha;
|
||||
|
||||
x = pt2[y].x;
|
||||
aa = x - (double) ((int) x);
|
||||
alpha = (1.0 - aa) * a;
|
||||
p = &(im->data[(im->w * y) + (int) x]);
|
||||
aa = pt2[y].x - (double) ((int) pt2[y].x);
|
||||
alpha = (aa - 1.0) * a;
|
||||
p = &(im->data[(im->w * y) + (int) pt2[y].x]);
|
||||
switch (op)
|
||||
{
|
||||
case OP_RESHADE:
|
||||
|
@ -2204,7 +2150,7 @@ spanAA(ImlibImage * im, int y, edgeRec * pt1, edgeRec * pt2, DATA8 r, DATA8 g,
|
|||
break;
|
||||
}
|
||||
/* the final span is shorter */
|
||||
x2 -= 2;
|
||||
x2--;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2217,8 +2163,8 @@ spanAA(ImlibImage * im, int y, edgeRec * pt1, edgeRec * pt2, DATA8 r, DATA8 g,
|
|||
else
|
||||
da = a / (downramp_len);
|
||||
alpha = a;
|
||||
/* draw the downramp (note: we are drawing right to left) */
|
||||
for (ux1 = pt2[y].x - downramp_len; ux1 <= pt2[y].x; ux1++)
|
||||
/* draw the downramp */
|
||||
for (ux1 = pt2[y].x - downramp_len + 1; ux1 <= (int) pt2[y].x; ux1++)
|
||||
{
|
||||
p = &(im->data[(im->w * y) + ux1]);
|
||||
switch (op)
|
||||
|
@ -2244,10 +2190,10 @@ spanAA(ImlibImage * im, int y, edgeRec * pt1, edgeRec * pt2, DATA8 r, DATA8 g,
|
|||
alpha -= da;
|
||||
}
|
||||
/* the final span is shorter */
|
||||
x2 -= downramp_len + 1;
|
||||
x2 -= downramp_len;
|
||||
}
|
||||
}
|
||||
if (x1 == x2)
|
||||
if (x2 <= x1)
|
||||
return;
|
||||
|
||||
/* just fill the remaining span */
|
||||
|
@ -2345,9 +2291,8 @@ __imlib_draw_polygon_filled(ImlibImage * im, ImlibPoly poly, int clip_xmin,
|
|||
pnt1 = iminy;
|
||||
pnt2 = iminy + 1;
|
||||
if (pnt2 >= poly->pointcount)
|
||||
{
|
||||
pnt2 = 0;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
edge(table1, &poly->points[pnt1], &poly->points[pnt2]);
|
||||
|
@ -2362,9 +2307,8 @@ __imlib_draw_polygon_filled(ImlibImage * im, ImlibPoly poly, int clip_xmin,
|
|||
pnt1 = imaxy;
|
||||
pnt2 = imaxy + 1;
|
||||
if (pnt2 >= poly->pointcount)
|
||||
{
|
||||
pnt2 = 0;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
edge(table2, &poly->points[pnt1], &poly->points[pnt2]);
|
||||
|
@ -2393,7 +2337,7 @@ __imlib_draw_polygon_filled(ImlibImage * im, ImlibPoly poly, int clip_xmin,
|
|||
spanAA(im, iy1, table1, table2, r, g, b, a, op);
|
||||
iy1++;
|
||||
}
|
||||
while (iy1 <= iy2);
|
||||
while (iy1 < iy2);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2402,7 +2346,7 @@ __imlib_draw_polygon_filled(ImlibImage * im, ImlibPoly poly, int clip_xmin,
|
|||
span(im, iy1, &table1[iy1], &table2[iy1], r, g, b, a, op);
|
||||
iy1++;
|
||||
}
|
||||
while (iy1 <= iy2);
|
||||
while (iy1 < iy2);
|
||||
}
|
||||
|
||||
free(table1);
|
||||
|
|
|
@ -23,3 +23,5 @@ loaderpath.h
|
|||
.icons
|
||||
bumpmaptest
|
||||
imlib2_test
|
||||
polytest
|
||||
core
|
||||
|
|
|
@ -11,7 +11,7 @@ INCLUDES = -I/usr/X11R6/include -I$(top_srcdir)/libltdl \
|
|||
-I. -I$(top_srcdir) -I$(top_srcdir)/src \
|
||||
-I$(top_srcdir)/loaders
|
||||
|
||||
bin_PROGRAMS = imlib2 bumpmaptest imlib2_test
|
||||
bin_PROGRAMS = imlib2 bumpmaptest imlib2_test polytest
|
||||
imlib2_SOURCES = main.c
|
||||
imlib2_LDADD = @DLLDFLAGS@ $(top_builddir)/libltdl/libltdlc.la \
|
||||
-lX11 -lXext -lttf -lImlib2
|
||||
|
@ -23,3 +23,7 @@ bumpmaptest_LDADD = @DLLDFLAGS@ $(top_builddir)/libltdl/libltdlc.la \
|
|||
imlib2_test_SOURCES = imlib2_test.c
|
||||
imlib2_test_LDADD = @DLLDFLAGS@ $(top_builddir)/libltdl/libltdlc.la \
|
||||
-lX11 -lXext -lttf -lImlib2
|
||||
|
||||
polytest_SOURCES = polytest.c
|
||||
polytest_LDADD = @DLLDFLAGS@ $(top_builddir)/libltdl/libltdlc.la \
|
||||
-lX11 -lXext -lttf -lImlib2
|
||||
|
|
|
@ -0,0 +1,126 @@
|
|||
#include <X11/Xlib.h>
|
||||
#include <X11/extensions/XShm.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/extensions/shape.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xos.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "Imlib2.h"
|
||||
|
||||
Display *disp;
|
||||
Window win;
|
||||
Visual *vis;
|
||||
Colormap cm;
|
||||
int depth;
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int w, h;
|
||||
Imlib_Image im_bg = NULL;
|
||||
XEvent ev;
|
||||
KeySym keysym;
|
||||
static char kbuf[20];
|
||||
ImlibPolygon poly, poly1, poly2;
|
||||
|
||||
/**
|
||||
* First tests to determine which rendering task to perform
|
||||
*/
|
||||
disp = XOpenDisplay(NULL);
|
||||
vis = DefaultVisual(disp, DefaultScreen(disp));
|
||||
depth = DefaultDepth(disp, DefaultScreen(disp));
|
||||
cm = DefaultColormap(disp, DefaultScreen(disp));
|
||||
win =
|
||||
XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100, 0, 0,
|
||||
0);
|
||||
XSelectInput(disp, win,
|
||||
ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
|
||||
PointerMotionMask | ExposureMask | KeyPressMask);
|
||||
XMapWindow(disp, win);
|
||||
|
||||
/**
|
||||
* Start rendering
|
||||
*/
|
||||
imlib_context_set_display(disp);
|
||||
imlib_context_set_visual(vis);
|
||||
imlib_context_set_colormap(cm);
|
||||
imlib_context_set_drawable(win);
|
||||
imlib_context_set_blend(0);
|
||||
imlib_context_set_color_modifier(NULL);
|
||||
imlib_context_set_blend(0);
|
||||
|
||||
im_bg = imlib_create_image(400, 400);
|
||||
imlib_context_set_image(im_bg);
|
||||
w = imlib_image_get_width();
|
||||
h = imlib_image_get_height();
|
||||
imlib_context_set_color(0, 0, 0, 255);
|
||||
imlib_image_fill_rectangle(0, 0, w, h);
|
||||
XResizeWindow(disp, win, w, h);
|
||||
XSync(disp, False);
|
||||
|
||||
poly = imlib_polygon_new();
|
||||
imlib_polygon_add_point(poly, 20, 20);
|
||||
imlib_polygon_add_point(poly, 70, 20);
|
||||
imlib_polygon_add_point(poly, 70, 70);
|
||||
imlib_polygon_add_point(poly, 20, 70);
|
||||
|
||||
poly1 = imlib_polygon_new();
|
||||
imlib_polygon_add_point(poly1, 100, 20);
|
||||
imlib_polygon_add_point(poly1, 190, 100);
|
||||
imlib_polygon_add_point(poly1, 120, 70);
|
||||
|
||||
poly2 = imlib_polygon_new();
|
||||
imlib_polygon_add_point(poly2, 290, 20);
|
||||
imlib_polygon_add_point(poly2, 200, 100);
|
||||
imlib_polygon_add_point(poly2, 270, 70);
|
||||
|
||||
while (1)
|
||||
{
|
||||
do
|
||||
{
|
||||
XNextEvent(disp, &ev);
|
||||
switch (ev.type)
|
||||
{
|
||||
case ButtonRelease:
|
||||
exit(0);
|
||||
break;
|
||||
case KeyPress:
|
||||
XLookupString(&ev.xkey, (char *) kbuf, sizeof(kbuf), &keysym,
|
||||
NULL);
|
||||
switch (*kbuf)
|
||||
{
|
||||
case ' ':
|
||||
imlib_context_set_anti_alias(!imlib_context_get_anti_alias
|
||||
());
|
||||
printf("AA is %s\n",
|
||||
imlib_context_get_anti_alias()? "on" : "off");
|
||||
break;
|
||||
case 'q':
|
||||
exit(0);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
while (XPending(disp));
|
||||
|
||||
imlib_context_set_image(im_bg);
|
||||
imlib_context_set_color(0, 0, 0, 255);
|
||||
imlib_image_fill_rectangle(0, 0, w, h);
|
||||
imlib_context_set_color(255, 255, 255, 255);
|
||||
imlib_image_fill_polygon(poly);
|
||||
imlib_image_fill_polygon(poly1);
|
||||
imlib_image_fill_polygon(poly2);
|
||||
imlib_render_image_on_drawable(0, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue