Defined a new color class

The new color class is temporarily named expr_color for experiment.
This commit is contained in:
cnjinhao
2014-12-14 10:15:19 +08:00
parent d0a317bd45
commit 74c09eb9b3
37 changed files with 1495 additions and 674 deletions

View File

@@ -103,22 +103,85 @@ namespace nana
const color_t null_color = 0xFFFFFFFF;
struct pixel_rgb_t
union pixel_argb_t
{
union
struct element_tag
{
struct element_tag
{
unsigned int blue:8;
unsigned int green:8;
unsigned int red:8;
unsigned int alpha_channel:8;
}element;
color_t color;
}u;
unsigned int blue:8;
unsigned int green:8;
unsigned int red:8;
unsigned int alpha_channel:8;
}element;
color_t value;
};
union pixel_rgba_t
{
struct element_tag
{
unsigned int alpha_channel : 8;
unsigned int blue : 8;
unsigned int green : 8;
unsigned int red : 8;
}element;
color_t value;
};
using pixel_color_t = pixel_argb_t;
//http://www.w3.org/TR/2011/REC-css3-color-20110607/
//4.3. Extended color keywords
enum class colors
{
black = 0x0,
blue = 0x0000FF,
gray = 0x808080,
green = 0x00FF00,
red = 0xFF0000,
white = 0xFFFFFF,
button_face_shadow_start = 0xF5F4F2,
button_face_shadow_end = 0xD5D2CA,
button_face = 0xD4D0C8,
dark_border = 0x404040,
gray_border = 0x808080,
highlight = 0x1CC4F7
};
class expr_color
{
public:
expr_color() = default;
expr_color(colors);
expr_color(colors, double alpha);
expr_color(unsigned red, unsigned green, unsigned blue);
expr_color(unsigned red, unsigned green, unsigned blue, double alpha);
void blend(const expr_color& bgcolor, bool ignore_bgcolor_alpha);
///< Blends two colors with the specified alpha, and the alpha values that come with these two colors are both ignored.
void blend(const expr_color& bgcolor, double alpha);
bool invisible() const;
pixel_argb_t argb() const;
pixel_rgba_t rgba() const;
const double& r() const;
const double& g() const;
const double& b() const;
const double& a() const;
bool operator==(const expr_color& other) const;
bool operator!=(const expr_color& other) const;
private:
double r_;
double g_;
double b_;
double a_{ 0.0 };
};
struct rectangle;
struct point

View File

