Esempio n. 1
0
static void
GrFreeImageWrapper(void *r)
{
	nxFreeImageReq *req = r;

	GrFreeImage(req->id);
}
Esempio n. 2
0
void CObjectPlatButton::UnloadImage()
{
	if(m_Image)
	{
		GrFreeImage(m_Image);
		m_Image = 0;
	}

//	printf("%s: unload complete\r\n", __func__);
}
Esempio n. 3
0
void CObjectCheck::UnloadImage()
{
	int i;

	for(i=0; i<IMG_BUTTON_COUNT; i++)
	{
		if(m_Image[i])
		{
			GrFreeImage(m_Image[i]);
			m_Image[i] = 0;
		}
	}

//	printf("%s: unload complete\r\n", __func__);
}
Esempio n. 4
0
/**
 * Load image from filename and return its ID
*/
GR_WINDOW_ID theme_load_image(char * filename)
{
	GR_GC_ID gc;
	GR_IMAGE_ID iid;
	GR_WINDOW_ID pid;
	GR_IMAGE_INFO iif;

	gc = GrNewGC();
	if(!(iid = GrLoadImageFromFile(filename, 0))) {
		fprintf(stderr, "Failed to load image file \"%s\"\n", filename);
		return 0;
	}
	GrGetImageInfo(iid, &iif);
	pid = GrNewPixmap(iif.width, iif.height, NULL);

	GrDrawImageToFit(pid, gc, 0, 0, iif.width, iif.height, iid);
	GrDestroyGC(gc);
	GrFreeImage(iid);

	return pid;
}
Esempio n. 5
0
void CObjectIcon::UnloadImage()
{
	int i;

	if(m_pImage)
	{
		for(i=0; i<m_nImgCount; i++)
		{
			if(m_pImage[i])
			{
				GrFreeImage(m_pImage[i]);
				m_pImage[i] = 0;
			}
		}
		delete[] m_pImage;
		m_pImage = NULL;

		m_nImgCount = 0;
	}

//	printf("%s: unload complete\r\n", __func__);
}
Esempio n. 6
0
int
ui_loop(int argc, char **argv, const char *name) {
	GR_EVENT	event;		/* current event */
	GR_IMAGE_ID	id = 0;
	NGLXContext cx;
	int width, height, k;

	if (GrOpen() < 0) {
		fprintf(stderr, "cannot open graphics\n");
		exit(1);
	}

	width = 400;
	height = 300;

	GrSetErrorHandler(errorcatcher);

	w1 = GrNewWindow(GR_ROOT_WINDOW_ID, 10, 10, width, height, 4, BLACK, WHITE);

	GrSelectEvents(w1, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_KEY_DOWN);

	GrMapWindow(w1);

	gc1 = GrNewGC();

	GrSetGCForeground(gc1, WHITE);

	cx = nglXCreateContext(NULL, 0);
	nglXMakeCurrent(w1, cx);

	init();
	reshape(width, height);

	while (1) {
		GrCheckNextEvent(&event);

		switch (event.type) {
		case GR_EVENT_TYPE_CLOSE_REQ:
			GrFreeImage(id);
			GrClose();
			exit(0);

		case GR_EVENT_TYPE_EXPOSURE:
			break;

		case GR_EVENT_TYPE_KEY_DOWN: {
			GR_EVENT_KEYSTROKE *kp = &event.keystroke;

			/* XXX: nanoX special keys are totally bugged ! */
			switch (kp->ch) {
			case 81:
				k = KEY_LEFT;
				break;

			case 83:
				k = KEY_RIGHT;
				break;

			case 82:
				k = KEY_UP;
				break;

			case 84:
				k = KEY_DOWN;
				break;

			default:
				k = kp->ch;
				break;
			}

			key(k, 0);
		}
		break;

		default:
			idle();
			break;
		}
	}

	return 0;
}
Esempio n. 7
0
/*
 * Destroy windows and eventclient structures used by client.
 * Called by GsDropClient after a client has exited to clean
 * up resources.
 */
