Beispiel #1
0
/* Zeros out the palette/gamma entries.  Called before changing modes. */
void GGI_fbdev_color0(ggi_visual *vis)
{
	if (LIBGGI_PAL(vis)->clut.data == NULL) return; /* New visual. */
	vis->opcolor->setpalvec(vis, 0, 1 << GT_DEPTH(LIBGGI_GT(vis)),
		       LIBGGI_PAL(vis)->clut.data);
	vis->opcolor->setgammamap(vis, 0, vis->gamma->len, 
			LIBGGI_PAL(vis)->clut.data);
}
Beispiel #2
0
static int do_dbstuff(struct ggi_visual *vis)
{
	ggi_palemu_priv *priv = PALEMU_PRIV(vis);
	int i;

	/* allocate memory */
	priv->frame_size = LIBGGI_FB_SIZE(LIBGGI_MODE(vis));
	priv->fb_size = priv->frame_size * LIBGGI_MODE(vis)->frames;
	priv->fb_ptr  = malloc((size_t)priv->fb_size);
	
	DPRINT_MODE("display-palemu: fb=%p size=%d frame=%d\n", 
		priv->fb_ptr, priv->fb_size, priv->frame_size);

	if (priv->fb_ptr == NULL) {
		fprintf(stderr, "display-palemu: Out of memory.\n");
		return GGI_ENOMEM;
	}

        /* clear all frames */
	memset(priv->fb_ptr, 0, (size_t)priv->fb_size);

	/* set up pixel format */
	memset(LIBGGI_PIXFMT(vis), 0, sizeof(ggi_pixelformat));
	setup_pixfmt(LIBGGI_PIXFMT(vis), LIBGGI_GT(vis));
	_ggi_build_pixfmt(LIBGGI_PIXFMT(vis));

	/* set up direct buffers */
	for (i=0; i < LIBGGI_MODE(vis)->frames; i++) {
		ggi_directbuffer *buf;
		
		_ggi_db_add_buffer(LIBGGI_PRIVLIST(vis), _ggi_db_get_new());

		buf = LIBGGI_PRIVBUFS(vis)[i];

		buf->frame = i;
		buf->type  = GGI_DB_NORMAL | GGI_DB_SIMPLE_PLB;
		buf->read  = (char *) priv->fb_ptr + i * priv->frame_size;
		buf->write = buf->read;
		buf->layout = blPixelLinearBuffer;

		buf->buffer.plb.stride = 
			GT_ByPPP(LIBGGI_VIRTX(vis), LIBGGI_GT(vis));
		buf->buffer.plb.pixelformat = LIBGGI_PIXFMT(vis);
	}

	/* Set up palette */
	if (LIBGGI_PAL(vis)->clut.data) {
		free(LIBGGI_PAL(vis)->clut.data);
 		LIBGGI_PAL(vis)->clut.data = NULL;
	}
	if (GT_SCHEME(LIBGGI_GT(vis)) == GT_PALETTE) {
		LIBGGI_PAL(vis)->clut.data = _ggi_malloc((1 << GT_DEPTH(LIBGGI_GT(vis))) *
						sizeof(ggi_color));
		LIBGGI_PAL(vis)->clut.size = 1 << GT_DEPTH(LIBGGI_GT(vis));
	}

	return 0;
}
Beispiel #3
0
int GGI_monotext_setPalette(ggi_visual_t vis, size_t start, size_t size, const ggi_color *colormap)
{
	ggi_monotext_priv *priv = MONOTEXT_PRIV(vis);
	const ggi_color *src = colormap;
	size_t    end = start + size - 1;

 	DPRINT("display-monotext: SetPalette(%d,%d)\n", start, size);
		
	memcpy(LIBGGI_PAL(vis)->clut.data+start, colormap, size*sizeof(ggi_color));
		
	if (end > start) {
		UPDATE_MOD(priv, 0, 0, priv->size.x, priv->size.y);
	}
	
	for (; start<=end; ++start, ++src) {

		int r = (src->r >> 11) & 0x1f;
 		int g = (src->g >> 11) & 0x1f;
 		int b = (src->b >> 11) & 0x1f;
			
		priv->colormap[start] = *src;

		priv->greymap[start] = priv->rgb_to_grey[(r << 10) | (g << 5) | b];
	}
	
	UPDATE_SYNC;
	return 0;
}
Beispiel #4
0
int
GGI_directx_DDChangePalette(struct ggi_visual *vis)
{
	directx_priv *priv = LIBGGI_PRIVATE(vis);
	int start       = LIBGGI_PAL(vis)->rw_start;
	int stop        = LIBGGI_PAL(vis)->rw_stop;
	ggi_color *clut = LIBGGI_PAL(vis)->clut.data;
	HRESULT hr;
	int x;
	static PALETTEENTRY pal[256];

	LIB_ASSERT(priv->lpddp, "No palette!\n");

	if (start >= stop)
		return 0;

	for (x = start; x < stop; x++) {
		pal[x].peFlags = PC_NOCOLLAPSE;
		pal[x].peRed   = clut[x].r >> 8;
		pal[x].peGreen = clut[x].g >> 8;
		pal[x].peBlue  = clut[x].b >> 8;
	}
	/*
	for (x = 0; x < 10; x++) {
		pal[x].peFlags  = pal[x+246].peFlags = PC_EXPLICIT;
		pal[x].peRed = x;
		pal[x+246].peRed = x+246;
		pal[x].peGreen = pal[x].peBlue = 0;
	}
	*/

	hr = IDirectDrawPalette_SetEntries(
	priv->lpddp, 0, start, stop - start, &pal[start]);

	if (hr != 0) {
		fprintf(stderr, "DDP_SetEntries Failed RC = %ld. Exiting\n",
		hr & 0xffff);
		exit(-1);
	}

	return 0;
}
Beispiel #5
0
int GGI_aa_setPalette(struct ggi_visual *vis,size_t start,size_t size, const ggi_color *colormap)
{
	aa_palette   *pal  = (aa_palette*)(LIBGGI_PAL(vis)->priv);
	ggi_color    *dest = LIBGGI_PAL(vis)->clut.data + start;
	const ggi_color    *src  = colormap;
	size_t        end = start + size;

	DPRINT_COLOR("AA setpalette.(%d,%d) %d\n",
			start,size,LIBGGI_PAL(vis)->clut.size);
	
	for (; start<end; ++start, ++dest) {
		*dest = *(src++);
	
		aa_setpalette(*pal, start, dest->r>>8,
			                   dest->g>>8, 
			                   dest->b>>8 );
	}
		
	return 0;
}
Beispiel #6
0
static int do_setmode(struct ggi_visual *vis)
{
	char libname[GGI_MAX_APILEN], libargs[GGI_MAX_APILEN];
	ggi_graphtype gt;
	int err, id;

	err = do_mmap(vis); 
	if (err) return err;

	_ggiZapMode(vis, 0);
	for (id=1; GGI_lcd823_getapi(vis, id, libname, libargs) == 0; id++) {
		if (_ggiOpenDL(vis, libggi->config, libname, libargs, NULL) != 0) {
			fprintf(stderr,"display-lcd823: Error opening the "
				"%s (%s) library.\n", libname, libargs);
			return GGI_EFATAL;
		}

		DPRINT_LIBS("Success in loading %s (%s)\n",
			       libname, libargs);
	}

	/* Set up palette */
	gt = LIBGGI_GT(vis);
	if ((GT_SCHEME(gt) == GT_PALETTE) || (GT_SCHEME(gt) == GT_TEXT)) {
	    	int nocols = 1 << GT_DEPTH(gt);

		LIBGGI_PAL(vis)->clut.size = nocols;
		LIBGGI_PAL(vis)->clut.data = _ggi_malloc(nocols * sizeof(ggi_color));
		LIBGGI_PAL(vis)->priv = _ggi_malloc(256 * sizeof(uint16_t));
		LIBGGI_PAL(vis)->setPalette  = GGI_lcd823_setPalette;
		LIBGGI_PAL(vis)->getPrivSize = GGI_lcd823_getPrivSize;
		/* Initialize palette */
		ggiSetColorfulPalette(vis);
	}

	ggiIndicateChange(vis, GGI_CHG_APILIST);

	DPRINT_MODE("display-lcd823: do_setmode SUCCESS\n");

	return 0;
}
Beispiel #7
0
/* Free palette/gamma entries.  Called before changing modes. */
void GGI_fbdev_color_free(ggi_visual *vis)
{
	ggi_fbdev_priv *priv = FBDEV_PRIV(vis);

	/* Unhook the entry points */
	LIBGGI_PAL(vis)->setPalette = NULL;
	LIBGGI_PAL(vis)->getPrivSize = NULL;
	vis->opcolor->getpalvec = NULL; /* ##### */
	vis->opcolor->setgammamap = NULL;
	vis->opcolor->getgammamap = NULL;

	/* Free the convenience array */
	free (LIBGGI_PAL(vis)->priv);
	LIBGGI_PAL(vis)->priv = NULL;
	
	/* 
	 * Clean up any pointers that could be problematic if left set.
	 * Technically they should be taken care of below, but why not...
	 */
	priv->reds = priv->greens = priv->blues = NULL;
	vis->gamma = NULL;

	/* Free the storage area for the palettes. */
	priv->gamma.map = priv->orig_cmap = NULL;
	free (LIBGGI_PAL(vis)->clut.data);
	LIBGGI_PAL(vis)->clut.data = NULL;
}
Beispiel #8
0
int GGI_lcd823_setmode(struct ggi_visual *vis, ggi_mode *mode)
{ 
	int err;

        if ((err = ggiCheckMode(vis, mode)) != 0) {
		return err;
	}

	if (LIBGGI_PAL(vis)->clut.data) {
		free(LIBGGI_PAL(vis)->clut.data);
		LIBGGI_PAL(vis)->clut.data = NULL;
	}

	if (LIBGGI_PAL(vis)->priv) {
		free(LIBGGI_PAL(vis)->priv);
		LIBGGI_PAL(vis)->priv = NULL;
	}

	_GGI_lcd823_free_dbs(vis);

	memcpy(LIBGGI_MODE(vis), mode, sizeof(ggi_mode));

	/* Now actually set the mode */
	err = do_setmode(vis);
	if (err != 0) {
		return err;
	}

	/* Reset panning and frames */
        vis->d_frame_num = vis->origin_x = vis->origin_y = 0;

	return 0;
}
Beispiel #9
0
int
GGI_kgi_setPalette(struct ggi_visual *vis, size_t start, size_t len, const ggi_color *colormap)
{
	kgic_ilut_set_request_t ilut;
	size_t nocols = 1 << GT_DEPTH(LIBGGI_GT(vis));

	APP_ASSERT(colormap != NULL,
			 "GGI_kgi_setPalette() - colormap == NULL");

	DPRINT_COLOR("display-kgi: SetPalVec(%d,%d)\n", start, len);
	
	if (start == (size_t)GGI_PALETTE_DONTCARE) {
		start = 0;
	}

	if ((start < 0) || (len < 0) || (start+len > nocols)) {
		return GGI_ENOSPACE;
	}

	memcpy(LIBGGI_PAL(vis)->clut.data, colormap, len*sizeof(ggi_color));

	ilut.image = 0;
	ilut.resource = 0;
	ilut.lut = 0;
	ilut.idx = start;
	ilut.cnt = len;
	ilut.am = KGI_AM_COLORS;
	ilut.data = (kgi_u16_t *)KGI_PRIV(vis);

	for (start = 0; len > 0; start++, colormap++, len--) {
		ilut.data[start*3]     = colormap->r;
		ilut.data[start*3 + 1] = colormap->g;
		ilut.data[start*3 + 2] = colormap->b;
	}

	if(kgiSetIlut(&KGI_CTX(vis), &ilut) != KGI_EOK) {
		DPRINT_COLOR("display-kgi: PUTCMAP failed.");
		return -1;
	}

	return 0;
}
Beispiel #10
0
int GGI_quartz_setpalvec(struct ggi_visual *vis,int start,int len,const ggi_color *colormap)
{
	CGTableCount  i;
	CGDeviceColor color;
	ggi_quartz_priv *priv;

	priv = QUARTZ_PRIV(vis);

	DPRINT("quartz setpalette.\n");

	if (start == GGI_PALETTE_DONTCARE) {
		if (len > priv->ncols) {
			return GGI_ENOSPACE;
		}	/* if */

		start = priv->ncols - len;
	}	/* if */

	if (start+len > priv->ncols || start < 0)
		return GGI_ENOSPACE;

	memcpy(LIBGGI_PAL(vis)->clut.data+start, colormap, len*sizeof(ggi_color));

	for (i = (unsigned)start; i < (unsigned)start+len; i++) {
		/* Clamp colors between 0.0 and 1.0 */
		color.red   = (uint16_t)(colormap->r / 65535.0);
		color.green = (uint16_t)(colormap->g / 65535.0);
		color.blue  = (uint16_t)(colormap->b / 65535.0);

		colormap++;

		CGPaletteSetColorAtIndex (priv->palette, color, i);
	}	/* for */

	if ( CGDisplayNoErr != CGDisplaySetPalette (priv->display_id, priv->palette) )
		return 0;

	return 0;
}	/* GGI_quartz_setpalvec */
Beispiel #11
0
int GGI_palemu_setPalette(ggi_visual_t vis, size_t start, size_t len, const ggi_color *colormap)
{
	ggi_palemu_priv *priv = PALEMU_PRIV(vis);
	const ggi_color *src  = colormap;
	size_t          end   = start + len;

 	DPRINT("display-palemu: SetPalette(%d,%d)\n", start, len);
	
	if (start < 0 || start + len > 256) {
		return GGI_ENOSPACE;
	}

	memcpy(LIBGGI_PAL(vis)->clut.data+start, src, len*sizeof(ggi_color));
	if (end > start) {
		UPDATE_MOD(vis, 0, 0, LIBGGI_VIRTX(vis), LIBGGI_VIRTY(vis));
	}

	for (; start < end; ++start, ++src) {
		priv->palette[start] = *src;
		priv->lookup[start] = ggiMapColor(priv->parent, src);
	}
	
	return 0;
}
Beispiel #12
0
static int GGI_fbdev_setPalette(ggi_visual *vis, size_t start, size_t size, 
			       const ggi_color *colormap)
{
	ggi_fbdev_priv *priv = FBDEV_PRIV(vis);
	struct fb_cmap cmap;
	
	int len = (int)size;
	
	const ggi_color* src = colormap;
	
	DPRINT_COLOR("display-fbdev: SetPalette(%d,%d)\n", start, size);
	
	memcpy(LIBGGI_PAL(vis)->clut.data+start, colormap, size*sizeof(ggi_color));

	if (!priv->ismapped) return 0;

	cmap.start  = start;
	cmap.len    = size;
	cmap.red    = priv->reds + start;
	cmap.green  = priv->greens + start;
	cmap.blue   = priv->blues + start;
	cmap.transp = NULL;

	for (; len > 0; start++, src++, len--) {
		priv->reds[start]   = src->r;
		priv->greens[start] = src->g;
		priv->blues[start]  = src->b;
	}

	if (fbdev_doioctl(vis, FBIOPUTCMAP, &cmap) < 0) {
		DPRINT_COLOR("display-fbdev: PUTCMAP failed.");
		return -1;
	}

	return 0;
}
Beispiel #13
0
size_t GGI_kgi_getPrivSize(struct ggi_visual *vis)
{
  return (3 * LIBGGI_PAL(vis)->clut.size * sizeof(int));
}
Beispiel #14
0
void GGI_fbdev_color_setup(ggi_visual *vis)
{
	ggi_fbdev_priv *priv = FBDEV_PRIV(vis);
	struct fb_cmap cmap;
	int len;

	/* We rely on caller to have deallocated old storage */
	priv->orig_cmap = LIBGGI_PAL(vis)->clut.data = priv->gamma.map = NULL; 
	vis->gamma = NULL;
	priv->reds = priv->greens = priv->blues = NULL;
	priv->gamma.maxread_r = priv->gamma.maxread_g = 
	  priv->gamma.maxread_b = priv->gamma.maxread_r = 
	  priv->gamma.maxwrite_g = priv->gamma.maxwrite_b = -1;
	priv->gamma.len = priv->gamma.start = 0;

	if (!priv->var.bits_per_pixel) return;
	if (priv->fix.visual == FB_VISUAL_TRUECOLOR) return; /* No gamma. */

	if (priv->fix.visual == FB_VISUAL_DIRECTCOLOR) {

		DPRINT("display-fbdev: trying gamma.\n");

		priv->gamma.maxwrite_r = priv->gamma.maxread_r = 
			1 << priv->var.red.length;
		priv->gamma.maxwrite_g = priv->gamma.maxread_g = 
			1 << priv->var.green.length;
		priv->gamma.maxwrite_b = priv->gamma.maxread_b = 
			1 << priv->var.blue.length;
		
		len = priv->gamma.maxread_r;
		if (len < priv->gamma.maxread_g) 
			len = priv->gamma.maxread_g;
		if (len < priv->gamma.maxread_b)
			len = priv->gamma.maxread_b;
		priv->gamma.len = len;
		priv->gamma.start = 0;
		
		LIBGGI_PAL(vis)->clut.size = len * 2;
		LIBGGI_PAL(vis)->clut.data = calloc(len * 2 /* orig */, sizeof(ggi_color));
		if (LIBGGI_PAL(vis)->clut.data == NULL) return;
		priv->gamma.map = LIBGGI_PAL(vis)->clut.data;
		/* All of the above is moot until we turn it on like so: */
		vis->gamma = &(priv->gamma);
	} else {

		DPRINT("display-fbdev: trying palette.\n");

		len = 1 << priv->var.bits_per_pixel;
		LIBGGI_PAL(vis)->clut.size = len * 2;
		LIBGGI_PAL(vis)->clut.data = calloc(len * 2 /* orig */, sizeof(ggi_color));
		if (LIBGGI_PAL(vis)->clut.data == NULL) return;
	}

	cmap.start = 0;
	cmap.len   = len;
	cmap.red   = calloc(len * 3, 2);
	if (cmap.red == NULL) goto bail;
	cmap.green = cmap.red + len;
	cmap.blue  = cmap.green + len;
	cmap.transp = NULL;
	
	if (ioctl(LIBGGI_FD(vis), FBIOGETCMAP, &cmap) < 0) {
		DPRINT_COLOR("display-fbdev: GETCMAP failed.\n");
		free(cmap.red);
		goto bail;
	} 

	priv->orig_cmap = LIBGGI_PAL(vis)->clut.data + len;

	if (vis->gamma != NULL) {

		DPRINT_COLOR("display-fbdev: Saved gamma (len=%d/%d/%d).\n",
				priv->gamma.maxread_r, priv->gamma.maxread_g,
				priv->gamma.maxread_b);

		while (len--) {
			if (len < priv->gamma.maxread_r) 
				priv->orig_cmap[len].r = cmap.red[len];
			if (len < priv->gamma.maxread_g) 
				priv->orig_cmap[len].g = cmap.green[len];
			if (len < priv->gamma.maxread_b) 
				priv->orig_cmap[len].b = cmap.blue[len];
		}
		vis->opcolor->getgammamap = GGI_fbdev_getgammamap;
		vis->opcolor->setgammamap = GGI_fbdev_setgammamap;
	}
	else {
		DPRINT_COLOR("display-fbdev: Saved palette (len=%d).\n", 
				len);
		while (len--) {
			priv->orig_cmap[len].r = cmap.red[len];
			priv->orig_cmap[len].g = cmap.green[len];
			priv->orig_cmap[len].b = cmap.blue[len];
		}
		if (priv->fix.visual != FB_VISUAL_STATIC_PSEUDOCOLOR) {
			LIBGGI_PAL(vis)->setPalette  = GGI_fbdev_setPalette;
			LIBGGI_PAL(vis)->getPrivSize =  GGI_fbdev_getPrivSize;
		}
	}

	LIBGGI_PAL(vis)->priv = cmap.red;

	priv->reds = cmap.red;
	priv->greens = cmap.green;
	priv->blues = cmap.blue;
	return;

 bail:
	free(LIBGGI_PAL(vis)->clut.data);
	LIBGGI_PAL(vis)->clut.data = NULL;
	vis->gamma = NULL;
	return;

}
Beispiel #15
0
static size_t GGI_fbdev_getPrivSize(ggi_visual_t vis) 
{
	return (LIBGGI_PAL(vis)->clut.size * 3);
}
Beispiel #16
0
static int do_setmode(struct ggi_visual *vis)
{
	ggi_palemu_priv *priv = PALEMU_PRIV(vis);
	char libname[GGI_MAX_APILEN], libargs[GGI_MAX_APILEN];
	int err, id;


	_GGI_palemu_freedbs(vis);

	if ((err = do_dbstuff(vis)) != 0) {
		return err;
	}
	
	/* load libraries */

	for (id=1; GGI_palemu_getapi(vis, id, libname, libargs) == 0; id++) {
		err = _ggiOpenDL(vis, libggi->config, libname, libargs, NULL);
		if (err) {
			fprintf(stderr, "display-palemu: Error opening "
				" %s (%s) library.\n", libname, libargs);
			return GGI_EFATAL;
		}

		DPRINT("Success in loading %s (%s)\n", libname, libargs);
	}


	/* Backup the current 2D operations, and override them with our
	 * own (which then call on these backups to do the work).
	 */

	priv->mem_opdraw = _ggi_malloc(sizeof(struct ggi_visual_opdraw));

	*priv->mem_opdraw = *vis->opdraw;

	if (priv->target == PALEMU_TARGET) {
		vis->opdraw->putbox = GGI_palemu_putbox;
		vis->opdraw->drawbox = GGI_palemu_drawbox;
		vis->opdraw->copybox = GGI_palemu_copybox;
		vis->opdraw->crossblit = GGI_palemu_crossblit;
		vis->opdraw->fillscreen = GGI_palemu_fillscreen;
	} else {
		vis->opdraw->putbox = GGI_monotext_putbox;
		vis->opdraw->drawbox = GGI_monotext_drawbox;
		vis->opdraw->copybox = GGI_monotext_copybox;
		vis->opdraw->crossblit = GGI_monotext_crossblit;
		vis->opdraw->fillscreen = GGI_monotext_fillscreen;
	}

	vis->opdraw->drawpixel_nc=GGI_palemu_drawpixel_nc;
	vis->opdraw->drawpixel=GGI_palemu_drawpixel;
	vis->opdraw->drawhline_nc=GGI_palemu_drawhline_nc;
	vis->opdraw->drawhline=GGI_palemu_drawhline;
	vis->opdraw->drawvline_nc=GGI_palemu_drawvline_nc;
	vis->opdraw->drawvline=GGI_palemu_drawvline;
	vis->opdraw->drawline=GGI_palemu_drawline;

	vis->opdraw->putc=GGI_palemu_putc;
	vis->opdraw->putpixel_nc=GGI_palemu_putpixel_nc;
	vis->opdraw->putpixel=GGI_palemu_putpixel;
	vis->opdraw->puthline=GGI_palemu_puthline;
	vis->opdraw->putvline=GGI_palemu_putvline;


	vis->opdraw->setorigin=GGI_palemu_setorigin;

	/* colormap initialization */
	LIBGGI_PAL(vis)->setPalette = GGI_palemu_setPalette;

	vis->opdraw->setreadframe=GGI_palemu_setreadframe;
	vis->opdraw->setwriteframe=GGI_palemu_setwriteframe;
	vis->opdraw->setdisplayframe=GGI_palemu_setdisplayframe;

	ggiIndicateChange(vis->instance.stem, GGI_CHG_APILIST);

	/* set initial frames */
	priv->mem_opdraw->setreadframe(vis, 0);
	priv->mem_opdraw->setwriteframe(vis, 0);

	return 0;
}