Replace sf::Uint8 with std::uint8_t

This commit is contained in:
Chris Thrasher 2022-09-03 14:15:24 -06:00 committed by Lukas Dürrenberger
parent af34794123
commit e2528de20a
65 changed files with 239 additions and 236 deletions

View File

@ -344,7 +344,7 @@ float getMoisture(unsigned int x, unsigned int y)
////////////////////////////////////////////////////////////
sf::Color colorFromFloats(float r, float g, float b)
{
return sf::Color(static_cast<sf::Uint8>(r), static_cast<sf::Uint8>(g), static_cast<sf::Uint8>(b));
return sf::Color(static_cast<std::uint8_t>(r), static_cast<std::uint8_t>(g), static_cast<std::uint8_t>(b));
}
sf::Color getLowlandsTerrainColor(float moisture)
@ -381,9 +381,9 @@ sf::Color getHighlandsTerrainColor(float elevation, float moisture)
float factor = std::min((elevation - 0.4f) / 0.1f, 1.f);
color.r = static_cast<sf::Uint8>(lowlandsColor.r * (1.f - factor) + color.r * factor);
color.g = static_cast<sf::Uint8>(lowlandsColor.g * (1.f - factor) + color.g * factor);
color.b = static_cast<sf::Uint8>(lowlandsColor.b * (1.f - factor) + color.b * factor);
color.r = static_cast<std::uint8_t>(lowlandsColor.r * (1.f - factor) + color.r * factor);
color.g = static_cast<std::uint8_t>(lowlandsColor.g * (1.f - factor) + color.g * factor);
color.b = static_cast<std::uint8_t>(lowlandsColor.b * (1.f - factor) + color.b * factor);
return color;
}
@ -402,9 +402,9 @@ sf::Color getSnowcapTerrainColor(float elevation, float moisture)
float factor = std::min((elevation - snowcapHeight) / 0.05f, 1.f);
color.r = static_cast<sf::Uint8>(highlandsColor.r * (1.f - factor) + color.r * factor);
color.g = static_cast<sf::Uint8>(highlandsColor.g * (1.f - factor) + color.g * factor);
color.b = static_cast<sf::Uint8>(highlandsColor.b * (1.f - factor) + color.b * factor);
color.r = static_cast<std::uint8_t>(highlandsColor.r * (1.f - factor) + color.r * factor);
color.g = static_cast<std::uint8_t>(highlandsColor.g * (1.f - factor) + color.g * factor);
color.b = static_cast<std::uint8_t>(highlandsColor.b * (1.f - factor) + color.b * factor);
return color;
}
@ -417,15 +417,15 @@ sf::Color getSnowcapTerrainColor(float elevation, float moisture)
////////////////////////////////////////////////////////////
sf::Color getTerrainColor(float elevation, float moisture)
{
sf::Color color = elevation < 0.11f ? sf::Color(0, 0, static_cast<sf::Uint8>(elevation / 0.11f * 74.f + 181.0f))
sf::Color color = elevation < 0.11f ? sf::Color(0, 0, static_cast<std::uint8_t>(elevation / 0.11f * 74.f + 181.0f))
: elevation < 0.14f
? sf::Color(static_cast<sf::Uint8>(std::pow((elevation - 0.11f) / 0.03f, 0.3f) * 48.f),
static_cast<sf::Uint8>(std::pow((elevation - 0.11f) / 0.03f, 0.3f) * 48.f),
? sf::Color(static_cast<std::uint8_t>(std::pow((elevation - 0.11f) / 0.03f, 0.3f) * 48.f),
static_cast<std::uint8_t>(std::pow((elevation - 0.11f) / 0.03f, 0.3f) * 48.f),
255)
: elevation < 0.16f
? sf::Color(static_cast<sf::Uint8>((elevation - 0.14f) * 128.f / 0.02f + 48.f),
static_cast<sf::Uint8>((elevation - 0.14f) * 128.f / 0.02f + 48.f),
static_cast<sf::Uint8>(127.0f + (0.16f - elevation) * 128.f / 0.02f))
? sf::Color(static_cast<std::uint8_t>((elevation - 0.14f) * 128.f / 0.02f + 48.f),
static_cast<std::uint8_t>((elevation - 0.14f) * 128.f / 0.02f + 48.f),
static_cast<std::uint8_t>(127.0f + (0.16f - elevation) * 128.f / 0.02f))
: elevation < 0.17f ? sf::Color(240, 230, 140)
: elevation < 0.4f ? getLowlandsTerrainColor(moisture)
: elevation < snowcapHeight ? getHighlandsTerrainColor(elevation, moisture)

View File

@ -145,9 +145,9 @@ public:
{
auto x = x_distribution(rng);
auto y = y_distribution(rng);
auto r = static_cast<sf::Uint8>(color_distribution(rng));
auto g = static_cast<sf::Uint8>(color_distribution(rng));
auto b = static_cast<sf::Uint8>(color_distribution(rng));
auto r = static_cast<std::uint8_t>(color_distribution(rng));
auto g = static_cast<std::uint8_t>(color_distribution(rng));
auto b = static_cast<std::uint8_t>(color_distribution(rng));
m_points.append(sf::Vertex(sf::Vector2f(x, y), sf::Color(r, g, b)));
}

View File

@ -8,8 +8,8 @@
#include <iostream>
const sf::Uint8 clientAudioData = 1;
const sf::Uint8 clientEndOfStream = 2;
const std::uint8_t clientAudioData = 1;
const std::uint8_t clientEndOfStream = 2;
////////////////////////////////////////////////////////////

View File

@ -11,8 +11,8 @@
#include <mutex>
const sf::Uint8 serverAudioData = 1;
const sf::Uint8 serverEndOfStream = 2;
const std::uint8_t serverAudioData = 1;
const std::uint8_t serverEndOfStream = 2;
////////////////////////////////////////////////////////////
@ -119,7 +119,7 @@ private:
break;
// Extract the message ID
sf::Uint8 id;
std::uint8_t id;
packet >> id;
if (id == serverAudioData)

View File

@ -167,9 +167,6 @@
////////////////////////////////////////////////////////////
namespace sf
{
// 8 bits integer types
using Uint8 = std::uint8_t;
// 16 bits integer types
using Int16 = std::int16_t;
using Uint16 = std::uint16_t;

View File

@ -58,7 +58,7 @@ public:
/// \param alpha Alpha (opacity) component (in the range [0, 255])
///
////////////////////////////////////////////////////////////
constexpr Color(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha = 255);
constexpr Color(std::uint8_t red, std::uint8_t green, std::uint8_t blue, std::uint8_t alpha = 255);
////////////////////////////////////////////////////////////
/// \brief Construct the color from 32-bit unsigned integer
@ -92,10 +92,10 @@ public:
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
Uint8 r; //!< Red component
Uint8 g; //!< Green component
Uint8 b; //!< Blue component
Uint8 a; //!< Alpha (opacity) component
std::uint8_t r; //!< Red component
std::uint8_t g; //!< Green component
std::uint8_t b; //!< Blue component
std::uint8_t a; //!< Alpha (opacity) component
};
////////////////////////////////////////////////////////////

View File

@ -30,17 +30,21 @@ constexpr Color::Color() : r(0), g(0), b(0), a(255)
////////////////////////////////////////////////////////////
constexpr Color::Color(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha) : r(red), g(green), b(blue), a(alpha)
constexpr Color::Color(std::uint8_t red, std::uint8_t green, std::uint8_t blue, std::uint8_t alpha) :
r(red),
g(green),
b(blue),
a(alpha)
{
}
////////////////////////////////////////////////////////////
constexpr Color::Color(Uint32 color) :
r(static_cast<Uint8>((color & 0xff000000) >> 24)),
g(static_cast<Uint8>((color & 0x00ff0000) >> 16)),
b(static_cast<Uint8>((color & 0x0000ff00) >> 8)),
a(static_cast<Uint8>(color & 0x000000ff))
r(static_cast<std::uint8_t>((color & 0xff000000) >> 24)),
g(static_cast<std::uint8_t>((color & 0x00ff0000) >> 16)),
b(static_cast<std::uint8_t>((color & 0x0000ff00) >> 8)),
a(static_cast<std::uint8_t>(color & 0x000000ff))
{
}
@ -69,10 +73,10 @@ constexpr bool operator!=(const Color& left, const Color& right)
////////////////////////////////////////////////////////////
constexpr Color operator+(const Color& left, const Color& right)
{
const auto clampedAdd = [](Uint8 lhs, Uint8 rhs) -> Uint8
const auto clampedAdd = [](std::uint8_t lhs, std::uint8_t rhs) -> std::uint8_t
{
const int intResult = static_cast<int>(lhs) + static_cast<int>(rhs);
return static_cast<Uint8>(intResult < 255 ? intResult : 255);
return static_cast<std::uint8_t>(intResult < 255 ? intResult : 255);
};
return Color(clampedAdd(left.r, right.r),
@ -85,10 +89,10 @@ constexpr Color operator+(const Color& left, const Color& right)
////////////////////////////////////////////////////////////
constexpr Color operator-(const Color& left, const Color& right)
{
const auto clampedSub = [](Uint8 lhs, Uint8 rhs) -> Uint8
const auto clampedSub = [](std::uint8_t lhs, std::uint8_t rhs) -> std::uint8_t
{
const int intResult = static_cast<int>(lhs) - static_cast<int>(rhs);
return static_cast<Uint8>(intResult > 0 ? intResult : 0);
return static_cast<std::uint8_t>(intResult > 0 ? intResult : 0);
};
return Color(clampedSub(left.r, right.r),
@ -101,10 +105,10 @@ constexpr Color operator-(const Color& left, const Color& right)
////////////////////////////////////////////////////////////
constexpr Color operator*(const Color& left, const Color& right)
{
const auto scaledMul = [](Uint8 lhs, Uint8 rhs) -> Uint8
const auto scaledMul = [](std::uint8_t lhs, std::uint8_t rhs) -> std::uint8_t
{
const auto uint16Result = static_cast<Uint16>(static_cast<Uint16>(lhs) * static_cast<Uint16>(rhs));
return static_cast<Uint8>(uint16Result / 255u);
return static_cast<std::uint8_t>(uint16Result / 255u);
};
return Color(scaledMul(left.r, right.r),

View File

@ -427,7 +427,7 @@ private:
bool m_isSmooth; //!< Status of the smooth filter
Info m_info; //!< Information about the font
mutable PageTable m_pages; //!< Table containing the glyphs pages by character size
mutable std::vector<Uint8> m_pixelBuffer; //!< Pixel buffer holding a glyph's pixels before being written to the texture
mutable std::vector<std::uint8_t> m_pixelBuffer; //!< Pixel buffer holding a glyph's pixels before being written to the texture
#ifdef SFML_SYSTEM_ANDROID
std::unique_ptr<priv::ResourceStream> m_stream; //!< Asset file streamer (if loaded from file)
#endif

View File

@ -70,7 +70,7 @@ public:
/// \param pixels Array of pixels to copy to the image
///
////////////////////////////////////////////////////////////
void create(const Vector2u& size, const Uint8* pixels);
void create(const Vector2u& size, const std::uint8_t* pixels);
////////////////////////////////////////////////////////////
/// \brief Load the image from a file on disk
@ -157,7 +157,7 @@ public:
/// \see create, loadFromFile, loadFromMemory, saveToFile
///
////////////////////////////////////////////////////////////
[[nodiscard]] bool saveToMemory(std::vector<sf::Uint8>& output, const std::string& format) const;
[[nodiscard]] bool saveToMemory(std::vector<std::uint8_t>& output, const std::string& format) const;
////////////////////////////////////////////////////////////
/// \brief Return the size (width and height) of the image
@ -178,7 +178,7 @@ public:
/// \param alpha Alpha value to assign to transparent pixels
///
////////////////////////////////////////////////////////////
void createMaskFromColor(const Color& color, Uint8 alpha = 0);
void createMaskFromColor(const Color& color, std::uint8_t alpha = 0);
////////////////////////////////////////////////////////////
/// \brief Copy pixels from another image onto this one
@ -261,7 +261,7 @@ public:
/// \return Read-only pointer to the array of pixels
///
////////////////////////////////////////////////////////////
const Uint8* getPixelsPtr() const;
const std::uint8_t* getPixelsPtr() const;
////////////////////////////////////////////////////////////
/// \brief Flip the image horizontally (left <-> right)
@ -279,8 +279,8 @@ private:
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
Vector2u m_size; //!< Image size
std::vector<Uint8> m_pixels; //!< Pixels of the image
Vector2u m_size; //!< Image size
std::vector<std::uint8_t> m_pixels; //!< Pixels of the image
};
} // namespace sf

View File

@ -254,7 +254,7 @@ public:
/// \param pixels Array of pixels to copy to the texture
///
////////////////////////////////////////////////////////////
void update(const Uint8* pixels);
void update(const std::uint8_t* pixels);
////////////////////////////////////////////////////////////
/// \brief Update a part of the texture from an array of pixels
@ -274,7 +274,7 @@ public:
/// \param dest Coordinates of the destination position
///
////////////////////////////////////////////////////////////
void update(const Uint8* pixels, const Vector2u& size, const Vector2u& dest);
void update(const std::uint8_t* pixels, const Vector2u& size, const Vector2u& dest);
////////////////////////////////////////////////////////////
/// \brief Update a part of this texture from another texture
@ -703,7 +703,7 @@ private:
/// ...
///
/// // update the texture
/// sf::Uint8* pixels = ...; // get a fresh chunk of pixels (the next frame of a movie, for example)
/// std::uint8_t* pixels = ...; // get a fresh chunk of pixels (the next frame of a movie, for example)
/// texture.update(pixels);
///
/// // draw it

View File

@ -71,7 +71,7 @@ public:
/// \param byte3 Fourth byte of the address
///
////////////////////////////////////////////////////////////
IpAddress(Uint8 byte0, Uint8 byte1, Uint8 byte2, Uint8 byte3);
IpAddress(std::uint8_t byte0, std::uint8_t byte1, std::uint8_t byte2, std::uint8_t byte3);
////////////////////////////////////////////////////////////
/// \brief Construct the address from a 32-bits integer

View File

@ -218,7 +218,7 @@ public:
////////////////////////////////////////////////////////////
/// \overload
////////////////////////////////////////////////////////////
Packet& operator>>(Uint8& data);
Packet& operator>>(std::uint8_t& data);
////////////////////////////////////////////////////////////
/// \overload
@ -299,7 +299,7 @@ public:
////////////////////////////////////////////////////////////
/// \overload
////////////////////////////////////////////////////////////
Packet& operator<<(Uint8 data);
Packet& operator<<(std::uint8_t data);
////////////////////////////////////////////////////////////
/// \overload

View File

@ -286,7 +286,7 @@ public:
/// \see toUtf16, toUtf32
///
////////////////////////////////////////////////////////////
std::basic_string<Uint8> toUtf8() const;
std::basic_string<std::uint8_t> toUtf8() const;
////////////////////////////////////////////////////////////
/// \brief Convert the Unicode string to a UTF-16 string

View File

@ -86,7 +86,7 @@ public:
///
////////////////////////////////////////////////////////////
template <typename Out>
static Out encode(Uint32 input, Out output, Uint8 replacement = 0);
static Out encode(Uint32 input, Out output, std::uint8_t replacement = 0);
////////////////////////////////////////////////////////////
/// \brief Advance to the next UTF-8 character

View File

@ -68,7 +68,7 @@ In Utf<8>::decode(In begin, In end, Uint32& output, Uint32 replacement)
// clang-format on
// decode the character
int trailingBytes = trailing[static_cast<Uint8>(*begin)];
int trailingBytes = trailing[static_cast<std::uint8_t>(*begin)];
if (begin + trailingBytes < end)
{
output = 0;
@ -76,12 +76,12 @@ In Utf<8>::decode(In begin, In end, Uint32& output, Uint32 replacement)
// clang-format off
switch (trailingBytes)
{
case 5: output += static_cast<Uint8>(*begin++); output <<= 6; [[fallthrough]];
case 4: output += static_cast<Uint8>(*begin++); output <<= 6; [[fallthrough]];
case 3: output += static_cast<Uint8>(*begin++); output <<= 6; [[fallthrough]];
case 2: output += static_cast<Uint8>(*begin++); output <<= 6; [[fallthrough]];
case 1: output += static_cast<Uint8>(*begin++); output <<= 6; [[fallthrough]];
case 0: output += static_cast<Uint8>(*begin++);
case 5: output += static_cast<std::uint8_t>(*begin++); output <<= 6; [[fallthrough]];
case 4: output += static_cast<std::uint8_t>(*begin++); output <<= 6; [[fallthrough]];
case 3: output += static_cast<std::uint8_t>(*begin++); output <<= 6; [[fallthrough]];
case 2: output += static_cast<std::uint8_t>(*begin++); output <<= 6; [[fallthrough]];
case 1: output += static_cast<std::uint8_t>(*begin++); output <<= 6; [[fallthrough]];
case 0: output += static_cast<std::uint8_t>(*begin++);
}
// clang-format on
@ -100,10 +100,10 @@ In Utf<8>::decode(In begin, In end, Uint32& output, Uint32 replacement)
////////////////////////////////////////////////////////////
template <typename Out>
Out Utf<8>::encode(Uint32 input, Out output, Uint8 replacement)
Out Utf<8>::encode(Uint32 input, Out output, std::uint8_t replacement)
{
// Some useful precomputed data
static constexpr Uint8 firstBytes[7] = {0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC};
static constexpr std::uint8_t firstBytes[7] = {0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC};
// encode the character
if ((input > 0x0010FFFF) || ((input >= 0xD800) && (input <= 0xDBFF)))
@ -127,15 +127,15 @@ Out Utf<8>::encode(Uint32 input, Out output, Uint8 replacement)
// clang-format on
// Extract the bytes to write
Uint8 bytes[4];
std::uint8_t bytes[4];
// clang-format off
switch (bytestoWrite)
{
case 4: bytes[3] = static_cast<Uint8>((input | 0x80) & 0xBF); input >>= 6; [[fallthrough]];
case 3: bytes[2] = static_cast<Uint8>((input | 0x80) & 0xBF); input >>= 6; [[fallthrough]];
case 2: bytes[1] = static_cast<Uint8>((input | 0x80) & 0xBF); input >>= 6; [[fallthrough]];
case 1: bytes[0] = static_cast<Uint8> (input | firstBytes[bytestoWrite]);
case 4: bytes[3] = static_cast<std::uint8_t>((input | 0x80) & 0xBF); input >>= 6; [[fallthrough]];
case 3: bytes[2] = static_cast<std::uint8_t>((input | 0x80) & 0xBF); input >>= 6; [[fallthrough]];
case 2: bytes[1] = static_cast<std::uint8_t>((input | 0x80) & 0xBF); input >>= 6; [[fallthrough]];
case 1: bytes[0] = static_cast<std::uint8_t> (input | firstBytes[bytestoWrite]);
}
// clang-format on

View File

@ -172,7 +172,7 @@ public:
/// false otherwise
///
////////////////////////////////////////////////////////////
[[nodiscard]] bool loadFromPixels(const Uint8* pixels, Vector2u size, Vector2u hotspot);
[[nodiscard]] bool loadFromPixels(const std::uint8_t* pixels, Vector2u size, Vector2u hotspot);
////////////////////////////////////////////////////////////
/// \brief Create a native system cursor

View File

@ -281,7 +281,7 @@ public:
/// \see setTitle
///
////////////////////////////////////////////////////////////
void setIcon(const Vector2u& size, const Uint8* pixels);
void setIcon(const Vector2u& size, const std::uint8_t* pixels);
////////////////////////////////////////////////////////////
/// \brief Show or hide the window

View File

@ -67,7 +67,7 @@ int seekCallback(std::uint64_t offset, void* data)
return position < 0 ? -1 : 0;
}
bool hasValidId3Tag(const sf::Uint8* header)
bool hasValidId3Tag(const std::uint8_t* header)
{
return std::memcmp(header, "ID3", 3) == 0 &&
!((header[5] & 15) || (header[6] & 0x80) || (header[7] & 0x80) || (header[8] & 0x80) || (header[9] & 0x80));
@ -81,7 +81,7 @@ namespace priv
////////////////////////////////////////////////////////////
bool SoundFileReaderMp3::check(InputStream& stream)
{
Uint8 header[10];
std::uint8_t header[10];
if (static_cast<std::size_t>(stream.read(header, static_cast<Int64>(sizeof(header)))) < sizeof(header))
return false;

View File

@ -41,7 +41,7 @@ namespace
// The following functions read integers as little endian and
// return them in the host byte order
bool decode(sf::InputStream& stream, sf::Uint8& value)
bool decode(sf::InputStream& stream, std::uint8_t& value)
{
return static_cast<std::size_t>(stream.read(&value, sizeof(value))) == sizeof(value);
}
@ -164,7 +164,7 @@ Uint64 SoundFileReaderWav::read(Int16* samples, Uint64 maxCount)
{
case 1:
{
Uint8 sample = 0;
std::uint8_t sample = 0;
if (decode(*m_stream, sample))
*samples++ = static_cast<Int16>((static_cast<Int16>(sample) - 128) << 8);
else

View File

@ -536,7 +536,7 @@ void Font::cleanup()
// Reset members
m_pages.clear();
std::vector<Uint8>().swap(m_pixelBuffer);
std::vector<std::uint8_t>().swap(m_pixelBuffer);
}
@ -661,8 +661,8 @@ Glyph Font::loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, f
// Resize the pixel buffer to the new size and fill it with transparent white pixels
m_pixelBuffer.resize(static_cast<std::size_t>(width) * static_cast<std::size_t>(height) * 4);
Uint8* current = m_pixelBuffer.data();
Uint8* end = current + width * height * 4;
std::uint8_t* current = m_pixelBuffer.data();
std::uint8_t* end = current + width * height * 4;
while (current != end)
{
@ -673,7 +673,7 @@ Glyph Font::loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, f
}
// Extract the glyph's pixels from the bitmap
const Uint8* pixels = bitmap.buffer;
const std::uint8_t* pixels = bitmap.buffer;
if (bitmap.pixel_mode == FT_PIXEL_MODE_MONO)
{
// Pixels are 1 bit monochrome values

View File

@ -44,11 +44,11 @@ void Image::create(const Vector2u& size, const Color& color)
if (size.x && size.y)
{
// Create a new pixel buffer first for exception safety's sake
std::vector<Uint8> newPixels(static_cast<std::size_t>(size.x) * static_cast<std::size_t>(size.y) * 4);
std::vector<std::uint8_t> newPixels(static_cast<std::size_t>(size.x) * static_cast<std::size_t>(size.y) * 4);
// Fill it with the specified color
Uint8* ptr = newPixels.data();
Uint8* end = ptr + newPixels.size();
std::uint8_t* ptr = newPixels.data();
std::uint8_t* end = ptr + newPixels.size();
while (ptr < end)
{
*ptr++ = color.r;
@ -66,7 +66,7 @@ void Image::create(const Vector2u& size, const Color& color)
else
{
// Dump the pixel buffer
std::vector<Uint8>().swap(m_pixels);
std::vector<std::uint8_t>().swap(m_pixels);
// Assign the new size
m_size.x = 0;
@ -76,12 +76,12 @@ void Image::create(const Vector2u& size, const Color& color)
////////////////////////////////////////////////////////////
void Image::create(const Vector2u& size, const Uint8* pixels)
void Image::create(const Vector2u& size, const std::uint8_t* pixels)
{
if (pixels && size.x && size.y)
{
// Create a new pixel buffer first for exception safety's sake
std::vector<Uint8> newPixels(pixels, pixels + size.x * size.y * 4);
std::vector<std::uint8_t> newPixels(pixels, pixels + size.x * size.y * 4);
// Commit the new pixel buffer
m_pixels.swap(newPixels);
@ -92,7 +92,7 @@ void Image::create(const Vector2u& size, const Uint8* pixels)
else
{
// Dump the pixel buffer
std::vector<Uint8>().swap(m_pixels);
std::vector<std::uint8_t>().swap(m_pixels);
// Assign the new size
m_size.x = 0;
@ -138,7 +138,7 @@ bool Image::saveToFile(const std::filesystem::path& filename) const
}
////////////////////////////////////////////////////////////
bool Image::saveToMemory(std::vector<sf::Uint8>& output, const std::string& format) const
bool Image::saveToMemory(std::vector<std::uint8_t>& output, const std::string& format) const
{
return priv::ImageLoader::getInstance().saveImageToMemory(format, output, m_pixels, m_size);
}
@ -152,14 +152,14 @@ Vector2u Image::getSize() const
////////////////////////////////////////////////////////////
void Image::createMaskFromColor(const Color& color, Uint8 alpha)
void Image::createMaskFromColor(const Color& color, std::uint8_t alpha)
{
// Make sure that the image is not empty
if (!m_pixels.empty())
{
// Replace the alpha of the pixels that match the transparent color
Uint8* ptr = m_pixels.data();
Uint8* end = ptr + m_pixels.size();
std::uint8_t* ptr = m_pixels.data();
std::uint8_t* end = ptr + m_pixels.size();
while (ptr < end)
{
if ((ptr[0] == color.r) && (ptr[1] == color.g) && (ptr[2] == color.b) && (ptr[3] == color.a))
@ -209,8 +209,8 @@ void Image::createMaskFromColor(const Color& color, Uint8 alpha)
const unsigned int srcStride = source.m_size.x * 4;
const unsigned int dstStride = m_size.x * 4;
const Uint8* srcPixels = source.m_pixels.data() + (srcRect.left + srcRect.top * source.m_size.x) * 4;
Uint8* dstPixels = m_pixels.data() + (dest.x + dest.y * m_size.x) * 4;
const std::uint8_t* srcPixels = source.m_pixels.data() + (srcRect.left + srcRect.top * source.m_size.x) * 4;
std::uint8_t* dstPixels = m_pixels.data() + (dest.x + dest.y * m_size.x) * 4;
// Copy the pixels
if (applyAlpha)
@ -221,19 +221,20 @@ void Image::createMaskFromColor(const Color& color, Uint8 alpha)
for (unsigned int j = 0; j < dstSize.x; ++j)
{
// Get a direct pointer to the components of the current pixel
const Uint8* src = srcPixels + j * 4;
Uint8* dst = dstPixels + j * 4;
const std::uint8_t* src = srcPixels + j * 4;
std::uint8_t* dst = dstPixels + j * 4;
// Interpolate RGBA components using the alpha values of the destination and source pixels
Uint8 src_alpha = src[3];
Uint8 dst_alpha = dst[3];
Uint8 out_alpha = static_cast<Uint8>(src_alpha + dst_alpha - src_alpha * dst_alpha / 255);
std::uint8_t src_alpha = src[3];
std::uint8_t dst_alpha = dst[3];
std::uint8_t out_alpha = static_cast<std::uint8_t>(src_alpha + dst_alpha - src_alpha * dst_alpha / 255);
dst[3] = out_alpha;
if (out_alpha)
for (int k = 0; k < 3; k++)
dst[k] = static_cast<Uint8>((src[k] * src_alpha + dst[k] * (out_alpha - src_alpha)) / out_alpha);
dst[k] = static_cast<std::uint8_t>(
(src[k] * src_alpha + dst[k] * (out_alpha - src_alpha)) / out_alpha);
else
for (int k = 0; k < 3; k++)
dst[k] = src[k];
@ -261,24 +262,24 @@ void Image::createMaskFromColor(const Color& color, Uint8 alpha)
////////////////////////////////////////////////////////////
void Image::setPixel(const Vector2u& coords, const Color& color)
{
Uint8* pixel = &m_pixels[(coords.x + coords.y * m_size.x) * 4];
*pixel++ = color.r;
*pixel++ = color.g;
*pixel++ = color.b;
*pixel++ = color.a;
std::uint8_t* pixel = &m_pixels[(coords.x + coords.y * m_size.x) * 4];
*pixel++ = color.r;
*pixel++ = color.g;
*pixel++ = color.b;
*pixel++ = color.a;
}
////////////////////////////////////////////////////////////
Color Image::getPixel(const Vector2u& coords) const
{
const Uint8* pixel = &m_pixels[(coords.x + coords.y * m_size.x) * 4];
const std::uint8_t* pixel = &m_pixels[(coords.x + coords.y * m_size.x) * 4];
return Color(pixel[0], pixel[1], pixel[2], pixel[3]);
}
////////////////////////////////////////////////////////////
const Uint8* Image::getPixelsPtr() const
const std::uint8_t* Image::getPixelsPtr() const
{
if (!m_pixels.empty())
{
@ -301,9 +302,9 @@ void Image::flipHorizontally()
for (std::size_t y = 0; y < m_size.y; ++y)
{
auto left = m_pixels.begin() + static_cast<std::vector<Uint8>::iterator::difference_type>(y * rowSize);
auto left = m_pixels.begin() + static_cast<std::vector<std::uint8_t>::iterator::difference_type>(y * rowSize);
auto right = m_pixels.begin() +
static_cast<std::vector<Uint8>::iterator::difference_type>((y + 1) * rowSize - 4);
static_cast<std::vector<std::uint8_t>::iterator::difference_type>((y + 1) * rowSize - 4);
for (std::size_t x = 0; x < m_size.x / 2; ++x)
{
@ -322,7 +323,7 @@ void Image::flipVertically()
{
if (!m_pixels.empty())
{
auto rowSize = static_cast<std::vector<Uint8>::iterator::difference_type>(m_size.x * 4);
auto rowSize = static_cast<std::vector<std::uint8_t>::iterator::difference_type>(m_size.x * 4);
auto top = m_pixels.begin();
auto bottom = m_pixels.end() - rowSize;

View File

@ -64,8 +64,8 @@ int eof(void* user)
// stb_image callback for constructing a buffer
void bufferFromCallback(void* context, void* data, int size)
{
auto* source = static_cast<sf::Uint8*>(data);
auto* dest = static_cast<std::vector<sf::Uint8>*>(context);
auto* source = static_cast<std::uint8_t*>(data);
auto* dest = static_cast<std::vector<std::uint8_t>*>(context);
std::copy(source, source + size, std::back_inserter(*dest));
}
} // namespace
@ -92,7 +92,7 @@ ImageLoader::ImageLoader()
////////////////////////////////////////////////////////////
bool ImageLoader::loadImageFromFile(const std::filesystem::path& filename, std::vector<Uint8>& pixels, Vector2u& size)
bool ImageLoader::loadImageFromFile(const std::filesystem::path& filename, std::vector<std::uint8_t>& pixels, Vector2u& size)
{
// Clear the array (just in case)
pixels.clear();
@ -133,7 +133,7 @@ bool ImageLoader::loadImageFromFile(const std::filesystem::path& filename, std::
////////////////////////////////////////////////////////////
bool ImageLoader::loadImageFromMemory(const void* data, std::size_t dataSize, std::vector<Uint8>& pixels, Vector2u& size)
bool ImageLoader::loadImageFromMemory(const void* data, std::size_t dataSize, std::vector<std::uint8_t>& pixels, Vector2u& size)
{
// Check input parameters
if (data && dataSize)
@ -183,7 +183,7 @@ bool ImageLoader::loadImageFromMemory(const void* data, std::size_t dataSize, st
////////////////////////////////////////////////////////////
bool ImageLoader::loadImageFromStream(InputStream& stream, std::vector<Uint8>& pixels, Vector2u& size)
bool ImageLoader::loadImageFromStream(InputStream& stream, std::vector<std::uint8_t>& pixels, Vector2u& size)
{
// Clear the array (just in case)
pixels.clear();
@ -236,7 +236,9 @@ bool ImageLoader::loadImageFromStream(InputStream& stream, std::vector<Uint8>& p
////////////////////////////////////////////////////////////
bool ImageLoader::saveImageToFile(const std::filesystem::path& filename, const std::vector<Uint8>& pixels, const Vector2u& size)
bool ImageLoader::saveImageToFile(const std::filesystem::path& filename,
const std::vector<std::uint8_t>& pixels,
const Vector2u& size)
{
// Make sure the image is not empty
if (!pixels.empty() && (size.x > 0) && (size.y > 0))
@ -278,10 +280,10 @@ bool ImageLoader::saveImageToFile(const std::filesystem::path& filename, const s
}
////////////////////////////////////////////////////////////
bool ImageLoader::saveImageToMemory(const std::string& format,
std::vector<sf::Uint8>& output,
const std::vector<Uint8>& pixels,
const Vector2u& size)
bool ImageLoader::saveImageToMemory(const std::string& format,
std::vector<std::uint8_t>& output,
const std::vector<std::uint8_t>& pixels,
const Vector2u& size)
{
// Make sure the image is not empty
if (!pixels.empty() && (size.x > 0) && (size.y > 0))

View File

@ -68,7 +68,7 @@ public:
/// \return True if loading was successful
///
////////////////////////////////////////////////////////////
bool loadImageFromFile(const std::filesystem::path& filename, std::vector<Uint8>& pixels, Vector2u& size);
bool loadImageFromFile(const std::filesystem::path& filename, std::vector<std::uint8_t>& pixels, Vector2u& size);
////////////////////////////////////////////////////////////
/// \brief Load an image from a file in memory
@ -81,7 +81,7 @@ public:
/// \return True if loading was successful
///
////////////////////////////////////////////////////////////
bool loadImageFromMemory(const void* data, std::size_t dataSize, std::vector<Uint8>& pixels, Vector2u& size);
bool loadImageFromMemory(const void* data, std::size_t dataSize, std::vector<std::uint8_t>& pixels, Vector2u& size);
////////////////////////////////////////////////////////////
/// \brief Load an image from a custom stream
@ -93,7 +93,7 @@ public:
/// \return True if loading was successful
///
////////////////////////////////////////////////////////////
bool loadImageFromStream(InputStream& stream, std::vector<Uint8>& pixels, Vector2u& size);
bool loadImageFromStream(InputStream& stream, std::vector<std::uint8_t>& pixels, Vector2u& size);
////////////////////////////////////////////////////////////
/// \brief Save an array of pixels as an image file
@ -105,7 +105,7 @@ public:
/// \return True if saving was successful
///
////////////////////////////////////////////////////////////
bool saveImageToFile(const std::filesystem::path& filename, const std::vector<Uint8>& pixels, const Vector2u& size);
bool saveImageToFile(const std::filesystem::path& filename, const std::vector<std::uint8_t>& pixels, const Vector2u& size);
////////////////////////////////////////////////////////////
/// \brief Save an array of pixels as an encoded image buffer
@ -118,10 +118,10 @@ public:
/// \return True if saving was successful
///
////////////////////////////////////////////////////////////
bool saveImageToMemory(const std::string& format,
std::vector<sf::Uint8>& output,
const std::vector<Uint8>& pixels,
const Vector2u& size);
bool saveImageToMemory(const std::string& format,
std::vector<std::uint8_t>& output,
const std::vector<std::uint8_t>& pixels,
const Vector2u& size);
private:
////////////////////////////////////////////////////////////

View File

@ -302,7 +302,7 @@ bool Texture::loadFromImage(const Image& image, const IntRect& area)
priv::TextureSaver save;
// Copy the pixels to the texture, row by row
const Uint8* pixels = image.getPixelsPtr() + 4 * (rectangle.left + (width * rectangle.top));
const std::uint8_t* pixels = image.getPixelsPtr() + 4 * (rectangle.left + (width * rectangle.top));
glCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
for (int i = 0; i < rectangle.height; ++i)
{
@ -347,7 +347,7 @@ Image Texture::copyToImage() const
priv::TextureSaver save;
// Create an array of pixels
std::vector<Uint8> pixels(static_cast<std::size_t>(m_size.x) * static_cast<std::size_t>(m_size.y) * 4);
std::vector<std::uint8_t> pixels(static_cast<std::size_t>(m_size.x) * static_cast<std::size_t>(m_size.y) * 4);
#ifdef SFML_OPENGL_ES
@ -381,14 +381,14 @@ Image Texture::copyToImage() const
// Texture is either padded or flipped, we have to use a slower algorithm
// All the pixels will first be copied to a temporary array
std::vector<Uint8> allPixels(
std::vector<std::uint8_t> allPixels(
static_cast<std::size_t>(m_actualSize.x) * static_cast<std::size_t>(m_actualSize.y) * 4);
glCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
glCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, allPixels.data()));
// Then we copy the useful pixels from the temporary array to the final one
const Uint8* src = allPixels.data();
Uint8* dst = pixels.data();
const std::uint8_t* src = allPixels.data();
std::uint8_t* dst = pixels.data();
int srcPitch = static_cast<int>(m_actualSize.x * 4);
unsigned int dstPitch = m_size.x * 4;
@ -418,7 +418,7 @@ Image Texture::copyToImage() const
////////////////////////////////////////////////////////////
void Texture::update(const Uint8* pixels)
void Texture::update(const std::uint8_t* pixels)
{
// Update the whole texture
update(pixels, m_size, {0, 0});
@ -426,7 +426,7 @@ void Texture::update(const Uint8* pixels)
////////////////////////////////////////////////////////////
void Texture::update(const Uint8* pixels, const Vector2u& size, const Vector2u& dest)
void Texture::update(const std::uint8_t* pixels, const Vector2u& size, const Vector2u& dest)
{
assert(dest.x + size.x <= m_size.x);
assert(dest.y + size.y <= m_size.y);

View File

@ -537,15 +537,16 @@ Ftp::Response Ftp::DataChannel::open(Ftp::TransferMode mode)
std::string::size_type begin = response.getMessage().find_first_of("0123456789");
if (begin != std::string::npos)
{
Uint8 data[6] = {0, 0, 0, 0, 0, 0};
std::string str = response.getMessage().substr(begin);
std::size_t index = 0;
std::uint8_t data[6] = {0, 0, 0, 0, 0, 0};
std::string str = response.getMessage().substr(begin);
std::size_t index = 0;
for (unsigned char& datum : data)
{
// Extract the current number
while (isdigit(str[index]))
{
datum = static_cast<Uint8>(static_cast<Uint8>(datum * 10) + static_cast<Uint8>(str[index] - '0'));
datum = static_cast<std::uint8_t>(
static_cast<std::uint8_t>(datum * 10) + static_cast<std::uint8_t>(str[index] - '0'));
++index;
}
@ -554,7 +555,7 @@ Ftp::Response Ftp::DataChannel::open(Ftp::TransferMode mode)
}
// Reconstruct connection port and address
unsigned short port = static_cast<Uint8>(data[4] * 256) + data[5];
unsigned short port = static_cast<std::uint8_t>(data[4] * 256) + data[5];
IpAddress address(data[0], data[1], data[2], data[3]);
// Connect the data channel to the server

View File

@ -86,7 +86,7 @@ std::optional<IpAddress> IpAddress::resolve(std::string_view address)
////////////////////////////////////////////////////////////
IpAddress::IpAddress(Uint8 byte0, Uint8 byte1, Uint8 byte2, Uint8 byte3) :
IpAddress::IpAddress(std::uint8_t byte0, std::uint8_t byte1, std::uint8_t byte2, std::uint8_t byte3) :
m_address(htonl(static_cast<std::uint32_t>((byte0 << 24) | (byte1 << 16) | (byte2 << 8) | byte3)))
{
}

View File

@ -120,7 +120,7 @@ Packet::operator bool() const
////////////////////////////////////////////////////////////
Packet& Packet::operator>>(bool& data)
{
Uint8 value;
std::uint8_t value;
if (*this >> value)
data = (value != 0);
@ -142,7 +142,7 @@ Packet& Packet::operator>>(std::int8_t& data)
////////////////////////////////////////////////////////////
Packet& Packet::operator>>(Uint8& data)
Packet& Packet::operator>>(std::uint8_t& data)
{
if (checkSize(sizeof(data)))
{
@ -217,7 +217,7 @@ Packet& Packet::operator>>(Int64& data)
{
// Since ntohll is not available everywhere, we have to convert
// to network byte order (big endian) manually
Uint8 bytes[sizeof(data)];
std::uint8_t bytes[sizeof(data)];
std::memcpy(bytes, &m_data[m_readPos], sizeof(data));
data = (static_cast<Int64>(bytes[0]) << 56) | (static_cast<Int64>(bytes[1]) << 48) |
@ -239,7 +239,7 @@ Packet& Packet::operator>>(Uint64& data)
{
// Since ntohll is not available everywhere, we have to convert
// to network byte order (big endian) manually
Uint8 bytes[sizeof(data)];
std::uint8_t bytes[sizeof(data)];
std::memcpy(bytes, &m_data[m_readPos], sizeof(data));
data = (static_cast<Uint64>(bytes[0]) << 56) | (static_cast<Uint64>(bytes[1]) << 48) |
@ -394,7 +394,7 @@ Packet& Packet::operator>>(String& data)
////////////////////////////////////////////////////////////
Packet& Packet::operator<<(bool data)
{
*this << static_cast<Uint8>(data);
*this << static_cast<std::uint8_t>(data);
return *this;
}
@ -408,7 +408,7 @@ Packet& Packet::operator<<(std::int8_t data)
////////////////////////////////////////////////////////////
Packet& Packet::operator<<(Uint8 data)
Packet& Packet::operator<<(std::uint8_t data)
{
append(&data, sizeof(data));
return *this;
@ -457,14 +457,14 @@ Packet& Packet::operator<<(Int64 data)
// Since htonll is not available everywhere, we have to convert
// to network byte order (big endian) manually
Uint8 toWrite[] = {static_cast<Uint8>((data >> 56) & 0xFF),
static_cast<Uint8>((data >> 48) & 0xFF),
static_cast<Uint8>((data >> 40) & 0xFF),
static_cast<Uint8>((data >> 32) & 0xFF),
static_cast<Uint8>((data >> 24) & 0xFF),
static_cast<Uint8>((data >> 16) & 0xFF),
static_cast<Uint8>((data >> 8) & 0xFF),
static_cast<Uint8>((data)&0xFF)};
std::uint8_t toWrite[] = {static_cast<std::uint8_t>((data >> 56) & 0xFF),
static_cast<std::uint8_t>((data >> 48) & 0xFF),
static_cast<std::uint8_t>((data >> 40) & 0xFF),
static_cast<std::uint8_t>((data >> 32) & 0xFF),
static_cast<std::uint8_t>((data >> 24) & 0xFF),
static_cast<std::uint8_t>((data >> 16) & 0xFF),
static_cast<std::uint8_t>((data >> 8) & 0xFF),
static_cast<std::uint8_t>((data)&0xFF)};
append(&toWrite, sizeof(toWrite));
return *this;
@ -477,14 +477,14 @@ Packet& Packet::operator<<(Uint64 data)
// Since htonll is not available everywhere, we have to convert
// to network byte order (big endian) manually
Uint8 toWrite[] = {static_cast<Uint8>((data >> 56) & 0xFF),
static_cast<Uint8>((data >> 48) & 0xFF),
static_cast<Uint8>((data >> 40) & 0xFF),
static_cast<Uint8>((data >> 32) & 0xFF),
static_cast<Uint8>((data >> 24) & 0xFF),
static_cast<Uint8>((data >> 16) & 0xFF),
static_cast<Uint8>((data >> 8) & 0xFF),
static_cast<Uint8>((data)&0xFF)};
std::uint8_t toWrite[] = {static_cast<std::uint8_t>((data >> 56) & 0xFF),
static_cast<std::uint8_t>((data >> 48) & 0xFF),
static_cast<std::uint8_t>((data >> 40) & 0xFF),
static_cast<std::uint8_t>((data >> 32) & 0xFF),
static_cast<std::uint8_t>((data >> 24) & 0xFF),
static_cast<std::uint8_t>((data >> 16) & 0xFF),
static_cast<std::uint8_t>((data >> 8) & 0xFF),
static_cast<std::uint8_t>((data)&0xFF)};
append(&toWrite, sizeof(toWrite));
return *this;

View File

@ -182,10 +182,10 @@ std::wstring String::toWideString() const
////////////////////////////////////////////////////////////
std::basic_string<Uint8> String::toUtf8() const
std::basic_string<std::uint8_t> String::toUtf8() const
{
// Prepare the output string
std::basic_string<Uint8> output;
std::basic_string<std::uint8_t> output;
output.reserve(m_string.length());
// Convert

View File

@ -40,7 +40,7 @@ CursorImpl::CursorImpl()
////////////////////////////////////////////////////////////
bool CursorImpl::loadFromPixels(const Uint8* /* pixels */, Vector2u /* size */, Vector2u /* hotspot */)
bool CursorImpl::loadFromPixels(const std::uint8_t* /* pixels */, Vector2u /* size */, Vector2u /* hotspot */)
{
// Not supported
return false;

View File

@ -72,7 +72,7 @@ public:
/// Returns false.
///
////////////////////////////////////////////////////////////
bool loadFromPixels(const Uint8* pixels, Vector2u size, Vector2u hotspot);
bool loadFromPixels(const std::uint8_t* pixels, Vector2u size, Vector2u hotspot);
////////////////////////////////////////////////////////////
/// \brief Create a native system cursor

View File

@ -165,7 +165,7 @@ void WindowImplAndroid::setTitle(const String& /* title */)
////////////////////////////////////////////////////////////
void WindowImplAndroid::setIcon(const Vector2u& /* size */, const Uint8* /* pixels */)
void WindowImplAndroid::setIcon(const Vector2u& /* size */, const std::uint8_t* /* pixels */)
{
// Not applicable
}

View File

@ -127,7 +127,7 @@ public:
/// \param pixels Pointer to the pixels in memory, format must be RGBA 32 bits
///
////////////////////////////////////////////////////////////
void setIcon(const Vector2u& size, const Uint8* pixels) override;
void setIcon(const Vector2u& size, const std::uint8_t* pixels) override;
////////////////////////////////////////////////////////////
/// \brief Show or hide the window

View File

@ -45,7 +45,7 @@ Cursor::~Cursor() = default;
////////////////////////////////////////////////////////////
bool Cursor::loadFromPixels(const Uint8* pixels, Vector2u size, Vector2u hotspot)
bool Cursor::loadFromPixels(const std::uint8_t* pixels, Vector2u size, Vector2u hotspot)
{
if ((pixels == nullptr) || (size.x == 0) || (size.y == 0))
return false;

View File

@ -41,21 +41,21 @@ CursorImpl::CursorImpl()
////////////////////////////////////////////////////////////
bool CursorImpl::loadFromPixels(const Uint8* /*pixels*/, Vector2u /*size*/, Vector2u /*hotspot*/)
bool CursorImpl::loadFromPixels(const std::uint8_t* /*pixels*/, Vector2u /*size*/, Vector2u /*hotspot*/)
{
return false;
}
////////////////////////////////////////////////////////////
bool CursorImpl::loadFromPixelsARGB(const Uint8* /*pixels*/, Vector2u /*size*/, Vector2u /*hotspot*/)
bool CursorImpl::loadFromPixelsARGB(const std::uint8_t* /*pixels*/, Vector2u /*size*/, Vector2u /*hotspot*/)
{
return false;
}
////////////////////////////////////////////////////////////
bool CursorImpl::loadFromPixelsMonochrome(const Uint8* /*pixels*/, Vector2u /*size*/, Vector2u /*hotspot*/)
bool CursorImpl::loadFromPixelsMonochrome(const std::uint8_t* /*pixels*/, Vector2u /*size*/, Vector2u /*hotspot*/)
{
return false;
}

View File

@ -70,7 +70,7 @@ public:
/// Refer to sf::Cursor::loadFromPixels().
///
////////////////////////////////////////////////////////////
bool loadFromPixels(const Uint8* pixels, Vector2u size, Vector2u hotspot);
bool loadFromPixels(const std::uint8_t* pixels, Vector2u size, Vector2u hotspot);
////////////////////////////////////////////////////////////
/// \brief Create a native system cursor
@ -95,7 +95,7 @@ private:
/// Refer to sf::Cursor::loadFromPixels().
///
////////////////////////////////////////////////////////////
bool loadFromPixelsARGB(const Uint8* pixels, Vector2u size, Vector2u hotspot);
bool loadFromPixelsARGB(const std::uint8_t* pixels, Vector2u size, Vector2u hotspot);
////////////////////////////////////////////////////////////
/// \brief Create a cursor with the provided image (monochrome)
@ -103,7 +103,7 @@ private:
/// Refer to sf::Cursor::loadFromPixels().
///
////////////////////////////////////////////////////////////
bool loadFromPixelsMonochrome(const Uint8* pixels, Vector2u size, Vector2u hotspot);
bool loadFromPixelsMonochrome(const std::uint8_t* pixels, Vector2u size, Vector2u hotspot);
////////////////////////////////////////////////////////////
/// \brief Release the cursor, if we have loaded one.

View File

@ -101,7 +101,7 @@ void WindowImplDRM::setTitle(const String& /*title*/)
////////////////////////////////////////////////////////////
void WindowImplDRM::setIcon(const Vector2u& /*size*/, const Uint8* /*pixels*/)
void WindowImplDRM::setIcon(const Vector2u& /*size*/, const std::uint8_t* /*pixels*/)
{
}

View File

@ -122,7 +122,7 @@ public:
/// \param pixels Pointer to the pixels in memory, format must be RGBA 32 bits
///
////////////////////////////////////////////////////////////
virtual void setIcon(const Vector2u& size, const Uint8* pixels) override;
virtual void setIcon(const Vector2u& size, const std::uint8_t* pixels) override;
////////////////////////////////////////////////////////////
/// \brief Show or hide the window

View File

@ -53,8 +53,8 @@ String ClipboardImpl::getString()
////////////////////////////////////////////////////////////
void ClipboardImpl::setString(const String& text)
{
AutoreleasePool pool;
std::basic_string<Uint8> utf8 = text.toUtf8();
AutoreleasePool pool;
std::basic_string<std::uint8_t> utf8 = text.toUtf8();
NSString* data = [[NSString alloc] initWithBytes:utf8.data() length:utf8.length() encoding:NSUTF8StringEncoding];
NSPasteboard* pboard = [NSPasteboard generalPasteboard];

View File

@ -92,7 +92,7 @@ public:
/// Refer to sf::Cursor::loadFromPixels().
///
////////////////////////////////////////////////////////////
bool loadFromPixels(const Uint8* pixels, Vector2u size, Vector2u hotspot);
bool loadFromPixels(const std::uint8_t* pixels, Vector2u size, Vector2u hotspot);
////////////////////////////////////////////////////////////
/// \brief Create a native system cursor

View File

@ -67,7 +67,7 @@ CursorImpl::~CursorImpl()
////////////////////////////////////////////////////////////
bool CursorImpl::loadFromPixels(const Uint8* pixels, Vector2u size, Vector2u hotspot)
bool CursorImpl::loadFromPixels(const std::uint8_t* pixels, Vector2u size, Vector2u hotspot)
{
AutoreleasePool pool;
if (m_cursor)

View File

@ -47,6 +47,6 @@
/// \return an instance of NSImage that needs to be released by the caller
///
////////////////////////////////////////////////////////////
+ (NSImage*)imageWithRawData:(const sf::Uint8*)pixels andSize:(NSSize)size;
+ (NSImage*)imageWithRawData:(const std::uint8_t*)pixels andSize:(NSSize)size;
@end

View File

@ -30,7 +30,7 @@
@implementation NSImage (raw)
+ (NSImage*)imageWithRawData:(const sf::Uint8*)pixels andSize:(NSSize)size
+ (NSImage*)imageWithRawData:(const std::uint8_t*)pixels andSize:(NSSize)size
{
// Create an empty image representation.
NSBitmapImageRep* bitmap = [[NSBitmapImageRep alloc]

View File

@ -236,7 +236,7 @@
////////////////////////////////////////////////////////
- (void)setIconTo:(unsigned int)width by:(unsigned int)height with:(const sf::Uint8*)pixels
- (void)setIconTo:(unsigned int)width by:(unsigned int)height with:(const std::uint8_t*)pixels
{
(void)width;
(void)height;

View File

@ -543,7 +543,7 @@
////////////////////////////////////////////////////////
- (void)setIconTo:(unsigned int)width by:(unsigned int)height with:(const sf::Uint8*)pixels
- (void)setIconTo:(unsigned int)width by:(unsigned int)height with:(const std::uint8_t*)pixels
{
// Load image and set app icon.
NSImage* icon = [NSImage imageWithRawData:pixels andSize:NSMakeSize(width, height)];

View File

@ -296,7 +296,7 @@ public:
/// \param pixels Pointer to the pixels in memory, format must be RGBA 32 bits
///
////////////////////////////////////////////////////////////
void setIcon(const Vector2u& size, const Uint8* pixels) override;
void setIcon(const Vector2u& size, const std::uint8_t* pixels) override;
////////////////////////////////////////////////////////////
/// \brief Show or hide the window

View File

@ -448,7 +448,7 @@ void WindowImplCocoa::setTitle(const String& title)
////////////////////////////////////////////////////////////
void WindowImplCocoa::setIcon(const Vector2u& size, const Uint8* pixels)
void WindowImplCocoa::setIcon(const Vector2u& size, const std::uint8_t* pixels)
{
AutoreleasePool pool;
[m_delegate setIconTo:size.x by:size.y with:pixels];

View File

@ -26,7 +26,7 @@
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.hpp> // for sf::Uint8
#include <SFML/Config.hpp>
#include <SFML/Window/WindowHandle.hpp>
@ -221,7 +221,7 @@ class WindowImplCocoa;
/// \param pixels icon's data
///
////////////////////////////////////////////////////////////
- (void)setIconTo:(unsigned int)width by:(unsigned int)height with:(const sf::Uint8*)pixels;
- (void)setIconTo:(unsigned int)width by:(unsigned int)height with:(const std::uint8_t*)pixels;
////////////////////////////////////////////////////////////
/// \brief Fetch new event

View File

@ -343,7 +343,7 @@ void ClipboardImpl::processEvent(XEvent& windowEvent)
{
// Respond to a request for conversion to a UTF-8 string
// or an encoding of our choosing (we always choose UTF-8)
std::basic_string<Uint8> data = m_clipboardContents.toUtf8();
std::basic_string<std::uint8_t> data = m_clipboardContents.toUtf8();
XChangeProperty(m_display,
selectionRequestEvent.requestor,

View File

@ -58,7 +58,7 @@ CursorImpl::~CursorImpl()
////////////////////////////////////////////////////////////
bool CursorImpl::loadFromPixels(const Uint8* pixels, Vector2u size, Vector2u hotspot)
bool CursorImpl::loadFromPixels(const std::uint8_t* pixels, Vector2u size, Vector2u hotspot)
{
release();
@ -70,7 +70,7 @@ bool CursorImpl::loadFromPixels(const Uint8* pixels, Vector2u size, Vector2u hot
////////////////////////////////////////////////////////////
bool CursorImpl::loadFromPixelsARGB(const Uint8* pixels, Vector2u size, Vector2u hotspot)
bool CursorImpl::loadFromPixelsARGB(const std::uint8_t* pixels, Vector2u size, Vector2u hotspot)
{
// Create cursor image, convert from RGBA to ARGB.
XcursorImage* cursorImage = XcursorImageCreate(static_cast<int>(size.x), static_cast<int>(size.y));
@ -97,16 +97,16 @@ bool CursorImpl::loadFromPixelsARGB(const Uint8* pixels, Vector2u size, Vector2u
////////////////////////////////////////////////////////////
bool CursorImpl::loadFromPixelsMonochrome(const Uint8* pixels, Vector2u size, Vector2u hotspot)
bool CursorImpl::loadFromPixelsMonochrome(const std::uint8_t* pixels, Vector2u size, Vector2u hotspot)
{
// Convert the image into a bitmap (monochrome!).
// The bit data is stored packed into bytes. If the number of pixels on each row of the image
// does not fit exactly into (width/8) bytes, one extra byte is allocated at the end of each
// row to store the extra pixels.
std::size_t packedWidth = (size.x + 7) / 8;
std::size_t bytes = packedWidth * size.y;
std::vector<Uint8> mask(bytes, 0); // Defines which pixel is opaque (1) or transparent (0).
std::vector<Uint8> data(bytes, 0); // Defines which pixel is white (1) or black (0).
std::size_t packedWidth = (size.x + 7) / 8;
std::size_t bytes = packedWidth * size.y;
std::vector<std::uint8_t> mask(bytes, 0); // Defines which pixel is opaque (1) or transparent (0).
std::vector<std::uint8_t> data(bytes, 0); // Defines which pixel is white (1) or black (0).
for (std::size_t j = 0; j < size.y; ++j)
{
@ -117,15 +117,15 @@ bool CursorImpl::loadFromPixelsMonochrome(const Uint8* pixels, Vector2u size, Ve
std::size_t bitIndex = i % 8;
// Turn on pixel that are not transparent
Uint8 opacity = pixels[pixelIndex * 4 + 3] > 0 ? 1 : 0;
mask[byteIndex] |= static_cast<Uint8>(opacity << bitIndex);
std::uint8_t opacity = pixels[pixelIndex * 4 + 3] > 0 ? 1 : 0;
mask[byteIndex] |= static_cast<std::uint8_t>(opacity << bitIndex);
// Choose between black/background & white/foreground color for each pixel,
// based on the pixel color intensity: on average, if a channel is "active"
// at 50%, the bit is white.
int intensity = (pixels[pixelIndex * 4 + 0] + pixels[pixelIndex * 4 + 1] + pixels[pixelIndex * 4 + 2]) / 3;
Uint8 bit = intensity > 128 ? 1 : 0;
data[byteIndex] |= static_cast<Uint8>(bit << bitIndex);
std::uint8_t bit = intensity > 128 ? 1 : 0;
data[byteIndex] |= static_cast<std::uint8_t>(bit << bitIndex);
}
}

View File

@ -80,7 +80,7 @@ public:
/// Refer to sf::Cursor::loadFromPixels().
///
////////////////////////////////////////////////////////////
bool loadFromPixels(const Uint8* pixels, Vector2u size, Vector2u hotspot);
bool loadFromPixels(const std::uint8_t* pixels, Vector2u size, Vector2u hotspot);
////////////////////////////////////////////////////////////
/// \brief Create a native system cursor
@ -105,7 +105,7 @@ private:
/// Refer to sf::Cursor::loadFromPixels().
///
////////////////////////////////////////////////////////////
bool loadFromPixelsARGB(const Uint8* pixels, Vector2u size, Vector2u hotspot);
bool loadFromPixelsARGB(const std::uint8_t* pixels, Vector2u size, Vector2u hotspot);
////////////////////////////////////////////////////////////
/// \brief Create a cursor with the provided image (monochrome)
@ -113,7 +113,7 @@ private:
/// Refer to sf::Cursor::loadFromPixels().
///
////////////////////////////////////////////////////////////
bool loadFromPixelsMonochrome(const Uint8* pixels, Vector2u size, Vector2u hotspot);
bool loadFromPixelsMonochrome(const std::uint8_t* pixels, Vector2u size, Vector2u hotspot);
////////////////////////////////////////////////////////////
/// \brief Release the cursor, if we have loaded one.

View File

@ -956,7 +956,7 @@ void WindowImplX11::setTitle(const String& title)
// There is however an option to tell the window manager your Unicode title via hints.
// Convert to UTF-8 encoding.
std::basic_string<Uint8> utf8Title;
std::basic_string<std::uint8_t> utf8Title;
Utf32::toUtf8(title.begin(), title.end(), std::back_inserter(utf8Title));
Atom useUtf8 = getAtom("UTF8_STRING", false);
@ -1001,11 +1001,11 @@ void WindowImplX11::setTitle(const String& title)
////////////////////////////////////////////////////////////
void WindowImplX11::setIcon(const Vector2u& size, const Uint8* pixels)
void WindowImplX11::setIcon(const Vector2u& size, const std::uint8_t* pixels)
{
// X11 wants BGRA pixels: swap red and blue channels
// Note: this memory will be freed by XDestroyImage
auto* iconPixels = static_cast<Uint8*>(
auto* iconPixels = static_cast<std::uint8_t*>(
std::malloc(static_cast<std::size_t>(size.x) * static_cast<std::size_t>(size.y) * 4));
for (std::size_t i = 0; i < static_cast<std::size_t>(size.x) * static_cast<std::size_t>(size.y); ++i)
{
@ -1048,8 +1048,8 @@ void WindowImplX11::setIcon(const Vector2u& size, const Uint8* pixels)
XDestroyImage(iconImage);
// Create the mask pixmap (must have 1 bit depth)
std::size_t pitch = (size.x + 7) / 8;
std::vector<Uint8> maskPixels(pitch * size.y, 0);
std::size_t pitch = (size.x + 7) / 8;
std::vector<std::uint8_t> maskPixels(pitch * size.y, 0);
for (std::size_t j = 0; j < size.y; ++j)
{
for (std::size_t i = 0; i < pitch; ++i)
@ -1058,8 +1058,8 @@ void WindowImplX11::setIcon(const Vector2u& size, const Uint8* pixels)
{
if (i * 8 + k < size.x)
{
Uint8 opacity = (pixels[(i * 8 + k + j * size.x) * 4 + 3] > 0) ? 1 : 0;
maskPixels[i + j * pitch] |= static_cast<Uint8>(opacity << k);
std::uint8_t opacity = (pixels[(i * 8 + k + j * size.x) * 4 + 3] > 0) ? 1 : 0;
maskPixels[i + j * pitch] |= static_cast<std::uint8_t>(opacity << k);
}
}
}
@ -1921,8 +1921,8 @@ bool WindowImplX11::processEvent(XEvent& windowEvent)
#ifdef X_HAVE_UTF8_STRING
if (m_inputContext)
{
Status status;
Uint8 keyBuffer[64];
Status status;
std::uint8_t keyBuffer[64];
int length = Xutf8LookupString(m_inputContext,
&windowEvent.xkey,
@ -1940,8 +1940,8 @@ bool WindowImplX11::processEvent(XEvent& windowEvent)
{
// There might be more than 1 characters in this event,
// so we must iterate it
Uint32 unicode = 0;
Uint8* iter = keyBuffer;
Uint32 unicode = 0;
std::uint8_t* iter = keyBuffer;
while (iter < keyBuffer + length)
{
iter = Utf8::decode(iter, keyBuffer + length, unicode, 0);

View File

@ -129,7 +129,7 @@ public:
/// \param pixels Pointer to the pixels in memory, format must be RGBA 32 bits
///
////////////////////////////////////////////////////////////
void setIcon(const Vector2u& size, const Uint8* pixels) override;
void setIcon(const Vector2u& size, const std::uint8_t* pixels) override;
////////////////////////////////////////////////////////////
/// \brief Show or hide the window

View File

@ -53,7 +53,7 @@ CursorImpl::~CursorImpl()
////////////////////////////////////////////////////////////
bool CursorImpl::loadFromPixels(const Uint8* pixels, Vector2u size, Vector2u hotspot)
bool CursorImpl::loadFromPixels(const std::uint8_t* pixels, Vector2u size, Vector2u hotspot)
{
release();

View File

@ -77,7 +77,7 @@ public:
/// Refer to sf::Cursor::loadFromPixels().
///
////////////////////////////////////////////////////////////
bool loadFromPixels(const Uint8* pixels, Vector2u size, Vector2u hotspot);
bool loadFromPixels(const std::uint8_t* pixels, Vector2u size, Vector2u hotspot);
////////////////////////////////////////////////////////////
/// \brief Create a native system cursor

View File

@ -367,14 +367,14 @@ void WindowImplWin32::setTitle(const String& title)
////////////////////////////////////////////////////////////
void WindowImplWin32::setIcon(const Vector2u& size, const Uint8* pixels)
void WindowImplWin32::setIcon(const Vector2u& size, const std::uint8_t* pixels)
{
// First destroy the previous one
if (m_icon)
DestroyIcon(m_icon);
// Windows wants BGRA pixels: swap red and blue channels
std::vector<Uint8> iconPixels(size.x * size.y * 4);
std::vector<std::uint8_t> iconPixels(size.x * size.y * 4);
for (std::size_t i = 0; i < iconPixels.size() / 4; ++i)
{
iconPixels[i * 4 + 0] = pixels[i * 4 + 2];

View File

@ -126,7 +126,7 @@ public:
/// \param pixels Pointer to the pixels in memory, format must be RGBA 32 bits
///
////////////////////////////////////////////////////////////
void setIcon(const Vector2u& size, const Uint8* pixels) override;
void setIcon(const Vector2u& size, const std::uint8_t* pixels) override;
////////////////////////////////////////////////////////////
/// \brief Show or hide the window

View File

@ -229,7 +229,7 @@ void WindowBase::setTitle(const String& title)
////////////////////////////////////////////////////////////
void WindowBase::setIcon(const Vector2u& size, const Uint8* pixels)
void WindowBase::setIcon(const Vector2u& size, const std::uint8_t* pixels)
{
if (m_impl)
m_impl->setIcon(size, pixels);

View File

@ -180,7 +180,7 @@ public:
/// \param pixels Pointer to the pixels in memory, format must be RGBA 32 bits
///
////////////////////////////////////////////////////////////
virtual void setIcon(const Vector2u& size, const Uint8* pixels) = 0;
virtual void setIcon(const Vector2u& size, const std::uint8_t* pixels) = 0;
////////////////////////////////////////////////////////////
/// \brief Show or hide the window

View File

@ -58,7 +58,7 @@ String ClipboardImpl::getString()
////////////////////////////////////////////////////////////
void ClipboardImpl::setString(const String& text)
{
std::basic_string<Uint8> utf8 = text.toUtf8();
std::basic_string<std::uint8_t> utf8 = text.toUtf8();
NSString* data = [[NSString alloc] initWithBytes:utf8.data() length:utf8.length() encoding:NSUTF8StringEncoding];
UIPasteboard* pboard = [UIPasteboard generalPasteboard];

View File

@ -40,7 +40,7 @@ CursorImpl::CursorImpl()
////////////////////////////////////////////////////////////
bool CursorImpl::loadFromPixels(const Uint8* /* pixels */, Vector2u /* size */, Vector2u /* hotspot */)
bool CursorImpl::loadFromPixels(const std::uint8_t* /* pixels */, Vector2u /* size */, Vector2u /* hotspot */)
{
// Not supported
return false;

View File

@ -72,7 +72,7 @@ public:
/// Returns false.
///
////////////////////////////////////////////////////////////
bool loadFromPixels(const Uint8* pixels, Vector2u size, Vector2u hotspot);
bool loadFromPixels(const std::uint8_t* pixels, Vector2u size, Vector2u hotspot);
////////////////////////////////////////////////////////////
/// \brief Create a native system cursor

View File

@ -129,7 +129,7 @@ public:
/// \param pixels Pointer to the pixels in memory, format must be RGBA 32 bits
///
////////////////////////////////////////////////////////////
void setIcon(const Vector2u& size, const Uint8* pixels) override;
void setIcon(const Vector2u& size, const std::uint8_t* pixels) override;
////////////////////////////////////////////////////////////
/// \brief Show or hide the window

View File

@ -161,7 +161,7 @@ void WindowImplUIKit::setTitle(const String& /* title */)
////////////////////////////////////////////////////////////
void WindowImplUIKit::setIcon(const Vector2u& /* size */, const Uint8* /* pixels */)
void WindowImplUIKit::setIcon(const Vector2u& /* size */, const std::uint8_t* /* pixels */)
{
// Not applicable
}

View File

@ -49,10 +49,10 @@ TEST_CASE("sf::Image - [graphics]")
}
}
SUBCASE("create(Vector2, Uint8*)")
SUBCASE("create(Vector2, std::uint8_t*)")
{
// 10 x 10, with 4 colour channels array
std::array<sf::Uint8, 400> pixels;
std::array<std::uint8_t, 400> pixels;
for (std::size_t i = 0; i < pixels.size(); i += 4)
{
pixels[i] = 255; // r
@ -135,12 +135,12 @@ TEST_CASE("sf::Image - [graphics]")
const sf::Color source(5, 255, 78, 232);
// Create the composited colour for via the alpha composite over operation
const auto a = static_cast<sf::Uint8>(source.a + (dest.a * (255 - source.a)) / 255);
const auto r = static_cast<sf::Uint8>(
const auto a = static_cast<std::uint8_t>(source.a + (dest.a * (255 - source.a)) / 255);
const auto r = static_cast<std::uint8_t>(
((source.r * source.a) + (((dest.r * dest.a) * (255 - source.a))) / 255) / a);
const auto g = static_cast<sf::Uint8>(
const auto g = static_cast<std::uint8_t>(
((source.g * source.a) + (((dest.g * dest.a) * (255 - source.a))) / 255) / a);
const auto b = static_cast<sf::Uint8>(
const auto b = static_cast<std::uint8_t>(
((source.b * source.a) + (((dest.b * dest.a) * (255 - source.a))) / 255) / a);
const sf::Color composite(r, g, b, a);
@ -214,7 +214,7 @@ TEST_CASE("sf::Image - [graphics]")
}
}
SUBCASE("createMaskFromColor(Color, Uint8)")
SUBCASE("createMaskFromColor(Color, std::uint8_t)")
{
sf::Image image;
image.create(sf::Vector2u(10, 10), sf::Color::Blue);

View File

@ -14,8 +14,6 @@ TEST_CASE("SFML/Config.hpp")
SUBCASE("Fixed width types")
{
CHECK(sizeof(sf::Uint8) == 1);
CHECK(sizeof(sf::Int16) == 2);
CHECK(sizeof(sf::Uint16) == 2);