1 /************************************************************************/
2 /*  An image description and its data.					*/
3 /************************************************************************/
4 
5 #   include	"bitmapConfig.h"
6 
7 #   include	<stdlib.h>
8 #   include	<string.h>
9 
10 #   include	"bitmap.h"
11 
12 #   include	<appDebugon.h>
13 
14 /************************************************************************/
15 /*									*/
16 /*  Clean an image structure.						*/
17 /*									*/
18 /************************************************************************/
19 
bmCleanRasterImage(RasterImage * ri)20 void bmCleanRasterImage(	RasterImage *	ri )
21     {
22     if  ( ri->riBytes )
23 	{
24 	free( ri->riBytes );
25 	ri->riBytes= (unsigned char *)0;
26 	}
27 
28     bmCleanDescription( &ri->riDescription );
29     bmInitDescription( &ri->riDescription );
30     }
31 
bmFreeRasterImage(RasterImage * ri)32 void bmFreeRasterImage(	RasterImage *	ri )
33     {
34     bmCleanRasterImage( ri );
35     free( ri );
36     }
37 
bmInitRasterImage(RasterImage * ri)38 void bmInitRasterImage(	RasterImage *	ri )
39     {
40     bmInitDescription( &(ri->riDescription) );
41     ri->riBytes= (unsigned char *)0;
42     ri->riFormat= -1;
43     }
44 
bmCopyRasterImage(RasterImage * to,const RasterImage * from)45 int bmCopyRasterImage(	RasterImage *		to,
46 			const RasterImage *	from )
47     {
48     int			rval= 0;
49     unsigned char *	copy= (unsigned char *)0;
50 
51     copy= (unsigned char *)malloc( from->riDescription.bdBufferLength );
52     if  ( ! copy )
53 	{
54 	LXDEB(from->riDescription.bdBufferLength,copy);
55 	rval= -1; goto ready;
56 	}
57     memcpy( copy, from->riBytes, from->riDescription.bdBufferLength );
58 
59     if  ( bmCopyDescription( &(to->riDescription), &(from->riDescription) ) )
60 	{ LDEB(1); rval= -1; goto ready;	}
61 
62     if  ( to->riBytes )
63 	{ free(to->riBytes);	}
64     to->riBytes= copy; copy= (unsigned char *)0; /* steal */
65 
66   ready:
67 
68     if  ( copy )
69 	{ free( copy );	}
70 
71     return rval;
72     }
73 
74