From 9e08928ad33d451fdf874346d016574be186086b Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 16 Jun 2014 23:33:24 +0000 Subject: [PATCH] base: allow to retrieve the keys in Map, and use that to clean up Image. --- src/image/image.cpp | 5 +++ src/image/pipi.cpp | 96 --------------------------------------------- src/lol/base/map.h | 8 ++++ 3 files changed, 13 insertions(+), 96 deletions(-) delete mode 100644 src/image/pipi.cpp diff --git a/src/image/image.cpp b/src/image/image.cpp index b6d5e32c..ef9a5546 100644 --- a/src/image/image.cpp +++ b/src/image/image.cpp @@ -123,6 +123,11 @@ Image & Image::operator =(Image other) Image::~Image() { + for (int k : m_data->m_pixels.Keys()) + { + delete m_data->m_pixels[k]; + m_data->m_pixels[k] = nullptr; + } delete m_data; } diff --git a/src/image/pipi.cpp b/src/image/pipi.cpp deleted file mode 100644 index 67ce3b14..00000000 --- a/src/image/pipi.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - * libpipi Pathetic image processing interface library - * Copyright (c) 2004-2008 Sam Hocevar - * All Rights Reserved - * - * $Id$ - * - * This library is free software. It comes without any warranty, to - * the extent permitted by applicable law. You can redistribute it - * and/or modify it under the terms of the Do What The Fuck You Want - * To Public License, Version 2, as published by Sam Hocevar. See - * http://sam.zoy.org/wtfpl/COPYING for more details. - */ - -/* - * pipi.c: core library routines - */ - -#include "config.h" - -#include -#include -#include - -#include "pipi.h" -#include "pipi-internals.h" - -/** \brief Return the \e libpipi version. - * - * Return a read-only string with the \e libpipi version information. - * - * This function never fails. - * - * \return The \e libpipi version information. - */ -char const * pipi_get_version(void) -{ - return PACKAGE_VERSION; -} - -/* -static int init = 0; - -void _pipi_init(void) -{ - if(init) - return; - - _pipi_init_pixels(); -} -*/ - -pipi_image_t *pipi_new(int w, int h) -{ - pipi_image_t *img; - - img = malloc(sizeof(pipi_image_t)); - memset(img, 0, sizeof(pipi_image_t)); - - img->w = w; - img->h = h; - img->last_modified = PIPI_PIXELS_UNINITIALISED; - img->codec_format = PIPI_PIXELS_UNINITIALISED; - - img->wrap = 0; - img->u8 = 1; - - return img; -} - -pipi_image_t *pipi_copy(pipi_image_t *src) -{ - pipi_image_t *dst = pipi_new(src->w, src->h); - - /* Copy properties */ - dst->wrap = src->wrap; - dst->u8 = src->u8; - - /* Copy pixels, if any */ - if(src->last_modified != PIPI_PIXELS_UNINITIALISED) - { - pipi_pixels_t *srcp, *dstp; - - srcp = &src->p[src->last_modified]; - dstp = &dst->p[src->last_modified]; - - memcpy(dstp, srcp, sizeof(pipi_pixels_t)); - dstp->pixels = malloc(dstp->bytes); - memcpy(dstp->pixels, srcp->pixels, dstp->bytes); - - dst->last_modified = src->last_modified; - } - - return dst; -} - diff --git a/src/lol/base/map.h b/src/lol/base/map.h index 028300b2..df520110 100644 --- a/src/lol/base/map.h +++ b/src/lol/base/map.h @@ -80,6 +80,14 @@ public: return false; } + Array Keys() const + { + Array ret; + for (auto it : m_array) + ret.Push(it.m2); + return ret; + } + inline int Count() const { return m_array.Count();