本文整理汇总了C++中SDL_CreateRGBSurfaceFrom函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_CreateRGBSurfaceFrom函数的具体用法?C++ SDL_CreateRGBSurfaceFrom怎么用?C++ SDL_CreateRGBSurfaceFrom使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_CreateRGBSurfaceFrom函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: copytoscreen
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);
}
示例2: create_cam_img
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);
}
示例3: create_surface_from_data
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;
}
示例4: getPixelFormatSize
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;
}
示例5: assert
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);
}
示例6: videodev_start
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;
}
示例7: _freeSprites
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;
}
示例8: SDL_CreateRGBSurfaceFrom
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);
}
示例9: SetSDLIcon
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);
}
示例10: SDL_CreateRGBSurfaceFrom
//! 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();
}
示例11: draw_pdf
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);
}
示例12: sdl_srcalpha
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 );
};
示例13: TexturePrivate
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);
}
示例14: SDL_CreateRGBSurfaceFrom
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;
}
示例15: create_surface_from_data
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;
}