Skip to content

Commit

Permalink
Matplotlib 2.0.0b3 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jwiggins committed Aug 1, 2016
1 parent 6baeafa commit 894ae3b
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 99 deletions.
2 changes: 1 addition & 1 deletion agg-svn/agg-2.4/include/agg_basics.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
Expand Down
135 changes: 70 additions & 65 deletions agg-svn/agg-2.4/include/agg_gamma_lut.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 LinearType>
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 LinearType>
class sRGB_lut;

template<>
class sRGB_lut<float>
class sRGB_lut<float> : public sRGB_lut_base<float>
{
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<int16u>
class sRGB_lut<int16u> : public sRGB_lut_base<int16u>
{
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<int8u>
class sRGB_lut<int8u> : public sRGB_lut_base<int8u>
{
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.
Expand Down Expand Up @@ -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);
}
};

Expand Down
4 changes: 2 additions & 2 deletions agg-svn/agg-2.4/include/agg_image_accessors.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 9 additions & 5 deletions agg-svn/agg-2.4/include/agg_rasterizer_cells_aa.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#ifndef AGG_RASTERIZER_CELLS_AA_INCLUDED
#define AGG_RASTERIZER_CELLS_AA_INCLUDED

#include <stdexcept>
#include <string.h>
#include <math.h>
#include "agg_math.h"
Expand All @@ -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
Expand All @@ -63,7 +63,7 @@ namespace agg
typedef rasterizer_cells_aa<Cell> 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);
Expand Down Expand Up @@ -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<cell_type*> m_sorted_cells;
Expand Down Expand Up @@ -141,11 +142,12 @@ namespace agg

//------------------------------------------------------------------------
template<class Cell>
rasterizer_cells_aa<Cell>::rasterizer_cells_aa() :
rasterizer_cells_aa<Cell>::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(),
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions agg-svn/agg-2.4/include/agg_rasterizer_compound_aa.h
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
8 changes: 4 additions & 4 deletions agg-svn/agg-2.4/include/agg_rasterizer_scanline_aa.h
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -108,8 +108,8 @@ namespace agg

//--------------------------------------------------------------------
template<class GammaF>
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),
Expand Down
4 changes: 2 additions & 2 deletions agg-svn/agg-2.4/include/agg_rasterizer_scanline_aa_nogamma.h
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
5 changes: 0 additions & 5 deletions agg-svn/agg-2.4/include/agg_renderer_markers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions agg-svn/agg-2.4/include/agg_renderer_outline_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion agg-svn/agg-2.4/include/agg_renderer_scanline.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion agg-svn/agg-2.4/include/agg_span_image_filter_gray.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 894ae3b

Please sign in to comment.