From 5170615e03a5d9293d47e8c108da00a14d6d8f88 Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Thu, 15 Aug 2024 21:26:24 -0400 Subject: [PATCH] Don't clone surface when getting non-transparent rect --- src/sdl/utils.cpp | 12 +++--------- src/sdl/utils.hpp | 2 +- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/sdl/utils.cpp b/src/sdl/utils.cpp index e04788bd909..64e267964a4 100644 --- a/src/sdl/utils.cpp +++ b/src/sdl/utils.cpp @@ -1805,16 +1805,10 @@ constexpr bool not_alpha(uint32_t pixel) } } -rect get_non_transparent_portion(const surface &surf) +rect get_non_transparent_portion(surface nsurf) { rect res {0,0,0,0}; - surface nsurf = surf.clone(); - if(nsurf == nullptr) { - PLAIN_LOG << "failed to make neutral surface"; - return res; - } - surface_lock lock(nsurf); const uint32_t* const pixels = lock.pixels(); @@ -1830,7 +1824,7 @@ rect get_non_transparent_portion(const surface &surf) res.y = n; for(n = 0; n != nsurf->h-res.y; ++n) { - const uint32_t* const start_row = pixels + (nsurf->h-n-1)*surf->w; + const uint32_t* const start_row = pixels + (nsurf->h-n-1)*nsurf->w; const uint32_t* const end_row = start_row + nsurf->w; if(std::find_if(start_row,end_row,not_alpha) != end_row) @@ -1859,7 +1853,7 @@ rect get_non_transparent_portion(const surface &surf) for(n = 0; n != nsurf->w-res.x; ++n) { int y; for(y = 0; y != nsurf->h; ++y) { - const uint32_t pixel = pixels[y*nsurf->w + surf->w - n - 1]; + const uint32_t pixel = pixels[y*nsurf->w + nsurf->w - n - 1]; if(not_alpha(pixel)) break; } diff --git a/src/sdl/utils.hpp b/src/sdl/utils.hpp index 6fb4cbeee9e..cbde1758233 100644 --- a/src/sdl/utils.hpp +++ b/src/sdl/utils.hpp @@ -246,7 +246,7 @@ surface rotate_90_surface(const surface &surf, bool clockwise); surface flip_surface(const surface &surf); surface flop_surface(const surface &surf); -rect get_non_transparent_portion(const surface &surf); +rect get_non_transparent_portion(surface surf); /** * Helper methods for setting/getting a single pixel in an image.