Fixed a bug where alpha disappeared from multi-hex .png files...
...on loading sub-tiles. (code) Added a cut_surface function in sdl_utils, that extracts a surface "subset" from another surface.
This commit is contained in:
parent
1db4441e65
commit
00688b0452
3 changed files with 30 additions and 6 deletions
|
@ -145,13 +145,8 @@ SDL_Surface * load_image_sub_file(image::locator i_locator)
|
|||
if(mask == NULL)
|
||||
return NULL;
|
||||
|
||||
tmp = SDL_CreateRGBSurface(SDL_SWSURFACE, 72, 72, mother_surface->format->BitsPerPixel, mother_surface->format->Rmask,
|
||||
mother_surface->format->Gmask, mother_surface->format->Bmask, mother_surface->format->Amask);
|
||||
|
||||
SDL_Rect srcrect = { 54 * i_locator.loc.x, 72 * i_locator.loc.y + 36 * (i_locator.loc.x % 2), 72, 72 };
|
||||
SDL_Rect destrect = { 0, 0, 72, 72 };
|
||||
SDL_BlitSurface(mother_surface, &srcrect, tmp, &destrect);
|
||||
|
||||
tmp = cut_surface(mother_surface, srcrect);
|
||||
surf = mask_surface(tmp, mask);
|
||||
|
||||
SDL_FreeSurface(tmp);
|
||||
|
|
|
@ -424,6 +424,34 @@ SDL_Surface* mask_surface(SDL_Surface* surface, SDL_Surface* mask)
|
|||
return clone_surface(surf);
|
||||
}
|
||||
|
||||
// Cuts a rectangle from a surface.
|
||||
SDL_Surface* cut_surface(SDL_Surface *surface, const SDL_Rect& r)
|
||||
{
|
||||
SDL_Surface* res = create_compatible_surface(surface, r.w, r.h);
|
||||
|
||||
size_t sbpp = surface->format->BytesPerPixel;
|
||||
size_t spitch = surface->pitch;
|
||||
size_t rbpp = res->format->BytesPerPixel;
|
||||
size_t rpitch = res->pitch;
|
||||
|
||||
surface_lock slock(surface);
|
||||
surface_lock rlock(res);
|
||||
|
||||
Uint8* src = reinterpret_cast<Uint8 *>(slock.pixels());
|
||||
Uint8* dest = reinterpret_cast<Uint8 *>(rlock.pixels());
|
||||
|
||||
for(int y = 0; y < r.h && (r.y + y) < surface->h; ++y) {
|
||||
Uint8* line_src = src + (r.y + y) * spitch + r.x * sbpp;
|
||||
Uint8* line_dest = dest + y * rpitch;
|
||||
size_t size = r.w + r.x <= surface->w ? r.w : surface->w - r.x;
|
||||
|
||||
assert(rpitch >= r.w * rbpp);
|
||||
memcpy(line_dest, line_src, size * rbpp);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
SDL_Surface* blend_surface(SDL_Surface* surface, double amount, Uint32 colour)
|
||||
{
|
||||
if(surface == NULL) {
|
||||
|
|
|
@ -56,6 +56,7 @@ SDL_Surface* get_surface_portion(SDL_Surface* src, SDL_Rect& rect);
|
|||
SDL_Surface* adjust_surface_alpha(SDL_Surface* surface, double amount);
|
||||
SDL_Surface* adjust_surface_alpha_add(SDL_Surface* surface, int amount);
|
||||
SDL_Surface* mask_surface(SDL_Surface* surface, SDL_Surface* mask);
|
||||
SDL_Surface* cut_surface(SDL_Surface* surface, const SDL_Rect& r);
|
||||
SDL_Surface* blend_surface(SDL_Surface* surface, double amount, Uint32 colour);
|
||||
SDL_Surface* flip_surface(SDL_Surface* surface);
|
||||
SDL_Surface* flop_surface(SDL_Surface* surface);
|
||||
|
|
Loading…
Add table
Reference in a new issue