1 2 // Copyright 2019 - 2021 Michael D. Parker 3 // Distributed under the Boost Software License, Version 1.0. 4 // (See accompanying file LICENSE_1_0.txt or copy at 5 // http://www.boost.org/LICENSE_1_0.txt) 6 7 module bindbc.freeimage.types; 8 9 import core.stdc.config, 10 core.stdc.stddef; 11 12 enum FISupport { 13 noLibrary, 14 badLibrary, 15 fi317 = 317, 16 fi318 = 318, 17 } 18 19 enum FREEIMAGE_MAJOR_VERSION = 3; 20 21 version(FI_317) { 22 enum FREEIMAGE_MINOR_VERSION = 17; 23 enum FREEIMAGE_RELEASE_SERIAL = 0; 24 enum fiSupport = FISupport.fi317; 25 } 26 else version(FI_318) { 27 enum FREEIMAGE_MINOR_VERSION = 18; 28 enum FREEIMAGE_RELEASE_SERIAL = 0; 29 enum fiSupport = FISupport.fi318; 30 } 31 32 enum FREEIMAGE_COLORORDER_BGR = 0, 33 FREEIMAGE_COLORORDER_RGB = 1; 34 35 version(LittleEndian) { 36 version = FREEIMAGE_COLORORDER_BGR; 37 } 38 else { 39 version = FREEIMAGE_COLORORDER_RGB; 40 } 41 42 struct FIBITMAP { 43 void *data; 44 } 45 46 struct FIMULTIBITMAP { 47 void *data; 48 } 49 50 enum { 51 FALSE = 0, 52 TRUE = 1, 53 NULL = 0, 54 SEEK_SET = 0, 55 SEEK_CUR = 1, 56 SEEK_END = 2 57 } 58 59 alias BOOL = uint; 60 alias BYTE = ubyte; 61 alias WORD = ushort; 62 alias DWORD = c_ulong; 63 alias LONG = int; 64 65 // Renamed from FIINT64 and FIUINT64 in 3.15.4 66 alias INT64 = long; 67 alias UINT64 = ulong; 68 69 // Added in 3.15.3 70 alias FIINT64 = INT64; 71 alias FIUINT64 = UINT64; 72 73 align(1) struct RGBQUAD { 74 version(FREEIMAGE_COLORORDER_BGR) { 75 BYTE rgbBlue; 76 BYTE rgbGreen; 77 BYTE rgbRed; 78 } else { 79 BYTE rgbRed; 80 BYTE rgbGreen; 81 BYTE rgbBlue; 82 } 83 BYTE rgbReserved; 84 } 85 86 align(1) struct RGBTRIPLE { 87 version(FREEIMAGE_COLORORDER_BGR) { 88 BYTE rgbtBlue; 89 BYTE rgbtGreen; 90 BYTE rgbtRed; 91 } else { 92 BYTE rgbtRed; 93 BYTE rgbtGreen; 94 BYTE rgbtBlue; 95 } 96 } 97 98 align(1) struct BITMAPINFOHEADER { 99 DWORD biSize; 100 LONG biWidth; 101 LONG biHeight; 102 WORD biPlanes; 103 WORD biBitCount; 104 DWORD biCompression; 105 DWORD biSizeImage; 106 LONG biXPelsPerMeter; 107 LONG biYPelsPerMeter; 108 DWORD biClrUsed; 109 DWORD biClrImportant; 110 } 111 112 alias PBITMAPINFOHEADER = BITMAPINFOHEADER*; 113 114 align(1) struct BITMAPINFO { 115 BITMAPINFOHEADER bmiHeader; 116 RGBQUAD[1] bmiColors; 117 } 118 119 alias PBITMAPINFO = BITMAPINFO*; 120 121 align(1) struct FIRGB16 { 122 WORD red; 123 WORD green; 124 WORD blue; 125 } 126 127 align(1) struct FIRGBA16 { 128 WORD red; 129 WORD green; 130 WORD blue; 131 WORD alpha; 132 } 133 134 align(1) struct FIRGBF { 135 float red; 136 float green; 137 float blue; 138 } 139 140 align(1) struct FIRGBAF { 141 float red; 142 float green; 143 float blue; 144 float alpha; 145 } 146 147 align(1) struct FICOMPLEX { 148 double r; 149 double i; 150 } 151 152 struct FIMETADATA { 153 void* data; 154 } 155 156 struct FITAG { 157 void* data; 158 } 159 160 version(LittleEndian) { 161 version(FREEIMAGE_COLORORDER_BGR) { 162 enum { 163 FI_RGBA_RED = 2, 164 FI_RGBA_GREEN = 1, 165 FI_RGBA_BLUE = 0, 166 FI_RGBA_ALPHA = 3, 167 FI_RGBA_RED_MASK = 0x00FF0000, 168 FI_RGBA_GREEN_MASK = 0x0000FF00, 169 FI_RGBA_BLUE_MASK = 0x000000FF, 170 FI_RGBA_ALPHA_MASK = 0xFF000000, 171 FI_RGBA_RED_SHIFT = 16, 172 FI_RGBA_GREEN_SHIFT = 8, 173 FI_RGBA_BLUE_SHIFT = 0, 174 FI_RGBA_ALPHA_SHIFT = 24 175 } 176 } else { 177 enum 178 { 179 FI_RGBA_RED = 0, 180 FI_RGBA_GREEN = 1, 181 FI_RGBA_BLUE = 2, 182 FI_RGBA_ALPHA = 3, 183 FI_RGBA_RED_MASK = 0x000000FF, 184 FI_RGBA_GREEN_MASK = 0x0000FF00, 185 FI_RGBA_BLUE_MASK = 0x00FF0000, 186 FI_RGBA_ALPHA_MASK = 0xFF000000, 187 FI_RGBA_RED_SHIFT = 0, 188 FI_RGBA_GREEN_SHIFT = 8, 189 FI_RGBA_BLUE_SHIFT = 16, 190 FI_RGBA_ALPHA_SHIFT = 24 191 } 192 } 193 } 194 else { 195 version(FREEIMAGE_COLORORDER_BGR) { 196 enum { 197 FI_RGBA_RED = 2, 198 FI_RGBA_GREEN = 1, 199 FI_RGBA_BLUE = 0, 200 FI_RGBA_ALPHA = 3, 201 FI_RGBA_RED_MASK = 0x0000FF00, 202 FI_RGBA_GREEN_MASK = 0x00FF0000, 203 FI_RGBA_BLUE_MASK = 0xFF000000, 204 FI_RGBA_ALPHA_MASK = 0x000000FF, 205 FI_RGBA_RED_SHIFT = 8, 206 FI_RGBA_GREEN_SHIFT = 16, 207 FI_RGBA_BLUE_SHIFT = 24, 208 FI_RGBA_ALPHA_SHIFT = 0 209 } 210 } 211 else { 212 enum { 213 FI_RGBA_RED = 0, 214 FI_RGBA_GREEN = 1, 215 FI_RGBA_BLUE = 2, 216 FI_RGBA_ALPHA = 3, 217 FI_RGBA_RED_MASK = 0xFF000000, 218 FI_RGBA_GREEN_MASK = 0x00FF0000, 219 FI_RGBA_BLUE_MASK = 0x0000FF00, 220 FI_RGBA_ALPHA_MASK = 0x000000FF, 221 FI_RGBA_RED_SHIFT = 24, 222 FI_RGBA_GREEN_SHIFT = 16, 223 FI_RGBA_BLUE_SHIFT = 8, 224 FI_RGBA_ALPHA_SHIFT = 0 225 } 226 } 227 } 228 229 enum FI_RGBA_RGB_MASK = FI_RGBA_RED_MASK | FI_RGBA_GREEN_MASK | FI_RGBA_BLUE_MASK; 230 231 enum { 232 FI16_555_RED_MASK = 0x7C00, 233 FI16_555_GREEN_MASK = 0x03E0, 234 FI16_555_BLUE_MASK = 0x001F, 235 FI16_555_RED_SHIFT = 10, 236 FI16_555_GREEN_SHIFT = 5, 237 FI16_555_BLUE_SHIFT = 0, 238 FI16_565_RED_MASK = 0xF800, 239 FI16_565_GREEN_MASK = 0x07E0, 240 FI16_565_BLUE_MASK = 0x001F, 241 FI16_565_RED_SHIFT = 11, 242 FI16_565_GREEN_SHIFT = 5, 243 FI16_565_BLUE_SHIFT = 0 244 } 245 246 enum { 247 FIICC_DEFAULT = 0x00, 248 FIICC_COLOR_IS_CMYK = 0x01 249 } 250 251 struct FIICCPROFILE { 252 WORD flags; // info flag 253 DWORD size; // profile's size measured in bytes 254 void *data; // points to a block of contiguous memory containing the profile 255 } 256 257 enum FREE_IMAGE_FORMAT { 258 FIF_UNKNOWN = -1, 259 FIF_BMP = 0, 260 FIF_ICO = 1, 261 FIF_JPEG = 2, 262 FIF_JNG = 3, 263 FIF_KOALA = 4, 264 FIF_LBM = 5, 265 FIF_IFF = FIF_LBM, 266 FIF_MNG = 6, 267 FIF_PBM = 7, 268 FIF_PBMRAW = 8, 269 FIF_PCD = 9, 270 FIF_PCX = 10, 271 FIF_PGM = 11, 272 FIF_PGMRAW = 12, 273 FIF_PNG = 13, 274 FIF_PPM = 14, 275 FIF_PPMRAW = 15, 276 FIF_RAS = 16, 277 FIF_TARGA = 17, 278 FIF_TIFF = 18, 279 FIF_WBMP = 19, 280 FIF_PSD = 20, 281 FIF_CUT = 21, 282 FIF_XBM = 22, 283 FIF_XPM = 23, 284 FIF_DDS = 24, 285 FIF_GIF = 25, 286 FIF_HDR = 26, 287 FIF_FAXG3 = 27, 288 FIF_SGI = 28, 289 FIF_EXR = 29, 290 FIF_J2K = 30, 291 FIF_JP2 = 31, 292 FIF_PFM = 32, 293 FIF_PICT = 33, 294 FIF_RAW = 34, 295 // FreeImage 3.16.0 296 FIF_WEBP = 35, 297 FFI_JXR = 36, 298 } 299 mixin(expandEnum!FREE_IMAGE_FORMAT); 300 301 enum FREE_IMAGE_TYPE { 302 FIT_UNKNOWN = 0, 303 FIT_BITMAP = 1, 304 FIT_UINT16 = 2, 305 FIT_INT16 = 3, 306 FIT_UINT32 = 4, 307 FIT_INT32 = 5, 308 FIT_FLOAT = 6, 309 FIT_DOUBLE = 7, 310 FIT_COMPLEX = 8, 311 FIT_RGB16 = 9, 312 FIT_RGBA16 = 10, 313 FIT_RGBF = 11, 314 FIT_RGBAF = 12 315 } 316 mixin(expandEnum!FREE_IMAGE_TYPE); 317 318 enum FREE_IMAGE_COLOR_TYPE { 319 FIC_MINISWHITE = 0, 320 FIC_MINISBLACK = 1, 321 FIC_RGB = 2, 322 FIC_PALETTE = 3, 323 FIC_RGBALPHA = 4, 324 FIC_CMYK = 5 325 } 326 mixin(expandEnum!FREE_IMAGE_COLOR_TYPE); 327 328 enum FREE_IMAGE_QUANTIZE { 329 FIQ_WUQUANT = 0, 330 FIQ_NNQUANT = 1 331 } 332 mixin(expandEnum!FREE_IMAGE_QUANTIZE); 333 334 enum FREE_IMAGE_DITHER { 335 FID_FS = 0, 336 FID_BAYER4x4 = 1, 337 FID_BAYER8x8 = 2, 338 FID_CLUSTER6x6 = 3, 339 FID_CLUSTER8x8 = 4, 340 FID_CLUSTER16x16= 5, 341 FID_BAYER16x16 = 6 342 } 343 mixin(expandEnum!FREE_IMAGE_DITHER); 344 345 enum FREE_IMAGE_JPEG_OPERATION { 346 FIJPEG_OP_NONE = 0, 347 FIJPEG_OP_FLIP_H = 1, 348 FIJPEG_OP_FLIP_V = 2, 349 FIJPEG_OP_TRANSPOSE = 3, 350 FIJPEG_OP_TRANSVERSE = 4, 351 FIJPEG_OP_ROTATE_90 = 5, 352 FIJPEG_OP_ROTATE_180 = 6, 353 FIJPEG_OP_ROTATE_270 = 7 354 } 355 mixin(expandEnum!FREE_IMAGE_JPEG_OPERATION); 356 357 enum FREE_IMAGE_TMO { 358 FITMO_DRAGO03 = 0, 359 FITMO_REINHARD05 = 1, 360 FITMO_FATTAL02 = 2 361 } 362 mixin(expandEnum!FREE_IMAGE_TMO); 363 364 enum FREE_IMAGE_FILTER { 365 FILTER_BOX = 0, 366 FILTER_BICUBIC = 1, 367 FILTER_BILINEAR = 2, 368 FILTER_BSPLINE = 3, 369 FILTER_CATMULLROM = 4, 370 FILTER_LANCZOS3 = 5 371 } 372 mixin(expandEnum!FREE_IMAGE_FILTER); 373 374 enum FREE_IMAGE_COLOR_CHANNEL 375 { 376 FICC_RGB = 0, 377 FICC_RED = 1, 378 FICC_GREEN = 2, 379 FICC_BLUE = 3, 380 FICC_ALPHA = 4, 381 FICC_BLACK = 5, 382 FICC_REAL = 6, 383 FICC_IMAG = 7, 384 FICC_MAG = 8, 385 FICC_PHASE = 9 386 } 387 mixin(expandEnum!FREE_IMAGE_COLOR_CHANNEL); 388 389 enum FREE_IMAGE_MDTYPE { 390 FIDT_NOTYPE = 0, 391 FIDT_BYTE = 1, 392 FIDT_ASCII = 2, 393 FIDT_SHORT = 3, 394 FIDT_LONG = 4, 395 FIDT_RATIONAL = 5, 396 FIDT_SBYTE = 6, 397 FIDT_UNDEFINED = 7, 398 FIDT_SSHORT = 8, 399 FIDT_SLONG = 9, 400 FIDT_SRATIONAL = 10, 401 FIDT_FLOAT = 11, 402 FIDT_DOUBLE = 12, 403 FIDT_IFD = 13, 404 FIDT_PALETTE = 14, 405 // Added in 3.15.3 406 FIDT_LONG8 = 16, 407 FIDT_SLONG8 = 17, 408 FIDT_IFD8 = 18 409 } 410 mixin(expandEnum!FREE_IMAGE_MDTYPE); 411 412 enum FREE_IMAGE_MDMODEL { 413 FIMD_NODATA = -1, 414 FIMD_COMMENTS = 0, 415 FIMD_EXIF_MAIN = 1, 416 FIMD_EXIF_EXIF = 2, 417 FIMD_EXIF_GPS = 3, 418 FIMD_EXIF_MAKERNOTE = 4, 419 FIMD_EXIF_INTEROP = 5, 420 FIMD_IPTC = 6, 421 FIMD_XMP = 7, 422 FIMD_GEOTIFF = 8, 423 FIMD_ANIMATION = 9, 424 FIMD_CUSTOM = 10, 425 FIMD_EXIF_RAW = 11 426 } 427 mixin(expandEnum!FREE_IMAGE_MDMODEL); 428 429 alias fi_handle = void*; 430 extern(System) nothrow { 431 alias FI_ReadProc = uint function(void *buffer, uint size, uint count, fi_handle handle); 432 alias FI_WriteProc = uint function(void *buffer, uint size, uint count, fi_handle handle); 433 alias FI_SeekProc = int function(fi_handle handle, c_long offset, int origin); 434 alias FI_TellProc = c_long function(fi_handle handle); 435 } 436 437 align(1) struct FreeImageIO { 438 FI_ReadProc read_proc; 439 FI_WriteProc write_proc; 440 FI_SeekProc seek_proc; 441 FI_TellProc tell_proc; 442 } 443 444 struct FIMEMORY { 445 void *data; 446 } 447 448 extern(C) nothrow { 449 alias FI_FormatProc = const(char)* function(char)* function(); 450 alias FI_DescriptionProc = const(char)* function(char)* function(); 451 alias FI_ExtensionListProc = const(char)* function(char)* function(); 452 alias FI_RegExprProc = const(char)* function(char)* function(); 453 alias FI_OpenProc = void* function(FreeImageIO *io, fi_handle handle, BOOL read); 454 alias FI_CloseProc = void function(FreeImageIO *io, fi_handle handle, void *data); 455 alias FI_PageCountProc = int function(FreeImageIO *io, fi_handle handle, void *data); 456 alias FI_PageCapabilityProc = int function(FreeImageIO *io, fi_handle handle, void *data); 457 alias FI_LoadProc = FIBITMAP* function(FreeImageIO *io, fi_handle handle, int page, int flags, void *data); 458 alias FI_SaveProc = BOOL function(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data); 459 alias FI_ValidateProc = BOOL function(FreeImageIO *io, fi_handle handle); 460 alias FI_MimeProc = const(char) function(char) function(); 461 alias FI_SupportsExportBPPProc = BOOL function(int bpp); 462 alias FI_SupportsExportTypeProc = BOOL function(FREE_IMAGE_TYPE type); 463 alias FI_SupportsICCProfilesProc = BOOL function(); 464 alias FI_SupportsNoPixelsProc = BOOL function(); 465 } 466 467 struct Plugin { 468 FI_FormatProc format_proc; 469 FI_DescriptionProc description_proc; 470 FI_ExtensionListProc extension_proc; 471 FI_RegExprProc regexpr_proc; 472 FI_OpenProc open_proc; 473 FI_CloseProc close_proc; 474 FI_PageCountProc pagecount_proc; 475 FI_PageCapabilityProc pagecapability_proc; 476 FI_LoadProc load_proc; 477 FI_SaveProc save_proc; 478 FI_ValidateProc validate_proc; 479 FI_MimeProc mime_proc; 480 FI_SupportsExportBPPProc supports_export_bpp_proc; 481 FI_SupportsExportTypeProc supports_export_type_proc; 482 FI_SupportsICCProfilesProc supports_icc_profiles_proc; 483 FI_SupportsNoPixelsProc supports_no_pixels_proc; 484 } 485 486 487 extern(C) nothrow alias FI_InitProc =void function(Plugin *plugin, int format_id); 488 489 490 // Load / Save flag constants ----------------------------------------------- 491 492 enum { 493 FIF_LOAD_NOPIXELS = 0x8000, 494 BMP_DEFAULT = 0, 495 BMP_SAVE_RLE = 1, 496 CUT_DEFAULT = 0, 497 DDS_DEFAULT = 0, 498 EXR_DEFAULT = 0, 499 EXR_FLOAT = 0x0001, 500 EXR_NONE = 0x0002, 501 EXR_ZIP = 0x0004, 502 EXR_PIZ = 0x0008, 503 EXR_PXR24 = 0x0010, 504 EXR_B44 = 0x0020, 505 EXR_LC = 0x0040, 506 FAXG3_DEFAULT = 0, 507 GIF_DEFAULT = 0, 508 GIF_LOAD256 = 1, 509 GIF_PLAYBACK = 2, 510 HDR_DEFAULT = 0, 511 ICO_DEFAULT = 0, 512 ICO_MAKEALPHA = 1, 513 IFF_DEFAULT = 0, 514 J2K_DEFAULT = 0, 515 JP2_DEFAULT = 0, 516 JPEG_DEFAULT = 0, 517 JPEG_FAST = 0x0001, 518 JPEG_ACCURATE = 0x0002, 519 JPEG_CMYK = 0x0004, 520 JPEG_EXIFROTATE = 0x0008, 521 JPEG_GRAYSCALE = 0x0010, // Added in 3.15.4 522 JPEG_QUALITYSUPERB = 0x80, 523 JPEG_QUALITYGOOD = 0x0100, 524 JPEG_QUALITYNORMAL = 0x0200, 525 JPEG_QUALITYAVERAGE = 0x0400, 526 JPEG_QUALITYBAD = 0x0800, 527 JPEG_PROGRESSIVE = 0x2000, 528 529 JPEG_SUBSAMPLING_411 = 0x1000, 530 JPEG_SUBSAMPLING_420 = 0x4000, 531 JPEG_SUBSAMPLING_422 = 0x8000, 532 JPEG_SUBSAMPLING_444 = 0x10000, 533 JPEG_OPTIMIZE = 0x20000, 534 JPEG_BASELINE = 0x40000, 535 KOALA_DEFAULT = 0, 536 LBM_DEFAULT = 0, 537 MNG_DEFAULT = 0, 538 PCD_DEFAULT = 0, 539 PCD_BASE = 1, 540 PCD_BASEDIV4 = 2, 541 PCD_BASEDIV16 = 3, 542 PCX_DEFAULT = 0, 543 PFM_DEFAULT = 0, 544 PICT_DEFAULT = 0, 545 PNG_DEFAULT = 0, 546 PNG_IGNOREGAMMA = 1, 547 PNG_Z_BEST_SPEED = 0x0001, 548 PNG_Z_DEFAULT_COMPRESSION = 0x0006, 549 PNG_Z_BEST_COMPRESSION = 0x0009, 550 PNG_Z_NO_COMPRESSION = 0x0100, 551 PNG_INTERLACED = 0x0200, 552 PNM_DEFAULT = 0, 553 PNM_SAVE_RAW = 0, 554 PNM_SAVE_ASCII = 1, 555 PSD_DEFAULT = 0, 556 PSD_CMYK = 1, 557 PSD_LAB = 2, 558 PSD_NONE = 0x0100, // Added in 3.18.0 559 PSD_RLE = 0x0200, // ditto 560 PSD_PSB = 0x2000, // ditto 561 RAS_DEFAULT = 0, 562 RAW_DEFAULT = 0, 563 RAW_PREVIEW = 1, 564 RAW_DISPLAY = 2, 565 RAW_HALFSIZE = 4, // Added in 3.15.1 566 RAW_UNPROCESSED = 8, // Added in 3.17.0 567 SGI_DEFAULT = 0, 568 TARGA_DEFAULT = 0, 569 TARGA_LOAD_RGB888 = 1, 570 TARGA_SAVE_RLE = 2, 571 TIFF_DEFAULT = 0, 572 TIFF_CMYK = 0x0001, 573 TIFF_PACKBITS = 0x0100, 574 TIFF_DEFLATE = 0x0200, 575 TIFF_ADOBE_DEFLATE = 0x0400, 576 TIFF_NONE = 0x0800, 577 TIFF_CCITTFAX3 = 0x1000, 578 TIFF_CCITTFAX4 = 0x2000, 579 TIFF_LZW = 0x4000, 580 TIFF_JPEG = 0x8000, 581 TIFF_LOGLUV = 0x10000, 582 WBMP_DEFAULT = 0, 583 XBM_DEFAULT = 0, 584 XPM_DEFAULT = 0, 585 // FreeImage 3.16.0 586 WEBP_DEFAULT = 0, 587 WEBP_LOSSLESS = 0x100, 588 JXR_DEFAULT = 0, 589 JXR_LOSSLESS = 0x0064, 590 JXR_PROGRESSIVE = 0x2000, 591 } 592 593 enum { 594 FI_COLOR_IS_RGB_COLOR = 0x00, 595 FI_COLOR_IS_RGBA_COLOR = 0x01, 596 FI_COLOR_FIND_EQUAL_COLOR = 0x02, 597 FI_COLOR_ALPHA_IS_INDEX = 0x04, 598 FI_COLOR_PALETTE_SEARCH_MASK = (FI_COLOR_FIND_EQUAL_COLOR | FI_COLOR_ALPHA_IS_INDEX) 599 } 600 601 // FreeImage 3.17.0 602 enum { 603 FI_RESCALE_DEFAULT = 0x00, 604 FI_RESCALE_TRUE_COLOR = 0x01, 605 FI_RESCALE_OMIT_METADATA = 0x02, 606 } 607 608 extern(C) nothrow alias FreeImage_OutputMessageFunction = void function(FREE_IMAGE_FORMAT fif, const(char)* msg); 609 extern(Windows) nothrow alias FreeImage_OutputMessageFunctionStdCall = void function(FREE_IMAGE_FORMAT fif, const(char)* msg); 610 611 private: 612 enum expandEnum(EnumType, string fqnEnumType = EnumType.stringof) = (){ 613 string expandEnum = "enum {"; 614 foreach(m;__traits(allMembers, EnumType)) { 615 expandEnum ~= m ~ " = " ~ fqnEnumType ~ "." ~ m ~ ","; 616 } 617 expandEnum ~= "}"; 618 return expandEnum; 619 }();