summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLC <mathew1800@gmail.com>2020-12-19 21:45:21 -0500
committerGitHub <noreply@github.com>2020-12-19 21:45:21 -0500
commit0315ca5e37f0f240e1fb7df72e1bb3bc3f7222eb (patch)
tree5af5f79f322b98aaae41f2986e0dc3c0b9399141
parent2097de603c1e225dd4fb8118d7c1cfd3f5162471 (diff)
parent0ad2f3da454feca1fc9ba9c3f8592e104028b936 (diff)
Merge pull request #9332 from leoetlino/warning-fixes
Core: Fix various warnings
-rw-r--r--Source/Core/Common/Image.cpp25
-rw-r--r--Source/Core/Common/Image.h5
-rw-r--r--Source/Core/Core/HW/GCMemcard/GCMemcard.cpp6
-rw-r--r--Source/Core/VideoBackends/Software/DebugUtil.cpp23
-rw-r--r--Source/Core/VideoBackends/Software/SetupUnit.cpp2
-rw-r--r--Source/Core/VideoCommon/AbstractTexture.cpp9
-rw-r--r--Source/Core/VideoCommon/BPStructs.cpp2
-rw-r--r--Source/Core/VideoCommon/CMakeLists.txt2
-rw-r--r--Source/Core/VideoCommon/ImageWrite.cpp57
-rw-r--r--Source/Core/VideoCommon/ImageWrite.h12
-rw-r--r--Source/Core/VideoCommon/RenderBase.cpp15
-rw-r--r--Source/Core/VideoCommon/ShaderCache.cpp2
-rw-r--r--Source/Core/VideoCommon/VideoBackendBase.cpp4
-rw-r--r--Source/Core/VideoCommon/VideoCommon.vcxproj4
-rw-r--r--Source/Core/VideoCommon/VideoCommon.vcxproj.filters8
15 files changed, 65 insertions, 111 deletions
diff --git a/Source/Core/Common/Image.cpp b/Source/Core/Common/Image.cpp
index 478d4b42ab..0621eb64d4 100644
--- a/Source/Core/Common/Image.cpp
+++ b/Source/Core/Common/Image.cpp
@@ -83,4 +83,29 @@ bool SavePNG(const std::string& path, const u8* input, ImageByteFormat format, u
return false;
return outfile.WriteBytes(buffer.data(), size);
}
+
+bool ConvertRGBAToRGBAndSavePNG(const std::string& path, const u8* input, u32 width, u32 height,
+ int stride)
+{
+ const std::vector<u8> data = RGBAToRGB(input, width, height, stride);
+ return SavePNG(path, data.data(), ImageByteFormat::RGB, width, height);
+}
+
+std::vector<u8> RGBAToRGB(const u8* input, u32 width, u32 height, int row_stride)
+{
+ std::vector<u8> buffer;
+ buffer.reserve(width * height * 3);
+
+ for (u32 y = 0; y < height; ++y)
+ {
+ const u8* pos = input + y * row_stride;
+ for (u32 x = 0; x < width; ++x)
+ {
+ buffer.push_back(pos[x * 4]);
+ buffer.push_back(pos[x * 4 + 1]);
+ buffer.push_back(pos[x * 4 + 2]);
+ }
+ }
+ return buffer;
+}
} // namespace Common
diff --git a/Source/Core/Common/Image.h b/Source/Core/Common/Image.h
index 9ef399138e..271f0b5624 100644
--- a/Source/Core/Common/Image.h
+++ b/Source/Core/Common/Image.h
@@ -22,4 +22,9 @@ enum class ImageByteFormat
bool SavePNG(const std::string& path, const u8* input, ImageByteFormat format, u32 width,
u32 height, int stride = 0);
+bool ConvertRGBAToRGBAndSavePNG(const std::string& path, const u8* input, u32 width, u32 height,
+ int stride = 0);
+
+std::vector<u8> RGBAToRGB(const u8* input, u32 width, u32 height, int row_stride = 0);
+
} // namespace Common
diff --git a/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp b/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp
index c12d4e9819..6bf6e1468c 100644
--- a/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp
+++ b/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp
@@ -931,7 +931,7 @@ GCMemcardRemoveFileRetVal GCMemcard::RemoveFile(u8 index) // index in the direc
// here that has an empty file with the filename "Broken File000" where the actual deleted file
// was. Determine when exactly this happens and if this is neccessary for anything.
- memset(&(UpdatedDir.m_dir_entries[index]), 0xFF, DENTRY_SIZE);
+ memset(reinterpret_cast<u8*>(&UpdatedDir.m_dir_entries[index]), 0xFF, DENTRY_SIZE);
UpdatedDir.m_update_counter = UpdatedDir.m_update_counter + 1;
UpdateDirectory(UpdatedDir);
@@ -1623,7 +1623,7 @@ std::pair<u32, u32> Header::CalculateSerial() const
DEntry::DEntry()
{
- memset(this, 0xFF, DENTRY_SIZE);
+ memset(reinterpret_cast<u8*>(this), 0xFF, DENTRY_SIZE);
}
std::string DEntry::GCI_FileName() const
@@ -1678,7 +1678,7 @@ GCMemcardErrorCode Header::CheckForErrors(u16 card_size_mbits) const
Directory::Directory()
{
- memset(this, 0xFF, BLOCK_SIZE);
+ memset(reinterpret_cast<u8*>(this), 0xFF, BLOCK_SIZE);
m_update_counter = 0;
m_checksum = Common::swap16(0xF003);
m_checksum_inv = 0;
diff --git a/Source/Core/VideoBackends/Software/DebugUtil.cpp b/Source/Core/VideoBackends/Software/DebugUtil.cpp
index c427160fc7..4c20c08d1a 100644
--- a/Source/Core/VideoBackends/Software/DebugUtil.cpp
+++ b/Source/Core/VideoBackends/Software/DebugUtil.cpp
@@ -5,18 +5,18 @@
#include "VideoBackends/Software/DebugUtil.h"
#include <cstring>
+#include <memory>
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
+#include "Common/Image.h"
#include "Common/StringUtil.h"
#include "Common/Swap.h"
#include "VideoBackends/Software/EfbInterface.h"
-#include "VideoBackends/Software/SWRenderer.h"
#include "VideoBackends/Software/TextureSampler.h"
#include "VideoCommon/BPMemory.h"
-#include "VideoCommon/ImageWrite.h"
#include "VideoCommon/Statistics.h"
#include "VideoCommon/VideoCommon.h"
#include "VideoCommon/VideoConfig.h"
@@ -61,12 +61,10 @@ static void SaveTexture(const std::string& filename, u32 texmap, s32 mip)
u32 width = ti0.width + 1;
u32 height = ti0.height + 1;
- u8* data = new u8[width * height * 4];
+ auto data = std::make_unique<u8[]>(width * height * 4);
- GetTextureRGBA(data, texmap, mip, width, height);
-
- TextureToPng(data, width * 4, filename, width, height, true);
- delete[] data;
+ GetTextureRGBA(data.get(), texmap, mip, width, height);
+ Common::SavePNG(filename, data.get(), Common::ImageByteFormat::RGBA, width, height, width * 4);
}
void GetTextureRGBA(u8* dst, u32 texmap, s32 mip, u32 width, u32 height)
@@ -133,8 +131,8 @@ void DumpActiveTextures()
static void DumpEfb(const std::string& filename)
{
- u8* data = new u8[EFB_WIDTH * EFB_HEIGHT * 4];
- u8* writePtr = data;
+ auto data = std::make_unique<u8[]>(EFB_WIDTH * EFB_HEIGHT * 4);
+ u8* writePtr = data.get();
for (u32 y = 0; y < EFB_HEIGHT; y++)
{
@@ -148,8 +146,8 @@ static void DumpEfb(const std::string& filename)
}
}
- TextureToPng(data, EFB_WIDTH * 4, filename, EFB_WIDTH, EFB_HEIGHT, true);
- delete[] data;
+ Common::SavePNG(filename, data.get(), Common::ImageByteFormat::RGBA, EFB_WIDTH, EFB_HEIGHT,
+ EFB_WIDTH * 4);
}
void DrawObjectBuffer(s16 x, s16 y, const u8* color, int bufferBase, int subBuffer,
@@ -219,7 +217,8 @@ void OnObjectEnd()
"%sobject%i_%s(%i).png", File::GetUserPath(D_DUMPOBJECTS_IDX).c_str(),
g_stats.this_frame.num_drawn_objects, ObjectBufferName[i], i - BufferBase[i]);
- TextureToPng((u8*)ObjectBuffer[i], EFB_WIDTH * 4, filename, EFB_WIDTH, EFB_HEIGHT, true);
+ Common::SavePNG(filename, reinterpret_cast<u8*>(ObjectBuffer[i]),
+ Common::ImageByteFormat::RGBA, EFB_WIDTH, EFB_HEIGHT, EFB_WIDTH * 4);
memset(ObjectBuffer[i], 0, EFB_WIDTH * EFB_HEIGHT * sizeof(u32));
}
}
diff --git a/Source/Core/VideoBackends/Software/SetupUnit.cpp b/Source/Core/VideoBackends/Software/SetupUnit.cpp
index 589d404552..3cdbbee614 100644
--- a/Source/Core/VideoBackends/Software/SetupUnit.cpp
+++ b/Source/Core/VideoBackends/Software/SetupUnit.cpp
@@ -25,7 +25,7 @@ void SetupUnit::Init(u8 primitiveType)
OutputVertexData* SetupUnit::GetVertex()
{
- memset(m_VertWritePointer, 0, sizeof(*m_VertWritePointer));
+ memset(reinterpret_cast<u8*>(m_VertWritePointer), 0, sizeof(*m_VertWritePointer));
return m_VertWritePointer;
}
diff --git a/Source/Core/VideoCommon/AbstractTexture.cpp b/Source/Core/VideoCommon/AbstractTexture.cpp
index 8e2dc39d76..9b26d55ff8 100644
--- a/Source/Core/VideoCommon/AbstractTexture.cpp
+++ b/Source/Core/VideoCommon/AbstractTexture.cpp
@@ -5,10 +5,10 @@
#include <algorithm>
#include "Common/Assert.h"
+#include "Common/Image.h"
#include "Common/MsgHandler.h"
#include "VideoCommon/AbstractStagingTexture.h"
#include "VideoCommon/AbstractTexture.h"
-#include "VideoCommon/ImageWrite.h"
#include "VideoCommon/RenderBase.h"
AbstractTexture::AbstractTexture(const TextureConfig& c) : m_config(c)
@@ -48,9 +48,10 @@ bool AbstractTexture::Save(const std::string& filename, unsigned int level)
if (!readback_texture->Map())
return false;
- return TextureToPng(reinterpret_cast<const u8*>(readback_texture->GetMappedPointer()),
- static_cast<int>(readback_texture->GetMappedStride()), filename, level_width,
- level_height);
+ return Common::SavePNG(filename,
+ reinterpret_cast<const u8*>(readback_texture->GetMappedPointer()),
+ Common::ImageByteFormat::RGBA, level_width, level_height,
+ static_cast<int>(readback_texture->GetMappedStride()));
}
bool AbstractTexture::IsCompressedFormat(AbstractTextureFormat format)
diff --git a/Source/Core/VideoCommon/BPStructs.cpp b/Source/Core/VideoCommon/BPStructs.cpp
index 585b072727..2376fd0840 100644
--- a/Source/Core/VideoCommon/BPStructs.cpp
+++ b/Source/Core/VideoCommon/BPStructs.cpp
@@ -43,7 +43,7 @@ static const float s_gammaLUT[] = {1.0f, 1.7f, 2.2f, 1.0f};
void BPInit()
{
- memset(&bpmem, 0, sizeof(bpmem));
+ memset(reinterpret_cast<u8*>(&bpmem), 0, sizeof(bpmem));
bpmem.bpMask = 0xFFFFFF;
}
diff --git a/Source/Core/VideoCommon/CMakeLists.txt b/Source/Core/VideoCommon/CMakeLists.txt
index 8e957f4a8d..2470c5ee4d 100644
--- a/Source/Core/VideoCommon/CMakeLists.txt
+++ b/Source/Core/VideoCommon/CMakeLists.txt
@@ -42,8 +42,6 @@ add_library(videocommon
HiresTextures.cpp
HiresTextures.h
HiresTextures_DDSLoader.cpp
- ImageWrite.cpp
- ImageWrite.h
IndexGenerator.cpp
IndexGenerator.h
LightingShaderGen.cpp
diff --git a/Source/Core/VideoCommon/ImageWrite.cpp b/Source/Core/VideoCommon/ImageWrite.cpp
deleted file mode 100644
index d2dcbc9dc5..0000000000
--- a/Source/Core/VideoCommon/ImageWrite.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright 2008 Dolphin Emulator Project
-// Licensed under GPLv2+
-// Refer to the license.txt file included.
-
-#include <list>
-#include <string>
-#include <vector>
-
-#include "Common/CommonTypes.h"
-#include "Common/File.h"
-#include "Common/FileUtil.h"
-#include "Common/Image.h"
-
-bool SaveData(const std::string& filename, const std::string& data)
-{
- std::ofstream f;
- File::OpenFStream(f, filename, std::ios::binary);
- f << data;
-
- return true;
-}
-
-/*
-TextureToPng
-
-Inputs:
-data : This is an array of RGBA with 8 bits per channel. 4 bytes for each pixel.
-row_stride: Determines the amount of bytes per row of pixels.
-*/
-bool TextureToPng(const u8* data, int row_stride, const std::string& filename, int width,
- int height, bool save_alpha)
-{
- if (!data)
- return false;
-
- if (save_alpha)
- {
- return Common::SavePNG(filename, data, Common::ImageByteFormat::RGBA, width, height,
- row_stride);
- }
-
- std::vector<u8> buffer;
- buffer.reserve(width * height * 3);
-
- for (int y = 0; y < height; ++y)
- {
- const u8* pos = data + y * row_stride;
- for (int x = 0; x < width; ++x)
- {
- buffer.push_back(pos[x * 4]);
- buffer.push_back(pos[x * 4 + 1]);
- buffer.push_back(pos[x * 4 + 2]);
- }
- }
-
- return Common::SavePNG(filename, buffer.data(), Common::ImageByteFormat::RGB, width, height);
-}
diff --git a/Source/Core/VideoCommon/ImageWrite.h b/Source/Core/VideoCommon/ImageWrite.h
deleted file mode 100644
index 46ce760e16..0000000000
--- a/Source/Core/VideoCommon/ImageWrite.h
+++ /dev/null
@@ -1,12 +0,0 @@
-// Copyright 2008 Dolphin Emulator Project
-// Licensed under GPLv2+
-// Refer to the license.txt file included.
-
-#pragma once
-
-#include <string>
-#include "Common/CommonTypes.h"
-
-bool SaveData(const std::string& filename, const std::string& data);
-bool TextureToPng(const u8* data, int row_stride, const std::string& filename, int width,
- int height, bool save_alpha = true);
diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp
index 94379909ec..02deb3a8b1 100644
--- a/Source/Core/VideoCommon/RenderBase.cpp
+++ b/Source/Core/VideoCommon/RenderBase.cpp
@@ -29,9 +29,9 @@
#include "Common/ChunkFile.h"
#include "Common/CommonTypes.h"
#include "Common/Config/Config.h"
-#include "Common/Event.h"
#include "Common/FileUtil.h"
#include "Common/Flag.h"
+#include "Common/Image.h"
#include "Common/Logging/Log.h"
#include "Common/MsgHandler.h"
#include "Common/Profiler.h"
@@ -64,7 +64,6 @@
#include "VideoCommon/FramebufferManager.h"
#include "VideoCommon/FramebufferShaderGen.h"
#include "VideoCommon/FreeLookCamera.h"
-#include "VideoCommon/ImageWrite.h"
#include "VideoCommon/NetPlayChatUI.h"
#include "VideoCommon/NetPlayGolfUI.h"
#include "VideoCommon/OnScreenDisplay.h"
@@ -92,6 +91,12 @@ static float AspectToWidescreen(float aspect)
return aspect * ((16.0f / 9.0f) / (4.0f / 3.0f));
}
+static bool DumpFrameToPNG(const FrameDump::FrameData& frame, const std::string& file_name)
+{
+ return Common::ConvertRGBAToRGBAndSavePNG(file_name, frame.data, frame.width, frame.height,
+ frame.stride);
+}
+
Renderer::Renderer(int backbuffer_width, int backbuffer_height, float backbuffer_scale,
AbstractTextureFormat backbuffer_format)
: m_backbuffer_width(backbuffer_width), m_backbuffer_height(backbuffer_height),
@@ -1572,8 +1577,7 @@ void Renderer::FrameDumpThreadFunc()
{
std::lock_guard<std::mutex> lk(m_screenshot_lock);
- if (TextureToPng(frame.data, frame.stride, m_screenshot_name, frame.width, frame.height,
- false))
+ if (DumpFrameToPNG(frame, m_screenshot_name))
OSD::AddMessage("Screenshot saved to " + m_screenshot_name);
// Reset settings
@@ -1681,8 +1685,7 @@ bool Renderer::StartFrameDumpToImage(const FrameDump::FrameData&)
void Renderer::DumpFrameToImage(const FrameDump::FrameData& frame)
{
- std::string filename = GetFrameDumpNextImageFileName();
- TextureToPng(frame.data, frame.stride, filename, frame.width, frame.height, false);
+ DumpFrameToPNG(frame, GetFrameDumpNextImageFileName());
m_frame_dump_image_counter++;
}
diff --git a/Source/Core/VideoCommon/ShaderCache.cpp b/Source/Core/VideoCommon/ShaderCache.cpp
index f8b4b881f0..7383dc6595 100644
--- a/Source/Core/VideoCommon/ShaderCache.cpp
+++ b/Source/Core/VideoCommon/ShaderCache.cpp
@@ -188,7 +188,7 @@ template <typename SerializedUidType, typename UidType>
static void SerializePipelineUid(const UidType& uid, SerializedUidType& serialized_uid)
{
// Convert to disk format. Ensure all padding bytes are zero.
- std::memset(&serialized_uid, 0, sizeof(serialized_uid));
+ std::memset(reinterpret_cast<u8*>(&serialized_uid), 0, sizeof(serialized_uid));
serialized_uid.vertex_decl = uid.vertex_format->GetVertexDeclaration();
serialized_uid.vs_uid = uid.vs_uid;
serialized_uid.gs_uid = uid.gs_uid;
diff --git a/Source/Core/VideoCommon/VideoBackendBase.cpp b/Source/Core/VideoCommon/VideoBackendBase.cpp
index 20f4d116a6..2f7e92664a 100644
--- a/Source/Core/VideoCommon/VideoBackendBase.cpp
+++ b/Source/Core/VideoCommon/VideoBackendBase.cpp
@@ -295,8 +295,8 @@ void VideoBackendBase::DoState(PointerWrap& p)
void VideoBackendBase::InitializeShared()
{
- memset(&g_main_cp_state, 0, sizeof(g_main_cp_state));
- memset(&g_preprocess_cp_state, 0, sizeof(g_preprocess_cp_state));
+ memset(reinterpret_cast<u8*>(&g_main_cp_state), 0, sizeof(g_main_cp_state));
+ memset(reinterpret_cast<u8*>(&g_preprocess_cp_state), 0, sizeof(g_preprocess_cp_state));
memset(texMem, 0, TMEM_SIZE);
// do not initialize again for the config window
diff --git a/Source/Core/VideoCommon/VideoCommon.vcxproj b/Source/Core/VideoCommon/VideoCommon.vcxproj
index bd144ae0f6..ecfc6b2def 100644
--- a/Source/Core/VideoCommon/VideoCommon.vcxproj
+++ b/Source/Core/VideoCommon/VideoCommon.vcxproj
@@ -48,7 +48,6 @@
<ClCompile Include="FreeLookCamera.cpp" />
<ClCompile Include="HiresTextures.cpp" />
<ClCompile Include="HiresTextures_DDSLoader.cpp" />
- <ClCompile Include="ImageWrite.cpp" />
<ClCompile Include="IndexGenerator.cpp" />
<ClCompile Include="NetPlayChatUI.cpp" />
<ClCompile Include="NetPlayGolfUI.cpp" />
@@ -132,7 +131,6 @@
<ClInclude Include="UberShaderCommon.h" />
<ClInclude Include="UberShaderPixel.h" />
<ClInclude Include="HiresTextures.h" />
- <ClInclude Include="ImageWrite.h" />
<ClInclude Include="IndexGenerator.h" />
<ClInclude Include="LightingShaderGen.h" />
<ClInclude Include="LookUpTables.h" />
@@ -201,4 +199,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
-</Project> \ No newline at end of file
+</Project>
diff --git a/Source/Core/VideoCommon/VideoCommon.vcxproj.filters b/Source/Core/VideoCommon/VideoCommon.vcxproj.filters
index 1535249e06..96d76b5646 100644
--- a/Source/Core/VideoCommon/VideoCommon.vcxproj.filters
+++ b/Source/Core/VideoCommon/VideoCommon.vcxproj.filters
@@ -95,9 +95,6 @@
<ClCompile Include="HiresTextures.cpp">
<Filter>Util</Filter>
</ClCompile>
- <ClCompile Include="ImageWrite.cpp">
- <Filter>Util</Filter>
- </ClCompile>
<ClCompile Include="IndexGenerator.cpp">
<Filter>Util</Filter>
</ClCompile>
@@ -290,9 +287,6 @@
<ClInclude Include="HiresTextures.h">
<Filter>Util</Filter>
</ClInclude>
- <ClInclude Include="ImageWrite.h">
- <Filter>Util</Filter>
- </ClInclude>
<ClInclude Include="IndexGenerator.h">
<Filter>Util</Filter>
</ClInclude>
@@ -411,4 +405,4 @@
<ItemGroup>
<Text Include="CMakeLists.txt" />
</ItemGroup>
-</Project> \ No newline at end of file
+</Project>