Exemple #1
0
AG_Surface *
AG_SDL_ShadowSurface(SDL_Surface *ss)
{
	AG_PixelFormat *pf;
	AG_Surface *ds;

	if ((pf = AG_SDL_GetPixelFormat(ss)) == NULL) {
		return (NULL);
	}
	if (pf->palette != NULL) {
		AG_SetError("Indexed formats not supported");
		AG_PixelFormatFree(pf);
		return (NULL);
	}

	if ((ds = AG_SurfaceNew(AG_SURFACE_PACKED, 0, 0, pf, 0))
	    == NULL) {
		goto out;
	}
	if (ss->flags & SDL_SRCCOLORKEY) { ds->flags |= AG_SRCCOLORKEY; }
	if (ss->flags & SDL_SRCALPHA) { ds->flags |= AG_SRCALPHA; }

	ds->pixels = ss->pixels;
	ds->w = ss->w;
	ds->h = ss->h;
	ds->pitch = ds->w * pf->BytesPerPixel;
	ds->clipRect = AG_RECT(0,0,ds->w,ds->h);

out:
	AG_PixelFormatFree(pf);
	return (ds);
}
Exemple #2
0
/* Convert a SDL_Surface to an AG_Surface. */
AG_Surface *
AG_SDL_ImportSurface(SDL_Surface *ss)
{
	AG_PixelFormat *pf;
	AG_Surface *ds;
	Uint8 *pSrc, *pDst;
	int y;
#if 0
	Uint32 px;
	AG_Color C;
	int x;
#endif

	if ((pf = AG_SDL_GetPixelFormat(ss)) == NULL) {
		return (NULL);
	}
	if (pf->palette != NULL) {
		AG_SetError("Indexed formats not supported");
		AG_PixelFormatFree(pf);
		return (NULL);
	}

	if ((ds = AG_SurfaceNew(AG_SURFACE_PACKED, ss->w, ss->h, pf, 0))
	    == NULL) {
		goto out;
	}
	if (ss->flags & SDL_SRCCOLORKEY) { ds->flags |= AG_SRCCOLORKEY; }
	if (ss->flags & SDL_SRCALPHA) { ds->flags |= AG_SRCALPHA; }
	
	if (SDL_MUSTLOCK(ss)) {
		SDL_LockSurface(ss);
	}
	pSrc = (Uint8 *)ss->pixels;
	pDst = (Uint8 *)ds->pixels;
	for (y = 0; y < ss->h; y++) {
		memcpy(pDst, pSrc, ss->pitch);
		pSrc += ss->pitch;
		pDst += ds->pitch;
	}
#if 0
	for (y = 0; y < ss->h; y++) {
		for (x = 0; x < ss->w; x++) {
			AG_PACKEDPIXEL_GET(ss->format->BytesPerPixel, px, pSrc);
			C = AG_SDL_GetColorRGBA(px, ss->format);
			AG_PUT_PIXEL(ds,pDst,
			    AG_MapColorRGBA(ds->format, C));
			pSrc += ss->format->BytesPerPixel;
			pDst += ds->format->BytesPerPixel;
		}
	}
#endif
	if (SDL_MUSTLOCK(ss))
		SDL_UnlockSurface(ss);

out:
	AG_PixelFormatFree(pf);
	return (ds);
}
BOOL DumpObject::InitConsole(int w, int h)
{
    int size;
    AG_PixelFormat fmt;
    int xx;
    int yy;

    if((w <= 0) || (h <= 0)) return FALSE;
    AG_MutexLock(&mutex);
    W = w;
    H = h;
    X = 0;
    Y = 0;
    size = w * h;
    if(ConsoleBuf != NULL) delete [] ConsoleBuf;
    if(BackupConsoleBuf != NULL) delete [] ConsoleBuf;
    if(Screen != NULL) {
        Screen = NULL;
        AG_SurfaceFree(Screen);
    }

    ConsoleBuf = new BYTE[size];
    BackupConsoleBuf = new BYTE[size];
    for(yy = 0; yy < H; yy++) {
        for(xx = 0; xx < W; xx++) {
            ConsoleBuf[xx + yy * W] = 0x00000000;
            BackupConsoleBuf[xx + yy * W] = 0x00000000;
        }
    }
    SetPixelFormat(&fmt);
    Screen = AG_SurfaceNew(AG_SURFACE_PACKED, W * CHRW, H * CHRH, &fmt, 0);
    {
        AG_Color col;
        AG_Rect rec;
        col.r = 0;
        col.g = 0;
        col.b = 0;
        col.a = 255;
        rec.x = 0;
        rec.y = 0;
        rec.w = Screen->w;
        rec.h = Screen->h;
        AG_FillRect(Screen, &rec, col);
    }
    AG_MutexUnlock(&mutex);
}