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 184 185 186 187 188 189 190 191 192 193
|
# include "bitmapConfig.h"
# include "bmintern.h"
# define y0 math_y0
# define y1 math_y1
# include <math.h>
# undef y0
# undef y1
# include <appDebugon.h>
/************************************************************************/
/* */
/* Map the values of the samples for the individual color components. */
/* */
/************************************************************************/
static void bmMapLine8( unsigned char * b,
const int * map,
int bypr,
int spp )
{
int i;
int j;
j= 0;
for ( i= 0; i < bypr; i++ )
{
*b= map[spp* *b+ ( j % spp )]; j++;
b++;
}
return;
}
static void bmMapLine4( unsigned char * b,
const int * map,
int bypr,
int spp )
{
int i;
int j;
j= 0;
for ( i= 0; i < bypr; i++ )
{
unsigned char us= 0;
us |= map[ spp* ( ( *b & 0x0f ) >> 0 ) + ( j % spp ) ] << 0; j++;
us |= map[ spp* ( ( *b & 0xf0 ) >> 4 ) + ( j % spp ) ] << 4; j++;
*(b++)= us;
}
return;
}
static void bmMapLine2( unsigned char * b,
const int * map,
int bypr,
int spp )
{
int i;
int j;
j= 0;
for ( i= 0; i < bypr; i++ )
{
unsigned char us= 0;
us |= map[ spp* ( ( *b & 0x03 ) >> 0 ) + ( j % spp ) ] << 0; j++;
us |= map[ spp* ( ( *b & 0x0c ) >> 2 ) + ( j % spp ) ] << 2; j++;
us |= map[ spp* ( ( *b & 0x30 ) >> 4 ) + ( j % spp ) ] << 4; j++;
us |= map[ spp* ( ( *b & 0xc0 ) >> 6 ) + ( j % spp ) ] << 6; j++;
*(b++)= us;
}
return;
}
static void bmMapLine1( unsigned char * b,
const int * map,
int bypr,
int spp )
{
int i;
int j;
j= 0;
for ( i= 0; i < bypr; i++ )
{
unsigned char us= 0;
us |= map[ spp* ( ( *b & 0x01 ) >> 0 ) + ( j % spp ) ] << 0; j++;
us |= map[ spp* ( ( *b & 0x02 ) >> 1 ) + ( j % spp ) ] << 1; j++;
us |= map[ spp* ( ( *b & 0x04 ) >> 2 ) + ( j % spp ) ] << 2; j++;
us |= map[ spp* ( ( *b & 0x08 ) >> 3 ) + ( j % spp ) ] << 3; j++;
us |= map[ spp* ( ( *b & 0x10 ) >> 4 ) + ( j % spp ) ] << 4; j++;
us |= map[ spp* ( ( *b & 0x20 ) >> 5 ) + ( j % spp ) ] << 5; j++;
us |= map[ spp* ( ( *b & 0x40 ) >> 6 ) + ( j % spp ) ] << 6; j++;
us |= map[ spp* ( ( *b & 0x80 ) >> 7 ) + ( j % spp ) ] << 7; j++;
*(b++)= us;
}
return;
}
int bmMapImageColors( const BitmapDescription * bd,
const int * map,
unsigned char * buffer )
{
int i;
int spp= bd->bdSamplesPerPixel;
int bypr= bd->bdBytesPerRow;
switch( bd->bdColorEncoding )
{
case BMcoBLACKWHITE:
case BMcoWHITEBLACK:
case BMcoRGB:
switch( bd->bdBitsPerSample )
{
case 1:
for ( i= 0; i < bd->bdPixelsHigh; i++ )
{ bmMapLine1( buffer+ i* bypr, map, bypr, spp ); }
break;
case 2:
for ( i= 0; i < bd->bdPixelsHigh; i++ )
{ bmMapLine2( buffer+ i* bypr, map, bypr, spp ); }
break;
case 4:
for ( i= 0; i < bd->bdPixelsHigh; i++ )
{ bmMapLine4( buffer+ i* bypr, map, bypr, spp ); }
break;
case 8:
for ( i= 0; i < bd->bdPixelsHigh; i++ )
{ bmMapLine8( buffer+ i* bypr, map, bypr, spp ); }
break;
default:
LLDEB(bd->bdColorEncoding,bd->bdBitsPerSample);
return -1;
}
break;
case BMcoRGB8PALETTE:
switch( spp )
{
RGB8Color * rgb8;
case 3:
rgb8= bd->bdRGB8Palette;
for ( i= 0; i < bd->bdColorCount; rgb8++, i++ )
{
rgb8->rgb8Red= map[spp* rgb8->rgb8Red+ 0];
rgb8->rgb8Green= map[spp* rgb8->rgb8Green+ 1];
rgb8->rgb8Blue= map[spp* rgb8->rgb8Blue+ 2];
}
break;
case 4:
rgb8= bd->bdRGB8Palette;
for ( i= 0; i < bd->bdColorCount; rgb8++, i++ )
{
rgb8->rgb8Red= map[spp* rgb8->rgb8Red+ 0];
rgb8->rgb8Green= map[spp* rgb8->rgb8Green+ 1];
rgb8->rgb8Blue= map[spp* rgb8->rgb8Blue+ 2];
rgb8->rgb8Alpha= map[spp* rgb8->rgb8Red+ 3];
}
break;
default:
LLDEB(bd->bdColorEncoding,spp);
return -1;
}
break;
default:
LDEB(bd->bdColorEncoding);
return -1;
}
return 0;
}
|