Skip to content

Commit

Permalink
Removed RendererBase dependency from Image
Browse files Browse the repository at this point in the history
  • Loading branch information
jayrulez committed Dec 28, 2023
1 parent abeb6fe commit c1ca14f
Show file tree
Hide file tree
Showing 14 changed files with 174 additions and 130 deletions.
6 changes: 0 additions & 6 deletions Code/Libraries/Core/Image/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ target_sources(Image
target_link_libraries(Image
PUBLIC
Common
RendererBase
Libpng
ZLib
)

target_include_directories(Image
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/../../Renderer/
)
18 changes: 9 additions & 9 deletions Code/Libraries/Core/Image/HdrSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,31 +352,31 @@ bool IsHdr(Stream* stream)

bool ReadHdrInfo(Stream* stream, ImageInfo& info)
{
info.Format = TextureFormat::RGB32f;
info.Format = ImageFormat::RGB32f;

Status status;
ParseHdrHeader(status, stream, info.Width, info.Height);
stream->Seek(0);
return status.Succeeded();
}

bool IsHdrLoadFormat(TextureFormat::Enum format)
bool IsHdrLoadFormat(ImageFormat::Enum format)
{
return format == TextureFormat::None || IsHdrSaveFormat(format);
return format == ImageFormat::None || IsHdrSaveFormat(format);
}

bool IsHdrSaveFormat(TextureFormat::Enum format)
bool IsHdrSaveFormat(ImageFormat::Enum format)
{
return format == TextureFormat::RGB32f;
return format == ImageFormat::RGB32f;
}

void LoadHdr(Status& status,
Stream* stream,
::byte** output,
uint* width,
uint* height,
TextureFormat::Enum* format,
TextureFormat::Enum requireFormat)
ImageFormat::Enum* format,
ImageFormat::Enum requireFormat)
{
if (!IsHdrLoadFormat(requireFormat))
{
Expand Down Expand Up @@ -444,10 +444,10 @@ void LoadHdr(Status& status,
*output = (::byte*)outputImage;

// We always output the RGB32f format.
*format = TextureFormat::RGB32f;
*format = ImageFormat::RGB32f;
}

void SaveHdr(Status& status, Stream* stream, const ::byte* image, uint width, uint height, TextureFormat::Enum format)
void SaveHdr(Status& status, Stream* stream, const ::byte* image, uint width, uint height, ImageFormat::Enum format)
{
if (!IsHdrSaveFormat(format))
{
Expand Down
10 changes: 5 additions & 5 deletions Code/Libraries/Core/Image/HdrSupport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ bool IsHdr(Stream* stream);
bool ReadHdrInfo(Stream* stream, ImageInfo& info);

// Checks if the format is a valid load format (always returns true for None).
bool IsHdrLoadFormat(TextureFormat::Enum format);
bool IsHdrLoadFormat(ImageFormat::Enum format);

// Checks if the format is a valid save format (always returns false for None).
bool IsHdrSaveFormat(TextureFormat::Enum format);
bool IsHdrSaveFormat(ImageFormat::Enum format);

// Both Load/Save will leave the stream at the end, or wherever they failed.
// Supported texture formats: RGB32f
Expand All @@ -28,9 +28,9 @@ void LoadHdr(Status& status,
::byte** output,
uint* width,
uint* height,
TextureFormat::Enum* format,
TextureFormat::Enum requireFormat = TextureFormat::None);
void SaveHdr(Status& status, Stream* stream, const ::byte* image, uint width, uint height, TextureFormat::Enum format);
ImageFormat::Enum* format,
ImageFormat::Enum requireFormat = ImageFormat::None);
void SaveHdr(Status& status, Stream* stream, const ::byte* image, uint width, uint height, ImageFormat::Enum format);

void RgbeToRgb32f(::byte* rgbe, float* rgb32f);
void Rgb32fToRgbe(float* rgb32f, ::byte* rgbe);
Expand Down
32 changes: 31 additions & 1 deletion Code/Libraries/Core/Image/ImageStandard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,39 @@
#pragma once

#include "Common/CommonStandard.hpp"
#include "RendererBase/RendererBaseStandard.hpp"
#include "Common/Platform/PlatformStandard.hpp"

namespace Zero
{
// This must mirror TextureFormat in RendererBase
DeclareEnum25(ImageFormat,
None,
R8,
RG8,
RGB8,
RGBA8, // byte
R16,
RG16,
RGB16,
RGBA16, // short
R16f,
RG16f,
RGB16f,
RGBA16f, // half float
R32f,
RG32f,
RGB32f,
RGBA32f, // float
SRGB8,
SRGB8A8, // gamma
Depth16,
Depth24,
Depth32,
Depth32f, // depth
Depth24Stencil8,
Depth32fStencil8Pad24); // depth-stencil
}

#include "ImageSupport.hpp"
#include "PngSupport.hpp"
#include "HdrSupport.hpp"
104 changes: 52 additions & 52 deletions Code/Libraries/Core/Image/ImageSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,126 +50,126 @@ static stbi_io_callbacks StbStreamCallbacks()
return callbacks;
}

bool IsImageLoadFormat(TextureFormat::Enum format)
bool IsImageLoadFormat(ImageFormat::Enum format)
{
return format == TextureFormat::None || IsImageSaveFormat(format);
return format == ImageFormat::None || IsImageSaveFormat(format);
}

bool IsImageSaveFormat(TextureFormat::Enum format)
bool IsImageSaveFormat(ImageFormat::Enum format)
{
return format == TextureFormat::R8 || format == TextureFormat::RG8 || format == TextureFormat::RGB8 ||
format == TextureFormat::RGBA8 || format == TextureFormat::SRGB8 || format == TextureFormat::SRGB8A8 ||
format == TextureFormat::R16 || format == TextureFormat::RG16 || format == TextureFormat::RGB16 ||
format == TextureFormat::RGBA16 || format == TextureFormat::R32f || format == TextureFormat::RG32f ||
format == TextureFormat::RGB32f || format == TextureFormat::RGBA32f;
return format == ImageFormat::R8 || format == ImageFormat::RG8 || format == ImageFormat::RGB8 ||
format == ImageFormat::RGBA8 || format == ImageFormat::SRGB8 || format == ImageFormat::SRGB8A8 ||
format == ImageFormat::R16 || format == ImageFormat::RG16 || format == ImageFormat::RGB16 ||
format == ImageFormat::RGBA16 || format == ImageFormat::R32f || format == ImageFormat::RG32f ||
format == ImageFormat::RGB32f || format == ImageFormat::RGBA32f;
}

TextureFormat::Enum ToImageFormat(int components, ImageBitDepth::Enum depth)
ImageFormat::Enum ToImageFormat(int components, ImageBitDepth::Enum depth)
{
switch (depth)
{
case ImageBitDepth::I8:
switch (components)
{
case 1:
return TextureFormat::R8;
return ImageFormat::R8;
case 2:
return TextureFormat::RG8;
return ImageFormat::RG8;
case 3:
return TextureFormat::RGB8;
return ImageFormat::RGB8;
case 4:
return TextureFormat::RGBA8;
return ImageFormat::RGBA8;
}
break;
case ImageBitDepth::I16:
switch (components)
{
case 1:
return TextureFormat::R16;
return ImageFormat::R16;
case 2:
return TextureFormat::RG16;
return ImageFormat::RG16;
case 3:
return TextureFormat::RGB16;
return ImageFormat::RGB16;
case 4:
return TextureFormat::RGBA16;
return ImageFormat::RGBA16;
}
break;
case ImageBitDepth::F32:
switch (components)
{
case 1:
return TextureFormat::R32f;
return ImageFormat::R32f;
case 2:
return TextureFormat::RG32f;
return ImageFormat::RG32f;
case 3:
return TextureFormat::RGB32f;
return ImageFormat::RGB32f;
case 4:
return TextureFormat::RGBA32f;
return ImageFormat::RGBA32f;
}
break;
default:
break;
}
return TextureFormat::None;
return ImageFormat::None;
}

void FromImageFormat(TextureFormat::Enum format, int* components, ImageBitDepth::Enum* depth)
void FromImageFormat(ImageFormat::Enum format, int* components, ImageBitDepth::Enum* depth)
{
switch (format)
{
case TextureFormat::R8:
case ImageFormat::R8:
*components = 1;
*depth = ImageBitDepth::I8;
return;
case TextureFormat::RG8:
case ImageFormat::RG8:
*components = 2;
*depth = ImageBitDepth::I8;
return;
case TextureFormat::RGB8:
case ImageFormat::RGB8:
*components = 3;
*depth = ImageBitDepth::I8;
return;
case TextureFormat::RGBA8:
case ImageFormat::RGBA8:
*components = 4;
*depth = ImageBitDepth::I8;
return;
case TextureFormat::SRGB8:
case ImageFormat::SRGB8:
*components = 3;
*depth = ImageBitDepth::I8;
return;
case TextureFormat::SRGB8A8:
case ImageFormat::SRGB8A8:
*components = 4;
*depth = ImageBitDepth::I8;
return;
case TextureFormat::R16:
case ImageFormat::R16:
*components = 1;
*depth = ImageBitDepth::I16;
return;
case TextureFormat::RG16:
case ImageFormat::RG16:
*components = 2;
*depth = ImageBitDepth::I16;
return;
case TextureFormat::RGB16:
case ImageFormat::RGB16:
*components = 3;
*depth = ImageBitDepth::I16;
return;
case TextureFormat::RGBA16:
case ImageFormat::RGBA16:
*components = 4;
*depth = ImageBitDepth::I16;
return;
case TextureFormat::R32f:
case ImageFormat::R32f:
*components = 1;
*depth = ImageBitDepth::F32;
return;
case TextureFormat::RG32f:
case ImageFormat::RG32f:
*components = 2;
*depth = ImageBitDepth::F32;
return;
case TextureFormat::RGB32f:
case ImageFormat::RGB32f:
*components = 3;
*depth = ImageBitDepth::F32;
return;
case TextureFormat::RGBA32f:
case ImageFormat::RGBA32f:
*components = 4;
*depth = ImageBitDepth::F32;
return;
Expand Down Expand Up @@ -266,8 +266,8 @@ void LoadImage(Status& status,
::byte** output,
uint* width,
uint* height,
TextureFormat::Enum* format,
TextureFormat::Enum requireFormat)
ImageFormat::Enum* format,
ImageFormat::Enum requireFormat)
{
#ifdef ZeroCustomPngSupport
if (IsPngLoadFormat(requireFormat) && IsPng(stream))
Expand Down Expand Up @@ -399,8 +399,8 @@ void LoadImage(Status& status,
::byte** output,
uint* width,
uint* height,
TextureFormat::Enum* format,
TextureFormat::Enum requireFormat)
ImageFormat::Enum* format,
ImageFormat::Enum requireFormat)
{
FileStream stream(file);
LoadImage(status, &stream, output, width, height, format, requireFormat);
Expand All @@ -411,8 +411,8 @@ void LoadImage(Status& status,
::byte** output,
uint* width,
uint* height,
TextureFormat::Enum* format,
TextureFormat::Enum requireFormat)
ImageFormat::Enum* format,
ImageFormat::Enum requireFormat)
{
File file;
if (!file.Open(filename.c_str(), FileMode::Read, FileAccessPattern::Sequential, FileShare::Unspecified, &status))
Expand All @@ -427,8 +427,8 @@ void LoadImage(Status& status,
::byte** output,
uint* width,
uint* height,
TextureFormat::Enum* format,
TextureFormat::Enum requireFormat)
ImageFormat::Enum* format,
ImageFormat::Enum requireFormat)
{
FixedMemoryStream stream(encoded, size);
LoadImage(status, &stream, output, width, height, format, requireFormat);
Expand All @@ -440,13 +440,13 @@ void LoadImage(Status& status, Stream* stream, Image* imageOut)
::byte* output = nullptr;
uint width = 0;
uint height = 0;
TextureFormat::Enum format = TextureFormat::None;
LoadImage(status, stream, &output, &width, &height, &format, TextureFormat::RGBA8);
ImageFormat::Enum format = ImageFormat::None;
LoadImage(status, stream, &output, &width, &height, &format, ImageFormat::RGBA8);

// Note that Image::Set steals the data
if (output && status.Succeeded())
{
ErrorIf(format != TextureFormat::RGBA8, "Got back an invalid format from LoadImage");
ErrorIf(format != ImageFormat::RGBA8, "Got back an invalid format from LoadImage");
imageOut->Set((ImagePixel*)output, width, height);
}
}
Expand Down Expand Up @@ -477,7 +477,7 @@ void SaveImage(Status& status,
const ::byte* image,
uint width,
uint height,
TextureFormat::Enum format,
ImageFormat::Enum format,
ImageSaveFormat::Enum imageType)
{
if (image == nullptr || width == 0 || height == 0)
Expand Down Expand Up @@ -552,7 +552,7 @@ void SaveImage(Status& status,
const ::byte* image,
uint width,
uint height,
TextureFormat::Enum format,
ImageFormat::Enum format,
ImageSaveFormat::Enum imageType)
{
FileStream stream(file);
Expand All @@ -564,7 +564,7 @@ void SaveImage(Status& status,
const ::byte* image,
uint width,
uint height,
TextureFormat::Enum format,
ImageFormat::Enum format,
ImageSaveFormat::Enum imageType)
{
File file;
Expand All @@ -575,7 +575,7 @@ void SaveImage(Status& status,

void SaveImage(Status& status, Stream* stream, Image* image, ImageSaveFormat::Enum imageType)
{
return SaveImage(status, stream, (::byte*)image->Data, image->Width, image->Height, TextureFormat::RGBA8, imageType);
return SaveImage(status, stream, (::byte*)image->Data, image->Width, image->Height, ImageFormat::RGBA8, imageType);
}

void SaveImage(Status& status, File& file, Image* image, ImageSaveFormat::Enum imageType)
Expand Down
Loading

0 comments on commit c1ca14f

Please sign in to comment.