summaryrefslogtreecommitdiffstats
path: root/src/common/image.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/image.cpp')
-rw-r--r--src/common/image.cpp35
1 files changed, 27 insertions, 8 deletions
diff --git a/src/common/image.cpp b/src/common/image.cpp
index 50f6eee..6a2ab0e 100644
--- a/src/common/image.cpp
+++ b/src/common/image.cpp
@@ -190,7 +190,7 @@ Math::IntPoint CImage::GetSize() const
* \param pixel pixel coords (range x: 0..width-1 y: 0..height-1)
* \returns color
*/
-Gfx::Color CImage::GetPixel(Math::IntPoint pixel)
+Gfx::IntColor CImage::GetPixelInt(Math::IntPoint pixel)
{
assert(m_data != nullptr);
assert(pixel.x >= 0 || pixel.x <= m_data->surface->w);
@@ -229,16 +229,28 @@ Gfx::Color CImage::GetPixel(Math::IntPoint pixel)
Uint8 r = 0, g = 0, b = 0, a = 0;
SDL_GetRGBA(u, m_data->surface->format, &r, &g, &b, &a);
- return Gfx::Color(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f);
+ return Gfx::IntColor(r, g, b, a);
+}
+
+/**
+ * Image must be valid and pixel coords in valid range.
+ *
+ * \param pixel pixel coords (range x: 0..width-1 y: 0..height-1)
+ * \returns color
+ */
+Gfx::Color CImage::GetPixel(Math::IntPoint pixel)
+{
+ return Gfx::IntColorToColor(GetPixelInt(pixel));
}
+
/**
* Image must be valid and pixel coords in valid range.
*
* \param pixel pixel coords (range x: 0..width-1 y: 0..height-1)
* \param color color
*/
-void CImage::SetPixel(Math::IntPoint pixel, Gfx::Color color)
+void CImage::SetPixelInt(Math::IntPoint pixel, Gfx::IntColor color)
{
assert(m_data != nullptr);
assert(pixel.x >= 0 || pixel.x <= m_data->surface->w);
@@ -248,11 +260,7 @@ void CImage::SetPixel(Math::IntPoint pixel, Gfx::Color color)
int index = pixel.y * m_data->surface->pitch + pixel.x * bpp;
Uint8* p = &static_cast<Uint8*>(m_data->surface->pixels)[index];
- Uint8 r = static_cast<Uint8>(color.r * 255.0f);
- Uint8 g = static_cast<Uint8>(color.g * 255.0f);
- Uint8 b = static_cast<Uint8>(color.b * 255.0f);
- Uint8 a = static_cast<Uint8>(color.a * 255.0f);
- Uint32 u = SDL_MapRGBA(m_data->surface->format, r, g, b, a);
+ Uint32 u = SDL_MapRGBA(m_data->surface->format, color.r, color.g, color.b, color.a);
switch(bpp)
{
@@ -288,6 +296,17 @@ void CImage::SetPixel(Math::IntPoint pixel, Gfx::Color color)
}
}
+/**
+ * Image must be valid and pixel coords in valid range.
+ *
+ * \param pixel pixel coords (range x: 0..width-1 y: 0..height-1)
+ * \param color color
+ */
+void CImage::SetPixel(Math::IntPoint pixel, Gfx::Color color)
+{
+ SetPixelInt(pixel, Gfx::ColorToIntColor(color));
+}
+
std::string CImage::GetError()
{
return m_error;