mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-29 19:20:09 +00:00
Add a rgba_blender_normal() version without opacity
This can be used to speed up text rendering and rotation algorithm.
This commit is contained in:
parent
ce02a31c01
commit
d4faf04946
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
// Copyright (C) 2001-2016 David Capello
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
@ -156,7 +156,7 @@ doc::Image* render_text(const std::string& fontfile, int fontsize,
|
||||
doc::rgba(doc::rgba_getr(color),
|
||||
doc::rgba_getg(color),
|
||||
doc::rgba_getb(color),
|
||||
MUL_UN8(doc::rgba_geta(color), alpha, t)), 255));
|
||||
MUL_UN8(doc::rgba_geta(color), alpha, t))));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -78,11 +78,11 @@ static void image_scale_tpl(
|
||||
}
|
||||
|
||||
static color_t rgba_blender(color_t back, color_t front) {
|
||||
return rgba_blender_normal(back, front, 255);
|
||||
return rgba_blender_normal(back, front);
|
||||
}
|
||||
|
||||
static color_t grayscale_blender(color_t back, color_t front) {
|
||||
return graya_blender_normal(back, front, 255);
|
||||
return graya_blender_normal(back, front);
|
||||
}
|
||||
|
||||
class if_blender {
|
||||
@ -254,7 +254,7 @@ public:
|
||||
|
||||
int c = get_pixel_fast<RgbTraits>(spr, spr_x, spr_y);
|
||||
if ((rgba_geta(m_mask_color) == 0) || ((c & rgba_rgb_mask) != (m_mask_color & rgba_rgb_mask)))
|
||||
*m_it = rgba_blender_normal(*m_it, c, 255);
|
||||
*m_it = rgba_blender_normal(*m_it, c);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -192,6 +192,39 @@ color_t rgba_blender_normal(color_t backdrop, color_t src, int opacity)
|
||||
return rgba(Rr, Rg, Rb, Ra);
|
||||
}
|
||||
|
||||
color_t rgba_blender_normal(color_t backdrop, color_t src)
|
||||
{
|
||||
int t;
|
||||
|
||||
if ((backdrop & rgba_a_mask) == 0) {
|
||||
return src;
|
||||
}
|
||||
else if ((src & rgba_a_mask) == 0) {
|
||||
return backdrop;
|
||||
}
|
||||
|
||||
int Br, Bg, Bb, Ba;
|
||||
int Sr, Sg, Sb, Sa;
|
||||
int Rr, Rg, Rb, Ra;
|
||||
|
||||
Br = rgba_getr(backdrop);
|
||||
Bg = rgba_getg(backdrop);
|
||||
Bb = rgba_getb(backdrop);
|
||||
Ba = rgba_geta(backdrop);
|
||||
|
||||
Sr = rgba_getr(src);
|
||||
Sg = rgba_getg(src);
|
||||
Sb = rgba_getb(src);
|
||||
Sa = rgba_geta(src);
|
||||
|
||||
Ra = Ba + Sa - MUL_UN8(Ba, Sa, t);
|
||||
Rr = Br + (Sr-Br) * Sa / Ra;
|
||||
Rg = Bg + (Sg-Bg) * Sa / Ra;
|
||||
Rb = Bb + (Sb-Bb) * Sa / Ra;
|
||||
|
||||
return rgba(Rr, Rg, Rb, Ra);
|
||||
}
|
||||
|
||||
color_t rgba_blender_multiply(color_t backdrop, color_t src, int opacity)
|
||||
{
|
||||
int t;
|
||||
@ -502,6 +535,32 @@ color_t graya_blender_normal(color_t backdrop, color_t src, int opacity)
|
||||
return graya(Rg, Ra);
|
||||
}
|
||||
|
||||
color_t graya_blender_normal(color_t backdrop, color_t src)
|
||||
{
|
||||
int t;
|
||||
|
||||
if ((backdrop & graya_a_mask) == 0) {
|
||||
return src;
|
||||
}
|
||||
else if ((src & graya_a_mask) == 0)
|
||||
return backdrop;
|
||||
|
||||
int Bg, Ba;
|
||||
int Sg, Sa;
|
||||
int Rg, Ra;
|
||||
|
||||
Bg = graya_getv(backdrop);
|
||||
Ba = graya_geta(backdrop);
|
||||
|
||||
Sg = graya_getv(src);
|
||||
Sa = graya_geta(src);
|
||||
|
||||
Ra = Ba + Sa - MUL_UN8(Ba, Sa, t);
|
||||
Rg = Bg + (Sg-Bg) * Sa / Ra;
|
||||
|
||||
return graya(Rg, Ra);
|
||||
}
|
||||
|
||||
color_t graya_blender_multiply(color_t backdrop, color_t src, int opacity)
|
||||
{
|
||||
int t;
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite Document Library
|
||||
// Copyright (c) 2001-2015 David Capello
|
||||
// Copyright (c) 2001-2016 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
@ -16,10 +16,12 @@ namespace doc {
|
||||
typedef color_t (*BlendFunc)(color_t backdrop, color_t src, int opacity);
|
||||
|
||||
color_t rgba_blender_normal(color_t backdrop, color_t src, int opacity);
|
||||
color_t rgba_blender_normal(color_t backdrop, color_t src);
|
||||
color_t rgba_blender_merge(color_t backdrop, color_t src, int opacity);
|
||||
color_t rgba_blender_neg_bw(color_t backdrop, color_t src, int opacity);
|
||||
|
||||
color_t graya_blender_normal(color_t backdrop, color_t src, int opacity);
|
||||
color_t graya_blender_normal(color_t backdrop, color_t src);
|
||||
color_t graya_blender_merge(color_t backdrop, color_t src, int opacity);
|
||||
color_t graya_blender_neg_bw(color_t backdrop, color_t src, int opacity);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user