void
GsDestroyClientResources(GR_CLIENT * client)
{
	GR_WINDOW     * wp, *nwp;
	GR_PIXMAP     * pp, *npp;
	GR_GC 	      * gp, *ngp;
	GR_REGION     * rp, *nrp;
	GR_FONT       * fp, *nfp;
	GR_IMAGE      * ip, *nip;
	GR_CURSOR     *	cp, *ncp;
	GR_EVENT_CLIENT *ecp, *necp;
	GR_EVENT_CLIENT *pecp = NULL;
	GR_EVENT_LIST	*evp;

printf("Destroy client %d resources\n", client->id);
	/* search window list, destroy windows owned by client*/
	for(wp=listwp; wp; wp=nwp) {
		nwp = wp->next;
		/*
		 * Remove eventclient structures for this client
		 */
		ecp = wp->eventclients;
		while (ecp) {
			necp = ecp->next;
			if (ecp->client == client) {
printf( "  Destroy window %d eventclient mask %08lx\n", wp->id, ecp->eventmask);
				if (ecp == wp->eventclients)
					wp->eventclients = ecp->next;
				else
					pecp->next = ecp->next;
				free(ecp);
			} else
				pecp = ecp;
			ecp = necp;
		}
		if (wp->owner == client) {
printf("  Destroy window %d\n", wp->id);
			GrDestroyWindow(wp->id);
		}
	}

	/* search pixmap list, destroy pixmaps owned by client*/
	for(pp=listpp; pp; pp=npp) {
		npp = pp->next;
		if (pp->owner == client) {
printf("  Destroy pixmap %d\n", pp->id);
			GrDestroyWindow(pp->id);
		}
	}

	/* free gc's owned by client*/
	for(gp=listgcp; gp; gp=ngp) {
		ngp = gp->next;
		if (gp->owner == client) {
printf("  Destroy gc %d\n", gp->id);
			GrDestroyGC(gp->id);
		}
	}

	/* free fonts owned by client*/
	for(fp=listfontp; fp; fp=nfp) {
		nfp = fp->next;
		if (fp->owner == client) {
printf("  Destroy font %d\n", fp->id);
			GrDestroyFont(fp->id);
		}
	}

	/* free regions owned by client*/
	for(rp=listregionp; rp; rp=nrp) {
		nrp = rp->next;
		if (rp->owner == client) {
printf("  Destroy region %d\n", rp->id);
			GrDestroyRegion(rp->id);
		}
	}

	/* free images owned by client*/
	for(ip=listimagep; ip; ip=nip) {
		nip = ip->next;
		if (ip->owner == client) {
printf("  Destroy image %d\n", ip->id);
			GrFreeImage(ip->id);
		}
	}

	/* free cursors owned by client*/
	for(cp=listcursorp; cp; cp=ncp) {
		ncp = cp->next;
		if (cp->owner == client) {
printf("  Destroy cursor %d\n", cp->id);
			GrDestroyCursor(cp->id);
		}
	}

	/* Free events associated with client*/
	evp = client->eventhead;
	while (evp) {
printf("  Destroy event %d\n", evp->event.type);
		client->eventhead = evp->next;
		evp->next = eventfree;
		eventfree = evp;
		evp = client->eventhead;
	}
}
Esempio n. 8
0
void
show_jpeg(int client, char *file, int show_time)
{
    GR_EVENT        event;          /* current event */
    GR_IMAGE_ID     id = 0;
    GR_SIZE         w = -1;
    GR_SIZE         h = -1;
    GR_IMAGE_INFO   info;
    GR_WINDOW_ID    w1;             /* id for large window */
    GR_GC_ID        gc1;            /* graphics context for text */
    GR_SCREEN_INFO  si;

    int time_left;
    bool ever_exposed = false;

#if !defined(HAVE_JPEG_SUPPORT) && !defined(HAVE_BMP_SUPPORT) && !defined(HAVE_GIF_SUPPORT)
    printf("Sorry, no image support compiled in\n");
    exit(1);        
#endif

    GrGetScreenInfo(&si);
    printf("Loading image: %s\n", file);
    if (access(file, F_OK) < 0) {
        fdprintf(client, "Can't access \"%s\": %s\n", file, strerror(errno));
        return;
    }
    id = GrLoadImageFromFile(file, 0);
    if (id) {
        GrGetImageInfo(id, &info);
    } else {
        // File exists, so why the error?
        int fd, len;
        char buf[64];
        fdprintf(client, "Can't load %s\n", file);
        if ((fd = open(file, O_RDONLY)) >= 0) {
            len = read(fd, buf, 64);
            if (len != 64) {
                diag_printf("Short read? len = %d\n", len);
            } else {
                diag_dump_buf(buf, len);
            }
            close(fd);
        } else {
            diag_printf("Can't oopen \"%s\": %s\n",  file, strerror(errno));
        }
        return;
    }

    w = info.width;
    h = info.height;
    if ((si.rows < info.height) || (si.cols < info.width)) {
        // Preserve aspect ratio
        if (si.cols < info.width) {
            w = si.cols;
            h = (si.cols * info.height) / info.width;
        }
        if (si.rows < h) {
            w = (si.rows * w) / h;
            h = si.rows;
        }
    }
    printf("Create window - orig %dx%d => %dx%d\n", info.width, info.height, w, h);
    fdprintf(client, "<INFO> Display \"%s\" - orig %dx%d => %dx%d\n", file, info.width, info.height, w, h);
    w1 = GrNewWindow(GR_ROOT_WINDOW_ID, 10, 10, w, h, 4, BLACK, WHITE);
    GrSelectEvents(w1, GR_EVENT_MASK_CLOSE_REQ|GR_EVENT_MASK_EXPOSURE);
    GrMapWindow(w1);
    gc1 = GrNewGC();
    GrSetGCForeground(gc1, WHITE);

#define TO_MS 50
    time_left = show_time * 1000;
    while (time_left > 0) {
        GrGetNextEventTimeout(&event, TO_MS);  // milliseconds
        switch(event.type) {
        case GR_EVENT_TYPE_CLOSE_REQ:
            GrDestroyWindow(w1);
            GrFreeImage(id);
            return;
            /* no return*/
        case GR_EVENT_TYPE_EXPOSURE:
            /*GrDrawImageFromFile(w1, gc1, 0, 0, w, h, argv[1],0);*/
            GrDrawImageToFit(w1, gc1, 0, 0, w, h, id);
            ever_exposed = true;
            break;
        default:
        case GR_EVENT_TYPE_NONE:
        case GR_EVENT_TYPE_TIMEOUT:
            time_left -= TO_MS;
            if ((time_left < 0) && !ever_exposed) {
                // Things get real cranky if we delete the window too fast!
                time_left = TO_MS;
            }
            break;
        }
    }    
    GrUnmapWindow(w1);
    GrDestroyWindow(w1);
    GrDestroyGC(gc1);
    GrFreeImage(id);
}
Esempio n. 9
0
void initialise(lstate *state)
{
	GR_SCREEN_INFO si;
	GR_IMAGE_ID back_image;
	GR_IMAGE_INFO imageinfo;
	int rows = 1, columns = 1, width, height, x = 0, y = 0;
	GR_WM_PROPERTIES props;
	litem *i;

	if(GrOpen() < 0) {
		GrError("Couldn't connect to Nano-X server\n");
		exit(4);
	}

	state->window_background_mode = 0;
	state->window_background_image = NULL;
	sspid = -1;

	read_config(state);

	GrGetScreenInfo(&si);

	if(si.rows > si.cols) {
		rows = state->numlitems;
		while((((rows / columns) + rows % columns) * ITEM_HEIGHT) >
								si.rows) {
			columns++;
		}
		if((columns * ITEM_WIDTH) > si.cols) goto toomany;
		rows = (rows / columns) + (rows % columns);
		width = columns * ITEM_WIDTH + 1 + columns;
		height = rows * ITEM_HEIGHT + 1 + rows;
	} else {
		columns = state->numlitems;
		while((((columns / rows) + (columns % rows)) * ITEM_WIDTH) >
								si.cols) {
			rows++;
		}
		if((rows * ITEM_HEIGHT) > si.rows) goto toomany;
		columns = (columns / rows) + (columns % rows);
		width = columns * ITEM_WIDTH + 1 + columns;
		height = (rows * ITEM_HEIGHT) + 1 + rows;
		y = si.rows - (rows * ITEM_HEIGHT) - 1 - rows;
	}

	state->gc = GrNewGC();
	GrSetGCForeground(state->gc, ITEM_TEXT_COLOUR);
	GrSetGCBackground(state->gc, ITEM_BACKGROUND_COLOUR);

	if(state->window_background_image) {
		if(!(back_image = GrLoadImageFromFile(
					state->window_background_image, 0))) {
			GrError("Couldn't load background image\n");
		} else {
			GrGetImageInfo(back_image, &imageinfo);
			if(!(state->background_pixmap = GrNewPixmap(
							imageinfo.width,
						imageinfo.height, NULL))) {
				GrError("Couldn't allocate pixmap "	
						"for background image\n");
			} else {
				GrDrawImageToFit(state->background_pixmap,
					state->gc, 0, 0, imageinfo.width,
					imageinfo.height, back_image);
				GrFreeImage(back_image);
				GrSetBackgroundPixmap(GR_ROOT_WINDOW_ID,
					state->background_pixmap,
					state->window_background_mode);
				GrClearWindow(GR_ROOT_WINDOW_ID, GR_TRUE);
			}
		}
	}

	if(state->ssitems)
		GrSelectEvents(GR_ROOT_WINDOW_ID, GR_EVENT_MASK_SCREENSAVER);

	state->main_window = GrNewWindow(GR_ROOT_WINDOW_ID, 0, y, width, height,
						0, ITEM_BACKGROUND_COLOUR, 0);
	GrSelectEvents(state->main_window, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_TIMER);
	props.flags = GR_WM_FLAGS_PROPS;
	props.props = GR_WM_PROPS_NOMOVE | GR_WM_PROPS_NODECORATE | GR_WM_PROPS_NOAUTOMOVE | GR_WM_PROPS_NOAUTORESIZE;
	GrSetWMProperties(state->main_window, &props);

	i = state->lastlitem;
	y = 0;
	while(i) {
		i->wid = GrNewWindow(state->main_window,
					(x * ITEM_WIDTH) + x + 1,
					(y * ITEM_HEIGHT) + y + 1, ITEM_WIDTH,
					ITEM_HEIGHT, 1, ITEM_BACKGROUND_COLOUR, ITEM_BORDER_COLOUR);
		GrSelectEvents(i->wid, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN);
		GrMapWindow(i->wid);
		i = i->prev;
		if(++x == columns) {
			x = 0;
			y++;
		}
	}

	GrMapWindow(state->main_window);

	signal(SIGCHLD, &reaper);

	do_startups(state);

	return;

toomany:
	GrError("Too many items to fit on screen\n");
	exit(6);
}
Esempio n. 10
0
void parse_config_line(lstate *state, char *buf, int lineno)
{
	char *p, *pp, *name, *icon;
	int n;
	litem *new_litem, *li;
	ssitem *new_ssitem, *tmp_ssitem;
	stitem *new_stitem, *tmp_stitem;
	GR_IMAGE_INFO imageinfo;

	p = buf;

	if((!*p) || (*p == '#') || (*p == '\n')) return;

	while(isspace(*p)) p++;
	name = p;
	while(*p && (!isspace(*p))) p++;
	if(!*p) goto premature;
	*p++ = 0;

	if(!strcmp(name, "$screensaver")) {
		new_ssitem = my_malloc(sizeof(ssitem));
		if(!(new_ssitem->prog = make_prog_item(p, lineno))) {
			free(new_ssitem);
			return;
		}
		state->numssitems++;
		new_ssitem->next = NULL;
		if(!state->ssitems) state->ssitems = new_ssitem;
		else {
			tmp_ssitem = state->ssitems;
			while(tmp_ssitem->next) tmp_ssitem = tmp_ssitem->next;
			tmp_ssitem->next = new_ssitem;
		}
		return;
	} else if(!strcmp(name, "$startup")) {
		new_stitem = my_malloc(sizeof(stitem));
		if(!(new_stitem->prog = make_prog_item(p, lineno))) {
			free(new_stitem);
			return;
		}
		new_stitem->next = NULL;
		if(!state->stitems) state->stitems = new_stitem;
		else {
			tmp_stitem = state->stitems;
			while(tmp_stitem->next) tmp_stitem = tmp_stitem->next;
			tmp_stitem->next = new_stitem;
		}
		return;
	} else if(!strcmp(name, "$screensaver_timeout")) {
		n = strtol(p, NULL, 10);
		GrSetScreenSaverTimeout(n);
		return;
	} else if(!strcmp(name, "$screensaver_rotate_time")) {
		state->rotatess = strtol(p, NULL, 10);
		return;
	} else if(!strcmp(name, "$random_screensaver")) {
		srand(time(0));
		state->randomss = 1;
		return;
	} else if(!strcmp(name, "$window_background_image")) {
		while(isspace(*p)) p++;
		if(!*p) goto premature;
		pp = p;
		while(*p && (!isspace(*p))) p++;
		*p = 0;
		state->window_background_image = strdup(pp);
		return;
	} else if(!strcmp(name, "$window_background_mode")) {
		state->window_background_mode = (int) strtol(p, NULL, 10);
		return;
	} else if(!strcmp(name, "$window_background_colour")) {
		set_window_background_colour(p, lineno);
		return;
	}

	while(isspace(*p)) p++;
	if(!*p) goto premature;
	icon = p;
	while(*p && (!isspace(*p))) p++;
	if(!*p) goto premature;
	*p++ = 0;

	new_litem = my_malloc(sizeof(litem));
	if(!(new_litem->name = strdup(name))) {
		free(new_litem);
		goto nomem;
	}
	if(!(new_litem->icon = strdup(icon))) {
		free(new_litem->name);
		free(new_litem);
		goto nomem;
	}
	if(!(new_litem->prog = make_prog_item(p, lineno))) {
		free(new_litem->name);
		free(new_litem->icon);
		free(new_litem);
		return;
	}
	new_litem->iconid = 0;
	if(strcmp("-", icon)) {
		li = state->litems;
		while(li) {
			if(!(strcmp(icon, li->name))) {
				new_litem->iconid = li->iconid;
				break;
			}
			li = li->next;
		}
		if(!new_litem->iconid) {
			if(!(new_litem->iconid = GrLoadImageFromFile(icon, 0))){
				GrError("Couldn't load icon \"%s\"\n",
									icon);
			} else {
				GrGetImageInfo(new_litem->iconid, &imageinfo);
				if((imageinfo.width != ICON_WIDTH) ||
					(imageinfo.height != ICON_HEIGHT)) {
					GrError("Icon \"%s\" is the "
					"wrong size (%dx%d instead of %dx%d)"
					"\n", icon, imageinfo.width,
					imageinfo.height, ICON_WIDTH,
					ICON_HEIGHT);
					GrFreeImage(new_litem->iconid);
					new_litem->iconid = 0;
				}
			}
		}
	}

	new_litem->prev = NULL;
	new_litem->next = NULL;
	if(!state->litems) {
		state->lastlitem = new_litem;
		state->litems = new_litem;
	} else {
		new_litem->next = state->litems;
		state->litems->prev = new_litem;
		state->litems = new_litem;
	}

	state->numlitems++;

	return;

nomem:
	GrError("Out of memory\n");
	exit(1);

premature:
	GrError("Premature end of line on line %d of config file\n",
								lineno);
}
Esempio n. 11
0
int GrBitmapEx_Apollo_NEW(GR_WINDOW_ID id,GR_GC_ID gc,int x,int y,int width,int height,int src_x,int src_y, int src_width,int src_height, GR_CHAR *imagebits)
{
    
    BMPHEADER_256 lpHeader;
    GR_IMAGE_ID ImageId;
    int HeaderLen;
    int i;
    int Lines;
    int BmpBufBytsPerLine=0,BytesPerLine=0;


    unsigned char char1,char2,char3,char4,BmpChar1;
    unsigned char *Screen_Buf=NULL,*BmpFileBuf=NULL,*BufPtr=NULL,*HeaderBuf=NULL,*pimg = NULL;
    int GrayLevel=8;//256 gray level
    int BmpWidth=0,BmpHeight=0,PixesPerByte=0,BmpPanelNumbers=0,Bmpheadersize=0;
    BmpWidth=min(width,src_width);
    BmpHeight=min(height,src_height-src_y);
//  BmpHeight=min(height,src_height);
    if(BmpHeight<=0)
        BmpHeight=1;    

    PixesPerByte=8/GrayLevel;
    BmpPanelNumbers=1<<GrayLevel;
    BytesPerLine=(BmpWidth*GrayLevel+31)/32*4;//
    BmpBufBytsPerLine=(((src_width*GrayLevel+7)/8+3)/4)*4;


    i=sizeof(BMPHEADER_256);
    HeaderLen=BITMAPFILEHEADER_SIZE+sizeof(BITMAPINFOHEADER)+sizeof(MWPALENTRY)*BmpPanelNumbers;
    memcpy((unsigned char *)&lpHeader.FileHeader.bfType,"BM",2);//
    lpHeader.FileHeader.bfSize=(BmpHeight*BytesPerLine)/PixesPerByte+HeaderLen; //
    lpHeader.FileHeader.bfReserved1=0;//
    lpHeader.FileHeader.bfReserved2=0;//
    lpHeader.FileHeader.bfOffBits=HeaderLen;//
    lpHeader.BmpInfo.biSize=sizeof(BITMAPINFOHEADER);//BMP
    lpHeader.BmpInfo.biWidth=BmpWidth;//
    lpHeader.BmpInfo.biHeight=BmpHeight;//
    lpHeader.BmpInfo.biPlanes=1;//
    lpHeader.BmpInfo.biBitCount=GrayLevel;//
    lpHeader.BmpInfo.biCompression=0;
    lpHeader.BmpInfo.biSizeImage=lpHeader.FileHeader.bfSize-HeaderLen;
    lpHeader.BmpInfo.biXPelsPerMeter=0x257E;
    lpHeader.BmpInfo.biYPelsPerMeter=0x257E;
    lpHeader.BmpInfo.biClrUsed=0;
    lpHeader.BmpInfo.biClrImportant=0;
    
    Bmpheadersize=HeaderLen;
    BmpFileBuf=new unsigned char[BmpHeight*BytesPerLine+Bmpheadersize];

    if(!BmpFileBuf)
    {
        return 1;
    }
    memset(BmpFileBuf,0xFF,BmpHeight*BytesPerLine+Bmpheadersize);
    HeaderBuf=BmpFileBuf;   
    Screen_Buf=BmpFileBuf+Bmpheadersize;
    BufPtr=Screen_Buf;

    memcpy(HeaderBuf,(char *)&lpHeader.FileHeader.bfType,2);
    memcpy(&HeaderBuf[2],(char *)&lpHeader.FileHeader.bfSize,4);
    memcpy(&HeaderBuf[6],(char *)&lpHeader.FileHeader.bfReserved1,2);
    memcpy(&HeaderBuf[8],(char *)&lpHeader.FileHeader.bfReserved2,2);
    memcpy(&HeaderBuf[10],(char *)&lpHeader.FileHeader.bfOffBits,4);
    HeaderBuf+=BITMAPFILEHEADER_SIZE;
    memcpy(HeaderBuf,(unsigned char *)&lpHeader.BmpInfo,BITMAPINFOHEADER_SIZE);
    HeaderBuf+=BITMAPINFOHEADER_SIZE;
    memcpy(HeaderBuf,(unsigned char *)&panel256,sizeof(MWPALENTRY)*BmpPanelNumbers);
    HeaderBuf=BmpFileBuf;   
                
    Lines=0;
    BufPtr = (unsigned char *)(Screen_Buf+(BmpHeight-1)*BytesPerLine);
    pimg = (unsigned char *)(imagebits + src_y*BmpBufBytsPerLine +src_x);
    for(Lines=0;Lines<BmpHeight;Lines++)
    {
//printf("%s line = %d,height =%d,byte = %d,buf =%d\n",__FUNCTION__,Lines,BmpHeight,BytesPerLine,BufPtr);
//      BufPtr=(unsigned char *)&Screen_Buf[(BmpHeight-1-Lines)*BytesPerLine];
//      memcpy(BufPtr,(unsigned char *)&imagebits[(Lines+src_y)*BmpBufBytsPerLine+src_x],BytesPerLine);
        memcpy(BufPtr,pimg,BytesPerLine);
        BufPtr -= BytesPerLine;
        pimg += BmpBufBytsPerLine;      
    }
    


    
    ImageId=GrLoadImageFromBuffer(BmpFileBuf,lpHeader.FileHeader.bfSize,GR_BACKGROUND_TOPLEFT);
    
    GrDrawImageToFit(id,gc,x,y,BmpWidth,BmpHeight,ImageId);
    printf("x=%d,y=%d,BmpWidth=%d,BmpHeight=%d\n",x,y,BmpWidth,BmpHeight);
    GrFreeImage(ImageId);

    delete(BmpFileBuf);
    return 0;
}
Esempio n. 12
0
int
main(int argc,char **argv)
{
	int			t;
	GR_IMAGE_ID	image_id;
	GR_WINDOW_ID	window_id;
	GR_GC_ID	gc_id;
	GR_SIZE		w = -1;
	GR_SIZE		h = -1;
	GR_EVENT	event;
	GR_SCREEN_INFO	sinfo;
	GR_IMAGE_INFO	info;
	char		title[256];

	if (argc < 2) {
		GrError("Usage: nxview [-p] [-s] <image file>\n");
		return 1;
	}

	t = 1;
	while ( t < argc ) {
		if ( !strcmp("-p",argv[t])) {
			pflag = 1;
			++t;
			continue;
		}
		if ( !strcmp("-s",argv[t])) {
			sflag = 1;
			++t;
			continue;
		}
		break;
	}

	if (GrOpen() < 0) {
		GrError("cannot open graphics\n");
		return 1;
	}
	
	if (!(image_id = GrLoadImageFromFile(argv[t], 0))) {
		GrError("Can't load image file: %s\n", argv[t]);
		return 1;
	}

	if(sflag) {
		/* stretch to half screen size*/
		GrGetScreenInfo(&sinfo);
		w = sinfo.cols/2;
		h = sinfo.rows/2;
	} else {
		GrGetImageInfo(image_id, &info);
		w = info.width;
		h = info.height;
	}

	sprintf(title, "nxview %s", argv[t]);
	window_id = GrNewWindowEx(GR_WM_PROPS_APPWINDOW, title, GR_ROOT_WINDOW_ID, 0, 0, w, h, GRAY);

	GrSelectEvents(window_id,
		GR_EVENT_MASK_CLOSE_REQ|GR_EVENT_MASK_EXPOSURE);

	GrMapWindow(window_id);

	gc_id = GrNewGC();

	while (1) {
		GrGetNextEvent(&event);
		switch(event.type) {
		case GR_EVENT_TYPE_CLOSE_REQ:
			GrDestroyWindow(window_id);
			GrDestroyGC(gc_id);
			GrFreeImage(image_id);
			GrClose();
			return 0;
			/* no return*/
		case GR_EVENT_TYPE_EXPOSURE:
			if (pflag) {
				int x, y;
				GR_WINDOW_INFO wi;

				GrGetWindowInfo(window_id, &wi);
				for (x=0; x<wi.width; x+=CX*2)
					for (y=0; y<wi.height; y+=CY) {
						if (y & CY)
							GrFillRect(window_id, gc_id, x, y, CX, CY);
						else GrFillRect(window_id, gc_id, x+CX, y, CX, CY); 
					}
			}
			GrDrawImageToFit(window_id, gc_id, 0,0, w,h, image_id);
			break;
		}
	}

	return 0;
}
Esempio n. 13
0
/* Create a new sprite from the specified image file. Returns the address of
 * the new sprite on success or 0 on failure. If width is -1, the real
 * dimensions of the image file will be used, otherwise the image will be
 * scaled up or down to the specified dimensions. */
