mirror of https://github.com/GNOME/gimp.git
app: remove gimpimage-colorhash.[ch]
All indexed mapping is done with Babl now \o/
This commit is contained in:
parent
4ba37eacd8
commit
b68a05f240
|
@ -201,8 +201,6 @@ libappcore_a_sources = \
|
|||
gimpimage.h \
|
||||
gimpimage-arrange.c \
|
||||
gimpimage-arrange.h \
|
||||
gimpimage-colorhash.c \
|
||||
gimpimage-colorhash.h \
|
||||
gimpimage-colormap.c \
|
||||
gimpimage-colormap.h \
|
||||
gimpimage-contiguous-region.c \
|
||||
|
|
|
@ -1,173 +0,0 @@
|
|||
/* GIMP - The GNU Image Manipulation Program
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <gegl.h>
|
||||
|
||||
#include "core-types.h"
|
||||
|
||||
#include "gimpimage.h"
|
||||
#include "gimpimage-colorhash.h"
|
||||
#include "gimpimage-colormap.h"
|
||||
|
||||
|
||||
#define MAXDIFF 195076
|
||||
#define HASH_TABLE_SIZE 1021
|
||||
|
||||
|
||||
typedef struct _ColorHash ColorHash;
|
||||
|
||||
struct _ColorHash
|
||||
{
|
||||
gint pixel; /* R << 16 | G << 8 | B */
|
||||
gint index; /* colormap index */
|
||||
GimpImage *image;
|
||||
};
|
||||
|
||||
|
||||
static ColorHash color_hash_table[HASH_TABLE_SIZE];
|
||||
static gint color_hash_misses;
|
||||
static gint color_hash_hits;
|
||||
|
||||
|
||||
void
|
||||
gimp_image_color_hash_init (void)
|
||||
{
|
||||
gint i;
|
||||
|
||||
/* initialize the color hash table--invalidate all entries */
|
||||
for (i = 0; i < HASH_TABLE_SIZE; i++)
|
||||
{
|
||||
color_hash_table[i].pixel = 0;
|
||||
color_hash_table[i].index = 0;
|
||||
color_hash_table[i].image = NULL;
|
||||
}
|
||||
|
||||
color_hash_misses = 0;
|
||||
color_hash_hits = 0;
|
||||
}
|
||||
|
||||
void
|
||||
gimp_image_color_hash_exit (void)
|
||||
{
|
||||
#if 0
|
||||
/* print out the hash table statistics */
|
||||
g_print ("RGB->indexed hash table lookups: %d\n",
|
||||
color_hash_hits + color_hash_misses);
|
||||
g_print ("RGB->indexed hash table hits: %d\n", color_hash_hits);
|
||||
g_print ("RGB->indexed hash table misses: %d\n", color_hash_misses);
|
||||
g_print ("RGB->indexed hash table hit rate: %f\n",
|
||||
100.0 * color_hash_hits / (color_hash_hits + color_hash_misses));
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
gimp_image_color_hash_invalidate (GimpImage *image,
|
||||
gint index)
|
||||
{
|
||||
gint i;
|
||||
|
||||
g_return_if_fail (GIMP_IS_IMAGE (image));
|
||||
|
||||
if (index == -1) /* invalidate all entries */
|
||||
{
|
||||
for (i = 0; i < HASH_TABLE_SIZE; i++)
|
||||
if (color_hash_table[i].image == image)
|
||||
{
|
||||
color_hash_table[i].pixel = 0;
|
||||
color_hash_table[i].index = 0;
|
||||
color_hash_table[i].image = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < HASH_TABLE_SIZE; i++)
|
||||
if (color_hash_table[i].image == image &&
|
||||
color_hash_table[i].index == index)
|
||||
{
|
||||
color_hash_table[i].pixel = 0;
|
||||
color_hash_table[i].index = 0;
|
||||
color_hash_table[i].image = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gint
|
||||
gimp_image_color_hash_rgb_to_indexed (const GimpImage *image,
|
||||
gint r,
|
||||
gint g,
|
||||
gint b)
|
||||
{
|
||||
const guchar *cmap;
|
||||
gint num_cols;
|
||||
guint pixel;
|
||||
gint hash_index;
|
||||
gint cmap_index;
|
||||
|
||||
cmap = gimp_image_get_colormap (image);
|
||||
num_cols = gimp_image_get_colormap_size (image);
|
||||
pixel = (r << 16) | (g << 8) | b;
|
||||
hash_index = pixel % HASH_TABLE_SIZE;
|
||||
|
||||
if (color_hash_table[hash_index].image == image &&
|
||||
color_hash_table[hash_index].pixel == pixel)
|
||||
{
|
||||
/* Hash table lookup hit */
|
||||
|
||||
cmap_index = color_hash_table[hash_index].index;
|
||||
color_hash_hits++;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Hash table lookup miss */
|
||||
|
||||
const guchar *col;
|
||||
gint diff, sum, max;
|
||||
gint i;
|
||||
|
||||
max = MAXDIFF;
|
||||
cmap_index = 0;
|
||||
col = cmap;
|
||||
|
||||
for (i = 0; i < num_cols; i++)
|
||||
{
|
||||
diff = r - *col++;
|
||||
sum = diff * diff;
|
||||
|
||||
diff = g - *col++;
|
||||
sum += diff * diff;
|
||||
|
||||
diff = b - *col++;
|
||||
sum += diff * diff;
|
||||
|
||||
if (sum < max)
|
||||
{
|
||||
cmap_index = i;
|
||||
max = sum;
|
||||
}
|
||||
}
|
||||
|
||||
/* update the hash table */
|
||||
color_hash_table[hash_index].pixel = pixel;
|
||||
color_hash_table[hash_index].index = cmap_index;
|
||||
color_hash_table[hash_index].image = (GimpImage *) image;
|
||||
color_hash_misses++;
|
||||
}
|
||||
|
||||
return cmap_index;
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
/* GIMP - The GNU Image Manipulation Program
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __GIMP_IMAGE_COLOR_HASH_H__
|
||||
#define __GIMP_IMAGE_COLOR_HASH_H__
|
||||
|
||||
|
||||
void gimp_image_color_hash_init (void);
|
||||
void gimp_image_color_hash_exit (void);
|
||||
|
||||
void gimp_image_color_hash_invalidate (GimpImage *image,
|
||||
gint index);
|
||||
|
||||
gint gimp_image_color_hash_rgb_to_indexed (const GimpImage *image,
|
||||
gint r,
|
||||
gint g,
|
||||
gint b);
|
||||
|
||||
|
||||
#endif /* __GIMP_IMAGE_COLOR_HASH_H__ */
|
|
@ -41,7 +41,6 @@
|
|||
#include "gimperror.h"
|
||||
#include "gimpgrouplayer.h"
|
||||
#include "gimpimage.h"
|
||||
#include "gimpimage-colorhash.h"
|
||||
#include "gimpimage-merge.h"
|
||||
#include "gimpimage-undo.h"
|
||||
#include "gimpitemstack.h"
|
||||
|
|
|
@ -46,7 +46,6 @@
|
|||
#include "gimpguide.h"
|
||||
#include "gimpidtable.h"
|
||||
#include "gimpimage.h"
|
||||
#include "gimpimage-colorhash.h"
|
||||
#include "gimpimage-colormap.h"
|
||||
#include "gimpimage-guides.h"
|
||||
#include "gimpimage-sample-points.h"
|
||||
|
@ -596,8 +595,6 @@ gimp_image_class_init (GimpImageClass *klass)
|
|||
GIMP_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT));
|
||||
|
||||
gimp_image_color_hash_init ();
|
||||
|
||||
g_type_class_add_private (klass, sizeof (GimpImagePrivate));
|
||||
}
|
||||
|
||||
|
@ -1203,8 +1200,6 @@ gimp_image_real_colormap_changed (GimpImage *image,
|
|||
|
||||
if (gimp_image_base_type (image) == GIMP_INDEXED)
|
||||
{
|
||||
gimp_image_color_hash_invalidate (image, color_index);
|
||||
|
||||
/* A colormap alteration affects the whole image */
|
||||
gimp_image_invalidate (image,
|
||||
0, 0,
|
||||
|
|
Loading…
Reference in New Issue