1 /************************************************************************/ 2 /* */ 3 /* Description of a bitmap. */ 4 /* */ 5 /************************************************************************/ 6 7 # ifndef BITMAP_H 8 # define BITMAP_H 9 10 # include <utilColor.h> 11 # include <utilPalette.h> 12 # include <utilMemoryBuffer.h> 13 # include <geo2DInteger.h> 14 15 /************************************************************************/ 16 /* */ 17 /* Color encodings. */ 18 /* */ 19 /************************************************************************/ 20 21 typedef enum BitmapColorEncoding 22 { 23 BMcoBLACKWHITE= 0, 24 BMcoWHITEBLACK, 25 BMcoRGB, 26 BMcoRGB8PALETTE, 27 28 BMco_COUNT 29 } BitmapColorEncoding; 30 31 # define BMcoILLEGALVALUE BMco_COUNT 32 33 extern const char * bmcoIntToString( int colorEncodingInt ); 34 extern int bmcoStringToInt( const char * colorEncodingString ); 35 extern const char * bmcoStrings[]; 36 37 /************************************************************************/ 38 /* */ 39 /* Units of measurement. */ 40 /* */ 41 /************************************************************************/ 42 43 typedef enum BitmapResolution 44 { 45 BMunM= 0, 46 BMunINCH, 47 BMunPOINT, 48 BMunPIXEL, 49 50 BMun_COUNT 51 } BitmapResolution; 52 53 # define BMunILLEGALVALUE BMun_COUNT 54 55 extern const char * bmunIntToString( int unitInt ); 56 extern int bmunStringToInt( const char * unitString ); 57 extern const char * bmunStrings[]; 58 59 /************************************************************************/ 60 /* */ 61 /* Description of a bitmap. */ 62 /* */ 63 /************************************************************************/ 64 65 typedef struct BitmapDescription 66 { 67 /********************************/ 68 /* Number of bytes in an image */ 69 /* buffer; Idem for one row. */ 70 /* Rows are never divided over */ 71 /* more than one byte. */ 72 /********************************/ 73 unsigned int bdBufferLength; 74 unsigned int bdBytesPerRow; 75 /********************************/ 76 /* Height/width of an image */ 77 /********************************/ 78 unsigned int bdPixelsWide; 79 unsigned int bdPixelsHigh; 80 /********************************/ 81 /* Description of how pixels */ 82 /* are encoded. */ 83 /* For direct images, all three*/ 84 /* refer to the buffer. */ 85 /* For palette type images, */ 86 /* BitsPerSample, */ 87 /* SamplesPerPixel refer to the*/ 88 /* image; BitsPerPixel refers */ 89 /* to the buffer. */ 90 /********************************/ 91 int bdBitsPerSample; 92 int bdSamplesPerPixel; 93 int bdBitsPerPixel; 94 /********************************/ 95 /* Pixels per metric unit; */ 96 /* The unit. */ 97 /********************************/ 98 int bdXResolution; 99 int bdYResolution; 100 unsigned char bdUnit; 101 /********************************/ 102 /* How are colors encoded. */ 103 /********************************/ 104 unsigned char bdColorEncoding; 105 /********************************/ 106 /* Does it have a transparency */ 107 /* mask? If so, 0 in the data */ 108 /* means transparent, the */ 109 /* maximum value opaque. Values*/ 110 /* between are not supported. */ 111 /********************************/ 112 unsigned char bdHasAlpha; 113 /********************************/ 114 /* Palette is only relevant */ 115 /* with BMcoRGB8PALETTE. */ 116 /********************************/ 117 ColorPalette bdPalette; 118 } BitmapDescription; 119 120 /************************************************************************/ 121 /* */ 122 /* Used to store and manage a bitmap image. */ 123 /* */ 124 /************************************************************************/ 125 126 typedef struct RasterImage 127 { 128 BitmapDescription riDescription; 129 unsigned char * riBytes; 130 int riFormat; 131 } RasterImage; 132 133 /************************************************************************/ 134 /* */ 135 /* Description of a bitmap file format. */ 136 /* */ 137 /************************************************************************/ 138 139 typedef struct BitmapFileType 140 { 141 int (*bftWrite)( const MemoryBuffer * filename, 142 const unsigned char * buffer, 143 const BitmapDescription * bd, 144 int privateFormat ); 145 146 int (*bftCanWrite)( const BitmapDescription * bd, 147 int privateFormat ); 148 149 int (*bftRead)( const MemoryBuffer * filename, 150 unsigned char ** pBuffer, 151 BitmapDescription * bd, 152 int * pPrivateFormat ); 153 154 const char * bftFileExtension; 155 const char * bftFileFilter; 156 const char * bftTypeId; 157 const char * bftTypeDescription; 158 } BitmapFileType; 159 160 typedef struct BitmapFileFormat 161 { 162 const char * bffDescription; 163 const char * bffId; 164 int bffPrivate; 165 BitmapFileType * bffFileType; 166 } BitmapFileFormat; 167 168 /************************************************************************/ 169 /* */ 170 /* Catalog of available of a bitmap file formats. */ 171 /* */ 172 /************************************************************************/ 173 174 extern BitmapFileFormat bmFileFormats[]; 175 extern const int bmNumberOfFileFormats; 176 177 extern BitmapFileType * bmFileTypes[]; 178 extern const int bmNumberOfFileTypes; 179 180 /************************************************************************/ 181 /* */ 182 /* For Reading/Writing from/to streams. */ 183 /* */ 184 /************************************************************************/ 185 186 extern int bmWriteGifFile( const MemoryBuffer * filename, 187 const unsigned char * buffer, 188 const BitmapDescription * bd, 189 int privateFormat ); 190 191 extern int bmCanWriteGifFile( const BitmapDescription * bd, 192 int privateFormat ); 193 194 extern int bmWriteJpegFile( const MemoryBuffer * filename, 195 const unsigned char * buffer, 196 const BitmapDescription * bd, 197 int privateFormat ); 198 199 extern int bmCanWriteJpegFile( const BitmapDescription * bd, 200 int privateFormat ); 201 202 /************************************************************************/ 203 204 extern int bmWriteRtfFile( const MemoryBuffer * filename, 205 const unsigned char * buffer, 206 const BitmapDescription * bd, 207 int privateFormat ); 208 209 extern int bmCanWriteRtfFile( const BitmapDescription * bd, 210 int privateFormat ); 211 212 extern int bmCanWritePngFile( const BitmapDescription * bd, 213 int privateFormat ); 214 215 /************************************************************************/ 216 /* Routines. */ 217 /************************************************************************/ 218 219 extern void bmInitDescription( BitmapDescription * bd ); 220 221 extern void bmCleanDescription( BitmapDescription * bd ); 222 223 extern int bmCopyDescription( BitmapDescription * bdOut, 224 const BitmapDescription * bdIn ); 225 226 extern int bmWrite( const MemoryBuffer * filename, 227 const unsigned char * buffer, 228 const BitmapDescription * bd, 229 int fileFormat ); 230 231 extern int bmCanWrite( const BitmapDescription * bd, 232 int fileFormat ); 233 234 extern int bmRead( const MemoryBuffer * filename, 235 unsigned char ** pBuffer, 236 BitmapDescription * bd, 237 int * pFileFormat ); 238 239 extern int bmSelect( RasterImage * riOut, 240 const RasterImage * riIn, 241 const DocumentRectangle * drSrc ); 242 243 extern int bmComponents( void *** pComponents, 244 int * pCount, 245 const unsigned char * buffer, 246 const BitmapDescription * bd ); 247 248 extern int bmComponentBitmap( unsigned char ** buffer, 249 BitmapDescription * bdout, 250 DocumentRectangle * dr, 251 const BitmapDescription * bdin, 252 const void * component ); 253 254 extern int bmGroupBitmap( unsigned char ** buffer, 255 BitmapDescription * bdout, 256 DocumentRectangle * dr, 257 const BitmapDescription * bdin, 258 const void * vbc ); 259 260 int bmgGroupBitmap( unsigned char ** pBuffer, 261 BitmapDescription * bdout, 262 DocumentRectangle * dr, 263 const BitmapDescription * bdin, 264 const void * vcg ); 265 266 extern int bmGroups( void *** pGroups, 267 void ** comps, 268 int ncomp, 269 const BitmapDescription * bd ); 270 271 extern void bmFreeGroups( void ** groups, 272 int numberOfGroups ); 273 274 /************************************************************************/ 275 /* */ 276 /* Palette expansion for drawing. */ 277 /* */ 278 /************************************************************************/ 279 280 int bmExpandRGB8Palette( unsigned char * to, 281 const unsigned char * from, 282 int pixelsWide, 283 int bitsPerColor, 284 const ColorPalette * palette, 285 int hasAlpha ); 286 287 /************************************************************************/ 288 /* */ 289 /* Bitmap transformations. */ 290 /* */ 291 /************************************************************************/ 292 293 typedef int (*BM_PIX_FUN)( void * through, 294 int row, 295 int col ); 296 297 typedef void (*BM_SEG_FUN)( void * through, 298 int x0, 299 int y0, 300 int x1, 301 int y1 ); 302 303 typedef int (*RasterTransformation)(RasterImage * riOut, 304 const RasterImage * riIn, 305 int option ); 306 307 extern int bmWhiteToTransparent(RasterImage * riOut, 308 const RasterImage * riIn, 309 int ignoredInt ); 310 311 extern int bmVerticalFlip( RasterImage * riOut, 312 const RasterImage * riIn, 313 int ignoredInt ); 314 315 extern int bmHorizontalFlip( RasterImage * riOut, 316 const RasterImage * riIn, 317 int ignoredInt ); 318 319 extern int bmRotate180( RasterImage * riOut, 320 const RasterImage * riIn, 321 int ignoredInt ); 322 323 extern int bmRotate90( RasterImage * riOut, 324 const RasterImage * riIn, 325 int ignoredInt ); 326 327 extern int bmColorReduce( RasterImage * riOut, 328 const RasterImage * riIn, 329 int colorCount ); 330 331 extern int bmRotate( RasterImage * riOut, 332 const RasterImage * riIn, 333 double angle ); 334 335 extern int bmFilterSobel( RasterImage * riOut, 336 const RasterImage * riIn, 337 int ignoredInt ); 338 339 extern int bmFilterLaplace( RasterImage * riOut, 340 const RasterImage * riIn, 341 int ignoredInt ); 342 343 extern int bmFilterSmoothe( RasterImage * riOut, 344 const RasterImage * riIn, 345 int ignoredInt ); 346 347 extern int bmFilterBlur( RasterImage * riOut, 348 const RasterImage * riIn, 349 int ignoredInt ); 350 351 extern int bmFilterRelative( RasterImage * riOut, 352 const RasterImage * riIn, 353 int ignoredInt ); 354 355 extern int bmFlipBytes( unsigned char * buffer, 356 int byteCount, 357 int bitsPerPixel ); 358 359 int bmMapImageColors( const BitmapDescription * bd, 360 const int * map, 361 unsigned char * buffer ); 362 363 extern int bmAverage( RasterImage * riOut, 364 const RasterImage * riIn, 365 int xpixels, 366 int ypixels ); 367 368 extern int bmExpandPaletteImage( RasterImage * riOut, 369 const RasterImage * riIn, 370 int ignoredInt ); 371 372 extern int bmTransparentImage( BitmapDescription * bdOut, 373 unsigned char ** pBufOut, 374 int colorEncoding, 375 int wide, 376 int high ); 377 378 extern int bmRGBImage( BitmapDescription * bdOut, 379 unsigned char ** pBufOut, 380 int colorEncoding, 381 int r, 382 int g, 383 int b, 384 int wide, 385 int high ); 386 387 extern int bmGammaCorrect( RasterImage * riOut, 388 const RasterImage * riIn, 389 double gammaValue ); 390 391 extern int bmInvertImage( RasterImage * riOut, 392 const RasterImage * riIn, 393 int ignoredInt ); 394 395 extern void bmImageSizeTwips( 396 int * pImageWideTwips, 397 int * pImageHighTwips, 398 const BitmapDescription * bd ); 399 400 extern void bmRectangleSizeTwips( 401 int * pRectangleWideTwips, 402 int * pRectangleHighTwips, 403 const BitmapDescription * bd, 404 int pixelsWide, 405 int pixelsHigh ); 406 407 extern int bmCalculateSizes( BitmapDescription * bd ); 408 extern int bmAllocateBuffer( RasterImage * ri ); 409 410 extern int bmToGrayscale( 411 RasterImage * riOut, 412 const RasterImage * riIn, 413 int ignoredInt ); 414 415 extern int bmToWebSafe( RasterImage * riOut, 416 const RasterImage * riIn, 417 int ignoredInt ); 418 419 extern int bmThreshold( RasterImage * riOut, 420 const RasterImage * riIn, 421 int ignoredInt ); 422 423 extern int bmMorphoDilateSimple( 424 RasterImage * riOut, 425 const RasterImage * riIn, 426 int ignoredInt ); 427 428 extern int bmMorphoErodeSimple( 429 RasterImage * riOut, 430 const RasterImage * riIn, 431 int ignoredInt ); 432 433 extern int bmMorphoDilate( RasterImage * riOut, 434 const RasterImage * riIn, 435 const RasterImage * riSe, 436 int rowOrig, 437 int colOrig ); 438 439 extern int bmMorphoErode( RasterImage * riOut, 440 const RasterImage * riIn, 441 const RasterImage * riSe, 442 int rowOrig, 443 int colOrig ); 444 445 extern int bmMorphoSetSimpleSe( RasterImage * riOut ); 446 447 extern int bmMorphoLineElement( RasterImage * riOut, 448 int wide, 449 int high, 450 int x0, 451 int y0, 452 int x1, 453 int y1 ); 454 455 extern void bmDraw1BitImage( const BitmapDescription * bdTo, 456 unsigned char * bufTo, 457 const RasterImage * riIn, 458 unsigned char invertMaskIn, 459 int rowTo0, 460 int colTo0 ); 461 462 extern int bmForAll1Pixels( const RasterImage * riIn, 463 unsigned char invertMaskIn, 464 void * through, 465 BM_PIX_FUN pixFun ); 466 467 extern int bmFindLineSegments( const RasterImage * riIn, 468 int size, 469 void * through, 470 BM_SEG_FUN segFun ); 471 472 extern int bmCountLinePixels( const unsigned char * buffer, 473 const BitmapDescription * bd, 474 int x0, 475 int y0, 476 int x1, 477 int y1 ); 478 479 extern int bmDrawLine( unsigned char * buffer, 480 const BitmapDescription * bd, 481 int x0, 482 int y0, 483 int x1, 484 int y1, 485 int wide ); 486 487 extern int bmDrawBox( unsigned char * buffer, 488 const BitmapDescription * bd, 489 int x0, 490 int y0, 491 int x1, 492 int y1, 493 int wide ); 494 495 extern int bmSuggestFormat( const MemoryBuffer * filename, 496 int suggestedFormat, 497 const BitmapDescription * bd ); 498 499 extern int bmSetSolidWhite( RasterImage * ri ); 500 extern int bmSetSolidBlack( RasterImage * ri ); 501 502 extern int bmCopyArea( int up, 503 int vp, 504 RasterImage * riTo, 505 const RasterImage * riFrom ); 506 507 extern int bmPaintArea( int up, 508 int vp, 509 RasterImage * riTo, 510 const RasterImage * riFrom ); 511 512 extern int bmGetAlphaMask( 513 RasterImage * riOut, 514 const RasterImage * riIn, 515 int ignoredInt ); 516 517 extern int bmRemoveAlpha( RasterImage * riOut, 518 const RasterImage * riIn, 519 int ignoredInt ); 520 521 extern int bmSetAlphaMask( 522 BitmapDescription * bdOut, 523 const BitmapDescription * bdImage, 524 const BitmapDescription * bdAlpha, 525 unsigned char ** pBufOut, 526 const unsigned char * bufImage, 527 const unsigned char * bufAlpha ); 528 529 extern void bmInitRasterImage( RasterImage * ri ); 530 extern void bmCleanRasterImage( RasterImage * ri ); 531 extern void bmFreeRasterImage( RasterImage * ri ); 532 533 extern int bmCopyRasterImage( RasterImage * to, 534 const RasterImage * from ); 535 536 # endif 537