static int
scummvm_init_specific(struct _gfx_driver *drv, int xfact, int yfact, int bytespp)
{
	int i;

	if (!drv->state) // = S
		drv->state = new _scummvm_driver_state;
	if (!drv->state)
		return GFX_FATAL;

	S->xsize = xfact * 320;
	S->ysize = yfact * 200;

	S->pointer_data[0] = NULL;
	S->pointer_data[1] = NULL;
	//S->buckystate = 0;

	for (i = 0; i < 2; i++) {
		S->priority[i] = gfx_pixmap_alloc_index_data(gfx_new_pixmap(S->xsize, S->ysize, GFX_RESID_NONE, -i, -777));
		if (!S->priority[i]) {
			printf("Out of memory: Could not allocate priority maps! (%dx%d)\n",
					S->xsize, S->ysize);
			return GFX_FATAL;
		}
	}
	// create the visual buffers
	for (i = 0; i < 3; i++) {
		S->visual[i] = NULL;
		S->visual[i] = new byte[S->xsize * S->ysize];
		if (!S->visual[i]) {
			printf("Out of memory: Could not allocate visual buffers! (%dx%d)\n",
					S->xsize, S->ysize);
			return GFX_FATAL;
		}
		memset(S->visual[i], 0, S->xsize * S->ysize);
	}

	drv->mode = gfx_new_mode(xfact, yfact, bytespp,
				0, 0, 0, 0,
				0, 0, 0, 0, 256, 0);

	return GFX_OK;
}
Esempio n. 2
0
gfx_pixmap_t *
gfxr_draw_cel0(int id, int loop, int cel, byte *resource, int size, gfxr_view_t *view, int mirrored)
{
	int xl = get_int_16(resource);
	int yl = get_int_16(resource + 2);
	int xhot = ((signed char *) resource)[4];
	int yhot = ((signed char *) resource)[5];
	int color_key = resource[6];
	int pos = 7;
	int writepos = mirrored? xl : 0;
	int pixmap_size = xl * yl;
	int line_base = 0;
	gfx_pixmap_t *retval = gfx_pixmap_alloc_index_data(gfx_new_pixmap(xl, yl, id, loop, cel));
	byte *dest = retval->index_data;

	retval->color_key = 255; /* Pick something larger than 15  */

	retval->xoffset = mirrored? xhot : -xhot;
	retval->yoffset = -yhot;

	if (view) {
		retval->colors = view->colors;
		retval->colors_nr = view->colors_nr;
		retval->flags |= GFX_PIXMAP_FLAG_EXTERNAL_PALETTE;
	} else
	{
		retval->colors = gfx_sci0_image_colors[sci0_palette];
		retval->colors_nr = GFX_SCI0_IMAGE_COLORS_NR;
		retval->flags |= GFX_PIXMAP_FLAG_EXTERNAL_PALETTE;
	}

	if (xl <= 0 || yl <= 0) {
		gfx_free_pixmap(NULL, retval);
		GFXERROR("View %02x:(%d/%d) has invalid xl=%d or yl=%d\n", id, loop, cel, xl, yl);
		return NULL;
	}

	if (mirrored) {

		while (yl && pos < size) {
			int op = resource[pos++];
			int count = op >> 4;
			int color = op & 0xf;

			if (view->flags & GFX_PIXMAP_FLAG_PALETTIZED)
				color = view->translation[color];

			if (color == color_key)
				color = retval->color_key;

			while (count) {
				int pixels = writepos - line_base;

				if (pixels > count)
					pixels = count;

				writepos -= pixels;
				memset(dest + writepos, color, pixels);
				count -= pixels;

				if (writepos == line_base) {
					yl--;
					writepos += (xl << 1);
					line_base += xl;
				}
			}
		}
	} else {

		while (writepos < pixmap_size && pos < size) {
Esempio n. 3
0
gfx_pixmap_t *gfxr_draw_font(gfx_bitmap_font_t *font, const char *stext, int characters, PaletteEntry *fg0, PaletteEntry *fg1, PaletteEntry *bg) {
	unsigned char *text = (unsigned char *)stext;
	int height = font->height;
	int width = 0;
	gfx_pixmap_t *pxm;
	int fore_0, fore_1, back;
	int i;
	int hack = 0;
	PaletteEntry dummy(0,0,0); // black
	byte *offset;

	for (i = 0; i < characters; i++) {
		int ch = (int) text[i];

		if (ch >= font->chars_nr) {
			error("Invalid character 0x%02x encountered", text[i]);
			return NULL;
		}

		width += font->widths[ch];
	}

	pxm = gfx_pixmap_alloc_index_data(gfx_new_pixmap(width, height, GFX_RESID_NONE, 0, 0));

	int colors_nr = !!fg0 + !!fg1 + !!bg;
	if (colors_nr == 0) {
		warning("[GFX] Pixmap would have zero colors, resetting");
		colors_nr = 3;
		hack = 1;
		fg0 = fg1 = bg = &dummy;
	}
	pxm->palette = new Palette(colors_nr);
	pxm->palette->name = "font";

	i = 0;

	if (fg0 || hack) {
		pxm->palette->setColor(i, fg0->r, fg0->g, fg0->b);
		fore_0 = i++;
	} else
		fore_0 = pxm->color_key;

	if (fg1 || hack) {
		pxm->palette->setColor(i, fg1->r, fg1->g, fg1->b);
		fore_1 = i++;
	} else
		fore_1 = pxm->color_key;

	if (bg || hack) {
		pxm->palette->setColor(i, bg->r, bg->g, bg->b);
		back = i++;
	} else
		back = pxm->color_key;

	offset = pxm->index_data;

	memset(pxm->index_data, back, pxm->index_width * pxm->index_height);
	for (i = 0; i < characters; i++) {
		unsigned char ch = text[i];
		width = font->widths[ch];

		render_char(offset, font->data + (ch * font->char_size), width,
		            pxm->index_width, pxm->index_height, font->row_size, fore_0, fore_1, back);

		offset += width;
	}

	return pxm;
}