8000 Merge pull request #28904 from QuLogic/remove-16bit-limits · matplotlib/matplotlib@9b33fbd · GitHub
[go: up one dir, main page]

Skip to content

Commit 9b33fbd

Browse files
authored
Merge pull request #28904 from QuLogic/remove-16bit-limits
Agg: Remove 16-bit limits
2 parents f8cadb3 + 9259989 commit 9b33fbd

File tree

6 files changed

+21
-9
lines changed

6 files changed

+21
-9
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Increased Figure limits with Agg renderer
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
Figures using the Agg renderer are now limited to 2**23 pixels in each
5+
direction, instead of 2**16. Additionally, bugs that caused artists to not
6+
render past 2**15 pixels horizontally have been fixed.
7+
8+
Note that if you are using a GUI backend, it may have its own smaller limits
9+
(which may themselves depend on screen size.)

extern/agg24-svn/include/agg_rasterizer_cells_aa.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,10 @@ namespace agg
325325

326326
if(dx >= dx_limit || dx <= -dx_limit)
327327
{
328-
int cx = (x1 + x2) >> 1;
329-
int cy = (y1 + y2) >> 1;
328+
// These are overflow safe versions of (x1 + x2) >> 1; divide each by 2
329+
// first, then add 1 if both were odd.
330+
int cx = (x1 >> 1) + (x2 >> 1) + ((x1 & 1) & (x2 & 1));
331+
int cy = (y1 >> 1) + (y2 >> 1) + ((y1 & 1) & (y2 & 1));
330332
line(x1, y1, cx, cy);
331333
line(cx, cy, x2, y2);
332334
return;

lib/matplotlib/tests/test_agg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def process_image(self, padded_src, dpi):
199199

200200

201201
def test_too_large_image():
202-
fig = plt.figure(figsize=(300, 1000))
202+
fig = plt.figure(figsize=(300, 2**25))
203203
buff = io.BytesIO()
204204
with pytest.raises(ValueError):
205205
fig.savefig(buff)

src/_backend_agg.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ RendererAgg::RendererAgg(unsigned int width, unsigned int height, double dpi)
3333
throw std::range_error("dpi must be positive");
3434
}
3535

36-
if (width >= 1 << 16 || height >= 1 << 16) {
36+
if (width >= 1 << 23 || height >= 1 << 23) {
3737
throw std::range_error(
3838
"Image size of " + std::to_string(width) + "x" + std::to_string(height) +
39-
" pixels is too large. It must be less than 2^16 in each direction.");
39+
" pixels is too large. It must be less than 2^23 in each direction.");
4040
}
4141

4242
unsigned stride(width * 4);

src/_backend_agg.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ class RendererAgg
117117
typedef agg::renderer_scanline_bin_solid<renderer_base> renderer_bin;
118118
typedef agg::rasterizer_scanline_aa<agg::rasterizer_sl_clip_dbl> rasterizer;
119119

120-
typedef agg::scanline_p8 scanline_p8;
121-
typedef agg::scanline_bin scanline_bin;
120+
typedef agg::scanline32_p8 scanline_p8;
121+
typedef agg::scanline32_bin scanline_bin;
122122
typedef agg::amask_no_clip_gray8 alpha_mask_type;
123-
typedef agg::scanline_u8_am<alpha_mask_type> scanline_am;
123+
typedef agg::scanline32_u8_am<alpha_mask_type> scanline_am;
124124

125125
typedef agg::renderer_base<agg::pixfmt_gray8> renderer_base_alpha_mask_type;
126126
typedef agg::renderer_scanline_aa_solid<renderer_base_alpha_mask_type> renderer_alpha_mask_type;

src/_image_resample.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ void resample(
712712

713713
using renderer_t = agg::renderer_base<output_pixfmt_t>;
714714
using rasterizer_t = agg::rasterizer_scanline_aa<agg::rasterizer_sl_clip_dbl>;
715+
using scanline_t = agg::scanline32_u8;
715716

716717
using reflect_t = agg::wrap_mode_reflect;
717718
using image_accessor_t = agg::image_accessor_wrap<input_pixfmt_t, reflect_t, reflect_t>;
@@ -739,7 +740,7 @@ void resample(
739740

740741
span_alloc_t span_alloc;
741742
rasterizer_t rasterizer;
742-
agg::scanline_u8 scanline;
743+
scanline_t scanline;
743744

744745
span_conv_alpha_t conv_alpha(params.alpha);
745746

0 commit comments

Comments
 (0)
0