From 8df85096ba2eaeefda8db42aca476f09b6ed54c1 Mon Sep 17 00:00:00 2001 From: rachytski Date: Sat, 5 Feb 2011 20:18:29 +0200 Subject: [PATCH] agg::rgba4444_blender channel order fixes. --- 3party/agg/agg_pixfmt_rgb_packed.h | 29 +++++++++++++++++++++++--- yg/circle_info.cpp | 4 ++++ yg/circle_info.hpp | 2 ++ yg/pen_info.cpp | 5 ----- yg/skin_page.cpp | 33 +++++++++++++++--------------- yg/yg_tests/screengl_test.cpp | 2 +- 6 files changed, 49 insertions(+), 26 deletions(-) diff --git a/3party/agg/agg_pixfmt_rgb_packed.h b/3party/agg/agg_pixfmt_rgb_packed.h index 658c994c5b..ee93435a43 100644 --- a/3party/agg/agg_pixfmt_rgb_packed.h +++ b/3party/agg/agg_pixfmt_rgb_packed.h @@ -82,6 +82,7 @@ namespace agg unsigned alpha, unsigned) { +/* /// from the least bit to most significant (r, g, b, a) pixel_type rgb = *p; calc_type b = (rgb >> 4) & 0xF0; @@ -92,21 +93,43 @@ namespace agg (((((cb - b) * alpha + (b << 8)) >> 4) & 0x0F00) | ((((cg - g) * alpha + (g << 8)) >> 8) & 0x00F0) | (((cr - r) * alpha + (r << 8)) >> 12) | 0xF000); - } +*/ + /// from the least bit to most significant (a, b, g, r) + + pixel_type rgb = *p; + + calc_type r = (rgb >> 8) & 0xF0; + calc_type g = (rgb >> 4) & 0xF0; + calc_type b = (rgb ) & 0xF0; + + *p = (pixel_type) + (((((cr - r) * alpha + (r << 8)) ) & 0xF000) | + ((((cg - g) * alpha + (g << 8)) >> 4) & 0x0F00) | + ((((cb - b) * alpha + (b << 8)) >> 8) & 0x00F0) | 0x000F); + } static AGG_INLINE pixel_type make_pix(unsigned r, unsigned g, unsigned b) { +/* return (pixel_type)(((b & 0xF0) << 4) | ((g & 0xF0) ) | (r >> 4) | 0xF000); + */ + return (pixel_type)(((r & 0xF0) << 8) | + ((g & 0xF0) << 4) | + (b & 0xF0) | + 0x000F); } static AGG_INLINE color_type make_color(pixel_type p) { - return color_type((p << 4) & 0xF0, +/* return color_type((p << 4) & 0xF0, (p ) & 0xF0, - (p >> 4) & 0xF0); + (p >> 4) & 0xF0);*/ + return color_type((p >> 8) & 0xF0, + (p >> 4) & 0xF0, + (p ) & 0xF0); } }; diff --git a/yg/circle_info.cpp b/yg/circle_info.cpp index 0536325754..11f01cfc97 100644 --- a/yg/circle_info.cpp +++ b/yg/circle_info.cpp @@ -7,10 +7,12 @@ namespace yg CircleInfo::CircleInfo(unsigned radius, Color const & color, bool isOutlined, + unsigned outlineWidth, Color const & outlineColor) : m_radius(radius), m_color(color), m_isOutlined(isOutlined), + m_outlineWidth(outlineWidth), m_outlineColor(outlineColor) {} @@ -25,6 +27,8 @@ namespace yg return l.m_color < r.m_color; if (l.m_isOutlined != r.m_isOutlined) return l.m_isOutlined < r.m_isOutlined; + if (l.m_outlineWidth != r.m_outlineWidth) + return l.m_outlineWidth < r.m_outlineWidth; return l.m_outlineColor < r.m_outlineColor; } } diff --git a/yg/circle_info.hpp b/yg/circle_info.hpp index 7a53259d9f..d47b14db6b 100644 --- a/yg/circle_info.hpp +++ b/yg/circle_info.hpp @@ -9,6 +9,7 @@ namespace yg unsigned m_radius; Color m_color; bool m_isOutlined; + unsigned m_outlineWidth; Color m_outlineColor; CircleInfo(); @@ -16,6 +17,7 @@ namespace yg unsigned radius, Color const & color = Color(0, 0, 0, 255), bool isOutlined = false, + unsigned outlineWidth = 0, Color const & outlineColor = Color(255, 255, 255, 255)); }; diff --git a/yg/pen_info.cpp b/yg/pen_info.cpp index 9b394c8e65..40a2c1a876 100644 --- a/yg/pen_info.cpp +++ b/yg/pen_info.cpp @@ -15,12 +15,7 @@ namespace yg /// if pattern is solid if ((pattern == 0 ) || (patternSize == 0)) - { m_isSolid = true; -// m_pat.push_back(5); -// m_pat.push_back(50); -// m_pat.push_back(0); - } else { copy(pattern, pattern + patternSize, back_inserter(m_pat)); diff --git a/yg/skin_page.cpp b/yg/skin_page.cpp index 24097aba9f..bb466acb05 100644 --- a/yg/skin_page.cpp +++ b/yg/skin_page.cpp @@ -292,7 +292,7 @@ namespace yg if (foundHandle != m_packer.invalidHandle()) return foundHandle; - unsigned r = circleInfo.m_isOutlined ? circleInfo.m_radius + 1 : circleInfo.m_radius; + unsigned r = circleInfo.m_isOutlined ? circleInfo.m_radius + circleInfo.m_outlineWidth : circleInfo.m_radius; m2::Packer::handle_t handle = m_packer.pack( r * 2 + 4, @@ -309,7 +309,7 @@ namespace yg bool SkinPage::hasRoom(CircleInfo const & circleInfo) const { - unsigned r = circleInfo.m_isOutlined ? circleInfo.m_radius + 1 : circleInfo.m_radius; + unsigned r = circleInfo.m_isOutlined ? circleInfo.m_radius + circleInfo.m_outlineWidth : circleInfo.m_radius; return m_packer.hasRoom(r * 2 + 4, r * 2 + 4); } @@ -396,10 +396,7 @@ namespace yg yg::Color penInfoColor = penInfo.m_color; - penInfoColor.r /= TDynamicTexture::channelScaleFactor; - penInfoColor.g /= TDynamicTexture::channelScaleFactor; - penInfoColor.b /= TDynamicTexture::channelScaleFactor; - penInfoColor.a /= TDynamicTexture::channelScaleFactor; + penInfoColor /= TDynamicTexture::channelScaleFactor; TDynamicTexture::pixel_t penColorTranslucent; @@ -455,20 +452,22 @@ namespace yg { unsigned char alpha = gil::get_color(v(x, y), gil::alpha_t()); float fAlpha = alpha / (float)TDynamicTexture::maxChannelVal; -// if (alpha != 0) -// { - gil::get_color(v(x, y), gil::red_t()) *= fAlpha; - gil::get_color(v(x, y), gil::green_t()) *= fAlpha; - gil::get_color(v(x, y), gil::blue_t()) *= fAlpha; + if (alpha != 0) + { +// gil::get_color(v(x, y), gil::red_t()) *= fAlpha; +// gil::get_color(v(x, y), gil::green_t()) *= fAlpha; +// gil::get_color(v(x, y), gil::blue_t()) *= fAlpha; // gil::get_color(v(x, y), gil::alpha_t()) = TDynamicTexture::maxChannelVal; -// } - }*/ + v(x, y) = penColor; + } + } +*/ } else { gil::fill_pixels( - gil::subimage_view(v, 2, 2, rect.SizeX() - 4, rect.SizeY() - 4), + gil::subimage_view(v, 1, 1, rect.SizeX() - 2, rect.SizeY() - 2), penColor ); } @@ -600,7 +599,7 @@ namespace yg m2::PointD center(circleInfo.m_radius + 2, circleInfo.m_radius + 2); if (circleInfo.m_isOutlined) - center += m2::PointD(1, 1); + center += m2::PointD(circleInfo.m_outlineWidth, circleInfo.m_outlineWidth); agg::scanline_u8 s; agg::rasterizer_scanline_aa<> rasterizer; @@ -609,8 +608,8 @@ namespace yg ell.init(center.x, center.y, - circleInfo.m_isOutlined ? circleInfo.m_radius + 1 : circleInfo.m_radius, - circleInfo.m_isOutlined ? circleInfo.m_radius + 1 : circleInfo.m_radius, + circleInfo.m_isOutlined ? circleInfo.m_radius + circleInfo.m_outlineWidth : circleInfo.m_radius, + circleInfo.m_isOutlined ? circleInfo.m_radius + circleInfo.m_outlineWidth : circleInfo.m_radius, 100); rasterizer.add_path(ell); diff --git a/yg/yg_tests/screengl_test.cpp b/yg/yg_tests/screengl_test.cpp index 7d56c6c39a..eebe919e87 100644 --- a/yg/yg_tests/screengl_test.cpp +++ b/yg/yg_tests/screengl_test.cpp @@ -931,7 +931,7 @@ namespace void DoDraw(shared_ptr const & p) { p->drawCircle(m2::PointD(200, 200), p->skin()->mapCircleInfo(yg::CircleInfo(10, yg::Color(255, 0, 0, 255))), 100); - p->drawCircle(m2::PointD(100, 200), p->skin()->mapCircleInfo(yg::CircleInfo(10, yg::Color(255, 0, 0, 255), true, yg::Color(255, 255, 255, 255))), 100); + p->drawCircle(m2::PointD(100, 200), p->skin()->mapCircleInfo(yg::CircleInfo(10, yg::Color(255, 0, 0, 255), true, 4, yg::Color(255, 255, 255, 255))), 100); } };