Better color distance-measuring algorithm, taken from here:
http://www.stud.uni-hannover.de/~michaelt/juggle/Algorithms.pdf. Still not 100% identical to be's one, but much closer. Small cleanups. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13091 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Copyright (c) 2001-2002, Haiku, Inc.
|
// Copyright (c) 2001-2005, Haiku, Inc.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
// copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -20,19 +20,13 @@
|
|||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
// File Name: SystemPalette.cpp
|
// File Name: SystemPalette.cpp
|
||||||
// Author: DarkWyrm <[email protected]>
|
// Authors: DarkWyrm <[email protected]>
|
||||||
|
// Stefano Ceccherini <[email protected]>
|
||||||
// Description: One global function to generate the palette which is
|
// Description: One global function to generate the palette which is
|
||||||
// the default BeOS System palette and the variable to go with it
|
// the default BeOS System palette and the variable to go with it
|
||||||
//
|
//
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
#include <SystemPalette.h>
|
||||||
// Local Includes --------------------------------------------------------------
|
|
||||||
#include "SystemPalette.h"
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: BWindowScreen has a method to set the palette.
|
|
||||||
// maybe we should have a lock to protect this variable.
|
|
||||||
static color_map sColorMap;
|
|
||||||
|
|
||||||
const static rgb_color kSystemPalette[] = {
|
const static rgb_color kSystemPalette[] = {
|
||||||
{ 0, 0, 0, 255 }, { 8, 8, 8, 255 }, { 16, 16, 16, 255 },
|
{ 0, 0, 0, 255 }, { 8, 8, 8, 255 }, { 16, 16, 16, 255 },
|
||||||
@@ -124,6 +118,11 @@ const static rgb_color kSystemPalette[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: BWindowScreen has a method to set the palette.
|
||||||
|
// maybe we should have a lock to protect this variable.
|
||||||
|
static color_map sColorMap;
|
||||||
|
|
||||||
|
|
||||||
// color_distance
|
// color_distance
|
||||||
/*! \brief Returns the "distance" between two RGB colors.
|
/*! \brief Returns the "distance" between two RGB colors.
|
||||||
|
|
||||||
@@ -143,17 +142,20 @@ unsigned
|
|||||||
color_distance(uint8 red1, uint8 green1, uint8 blue1,
|
color_distance(uint8 red1, uint8 green1, uint8 blue1,
|
||||||
uint8 red2, uint8 green2, uint8 blue2)
|
uint8 red2, uint8 green2, uint8 blue2)
|
||||||
{
|
{
|
||||||
// euklidian distance (its square actually)
|
|
||||||
int rd = (int)red1 - (int)red2;
|
int rd = (int)red1 - (int)red2;
|
||||||
int gd = (int)green1 - (int)green2;
|
int gd = (int)green1 - (int)green2;
|
||||||
int bd = (int)blue1 - (int)blue2;
|
int bd = (int)blue1 - (int)blue2;
|
||||||
// return rd * rd + gd * gd + bd * bd;
|
|
||||||
|
|
||||||
// distance according to psycho-visual tests
|
// distance according to psycho-visual tests
|
||||||
int rmean = ((int)red1 + (int)red2) / 2;
|
int rmean = ((int)red1 + (int)red2) / 2;
|
||||||
|
#if 0
|
||||||
return (((512 + rmean) * rd * rd) >> 8)
|
return (((512 + rmean) * rd * rd) >> 8)
|
||||||
+ 4 * gd * gd
|
+ 4 * gd * gd
|
||||||
+ (((767 - rmean) * bd * bd) >> 8);
|
+ (((767 - rmean) * bd * bd) >> 8);
|
||||||
|
#endif
|
||||||
|
return (2 + rmean / 256) * rd * rd
|
||||||
|
+ 4 * gd * gd
|
||||||
|
+ (2 + (255 - rmean) / 256) * bd * bd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -192,6 +194,7 @@ InvertColor(const rgb_color &color)
|
|||||||
inverted.red = 255 - color.red;
|
inverted.red = 255 - color.red;
|
||||||
inverted.green = 255 - color.green;
|
inverted.green = 255 - color.green;
|
||||||
inverted.blue = 255 - color.blue;
|
inverted.blue = 255 - color.blue;
|
||||||
|
inverted.alpha = 255;
|
||||||
|
|
||||||
return inverted;
|
return inverted;
|
||||||
}
|
}
|
||||||
@@ -213,8 +216,7 @@ FillColorMap(const rgb_color *palette, color_map *map)
|
|||||||
rgbColor.green |= rgbColor.green >> 5;
|
rgbColor.green |= rgbColor.green >> 5;
|
||||||
rgbColor.blue |= rgbColor.blue >> 5;
|
rgbColor.blue |= rgbColor.blue >> 5;
|
||||||
|
|
||||||
uint8 closestIndex = FindClosestColor(rgbColor, palette);
|
map->index_map[color] = FindClosestColor(rgbColor, palette);
|
||||||
map->index_map[color] = closestIndex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// init inversion map
|
// init inversion map
|
||||||
|
|||||||
Reference in New Issue
Block a user