2014-12-07 19:09:38 -05:00
|
|
|
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
#include "Core.h"
|
|
|
|
|
#include "ModuleInterface.h"
|
|
|
|
|
#include "ModuleManager.h"
|
|
|
|
|
#include "TargetPlatform.h"
|
|
|
|
|
#include "TextureCompressorModule.h"
|
|
|
|
|
#include "PixelFormat.h"
|
|
|
|
|
#include "ImageCore.h"
|
|
|
|
|
|
|
|
|
|
DEFINE_LOG_CATEGORY_STATIC(LogTextureFormatUncompressed, Log, All);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Macro trickery for supported format names.
|
|
|
|
|
*/
|
|
|
|
|
#define ENUM_SUPPORTED_FORMATS(op) \
|
|
|
|
|
op(BGRA8) \
|
|
|
|
|
op(G8) \
|
|
|
|
|
op(VU8) \
|
|
|
|
|
op(RGBA16F) \
|
2014-05-22 09:13:12 -04:00
|
|
|
op(XGXR8) \
|
2015-06-15 15:39:57 -04:00
|
|
|
op(RGBA8) \
|
|
|
|
|
op(POTERROR)
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
#define DECL_FORMAT_NAME(FormatName) static FName GTextureFormatName##FormatName = FName(TEXT(#FormatName));
|
|
|
|
|
ENUM_SUPPORTED_FORMATS(DECL_FORMAT_NAME);
|
|
|
|
|
#undef DECL_FORMAT_NAME
|
|
|
|
|
|
|
|
|
|
#define DECL_FORMAT_NAME_ENTRY(FormatName) GTextureFormatName##FormatName ,
|
|
|
|
|
static FName GSupportedTextureFormatNames[] =
|
|
|
|
|
{
|
|
|
|
|
ENUM_SUPPORTED_FORMATS(DECL_FORMAT_NAME_ENTRY)
|
|
|
|
|
};
|
|
|
|
|
#undef DECL_FORMAT_NAME_ENTRY
|
|
|
|
|
|
|
|
|
|
#undef ENUM_SUPPORTED_FORMATS
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Uncompressed texture format handler.
|
|
|
|
|
*/
|
|
|
|
|
class FTextureFormatUncompressed : public ITextureFormat
|
|
|
|
|
{
|
2014-06-13 06:14:46 -04:00
|
|
|
virtual bool AllowParallelBuild() const override
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-13 06:14:46 -04:00
|
|
|
virtual uint16 GetVersion(FName Format) const override
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-13 06:14:46 -04:00
|
|
|
virtual void GetSupportedFormats(TArray<FName>& OutFormats) const override
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
for (int32 i = 0; i < ARRAY_COUNT(GSupportedTextureFormatNames); ++i)
|
|
|
|
|
{
|
|
|
|
|
OutFormats.Add(GSupportedTextureFormatNames[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-23 20:04:50 -04:00
|
|
|
|
2014-06-13 06:14:46 -04:00
|
|
|
virtual FTextureFormatCompressorCaps GetFormatCapabilities() const override
|
2014-04-23 20:04:50 -04:00
|
|
|
{
|
|
|
|
|
return FTextureFormatCompressorCaps(); // Default capabilities.
|
|
|
|
|
}
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
virtual bool CompressImage(
|
|
|
|
|
const FImage& InImage,
|
|
|
|
|
const struct FTextureBuildSettings& BuildSettings,
|
|
|
|
|
bool bImageHasAlphaChannel,
|
|
|
|
|
FCompressedImage2D& OutCompressedImage
|
2014-06-13 06:14:46 -04:00
|
|
|
) const override
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
if (BuildSettings.TextureFormatName == GTextureFormatNameG8)
|
|
|
|
|
{
|
|
|
|
|
FImage Image;
|
Gamma Correction - Changing the way all FColors are converted into FLinearColor by default. Previously all sRGB textures coming into the engine along with all other usage of FColor -> FLinearColor used a lookup table that assumed the final gamma correction would simply be pow(color, 1/DisplayGamma). However, that's not the case, we use the IEC 61966-2-1 standard on most platforms for both the scene renderer, as well as for gamma correction in Slate. In Slate you should now see an image matching Photoshop instead of being slightly darker in the lower ranges. However, because we don't want to invalidate all existing textures that users have authored, all existing UTextures have a UseLegacyGamma flag set to true, all new textures will be set to false. The flag is part of the DDC key calculation, but steps were taken so that when legacy is true, keys match existing keys to prevent universally invalidating all games DDCs just to make this change.
To summarize,
Old Pipeline: sRGB-Pow(2.2) -> Linear -> sRGB-IEC 61966
New Pipeline: sRGB-IEC 61966 -> Linear -> sRGB-IEC 61966
#codereview gil.gribb, nick.penwarden, martin.mittring
[CL 2571070 by Nick Darnell in Main branch]
2015-05-29 16:03:43 -04:00
|
|
|
InImage.CopyTo(Image, ERawImageFormat::G8, BuildSettings.GetGammaSpace());
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
OutCompressedImage.SizeX = Image.SizeX;
|
|
|
|
|
OutCompressedImage.SizeY = Image.SizeY;
|
|
|
|
|
OutCompressedImage.PixelFormat = PF_G8;
|
|
|
|
|
OutCompressedImage.RawData = Image.RawData;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (BuildSettings.TextureFormatName == GTextureFormatNameVU8)
|
|
|
|
|
{
|
|
|
|
|
FImage Image;
|
Gamma Correction - Changing the way all FColors are converted into FLinearColor by default. Previously all sRGB textures coming into the engine along with all other usage of FColor -> FLinearColor used a lookup table that assumed the final gamma correction would simply be pow(color, 1/DisplayGamma). However, that's not the case, we use the IEC 61966-2-1 standard on most platforms for both the scene renderer, as well as for gamma correction in Slate. In Slate you should now see an image matching Photoshop instead of being slightly darker in the lower ranges. However, because we don't want to invalidate all existing textures that users have authored, all existing UTextures have a UseLegacyGamma flag set to true, all new textures will be set to false. The flag is part of the DDC key calculation, but steps were taken so that when legacy is true, keys match existing keys to prevent universally invalidating all games DDCs just to make this change.
To summarize,
Old Pipeline: sRGB-Pow(2.2) -> Linear -> sRGB-IEC 61966
New Pipeline: sRGB-IEC 61966 -> Linear -> sRGB-IEC 61966
#codereview gil.gribb, nick.penwarden, martin.mittring
[CL 2571070 by Nick Darnell in Main branch]
2015-05-29 16:03:43 -04:00
|
|
|
InImage.CopyTo(Image, ERawImageFormat::BGRA8, BuildSettings.GetGammaSpace());
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
OutCompressedImage.SizeX = Image.SizeX;
|
|
|
|
|
OutCompressedImage.SizeY = Image.SizeY;
|
|
|
|
|
OutCompressedImage.PixelFormat = PF_V8U8;
|
|
|
|
|
|
|
|
|
|
uint32 NumTexels = Image.SizeX * Image.SizeY * Image.NumSlices;
|
|
|
|
|
OutCompressedImage.RawData.Empty(NumTexels * 2);
|
|
|
|
|
OutCompressedImage.RawData.AddUninitialized(NumTexels * 2);
|
|
|
|
|
const FColor* FirstColor = Image.AsBGRA8();
|
|
|
|
|
const FColor* LastColor = FirstColor + NumTexels;
|
2014-09-29 04:23:44 -04:00
|
|
|
int8* Dest = (int8*)OutCompressedImage.RawData.GetData();
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
for (const FColor* Color = FirstColor; Color < LastColor; ++Color)
|
|
|
|
|
{
|
|
|
|
|
*Dest++ = (int32)Color->R - 128;
|
|
|
|
|
*Dest++ = (int32)Color->G - 128;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (BuildSettings.TextureFormatName == GTextureFormatNameBGRA8)
|
|
|
|
|
{
|
|
|
|
|
FImage Image;
|
Gamma Correction - Changing the way all FColors are converted into FLinearColor by default. Previously all sRGB textures coming into the engine along with all other usage of FColor -> FLinearColor used a lookup table that assumed the final gamma correction would simply be pow(color, 1/DisplayGamma). However, that's not the case, we use the IEC 61966-2-1 standard on most platforms for both the scene renderer, as well as for gamma correction in Slate. In Slate you should now see an image matching Photoshop instead of being slightly darker in the lower ranges. However, because we don't want to invalidate all existing textures that users have authored, all existing UTextures have a UseLegacyGamma flag set to true, all new textures will be set to false. The flag is part of the DDC key calculation, but steps were taken so that when legacy is true, keys match existing keys to prevent universally invalidating all games DDCs just to make this change.
To summarize,
Old Pipeline: sRGB-Pow(2.2) -> Linear -> sRGB-IEC 61966
New Pipeline: sRGB-IEC 61966 -> Linear -> sRGB-IEC 61966
#codereview gil.gribb, nick.penwarden, martin.mittring
[CL 2571070 by Nick Darnell in Main branch]
2015-05-29 16:03:43 -04:00
|
|
|
InImage.CopyTo(Image, ERawImageFormat::BGRA8, BuildSettings.GetGammaSpace());
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
OutCompressedImage.SizeX = Image.SizeX;
|
|
|
|
|
OutCompressedImage.SizeY = Image.SizeY;
|
|
|
|
|
OutCompressedImage.PixelFormat = PF_B8G8R8A8;
|
|
|
|
|
OutCompressedImage.RawData = Image.RawData;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-05-22 09:13:12 -04:00
|
|
|
else if (BuildSettings.TextureFormatName == GTextureFormatNameRGBA8)
|
|
|
|
|
{
|
|
|
|
|
FImage Image;
|
Gamma Correction - Changing the way all FColors are converted into FLinearColor by default. Previously all sRGB textures coming into the engine along with all other usage of FColor -> FLinearColor used a lookup table that assumed the final gamma correction would simply be pow(color, 1/DisplayGamma). However, that's not the case, we use the IEC 61966-2-1 standard on most platforms for both the scene renderer, as well as for gamma correction in Slate. In Slate you should now see an image matching Photoshop instead of being slightly darker in the lower ranges. However, because we don't want to invalidate all existing textures that users have authored, all existing UTextures have a UseLegacyGamma flag set to true, all new textures will be set to false. The flag is part of the DDC key calculation, but steps were taken so that when legacy is true, keys match existing keys to prevent universally invalidating all games DDCs just to make this change.
To summarize,
Old Pipeline: sRGB-Pow(2.2) -> Linear -> sRGB-IEC 61966
New Pipeline: sRGB-IEC 61966 -> Linear -> sRGB-IEC 61966
#codereview gil.gribb, nick.penwarden, martin.mittring
[CL 2571070 by Nick Darnell in Main branch]
2015-05-29 16:03:43 -04:00
|
|
|
InImage.CopyTo(Image, ERawImageFormat::BGRA8, BuildSettings.GetGammaSpace());
|
2014-05-22 09:13:12 -04:00
|
|
|
|
|
|
|
|
OutCompressedImage.SizeX = Image.SizeX;
|
|
|
|
|
OutCompressedImage.SizeY = Image.SizeY;
|
|
|
|
|
OutCompressedImage.PixelFormat = PF_B8G8R8A8;
|
|
|
|
|
|
|
|
|
|
// swizzle each texel
|
|
|
|
|
uint32 NumTexels = Image.SizeX * Image.SizeY * Image.NumSlices;
|
|
|
|
|
OutCompressedImage.RawData.Empty(NumTexels * 4);
|
|
|
|
|
OutCompressedImage.RawData.AddUninitialized(NumTexels * 4);
|
|
|
|
|
const FColor* FirstColor = Image.AsBGRA8();
|
|
|
|
|
const FColor* LastColor = FirstColor + NumTexels;
|
2014-09-29 04:23:44 -04:00
|
|
|
int8* Dest = (int8*)OutCompressedImage.RawData.GetData();
|
2014-05-22 09:13:12 -04:00
|
|
|
|
|
|
|
|
for (const FColor* Color = FirstColor; Color < LastColor; ++Color)
|
|
|
|
|
{
|
|
|
|
|
*Dest++ = (int32)Color->R;
|
|
|
|
|
*Dest++ = (int32)Color->G;
|
|
|
|
|
*Dest++ = (int32)Color->B;
|
|
|
|
|
*Dest++ = (int32)Color->A;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-03-14 14:13:41 -04:00
|
|
|
else if (BuildSettings.TextureFormatName == GTextureFormatNameXGXR8)
|
|
|
|
|
{
|
|
|
|
|
FImage Image;
|
Gamma Correction - Changing the way all FColors are converted into FLinearColor by default. Previously all sRGB textures coming into the engine along with all other usage of FColor -> FLinearColor used a lookup table that assumed the final gamma correction would simply be pow(color, 1/DisplayGamma). However, that's not the case, we use the IEC 61966-2-1 standard on most platforms for both the scene renderer, as well as for gamma correction in Slate. In Slate you should now see an image matching Photoshop instead of being slightly darker in the lower ranges. However, because we don't want to invalidate all existing textures that users have authored, all existing UTextures have a UseLegacyGamma flag set to true, all new textures will be set to false. The flag is part of the DDC key calculation, but steps were taken so that when legacy is true, keys match existing keys to prevent universally invalidating all games DDCs just to make this change.
To summarize,
Old Pipeline: sRGB-Pow(2.2) -> Linear -> sRGB-IEC 61966
New Pipeline: sRGB-IEC 61966 -> Linear -> sRGB-IEC 61966
#codereview gil.gribb, nick.penwarden, martin.mittring
[CL 2571070 by Nick Darnell in Main branch]
2015-05-29 16:03:43 -04:00
|
|
|
InImage.CopyTo(Image, ERawImageFormat::BGRA8, BuildSettings.GetGammaSpace());
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
OutCompressedImage.SizeX = Image.SizeX;
|
|
|
|
|
OutCompressedImage.SizeY = Image.SizeY;
|
|
|
|
|
OutCompressedImage.PixelFormat = PF_B8G8R8A8;
|
|
|
|
|
|
|
|
|
|
// swizzle each texel
|
|
|
|
|
uint32 NumTexels = Image.SizeX * Image.SizeY * Image.NumSlices;
|
|
|
|
|
OutCompressedImage.RawData.Empty(NumTexels * 4);
|
|
|
|
|
OutCompressedImage.RawData.AddUninitialized(NumTexels * 4);
|
|
|
|
|
const FColor* FirstColor = Image.AsBGRA8();
|
|
|
|
|
const FColor* LastColor = FirstColor + NumTexels;
|
2014-09-29 04:23:44 -04:00
|
|
|
int8* Dest = (int8*)OutCompressedImage.RawData.GetData();
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
for (const FColor* Color = FirstColor; Color < LastColor; ++Color)
|
|
|
|
|
{
|
|
|
|
|
*Dest++ = (int32)Color->B;
|
|
|
|
|
*Dest++ = (int32)Color->G;
|
|
|
|
|
*Dest++ = (int32)Color->A;
|
|
|
|
|
*Dest++ = (int32)Color->R;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (BuildSettings.TextureFormatName == GTextureFormatNameRGBA16F)
|
|
|
|
|
{
|
|
|
|
|
FImage Image;
|
Gamma Correction - Changing the way all FColors are converted into FLinearColor by default. Previously all sRGB textures coming into the engine along with all other usage of FColor -> FLinearColor used a lookup table that assumed the final gamma correction would simply be pow(color, 1/DisplayGamma). However, that's not the case, we use the IEC 61966-2-1 standard on most platforms for both the scene renderer, as well as for gamma correction in Slate. In Slate you should now see an image matching Photoshop instead of being slightly darker in the lower ranges. However, because we don't want to invalidate all existing textures that users have authored, all existing UTextures have a UseLegacyGamma flag set to true, all new textures will be set to false. The flag is part of the DDC key calculation, but steps were taken so that when legacy is true, keys match existing keys to prevent universally invalidating all games DDCs just to make this change.
To summarize,
Old Pipeline: sRGB-Pow(2.2) -> Linear -> sRGB-IEC 61966
New Pipeline: sRGB-IEC 61966 -> Linear -> sRGB-IEC 61966
#codereview gil.gribb, nick.penwarden, martin.mittring
[CL 2571070 by Nick Darnell in Main branch]
2015-05-29 16:03:43 -04:00
|
|
|
InImage.CopyTo(Image, ERawImageFormat::RGBA16F, EGammaSpace::Linear);
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
OutCompressedImage.SizeX = Image.SizeX;
|
|
|
|
|
OutCompressedImage.SizeY = Image.SizeY;
|
|
|
|
|
OutCompressedImage.PixelFormat = PF_FloatRGBA;
|
|
|
|
|
OutCompressedImage.RawData = Image.RawData;
|
|
|
|
|
|
2015-06-15 15:39:57 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (BuildSettings.TextureFormatName == GTextureFormatNamePOTERROR)
|
|
|
|
|
{
|
|
|
|
|
// load the error image data we will just repeat into the texture
|
|
|
|
|
TArray<uint8> ErrorData;
|
|
|
|
|
FFileHelper::LoadFileToArray(ErrorData, TEXT("../../../Engine/Content/MobileResources/PowerOfTwoError64x64.raw"));
|
|
|
|
|
|
|
|
|
|
// set output
|
|
|
|
|
OutCompressedImage.SizeX = InImage.SizeX;
|
|
|
|
|
OutCompressedImage.SizeY = InImage.SizeY;
|
|
|
|
|
OutCompressedImage.PixelFormat = PF_B8G8R8A8;
|
|
|
|
|
|
|
|
|
|
// allocate output memory
|
|
|
|
|
check(InImage.NumSlices == 1);
|
|
|
|
|
uint32 NumTexels = InImage.SizeX * InImage.SizeY;
|
|
|
|
|
OutCompressedImage.RawData.Empty(NumTexels * 4);
|
|
|
|
|
OutCompressedImage.RawData.AddUninitialized(NumTexels * 4);
|
|
|
|
|
|
|
|
|
|
// write out texels
|
|
|
|
|
uint8* Src = ErrorData.GetData();
|
|
|
|
|
uint8* Dest = (uint8*)OutCompressedImage.RawData.GetData();
|
|
|
|
|
for (int32 Y = 0; Y < InImage.SizeY; Y++)
|
|
|
|
|
{
|
|
|
|
|
for (int32 X = 0; X < InImage.SizeX * 4; X++)
|
|
|
|
|
{
|
|
|
|
|
int32 SrcX = X & (64 * 4 - 1);
|
|
|
|
|
int32 SrcY = Y & 63;
|
|
|
|
|
Dest[Y * InImage.SizeX * 4 + X] = Src[SrcY * 64 * 4 + SrcX];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UE_LOG(LogTextureFormatUncompressed, Warning,
|
|
|
|
|
TEXT("Cannot convert uncompressed image to format '%s'."),
|
|
|
|
|
*BuildSettings.TextureFormatName.ToString()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Module for uncompressed texture formats.
|
|
|
|
|
*/
|
|
|
|
|
static ITextureFormat* Singleton = NULL;
|
|
|
|
|
|
|
|
|
|
class FTextureFormatUncompressedModule : public ITextureFormatModule
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
virtual ~FTextureFormatUncompressedModule()
|
|
|
|
|
{
|
|
|
|
|
delete Singleton;
|
|
|
|
|
Singleton = NULL;
|
|
|
|
|
}
|
|
|
|
|
virtual ITextureFormat* GetTextureFormat()
|
|
|
|
|
{
|
|
|
|
|
if (!Singleton)
|
|
|
|
|
{
|
|
|
|
|
Singleton = new FTextureFormatUncompressed();
|
|
|
|
|
}
|
|
|
|
|
return Singleton;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
IMPLEMENT_MODULE(FTextureFormatUncompressedModule, TextureFormatUncompressed);
|
|
|
|
|
|