ATOM-16854 Texture Settings dialog box crashes in the Editor (#5777)

Changes include:
-Fixed image preview issue which was trying to convert a compressed texture directly to QImage.
-Fixed texture resolution display for cubemap in texture setting editor.
-Sort the preset names in preset combo box
-Fixed a crash when showing IBLSkybox preset info in texture setting editor

Signed-off-by: Qing Tao <55564570+VickyAtAZ@users.noreply.github.com>
This commit is contained in:
Qing Tao
2021-11-19 09:02:11 -08:00
committed by GitHub
parent ebb24d2285
commit 8fd9cbfb64
11 changed files with 99 additions and 132 deletions
@@ -905,68 +905,6 @@ namespace ImageProcessingAtom
return result;
}
IImageObjectPtr MergeOutputImageForPreview(IImageObjectPtr image, IImageObjectPtr alphaImage)
{
if (!image)
{
return IImageObjectPtr();
}
ImageToProcess imageToProcess(image);
imageToProcess.ConvertFormat(ePixelFormat_R8G8B8A8);
IImageObjectPtr previewImage = imageToProcess.Get();
// If there is separate Alpha image, combine it with output
if (alphaImage)
{
// Create pixel operation function for rgb and alpha images
IPixelOperationPtr imageOp = CreatePixelOperation(ePixelFormat_R8G8B8A8);
IPixelOperationPtr alphaOp = CreatePixelOperation(ePixelFormat_A8);
// Convert the alpha image to A8 first
ImageToProcess imageToProcess2(alphaImage);
imageToProcess2.ConvertFormat(ePixelFormat_A8);
IImageObjectPtr previewImageAlpha = imageToProcess2.Get();
const uint32 imageMips = previewImage->GetMipCount();
[[maybe_unused]] const uint32 alphaMips = previewImageAlpha->GetMipCount();
// Get count of bytes per pixel for both rgb and alpha images
uint32 imagePixelBytes = CPixelFormats::GetInstance().GetPixelFormatInfo(ePixelFormat_R8G8B8A8)->bitsPerBlock / 8;
uint32 alphaPixelBytes = CPixelFormats::GetInstance().GetPixelFormatInfo(ePixelFormat_A8)->bitsPerBlock / 8;
AZ_Assert(imageMips <= alphaMips, "Mip level of alpha image is less than origin image!");
// For each mip level, set the alpha value to the image
for (uint32 mipLevel = 0; mipLevel < imageMips; ++mipLevel)
{
const uint32 pixelCount = previewImage->GetPixelCount(mipLevel);
[[maybe_unused]] const uint32 alphaPixelCount = previewImageAlpha->GetPixelCount(mipLevel);
AZ_Assert(pixelCount == alphaPixelCount, "Pixel count for image and alpha image at mip level %d is not equal!", mipLevel);
uint8* imageBuf;
uint32 pitch;
previewImage->GetImagePointer(mipLevel, imageBuf, pitch);
uint8* alphaBuf;
uint32 alphaPitch;
previewImageAlpha->GetImagePointer(mipLevel, alphaBuf, alphaPitch);
float rAlpha, gAlpha, bAlpha, aAlpha, rImage, gImage, bImage, aImage;
for (uint32 i = 0; i < pixelCount; ++i, imageBuf += imagePixelBytes, alphaBuf += alphaPixelBytes)
{
alphaOp->GetRGBA(alphaBuf, rAlpha, gAlpha, bAlpha, aAlpha);
imageOp->GetRGBA(imageBuf, rImage, gImage, bImage, aImage);
imageOp->SetRGBA(imageBuf, rImage, gImage, bImage, aAlpha);
}
}
}
return previewImage;
}
IImageObjectPtr ConvertImageForPreview(IImageObjectPtr image)
{
if (!image)
@@ -51,9 +51,6 @@ namespace ImageProcessingAtom
//Converts the image to a RGBA8 format that can be displayed in a preview UI.
IImageObjectPtr ConvertImageForPreview(IImageObjectPtr image);
//Combine image with alpha image if any and output as RGBA8
IImageObjectPtr MergeOutputImageForPreview(IImageObjectPtr image, IImageObjectPtr alphaImage);
//get output image size and mip count based on the texture setting and preset setting
//other helper functions
@@ -16,28 +16,14 @@
namespace ImageProcessingAtom
{
IImageObjectPtr ImageConvertOutput::GetOutputImage(OutputImageType type) const
IImageObjectPtr ImageConvertOutput::GetOutputImage() const
{
if (type < OutputImageType::Count)
{
return m_outputImage[static_cast<int>(type)];
}
else
{
return IImageObjectPtr();
}
return m_outputImage;
}
void ImageConvertOutput::SetOutputImage(IImageObjectPtr image, OutputImageType type)
void ImageConvertOutput::SetOutputImage(IImageObjectPtr image)
{
if (type < OutputImageType::Count)
{
m_outputImage[static_cast<int>(type)] = image;
}
else
{
AZ_Error("ImageProcess", false, "Cannot set output image to %d", type);
}
m_outputImage = image;
}
void ImageConvertOutput::SetReady(bool ready)
@@ -62,10 +48,7 @@ namespace ImageProcessingAtom
void ImageConvertOutput::Reset()
{
for (int i = 0; i < static_cast<int>(OutputImageType::Count); i++)
{
m_outputImage[i] = nullptr;
}
m_outputImage = nullptr;
m_outputReady = false;
m_progress = 0.0f;
}
@@ -109,13 +92,12 @@ namespace ImageProcessingAtom
IImageObjectPtr outputImage = m_process->GetOutputImage();
m_output->SetOutputImage(outputImage, ImageConvertOutput::Base);
if (!IsJobCancelled())
{
// For preview, combine image output with alpha if any
// convert the output image to RGBA format for preview
m_output->SetProgress(1.0f / static_cast<float>(m_previewProcessStep));
m_output->SetOutputImage(outputImage, ImageConvertOutput::Preview);
IImageObjectPtr uncompressedImage = ConvertImageForPreview(outputImage);
m_output->SetOutputImage(uncompressedImage);
}
m_output->SetReady(true);
@@ -21,16 +21,8 @@ namespace ImageProcessingAtom
class ImageConvertOutput
{
public:
enum OutputImageType
{
Base = 0, // Might contains alpha or not
Alpha, // Separate alpha image
Preview, // Combine base image with alpha if any, format RGBA8
Count
};
IImageObjectPtr GetOutputImage(OutputImageType type) const;
void SetOutputImage(IImageObjectPtr image, OutputImageType type);
IImageObjectPtr GetOutputImage() const;
void SetOutputImage(IImageObjectPtr image);
void SetReady(bool ready);
bool IsReady() const;
float GetProgress() const;
@@ -38,7 +30,7 @@ namespace ImageProcessingAtom
void Reset();
private:
IImageObjectPtr m_outputImage[OutputImageType::Count];
IImageObjectPtr m_outputImage;
bool m_outputReady = false;
float m_progress = 0.0f;
};
@@ -86,7 +86,7 @@ namespace ImageProcessingAtom
IImageObjectPtr ImagePreview::GetOutputImage()
{
return m_output.GetOutputImage(ImageConvertOutput::Preview);
return m_output.GetOutputImage();
}
ImagePreview::~ImagePreview()