I am really close on having blit work for the tkagg.
> I committed my changes. There is one problem left I was
> hoping you could help on. I blit the axes in the right
> place, but it is blitting the upper-left of the whole
> figure. Running your test script below, this is easily
> seen. How do I pass in just the pixmap of the area of
> interest?
You are very close
You need to follow the logic of the "destbuffer" in _gtkagg src. This
will either use the who agg pixBuffer if bbox is None, or else copy
out the proper region of the agg pixel buffer into destbuffer. There
is a boolean "needfree" that keeps track of whether you need to free
the memory. This is true when bbox!=None since we have to allocate a
temporary buffer to copy the rectangle of the pixBuffer into.
You then pass destbuffer instead of pixBuffer off to the tk drawing
routine.
Thanks!
JDH
bool needfree = false;
agg::int8u *destbuffer = NULL;
if (args[2].ptr() == Py_None) {
//bbox is None; copy the entire image
destbuffer = aggRenderer->pixBuffer;
destwidth = srcwidth;
destheight = srcheight;
deststride = srcstride;
}
else {
//bbox is not None; copy the image in the bbox
Bbox* clipbox = static_cast<Bbox*>(args[2].ptr());
double l = clipbox->ll_api()->x_api()->val() ;
double b = clipbox->ll_api()->y_api()->val();
double r = clipbox->ur_api()->x_api()->val() ;
double t = clipbox->ur_api()->y_api()->val() ;
//std::cout << b << " "
// << t << " ";
destx = (int)l;
desty = srcheight-(int)t;
destwidth = (int)(r-l);
destheight = (int)(t-b);
deststride = destwidth*4;
needfree = true;
destbuffer = new agg::int8u[deststride*destheight];
if (destbuffer ==NULL) {
throw Py::MemoryError("_gtkagg could not allocate memory for destbuffer");
}
agg::rendering_buffer destrbuf;
destrbuf.attach(destbuffer, destwidth, destheight, deststride);
pixfmt destpf(destrbuf);
renderer_base destrb(destpf);
//destrb.clear(agg::rgba(1, 0, 0));
//std::cout << "rect " << r << " " << srcheight << " " << b << " ";
agg::rect_base<int> region(destx, desty, (int)r, srcheight-(int)b);
destrb.copy_from(*aggRenderer->renderingBuffer, ®ion,
-destx, -desty);
}
gdk_draw_rgb_32_image(drawable, gc, destx, desty,
destwidth,
destheight,
GDK_RGB_DITHER_NORMAL,
destbuffer,
deststride);
if (needfree) delete destbuffer;
···
- Charlie