From 361b46140d87d5acdd33b5d02741c60003b416ed Mon Sep 17 00:00:00 2001 From: rachytski Date: Sat, 28 Jul 2012 21:13:35 -0700 Subject: [PATCH] added function for getting information about yg::DataFormat. --- yg/agg_traits.hpp | 2 +- yg/circle_style.cpp | 2 +- yg/data_formats.cpp | 39 +++++++++++ yg/data_formats.hpp | 140 +++------------------------------------- yg/data_traits.hpp | 140 ++++++++++++++++++++++++++++++++++++++++ yg/glyph_cache.cpp | 2 +- yg/glyph_style.cpp | 2 +- yg/line_style.cpp | 2 +- yg/renderer.cpp | 2 +- yg/resource_manager.cpp | 19 +----- yg/resource_manager.hpp | 7 +- yg/resource_style.cpp | 2 +- yg/skin_page.cpp | 2 +- yg/texture.hpp | 2 +- yg/yg.pro | 6 +- 15 files changed, 203 insertions(+), 166 deletions(-) create mode 100644 yg/data_formats.cpp create mode 100644 yg/data_traits.hpp diff --git a/yg/agg_traits.hpp b/yg/agg_traits.hpp index c9aa0945aa..04bd0dfea7 100644 --- a/yg/agg_traits.hpp +++ b/yg/agg_traits.hpp @@ -7,7 +7,7 @@ #include #include -#include "data_formats.hpp" +#include "data_traits.hpp" template struct AggTraits diff --git a/yg/circle_style.cpp b/yg/circle_style.cpp index 7bb497bddc..25e6e15cf7 100644 --- a/yg/circle_style.cpp +++ b/yg/circle_style.cpp @@ -1,7 +1,7 @@ #include "resource_style.hpp" #include "agg_traits.hpp" -#include "data_formats.hpp" +#include "data_traits.hpp" namespace yg { diff --git a/yg/data_formats.cpp b/yg/data_formats.cpp new file mode 100644 index 0000000000..3056251cf3 --- /dev/null +++ b/yg/data_formats.cpp @@ -0,0 +1,39 @@ +#include "data_formats.hpp" + +namespace yg +{ + struct DataFormatInfo + { + yg::DataFormat m_fmt; + unsigned m_size; + char const * m_name; + DataFormatInfo(yg::DataFormat fmt, unsigned size, char const * name) + : m_fmt(fmt), m_size(size), m_name(name) + {} + }; + + DataFormatInfo s_info [] = {DataFormatInfo(Data4Bpp, 2, "Data4Bpp"), + DataFormatInfo(Data8Bpp, 4, "Data8Bpp"), + DataFormatInfo(Data565Bpp, 2, "Data565Bpp"), + DataFormatInfo((yg::DataFormat)0, 0, "Unknown")}; + + DataFormatInfo const findInfo(yg::DataFormat const & fmt) + { + unsigned const cnt = sizeof(s_info) / sizeof(DataFormatInfo); + for (unsigned i = 0; i < cnt; ++i) + if (s_info[i].m_fmt == fmt) + return s_info[i]; + + return s_info[cnt - 1]; + } + + unsigned formatSize(DataFormat const & fmt) + { + return findInfo(fmt).m_size; + } + + char const * formatName(DataFormat const & fmt) + { + return findInfo(fmt).m_name; + } +} diff --git a/yg/data_formats.hpp b/yg/data_formats.hpp index 6ebf2492d5..a41b68b796 100644 --- a/yg/data_formats.hpp +++ b/yg/data_formats.hpp @@ -1,140 +1,16 @@ #pragma once -#include "internal/opengl.hpp" -#include "color.hpp" -#include -#include - -namespace gil = boost::gil; -namespace mpl = boost::mpl; - namespace yg { - template - struct DownsampleImpl + enum DataFormat { - template - void operator()(Ch1 const & ch1, Ch2 & ch2) const - { - ch2 = ch1 / Denom; - } + Data8Bpp, + Data4Bpp, + Data565Bpp }; - template - struct Downsample - { - static const int Denom = 1 << (FromBig - ToSmall); - - template - void operator()(SrcP const & src, DstP & dst) const - { - static_for_each(src, dst, DownsampleImpl()); - } - }; - - struct RGBA8Traits - { - typedef gil::rgba8_pixel_t pixel_t; - typedef gil::rgba8c_pixel_t const_pixel_t; - typedef gil::rgba8_view_t view_t; - typedef gil::rgba8c_view_t const_view_t; - typedef gil::rgba8_image_t image_t; - - static const int maxChannelVal = 255; - static const int channelScaleFactor = 1; - - static const int gl_pixel_data_type = GL_UNSIGNED_BYTE; - static const int gl_pixel_format_type = GL_RGBA; - - typedef Downsample<8, 8> color_converter; - - static pixel_t const createPixel(yg::Color const & c) - { - return pixel_t((unsigned char)(c.r / 255.0f) * maxChannelVal, - (unsigned char)(c.g / 255.0f) * maxChannelVal, - (unsigned char)(c.b / 255.0f) * maxChannelVal, - (unsigned char)(c.a / 255.0f) * maxChannelVal); - } - }; - - struct RGB565Traits - { - typedef gil::packed_pixel_type< - unsigned short, - mpl::vector3_c, - gil::bgr_layout_t - >::type pixel_t; - - typedef gil::memory_based_step_iterator iterator_t; - typedef gil::memory_based_2d_locator locator_t; - typedef gil::image_view view_t; - - typedef pixel_t const const_pixel_t; - - typedef gil::memory_based_step_iterator const_iterator_t; - typedef gil::memory_based_2d_locator const_locator_t; - typedef gil::image_view const_view_t; - - typedef gil::image image_t; - - static const int maxChannelVal = 32; - static const int channelScaleFactor = 8; - - static const int gl_pixel_data_type = GL_UNSIGNED_SHORT_5_6_5; - static const int gl_pixel_format_type = GL_RGB; - - typedef Downsample<8, 5> color_converter; - - static pixel_t const createPixel(yg::Color const & c) - { - return pixel_t((int)(c.r / 255.0f) * maxChannelVal, - (int)(c.g / 255.0f) * maxChannelVal, //< fix this channel - (int)(c.b / 255.0f) * maxChannelVal); - } - }; - - struct RGBA4Traits - { - typedef gil::packed_pixel_type< - unsigned short, - mpl::vector4_c, - gil::abgr_layout_t - >::type pixel_t; - - typedef gil::memory_based_step_iterator iterator_t; - typedef gil::memory_based_2d_locator locator_t; - typedef gil::image_view view_t; - - typedef pixel_t const const_pixel_t; - - typedef gil::memory_based_step_iterator const_iterator_t; - typedef gil::memory_based_2d_locator const_locator_t; - typedef gil::image_view const_view_t; - - typedef gil::image image_t; - - static const int maxChannelVal = 15; - static const int channelScaleFactor = 16; - - static const int gl_pixel_data_type = GL_UNSIGNED_SHORT_4_4_4_4; - static const int gl_pixel_format_type = GL_RGBA; - - typedef Downsample<8, 4> color_converter; - - static pixel_t const createPixel(yg::Color const & c) - { - return pixel_t((int)(c.r / 255.0f) * maxChannelVal, - (int)(c.g / 255.0f) * maxChannelVal, - (int)(c.b / 255.0f) * maxChannelVal, - (int)(c.a / 255.0f) * maxChannelVal); - } - }; + /// getting size of the pixel in specified DataFormat. + unsigned formatSize(DataFormat const & fmt); + /// getting string representation of the specified DataFormat. + char const * formatName(DataFormat const & fmt); } - -#ifdef OMIM_GL_ES - #define DATA_TRAITS yg::RGBA4Traits - #define RT_TRAITS yg::RGBA4Traits -#else - #define DATA_TRAITS yg::RGBA8Traits - #define RT_TRAITS yg::RGBA8Traits -#endif diff --git a/yg/data_traits.hpp b/yg/data_traits.hpp new file mode 100644 index 0000000000..6ebf2492d5 --- /dev/null +++ b/yg/data_traits.hpp @@ -0,0 +1,140 @@ +#pragma once + +#include "internal/opengl.hpp" +#include "color.hpp" +#include +#include + +namespace gil = boost::gil; +namespace mpl = boost::mpl; + +namespace yg +{ + template + struct DownsampleImpl + { + template + void operator()(Ch1 const & ch1, Ch2 & ch2) const + { + ch2 = ch1 / Denom; + } + }; + + template + struct Downsample + { + static const int Denom = 1 << (FromBig - ToSmall); + + template + void operator()(SrcP const & src, DstP & dst) const + { + static_for_each(src, dst, DownsampleImpl()); + } + }; + + struct RGBA8Traits + { + typedef gil::rgba8_pixel_t pixel_t; + typedef gil::rgba8c_pixel_t const_pixel_t; + typedef gil::rgba8_view_t view_t; + typedef gil::rgba8c_view_t const_view_t; + typedef gil::rgba8_image_t image_t; + + static const int maxChannelVal = 255; + static const int channelScaleFactor = 1; + + static const int gl_pixel_data_type = GL_UNSIGNED_BYTE; + static const int gl_pixel_format_type = GL_RGBA; + + typedef Downsample<8, 8> color_converter; + + static pixel_t const createPixel(yg::Color const & c) + { + return pixel_t((unsigned char)(c.r / 255.0f) * maxChannelVal, + (unsigned char)(c.g / 255.0f) * maxChannelVal, + (unsigned char)(c.b / 255.0f) * maxChannelVal, + (unsigned char)(c.a / 255.0f) * maxChannelVal); + } + }; + + struct RGB565Traits + { + typedef gil::packed_pixel_type< + unsigned short, + mpl::vector3_c, + gil::bgr_layout_t + >::type pixel_t; + + typedef gil::memory_based_step_iterator iterator_t; + typedef gil::memory_based_2d_locator locator_t; + typedef gil::image_view view_t; + + typedef pixel_t const const_pixel_t; + + typedef gil::memory_based_step_iterator const_iterator_t; + typedef gil::memory_based_2d_locator const_locator_t; + typedef gil::image_view const_view_t; + + typedef gil::image image_t; + + static const int maxChannelVal = 32; + static const int channelScaleFactor = 8; + + static const int gl_pixel_data_type = GL_UNSIGNED_SHORT_5_6_5; + static const int gl_pixel_format_type = GL_RGB; + + typedef Downsample<8, 5> color_converter; + + static pixel_t const createPixel(yg::Color const & c) + { + return pixel_t((int)(c.r / 255.0f) * maxChannelVal, + (int)(c.g / 255.0f) * maxChannelVal, //< fix this channel + (int)(c.b / 255.0f) * maxChannelVal); + } + }; + + struct RGBA4Traits + { + typedef gil::packed_pixel_type< + unsigned short, + mpl::vector4_c, + gil::abgr_layout_t + >::type pixel_t; + + typedef gil::memory_based_step_iterator iterator_t; + typedef gil::memory_based_2d_locator locator_t; + typedef gil::image_view view_t; + + typedef pixel_t const const_pixel_t; + + typedef gil::memory_based_step_iterator const_iterator_t; + typedef gil::memory_based_2d_locator const_locator_t; + typedef gil::image_view const_view_t; + + typedef gil::image image_t; + + static const int maxChannelVal = 15; + static const int channelScaleFactor = 16; + + static const int gl_pixel_data_type = GL_UNSIGNED_SHORT_4_4_4_4; + static const int gl_pixel_format_type = GL_RGBA; + + typedef Downsample<8, 4> color_converter; + + static pixel_t const createPixel(yg::Color const & c) + { + return pixel_t((int)(c.r / 255.0f) * maxChannelVal, + (int)(c.g / 255.0f) * maxChannelVal, + (int)(c.b / 255.0f) * maxChannelVal, + (int)(c.a / 255.0f) * maxChannelVal); + } + }; +} + +#ifdef OMIM_GL_ES + #define DATA_TRAITS yg::RGBA4Traits + #define RT_TRAITS yg::RGBA4Traits +#else + #define DATA_TRAITS yg::RGBA8Traits + #define RT_TRAITS yg::RGBA8Traits +#endif diff --git a/yg/glyph_cache.cpp b/yg/glyph_cache.cpp index 2ccd3e9b29..efeb9f5e63 100644 --- a/yg/glyph_cache.cpp +++ b/yg/glyph_cache.cpp @@ -1,6 +1,6 @@ #include "glyph_cache.hpp" #include "glyph_cache_impl.hpp" -#include "data_formats.hpp" +#include "data_traits.hpp" #include "internal/opengl.hpp" #include "ft2_debug.hpp" diff --git a/yg/glyph_style.cpp b/yg/glyph_style.cpp index 81aeeeec98..787b30987e 100644 --- a/yg/glyph_style.cpp +++ b/yg/glyph_style.cpp @@ -2,7 +2,7 @@ #include "glyph_cache.hpp" #include "agg_traits.hpp" -#include "data_formats.hpp" +#include "data_traits.hpp" namespace yg { diff --git a/yg/line_style.cpp b/yg/line_style.cpp index 25f114c610..1e7c01194e 100644 --- a/yg/line_style.cpp +++ b/yg/line_style.cpp @@ -1,7 +1,7 @@ #include "resource_style.hpp" #include "agg_traits.hpp" -#include "data_formats.hpp" +#include "data_traits.hpp" namespace yg { diff --git a/yg/renderer.cpp b/yg/renderer.cpp index 995b0e8dfc..135b667e66 100644 --- a/yg/renderer.cpp +++ b/yg/renderer.cpp @@ -1,6 +1,6 @@ #include "../base/SRC_FIRST.hpp" #include "renderer.hpp" -#include "data_formats.hpp" +#include "data_traits.hpp" #include "utils.hpp" #include "framebuffer.hpp" #include "renderbuffer.hpp" diff --git a/yg/resource_manager.cpp b/yg/resource_manager.cpp index 31a6f1a3fd..b64f9549f4 100644 --- a/yg/resource_manager.cpp +++ b/yg/resource_manager.cpp @@ -1,7 +1,7 @@ #include "internal/opengl.hpp" #include "base_texture.hpp" -#include "data_formats.hpp" +#include "data_traits.hpp" #include "resource_manager.hpp" #include "skin_loader.hpp" #include "storage.hpp" @@ -430,23 +430,8 @@ namespace if (isGPU("Vivante Corporation", "", false)) m_useVA = true;*/ - string name; - switch (m_texRtFormat) - { - case yg::Data4Bpp: - name = "Data4Bpp"; - break; - case yg::Data8Bpp: - name = "Data8Bpp"; - break; - case yg::Data565Bpp: - name = "Data565Bpp"; - break; - default: - name = "Unknown"; - }; + LOG(LINFO, ("selected", yg::formatName(m_texRtFormat), "format for tile textures")); - LOG(LINFO, ("selected", name, "format for tile textures")); if (m_useReadPixelsToSynchronize) LOG(LINFO, ("using ReadPixels instead of glFinish to synchronize")); } diff --git a/yg/resource_manager.hpp b/yg/resource_manager.hpp index 3bbc582e49..af9462e9a2 100644 --- a/yg/resource_manager.hpp +++ b/yg/resource_manager.hpp @@ -11,6 +11,7 @@ #include "storage.hpp" #include "glyph_cache.hpp" +#include "data_formats.hpp" namespace yg { @@ -24,12 +25,6 @@ namespace yg struct GlyphInfo; - enum DataFormat - { - Data8Bpp, - Data4Bpp, - Data565Bpp - }; struct TTextureFactory : BasePoolElemFactory { diff --git a/yg/resource_style.cpp b/yg/resource_style.cpp index 0439b1e912..327327b7bc 100644 --- a/yg/resource_style.cpp +++ b/yg/resource_style.cpp @@ -1,6 +1,6 @@ #include "resource_style.hpp" -#include "data_formats.hpp" +#include "data_traits.hpp" namespace yg { diff --git a/yg/skin_page.cpp b/yg/skin_page.cpp index 75baa96350..a62678c8cf 100644 --- a/yg/skin_page.cpp +++ b/yg/skin_page.cpp @@ -1,7 +1,7 @@ #include "skin_page.hpp" #include "texture.hpp" -#include "data_formats.hpp" +#include "data_traits.hpp" #include "resource_style.hpp" #include "resource_manager.hpp" #include "internal/opengl.hpp" diff --git a/yg/texture.hpp b/yg/texture.hpp index e0fe3c87f3..34a57514e6 100644 --- a/yg/texture.hpp +++ b/yg/texture.hpp @@ -1,7 +1,7 @@ #pragma once #include "managed_texture.hpp" -#include "data_formats.hpp" +#include "data_traits.hpp" #include "../platform/platform.hpp" diff --git a/yg/yg.pro b/yg/yg.pro index e055003b3a..67d5051950 100644 --- a/yg/yg.pro +++ b/yg/yg.pro @@ -61,7 +61,8 @@ SOURCES += \ glyph_style.cpp \ circle_element.cpp \ packets_queue.cpp \ - display_list.cpp + display_list.cpp \ + data_formats.cpp HEADERS += \ internal/opengl.hpp \ @@ -116,7 +117,8 @@ HEADERS += \ agg_traits.hpp \ circle_element.hpp \ packets_queue.hpp \ - display_list.hpp + display_list.hpp \ + data_traits.hpp # At the moment do not use OpenGL 2.0 on iOS. !iphone* {