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 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
# include "bitmapConfig.h"
# include "bmintern.h"
# include <string.h>
# include <appDebugon.h>
/************************************************************************/
/* Translation back and forth between color encoding and string. */
/************************************************************************/
const char * bmcoStrings[]=
{
"black on white",
"white on black",
"RGB",
"RGB palette",
0
};
const char * bmcoIntToString( int colorEncodingInt )
{
if ( colorEncodingInt >= 0 &&
colorEncodingInt < sizeof( bmcoStrings )/sizeof(char *) -1 )
{ return bmcoStrings[colorEncodingInt]; }
LDEB(colorEncodingInt); return (char *)0;
}
int bmcoStringToInt( const char * colorEncodingString )
{
int i;
for ( i= 0; i < sizeof( bmcoStrings )/sizeof(char *) -1; i++ )
{
if ( ! strcmp( colorEncodingString, bmcoStrings[i] ) )
{ return i; }
}
SDEB(colorEncodingString); return -1;
}
/************************************************************************/
/* Translation back and forth between resolution unit and string. */
/************************************************************************/
const char * bmunStrings[]=
{
"m",
"inch",
"point",
"pixel",
0
};
const char * bmunIntToString( int unitInt )
{
if ( unitInt >= 0 &&
unitInt < sizeof( bmcoStrings )/sizeof(char *) -1 )
{ return bmunStrings[unitInt]; }
LDEB(unitInt); return (char *)0;
}
int bmunStringToInt( const char * unitString )
{
int i;
for ( i= 0; i < sizeof( bmunStrings )/sizeof(char *) -1; i++ )
{
if ( ! strcmp( unitString, bmunStrings[i] ) )
{ return i; }
}
SDEB(unitString); return -1;
}
/************************************************************************/
/* Initialise a BitmapDescription. */
/************************************************************************/
void bmInitDescription ( BitmapDescription * bd )
{
bd->bdBufferLength= 0;
bd->bdBytesPerRow= 0;
bd->bdPixelsWide= 0;
bd->bdPixelsHigh= 0;
bd->bdBitsPerSample= 0;
bd->bdSamplesPerPixel= 0;
bd->bdBitsPerPixel= 0;
bd->bdXResolution= 0;
bd->bdYResolution= 0;
bd->bdUnit= BMunILLEGALVALUE;
bd->bdColorEncoding= BMcoILLEGALVALUE;
bd->bdHasAlpha= 0;
/********************************************/
/* Or any other member of the union. */
/********************************************/
bd->bdColorCount= 0;
bd->bdRGB8Palette= (RGB8Color *)0;
}
/************************************************************************/
/* */
/* Clean a BitmapDescription. */
/* */
/************************************************************************/
void bmCleanDescription ( BitmapDescription * bd )
{
switch( bd->bdColorEncoding )
{
case BMcoRGB8PALETTE:
if ( bd->bdRGB8Palette )
{ free( bd->bdRGB8Palette ); }
break;
default:
break;
}
}
/************************************************************************/
/* */
/* Copy a BitmapDescription. */
/* */
/************************************************************************/
int bmCopyDescription ( BitmapDescription * to,
const BitmapDescription * from )
{
switch( from->bdColorEncoding )
{
case BMcoRGB8PALETTE:
*to= *from;
to->bdRGB8Palette= malloc( to->bdColorCount* sizeof(RGB8Color) );
if ( ! to->bdRGB8Palette )
{ XDEB(to->bdRGB8Palette); return -1; }
memcpy( to->bdRGB8Palette, from->bdRGB8Palette,
from->bdColorCount* sizeof( RGB8Color ) );
break;
default:
*to= *from;
break;
}
return 0;
}
/************************************************************************/
/* */
/* Byte masks */
/* */
/************************************************************************/
unsigned char Bmc1Masks[8]=
{ 0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1 };
unsigned char Bmc7Masks[8]=
{ 0x7f, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd, 0xfe };
/************************************************************************/
/* */
/* Geometry. */
/* */
/************************************************************************/
void bmImageSizeTwips( int * pImageWideTwips,
int * pImageHighTwips,
const BitmapDescription * bd )
{
int imageWideTwips;
int imageHighTwips;
switch( bd->bdUnit )
{
case BMunM:
imageWideTwips= (int) ( ( TWIPS_PER_M* bd->bdPixelsWide )/
bd->bdXResolution );
imageHighTwips= (int) ( ( TWIPS_PER_M* bd->bdPixelsHigh )/
bd->bdYResolution );
break;
case BMunINCH:
imageWideTwips= (int)( ( 72* 20* bd->bdPixelsWide )/
bd->bdXResolution );
imageHighTwips= (int)( ( 72* 20* bd->bdPixelsHigh )/
bd->bdYResolution );
break;
case BMunPOINT:
imageWideTwips= (int)( ( 20* bd->bdPixelsWide )/
bd->bdXResolution );
imageHighTwips= (int)( ( 20* bd->bdPixelsHigh )/
bd->bdYResolution );
break;
case BMunPIXEL:
imageWideTwips= 20* bd->bdPixelsWide;
imageHighTwips= 20* bd->bdPixelsHigh;
break;
default:
LDEB(bd->bdUnit);
imageWideTwips= 20* bd->bdPixelsWide;
imageHighTwips= 20* bd->bdPixelsHigh;
break;
}
*pImageWideTwips= imageWideTwips;
*pImageHighTwips= imageHighTwips;
return;
}
|