diff options
-rwxr-xr-x | gtk/PlatGTK.cxx | 15 | ||||
-rw-r--r-- | src/XPM.cxx | 9 | ||||
-rw-r--r-- | src/XPM.h | 2 | ||||
-rw-r--r-- | win32/PlatWin.cxx | 4 |
4 files changed, 13 insertions, 17 deletions
diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx index aff6b5e30..691872e5a 100755 --- a/gtk/PlatGTK.cxx +++ b/gtk/PlatGTK.cxx @@ -1228,7 +1228,7 @@ public: int GetSelection() override; int Find(const char *prefix) override; void GetValue(int n, char *value, int len) override; - void RegisterRGBA(int type, RGBAImage *image); + void RegisterRGBA(int type, std::unique_ptr<RGBAImage> image); void RegisterImage(int type, const char *xpm_data) override; void RegisterRGBAImage(int type, int width, int height, const unsigned char *pixelsImage) override; void ClearRegisteredImages() override; @@ -1815,8 +1815,9 @@ void ListBoxX::GetValue(int n, char *value, int len) { #pragma warning(disable: 4127) #endif -void ListBoxX::RegisterRGBA(int type, RGBAImage *image) { - images.Add(type, image); +void ListBoxX::RegisterRGBA(int type, std::unique_ptr<RGBAImage> image) { + images.AddImage(type, std::move(image)); + const RGBAImage * const observe = images.Get(type); if (!pixhash) { pixhash = g_hash_table_new(g_direct_hash, g_direct_equal); @@ -1828,10 +1829,10 @@ void ListBoxX::RegisterRGBA(int type, RGBAImage *image) { if (list_image->pixbuf) g_object_unref(list_image->pixbuf); list_image->pixbuf = nullptr; - list_image->rgba_data = image; + list_image->rgba_data = observe; } else { list_image = g_new0(ListImage, 1); - list_image->rgba_data = image; + list_image->rgba_data = observe; g_hash_table_insert((GHashTable *) pixhash, GINT_TO_POINTER(type), (gpointer) list_image); } @@ -1840,11 +1841,11 @@ void ListBoxX::RegisterRGBA(int type, RGBAImage *image) { void ListBoxX::RegisterImage(int type, const char *xpm_data) { g_return_if_fail(xpm_data); XPM xpmImage(xpm_data); - RegisterRGBA(type, new RGBAImage(xpmImage)); + RegisterRGBA(type, std::make_unique<RGBAImage>(xpmImage)); } void ListBoxX::RegisterRGBAImage(int type, int width, int height, const unsigned char *pixelsImage) { - RegisterRGBA(type, new RGBAImage(width, height, 1.0, pixelsImage)); + RegisterRGBA(type, std::make_unique<RGBAImage>(width, height, 1.0f, pixelsImage)); } void ListBoxX::ClearRegisteredImages() { diff --git a/src/XPM.cxx b/src/XPM.cxx index cfe6d94af..c310911f6 100644 --- a/src/XPM.cxx +++ b/src/XPM.cxx @@ -297,13 +297,8 @@ void RGBAImageSet::Clear() noexcept { } /// Add an image. -void RGBAImageSet::Add(int ident, RGBAImage *image) { - ImageMap::iterator it=images.find(ident); - if (it == images.end()) { - images[ident] = std::unique_ptr<RGBAImage>(image); - } else { - it->second.reset(image); - } +void RGBAImageSet::AddImage(int ident, std::unique_ptr<RGBAImage> image) { + images[ident] = std::move(image); height = -1; width = -1; } @@ -88,7 +88,7 @@ public: /// Remove all images. void Clear() noexcept; /// Add an image. - void Add(int ident, RGBAImage *image); + void AddImage(int ident, std::unique_ptr<RGBAImage> image); /// Get image by id. RGBAImage *Get(int ident); /// Give the largest height of the set. diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index fc4d56cf1..2ad3e2f7b 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -2728,11 +2728,11 @@ void ListBoxX::GetValue(int n, char *value, int len) { void ListBoxX::RegisterImage(int type, const char *xpm_data) { XPM xpmImage(xpm_data); - images.Add(type, new RGBAImage(xpmImage)); + images.AddImage(type, std::make_unique<RGBAImage>(xpmImage)); } void ListBoxX::RegisterRGBAImage(int type, int width, int height, const unsigned char *pixelsImage) { - images.Add(type, new RGBAImage(width, height, 1.0, pixelsImage)); + images.AddImage(type, std::make_unique<RGBAImage>(width, height, 1.0f, pixelsImage)); } void ListBoxX::ClearRegisteredImages() { |