1313#include < stdlib.h>
1414
1515#include " _backend_agg.h"
16+ #include " _transforms.h"
1617
1718extern " C" {
1819#ifdef __APPLE__
@@ -41,10 +42,15 @@ PyAggImagePhoto(ClientData clientdata, Tcl_Interp* interp,
4142 Tk_PhotoHandle photo;
4243 Tk_PhotoImageBlock block;
4344 PyObject* aggo;
45+
46+ // vars for blitting
47+ PyObject* bboxo;
48+ Bbox* bbox;
49+ double l,b,r,t;
4450
4551 long mode;
4652 long nval;
47- if (argc != 4 ) {
53+ if (argc != 5 ) {
4854 Tcl_AppendResult (interp, " usage: " , argv[0 ],
4955 " destPhoto srcImage" , (char *) NULL );
5056 return TCL_ERROR;
@@ -69,6 +75,23 @@ PyAggImagePhoto(ClientData clientdata, Tcl_Interp* interp,
6975 return TCL_ERROR;
7076 }
7177
78+ /* check for bbox/blitting */
79+ bboxo = (PyObject*)atol (argv[4 ]);
80+ if (bboxo != Py_None) {
81+ bbox = (Bbox*)bboxo;
82+ l = bbox->ll_api ()->x_api ()->val ();
83+ b = bbox->ll_api ()->y_api ()->val ();
84+ r = bbox->ur_api ()->x_api ()->val ();
85+ t = bbox->ur_api ()->y_api ()->val ();
86+ // int casts messes up precision, so must round
87+ l = round (l);
88+ b = round (b);
89+ r = round (r);
90+ t = round (t);
91+ } else {
92+ bbox = NULL ;
93+ }
94+
7295 /* setup tkblock */
7396 block.pixelSize = 1 ;
7497 if (mode == 0 ) {
@@ -87,16 +110,22 @@ PyAggImagePhoto(ClientData clientdata, Tcl_Interp* interp,
87110 block.pixelSize = 4 ;
88111 nval = 4 ;
89112 }
90- }
113+ }
114+
91115 block.width = aggRenderer->get_width ();
92116 block.height = aggRenderer->get_height ();
93117 // std::cout << "w,h: " << block.width << " " << block.height << std::endl;
94118 block.pitch = block.width * nval;
95119 block.pixelPtr = aggRenderer->pixBuffer ;
96- /* Clear current contents */
97- Tk_PhotoBlank (photo);
98- /* Copy opaque block to photo image, and leave the rest to TK */
99- Tk_PhotoPutBlock (photo, &block, 0 , 0 , block.width , block.height );
120+
121+ if (bbox) {
122+ Tk_PhotoPutBlock (photo, &block, (int )l, (int )b, (int )(r-l), (int )(t-b));
123+ } else {
124+ /* Clear current contents */
125+ Tk_PhotoBlank (photo);
126+ /* Copy opaque block to photo image, and leave the rest to TK */
127+ Tk_PhotoPutBlock (photo, &block, 0 , 0 , block.width , block.height );
128+ }
100129
101130 return TCL_OK;
102131}
0 commit comments