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

Skip to content

WIP: floating point rendering buffer #3783

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
88 changes: 12 additions & 76 deletions src/_backend_agg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,11 @@
#include "mplutils.h"
#include "MPL_isnan.h"

void BufferRegion::to_string_argb(uint8_t *buf)
{
unsigned char *pix;
unsigned char tmp;
size_t i, j;

memcpy(buf, data, height * stride);

for (i = 0; i < (size_t)height; ++i) {
pix = buf + i * stride;
for (j = 0; j < (size_t)width; ++j) {
// Convert rgba to argb
tmp = pix[2];
pix[2] = pix[0];
pix[0] = tmp;
pix += 4;
}
}
}

RendererAgg::RendererAgg(unsigned int width, unsigned int height, double dpi)
: width(width),
height(height),
dpi(dpi),
NUMBYTES(width * height * 4),
NUMBYTES(width * height * sizeof(pixfmt::color_type)),
pixBuffer(NULL),
renderingBuffer(),
alphaBuffer(NULL),
Expand All @@ -50,7 +30,7 @@ RendererAgg::RendererAgg(unsigned int width, unsigned int height, double dpi)
lastclippath(NULL),
_fill_color(agg::rgba(1, 1, 1, 0))
{
unsigned stride(width * 4);
unsigned stride(width * sizeof(pixfmt::color_type));

pixBuffer = new agg::int8u[NUMBYTES];
renderingBuffer.attach(pixBuffer, width, height, stride);
Expand All @@ -59,7 +39,8 @@ RendererAgg::RendererAgg(unsigned int width, unsigned int height, double dpi)
rendererBase.clear(_fill_color);
rendererAA.attach(rendererBase);
rendererBin.attach(rendererBase);
hatchRenderingBuffer.attach(hatchBuffer, HATCH_SIZE, HATCH_SIZE, HATCH_SIZE * 4);
hatchRenderingBuffer.attach(
hatchBuffer, HATCH_SIZE, HATCH_SIZE, HATCH_SIZE * sizeof(color_type));
}

RendererAgg::~RendererAgg()
Expand All @@ -78,54 +59,6 @@ void RendererAgg::create_alpha_buffers()
}
}

BufferRegion *RendererAgg::copy_from_bbox(agg::rect_d in_rect)
{
agg::rect_i rect(
(int)in_rect.x1, height - (int)in_rect.y2, (int)in_rect.x2, height - (int)in_rect.y1);

BufferRegion *reg = NULL;
reg = new BufferRegion(rect);

agg::rendering_buffer rbuf;
rbuf.attach(reg->get_data(), reg->get_width(), reg->get_height(), reg->get_stride());

pixfmt pf(rbuf);
renderer_base rb(pf);
rb.copy_from(renderingBuffer, &rect, -rect.x1, -rect.y1);

return reg;
}

void RendererAgg::restore_region(BufferRegion &region)
{
if (region.get_data() == NULL) {
throw "Cannot restore_region from NULL data";
}

agg::rendering_buffer rbuf;
rbuf.attach(region.get_data(), region.get_width(), region.get_height(), region.get_stride());

rendererBase.copy_from(rbuf, 0, region.get_rect().x1, region.get_rect().y1);
}

// Restore the part of the saved region with offsets
void
RendererAgg::restore_region(BufferRegion &region, int x, int y, int xx1, int yy1, int xx2, int yy2)
{
if (region.get_data() == NULL) {
throw "Cannot restore_region from NULL data";
}

agg::rect_i &rrect = region.get_rect();

agg::rect_i rect(xx1 - rrect.x1, (yy1 - rrect.y1), xx2 - rrect.x1, (yy2 - rrect.y1));

agg::rendering_buffer rbuf;
rbuf.attach(region.get_data(), region.get_width(), region.get_height(), region.get_stride());

rendererBase.copy_from(rbuf, &rect, x, y);
}

bool RendererAgg::render_clippath(py::PathIterator &clippath,
const agg::trans_affine &clippath_trans)
{
Expand Down Expand Up @@ -163,34 +96,37 @@ void RendererAgg::tostring_rgb(uint8_t *buf)
agg::rendering_buffer renderingBufferTmp;
renderingBufferTmp.attach(buf, width, height, row_len);

agg::color_conv(&renderingBufferTmp, &renderingBuffer, agg::color_conv_rgba32_to_rgb24());
agg::convert<agg::pixfmt_rgb24, pixfmt, agg::rendering_buffer>(&renderingBufferTmp, &renderingBuffer);
}

void RendererAgg::tostring_argb(uint8_t *buf)
{
//"Return the rendered buffer as an RGB string";

int row_len = width * 4;
int row_len = width * sizeof(agg::rgba8);

agg::rendering_buffer renderingBufferTmp;
renderingBufferTmp.attach(buf, width, height, row_len);
agg::color_conv(&renderingBufferTmp, &renderingBuffer, agg::color_conv_rgba32_to_argb32());

agg::convert<agg::pixfmt_argb32, pixfmt, agg::rendering_buffer>(&renderingBufferTmp, &renderingBuffer);
}

void RendererAgg::tostring_bgra(uint8_t *buf)
{
//"Return the rendered buffer as an RGB string";

int row_len = width * 4;
int row_len = width * sizeof(agg::rgba8);

agg::rendering_buffer renderingBufferTmp;
renderingBufferTmp.attach(buf, width, height, row_len);

agg::color_conv(&renderingBufferTmp, &renderingBuffer, agg::color_conv_rgba32_to_bgra32());
agg::convert<agg::pixfmt_bgra32, pixfmt, agg::rendering_buffer>(&renderingBufferTmp, &renderingBuffer);
}

agg::rect_i RendererAgg::get_content_extents()
{
// TODO: This is most definitely broken

agg::rect_i r(width, height, 0, 0);

// Looks at the alpha channel to find the minimum extents of the image
Expand Down
Loading