diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index b056502d7..cb66672bb 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -312,9 +312,9 @@ static bool ConvertToRGBA(uint8_t *pDest, const CImageInfo &SrcImage) { const size_t SrcChannelCount = CImageInfo::PixelSize(SrcImage.m_Format); const size_t DstChannelCount = CImageInfo::PixelSize(CImageInfo::FORMAT_RGBA); - for(size_t Y = 0; Y < (size_t)SrcImage.m_Height; ++Y) + for(size_t Y = 0; Y < SrcImage.m_Height; ++Y) { - for(size_t X = 0; X < (size_t)SrcImage.m_Width; ++X) + for(size_t X = 0; X < SrcImage.m_Width; ++X) { size_t ImgOffsetSrc = (Y * SrcImage.m_Width * SrcChannelCount) + (X * SrcChannelCount); size_t ImgOffsetDest = (Y * SrcImage.m_Width * DstChannelCount) + (X * DstChannelCount); @@ -349,7 +349,7 @@ int CGraphics_Threaded::LoadTextureRawSub(CTextureHandle TextureId, int x, int y Cmd.m_Height = Image.m_Height; Cmd.m_Format = CCommandBuffer::TEXFORMAT_RGBA; - uint8_t *pTmpData = static_cast(malloc((size_t)Image.m_Width * Image.m_Height * CImageInfo::PixelSize(CImageInfo::FORMAT_RGBA))); + uint8_t *pTmpData = static_cast(malloc(Image.m_Width * Image.m_Height * CImageInfo::PixelSize(CImageInfo::FORMAT_RGBA))); ConvertToRGBA(pTmpData, Image); Cmd.m_pData = pTmpData; AddCmd(Cmd); @@ -460,7 +460,7 @@ IGraphics::CTextureHandle CGraphics_Threaded::LoadTextureRaw(const CImageInfo &I CCommandBuffer::SCommand_Texture_Create Cmd = LoadTextureCreateCommand(TextureHandle.Id(), Image.m_Width, Image.m_Height, Flags); // Copy texture data and convert if necessary - uint8_t *pTmpData = static_cast(malloc((size_t)Image.m_Width * Image.m_Height * CImageInfo::PixelSize(CImageInfo::FORMAT_RGBA))); + uint8_t *pTmpData = static_cast(malloc(Image.m_Width * Image.m_Height * CImageInfo::PixelSize(CImageInfo::FORMAT_RGBA))); if(!ConvertToRGBA(pTmpData, Image)) { dbg_msg("graphics", "converted image '%s' to RGBA, consider making its file format RGBA", pTexName ? pTexName : "(no name)"); diff --git a/src/engine/gfx/image_loader.cpp b/src/engine/gfx/image_loader.cpp index 067d232da..139e4adf0 100644 --- a/src/engine/gfx/image_loader.cpp +++ b/src/engine/gfx/image_loader.cpp @@ -124,7 +124,7 @@ static int PngliteIncompatibility(png_structp pPNGStruct, png_infop pPNGInfo) return Result; } -bool LoadPng(SImageByteBuffer &ByteLoader, const char *pFileName, int &PngliteIncompatible, int &Width, int &Height, uint8_t *&pImageBuff, EImageFormat &ImageFormat) +bool LoadPng(SImageByteBuffer &ByteLoader, const char *pFileName, int &PngliteIncompatible, size_t &Width, size_t &Height, uint8_t *&pImageBuff, EImageFormat &ImageFormat) { SLibPNGWarningItem UserErrorStruct = {&ByteLoader, pFileName, {}}; @@ -143,7 +143,7 @@ bool LoadPng(SImageByteBuffer &ByteLoader, const char *pFileName, int &PngliteIn { if(pRowPointers != nullptr) { - for(int i = 0; i < Height; ++i) + for(size_t i = 0; i < Height; ++i) { delete[] pRowPointers[i]; } @@ -220,12 +220,12 @@ bool LoadPng(SImageByteBuffer &ByteLoader, const char *pFileName, int &PngliteIn png_read_update_info(pPNGStruct, pPNGInfo); - const int ColorChannelCount = png_get_channels(pPNGStruct, pPNGInfo); - const int BytesInRow = png_get_rowbytes(pPNGStruct, pPNGInfo); + const size_t ColorChannelCount = png_get_channels(pPNGStruct, pPNGInfo); + const size_t BytesInRow = png_get_rowbytes(pPNGStruct, pPNGInfo); dbg_assert(BytesInRow == Width * ColorChannelCount, "bytes in row incorrect."); pRowPointers = new png_bytep[Height]; - for(int y = 0; y < Height; ++y) + for(size_t y = 0; y < Height; ++y) { pRowPointers[y] = new png_byte[BytesInRow]; } @@ -233,9 +233,9 @@ bool LoadPng(SImageByteBuffer &ByteLoader, const char *pFileName, int &PngliteIn png_read_image(pPNGStruct, pRowPointers); if(ByteLoader.m_Err == 0) - pImageBuff = (uint8_t *)malloc((size_t)Height * (size_t)Width * (size_t)ColorChannelCount * sizeof(uint8_t)); + pImageBuff = (uint8_t *)malloc(Height * Width * ColorChannelCount * sizeof(uint8_t)); - for(int i = 0; i < Height; ++i) + for(size_t i = 0; i < Height; ++i) { if(ByteLoader.m_Err == 0) mem_copy(&pImageBuff[i * BytesInRow], pRowPointers[i], BytesInRow); @@ -277,7 +277,7 @@ static void WriteDataFromLoadedBytes(png_structp pPNGStruct, png_bytep pOutBytes static void FlushPNGWrite(png_structp png_ptr) {} -static int ImageLoaderHelperFormatToColorChannel(EImageFormat Format) +static size_t ImageLoaderHelperFormatToColorChannel(EImageFormat Format) { switch(Format) { @@ -295,7 +295,7 @@ static int ImageLoaderHelperFormatToColorChannel(EImageFormat Format) } } -bool SavePng(EImageFormat ImageFormat, const uint8_t *pRawBuffer, SImageByteBuffer &WrittenBytes, int Width, int Height) +bool SavePng(EImageFormat ImageFormat, const uint8_t *pRawBuffer, SImageByteBuffer &WrittenBytes, size_t Width, size_t Height) { png_structp pPNGStruct = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); @@ -320,7 +320,7 @@ bool SavePng(EImageFormat ImageFormat, const uint8_t *pRawBuffer, SImageByteBuff png_set_write_fn(pPNGStruct, (png_bytep)&WrittenBytes, WriteDataFromLoadedBytes, FlushPNGWrite); int ColorType = PNG_COLOR_TYPE_RGB; - int WriteBytesPerPixel = ImageLoaderHelperFormatToColorChannel(ImageFormat); + size_t WriteBytesPerPixel = ImageLoaderHelperFormatToColorChannel(ImageFormat); if(ImageFormat == IMAGE_FORMAT_R) { ColorType = PNG_COLOR_TYPE_GRAY; @@ -335,9 +335,9 @@ bool SavePng(EImageFormat ImageFormat, const uint8_t *pRawBuffer, SImageByteBuff png_write_info(pPNGStruct, pPNGInfo); png_bytepp pRowPointers = new png_bytep[Height]; - int WidthBytes = Width * WriteBytesPerPixel; + size_t WidthBytes = Width * WriteBytesPerPixel; ptrdiff_t BufferOffset = 0; - for(int y = 0; y < Height; ++y) + for(size_t y = 0; y < Height; ++y) { pRowPointers[y] = new png_byte[WidthBytes]; mem_copy(pRowPointers[y], pRawBuffer + BufferOffset, WidthBytes); @@ -347,7 +347,7 @@ bool SavePng(EImageFormat ImageFormat, const uint8_t *pRawBuffer, SImageByteBuff png_write_end(pPNGStruct, pPNGInfo); - for(int y = 0; y < Height; ++y) + for(size_t y = 0; y < Height; ++y) { delete[](pRowPointers[y]); } diff --git a/src/engine/gfx/image_loader.h b/src/engine/gfx/image_loader.h index 1ef8b32bc..9c54d94cf 100644 --- a/src/engine/gfx/image_loader.h +++ b/src/engine/gfx/image_loader.h @@ -32,7 +32,7 @@ enum PNGLITE_FILTER_TYPE = 1 << 4, }; -bool LoadPng(SImageByteBuffer &ByteLoader, const char *pFileName, int &PngliteIncompatible, int &Width, int &Height, uint8_t *&pImageBuff, EImageFormat &ImageFormat); -bool SavePng(EImageFormat ImageFormat, const uint8_t *pRawBuffer, SImageByteBuffer &WrittenBytes, int Width, int Height); +bool LoadPng(SImageByteBuffer &ByteLoader, const char *pFileName, int &PngliteIncompatible, size_t &Width, size_t &Height, uint8_t *&pImageBuff, EImageFormat &ImageFormat); +bool SavePng(EImageFormat ImageFormat, const uint8_t *pRawBuffer, SImageByteBuffer &WrittenBytes, size_t Width, size_t Height); #endif // ENGINE_GFX_IMAGE_LOADER_H diff --git a/src/engine/graphics.h b/src/engine/graphics.h index 98d3548ec..b96214698 100644 --- a/src/engine/graphics.h +++ b/src/engine/graphics.h @@ -78,12 +78,12 @@ public: /** * Contains the width of the image */ - int m_Width = 0; + size_t m_Width = 0; /** * Contains the height of the image */ - int m_Height = 0; + size_t m_Height = 0; /** * Contains the format of the image. @@ -120,7 +120,7 @@ public: size_t DataSize() const { - return (size_t)m_Width * m_Height * PixelSize(m_Format); + return m_Width * m_Height * PixelSize(m_Format); } static EImageFormat ImageFormatFromInt(int Format) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 87176ad5e..e77e29242 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -2344,7 +2344,7 @@ int CMenus::MenuImageScan(const char *pName, int IsDir, int DirType, void *pUser // create gray scale version unsigned char *pData = static_cast(Info.m_pData); const size_t Step = Info.PixelSize(); - for(int i = 0; i < Info.m_Width * Info.m_Height; i++) + for(size_t i = 0; i < Info.m_Width * Info.m_Height; i++) { int v = (pData[i * Step] + pData[i * Step + 1] + pData[i * Step + 2]) / 3; pData[i * Step] = v; diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index 25a93765b..34ed4b98b 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -1978,7 +1978,7 @@ void CMenus::LoadCommunityIconFinish(const char *pCommunityId, CImageInfo &Info, // create gray scale version unsigned char *pData = static_cast(Info.m_pData); const size_t Step = Info.PixelSize(); - for(int i = 0; i < Info.m_Width * Info.m_Height; i++) + for(size_t i = 0; i < Info.m_Width * Info.m_Height; i++) { int v = (pData[i * Step] + pData[i * Step + 1] + pData[i * Step + 2]) / 3; pData[i * Step] = v; diff --git a/src/game/client/components/skins.cpp b/src/game/client/components/skins.cpp index 082d04d99..148ff7855 100644 --- a/src/game/client/components/skins.cpp +++ b/src/game/client/components/skins.cpp @@ -197,20 +197,20 @@ const CSkin *CSkins::LoadSkin(const char *pName, CImageInfo &Info) int BodyOutlineOffsetX = g_pData->m_aSprites[SPRITE_TEE_BODY_OUTLINE].m_X * BodyOutlineGridPixelsWidth; int BodyOutlineOffsetY = g_pData->m_aSprites[SPRITE_TEE_BODY_OUTLINE].m_Y * BodyOutlineGridPixelsHeight; - int BodyWidth = g_pData->m_aSprites[SPRITE_TEE_BODY].m_W * (Info.m_Width / g_pData->m_aSprites[SPRITE_TEE_BODY].m_pSet->m_Gridx); // body width - int BodyHeight = g_pData->m_aSprites[SPRITE_TEE_BODY].m_H * (Info.m_Height / g_pData->m_aSprites[SPRITE_TEE_BODY].m_pSet->m_Gridy); // body height + size_t BodyWidth = g_pData->m_aSprites[SPRITE_TEE_BODY].m_W * (Info.m_Width / g_pData->m_aSprites[SPRITE_TEE_BODY].m_pSet->m_Gridx); // body width + size_t BodyHeight = g_pData->m_aSprites[SPRITE_TEE_BODY].m_H * (Info.m_Height / g_pData->m_aSprites[SPRITE_TEE_BODY].m_pSet->m_Gridy); // body height if(BodyWidth > Info.m_Width || BodyHeight > Info.m_Height) return nullptr; - unsigned char *pData = (unsigned char *)Info.m_pData; + uint8_t *pData = Info.m_pData; const int PixelStep = 4; int Pitch = Info.m_Width * PixelStep; // dig out blood color { int64_t aColors[3] = {0}; - for(int y = 0; y < BodyHeight; y++) + for(size_t y = 0; y < BodyHeight; y++) { - for(int x = 0; x < BodyWidth; x++) + for(size_t x = 0; x < BodyWidth; x++) { uint8_t AlphaValue = pData[y * Pitch + x * PixelStep + 3]; if(AlphaValue > 128) @@ -237,7 +237,7 @@ const CSkin *CSkins::LoadSkin(const char *pName, CImageInfo &Info) CheckMetrics(Skin.m_Metrics.m_Feet, pData, Pitch, FeetOutlineOffsetX, FeetOutlineOffsetY, FeetOutlineWidth, FeetOutlineHeight); // make the texture gray scale - for(int i = 0; i < Info.m_Width * Info.m_Height; i++) + for(size_t i = 0; i < Info.m_Width * Info.m_Height; i++) { int v = (pData[i * PixelStep] + pData[i * PixelStep + 1] + pData[i * PixelStep + 2]) / 3; pData[i * PixelStep] = v; @@ -250,8 +250,8 @@ const CSkin *CSkins::LoadSkin(const char *pName, CImageInfo &Info) int NewWeight = 192; // find most common frequency - for(int y = 0; y < BodyHeight; y++) - for(int x = 0; x < BodyWidth; x++) + for(size_t y = 0; y < BodyHeight; y++) + for(size_t x = 0; x < BodyWidth; x++) { if(pData[y * Pitch + x * PixelStep + 3] > 128) aFreq[pData[y * Pitch + x * PixelStep]]++; @@ -266,8 +266,8 @@ const CSkin *CSkins::LoadSkin(const char *pName, CImageInfo &Info) // reorder int InvOrgWeight = 255 - OrgWeight; int InvNewWeight = 255 - NewWeight; - for(int y = 0; y < BodyHeight; y++) - for(int x = 0; x < BodyWidth; x++) + for(size_t y = 0; y < BodyHeight; y++) + for(size_t x = 0; x < BodyWidth; x++) { int v = pData[y * Pitch + x * PixelStep]; if(v <= OrgWeight && OrgWeight == 0) diff --git a/src/game/editor/mapitems/image.cpp b/src/game/editor/mapitems/image.cpp index a09dddf26..34e5a40cf 100644 --- a/src/game/editor/mapitems/image.cpp +++ b/src/game/editor/mapitems/image.cpp @@ -27,22 +27,20 @@ void CEditorImage::AnalyseTileFlags() { mem_zero(m_aTileFlags, sizeof(m_aTileFlags)); - int tw = m_Width / 16; // tilesizes - int th = m_Height / 16; + size_t tw = m_Width / 16; // tilesizes + size_t th = m_Height / 16; if(tw == th && m_Format == CImageInfo::FORMAT_RGBA) { - unsigned char *pPixelData = (unsigned char *)m_pData; - int TileId = 0; - for(int ty = 0; ty < 16; ty++) - for(int tx = 0; tx < 16; tx++, TileId++) + for(size_t ty = 0; ty < 16; ty++) + for(size_t tx = 0; tx < 16; tx++, TileId++) { bool Opaque = true; - for(int x = 0; x < tw; x++) - for(int y = 0; y < th; y++) + for(size_t x = 0; x < tw; x++) + for(size_t y = 0; y < th; y++) { - int p = (ty * tw + y) * m_Width + tx * tw + x; - if(pPixelData[p * 4 + 3] < 250) + size_t p = (ty * tw + y) * m_Width + tx * tw + x; + if(m_pData[p * 4 + 3] < 250) { Opaque = false; break; @@ -68,9 +66,9 @@ bool CEditorImage::DataEquals(const CEditorImage &Other) const }; // Look through every pixel and check if there are any difference - for(int y = 0; y < m_Height; y += ImgPixelSize) + for(size_t y = 0; y < m_Height; y += ImgPixelSize) { - for(int x = 0; x < m_Width; x += ImgPixelSize) + for(size_t x = 0; x < m_Width; x += ImgPixelSize) { for(size_t p = 0; p < ImgPixelSize; p++) if(GetPixel(m_pData, x, y, p) != GetPixel(Other.m_pData, x, y, p)) diff --git a/src/game/editor/mapitems/map_io.cpp b/src/game/editor/mapitems/map_io.cpp index ba91960ce..cdf8abd08 100644 --- a/src/game/editor/mapitems/map_io.cpp +++ b/src/game/editor/mapitems/map_io.cpp @@ -1032,7 +1032,7 @@ void CEditorMap::PerformSanityChecks(const std::functionm_Image = -1; char aBuf[IO_MAX_PATH_LENGTH + 128]; - str_format(aBuf, sizeof(aBuf), "Error: The image '%s' (size %dx%d) has a width or height that is not divisible by 16 and therefore cannot be used for tile layers. The image of layer #%" PRIzu " '%s' in group #%" PRIzu " '%s' has been unset.", pImage->m_aName, pImage->m_Width, pImage->m_Height, LayerIndex, pLayer->m_aName, GroupIndex, pGroup->m_aName); + str_format(aBuf, sizeof(aBuf), "Error: The image '%s' (size %" PRIzu "x%" PRIzu ") has a width or height that is not divisible by 16 and therefore cannot be used for tile layers. The image of layer #%" PRIzu " '%s' in group #%" PRIzu " '%s' has been unset.", pImage->m_aName, pImage->m_Width, pImage->m_Height, LayerIndex, pLayer->m_aName, GroupIndex, pGroup->m_aName); ErrorHandler(aBuf); } } diff --git a/src/game/editor/tileart.cpp b/src/game/editor/tileart.cpp index 92db0506a..ec79d71bd 100644 --- a/src/game/editor/tileart.cpp +++ b/src/game/editor/tileart.cpp @@ -66,9 +66,9 @@ static std::vector GetUniqueColors(const CImageInfo &Image) { std::set ColorSet; std::vector vUniqueColors; - for(int x = 0; x < Image.m_Width; x++) + for(size_t x = 0; x < Image.m_Width; x++) { - for(int y = 0; y < Image.m_Height; y++) + for(size_t y = 0; y < Image.m_Height; y++) { ColorRGBA Color = GetPixelColor(Image, x, y); if(Color.a > 0 && ColorSet.insert(Color).second) diff --git a/src/tools/map_create_pixelart.cpp b/src/tools/map_create_pixelart.cpp index 3e8f91b77..9b9e258d3 100644 --- a/src/tools/map_create_pixelart.cpp +++ b/src/tools/map_create_pixelart.cpp @@ -17,14 +17,14 @@ void SaveOutputMap(CDataFileReader &, CDataFileWriter &, CMapItemLayerQuads *, i CMapItemLayerQuads *GetQuadLayer(CDataFileReader &, const int[2], int *); CQuad CreateNewQuad(float, float, int, int, const uint8_t[4], const int[2]); -bool GetPixelClamped(const CImageInfo &, int, int, uint8_t[4]); +bool GetPixelClamped(const CImageInfo &, size_t, size_t, uint8_t[4]); bool ComparePixel(const uint8_t[4], const uint8_t[4]); -bool IsPixelOptimizable(const CImageInfo &, int, int, const uint8_t[4], const bool[]); -void SetVisitedPixels(const CImageInfo &, int, int, int, int, bool[]); +bool IsPixelOptimizable(const CImageInfo &, size_t, size_t, const uint8_t[4], const bool[]); +void SetVisitedPixels(const CImageInfo &, size_t, size_t, size_t, size_t, bool[]); -int GetImagePixelSize(const CImageInfo &); -int FindSuperPixelSize(const CImageInfo &, const uint8_t[4], int, int, int, bool[]); -void GetOptimizedQuadSize(const CImageInfo &, int, const uint8_t[4], int, int, int &, int &, bool[]); +size_t GetImagePixelSize(const CImageInfo &); +size_t FindSuperPixelSize(const CImageInfo &, const uint8_t[4], size_t, size_t, size_t, bool[]); +void GetOptimizedQuadSize(const CImageInfo &, size_t, const uint8_t[4], size_t, size_t, size_t &, size_t &, bool[]); int main(int argc, const char **argv) { @@ -83,7 +83,7 @@ bool CreatePixelArt(const char aFilenames[3][64], const int aLayerId[2], const i if(!pQuadLayer) return false; - int MaxNewQuads = std::ceil((Img.m_Width * Img.m_Height) / aPixelSizes[0]); + size_t MaxNewQuads = std::ceil((Img.m_Width * Img.m_Height) / aPixelSizes[0]); CQuad *pQuads = new CQuad[pQuadLayer->m_NumQuads + MaxNewQuads]; InsertCurrentQuads(InputMap, pQuadLayer, pQuads); @@ -104,19 +104,19 @@ void InsertCurrentQuads(CDataFileReader &InputMap, CMapItemLayerQuads *pQuadLaye int InsertPixelArtQuads(CQuad *pQuads, int &NumQuads, const CImageInfo &Img, const int aStartingPos[2], const int aPixelSizes[2], const bool aArtOptions[2]) { - int ImgPixelSize = aPixelSizes[0], QuadPixelSize = aPixelSizes[1], OriginalNumQuads = NumQuads; + size_t ImgPixelSize = aPixelSizes[0], QuadPixelSize = aPixelSizes[1], OriginalNumQuads = NumQuads; int aForcedPivot[2] = {std::numeric_limits::max(), std::numeric_limits::max()}; bool *aVisitedPixels = new bool[Img.m_Height * Img.m_Width]; mem_zero(aVisitedPixels, sizeof(bool) * Img.m_Height * Img.m_Width); - for(int y = 0; y < Img.m_Height; y += ImgPixelSize) - for(int x = 0; x < Img.m_Width; x += ImgPixelSize) + for(size_t y = 0; y < Img.m_Height; y += ImgPixelSize) + for(size_t x = 0; x < Img.m_Width; x += ImgPixelSize) { uint8_t aPixel[4]; if(aVisitedPixels[x + y * Img.m_Width] || !GetPixelClamped(Img, x, y, aPixel)) continue; - int Width = 1, Height = 1; + size_t Width = 1, Height = 1; if(aArtOptions[0]) GetOptimizedQuadSize(Img, ImgPixelSize, aPixel, x, y, Width, Height, aVisitedPixels); @@ -136,9 +136,9 @@ int InsertPixelArtQuads(CQuad *pQuads, int &NumQuads, const CImageInfo &Img, con return NumQuads - OriginalNumQuads; } -void GetOptimizedQuadSize(const CImageInfo &Img, const int ImgPixelSize, const uint8_t aPixel[4], const int PosX, const int PosY, int &Width, int &Height, bool aVisitedPixels[]) +void GetOptimizedQuadSize(const CImageInfo &Img, const size_t ImgPixelSize, const uint8_t aPixel[4], const size_t PosX, const size_t PosY, size_t &Width, size_t &Height, bool aVisitedPixels[]) { - int w = 0, h = 0, OptimizedWidth = 0, OptimizedHeight = 0; + size_t w = 0, h = 0, OptimizedWidth = 0, OptimizedHeight = 0; while(IsPixelOptimizable(Img, PosX + w, PosY + h, aPixel, aVisitedPixels)) { @@ -158,31 +158,31 @@ void GetOptimizedQuadSize(const CImageInfo &Img, const int ImgPixelSize, const u Height = OptimizedHeight / ImgPixelSize; } -int GetImagePixelSize(const CImageInfo &Img) +size_t GetImagePixelSize(const CImageInfo &Img) { - int ImgPixelSize = std::numeric_limits::max(); + size_t ImgPixelSize = std::numeric_limits::max(); bool *aVisitedPixels = new bool[Img.m_Height * Img.m_Width]; mem_zero(aVisitedPixels, sizeof(bool) * Img.m_Height * Img.m_Width); - for(int y = 0; y < Img.m_Height && ImgPixelSize > 1; y++) - for(int x = 0; x < Img.m_Width && ImgPixelSize > 1; x++) + for(size_t y = 0; y < Img.m_Height && ImgPixelSize > 1; y++) + for(size_t x = 0; x < Img.m_Width && ImgPixelSize > 1; x++) { uint8_t aPixel[4]; if(aVisitedPixels[x + y * Img.m_Width]) continue; GetPixelClamped(Img, x, y, aPixel); - int SuperPixelSize = FindSuperPixelSize(Img, aPixel, x, y, 1, aVisitedPixels); + size_t SuperPixelSize = FindSuperPixelSize(Img, aPixel, x, y, 1, aVisitedPixels); if(SuperPixelSize < ImgPixelSize) ImgPixelSize = SuperPixelSize; } delete[] aVisitedPixels; - dbg_msg("map_create_pixelart", "INFO: automatically detected img_pixelsize of %dpx", ImgPixelSize); + dbg_msg("map_create_pixelart", "INFO: automatically detected img_pixelsize of %" PRIzu "px", ImgPixelSize); return ImgPixelSize; } -int FindSuperPixelSize(const CImageInfo &Img, const uint8_t aPixel[4], const int PosX, const int PosY, const int CurrentSize, bool aVisitedPixels[]) +size_t FindSuperPixelSize(const CImageInfo &Img, const uint8_t aPixel[4], const size_t PosX, const size_t PosY, const size_t CurrentSize, bool aVisitedPixels[]) { if(PosX + CurrentSize >= Img.m_Width || PosY + CurrentSize >= Img.m_Height) { @@ -192,10 +192,10 @@ int FindSuperPixelSize(const CImageInfo &Img, const uint8_t aPixel[4], const int for(int i = 0; i < 2; i++) { - for(int j = 0; j < CurrentSize + 1; j++) + for(size_t j = 0; j < CurrentSize + 1; j++) { uint8_t aCheckPixel[4]; - int x = PosX, y = PosY; + size_t x = PosX, y = PosY; x += i == 0 ? j : CurrentSize; y += i == 0 ? CurrentSize : j; @@ -211,10 +211,10 @@ int FindSuperPixelSize(const CImageInfo &Img, const uint8_t aPixel[4], const int return FindSuperPixelSize(Img, aPixel, PosX, PosY, CurrentSize + 1, aVisitedPixels); } -bool GetPixelClamped(const CImageInfo &Img, int x, int y, uint8_t aPixel[4]) +bool GetPixelClamped(const CImageInfo &Img, size_t x, size_t y, uint8_t aPixel[4]) { - x = clamp(x, 0, (int)Img.m_Width - 1); - y = clamp(y, 0, (int)Img.m_Height - 1); + x = clamp(x, 0, Img.m_Width - 1); + y = clamp(y, 0, Img.m_Height - 1); aPixel[0] = 255; aPixel[1] = 255; aPixel[2] = 255; @@ -235,16 +235,16 @@ bool ComparePixel(const uint8_t aPixel1[4], const uint8_t aPixel2[4]) return true; } -bool IsPixelOptimizable(const CImageInfo &Img, const int PosX, const int PosY, const uint8_t aPixel[4], const bool aVisitedPixels[]) +bool IsPixelOptimizable(const CImageInfo &Img, const size_t PosX, const size_t PosY, const uint8_t aPixel[4], const bool aVisitedPixels[]) { uint8_t aCheckPixel[4]; return PosX < Img.m_Width && PosY < Img.m_Height && !aVisitedPixels[PosX + PosY * Img.m_Width] && GetPixelClamped(Img, PosX, PosY, aCheckPixel) && ComparePixel(aPixel, aCheckPixel); } -void SetVisitedPixels(const CImageInfo &Img, int PosX, int PosY, int Width, int Height, bool aVisitedPixels[]) +void SetVisitedPixels(const CImageInfo &Img, size_t PosX, size_t PosY, size_t Width, size_t Height, bool aVisitedPixels[]) { - for(int y = PosY; y < PosY + Height; y++) - for(int x = PosX; x < PosX + Width; x++) + for(size_t y = PosY; y < PosY + Height; y++) + for(size_t x = PosX; x < PosX + Width; x++) aVisitedPixels[x + y * Img.m_Width] = true; }