Example #1
2
void WindowManager::setDefaultWindowIcon()
{
  SDL_Surface *surface;     // Declare an SDL_Surface to be filled in with pixel data from an image file
  Uint16 pixels[16*16] = {  // ...or with raw pixel data:
    0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff,
    0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff,
    0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff,
    0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff,
    0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff,
    0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff,
    0x0fff, 0x0aab, 0x0789, 0x0bcc, 0x0eee, 0x09aa, 0x099a, 0x0ddd,
    0x0fff, 0x0eee, 0x0899, 0x0fff, 0x0fff, 0x1fff, 0x0dde, 0x0dee,
    0x0fff, 0xabbc, 0xf779, 0x8cdd, 0x3fff, 0x9bbc, 0xaaab, 0x6fff,
    0x0fff, 0x3fff, 0xbaab, 0x0fff, 0x0fff, 0x6689, 0x6fff, 0x0dee,
    0xe678, 0xf134, 0x8abb, 0xf235, 0xf678, 0xf013, 0xf568, 0xf001,
    0xd889, 0x7abc, 0xf001, 0x0fff, 0x0fff, 0x0bcc, 0x9124, 0x5fff,
    0xf124, 0xf356, 0x3eee, 0x0fff, 0x7bbc, 0xf124, 0x0789, 0x2fff,
    0xf002, 0xd789, 0xf024, 0x0fff, 0x0fff, 0x0002, 0x0134, 0xd79a,
    0x1fff, 0xf023, 0xf000, 0xf124, 0xc99a, 0xf024, 0x0567, 0x0fff,
    0xf002, 0xe678, 0xf013, 0x0fff, 0x0ddd, 0x0fff, 0x0fff, 0xb689,
    0x8abb, 0x0fff, 0x0fff, 0xf001, 0xf235, 0xf013, 0x0fff, 0xd789,
    0xf002, 0x9899, 0xf001, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0xe789,
    0xf023, 0xf000, 0xf001, 0xe456, 0x8bcc, 0xf013, 0xf002, 0xf012,
    0x1767, 0x5aaa, 0xf013, 0xf001, 0xf000, 0x0fff, 0x7fff, 0xf124,
    0x0fff, 0x089a, 0x0578, 0x0fff, 0x089a, 0x0013, 0x0245, 0x0eff,
    0x0223, 0x0dde, 0x0135, 0x0789, 0x0ddd, 0xbbbc, 0xf346, 0x0467,
    0x0fff, 0x4eee, 0x3ddd, 0x0edd, 0x0dee, 0x0fff, 0x0fff, 0x0dee,
    0x0def, 0x08ab, 0x0fff, 0x7fff, 0xfabc, 0xf356, 0x0457, 0x0467,
    0x0fff, 0x0bcd, 0x4bde, 0x9bcc, 0x8dee, 0x8eff, 0x8fff, 0x9fff,
    0xadee, 0xeccd, 0xf689, 0xc357, 0x2356, 0x0356, 0x0467, 0x0467,
    0x0fff, 0x0ccd, 0x0bdd, 0x0cdd, 0x0aaa, 0x2234, 0x4135, 0x4346,
    0x5356, 0x2246, 0x0346, 0x0356, 0x0467, 0x0356, 0x0467, 0x0467,
    0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff,
    0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff,
    0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff,
    0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff
  };
  surface = SDL_CreateRGBSurfaceFrom(pixels,16,16,16,16*2,0x0f00,0x00f0,0x000f,0xf000);

  // The icon is attached to the window pointer
  SDL_SetWindowIcon(this->p_window, surface);

  // ...and the surface containing the icon pixel data is no longer required.
  SDL_FreeSurface(surface);

}
Example #2
0
void copytoscreen(char* tmap) {
	int loop=0;
	do{
		SDL_PollEvent(&event);
		if (event.type == SDL_KEYDOWN) {
			v4l1_close(fd);
			SDL_Quit();
			exit(0);
		}
		// usleep(20);
	} while(loop++<20);
	offscreen = SDL_CreateRGBSurfaceFrom((void *) tmap, mywidth, myheight, 24, mywidth*3, 0xFF0000, 0x00FF00, 0x0000FF, 0x000000);
	SDL_BlitSurface(offscreen, NULL, screen, NULL);
	SDL_UpdateRect(screen, 0, 0, 0, 0);
	SDL_FreeSurface(offscreen);
}
Example #3
0
SDL_Surface* create_cam_img (unsigned char *pixels, int w,int h)
{
    int bpp,pitch;
    Uint32 rmask, gmask, bmask, amask;

    bpp=24;
    pitch = w * 3;

    amask = 0;
    bmask = 0xff0000;
    gmask = 0x00ff00;
    rmask = 0x0000ff;

    return SDL_CreateRGBSurfaceFrom (pixels,w,h,bpp,pitch,rmask,gmask,bmask,amask);

}
Example #4
0
static SDL_Surface *
create_surface_from_data(void *data, int width, int height, int transparent) {
	int r;

	/* Create sprite surface */
	SDL_Surface *surf8 =
	SDL_CreateRGBSurfaceFrom(data, (int)width, (int)height, 8,
				 (int)(width*sizeof(uint8_t)), 0, 0, 0, 0);
	if (surf8 == NULL) {
		LOGE("sdl-video", "Unable to create sprite surface: %s.",
		     SDL_GetError());
		exit(EXIT_FAILURE);
	}

	/* Set sprite palette */
	r = SDL_SetPalette(surf8, SDL_LOGPAL | SDL_PHYSPAL, pal_colors, 0, 256);
	if (r == 0) {
		LOGE("sdl-video", "Unable to set palette for sprite.");
		exit(EXIT_FAILURE);
	}

	/* Covert to screen format */
	SDL_Surface *surf = NULL;

	if (transparent) {
		/* Set color key */
		r = SDL_SetColorKey(surf8, SDL_SRCCOLORKEY | SDL_RLEACCEL, 0);
		if (r < 0) {
			LOGE("sdl-video", "Unable to set color key for sprite.");
			exit(EXIT_FAILURE);
		}

		surf = SDL_DisplayFormatAlpha(surf8);
	} else {
		surf = SDL_DisplayFormat(surf8);
	}

	if (surf == NULL) {
		LOGE("sdl-video", "Unable to convert sprite surface: %s.",
		     SDL_GetError());
		exit(EXIT_FAILURE);
	}
	
	SDL_FreeSurface(surf8);
	
	return surf;
}
Example #5
0
bool Window::setIcon(love::image::ImageData *imgd)
{
	if (!imgd)
		return false;

	if (imgd->getFormat() != PIXELFORMAT_RGBA8)
		throw love::Exception("setIcon only accepts 32-bit RGBA images.");

	icon.set(imgd);

	if (!window)
		return false;

	Uint32 rmask, gmask, bmask, amask;
#ifdef LOVE_BIG_ENDIAN
	rmask = 0xFF000000;
	gmask = 0x00FF0000;
	bmask = 0x0000FF00;
	amask = 0x000000FF;
#else
	rmask = 0x000000FF;
	gmask = 0x0000FF00;
	bmask = 0x00FF0000;
	amask = 0xFF000000;
#endif

	int w = imgd->getWidth();
	int h = imgd->getHeight();
	int bytesperpixel = (int) getPixelFormatSize(imgd->getFormat());
	int pitch = w * bytesperpixel;

	SDL_Surface *sdlicon = nullptr;

	{
		// We don't want another thread modifying the ImageData mid-copy.
		love::thread::Lock lock(imgd->getMutex());
		sdlicon = SDL_CreateRGBSurfaceFrom(imgd->getData(), w, h, bytesperpixel * 8, pitch, rmask, gmask, bmask, amask);
	}

	if (!sdlicon)
		return false;

	SDL_SetWindowIcon(window, sdlicon);
	SDL_FreeSurface(sdlicon);

	return true;
}
Example #6
0
void ttext::rerender(const bool force) const
{
	if(surface_dirty_ || force) {
		assert(layout_);

		recalculate(force);
		surface_dirty_ = false;

		int width  = rect_.x + rect_.width;
		int height = rect_.y + rect_.height;
		if(maximum_width_  > 0) { width  = std::min(width, maximum_width_); }
		if(maximum_height_ > 0) { height = std::min(height, maximum_height_); }

		cairo_format_t format = CAIRO_FORMAT_ARGB32;
		const unsigned stride = cairo_format_stride_for_width(format, width);

		create_surface_buffer(stride * height);

		cairo_surface_t* cairo_surface =
			cairo_image_surface_create_for_data(surface_buffer_, format, width, height, stride);
		cairo_t* cr = cairo_create(cairo_surface);

		/* set color (used for foreground). */
		cairo_set_source_rgba(cr,
			 (foreground_color_ >> 24)         / 256.0,
			((foreground_color_ >> 16) & 0xFF) / 256.0,
			((foreground_color_ >> 8)  & 0xFF) / 256.0,
			(foreground_color_         & 0xFF) / 256.0);

		pango_cairo_show_layout(cr, layout_);

		// The cairo surface is in CAIRO_FORMAT_ARGB32 which uses
		// pre-multiplied alpha. SDL doesn't use that so the pixels need to be
		// decoded again.
		for(int y = 0; y < height; ++y) {
			for(int x = 0; x < width; ++x) {
				unsigned char* pixel = &surface_buffer_[(y * width + x) * 4];
				decode_pixel(pixel);
			}
		}

		surface_.assign(SDL_CreateRGBSurfaceFrom(
			surface_buffer_, width, height, 32, stride, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000));
		cairo_destroy(cr);
		cairo_surface_destroy(cairo_surface);
	}
Example #7
0
int videodev_start (void) {
	printf("videocapture: init\n");
	dev_name = "/dev/video0";
	generate_YCbCr_to_RGB_lookup();
	open_device();
	if (video_ok == 0) {
		return 0;
	}
	init_device();
	if (video_ok == 0) {
		return 0;
	}
	buffer_sdl = (uint8_t*)malloc(WIDTH*HEIGHT*3);
	data_sf = SDL_CreateRGBSurfaceFrom(buffer_sdl, WIDTH, HEIGHT, 24, WIDTH * 3, mask32(0), mask32(1), mask32(2), 0);
	start_capturing();
	return 0;
}
Example #8
0
bool THSpriteSheet::loadFromTHFile(
                        const unsigned char* pTableData, size_t iTableDataLength,
                        const unsigned char* pChunkData, size_t iChunkDataLength,
                        bool bComplexChunks, THRenderTarget*)
{
    _freeSprites();
    m_iSpriteCount = (unsigned int)(iTableDataLength / sizeof(th_sprite_t));
    m_pSprites = new (std::nothrow) sprite_t[m_iSpriteCount];
    if(m_pSprites == NULL)
    {
        m_iSpriteCount = 0;
        return false;
    }

    for(unsigned int i = 0; i < m_iSpriteCount; ++i)
    {
        sprite_t *pSprite = m_pSprites + i;
        const th_sprite_t *pTHSprite = reinterpret_cast<const th_sprite_t*>(pTableData) + i;
        for(unsigned int j = 0; j < 32; ++j)
            m_pSprites[i].pBitmap[j] = NULL;
        pSprite->pData = NULL;
        pSprite->pAltPaletteMap = NULL;
        pSprite->iWidth = pTHSprite->width;
        pSprite->iHeight = pTHSprite->height;

        if(pSprite->iWidth == 0 || pSprite->iHeight == 0)
            continue;

        {
            THChunkRenderer oRenderer(pSprite->iWidth, pSprite->iHeight, NULL);
            int iDataLen = static_cast<int>(iChunkDataLength) - static_cast<int>(pTHSprite->position);
            if(iDataLen < 0)
                iDataLen = 0;
            oRenderer.decodeChunks(pChunkData + pTHSprite->position, iDataLen, bComplexChunks);
            pSprite->pData = oRenderer.takeData();
        }

        pSprite->pBitmap[0] = SDL_CreateRGBSurfaceFrom(pSprite->pData,
            pSprite->iWidth, pSprite->iHeight, 8, pSprite->iWidth, 0, 0, 0, 0);

        if(pSprite->pBitmap[0] != NULL)
            m_pPalette->_assign(pSprite->pBitmap[0]);
    }

    return true;
}
Example #9
0
static void draw_pdf()
{
	SDL_Rect dest_rec;
    SDL_Surface *optimizedImage = NULL;
    SDL_FreeSurface(page_copy);

    page_copy = SDL_CreateRGBSurfaceFrom(app.image->samples, app.image->w, app.image->h,
            32, app.image->w * 4, 0x00, 0x00, 0x00, 0x00);
    optimizedImage = SDL_DisplayFormat(page_copy); 
    //		content = SDL_CreateRGBSurfaceFrom(app.image->samples, pagewidth,pageheight,
    //			32,pagewidth * 4, 0x00, 0x00, 0x00, 0x00);
    dest_rec.x = (1024 - app.image->w)/2;
	dest_rec.y = 0;
	SDL_FillRect(Surface,NULL,SDL_MapRGBA(Surface->format,45,45,45,0));
    SDL_BlitSurface(optimizedImage,NULL, Surface, &dest_rec);
    SDL_Flip(Surface);
    //		SDL_Delay(100);
}
Example #10
0
BLIT sdl_srcalpha(void *src, SDL_Rect *src_rect,
		  SDL_Surface *dst, SDL_Rect *dst_rect,
		  Geometry *geo, Linklist<Parameter> *params) {

  float alpha = *(float*)(params->begin()->value); // only one value
  unsigned int int_alpha = (unsigned int) alpha;

  sdl_surf = SDL_CreateRGBSurfaceFrom
    (src, geo->w, geo->h, geo->bpp,
     geo->bytewidth, red_bitmask, green_bitmask, blue_bitmask, alpha_bitmask);
  
  SDL_SetAlpha( sdl_surf, SDL_SRCALPHA|SDL_RLEACCEL, int_alpha );  

  SDL_BlitSurface( sdl_surf, src_rect, dst, dst_rect );
  
  SDL_FreeSurface( sdl_surf );
  
};
Example #11
0
  TexturePrivate(Renderer &renderer, Sprite &sprite, Palette &palette) : src_rect_(0,0,8,8), dst_rect_(0,0,8,8){
    SDL_Surface* surface = SDL_CreateRGBSurfaceFrom(sprite.data(), sprite.width(), sprite.height(), 8, sprite.width(), 0, 0, 0, 0);

    SDL_Color colours[4];
    for(int i = 0; i < 4; i++){
      colours[i].a = palette[i].a;
      colours[i].r = palette[i].r;
      colours[i].g = palette[i].g;
      colours[i].b = palette[i].b;
    }

    SDL_SetPaletteColors(surface->format->palette, colours, 0, 4);
    texture_ = SDL_CreateTextureFromSurface(renderer.rawRenderer(), surface);
    if(texture_ == nullptr){
      throw std::runtime_error("SDL_CreateTextureFromSurface failed: " + std::string(SDL_GetError()));
    }
    SDL_FreeSurface(surface);
  }
Example #12
0
bool Image::initialize( void* pixels, int32 width, int32 height,
                        int bits_per_pixel, uint16 pitch,
                        uint32 Rmask, uint32 Gmask, uint32 Bmask, uint32 Amask
                      )
{
  // NOM_LOG_TRACE( NOM );

  this->image_.reset ( SDL_CreateRGBSurfaceFrom ( pixels, width, height, bits_per_pixel, pitch, Rmask, Gmask, Bmask, Amask ), priv::FreeSurface );
  //this->set_bounds ( IntRect( 0, 0, width, height) );

  if ( this->valid() == false )
  {
    NOM_LOG_ERR ( NOM, SDL_GetError() );
    return false;
  }

  return true;
}
Example #13
0
static SDL_Surface *
create_surface_from_data(void *data, int width, int height, int transparent) {
	int r;

	/* Create sprite surface */
	SDL_Surface *surf8 =
	SDL_CreateRGBSurfaceFrom(data, (int)width, (int)height, 8,
				 (int)(width*sizeof(uint8_t)), 0, 0, 0, 0);
	if (surf8 == NULL) {
		LOGE("sdl-video", "Unable to create sprite surface: %s.",
		     SDL_GetError());
		exit(EXIT_FAILURE);
	}

	/* Set sprite palette */
	r = SDL_SetPaletteColors(surf8->format->palette, pal_colors, 0, 256);
	if (r < 0) {
		LOGE("sdl-video", "Unable to set palette for sprite.");
		exit(EXIT_FAILURE);
	}

	/* Covert to screen format */
	SDL_Surface *surf = NULL;

	if (transparent) {
		/* Set color key */
		r = SDL_SetColorKey(surf8, SDL_TRUE, 0);
		if (r < 0) {
			LOGE("sdl-video", "Unable to set color key for sprite.");
			exit(EXIT_FAILURE);
		}
	}

	surf = SDL_ConvertSurface(surf8, screen.surf->format, 0);
	if (surf == NULL) {
		LOGE("sdl-video", "Unable to convert sprite surface: %s.",
		     SDL_GetError());
		exit(EXIT_FAILURE);
	}

	SDL_FreeSurface(surf8);

	return surf;
}
Example #14
0
/**
 * Sets up a blank 8bpp surface with the specified size and position,
 * with pure black as the transparent color.
 * @note Surfaces don't have to fill the whole size since their
 * background is transparent, specially subclasses with their own
 * drawing logic, so it just covers the maximum drawing area.
 * @param width Width in pixels.
 * @param height Height in pixels.
 * @param x X position in pixels.
 * @param y Y position in pixels.
 * @param bpp Bits-per-pixel depth.
 */
Surface::Surface(int width, int height, int x, int y, int bpp) : _x(x), _y(y), _visible(true), _hidden(false), _redraw(false), _originalColors(0), _alignedBuffer(0)
{
	_alignedBuffer = NewAligned(bpp, width, height);
	_surface = SDL_CreateRGBSurfaceFrom(_alignedBuffer, width, height, bpp, GetPitch(bpp, width), 0, 0, 0, 0);

	if (_surface == 0)
	{
		throw Exception(SDL_GetError());
	}

	SDL_SetColorKey(_surface, SDL_SRCCOLORKEY, 0);

	_crop.w = 0;
	_crop.h = 0;
	_crop.x = 0;
	_crop.y = 0;
	_dx = Screen::getDX();
	_dy = Screen::getDY();
}
Example #15
0
void Game_takeScreenshot(const Game *g) {
    uint8_t *lin = malloc(4 * g->window_size.x);
    if(!lin) {
        fputs("Could not take screenshot: malloc() failed.\n", stderr);
        return;
    }
    uint8_t *img = malloc(4 * g->window_size.x * g->window_size.y);
    if(!img) {
        fputs("Could not take screenshot: malloc() failed.\n", stderr);
        free(lin);
        return;
    }
    glReadPixels(0, 0, g->window_size.x, g->window_size.y, 
                 GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, img);
    /* Faire la symétrie verticale.*/
    size_t linesize = 4*g->window_size.x;
    size_t t, b; /* top, bottom */
    for(t=0, b=g->window_size.y-1 ; t<b ; ++t, --b) {
        memcpy(lin,            img+t*linesize, linesize);
        memcpy(img+t*linesize, img+b*linesize, linesize);
        memcpy(img+b*linesize, lin,            linesize);
    }
    free(lin);
    SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(
            img, g->window_size.x, g->window_size.y, 32, linesize,
            0xff000000, 0xff0000, 0xff00, 0xff);
    if(!surface) {
        fputs("Could not take screenshot: "
              "SDL_CreateRGBSurfaceFrom() failed.\n",
              stderr);
        free(img);
        return;
    }
    char filename[64];
    snprintf(filename, sizeof(filename), "data/screenshots/%010u-%010u.bmp",
             (uint32_t)time(NULL), SDL_GetTicks());
    int saved = SDL_SaveBMP(surface, filename);
    SDL_FreeSurface(surface);
    free(img);
    if(saved == -1)
        fputs("Could not save screenshot: SDL_SaveBMP() failed.\n", stderr);
    else printf("Saved screenshot to %s\n", filename);
}
Example #16
0
SDL_Surface *image_sdl_create_from_rgba(void *rgba_buffer, uint32_t width,
										uint32_t height, uint8_t depth)
{
	SDL_Surface *surf;

	assert(rgba_buffer);
	assert(width > 0);
	assert(height > 0);
	assert(depth > 0);

	/* It's much faster than SDL_CreateRGBSurface and SDL_ConvertSurface. */
	surf = SDL_CreateRGBSurfaceFrom(rgba_buffer, width, height, depth,
									width * ( depth / 8 /* Bits. */ ),
									rmask, gmask, bmask, amask);
	if(surf == NULL)
		sg_log_err("SDL_CreateRGBSurfaceFrom error, %s.", SDL_GetError());

	return surf;
}
Example #17
0
static void Screenshot(void)
{
	// allocate a pixel array
	unsigned char *pixels = static_cast<unsigned char *>(malloc(SCREEN_WIDTH * SCREEN_HEIGHT * 4));

	// read pixels from frame buffer
	for (int y = 0; y < SCREEN_HEIGHT; ++y)
		glReadPixels(0, SCREEN_HEIGHT - y - 1, SCREEN_WIDTH, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels + y * SCREEN_WIDTH * 4);

	// create an SDL surface from the pixel array
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    unsigned int rmask = 0xff000000;
    unsigned int gmask = 0x00ff0000;
    unsigned int bmask = 0x0000ff00;
    unsigned int amask = 0x00000000;
#else
    unsigned int rmask = 0x000000ff;
    unsigned int gmask = 0x0000ff00;
    unsigned int bmask = 0x00ff0000;
    unsigned int amask = 0x00000000;
#endif
	SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(pixels, SCREEN_WIDTH, SCREEN_HEIGHT, 32, SCREEN_WIDTH * 4, rmask, gmask, bmask, amask);

	// generate a filename
	time_t rawtime;
	time( &rawtime );
	tm* timeinfo;
	timeinfo = localtime( &rawtime );
	char acTimeString[ 128 ] = "";
	strftime( acTimeString, 128, "%Y_%m_%d_%H_%M_%S", timeinfo );
	char acFileName[ 256 ] = "";
	sprintf( acFileName, "screenshot_%s.bmp", acTimeString );

	// save to a bitmap file
	if (SDL_SaveBMP(surface, acFileName) < 0)
		DebugPrint("error: %s\n", SDL_GetError());

	// free the surface
	SDL_FreeSurface(surface);

	// free the pixel array
	free(pixels);
}
Example #18
0
/**
	init_system_ColorCursor()-- Create a colored mouse cursor image
 */
SDL_Cursor *init_system_ColorCursor(CURSOR cur, const char *fileName)
{

	iV_Image *psSprite = (iV_Image *)malloc(sizeof(iV_Image));
	if (!psSprite)
	{
		debug(LOG_FATAL, "Could not allocate memory for cursor sprite. Exiting.");
		exit(-1);
	}

	if (!iV_loadImage_PNG(fileName, psSprite))
	{
		debug(LOG_FATAL, "Could not load cursor sprite. Exiting.");
		exit(-1);
	}

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
	uint32_t rmask = 0xff000000;
	uint32_t gmask = 0x00ff0000;
	uint32_t bmask = 0x0000ff00;
	uint32_t amask = 0x000000ff;
#else
	uint32_t rmask = 0x000000ff;
	uint32_t gmask = 0x0000ff00;
	uint32_t bmask = 0x00ff0000;
	uint32_t amask = 0xff000000;
#endif

	SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(psSprite->bmp, psSprite->width, psSprite->height, psSprite->depth * 8, psSprite->width * 4, rmask, gmask, bmask, amask);
	SDL_Cursor *pointer = SDL_CreateColorCursor(surface, psSprite->width / 2, psSprite->height / 2);	// We center the hotspot for all (FIXME ?)
	if (!pointer)
	{
		debug(LOG_FATAL, "Could not create cursor because %s", SDL_GetError());
		exit(-1);
	}

	// free up image & surface data
	free(psSprite->bmp);
	free(psSprite);
	SDL_FreeSurface(surface);

	return pointer;
}
Example #19
0
static void save_screenshot(const char *filename) {
	if ( TCOD_ctx.renderer == TCOD_RENDERER_SDL ) {
		/* This would be a lot easier if image saving could do textures. */
	    SDL_Rect rect;
		SDL_RenderGetViewport(renderer, &rect);
		Uint32 format = SDL_GetWindowPixelFormat(window);
		SDL_Texture *texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_TARGET, rect.w, rect.h);
		if (0 != texture) {
			if (SDL_SetRenderTarget(renderer, texture)) {
				void *pixels;
				int pitch, access;

				actual_rendering();
				SDL_SetRenderTarget(renderer, NULL);

				rect.x = rect.y = rect.w = rect.h = 0;
				if (-1 != SDL_QueryTexture(texture, &format, &access, &rect.w, &rect.h) &&
						-1 != SDL_LockTexture(texture, NULL, &pixels, &pitch)) {
					int depth;
					Uint32 rmask, gmask, bmask, amask;
					if (SDL_TRUE == SDL_PixelFormatEnumToMasks(format, &depth, &rmask, &gmask, &bmask, &amask)) {
						SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(pixels, rect.w, rect.h, depth, pitch, rmask, gmask, bmask, amask);
						TCOD_sys_save_bitmap((void *)surface,filename);
						SDL_FreeSurface(surface);
					} else
						TCOD_LOG(("TCOD_sys_save_screenshot - failed call to SDL_PixelFormatEnumToMasks"));

					SDL_UnlockTexture(texture);
				} else
					TCOD_LOG(("TCOD_sys_save_screenshot - failed call to SDL_QueryTexture or SDL_LockTexture"));
			} else
				TCOD_LOG(("TCOD_sys_save_screenshot - failed call to SDL_SetRenderTarget"));
			SDL_DestroyTexture(texture);
		} else
			TCOD_LOG(("TCOD_sys_save_screenshot - failed call to SDL_CreateTexture"));
#ifndef NO_OPENGL		
	} else {
		SDL_Surface *screenshot=(SDL_Surface *)TCOD_opengl_get_screen();
		TCOD_sys_save_bitmap((void *)screenshot,filename);
		SDL_FreeSurface(screenshot);
#endif		
	}
}
SkinSurface* skin_surface_create_argb32_from(int w,
                                             int h,
                                             int pitch,
                                             uint32_t* pixels) {
    SDL_Surface* surface = SDL_CreateRGBSurfaceFrom(
            pixels,
            w,
            h,
            32,
            pitch,
            ARGB32_R_MASK,
            ARGB32_G_MASK,
            ARGB32_B_MASK,
            ARGB32_A_MASK);
    if (!surface) {
        D("Could not create ARGB32 %dx%d surface: %s", w, h, SDL_GetError());
        return NULL;
    }
    return _skin_surface_create(surface, NULL, w, h);
}
NativeImagePtr RGBA32Buffer::asNewNativeImage() const
{
    Uint32 rmask, gmask, bmask, amask;
    /* SDL interprets each pixel as a 32-bit number, so our masks must depend
    on the endianness (byte order) of the machine */
#if !PLATFORM(AMIGAOS4) && SDL_BYTEORDER == SDL_BIG_ENDIAN
    rmask = 0xff000000;
    gmask = 0x00ff0000;
    bmask = 0x0000ff00;
    amask = 0x000000ff;
#else
    rmask = 0x00ff0000;
    gmask = 0x0000ff00;
    bmask = 0x000000ff;
    amask = 0xff000000;
#endif
    return SDL_CreateRGBSurfaceFrom((void*)(const_cast<PixelData*>(m_bytes.data())), 
                                    width(), height(), 32, width() * sizeof(PixelData),
                                    rmask, gmask, bmask, amask);
}
void SDL_Surface_Image::PutImage(Image* img, Rect dstRegion, Rect srcRegion) {
	Size s = img->GetImageSize();
	const unsigned int* pixels = img->GetImage();
	SDL_Surface* tmp_surf = SDL_CreateRGBSurfaceFrom((void*)pixels,
        s.w,s.h,24,4*s.w,0x00ff0000,0x0000ff00,0x000000ff,0xff000000);
	
	SDL_Rect src_rect;
	src_rect.x = srcRegion.x;
	src_rect.y = srcRegion.y;
	src_rect.w = srcRegion.w;
	src_rect.h = srcRegion.h;
	
	SDL_Rect dst_rect;
	dst_rect.x = dstRegion.x;
	dst_rect.y = dstRegion.y;
	dst_rect.w = dstRegion.w;
	dst_rect.h = dstRegion.h;
	
	SDL_BlitSurface(tmp_surf, &src_rect, this->surf, &dst_rect);
}
int main(int argc, char **argv)
{
  dev_name = "/dev/video0";

   setpriority(PRIO_PROCESS, 0, -10);
  generate_YCbCr_to_RGB_lookup();

  open_device();
  init_device();

  atexit(SDL_Quit);
  if (SDL_Init(SDL_INIT_VIDEO) < 0)
      return 1;

  SDL_WM_SetCaption(filter_names[filter_no], NULL);


  buffer_sdl = (uint8_t*)malloc(WIDTH*HEIGHT*3);

  SDL_SetVideoMode(WIDTH, HEIGHT, 32, SDL_DOUBLEBUF|SDL_ASYNCBLIT|SDL_HWACCEL|SDL_HWSURFACE);

  data_sf = SDL_CreateRGBSurfaceFrom(buffer_sdl, WIDTH, HEIGHT,
                                     24, WIDTH * 3,
                                     mask32(0), mask32(1), mask32(2), 0);

  SDL_SetEventFilter(sdl_filter);

  start_capturing();
  mainloop();
  stop_capturing();

  uninit_device();
  close_device();

  SDL_FreeSurface(data_sf);
  free(buffer_sdl);

  exit(EXIT_SUCCESS);

  return 0;
}
Example #24
0
void Utilities::upload_2d_mipmap(const PixelFormatDescriptor& pfd, GLsizei w, GLsizei h, const void *data)
{
    GLenum internalFormat_gl, format_gl, type_gl;
    toOpenGL(pfd, internalFormat_gl, format_gl, type_gl);
    PushClientAttrib pca(GL_CLIENT_PIXEL_STORE_BIT);

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    GL_DEBUG(glTexImage2D)(GL_TEXTURE_2D, 0, internalFormat_gl, w, h, 0, format_gl, type_gl, data);
    
    if (w == 1 && h == 1) return;
    
    uint32_t alphaMask = pfd.getAlphaMask(),
        redMask = pfd.getRedMask(),
        greenMask = pfd.getGreenMask(),
        blueMask = pfd.getBlueMask();
    int bpp = pfd.getColourDepth().getDepth();
    
    SDL_Surface *surf = SDL_CreateRGBSurfaceFrom((void *)data, w, h, bpp, w * bpp / 8, redMask, greenMask, blueMask, alphaMask);
    SDL_assert(surf != nullptr);
    
    GLsizei newW = w;
    GLsizei newH = h;
    GLint level = 0;
    
    do {
        if (newW > 1) newW /= 2;
        if (newH > 1) newH /= 2;
        level++;
        
        SDL_Surface *newSurf = SDL_CreateRGBSurface(0, newW, newH, bpp, redMask, greenMask, blueMask, alphaMask);
        SDL_assert(newSurf != nullptr);
        
        /// @todo this is 'low-quality' and not thread-safe
        SDL_SoftStretch(surf, nullptr, newSurf, nullptr);
        
        GL_DEBUG(glTexImage2D)(GL_TEXTURE_2D, level, internalFormat_gl, newW, newH, 0, format_gl, type_gl, newSurf->pixels);
        SDL_FreeSurface(newSurf);
    } while (!(newW == 1 && newH == 1));
    
    SDL_FreeSurface(surf);
}
Example #25
0
int BEE::save_screenshot(std::string filename) { // Slow, use sparingly
	if (options->is_opengl) {
		unsigned char* pixels = new unsigned char[width*height*4]; // 4 bytes for RGBA
		glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);

		SDL_Surface* screenshot  = SDL_CreateRGBSurfaceFrom(pixels, width, height, 8*4, width*4, 0,0,0,0);
		SDL_SaveBMP(screenshot, filename.c_str());

		SDL_FreeSurface(screenshot);
		delete [] pixels;
	} else {
		SDL_Surface *screenshot = SDL_CreateRGBSurface(0, width, height, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
		SDL_RenderReadPixels(renderer, NULL, SDL_PIXELFORMAT_ARGB8888, screenshot->pixels, screenshot->pitch);

		SDL_SaveBMP(screenshot, filename.c_str());

		SDL_FreeSurface(screenshot);
	}

	return 0;
}
Example #26
0
/**
 * Sets up a blank 8bpp surface with the specified size and position,
 * with pure black as the transparent color.
 * @note Surfaces don't have to fill the whole size since their
 * background is transparent, specially subclasses with their own
 * drawing logic, so it just covers the maximum drawing area.
 * @param width Width in pixels.
 * @param height Height in pixels.
 * @param x X position in pixels.
 * @param y Y position in pixels.
 * @param bpp Bits-per-pixel depth.
 */
