From: David Maciejak <[email protected]>

The library uses internally a cache of tables to convert image to different
depths, there is now an internal function 'r_destroy_conversion_tables' to
free them.
---
 wrlib/Makefile.am |  1 +
 wrlib/convert.c   | 34 ++++++++++++++++++++++++++++++++++
 wrlib/convert.h   | 39 +++++++++++++++++++++++++++++++++++++++
 wrlib/misc.c      |  2 ++
 4 files changed, 76 insertions(+)
 create mode 100644 wrlib/convert.h

diff --git a/wrlib/Makefile.am b/wrlib/Makefile.am
index d88ecc6..3f229c5 100644
--- a/wrlib/Makefile.am
+++ b/wrlib/Makefile.am
@@ -28,6 +28,7 @@ libwraster_la_SOURCES =       \
        save.c          \
        gradient.c      \
        xpixmap.c       \
+       convert.h       \
        convert.c       \
        context.c       \
        misc.c          \
diff --git a/wrlib/convert.c b/wrlib/convert.c
index f3c9a49..95a14d4 100644
--- a/wrlib/convert.c
+++ b/wrlib/convert.c
@@ -34,6 +34,8 @@
 #include <assert.h>
 
 #include "wraster.h"
+#include "convert.h"
+
 
 #ifdef USE_XSHM
 extern Pixmap R_CreateXImageMappedPixmap(RContext * context, RXImage * ximage);
@@ -62,6 +64,38 @@ typedef struct RStdConversionTable {
 static RConversionTable *conversionTable = NULL;
 static RStdConversionTable *stdConversionTable = NULL;
 
+static void release_conversion_table(void)
+{
+       RConversionTable *tmp = conversionTable;
+
+       while (tmp) {
+               RConversionTable *tmp_to_delete = tmp;
+
+               tmp = tmp->next;
+               free(tmp_to_delete);
+       }
+       conversionTable = NULL;
+}
+
+static void release_std_conversion_table(void)
+{
+       RStdConversionTable *tmp = stdConversionTable;
+
+       while (tmp) {
+               RStdConversionTable *tmp_to_delete = tmp;
+
+               tmp = tmp->next;
+               free(tmp_to_delete);
+       }
+       stdConversionTable = NULL;
+}
+
+void r_destroy_conversion_tables(void)
+{
+       release_conversion_table();
+       release_std_conversion_table();
+}
+
 static unsigned short *computeTable(unsigned short mask)
 {
        RConversionTable *tmp = conversionTable;
diff --git a/wrlib/convert.h b/wrlib/convert.h
new file mode 100644
index 0000000..a3045e0
--- /dev/null
+++ b/wrlib/convert.h
@@ -0,0 +1,39 @@
+/*
+ * Raster graphics library
+ *
+ * Copyright (c) 2014 Window Maker Team
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ *  MA 02110-1301, USA.
+ */
+
+/*
+ * Functions to convert images to given color depths
+ *
+ * The functions here are for WRaster library's internal use only,
+ * Please use functions in 'wraster.h' in applications
+ */
+
+#ifndef WRASTER_CONVERT_H
+#define WRASTER_CONVERT_H
+
+
+/*
+ * Function for to release internal Conversion Tables
+ */
+void r_destroy_conversion_tables(void);
+
+
+#endif
diff --git a/wrlib/misc.c b/wrlib/misc.c
index 53d5aaa..615777e 100644
--- a/wrlib/misc.c
+++ b/wrlib/misc.c
@@ -27,6 +27,7 @@
 
 #include "wraster.h"
 #include "imgformat.h"
+#include "convert.h"
 
 
 void RBevelImage(RImage * image, int bevel_type)
@@ -252,4 +253,5 @@ void RShutdown(void)
        RReleaseMagick();
 #endif
        RReleaseCache();
+       r_destroy_conversion_tables();
 }
-- 
1.9.2


-- 
To unsubscribe, send mail to [email protected].

Reply via email to