Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,147 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <ImageProcessing/PixelFormats.h>
#include <AzCore/std/smart_ptr/shared_ptr.h>
#include <AzCore/std/string/string.h>
#include <AzCore/std/containers/vector.h>
#include <AzCore/Math/Vector4.h>
#include <AzCore/Math/Color.h>
namespace AZ
{
namespace IO
{
class SystemFileStream;
}
}
namespace ImageProcessing
{
class IImageObject;
class TextureSettings;
typedef AZStd::shared_ptr<IImageObject> IImageObjectPtr;
enum class EAlphaContent
{
eAlphaContent_Indeterminate, // the format may have alpha, but can't be calculated
eAlphaContent_Absent, // the format has no alpha
eAlphaContent_OnlyWhite, // alpha contains just white
eAlphaContent_OnlyBlack, // alpha contains just black
eAlphaContent_OnlyBlackAndWhite, // alpha contains just black and white
eAlphaContent_Greyscale // alpha contains grey tones
};
//interface for image object. The image object may have mipmaps.
class IImageObject
{
public:
//static functions
static IImageObject* CreateImage(AZ::u32 width, AZ::u32 height, AZ::u32 maxMipCount, EPixelFormat pixelFormat);
virtual ~IImageObject() {};
public:
//creating new image object outof this image object
virtual IImageObject* Clone() const = 0;
// allocate an empty image object with requested format and same properties with current image
virtual IImageObject* AllocateImage(EPixelFormat pixelFormat) const = 0;
virtual IImageObject* AllocateImage() const = 0;
//get pixel format
virtual EPixelFormat GetPixelFormat() const = 0;
virtual AZ::u32 GetPixelCount(AZ::u32 mip) const = 0;
virtual AZ::u32 GetWidth(AZ::u32 mip) const = 0;
virtual AZ::u32 GetHeight(AZ::u32 mip) const = 0;
virtual bool IsCubemap() const = 0;
virtual AZ::u32 GetMipCount() const = 0;
//get pixel data buffer
virtual void GetImagePointer(AZ::u32 mip, AZ::u8*& pMem, AZ::u32& pitch) const = 0;
virtual AZ::u32 GetMipBufSize(AZ::u32 mip) const = 0;
virtual void SetMipData(AZ::u32 mip, AZ::u8* mipBuf, AZ::u32 bufSize, AZ::u32 pitch) = 0;
//get/set image flags
virtual AZ::u32 GetImageFlags() const = 0;
virtual void SetImageFlags(AZ::u32 imageFlags) = 0;
virtual void AddImageFlags(AZ::u32 imageFlags) = 0;
virtual void RemoveImageFlags(AZ::u32 imageFlags) = 0;
virtual bool HasImageFlags(AZ::u32 imageFlags) const = 0;
// image data operations and calculation
// Calculates "(pixel.rgba * scale) + bias"
virtual void ScaleAndBiasChannels(AZ::u32 firstMip, AZ::u32 maxMipCount, const AZ::Vector4& scale, const AZ::Vector4& bias) = 0;
// Calculates "clamp(pixel.rgba, min, max)"
virtual void ClampChannels(AZ::u32 firstMip, AZ::u32 maxMipCount, const AZ::Vector4& min, const AZ::Vector4& max) = 0;
//transfer alpha coverage from source image
virtual void TransferAlphaCoverage(const TextureSettings* textureSetting, const IImageObjectPtr srcImg) = 0;
// Routines to measure and manipulate alpha coverage
virtual float ComputeAlphaCoverageScaleFactor(AZ::u32 mip, float fDesiredCoverage, float fAlphaRef) const = 0;
virtual float ComputeAlphaCoverage(AZ::u32 mip, float fAlphaRef) const = 0;
//helper functions
//compare whether two images are same. return true if they are same.
virtual bool CompareImage(const IImageObjectPtr otherImage) const = 0;
// Writes this image to file used for runtime, overwrites any existing file.
// It may write alpha image as attached image into the same file
// outFilePaths will save filenames finally saved to since the image might be split and saved to multiple files
virtual bool SaveImage(const char* filename, IImageObjectPtr alphaImage, AZStd::vector<AZStd::string>& outFilePaths) const = 0;
virtual bool SaveImage(AZ::IO::SystemFileStream& out) const = 0;
virtual bool SaveMipToFile(AZ::u32 mip, const AZStd::string& filename) const = 0;
//get total image data size in memory of all mipmaps. Not includs header and flags.
virtual AZ::u32 GetTextureMemory() const = 0;
//identify content of the alpha channel
virtual EAlphaContent GetAlphaContent() const = 0;
//normalize rgb channel for specified mips
virtual void NormalizeVectors(AZ::u32 firstMip, AZ::u32 maxMipCount) = 0;
// use when you convert an image to another one
virtual void CopyPropertiesFrom(const IImageObjectPtr src) = 0;
//swizzle data for source channels to dest channels
virtual void Swizzle(const char channels[4]) = 0;
//get/set properties of the image object
virtual void GetColorRange(AZ::Color& minColor, AZ::Color& maxColor) const = 0;
virtual void SetColorRange(const AZ::Color& minColor, const AZ::Color& maxColor) = 0;
virtual AZ::u32 GetNumPersistentMips() const = 0;
virtual void SetNumPersistentMips(AZ::u32 nMips) = 0;
virtual float GetAverageBrightness() const = 0;
virtual void SetAverageBrightness(float avgBrightness) = 0;
// Derive new roughness from normal variance to preserve the bumpiness of normal map mips and to reduce specular aliasing.
// The derived roughness is combined with the artist authored roughness stored in the alpha channel of the normal map.
// The algorithm is based on the Frequency Domain Normal Mapping implementation presented by Neubelt and Pettineo at Siggraph 2013.
virtual void GlossFromNormals(bool hasAuthoredGloss) = 0;
//convert gloss map from legacy distribution to new one. New World is still using legacy gloss map.
virtual void ConvertLegacyGloss() = 0;
//clear image with color
virtual void ClearColor(float r, float g, float b, float a) = 0;
virtual bool HasPowerOfTwoSizes() const = 0;
};
//loading function to load output dds file to a IImageObject
IImageObject* LoadImageFromDdsFile(const AZStd::string& filename);
IImageObject* LoadImageFromDdsFile(AZ::IO::SystemFileStream& fileLoadStream);
IImageObject* LoadAttachedImageFromDdsFile(const AZStd::string& filename, IImageObjectPtr originImage);
} // namespace ImageProcessing
@@ -0,0 +1,34 @@
/*
* All or portions of this file Copyright(c) Amazon.com, Inc.or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
*WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/EBus/EBus.h>
namespace ImageProcessing
{
class IImageObject;
class ImageProcessingRequests
: public AZ::EBusTraits
{
public:
//////////////////////////////////////////////////////////////////////////
// EBusTraits overrides
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
//////////////////////////////////////////////////////////////////////////
virtual IImageObject* LoadImage(const AZStd::string& filePath) = 0;
};
using ImageProcessingRequestBus = AZ::EBus<ImageProcessingRequests>;
} // namespace ImageProcessing
@@ -0,0 +1,36 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/EBus/EBus.h>
class QString;
namespace ImageProcessingEditor
{
class ImageProcessingEditorRequests
: public AZ::EBusTraits
{
public:
//////////////////////////////////////////////////////////////////////////
// EBusTraits overrides
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
/////////////////////////////////////////////////////////////////////////
//! Open single texture file
virtual void OpenSourceTextureFile(const AZ::Uuid& textureSourceID) = 0;
};
using ImageProcessingEditorRequestBus = AZ::EBus<ImageProcessingEditorRequests>;
}//namespace ImageProcessingEditor
@@ -0,0 +1,107 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
namespace ImageProcessing
{
enum EPixelFormat : int
{
//unsigned formats
ePixelFormat_R8G8B8A8 = 0,
ePixelFormat_R8G8B8X8,
ePixelFormat_R8G8,
ePixelFormat_R8,
ePixelFormat_A8,
ePixelFormat_R16G16B16A16,
ePixelFormat_R16G16,
ePixelFormat_R16,
//Custom FourCC Formats
// Data in these FourCC formats is custom compressed data and only decodable by certain hardware.
//ASTC formats supported by ios devices with A8 processor. Also supported by Android Extension Pack.
ePixelFormat_ASTC_4x4,
ePixelFormat_ASTC_5x4,
ePixelFormat_ASTC_5x5,
ePixelFormat_ASTC_6x5,
ePixelFormat_ASTC_6x6,
ePixelFormat_ASTC_8x5,
ePixelFormat_ASTC_8x6,
ePixelFormat_ASTC_8x8,
ePixelFormat_ASTC_10x5,
ePixelFormat_ASTC_10x6,
ePixelFormat_ASTC_10x8,
ePixelFormat_ASTC_10x10,
ePixelFormat_ASTC_12x10,
ePixelFormat_ASTC_12x12,
//Formats supported by PowerVR GPU. Mainly for ios devices.
ePixelFormat_PVRTC2, //2bpp
ePixelFormat_PVRTC4, //4bpp
//formats for opengl and opengles 3.0 (android devices)
ePixelFormat_EAC_R11, //one channel unsigned data
ePixelFormat_EAC_RG11, //two channel unsigned data
ePixelFormat_ETC2, //Compresses RGB888 data, it taks 4x4 groups of pixel data and compresses each into a 64-bit
ePixelFormat_ETC2a, //Compresses RGBA8888 data with full alpha support
// Standardized Compressed DXGI Formats (DX10+)
// Data in these compressed formats is hardware decodable on all DX10 chips, and manageable with the DX10-API.
ePixelFormat_BC1, // RGB without alpha, 0.5 byte/px
ePixelFormat_BC1a, // RGB with 1 bit of alpha, 0.5 byte/px.
ePixelFormat_BC3, // RGBA 1 byte/px, color maps with full alpha.
ePixelFormat_BC3t, // BC3 with alpha weighted color
ePixelFormat_BC4, // One color channel, 0.5 byte/px, unsigned
ePixelFormat_BC4s, // BC4, signed
ePixelFormat_BC5, // Two color channels, 1 byte/px, unsigned. Usually use for tangent-space normal maps
ePixelFormat_BC5s, // BC5, signed
ePixelFormat_BC6UH, // RGB, floating-point. Used for HDR images. Decompress to RGB in half floating point
ePixelFormat_BC7, // RGB or RGBA. 1 byte/px. Three color channels (4 to 7 bits per channel) with 0 to 8 bits of alpha
ePixelFormat_BC7t, // BC& with alpha weighted color
// Float formats
// Data in a Float format is floating point data.
ePixelFormat_R9G9B9E5,
ePixelFormat_R32G32B32A32F,
ePixelFormat_R32G32F,
ePixelFormat_R32F,
ePixelFormat_R16G16B16A16F,
ePixelFormat_R16G16F,
ePixelFormat_R16F,
//legacy format. Only used to load old converted dds files.
ePixelFormat_B8G8R8A8, //32bits rgba format
ePixelFormat_R32,
ePixelFormat_Count,
ePixelFormat_Unknown = ePixelFormat_Count
};
inline bool IsASTCFormat(EPixelFormat fmt)
{
return fmt == ePixelFormat_ASTC_4x4 || fmt == ePixelFormat_ASTC_5x4 || fmt == ePixelFormat_ASTC_5x5 ||
fmt == ePixelFormat_ASTC_6x5 || fmt == ePixelFormat_ASTC_6x6 || fmt == ePixelFormat_ASTC_8x5 ||
fmt == ePixelFormat_ASTC_8x6 || fmt == ePixelFormat_ASTC_8x8 || fmt == ePixelFormat_ASTC_10x5 ||
fmt == ePixelFormat_ASTC_10x6 || fmt == ePixelFormat_ASTC_10x8 || fmt == ePixelFormat_ASTC_10x10 ||
fmt == ePixelFormat_ASTC_12x10 || fmt == ePixelFormat_ASTC_12x12;
}
inline bool IsETCFormat(EPixelFormat fmt)
{
return fmt == ePixelFormat_ETC2 || fmt == ePixelFormat_ETC2a || fmt == ePixelFormat_EAC_R11 ||
fmt == ePixelFormat_EAC_RG11;
}
inline bool IsPVRTCFormat(EPixelFormat fmt)
{
return fmt == ePixelFormat_PVRTC2 || fmt == ePixelFormat_PVRTC4;
}
} // namespace ImageProcessing