예제 #1
0
static GImage *ReadRasBitmap(GImage *ret,int width, int height, FILE *fp ) {
    struct _GImage *base = ret->u.image;
    int i,j,len;
    unsigned char *pt, *buf;

    len = ((width+15)/16)*2;
    buf = (unsigned char *) galloc(len);
    for ( i=0; i<height; ++i ) {
	if ( fread(buf,len,1,fp)==EOF ) {
	    GImageDestroy(ret);
return( NULL);
	}
	pt = (unsigned char *) (base->data + i*base->bytes_per_line);
	for ( j=0 ; j<width; ++j )
	    if ( buf[j>>3]&(1<<(j&7)) )
		*pt++ = 1;
	    else
		*pt++ = 0;
    }
예제 #2
0
static int wheel_e_h(GWindow gw, GEvent *event) {
    struct gcol_data *d = GDrawGetUserData(gw);
    GRect size;
    if ( event->type==et_expose ) {
	GRect circle;
	GDrawGetSize(d->wheelw,&size);
	if ( d->wheel==NULL || 
		GImageGetHeight(d->wheel)!=size.height ||
		GImageGetWidth(d->wheel)!=size.width ) {
	    if ( d->wheel!=NULL )
		GImageDestroy(d->wheel);
	    d->wheel = ColorWheel(size.width,size.height);
	}
	GDrawDrawImage(gw,d->wheel,NULL,0,0);
	if ( d->col.hsv ) {
	    double s = sin(d->col.h*3.1415926535897932/180.);
	    double c = cos(d->col.h*3.1415926535897932/180.);
	    int y = (int) rint(d->col.s*(size.height-1)*s/2.0) + size.height/2;
	    int x = (int) rint(d->col.s*(size.width-1)*c/2.0) + size.width/2;
	    circle.x = x-3; circle.y = y-3;
	    circle.width = circle.height = 7;
	    GDrawDrawElipse(gw,&circle,0x000000);
	}
    } else if ( event->type == et_mousedown ||
	    (event->type==et_mousemove && d->pressed) ||
	    event->type==et_mouseup ) {
	Color rgb;
	struct hslrgba temp;
	GDrawGetSize(d->wheelw,&size);
	if ( event->u.mouse.y>=0 && event->u.mouse.y<size.height &&
		event->u.mouse.x>=0 && event->u.mouse.x<size.width ) {
	    rgb = GImageGetPixelRGBA(d->wheel,event->u.mouse.x,event->u.mouse.y);
	    temp.r = ((rgb>>16)&0xff)/255.;
	    temp.g = ((rgb>>8)&0xff)/255.;
	    temp.b = ((rgb   )&0xff)/255.;
	    gRGB2HSV((struct hslrgb *) &temp);
	    d->col.h = temp.h; d->col.s = temp.s;
	    GCol_ShowTexts(d);
	    GDrawRequestExpose(d->colw,NULL,false);
	    GDrawRequestExpose(d->wheelw,NULL,false);
	}