Exemplo n.º 1
0
void Surface::Set(const void* pixels, unsigned int width, unsigned int height, unsigned char bytes_per_pixel, bool amask0)
{
    FreeSurface(*this);

    switch(bytes_per_pixel)
    {
	case 1:
	    CreateSurface(width, height, 8, false);
	    LoadPalette();
	    Lock();
	    std::memcpy(surface->pixels, pixels, width * height);
	    Unlock();
	    break;

	default:
	{
	    u32 rmask, gmask, bmask, amask;
	    GetRGBAMask(bytes_per_pixel * 8, rmask, gmask, bmask, amask);
	    surface = SDL_CreateRGBSurfaceFrom(const_cast<void *>(pixels), width, height, 8 * bytes_per_pixel, width * bytes_per_pixel,
		rmask, gmask, bmask, (amask0 ? amask : 0));
	}
	break;
    }

    if(!surface)
	Error::Except(__FUNCTION__, SDL_GetError());
}
Exemplo n.º 2
0
Surface::Surface(const void* pixels, u32 width, u32 height, u32 bytes_per_pixel /* 1, 2, 3, 4 */, bool amask) : surface(NULL)
{
    SurfaceFormat fm = GetRGBAMask(8 * bytes_per_pixel);

    if(8 == fm.depth)
    {
#if SDL_VERSION_ATLEAST(2, 0, 0)
	surface = SDL_CreateRGBSurface(0, width, height, fm.depth, fm.rmask, fm.gmask, fm.bmask, (amask ? fm.amask : 0));
#else
	surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, fm.depth, fm.rmask, fm.gmask, fm.bmask, (amask ? fm.amask : 0));
#endif
    }
    else
    {
	surface = SDL_CreateRGBSurfaceFrom(const_cast<void *>(pixels), width, height, fm.depth, width * bytes_per_pixel,
		fm.rmask, fm.gmask, fm.bmask, amask ? fm.amask : 0);
#if SDL_VERSION_ATLEAST(2, 0, 0)
	SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE);
#endif
    }

    if(!surface)
	Error::Except(__FUNCTION__, SDL_GetError());

    if(8 == fm.depth)
    {
	SetPalette();
	Lock();
	std::memcpy(surface->pixels, pixels, width * height);
	Unlock();
    }
}
Exemplo n.º 3
0
/* create new surface */
void Surface::CreateSurface(u16 sw, u16 sh, u8 bpp, bool amask0)
{
    u32 rmask, gmask, bmask, amask;
    GetRGBAMask(bpp, rmask, gmask, bmask, amask);
    surface = SDL_CreateRGBSurface(SDL_SWSURFACE, sw, sh, bpp, rmask, gmask, bmask, (amask0 ? amask : 0));

    if(!surface)
	Error::Except(__FUNCTION__, SDL_GetError());
}
Exemplo n.º 4
0
void Surface::Set(u32 sw, u32 sh, u32 bpp /* bpp: 8, 16, 24, 32 */, bool amask)
{
    if(bpp == 8)
	bpp = 32;

    SurfaceFormat fm = GetRGBAMask(bpp);

    if(8 == fm.depth || ! amask) fm.amask = 0;
    Set(sw, sh, fm);
}