|
Packit Service |
2781ba |
/* This file is part of GEGL
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* GEGL is free software; you can redistribute it and/or
|
|
Packit Service |
2781ba |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
2781ba |
* License as published by the Free Software Foundation; either
|
|
Packit Service |
2781ba |
* version 3 of the License, or (at your option) any later version.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* GEGL is distributed in the hope that it will be useful,
|
|
Packit Service |
2781ba |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
2781ba |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
2781ba |
* Lesser General Public License for more details.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
2781ba |
* License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* Copyright 2009 Øyvind Kolås
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#ifndef __GEGL_LOOKUP_H__
|
|
Packit Service |
2781ba |
#define __GEGL_LOOKUP_H__
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
G_BEGIN_DECLS
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
typedef gfloat (* GeglLookupFunction) (gfloat value,
|
|
Packit Service |
2781ba |
gpointer data);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#define GEGL_LOOKUP_MAX_ENTRIES (819200)
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
typedef struct GeglLookup
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglLookupFunction function;
|
|
Packit Service |
2781ba |
gpointer data;
|
|
Packit Service |
2781ba |
gint shift;
|
|
Packit Service |
2781ba |
guint32 positive_min, positive_max, negative_min, negative_max;
|
|
Packit Service |
2781ba |
guint32 bitmask[GEGL_LOOKUP_MAX_ENTRIES/32];
|
|
Packit Service |
2781ba |
gfloat table[];
|
|
Packit Service |
2781ba |
} GeglLookup;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
GeglLookup *gegl_lookup_new_full (GeglLookupFunction function,
|
|
Packit Service |
2781ba |
gpointer data,
|
|
Packit Service |
2781ba |
gfloat start,
|
|
Packit Service |
2781ba |
gfloat end,
|
|
Packit Service |
2781ba |
gfloat precision);
|
|
Packit Service |
2781ba |
GeglLookup *gegl_lookup_new (GeglLookupFunction function,
|
|
Packit Service |
2781ba |
gpointer data);
|
|
Packit Service |
2781ba |
void gegl_lookup_free (GeglLookup *lookup);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static inline gfloat
|
|
Packit Service |
2781ba |
gegl_lookup (GeglLookup *lookup,
|
|
Packit Service |
2781ba |
gfloat number)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
union
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
float f;
|
|
Packit Service |
2781ba |
guint32 i;
|
|
Packit Service |
2781ba |
} u;
|
|
Packit Service |
2781ba |
guint i;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
u.f = number;
|
|
Packit Service |
2781ba |
i = u.i >> lookup->shift;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (i > lookup->positive_min &&
|
|
Packit Service |
2781ba |
i < lookup->positive_max)
|
|
Packit Service |
2781ba |
i = i - lookup->positive_min;
|
|
Packit Service |
2781ba |
else if (i > lookup->negative_min &&
|
|
Packit Service |
2781ba |
i < lookup->negative_max)
|
|
Packit Service |
2781ba |
i = i - lookup->negative_min + (lookup->positive_max - lookup->positive_min);
|
|
Packit Service |
2781ba |
else
|
|
Packit Service |
2781ba |
return lookup->function (number, lookup->data);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (!(lookup->bitmask[i/32] & (1<<(i & 31))))
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
lookup->table[i]= lookup->function (number, lookup->data);
|
|
Packit Service |
2781ba |
lookup->bitmask[i/32] |= (1<<(i & 31));
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
return lookup->table[i];
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
G_END_DECLS
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#endif
|