1 #   include	"bitmapConfig.h"
2 
3 #   include	"bmintern.h"
4 
5 #   include	<stdlib.h>
6 #   include	<string.h>
7 
8 #   include	<appDebugon.h>
9 
10 /************************************************************************/
11 /*									*/
12 /*  Invert the individual components of an image.			*/
13 /*									*/
14 /************************************************************************/
15 
16 #   define	MAX_COMPONENTS	4
17 
bmInvertImage(RasterImage * riOut,const RasterImage * riIn,int ignoredInt)18 int bmInvertImage(	RasterImage *			riOut,
19 			const RasterImage *		riIn,
20 			int				ignoredInt )
21     {
22     const BitmapDescription *	bdIn= &(riIn->riDescription);
23     int				rval= 0;
24 
25     int				map[256*MAX_COMPONENTS];
26     int *			mp;
27     int				mxv;
28 
29     int				i;
30     int				j;
31 
32     RasterImage			ri;
33 
34     bmInitRasterImage( &ri );
35 
36     /*  1  */
37     if  ( bdIn->bdBitsPerSample > 8 )
38 	{ LDEB(bdIn->bdBitsPerSample); rval= -1; goto ready;	}
39 
40     /*  2  */
41     mxv= 1;
42     for ( i= 0; i < bdIn->bdBitsPerSample; i++ )
43 	{ mxv *= 2;	}
44     mxv--;
45 
46     /*  3  */
47     mp= map;
48     for ( i= 0; i <= mxv; i++ )
49 	{
50 	for ( j= 0; j < bdIn->bdSamplesPerPixel; j++ )
51 	    { *(mp++)= mxv- i;	}
52 	}
53 
54     if  ( bmCopyDescription( &(ri.riDescription), bdIn ) )
55 	{ LDEB(1); rval= -1; goto ready;	}
56 
57     /*  4  */
58     ri.riBytes= (unsigned char *)malloc( bdIn->bdBufferLength+ bdIn->bdSamplesPerPixel- 1 );
59     if  ( ! ri.riBytes )
60 	{ LXDEB(bdIn->bdBufferLength,ri.riBytes); rval= -1; goto ready; }
61 
62     memcpy( ri.riBytes, riIn->riBytes, bdIn->bdBufferLength );
63 
64     /*  5  */
65     if  ( bmMapImageColors( &(ri.riDescription), map, ri.riBytes ) )
66 	{ LDEB(1); rval= -1; goto ready;	}
67 
68     /*  6  */
69     /* steal */
70     *riOut= ri; bmInitRasterImage( &ri );
71 
72   ready:
73 
74     bmCleanRasterImage( &ri );
75 
76     return rval;
77     }
78 
79