2011-10-12 03:02:50 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Anti-Grain Geometry - Version 2.4
|
|
|
|
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
|
|
|
|
//
|
2014-12-01 10:55:05 +00:00
|
|
|
// Permission to copy, use, modify, sell and distribute this software
|
|
|
|
// is granted provided this copyright notice appears in all copies.
|
2011-10-12 03:02:50 +00:00
|
|
|
// This software is provided "as is" without express or implied
|
|
|
|
// warranty, and with no claim as to its suitability for any purpose.
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Contact: mcseem@antigrain.com
|
|
|
|
// mcseemagg@yahoo.com
|
|
|
|
// http://www.antigrain.com
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
2014-12-01 10:55:05 +00:00
|
|
|
// Adaptation for high precision colors has been sponsored by
|
2011-10-12 03:02:50 +00:00
|
|
|
// Liberty Technology Systems, Inc., visit http://lib-sys.com
|
|
|
|
//
|
|
|
|
// Liberty Technology Systems, Inc. is the provider of
|
|
|
|
// PostScript and PDF technology for software developers.
|
2014-12-01 10:55:05 +00:00
|
|
|
//
|
2011-10-12 03:02:50 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#ifndef AGG_PIXFMT_GRAY_INCLUDED
|
|
|
|
#define AGG_PIXFMT_GRAY_INCLUDED
|
|
|
|
|
2013-02-28 19:41:08 +00:00
|
|
|
#include <cstring>
|
2014-12-01 10:55:05 +00:00
|
|
|
#include "agg_pixfmt_base.h"
|
2011-10-12 03:02:50 +00:00
|
|
|
#include "agg_rendering_buffer.h"
|
|
|
|
|
|
|
|
namespace agg
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
|
2011-10-12 03:02:50 +00:00
|
|
|
//============================================================blender_gray
|
|
|
|
template<class ColorT> struct blender_gray
|
|
|
|
{
|
|
|
|
typedef ColorT color_type;
|
|
|
|
typedef typename color_type::value_type value_type;
|
|
|
|
typedef typename color_type::calc_type calc_type;
|
2014-12-01 10:55:05 +00:00
|
|
|
typedef typename color_type::long_type long_type;
|
2011-10-12 03:02:50 +00:00
|
|
|
|
2014-12-01 10:55:05 +00:00
|
|
|
// Blend pixels using the non-premultiplied form of Alvy-Ray Smith's
|
|
|
|
// compositing function. Since the render buffer is opaque we skip the
|
|
|
|
// initial premultiply and final demultiply.
|
|
|
|
|
|
|
|
static AGG_INLINE void blend_pix(value_type* p,
|
|
|
|
value_type cv, value_type alpha, cover_type cover)
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
blend_pix(p, cv, color_type::mult_cover(alpha, cover));
|
|
|
|
}
|
|
|
|
|
|
|
|
static AGG_INLINE void blend_pix(value_type* p,
|
|
|
|
value_type cv, value_type alpha)
|
|
|
|
{
|
|
|
|
*p = color_type::lerp(*p, cv, alpha);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//======================================================blender_gray_pre
|
|
|
|
template<class ColorT> struct blender_gray_pre
|
|
|
|
{
|
|
|
|
typedef ColorT color_type;
|
|
|
|
typedef typename color_type::value_type value_type;
|
|
|
|
typedef typename color_type::calc_type calc_type;
|
2014-12-01 10:55:05 +00:00
|
|
|
typedef typename color_type::long_type long_type;
|
|
|
|
|
|
|
|
// Blend pixels using the premultiplied form of Alvy-Ray Smith's
|
|
|
|
// compositing function.
|
2011-10-12 03:02:50 +00:00
|
|
|
|
2014-12-01 10:55:05 +00:00
|
|
|
static AGG_INLINE void blend_pix(value_type* p,
|
|
|
|
value_type cv, value_type alpha, cover_type cover)
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
blend_pix(p, color_type::mult_cover(cv, cover), color_type::mult_cover(alpha, cover));
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
|
2014-12-01 10:55:05 +00:00
|
|
|
static AGG_INLINE void blend_pix(value_type* p,
|
|
|
|
value_type cv, value_type alpha)
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
*p = color_type::prelerp(*p, cv, alpha);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
};
|
2014-12-01 10:55:05 +00:00
|
|
|
|
2011-10-12 03:02:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
//=====================================================apply_gamma_dir_gray
|
|
|
|
template<class ColorT, class GammaLut> class apply_gamma_dir_gray
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef typename ColorT::value_type value_type;
|
|
|
|
|
|
|
|
apply_gamma_dir_gray(const GammaLut& gamma) : m_gamma(gamma) {}
|
|
|
|
|
|
|
|
AGG_INLINE void operator () (value_type* p)
|
|
|
|
{
|
|
|
|
*p = m_gamma.dir(*p);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const GammaLut& m_gamma;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//=====================================================apply_gamma_inv_gray
|
|
|
|
template<class ColorT, class GammaLut> class apply_gamma_inv_gray
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef typename ColorT::value_type value_type;
|
|
|
|
|
|
|
|
apply_gamma_inv_gray(const GammaLut& gamma) : m_gamma(gamma) {}
|
|
|
|
|
|
|
|
AGG_INLINE void operator () (value_type* p)
|
|
|
|
{
|
|
|
|
*p = m_gamma.inv(*p);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const GammaLut& m_gamma;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//=================================================pixfmt_alpha_blend_gray
|
2014-12-01 10:55:05 +00:00
|
|
|
template<class Blender, class RenBuf, unsigned Step = 1, unsigned Offset = 0>
|
2011-10-12 03:02:50 +00:00
|
|
|
class pixfmt_alpha_blend_gray
|
|
|
|
{
|
|
|
|
public:
|
2014-12-01 10:55:05 +00:00
|
|
|
typedef pixfmt_gray_tag pixfmt_category;
|
2011-10-12 03:02:50 +00:00
|
|
|
typedef RenBuf rbuf_type;
|
|
|
|
typedef typename rbuf_type::row_data row_data;
|
|
|
|
typedef Blender blender_type;
|
|
|
|
typedef typename blender_type::color_type color_type;
|
|
|
|
typedef int order_type; // A fake one
|
|
|
|
typedef typename color_type::value_type value_type;
|
|
|
|
typedef typename color_type::calc_type calc_type;
|
2014-12-01 10:55:05 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
num_components = 1,
|
|
|
|
pix_width = sizeof(value_type) * Step,
|
|
|
|
pix_step = Step,
|
|
|
|
pix_offset = Offset,
|
|
|
|
};
|
|
|
|
struct pixel_type
|
|
|
|
{
|
|
|
|
value_type c[num_components];
|
|
|
|
|
|
|
|
void set(value_type v)
|
|
|
|
{
|
|
|
|
c[0] = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set(const color_type& color)
|
|
|
|
{
|
|
|
|
set(color.v);
|
|
|
|
}
|
|
|
|
|
|
|
|
void get(value_type& v) const
|
|
|
|
{
|
|
|
|
v = c[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
color_type get() const
|
|
|
|
{
|
|
|
|
return color_type(c[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
pixel_type* next()
|
|
|
|
{
|
|
|
|
return (pixel_type*)(c + pix_step);
|
|
|
|
}
|
|
|
|
|
|
|
|
const pixel_type* next() const
|
|
|
|
{
|
|
|
|
return (const pixel_type*)(c + pix_step);
|
|
|
|
}
|
|
|
|
|
|
|
|
pixel_type* advance(int n)
|
|
|
|
{
|
|
|
|
return (pixel_type*)(c + n * pix_step);
|
|
|
|
}
|
|
|
|
|
|
|
|
const pixel_type* advance(int n) const
|
|
|
|
{
|
|
|
|
return (const pixel_type*)(c + n * pix_step);
|
|
|
|
}
|
2011-10-12 03:02:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
//--------------------------------------------------------------------
|
2014-12-01 10:55:05 +00:00
|
|
|
AGG_INLINE void blend_pix(pixel_type* p,
|
|
|
|
value_type v, value_type a,
|
|
|
|
unsigned cover)
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
blender_type::blend_pix(p->c, v, a, cover);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
AGG_INLINE void blend_pix(pixel_type* p, value_type v, value_type a)
|
|
|
|
{
|
|
|
|
blender_type::blend_pix(p->c, v, a);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
AGG_INLINE void blend_pix(pixel_type* p, const color_type& c, unsigned cover)
|
|
|
|
{
|
|
|
|
blender_type::blend_pix(p->c, c.v, c.a, cover);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
AGG_INLINE void blend_pix(pixel_type* p, const color_type& c)
|
|
|
|
{
|
|
|
|
blender_type::blend_pix(p->c, c.v, c.a);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
AGG_INLINE void copy_or_blend_pix(pixel_type* p, const color_type& c, unsigned cover)
|
|
|
|
{
|
|
|
|
if (!c.is_transparent())
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
if (c.is_opaque() && cover == cover_mask)
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
p->set(c);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
blend_pix(p, c, cover);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-01 10:55:05 +00:00
|
|
|
//--------------------------------------------------------------------
|
|
|
|
AGG_INLINE void copy_or_blend_pix(pixel_type* p, const color_type& c)
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
if (!c.is_transparent())
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
if (c.is_opaque())
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
p->set(c);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
blend_pix(p, c);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
explicit pixfmt_alpha_blend_gray(rbuf_type& rb) :
|
|
|
|
m_rbuf(&rb)
|
|
|
|
{}
|
|
|
|
void attach(rbuf_type& rb) { m_rbuf = &rb; }
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
|
|
|
|
template<class PixFmt>
|
|
|
|
bool attach(PixFmt& pixf, int x1, int y1, int x2, int y2)
|
|
|
|
{
|
|
|
|
rect_i r(x1, y1, x2, y2);
|
2014-12-01 10:55:05 +00:00
|
|
|
if (r.clip(rect_i(0, 0, pixf.width()-1, pixf.height()-1)))
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
|
|
|
int stride = pixf.stride();
|
2014-12-01 10:55:05 +00:00
|
|
|
m_rbuf->attach(pixf.pix_ptr(r.x1, stride < 0 ? r.y2 : r.y1),
|
2011-10-12 03:02:50 +00:00
|
|
|
(r.x2 - r.x1) + 1,
|
|
|
|
(r.y2 - r.y1) + 1,
|
|
|
|
stride);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
AGG_INLINE unsigned width() const { return m_rbuf->width(); }
|
|
|
|
AGG_INLINE unsigned height() const { return m_rbuf->height(); }
|
|
|
|
AGG_INLINE int stride() const { return m_rbuf->stride(); }
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2014-12-01 10:55:05 +00:00
|
|
|
int8u* row_ptr(int y) { return m_rbuf->row_ptr(y); }
|
2011-10-12 03:02:50 +00:00
|
|
|
const int8u* row_ptr(int y) const { return m_rbuf->row_ptr(y); }
|
|
|
|
row_data row(int y) const { return m_rbuf->row(y); }
|
|
|
|
|
2014-12-01 10:55:05 +00:00
|
|
|
//--------------------------------------------------------------------
|
|
|
|
AGG_INLINE int8u* pix_ptr(int x, int y)
|
|
|
|
{
|
|
|
|
return m_rbuf->row_ptr(y) + sizeof(value_type) * (x * pix_step + pix_offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
AGG_INLINE const int8u* pix_ptr(int x, int y) const
|
|
|
|
{
|
|
|
|
return m_rbuf->row_ptr(y) + sizeof(value_type) * (x * pix_step + pix_offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return pointer to pixel value, forcing row to be allocated.
|
|
|
|
AGG_INLINE pixel_type* pix_value_ptr(int x, int y, unsigned len)
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
return (pixel_type*)(m_rbuf->row_ptr(x, y, len) + sizeof(value_type) * (x * pix_step + pix_offset));
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
|
2014-12-01 10:55:05 +00:00
|
|
|
// Return pointer to pixel value, or null if row not allocated.
|
|
|
|
AGG_INLINE const pixel_type* pix_value_ptr(int x, int y) const
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
int8u* p = m_rbuf->row_ptr(y);
|
|
|
|
return p ? (pixel_type*)(p + sizeof(value_type) * (x * pix_step + pix_offset)) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get pixel pointer from raw buffer pointer.
|
|
|
|
AGG_INLINE static pixel_type* pix_value_ptr(void* p)
|
|
|
|
{
|
|
|
|
return (pixel_type*)((value_type*)p + pix_offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get pixel pointer from raw buffer pointer.
|
|
|
|
AGG_INLINE static const pixel_type* pix_value_ptr(const void* p)
|
|
|
|
{
|
|
|
|
return (const pixel_type*)((const value_type*)p + pix_offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
AGG_INLINE static void write_plain_color(void* p, color_type c)
|
|
|
|
{
|
|
|
|
// Grayscale formats are implicitly premultiplied.
|
|
|
|
c.premultiply();
|
|
|
|
pix_value_ptr(p)->set(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
AGG_INLINE static color_type read_plain_color(const void* p)
|
|
|
|
{
|
|
|
|
return pix_value_ptr(p)->get();
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
AGG_INLINE static void make_pix(int8u* p, const color_type& c)
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
((pixel_type*)p)->set(c);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
AGG_INLINE color_type pixel(int x, int y) const
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
if (const pixel_type* p = pix_value_ptr(x, y))
|
|
|
|
{
|
|
|
|
return p->get();
|
|
|
|
}
|
|
|
|
return color_type::no_color();
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
AGG_INLINE void copy_pixel(int x, int y, const color_type& c)
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
pix_value_ptr(x, y, 1)->set(c);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
AGG_INLINE void blend_pixel(int x, int y, const color_type& c, int8u cover)
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
copy_or_blend_pix(pix_value_ptr(x, y, 1), c, cover);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2014-12-01 10:55:05 +00:00
|
|
|
AGG_INLINE void copy_hline(int x, int y,
|
|
|
|
unsigned len,
|
2011-10-12 03:02:50 +00:00
|
|
|
const color_type& c)
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
pixel_type* p = pix_value_ptr(x, y, len);
|
2011-10-12 03:02:50 +00:00
|
|
|
do
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
p->set(c);
|
|
|
|
p = p->next();
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
while(--len);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
AGG_INLINE void copy_vline(int x, int y,
|
2014-12-01 10:55:05 +00:00
|
|
|
unsigned len,
|
2011-10-12 03:02:50 +00:00
|
|
|
const color_type& c)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
pix_value_ptr(x, y++, 1)->set(c);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
2014-12-01 10:55:05 +00:00
|
|
|
while (--len);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
void blend_hline(int x, int y,
|
2014-12-01 10:55:05 +00:00
|
|
|
unsigned len,
|
2011-10-12 03:02:50 +00:00
|
|
|
const color_type& c,
|
|
|
|
int8u cover)
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
if (!c.is_transparent())
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
pixel_type* p = pix_value_ptr(x, y, len);
|
2011-10-12 03:02:50 +00:00
|
|
|
|
2014-12-01 10:55:05 +00:00
|
|
|
if (c.is_opaque() && cover == cover_mask)
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
p->set(c);
|
|
|
|
p = p->next();
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
2014-12-01 10:55:05 +00:00
|
|
|
while (--len);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
blend_pix(p, c, cover);
|
|
|
|
p = p->next();
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
2014-12-01 10:55:05 +00:00
|
|
|
while (--len);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
void blend_vline(int x, int y,
|
2014-12-01 10:55:05 +00:00
|
|
|
unsigned len,
|
2011-10-12 03:02:50 +00:00
|
|
|
const color_type& c,
|
|
|
|
int8u cover)
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
if (!c.is_transparent())
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
if (c.is_opaque() && cover == cover_mask)
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
pix_value_ptr(x, y++, 1)->set(c);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
2014-12-01 10:55:05 +00:00
|
|
|
while (--len);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
blend_pix(pix_value_ptr(x, y++, 1), c, cover);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
2014-12-01 10:55:05 +00:00
|
|
|
while (--len);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
void blend_solid_hspan(int x, int y,
|
2014-12-01 10:55:05 +00:00
|
|
|
unsigned len,
|
2011-10-12 03:02:50 +00:00
|
|
|
const color_type& c,
|
|
|
|
const int8u* covers)
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
if (!c.is_transparent())
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
pixel_type* p = pix_value_ptr(x, y, len);
|
2011-10-12 03:02:50 +00:00
|
|
|
|
2014-12-01 10:55:05 +00:00
|
|
|
do
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
if (c.is_opaque() && *covers == cover_mask)
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
p->set(c);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
blend_pix(p, c, *covers);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
2014-12-01 10:55:05 +00:00
|
|
|
p = p->next();
|
2011-10-12 03:02:50 +00:00
|
|
|
++covers;
|
|
|
|
}
|
2014-12-01 10:55:05 +00:00
|
|
|
while (--len);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
void blend_solid_vspan(int x, int y,
|
2014-12-01 10:55:05 +00:00
|
|
|
unsigned len,
|
2011-10-12 03:02:50 +00:00
|
|
|
const color_type& c,
|
|
|
|
const int8u* covers)
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
if (!c.is_transparent())
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
do
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
pixel_type* p = pix_value_ptr(x, y++, 1);
|
2011-10-12 03:02:50 +00:00
|
|
|
|
2014-12-01 10:55:05 +00:00
|
|
|
if (c.is_opaque() && *covers == cover_mask)
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
p->set(c);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
blend_pix(p, c, *covers);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
++covers;
|
|
|
|
}
|
2014-12-01 10:55:05 +00:00
|
|
|
while (--len);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
void copy_color_hspan(int x, int y,
|
2014-12-01 10:55:05 +00:00
|
|
|
unsigned len,
|
2011-10-12 03:02:50 +00:00
|
|
|
const color_type* colors)
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
pixel_type* p = pix_value_ptr(x, y, len);
|
2011-10-12 03:02:50 +00:00
|
|
|
|
2014-12-01 10:55:05 +00:00
|
|
|
do
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
p->set(*colors++);
|
|
|
|
p = p->next();
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
2014-12-01 10:55:05 +00:00
|
|
|
while (--len);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
void copy_color_vspan(int x, int y,
|
2014-12-01 10:55:05 +00:00
|
|
|
unsigned len,
|
2011-10-12 03:02:50 +00:00
|
|
|
const color_type* colors)
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
do
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
pix_value_ptr(x, y++, 1)->set(*colors++);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
2014-12-01 10:55:05 +00:00
|
|
|
while (--len);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
void blend_color_hspan(int x, int y,
|
2014-12-01 10:55:05 +00:00
|
|
|
unsigned len,
|
2011-10-12 03:02:50 +00:00
|
|
|
const color_type* colors,
|
|
|
|
const int8u* covers,
|
|
|
|
int8u cover)
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
pixel_type* p = pix_value_ptr(x, y, len);
|
2011-10-12 03:02:50 +00:00
|
|
|
|
2014-12-01 10:55:05 +00:00
|
|
|
if (covers)
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
do
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
|
|
|
copy_or_blend_pix(p, *colors++, *covers++);
|
2014-12-01 10:55:05 +00:00
|
|
|
p = p->next();
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
2014-12-01 10:55:05 +00:00
|
|
|
while (--len);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
if (cover == cover_mask)
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
do
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
copy_or_blend_pix(p, *colors++);
|
|
|
|
p = p->next();
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
2014-12-01 10:55:05 +00:00
|
|
|
while (--len);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
do
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
|
|
|
copy_or_blend_pix(p, *colors++, cover);
|
2014-12-01 10:55:05 +00:00
|
|
|
p = p->next();
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
2014-12-01 10:55:05 +00:00
|
|
|
while (--len);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
void blend_color_vspan(int x, int y,
|
2014-12-01 10:55:05 +00:00
|
|
|
unsigned len,
|
2011-10-12 03:02:50 +00:00
|
|
|
const color_type* colors,
|
|
|
|
const int8u* covers,
|
|
|
|
int8u cover)
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
if (covers)
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
do
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
copy_or_blend_pix(pix_value_ptr(x, y++, 1), *colors++, *covers++);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
2014-12-01 10:55:05 +00:00
|
|
|
while (--len);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
if (cover == cover_mask)
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
do
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
copy_or_blend_pix(pix_value_ptr(x, y++, 1), *colors++);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
2014-12-01 10:55:05 +00:00
|
|
|
while (--len);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
do
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
copy_or_blend_pix(pix_value_ptr(x, y++, 1), *colors++, cover);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
2014-12-01 10:55:05 +00:00
|
|
|
while (--len);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
template<class Function> void for_each_pixel(Function f)
|
|
|
|
{
|
|
|
|
unsigned y;
|
2014-12-01 10:55:05 +00:00
|
|
|
for (y = 0; y < height(); ++y)
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
|
|
|
row_data r = m_rbuf->row(y);
|
2014-12-01 10:55:05 +00:00
|
|
|
if (r.ptr)
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
|
|
|
unsigned len = r.x2 - r.x1 + 1;
|
2014-12-01 10:55:05 +00:00
|
|
|
pixel_type* p = pix_value_ptr(r.x1, y, len);
|
2011-10-12 03:02:50 +00:00
|
|
|
do
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
f(p->c);
|
|
|
|
p = p->next();
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
2014-12-01 10:55:05 +00:00
|
|
|
while (--len);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
template<class GammaLut> void apply_gamma_dir(const GammaLut& g)
|
|
|
|
{
|
|
|
|
for_each_pixel(apply_gamma_dir_gray<color_type, GammaLut>(g));
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
template<class GammaLut> void apply_gamma_inv(const GammaLut& g)
|
|
|
|
{
|
|
|
|
for_each_pixel(apply_gamma_inv_gray<color_type, GammaLut>(g));
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
template<class RenBuf2>
|
2014-12-01 10:55:05 +00:00
|
|
|
void copy_from(const RenBuf2& from,
|
2011-10-12 03:02:50 +00:00
|
|
|
int xdst, int ydst,
|
|
|
|
int xsrc, int ysrc,
|
|
|
|
unsigned len)
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
if (const int8u* p = from.row_ptr(ysrc))
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
memmove(m_rbuf->row_ptr(xdst, ydst, len) + xdst * pix_width,
|
|
|
|
p + xsrc * pix_width,
|
2011-10-12 03:02:50 +00:00
|
|
|
len * pix_width);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2014-12-01 10:55:05 +00:00
|
|
|
// Blend from single color, using grayscale surface as alpha channel.
|
2011-10-12 03:02:50 +00:00
|
|
|
template<class SrcPixelFormatRenderer>
|
2014-12-01 10:55:05 +00:00
|
|
|
void blend_from_color(const SrcPixelFormatRenderer& from,
|
2011-10-12 03:02:50 +00:00
|
|
|
const color_type& color,
|
|
|
|
int xdst, int ydst,
|
|
|
|
int xsrc, int ysrc,
|
|
|
|
unsigned len,
|
|
|
|
int8u cover)
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
typedef typename SrcPixelFormatRenderer::pixel_type src_pixel_type;
|
|
|
|
typedef typename SrcPixelFormatRenderer::color_type src_color_type;
|
|
|
|
|
|
|
|
if (const src_pixel_type* psrc = from.pix_value_ptr(xsrc, ysrc))
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
pixel_type* pdst = pix_value_ptr(xdst, ydst, len);
|
|
|
|
|
|
|
|
do
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
copy_or_blend_pix(pdst, color, src_color_type::scale_cover(cover, psrc->c[0]));
|
|
|
|
psrc = psrc->next();
|
|
|
|
pdst = pdst->next();
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
2014-12-01 10:55:05 +00:00
|
|
|
while (--len);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2014-12-01 10:55:05 +00:00
|
|
|
// Blend from color table, using grayscale surface as indexes into table.
|
|
|
|
// Obviously, this only works for integer value types.
|
2011-10-12 03:02:50 +00:00
|
|
|
template<class SrcPixelFormatRenderer>
|
2014-12-01 10:55:05 +00:00
|
|
|
void blend_from_lut(const SrcPixelFormatRenderer& from,
|
2011-10-12 03:02:50 +00:00
|
|
|
const color_type* color_lut,
|
|
|
|
int xdst, int ydst,
|
|
|
|
int xsrc, int ysrc,
|
|
|
|
unsigned len,
|
|
|
|
int8u cover)
|
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
typedef typename SrcPixelFormatRenderer::pixel_type src_pixel_type;
|
|
|
|
|
|
|
|
if (const src_pixel_type* psrc = from.pix_value_ptr(xsrc, ysrc))
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
pixel_type* pdst = pix_value_ptr(xdst, ydst, len);
|
|
|
|
|
|
|
|
do
|
2011-10-12 03:02:50 +00:00
|
|
|
{
|
2014-12-01 10:55:05 +00:00
|
|
|
copy_or_blend_pix(pdst, color_lut[psrc->c[0]], cover);
|
|
|
|
psrc = psrc->next();
|
|
|
|
pdst = pdst->next();
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
2014-12-01 10:55:05 +00:00
|
|
|
while (--len);
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
rbuf_type* m_rbuf;
|
|
|
|
};
|
|
|
|
|
2014-12-01 10:55:05 +00:00
|
|
|
typedef blender_gray<gray8> blender_gray8;
|
|
|
|
typedef blender_gray<sgray8> blender_sgray8;
|
|
|
|
typedef blender_gray<gray16> blender_gray16;
|
|
|
|
typedef blender_gray<gray32> blender_gray32;
|
|
|
|
|
|
|
|
typedef blender_gray_pre<gray8> blender_gray8_pre;
|
|
|
|
typedef blender_gray_pre<sgray8> blender_sgray8_pre;
|
2011-10-12 03:02:50 +00:00
|
|
|
typedef blender_gray_pre<gray16> blender_gray16_pre;
|
2014-12-01 10:55:05 +00:00
|
|
|
typedef blender_gray_pre<gray32> blender_gray32_pre;
|
|
|
|
|
|
|
|
typedef pixfmt_alpha_blend_gray<blender_gray8, rendering_buffer> pixfmt_gray8;
|
|
|
|
typedef pixfmt_alpha_blend_gray<blender_sgray8, rendering_buffer> pixfmt_sgray8;
|
|
|
|
typedef pixfmt_alpha_blend_gray<blender_gray16, rendering_buffer> pixfmt_gray16;
|
|
|
|
typedef pixfmt_alpha_blend_gray<blender_gray32, rendering_buffer> pixfmt_gray32;
|
2011-10-12 03:02:50 +00:00
|
|
|
|
2014-12-01 10:55:05 +00:00
|
|
|
typedef pixfmt_alpha_blend_gray<blender_gray8_pre, rendering_buffer> pixfmt_gray8_pre;
|
|
|
|
typedef pixfmt_alpha_blend_gray<blender_sgray8_pre, rendering_buffer> pixfmt_sgray8_pre;
|
|
|
|
typedef pixfmt_alpha_blend_gray<blender_gray16_pre, rendering_buffer> pixfmt_gray16_pre;
|
|
|
|
typedef pixfmt_alpha_blend_gray<blender_gray32_pre, rendering_buffer> pixfmt_gray32_pre;
|
2011-10-12 03:02:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|