Stop calling adjust_surface_alpha() with SDL_ALPHA_OPAQUE
The function doesn't do anything if that value is passed, except if adjust_surface_alpha() has been called for the same surface before with a different value. The only case that remains is floating_label.cpp line 123, since in that case the alpha *is* changed few lines earlier.
This commit is contained in:
parent
ee79eb426e
commit
09d9054e4a
11 changed files with 85 additions and 263 deletions
|
@ -430,9 +430,6 @@ void battle_prediction_pane::get_hp_distrib_surface(const std::vector<std::pair<
|
|||
// Create the surface.
|
||||
surf = create_neutral_surface(width, height);
|
||||
|
||||
// Disable alpha channel to avoid problem with sdl_blit
|
||||
adjust_surface_alpha(surf, SDL_ALPHA_OPAQUE);
|
||||
|
||||
SDL_Rect clip_rect = sdl::create_rect(0, 0, width, height);
|
||||
Uint32 grey_color = SDL_MapRGBA(surf->format, 0xb7, 0xc1, 0xc1, SDL_ALPHA_OPAQUE);
|
||||
|
||||
|
|
|
@ -1605,18 +1605,18 @@ void display::render_image(int x, int y, const display::drawing_layer drawing_la
|
|||
surf = image::reverse_image(surf);
|
||||
}
|
||||
if(vreverse) {
|
||||
surf = flop_surface(surf, false);
|
||||
surf = flop_surface(surf);
|
||||
}
|
||||
|
||||
if(greyscale) {
|
||||
surf = greyscale_image(surf, false);
|
||||
surf = greyscale_image(surf);
|
||||
}
|
||||
|
||||
if(blend_ratio != 0) {
|
||||
surf = blend_surface(surf, blend_ratio, blendto, false);
|
||||
surf = blend_surface(surf, blend_ratio, blendto);
|
||||
}
|
||||
if(alpha > ftofxp(1.0)) {
|
||||
surf = brighten_image(surf, alpha, false);
|
||||
surf = brighten_image(surf, alpha);
|
||||
//} else if(alpha != 1.0 && blendto != 0) {
|
||||
// surf.assign(blend_surface(surf,1.0-alpha,blendto));
|
||||
} else if(alpha != ftofxp(1.0)) {
|
||||
|
@ -1642,7 +1642,7 @@ void display::render_image(int x, int y, const display::drawing_layer drawing_la
|
|||
float alpha_base = 0.3f; // 30% alpha at surface of water
|
||||
float alpha_delta = 0.015f; // lose 1.5% per pixel depth
|
||||
alpha_delta *= zoom_ / DefaultZoom; // adjust with zoom
|
||||
surf = submerge_alpha(surf, depth, alpha_base, alpha_delta, false);
|
||||
surf = submerge_alpha(surf, depth, alpha_base, alpha_delta);
|
||||
|
||||
srcrect.y = submerge_height;
|
||||
srcrect.h = surf->h-submerge_height;
|
||||
|
|
|
@ -249,11 +249,6 @@ void tristate_button::draw_contents() {
|
|||
sdl_blit(noverlay, nullptr, nbase, nullptr);
|
||||
}
|
||||
|
||||
// TODO for later reference
|
||||
// adjust_surface_alpha(nbase, SDL_ALPHA_OPAQUE);
|
||||
// adjust_surface_alpha(image, SDL_ALPHA_TRANSPARENT);
|
||||
//
|
||||
// TODO might be needed.
|
||||
bg_restore();
|
||||
|
||||
image = nbase;
|
||||
|
|
|
@ -107,7 +107,6 @@ surface floating_label::create_surface()
|
|||
|
||||
if (background == nullptr) {
|
||||
ERR_FT << "could not create tooltip box" << std::endl;
|
||||
adjust_surface_alpha(foreground, SDL_ALPHA_OPAQUE);
|
||||
return surf_ = foreground;
|
||||
}
|
||||
|
||||
|
@ -124,11 +123,7 @@ surface floating_label::create_surface()
|
|||
adjust_surface_alpha(foreground, SDL_ALPHA_OPAQUE);
|
||||
sdl_blit(foreground, nullptr, background, &r);
|
||||
|
||||
adjust_surface_alpha(background, SDL_ALPHA_OPAQUE);
|
||||
surf_ = background;
|
||||
// RLE compression seems less efficient for big semi-transparent area
|
||||
// so, remove it for this case, but keep the optimized display format
|
||||
adjust_surface_alpha(surf_, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
else {
|
||||
// background is blurred shadow of the text
|
||||
|
@ -137,16 +132,13 @@ surface floating_label::create_surface()
|
|||
sdl::fill_rect(background, nullptr, 0);
|
||||
SDL_Rect r = { 2, 2, 0, 0 };
|
||||
sdl_blit(foreground, nullptr, background, &r);
|
||||
background = shadow_image(background, false);
|
||||
background = shadow_image(background);
|
||||
|
||||
if (background == nullptr) {
|
||||
ERR_FT << "could not create floating label's shadow" << std::endl;
|
||||
adjust_surface_alpha(foreground, SDL_ALPHA_OPAQUE);
|
||||
return surf_ = foreground;
|
||||
}
|
||||
adjust_surface_alpha(foreground, SDL_ALPHA_OPAQUE);
|
||||
sdl_blit(foreground, nullptr, background, &r);
|
||||
adjust_surface_alpha(background, SDL_ALPHA_OPAQUE);
|
||||
surf_ = background;
|
||||
}
|
||||
}
|
||||
|
@ -197,8 +189,7 @@ void floating_label::undraw(surface screen)
|
|||
--lifetime_;
|
||||
if(alpha_change_ != 0 && (xmove_ != 0.0 || ymove_ != 0.0) && surf_ != nullptr) {
|
||||
// fade out moving floating labels
|
||||
// note that we don't optimize these surfaces since they will always change
|
||||
surf_.assign(adjust_surface_alpha_add(surf_,alpha_change_,false));
|
||||
surf_.assign(adjust_surface_alpha_add(surf_,alpha_change_));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1091,7 +1091,7 @@ void image_shape::draw(surface& canvas,
|
|||
DBG_GUI_D << "Image: vertical stretch from " << image_->w << ','
|
||||
<< image_->h << " to a height of " << h << ".\n";
|
||||
|
||||
surf = stretch_surface_vertical(image_, h, false);
|
||||
surf = stretch_surface_vertical(image_, h);
|
||||
done = true;
|
||||
}
|
||||
w = image_->w;
|
||||
|
@ -1103,7 +1103,7 @@ void image_shape::draw(surface& canvas,
|
|||
<< ',' << image_->h << " to a width of " << w
|
||||
<< ".\n";
|
||||
|
||||
surf = stretch_surface_horizontal(image_, w, false);
|
||||
surf = stretch_surface_horizontal(image_, w);
|
||||
done = true;
|
||||
}
|
||||
h = image_->h;
|
||||
|
@ -1136,7 +1136,7 @@ void image_shape::draw(surface& canvas,
|
|||
DBG_GUI_D << "Image: scaling from " << image_->w << ','
|
||||
<< image_->h << " to " << w << ',' << h << ".\n";
|
||||
|
||||
surf = scale_surface(image_, w, h, false);
|
||||
surf = scale_surface(image_, w, h);
|
||||
}
|
||||
}
|
||||
src_clip.w = w;
|
||||
|
@ -1146,7 +1146,7 @@ void image_shape::draw(surface& canvas,
|
|||
}
|
||||
|
||||
if(vertical_mirror_(local_variables)) {
|
||||
surf = flip_surface(surf, false);
|
||||
surf = flip_surface(surf);
|
||||
}
|
||||
|
||||
blit_surface(surf, &src_clip, canvas, &dst_clip);
|
||||
|
@ -1467,7 +1467,7 @@ void canvas::blit(surface& surf, SDL_Rect rect)
|
|||
// Can't directly blur the surface if not 32 bpp.
|
||||
SDL_Rect r = rect;
|
||||
surface s = get_surface_portion(surf, r);
|
||||
s = blur_surface(s, blur_depth_, false);
|
||||
s = blur_surface(s, blur_depth_);
|
||||
sdl_blit(s, nullptr, surf, &r);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -944,10 +944,6 @@ surface get_image(const image::locator& i_locator, TYPE type)
|
|||
return res;
|
||||
}
|
||||
|
||||
// Optimizes surface before storing it
|
||||
if(res)
|
||||
adjust_surface_alpha(res, SDL_ALPHA_OPAQUE);
|
||||
|
||||
#ifdef _OPENMP
|
||||
#pragma omp critical(image_cache)
|
||||
#endif //_OPENMP
|
||||
|
@ -1001,9 +997,6 @@ surface get_lighted_image(const image::locator& i_locator, const light_string& l
|
|||
;
|
||||
}
|
||||
|
||||
// Optimizes surface before storing it
|
||||
adjust_surface_alpha(res, SDL_ALPHA_OPAQUE);
|
||||
|
||||
// record the lighted surface in the corresponding variants cache
|
||||
i_locator.access_in_cache(*imap)[ls] = res;
|
||||
|
||||
|
|
|
@ -284,8 +284,6 @@ surface adjust_alpha_modification::operator()(const surface & src) const
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
adjust_surface_alpha(nsurf, SDL_ALPHA_OPAQUE);
|
||||
|
||||
{
|
||||
surface_lock lock(nsurf);
|
||||
Uint32* cur = lock.pixels();
|
||||
|
@ -333,8 +331,6 @@ surface adjust_channels_modification::operator()(const surface & src) const
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
adjust_surface_alpha(nsurf, SDL_ALPHA_OPAQUE);
|
||||
|
||||
{
|
||||
surface_lock lock(nsurf);
|
||||
Uint32* cur = lock.pixels();
|
||||
|
@ -386,8 +382,7 @@ surface crop_modification::operator()(const surface& src) const
|
|||
* Since it seems to work for most cases, rather change this caller instead
|
||||
* of the function signature. (The issue was discovered in bug #20876).
|
||||
*/
|
||||
surface temp = cut_surface(make_neutral_surface(src), area);
|
||||
adjust_surface_alpha(temp, SDL_ALPHA_OPAQUE);
|
||||
surface temp = cut_surface(make_neutral_surface(src), area);
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
@ -454,7 +449,7 @@ surface light_modification::operator()(const surface& src) const {
|
|||
// light_surface wants a neutral surface having same dimensions
|
||||
surface nsurf;
|
||||
if(surf_->w != src->w || surf_->h != src->h) {
|
||||
nsurf = scale_surface(surf_, src->w, src->h, false);
|
||||
nsurf = scale_surface(surf_, src->w, src->h);
|
||||
} else {
|
||||
nsurf = make_neutral_surface(surf_);
|
||||
}
|
||||
|
@ -596,7 +591,6 @@ surface background_modification::operator()(const surface &src) const
|
|||
SDL_FillRect(ret, nullptr, SDL_MapRGBA(ret->format, color_.r, color_.g,
|
||||
color_.b, color_.a));
|
||||
surface temp = src;
|
||||
adjust_surface_alpha(temp, SDL_ALPHA_OPAQUE);
|
||||
sdl_blit(temp, nullptr, ret, nullptr);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -63,9 +63,6 @@ surface make_neutral_surface(const surface &surf)
|
|||
}
|
||||
|
||||
surface result = SDL_ConvertSurface(surf,&get_neutral_pixel_format(),SDL_SWSURFACE);
|
||||
if(result != nullptr) {
|
||||
adjust_surface_alpha(result, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -89,7 +86,7 @@ surface create_neutral_surface(int w, int h)
|
|||
}
|
||||
|
||||
surface stretch_surface_horizontal(
|
||||
const surface& surf, const unsigned w, const bool optimize)
|
||||
const surface& surf, const unsigned w)
|
||||
{
|
||||
// Since SDL version 1.1.5 0 is transparent, before 255 was transparent.
|
||||
assert(SDL_ALPHA_TRANSPARENT==0);
|
||||
|
@ -130,15 +127,11 @@ surface stretch_surface_horizontal(
|
|||
}
|
||||
}
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(dst, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
surface stretch_surface_vertical(
|
||||
const surface& surf, const unsigned h, const bool optimize)
|
||||
const surface& surf, const unsigned h)
|
||||
{
|
||||
// Since SDL version 1.1.5 0 is transparent, before 255 was transparent.
|
||||
assert(SDL_ALPHA_TRANSPARENT==0);
|
||||
|
@ -177,10 +170,6 @@ surface stretch_surface_vertical(
|
|||
}
|
||||
}
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(dst, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
@ -206,7 +195,6 @@ surface scale_surface_xbrz(const surface & surf, size_t z)
|
|||
|
||||
if (z == 1) {
|
||||
surface temp = surf; // TODO: no temp surface
|
||||
adjust_surface_alpha(temp, SDL_ALPHA_OPAQUE);
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
@ -231,7 +219,6 @@ surface scale_surface_xbrz(const surface & surf, size_t z)
|
|||
xbrz::scale(z, src_lock.pixels(), dst_lock.pixels(), surf->w, surf->h);
|
||||
}
|
||||
|
||||
adjust_surface_alpha(dst, SDL_ALPHA_OPAQUE);
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
@ -271,16 +258,11 @@ surface scale_surface_nn (const surface & surf, int w, int h)
|
|||
xbrz::nearestNeighborScale(src_lock.pixels(), surf->w, surf->h, dst_lock.pixels(), w, h);
|
||||
}
|
||||
|
||||
adjust_surface_alpha(dst, SDL_ALPHA_OPAQUE);
|
||||
return dst;
|
||||
}
|
||||
|
||||
// NOTE: Don't pass this function 0 scaling arguments.
|
||||
surface scale_surface(const surface &surf, int w, int h) {
|
||||
return scale_surface(surf, w, h, true);
|
||||
}
|
||||
|
||||
surface scale_surface(const surface &surf, int w, int h, bool optimize)
|
||||
surface scale_surface(const surface &surf, int w, int h)
|
||||
{
|
||||
// Since SDL version 1.1.5 0 is transparent, before 255 was transparent.
|
||||
assert(SDL_ALPHA_TRANSPARENT==0);
|
||||
|
@ -409,14 +391,10 @@ surface scale_surface(const surface &surf, int w, int h, bool optimize)
|
|||
}
|
||||
}
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(dst, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
surface scale_surface_sharp(const surface& surf, int w, int h, bool optimize)
|
||||
surface scale_surface_sharp(const surface& surf, int w, int h)
|
||||
{
|
||||
// Since SDL version 1.1.5 0 is transparent, before 255 was transparent.
|
||||
assert(SDL_ALPHA_TRANSPARENT==0);
|
||||
|
@ -505,15 +483,11 @@ surface scale_surface_sharp(const surface& surf, int w, int h, bool optimize)
|
|||
}
|
||||
}
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(dst, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
||||
surface tile_surface(const surface& surf, int w, int h, bool optimize)
|
||||
surface tile_surface(const surface& surf, int w, int h)
|
||||
{
|
||||
if (surf->w == w && surf->h == h) {
|
||||
return surf;
|
||||
|
@ -554,25 +528,16 @@ surface tile_surface(const surface& surf, int w, int h, bool optimize)
|
|||
}
|
||||
}
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(dest, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
surface adjust_surface_color(const surface &surf, int red, int green, int blue, bool optimize)
|
||||
surface adjust_surface_color(const surface &surf, int red, int green, int blue)
|
||||
{
|
||||
if(surf == nullptr)
|
||||
return nullptr;
|
||||
|
||||
if((red == 0 && green == 0 && blue == 0)) {
|
||||
surface temp = surf; // TODO: remove temp surface
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(temp, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
@ -608,14 +573,10 @@ surface adjust_surface_color(const surface &surf, int red, int green, int blue,
|
|||
}
|
||||
}
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(nsurf, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return nsurf;
|
||||
}
|
||||
|
||||
surface greyscale_image(const surface &surf, bool optimize)
|
||||
surface greyscale_image(const surface &surf)
|
||||
{
|
||||
if(surf == nullptr)
|
||||
return nullptr;
|
||||
|
@ -657,14 +618,10 @@ surface greyscale_image(const surface &surf, bool optimize)
|
|||
}
|
||||
}
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(nsurf, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return nsurf;
|
||||
}
|
||||
|
||||
surface monochrome_image(const surface &surf, const int threshold, bool optimize)
|
||||
surface monochrome_image(const surface &surf, const int threshold)
|
||||
{
|
||||
if(surf == nullptr)
|
||||
return nullptr;
|
||||
|
@ -701,14 +658,10 @@ surface monochrome_image(const surface &surf, const int threshold, bool optimize
|
|||
}
|
||||
}
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(nsurf, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return nsurf;
|
||||
}
|
||||
|
||||
surface sepia_image(const surface &surf, bool optimize)
|
||||
surface sepia_image(const surface &surf)
|
||||
{
|
||||
if(surf == nullptr)
|
||||
return nullptr;
|
||||
|
@ -747,14 +700,10 @@ surface sepia_image(const surface &surf, bool optimize)
|
|||
}
|
||||
}
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(nsurf, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return nsurf;
|
||||
}
|
||||
|
||||
surface negative_image(const surface &surf, const int thresholdR, const int thresholdG, const int thresholdB, bool optimize)
|
||||
surface negative_image(const surface &surf, const int thresholdR, const int thresholdG, const int thresholdB)
|
||||
{
|
||||
if(surf == nullptr)
|
||||
return nullptr;
|
||||
|
@ -794,14 +743,10 @@ surface negative_image(const surface &surf, const int thresholdR, const int thre
|
|||
}
|
||||
}
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(nsurf, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return nsurf;
|
||||
}
|
||||
|
||||
surface alpha_to_greyscale(const surface &surf, bool optimize)
|
||||
surface alpha_to_greyscale(const surface &surf)
|
||||
{
|
||||
if(surf == nullptr)
|
||||
return nullptr;
|
||||
|
@ -826,14 +771,10 @@ surface alpha_to_greyscale(const surface &surf, bool optimize)
|
|||
}
|
||||
}
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(nsurf, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return nsurf;
|
||||
}
|
||||
|
||||
surface wipe_alpha(const surface &surf, bool optimize)
|
||||
surface wipe_alpha(const surface &surf)
|
||||
{
|
||||
if(surf == nullptr)
|
||||
return nullptr;
|
||||
|
@ -857,21 +798,17 @@ surface wipe_alpha(const surface &surf, bool optimize)
|
|||
}
|
||||
}
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(nsurf, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return nsurf;
|
||||
}
|
||||
|
||||
|
||||
surface shadow_image(const surface &surf, bool optimize)
|
||||
surface shadow_image(const surface &surf)
|
||||
{
|
||||
if(surf == nullptr)
|
||||
return nullptr;
|
||||
|
||||
// we blur it, and reuse the neutral surface created by the blur function (optimized = false)
|
||||
surface nsurf (blur_alpha_surface(surf, 2, false));
|
||||
// we blur it, and reuse the neutral surface created by the blur function
|
||||
surface nsurf (blur_alpha_surface(surf, 2));
|
||||
|
||||
if(nsurf == nullptr) {
|
||||
std::cerr << "failed to blur the shadow surface\n";
|
||||
|
@ -899,14 +836,10 @@ surface shadow_image(const surface &surf, bool optimize)
|
|||
}
|
||||
}
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(nsurf, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return nsurf;
|
||||
}
|
||||
|
||||
surface swap_channels_image(const surface& surf, channel r, channel g, channel b, channel a, bool optimize) {
|
||||
surface swap_channels_image(const surface& surf, channel r, channel g, channel b, channel a) {
|
||||
if(surf == nullptr)
|
||||
return nullptr;
|
||||
|
||||
|
@ -1005,14 +938,10 @@ surface swap_channels_image(const surface& surf, channel r, channel g, channel b
|
|||
}
|
||||
}
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(nsurf, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return nsurf;
|
||||
}
|
||||
|
||||
surface recolor_image(surface surf, const color_range_map& map_rgb, bool optimize)
|
||||
surface recolor_image(surface surf, const color_range_map& map_rgb)
|
||||
{
|
||||
if(surf == nullptr)
|
||||
return nullptr;
|
||||
|
@ -1048,14 +977,10 @@ surface recolor_image(surface surf, const color_range_map& map_rgb, bool optimiz
|
|||
++beg;
|
||||
}
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(nsurf, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return nsurf;
|
||||
}
|
||||
|
||||
surface brighten_image(const surface &surf, fixed_t amount, bool optimize)
|
||||
surface brighten_image(const surface &surf, fixed_t amount)
|
||||
{
|
||||
if(surf == nullptr) {
|
||||
return nullptr;
|
||||
|
@ -1094,10 +1019,6 @@ surface brighten_image(const surface &surf, fixed_t amount, bool optimize)
|
|||
}
|
||||
}
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(nsurf, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return nsurf;
|
||||
}
|
||||
|
||||
|
@ -1110,7 +1031,7 @@ void adjust_surface_alpha(surface& surf, fixed_t amount)
|
|||
SDL_SetSurfaceAlphaMod(surf, Uint8(amount));
|
||||
}
|
||||
|
||||
surface adjust_surface_alpha_add(const surface &surf, int amount, bool optimize)
|
||||
surface adjust_surface_alpha_add(const surface &surf, int amount)
|
||||
{
|
||||
if(surf== nullptr) {
|
||||
return nullptr;
|
||||
|
@ -1145,10 +1066,6 @@ surface adjust_surface_alpha_add(const surface &surf, int amount, bool optimize)
|
|||
}
|
||||
}
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(nsurf, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return nsurf;
|
||||
}
|
||||
|
||||
|
@ -1218,7 +1135,6 @@ surface mask_surface(const surface &surf, const surface &mask, bool* empty_resul
|
|||
if(empty_result)
|
||||
*empty_result = empty;
|
||||
|
||||
//adjust_surface_alpha(nsurf, SDL_ALPHA_OPAQUE);
|
||||
return nsurf;
|
||||
}
|
||||
|
||||
|
@ -1268,7 +1184,7 @@ bool in_mask_surface(const surface &surf, const surface &mask)
|
|||
return true;
|
||||
}
|
||||
|
||||
surface submerge_alpha(const surface &surf, int depth, float alpha_base, float alpha_delta, bool optimize)
|
||||
surface submerge_alpha(const surface &surf, int depth, float alpha_base, float alpha_delta)
|
||||
{
|
||||
if(surf== nullptr) {
|
||||
return nullptr;
|
||||
|
@ -1327,14 +1243,10 @@ surface submerge_alpha(const surface &surf, int depth, float alpha_base, float a
|
|||
|
||||
}
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(nsurf, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return nsurf;
|
||||
}
|
||||
|
||||
surface light_surface(const surface &surf, const surface &lightmap, bool optimize)
|
||||
surface light_surface(const surface &surf, const surface &lightmap)
|
||||
{
|
||||
if(surf == nullptr) {
|
||||
return nullptr;
|
||||
|
@ -1396,15 +1308,11 @@ surface light_surface(const surface &surf, const surface &lightmap, bool optimiz
|
|||
}
|
||||
}
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(nsurf, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return nsurf;
|
||||
}
|
||||
|
||||
|
||||
surface blur_surface(const surface &surf, int depth, bool optimize)
|
||||
surface blur_surface(const surface &surf, int depth)
|
||||
{
|
||||
if(surf == nullptr) {
|
||||
return nullptr;
|
||||
|
@ -1420,10 +1328,6 @@ surface blur_surface(const surface &surf, int depth, bool optimize)
|
|||
SDL_Rect rect = sdl::create_rect(0, 0, surf->w, surf->h);
|
||||
blur_surface(res, rect, depth);
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(res, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -1543,7 +1447,7 @@ void blur_surface(surface& surf, SDL_Rect rect, int depth)
|
|||
}
|
||||
}
|
||||
|
||||
surface blur_alpha_surface(const surface &surf, int depth, bool optimize)
|
||||
surface blur_alpha_surface(const surface &surf, int depth)
|
||||
{
|
||||
if(surf == nullptr) {
|
||||
return nullptr;
|
||||
|
@ -1663,10 +1567,6 @@ surface blur_alpha_surface(const surface &surf, int depth, bool optimize)
|
|||
}
|
||||
}
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(res, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -1731,8 +1631,7 @@ surface cut_surface(const surface &surf, SDL_Rect const &r)
|
|||
surface blend_surface(
|
||||
const surface &surf
|
||||
, const double amount
|
||||
, const color_t color
|
||||
, const bool optimize)
|
||||
, const color_t color)
|
||||
{
|
||||
if(surf== nullptr) {
|
||||
return nullptr;
|
||||
|
@ -1768,10 +1667,6 @@ surface blend_surface(
|
|||
}
|
||||
}
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(nsurf, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return nsurf;
|
||||
}
|
||||
|
||||
|
@ -1780,7 +1675,7 @@ surface blend_surface(
|
|||
* Lifted from: http://github.com/salmonmoose/SpriteRotator
|
||||
* 1) Zoom the source image by a certain factor.
|
||||
* 2) Scan the zoomed source image at every step=offset and put it in the result. */
|
||||
surface rotate_any_surface(const surface& surf, float angle, int zoom, int offset, bool optimize)
|
||||
surface rotate_any_surface(const surface& surf, float angle, int zoom, int offset)
|
||||
{
|
||||
int src_w, src_h, dst_w, dst_h;
|
||||
float min_x, min_y, sine, cosine;
|
||||
|
@ -1813,7 +1708,7 @@ surface rotate_any_surface(const surface& surf, float angle, int zoom, int offse
|
|||
surface dst(create_neutral_surface(dst_w, dst_h));
|
||||
{
|
||||
surface_lock dst_lock(dst);
|
||||
const surface src = scale_surface(surf, src_w, src_h, false);
|
||||
const surface src = scale_surface(surf, src_w, src_h);
|
||||
const_surface_lock src_lock(src);
|
||||
const float scale = 1.f / zoom;
|
||||
const int max_x = dst_w * zoom;
|
||||
|
@ -1834,10 +1729,6 @@ surface rotate_any_surface(const surface& surf, float angle, int zoom, int offse
|
|||
}
|
||||
}
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(dst, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
@ -1895,12 +1786,12 @@ Uint32 get_pixel(const surface& surf, const const_surface_lock& surf_lock, int x
|
|||
}
|
||||
|
||||
// Rotates a surface 180 degrees.
|
||||
surface rotate_180_surface(const surface &surf, bool optimize)
|
||||
surface rotate_180_surface(const surface &surf)
|
||||
{
|
||||
if ( surf == nullptr )
|
||||
return nullptr;
|
||||
|
||||
// Work with a "neutral" (unoptimized) surface.
|
||||
// Work with a "neutral" surface.
|
||||
surface nsurf(make_neutral_surface(surf));
|
||||
|
||||
if ( nsurf == nullptr ) {
|
||||
|
@ -1932,21 +1823,17 @@ surface rotate_180_surface(const surface &surf, bool optimize)
|
|||
}
|
||||
}
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(nsurf, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return nsurf;
|
||||
}
|
||||
|
||||
|
||||
// Rotates a surface 90 degrees, either clockwise or counter-clockwise.
|
||||
surface rotate_90_surface(const surface &surf, bool clockwise, bool optimize)
|
||||
surface rotate_90_surface(const surface &surf, bool clockwise)
|
||||
{
|
||||
if ( surf == nullptr )
|
||||
return nullptr;
|
||||
|
||||
// Work with "neutral" (unoptimized) surfaces.
|
||||
// Work with "neutral" surfaces.
|
||||
surface dst(create_neutral_surface(surf->h, surf->w)); // Flipped dimensions.
|
||||
surface src(make_neutral_surface(surf));
|
||||
|
||||
|
@ -1974,15 +1861,11 @@ surface rotate_90_surface(const surface &surf, bool clockwise, bool optimize)
|
|||
}
|
||||
}
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(dst, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
||||
surface flip_surface(const surface &surf, bool optimize)
|
||||
surface flip_surface(const surface &surf)
|
||||
{
|
||||
if(surf == nullptr) {
|
||||
return nullptr;
|
||||
|
@ -2008,14 +1891,10 @@ surface flip_surface(const surface &surf, bool optimize)
|
|||
}
|
||||
}
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(nsurf, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return nsurf;
|
||||
}
|
||||
|
||||
surface flop_surface(const surface &surf, bool optimize)
|
||||
surface flop_surface(const surface &surf)
|
||||
{
|
||||
if(surf == nullptr) {
|
||||
return nullptr;
|
||||
|
@ -2041,10 +1920,6 @@ surface flop_surface(const surface &surf, bool optimize)
|
|||
}
|
||||
}
|
||||
|
||||
if(optimize) {
|
||||
adjust_surface_alpha(nsurf, SDL_ALPHA_OPAQUE);
|
||||
}
|
||||
|
||||
return nsurf;
|
||||
}
|
||||
|
||||
|
|
|
@ -71,16 +71,14 @@ surface create_neutral_surface(int w, int h);
|
|||
* This means only the first column of the original is used for the destination.
|
||||
* @param surf The source surface.
|
||||
* @param w The width of the resulting surface.
|
||||
* @param optimize Should the return surface be RLE optimized.
|
||||
*
|
||||
* @return An optimized surface.
|
||||
* @return A surface.
|
||||
* returned.
|
||||
* @retval 0 Returned upon error.
|
||||
* @retval surf Returned if w == surf->w, note this ignores the
|
||||
* optimize flag.
|
||||
* @retval surf Returned if w == surf->w.
|
||||
*/
|
||||
surface stretch_surface_horizontal(
|
||||
const surface& surf, const unsigned w, const bool optimize = true);
|
||||
const surface& surf, const unsigned w);
|
||||
|
||||
/**
|
||||
* Stretches a surface in the vertical direction.
|
||||
|
@ -90,21 +88,19 @@ surface stretch_surface_horizontal(
|
|||
* This means only the first row of the original is used for the destination.
|
||||
* @param surf The source surface.
|
||||
* @param h The height of the resulting surface.
|
||||
* @param optimize Should the return surface be RLE optimized.
|
||||
*
|
||||
* @return An optimized surface.
|
||||
* @return A surface.
|
||||
* returned.
|
||||
*
|
||||
* @retval surf Returned if h == surf->h, note this ignores the
|
||||
* optimize flag.
|
||||
* @retval surf Returned if h == surf->h.
|
||||
*/
|
||||
surface stretch_surface_vertical(
|
||||
const surface& surf, const unsigned h, const bool optimize = true);
|
||||
const surface& surf, const unsigned h);
|
||||
|
||||
/** Scale a surface using xBRZ algorithm
|
||||
* @param surf The source surface
|
||||
* @param z The scaling factor. Should be an integer 2-5 (1 is tolerated).
|
||||
* @return The scaled (optimized) surface
|
||||
* @return The scaled surface
|
||||
*/
|
||||
surface scale_surface_xbrz(const surface & surf, size_t z);
|
||||
|
||||
|
@ -120,53 +116,45 @@ surface scale_surface_nn(const surface & surf, int w, int h);
|
|||
* @param surf The source surface.
|
||||
* @param w The width of the resulting surface.
|
||||
* @param h The height of the resulting surface.
|
||||
* @param optimize Should the return surface be RLE optimized.
|
||||
* @return A surface containing the scaled version of the source.
|
||||
* @retval 0 Returned upon error.
|
||||
* @retval surf Returned if w == surf->w and h == surf->h
|
||||
* note this ignores the optimize flag.
|
||||
* @retval surf Returned if w == surf->w and h == surf->h.
|
||||
*/
|
||||
surface scale_surface(const surface &surf, int w, int h, bool optimize /*=true*/);
|
||||
surface scale_surface(const surface &surf, int w, int h);
|
||||
//commenting out the default parameter so that it is possible to make function pointers to the 3 parameter version
|
||||
|
||||
/** Scale a surface using modified nearest neighbour algorithm. Use only if
|
||||
* preserving sharp edges is a priority (e.g. minimap).
|
||||
* @param surf The source surface.
|
||||
* @param w The width of the resulting surface.
|
||||
* @param h The height of the resulting surface.
|
||||
* @param optimize Should the return surface be RLE optimized.
|
||||
* @return A surface containing the scaled version of the source.
|
||||
* @retval 0 Returned upon error.
|
||||
* @retval surf Returned if w == surf->w and h == surf->h
|
||||
* note this ignores the optimize flag.
|
||||
* @retval surf Returned if w == surf->w and h == surf->h.
|
||||
*/
|
||||
surface scale_surface_sharp(const surface& surf, int w, int h, bool optimize=true);
|
||||
surface scale_surface_sharp(const surface& surf, int w, int h);
|
||||
|
||||
/** Tile a surface
|
||||
* @param surf The source surface.
|
||||
* @param w The width of the resulting surface.
|
||||
* @param h The height of the resulting surface.
|
||||
* @param optimize Should the return surface be RLE optimized
|
||||
* @return A surface containing the tiled version of the source.
|
||||
* @retval 0 Returned upon error
|
||||
* @retval surf Returned if w == surf->w and h == surf->h
|
||||
* note this ignores the optimize flag.
|
||||
* @retval surf Returned if w == surf->w and h == surf->h.
|
||||
*/
|
||||
surface tile_surface(const surface &surf, int w, int h, bool optimize=true);
|
||||
surface tile_surface(const surface &surf, int w, int h);
|
||||
|
||||
surface adjust_surface_color(const surface &surf, int r, int g, int b, bool optimize=true);
|
||||
surface greyscale_image(const surface &surf, bool optimize=true);
|
||||
surface monochrome_image(const surface &surf, const int threshold, bool optimize=true);
|
||||
surface sepia_image(const surface &surf, bool optimize=true);
|
||||
surface negative_image(const surface &surf, const int thresholdR, const int thresholdG, const int thresholdB, bool optimize=true);
|
||||
surface alpha_to_greyscale(const surface & surf, bool optimize=true);
|
||||
surface wipe_alpha(const surface & surf, bool optimize=true);
|
||||
surface adjust_surface_color(const surface &surf, int r, int g, int b);
|
||||
surface greyscale_image(const surface &surf);
|
||||
surface monochrome_image(const surface &surf, const int threshold);
|
||||
surface sepia_image(const surface &surf);
|
||||
surface negative_image(const surface &surf, const int thresholdR, const int thresholdG, const int thresholdB);
|
||||
surface alpha_to_greyscale(const surface & surf);
|
||||
surface wipe_alpha(const surface & surf);
|
||||
/** create an heavy shadow of the image, by blurring, increasing alpha and darkening */
|
||||
surface shadow_image(const surface &surf, bool optimize=true);
|
||||
surface shadow_image(const surface &surf);
|
||||
|
||||
enum channel { RED, GREEN, BLUE, ALPHA };
|
||||
surface swap_channels_image(const surface& surf, channel r, channel g, channel b, channel a, bool optimize=true);
|
||||
surface swap_channels_image(const surface& surf, channel r, channel g, channel b, channel a);
|
||||
|
||||
/**
|
||||
* Recolors a surface using a map with source and converted palette values.
|
||||
|
@ -175,15 +163,12 @@ surface swap_channels_image(const surface& surf, channel r, channel g, channel b
|
|||
* @param surf The source surface.
|
||||
* @param map_rgb Map of color values, with the keys corresponding to the
|
||||
* source palette, and the values to the recolored palette.
|
||||
* @param optimize Whether the new surface should be RLE encoded. Only
|
||||
* useful when the source is not the screen and it is
|
||||
* going to be used multiple times.
|
||||
* @return A recolored surface, or a null surface if there are
|
||||
* problems with the source.
|
||||
*/
|
||||
surface recolor_image(surface surf, const color_range_map& map_rgb, bool optimize=true);
|
||||
surface recolor_image(surface surf, const color_range_map& map_rgb);
|
||||
|
||||
surface brighten_image(const surface &surf, fixed_t amount, bool optimize=true);
|
||||
surface brighten_image(const surface &surf, fixed_t amount);
|
||||
|
||||
/** Get a portion of the screen.
|
||||
* Send nullptr if the portion is outside of the screen.
|
||||
|
@ -196,7 +181,7 @@ surface brighten_image(const surface &surf, fixed_t amount, bool optimize=true);
|
|||
surface get_surface_portion(const surface &surf, SDL_Rect &rect);
|
||||
|
||||
void adjust_surface_alpha(surface& surf, fixed_t amount);
|
||||
surface adjust_surface_alpha_add(const surface &surf, int amount, bool optimize=true);
|
||||
surface adjust_surface_alpha_add(const surface &surf, int amount);
|
||||
|
||||
/** Applies a mask on a surface. */
|
||||
surface mask_surface(const surface &surf, const surface &mask, bool* empty_result = nullptr, const std::string& filename = std::string());
|
||||
|
@ -209,9 +194,8 @@ bool in_mask_surface(const surface &surf, const surface &mask);
|
|||
* @param depth The height of the bottom part in pixels
|
||||
* @param alpha_base The alpha adjustment at the interface
|
||||
* @param alpha_delta The alpha adjustment reduction rate by pixel depth
|
||||
* @param optimize Optimize by converting to result to display
|
||||
*/
|
||||
surface submerge_alpha(const surface &surf, int depth, float alpha_base, float alpha_delta, bool optimize=true);
|
||||
surface submerge_alpha(const surface &surf, int depth, float alpha_base, float alpha_delta);
|
||||
|
||||
/**
|
||||
* Light surf using lightmap
|
||||
|
@ -220,18 +204,16 @@ surface submerge_alpha(const surface &surf, int depth, float alpha_base, float a
|
|||
* but RGB values are converted to (X-128)*2
|
||||
* to cover the full (-256,256) spectrum.
|
||||
* Should already be neutral
|
||||
* @param optimize Whether the new surface should be RLE encoded.
|
||||
*/
|
||||
surface light_surface(const surface &surf, const surface &lightmap, bool optimize=true);
|
||||
surface light_surface(const surface &surf, const surface &lightmap);
|
||||
|
||||
/** Cross-fades a surface. */
|
||||
surface blur_surface(const surface &surf, int depth = 1, bool optimize=true);
|
||||
surface blur_surface(const surface &surf, int depth = 1);
|
||||
|
||||
/**
|
||||
* Cross-fades a surface in place.
|
||||
*
|
||||
* @param surf The surface to blur, must be not optimized
|
||||
* and have 32 bits per pixel.
|
||||
* @param surf The surface to blur, must have 32 bits per pixel.
|
||||
* @param rect The part of the surface to blur.
|
||||
* @param depth The depth of the blurring.
|
||||
*/
|
||||
|
@ -243,7 +225,7 @@ void blur_surface(surface& surf, SDL_Rect rect, int depth = 1);
|
|||
* @todo FIXME: This is just an adapted copy-paste
|
||||
* of the normal blur but with blur alpha channel too
|
||||
*/
|
||||
surface blur_alpha_surface(const surface &surf, int depth = 1, bool optimize=true);
|
||||
surface blur_alpha_surface(const surface &surf, int depth = 1);
|
||||
|
||||
/** Cuts a rectangle from a surface. */
|
||||
surface cut_surface(const surface &surf, SDL_Rect const &r);
|
||||
|
@ -260,15 +242,13 @@ surface cut_surface(const surface &surf, SDL_Rect const &r);
|
|||
* [0, 1].
|
||||
* @param color The color to blend width, note its alpha
|
||||
* channel is ignored.
|
||||
* @param optimize Should the return surface be RLE optimized.
|
||||
*
|
||||
* @return The blended surface.
|
||||
*/
|
||||
surface blend_surface(
|
||||
const surface &surf
|
||||
, const double amount
|
||||
, const color_t color
|
||||
, const bool optimize = true);
|
||||
, const color_t color);
|
||||
|
||||
/**
|
||||
* Rotates a surface by any degrees.
|
||||
|
@ -280,22 +260,20 @@ surface blend_surface(
|
|||
* @param angle The angle of rotation.
|
||||
* @param zoom Which zoom level to use for calculating the result.
|
||||
* @param offset Pixel offset when scanning the zoomed source.
|
||||
* @param optimize Should the return surface be RLE optimized.
|
||||
*
|
||||
* @return The rotated surface.
|
||||
*/
|
||||
surface rotate_any_surface(const surface& surf, float angle,
|
||||
int zoom, int offset, bool optimize=true);
|
||||
int zoom, int offset);
|
||||
|
||||
/**
|
||||
* Rotates a surface 180 degrees.
|
||||
*
|
||||
* @param surf The surface to rotate.
|
||||
* @param optimize Should the return surface be RLE optimized.
|
||||
*
|
||||
* @return The rotated surface.
|
||||
*/
|
||||
surface rotate_180_surface(const surface &surf, bool optimize=true);
|
||||
surface rotate_180_surface(const surface &surf);
|
||||
|
||||
/**
|
||||
* Rotates a surface 90 degrees.
|
||||
|
@ -303,14 +281,13 @@ surface rotate_180_surface(const surface &surf, bool optimize=true);
|
|||
* @param surf The surface to rotate.
|
||||
* @param clockwise Whether the rotation should be clockwise (true)
|
||||
* or counter-clockwise (false).
|
||||
* @param optimize Should the return surface be RLE optimized.
|
||||
*
|
||||
* @return The rotated surface.
|
||||
*/
|
||||
surface rotate_90_surface(const surface &surf, bool clockwise, bool optimize=true);
|
||||
surface rotate_90_surface(const surface &surf, bool clockwise);
|
||||
|
||||
surface flip_surface(const surface &surf, bool optimize=true);
|
||||
surface flop_surface(const surface &surf, bool optimize=true);
|
||||
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);
|
||||
|
||||
/**
|
||||
|
|
|
@ -302,7 +302,7 @@ void dialog_frame::draw_background()
|
|||
|
||||
if (dialog_style_.blur_radius) {
|
||||
surface surf = ::get_surface_portion(video_.getSurface(), dim_.exterior);
|
||||
surf = blur_surface(surf, dialog_style_.blur_radius, false);
|
||||
surf = blur_surface(surf, dialog_style_.blur_radius);
|
||||
sdl_blit(surf, nullptr, video_.getSurface(), &dim_.exterior);
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ namespace {
|
|||
{
|
||||
SDL_Rect blur_rect = sdl::create_rect(0, y, screen_area().w, h);
|
||||
surface blur = get_surface_portion(video.getSurface(), blur_rect);
|
||||
blur = blur_surface(blur, 1, false);
|
||||
blur = blur_surface(blur, 1);
|
||||
video.blit_surface(0, y, blur);
|
||||
}
|
||||
}
|
||||
|
@ -137,12 +137,12 @@ void part_ui::prepare_background()
|
|||
x_scale_factor = y_scale_factor = yscale;
|
||||
}
|
||||
|
||||
layer = scale_surface(layer, static_cast<int>(layer->w*x_scale_factor), static_cast<int>(layer->h*y_scale_factor), false);
|
||||
layer = scale_surface(layer, static_cast<int>(layer->w*x_scale_factor), static_cast<int>(layer->h*y_scale_factor));
|
||||
|
||||
const int tilew = bl.tile_horizontally() ? video_.getx() : layer->w;
|
||||
const int tileh = bl.tile_vertically() ? video_.gety() : layer->h;
|
||||
|
||||
layer = tile_surface(layer, tilew, tileh, false);
|
||||
layer = tile_surface(layer, tilew, tileh);
|
||||
|
||||
SDL_Rect drect = sdl::create_rect(
|
||||
(background_->w - layer->w) / 2
|
||||
|
|
Loading…
Add table
Reference in a new issue