15
15
You should have received a copy of the GNU General Public License
16
16
along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
*/
18
+
18
19
#include <math.h>
19
20
#include <string.h>
20
21
#include <errno.h>
21
22
#include <pthread.h>
23
+ #include <assert.h>
22
24
#include <libdjvu/miniexp.h>
23
25
#include <libdjvu/ddjvuapi.h>
24
26
@@ -488,7 +490,7 @@ static int getAutoBBox(lua_State *L) {
488
490
prect .h = ddjvu_page_get_height (page -> page_ref );
489
491
rrect = prect ;
490
492
491
- WILLUSBITMAP * src = malloc ( sizeof ( WILLUSBITMAP )) ;
493
+ WILLUSBITMAP * src = & kctx -> src ;
492
494
bmp_init (src );
493
495
src -> width = rrect .w ;
494
496
src -> height = rrect .h ;
@@ -504,7 +506,6 @@ static int getAutoBBox(lua_State *L) {
504
506
ddjvu_page_render (page -> page_ref , 0 , & prect , & rrect , page -> doc -> pixelformat ,
505
507
bmp_bytewidth (src ), (char * ) src -> data );
506
508
507
- kctx -> src = src ;
508
509
k2pdfopt_crop_bmp (kctx );
509
510
510
511
lua_pushnumber (L , ((double )kctx -> bbox .x0 ));
@@ -548,7 +549,7 @@ static int reflowPage(lua_State *L) {
548
549
printf ("rendering page:%d,%d,%d,%d\n" ,rrect .x ,rrect .y ,rrect .w ,rrect .h );
549
550
kctx -> zoom = scale ;
550
551
551
- WILLUSBITMAP * src = malloc ( sizeof ( WILLUSBITMAP )) ;
552
+ WILLUSBITMAP * src = & kctx -> src ;
552
553
bmp_init (src );
553
554
src -> width = rrect .w ;
554
555
src -> height = rrect .h ;
@@ -566,7 +567,6 @@ static int reflowPage(lua_State *L) {
566
567
status = ddjvu_page_render (page -> page_ref , mode , & prect , & rrect , page -> doc -> pixelformat ,
567
568
bmp_bytewidth (src ), (char * ) src -> data );
568
569
569
- kctx -> src = src ;
570
570
if (kctx -> precache ) {
571
571
pthread_t rf_thread ;
572
572
pthread_attr_t attr ;
@@ -586,7 +586,11 @@ static int drawReflowedPage(lua_State *L) {
586
586
KOPTContext * kc = (KOPTContext * ) luaL_checkudata (L , 2 , "koptcontext" );
587
587
BlitBuffer * bb = (BlitBuffer * ) luaL_checkudata (L , 3 , "blitbuffer" );
588
588
589
- uint8_t * koptr = kc -> data ;
589
+ assert (kc -> dst .data != NULL );
590
+ assert (kc -> dst .width >= bb -> w );
591
+ assert (kc -> dst .height >= bb -> h );
592
+
593
+ uint8_t * koptr = kc -> dst .data ;
590
594
uint8_t * bbptr = bb -> data ;
591
595
592
596
int x_offset = 0 ;
0 commit comments