File: gcache.c

package info (click to toggle)
mc 4.1.35-1
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 6,924 kB
  • ctags: 9,665
  • sloc: ansic: 84,273; tcl: 1,779; makefile: 1,266; sh: 864; perl: 262; awk: 148; sed: 93; csh: 1
file content (43 lines) | stat: -rw-r--r-- 862 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
 * Simple Image cache for images
 * Copyright (C) 1998 the Free Software Foundation 
 *
 * Author: Miguel de Icaza (miguel@kernel.org)
 */
#include <gnome.h>
#include <string.h>
#include "gcache.h"
static GHashTable *image_cache;

static void
destroy_image_callback (gpointer key, gpointer data, gpointer user_data)
{
	gdk_imlib_destroy_image (data);
	g_free (key);
}

void
image_cache_destroy ()
{
	g_hash_table_foreach (image_cache, destroy_image_callback, NULL);
	g_hash_table_destroy (image_cache);
}

GdkImlibImage *
image_cache_load_image (char *file)
{
	void *data;
	
	if (!image_cache)
		image_cache = g_hash_table_new (g_str_hash, g_str_equal);

	data = g_hash_table_lookup (image_cache, file);
	if (data)
		return data;

	data = gdk_imlib_load_image (file);
	if (data){
		g_hash_table_insert (image_cache, g_strdup (file), data);
	}
	return data;
}