Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ad4a625

Browse files
committed
Make some casts in Agg usage explicit
The Agg API uses `double`s here, but the array sizes are `pybind11::ssize_t`, which are technically bigger (in some ways), and cause a warning on MSVC. We don't accept a backing surface larger than ~2^24, so there's no worry about these overflowing.
1 parent d4b45d0 commit ad4a625

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/_backend_agg.h

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ RendererAgg::_draw_path(path_t &path, bool has_clippath, const facepair_t &face,
350350
agg::trans_affine hatch_trans;
351351
hatch_trans *= agg::trans_affine_scaling(1.0, -1.0);
352352
hatch_trans *= agg::trans_affine_translation(0.0, 1.0);
353-
hatch_trans *= agg::trans_affine_scaling(hatch_size, hatch_size);
353+
hatch_trans *= agg::trans_affine_scaling(static_cast<double>(hatch_size),
354+
static_cast<double>(hatch_size));
354355
hatch_path_trans_t hatch_path_trans(hatch_path, hatch_trans);
355356
hatch_path_curve_t hatch_path_curve(hatch_path_trans);
356357
hatch_path_stroke_t hatch_path_stroke(hatch_path_curve);
@@ -739,16 +740,19 @@ inline void RendererAgg::draw_text_image(GCAgg &gc, ImageArray &image, int x, in
739740

740741
set_clipbox(gc.cliprect, theRasterizer);
741742

743+
auto image_height = static_cast<double>(image.shape(0)),
744+
image_width = static_cast<double>(image.shape(1));
745+
742746
agg::trans_affine mtx;
743-
mtx *= agg::trans_affine_translation(0, -image.shape(0));
747+
mtx *= agg::trans_affine_translation(0, -image_height);
744748
mtx *= agg::trans_affine_rotation(-angle * (agg::pi / 180.0));
745749
mtx *= agg::trans_affine_translation(x, y);
746750

747751
agg::path_storage rect;
748752
rect.move_to(0, 0);
749-
rect.line_to(image.shape(1), 0);
750-
rect.line_to(image.shape(1), image.shape(0));
751-
rect.line_to(0, image.shape(0));
753+
rect.line_to(image_width, 0);
754+
rect.line_to(image_width, image_height);
755+
rect.line_to(0, image_height);
752756
rect.line_to(0, 0);
753757
agg::conv_transform<agg::path_storage> rect2(rect, mtx);
754758

@@ -842,12 +846,15 @@ inline void RendererAgg::draw_image(GCAgg &gc,
842846
agg::trans_affine mtx;
843847
agg::path_storage rect;
844848

845-
mtx *= agg::trans_affine_translation((int)x, (int)(height - (y + image.shape(0))));
849+
auto image_height = static_cast<double>(image.shape(0)),
850+
image_width = static_cast<double>(image.shape(1));
851+
852+
mtx *= agg::trans_affine_translation((int)x, (int)(height - (y + image_height)));
846853

847854
rect.move_to(0, 0);
848-
rect.line_to(image.shape(1), 0);
849-
rect.line_to(image.shape(1), image.shape(0));
850-
rect.line_to(0, image.shape(0));
855+
rect.line_to(image_width, 0);
856+
rect.line_to(image_width, image_height);
857+
rect.line_to(0, image_height);
851858
rect.line_to(0, 0);
852859

853860
agg::conv_transform<agg::path_storage> rect2(rect, mtx);

src/_image_resample.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,8 @@ class span_conv_alpha
566566
{
567567
if (m_alpha != 1.0) {
568568
do {
569-
span->a *= m_alpha;
569+
span->a = static_cast<typename color_type::value_type>(
570+
static_cast<typename color_type::calc_type>(span->a) * m_alpha);
570571
++span;
571572
} while (--len);
572573
}

0 commit comments

Comments
 (0)