diff --git a/agg-svn/agg-2.4/include/agg_basics.h b/agg-svn/agg-2.4/include/agg_basics.h index 3097130..112bb35 100644 --- a/agg-svn/agg-2.4/include/agg_basics.h +++ b/agg-svn/agg-2.4/include/agg_basics.h @@ -228,7 +228,7 @@ namespace agg { AGG_INLINE static unsigned mul(unsigned a, unsigned b) { - unsigned q = a * b + (1 << (Shift-1)); + register unsigned q = a * b + (1 << (Shift-1)); return (q + (q >> Shift)) >> Shift; } }; diff --git a/agg-svn/agg-2.4/include/agg_gamma_lut.h b/agg-svn/agg-2.4/include/agg_gamma_lut.h index e308736..4616c45 100644 --- a/agg-svn/agg-2.4/include/agg_gamma_lut.h +++ b/agg-svn/agg-2.4/include/agg_gamma_lut.h @@ -122,103 +122,107 @@ namespace agg // sRGB support classes // + // Optimized sRGB lookup table. The direct conversion (sRGB to linear) + // is a straightforward lookup. The inverse conversion (linear to sRGB) + // is implemented using binary search. + template + class sRGB_lut_base + { + public: + LinearType dir(int8u v) const + { + return m_dir_table[v]; + } + + int8u inv(LinearType v) const + { + // Unrolled binary search. + int8u x = 0; + if (v > m_inv_table[128]) x = 128; + if (v > m_inv_table[x + 64]) x += 64; + if (v > m_inv_table[x + 32]) x += 32; + if (v > m_inv_table[x + 16]) x += 16; + if (v > m_inv_table[x + 8]) x += 8; + if (v > m_inv_table[x + 4]) x += 4; + if (v > m_inv_table[x + 2]) x += 2; + if (v > m_inv_table[x + 1]) x += 1; + return x; + } + + protected: + LinearType m_dir_table[256]; + LinearType m_inv_table[256]; + + // Only derived classes may instantiate. + sRGB_lut_base() + { + } + }; + // sRGB_lut - implements sRGB conversion for the various types. // Base template is undefined, specializations are provided below. template class sRGB_lut; template<> - class sRGB_lut + class sRGB_lut : public sRGB_lut_base { public: - sRGB_lut() - { - // Generate lookup tables. - for (int i = 0; i <= 255; ++i) - { - m_dir_table[i] = float(sRGB_to_linear(i / 255.0)); - } - for (int i = 0; i <= 65535; ++i) - { - m_inv_table[i] = uround(255.0 * linear_to_sRGB(i / 65535.0)); - } - } - - float dir(int8u v) const - { - return m_dir_table[v]; - } - - int8u inv(float v) const - { - return m_inv_table[int16u(0.5 + v * 65535)]; - } - - private: - float m_dir_table[256]; - int8u m_inv_table[65536]; + sRGB_lut() + { + // Generate lookup tables. + m_dir_table[0] = 0; + m_inv_table[0] = 0; + for (unsigned i = 1; i <= 255; ++i) + { + // Floating-point RGB is in range [0,1]. + m_dir_table[i] = float(sRGB_to_linear(i / 255.0)); + m_inv_table[i] = float(sRGB_to_linear((i - 0.5) / 255.0)); + } + } }; template<> - class sRGB_lut + class sRGB_lut : public sRGB_lut_base { public: sRGB_lut() { // Generate lookup tables. - for (int i = 0; i <= 255; ++i) + m_dir_table[0] = 0; + m_inv_table[0] = 0; + for (unsigned i = 1; i <= 255; ++i) { + // 16-bit RGB is in range [0,65535]. m_dir_table[i] = uround(65535.0 * sRGB_to_linear(i / 255.0)); + m_inv_table[i] = uround(65535.0 * sRGB_to_linear((i - 0.5) / 255.0)); } - for (int i = 0; i <= 65535; ++i) - { - m_inv_table[i] = uround(255.0 * linear_to_sRGB(i / 65535.0)); - } - } - - int16u dir(int8u v) const - { - return m_dir_table[v]; - } - - int8u inv(int16u v) const - { - return m_inv_table[v]; - } - - private: - int16u m_dir_table[256]; - int8u m_inv_table[65536]; - }; + } + }; template<> - class sRGB_lut + class sRGB_lut : public sRGB_lut_base { public: sRGB_lut() { // Generate lookup tables. - for (int i = 0; i <= 255; ++i) + m_dir_table[0] = 0; + m_inv_table[0] = 0; + for (unsigned i = 1; i <= 255; ++i) { + // 8-bit RGB is handled with simple bidirectional lookup tables. m_dir_table[i] = uround(255.0 * sRGB_to_linear(i / 255.0)); m_inv_table[i] = uround(255.0 * linear_to_sRGB(i / 255.0)); } } - int8u dir(int8u v) const - { - return m_dir_table[v]; - } - - int8u inv(int8u v) const + int8u inv(int8u v) const { + // In this case, the inverse transform is a simple lookup. return m_inv_table[v]; } - - private: - int8u m_dir_table[256]; - int8u m_inv_table[256]; - }; + }; // Common base class for sRGB_conv objects. Defines an internal // sRGB_lut object so that users don't have to. @@ -256,13 +260,14 @@ namespace agg public: static float alpha_from_sRGB(int8u x) { - static const double y = 1 / 255.0; - return float(x * y); + return float(x / 255.0); } static int8u alpha_to_sRGB(float x) { - return int8u(0.5 + x * 255); + if (x <= 0) return 0; + else if (x >= 1) return 255; + else return int8u(0.5 + x * 255); } }; diff --git a/agg-svn/agg-2.4/include/agg_image_accessors.h b/agg-svn/agg-2.4/include/agg_image_accessors.h index c651d6d..7c39028 100644 --- a/agg-svn/agg-2.4/include/agg_image_accessors.h +++ b/agg-svn/agg-2.4/include/agg_image_accessors.h @@ -174,8 +174,8 @@ namespace agg private: AGG_INLINE const int8u* pixel() const { - int x = m_x; - int y = m_y; + register int x = m_x; + register int y = m_y; if(x < 0) x = 0; if(y < 0) y = 0; if(x >= (int)m_pixf->width()) x = m_pixf->width() - 1; diff --git a/agg-svn/agg-2.4/include/agg_rasterizer_cells_aa.h b/agg-svn/agg-2.4/include/agg_rasterizer_cells_aa.h index 1d797bf..a7dc80d 100644 --- a/agg-svn/agg-2.4/include/agg_rasterizer_cells_aa.h +++ b/agg-svn/agg-2.4/include/agg_rasterizer_cells_aa.h @@ -29,6 +29,7 @@ #ifndef AGG_RASTERIZER_CELLS_AA_INCLUDED #define AGG_RASTERIZER_CELLS_AA_INCLUDED +#include #include #include #include "agg_math.h" @@ -48,8 +49,7 @@ namespace agg cell_block_shift = 12, cell_block_size = 1 << cell_block_shift, cell_block_mask = cell_block_size - 1, - cell_block_pool = 256, - cell_block_limit = 1024 + cell_block_pool = 256 }; struct sorted_y @@ -63,7 +63,7 @@ namespace agg typedef rasterizer_cells_aa self_type; ~rasterizer_cells_aa(); - rasterizer_cells_aa(); + rasterizer_cells_aa(unsigned cell_block_limit=1024); void reset(); void style(const cell_type& style_cell); @@ -107,6 +107,7 @@ namespace agg unsigned m_max_blocks; unsigned m_curr_block; unsigned m_num_cells; + unsigned m_cell_block_limit; cell_type** m_cells; cell_type* m_curr_cell_ptr; pod_vector m_sorted_cells; @@ -141,11 +142,12 @@ namespace agg //------------------------------------------------------------------------ template - rasterizer_cells_aa::rasterizer_cells_aa() : + rasterizer_cells_aa::rasterizer_cells_aa(unsigned cell_block_limit) : m_num_blocks(0), m_max_blocks(0), m_curr_block(0), m_num_cells(0), + m_cell_block_limit(cell_block_limit), m_cells(0), m_curr_cell_ptr(0), m_sorted_cells(), @@ -183,7 +185,9 @@ namespace agg { if((m_num_cells & cell_block_mask) == 0) { - if(m_num_blocks >= cell_block_limit) return; + if(m_num_blocks >= m_cell_block_limit) { + throw std::overflow_error("Exceeded cell block limit"); + } allocate_block(); } *m_curr_cell_ptr++ = m_curr_cell; diff --git a/agg-svn/agg-2.4/include/agg_rasterizer_compound_aa.h b/agg-svn/agg-2.4/include/agg_rasterizer_compound_aa.h index 165806d..41d5080 100644 --- a/agg-svn/agg-2.4/include/agg_rasterizer_compound_aa.h +++ b/agg-svn/agg-2.4/include/agg_rasterizer_compound_aa.h @@ -109,8 +109,8 @@ namespace agg }; //-------------------------------------------------------------------- - rasterizer_compound_aa() : - m_outline(), + rasterizer_compound_aa(unsigned cell_block_limit=1024) : + m_outline(cell_block_limit), m_clipper(), m_filling_rule(fill_non_zero), m_layer_order(layer_direct), diff --git a/agg-svn/agg-2.4/include/agg_rasterizer_scanline_aa.h b/agg-svn/agg-2.4/include/agg_rasterizer_scanline_aa.h index ffc2ddf..15a89a9 100644 --- a/agg-svn/agg-2.4/include/agg_rasterizer_scanline_aa.h +++ b/agg-svn/agg-2.4/include/agg_rasterizer_scanline_aa.h @@ -93,8 +93,8 @@ namespace agg }; //-------------------------------------------------------------------- - rasterizer_scanline_aa() : - m_outline(), + rasterizer_scanline_aa(unsigned cell_block_limit=1024) : + m_outline(cell_block_limit), m_clipper(), m_filling_rule(fill_non_zero), m_auto_close(true), @@ -108,8 +108,8 @@ namespace agg //-------------------------------------------------------------------- template - rasterizer_scanline_aa(const GammaF& gamma_function) : - m_outline(), + rasterizer_scanline_aa(const GammaF& gamma_function, unsigned cell_block_limit) : + m_outline(cell_block_limit), m_clipper(m_outline), m_filling_rule(fill_non_zero), m_auto_close(true), diff --git a/agg-svn/agg-2.4/include/agg_rasterizer_scanline_aa_nogamma.h b/agg-svn/agg-2.4/include/agg_rasterizer_scanline_aa_nogamma.h index 07858b3..52de62d 100644 --- a/agg-svn/agg-2.4/include/agg_rasterizer_scanline_aa_nogamma.h +++ b/agg-svn/agg-2.4/include/agg_rasterizer_scanline_aa_nogamma.h @@ -121,8 +121,8 @@ namespace agg }; //-------------------------------------------------------------------- - rasterizer_scanline_aa_nogamma() : - m_outline(), + rasterizer_scanline_aa_nogamma(unsigned cell_block_limit=1024) : + m_outline(cell_block_limit), m_clipper(), m_filling_rule(fill_non_zero), m_auto_close(true), diff --git a/agg-svn/agg-2.4/include/agg_renderer_markers.h b/agg-svn/agg-2.4/include/agg_renderer_markers.h index 6ff0534..820f753 100644 --- a/agg-svn/agg-2.4/include/agg_renderer_markers.h +++ b/agg-svn/agg-2.4/include/agg_renderer_markers.h @@ -572,7 +572,6 @@ namespace agg case marker_dash: dash(x, y, r); break; case marker_dot: dot(x, y, r); break; case marker_pixel: pixel(x, y, r); break; - case end_of_markers: break; } } @@ -614,7 +613,6 @@ namespace agg case marker_dash: do { dash (int(*x), int(*y), int(r)); ++x; ++y; } while(--n); break; case marker_dot: do { dot (int(*x), int(*y), int(r)); ++x; ++y; } while(--n); break; case marker_pixel: do { pixel (int(*x), int(*y), int(r)); ++x; ++y; } while(--n); break; - case end_of_markers: break; } } @@ -643,7 +641,6 @@ namespace agg case marker_dash: do { dash (int(*x), int(*y), int(*r)); ++x; ++y; ++r; } while(--n); break; case marker_dot: do { dot (int(*x), int(*y), int(*r)); ++x; ++y; ++r; } while(--n); break; case marker_pixel: do { pixel (int(*x), int(*y), int(*r)); ++x; ++y; ++r; } while(--n); break; - case end_of_markers: break; } } @@ -672,7 +669,6 @@ namespace agg case marker_dash: do { base_type::fill_color(*fc); dash (int(*x), int(*y), int(*r)); ++x; ++y; ++r; ++fc; } while(--n); break; case marker_dot: do { base_type::fill_color(*fc); dot (int(*x), int(*y), int(*r)); ++x; ++y; ++r; ++fc; } while(--n); break; case marker_pixel: do { base_type::fill_color(*fc); pixel (int(*x), int(*y), int(*r)); ++x; ++y; ++r; ++fc; } while(--n); break; - case end_of_markers: break; } } @@ -701,7 +697,6 @@ namespace agg case marker_dash: do { base_type::fill_color(*fc); base_type::line_color(*lc); dash (int(*x), int(*y), int(*r)); ++x; ++y; ++r; ++fc; ++lc; } while(--n); break; case marker_dot: do { base_type::fill_color(*fc); base_type::line_color(*lc); dot (int(*x), int(*y), int(*r)); ++x; ++y; ++r; ++fc; ++lc; } while(--n); break; case marker_pixel: do { base_type::fill_color(*fc); base_type::line_color(*lc); pixel (int(*x), int(*y), int(*r)); ++x; ++y; ++r; ++fc; ++lc; } while(--n); break; - case end_of_markers: break; } } }; diff --git a/agg-svn/agg-2.4/include/agg_renderer_outline_image.h b/agg-svn/agg-2.4/include/agg_renderer_outline_image.h index 2ccc5be..8abb9fa 100644 --- a/agg-svn/agg-2.4/include/agg_renderer_outline_image.h +++ b/agg-svn/agg-2.4/include/agg_renderer_outline_image.h @@ -51,8 +51,8 @@ namespace agg int h = m_source.height() - 1; int y1 = ifloor(src_y); int y2 = y1 + 1; - rgba pix1 = (y1 < 0) ? rgba::no_color() : rgba(m_source.pixel(x, y1)); - rgba pix2 = (y2 > h) ? rgba::no_color() : rgba(m_source.pixel(x, y2)); + rgba pix1 = (y1 < 0) ? rgba::no_color() : m_source.pixel(x, y1); + rgba pix2 = (y2 > h) ? rgba::no_color() : m_source.pixel(x, y2); return pix1.gradient(pix2, src_y - y1); } else diff --git a/agg-svn/agg-2.4/include/agg_renderer_scanline.h b/agg-svn/agg-2.4/include/agg_renderer_scanline.h index 68d2b4a..6d65056 100644 --- a/agg-svn/agg-2.4/include/agg_renderer_scanline.h +++ b/agg-svn/agg-2.4/include/agg_renderer_scanline.h @@ -65,7 +65,7 @@ namespace agg // "rgba8" is needed. Otherwise it will be implicitly // converted in the loop many times. //---------------------- - typename BaseRenderer::color_type ren_color = color; + typename BaseRenderer::color_type ren_color(color); sl.reset(ras.min_x(), ras.max_x()); while(ras.sweep_scanline(sl)) diff --git a/agg-svn/agg-2.4/include/agg_span_image_filter_gray.h b/agg-svn/agg-2.4/include/agg_span_image_filter_gray.h index 4bc9c00..e2c688e 100644 --- a/agg-svn/agg-2.4/include/agg_span_image_filter_gray.h +++ b/agg-svn/agg-2.4/include/agg_span_image_filter_gray.h @@ -490,7 +490,7 @@ namespace agg fg_ptr = (const value_type*)base_type::source().next_y(); } - fg >>= image_filter_shift; + fg = color_type::downshift(fg, image_filter_shift); if(fg < 0) fg = 0; if(fg > color_type::full_value()) fg = color_type::full_value(); span->v = (value_type)fg; diff --git a/agg-svn/agg-2.4/include/agg_trans_affine.h b/agg-svn/agg-2.4/include/agg_trans_affine.h index 1a61163..8933d76 100644 --- a/agg-svn/agg-2.4/include/agg_trans_affine.h +++ b/agg-svn/agg-2.4/include/agg_trans_affine.h @@ -292,7 +292,7 @@ namespace agg //------------------------------------------------------------------------ inline void trans_affine::transform(double* x, double* y) const { - double tmp = *x; + register double tmp = *x; *x = tmp * sx + *y * shx + tx; *y = tmp * shy + *y * sy + ty; } @@ -300,7 +300,7 @@ namespace agg //------------------------------------------------------------------------ inline void trans_affine::transform_2x2(double* x, double* y) const { - double tmp = *x; + register double tmp = *x; *x = tmp * sx + *y * shx; *y = tmp * shy + *y * sy; } @@ -308,9 +308,9 @@ namespace agg //------------------------------------------------------------------------ inline void trans_affine::inverse_transform(double* x, double* y) const { - double d = determinant_reciprocal(); - double a = (*x - tx) * d; - double b = (*y - ty) * d; + register double d = determinant_reciprocal(); + register double a = (*x - tx) * d; + register double b = (*y - ty) * d; *x = a * sy - b * shx; *y = b * sx - a * shy; } diff --git a/agg-svn/agg-2.4/src/ctrl/agg_scale_ctrl.cpp b/agg-svn/agg-2.4/src/ctrl/agg_scale_ctrl.cpp index 0f35ea6..7f16779 100644 --- a/agg-svn/agg-2.4/src/ctrl/agg_scale_ctrl.cpp +++ b/agg-svn/agg-2.4/src/ctrl/agg_scale_ctrl.cpp @@ -415,9 +415,9 @@ namespace agg m_value1 = m_value2 - dv; } return true; - default: - return false; } + + return false; } diff --git a/agg-svn/agg-2.4/src/platform/X11/agg_platform_support.cpp b/agg-svn/agg-2.4/src/platform/X11/agg_platform_support.cpp index 396f12b..46b874d 100644 --- a/agg-svn/agg-2.4/src/platform/X11/agg_platform_support.cpp +++ b/agg-svn/agg-2.4/src/platform/X11/agg_platform_support.cpp @@ -702,7 +702,7 @@ namespace agg { fprintf(stderr, "RGB masks are not compatible with AGG pixel formats:\n" - "R=%08lx, R=%08lx, B=%08lx\n", r_mask, g_mask, b_mask); + "R=%08x, R=%08x, B=%08x\n", r_mask, g_mask, b_mask); XCloseDisplay(m_specific->m_display); return false; } diff --git a/agg-svn/agg-2.4/src/platform/win32/agg_platform_support.cpp b/agg-svn/agg-2.4/src/platform/win32/agg_platform_support.cpp index ea91238..d9eba30 100644 --- a/agg-svn/agg-2.4/src/platform/win32/agg_platform_support.cpp +++ b/agg-svn/agg-2.4/src/platform/win32/agg_platform_support.cpp @@ -1480,7 +1480,7 @@ namespace agg tok.len = 0; if(m_src_string == 0 || m_start == -1) return tok; - const char *pstr = m_src_string + m_start; + register const char *pstr = m_src_string + m_start; if(*pstr == 0) {