Surface::Surface(int width, int height, int x, int y, int bpp) : _x(x), _y(y), _visible(true), _hidden(false), _redraw(false), _tftdMode(false), _alignedBuffer(0)
{
	_alignedBuffer = NewAligned(bpp, width, height);
	_surface = SDL_CreateRGBSurfaceFrom(_alignedBuffer, width, height, bpp, GetPitch(bpp, width), 0, 0, 0, 0);

	if (_surface == 0)
	{
		throw Exception(SDL_GetError());
	}

	SDL_SetColorKey(_surface, SDL_SRCCOLORKEY, 0);

	_crop.w = 0;
	_crop.h = 0;
	_crop.x = 0;
	_crop.y = 0;
	_clear.x = 0;
	_clear.y = 0;
	_clear.w = getWidth();
	_clear.h = getHeight();
}
Example #27
0
static int VID_SetWindowIcon(SDL_Window *sdl_window)
{
#ifdef __APPLE__
	// on OS X the icon is handled by the app bundle
	// it actually is higher resolution than the one here.
	return 0;
#else
	SDL_Surface *icon_surface;
        icon_surface = SDL_CreateRGBSurfaceFrom((void *)ezquake_icon.pixel_data, ezquake_icon.width, ezquake_icon.height, ezquake_icon.bytes_per_pixel * 8,
                ezquake_icon.width * ezquake_icon.bytes_per_pixel,
                0x000000FF,0x0000FF00,0x00FF0000,0xFF000000);

        if (icon_surface) {
            SDL_SetWindowIcon(sdl_window, icon_surface);
            SDL_FreeSurface(icon_surface);
	    return 0;
        }

	return -1;
#endif
}
Example #28
0
void vgainit(void)
{
	SDL_Surface *tmp = NULL;
	
	tmp = SDL_CreateRGBSurfaceFrom(Icon, 64, 64, 8, 64, 0, 0, 0, 0);
	SDL_SetColorKey(tmp, SDL_SRCCOLORKEY, 247); 			

	tmp->format->palette->colors = IconPalette;
	
	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
		fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
		exit(1);
	}
	SDL_WM_SetCaption("D I G G E R", NULL);
	SDL_WM_SetIcon(tmp, NULL);
	if(setmode() == false) {
		fprintf(stderr, "Couldn't set 640x480x8 video mode: %s\n", SDL_GetError());
		exit(1);
        }
	SDL_ShowCursor(0);
}
Example #29
-1
void SetSDLIcon(SDL_Window* window) {
	SDL_Surface* surface = SDL_CreateRGBSurfaceFrom(
	                           (void*)gimp_image.pixel_data,
	                           gimp_image.width,
	                           gimp_image.height,
	                           gimp_image.bytes_per_pixel * 8,
	                           gimp_image.bytes_per_pixel * gimp_image.width,
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
	                           0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF
#else
	                           0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000
#endif
	                       );
	SDL_SetWindowIcon(window, surface);
	SDL_FreeSurface(surface);

}
//! presents a surface in the client area
void CIrrDeviceSDL::present(video::IImage* surface, s32 windowId, core::rect<s32>* src)
{
	SDL_Rect srcClip;
	SDL_Surface *sdlSurface = SDL_CreateRGBSurfaceFrom (surface->lock(), surface->getDimension().Width, surface->getDimension().Height, surface->getBitsPerPixel(), surface->getPitch(), surface->getRedMask(), surface->getGreenMask(), surface->getBlueMask(), 0);
	if (src)
	{
		srcClip.x = src->UpperLeftCorner.X;
		srcClip.y = src->UpperLeftCorner.Y;
		srcClip.w = src->getWidth();
		srcClip.h = src->getHeight();
		SDL_BlitSurface(sdlSurface, &srcClip, Screen, NULL);
	}
	else
		SDL_BlitSurface(sdlSurface, NULL, Screen, NULL);
	SDL_UpdateRect(Screen, 0, 0, surface->getDimension().Width, surface->getDimension().Height);
	SDL_FreeSurface(sdlSurface);
	surface->unlock();
}