@@ -84,11 +84,6 @@ namespace detail
{
typedef std::shared_ptr<font_tag> font_ptr_t;
drawable_impl_type();
~drawable_impl_type();
void fgcolor(unsigned color);
Pixmap pixmap;
GC context;
font_ptr_t font;
@@ -104,11 +99,23 @@ namespace detail
#if defined(NANA_UNICODE)
XftDraw * xftdraw;
XftColor xft_fgcolor;
XftColor xft_bgcolor;
//XftColor xft_bgcolor; //deprecated
const std::string charset(const nana::string& str, const std::string& strcode);
#endif
drawable_impl_type();
~drawable_impl_type();
void fgcolor(nana::color_t); //deprecated
void set_color(nana::color_t);
void set_text_color(nana::color_t);
void update_color();
void update_text_color();
private:
unsigned fgcolor_;
unsigned current_color_{ 0xFFFFFF };
unsigned color_{ 0xFFFFFFFF };
unsigned text_color_{ 0xFFFFFFFF };
#if defined(NANA_UNICODE)
struct conv_tag
{

View File

@@ -91,8 +91,8 @@ namespace detail
HDC context;
HBITMAP pixmap;
pixel_rgb_t* pixbuf_ptr;
std::size_t bytes_per_line;
pixel_argb_t* pixbuf_ptr{nullptr};
std::size_t bytes_per_line{0};
font_ptr_t font;
struct pen_spec
@@ -136,9 +136,15 @@ namespace detail
drawable_impl_type();
~drawable_impl_type();
void fgcolor(nana::color_t);
void fgcolor(nana::color_t); //deprecated
void set_color(nana::color_t);
void set_text_color(nana::color_t);
void update_pen();
void update_brush();
private:
unsigned fgcolor_;
unsigned color_{ 0xffffffff };
unsigned text_color_{0xffffffff};
};
class platform_spec

View File

@@ -98,7 +98,7 @@ namespace nana
};
};
namespace color
namespace color //deprecated
{
enum
{

View File

@@ -177,10 +177,14 @@ namespace detail
struct
{
color_t foreground;
color_t background;
color_t active;
}color;
color_t foreground; //deprecated
color_t background; //deprecated
color_t active; //deprecated
expr_color fgcolor;
expr_color bgcolor;
expr_color activated;
}colors;
struct
{

View File

@@ -110,7 +110,7 @@ namespace nana{
auto graph = wd->root_graph;
nana::paint::pixel_buffer pixbuf(graph->handle(), r);
pixel_rgb_t px0, px1, px2, px3;
pixel_argb_t px0, px1, px2, px3;
px0 = pixbuf.pixel(0, 0);
px1 = pixbuf.pixel(r.width - 1, 0);
@@ -120,12 +120,12 @@ namespace nana{
good_r.x = good_r.y = 1;
good_r.width = r.width - 2;
good_r.height = r.height - 2;
pixbuf.rectangle(good_r, wd->color.active, 0.95, false);
pixbuf.rectangle(good_r, wd->colors.active, 0.95, false);
good_r.x = good_r.y = 0;
good_r.width = r.width;
good_r.height = r.height;
pixbuf.rectangle(good_r, wd->color.active, 0.4, false);
pixbuf.rectangle(good_r, wd->colors.active, 0.4, false);
pixbuf.pixel(0, 0, px0);
pixbuf.pixel(r.width - 1, 0, px1);

View File

@@ -35,7 +35,7 @@ namespace nana
virtual ~element_interface()
{}
virtual bool draw(graph_reference, nana::color_t bgcolor, nana::color_t fgcolor, const nana::rectangle&, element_state) = 0;
virtual bool draw(graph_reference, const nana::expr_color& bgcolor, const nana::expr_color& fgcolor, const nana::rectangle&, element_state) = 0;
};
class crook_interface
@@ -53,7 +53,7 @@ namespace nana
virtual ~crook_interface()
{}
virtual bool draw(graph_reference, nana::color_t bgcolor, nana::color_t fgcolor, const nana::rectangle&, element_state, const data&) = 0;
virtual bool draw(graph_reference, const nana::expr_color& bgcolor, const nana::expr_color& fgcolor, const nana::rectangle&, element_state, const data&) = 0;
};
class provider
@@ -122,7 +122,7 @@ namespace nana
void switch_to(const char*);
public:
//Implement element_interface
bool draw(graph_reference, nana::color_t bgcolor, nana::color_t fgcolor, const nana::rectangle& r, element_state) override;
bool draw(graph_reference, const nana::expr_color& bgcolor, const nana::expr_color& fgcolor, const nana::rectangle& r, element_state) override;
private:
element::crook_interface::data data_;
element::crook_interface* const * keeper_;
@@ -144,7 +144,7 @@ namespace nana
void set(const cloneable_element&);
void set(const char*);
bool draw(graph_reference, nana::color_t bgcolor, nana::color_t fgcolor, const nana::rectangle&, element_state);
bool draw(graph_reference, const nana::expr_color& bgcolor, const nana::expr_color& fgcolor, const nana::rectangle&, element_state);
private:
cloneable_element holder_;
element_interface * place_ptr_;
@@ -174,7 +174,7 @@ namespace nana
void stretch_parts(unsigned left, unsigned top, unsigned right, unsigned bottom);
//Implement the methods of element_interface.
virtual bool draw(graph_reference, nana::color_t bgcolor, nana::color_t fgcolor, const nana::rectangle&, element_state);
virtual bool draw(graph_reference, const nana::expr_color& bgcolor, const nana::expr_color& fgcolor, const nana::rectangle&, element_state);
private:
struct draw_method;
struct draw_image;

View File

@@ -201,12 +201,20 @@ namespace API
void capture_ignore_children(bool ignore); ///< Enables or disables the captured window whether redirects the mouse input to its children if the mouse is over its children.
void modal_window(window); ///< Blocks the routine til the specified window is closed.
void wait_for(window);
color_t foreground(window);
color_t foreground(window, color_t);
color_t background(window);
color_t background(window, color_t);
color_t active(window);
color_t active(window, color_t);
color_t foreground(window); //deprecated
color_t foreground(window, color_t); //deprecated
color_t background(window); //deprecated
color_t background(window, color_t); //deprecated
color_t active(window); //deprecated
color_t active(window, color_t); //deprecated
expr_color fgcolor(window);
expr_color fgcolor(window, const expr_color&);
expr_color bgcolor(window);
expr_color bgcolor(window, const expr_color&);
expr_color activated_color(window);
expr_color activated_color(window, const expr_color&);
void create_caret(window, unsigned width, unsigned height);
void destroy_caret(window);

View File

@@ -53,10 +53,10 @@ namespace nana{
void _m_draw_background(graph_reference);
void _m_draw_border(graph_reference);
private:
widget* widget_;
paint::graphics* graph_;
widget* wdg_{nullptr};
paint::graphics* graph_{nullptr};
element::cite_bground cite_;
element::cite_bground cite_{"button"};
struct attr_tag
{
@@ -68,8 +68,10 @@ namespace nana{
bool enable_pushed;
bool focus_color;
paint::image * icon;
color_t bgcolor;
color_t fgcolor;
//color_t bgcolor; //deprecated
//color_t fgcolor;
::nana::expr_color bgcolor;
::nana::expr_color fgcolor;
}attr_;
};
}//end namespace button

View File

@@ -33,10 +33,14 @@ namespace nana
{
struct format
{
::nana::color_t bgcolor;
::nana::color_t fgcolor;
//::nana::color_t bgcolor;
//::nana::color_t fgcolor;
format(color_t bgcolor = 0xFF000000, color_t fgcolor = 0xFF000000);
::nana::expr_color bgcolor;
::nana::expr_color fgcolor;
format() = default;
format(const ::nana::expr_color& bgcolor, const ::nana::expr_color& fgcolor);
};
using format_ptr = std::unique_ptr < format > ;
@@ -49,7 +53,7 @@ namespace nana
cell(cell&&);
cell(nana::string);
cell(nana::string, const format&);
cell(nana::string, color_t bgcolor, color_t fgcolor);
cell(nana::string, const ::nana::expr_color& bgcolor, const ::nana::expr_color& fgcolor);
cell& operator=(const cell&);
cell& operator=(cell&&);
@@ -212,11 +216,11 @@ namespace nana
item_proxy & select(bool);
bool selected() const;
item_proxy & bgcolor(nana::color_t);
nana::color_t bgcolor() const;
item_proxy & bgcolor(const nana::expr_color&);
nana::expr_color bgcolor() const;
item_proxy& fgcolor(nana::color_t);
nana::color_t fgcolor() const;
item_proxy& fgcolor(const nana::expr_color&);
nana::expr_color fgcolor() const;
index_pair pos() const;

View File

@@ -74,11 +74,13 @@ namespace nana
virtual ~renderer_interface()
{}
virtual void bground(graph_reference, nana::color_t bgcolor, nana::color_t fgcolor, const compset_interface *) const = 0;
virtual void expander(graph_reference, nana::color_t bgcolor, nana::color_t fgcolor, const compset_interface *) const = 0;
virtual void crook(graph_reference, nana::color_t bgcolor, nana::color_t fgcolor, const compset_interface *) const = 0;
virtual void icon(graph_reference, nana::color_t bgcolor, nana::color_t fgcolor, const compset_interface *) const = 0;
virtual void text(graph_reference, nana::color_t bgcolor, nana::color_t fgcolor, const compset_interface *) const = 0;
virtual void set_color(const nana::expr_color& bgcolor, const nana::expr_color& fgcolor) = 0;
virtual void bground(graph_reference, const compset_interface *) const = 0;
virtual void expander(graph_reference, const compset_interface *) const = 0;
virtual void crook(graph_reference, const compset_interface *) const = 0;
virtual void icon(graph_reference, const compset_interface *) const = 0;
virtual void text(graph_reference, const compset_interface *) const = 0;
};
class item_proxy;

View File

@@ -73,11 +73,16 @@ namespace nana
void move(int x, int y);
void move(const rectangle&);
void foreground(nana::color_t);
void foreground(nana::color_t); //deprecated
nana::color_t foreground() const;
void background(nana::color_t);
nana::color_t background() const;
void fgcolor(const nana::expr_color&); //deprecated
nana::expr_color fgcolor() const;
void bgcolor(const nana::expr_color&);
nana::expr_color bgcolor() const;
general_events& events() const;
void umake_event(event_handle eh) const; ///< Deletes an event callback by a handle.
@@ -106,10 +111,10 @@ namespace nana
virtual void _m_typeface(const nana::paint::font& font);
virtual nana::paint::font _m_typeface() const;
virtual void _m_foreground(nana::color_t);
virtual nana::color_t _m_foreground() const;
virtual void _m_background(nana::color_t);
virtual nana::color_t _m_background() const;
virtual void _m_fgcolor(const nana::expr_color&);
virtual nana::expr_color _m_fgcolor() const;
virtual void _m_bgcolor(const nana::expr_color&);
virtual nana::expr_color _m_bgcolor() const;
};
/// Base class of all the classes defined as a widget window. Defaultly a widget_tag

View File

@@ -102,7 +102,7 @@ namespace nana{ namespace paint
pixbuf_.open(info->bmiHeader.biWidth, height_pixels);
pixel_rgb_t * d = pixbuf_.raw_ptr(0);
auto d = pixbuf_.raw_ptr(0);
if(16 <= info->bmiHeader.biBitCount)
{
@@ -110,23 +110,23 @@ namespace nana{ namespace paint
}
else if(8 == info->bmiHeader.biBitCount)
{
const pixel_rgb_t * const lend = d + info->bmiHeader.biWidth * height_pixels;
const auto lend = d + info->bmiHeader.biWidth * height_pixels;
if(info->bmiHeader.biHeight < 0)
{
const unsigned char* s = bits;
auto s = bits;
while(d < lend)
{
pixel_rgb_t * d_p = d;
pixel_rgb_t * const dpend = d_p + info->bmiHeader.biWidth;
const unsigned char * s_p = s;
auto d_p = d;
auto dpend = d_p + info->bmiHeader.biWidth;
auto s_p = s;
while(d_p != dpend)
{
rgb_quad & rgb = info->bmiColors[*s_p++];
d_p->u.element.red = rgb.rgbRed;
d_p->u.element.green = rgb.rgbGreen;
d_p->u.element.blue = rgb.rgbBlue;
d_p->u.element.alpha_channel = rgb.rgbReserved;
d_p->element.red = rgb.rgbRed;
d_p->element.green = rgb.rgbGreen;
d_p->element.blue = rgb.rgbBlue;
d_p->element.alpha_channel = rgb.rgbReserved;
++d_p;
}
d = dpend;
@@ -135,19 +135,19 @@ namespace nana{ namespace paint
}
else
{
const unsigned char* s = bits + bytes_per_line * (height_pixels - 1);
const auto* s = bits + bytes_per_line * (height_pixels - 1);
while(d < lend)
{
pixel_rgb_t * d_p = d;
pixel_rgb_t * const dpend = d_p + info->bmiHeader.biWidth;
const unsigned char * s_p = s;
auto d_p = d;
auto* const dpend = d_p + info->bmiHeader.biWidth;
const auto * s_p = s;
while(d_p != dpend)
{
rgb_quad & rgb = info->bmiColors[*s_p++];
d_p->u.element.red = rgb.rgbRed;
d_p->u.element.green = rgb.rgbGreen;
d_p->u.element.blue = rgb.rgbBlue;
d_p->u.element.alpha_channel = rgb.rgbReserved;
d_p->element.red = rgb.rgbRed;
d_p->element.green = rgb.rgbGreen;
d_p->element.blue = rgb.rgbBlue;
d_p->element.alpha_channel = rgb.rgbReserved;
++d_p;
}
d = dpend;
@@ -157,23 +157,23 @@ namespace nana{ namespace paint
}
else if(4 == info->bmiHeader.biBitCount)
{
const pixel_rgb_t * const lend = d + info->bmiHeader.biWidth * height_pixels;
const auto * const lend = d + info->bmiHeader.biWidth * height_pixels;
if(info->bmiHeader.biHeight < 0)
{
const unsigned char* s = bits;
while(d < lend)
{
pixel_rgb_t * d_p = d;
pixel_rgb_t * const dpend = d_p + info->bmiHeader.biWidth;
auto d_p = d;
auto * const dpend = d_p + info->bmiHeader.biWidth;
unsigned index = 0;
while(d_p != dpend)
{
rgb_quad & rgb = info->bmiColors[(index & 1) ? (s[index >> 1] & 0xF) : (s[index >> 1] & 0xF0) >> 4];
d_p->u.element.red = rgb.rgbRed;
d_p->u.element.green = rgb.rgbGreen;
d_p->u.element.blue = rgb.rgbBlue;
d_p->u.element.alpha_channel = rgb.rgbReserved;
d_p->element.red = rgb.rgbRed;
d_p->element.green = rgb.rgbGreen;
d_p->element.blue = rgb.rgbBlue;
d_p->element.alpha_channel = rgb.rgbReserved;
++d_p;
++index;
}
@@ -183,21 +183,21 @@ namespace nana{ namespace paint
}
else
{
const unsigned char* s = bits + bytes_per_line * (height_pixels - 1);
const auto* s = bits + bytes_per_line * (height_pixels - 1);
while(d < lend)
{
pixel_rgb_t * d_p = d;
pixel_rgb_t * const dpend = d_p + info->bmiHeader.biWidth;
auto d_p = d;
auto * const dpend = d_p + info->bmiHeader.biWidth;
unsigned index = 0;
while(d_p != dpend)
{
rgb_quad & rgb = info->bmiColors[(index & 1) ? (s[index >> 1] & 0xF) : (s[index >> 1] & 0xF0) >> 4];
d_p->u.element.red = rgb.rgbRed;
d_p->u.element.green = rgb.rgbGreen;
d_p->u.element.blue = rgb.rgbBlue;
d_p->u.element.alpha_channel = rgb.rgbReserved;
d_p->element.red = rgb.rgbRed;
d_p->element.green = rgb.rgbGreen;
d_p->element.blue = rgb.rgbBlue;
d_p->element.alpha_channel = rgb.rgbReserved;
++d_p;
++index;
}
@@ -208,24 +208,24 @@ namespace nana{ namespace paint
}
else if(2 == info->bmiHeader.biBitCount)
{
const pixel_rgb_t * const lend = d + info->bmiHeader.biWidth * height_pixels;
const auto * const lend = d + info->bmiHeader.biWidth * height_pixels;
if(info->bmiHeader.biHeight < 0)
{
const unsigned char* s = bits;
while(d < lend)
{
pixel_rgb_t * d_p = d;
pixel_rgb_t * const dpend = d_p + info->bmiHeader.biWidth;
auto d_p = d;
auto * const dpend = d_p + info->bmiHeader.biWidth;
unsigned index = 0;
while(d_p != dpend)
{
unsigned shift = (3 - (index & 0x3)) << 1; // (index % 4) * 2
rgb_quad& rgb = info->bmiColors[(s[index >> 2] & (0x3 << shift))>>shift];
d_p->u.element.red = rgb.rgbRed;
d_p->u.element.green = rgb.rgbGreen;
d_p->u.element.blue = rgb.rgbBlue;
d_p->u.element.alpha_channel = rgb.rgbReserved;
d_p->element.red = rgb.rgbRed;
d_p->element.green = rgb.rgbGreen;
d_p->element.blue = rgb.rgbBlue;
d_p->element.alpha_channel = rgb.rgbReserved;
++d_p;
++index;
}
@@ -235,11 +235,11 @@ namespace nana{ namespace paint
}
else
{
const unsigned char* s = bits + bytes_per_line * (height_pixels - 1);
const auto* s = bits + bytes_per_line * (height_pixels - 1);
while(d < lend)
{
pixel_rgb_t * d_p = d;
pixel_rgb_t * const dpend = d_p + info->bmiHeader.biWidth;
auto d_p = d;
auto * const dpend = d_p + info->bmiHeader.biWidth;
unsigned index = 0;
while(d_p != dpend)
@@ -247,10 +247,10 @@ namespace nana{ namespace paint
unsigned shift = (3 - (index & 0x3)) << 1; // (index % 4) * 2
rgb_quad& rgb = info->bmiColors[(s[index >> 2] & (0x3 << shift))>>shift];
d_p->u.element.red = rgb.rgbRed;
d_p->u.element.green = rgb.rgbGreen;
d_p->u.element.blue = rgb.rgbBlue;
d_p->u.element.alpha_channel = rgb.rgbReserved;
d_p->element.red = rgb.rgbRed;
d_p->element.green = rgb.rgbGreen;
d_p->element.blue = rgb.rgbBlue;
d_p->element.alpha_channel = rgb.rgbReserved;
++d_p;
++index;
}
@@ -261,24 +261,24 @@ namespace nana{ namespace paint
}
else if(1 == info->bmiHeader.biBitCount)
{
const pixel_rgb_t * const lend = d + info->bmiHeader.biWidth * height_pixels;
const auto * const lend = d + info->bmiHeader.biWidth * height_pixels;
if(info->bmiHeader.biHeight < 0)
{
const unsigned char* s = bits;
const auto* s = bits;
while(d < lend)
{
pixel_rgb_t * d_p = d;
pixel_rgb_t * const dpend = d_p + info->bmiHeader.biWidth;
auto d_p = d;
auto * const dpend = d_p + info->bmiHeader.biWidth;
unsigned index = 0;
while(d_p != dpend)
{
unsigned bi = (7 - (index & 7)); //(index % 8)
rgb_quad & rgb = info->bmiColors[(s[index >> 3] & (1 << bi)) >> bi];
d_p->u.element.red = rgb.rgbRed;
d_p->u.element.green = rgb.rgbGreen;
d_p->u.element.blue = rgb.rgbBlue;
d_p->u.element.alpha_channel = rgb.rgbReserved;
d_p->element.red = rgb.rgbRed;
d_p->element.green = rgb.rgbGreen;
d_p->element.blue = rgb.rgbBlue;
d_p->element.alpha_channel = rgb.rgbReserved;
++d_p;
++index;
}
@@ -288,11 +288,11 @@ namespace nana{ namespace paint
}
else
{
const unsigned char* s = bits + bytes_per_line * (height_pixels - 1);
const auto* s = bits + bytes_per_line * (height_pixels - 1);
while(d < lend)
{
pixel_rgb_t * d_p = d;
pixel_rgb_t * const dpend = d_p + info->bmiHeader.biWidth;
auto d_p = d;
auto * const dpend = d_p + info->bmiHeader.biWidth;
unsigned index = 0;
while(d_p != dpend)
@@ -300,10 +300,10 @@ namespace nana{ namespace paint
unsigned bi = (7 - (index & 7));
rgb_quad & rgb = info->bmiColors[(s[index >> 3] & (1 << bi)) >> bi];
d_p->u.element.red = rgb.rgbRed;
d_p->u.element.green = rgb.rgbGreen;
d_p->u.element.blue = rgb.rgbBlue;
d_p->u.element.alpha_channel = rgb.rgbReserved;
d_p->element.red = rgb.rgbRed;
d_p->element.green = rgb.rgbGreen;
d_p->element.blue = rgb.rgbBlue;
d_p->element.alpha_channel = rgb.rgbReserved;
++d_p;
++index;
}

View File

@@ -72,7 +72,7 @@ namespace nana
const bool is_alpha_enabled = ((PNG_COLOR_MASK_ALPHA & color_type) != 0);
pixbuf_.alpha_channel(is_alpha_enabled);
if(is_alpha_enabled && (png_rowbytes == png_width * sizeof(pixel_rgb_t)))
if(is_alpha_enabled && (png_rowbytes == png_width * sizeof(pixel_argb_t)))
{
for(int i = 0; i < png_height; ++i)
row_ptrs[i] = reinterpret_cast<png_bytep>(pixbuf_.raw_ptr(i));
@@ -85,9 +85,9 @@ namespace nana
auto p = pixbuf_.raw_ptr(i);
for (int u = 0; u < png_width; ++u)
{
auto t = p[u].u.element.red;
p[u].u.element.red = p[u].u.element.blue;
p[u].u.element.blue = t;
auto t = p[u].element.red;
p[u].element.red = p[u].element.blue;
p[u].element.blue = t;
}
}
}
@@ -103,32 +103,32 @@ namespace nana
std::size_t png_pixel_bytes = png_rowbytes / png_width;
pixel_rgb_t * rgb_row_ptr = pixbuf_.raw_ptr(0);
pixel_argb_t * rgb_row_ptr = pixbuf_.raw_ptr(0);
for(int y = 0; y < png_height; ++y)
{
png_bytep png_ptr = row_ptrs[y];
pixel_rgb_t * rgb_end = rgb_row_ptr + png_width;
pixel_argb_t * rgb_end = rgb_row_ptr + png_width;
if(is_alpha_enabled)
{
for(pixel_rgb_t * i = rgb_row_ptr; i < rgb_end; ++i)
for(pixel_argb_t * i = rgb_row_ptr; i < rgb_end; ++i)
{
i->u.element.red = png_ptr[0];
i->u.element.green = png_ptr[1];
i->u.element.blue = png_ptr[2];
i->u.element.alpha_channel = png_ptr[3];
i->element.red = png_ptr[0];
i->element.green = png_ptr[1];
i->element.blue = png_ptr[2];
i->element.alpha_channel = png_ptr[3];
png_ptr += png_pixel_bytes;
}
}
else
{
for(pixel_rgb_t * i = rgb_row_ptr; i < rgb_end; ++i)
for(pixel_argb_t * i = rgb_row_ptr; i < rgb_end; ++i)
{
i->u.element.red = png_ptr[0];
i->u.element.green = png_ptr[1];
i->u.element.blue = png_ptr[2];
i->u.element.alpha_channel = 255;
i->element.red = png_ptr[0];
i->element.green = png_ptr[1];
i->element.blue = png_ptr[2];
i->element.alpha_channel = 255;
png_ptr += png_pixel_bytes;
}
}

View File

@@ -38,32 +38,32 @@ namespace detail
double rate_x = double(r_src.width) / r_dst.width;
double rate_y = double(r_src.height) / r_dst.height;
pixel_rgb_t * s_raw_pixbuf = s_pixbuf.raw_ptr(0);
pixel_argb_t * s_raw_pixbuf = s_pixbuf.raw_ptr(0);
if(s_pixbuf.alpha_channel())
{
for(std::size_t row = 0; row < r_dst.height; ++row)
{
const pixel_rgb_t * s_line = pixel_at(s_raw_pixbuf, (static_cast<int>(row * rate_y) + r_src.y) * bytes_per_line);
pixel_rgb_t * i = pixbuf.raw_ptr(r_dst.y + row);
const pixel_argb_t * s_line = pixel_at(s_raw_pixbuf, (static_cast<int>(row * rate_y) + r_src.y) * bytes_per_line);
pixel_argb_t * i = pixbuf.raw_ptr(r_dst.y + row);
for(std::size_t x = 0; x < r_dst.width; ++x, ++i)
{
const pixel_rgb_t * s = s_line + static_cast<int>(x * rate_x) + r_src.x;
if(0 == s->u.element.alpha_channel)
const pixel_argb_t * s = s_line + static_cast<int>(x * rate_x) + r_src.x;
if(0 == s->element.alpha_channel)
continue;
if(s->u.element.alpha_channel != 255)
if(s->element.alpha_channel != 255)
{
i->u.element.red = unsigned(i->u.element.red * (255 - s->u.element.alpha_channel) + s->u.element.red * s->u.element.alpha_channel) / 255;
i->u.element.green = unsigned(i->u.element.green * (255 - s->u.element.alpha_channel) + s->u.element.green * s->u.element.alpha_channel) / 255;
i->u.element.blue = unsigned(i->u.element.blue * (255 - s->u.element.alpha_channel) + s->u.element.blue * s->u.element.alpha_channel) / 255;
i->element.red = unsigned(i->element.red * (255 - s->element.alpha_channel) + s->element.red * s->element.alpha_channel) / 255;
i->element.green = unsigned(i->element.green * (255 - s->element.alpha_channel) + s->element.green * s->element.alpha_channel) / 255;
i->element.blue = unsigned(i->element.blue * (255 - s->element.alpha_channel) + s->element.blue * s->element.alpha_channel) / 255;
}
else
{
unsigned alpha_chn = i->u.element.alpha_channel;
unsigned alpha_chn = i->element.alpha_channel;
*i = *s;
i->u.element.alpha_channel = alpha_chn;
i->element.alpha_channel = alpha_chn;
}
}
}
@@ -72,8 +72,8 @@ namespace detail
{
for(std::size_t row = 0; row < r_dst.height; ++row)
{
const pixel_rgb_t * s_line = pixel_at(s_raw_pixbuf, (static_cast<int>(row * rate_y) + r_src.y) * bytes_per_line);
pixel_rgb_t * i = pixbuf.raw_ptr(r_dst.y + row);
const pixel_argb_t * s_line = pixel_at(s_raw_pixbuf, (static_cast<int>(row * rate_y) + r_src.y) * bytes_per_line);
pixel_argb_t * i = pixbuf.raw_ptr(r_dst.y + row);
for(std::size_t x = 0; x < r_dst.width; ++x, ++i)
*i = s_line[static_cast<int>(x * rate_x) + r_src.x];
@@ -105,7 +105,7 @@ namespace detail
const int right_bound = static_cast<int>(r_src.width) - 1 + r_src.x;
const nana::pixel_rgb_t * s_raw_pixel_buffer = s_pixbuf.raw_ptr(0);
const nana::pixel_argb_t * s_raw_pixel_buffer = s_pixbuf.raw_ptr(0);
const int bottom = r_src.y + static_cast<int>(r_src.height - 1);
@@ -151,15 +151,15 @@ namespace detail
std::size_t iv = static_cast<size_t>(v * coef);
const std::size_t iv_minus_coef = coef - iv;
const nana::pixel_rgb_t * s_line = pixel_at(s_raw_pixel_buffer, sy * s_bytes_per_line);
const nana::pixel_rgb_t * next_s_line = pixel_at(s_line, (sy < bottom ? s_bytes_per_line : 0));
const nana::pixel_argb_t * s_line = pixel_at(s_raw_pixel_buffer, sy * s_bytes_per_line);
const nana::pixel_argb_t * next_s_line = pixel_at(s_line, (sy < bottom ? s_bytes_per_line : 0));
nana::pixel_rgb_t col0;
nana::pixel_rgb_t col1;
nana::pixel_rgb_t col2;
nana::pixel_rgb_t col3;
nana::pixel_argb_t col0;
nana::pixel_argb_t col1;
nana::pixel_argb_t col2;
nana::pixel_argb_t col3;
pixel_rgb_t * i = pixbuf.raw_ptr(row + r_dst.y) + r_dst.x;
pixel_argb_t * i = pixbuf.raw_ptr(row + r_dst.y) + r_dst.x;
if(is_alpha_channel)
{
@@ -186,24 +186,24 @@ namespace detail
std::size_t coef2 = el.iu * iv_minus_coef;
std::size_t coef3 = el.iu * iv;
unsigned alpha_chn = static_cast<unsigned>((coef0 * col0.u.element.alpha_channel + coef1 * col1.u.element.alpha_channel + (coef2 * col2.u.element.alpha_channel + coef3 * col3.u.element.alpha_channel)) >> double_shift_size);
unsigned s_red = static_cast<unsigned>((coef0 * col0.u.element.red + coef1 * col1.u.element.red + (coef2 * col2.u.element.red + coef3 * col3.u.element.red)) >> double_shift_size);
unsigned s_green = static_cast<unsigned>((coef0 * col0.u.element.green + coef1 * col1.u.element.green + (coef2 * col2.u.element.green + coef3 * col3.u.element.green)) >> double_shift_size);
unsigned s_blue = static_cast<unsigned>((coef0 * col0.u.element.blue + coef1 * col1.u.element.blue + (coef2 * col2.u.element.blue + coef3 * col3.u.element.blue)) >> double_shift_size);
unsigned alpha_chn = static_cast<unsigned>((coef0 * col0.element.alpha_channel + coef1 * col1.element.alpha_channel + (coef2 * col2.element.alpha_channel + coef3 * col3.element.alpha_channel)) >> double_shift_size);
unsigned s_red = static_cast<unsigned>((coef0 * col0.element.red + coef1 * col1.element.red + (coef2 * col2.element.red + coef3 * col3.element.red)) >> double_shift_size);
unsigned s_green = static_cast<unsigned>((coef0 * col0.element.green + coef1 * col1.element.green + (coef2 * col2.element.green + coef3 * col3.element.green)) >> double_shift_size);
unsigned s_blue = static_cast<unsigned>((coef0 * col0.element.blue + coef1 * col1.element.blue + (coef2 * col2.element.blue + coef3 * col3.element.blue)) >> double_shift_size);
if(alpha_chn)
{
if(alpha_chn != 255)
{
i->u.element.red = unsigned(i->u.element.red * (255 - alpha_chn) + s_red * alpha_chn) / 255;
i->u.element.green = unsigned(i->u.element.green * (255 - alpha_chn) + s_green * alpha_chn) / 255;
i->u.element.blue = unsigned(i->u.element.blue * (255 - alpha_chn) + s_blue * alpha_chn) / 255;
i->element.red = unsigned(i->element.red * (255 - alpha_chn) + s_red * alpha_chn) / 255;
i->element.green = unsigned(i->element.green * (255 - alpha_chn) + s_green * alpha_chn) / 255;
i->element.blue = unsigned(i->element.blue * (255 - alpha_chn) + s_blue * alpha_chn) / 255;
}
else
{
i->u.element.red = s_red;
i->u.element.green = s_green;
i->u.element.blue = s_blue;
i->element.red = s_red;
i->element.green = s_green;
i->element.blue = s_blue;
}
}
}
@@ -233,9 +233,9 @@ namespace detail
std::size_t coef2 = el.iu * iv_minus_coef;
std::size_t coef3 = el.iu * iv;
i->u.element.red = static_cast<unsigned>((coef0 * col0.u.element.red + coef1 * col1.u.element.red + (coef2 * col2.u.element.red + coef3 * col3.u.element.red)) >> double_shift_size);
i->u.element.green = static_cast<unsigned>((coef0 * col0.u.element.green + coef1 * col1.u.element.green + (coef2 * col2.u.element.green + coef3 * col3.u.element.green)) >> double_shift_size);
i->u.element.blue = static_cast<unsigned>((coef0 * col0.u.element.blue + coef1 * col1.u.element.blue + (coef2 * col2.u.element.blue + coef3 * col3.u.element.blue)) >> double_shift_size);
i->element.red = static_cast<unsigned>((coef0 * col0.element.red + coef1 * col1.element.red + (coef2 * col2.element.red + coef3 * col3.element.red)) >> double_shift_size);
i->element.green = static_cast<unsigned>((coef0 * col0.element.green + coef1 * col1.element.green + (coef2 * col2.element.green + coef3 * col3.element.green)) >> double_shift_size);
i->element.blue = static_cast<unsigned>((coef0 * col0.element.blue + coef1 * col1.element.blue + (coef2 * col2.element.blue + coef3 * col3.element.blue)) >> double_shift_size);
}
}
}
@@ -250,83 +250,83 @@ namespace detail
//process
virtual void process(const paint::pixel_buffer& s_pixbuf, const nana::rectangle& s_r, paint::pixel_buffer& d_pixbuf, const nana::point& d_pos) const
{
nana::pixel_rgb_t * d_rgb = d_pixbuf.at(d_pos);
nana::pixel_rgb_t * s_rgb = s_pixbuf.raw_ptr(s_r.y) + s_r.x;
auto d_rgb = d_pixbuf.at(d_pos);
auto s_rgb = s_pixbuf.raw_ptr(s_r.y) + s_r.x;
if(d_rgb && s_rgb)
{
const unsigned rest = s_r.width & 0x3;
const unsigned length_align4 = s_r.width - rest;
std::size_t d_step_bytes = d_pixbuf.bytes_per_line() - (s_r.width - rest) * sizeof(pixel_rgb_t);
std::size_t s_step_bytes = s_pixbuf.bytes_per_line() - (s_r.width - rest) * sizeof(pixel_rgb_t);
std::size_t d_step_bytes = d_pixbuf.bytes_per_line() - (s_r.width - rest) * sizeof(pixel_argb_t);
std::size_t s_step_bytes = s_pixbuf.bytes_per_line() - (s_r.width - rest) * sizeof(pixel_argb_t);
for(unsigned line = 0; line < s_r.height; ++line)
{
pixel_rgb_t* end = d_rgb + length_align4;
const auto end = d_rgb + length_align4;
for(; d_rgb < end; d_rgb += 4, s_rgb += 4)
{
//0
if(s_rgb->u.element.alpha_channel)
if(s_rgb->element.alpha_channel)
{
if(s_rgb->u.element.alpha_channel != 255)
if(s_rgb->element.alpha_channel != 255)
{
d_rgb->u.element.red = unsigned(d_rgb->u.element.red * (255 - s_rgb[0].u.element.alpha_channel) + s_rgb[0].u.element.red * s_rgb[0].u.element.alpha_channel) / 255;
d_rgb->u.element.green = unsigned(d_rgb->u.element.green * (255 - s_rgb[0].u.element.alpha_channel) + s_rgb[0].u.element.green * s_rgb[0].u.element.alpha_channel) / 255;
d_rgb->u.element.blue = unsigned(d_rgb->u.element.blue * (255 - s_rgb[0].u.element.alpha_channel) + s_rgb[0].u.element.blue * s_rgb[0].u.element.alpha_channel) / 255;
d_rgb->element.red = unsigned(d_rgb->element.red * (255 - s_rgb[0].element.alpha_channel) + s_rgb[0].element.red * s_rgb[0].element.alpha_channel) / 255;
d_rgb->element.green = unsigned(d_rgb->element.green * (255 - s_rgb[0].element.alpha_channel) + s_rgb[0].element.green * s_rgb[0].element.alpha_channel) / 255;
d_rgb->element.blue = unsigned(d_rgb->element.blue * (255 - s_rgb[0].element.alpha_channel) + s_rgb[0].element.blue * s_rgb[0].element.alpha_channel) / 255;
}
else
*d_rgb = *s_rgb;
}
//1
if(s_rgb[1].u.element.alpha_channel)
if(s_rgb[1].element.alpha_channel)
{
if(s_rgb[1].u.element.alpha_channel != 255)
if(s_rgb[1].element.alpha_channel != 255)
{
d_rgb[1].u.element.red = unsigned(d_rgb[1].u.element.red * (255 - s_rgb[1].u.element.alpha_channel) + s_rgb[1].u.element.red * s_rgb[1].u.element.alpha_channel) / 255;
d_rgb[1].u.element.green = unsigned(d_rgb[1].u.element.green * (255 - s_rgb[1].u.element.alpha_channel) + s_rgb[1].u.element.green * s_rgb[1].u.element.alpha_channel) / 255;
d_rgb[1].u.element.blue = unsigned(d_rgb[1].u.element.blue * (255 - s_rgb[1].u.element.alpha_channel) + s_rgb[1].u.element.blue * s_rgb[1].u.element.alpha_channel) / 255;
d_rgb[1].element.red = unsigned(d_rgb[1].element.red * (255 - s_rgb[1].element.alpha_channel) + s_rgb[1].element.red * s_rgb[1].element.alpha_channel) / 255;
d_rgb[1].element.green = unsigned(d_rgb[1].element.green * (255 - s_rgb[1].element.alpha_channel) + s_rgb[1].element.green * s_rgb[1].element.alpha_channel) / 255;
d_rgb[1].element.blue = unsigned(d_rgb[1].element.blue * (255 - s_rgb[1].element.alpha_channel) + s_rgb[1].element.blue * s_rgb[1].element.alpha_channel) / 255;
}
else
d_rgb[1] = s_rgb[1];
}
//2
if(s_rgb[2].u.element.alpha_channel)
if(s_rgb[2].element.alpha_channel)
{
if(s_rgb[2].u.element.alpha_channel != 255)
if(s_rgb[2].element.alpha_channel != 255)
{
d_rgb[2].u.element.red = unsigned(d_rgb[2].u.element.red * (255 - s_rgb[2].u.element.alpha_channel) + s_rgb[2].u.element.red * s_rgb[2].u.element.alpha_channel) / 255;
d_rgb[2].u.element.green = unsigned(d_rgb[2].u.element.green * (255 - s_rgb[2].u.element.alpha_channel) + s_rgb[2].u.element.green * s_rgb[2].u.element.alpha_channel) / 255;
d_rgb[2].u.element.blue = unsigned(d_rgb[2].u.element.blue * (255 - s_rgb[2].u.element.alpha_channel) + s_rgb[2].u.element.blue * s_rgb[2].u.element.alpha_channel) / 255;
d_rgb[2].element.red = unsigned(d_rgb[2].element.red * (255 - s_rgb[2].element.alpha_channel) + s_rgb[2].element.red * s_rgb[2].element.alpha_channel) / 255;
d_rgb[2].element.green = unsigned(d_rgb[2].element.green * (255 - s_rgb[2].element.alpha_channel) + s_rgb[2].element.green * s_rgb[2].element.alpha_channel) / 255;
d_rgb[2].element.blue = unsigned(d_rgb[2].element.blue * (255 - s_rgb[2].element.alpha_channel) + s_rgb[2].element.blue * s_rgb[2].element.alpha_channel) / 255;
}
else
d_rgb[2] = s_rgb[2];
}
//3
if(s_rgb[3].u.element.alpha_channel)
if(s_rgb[3].element.alpha_channel)
{
if(s_rgb[3].u.element.alpha_channel != 255)
if(s_rgb[3].element.alpha_channel != 255)
{
d_rgb[3].u.element.red = unsigned(d_rgb[3].u.element.red * (255 - s_rgb[3].u.element.alpha_channel) + s_rgb[3].u.element.red * s_rgb[3].u.element.alpha_channel) / 255;
d_rgb[3].u.element.green = unsigned(d_rgb[3].u.element.green * (255 - s_rgb[3].u.element.alpha_channel) + s_rgb[3].u.element.green * s_rgb[3].u.element.alpha_channel) / 255;
d_rgb[3].u.element.blue = unsigned(d_rgb[3].u.element.blue * (255 - s_rgb[3].u.element.alpha_channel) + s_rgb[3].u.element.blue * s_rgb[3].u.element.alpha_channel) / 255;
d_rgb[3].element.red = unsigned(d_rgb[3].element.red * (255 - s_rgb[3].element.alpha_channel) + s_rgb[3].element.red * s_rgb[3].element.alpha_channel) / 255;
d_rgb[3].element.green = unsigned(d_rgb[3].element.green * (255 - s_rgb[3].element.alpha_channel) + s_rgb[3].element.green * s_rgb[3].element.alpha_channel) / 255;
d_rgb[3].element.blue = unsigned(d_rgb[3].element.blue * (255 - s_rgb[3].element.alpha_channel) + s_rgb[3].element.blue * s_rgb[3].element.alpha_channel) / 255;
}
else
d_rgb[3] = s_rgb[3];
}
}
const pixel_rgb_t * s_end = s_rgb + rest;
const pixel_argb_t * s_end = s_rgb + rest;
for(auto i = s_rgb; i != s_end; ++i)
{
if(i->u.element.alpha_channel)
if(i->element.alpha_channel)
{
if(i->u.element.alpha_channel != 255)
if(i->element.alpha_channel != 255)
{
d_rgb[3].u.element.red = unsigned(d_rgb[3].u.element.red * (255 - i->u.element.alpha_channel) + i->u.element.red * i->u.element.alpha_channel) / 255;
d_rgb[3].u.element.green = unsigned(d_rgb[3].u.element.green * (255 - i->u.element.alpha_channel) + i->u.element.green * i->u.element.alpha_channel) / 255;
d_rgb[3].u.element.blue = unsigned(d_rgb[3].u.element.blue * (255 - i->u.element.alpha_channel) + i->u.element.blue * i->u.element.alpha_channel) / 255;
d_rgb[3].element.red = unsigned(d_rgb[3].element.red * (255 - i->element.alpha_channel) + i->element.red * i->element.alpha_channel) / 255;
d_rgb[3].element.green = unsigned(d_rgb[3].element.green * (255 - i->element.alpha_channel) + i->element.green * i->element.alpha_channel) / 255;
d_rgb[3].element.blue = unsigned(d_rgb[3].element.blue * (255 - i->element.alpha_channel) + i->element.blue * i->element.alpha_channel) / 255;
}
else
d_rgb[3] = *i;
@@ -347,8 +347,8 @@ namespace detail
//process
virtual void process(const paint::pixel_buffer& s_pixbuf, const nana::rectangle& s_r, paint::pixel_buffer& d_pixbuf, const nana::point& d_pos, double fade_rate) const
{
nana::pixel_rgb_t * d_rgb = d_pixbuf.raw_ptr(d_pos.y) + d_pos.x;
nana::pixel_rgb_t * s_rgb = s_pixbuf.raw_ptr(s_r.y) + s_r.x;
auto d_rgb = d_pixbuf.raw_ptr(d_pos.y) + d_pos.x;
auto s_rgb = s_pixbuf.raw_ptr(s_r.y) + s_r.x;
if(d_rgb && s_rgb)
{
@@ -359,39 +359,39 @@ namespace detail
const unsigned rest = s_r.width & 0x3;
const unsigned length_align4 = s_r.width - rest;
std::size_t d_step_bytes = d_pixbuf.bytes_per_line() - (s_r.width - rest) * sizeof(pixel_rgb_t);
std::size_t s_step_bytes = s_pixbuf.bytes_per_line() - (s_r.width - rest) * sizeof(pixel_rgb_t);
std::size_t d_step_bytes = d_pixbuf.bytes_per_line() - (s_r.width - rest) * sizeof(pixel_argb_t);
std::size_t s_step_bytes = s_pixbuf.bytes_per_line() - (s_r.width - rest) * sizeof(pixel_argb_t);
for(unsigned line = 0; line < s_r.height; ++line)
{
pixel_rgb_t* end = d_rgb + length_align4;
const auto end = d_rgb + length_align4;
for(; d_rgb < end; d_rgb += 4, s_rgb += 4)
{
//0
d_rgb[0].u.element.red = unsigned(d_table[d_rgb[0].u.element.red] + s_table[s_rgb[0].u.element.red]);
d_rgb[0].u.element.green = unsigned(d_table[d_rgb[0].u.element.green] + s_table[s_rgb[0].u.element.green]);
d_rgb[0].u.element.blue = unsigned(d_table[d_rgb[0].u.element.blue] + s_table[s_rgb[0].u.element.blue]);
d_rgb[0].element.red = unsigned(d_table[d_rgb[0].element.red] + s_table[s_rgb[0].element.red]);
d_rgb[0].element.green = unsigned(d_table[d_rgb[0].element.green] + s_table[s_rgb[0].element.green]);
d_rgb[0].element.blue = unsigned(d_table[d_rgb[0].element.blue] + s_table[s_rgb[0].element.blue]);
//1
d_rgb[1].u.element.red = unsigned(d_table[d_rgb[1].u.element.red] + s_table[s_rgb[1].u.element.red]);
d_rgb[1].u.element.green = unsigned(d_table[d_rgb[1].u.element.green] + s_table[s_rgb[1].u.element.green]);
d_rgb[1].u.element.blue = unsigned(d_table[d_rgb[1].u.element.blue] + s_table[s_rgb[1].u.element.blue]);
d_rgb[1].element.red = unsigned(d_table[d_rgb[1].element.red] + s_table[s_rgb[1].element.red]);
d_rgb[1].element.green = unsigned(d_table[d_rgb[1].element.green] + s_table[s_rgb[1].element.green]);
d_rgb[1].element.blue = unsigned(d_table[d_rgb[1].element.blue] + s_table[s_rgb[1].element.blue]);
//2
d_rgb[2].u.element.red = unsigned(d_table[d_rgb[2].u.element.red] + s_table[s_rgb[2].u.element.red]);
d_rgb[2].u.element.green = unsigned(d_table[d_rgb[2].u.element.green] + s_table[s_rgb[2].u.element.green]);
d_rgb[2].u.element.blue = unsigned(d_table[d_rgb[2].u.element.blue] + s_table[s_rgb[2].u.element.blue]);
d_rgb[2].element.red = unsigned(d_table[d_rgb[2].element.red] + s_table[s_rgb[2].element.red]);
d_rgb[2].element.green = unsigned(d_table[d_rgb[2].element.green] + s_table[s_rgb[2].element.green]);
d_rgb[2].element.blue = unsigned(d_table[d_rgb[2].element.blue] + s_table[s_rgb[2].element.blue]);
//3
d_rgb[3].u.element.red = unsigned(d_table[d_rgb[3].u.element.red] + s_table[s_rgb[3].u.element.red]);
d_rgb[3].u.element.green = unsigned(d_table[d_rgb[3].u.element.green] + s_table[s_rgb[3].u.element.green]);
d_rgb[3].u.element.blue = unsigned(d_table[d_rgb[3].u.element.blue] + s_table[s_rgb[3].u.element.blue]);
d_rgb[3].element.red = unsigned(d_table[d_rgb[3].element.red] + s_table[s_rgb[3].element.red]);
d_rgb[3].element.green = unsigned(d_table[d_rgb[3].element.green] + s_table[s_rgb[3].element.green]);
d_rgb[3].element.blue = unsigned(d_table[d_rgb[3].element.blue] + s_table[s_rgb[3].element.blue]);
}
for(unsigned i = 0; i < rest; ++i)
{
d_rgb[i].u.element.red = unsigned(d_table[d_rgb[i].u.element.red] + s_table[s_rgb[i].u.element.red]);
d_rgb[i].u.element.green = unsigned(d_table[d_rgb[i].u.element.green] + s_table[s_rgb[i].u.element.green]);
d_rgb[i].u.element.blue = unsigned(d_table[d_rgb[i].u.element.blue] + s_table[s_rgb[i].u.element.blue]);
d_rgb[i].element.red = unsigned(d_table[d_rgb[i].element.red] + s_table[s_rgb[i].element.red]);
d_rgb[i].element.green = unsigned(d_table[d_rgb[i].element.green] + s_table[s_rgb[i].element.green]);
d_rgb[i].element.blue = unsigned(d_table[d_rgb[i].element.blue] + s_table[s_rgb[i].element.blue]);
}
d_rgb = pixel_at(d_rgb, d_step_bytes);
s_rgb = pixel_at(s_rgb, s_step_bytes);
@@ -409,15 +409,15 @@ namespace detail
{
const std::size_t bytes_pl = pixbuf.bytes_per_line();
unsigned char * fade_table = nullptr;
nana::pixel_rgb_t rgb_imd;
nana::pixel_argb_t rgb_imd;
if(fade_rate != 0.0)
{
fade_table = detail::alloc_fade_table(1 - fade_rate);
rgb_imd.u.color = color;
rgb_imd.value = color;
rgb_imd = detail::fade_color_intermedia(rgb_imd, fade_table);
}
nana::pixel_rgb_t * i = pixel_at(pixbuf.raw_ptr(0), pos_beg.y * bytes_pl) + pos_beg.x;
auto i = pixel_at(pixbuf.raw_ptr(0), pos_beg.y * bytes_pl) + pos_beg.x;
auto delta = pos_end - pos_beg;
@@ -432,7 +432,7 @@ namespace detail
if(delta.x == delta.y)
{
step_bytes += sizeof(pixel_rgb_t);
step_bytes += sizeof(pixel_argb_t);
++delta.x;
if(fade_table)
@@ -447,7 +447,7 @@ namespace detail
{
for(int x = 0; x < delta.x; ++x)
{
i->u.color = color;
i->value = color;
i = pixel_at(i, step_bytes);
}
}
@@ -479,7 +479,7 @@ namespace detail
{
for(int x = 0; x < delta.x; ++x)
{
i->u.color = color;
i->value = color;
if(error >= 0)
{
error -= dx_2;
@@ -513,7 +513,7 @@ namespace detail
{
for (int y = 0; y < delta.y; ++y)
{
i->u.color = color;
i->value = color;
if(error >= 0)
{
error -= dy_2;
@@ -579,20 +579,20 @@ namespace detail
{
for(int i = - radius; i <= radius; ++i)
{
nana::pixel_rgb_t px = linepix[(i > 0 ? i : 0)];
sum_r += px.u.element.red;
sum_g += px.u.element.green;
sum_b += px.u.element.blue;
auto px = linepix[(i > 0 ? i : 0)];
sum_r += px.element.red;
sum_g += px.element.green;
sum_b += px.element.blue;
}
}
else
{
for(int i = - radius; i <= radius; ++i)
{
nana::pixel_rgb_t px = linepix[std::min(wm, (i > 0 ? i : 0))];
sum_r += px.u.element.red;
sum_g += px.u.element.green;
sum_b += px.u.element.blue;
auto px = linepix[std::min(wm, (i > 0 ? i : 0))];
sum_r += px.element.red;
sum_g += px.element.green;
sum_b += px.element.blue;
}
}
@@ -608,12 +608,12 @@ namespace detail
vmax[x] = std::max(x - radius, 0);
}
nana::pixel_rgb_t p1 = linepix[vmin[x]];
nana::pixel_rgb_t p2 = linepix[vmax[x]];
auto p1 = linepix[vmin[x]];
auto p2 = linepix[vmax[x]];
sum_r += p1.u.element.red - p2.u.element.red;
sum_g += p1.u.element.green - p2.u.element.green;
sum_b += p1.u.element.blue - p2.u.element.blue;
sum_r += p1.element.red - p2.element.red;
sum_g += p1.element.green - p2.element.green;
sum_b += p1.element.blue - p2.element.blue;
++yi;
}
linepix = pixbuf.raw_ptr(area.y + y) + area.x;
@@ -649,7 +649,7 @@ namespace detail
for(int y = 0; y < h; ++y)
{
linepix->u.color = 0xFF000000 | (dv[sum_r] << 16) | (dv[sum_g] << 8) | dv[sum_b];
linepix->value = 0xFF000000 | (dv[sum_r] << 16) | (dv[sum_g] << 8) | dv[sum_b];
if(x == 0)
{
vmin[y] = std::min(y + radius + 1, hm) * w;

View File

@@ -25,16 +25,16 @@ namespace detail
void free_fade_table(const unsigned char*);
//color = bgcolor * fade_rate + fgcolor * (1 - fade_rate);
nana::pixel_rgb_t fade_color(nana::pixel_rgb_t bgcolor, nana::pixel_rgb_t fgcolor, double fade_rate);
nana::pixel_rgb_t fade_color(nana::pixel_rgb_t bgcolor, nana::pixel_rgb_t fgcolor, const unsigned char* const fade_table);
nana::pixel_rgb_t fade_color_intermedia(nana::pixel_rgb_t fgcolor, const unsigned char* fade_table);
nana::pixel_rgb_t fade_color_by_intermedia(nana::pixel_rgb_t bgcolor, nana::pixel_rgb_t fgcolor_intermedia, const unsigned char* const fade_table);
//nana::pixel_color_t fade_color(nana::pixel_color_t bgcolor, nana::pixel_color_t fgcolor, double fade_rate); //deprecated
nana::pixel_color_t fade_color(nana::pixel_color_t bgcolor, nana::pixel_color_t fgcolor, const unsigned char* const fade_table);
nana::pixel_color_t fade_color_intermedia(nana::pixel_color_t fgcolor, const unsigned char* fade_table);
nana::pixel_color_t fade_color_by_intermedia(nana::pixel_color_t bgcolor, nana::pixel_color_t fgcolor_intermedia, const unsigned char* const fade_table);
void blend(drawable_type dw, const nana::rectangle& r, nana::color_t, double fade_rate);
nana::size raw_text_extent_size(drawable_type, const nana::char_t*, std::size_t len);
nana::size text_extent_size(drawable_type, const nana::char_t*, std::size_t len);
void draw_string(drawable_type, int x, int y, const nana::char_t *, std::size_t len);
void draw_string(drawable_type, const nana::point&, const nana::char_t *, std::size_t len);
}//end namespace detail
}//end namespace paint
}//end namespace nana

View File

@@ -28,7 +28,8 @@ namespace gadget
void arrow_16_pixels(nana::paint::graphics&, int x, int y, unsigned color, uint32_t style, directions::t direction);
void close_16_pixels(nana::paint::graphics&, int x, int y, uint32_t style, uint32_t color);
void cross(nana::paint::graphics&, int x, int y, uint32_t size, uint32_t thickness, nana::color_t color);
void cross(nana::paint::graphics&, int x, int y, uint32_t size, uint32_t thickness, nana::color_t color); //deprecated
void cross(nana::paint::graphics&, int x, int y, uint32_t size, uint32_t thickness, const nana::expr_color&);
}//end namespace gadget

View File

@@ -112,7 +112,8 @@ namespace nana
void rectangle_line(const ::nana::rectangle&, color_t left, color_t top, color_t right, color_t bottom);
void round_rectangle(int x, int y, unsigned width, unsigned height, unsigned radius_x, unsigned radius_y, color_t, bool solid, color_t color_if_solid);
void round_rectangle(const ::nana::rectangle&, unsigned radius_x, unsigned radius_y, color_t, bool solid, color_t color_if_solid);
void shadow_rectangle(const ::nana::rectangle&, color_t beg_color, color_t end_color, bool vertical);
void shadow_rectangle(const ::nana::rectangle&, color_t beg_color, color_t end_color, bool vertical); //deprecated
void shadow_rectangle(int x, int y, unsigned width, unsigned height, color_t beg_color, color_t end_color, bool vertical); ///< Draws a width and height rectangle at (x, y) and the color in range of [begin, end]
void line(int x1, int y1, int x2, int y2, color_t); ///< Draws a line from point (x1, y1) to point (x2, y2) in the specified color.
@@ -151,7 +152,20 @@ namespace nana
void release();
void save_as_file(const char*);
static color_t mix(color_t colorX, color_t colorY, double persent);
static color_t mix(color_t colorX, color_t colorY, double persent); //deprecated
void set_color(const ::nana::expr_color&);
void set_text_color(const ::nana::expr_color&);
unsigned bidi_string(const nana::point&, const char_t *, std::size_t len);
void string(nana::point, const char_t*, std::size_t len);
void string(const nana::point&, const char_t*);
void string(const nana::point&, const nana::string&);
void line(const nana::point&, const nana::point&);
void rectangle(const ::nana::rectangle&, bool solid);
void gradual_rectangle(const ::nana::rectangle&, const ::nana::expr_color& from, const ::nana::expr_color& to, bool vertical);
private:
std::shared_ptr< ::nana::detail::drawable_impl_type> dwptr_;
font font_shadow_;

View File

@@ -19,14 +19,14 @@ namespace nana{ namespace paint
{
///@brief Seek a pixel address by using offset bytes
///@return the specified pixel address
inline pixel_rgb_t * pixel_at(pixel_rgb_t * p, std::size_t bytes)
inline pixel_argb_t * pixel_at(pixel_argb_t * p, std::size_t bytes)
{
return reinterpret_cast<pixel_rgb_t*>(reinterpret_cast<char*>(p) + bytes);
return reinterpret_cast<pixel_argb_t*>(reinterpret_cast<char*>(p) + bytes);
}
inline const pixel_rgb_t * pixel_at(const pixel_rgb_t * p, std::size_t bytes)
inline const pixel_argb_t * pixel_at(const pixel_argb_t * p, std::size_t bytes)
{
return reinterpret_cast<const pixel_rgb_t*>(reinterpret_cast<const char*>(p) + bytes);
return reinterpret_cast<const pixel_argb_t*>(reinterpret_cast<const char*>(p) + bytes);
}
class pixel_buffer
@@ -60,9 +60,9 @@ namespace nana{ namespace paint
std::size_t bytes_per_line() const;
nana::size size() const;
pixel_rgb_t * at(const point& pos) const;
pixel_rgb_t * raw_ptr(std::size_t row) const;
pixel_rgb_t * operator[](std::size_t row) const;
pixel_argb_t * at(const point& pos) const;
pixel_argb_t * raw_ptr(std::size_t row) const;
pixel_argb_t * operator[](std::size_t row) const;
void put(const unsigned char* rawbits, std::size_t width, std::size_t height, std::size_t bits_per_pixel, std::size_t bytes_per_line, bool is_negative);
@@ -70,10 +70,11 @@ namespace nana{ namespace paint
void line(const nana::point& pos_beg, const nana::point& pos_end, nana::color_t color, double fade_rate);
void rectangle(const nana::rectangle&, nana::color_t, double fade_rate, bool solid);
void shadow_rectangle(const nana::rectangle&, nana::color_t beg, nana::color_t end, double fade_rate, bool vertical);
void shadow_rectangle(const nana::rectangle&, nana::color_t beg, nana::color_t end, double fade_rate, bool vertical); //deprecated
void gradual_rectangle(const ::nana::rectangle&, const ::nana::expr_color& from, const ::nana::expr_color& to, double fade_rate, bool vertical);
pixel_rgb_t pixel(int x, int y) const;
void pixel(int x, int y, pixel_rgb_t);
pixel_argb_t pixel(int x, int y) const;
void pixel(int x, int y, pixel_argb_t);
void paste(drawable_type, int x, int y) const;
void paste(const nana::rectangle& s_r, drawable_type, int x, int y) const;

View File

@@ -18,6 +18,8 @@ namespace nana
void render(int x, int y, nana::color_t, const nana::char_t*, std::size_t len, unsigned restricted_pixels);
nana::size extent_size(int x, int y, const nana::char_t*, std::size_t len, unsigned restricted_pixels) const;
void render(const nana::point&, const nana::char_t*, std::size_t len, unsigned restricted_pixels, bool omiited);
private:
graph_reference graph_;
align text_align_;