Removed custom blit_surface function
Unused now. And we wanted to get rid of it anyway.
This commit is contained in:
parent
c198be1fa8
commit
c453a97dac
2 changed files with 0 additions and 171 deletions
|
@ -2119,156 +2119,6 @@ surface create_compatible_surface(const surface &surf, int width, int height)
|
|||
return s;
|
||||
}
|
||||
|
||||
void blit_surface(const surface& surf,
|
||||
const SDL_Rect* srcrect, surface& dst, const SDL_Rect* dstrect)
|
||||
{
|
||||
assert(surf);
|
||||
assert(dst);
|
||||
assert(is_neutral(dst));
|
||||
|
||||
const surface& src = is_neutral(surf) ? surf : make_neutral_surface(surf);
|
||||
|
||||
// Get the areas to blit
|
||||
SDL_Rect dst_rect {0, 0, dst->w, dst->h};
|
||||
if(dstrect) {
|
||||
dst_rect.x = dstrect->x;
|
||||
dst_rect.w -= dstrect->x;
|
||||
|
||||
dst_rect.y = dstrect->y;
|
||||
dst_rect.h -= dstrect->y;
|
||||
|
||||
}
|
||||
|
||||
SDL_Rect src_rect {0, 0, src->w, src->h};
|
||||
if(srcrect && srcrect->w && srcrect->h) {
|
||||
src_rect.x = srcrect->x;
|
||||
src_rect.y = srcrect->y;
|
||||
|
||||
src_rect.w = srcrect->w;
|
||||
src_rect.h = srcrect->h;
|
||||
|
||||
if (src_rect.x < 0) {
|
||||
if (src_rect.x + src_rect.w <= 0 || src_rect.x + dst_rect.w <= 0 )
|
||||
return;
|
||||
dst_rect.x -= src_rect.x;
|
||||
dst_rect.w += src_rect.x;
|
||||
src_rect.w += src_rect.x;
|
||||
src_rect.x = 0;
|
||||
}
|
||||
if (src_rect.y < 0) {
|
||||
if (src_rect.y + src_rect.h <= 0 || src_rect.y + dst_rect.h <= 0 )
|
||||
return;
|
||||
dst_rect.y -= src_rect.y;
|
||||
dst_rect.h += src_rect.y;
|
||||
src_rect.h += src_rect.y;
|
||||
src_rect.y = 0;
|
||||
}
|
||||
if (src_rect.x + src_rect.w > src->w) {
|
||||
if (src_rect.x >= src->w)
|
||||
return;
|
||||
src_rect.w = src->w - src_rect.x;
|
||||
}
|
||||
if (src_rect.y + src_rect.h > src->h) {
|
||||
if (src_rect.y >= src->h)
|
||||
return;
|
||||
src_rect.h = src->h - src_rect.y;
|
||||
}
|
||||
}
|
||||
|
||||
assert(dst_rect.x >= 0);
|
||||
assert(dst_rect.y >= 0);
|
||||
|
||||
// Get the blit size limits.
|
||||
const unsigned width = std::min(src_rect.w, dst_rect.w);
|
||||
const unsigned height = std::min(src_rect.h, dst_rect.h);
|
||||
|
||||
{
|
||||
// Extra scoping used for the surface_lock.
|
||||
const_surface_lock src_lock(src);
|
||||
surface_lock dst_lock(dst);
|
||||
|
||||
const uint32_t* const src_pixels = src_lock.pixels();
|
||||
uint32_t* dst_pixels = dst_lock.pixels();
|
||||
|
||||
for(unsigned y = 0; y < height; ++y) {
|
||||
for(unsigned x = 0; x < width; ++x) {
|
||||
|
||||
// We need to do the blitting using some optimizations
|
||||
// if the src is fully transparent we can ignore this pixel
|
||||
// if the src is fully opaque we can overwrite the destination with this pixel
|
||||
// if the destination is fully transparent we replace us with the source
|
||||
//
|
||||
// We do these optimizations between the extraction of the variables
|
||||
// to avoid creating variables not used (it might save us some cycles).
|
||||
|
||||
const int src_offset = (y + src_rect.y) * src->w + (x + src_rect.x);
|
||||
assert(src_offset < src->w * src->h);
|
||||
const uint32_t src_pixel = src_pixels[src_offset];
|
||||
const uint8_t src_a = (src_pixel & 0xFF000000) >> 24;
|
||||
|
||||
if(!src_a) {
|
||||
// Fully transparent source, ignore
|
||||
continue;
|
||||
}
|
||||
|
||||
const ptrdiff_t dst_offset = (y + dst_rect.y) * dst->w + (x + dst_rect.x);
|
||||
assert(dst_offset < dst->w * dst->h);
|
||||
if(src_a == 255) {
|
||||
// Fully opaque source, copy
|
||||
dst_pixels[dst_offset] = src_pixel;
|
||||
continue;
|
||||
}
|
||||
|
||||
const uint32_t dst_pixel = dst_pixels[dst_offset];
|
||||
uint8_t dst_a = (dst_pixel & 0xFF000000) >> 24;
|
||||
|
||||
if(!dst_a) {
|
||||
// Fully transparent destination, copy
|
||||
dst_pixels[dst_offset] = src_pixel;
|
||||
continue;
|
||||
}
|
||||
|
||||
const uint8_t src_r = (src_pixel & 0x00FF0000) >> 16;
|
||||
const uint8_t src_g = (src_pixel & 0x0000FF00) >> 8;
|
||||
const uint8_t src_b = src_pixel & 0x000000FF;
|
||||
|
||||
uint8_t dst_r = (dst_pixel & 0x00FF0000) >> 16;
|
||||
uint8_t dst_g = (dst_pixel & 0x0000FF00) >> 8;
|
||||
uint8_t dst_b = dst_pixel & 0x000000FF;
|
||||
|
||||
if(dst_a == 255) {
|
||||
|
||||
// Destination fully opaque blend the source.
|
||||
dst_r = (((src_r - dst_r) * src_a) >> 8 ) + dst_r;
|
||||
dst_g = (((src_g - dst_g) * src_a) >> 8 ) + dst_g;
|
||||
dst_b = (((src_b - dst_b) * src_a) >> 8 ) + dst_b;
|
||||
|
||||
} else {
|
||||
|
||||
// Destination and source party transparent.
|
||||
|
||||
// acquired the data now do the blitting
|
||||
const unsigned tmp_a = 255 - src_a;
|
||||
|
||||
const unsigned tmp_r = 1 + (src_r * src_a) + (dst_r * tmp_a);
|
||||
dst_r = (tmp_r + (tmp_r >> 8)) >> 8;
|
||||
|
||||
const unsigned tmp_g = 1 + (src_g * src_a) + (dst_g * tmp_a);
|
||||
dst_g = (tmp_g + (tmp_g >> 8)) >> 8;
|
||||
|
||||
const unsigned tmp_b = 1 + (src_b * src_a) + (dst_b * tmp_a);
|
||||
dst_b = (tmp_b + (tmp_b >> 8)) >> 8;
|
||||
|
||||
dst_a += (((255 - dst_a) * src_a) >> 8);
|
||||
}
|
||||
|
||||
dst_pixels[dst_offset] = (dst_a << 24) | (dst_r << 16) | (dst_g << 8) | (dst_b);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
surface get_surface_portion(const surface &src, SDL_Rect &area)
|
||||
{
|
||||
if (src == nullptr) {
|
||||
|
|
|
@ -302,27 +302,6 @@ surface flip_surface(const surface &surf);
|
|||
surface flop_surface(const surface &surf);
|
||||
surface create_compatible_surface(const surface &surf, int width = -1, int height = -1);
|
||||
|
||||
/**
|
||||
* Replacement for sdl_blit.
|
||||
*
|
||||
* sdl_blit has problems with blitting partly transparent surfaces so
|
||||
* this is a replacement. It ignores the SDL_SRCALPHA and SDL_SRCCOLORKEY
|
||||
* flags. src and dst will have the SDL_RLEACCEL flag removed.
|
||||
* The return value of SDL_BlistSurface is normally ignored so no return value.
|
||||
* The rectangles are const and will not be modified.
|
||||
*
|
||||
* @pre @p src contains a valid canvas.
|
||||
* @pre @p dst contains a valid neutral canvas.
|
||||
* @pre The caller must make sure the @p src fits on the @p dst.
|
||||
*
|
||||
* @param src The surface to blit.
|
||||
* @param srcrect The region of the surface to blit
|
||||
* @param dst The surface to blit on.
|
||||
* @param dstrect The offset to blit the surface on, only x and y are used.
|
||||
*/
|
||||
void blit_surface(const surface& src,
|
||||
const SDL_Rect* srcrect, surface& dst, const SDL_Rect* dstrect);
|
||||
|
||||
SDL_Rect get_non_transparent_portion(const surface &surf);
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue