1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748
|
#include <version.h>
struct image;
void pgtk_encode_truecolor_masks(struct image *i,
int bitspp,
int pad,
int byteorder,
unsigned int red_mask,
unsigned int green_mask,
unsigned int blue_mask,
unsigned char *buffer,
int debuglen);
void pgtk_encode_grey(struct image *i, unsigned char *dest, int bpp, int bpl );
void *get_swapped_string( struct pike_string *s,int force_wide )
{
int i;
unsigned short *res, *tmp;
#if (BYTEORDER!=4321)
switch(s->size_shift)
{
default:
return 0;
case 1:
{
res= malloc(s->len * 2);
tmp = (unsigned short *)s->str;
for(i=0;i<s->len; i++)
res[i] = htons( tmp[i] );
return res;
}
}
#endif
if(force_wide)
{
switch(s->size_shift)
{
case 0:
res = malloc(s->len*2);
for(i=0;i<s->len;i++)
res[i] = htons( (short)(((unsigned char *)s->str)[i]) );
return res;
case 1:
return 0;
case 2:
res = malloc(s->len*2);
for(i=0;i<s->len;i++)
res[i] = htons( (short)(((unsigned int *)s->str)[i]) );
return res;
}
}
#ifdef DEBUG
fatal("not reached\n");
#endif
return 0;
}
struct object *pikeimage_from_gdkimage( GdkImage *img )
{
}
GdkImage *gdkimage_from_pikeimage( struct object *img, int fast, GdkImage *i )
{
GdkColormap *col = gdk_colormap_get_system();
GdkVisual *vis = gdk_visual_get_system();
int x, y;
/* 1a: create the actual image... */
TIMER_INIT("Creating image");
apply(img, "xsize", 0); apply(img, "ysize", 0);
get_all_args("internal", 2, "%d%d", &x, &y);
pop_n_elems( 2 );
if( x==0 || y==0 )
error("Size of image must be != 0x0\n");
if(i)
{
if(i->width != x || i->height != y)
{
gdk_image_destroy((void *)i);
i= NULL;
}
}
if(!i)
i = (void *)gdk_image_new(fast, vis, x, y);
if(!i)
error("Failed to create gdkimage\n");
/* 1b: do the work.. */
if(vis->type == GDK_VISUAL_TRUE_COLOR || vis->type == GDK_VISUAL_STATIC_GRAY)
/* no colormap.. */
{
int pad = 0;
int native_byteorder;
PFTIME("Convert");
if(vis->type == GDK_VISUAL_STATIC_GRAY)
pgtk_encode_grey( (void *)img->storage, i->mem, i->bpp, i->bpl );
else
{
switch(i->bpl - (i->bpp*x))
{
case 0: pad = 0; break;
case 1: pad = 2; break;
default: pad = 4; break;
}
pgtk_encode_truecolor_masks( (void *)img->storage, i->bpp*8, pad*8,
(i->byte_order!=MSBFirst), vis->red_mask,
vis->green_mask, vis->blue_mask,
i->mem, i->bpl*y );
}
} else {
static int colors_allocated = 0;
static struct object *pike_cmap;
/* I hate this... colormaps, here we come.. */
/* This is rather complicated, but:
1/ build an array of the colors in the colormap
2/ use that array to build a pike X-image colormap.
3/ call Image.X.encode_pseudocolor( img, bpp, lpad, depth, colormp )
4/ copy the actual data to the image..
*/
if(!colors_allocated)
{
#define COLORMAP_SIZE 256
char allocated[COLORMAP_SIZE];
int j, i, r, g, b;
PFTIME("Creating colormap");
colors_allocated=1;
MEMSET(allocated, 0, sizeof(allocated));
for(r=0; r<3; r++) for(g=0; g<4; g++) for(b=0; b<3; b++)
{
GdkColor color;
color.red = (int)(r * (65535/2.0));
color.green = (int)(g * (65535/3.0));
color.blue = (int)(b * (65535/2.0));
color.pixel = 0;
if(gdk_color_alloc( col, &color ))
if(color.pixel < COLORMAP_SIZE)
allocated[ color.pixel ] = 1;
}
for(r=0; r<6; r++) for(g=0; g<7; g++) for(b=0; b<6; b++)
{
GdkColor color;
color.red = (int)(r * (65535/5.0));
color.green = (int)(g * (65535/6.0));
color.blue = (int)(b * (65535/5.0));
color.pixel = 0;
if(gdk_color_alloc( col, &color ))
if(color.pixel < COLORMAP_SIZE)
allocated[ color.pixel ] = 1;
}
for(i=0; i<COLORMAP_SIZE; i++)
{
if( allocated[ i ] )
{
push_int(col->colors[i].red>>8);
push_int(col->colors[i].green>>8);
push_int(col->colors[i].blue>>8);
f_aggregate(3);
}
else
push_int(0);
}
f_aggregate(256);
/* now on stack: the array with colors. */
push_text("Image");
push_int(0);
SAFE_APPLY_MASTER("resolv", 2);
if (sp[-1].type!=T_OBJECT)
error("No Image module.\n");
push_text("colortable");
f_index(2);
/* on stack: array function */
sp[0]=sp[-1];
sp[-1]=sp[-2];
sp[-2]=sp[0];
/* on stack: function array */
PFTIME("Creating colormap obj");
apply_svalue( sp-2, 1 );
/* on stack: function cmap */
get_all_args("internal", 1, "%o", &pike_cmap);
pike_cmap->refs+=100; /* lets keep this one.. :-) */
push_int(8); push_int(8); push_int(8);
#if (PIKE_MAJOR_VERSION > 0) || (PIKE_MINOR_VERSION > 6)
apply(pike_cmap, "rigid", 3); pop_stack();
#else
apply(pike_cmap, "cubicles", 3); pop_stack();
#endif
apply(pike_cmap, "ordered", 0); pop_stack();
pop_stack();
}
{ /* now we have a colormap available. Happy happy joy joy! */
struct pike_string *s;
struct object *image_module;
push_text("Image");
push_int(0);
SAFE_APPLY_MASTER("resolv", 2);
if (sp[-1].type!=T_OBJECT)
error("No Image module.\n");
push_text("X");
f_index(2);
if (sp[-1].type!=T_OBJECT)
error("No Image.X module.\n");
push_text("encode_pseudocolor");
f_index(2);
if (sp[-1].type!=T_FUNCTION)
error("No Image.X.encode_pseudocolor function.\n");
/* on stack: function */
add_ref(img);
push_object( img );
push_int( i->bpp*8 );
{
int pad = 0;
switch(i->bpl - (i->bpp*x))
{
case 0: pad = 0; break;
case 1: pad = 16; break;
default: pad = 32; break;
}
push_int( pad ); /* extra padding.. */
}
push_int( i->depth );
add_ref(pike_cmap);
push_object( pike_cmap );
/* on stack: function img bpp linepad depth cmap*/
/* 6 5 4 3 2 1 */
PFTIME("Dithering image");
apply_svalue( sp-6, 5 );
if(sp[-1].type != T_STRING)
{
gdk_image_destroy((void *)i);
error("Failed to convert image\n");
}
PFTIME("Converting image");
MEMCPY(i->mem, sp[-1].u.string->str, sp[-1].u.string->len);
pop_stack(); /* string */
pop_stack(); /* function */
}
}
TIMER_END();
return i;
}
void push_gtkobjectclass(void *obj, struct program *def)
{
struct object *o;
if(!obj)
{
push_int(0);
return;
}
if( (o=gtk_object_get_data(GTK_OBJECT(obj), "pike_object")) )
{
ref_push_object( o );
return;
}
o = low_clone( def );
call_c_initializers( o );
((struct object_wrapper *)o->storage)->obj = obj;
pgtk__init_object( o );
ref_push_object( o );
return;
}
void push_pgdkobject(void *obj, struct program *def)
{
struct object *o;
if(!obj)
{
push_int(0);
return;
}
o = low_clone( def );
call_c_initializers( o );
((struct object_wrapper *)o->storage)->obj = obj;
ref_push_object( o );
return;
}
GtkObject *get_pgtkobject(struct object *from, struct program *type)
{
struct object_wrapper * o;
if(!from) return NULL;
o=(struct object_wrapper *)get_storage( from, type );
if(!o) return 0;
return o->obj;
}
void *get_pgdkobject(struct object *from, struct program *type)
{
void *f;
if(!from) return NULL;
if(type)
f = get_storage( from, type );
else
f = from->storage;
if(!f)
return 0;
return (void *)((struct object_wrapper *)f)->obj;
}
void pgtk__init_object( struct object *o )
{
GtkObject *go = get_gtkobject(o);
if(!go)
fatal("pgtk__init_object called on a non-pgtk object!\n");
o->refs+=3;
gtk_object_set_data_full(go,"pike_object",
(void*)o, (void*)destruct);
}
void pgtk_get_mapping_arg( struct mapping *map,
char *name, int type, int madd,
void *dest, long *mask, int len )
{
struct svalue *s;
if( s = simple_mapping_string_lookup( map, name ) )
{
if( s->type == type )
{
switch(type)
{
case T_STRING:
if(len != sizeof(char *))
fatal("oddities detected\n");
MEMCPY(((char **)dest), &s->u.string->str, sizeof(char *));
break;
case T_INT:
if(len == 2)
{
short i = (short)s->u.integer;
MEMCPY(((short *)dest), &i, 2);
}
else if(len == 4)
MEMCPY(((int *)dest), &s->u.integer, len);
break;
case T_FLOAT:
if(len == sizeof(float))
MEMCPY(((float *)dest), &s->u.float_number,len);
else if(len == sizeof(double))
{
double d = s->u.float_number;
MEMCPY(((double *)dest), &d,len);
}
break;
}
*mask |= madd;
}
}
}
GdkAtom get_gdkatom( struct object *o )
{
if(get_gdkobject( o,_Atom ))
return (GdkAtom)get_gdkobject( o, _Atom );
apply( o, "get_atom", 0);
get_all_args( "internal_get_atom", 1, "%o", &o );
if(get_gdkobject( o,_Atom ))
{
GdkAtom r = (GdkAtom)get_gdkobject( o,_Atom );
pop_stack();
return r;
}
error("Got non GDK.Atom object to get_gdkatom()\n");
}
struct my_pixel pgtk_pixel_from_xpixel( unsigned int pix, GdkImage *i )
{
static GdkColormap *col;
GdkColor * c;
struct my_pixel res;
int l;
if(!col) col = gdk_colormap_get_system();
res.r = res.g= res.b = 0;
switch(i->visual->type)
{
case GDK_VISUAL_GRAYSCALE:
case GDK_VISUAL_PSEUDO_COLOR:
for(l=0; l<col->size; l++)
if(col->colors[l].pixel == pix) /* 76 */
{
res.r = col->colors[l].red/257;
res.g = col->colors[l].green/257;
res.b = col->colors[l].blue/257;
break;
}
break;
case GDK_VISUAL_STATIC_COLOR:
case GDK_VISUAL_TRUE_COLOR:
case GDK_VISUAL_DIRECT_COLOR:
/* Well well well.... */
res.r = ((pix&i->visual->red_mask)
>> i->visual->red_shift)
<< (8-i->visual->red_prec);
res.g = ((pix&i->visual->green_mask)
>> i->visual->green_shift)
<< (8-i->visual->green_prec);
res.b = ((pix&i->visual->blue_mask)
>> i->visual->blue_shift)
<< (8-i->visual->blue_prec);
break;
case GDK_VISUAL_STATIC_GRAY:
res.r = res.g = res.b = (pix*256) / 1<<i->visual->depth;
break;
}
return res;
}
int pgtkbuttonfuncwrapper(GtkObject *obj, struct signal_data *d, void *foo)
{
int res;
push_svalue(&d->args);
apply_svalue(&d->cb, 1);
res = sp[-1].u.integer;
pop_stack();
return res;
}
void push_gdk_event(GdkEvent *e)
{
struct svalue *osp = sp;
if(!e)
{
push_text("NullEvent"); /* Why, o why? */
return;
}
switch(e->type)
{
case GDK_NOTHING:
push_text("type"); push_text("nothing");
break;
case GDK_DELETE:
push_text("type"); push_text("delete");
break;
case GDK_DESTROY:
push_text("type"); push_text("destroy");
break;
case GDK_EXPOSE:
push_text("type"); push_text("expose");
push_text("count"); push_int(e->expose.count);
push_text("x"); push_int(e->expose.area.x);
push_text("y"); push_int(e->expose.area.y);
push_text("width"); push_int(e->expose.area.width);
push_text("height"); push_int(e->expose.area.height);
break;
case GDK_MOTION_NOTIFY:
push_text("type"); push_text("motion");
push_text("time"); push_int(e->motion.time);
push_text("x"); push_float(e->motion.x);
push_text("y"); push_float(e->motion.y);
push_text("pressure");push_float(e->motion.pressure);
push_text("xtilt"); push_float(e->motion.xtilt);
push_text("ytilt"); push_float(e->motion.ytilt);
push_text("state"); push_int(e->motion.state);
push_text("time"); push_int(e->motion.time);
push_text("deviceid");push_int(e->motion.deviceid);
push_text("x_root"); push_float(e->motion.x_root);
push_text("y_root"); push_int(e->motion.y_root);
break;
case GDK_BUTTON_PRESS:
push_text("type"); push_text("button_press");
goto press_event;
case GDK_2BUTTON_PRESS:
push_text("type"); push_text("2button_press");
goto press_event;
case GDK_3BUTTON_PRESS:
push_text("type"); push_text("3button_press");
goto press_event;
case GDK_BUTTON_RELEASE:
push_text("type"); push_text("button_release");
press_event:
push_text("time"); push_int(e->button.time);
push_text("x"); push_float(e->button.x);
push_text("y"); push_float(e->button.y);
push_text("pressure");push_float(e->button.pressure);
push_text("xtilt"); push_float(e->button.xtilt);
push_text("ytilt"); push_float(e->button.ytilt);
push_text("state"); push_int(e->button.state);
push_text("button"); push_int(e->button.button);
push_text("deviceid");push_int(e->button.deviceid);
push_text("x_root"); push_float(e->button.x_root);
push_text("y_root"); push_int(e->button.y_root);
break;
case GDK_KEY_PRESS:
push_text("type"); push_text("key_press");
goto key_event;
case GDK_KEY_RELEASE:
push_text("type"); push_text("key_release");
key_event:
push_text("time"); push_int(e->key.time);
push_text("state"); push_int(e->key.state);
push_text("keyval"); push_int(e->key.keyval);
if(e->key.string)
{
push_text("data");
push_string(make_shared_binary_string(e->key.string, e->key.length));
}
break;
case GDK_ENTER_NOTIFY:
push_text("type"); push_text("enter_notify");
goto enter_event;
case GDK_LEAVE_NOTIFY:
push_text("type"); push_text("leave_notify");
enter_event:
push_text("detail"); push_int(e->crossing.detail);
break;
case GDK_FOCUS_CHANGE:
push_text("type"); push_text("focus");
break;
case GDK_CONFIGURE:
push_text("type"); push_text("configure");
push_text("x"); push_int(e->configure.x);
push_text("y"); push_int(e->configure.x);
push_text("width"); push_int(e->configure.width);
push_text("height"); push_int(e->configure.height);
break;
case GDK_MAP:
push_text("type"); push_text("map");
break;
case GDK_UNMAP:
push_text("type"); push_text("unmap");
break;
case GDK_PROPERTY_NOTIFY:
push_text("type"); push_text("property");
break;
case GDK_SELECTION_CLEAR:
push_text("type"); push_text("selection_clear");
break;
case GDK_SELECTION_REQUEST:
push_text("type"); push_text("selection_request");
break;
case GDK_SELECTION_NOTIFY:
push_text("type"); push_text("selection_notify");
break;
case GDK_PROXIMITY_IN:
push_text("type"); push_text("proximity_in");
break;
case GDK_PROXIMITY_OUT:
push_text("type"); push_text("proximity_out");
break;
case GDK_CLIENT_EVENT:
push_text("type"); push_text("client");
break;
case GDK_VISIBILITY_NOTIFY:
push_text("type"); push_text("visibility");
break;
case GDK_NO_EXPOSE:
push_text("type"); push_text("noexpose");
break;
}
f_aggregate_mapping( sp - osp );
}
int pgtk_signal_func_wrapper(GtkObject *obj,struct signal_data *d,
int nparams, GtkArg *params)
{
int i, j=0, res, return_value = 0;
push_svalue(&d->args);
push_gtkobject( obj );
for(i=0; i<nparams; i++)
{
switch( params[i].type )
{
case GTK_TYPE_INT:
case GTK_TYPE_ENUM:
case GTK_TYPE_FLAGS:
push_int( (INT32)GTK_VALUE_INT(params[i]) );
break;
case GTK_TYPE_BOOL:
push_int( (INT32)GTK_VALUE_BOOL(params[i]) );
break;
case GTK_TYPE_UINT:
push_int( (INT32)GTK_VALUE_UINT(params[i]) );
break;
case GTK_TYPE_LONG:
push_int( (INT32)GTK_VALUE_LONG(params[i]) );
break;
case GTK_TYPE_CHAR:
push_int( (INT32)((unsigned char)GTK_VALUE_CHAR( params[i] )) );
break;
case GTK_TYPE_ULONG:
push_int( (INT32)GTK_VALUE_ULONG(params[i]) );
break;
case GTK_TYPE_INVALID:
case GTK_TYPE_NONE:
push_int( 0 );
break;
case GTK_TYPE_FLOAT:
push_float( (float)GTK_VALUE_FLOAT(params[i]) );
break;
case GTK_TYPE_DOUBLE:
push_float( (float)GTK_VALUE_DOUBLE(params[i]) );
break;
case GTK_TYPE_POINTER: /* These probably need fixing.. / Hubbe */
case GTK_TYPE_FOREIGN:
case GTK_TYPE_STRING:
if(GTK_VALUE_STRING( params[i] ))
push_text( GTK_VALUE_STRING( params[i] ) );
else
push_text( "" );
break;
case GTK_TYPE_OBJECT:
push_gtkobject( GTK_VALUE_OBJECT( params[i] ) );
break;
default:
{
char *n = gtk_type_name( params[i].type );
if(n)
{
int ok = 0;
switch(n[3])
{
case 'A':
if(!strcmp(n, "GtkAccelFlags"))
{
push_int( GTK_VALUE_UINT( params[i] ) );
ok=1;
}
else if(!strcmp(n, "GtkAccelGroup"))
{
ok=1;
gtk_accel_group_ref( (void *)GTK_VALUE_POINTER(params[i]) );
push_pgdkobject( GTK_VALUE_POINTER(params[i]),
pgtk_accel_group_program);
}
break;
case 'C':
if(!strcmp(n, "GtkCTreeNode"))
{
ok=1;
push_pgdkobject( GTK_VALUE_POINTER(params[i]),
pgtk_CTreeNode_program);
}
else if(!strcmp(n, "GtkCTreeRow"))
{
ok=1;
push_pgdkobject( GTK_VALUE_POINTER(params[i]),
pgtk_CTreeRow_program);
}
break;
case 'D':
if(!strcmp(n, "GdkDragContext"))
{
ok=1;
push_pgdkobject( GTK_VALUE_POINTER(params[i]),
pgtk_GdkDragContext_program);
}
break;
case 'E':
if(!strcmp(n, "GdkEvent"))
{
return_value = 1;
ok=1;
push_gdk_event( GTK_VALUE_POINTER( params[i] ) );
}
break;
case 'M':
if(!strcmp(n, "GdkModifierType"))
{
ok=1;
push_int( GTK_VALUE_UINT( params[i] ) );
}
break;
case 'S':
if(!strcmp(n, "GtkSelectionData"))
{
ok=1;
push_pgdkobject( GTK_VALUE_POINTER(params[i]),
pgtk_selection_data_program);
}
break;
}
if(!ok)
{
fprintf(stderr,"Unknown param type: %s<value=%p>\n",
n, GTK_VALUE_POINTER(params[i]));
push_text( n );
}
}
else
push_int( 0 );
}
}
j++;
}
apply_svalue(&d->cb, 2+j);
res = sp[-1].u.integer;
pop_stack();
if( return_value )
{
if( params[1].type == GTK_TYPE_POINTER)
{
gint *return_val;
return_val = GTK_RETLOC_BOOL( params[ 1 ] );
if(return_val)
*return_val = res;
}
}
return res;
}
void pgtk_free_signal_data( struct signal_data *s)
{
free_svalue( &s->cb );
free_svalue( &s->args );
free(s);
}
|