Add perceptual color distance function.
This commit is contained in:
parent
26283c8c25
commit
5cf219a22e
@ -2,29 +2,18 @@ PROJECT(nvimage)
|
||||
|
||||
SET(IMAGE_SRCS
|
||||
nvimage.h
|
||||
FloatImage.h
|
||||
FloatImage.cpp
|
||||
Filter.h
|
||||
Filter.cpp
|
||||
Image.h
|
||||
Image.cpp
|
||||
ImageIO.h
|
||||
ImageIO.cpp
|
||||
ColorBlock.h
|
||||
ColorBlock.cpp
|
||||
BlockDXT.h
|
||||
BlockDXT.cpp
|
||||
DirectDrawSurface.h
|
||||
DirectDrawSurface.cpp
|
||||
Quantize.h
|
||||
Quantize.cpp
|
||||
NormalMap.h
|
||||
NormalMap.cpp
|
||||
PsdFile.h
|
||||
TgaFile.h
|
||||
BlockDXT.h BlockDXT.cpp
|
||||
ColorBlock.h ColorBlock.cpp
|
||||
DirectDrawSurface.h DirectDrawSurface.cpp
|
||||
Filter.h Filter.cpp
|
||||
FloatImage.h FloatImage.cpp
|
||||
Image.h Image.cpp
|
||||
ImageIO.h ImageIO.cpp
|
||||
NormalMap.h NormalMap.cpp
|
||||
PixelFormat.h
|
||||
ColorSpace.h
|
||||
ColorSpace.cpp)
|
||||
PsdFile.h
|
||||
Quantize.h Quantize.cpp
|
||||
TgaFile.h)
|
||||
|
||||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
|
@ -175,6 +175,16 @@ namespace nv
|
||||
return Vector4(c.r * scale, c.g * scale, c.b * scale, c.a * scale);
|
||||
}
|
||||
|
||||
|
||||
inline float perceptualColorDistance(Vector3::Arg c0, Vector3::Arg c1)
|
||||
{
|
||||
float rmean = (c0.r + c1.r) * 0.5f;
|
||||
float r = c1.r - c0.r;
|
||||
float g = c1.g - c0.g;
|
||||
float b = c1.b - c0.b;
|
||||
return sqrtf((2 + rmean)*r*r + 4*g*g + (3 - rmean)*b*b);
|
||||
}
|
||||
|
||||
} // nv namespace
|
||||
|
||||
#endif // NV_MATH_COLOR_H
|
||||
|
@ -86,7 +86,7 @@ void CompressionOptions::setQuality(Quality quality)
|
||||
|
||||
|
||||
/// Set the weights of each color channel.
|
||||
/// The choice for these values is subjective. In many case uniform color weights
|
||||
/// The choice for these values is subjective. In most cases uniform color weights
|
||||
/// (1.0, 1.0, 1.0) work very well. A popular choice is to use the NTSC luma encoding
|
||||
/// weights (0.2126, 0.7152, 0.0722), but I think that blue contributes to our
|
||||
/// perception more than a 7%. A better choice in my opinion is (3, 4, 2).
|
||||
|
Loading…
Reference in New Issue
Block a user