Integrate YCoCg color space conversion by Jim Tilander.
This commit is contained in:
parent
a889f2fda6
commit
c562af6d9b
@ -82,11 +82,12 @@
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Debug|x64"
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(ConfigurationName)\$(PlatformName)"
|
||||
IntermediateDirectory="$(ConfigurationName)\$(PlatformName)"
|
||||
ConfigurationType="4"
|
||||
CharacterSet="0"
|
||||
CharacterSet="2"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
@ -102,16 +103,12 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TargetEnvironment="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..;..\..\..\src;..\..\..\gnuwin32\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;__SSE2__;__SSE__;__MMX__"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;__SSE2__;__SSE__;__MMX__"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
@ -146,12 +143,11 @@
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
Name="Debug|x64"
|
||||
OutputDirectory="$(ConfigurationName)\$(PlatformName)"
|
||||
IntermediateDirectory="$(ConfigurationName)\$(PlatformName)"
|
||||
ConfigurationType="4"
|
||||
CharacterSet="2"
|
||||
WholeProgramOptimization="1"
|
||||
CharacterSet="0"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
@ -167,12 +163,16 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TargetEnvironment="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..;..\..\..\src;..\..\..\gnuwin32\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;__SSE2__;__SSE__;__MMX__"
|
||||
RuntimeLibrary="2"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;__SSE2__;__SSE__;__MMX__"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
@ -285,6 +285,10 @@
|
||||
RelativePath="..\..\..\src\nvimage\ColorBlock.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\src\nvimage\ColorSpace.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\src\nvimage\DirectDrawSurface.cpp"
|
||||
>
|
||||
@ -327,6 +331,10 @@
|
||||
RelativePath="..\..\..\src\nvimage\ColorBlock.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\src\nvimage\ColorSpace.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\..\src\nvimage\DirectDrawSurface.h"
|
||||
>
|
||||
|
@ -25,7 +25,9 @@ SET(IMAGE_SRCS
|
||||
NormalMipmap.h
|
||||
NormalMipmap.cpp
|
||||
PsdFile.h
|
||||
TgaFile.h)
|
||||
TgaFile.h
|
||||
ColorSpace.h
|
||||
ColorSpace.cpp)
|
||||
|
||||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
|
66
src/nvimage/ColorSpace.cpp
Normal file
66
src/nvimage/ColorSpace.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
#include "ColorSpace.h"
|
||||
#include <nvmath/Color.h>
|
||||
#include <nvimage/Image.h>
|
||||
#include <nvcore/nvcore.h>
|
||||
|
||||
namespace nv
|
||||
{
|
||||
void ColorSpace::RGBtoYCoCg_R(Image* img)
|
||||
{
|
||||
const uint w = img->width();
|
||||
const uint h = img->height();
|
||||
|
||||
for( uint y=0; y < h; y++ )
|
||||
{
|
||||
for( uint x=0; x < w; x++ )
|
||||
{
|
||||
Color32 pixel = img->pixel(x, y);
|
||||
|
||||
const int r = pixel.r;
|
||||
const int g = pixel.g;
|
||||
const int b = pixel.b;
|
||||
|
||||
const int Co = r - b;
|
||||
const int t = b + Co/2;
|
||||
const int Cg = g - t;
|
||||
const int Y = t + Cg/2;
|
||||
|
||||
// Just saturate the chroma here (we loose out of one bit in each channel)
|
||||
// this just means that we won't have as high dynamic range. Perhaps a better option
|
||||
// is to loose the least significant bit instead?
|
||||
pixel.r = clamp(Co + 128, 0, 255);
|
||||
pixel.g = clamp(Cg + 128, 0, 255);
|
||||
pixel.b = 0;
|
||||
pixel.a = Y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ColorSpace::YCoCg_RtoRGB(Image* img)
|
||||
{
|
||||
const uint w = img->width();
|
||||
const uint h = img->height();
|
||||
|
||||
for( uint y=0; y < h; y++ )
|
||||
{
|
||||
for( uint x=0; x < w; x++ )
|
||||
{
|
||||
Color32 pixel = img->pixel(x, y);
|
||||
|
||||
const int Co = (int)pixel.r - 128;
|
||||
const int Cg = (int)pixel.g - 128;
|
||||
const int Y = pixel.a;
|
||||
|
||||
const int t = Y - Cg/2;
|
||||
const int g = Cg + t;
|
||||
const int b = t - Co/2;
|
||||
const int r = b + Co;
|
||||
|
||||
pixel.r = r;
|
||||
pixel.g = g;
|
||||
pixel.b = b;
|
||||
pixel.a = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
20
src/nvimage/ColorSpace.h
Normal file
20
src/nvimage/ColorSpace.h
Normal file
@ -0,0 +1,20 @@
|
||||
|
||||
#ifndef NV_IMAGE_COLORSPACE_H
|
||||
#define NV_IMAGE_COLORSPACE_H
|
||||
|
||||
namespace nv
|
||||
{
|
||||
class Image;
|
||||
|
||||
// Defines simple mappings between different color spaces and encodes them in the
|
||||
// input image.
|
||||
namespace ColorSpace
|
||||
{
|
||||
void RGBtoYCoCg_R(Image* img);
|
||||
void YCoCg_RtoRGB(Image* img);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -34,6 +34,7 @@
|
||||
#include <nvimage/Filter.h>
|
||||
#include <nvimage/Quantize.h>
|
||||
#include <nvimage/NormalMap.h>
|
||||
#include <nvimage/ColorSpace.h>
|
||||
|
||||
#include "Compressor.h"
|
||||
#include "InputOptions.h"
|
||||
@ -482,6 +483,17 @@ bool Compressor::Private::initMipmap(Mipmap & mipmap, const InputOptions::Privat
|
||||
premultiplyAlphaMipmap(mipmap, inputOptions);
|
||||
}
|
||||
|
||||
// Apply gamma space color transforms:
|
||||
if (inputOptions.colorTransform == ColorTransform_YCoCg)
|
||||
{
|
||||
ColorSpace::RGBtoYCoCg_R(mipmap.asMutableFixedImage());
|
||||
}
|
||||
else if (inputOptions.colorTransform == ColorTransform_ScaledYCoCg)
|
||||
{
|
||||
// @@ TODO
|
||||
//ColorSpace::RGBtoYCoCg_R(mipmap.asMutableFixedImage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -156,8 +156,10 @@ namespace nvtt
|
||||
enum ColorTransform
|
||||
{
|
||||
ColorTransform_None,
|
||||
ColorTransform_Linear,
|
||||
ColorTransform_Swizzle
|
||||
ColorTransform_Linear, ///< Not implemented.
|
||||
ColorTransform_Swizzle, ///< Not implemented.
|
||||
ColorTransform_YCoCg, ///< Transform into r=Co, g=Cg, b=0, a=Y
|
||||
ColorTransform_ScaledYCoCg, ///< Not implemented.
|
||||
};
|
||||
|
||||
/// Extents rounding mode.
|
||||
|
Loading…
Reference in New Issue
Block a user