added function for getting information about yg::DataFormat.

This commit is contained in:
rachytski 2012-07-28 21:13:35 -07:00 committed by Alex Zolotarev
parent 7afd894da4
commit 361b46140d
15 changed files with 203 additions and 166 deletions

View file

@ -7,7 +7,7 @@
#include <agg_scanline_u.h>
#include <agg_ellipse.h>
#include "data_formats.hpp"
#include "data_traits.hpp"
template <typename Traits>
struct AggTraits

View file

@ -1,7 +1,7 @@
#include "resource_style.hpp"
#include "agg_traits.hpp"
#include "data_formats.hpp"
#include "data_traits.hpp"
namespace yg
{

39
yg/data_formats.cpp Normal file
View file

@ -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;
}
}

View file

@ -1,140 +1,16 @@
#pragma once
#include "internal/opengl.hpp"
#include "color.hpp"
#include <boost/gil/gil_all.hpp>
#include <boost/mpl/vector_c.hpp>
namespace gil = boost::gil;
namespace mpl = boost::mpl;
namespace yg
{
template <unsigned Denom>
struct DownsampleImpl
enum DataFormat
{
template <typename Ch1, typename Ch2>
void operator()(Ch1 const & ch1, Ch2 & ch2) const
{
ch2 = ch1 / Denom;
}
Data8Bpp,
Data4Bpp,
Data565Bpp
};
template <unsigned FromBig, unsigned ToSmall>
struct Downsample
{
static const int Denom = 1 << (FromBig - ToSmall);
template <typename SrcP, typename DstP>
void operator()(SrcP const & src, DstP & dst) const
{
static_for_each(src, dst, DownsampleImpl<Denom>());
}
};
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<unsigned, 5, 6, 5>,
gil::bgr_layout_t
>::type pixel_t;
typedef gil::memory_based_step_iterator<pixel_t*> iterator_t;
typedef gil::memory_based_2d_locator<iterator_t> locator_t;
typedef gil::image_view<locator_t> view_t;
typedef pixel_t const const_pixel_t;
typedef gil::memory_based_step_iterator<pixel_t const *> const_iterator_t;
typedef gil::memory_based_2d_locator<const_iterator_t> const_locator_t;
typedef gil::image_view<const_locator_t> const_view_t;
typedef gil::image<pixel_t, false> 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<unsigned, 4, 4, 4, 4>,
gil::abgr_layout_t
>::type pixel_t;
typedef gil::memory_based_step_iterator<pixel_t*> iterator_t;
typedef gil::memory_based_2d_locator<iterator_t> locator_t;
typedef gil::image_view<locator_t> view_t;
typedef pixel_t const const_pixel_t;
typedef gil::memory_based_step_iterator<pixel_t const *> const_iterator_t;
typedef gil::memory_based_2d_locator<const_iterator_t> const_locator_t;
typedef gil::image_view<const_locator_t> const_view_t;
typedef gil::image<pixel_t, false> 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

140
yg/data_traits.hpp Normal file
View file

@ -0,0 +1,140 @@
#pragma once
#include "internal/opengl.hpp"
#include "color.hpp"
#include <boost/gil/gil_all.hpp>
#include <boost/mpl/vector_c.hpp>
namespace gil = boost::gil;
namespace mpl = boost::mpl;
namespace yg
{
template <unsigned Denom>
struct DownsampleImpl
{
template <typename Ch1, typename Ch2>
void operator()(Ch1 const & ch1, Ch2 & ch2) const
{
ch2 = ch1 / Denom;
}
};
template <unsigned FromBig, unsigned ToSmall>
struct Downsample
{
static const int Denom = 1 << (FromBig - ToSmall);
template <typename SrcP, typename DstP>
void operator()(SrcP const & src, DstP & dst) const
{
static_for_each(src, dst, DownsampleImpl<Denom>());
}
};
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<unsigned, 5, 6, 5>,
gil::bgr_layout_t
>::type pixel_t;
typedef gil::memory_based_step_iterator<pixel_t*> iterator_t;
typedef gil::memory_based_2d_locator<iterator_t> locator_t;
typedef gil::image_view<locator_t> view_t;
typedef pixel_t const const_pixel_t;
typedef gil::memory_based_step_iterator<pixel_t const *> const_iterator_t;
typedef gil::memory_based_2d_locator<const_iterator_t> const_locator_t;
typedef gil::image_view<const_locator_t> const_view_t;
typedef gil::image<pixel_t, false> 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<unsigned, 4, 4, 4, 4>,
gil::abgr_layout_t
>::type pixel_t;
typedef gil::memory_based_step_iterator<pixel_t*> iterator_t;
typedef gil::memory_based_2d_locator<iterator_t> locator_t;
typedef gil::image_view<locator_t> view_t;
typedef pixel_t const const_pixel_t;
typedef gil::memory_based_step_iterator<pixel_t const *> const_iterator_t;
typedef gil::memory_based_2d_locator<const_iterator_t> const_locator_t;
typedef gil::image_view<const_locator_t> const_view_t;
typedef gil::image<pixel_t, false> 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

View file

@ -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"

View file

@ -2,7 +2,7 @@
#include "glyph_cache.hpp"
#include "agg_traits.hpp"
#include "data_formats.hpp"
#include "data_traits.hpp"
namespace yg
{

View file

@ -1,7 +1,7 @@
#include "resource_style.hpp"
#include "agg_traits.hpp"
#include "data_formats.hpp"
#include "data_traits.hpp"
namespace yg
{

View file

@ -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"

View file

@ -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"));
}

View file

@ -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
{

View file

@ -1,6 +1,6 @@
#include "resource_style.hpp"
#include "data_formats.hpp"
#include "data_traits.hpp"
namespace yg
{

View file

@ -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"

View file

@ -1,7 +1,7 @@
#pragma once
#include "managed_texture.hpp"
#include "data_formats.hpp"
#include "data_traits.hpp"
#include "../platform/platform.hpp"

View file

@ -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* {