File: agg_span_pattern_rgba32.h

package info (click to toggle)
aggdraw 1.3.9%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,456 kB
  • sloc: cpp: 41,441; python: 178; sh: 29; makefile: 17
file content (77 lines) | stat: -rw-r--r-- 2,848 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.2
// Copyright (C) 2002-2004 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software 
// is granted provided this copyright notice appears in all copies. 
// 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
//----------------------------------------------------------------------------


#ifndef AGG_SPAN_PATTERN_RGBA32_INCLUDED
#define AGG_SPAN_PATTERN_RGBA32_INCLUDED

#include "agg_basics.h"
#include "agg_pixfmt_rgba32.h"
#include "agg_span_pattern.h"

namespace agg
{

    //======================================================span_pattern_rgba32
    template<class Order, class Allocator = span_allocator<rgba8> >
    class span_pattern_rgba32 : public span_pattern<rgba8, int8u, Allocator>
    {
    public:
        typedef Allocator alloc_type;
        typedef rgba8 color_type;
        typedef span_pattern<color_type, int8u, alloc_type> base_type;

        //--------------------------------------------------------------------
        span_pattern_rgba32(alloc_type& alloc) : base_type(alloc) {}

        //----------------------------------------------------------------
        span_pattern_rgba32(alloc_type& alloc,
                            const rendering_buffer& src, 
                            unsigned offset_x, unsigned offset_y) :
            base_type(alloc, src, offset_x, offset_y, 0)
        {}

        //--------------------------------------------------------------------
        color_type* generate(int x, int y, unsigned len)
        {   
            color_type* span = base_type::allocator().span();
            unsigned sx = (base_type::offset_x() + x) % base_type::source_image().width();
            unsigned wp = base_type::source_image().width() << 2;
            const int8u* p = base_type::source_image().row((base_type::offset_y() + y) % base_type::source_image().height());
            p += sx << 2;
            do
            {
                span->r = p[Order::R];
                span->g = p[Order::G];
                span->b = p[Order::B];
                span->a = p[Order::A];
                p += 4;
                ++sx;
                ++span;
                if(sx >= base_type::source_image().width())
                {
                    sx -= base_type::source_image().width();
                    p -= wp;
                }
            }
            while(--len);
            return base_type::allocator().span();
        }
    };

}

#endif