tkagg animation

  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 :slight_smile:

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, &region,
           -destx, -desty);
      
    }

    gdk_draw_rgb_32_image(drawable, gc, destx, desty,
        destwidth,
        destheight,
        GDK_RGB_DITHER_NORMAL,
        destbuffer,
        deststride);
    
    if (needfree) delete destbuffer;

···

- Charlie

Alright, I think its ready to go. I can't say I am thrilled with the performance of the TkAgg compared to the GtkAgg. I get about 62fps compared to 112fps for gtkagg. It is still a LOT faster.
  FYI, the current state of examples/animation_blit.py does nothing, and you print a fps for 200 frames when only 50 are actually drawn giving an unrealistically high fps measurement.
  Finally, could you please send me a windows-2.4 binary of current cvs. I have a project that I am wanting to use the blitting for the tkagg and I want to test on windows. I don't have a build environment for it. If it is too much trouble, it is not a big deal.

Thanks,
  Charlie

John Hunter wrote:

···

"Charles" == Charles Moad <cmoad@...209...> writes:

    > 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 :slight_smile:

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, &region, -destx, -desty);
      
    gdk_draw_rgb_32_image(drawable, gc, destx, desty, destwidth, destheight, GDK_RGB_DITHER_NORMAL,
        destbuffer,
        deststride);
        if (needfree) delete destbuffer;

    > - Charlie