From 2fa4d7b0db88abcccbda287af10fc336a8dbb910 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Wed, 26 Sep 2012 19:18:33 +0200 Subject: Refactored resource and relief loading - now loading can be from any image format - added IntColor struct for precise pixel operations --- src/common/image.cpp | 35 +++++++++++++++++++++++++++-------- src/common/image.h | 6 ++++++ 2 files changed, 33 insertions(+), 8 deletions(-) (limited to 'src/common') 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(m_data->surface->pixels)[index]; - Uint8 r = static_cast(color.r * 255.0f); - Uint8 g = static_cast(color.g * 255.0f); - Uint8 b = static_cast(color.b * 255.0f); - Uint8 a = static_cast(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; diff --git a/src/common/image.h b/src/common/image.h index 93c7cab..3391bdb 100644 --- a/src/common/image.h +++ b/src/common/image.h @@ -78,9 +78,15 @@ public: //! Sets the color at given pixel void SetPixel(Math::IntPoint pixel, Gfx::Color color); + //! Sets the precise color at given pixel + void SetPixelInt(Math::IntPoint pixel, Gfx::IntColor color); + //! Returns the color at given pixel Gfx::Color GetPixel(Math::IntPoint pixel); + //! Returns the precise color at given pixel + Gfx::IntColor GetPixelInt(Math::IntPoint pixel); + //! Loads an image from the specified file bool Load(const std::string &fileName); -- cgit v1.2.3-1-g7c22 From a394c9efec830b275c0b738974126aead284ec4e Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Thu, 27 Sep 2012 20:43:20 +0200 Subject: Updated docs and some Doxygen fixes --- src/common/README.txt | 2 +- src/common/event.h | 2 +- src/common/iman.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/common') diff --git a/src/common/README.txt b/src/common/README.txt index 73d65b7..25c9fbf 100644 --- a/src/common/README.txt +++ b/src/common/README.txt @@ -1,4 +1,4 @@ /** - * \dir common + * \dir src/common * \brief Structs and utils shared throughout the application */ diff --git a/src/common/event.h b/src/common/event.h index dc50ee6..ce2872a 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -81,7 +81,7 @@ enum WheelDirection }; /** - * \enum MouseWheelEventData + * \struct MouseWheelEventData * \brief Additional data for mouse wheel event. */ struct MouseWheelEventData diff --git a/src/common/iman.h b/src/common/iman.h index 44f143a..75655aa 100644 --- a/src/common/iman.h +++ b/src/common/iman.h @@ -95,7 +95,7 @@ enum ManagedClassType /** - * \enum ManagedClassInstances + * \struct ManagedClassInstances * \brief Instances of class managed by CInstanceManager */ struct ManagedClassInstances -- cgit v1.2.3-1-g7c22 From e7e895438497f4efcb4d8bee240b2fe4e5938184 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sat, 29 Sep 2012 17:19:23 +0200 Subject: MXE support and CMake files refactoring - added support for cross-compiling with MXE (http://mxe.cc/) - refactored CMake files, adding some options and moving definitions to more suitable places --- src/common/config.h.cmake | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/common') diff --git a/src/common/config.h.cmake b/src/common/config.h.cmake index f496db0..8c85df1 100644 --- a/src/common/config.h.cmake +++ b/src/common/config.h.cmake @@ -1,10 +1,9 @@ #pragma once // Macros set by CMake -#cmakedefine DEBUG - #cmakedefine PLATFORM_WINDOWS @PLATFORM_WINDOWS@ #cmakedefine PLATFORM_LINUX @PLATFORM_LINUX@ #cmakedefine PLATFORM_OTHER @PLATFORM_OTHER@ #cmakedefine USE_GLEW @USE_GLEW@ +#cmakedefine GLEW_STATIC \ No newline at end of file -- cgit v1.2.3-1-g7c22