gdi32: Simplify the optional free'ing of bits pointer.

This commit is contained in:
Huw Davies 2011-07-12 16:12:04 +01:00 committed by Alexandre Julliard
parent dd39da49e5
commit 00a386ebf9
4 changed files with 14 additions and 12 deletions

View File

@ -74,6 +74,7 @@ static BOOL init_dib_info(dib_info *dib, const BITMAPINFOHEADER *bi, const DWORD
dib->height = bi->biHeight; dib->height = bi->biHeight;
dib->stride = ((dib->width * dib->bit_count + 31) >> 3) & ~3; dib->stride = ((dib->width * dib->bit_count + 31) >> 3) & ~3;
dib->bits = bits; dib->bits = bits;
dib->ptr_to_free = NULL;
if(dib->height < 0) /* top-down */ if(dib->height < 0) /* top-down */
{ {
@ -197,6 +198,7 @@ static void clear_dib_info(dib_info *dib)
{ {
dib->color_table = NULL; dib->color_table = NULL;
dib->bits = NULL; dib->bits = NULL;
dib->ptr_to_free = NULL;
} }
/********************************************************************** /**********************************************************************
@ -204,15 +206,14 @@ static void clear_dib_info(dib_info *dib)
* *
* Free the resources associated with a dib and optionally the bits * Free the resources associated with a dib and optionally the bits
*/ */
void free_dib_info(dib_info *dib, BOOL free_bits) void free_dib_info(dib_info *dib)
{ {
HeapFree(GetProcessHeap(), 0, dib->color_table); HeapFree(GetProcessHeap(), 0, dib->color_table);
dib->color_table = NULL; dib->color_table = NULL;
if(free_bits)
{ HeapFree(GetProcessHeap(), 0, dib->ptr_to_free);
HeapFree(GetProcessHeap(), 0, dib->bits); dib->ptr_to_free = NULL;
dib->bits = NULL; dib->bits = NULL;
}
} }
void copy_dib_color_info(dib_info *dst, const dib_info *src) void copy_dib_color_info(dib_info *dst, const dib_info *src)
@ -254,7 +255,7 @@ BOOL convert_dib(dib_info *dst, const dib_info *src)
dst->height = src->height; dst->height = src->height;
dst->width = src->width; dst->width = src->width;
dst->stride = ((dst->width * dst->bit_count + 31) >> 3) & ~3; dst->stride = ((dst->width * dst->bit_count + 31) >> 3) & ~3;
dst->bits = HeapAlloc(GetProcessHeap(), 0, dst->height * dst->stride); dst->ptr_to_free = dst->bits = HeapAlloc(GetProcessHeap(), 0, dst->height * dst->stride);
src_rect.left = src_rect.top = 0; src_rect.left = src_rect.top = 0;
src_rect.right = src->width; src_rect.right = src->width;
@ -262,7 +263,7 @@ BOOL convert_dib(dib_info *dst, const dib_info *src)
ret = dst->funcs->convert_to(dst, src, &src_rect); ret = dst->funcs->convert_to(dst, src, &src_rect);
if(!ret) free_dib_info(dst, TRUE); if(!ret) free_dib_info(dst);
return ret; return ret;
} }
@ -289,7 +290,7 @@ static BOOL CDECL dibdrv_DeleteDC( PHYSDEV dev )
TRACE("(%p)\n", dev); TRACE("(%p)\n", dev);
DeleteObject(pdev->clip); DeleteObject(pdev->clip);
free_pattern_brush(pdev); free_pattern_brush(pdev);
free_dib_info(&pdev->dib, FALSE); free_dib_info(&pdev->dib);
return 0; return 0;
} }

View File

@ -60,7 +60,7 @@ extern void calc_and_xor_masks(INT rop, DWORD color, DWORD *and, DWORD *xor) DEC
extern void update_brush_rop( dibdrv_physdev *pdev, INT rop ) DECLSPEC_HIDDEN; extern void update_brush_rop( dibdrv_physdev *pdev, INT rop ) DECLSPEC_HIDDEN;
extern void reset_dash_origin(dibdrv_physdev *pdev) DECLSPEC_HIDDEN; extern void reset_dash_origin(dibdrv_physdev *pdev) DECLSPEC_HIDDEN;
extern BOOL init_dib_info_from_packed(dib_info *dib, const BITMAPINFOHEADER *bi, WORD usage, HPALETTE pal) DECLSPEC_HIDDEN; extern BOOL init_dib_info_from_packed(dib_info *dib, const BITMAPINFOHEADER *bi, WORD usage, HPALETTE pal) DECLSPEC_HIDDEN;
extern void free_dib_info(dib_info *dib, BOOL free_bits) DECLSPEC_HIDDEN; extern void free_dib_info(dib_info *dib) DECLSPEC_HIDDEN;
extern void free_pattern_brush(dibdrv_physdev *pdev) DECLSPEC_HIDDEN; extern void free_pattern_brush(dibdrv_physdev *pdev) DECLSPEC_HIDDEN;
extern void copy_dib_color_info(dib_info *dst, const dib_info *src) DECLSPEC_HIDDEN; extern void copy_dib_color_info(dib_info *dst, const dib_info *src) DECLSPEC_HIDDEN;
extern BOOL convert_dib(dib_info *dst, const dib_info *src) DECLSPEC_HIDDEN; extern BOOL convert_dib(dib_info *dst, const dib_info *src) DECLSPEC_HIDDEN;

View File

@ -1072,7 +1072,7 @@ static void free_pattern_brush_bits( dibdrv_physdev *pdev )
void free_pattern_brush( dibdrv_physdev *pdev ) void free_pattern_brush( dibdrv_physdev *pdev )
{ {
free_pattern_brush_bits( pdev ); free_pattern_brush_bits( pdev );
free_dib_info( &pdev->brush_dib, TRUE ); free_dib_info( &pdev->brush_dib );
} }
static BOOL create_pattern_brush_bits(dibdrv_physdev *pdev) static BOOL create_pattern_brush_bits(dibdrv_physdev *pdev)
@ -1295,7 +1295,7 @@ HBRUSH CDECL dibdrv_SelectBrush( PHYSDEV dev, HBRUSH hbrush )
pdev->brush_rects = pattern_brush; pdev->brush_rects = pattern_brush;
pdev->defer &= ~DEFER_BRUSH; pdev->defer &= ~DEFER_BRUSH;
} }
free_dib_info(&orig_dib, FALSE); free_dib_info(&orig_dib);
} }
GlobalUnlock((HGLOBAL)logbrush.lbHatch); GlobalUnlock((HGLOBAL)logbrush.lbHatch);
break; break;

View File

@ -78,6 +78,7 @@ typedef struct
int bit_count, width, height; int bit_count, width, height;
int stride; /* stride in bytes. Will be -ve for bottom-up dibs (see bits). */ int stride; /* stride in bytes. Will be -ve for bottom-up dibs (see bits). */
void *bits; /* points to the top-left corner of the dib. */ void *bits; /* points to the top-left corner of the dib. */
void *ptr_to_free;
DWORD red_mask, green_mask, blue_mask; DWORD red_mask, green_mask, blue_mask;
int red_shift, green_shift, blue_shift; int red_shift, green_shift, blue_shift;