2
2
// Anti-Grain Geometry - Version 2.4
3
3
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
5
// Permission to copy, use, modify, sell and distribute this software
6
// is granted provided this copyright notice appears in all copies.
5
// Permission to copy, use, modify, sell and distribute this software
6
// is granted provided this copyright notice appears in all copies.
7
7
// This software is provided "as is" without express or implied
8
8
// warranty, and with no claim as to its suitability for any purpose.
13
13
// http://www.antigrain.com
14
14
//----------------------------------------------------------------------------
16
// Adaptation for 32-bit screen coordinates (scanline32_u) has been sponsored by
16
// Adaptation for 32-bit screen coordinates (scanline32_u) has been sponsored by
17
17
// Liberty Technology Systems, Inc., visit http://lib-sys.com
19
19
// Liberty Technology Systems, Inc. is the provider of
20
20
// PostScript and PDF technology for software developers.
22
22
//----------------------------------------------------------------------------
24
24
#ifndef AGG_SCANLINE_U_INCLUDED
33
33
// Unpacked scanline container class
35
// This class is used to transfer data from a scanline rasterizer
36
// to the rendering buffer. It's organized very simple. The class stores
37
// information of horizontal spans to render it into a pixel-map buffer.
38
// Each span has staring X, length, and an array of bytes that determine the
39
// cover-values for each pixel.
40
// Before using this class you should know the minimal and maximal pixel
35
// This class is used to transfer data from a scanline rasterizer
36
// to the rendering buffer. It's organized very simple. The class stores
37
// information of horizontal spans to render it into a pixel-map buffer.
38
// Each span has staring X, length, and an array of bytes that determine the
39
// cover-values for each pixel.
40
// Before using this class you should know the minimal and maximal pixel
41
41
// coordinates of your scanline. The protocol of using is:
42
42
// 1. reset(min_x, max_x)
43
// 2. add_cell() / add_span() - accumulate scanline.
43
// 2. add_cell() / add_span() - accumulate scanline.
44
44
// When forming one scanline the next X coordinate must be always greater
45
45
// than the last stored one, i.e. it works only with ordered coordinates.
46
46
// 3. Call finalize(y) and render the scanline.
47
47
// 3. Call reset_spans() to prepare for the new scanline.
51
51
// Scanline provides an iterator class that allows you to extract
52
52
// the spans and the cover values for each pixel. Be aware that clipping
53
53
// has not been done yet, so you should perform it yourself.
61
61
// ************************************
63
63
// scanline_u8::const_iterator span = sl.begin();
65
// unsigned char* row = m_rbuf->row(y); // The the address of the beginning
65
// unsigned char* row = m_rbuf->row(y); // The the address of the beginning
66
66
// // of the current row
68
68
// unsigned num_spans = sl.num_spans(); // Number of spans. It's guaranteed that
69
69
// // num_spans is always greater than 0.
76
76
// int num_pix = span->len; // Number of pixels of the span.
77
77
// // Always greater than 0, still it's
78
// // better to use "int" instead of
78
// // better to use "int" instead of
79
79
// // "unsigned" because it's more
80
80
// // convenient for clipping
81
81
// int x = span->x;
86
86
// **************************************
88
88
// unsigned char* dst = row + x; // Calculate the start address of the row.
89
// // In this case we assume a simple
89
// // In this case we assume a simple
90
90
// // grayscale image 1-byte per pixel.
93
// *dst++ = *covers++; // Hypotetical rendering.
93
// *dst++ = *covers++; // Hypotetical rendering.
95
95
// while(--num_pix);
99
99
// while(--num_spans); // num_spans cannot be 0, so this loop is quite safe
100
100
//------------------------------------------------------------------------
102
102
// The question is: why should we accumulate the whole scanline when we
103
103
// could render just separate spans when they're ready?
104
// That's because using the scanline is generally faster. When is consists
104
// That's because using the scanline is generally faster. When is consists
105
105
// of more than one span the conditions for the processor cash system
106
// are better, because switching between two different areas of memory
106
// are better, because switching between two different areas of memory
107
107
// (that can be very large) occurs less frequently.
108
108
//------------------------------------------------------------------------
109
109
class scanline_u8
240
240
//==========================================================scanline_u8_am
242
242
// The scanline container with alpha-masking
244
244
//------------------------------------------------------------------------
245
template<class AlphaMask>
245
template<class AlphaMask>
246
246
class scanline_u8_am : public scanline_u8
411
m_spans.add(span(coord_type(x + m_min_x),
411
m_spans.add(span(coord_type(x + m_min_x),
415
415
m_last_x = x + len - 1;
418
418
//--------------------------------------------------------------------
424
424
//--------------------------------------------------------------------
452
452
//========================================================scanline32_u8_am
454
454
// The scanline container with alpha-masking
456
456
//------------------------------------------------------------------------
457
template<class AlphaMask>
457
template<class AlphaMask>
458
458
class scanline32_u8_am : public scanline32_u8