mirror of https://github.com/GNOME/gimp.git
app: get rid of cpercep
This commit is contained in:
parent
f11ee4d82e
commit
b4e3843b6a
|
@ -23,8 +23,6 @@ libappbase_a_SOURCES = \
|
||||||
base-types.h \
|
base-types.h \
|
||||||
base-utils.c \
|
base-utils.c \
|
||||||
base-utils.h \
|
base-utils.h \
|
||||||
cpercep.c \
|
|
||||||
cpercep.h \
|
|
||||||
pixel-processor.c \
|
pixel-processor.c \
|
||||||
pixel-processor.h \
|
pixel-processor.h \
|
||||||
pixel-region.c \
|
pixel-region.c \
|
||||||
|
|
|
@ -1,98 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 1999-2002 Adam D. Moss (the "Author"). All Rights Reserved.
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is fur-
|
|
||||||
nished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
|
|
||||||
NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
||||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON-
|
|
||||||
NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
Except as contained in this notice, the name of the Author of the
|
|
||||||
Software shall not be used in advertising or otherwise to promote the sale,
|
|
||||||
use or other dealings in this Software without prior written authorization
|
|
||||||
from the Author.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
cpercep.c: The CPercep Functions v0.9: 2002-02-10
|
|
||||||
Adam D. Moss: adam@gimp.org <http://www.foxbox.org/adam/code/cpercep/>
|
|
||||||
|
|
||||||
This code module concerns itself with conversion from a hard-coded
|
|
||||||
RGB colour space (sRGB by default) to CIE L*a*b* and back again with
|
|
||||||
(primarily) precision and (secondarily) speed, oriented largely
|
|
||||||
towards the purposes of quantifying the PERCEPTUAL difference between
|
|
||||||
two arbitrary RGB colours with a minimum of fuss.
|
|
||||||
|
|
||||||
Motivation One: The author is disheartened at the amount of graphics
|
|
||||||
processing software around which uses weighted or non-weighted
|
|
||||||
Euclidean distance between co-ordinates within a (poorly-defined) RGB
|
|
||||||
space as the basis of what should really be an estimate of perceptual
|
|
||||||
difference to the human eye. Certainly it's fast to do it that way,
|
|
||||||
but please think carefully about whether your particular application
|
|
||||||
should be tolerating sloppy results for the sake of real-time response.
|
|
||||||
|
|
||||||
Motivation Two: Lack of tested, re-usable and free code available
|
|
||||||
for this purpose. The difficulty in finding something similar to
|
|
||||||
CPercep with a free license motivated this project; I hope that this
|
|
||||||
code also serves to illustrate how to perform the
|
|
||||||
R'G'B'->XYZ->L*a*b*->XYZ->R'G'B' transformation correctly since I
|
|
||||||
was distressed to note how many of the equations and code snippets
|
|
||||||
on the net were omitting the reverse transform and/or were using
|
|
||||||
incorrectly-derived or just plain wrong constants.
|
|
||||||
|
|
||||||
TODO: document functions, rename erroneously-named arguments
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include <babl/babl.h>
|
|
||||||
|
|
||||||
#include "cpercep.h"
|
|
||||||
|
|
||||||
void
|
|
||||||
cpercep_rgb_to_space (double inr,
|
|
||||||
double ing,
|
|
||||||
double inb,
|
|
||||||
double *outr,
|
|
||||||
double *outg,
|
|
||||||
double *outb)
|
|
||||||
{
|
|
||||||
float input[3] = {inr/255.0f, ing/255.0f, inb/255.0f};
|
|
||||||
float output[3];
|
|
||||||
babl_process (babl_fish (babl_format ("R'G'B' float"),
|
|
||||||
babl_format ("CIE Lab float")),
|
|
||||||
input, output, 1);
|
|
||||||
*outr = output[0];
|
|
||||||
*outg = output[1];
|
|
||||||
*outb = output[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
cpercep_space_to_rgb (double inr,
|
|
||||||
double ing,
|
|
||||||
double inb,
|
|
||||||
double *outr,
|
|
||||||
double *outg,
|
|
||||||
double *outb)
|
|
||||||
{
|
|
||||||
float input[3] = {inr, ing, inb};
|
|
||||||
float output[3];
|
|
||||||
babl_process (babl_fish (babl_format ("CIE Lab float"),
|
|
||||||
babl_format ("R'G'B' float")),
|
|
||||||
input, output, 1);
|
|
||||||
*outr = output[0] * 255;
|
|
||||||
*outg = output[1] * 255;
|
|
||||||
*outb = output[2] * 255;
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 1997-2002 Adam D. Moss (the "Author"). All Rights Reserved.
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is fur-
|
|
||||||
nished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
|
|
||||||
NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
||||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON-
|
|
||||||
NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
Except as contained in this notice, the name of the Author of the
|
|
||||||
Software shall not be used in advertising or otherwise to promote the sale,
|
|
||||||
use or other dealings in this Software without prior written authorization
|
|
||||||
from the Author.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
cpercep.c: The CPercep Functions v0.9: 2002-02-10
|
|
||||||
Adam D. Moss: adam@gimp.org <http://www.foxbox.org/adam/code/cpercep/>
|
|
||||||
|
|
||||||
TODO: document functions, rename erroneously-named arguments
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __CPERCEP_H__
|
|
||||||
#define __CPERCEP_H__
|
|
||||||
|
|
||||||
void cpercep_rgb_to_space (double inr,
|
|
||||||
double ing,
|
|
||||||
double inb,
|
|
||||||
double *outr,
|
|
||||||
double *outg,
|
|
||||||
double *outb);
|
|
||||||
|
|
||||||
void cpercep_space_to_rgb (double inr,
|
|
||||||
double ing,
|
|
||||||
double inb,
|
|
||||||
double *outr,
|
|
||||||
double *outg,
|
|
||||||
double *outb);
|
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
/* This is in the header so that it can potentially be inlined. */
|
|
||||||
static const double
|
|
||||||
cpercep_distance_space (const double L1, const double a1, const double b1,
|
|
||||||
const double L2, const double a2, const double b2)
|
|
||||||
{
|
|
||||||
const double Ld = L1 - L2;
|
|
||||||
const double ad = a1 - a2;
|
|
||||||
const double bd = b1 - b2;
|
|
||||||
|
|
||||||
return (Ld*Ld + ad*ad + bd*bd);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* __CPERCEP_H__ */
|
|
|
@ -142,9 +142,9 @@ calc_lab (const guchar *src,
|
||||||
{
|
{
|
||||||
case 3: /* RGB */
|
case 3: /* RGB */
|
||||||
case 4: /* RGBA */
|
case 4: /* RGBA */
|
||||||
rgb[0] = src[RED];
|
rgb[0] = src[RED]/255.0;
|
||||||
rgb[1] = src[GREEN];
|
rgb[1] = src[GREEN]/255.0;
|
||||||
rgb[2] = src[BLUE];
|
rgb[2] = src[BLUE]/255.0;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -152,15 +152,15 @@ calc_lab (const guchar *src,
|
||||||
{
|
{
|
||||||
gint i = *src * 3;
|
gint i = *src * 3;
|
||||||
|
|
||||||
rgb[0] = colormap[i + RED];
|
rgb[0] = colormap[i + RED] / 255.0;
|
||||||
rgb[1] = colormap[i + GREEN];
|
rgb[1] = colormap[i + GREEN] / 255.0;
|
||||||
rgb[2] = colormap[i + BLUE];
|
rgb[2] = colormap[i + BLUE] / 255.0;
|
||||||
}
|
}
|
||||||
else /* GRAY(A) */
|
else /* GRAY(A) */
|
||||||
{
|
{
|
||||||
rgb[0] = *src;
|
rgb[0] = *src / 255.0;
|
||||||
rgb[1] = *src;
|
rgb[1] = *src / 255.0;
|
||||||
rgb[2] = *src;
|
rgb[2] = *src / 255.0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -140,8 +140,6 @@
|
||||||
|
|
||||||
#include "core-types.h"
|
#include "core-types.h"
|
||||||
|
|
||||||
#include "base/cpercep.h"
|
|
||||||
|
|
||||||
#include "gegl/gimp-gegl-utils.h"
|
#include "gegl/gimp-gegl-utils.h"
|
||||||
|
|
||||||
#include "gimp.h"
|
#include "gimp.h"
|
||||||
|
@ -312,27 +310,19 @@ void rgb_to_unshifted_lin(const unsigned char r,
|
||||||
const unsigned char b,
|
const unsigned char b,
|
||||||
int *hr, int *hg, int *hb)
|
int *hr, int *hg, int *hb)
|
||||||
{
|
{
|
||||||
double sL, sa, sb;
|
|
||||||
int or, og, ob;
|
int or, og, ob;
|
||||||
|
float rgb[3] = {r/255.0, g/255.0, b/255.0};
|
||||||
|
float lab[3];
|
||||||
|
|
||||||
cpercep_rgb_to_space(r,g,b, &sL, &sa, &sb);
|
babl_process (babl_fish (babl_format ("R'G'B' float"),
|
||||||
|
babl_format ("CIE Lab float")),
|
||||||
|
rgb, lab, 1);
|
||||||
|
|
||||||
/* fprintf(stderr, " %d-%d-%d -> %0.3f,%0.3f,%0.3f ", r, g, b, sL, sa, sb);*/
|
/* fprintf(stderr, " %d-%d-%d -> %0.3f,%0.3f,%0.3f ", r, g, b, sL, sa, sb);*/
|
||||||
|
|
||||||
or = RINT(sL * LRAT);
|
or = RINT(lab[0] * LRAT);
|
||||||
og = RINT((sa - LOWA) * ARAT);
|
og = RINT((lab[1] - LOWA) * ARAT);
|
||||||
ob = RINT((sb - LOWB) * BRAT);
|
ob = RINT((lab[2] - LOWB) * BRAT);
|
||||||
|
|
||||||
/* fprintf(stderr, " %d-%d-%d ", or, og, ob); */
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
if (or < 0 || or > 255)
|
|
||||||
fprintf(stderr, " \007R%d ", or);
|
|
||||||
if (og < 0 || og > 255)
|
|
||||||
fprintf(stderr, " \007G%d ", og);
|
|
||||||
if (ob < 0 || ob > 255)
|
|
||||||
fprintf(stderr, " \007B%d ", ob);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
*hr = CLAMP(or, 0, 255);
|
*hr = CLAMP(or, 0, 255);
|
||||||
*hg = CLAMP(og, 0, 255);
|
*hg = CLAMP(og, 0, 255);
|
||||||
|
@ -429,36 +419,29 @@ void lin_to_rgb(const double hr, const double hg, const double hb,
|
||||||
unsigned char *g,
|
unsigned char *g,
|
||||||
unsigned char *b)
|
unsigned char *b)
|
||||||
{
|
{
|
||||||
double sr,sg,sb;
|
float rgb[3];
|
||||||
|
float lab[3];
|
||||||
double ir,ig,ib;
|
double ir,ig,ib;
|
||||||
|
|
||||||
/* fprintf(stderr, "%d.%d.%d ", hr,hg,hb); */
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
ir = (hr * ((double) (1 << R_SHIFT))) + (((double)(1<<R_SHIFT))*0.5);
|
|
||||||
ig = (hg * ((double) (1 << G_SHIFT))) + (((double)(1<<G_SHIFT))*0.5);
|
|
||||||
ib = (hb * ((double) (1 << B_SHIFT))) + (((double)(1<<B_SHIFT))*0.5);
|
|
||||||
#else
|
|
||||||
/* w/ artificial widening of dynamic range */
|
|
||||||
ir = ((double)(hr)) * 255.0F / (double)(HIST_R_ELEMS-1);
|
ir = ((double)(hr)) * 255.0F / (double)(HIST_R_ELEMS-1);
|
||||||
ig = ((double)(hg)) * 255.0F / (double)(HIST_G_ELEMS-1);
|
ig = ((double)(hg)) * 255.0F / (double)(HIST_G_ELEMS-1);
|
||||||
ib = ((double)(hb)) * 255.0F / (double)(HIST_B_ELEMS-1);
|
ib = ((double)(hb)) * 255.0F / (double)(HIST_B_ELEMS-1);
|
||||||
#endif
|
|
||||||
|
|
||||||
ir = ir / LRAT;
|
ir = ir / LRAT;
|
||||||
ig = (ig / ARAT) + LOWA;
|
ig = (ig / ARAT) + LOWA;
|
||||||
ib = (ib / BRAT) + LOWB;
|
ib = (ib / BRAT) + LOWB;
|
||||||
|
|
||||||
/* fprintf(stderr, "%0.1f,%0.1f,%0.1f ", ir,ig,ib); */
|
lab[0] = ir;
|
||||||
|
lab[1] = ig;
|
||||||
|
lab[2] = ib;
|
||||||
|
|
||||||
cpercep_space_to_rgb(ir, ig, ib,
|
babl_process (babl_fish (babl_format ("CIE Lab float"),
|
||||||
&sr, &sg, &sb);
|
babl_format ("R'G'B' float")),
|
||||||
|
lab, rgb, 1);
|
||||||
|
|
||||||
*r = RINT(CLAMP(sr, 0.0F, 255.0F));
|
*r = RINT(CLAMP(rgb[0]*255, 0.0F, 255.0F));
|
||||||
*g = RINT(CLAMP(sg, 0.0F, 255.0F));
|
*g = RINT(CLAMP(rgb[1]*255, 0.0F, 255.0F));
|
||||||
*b = RINT(CLAMP(sb, 0.0F, 255.0F));
|
*b = RINT(CLAMP(rgb[2]*255, 0.0F, 255.0F));
|
||||||
|
|
||||||
/* fprintf(stderr, "%d,%d,%d ", *r, *g, *b); */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue