From b67263107d12f500f4f64ea6d98fe7400fc6d540 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 9 Mar 2024 11:11:50 +0100 Subject: [PATCH] Use `uint8_t *` consistently for raw image data Previously, usage of `void *`, `unsigned char *` and `uint8_t *` was mixed in various places for pointers to raw image data and the pointers ended up being cast to `uint8_t *` at some point anyway. Now only `uint8_t *` is used consistently, which improves type safety and readability. Casts to `uint8_t *` are now only necessary when using `malloc` or when reading data from a map. --- src/engine/client/backend/backend_base.cpp | 8 ++-- src/engine/client/backend/backend_base.h | 4 +- .../client/backend/opengl/backend_opengl.cpp | 30 +++++++------- .../client/backend/opengl/backend_opengl.h | 6 +-- .../client/backend/opengl/backend_opengl3.cpp | 16 ++++---- .../client/backend/opengl/backend_opengl3.h | 4 +- .../client/backend/vulkan/backend_vulkan.cpp | 40 +++++++++---------- src/engine/client/graphics_threaded.cpp | 32 +++++++-------- src/engine/client/graphics_threaded.h | 20 +++++----- src/engine/client/text.cpp | 13 +++--- src/engine/gfx/image_manipulation.cpp | 24 +++++------ src/engine/gfx/image_manipulation.h | 4 +- src/engine/graphics.h | 12 +++--- src/engine/textrender.h | 2 +- src/game/client/components/mapimages.cpp | 8 ++-- src/game/client/components/mapimages.h | 2 +- src/game/editor/editor.cpp | 6 +-- src/game/editor/mapitems/image.cpp | 4 +- src/game/editor/mapitems/map_io.cpp | 2 +- src/game/editor/tileart.cpp | 4 +- src/tools/dilate.cpp | 19 +++------ src/tools/map_create_pixelart.cpp | 2 +- 22 files changed, 122 insertions(+), 140 deletions(-) diff --git a/src/engine/client/backend/backend_base.cpp b/src/engine/client/backend/backend_base.cpp index 168598064..f8592b28a 100644 --- a/src/engine/client/backend/backend_base.cpp +++ b/src/engine/client/backend/backend_base.cpp @@ -2,12 +2,12 @@ #include #include -void *CCommandProcessorFragment_GLBase::Resize(const unsigned char *pData, int Width, int Height, int NewWidth, int NewHeight, int BPP) +uint8_t *CCommandProcessorFragment_GLBase::Resize(const uint8_t *pData, int Width, int Height, int NewWidth, int NewHeight, int BPP) { - return ResizeImage((const uint8_t *)pData, Width, Height, NewWidth, NewHeight, BPP); + return ResizeImage(pData, Width, Height, NewWidth, NewHeight, BPP); } -bool CCommandProcessorFragment_GLBase::Texture2DTo3D(void *pImageBuffer, int ImageWidth, int ImageHeight, size_t PixelSize, int SplitCountWidth, int SplitCountHeight, void *pTarget3DImageData, int &Target3DImageWidth, int &Target3DImageHeight) +bool CCommandProcessorFragment_GLBase::Texture2DTo3D(uint8_t *pImageBuffer, int ImageWidth, int ImageHeight, size_t PixelSize, int SplitCountWidth, int SplitCountHeight, uint8_t *pTarget3DImageData, int &Target3DImageWidth, int &Target3DImageHeight) { Target3DImageWidth = ImageWidth / SplitCountWidth; Target3DImageHeight = ImageHeight / SplitCountHeight; @@ -26,7 +26,7 @@ bool CCommandProcessorFragment_GLBase::Texture2DTo3D(void *pImageBuffer, int Ima size_t TargetImageFullSize = (size_t)TargetImageFullWidth * Target3DImageHeight; ptrdiff_t ImageOffset = (ptrdiff_t)(((size_t)Y * FullImageWidth * (size_t)Target3DImageHeight) + ((size_t)Y3D * FullImageWidth) + ((size_t)X * TargetImageFullWidth)); ptrdiff_t TargetImageOffset = (ptrdiff_t)(TargetImageFullSize * (size_t)DepthIndex + ((size_t)Y3D * TargetImageFullWidth)); - mem_copy(((uint8_t *)pTarget3DImageData) + TargetImageOffset, ((uint8_t *)pImageBuffer) + (ptrdiff_t)(ImageOffset), TargetImageFullWidth); + mem_copy(pTarget3DImageData + TargetImageOffset, pImageBuffer + (ptrdiff_t)(ImageOffset), TargetImageFullWidth); } } } diff --git a/src/engine/client/backend/backend_base.h b/src/engine/client/backend/backend_base.h index 2d48e96b1..6df6eee7d 100644 --- a/src/engine/client/backend/backend_base.h +++ b/src/engine/client/backend/backend_base.h @@ -84,9 +84,9 @@ protected: SGfxErrorContainer m_Error; SGfxWarningContainer m_Warning; - static void *Resize(const unsigned char *pData, int Width, int Height, int NewWidth, int NewHeight, int BPP); + static uint8_t *Resize(const uint8_t *pData, int Width, int Height, int NewWidth, int NewHeight, int BPP); - static bool Texture2DTo3D(void *pImageBuffer, int ImageWidth, int ImageHeight, size_t PixelSize, int SplitCountWidth, int SplitCountHeight, void *pTarget3DImageData, int &Target3DImageWidth, int &Target3DImageHeight); + static bool Texture2DTo3D(uint8_t *pImageBuffer, int ImageWidth, int ImageHeight, size_t PixelSize, int SplitCountWidth, int SplitCountHeight, uint8_t *pTarget3DImageData, int &Target3DImageWidth, int &Target3DImageHeight); virtual bool GetPresentedImageData(uint32_t &Width, uint32_t &Height, CImageInfo::EImageFormat &Format, std::vector &vDstData) = 0; diff --git a/src/engine/client/backend/opengl/backend_opengl.cpp b/src/engine/client/backend/opengl/backend_opengl.cpp index 43f4f1046..ca2de6ab6 100644 --- a/src/engine/client/backend/opengl/backend_opengl.cpp +++ b/src/engine/client/backend/opengl/backend_opengl.cpp @@ -618,7 +618,7 @@ bool CCommandProcessorFragment_OpenGL::Cmd_Init(const SCommand_Init *pCommand) return true; } -void CCommandProcessorFragment_OpenGL::TextureUpdate(int Slot, int X, int Y, int Width, int Height, int GLFormat, void *pTexData) +void CCommandProcessorFragment_OpenGL::TextureUpdate(int Slot, int X, int Y, int Width, int Height, int GLFormat, uint8_t *pTexData) { glBindTexture(GL_TEXTURE_2D, m_vTextures[Slot].m_Tex); @@ -631,7 +631,7 @@ void CCommandProcessorFragment_OpenGL::TextureUpdate(int Slot, int X, int Y, int int ResizedW = (int)(Width * ResizeW); int ResizedH = (int)(Height * ResizeH); - void *pTmpData = Resize(static_cast(pTexData), Width, Height, ResizedW, ResizedH, GLFormatToPixelSize(GLFormat)); + uint8_t *pTmpData = Resize(pTexData, Width, Height, ResizedW, ResizedH, GLFormatToPixelSize(GLFormat)); free(pTexData); pTexData = pTmpData; @@ -653,7 +653,7 @@ void CCommandProcessorFragment_OpenGL::TextureUpdate(int Slot, int X, int Y, int Y /= 2; } - void *pTmpData = Resize(static_cast(pTexData), OldWidth, OldHeight, Width, Height, GLFormatToPixelSize(GLFormat)); + uint8_t *pTmpData = Resize(pTexData, OldWidth, OldHeight, Width, Height, GLFormatToPixelSize(GLFormat)); free(pTexData); pTexData = pTmpData; } @@ -705,7 +705,7 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Destroy(const CCommandBuffer: DestroyTexture(pCommand->m_Slot); } -void CCommandProcessorFragment_OpenGL::TextureCreate(int Slot, int Width, int Height, int GLFormat, int GLStoreFormat, int Flags, void *pTexData) +void CCommandProcessorFragment_OpenGL::TextureCreate(int Slot, int Width, int Height, int GLFormat, int GLStoreFormat, int Flags, uint8_t *pTexData) { #ifndef BACKEND_GL_MODERN_API @@ -728,7 +728,7 @@ void CCommandProcessorFragment_OpenGL::TextureCreate(int Slot, int Width, int He int PowerOfTwoHeight = HighestBit(Height); if(Width != PowerOfTwoWidth || Height != PowerOfTwoHeight) { - void *pTmpData = Resize(static_cast(pTexData), Width, Height, PowerOfTwoWidth, PowerOfTwoHeight, GLFormatToPixelSize(GLFormat)); + uint8_t *pTmpData = Resize(pTexData, Width, Height, PowerOfTwoWidth, PowerOfTwoHeight, GLFormatToPixelSize(GLFormat)); free(pTexData); pTexData = pTmpData; @@ -760,7 +760,7 @@ void CCommandProcessorFragment_OpenGL::TextureCreate(int Slot, int Width, int He if(NeedsResize) { - void *pTmpData = Resize(static_cast(pTexData), OldWidth, OldHeight, Width, Height, GLFormatToPixelSize(GLFormat)); + uint8_t *pTmpData = Resize(pTexData, OldWidth, OldHeight, Width, Height, GLFormatToPixelSize(GLFormat)); free(pTexData); pTexData = pTmpData; } @@ -867,9 +867,7 @@ void CCommandProcessorFragment_OpenGL::TextureCreate(int Slot, int Width, int He glBindSampler(0, 0); } - uint8_t *p3DImageData = NULL; - - p3DImageData = (uint8_t *)malloc((size_t)Width * Height * PixelSize); + uint8_t *p3DImageData = static_cast(malloc((size_t)Width * Height * PixelSize)); int Image3DWidth, Image3DHeight; int ConvertWidth = Width; @@ -880,7 +878,7 @@ void CCommandProcessorFragment_OpenGL::TextureCreate(int Slot, int Width, int He dbg_msg("gfx", "3D/2D array texture was resized"); int NewWidth = maximum(HighestBit(ConvertWidth), 16); int NewHeight = maximum(HighestBit(ConvertHeight), 16); - uint8_t *pNewTexData = (uint8_t *)Resize((const uint8_t *)pTexData, ConvertWidth, ConvertHeight, NewWidth, NewHeight, GLFormatToPixelSize(GLFormat)); + uint8_t *pNewTexData = Resize(pTexData, ConvertWidth, ConvertHeight, NewWidth, NewHeight, GLFormatToPixelSize(GLFormat)); ConvertWidth = NewWidth; ConvertHeight = NewHeight; @@ -889,7 +887,7 @@ void CCommandProcessorFragment_OpenGL::TextureCreate(int Slot, int Width, int He pTexData = pNewTexData; } - if((Texture2DTo3D(pTexData, ConvertWidth, ConvertHeight, PixelSize, 16, 16, p3DImageData, Image3DWidth, Image3DHeight))) + if(Texture2DTo3D(pTexData, ConvertWidth, ConvertHeight, PixelSize, 16, 16, p3DImageData, Image3DWidth, Image3DHeight)) { glTexImage3D(Target, 0, GLStoreFormat, Image3DWidth, Image3DHeight, 256, 0, GLFormat, GL_UNSIGNED_BYTE, p3DImageData); } @@ -1874,7 +1872,7 @@ void CCommandProcessorFragment_OpenGL2::Cmd_CreateBufferObject(const CCommandBuf SBufferObject &BufferObject = m_vBufferObjectIndices[Index]; BufferObject.m_BufferObjectId = VertBufferId; BufferObject.m_DataSize = pCommand->m_DataSize; - BufferObject.m_pData = malloc(pCommand->m_DataSize); + BufferObject.m_pData = static_cast(malloc(pCommand->m_DataSize)); if(pUploadData) mem_copy(BufferObject.m_pData, pUploadData, pCommand->m_DataSize); @@ -1894,7 +1892,7 @@ void CCommandProcessorFragment_OpenGL2::Cmd_RecreateBufferObject(const CCommandB BufferObject.m_DataSize = pCommand->m_DataSize; free(BufferObject.m_pData); - BufferObject.m_pData = malloc(pCommand->m_DataSize); + BufferObject.m_pData = static_cast(malloc(pCommand->m_DataSize)); if(pUploadData) mem_copy(BufferObject.m_pData, pUploadData, pCommand->m_DataSize); @@ -1913,7 +1911,7 @@ void CCommandProcessorFragment_OpenGL2::Cmd_UpdateBufferObject(const CCommandBuf glBindBuffer(GL_ARRAY_BUFFER, 0); if(pUploadData) - mem_copy(((uint8_t *)BufferObject.m_pData) + (ptrdiff_t)pCommand->m_pOffset, pUploadData, pCommand->m_DataSize); + mem_copy(BufferObject.m_pData + (ptrdiff_t)pCommand->m_pOffset, pUploadData, pCommand->m_DataSize); if(pCommand->m_DeletePointer) free(pUploadData); @@ -1927,10 +1925,10 @@ void CCommandProcessorFragment_OpenGL2::Cmd_CopyBufferObject(const CCommandBuffe SBufferObject &ReadBufferObject = m_vBufferObjectIndices[ReadIndex]; SBufferObject &WriteBufferObject = m_vBufferObjectIndices[WriteIndex]; - mem_copy(((uint8_t *)WriteBufferObject.m_pData) + (ptrdiff_t)pCommand->m_WriteOffset, ((uint8_t *)ReadBufferObject.m_pData) + (ptrdiff_t)pCommand->m_ReadOffset, pCommand->m_CopySize); + mem_copy(WriteBufferObject.m_pData + (ptrdiff_t)pCommand->m_WriteOffset, ReadBufferObject.m_pData + (ptrdiff_t)pCommand->m_ReadOffset, pCommand->m_CopySize); glBindBuffer(GL_ARRAY_BUFFER, WriteBufferObject.m_BufferObjectId); - glBufferSubData(GL_ARRAY_BUFFER, (GLintptr)(pCommand->m_WriteOffset), (GLsizeiptr)(pCommand->m_CopySize), ((uint8_t *)WriteBufferObject.m_pData) + (ptrdiff_t)pCommand->m_WriteOffset); + glBufferSubData(GL_ARRAY_BUFFER, (GLintptr)(pCommand->m_WriteOffset), (GLsizeiptr)(pCommand->m_CopySize), WriteBufferObject.m_pData + (ptrdiff_t)pCommand->m_WriteOffset); glBindBuffer(GL_ARRAY_BUFFER, 0); } diff --git a/src/engine/client/backend/opengl/backend_opengl.h b/src/engine/client/backend/opengl/backend_opengl.h index 274472c9d..db8dd5603 100644 --- a/src/engine/client/backend/opengl/backend_opengl.h +++ b/src/engine/client/backend/opengl/backend_opengl.h @@ -85,8 +85,8 @@ protected: static int TexFormatToOpenGLFormat(int TexFormat); static size_t GLFormatToPixelSize(int GLFormat); - void TextureUpdate(int Slot, int X, int Y, int Width, int Height, int GLFormat, void *pTexData); - void TextureCreate(int Slot, int Width, int Height, int GLFormat, int GLStoreFormat, int Flags, void *pTexData); + void TextureUpdate(int Slot, int X, int Y, int Width, int Height, int GLFormat, uint8_t *pTexData); + void TextureCreate(int Slot, int Width, int Height, int GLFormat, int GLStoreFormat, int Flags, uint8_t *pTexData); virtual bool Cmd_Init(const SCommand_Init *pCommand); virtual void Cmd_Shutdown(const SCommand_Shutdown *pCommand) {} @@ -151,7 +151,7 @@ class CCommandProcessorFragment_OpenGL2 : public CCommandProcessorFragment_OpenG m_DataSize = 0; } TWGLuint m_BufferObjectId; - void *m_pData; + uint8_t *m_pData; size_t m_DataSize; }; diff --git a/src/engine/client/backend/opengl/backend_opengl3.cpp b/src/engine/client/backend/opengl/backend_opengl3.cpp index 9ca7c5515..aae53b915 100644 --- a/src/engine/client/backend/opengl/backend_opengl3.cpp +++ b/src/engine/client/backend/opengl/backend_opengl3.cpp @@ -488,7 +488,7 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Shutdown(const SCommand_Shutdown * m_vBufferContainers.clear(); } -void CCommandProcessorFragment_OpenGL3_3::TextureUpdate(int Slot, int X, int Y, int Width, int Height, int GLFormat, void *pTexData) +void CCommandProcessorFragment_OpenGL3_3::TextureUpdate(int Slot, int X, int Y, int Width, int Height, int GLFormat, uint8_t *pTexData) { glBindTexture(GL_TEXTURE_2D, m_vTextures[Slot].m_Tex); @@ -503,7 +503,7 @@ void CCommandProcessorFragment_OpenGL3_3::TextureUpdate(int Slot, int X, int Y, Y /= 2; } - void *pTmpData = Resize(static_cast(pTexData), Width, Height, Width, Height, GLFormatToPixelSize(GLFormat)); + uint8_t *pTmpData = Resize(pTexData, Width, Height, Width, Height, GLFormatToPixelSize(GLFormat)); free(pTexData); pTexData = pTmpData; } @@ -525,7 +525,7 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Texture_Destroy(const CCommandBuff DestroyTexture(pCommand->m_Slot); } -void CCommandProcessorFragment_OpenGL3_3::TextureCreate(int Slot, int Width, int Height, int GLFormat, int GLStoreFormat, int Flags, void *pTexData) +void CCommandProcessorFragment_OpenGL3_3::TextureCreate(int Slot, int Width, int Height, int GLFormat, int GLStoreFormat, int Flags, uint8_t *pTexData) { while(Slot >= (int)m_vTextures.size()) m_vTextures.resize(m_vTextures.size() * 2); @@ -543,7 +543,7 @@ void CCommandProcessorFragment_OpenGL3_3::TextureCreate(int Slot, int Width, int ++RescaleCount; } while(Width > m_MaxTexSize || Height > m_MaxTexSize); - void *pTmpData = Resize(static_cast(pTexData), Width, Height, Width, Height, GLFormatToPixelSize(GLFormat)); + uint8_t *pTmpData = Resize(pTexData, Width, Height, Width, Height, GLFormatToPixelSize(GLFormat)); free(pTexData); pTexData = pTmpData; } @@ -618,9 +618,7 @@ void CCommandProcessorFragment_OpenGL3_3::TextureCreate(int Slot, int Width, int glSamplerParameterf(m_vTextures[Slot].m_Sampler2DArray, GL_TEXTURE_LOD_BIAS, ((GLfloat)m_OpenGLTextureLodBIAS / 1000.0f)); #endif - uint8_t *p3DImageData = NULL; - - p3DImageData = (uint8_t *)malloc((size_t)Width * Height * PixelSize); + uint8_t *p3DImageData = static_cast(malloc((size_t)Width * Height * PixelSize)); int Image3DWidth, Image3DHeight; int ConvertWidth = Width; @@ -631,7 +629,7 @@ void CCommandProcessorFragment_OpenGL3_3::TextureCreate(int Slot, int Width, int dbg_msg("gfx", "3D/2D array texture was resized"); int NewWidth = maximum(HighestBit(ConvertWidth), 16); int NewHeight = maximum(HighestBit(ConvertHeight), 16); - uint8_t *pNewTexData = (uint8_t *)Resize((const uint8_t *)pTexData, ConvertWidth, ConvertHeight, NewWidth, NewHeight, GLFormatToPixelSize(GLFormat)); + uint8_t *pNewTexData = Resize(pTexData, ConvertWidth, ConvertHeight, NewWidth, NewHeight, GLFormatToPixelSize(GLFormat)); ConvertWidth = NewWidth; ConvertHeight = NewHeight; @@ -640,7 +638,7 @@ void CCommandProcessorFragment_OpenGL3_3::TextureCreate(int Slot, int Width, int pTexData = pNewTexData; } - if((Texture2DTo3D(pTexData, ConvertWidth, ConvertHeight, PixelSize, 16, 16, p3DImageData, Image3DWidth, Image3DHeight))) + if(Texture2DTo3D(pTexData, ConvertWidth, ConvertHeight, PixelSize, 16, 16, p3DImageData, Image3DWidth, Image3DHeight)) { glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GLStoreFormat, Image3DWidth, Image3DHeight, 256, 0, GLFormat, GL_UNSIGNED_BYTE, p3DImageData); glGenerateMipmap(GL_TEXTURE_2D_ARRAY); diff --git a/src/engine/client/backend/opengl/backend_opengl3.h b/src/engine/client/backend/opengl/backend_opengl3.h index 041ce889d..6784bb963 100644 --- a/src/engine/client/backend/opengl/backend_opengl3.h +++ b/src/engine/client/backend/opengl/backend_opengl3.h @@ -78,8 +78,8 @@ protected: void UploadStreamBufferData(unsigned int PrimitiveType, const void *pVertices, size_t VertSize, unsigned int PrimitiveCount, bool AsTex3D = false); void RenderText(const CCommandBuffer::SState &State, int DrawNum, int TextTextureIndex, int TextOutlineTextureIndex, int TextureSize, const ColorRGBA &TextColor, const ColorRGBA &TextOutlineColor); - void TextureUpdate(int Slot, int X, int Y, int Width, int Height, int GLFormat, void *pTexData); - void TextureCreate(int Slot, int Width, int Height, int GLFormat, int GLStoreFormat, int Flags, void *pTexData); + void TextureUpdate(int Slot, int X, int Y, int Width, int Height, int GLFormat, uint8_t *pTexData); + void TextureCreate(int Slot, int Width, int Height, int GLFormat, int GLStoreFormat, int Flags, uint8_t *pTexData); bool Cmd_Init(const SCommand_Init *pCommand) override; void Cmd_Shutdown(const SCommand_Shutdown *pCommand) override; diff --git a/src/engine/client/backend/vulkan/backend_vulkan.cpp b/src/engine/client/backend/vulkan/backend_vulkan.cpp index 429c36aff..a196a0f57 100644 --- a/src/engine/client/backend/vulkan/backend_vulkan.cpp +++ b/src/engine/client/backend/vulkan/backend_vulkan.cpp @@ -502,9 +502,9 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase size_t m_OffsetInBuffer = 0; size_t m_Size; size_t m_UsedSize; - void *m_pMappedBufferData; + uint8_t *m_pMappedBufferData; - SFrameBuffers(VkBuffer Buffer, SDeviceMemoryBlock BufferMem, size_t OffsetInBuffer, size_t Size, size_t UsedSize, void *pMappedBufferData) : + SFrameBuffers(VkBuffer Buffer, SDeviceMemoryBlock BufferMem, size_t OffsetInBuffer, size_t Size, size_t UsedSize, uint8_t *pMappedBufferData) : m_Buffer(Buffer), m_BufferMem(BufferMem), m_OffsetInBuffer(OffsetInBuffer), m_Size(Size), m_UsedSize(UsedSize), m_pMappedBufferData(pMappedBufferData) { } @@ -514,7 +514,7 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase { std::array m_aUniformSets; - SFrameUniformBuffers(VkBuffer Buffer, SDeviceMemoryBlock BufferMem, size_t OffsetInBuffer, size_t Size, size_t UsedSize, void *pMappedBufferData) : + SFrameUniformBuffers(VkBuffer Buffer, SDeviceMemoryBlock BufferMem, size_t OffsetInBuffer, size_t Size, size_t UsedSize, uint8_t *pMappedBufferData) : SFrameBuffers(Buffer, BufferMem, OffsetInBuffer, Size, UsedSize, pMappedBufferData) {} }; @@ -2528,7 +2528,7 @@ protected: return 4; } - [[nodiscard]] bool UpdateTexture(size_t TextureSlot, VkFormat Format, void *&pData, int64_t XOff, int64_t YOff, size_t Width, size_t Height) + [[nodiscard]] bool UpdateTexture(size_t TextureSlot, VkFormat Format, uint8_t *&pData, int64_t XOff, int64_t YOff, size_t Width, size_t Height) { const size_t ImageSize = Width * Height * VulkanFormatToPixelSize(Format); SMemoryBlock StagingBuffer; @@ -2548,7 +2548,7 @@ protected: YOff /= 2; } - void *pTmpData = Resize((const uint8_t *)pData, Width, Height, Width, Height, VulkanFormatToPixelSize(Format)); + uint8_t *pTmpData = Resize(pData, Width, Height, Width, Height, VulkanFormatToPixelSize(Format)); free(pData); pData = pTmpData; } @@ -2581,7 +2581,7 @@ protected: VkFormat Format, VkFormat StoreFormat, int Flags, - void *&pData) + uint8_t *&pData) { size_t ImageIndex = (size_t)Slot; const size_t PixelSize = VulkanFormatToPixelSize(Format); @@ -2602,7 +2602,7 @@ protected: ++RescaleCount; } while((size_t)Width > m_MaxTextureSize || (size_t)Height > m_MaxTextureSize); - void *pTmpData = Resize((const uint8_t *)(pData), Width, Height, Width, Height, PixelSize); + uint8_t *pTmpData = Resize(pData, Width, Height, Width, Height, PixelSize); free(pData); pData = pTmpData; } @@ -2657,7 +2657,7 @@ protected: dbg_msg("vulkan", "3D/2D array texture was resized"); int NewWidth = maximum(HighestBit(ConvertWidth), 16); int NewHeight = maximum(HighestBit(ConvertHeight), 16); - uint8_t *pNewTexData = (uint8_t *)Resize((const uint8_t *)pData, ConvertWidth, ConvertHeight, NewWidth, NewHeight, PixelSize); + uint8_t *pNewTexData = Resize(pData, ConvertWidth, ConvertHeight, NewWidth, NewHeight, PixelSize); ConvertWidth = NewWidth; ConvertHeight = NewHeight; @@ -2667,7 +2667,7 @@ protected: } bool Needs3DTexDel = false; - void *p3DTexData = malloc((size_t)PixelSize * ConvertWidth * ConvertHeight); + uint8_t *p3DTexData = static_cast(malloc((size_t)PixelSize * ConvertWidth * ConvertHeight)); if(!Texture2DTo3D(pData, ConvertWidth, ConvertHeight, PixelSize, 16, 16, p3DTexData, Image3DWidth, Image3DHeight)) { free(p3DTexData); @@ -2793,9 +2793,9 @@ protected: return true; } - [[nodiscard]] bool CreateTextureImage(size_t ImageIndex, VkImage &NewImage, SMemoryImageBlock &NewImgMem, const void *pData, VkFormat Format, size_t Width, size_t Height, size_t Depth, size_t PixelSize, size_t MipMapLevelCount) + [[nodiscard]] bool CreateTextureImage(size_t ImageIndex, VkImage &NewImage, SMemoryImageBlock &NewImgMem, const uint8_t *pData, VkFormat Format, size_t Width, size_t Height, size_t Depth, size_t PixelSize, size_t MipMapLevelCount) { - int ImageSize = Width * Height * Depth * PixelSize; + VkDeviceSize ImageSize = Width * Height * Depth * PixelSize; SMemoryBlock StagingBuffer; if(!GetStagingBufferImage(StagingBuffer, pData, ImageSize)) @@ -6303,7 +6303,7 @@ public: BufferMem = BufferOfFrame.m_BufferMem; Offset = BufferOfFrame.m_UsedSize; BufferOfFrame.m_UsedSize += DataSize; - pMem = (uint8_t *)BufferOfFrame.m_pMappedBufferData; + pMem = BufferOfFrame.m_pMappedBufferData; pBufferMem = &BufferOfFrame; break; } @@ -6336,7 +6336,7 @@ public: BufferMem = StreamBufferMemory; pBufferMem = &NewStreamBuffer; - pMem = (uint8_t *)NewStreamBuffer.m_pMappedBufferData; + pMem = NewStreamBuffer.m_pMappedBufferData; Offset = NewStreamBuffer.m_OffsetInBuffer; NewStreamBuffer.m_UsedSize += DataSize; @@ -6634,8 +6634,7 @@ public: [[nodiscard]] bool Cmd_Texture_Update(const CCommandBuffer::SCommand_Texture_Update *pCommand) { size_t IndexTex = pCommand->m_Slot; - - void *pData = pCommand->m_pData; + uint8_t *pData = pCommand->m_pData; if(!UpdateTexture(IndexTex, VK_FORMAT_B8G8R8A8_UNORM, pData, pCommand->m_X, pCommand->m_Y, pCommand->m_Width, pCommand->m_Height)) return false; @@ -6665,7 +6664,7 @@ public: int Format = pCommand->m_Format; int StoreFormat = pCommand->m_StoreFormat; int Flags = pCommand->m_Flags; - void *pData = pCommand->m_pData; + uint8_t *pData = pCommand->m_pData; if(!CreateTextureCMD(Slot, Width, Height, TextureFormatToVulkanFormat(Format), TextureFormatToVulkanFormat(StoreFormat), Flags, pData)) return false; @@ -6682,8 +6681,8 @@ public: int Width = pCommand->m_Width; int Height = pCommand->m_Height; - void *pTmpData = pCommand->m_pTextData; - void *pTmpData2 = pCommand->m_pTextOutlineData; + uint8_t *pTmpData = pCommand->m_pTextData; + uint8_t *pTmpData2 = pCommand->m_pTextOutlineData; if(!CreateTextureCMD(Slot, Width, Height, VK_FORMAT_R8_UNORM, VK_FORMAT_R8_UNORM, CCommandBuffer::TEXFLAG_NOMIPMAPS, pTmpData)) return false; @@ -6717,8 +6716,7 @@ public: [[nodiscard]] bool Cmd_TextTexture_Update(const CCommandBuffer::SCommand_TextTexture_Update *pCommand) { size_t IndexTex = pCommand->m_Slot; - - void *pData = pCommand->m_pData; + uint8_t *pData = pCommand->m_pData; if(!UpdateTexture(IndexTex, VK_FORMAT_R8_UNORM, pData, pCommand->m_X, pCommand->m_Y, pCommand->m_Width, pCommand->m_Height)) return false; @@ -6819,7 +6817,7 @@ public: if(GetPresentedImageDataImpl(Width, Height, Format, m_vScreenshotHelper, true, {})) { const size_t ImgSize = (size_t)Width * (size_t)Height * CImageInfo::PixelSize(Format); - pCommand->m_pImage->m_pData = malloc(ImgSize); + pCommand->m_pImage->m_pData = static_cast(malloc(ImgSize)); mem_copy(pCommand->m_pImage->m_pData, m_vScreenshotHelper.data(), ImgSize); } else diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index e22dda5f6..5c22d9d80 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -337,7 +337,7 @@ static bool ConvertToRGBA(uint8_t *pDest, const uint8_t *pSrc, size_t SrcWidth, } } -int CGraphics_Threaded::LoadTextureRawSub(CTextureHandle TextureId, int x, int y, size_t Width, size_t Height, CImageInfo::EImageFormat Format, const void *pData) +int CGraphics_Threaded::LoadTextureRawSub(CTextureHandle TextureId, int x, int y, size_t Width, size_t Height, CImageInfo::EImageFormat Format, const uint8_t *pData) { dbg_assert(TextureId.IsValid(), "Invalid texture handle used with LoadTextureRawSub."); @@ -353,8 +353,8 @@ int CGraphics_Threaded::LoadTextureRawSub(CTextureHandle TextureId, int x, int y const size_t MemSize = Width * Height * CImageInfo::PixelSize(CImageInfo::FORMAT_RGBA); // copy texture data - void *pTmpData = malloc(MemSize); - ConvertToRGBA((uint8_t *)pTmpData, (const uint8_t *)pData, Width, Height, Format); + uint8_t *pTmpData = static_cast(malloc(MemSize)); + ConvertToRGBA(pTmpData, pData, Width, Height, Format); Cmd.m_pData = pTmpData; AddCmd(Cmd); @@ -365,7 +365,7 @@ IGraphics::CTextureHandle CGraphics_Threaded::LoadSpriteTextureImpl(CImageInfo & { const size_t PixelSize = FromImageInfo.PixelSize(); m_vSpriteHelper.resize(w * h * PixelSize); - CopyTextureFromTextureBufferSub(m_vSpriteHelper.data(), w, h, (uint8_t *)FromImageInfo.m_pData, FromImageInfo.m_Width, FromImageInfo.m_Height, PixelSize, x, y, w, h); + CopyTextureFromTextureBufferSub(m_vSpriteHelper.data(), w, h, FromImageInfo.m_pData, FromImageInfo.m_Width, FromImageInfo.m_Height, PixelSize, x, y, w, h); return LoadTextureRaw(w, h, FromImageInfo.m_Format, m_vSpriteHelper.data(), 0); } @@ -384,7 +384,7 @@ bool CGraphics_Threaded::IsImageSubFullyTransparent(CImageInfo &FromImageInfo, i { if(FromImageInfo.m_Format == CImageInfo::FORMAT_SINGLE_COMPONENT || FromImageInfo.m_Format == CImageInfo::FORMAT_RGBA) { - uint8_t *pImgData = (uint8_t *)FromImageInfo.m_pData; + const uint8_t *pImgData = FromImageInfo.m_pData; const size_t PixelSize = FromImageInfo.PixelSize(); for(int iy = 0; iy < h; ++iy) { @@ -450,7 +450,7 @@ static CCommandBuffer::SCommand_Texture_Create LoadTextureCreateCommand(int Text return Cmd; } -IGraphics::CTextureHandle CGraphics_Threaded::LoadTextureRaw(size_t Width, size_t Height, CImageInfo::EImageFormat Format, const void *pData, int Flags, const char *pTexName) +IGraphics::CTextureHandle CGraphics_Threaded::LoadTextureRaw(size_t Width, size_t Height, CImageInfo::EImageFormat Format, const uint8_t *pData, int Flags, const char *pTexName) { LoadTextureAddWarning(Width, Height, Flags, pTexName, m_vWarnings); @@ -462,8 +462,8 @@ IGraphics::CTextureHandle CGraphics_Threaded::LoadTextureRaw(size_t Width, size_ // Copy texture data and convert if necessary const size_t MemSize = Width * Height * CImageInfo::PixelSize(CImageInfo::FORMAT_RGBA); - void *pTmpData = malloc(MemSize); - if(!ConvertToRGBA(static_cast(pTmpData), static_cast(pData), Width, Height, Format)) + uint8_t *pTmpData = static_cast(malloc(MemSize)); + if(!ConvertToRGBA(pTmpData, pData, Width, Height, Format)) { dbg_msg("graphics", "converted image '%s' to RGBA, consider making its file format RGBA", pTexName ? pTexName : "(no name)"); } @@ -474,7 +474,7 @@ IGraphics::CTextureHandle CGraphics_Threaded::LoadTextureRaw(size_t Width, size_ return TextureHandle; } -IGraphics::CTextureHandle CGraphics_Threaded::LoadTextureRawMove(size_t Width, size_t Height, CImageInfo::EImageFormat Format, void *pData, int Flags, const char *pTexName) +IGraphics::CTextureHandle CGraphics_Threaded::LoadTextureRawMove(size_t Width, size_t Height, CImageInfo::EImageFormat Format, uint8_t *pData, int Flags, const char *pTexName) { if(Format != CImageInfo::FORMAT_RGBA) { @@ -522,7 +522,7 @@ IGraphics::CTextureHandle CGraphics_Threaded::NullTexture() const return m_NullTexture; } -bool CGraphics_Threaded::LoadTextTextures(size_t Width, size_t Height, CTextureHandle &TextTexture, CTextureHandle &TextOutlineTexture, void *pTextData, void *pTextOutlineData) +bool CGraphics_Threaded::LoadTextTextures(size_t Width, size_t Height, CTextureHandle &TextTexture, CTextureHandle &TextOutlineTexture, uint8_t *pTextData, uint8_t *pTextOutlineData) { if(Width == 0 || Height == 0) return false; @@ -556,7 +556,7 @@ bool CGraphics_Threaded::UnloadTextTextures(CTextureHandle &TextTexture, CTextur return true; } -bool CGraphics_Threaded::UpdateTextTexture(CTextureHandle TextureId, int x, int y, size_t Width, size_t Height, const void *pData) +bool CGraphics_Threaded::UpdateTextTexture(CTextureHandle TextureId, int x, int y, size_t Width, size_t Height, const uint8_t *pData) { CCommandBuffer::SCommand_TextTexture_Update Cmd; Cmd.m_Slot = TextureId.Id(); @@ -569,7 +569,7 @@ bool CGraphics_Threaded::UpdateTextTexture(CTextureHandle TextureId, int x, int const size_t MemSize = Width * Height; // copy texture data - void *pTmpData = malloc(MemSize); + uint8_t *pTmpData = static_cast(malloc(MemSize)); mem_copy(pTmpData, pData, MemSize); Cmd.m_pData = pTmpData; AddCmd(Cmd); @@ -694,7 +694,7 @@ bool CGraphics_Threaded::CheckImageDivisibility(const char *pFileName, CImageInf NewWidth = (NewHeight / DivY) * DivX; } - uint8_t *pNewImg = ResizeImage((uint8_t *)Img.m_pData, Img.m_Width, Img.m_Height, NewWidth, NewHeight, Img.PixelSize()); + uint8_t *pNewImg = ResizeImage(Img.m_pData, Img.m_Width, Img.m_Height, NewWidth, NewHeight, Img.PixelSize()); free(Img.m_pData); Img.m_pData = pNewImg; Img.m_Width = NewWidth; @@ -773,7 +773,7 @@ class CScreenshotSaveJob : public IJob char m_aName[IO_MAX_PATH_LENGTH]; int m_Width; int m_Height; - void *m_pData; + uint8_t *m_pData; void Run() override { @@ -785,7 +785,7 @@ class CScreenshotSaveJob : public IJob TImageByteBuffer ByteBuffer; SImageByteBuffer ImageByteBuffer(&ByteBuffer); - if(SavePNG(IMAGE_FORMAT_RGBA, (const uint8_t *)m_pData, ImageByteBuffer, m_Width, m_Height)) + if(SavePNG(IMAGE_FORMAT_RGBA, m_pData, ImageByteBuffer, m_Width, m_Height)) io_write(File, &ByteBuffer.front(), ByteBuffer.size()); io_close(File); @@ -799,7 +799,7 @@ class CScreenshotSaveJob : public IJob } public: - CScreenshotSaveJob(IStorage *pStorage, IConsole *pConsole, const char *pName, int Width, int Height, void *pData) : + CScreenshotSaveJob(IStorage *pStorage, IConsole *pConsole, const char *pName, int Width, int Height, uint8_t *pData) : m_pStorage(pStorage), m_pConsole(pConsole), m_Width(Width), diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index ba756e4c9..9c8f1f702 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -530,7 +530,7 @@ public: int m_Format; int m_StoreFormat; int m_Flags; - void *m_pData; // will be freed by the command processor + uint8_t *m_pData; // will be freed by the command processor }; struct SCommand_Texture_Update : public SCommand @@ -546,7 +546,7 @@ public: size_t m_Width; size_t m_Height; int m_Format; - void *m_pData; // will be freed by the command processor + uint8_t *m_pData; // will be freed by the command processor }; struct SCommand_Texture_Destroy : public SCommand @@ -570,8 +570,8 @@ public: size_t m_Width; size_t m_Height; - void *m_pTextData; - void *m_pTextOutlineData; + uint8_t *m_pTextData; // will be freed by the command processor + uint8_t *m_pTextOutlineData; // will be freed by the command processor }; struct SCommand_TextTextures_Destroy : public SCommand @@ -596,7 +596,7 @@ public: int m_Y; size_t m_Width; size_t m_Height; - void *m_pData; // will be freed by the command processor + uint8_t *m_pData; // will be freed by the command processor }; struct SCommand_WindowCreateNtf : public CCommandBuffer::SCommand @@ -965,14 +965,14 @@ public: IGraphics::CTextureHandle FindFreeTextureIndex(); void FreeTextureIndex(CTextureHandle *pIndex); int UnloadTexture(IGraphics::CTextureHandle *pIndex) override; - IGraphics::CTextureHandle LoadTextureRaw(size_t Width, size_t Height, CImageInfo::EImageFormat Format, const void *pData, int Flags, const char *pTexName = nullptr) override; - IGraphics::CTextureHandle LoadTextureRawMove(size_t Width, size_t Height, CImageInfo::EImageFormat Format, void *pData, int Flags, const char *pTexName = nullptr) override; - int LoadTextureRawSub(IGraphics::CTextureHandle TextureId, int x, int y, size_t Width, size_t Height, CImageInfo::EImageFormat Format, const void *pData) override; + IGraphics::CTextureHandle LoadTextureRaw(size_t Width, size_t Height, CImageInfo::EImageFormat Format, const uint8_t *pData, int Flags, const char *pTexName = nullptr) override; + IGraphics::CTextureHandle LoadTextureRawMove(size_t Width, size_t Height, CImageInfo::EImageFormat Format, uint8_t *pData, int Flags, const char *pTexName = nullptr) override; + int LoadTextureRawSub(IGraphics::CTextureHandle TextureId, int x, int y, size_t Width, size_t Height, CImageInfo::EImageFormat Format, const uint8_t *pData) override; IGraphics::CTextureHandle NullTexture() const override; - bool LoadTextTextures(size_t Width, size_t Height, CTextureHandle &TextTexture, CTextureHandle &TextOutlineTexture, void *pTextData, void *pTextOutlineData) override; + bool LoadTextTextures(size_t Width, size_t Height, CTextureHandle &TextTexture, CTextureHandle &TextOutlineTexture, uint8_t *pTextData, uint8_t *pTextOutlineData) override; bool UnloadTextTextures(CTextureHandle &TextTexture, CTextureHandle &TextOutlineTexture) override; - bool UpdateTextTexture(CTextureHandle TextureId, int x, int y, size_t Width, size_t Height, const void *pData) override; + bool UpdateTextTexture(CTextureHandle TextureId, int x, int y, size_t Width, size_t Height, const uint8_t *pData) override; CTextureHandle LoadSpriteTextureImpl(CImageInfo &FromImageInfo, int x, int y, size_t w, size_t h); CTextureHandle LoadSpriteTexture(CImageInfo &FromImageInfo, struct CDataSprite *pSprite) override; diff --git a/src/engine/client/text.cpp b/src/engine/client/text.cpp index c77bca98e..778e4d76b 100644 --- a/src/engine/client/text.cpp +++ b/src/engine/client/text.cpp @@ -391,8 +391,8 @@ private: void UploadTextures() { const size_t NewTextureSize = m_TextureDimension * m_TextureDimension; - void *pTmpTextFillData = malloc(NewTextureSize); - void *pTmpTextOutlineData = malloc(NewTextureSize); + uint8_t *pTmpTextFillData = static_cast(malloc(NewTextureSize)); + uint8_t *pTmpTextOutlineData = static_cast(malloc(NewTextureSize)); mem_copy(pTmpTextFillData, m_apTextureData[FONT_TEXTURE_FILL], NewTextureSize); mem_copy(pTmpTextOutlineData, m_apTextureData[FONT_TEXTURE_OUTLINE], NewTextureSize); Graphics()->LoadTextTextures(m_TextureDimension, m_TextureDimension, m_aTextures[FONT_TEXTURE_FILL], m_aTextures[FONT_TEXTURE_OUTLINE], pTmpTextFillData, pTmpTextOutlineData); @@ -729,7 +729,7 @@ public: return vec2(0.0f, 0.0f); } - void UploadEntityLayerText(void *pTexBuff, size_t PixelSize, size_t TexWidth, size_t TexHeight, int TexSubWidth, int TexSubHeight, const char *pText, int Length, float x, float y, int FontSize) + void UploadEntityLayerText(uint8_t *pTexBuff, size_t PixelSize, size_t TexWidth, size_t TexHeight, int TexSubWidth, int TexSubHeight, const char *pText, int Length, float x, float y, int FontSize) { if(FontSize < 1) return; @@ -770,7 +770,6 @@ public: else mem_zero(m_aaGlyphData[FONT_TEXTURE_FILL], GlyphDataSize); - uint8_t *pImageBuff = (uint8_t *)pTexBuff; for(unsigned OffY = 0; OffY < pBitmap->rows; ++OffY) { for(unsigned OffX = 0; OffX < pBitmap->width; ++OffX) @@ -783,11 +782,11 @@ public: { if(i != PixelSize - 1) { - *(pImageBuff + ImageOffset + i) = 255; + *(pTexBuff + ImageOffset + i) = 255; } else { - *(pImageBuff + ImageOffset + i) = *(m_aaGlyphData[FONT_TEXTURE_FILL] + GlyphOffset); + *(pTexBuff + ImageOffset + i) = *(m_aaGlyphData[FONT_TEXTURE_FILL] + GlyphOffset); } } } @@ -2181,7 +2180,7 @@ public: return TextContainer.m_BoundingBox; } - void UploadEntityLayerText(void *pTexBuff, size_t PixelSize, size_t TexWidth, size_t TexHeight, int TexSubWidth, int TexSubHeight, const char *pText, int Length, float x, float y, int FontSize) override + void UploadEntityLayerText(uint8_t *pTexBuff, size_t PixelSize, size_t TexWidth, size_t TexHeight, int TexSubWidth, int TexSubHeight, const char *pText, int Length, float x, float y, int FontSize) override { m_pGlyphMap->UploadEntityLayerText(pTexBuff, PixelSize, TexWidth, TexHeight, TexSubWidth, TexSubHeight, pText, Length, x, y, FontSize); } diff --git a/src/engine/gfx/image_manipulation.cpp b/src/engine/gfx/image_manipulation.cpp index 992ab7311..c01bc3939 100644 --- a/src/engine/gfx/image_manipulation.cpp +++ b/src/engine/gfx/image_manipulation.cpp @@ -4,7 +4,7 @@ #define TW_DILATE_ALPHA_THRESHOLD 10 -static void Dilate(int w, int h, const unsigned char *pSrc, unsigned char *pDest, unsigned char AlphaThreshold = TW_DILATE_ALPHA_THRESHOLD) +static void Dilate(int w, int h, const uint8_t *pSrc, uint8_t *pDest, uint8_t AlphaThreshold = TW_DILATE_ALPHA_THRESHOLD) { const int BPP = 4; // RGBA assumed int ix, iy; @@ -44,7 +44,7 @@ static void Dilate(int w, int h, const unsigned char *pSrc, unsigned char *pDest for(int i = 0; i < BPP - 1; ++i) { aSumOfOpaque[i] /= Counter; - pDest[m + i] = (unsigned char)aSumOfOpaque[i]; + pDest[m + i] = (uint8_t)aSumOfOpaque[i]; } pDest[m + AlphaCompIndex] = 255; @@ -53,7 +53,7 @@ static void Dilate(int w, int h, const unsigned char *pSrc, unsigned char *pDest } } -static void CopyColorValues(int w, int h, int BPP, const unsigned char *pSrc, unsigned char *pDest) +static void CopyColorValues(int w, int h, int BPP, const uint8_t *pSrc, uint8_t *pDest) { int m = 0; for(int y = 0; y < h; y++) @@ -69,28 +69,26 @@ static void CopyColorValues(int w, int h, int BPP, const unsigned char *pSrc, un } } -void DilateImage(unsigned char *pImageBuff, int w, int h) +void DilateImage(uint8_t *pImageBuff, int w, int h) { DilateImageSub(pImageBuff, w, h, 0, 0, w, h); } -void DilateImageSub(unsigned char *pImageBuff, int w, int h, int x, int y, int sw, int sh) +void DilateImageSub(uint8_t *pImageBuff, int w, int h, int x, int y, int sw, int sh) { const int BPP = 4; // RGBA assumed - unsigned char *apBuffer[2] = {NULL, NULL}; + uint8_t *apBuffer[2] = {NULL, NULL}; - apBuffer[0] = (unsigned char *)malloc((size_t)sw * sh * sizeof(unsigned char) * BPP); - apBuffer[1] = (unsigned char *)malloc((size_t)sw * sh * sizeof(unsigned char) * BPP); - unsigned char *pBufferOriginal = (unsigned char *)malloc((size_t)sw * sh * sizeof(unsigned char) * BPP); - - unsigned char *pPixelBuff = (unsigned char *)pImageBuff; + apBuffer[0] = (uint8_t *)malloc((size_t)sw * sh * sizeof(uint8_t) * BPP); + apBuffer[1] = (uint8_t *)malloc((size_t)sw * sh * sizeof(uint8_t) * BPP); + uint8_t *pBufferOriginal = (uint8_t *)malloc((size_t)sw * sh * sizeof(uint8_t) * BPP); for(int Y = 0; Y < sh; ++Y) { int SrcImgOffset = ((y + Y) * w * BPP) + (x * BPP); int DstImgOffset = (Y * sw * BPP); int CopySize = sw * BPP; - mem_copy(&pBufferOriginal[DstImgOffset], &pPixelBuff[SrcImgOffset], CopySize); + mem_copy(&pBufferOriginal[DstImgOffset], &pImageBuff[SrcImgOffset], CopySize); } Dilate(sw, sh, pBufferOriginal, apBuffer[0]); @@ -111,7 +109,7 @@ void DilateImageSub(unsigned char *pImageBuff, int w, int h, int x, int y, int s int SrcImgOffset = ((y + Y) * w * BPP) + (x * BPP); int DstImgOffset = (Y * sw * BPP); int CopySize = sw * BPP; - mem_copy(&pPixelBuff[SrcImgOffset], &pBufferOriginal[DstImgOffset], CopySize); + mem_copy(&pImageBuff[SrcImgOffset], &pBufferOriginal[DstImgOffset], CopySize); } free(pBufferOriginal); diff --git a/src/engine/gfx/image_manipulation.h b/src/engine/gfx/image_manipulation.h index 58a133540..c427f2ec3 100644 --- a/src/engine/gfx/image_manipulation.h +++ b/src/engine/gfx/image_manipulation.h @@ -4,8 +4,8 @@ #include // These functions assume that the image data is 4 bytes per pixel RGBA -void DilateImage(unsigned char *pImageBuff, int w, int h); -void DilateImageSub(unsigned char *pImageBuff, int w, int h, int x, int y, int sw, int sh); +void DilateImage(uint8_t *pImageBuff, int w, int h); +void DilateImageSub(uint8_t *pImageBuff, int w, int h, int x, int y, int sw, int sh); // returned pointer is allocated with malloc uint8_t *ResizeImage(const uint8_t *pImageData, int Width, int Height, int NewWidth, int NewHeight, int BPP); diff --git a/src/engine/graphics.h b/src/engine/graphics.h index dc00d4b12..7bd43092d 100644 --- a/src/engine/graphics.h +++ b/src/engine/graphics.h @@ -95,7 +95,7 @@ public: /** * Pointer to the image data. */ - void *m_pData = nullptr; + uint8_t *m_pData = nullptr; static size_t PixelSize(EImageFormat Format) { @@ -334,18 +334,18 @@ public: virtual void CopyTextureFromTextureBufferSub(uint8_t *pDestBuffer, size_t DestWidth, size_t DestHeight, uint8_t *pSourceBuffer, size_t SrcWidth, size_t SrcHeight, size_t PixelSize, size_t SrcSubOffsetX, size_t SrcSubOffsetY, size_t SrcSubCopyWidth, size_t SrcSubCopyHeight) = 0; virtual int UnloadTexture(CTextureHandle *pIndex) = 0; - virtual CTextureHandle LoadTextureRaw(size_t Width, size_t Height, CImageInfo::EImageFormat Format, const void *pData, int Flags, const char *pTexName = nullptr) = 0; - virtual CTextureHandle LoadTextureRawMove(size_t Width, size_t Height, CImageInfo::EImageFormat Format, void *pData, int Flags, const char *pTexName = nullptr) = 0; - virtual int LoadTextureRawSub(CTextureHandle TextureId, int x, int y, size_t Width, size_t Height, CImageInfo::EImageFormat Format, const void *pData) = 0; + virtual CTextureHandle LoadTextureRaw(size_t Width, size_t Height, CImageInfo::EImageFormat Format, const uint8_t *pData, int Flags, const char *pTexName = nullptr) = 0; + virtual CTextureHandle LoadTextureRawMove(size_t Width, size_t Height, CImageInfo::EImageFormat Format, uint8_t *pData, int Flags, const char *pTexName = nullptr) = 0; + virtual int LoadTextureRawSub(CTextureHandle TextureId, int x, int y, size_t Width, size_t Height, CImageInfo::EImageFormat Format, const uint8_t *pData) = 0; virtual CTextureHandle LoadTexture(const char *pFilename, int StorageType, int Flags = 0) = 0; virtual CTextureHandle NullTexture() const = 0; virtual void TextureSet(CTextureHandle Texture) = 0; void TextureClear() { TextureSet(CTextureHandle()); } // pTextData & pTextOutlineData are automatically free'd - virtual bool LoadTextTextures(size_t Width, size_t Height, CTextureHandle &TextTexture, CTextureHandle &TextOutlineTexture, void *pTextData, void *pTextOutlineData) = 0; + virtual bool LoadTextTextures(size_t Width, size_t Height, CTextureHandle &TextTexture, CTextureHandle &TextOutlineTexture, uint8_t *pTextData, uint8_t *pTextOutlineData) = 0; virtual bool UnloadTextTextures(CTextureHandle &TextTexture, CTextureHandle &TextOutlineTexture) = 0; - virtual bool UpdateTextTexture(CTextureHandle TextureId, int x, int y, size_t Width, size_t Height, const void *pData) = 0; + virtual bool UpdateTextTexture(CTextureHandle TextureId, int x, int y, size_t Width, size_t Height, const uint8_t *pData) = 0; virtual CTextureHandle LoadSpriteTexture(CImageInfo &FromImageInfo, struct CDataSprite *pSprite) = 0; diff --git a/src/engine/textrender.h b/src/engine/textrender.h index 067ab9062..9dc8725bd 100644 --- a/src/engine/textrender.h +++ b/src/engine/textrender.h @@ -344,7 +344,7 @@ public: virtual STextBoundingBox GetBoundingBoxTextContainer(STextContainerIndex TextContainerIndex) = 0; - virtual void UploadEntityLayerText(void *pTexBuff, size_t PixelSize, size_t TexWidth, size_t TexHeight, int TexSubWidth, int TexSubHeight, const char *pText, int Length, float x, float y, int FontSize) = 0; + virtual void UploadEntityLayerText(uint8_t *pTexBuff, size_t PixelSize, size_t TexWidth, size_t TexHeight, int TexSubWidth, int TexSubHeight, const char *pText, int Length, float x, float y, int FontSize) = 0; virtual int AdjustFontSize(const char *pText, int TextLength, int MaxSize, int MaxWidth) const = 0; virtual float GetGlyphOffsetX(int FontSize, char TextCharacter) const = 0; virtual int CalculateTextWidth(const char *pText, int TextLength, int FontWidth, int FontSize) const = 0; diff --git a/src/game/client/components/mapimages.cpp b/src/game/client/components/mapimages.cpp index 1d911acfd..3f8938e39 100644 --- a/src/game/client/components/mapimages.cpp +++ b/src/game/client/components/mapimages.cpp @@ -131,7 +131,7 @@ void CMapImages::OnMapLoadImpl(class CLayers *pLayers, IMap *pMap) } else if(Format == CImageInfo::FORMAT_RGBA) { - void *pData = pMap->GetData(pImg->m_ImageData); + const uint8_t *pData = static_cast(pMap->GetData(pImg->m_ImageData)); char aTexName[IO_MAX_PATH_LENGTH]; str_format(aTexName, sizeof(aTexName), "embedded: %s", pName); m_aTextures[i] = Graphics()->LoadTextureRaw(pImg->m_Width, pImg->m_Height, Format, pData, LoadFlag, aTexName); @@ -223,7 +223,7 @@ IGraphics::CTextureHandle CMapImages::GetEntities(EMapImageEntityLayerType Entit const size_t PixelSize = ImgInfo.PixelSize(); const size_t BuildImageSize = (size_t)ImgInfo.m_Width * ImgInfo.m_Height * PixelSize; - uint8_t *pTmpImgData = (uint8_t *)ImgInfo.m_pData; + uint8_t *pTmpImgData = ImgInfo.m_pData; uint8_t *pBuildImgData = (uint8_t *)malloc(BuildImageSize); // build game layer @@ -382,7 +382,7 @@ IGraphics::CTextureHandle CMapImages::UploadEntityLayerText(int TextureSize, int const size_t Height = 1024; const size_t PixelSize = CImageInfo::PixelSize(CImageInfo::FORMAT_RGBA); - void *pMem = calloc(Width * Height * PixelSize, 1); + uint8_t *pMem = static_cast(calloc(Width * Height * PixelSize, 1)); UpdateEntityLayerText(pMem, PixelSize, Width, Height, TextureSize, MaxWidth, YOffset, 0); UpdateEntityLayerText(pMem, PixelSize, Width, Height, TextureSize, MaxWidth, YOffset, 1); @@ -392,7 +392,7 @@ IGraphics::CTextureHandle CMapImages::UploadEntityLayerText(int TextureSize, int return Graphics()->LoadTextureRawMove(Width, Height, CImageInfo::FORMAT_RGBA, pMem, TextureLoadFlag); } -void CMapImages::UpdateEntityLayerText(void *pTexBuffer, size_t PixelSize, size_t TexWidth, size_t TexHeight, int TextureSize, int MaxWidth, int YOffset, int NumbersPower, int MaxNumber) +void CMapImages::UpdateEntityLayerText(uint8_t *pTexBuffer, size_t PixelSize, size_t TexWidth, size_t TexHeight, int TextureSize, int MaxWidth, int YOffset, int NumbersPower, int MaxNumber) { char aBuf[4]; int DigitsCount = NumbersPower + 1; diff --git a/src/game/client/components/mapimages.h b/src/game/client/components/mapimages.h index f567c2db1..9f0ac83f0 100644 --- a/src/game/client/components/mapimages.h +++ b/src/game/client/components/mapimages.h @@ -80,7 +80,7 @@ private: void InitOverlayTextures(); IGraphics::CTextureHandle UploadEntityLayerText(int TextureSize, int MaxWidth, int YOffset); - void UpdateEntityLayerText(void *pTexBuffer, size_t PixelSize, size_t TexWidth, size_t TexHeight, int TextureSize, int MaxWidth, int YOffset, int NumbersPower, int MaxNumber = -1); + void UpdateEntityLayerText(uint8_t *pTexBuffer, size_t PixelSize, size_t TexWidth, size_t TexHeight, int TextureSize, int MaxWidth, int YOffset, int NumbersPower, int MaxNumber = -1); }; #endif diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index eec33de67..ff0cb353d 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -866,7 +866,7 @@ bool CEditor::CallbackSaveImage(const char *pFileName, int StorageType, void *pU TImageByteBuffer ByteBuffer; SImageByteBuffer ImageByteBuffer(&ByteBuffer); - if(SavePNG(OutputFormat, static_cast(pImg->m_pData), ImageByteBuffer, pImg->m_Width, pImg->m_Height)) + if(SavePNG(OutputFormat, pImg->m_pData, ImageByteBuffer, pImg->m_Width, pImg->m_Height)) { IOHANDLE File = pEditor->Storage()->OpenFile(pFileName, IOFLAG_WRITE, StorageType); if(File) @@ -4377,7 +4377,7 @@ bool CEditor::ReplaceImage(const char *pFileName, int StorageType, bool CheckDup if(!pImg->m_External && g_Config.m_ClEditorDilate == 1 && pImg->m_Format == CImageInfo::FORMAT_RGBA) { - DilateImage((unsigned char *)ImgInfo.m_pData, ImgInfo.m_Width, ImgInfo.m_Height); + DilateImage(ImgInfo.m_pData, ImgInfo.m_Width, ImgInfo.m_Height); } pImg->m_AutoMapper.Load(pImg->m_aName); @@ -4437,7 +4437,7 @@ bool CEditor::AddImage(const char *pFileName, int StorageType, void *pUser) if(!pImg->m_External && g_Config.m_ClEditorDilate == 1 && pImg->m_Format == CImageInfo::FORMAT_RGBA) { - DilateImage((unsigned char *)ImgInfo.m_pData, ImgInfo.m_Width, ImgInfo.m_Height); + DilateImage(ImgInfo.m_pData, ImgInfo.m_Width, ImgInfo.m_Height); } int TextureLoadFlag = pEditor->Graphics()->Uses2DTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE; diff --git a/src/game/editor/mapitems/image.cpp b/src/game/editor/mapitems/image.cpp index 563d6b302..a3289b839 100644 --- a/src/game/editor/mapitems/image.cpp +++ b/src/game/editor/mapitems/image.cpp @@ -63,8 +63,8 @@ bool CEditorImage::DataEquals(const CEditorImage &Other) const if(Other.m_Height != m_Height || Other.m_Width != m_Width || Other.PixelSize() != ImgPixelSize) return false; - const auto &&GetPixel = [&](void *pData, int x, int y, size_t p) -> uint8_t { - return ((uint8_t *)pData)[x * ImgPixelSize + (m_Width * ImgPixelSize * y) + p]; + const auto &&GetPixel = [&](uint8_t *pData, int x, int y, size_t p) -> uint8_t { + return pData[x * ImgPixelSize + (m_Width * ImgPixelSize * y) + p]; }; // Look through every pixel and check if there are any difference diff --git a/src/game/editor/mapitems/map_io.cpp b/src/game/editor/mapitems/map_io.cpp index 8b51dcf40..5190830b9 100644 --- a/src/game/editor/mapitems/map_io.cpp +++ b/src/game/editor/mapitems/map_io.cpp @@ -524,7 +524,7 @@ bool CEditorMap::Load(const char *pFileName, int StorageType, const std::functio // copy image data void *pData = DataFile.GetData(pItem->m_ImageData); const size_t DataSize = (size_t)pImg->m_Width * pImg->m_Height * CImageInfo::PixelSize(Format); - pImg->m_pData = malloc(DataSize); + pImg->m_pData = static_cast(malloc(DataSize)); mem_copy(pImg->m_pData, pData, DataSize); int TextureLoadFlag = m_pEditor->Graphics()->Uses2DTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE; if(pImg->m_Width % 16 != 0 || pImg->m_Height % 16 != 0) diff --git a/src/game/editor/tileart.cpp b/src/game/editor/tileart.cpp index 5524dce02..c58fc5e6a 100644 --- a/src/game/editor/tileart.cpp +++ b/src/game/editor/tileart.cpp @@ -19,7 +19,7 @@ bool operator<(const ColorRGBA &Left, const ColorRGBA &Right) static ColorRGBA GetPixelColor(const CImageInfo &Image, size_t x, size_t y) { - uint8_t *pData = static_cast(Image.m_pData); + uint8_t *pData = Image.m_pData; const size_t PixelSize = Image.PixelSize(); const size_t PixelStartIndex = x * PixelSize + (Image.m_Width * PixelSize * y); @@ -43,7 +43,7 @@ static ColorRGBA GetPixelColor(const CImageInfo &Image, size_t x, size_t y) static void SetPixelColor(CImageInfo *pImage, size_t x, size_t y, ColorRGBA Color) { - uint8_t *pData = static_cast(pImage->m_pData); + uint8_t *pData = pImage->m_pData; const size_t PixelSize = pImage->PixelSize(); const size_t PixelStartIndex = x * PixelSize + (pImage->m_Width * PixelSize * y); diff --git a/src/tools/dilate.cpp b/src/tools/dilate.cpp index 4a8fcfb9b..ff3e37043 100644 --- a/src/tools/dilate.cpp +++ b/src/tools/dilate.cpp @@ -29,27 +29,18 @@ int DilateFile(const char *pFilename) io_close(File); CImageInfo Img; - - uint8_t *pImgBuffer = NULL; EImageFormat ImageFormat; int PngliteIncompatible; - if(LoadPNG(ImageByteBuffer, pFilename, PngliteIncompatible, Img.m_Width, Img.m_Height, pImgBuffer, ImageFormat)) + if(LoadPNG(ImageByteBuffer, pFilename, PngliteIncompatible, Img.m_Width, Img.m_Height, Img.m_pData, ImageFormat)) { if(ImageFormat != IMAGE_FORMAT_RGBA) { - free(pImgBuffer); + free(Img.m_pData); dbg_msg("dilate", "%s: not an RGBA image", pFilename); return -1; } - Img.m_pData = pImgBuffer; - - unsigned char *pBuffer = (unsigned char *)Img.m_pData; - - int w = Img.m_Width; - int h = Img.m_Height; - - DilateImage(pBuffer, w, h); + DilateImage(Img.m_pData, Img.m_Width, Img.m_Height); // save here IOHANDLE SaveFile = io_open(pFilename, IOFLAG_WRITE); @@ -58,11 +49,11 @@ int DilateFile(const char *pFilename) TImageByteBuffer ByteBuffer2; SImageByteBuffer ImageByteBuffer2(&ByteBuffer2); - if(SavePNG(IMAGE_FORMAT_RGBA, (const uint8_t *)pBuffer, ImageByteBuffer2, w, h)) + if(SavePNG(IMAGE_FORMAT_RGBA, Img.m_pData, ImageByteBuffer2, Img.m_Width, Img.m_Height)) io_write(SaveFile, &ByteBuffer2.front(), ByteBuffer2.size()); io_close(SaveFile); - free(pBuffer); + free(Img.m_pData); } } else diff --git a/src/tools/map_create_pixelart.cpp b/src/tools/map_create_pixelart.cpp index 5f179672c..5ce88183a 100644 --- a/src/tools/map_create_pixelart.cpp +++ b/src/tools/map_create_pixelart.cpp @@ -222,7 +222,7 @@ bool GetPixelClamped(const CImageInfo &Img, int x, int y, uint8_t aPixel[4]) const size_t PixelSize = Img.PixelSize(); for(size_t i = 0; i < PixelSize; i++) - aPixel[i] = ((uint8_t *)Img.m_pData)[x * PixelSize + (Img.m_Width * PixelSize * y) + i]; + aPixel[i] = Img.m_pData[x * PixelSize + (Img.m_Width * PixelSize * y) + i]; return aPixel[3] > 0; }