Skip to content

Commit d08fbcd

Browse files
committed
Fixed: MSVC warnings
1 parent 794474f commit d08fbcd

7 files changed

Lines changed: 20 additions & 12 deletions

File tree

Codecs/CodecBMP/Source/CodecBMP.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ namespace IMCodec
7878
return mPluginProperties;
7979
}
8080

81-
uint8_t GetValue(uint8_t bitWidth, const uint8_t* address, int position)
81+
uint8_t GetValue(uint8_t bitWidth, const uint8_t* address, size_t position)
8282
{
8383
const int mask = (1 << bitWidth) - 1;
8484
const int PixelsInOneByte = CHAR_BIT / bitWidth;
85-
const int byteOffset = position / PixelsInOneByte;
85+
const size_t byteOffset = position / PixelsInOneByte;
8686
const int bitOffset = (CHAR_BIT - ((position % PixelsInOneByte) + 1) * bitWidth);
8787
const uint8_t currentByte = address[byteOffset];
8888
uint8_t value = ((currentByte & (mask << bitOffset))) >> bitOffset;
@@ -181,7 +181,7 @@ namespace IMCodec
181181
}
182182

183183
const auto texelSize = IMCodec::GetTexelInfo(imageItem->descriptor.texelFormatDecompressed).texelSize;
184-
imageItem->descriptor.rowPitchInBytes = LLUtils::Utility::Align<size_t>(bmpInfo.biWidth * texelSize / CHAR_BIT, sizeof(uint32_t));
184+
imageItem->descriptor.rowPitchInBytes = LLUtils::Utility::Align<uint32_t>(bmpInfo.biWidth * texelSize / CHAR_BIT, sizeof(uint32_t));
185185
const size_t destDataSize = imageItem->descriptor.rowPitchInBytes * imageItem->descriptor.height;
186186

187187

@@ -208,7 +208,7 @@ namespace IMCodec
208208

209209
for (size_t x = 0; x < imageItem->descriptor.width; x++)
210210
{
211-
uint8_t pixelIndex = GetValue(bmpInfo.biBitCount, baseSourceAddress + sourceLineOffset, x);
211+
uint8_t pixelIndex = GetValue(static_cast<uint8_t>(bmpInfo.biBitCount), baseSourceAddress + sourceLineOffset, x);
212212
uint32_t color = 0xFF << 24 | colorTable[pixelIndex];
213213
uint32_t* currentpixel = reinterpret_cast<uint32_t*>(reinterpret_cast<uint8_t*>(imageItem->data.data()) + destLineOffset) + x;
214214
*currentpixel = color;

Codecs/CodecGif/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ add_subdirectory(${giflibFolder} ./external/libgif)
1818
if (IMCODEC_DISABLE_WARNINGS_EXTERNAL_LIBS)
1919
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
2020
target_compile_options(libgif PRIVATE -Wno-deprecated-declarations)
21+
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
22+
target_compile_options(libgif PRIVATE /wd4018 /wd4996 /wd4267 /wd4244)
2123
endif()
2224
endif()
2325

Codecs/CodecIcon/Source/CodecIcon.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ namespace IMCodec
7575
return mPluginProperties;
7676
}
7777

