diff options
author | Zaba999 <qrwfw5rp> | 2012-09-29 23:53:57 +0200 |
---|---|---|
committer | Zaba999 <qrwfw5rp> | 2012-09-29 23:53:57 +0200 |
commit | 95e1d101c82e43396fd93abfaa522e3651613c4c (patch) | |
tree | 9d72f27e84a25c7a744b31eb7612698506ac5b68 /src/common/image.cpp | |
parent | aa9df8b1f0fbbad4c7be0214a19a90b8495a2067 (diff) | |
parent | c8f39a4c96ab63f9e3edc96845e1b70c89b95d2b (diff) | |
download | colobot-95e1d101c82e43396fd93abfaa522e3651613c4c.tar.gz colobot-95e1d101c82e43396fd93abfaa522e3651613c4c.tar.bz2 colobot-95e1d101c82e43396fd93abfaa522e3651613c4c.zip |
Merge branch 'dev' of https://github.com/colobot/colobot into dev
Diffstat (limited to 'src/common/image.cpp')
-rw-r--r-- | src/common/image.cpp | 35 |
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; |