sprite *load_sprite(nbstate *state, unsigned char *fname, int width, int height)
{
	sprite *s;
	GR_DRAW_ID a;
	GR_DRAW_ID p;
	GR_IMAGE_ID img;
	GR_IMAGE_INFO ii;

	/* Make sure the file name has been specified: */
	if (! fname) return 0;

	/* Try to find a sprite in the list with the specified filename and
	 * dimensions (any dimensions are OK if width is -1). If one is found,
	 * increment its usage count and return its address. */
	for(s = state->spritelist; s; s = s->next) {
		if ((width == -1 || (width == s->w && height == s->h)) &&
		    s->fname && !strcmp(fname, s->fname)) {
			s->usage++;
			return s;
		}
	}
#ifdef HAVE_FILEIO
	{
	/* Make the full path to the filename because the Nano-X server
	 * probably isn't running from the game data directory: */
	char buf[256];
	if (snprintf(buf, 256, "%s/%s", state->gamedir, fname) >= 256){
		debug_printf ("Warning: image path \"%s/%s\" is too long\n",
				state->gamedir, fname);
		return 0;
	}

	/* Try to load the image file, and return 0 on failure: */
	img = GrLoadImageFromFile (buf, 0);
	}
#else
	if      (strcmp (fname, (unsigned char*)   "nbb1.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbb1_data, sizeof(   nbb1_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbb2.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbb2_data, sizeof(   nbb2_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbb3.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbb3_data, sizeof(   nbb3_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbb4.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbb4_data, sizeof(   nbb4_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbb5.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbb5_data, sizeof(   nbb5_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbb6.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbb6_data, sizeof(   nbb6_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbb7.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbb7_data, sizeof(   nbb7_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbb8.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbb8_data, sizeof(   nbb8_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbb9.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbb9_data, sizeof(   nbb9_data), 0);
	else if (strcmp (fname, (unsigned char*)"nbball1.gif") == 0) img = GrLoadImageFromBuffer ((char*)nbball1_data, sizeof(nbball1_data), 0);
	else if (strcmp (fname, (unsigned char*) "nbbat1.gif") == 0) img = GrLoadImageFromBuffer ((char*) nbbat1_data, sizeof( nbbat1_data), 0);
	else if (strcmp (fname, (unsigned char*) "nbbat2.gif") == 0) img = GrLoadImageFromBuffer ((char*) nbbat2_data, sizeof( nbbat2_data), 0);
	else if (strcmp (fname, (unsigned char*) "nbbat3.gif") == 0) img = GrLoadImageFromBuffer ((char*) nbbat3_data, sizeof( nbbat3_data), 0);
	else if (strcmp (fname, (unsigned char*) "nbbg10.gif") == 0) img = GrLoadImageFromBuffer ((char*) nbbg10_data, sizeof( nbbg10_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbbg1.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbbg1_data, sizeof(  nbbg1_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbbg2.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbbg2_data, sizeof(  nbbg2_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbbg3.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbbg3_data, sizeof(  nbbg3_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbbg4.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbbg4_data, sizeof(  nbbg4_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbbg5.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbbg5_data, sizeof(  nbbg5_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbbg6.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbbg6_data, sizeof(  nbbg6_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbbg7.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbbg7_data, sizeof(  nbbg7_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbbg8.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbbg8_data, sizeof(  nbbg8_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbbg9.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbbg9_data, sizeof(  nbbg9_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbpf.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbpf_data, sizeof(   nbpf_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbpn.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbpn_data, sizeof(   nbpn_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbpp.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbpp_data, sizeof(   nbpp_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbps.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbps_data, sizeof(   nbps_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbpt.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbpt_data, sizeof(   nbpt_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbpw.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbpw_data, sizeof(   nbpw_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbsp1.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbsp1_data, sizeof(  nbsp1_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbsp2.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbsp2_data, sizeof(  nbsp2_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbsp3.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbsp3_data, sizeof(  nbsp3_data), 0);
	else {
		debug_printf ("No such image: \"%s\"\n", fname);
		uos_halt (0);
		return 0;
	}
#endif
	if (! img) {
		debug_printf ("Warning: failed to load image \"%s\"- make "
				"sure it is where the server can find it and "
				"that support for loading the relevant image "
				"type has been built into the server\n", fname);
		return 0;
	}

	/* If a size wasn't specified, get the real image size from the server
	 * instead: */
	if(width == -1 || height == -1) {
		GrGetImageInfo(img, &ii);
		width = ii.width;
		height = ii.height;
	}

	/* Make the alpha channel and pixmap to store the image in: */
	if(!(a = GrNewPixmap(width, height, 0))) {
		GrFreeImage(img);
		return 0;
	}
	if(!(p = GrNewPixmap(width, height, 0))) {
		GrFreeImage(img);
		GrDestroyWindow(a);
		return 0;
	}

	/* Draw the image into the specified pixmap and alpha channel, scaling
	 * it up or down if necessary: */
	GrDrawImageToFit(p, state->gc, 0, 0, width, height, img);
	GrFreeImage(img); /* Destroy the server image object. */

	/* Make a new sprite and link it into the list, then return its
	 * address to the caller: */
	s = make_sprite(state, fname, width, height, p, a);
	if (! s) {
		GrDestroyWindow(a);
		GrDestroyWindow(p);
		return 0;
	}

	return s;
}
Esempio n. 14
0
static int keyman_handle_event(GR_EVENT * event)
{
	int ret = 0;
    switch( event->type )
    {
    case( GR_EVENT_TYPE_TIMER ):
	
	switch(GAMEN){
		
		
		case MENU:
			makemenu();
			
			MINIPHOTO(0,0,160,128);
			wlastkey.AR=0;wlastkey.AL=0;wlastkey.AU=0;wlastkey.AD=0;wlastkey.REE=0;wlastkey.PAU=0;
			break;
		case INGAME:
			
		
		
		
			if (wlastkey.AL==1){wnow.LR=-1;wnow.MUKI=-1;}
			else if(wlastkey.AR==1){wnow.LR=1;wnow.MUKI=1;}
			else {wnow.LR=0;}
			
			
			if(wlastkey.REE==1){
					if(wnow.JIMEN==ZIM){
					wnow.YKANSEI=-9;
					wnow.JIMEN=SORA;
					}
					else if (wnow.HASIGO==1){
					wnow.YKANSEI=-9;
					wnow.JIMEN=SORA;
					wnow.HASIGO=0;
					
					}
			}
			
			if (INIT(wnow.XLOC+8,wnow.YLOC+8,'G')==FALSE){wnow.HASIGO=0;}
			
			
			
			if (INIT(wnow.XLOC+8,wnow.YLOC+8,'G')== TRUE && wlastkey.AU !=0){
				wnow.HASIGO=1;
				wnow.shupict=2;
				//GrCopyArea(shu_pixmap,keyman_gc,0,0,16,16,yomipict_pixmap,32,112,0);
				wnow.XKANSEI=0;
				//wnow.YLOC=wnow.YLOC-3;
				}
			else if (INIT(wnow.XLOC+8,wnow.YLOC+8,'G')== TRUE && wlastkey.AD !=0){
				wnow.HASIGO=0;
				//GrCopyArea(shu_pixmap,keyman_gc,0,0,16,16,yomipict_pixmap,32,112,0);
				wnow.XKANSEI=0;
				//wnow.YLOC=wnow.YLOC+3;	
				}
				
			
			if (wnow.JIMEN==ZIM){wnow.XKANSEI=(0.9*wnow.XKANSEI)+(1*wnow.LR);}
			else {
				if (wnow.LR != 0){
				wnow.XKANSEI=(0.99*wnow.XKANSEI)+(0.3*wnow.LR);
				}
			}
			if (wnow.HASIGO==0 ){
				if (wnow.YKANSEI <= 6){
					wnow.YKANSEI++;
				}
			}
			else {wnow.YKANSEI=0;}
			
			
			

			
			wnow.XLOC=wnow.XLOC+wnow.XKANSEI;
			wnow.YLOC=wnow.YLOC+wnow.YKANSEI;
			
			
			if (wnow.NUPDW==-1 && ((wnow.MAPSCROLL) % 16)==0){wnow.YLOC=wnow.YLOC+16;}
			else if (wnow.NUPDW==1 && (wnow.MAPSCROLL % 16)==15){wnow.YLOC=wnow.YLOC-16;}
			
			
			
			if (wnow.MAPSCROLL>0 && wnow.MAPSCROLL<TATEHABA*16){
				wnow.MAPSCROLL=wnow.MAPSCROLL+wnow.NUPDW;
			}
			scr= (wnow.MAPSCROLL/16);
			ATARI2();
						
			
			if (wlastkey.AU != 1 && wlastkey.AD != 1){
			 if (wnow.MUKI==1){
			 wnow.shupict=0;
			 //GrCopyArea(shu_pixmap,keyman_gc,0,0,16,16,yomipict_pixmap,0,112,0);
			 }
			 else {
			 wnow.shupict=1;
			 //GrCopyArea(shu_pixmap,keyman_gc,0,0,16,16,yomipict_pixmap,16,112,0);
			 }
			}			
			
						
			if (wnow.NUPDW==-1 && wnow.YLOC>136){
				wdeady.sp=-20;
				wdeady.g=1.6;
				wdeady.nowt=128;
				GAMEN=END;
				wdeady.kaiten=0;
				ketumatu=0;
				wdeady.deadcount=1;}
				
			else if(wnow.NUPDW==1 && wnow.YLOC<0){
				wdeady.sp=12;
				wdeady.g=0;
				wdeady.nowt=-16;
				GAMEN=END;
				wdeady.kaiten=0;
				ketumatu=0;
				wdeady.deadcount=1;}
			else if (wnow.NUPDW==0 && (wnow.YLOC>136)) {
			
				wdeady.sp=-10;
				wdeady.g=1.6;
				wdeady.nowt=128;
				GAMEN=END;
				wdeady.kaiten=0;
				ketumatu=0;
				wdeady.deadcount=1;}
					
				
			
			GrCopyArea(mainmenu_pixmap,keyman_gc,0,0,160,128,allmap_pixmap,0,wnow.MAPSCROLL,0);
			kmbitmap();
			//GrCopyArea(mainmenu_pixmap,keyman_gc,wnow.XLOC,(wnow.YLOC-(wnow.MAPSCROLL % 16)),160,128,shu_pixmap,0,0,0);
			hensu();		
			
			MINIPHOTO(0,0,160,128);
			if (wlastkey.PAU==1){GAMEN=PAUSE;}
			
			wlastkey.AR=0;wlastkey.AL=0;wlastkey.AU=0;wlastkey.AD=0;wlastkey.REE=0;wlastkey.PAU=0;
			break;
		case PAUSE:
			GrCopyArea(dialogall_pixmap,keyman_gc,0,0,96,80,dialog_pixmap,0,0,0);
			GrCopyArea(dialogall_pixmap,keyman_gc,3,24+(dialogkey*24),13,16,yomipict_pixmap,115,48,0);
			GrCopyArea(keyman_wid,keyman_gc,32+((screen_info.cols-160)/2),24+((screen_info.rows-128)/2),96,80,dialogall_pixmap,0,0,0);
			
			break;
		case END:
				if (ketumatu==0){
					wdeady.sp=wdeady.sp+wdeady.g;
					wdeady.nowt=wdeady.nowt+wdeady.sp;
					//sprintf(hensuu,"%d",wnow.MAPSCROLL+(wdeady.deadcount*wnow.NUPDW));
					
					if (wnow.MAPSCROLL+(wdeady.deadcount*wnow.NUPDW)>0 && wnow.MAPSCROLL+(wdeady.deadcount*wnow.NUPDW)<TATEHABA*16){
						GrCopyArea(mainmenu_pixmap,keyman_gc,0,0,160,128,allmap_pixmap,0,wnow.MAPSCROLL+(wdeady.deadcount*wnow.NUPDW),0);
					}
					
					GrCopyArea(shu_pixmap,keyman_gc,0,0,16,16,yomipict_pixmap,wdeady.kaiten*16,16,0);
					GrCopyArea(mainmenu_pixmap,keyman_gc,wnow.XLOC,wdeady.nowt,160,128,shu_pixmap,0,0,0);
					hensu();
					
					MINIPHOTO(0,0,160,128);
					if (wdeady.kaiten<7){wdeady.kaiten++;}else{wdeady.kaiten=0;}
					if (training==0){
						if (wdeady.deadcount>31){GAMEN=MENU;
					
						}   
					}
					else if (training==1){
						if (wdeady.deadcount>15){opencard();GAMEN=INGAME;
						}
						
					}
					wdeady.deadcount++;
				}
				else if (ketumatu==1){
					if (training==0){
					GAMEN=MENU;
					}
					if (training==1){
						if (tranum>=MAXTRA){
							GAMEN=MENU;
						}
						else{
							startgame();
							GAMEN=INGAME;
						}
					
					}
				}
			break;
		case NODATA:
			GrSetGCForeground(keyman_gc, WHITE);
			GrFillRect(keyman_wid,keyman_gc,0,0,160,128);
			
			GrSetGCForeground(keyman_gc, GRAY);
			GrLine(keyman_wid,keyman_gc,80,20,34,100);
			GrLine(keyman_wid,keyman_gc,80,20,126,100);
			GrLine(keyman_wid,keyman_gc,34,100,126,100);
			GrEllipse(keyman_wid,keyman_gc,80,55,5,20);
			GrEllipse(keyman_wid,keyman_gc,80,85,5,5);
			
			GrSetGCForeground(keyman_gc, BLACK);
			GrText(keyman_wid,keyman_gc,50,48,"Please Copy",-1,GR_TFASCII|GR_TFTOP);
			GrText(keyman_wid,keyman_gc,30,68,"KMData folder to /etc",-1,GR_TFASCII|GR_TFTOP);
			GrText(keyman_wid,keyman_gc,50,100,"Click to Quit",-1,GR_TFASCII|GR_TFTOP);
			break;
		}
		
			
	break;
	

    case( GR_EVENT_TYPE_KEY_DOWN ):
	
	switch(GAMEN){
		case INGAME:
			if (event->keystroke.ch==wsetkey.KLEFT){wlastkey.AL=1;}else{wlastkey.AL=0;}
			if (event->keystroke.ch==wsetkey.KRIGHT){wlastkey.AR=1;}else{wlastkey.AR=0;}
			if (event->keystroke.ch==wsetkey.KUP){wlastkey.AU=1;}else{wlastkey.AU=0;}
			if (event->keystroke.ch==wsetkey.KDOWN){wlastkey.AD=1;}else{wlastkey.AD=0;}
			if (event->keystroke.ch==wsetkey.KJUMP){wlastkey.REE=1;}else{wlastkey.REE=0;}
			if (event->keystroke.ch==wsetkey.KPAUSE){wlastkey.PAU=1;}else{wlastkey.PAU=0;}
			break;
		case MENU:
			switch( event->keystroke.ch )
			{
	    
			case '\r': /* action */
				switch (wmenukey.BA){
				case 0:if (wmenukey.KEY<2){wmenukey.KEY++;}else{wmenukey.KEY=1;}break;	
				case 1:if (wmenukey.STAGE<MAXSTAGE){wmenukey.STAGE++;}
						else {wmenukey.STAGE=1;}
						break;
				
				case 2: GAMEN=INGAME; 
					training=0;
					startgame();
					break;
				case 3:GAMEN=INGAME;
					tranum=0;
					training=1;
					startgame();
					break;
				case 4: pz_close_window(keyman_wid);
					GrDestroyTimer(keyman_timer);
					GrUnmapWindow(keyman_wid);
					GrDestroyWindow(keyman_wid);
					GrFreeImage(kmimage_id);
					GrDestroyGC(keyman_gc);
					ret = 1;
					break;
				}
			break;
			case 'r': /* CCW spin */
			if (wmenukey.BA<4){ipod_beep();wmenukey.BA++;}		
			break;

			case 'l': /* CW spin */
			if (wmenukey.BA>0){ipod_beep();wmenukey.BA--;}
			break;
			
			case 'm': /* menu */
					pz_close_window(keyman_wid);
					GrDestroyTimer(keyman_timer);
					GrUnmapWindow(keyman_wid);
					GrDestroyWindow(keyman_wid);
					GrFreeImage(kmimage_id);
					GrDestroyGC(keyman_gc);
					ret = 1;		
			break;
			}
			break;
			
					
		case PAUSE:
			if (event->keystroke.ch==wsetkey.KLEFT && dialogkey == 1){ipod_beep();dialogkey=0;}
			if (event->keystroke.ch==wsetkey.KRIGHT && dialogkey == 0){ipod_beep();dialogkey=1;}
			if (event->keystroke.ch==wsetkey.KJUMP && dialogkey == 0){GAMEN=INGAME;}
			else if (event->keystroke.ch==wsetkey.KJUMP && dialogkey == 1){GAMEN=MENU;}
			
			break;
		case END:break;
		case NODATA:
			if (event->keystroke.ch=='\r'){
			GrDestroyTimer(keyman_timer);
			GrUnmapWindow(keyman_wid);
			GrDestroyWindow(keyman_wid);
			GrFreeImage(kmimage_id);
			GrDestroyGC(keyman_gc);
			ret = 1;
			}
			break;
		}
	
	
	
	break;
    }

    return ret;
}
Esempio n. 15
0
int GrBitmapEx_Apollo_FOUR(GR_WINDOW_ID id,GR_GC_ID gc,int x,int y,int width,int height,int src_x,int src_y, int src_width,int src_height, GR_CHAR *imagebits)

{
    // TODO: Add extra validation here
    //4 bit 16 level degree color
    
    
    BMPHEADER_256 lpHeader;
    GR_IMAGE_ID ImageId;
    int HeaderLen;
    int i;
    int Lines;
    int BmpBufBytsPerLine=0,BytesPerLine=0;

    unsigned char char1,char2,char3,char4,BmpChar1;
    unsigned char *Screen_Buf=NULL,*BmpFileBuf=NULL,*BufPtr=NULL,*HeaderBuf=NULL;
    int GrayLevel=8;//256 gray level
    int BmpWidth=0,BmpHeight=0,PixesPerByte=0,BmpPanelNumbers=0,Bmpheadersize=0;

    BmpWidth=min(width,src_width);
    BmpHeight=min(height,src_height);

    PixesPerByte=8/GrayLevel;
    BmpPanelNumbers=1<<GrayLevel;
    BytesPerLine=(BmpWidth*GrayLevel+31)/32*4;
    BmpBufBytsPerLine=(src_width*2+7)/8;


    i=sizeof(BMPHEADER_256);
    HeaderLen=BITMAPFILEHEADER_SIZE+sizeof(BITMAPINFOHEADER)+sizeof(MWPALENTRY)*BmpPanelNumbers;
    memcpy((unsigned char *)&lpHeader.FileHeader.bfType,"BM",2);
    lpHeader.FileHeader.bfSize=(BmpHeight*BytesPerLine)/PixesPerByte+HeaderLen;
    lpHeader.FileHeader.bfReserved1=0;
    lpHeader.FileHeader.bfReserved2=0;
    lpHeader.FileHeader.bfOffBits=HeaderLen;
    lpHeader.BmpInfo.biSize=sizeof(BITMAPINFOHEADER);
    lpHeader.BmpInfo.biWidth=BmpWidth;
    lpHeader.BmpInfo.biHeight=BmpHeight;
    lpHeader.BmpInfo.biPlanes=1;
    lpHeader.BmpInfo.biBitCount=GrayLevel;
    lpHeader.BmpInfo.biCompression=0;
    lpHeader.BmpInfo.biSizeImage=lpHeader.FileHeader.bfSize-HeaderLen;
    lpHeader.BmpInfo.biXPelsPerMeter=0x257E;
    lpHeader.BmpInfo.biYPelsPerMeter=0x257E;
    lpHeader.BmpInfo.biClrUsed=0;
    lpHeader.BmpInfo.biClrImportant=0;
    
    Bmpheadersize=HeaderLen;
    BmpFileBuf=new unsigned char[BmpHeight*BytesPerLine+Bmpheadersize];

    if(!BmpFileBuf)
    {
        return 1;
    }
    memset(BmpFileBuf,0x0,BmpHeight*BytesPerLine+Bmpheadersize);
    HeaderBuf=BmpFileBuf;   
    Screen_Buf=BmpFileBuf+Bmpheadersize;
    BufPtr=Screen_Buf;

    memcpy(HeaderBuf,(char *)&lpHeader.FileHeader.bfType,2);
    memcpy(&HeaderBuf[2],(char *)&lpHeader.FileHeader.bfSize,4);
    memcpy(&HeaderBuf[6],(char *)&lpHeader.FileHeader.bfReserved1,2);
    memcpy(&HeaderBuf[8],(char *)&lpHeader.FileHeader.bfReserved2,2);
    memcpy(&HeaderBuf[10],(char *)&lpHeader.FileHeader.bfOffBits,4);
    HeaderBuf+=BITMAPFILEHEADER_SIZE;
    memcpy(HeaderBuf,(unsigned char *)&lpHeader.BmpInfo,BITMAPINFOHEADER_SIZE);
    HeaderBuf+=BITMAPINFOHEADER_SIZE;
    memcpy(HeaderBuf,(unsigned char *)&panel16,sizeof(MWPALENTRY)*BmpPanelNumbers);
    HeaderBuf=BmpFileBuf;   
                
    Lines=0;
    //4 color degress change to 16 color degress,mainframe_img_bits is 4 color degress
    for(Lines=0;Lines<BmpHeight;Lines++)
    {
        
        char1=0;
        char2=0;
        char3=0;
        char4=0;
        //
        BufPtr=(unsigned char *)&Screen_Buf[(BmpHeight-1-Lines)*BytesPerLine];
        for(i=0;i<(BmpWidth*2+7)/8;i++)
        {
            BmpChar1=imagebits[i+(Lines+src_y)*BmpBufBytsPerLine+src_x/4];
            //
            char1=BmpChar1&0xc0;
            char1>>=6;
            *BufPtr=char1;
            BufPtr++;
            char2=BmpChar1&0x30;
            char2>>=4;
            *BufPtr=char2;
            BufPtr++;
            char3=BmpChar1&0x0c;
            char3>>=2;
            *BufPtr=char3;
            BufPtr++;
            char4=BmpChar1&0x03;
            *BufPtr=char4;
            BufPtr++;
        }
    }
    ImageId=GrLoadImageFromBuffer(BmpFileBuf,lpHeader.FileHeader.bfSize,GR_BACKGROUND_TOPLEFT);
    GrDrawImageToFit(id,gc,x,y,BmpWidth,BmpHeight,ImageId);
    GrFreeImage(ImageId);
    free(BmpFileBuf);
    return 0;
}
Esempio n. 16
0
/*
 * Destroy windows and eventclient structures used by client.
 * Called by GsDropClient after a client has exited to clean
 * up resources.
 */
void
GsDestroyClientResources(GR_CLIENT * client)
{
	GR_WINDOW     * wp, *nwp;
	GR_PIXMAP     * pp, *npp;
	GR_GC 	      * gp, *ngp;
	GR_REGION     * rp, *nrp;
	GR_FONT       * fp, *nfp;
	GR_CURSOR     *	cp, *ncp;
	GR_EVENT_CLIENT *ecp, *necp;
	GR_EVENT_CLIENT *pecp = NULL;
	GR_EVENT_LIST	*evp;
	GR_GRABBED_KEY	*kp, *nkp;
#if MW_FEATURE_IMAGES
	GR_IMAGE      * ip, *nip;
#endif
#if MW_FEATURE_TIMERS
	GR_TIMER      * tp, *ntp;
#endif

DPRINTF("Destroy client %d resources\n", client->id);
	/* search window list, destroy windows owned by client*/
	for(wp=listwp; wp; wp=nwp) {
		nwp = wp->next;
		/*
		 * Remove eventclient structures for this client
		 */
		ecp = wp->eventclients;
		while (ecp) {
			necp = ecp->next;
			if (ecp->client == client) {
DPRINTF( "  Destroy window %d eventclient mask %08lx\n", wp->id, ecp->eventmask);
				if (ecp == wp->eventclients)
					wp->eventclients = ecp->next;
				else
					pecp->next = ecp->next;
				free(ecp);
			} else
				pecp = ecp;
			ecp = necp;
		}
		if (wp->owner == client) {
DPRINTF("  Destroy window %d\n", wp->id);
			GrDestroyWindow(wp->id);
		}
	}

	/* search pixmap list, destroy pixmaps owned by client*/
	for(pp=listpp; pp; pp=npp) {
		npp = pp->next;
		if (pp->owner == client) {
DPRINTF("  Destroy pixmap %d\n", pp->id);
			GrDestroyWindow(pp->id);
		}
	}

	/* free gc's owned by client*/
	for(gp=listgcp; gp; gp=ngp) {
		ngp = gp->next;
		if (gp->owner == client) {
DPRINTF("  Destroy gc %d\n", gp->id);
			GrDestroyGC(gp->id);
		}
	}

	/* free fonts owned by client*/
	for(fp=listfontp; fp; fp=nfp) {
		nfp = fp->next;
		if (fp->owner == client) {
DPRINTF("  Destroy font %d\n", fp->id);
			GrDestroyFont(fp->id);
		}
	}

	/* free regions owned by client*/
	for(rp=listregionp; rp; rp=nrp) {
		nrp = rp->next;
		if (rp->owner == client) {
DPRINTF("  Destroy region %d\n", rp->id);
			GrDestroyRegion(rp->id);
		}
	}

#if MW_FEATURE_IMAGES
	/* free images owned by client*/
	for(ip=listimagep; ip; ip=nip) {
		nip = ip->next;
		if (ip->owner == client) {
DPRINTF("  Destroy image %d\n", ip->id);
			GrFreeImage(ip->id);
		}
	}
#endif

#if MW_FEATURE_TIMERS
	/* free timers owned by client*/
	for(tp=list_timer; tp; tp=ntp) {
		ntp = tp->next;
		if (tp->owner == client) {
DPRINTF("  Destroy timer %d\n", tp->id);
			GrDestroyTimer(tp->id);
		}
	}
#endif

	/* free cursors owned by client*/
	for(cp=listcursorp; cp; cp=ncp) {
		ncp = cp->next;
		if (cp->owner == client) {
DPRINTF("  Destroy cursor %d\n", cp->id);
			GrDestroyCursor(cp->id);
		}
	}

	/* Free key grabs associated with client*/
	for (kp=list_grabbed_keys; kp; kp = nkp) {
		nkp = kp->next;
		if (kp->owner == curclient) {
DPRINTF("  Destroy grabkey %d,%d\n", kp->wid, kp->key);
			GrUngrabKey(kp->wid, kp->key);
		}
	}

	/* Free events associated with client*/
	evp = client->eventhead;
	while (evp) {
DPRINTF("  Destroy event %d\n", evp->event.type);
		client->eventhead = evp->next;
		evp->next = eventfree;
		eventfree = evp;
		evp = client->eventhead;
	}
}
Esempio n. 17
0
static int playVideo(char * filename)
{
	int curframes;
	struct framet frames[VIDEO_FILEBUFFER_COUNT][NUM_FRAMES_BUFFER];
	int i;
	int buffersProcessed = 0;

	curbuffer = 0;
	if (hw_version < 0x4) {
		video_screenWidth=160;
		video_screenHeight=128;
		video_screenBPP=2;
		video_useAudio=1;
	} else if (hw_version == 0x4 || hw_version == 0x7) {
		video_screenWidth=138;
		video_screenHeight=110;
		video_screenBPP=2;
		video_useAudio=1;
	} else if (hw_version==0x5) {
		video_screenWidth=160;
		video_screenHeight=128;
		video_screenBPP=2;
		video_useAudio=1;
	} else if (hw_version==0x6) {
		video_screenWidth=220;
		video_screenHeight=176;
		video_screenBPP=16;
		video_useAudio = 1;
		video_useKeys = 1;	
		video_waitUsecPause = 15000;
	} else if (hw_version==0xc) {
		video_screenWidth=176;
		video_screenHeight=132;
		video_screenBPP=2;
		video_useAudio=1;
		video_useKeys=1;
		video_waitUsecPause = 15000;
	} //else  {
	 //nes_window("Video!!???");
	  video_screenWidth=320;
	  video_screenHeight=240;
	  video_screenBPP=2;
	  video_useAudio=0;
	  video_useKeys=0;
	  video_waitUsecPause=15000;
	//  }

	i = 0;
//nes_window("Loaded");
		
	openAviFile(filename);
	//nes_window("opened");
	readVideoInfo(curFile);
	//nes_window("read"); 
	if (!audio_header_found)
		video_useAudio = 0;
	outl((unsigned int)&ipod_handle_video, VAR_COP_HANDLER);

	cop_wakeup();
	audio_open();

	if (video_useAudio)
		audio_thread_start();
	cop_setPlay(0);
	cop_initVideo();

	cop_setVideoParams(bitmapInfo.bmiHeader.biWidth, bitmapInfo.bmiHeader.biHeight, mainHeader.dwMicroSecPerFrame);

	curframes = 1;
	while ((curframes > 0)) {
		while (inl(VAR_VIDEO_BUFFER_DONE + curbuffer * sizeof(unsigned int)) == 0) {
			if (video_useKeys) {
				video_refresh_control_state();
			}


			if (video_status == VIDEO_CONTROL_MODE_EXITING) {
				goto exiting;	
			}
		}

		curframes = bufferFrames(&fileBuffers[curbuffer], frames[curbuffer], NUM_FRAMES_BUFFER);


#ifndef DEBUGNODISP
		cop_presentFrames(curbuffer, frames[curbuffer], curframes);
#endif
		video_curPosition+=curframes;

		if (buffersProcessed ==  /* VIDEO_FILEBUFFER_COUNT - 1)  { */
				BUFFER_FILL_FIRST_COUNT) { 
			if (video_useAudio)
			{	
				if (video_status & VIDEO_CONTROL_MODE_AUDIOSYNC)
				{

					while (!audio_thread_starting);
					main_thread_starting = 1;
					while (!audio_thread_running);
					main_thread_running = 1;	
				}
			}
			cop_setPlay(1);
			
			video_status = VIDEO_CONTROL_MODE_RUNNING;
			buffersProcessed++;	
		} else {
			buffersProcessed++;
		} 

		curbuffer = (curbuffer+1)%VIDEO_FILEBUFFER_COUNT;

		if (video_useKeys) {
			video_refresh_control_state();
		}
		if (video_status == VIDEO_CONTROL_MODE_EXITING) {
			goto exiting;	
		}

	}

	curbuffer -= 2;
	if (curbuffer < 0) {
		curbuffer += VIDEO_FILEBUFFER_COUNT;
	}

	while (!inl(VAR_VIDEO_BUFFER_DONE + curbuffer * sizeof(unsigned int))) {
		if (video_useKeys)
			video_refresh_control_state();
		if (video_status == VIDEO_CONTROL_MODE_EXITING) {
			goto exiting;	
		}
	}
exiting:

	cop_setPlay(0);
	


	video_status = VIDEO_CONTROL_MODE_EXITING;	


	if (video_useAudio)	
		audio_thread_stop(); 
	audio_close();

	closeAviFile();
	pz_close_window(video_wid);
	GrFreeImage(video_id);
	GrDestroyGC(video_gc);
	return 0;
}