Skip to content

Commit

Permalink
wrlib: Added clean-up of library internals in 'RShutdown'
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dmaciejak authored and crmafra committed May 9, 2014
1 parent e237ec1 commit 1b2e8a6
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions wrlib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ libwraster_la_SOURCES = \
save.c \
gradient.c \
xpixmap.c \
convert.h \
convert.c \
context.c \
misc.c \
Expand Down
34 changes: 34 additions & 0 deletions wrlib/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include <assert.h>

#include "wraster.h"
#include "convert.h"


#ifdef USE_XSHM
extern Pixmap R_CreateXImageMappedPixmap(RContext * context, RXImage * ximage);
Expand Down Expand Up @@ -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;
Expand Down
39 changes: 39 additions & 0 deletions wrlib/convert.h
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions wrlib/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "wraster.h"
#include "imgformat.h"
#include "convert.h"


void RBevelImage(RImage * image, int bevel_type)
Expand Down Expand Up @@ -252,4 +253,5 @@ void RShutdown(void)
RReleaseMagick();
#endif
RReleaseCache();
r_destroy_conversion_tables();
}

0 comments on commit 1b2e8a6

Please sign in to comment.