78-
uint8_t GetValue(uint8_t bitWidth, const uint8_t* address, int position)
78+
uint8_t GetValue(uint8_t bitWidth, const uint8_t* address, size_t position)
7979
{
80-
const int mask = (1 << bitWidth) - 1;
81-
const int PixelsInOneByte = CHAR_BIT / bitWidth;
82-
const int byteOffset = position / PixelsInOneByte;
83-
const int bitOffset = (CHAR_BIT - ((position % PixelsInOneByte) + 1) * bitWidth);
80+
const size_t mask = (1 << bitWidth) - 1;
81+
const size_t PixelsInOneByte = CHAR_BIT / bitWidth;
82+
const size_t byteOffset = position / PixelsInOneByte;
83+
const uint8_t bitOffset = static_cast<uint8_t>((CHAR_BIT - ((position % PixelsInOneByte) + 1) * bitWidth));
8484
const uint8_t currentByte = address[byteOffset];
8585
uint8_t value = ((currentByte & (mask << bitOffset))) >> bitOffset;
8686
return value;
@@ -165,7 +165,7 @@ namespace IMCodec
165165

166166
for (size_t x = 0; x < currentDescriptor.width; x++)
167167
{
168-
uint8_t pixelIndex = GetValue(bitmapInfo->biBitCount, baseSourceAddress + sourceLineOffset, x);
168+
uint8_t pixelIndex = GetValue(static_cast<uint8_t>(bitmapInfo->biBitCount), baseSourceAddress + sourceLineOffset, x);
169169
uint8_t opacity = GetValue(MaskBitCount, baseSourceAddress + SourceLineMaskOffset, x);
170170
uint32_t color = ((opacity == 1 ? 0x00 : 0xFF) << 24) | colorTable[pixelIndex];
171171
uint32_t* currentpixel = reinterpret_cast<uint32_t*>(reinterpret_cast<uint8_t*>(imageItem->data.data()) + destLineOffset) + x;

Codecs/CodecPNG/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ set(zlibFolder ../../External/zlib)
1919
if (IMCODEC_DISABLE_WARNINGS_EXTERNAL_LIBS)
2020
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
2121
add_compile_options(-Wno-deprecated-non-prototype)
22+
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
23+
add_compile_options(/wd4244)
2224
endif()
2325
endif()
2426

Codecs/CodecPNG/Source/CodecPng.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ namespace IMCodec
196196

197197

198198

199-
for (auto frameIndex = 0; frameIndex < numFrames; frameIndex++)
199+
for (auto frameIndex = 0u; frameIndex < numFrames; frameIndex++)
200200
{
201201
auto& currentFrameBuffer = frameBuffers.at(frameIndex);
202202
currentFrameBuffer.Allocate(canvasheight * targetRowPitchInBytes);
@@ -211,7 +211,7 @@ namespace IMCodec
211211

212212
LLUtils::Buffer readBuffer(sourceRowPitchInBytes);
213213
png_bytep row_buf = (png_bytep)readBuffer.data();
214-
for (auto y = 0; y < frameheight; y++)
214+
for (auto y = 0u; y < frameheight; y++)
215215
{
216216
const size_t rowBytes = framewidth * targetPixelSize;
217217
png_read_rows(png_ptr, (png_bytepp)&row_buf, nullptr, 1);

Codecs/CodecPSD/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ if (IMCODEC_DISABLE_WARNINGS_EXTERNAL_LIBS)
1818
target_compile_options(libpsd PRIVATE -Wno-switch -Wno-unused-but-set-variable -Wno-implicit-function-declaration -Wno-pointer-sign -Wno-deprecated-declarations
1919
-Wno-pointer-to-int-cast -Wno-unused-variable -Wno-incompatible-function-pointer-types -Wno-int-to-pointer-cast -Wno-sometimes-uninitialized
2020
-Wno-unused-function -Wno-enum-conversion -Wno-empty-body)
21+
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
22+
target_compile_options(libpsd PRIVATE /wd4668 /wd4013 /wd4311 /wd4312 /wd4267 /wd4101 /wd4996)
2123
endif()
2224
endif()

Codecs/CodecTiff/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ if (IMCODEC_DISABLE_WARNINGS_EXTERNAL_LIBS)
5252
-Wno-reserved-identifier
5353
-Wno-missing-variable-declarations
5454
)
55+
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
56+
target_compile_options(tiff PRIVATE /wd4996)
5557
endif()
5658
target_compile_definitions(tiff PRIVATE _CRT_SECURE_NO_WARNINGS)
5759
endif()

0 commit comments

Comments
 (0)