Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Convert Agg extension to pybind11#27011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ksunden merged 6 commits intomatplotlib:mainfromQuLogic:agg-pybind11
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletionssrc/_backend_agg.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,6 +29,16 @@ RendererAgg::RendererAgg(unsigned int width, unsigned int height, double dpi)
lastclippath(NULL),
_fill_color(agg::rgba(1, 1, 1, 0))
{
if (dpi <= 0.0) {
throw std::range_error("dpi must be positive");
}

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

unsigned stride(width * 4);

pixBuffer = new agg::int8u[NUMBYTES];
Expand Down
29 changes: 24 additions & 5 deletionssrc/_backend_agg.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,8 +6,11 @@
#ifndef MPL_BACKEND_AGG_H
#define MPL_BACKEND_AGG_H

#include <pybind11/pybind11.h>

#include <cmath>
#include <algorithm>
#include <functional>

#include "agg_alpha_mask_u8.h"
#include "agg_conv_curve.h"
Expand DownExpand Up@@ -40,6 +43,8 @@
#include "array.h"
#include "agg_workaround.h"

namespace py = pybind11;

/**********************************************************************/

// a helper class to pass agg::buffer objects around.
Expand DownExpand Up@@ -728,7 +733,7 @@
rendererBase.reset_clipping(true);
if (angle != 0.0) {
agg::rendering_buffer srcbuf(
image.data(), (unsigned)image.shape(1),
image.mutable_data(0, 0), (unsigned)image.shape(1),
(unsigned)image.shape(0), (unsigned)image.shape(1));
agg::pixfmt_gray8 pixf_img(srcbuf);

Expand DownExpand Up@@ -828,8 +833,9 @@
bool has_clippath = render_clippath(gc.clippath.path, gc.clippath.trans, gc.snap_mode);

agg::rendering_buffer buffer;
buffer.attach(
image.data(), (unsigned)image.shape(1), (unsigned)image.shape(0), -(int)image.shape(1) * 4);
buffer.attach(image.mutable_data(0, 0, 0),
(unsigned)image.shape(1), (unsigned)image.shape(0),
-(int)image.shape(1) * 4);
pixfmt pixf(buffer);

if (has_clippath) {
Expand DownExpand Up@@ -1226,14 +1232,27 @@
ColorArray &colors,
agg::trans_affine &trans)
{
if (points.shape(0) && !check_trailing_shape(points, "points", 3, 2)) {
throw py::error_already_set();
}
if (colors.shape(0) && !check_trailing_shape(colors, "colors", 3, 4)) {
throw py::error_already_set();
}
if (points.shape(0) != colors.shape(0)) {
throw py::value_error(
"points and colors arrays must be the same length, got " +
std::to_string(points.shape(0)) + " points and " +

Check warning on line 1244 in src/_backend_agg.h

View check run for this annotation

Codecov/ codecov/patch

src/_backend_agg.h#L1243-L1244

Added lines #L1243 - L1244 were not covered by tests
std::to_string(colors.shape(0)) + "colors");
}

theRasterizer.reset_clipping();
rendererBase.reset_clipping(true);
set_clipbox(gc.cliprect, theRasterizer);
bool has_clippath = render_clippath(gc.clippath.path, gc.clippath.trans, gc.snap_mode);

for (int i = 0; i < points.shape(0); ++i) {
typename PointArray::sub_tpoint =points.subarray(i);
typename ColorArray::sub_tcolor =colors.subarray(i);
autopoint =std::bind(points, i, std::placeholders::_1, std::placeholders::_2);
autocolor =std::bind(colors, i, std::placeholders::_1, std::placeholders::_2);

_draw_gouraud_triangle(point, color, trans, has_clippath);
}
Expand Down
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp