Fix possible memory leak in Fl_WinAPI_Screen_Driver::read_win_rectangle_unscaled()
Thanks to "fire-eggs" for spotting it.
Also minor optimisations in Fl_X11_Screen_Driver::read_win_rectangle_unscaled() and
Fl_Cocoa_Screen_Driver::read_win_rectangle_unscaled().
This closes PR #151.
@ -364,9 +364,9 @@ Fl_RGB_Image *Fl_Cocoa_Screen_Driver::read_win_rectangle(int X, int Y, int w, in
@@ -364,9 +364,9 @@ Fl_RGB_Image *Fl_Cocoa_Screen_Driver::read_win_rectangle(int X, int Y, int w, in
// Copy the image from the off-screen buffer to the memory buffer.
@ -397,7 +397,7 @@ Fl_RGB_Image *Fl_Cocoa_Screen_Driver::read_win_rectangle(int X, int Y, int w, in
@@ -397,7 +397,7 @@ Fl_RGB_Image *Fl_Cocoa_Screen_Driver::read_win_rectangle(int X, int Y, int w, in
// Initialize the default colors/alpha in the whole image...
memset(p,alpha,w*h*d);
// Depth of image is always 3 here
// Grab all of the pixels in the image...
@ -534,7 +527,12 @@ Fl_RGB_Image *Fl_WinAPI_Screen_Driver::read_win_rectangle_unscaled(int X, int Y,
@@ -534,7 +527,12 @@ Fl_RGB_Image *Fl_WinAPI_Screen_Driver::read_win_rectangle_unscaled(int X, int Y,
Y=0;
}
if(h<1||w<1)return0/*p*/;// nothing to copy
if(h<1||w<1)return0;// nothing to copy
// Allocate and initialize the image data array
size_tarraySize=((size_t)w*h)*3;
uchar*p=newuchar[arraySize];
memset(p,0,arraySize);
intline_size=((3*w+3)/4)*4;// each line is aligned on a DWORD (4 bytes)
uchar*dib=newuchar[line_size*h];// create temporary buffer to read DIB
@ -572,15 +570,13 @@ Fl_RGB_Image *Fl_WinAPI_Screen_Driver::read_win_rectangle_unscaled(int X, int Y,
@@ -572,15 +570,13 @@ Fl_RGB_Image *Fl_WinAPI_Screen_Driver::read_win_rectangle_unscaled(int X, int Y,
for(intj=0;j<h;j++){
constuchar*src=dib+j*line_size;// source line
uchar*tg=p+(j+shift_y)*d*ww+shift_x*d;// target line
uchar*tg=p+(j+shift_y)*3*ww+shift_x*3;// target line
for(inti=0;i<w;i++){
ucharb=*src++;
ucharg=*src++;
*tg++=*src++;// R
*tg++=g;// G
*tg++=b;// B
if(alpha)
*tg++=alpha;// alpha
}
}
@ -591,8 +587,8 @@ Fl_RGB_Image *Fl_WinAPI_Screen_Driver::read_win_rectangle_unscaled(int X, int Y,
@@ -591,8 +587,8 @@ Fl_RGB_Image *Fl_WinAPI_Screen_Driver::read_win_rectangle_unscaled(int X, int Y,
@ -750,7 +750,6 @@ Fl_RGB_Image *Fl_X11_Screen_Driver::read_win_rectangle(int X, int Y, int w, int
@@ -750,7 +750,6 @@ Fl_RGB_Image *Fl_X11_Screen_Driver::read_win_rectangle(int X, int Y, int w, int
XImage*image;// Captured image
inti,maxindex;// Looping vars
intx,y;// Current X & Y in image
intd;// Depth of image
unsignedchar*line,// Array to hold image row
*line_ptr;// Pointer to current line image
unsignedchar*pixel;// Current color value
@ -865,11 +864,10 @@ Fl_RGB_Image *Fl_X11_Screen_Driver::read_win_rectangle(int X, int Y, int w, int
@@ -865,11 +864,10 @@ Fl_RGB_Image *Fl_X11_Screen_Driver::read_win_rectangle(int X, int Y, int w, int
// Initialize the default colors/alpha in the whole image...
memset(p,0,w*h*d);
@ -1167,7 +1165,7 @@ Fl_RGB_Image *Fl_X11_Screen_Driver::read_win_rectangle(int X, int Y, int w, int
@@ -1167,7 +1165,7 @@ Fl_RGB_Image *Fl_X11_Screen_Driver::read_win_rectangle(int X, int Y, int w, int