1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
# include "bitmapConfig.h"
# include "bmintern.h"
# include <appDebugon.h>
/************************************************************************/
/* */
/* Make images with standard content. */
/* */
/************************************************************************/
/************************************************************************/
/* */
/* Make a completely transparent image */
/* */
/************************************************************************/
int bmTransparentImage( BitmapDescription * bdOut,
unsigned char ** pBufOut,
int colorEncoding,
int wide,
int high )
{
BitmapDescription bd;
unsigned char * buffer;
switch( colorEncoding )
{
case BMcoRGB8PALETTE:
bd.bdPixelsWide= wide;
bd.bdPixelsHigh= high;
bd.bdHasAlpha= 1;
bd.bdUnit= BMunINCH;
bd.bdXResolution= 72;
bd.bdYResolution= 72;
bd.bdBitsPerSample= 8;
bd.bdSamplesPerPixel= 3;
if ( bd.bdHasAlpha )
{ bd.bdBitsPerPixel= 8; }
else{ bd.bdBitsPerPixel= 4; }
bd.bdColorEncoding= BMcoRGB8PALETTE;
bd.bdColorCount= 3;
bd.bdRGB8Palette= (RGB8Color *)0;
if ( bmCalculateSizes( &bd ) )
{ LDEB(1); return -1; }
buffer= (unsigned char *)malloc( bd.bdBufferLength );
if ( ! buffer )
{ LXDEB(bd.bdBufferLength,buffer); return -1; }
bd.bdRGB8Palette= (RGB8Color *)
malloc( 256* sizeof( RGB8Color ) );
if ( ! bd.bdRGB8Palette )
{
LLDEB(256,bd.bdRGB8Palette);
free( buffer ); return -1;
}
/* transparent */
bd.bdRGB8Palette[0].rgb8Red= 255;
bd.bdRGB8Palette[0].rgb8Green= 255;
bd.bdRGB8Palette[0].rgb8Blue= 255;
bd.bdRGB8Palette[0].rgb8Alpha= 0;
/* white */
bd.bdRGB8Palette[1].rgb8Red= 255;
bd.bdRGB8Palette[1].rgb8Green= 255;
bd.bdRGB8Palette[1].rgb8Blue= 255;
bd.bdRGB8Palette[1].rgb8Alpha= 255;
/* black */
bd.bdRGB8Palette[2].rgb8Red= 0;
bd.bdRGB8Palette[2].rgb8Green= 0;
bd.bdRGB8Palette[2].rgb8Blue= 0;
bd.bdRGB8Palette[2].rgb8Alpha= 255;
memset( buffer, 0, bd.bdBufferLength );
break;
default:
LDEB(colorEncoding); return -1;
}
*bdOut= bd; *pBufOut= buffer;
return 0;
}
/************************************************************************/
/* */
/* Make an image containing just one RGB color. */
/* */
/************************************************************************/
int bmRGBImage( BitmapDescription * bdOut,
unsigned char ** pBufOut,
int colorEncoding,
int r,
int g,
int b,
int wide,
int high )
{
BitmapDescription bd;
unsigned char * buffer;
switch( colorEncoding )
{
case BMcoRGB8PALETTE:
if ( r < 0 || r > 255 )
{ LDEB(r); return -1; }
if ( g < 0 || g > 255 )
{ LDEB(g); return -1; }
if ( b < 0 || b > 255 )
{ LDEB(b); return -1; }
bd.bdPixelsWide= wide;
bd.bdPixelsHigh= high;
bd.bdHasAlpha= 0;
bd.bdUnit= BMunINCH;
bd.bdXResolution= 72;
bd.bdYResolution= 72;
bd.bdBitsPerSample= 8;
bd.bdSamplesPerPixel= 3;
if ( bd.bdHasAlpha )
{ bd.bdBitsPerPixel= 8; }
else{ bd.bdBitsPerPixel= 4; }
bd.bdColorEncoding= BMcoRGB8PALETTE;
bd.bdColorCount= 3;
bd.bdRGB8Palette= (RGB8Color *)0;
if ( bmCalculateSizes( &bd ) )
{ LDEB(1); return -1; }
buffer= (unsigned char *)malloc( bd.bdBufferLength );
if ( ! buffer )
{ LXDEB(bd.bdBufferLength,buffer); return -1; }
bd.bdRGB8Palette= (RGB8Color *)
malloc( 256* sizeof( RGB8Color ) );
if ( ! bd.bdRGB8Palette )
{
LLDEB(256,bd.bdRGB8Palette);
free( buffer ); return -1;
}
/* color */
bd.bdRGB8Palette[0].rgb8Red= r;
bd.bdRGB8Palette[0].rgb8Green= g;
bd.bdRGB8Palette[0].rgb8Blue= b;
bd.bdRGB8Palette[0].rgb8Alpha= 255;
/* white */
bd.bdRGB8Palette[1].rgb8Red= 255;
bd.bdRGB8Palette[1].rgb8Green= 255;
bd.bdRGB8Palette[1].rgb8Blue= 255;
bd.bdRGB8Palette[1].rgb8Alpha= 255;
/* black */
bd.bdRGB8Palette[2].rgb8Red= 0;
bd.bdRGB8Palette[2].rgb8Green= 0;
bd.bdRGB8Palette[2].rgb8Blue= 0;
bd.bdRGB8Palette[2].rgb8Alpha= 255;
memset( buffer, 0, bd.bdBufferLength );
break;
default:
LDEB(colorEncoding); return -1;
}
*bdOut= bd; *pBufOut= buffer;
return 0;
}
|