378 } 379 break; 380 } 381 382 /* Fix memory leak by freeing colors 383 * - robi.khan@eng 9/22/1999 384 */ 385 free(colors); 386 } 387 388 static XImage * 389 ReadRegionsInList(disp,fakeVis,depth,format,width,height,bbox,regions) 390 Display *disp ; 391 Visual *fakeVis ; 392 int32_t depth , width , height ; 393 int32_t format ; 394 XRectangle bbox; /* bounding box of grabbed area */ 395 list_ptr regions;/* list of regions to read from */ 396 { 397 XImage *ximage ; 398 399 ximage = XCreateImage(disp,fakeVis,(uint32_t) depth,format,0,NULL, 400 (uint32_t)width,(uint32_t)height,8,0); 401 402 ximage->data = calloc(ximage->bytes_per_line*height*((format==ZPixmap)? 1 : depth), sizeof(char)); 403 ximage->bits_per_pixel = depth; /** Valid only if format is ZPixmap ***/ 404 405 for (image_region_type* reg = (image_region_type *) first_in_list( regions); reg; 406 reg = (image_region_type *) next_in_list( regions)) 407 { 408 struct my_XRegion *vis_reg = (struct my_XRegion *)(reg->visible_region); 409 for (int32_t rect = 0; rect < vis_reg->numRects; rect++) 410 { 411 /** ------------------------------------------------------------------------ 412 Intersect bbox with visible part of region giving src rect & output 413 location. Width is the min right side minus the max left side. 414 Similar for height. Offset src rect so x,y are relative to 415 origin of win, not the root-relative visible rect of win. 416 ------------------------------------------------------------------------ **/ 417 int32_t srcRect_width = MIN( vis_reg->rects[rect].x2, bbox.width + bbox.x) 418 - MAX( vis_reg->rects[rect].x1, bbox.x); 419 420 int32_t srcRect_height = MIN( vis_reg->rects[rect].y2, bbox.height + bbox.y) 421 - MAX( vis_reg->rects[rect].y1, bbox.y); 422 423 int32_t diff = bbox.x - vis_reg->rects[rect].x1; 424 int32_t srcRect_x = MAX( 0, diff) + (vis_reg->rects[rect].x1 - reg->x_rootrel - reg->border); 425 int32_t dst_x = MAX( 0, -diff) ; 426 427 diff = bbox.y - vis_reg->rects[rect].y1; 428 int32_t srcRect_y = MAX( 0, diff) + (vis_reg->rects[rect].y1 - reg->y_rootrel - reg->border); 429 int32_t dst_y = MAX( 0, -diff) ; | 378 } 379 break; 380 } 381 382 /* Fix memory leak by freeing colors 383 * - robi.khan@eng 9/22/1999 384 */ 385 free(colors); 386 } 387 388 static XImage * 389 ReadRegionsInList(disp,fakeVis,depth,format,width,height,bbox,regions) 390 Display *disp ; 391 Visual *fakeVis ; 392 int32_t depth , width , height ; 393 int32_t format ; 394 XRectangle bbox; /* bounding box of grabbed area */ 395 list_ptr regions;/* list of regions to read from */ 396 { 397 XImage *ximage ; 398 image_region_type* reg; 399 int32_t rect; 400 401 ximage = XCreateImage(disp,fakeVis,(uint32_t) depth,format,0,NULL, 402 (uint32_t)width,(uint32_t)height,8,0); 403 404 ximage->data = calloc(ximage->bytes_per_line*height*((format==ZPixmap)? 1 : depth), sizeof(char)); 405 ximage->bits_per_pixel = depth; /** Valid only if format is ZPixmap ***/ 406 407 for (reg = (image_region_type *) first_in_list( regions); reg; 408 reg = (image_region_type *) next_in_list( regions)) 409 { 410 struct my_XRegion *vis_reg = (struct my_XRegion *)(reg->visible_region); 411 for (rect = 0; rect < vis_reg->numRects; rect++) 412 { 413 /** ------------------------------------------------------------------------ 414 Intersect bbox with visible part of region giving src rect & output 415 location. Width is the min right side minus the max left side. 416 Similar for height. Offset src rect so x,y are relative to 417 origin of win, not the root-relative visible rect of win. 418 ------------------------------------------------------------------------ **/ 419 int32_t srcRect_width = MIN( vis_reg->rects[rect].x2, bbox.width + bbox.x) 420 - MAX( vis_reg->rects[rect].x1, bbox.x); 421 422 int32_t srcRect_height = MIN( vis_reg->rects[rect].y2, bbox.height + bbox.y) 423 - MAX( vis_reg->rects[rect].y1, bbox.y); 424 425 int32_t diff = bbox.x - vis_reg->rects[rect].x1; 426 int32_t srcRect_x = MAX( 0, diff) + (vis_reg->rects[rect].x1 - reg->x_rootrel - reg->border); 427 int32_t dst_x = MAX( 0, -diff) ; 428 429 diff = bbox.y - vis_reg->rects[rect].y1; 430 int32_t srcRect_y = MAX( 0, diff) + (vis_reg->rects[rect].y1 - reg->y_rootrel - reg->border); 431 int32_t dst_y = MAX( 0, -diff) ; |