本文整理汇总了C++中SDL_InvalidateMap函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_InvalidateMap函数的具体用法?C++ SDL_InvalidateMap怎么用?C++ SDL_InvalidateMap使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_InvalidateMap函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SDL_LowerBlitScaled
/**
* This is a semi-private blit function and it performs low-level surface
* scaled blitting only.
*/
int
SDL_LowerBlitScaled(SDL_Surface * src, SDL_Rect * srcrect,
SDL_Surface * dst, SDL_Rect * dstrect)
{
static const Uint32 complex_copy_flags = (
SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA |
SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD |
SDL_COPY_COLORKEY
);
/* Save off the original dst width, height */
int dstW = dstrect->w;
int dstH = dstrect->h;
SDL_Rect full_rect;
SDL_Rect final_dst = *dstrect;
SDL_Rect final_src = *srcrect;
/* Clip the dst surface to the dstrect */
full_rect.x = 0;
full_rect.y = 0;
full_rect.w = dst->w;
full_rect.h = dst->h;
if (!SDL_IntersectRect(&final_dst, &full_rect, &final_dst)) {
return 0;
}
/* Did the dst width change? */
if ( dstW != final_dst.w ) {
/* scale the src width appropriately */
final_src.w = final_src.w * dst->clip_rect.w / dstW;
}
/* Did the dst height change? */
if ( dstH != final_dst.h ) {
/* scale the src width appropriately */
final_src.h = final_src.h * dst->clip_rect.h / dstH;
}
/* Clip the src surface to the srcrect */
full_rect.x = 0;
full_rect.y = 0;
full_rect.w = src->w;
full_rect.h = src->h;
if (!SDL_IntersectRect(&final_src, &full_rect, &final_src)) {
return 0;
}
if (!(src->map->info.flags & SDL_COPY_NEAREST)) {
src->map->info.flags |= SDL_COPY_NEAREST;
SDL_InvalidateMap(src->map);
}
if ( !(src->map->info.flags & complex_copy_flags) &&
src->format->format == dst->format->format &&
!SDL_ISPIXELFORMAT_INDEXED(src->format->format) ) {
return SDL_SoftStretch( src, &final_src, dst, &final_dst );
} else {
return SDL_LowerBlit( src, &final_src, dst, &final_dst );
}
}
示例2: SDL_FreeSurface
/*
* Free a surface created by the above function.
*/
void
SDL_FreeSurface(SDL_Surface * surface)
{
if (surface == NULL) {
return;
}
if (surface->flags & SDL_DONTFREE) {
return;
}
SDL_InvalidateMap(surface->map);
if (--surface->refcount > 0) {
return;
}
while (surface->locked > 0) {
SDL_UnlockSurface(surface);
}
if (surface->flags & SDL_RLEACCEL) {
SDL_UnRLESurface(surface, 0);
}
if (surface->format) {
SDL_SetSurfacePalette(surface, NULL);
SDL_FreeFormat(surface->format);
surface->format = NULL;
}
if (!(surface->flags & SDL_PREALLOC)) {
SDL_free(surface->pixels);
}
if (surface->map) {
SDL_FreeBlitMap(surface->map);
}
SDL_free(surface);
}
示例3: SDL_SetColorKey
int
SDL_SetColorKey(SDL_Surface * surface, int flag, Uint32 key)
{
int flags;
if (!surface) {
return -1;
}
if (flag & SDL_RLEACCEL) {
SDL_SetSurfaceRLE(surface, 1);
}
flags = surface->map->info.flags;
if (flag) {
surface->map->info.flags |= SDL_COPY_COLORKEY;
surface->map->info.colorkey = key;
} else {
surface->map->info.flags &= ~SDL_COPY_COLORKEY;
}
if (surface->map->info.flags != flags) {
SDL_InvalidateMap(surface->map);
}
return 0;
}
示例4: SDL_SetColorKey
/*
* Set the color key in a blittable surface
*/
int SDL_SetColorKey (SDL_Surface *surface, Uint32 flag, Uint32 key)
{
/* Sanity check the flag as it gets passed in */
if ( flag & SDL_SRCCOLORKEY ) {
if ( flag & (SDL_RLEACCEL|SDL_RLEACCELOK) ) {
flag = (SDL_SRCCOLORKEY | SDL_RLEACCELOK);
} else {
flag = SDL_SRCCOLORKEY;
}
} else {
flag = 0;
}
/* Optimize away operations that don't change anything */
if ( (flag == (surface->flags & (SDL_SRCCOLORKEY|SDL_RLEACCELOK))) &&
(key == surface->format->colorkey) ) {
return(0);
}
if ( flag ) {
surface->flags |= SDL_SRCCOLORKEY;
surface->format->colorkey = key;
if ( flag & SDL_RLEACCELOK ) {
surface->flags |= SDL_RLEACCELOK;
} else {
surface->flags &= ~SDL_RLEACCELOK;
}
} else {
surface->flags &= ~(SDL_SRCCOLORKEY|SDL_RLEACCELOK);
surface->format->colorkey = 0;
}
SDL_InvalidateMap(surface->map);
return(0);
}
示例5: SDL_SetAlpha
/* This function sets the alpha channel of a surface */
int SDL_SetAlpha (SDL_Surface *surface, Uint32 flag, Uint8 value)
{
Uint32 oldflags = surface->flags;
Uint32 oldalpha = surface->format->alpha;
/* Sanity check the flag as it gets passed in */
if ( flag & SDL_SRCALPHA ) {
if ( flag & (SDL_RLEACCEL|SDL_RLEACCELOK) ) {
flag = (SDL_SRCALPHA | SDL_RLEACCELOK);
} else {
flag = SDL_SRCALPHA;
}
} else {
flag = 0;
}
/* Optimize away operations that don't change anything */
if ( (flag == (surface->flags & (SDL_SRCALPHA|SDL_RLEACCELOK))) &&
(!flag || value == oldalpha) ) {
return(0);
}
if(!(flag & SDL_RLEACCELOK) && (surface->flags & SDL_RLEACCEL))
SDL_UnRLESurface(surface, 1);
if ( flag ) {
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
surface->flags |= SDL_SRCALPHA;
surface->format->alpha = value;
if ( (surface->flags & SDL_HWACCEL) == SDL_HWACCEL ) {
if ( (video->SetHWAlpha == NULL) ||
(video->SetHWAlpha(this, surface, value) < 0) ) {
surface->flags &= ~SDL_HWACCEL;
}
}
if ( flag & SDL_RLEACCELOK ) {
surface->flags |= SDL_RLEACCELOK;
} else {
surface->flags &= ~SDL_RLEACCELOK;
}
} else {
surface->flags &= ~SDL_SRCALPHA;
surface->format->alpha = SDL_ALPHA_OPAQUE;
}
/*
* The representation for software surfaces is independent of
* per-surface alpha, so no need to invalidate the blit mapping
* if just the alpha value was changed. (If either is 255, we still
* need to invalidate.)
*/
if((surface->flags & SDL_HWACCEL) == SDL_HWACCEL
|| oldflags != surface->flags
|| (((oldalpha + 1) ^ (value + 1)) & 0x100))
SDL_InvalidateMap(surface->map);
return(0);
}
示例6: SDL_SetSurfacePalette
int
SDL_SetSurfacePalette(SDL_Surface * surface, SDL_Palette * palette)
{
if (!surface) {
return SDL_SetError("SDL_SetSurfacePalette() passed a NULL surface");
}
if (SDL_SetPixelFormatPalette(surface->format, palette) < 0) {
return -1;
}
SDL_InvalidateMap(surface->map);
return 0;
}
示例7: SDL_SetColorKey
/*
* Set the color key in a blittable surface
*/
int SDL_SetColorKey (SDL_Surface *surface, Uint32 flag, Uint32 key)
{
/* Sanity check the flag as it gets passed in */
if ( flag & SDL_SRCCOLORKEY ) {
if ( flag & (SDL_RLEACCEL|SDL_RLEACCELOK) ) {
flag = (SDL_SRCCOLORKEY | SDL_RLEACCELOK);
} else {
flag = SDL_SRCCOLORKEY;
}
} else {
flag = 0;
}
/* Optimize away operations that don't change anything */
if ( (flag == (surface->flags & (SDL_SRCCOLORKEY|SDL_RLEACCELOK))) &&
(key == surface->format->colorkey) ) {
return(0);
}
/* UnRLE surfaces before we change the colorkey */
if ( surface->flags & SDL_RLEACCEL ) {
SDL_UnRLESurface(surface, 1);
}
if ( flag ) {
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
surface->flags |= SDL_SRCCOLORKEY;
surface->format->colorkey = key;
if ( (surface->flags & SDL_HWACCEL) == SDL_HWACCEL ) {
if ( (video->SetHWColorKey == NULL) ||
(video->SetHWColorKey(this, surface, key) < 0) ) {
surface->flags &= ~SDL_HWACCEL;
}
}
if ( flag & SDL_RLEACCELOK ) {
surface->flags |= SDL_RLEACCELOK;
} else {
surface->flags &= ~SDL_RLEACCELOK;
}
} else {
surface->flags &= ~(SDL_SRCCOLORKEY|SDL_RLEACCELOK);
surface->format->colorkey = 0;
}
SDL_InvalidateMap(surface->map);
return(0);
}
示例8: SDL_SetColorKey
int
SDL_SetColorKey(SDL_Surface * surface, int flag, Uint32 key)
{
int flags;
if (!surface) {
return SDL_InvalidParamError("surface");
}
if (surface->format->palette && key >= ((Uint32) surface->format->palette->ncolors)) {
return SDL_InvalidParamError("key");
}
if (flag & SDL_RLEACCEL) {
SDL_SetSurfaceRLE(surface, 1);
}
flags = surface->map->info.flags;
if (flag) {
surface->map->info.flags |= SDL_COPY_COLORKEY;
surface->map->info.colorkey = key;
if (surface->format->palette) {
surface->format->palette->colors[surface->map->info.colorkey].a = SDL_ALPHA_TRANSPARENT;
++surface->format->palette->version;
if (!surface->format->palette->version) {
surface->format->palette->version = 1;
}
}
} else {
if (surface->format->palette) {
surface->format->palette->colors[surface->map->info.colorkey].a = SDL_ALPHA_OPAQUE;
++surface->format->palette->version;
if (!surface->format->palette->version) {
surface->format->palette->version = 1;
}
}
surface->map->info.flags &= ~SDL_COPY_COLORKEY;
}
if (surface->map->info.flags != flags) {
SDL_InvalidateMap(surface->map);
}
return 0;
}
示例9: SDL_SetSurfaceRLE
int
SDL_SetSurfaceRLE(SDL_Surface * surface, int flag)
{
int flags;
if (!surface) {
return -1;
}
flags = surface->map->info.flags;
if (flag) {
surface->map->info.flags |= SDL_COPY_RLE_DESIRED;
} else {
surface->map->info.flags &= ~SDL_COPY_RLE_DESIRED;
}
if (surface->map->info.flags != flags) {
SDL_InvalidateMap(surface->map);
}
return 0;
}
示例10: SDL_SetSurfaceAlphaMod
int
SDL_SetSurfaceAlphaMod(SDL_Surface * surface, Uint8 alpha)
{
int flags;
if (!surface) {
return -1;
}
surface->map->info.a = alpha;
flags = surface->map->info.flags;
if (alpha != 0xFF) {
surface->map->info.flags |= SDL_COPY_MODULATE_ALPHA;
} else {
surface->map->info.flags &= ~SDL_COPY_MODULATE_ALPHA;
}
if (surface->map->info.flags != flags) {
SDL_InvalidateMap(surface->map);
}
return 0;
}
示例11: SDL_LowerBlitScaled
/**
* This is a semi-private blit function and it performs low-level surface
* scaled blitting only.
*/
int
SDL_LowerBlitScaled(SDL_Surface * src, SDL_Rect * srcrect,
SDL_Surface * dst, SDL_Rect * dstrect)
{
static const Uint32 complex_copy_flags = (
SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA |
SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD |
SDL_COPY_COLORKEY
);
if (!(src->map->info.flags & SDL_COPY_NEAREST)) {
src->map->info.flags |= SDL_COPY_NEAREST;
SDL_InvalidateMap(src->map);
}
if ( !(src->map->info.flags & complex_copy_flags) &&
src->format->format == dst->format->format &&
!SDL_ISPIXELFORMAT_INDEXED(src->format->format) ) {
return SDL_SoftStretch( src, srcrect, dst, dstrect );
} else {
return SDL_LowerBlit( src, srcrect, dst, dstrect );
}
}
示例12: SDL_SetSurfaceBlendMode
int
SDL_SetSurfaceBlendMode(SDL_Surface * surface, SDL_BlendMode blendMode)
{
int flags, status;
if (!surface) {
return -1;
}
status = 0;
flags = surface->map->info.flags;
surface->map->info.flags &=
~(SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD);
switch (blendMode) {
case SDL_BLENDMODE_NONE:
break;
case SDL_BLENDMODE_BLEND:
surface->map->info.flags |= SDL_COPY_BLEND;
break;
case SDL_BLENDMODE_ADD:
surface->map->info.flags |= SDL_COPY_ADD;
break;
case SDL_BLENDMODE_MOD:
surface->map->info.flags |= SDL_COPY_MOD;
break;
default:
SDL_Unsupported();
status = -1;
break;
}
if (surface->map->info.flags != flags) {
SDL_InvalidateMap(surface->map);
}
return status;
}
示例13: SDL_SetSurfaceColorMod
int
SDL_SetSurfaceColorMod(SDL_Surface * surface, Uint8 r, Uint8 g, Uint8 b)
{
int flags;
if (!surface) {
return -1;
}
surface->map->info.r = r;
surface->map->info.g = g;
surface->map->info.b = b;
flags = surface->map->info.flags;
if (r != 0xFF || g != 0xFF || b != 0xFF) {
surface->map->info.flags |= SDL_COPY_MODULATE_COLOR;
} else {
surface->map->info.flags &= ~SDL_COPY_MODULATE_COLOR;
}
if (surface->map->info.flags != flags) {
SDL_InvalidateMap(surface->map);
}
return 0;
}
示例14: SDL_CalculateBlit
//.........这里部分代码省略.........
}
} else {
/* We only support accelerated blitting to hardware */
if ( surface->map->dst->flags & SDL_HWSURFACE ) {
hw_blit_ok = current_video->info.blit_sw;
} else {
hw_blit_ok = 0;
}
if (hw_blit_ok && (surface->flags & SDL_SRCCOLORKEY)) {
hw_blit_ok = current_video->info.blit_sw_CC;
}
if ( hw_blit_ok && (surface->flags & SDL_SRCALPHA) ) {
hw_blit_ok = current_video->info.blit_sw_A;
}
}
if ( hw_blit_ok ) {
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
video->CheckHWBlit(this, surface, surface->map->dst);
}
}
/* if an alpha pixel format is specified, we can accelerate alpha blits */
if (((surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE )&&(current_video->displayformatalphapixel))
{
if ( (surface->flags & SDL_SRCALPHA) )
if ( current_video->info.blit_hw_A ) {
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
video->CheckHWBlit(this, surface, surface->map->dst);
}
}
/* Get the blit function index, based on surface mode */
/* { 0 = nothing, 1 = colorkey, 2 = alpha, 3 = colorkey+alpha } */
blit_index = 0;
blit_index |= (!!(surface->flags & SDL_SRCCOLORKEY)) << 0;
if ( surface->flags & SDL_SRCALPHA
&& (surface->format->alpha != SDL_ALPHA_OPAQUE
|| surface->format->Amask) ) {
blit_index |= 2;
}
/* Check for special "identity" case -- copy blit */
if ( surface->map->identity && blit_index == 0 ) {
surface->map->sw_data->blit = SDL_BlitCopy;
/* Handle overlapping blits on the same surface */
if ( surface == surface->map->dst ) {
surface->map->sw_data->blit = SDL_BlitCopyOverlap;
}
} else {
if ( surface->format->BitsPerPixel < 8 ) {
surface->map->sw_data->blit =
SDL_CalculateBlit0(surface, blit_index);
} else {
switch ( surface->format->BytesPerPixel ) {
case 1:
surface->map->sw_data->blit =
SDL_CalculateBlit1(surface, blit_index);
break;
case 2:
case 3:
case 4:
surface->map->sw_data->blit =
SDL_CalculateBlitN(surface, blit_index);
break;
default:
surface->map->sw_data->blit = NULL;
break;
}
}
}
/* Make sure we have a blit function */
if ( surface->map->sw_data->blit == NULL ) {
SDL_InvalidateMap(surface->map);
SDL_SetError("Blit combination not supported");
return(-1);
}
/* Choose software blitting function */
if(surface->flags & SDL_RLEACCELOK
&& (surface->flags & SDL_HWACCEL) != SDL_HWACCEL) {
if(surface->map->identity
&& (blit_index == 1
|| (blit_index == 3 && !surface->format->Amask))) {
if ( SDL_RLESurface(surface) == 0 )
surface->map->sw_blit = SDL_RLEBlit;
} else if(blit_index == 2 && surface->format->Amask) {
if ( SDL_RLESurface(surface) == 0 )
surface->map->sw_blit = SDL_RLEAlphaBlit;
}
}
if ( surface->map->sw_blit == NULL ) {
surface->map->sw_blit = SDL_SoftBlit;
}
return(0);
}
示例15: SDL_ConvertSurface
/*
* Convert a surface into the specified pixel format.
*/
SDL_Surface *
SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format,
Uint32 flags)
{
SDL_Surface *convert;
Uint32 copy_flags;
SDL_Color copy_color;
SDL_Rect bounds;
/* Check for empty destination palette! (results in empty image) */
if (format->palette != NULL) {
int i;
for (i = 0; i < format->palette->ncolors; ++i) {
if ((format->palette->colors[i].r != 0xFF) ||
(format->palette->colors[i].g != 0xFF) ||
(format->palette->colors[i].b != 0xFF))
break;
}
if (i == format->palette->ncolors) {
SDL_SetError("Empty destination palette");
return (NULL);
}
}
/* Create a new surface with the desired format */
convert = SDL_CreateRGBSurface(flags, surface->w, surface->h,
format->BitsPerPixel, format->Rmask,
format->Gmask, format->Bmask,
format->Amask);
if (convert == NULL) {
return (NULL);
}
/* Copy the palette if any */
if (format->palette && convert->format->palette) {
SDL_memcpy(convert->format->palette->colors,
format->palette->colors,
format->palette->ncolors * sizeof(SDL_Color));
convert->format->palette->ncolors = format->palette->ncolors;
}
/* Save the original copy flags */
copy_flags = surface->map->info.flags;
copy_color.r = surface->map->info.r;
copy_color.g = surface->map->info.g;
copy_color.b = surface->map->info.b;
copy_color.a = surface->map->info.a;
surface->map->info.r = 0xFF;
surface->map->info.g = 0xFF;
surface->map->info.b = 0xFF;
surface->map->info.a = 0xFF;
surface->map->info.flags = 0;
SDL_InvalidateMap(surface->map);
/* Copy over the image data */
bounds.x = 0;
bounds.y = 0;
bounds.w = surface->w;
bounds.h = surface->h;
SDL_LowerBlit(surface, &bounds, convert, &bounds);
/* Clean up the original surface, and update converted surface */
convert->map->info.r = copy_color.r;
convert->map->info.g = copy_color.g;
convert->map->info.b = copy_color.b;
convert->map->info.a = copy_color.a;
convert->map->info.flags =
(copy_flags &
~(SDL_COPY_COLORKEY | SDL_COPY_BLEND
| SDL_COPY_RLE_DESIRED | SDL_COPY_RLE_COLORKEY |
SDL_COPY_RLE_ALPHAKEY));
surface->map->info.r = copy_color.r;
surface->map->info.g = copy_color.g;
surface->map->info.b = copy_color.b;
surface->map->info.a = copy_color.a;
surface->map->info.flags = copy_flags;
SDL_InvalidateMap(surface->map);
if (copy_flags & SDL_COPY_COLORKEY) {
SDL_bool set_colorkey_by_color = SDL_FALSE;
if (surface->format->palette) {
if (format->palette &&
surface->format->palette->ncolors <= format->palette->ncolors &&
(SDL_memcmp(surface->format->palette->colors, format->palette->colors,
surface->format->palette->ncolors * sizeof(SDL_Color)) == 0)) {
/* The palette is identical, just set the same colorkey */
SDL_SetColorKey(convert, 1, surface->map->info.colorkey);
} else if (format->Amask) {
/* The alpha was set in the destination from the palette */
} else {
set_colorkey_by_color = SDL_TRUE;
}
} else {
set_colorkey_by_color = SDL_TRUE;
}
if (set_colorkey_by_color) {
//.........这里部分代码省略.........