forked from old/legacy-imlib2
make imlib2 demo event based - test rect combining code in handling exposures
and stuff - works it seesm - need to expand api though... expose handlign works fine as does rect mergeing and stuff.. must more efficient updating method now for demo.. template for stuff to be used by apps later :) SVN revision: 400
This commit is contained in:
parent
f31c797e33
commit
5f74b58718
7
api.c
7
api.c
|
@ -57,6 +57,13 @@ imlib_get_visual_depth(Display *display, Visual *visual)
|
|||
return __imlib_XActualDepth(display, visual);
|
||||
}
|
||||
|
||||
Visual *
|
||||
imlib_get_best_visual(Display *display, int screen,
|
||||
int *depth_return)
|
||||
{
|
||||
return __imlib_BestVisual(display, screen, depth_return);
|
||||
}
|
||||
|
||||
Imlib_Image
|
||||
imlib_load_image(char *file)
|
||||
{
|
||||
|
|
19
api.h
19
api.h
|
@ -2,10 +2,10 @@
|
|||
#define __IMLIB_API_H 1
|
||||
|
||||
#ifndef DATA64
|
||||
# define DATA64 unsigned long long
|
||||
# define DATA32 unsigned int
|
||||
# define DATA16 unsigned short
|
||||
# define DATA8 unsigned char
|
||||
#define DATA64 u_int64_t
|
||||
#define DATA32 u_int32_t
|
||||
#define DATA16 u_int16_t
|
||||
#define DATA8 u_int8_t
|
||||
#endif
|
||||
|
||||
/* data types - guess what - no transparent datatypes - all hidden */
|
||||
|
@ -78,6 +78,8 @@ int imlib_get_color_usage(void);
|
|||
void imlib_set_color_usage(int max);
|
||||
|
||||
int imlib_get_visual_depth(Display *display, Visual *visual);
|
||||
Visual *imlib_get_best_visual(Display *display, int screen,
|
||||
int *depth_return);
|
||||
|
||||
/* image loading functions */
|
||||
Imlib_Image imlib_load_image(char *file);
|
||||
|
@ -217,6 +219,11 @@ Imlib_Image imlib_create_cropped_scaled_image(Imlib_Image image,
|
|||
int source_height,
|
||||
int destination_width,
|
||||
int destination_height);
|
||||
#if 0 /* FIXME: must impliment */
|
||||
Imlib_Updates imlib_updates_init(void);
|
||||
Imlib_Updates imlib_updates_append_updates(Imlib_Updates updates,
|
||||
Imlib_Updates appended_updates);
|
||||
#endif
|
||||
Imlib_Updates imlib_update_append_rect(Imlib_Updates updates,
|
||||
int x, int y, int w, int h);
|
||||
Imlib_Updates imlib_updates_merge(Imlib_Updates updates, int w, int h);
|
||||
|
@ -280,7 +287,7 @@ void imlib_free_font(Imlib_Font font);
|
|||
void imlib_text_draw(Imlib_font font, Imlib_Image image, int x, int y,
|
||||
int width, int height, Imlib_Text_Direction direction,
|
||||
char *text, Imlib_Color *color,
|
||||
Imlib_Operation operation);
|
||||
Imlib_Operation operation, char wrap);
|
||||
void imlib_get_text_size(Imlib_font font, Imlib_Text_Direction direction,
|
||||
char *text, int *width_return,
|
||||
int *height_return);
|
||||
|
@ -294,7 +301,7 @@ Imlib_Rectangle *imlib_get_text_in_text_size_and_position(Imlib_font font,
|
|||
int imlib_get_character_index_and_location_in_text(Imlib_font font,
|
||||
Imlib_Text_Direction direction,
|
||||
int width, int height,
|
||||
char *text,
|
||||
char *text, char wrap,
|
||||
int *x_return,
|
||||
int *y_return,
|
||||
int *width_return,
|
||||
|
|
37
color.c
37
color.c
|
@ -25,6 +25,43 @@ __imlib_XActualDepth(Display *d, Visual *v)
|
|||
return depth;
|
||||
}
|
||||
|
||||
Visual *
|
||||
__imlib_BestVisual(Display *d, int screen, int *depth_return)
|
||||
{
|
||||
XVisualInfo xvi, *xvir;
|
||||
int i, num, maxd = 0;
|
||||
Visual *v = NULL;
|
||||
|
||||
xvi.screen = screen;
|
||||
for (xvi.class = TrueColor; xvi.class >= StaticGray; xvi.class--)
|
||||
{
|
||||
xvir = XGetVisualInfo(d, VisualScreenMask | VisualClassMask,
|
||||
&xvi, &num);
|
||||
if (xvir)
|
||||
{
|
||||
maxd = 0;
|
||||
for (i = 0; i < num; i++)
|
||||
{
|
||||
if (xvir[i].depth > maxd)
|
||||
{
|
||||
maxd = xvir[i].depth;
|
||||
v = xvir[i].visual;
|
||||
}
|
||||
}
|
||||
XFree(xvir);
|
||||
}
|
||||
if (v)
|
||||
{
|
||||
if (depth_return)
|
||||
*depth_return = maxd;
|
||||
return v;
|
||||
}
|
||||
}
|
||||
if (depth_return)
|
||||
*depth_return = maxd;
|
||||
return v;
|
||||
}
|
||||
|
||||
DATA8 *
|
||||
__imlib_AllocColorTable(Display *d, Colormap cmap, DATA8 *type_return)
|
||||
{
|
||||
|
|
1
color.h
1
color.h
|
@ -4,6 +4,7 @@
|
|||
extern DATA16 _max_colors;
|
||||
|
||||
int __imlib_XActualDepth(Display *d, Visual *v);
|
||||
Visual *__imlib_BestVisual(Display *d, int screen, int *depth_return);
|
||||
DATA8 * __imlib_AllocColorTable(Display *d, Colormap cmap, DATA8 *type_return);
|
||||
DATA8 * __imlib_AllocColors332(Display *d, Colormap cmap);
|
||||
DATA8 * __imlib_AllocColors232(Display *d, Colormap cmap);
|
||||
|
|
8
common.h
8
common.h
|
@ -4,10 +4,16 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/*
|
||||
#define DATA64 unsigned long long
|
||||
#define DATA32 unsigned int
|
||||
#define DATA16 unsigned short
|
||||
#define DATA8 unsigned char
|
||||
*/
|
||||
|
||||
#define DATA64 u_int64_t
|
||||
#define DATA32 u_int32_t
|
||||
#define DATA16 u_int16_t
|
||||
#define DATA8 u_int8_t
|
||||
|
||||
#endif
|
||||
|
|
160
main.c
160
main.c
|
@ -67,7 +67,7 @@ int main (int argc, char **argv)
|
|||
root = 1;
|
||||
else if (!strcmp(argv[i], "-smooth"))
|
||||
aa = 1;
|
||||
else if (!strcmp(argv[i], "-interactive"))
|
||||
else if (!strcmp(argv[i], "-loop"))
|
||||
{
|
||||
interactive = 0;
|
||||
loop = 1;
|
||||
|
@ -103,11 +103,16 @@ int main (int argc, char **argv)
|
|||
disp = XOpenDisplay(NULL);
|
||||
vis = DefaultVisual(disp, DefaultScreen(disp));
|
||||
depth = DefaultDepth(disp, DefaultScreen(disp));
|
||||
printf("%i\n", depth);
|
||||
cm = DefaultColormap(disp, DefaultScreen(disp));
|
||||
if (root)
|
||||
win = DefaultRootWindow(disp);
|
||||
else
|
||||
win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 10, 10, 0, 0, 0);
|
||||
{
|
||||
win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 10, 10, 0, 0, 0);
|
||||
XSelectInput(disp, win, ButtonPressMask | PointerMotionMask |
|
||||
ExposureMask);
|
||||
}
|
||||
if (!interactive)
|
||||
{
|
||||
im = imlib_load_image_with_progress_callback(file, progress, 0);
|
||||
|
@ -169,14 +174,21 @@ int main (int argc, char **argv)
|
|||
}
|
||||
else if (interactive)
|
||||
{
|
||||
int wo, ho;
|
||||
Imlib_Image im_bg, im_sh1, im_sh2, im_sh3, im_ic[13];
|
||||
int wo, ho, px, py, first = 1;
|
||||
Imlib_Image im_bg, im_sh1, im_sh2, im_sh3, im_ic[13], im_tmp;
|
||||
Imlib_Border border;
|
||||
|
||||
Imlib_Updates up = NULL;
|
||||
int x, y, dum, i, j;
|
||||
unsigned int dui;
|
||||
Window rt;
|
||||
XEvent ev;
|
||||
|
||||
|
||||
if (file)
|
||||
im_bg = imlib_load_image(file);
|
||||
else
|
||||
im_bg = imlib_load_image("test_images/bg.png");
|
||||
im_tmp = imlib_clone_image(im_bg);
|
||||
w = imlib_image_get_width(im_bg);
|
||||
h = imlib_image_get_height(im_bg);
|
||||
wo = w;
|
||||
|
@ -184,13 +196,39 @@ int main (int argc, char **argv)
|
|||
w *= 1;
|
||||
h *= 1;
|
||||
XResizeWindow(disp, win, w, h);
|
||||
XSync(disp, False);
|
||||
im = imlib_create_image(w, h);
|
||||
imlib_set_cache_size(4 * 1024 * 1024);
|
||||
i = 0;
|
||||
up = imlib_update_append_rect(up, 0, 0, w, h);
|
||||
x = -9999;
|
||||
y = -9999;
|
||||
while (1)
|
||||
{
|
||||
int x, y, dum, i, j;
|
||||
unsigned int dui;
|
||||
Window rt;
|
||||
px = x;
|
||||
py = y;
|
||||
do
|
||||
{
|
||||
XNextEvent(disp, &ev);
|
||||
switch (ev.type)
|
||||
{
|
||||
case Expose:
|
||||
up = imlib_update_append_rect(up,
|
||||
ev.xexpose.x, ev.xexpose.y,
|
||||
ev.xexpose.width, ev.xexpose.height);
|
||||
break;
|
||||
case ButtonPress:
|
||||
exit(0);
|
||||
break;
|
||||
case MotionNotify:
|
||||
x = ev.xmotion.x;
|
||||
y = ev.xmotion.y;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
while (XPending(disp));
|
||||
|
||||
im_sh1 = imlib_load_image("test_images/sh1.png");
|
||||
im_sh2 = imlib_load_image("test_images/sh2.png");
|
||||
|
@ -208,49 +246,101 @@ int main (int argc, char **argv)
|
|||
im_ic[10] = imlib_load_image("test_images/tnt.png");
|
||||
im_ic[11] = imlib_load_image("test_images/bulb.png");
|
||||
im_ic[12] = imlib_load_image("test_images/lock.png");
|
||||
XQueryPointer(disp, win, &rt, &rt, &dum, &dum,
|
||||
&x, &y, &dui);
|
||||
if ((dui) && (x > 0) && (y > 0) && (x < w) && (y < h))
|
||||
exit(0);
|
||||
imlib_blend_image_onto_image(im_bg, im,
|
||||
0, 0, 0,
|
||||
0, 0, wo, ho,
|
||||
0, 0, w, h,
|
||||
NULL, IMLIB_OP_COPY);
|
||||
for (j = 0; j < 32; j++)
|
||||
|
||||
if (first)
|
||||
{
|
||||
for (i = 0; i < 32; i++)
|
||||
imlib_blend_image_onto_image(im_bg, im,
|
||||
0, 0, 0,
|
||||
0, 0, w, h,
|
||||
0, 0, w, h,
|
||||
NULL, IMLIB_OP_COPY);
|
||||
first = 0;
|
||||
}
|
||||
if ((px != x) || (py != y))
|
||||
{
|
||||
for (j = 0; j < 32; j++)
|
||||
{
|
||||
int ic, iw, ih, ww, hh;
|
||||
|
||||
ic = ((j * 32) + i) % 13;
|
||||
iw = imlib_image_get_width(im_ic[ic]);
|
||||
ih = imlib_image_get_height(im_ic[ic]);
|
||||
ww = iw;
|
||||
hh = ih;
|
||||
imlib_blend_image_onto_image(im_ic[ic], im,
|
||||
aa, blend, 0,
|
||||
0, 0, iw, ih,
|
||||
x + (i * iw), y + (j * ih),
|
||||
ww, hh,
|
||||
NULL, IMLIB_OP_COPY);
|
||||
for (i = 0; i < 32; i++)
|
||||
{
|
||||
int ic, iw, ih, ww, hh;
|
||||
|
||||
ic = ((j * 32) + i) % 13;
|
||||
iw = imlib_image_get_width(im_ic[ic]);
|
||||
ih = imlib_image_get_height(im_ic[ic]);
|
||||
ww = iw;
|
||||
hh = ih;
|
||||
up = imlib_update_append_rect(up, x + (i * iw * 2),
|
||||
y + (j * ih * 2), ww, hh);
|
||||
up = imlib_update_append_rect(up, px + (i * iw * 2),
|
||||
py + (j * ih * 2), ww, hh);
|
||||
imlib_blend_image_onto_image(im_ic[ic], im,
|
||||
aa, blend, 0,
|
||||
0, 0, iw, ih,
|
||||
x + (i * iw * 2),
|
||||
y + (j * ih * 2),
|
||||
ww, hh,
|
||||
NULL, IMLIB_OP_COPY);
|
||||
}
|
||||
}
|
||||
}
|
||||
imlib_blend_image_onto_image(im_sh1, im,
|
||||
aa, blend, 0,
|
||||
0, 0, 50, 50,
|
||||
0, 0, 50, 50, NULL, IMLIB_OP_COPY);
|
||||
up = imlib_update_append_rect(up, 0, 0, 50, 50);
|
||||
imlib_blend_image_onto_image(im_sh2, im,
|
||||
aa, blend, 0,
|
||||
0, 0, 50, 50,
|
||||
50, 0, w - 50, 50, NULL, IMLIB_OP_COPY);
|
||||
up = imlib_update_append_rect(up, 50, 0, w - 50, 50);
|
||||
imlib_blend_image_onto_image(im_sh3, im,
|
||||
aa, blend, 0,
|
||||
0, 0, 50, 50,
|
||||
0, 50, 50, h - 50, NULL, IMLIB_OP_COPY);
|
||||
imlib_render_image_on_drawable(im, disp, win, vis,
|
||||
cm, depth, dith, 1, 0, 0, NULL,
|
||||
IMLIB_OP_COPY);
|
||||
up = imlib_update_append_rect(up, 0, 50, 50, h - 50);
|
||||
up = imlib_updates_merge(up, w, h);
|
||||
imlib_render_image_updates_on_drawable(im, up, disp, win, vis, cm,
|
||||
depth, dith, 0, 0, NULL);
|
||||
if ((px != x) || (py != y))
|
||||
{
|
||||
Imlib_Updates u;
|
||||
|
||||
u = up;
|
||||
while (u)
|
||||
{
|
||||
int ux, uy, uw, uh;
|
||||
|
||||
imlib_updates_get_coordinates(u, &ux, &uy, &uw, &uh);
|
||||
imlib_blend_image_onto_image(im_bg, im,
|
||||
0, 0, 0,
|
||||
ux, uy, uw, uh,
|
||||
ux, uy, uw, uh,
|
||||
NULL, IMLIB_OP_COPY);
|
||||
u = imlib_updates_get_next(u);
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
{
|
||||
Imlib_Updates up2;
|
||||
GC gc;
|
||||
XGCValues gcv;
|
||||
|
||||
gc = XCreateGC(disp, win, 0, &gcv);
|
||||
XSetForeground(disp, gc, 0xffff);
|
||||
up2 = up;
|
||||
while(up2)
|
||||
{
|
||||
int ux, uy, uw, uh;
|
||||
|
||||
imlib_updates_get_coordinates(up2, &ux, &uy, &uw, &uh);
|
||||
XDrawRectangle(disp, win, gc, ux, uy, uw - 1, uh - 1);
|
||||
up2 = imlib_updates_get_next(up2);
|
||||
}
|
||||
XFreeGC(disp, gc);
|
||||
}
|
||||
#endif
|
||||
imlib_updates_free(up);
|
||||
up = NULL;
|
||||
imlib_free_image(im_sh1);
|
||||
imlib_free_image(im_sh2);
|
||||
imlib_free_image(im_sh3);
|
||||
|
|
2
rend.c
2
rend.c
|
@ -149,7 +149,7 @@ __imlib_RenderImage(Display *d, ImlibImage *im,
|
|||
}
|
||||
/* do a double check in 24/32bpp */
|
||||
if ((xim->bits_per_pixel == 32) && (depth == 24))
|
||||
depth = 32;
|
||||
actual_depth = 32;
|
||||
if (m)
|
||||
{
|
||||
mxim = __imlib_ProduceXImage(d, v, 1, dw, dh, &shm);
|
||||
|
|
57
rgbadraw.c
57
rgbadraw.c
|
@ -166,7 +166,64 @@ __imlib_BlurImage(ImlibImage *im, int rad)
|
|||
void
|
||||
__imlib_SharpenImage(ImlibImage *im, int rad)
|
||||
{
|
||||
DATA32 *data, *p1, *p2;
|
||||
int a, r, g, b, x, y;
|
||||
/* FIXME: impliment */
|
||||
|
||||
data = malloc(im->w * im->h * sizeof(DATA32));
|
||||
if (rad == 0)
|
||||
return;
|
||||
else
|
||||
{
|
||||
int mul, mul2, tot;
|
||||
|
||||
mul = (rad * 4) + 1;
|
||||
mul2 = rad;
|
||||
tot = mul - (mul2 * 4);
|
||||
for (y = 1; y < (im->h - 1); y++)
|
||||
{
|
||||
p1 = im->data + 1 + (y * im->w);
|
||||
p2 = data + 1 + (y * im->w);
|
||||
for (x = 1; x < (im->w - 1); x++)
|
||||
{
|
||||
b = (int)((p1[0] ) & 0xff) * 5;
|
||||
g = (int)((p1[0] >> 8 ) & 0xff) * 5;
|
||||
r = (int)((p1[0] >> 16) & 0xff) * 5;
|
||||
a = (int)((p1[0] >> 24) & 0xff) * 5;
|
||||
b -= (int)((p1[-1] ) & 0xff);
|
||||
g -= (int)((p1[-1] >> 8 ) & 0xff);
|
||||
r -= (int)((p1[-1] >> 16) & 0xff);
|
||||
a -= (int)((p1[-1] >> 24) & 0xff);
|
||||
b -= (int)((p1[1] ) & 0xff);
|
||||
g -= (int)((p1[1] >> 8 ) & 0xff);
|
||||
r -= (int)((p1[1] >> 16) & 0xff);
|
||||
a -= (int)((p1[1] >> 24) & 0xff);
|
||||
b -= (int)((p1[-im->w] ) & 0xff);
|
||||
g -= (int)((p1[-im->w] >> 8 ) & 0xff);
|
||||
r -= (int)((p1[-im->w] >> 16) & 0xff);
|
||||
a -= (int)((p1[-im->w] >> 24) & 0xff);
|
||||
b -= (int)((p1[im->w] ) & 0xff);
|
||||
g -= (int)((p1[im->w] >> 8 ) & 0xff);
|
||||
r -= (int)((p1[im->w] >> 16) & 0xff);
|
||||
a -= (int)((p1[im->w] >> 24) & 0xff);
|
||||
|
||||
a = (a & ((~a) >> 16));
|
||||
a = ((a | ((a & 256) - ((a & 256) >> 8))) );
|
||||
r = (r & ((~r) >> 16));
|
||||
r = ((r | ((r & 256) - ((r & 256) >> 8))) );
|
||||
g = (g & ((~g) >> 16));
|
||||
g = ((g | ((g & 256) - ((g & 256) >> 8))) );
|
||||
b = (b & ((~b) >> 16));
|
||||
b = ((b | ((b & 256) - ((b & 256) >> 8))) );
|
||||
|
||||
*p2 = (a << 24) | (r << 16) | (g << 8) | b;
|
||||
p2++;
|
||||
p1++;
|
||||
}
|
||||
}
|
||||
}
|
||||
free(im->data);
|
||||
im->data = data;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
40
updates.c
40
updates.c
|
@ -12,9 +12,11 @@ struct _tile
|
|||
enum _t_used used;
|
||||
};
|
||||
|
||||
#define TB 5
|
||||
#define TM 31
|
||||
#define TS 32
|
||||
#define TBITS 5
|
||||
#define TB TBITS
|
||||
#define TM ((1 << TBITS) - 1)
|
||||
#define TS (1 << TBITS)
|
||||
|
||||
#define T(x, y) t[((y) * tw) + (x)]
|
||||
#define CLIP(x, y, w, h, xx, yy, ww, hh) \
|
||||
if (x < xx) {w += x; x = xx;} \
|
||||
|
@ -50,41 +52,45 @@ __imlib_MergeUpdate(ImlibUpdate *u, int w, int h)
|
|||
for (x = 0; x < tw; x++)
|
||||
t[i++].used = T_UNUSED;
|
||||
}
|
||||
/* fill in all tiles with minimum and maximum x & y values */
|
||||
/* fill in all tiles*/
|
||||
for (uu = u; uu; uu = uu->next)
|
||||
{
|
||||
CLIP(uu->x, uu->y, uu->w, uu->h, 0, 0, w, h);
|
||||
for (y = uu->y >> TB; y < ((uu->y + uu->h - 1) >> TB) + 1; y++)
|
||||
for (y = uu->y >> TB; y <= ((uu->y + uu->h - 1) >> TB); y++)
|
||||
{
|
||||
for (x = uu->x >> TB; x < ((uu->x + uu->w - 1) >> TB) + 1; x++)
|
||||
for (x = uu->x >> TB; x <= ((uu->x + uu->w - 1) >> TB); x++)
|
||||
T(x, y).used = T_USED;
|
||||
}
|
||||
}
|
||||
for (y = 0; y < th; y++)
|
||||
{
|
||||
for (x = 0; x < tw - 1; x++)
|
||||
for (x = 0; x < tw; x++)
|
||||
{
|
||||
if (T(x + 1, y).used & T_USED)
|
||||
if (T(x, y).used & T_USED)
|
||||
{
|
||||
int xx, yy, ww, hh, ok;
|
||||
|
||||
for (xx = x, ww = 0; (T(xx, y).used & T_USED) && (xx < tw);
|
||||
for (xx = x + 1, ww = 1;
|
||||
(T(xx, y).used & T_USED) && (xx < tw);
|
||||
xx++, ww++);
|
||||
for (yy = y, hh = 1, ok = 1; (yy < th) && (ok); yy++, hh++)
|
||||
for (yy = y + 1, hh = 1, ok = 1;
|
||||
(yy < th) && (ok);
|
||||
yy++, hh++)
|
||||
{
|
||||
for (xx = x; xx < ww; xx++)
|
||||
for (xx = x; xx < (x + ww); xx++)
|
||||
{
|
||||
if (!(T(xx, yy).used & T_USED))
|
||||
{
|
||||
ok = 0;
|
||||
xx = ww;
|
||||
xx = x + ww;
|
||||
hh--;
|
||||
}
|
||||
}
|
||||
if (ok)
|
||||
{
|
||||
for (xx = x; xx < ww; xx++)
|
||||
T(xx, yy).used = T_UNUSED;
|
||||
}
|
||||
}
|
||||
for (yy = y; yy < (y + hh); yy++)
|
||||
{
|
||||
for (xx = x; xx < (x + ww); xx++)
|
||||
T(xx, yy).used = T_UNUSED;
|
||||
}
|
||||
nu = __imlib_AddUpdate(nu, (x << TB), (y << TB),
|
||||
(ww << TB), (hh << TB));
|
||||
|
|
Loading…
Reference in New Issue