1/**************************************************************************\ 2* 3* Copyright (c) 1998-2000, Microsoft Corp. All Rights Reserved. 4* 5* Module Name: 6* 7* GdiplusBitmap.h 8* 9* Abstract: 10* 11* Bitmap related declarations 12* 13\**************************************************************************/ 14 15#ifndef _GDIPLUSBITMAP_H 16#define _GDIPLUSBITMAP_H 17 18// NOTE: 19// Our current choice for the public API is to use constructors 20// instead of static load functions to create image objects. 21// 22// I've kept the static load functions here for now so that 23// existing test programs are not broken. But they should 24// eventually be taken out. 25 26#ifndef DCR_USE_NEW_140782 27 28inline 29Image::Image( 30 IN const WCHAR* filename 31 ) 32{ 33 nativeImage = NULL; 34 lastResult = DllExports::GdipLoadImageFromFile(filename, &nativeImage); 35} 36 37inline 38Image::Image( 39 IN IStream* stream 40 ) 41{ 42 nativeImage = NULL; 43 lastResult = DllExports::GdipLoadImageFromStream(stream, &nativeImage); 44} 45 46inline Image* 47Image::FromFile( 48 IN const WCHAR* filename 49 ) 50{ 51 return new Image(filename); 52} 53 54inline Image* 55Image::FromStream( 56 IN IStream* stream 57 ) 58{ 59 return new Image(stream); 60} 61 62#else 63 64inline 65Image::Image( 66 IN const WCHAR* filename, 67 IN BOOL useEmbeddedColorManagement 68 ) 69{ 70 nativeImage = NULL; 71 if(useEmbeddedColorManagement) 72 { 73 lastResult = DllExports::GdipLoadImageFromFileICM( 74 filename, 75 &nativeImage 76 ); 77 } 78 else 79 { 80 lastResult = DllExports::GdipLoadImageFromFile( 81 filename, 82 &nativeImage 83 ); 84 } 85} 86 87inline 88Image::Image( 89 IN IStream* stream, 90 IN BOOL useEmbeddedColorManagement 91 ) 92{ 93 nativeImage = NULL; 94 if(useEmbeddedColorManagement) 95 { 96 lastResult = DllExports::GdipLoadImageFromStreamICM( 97 stream, 98 &nativeImage 99 ); 100 } 101 else 102 { 103 lastResult = DllExports::GdipLoadImageFromStream( 104 stream, 105 &nativeImage 106 ); 107 } 108} 109 110inline Image* 111Image::FromFile( 112 IN const WCHAR* filename, 113 IN BOOL useEmbeddedColorManagement 114 ) 115{ 116 return new Image( 117 filename, 118 useEmbeddedColorManagement 119 ); 120} 121 122inline Image* 123Image::FromStream( 124 IN IStream* stream, 125 IN BOOL useEmbeddedColorManagement 126 ) 127{ 128 return new Image( 129 stream, 130 useEmbeddedColorManagement 131 ); 132} 133 134#endif 135 136inline 137Image::~Image() 138{ 139 DllExports::GdipDisposeImage(nativeImage); 140} 141 142inline Image* 143Image::Clone() 144{ 145 GpImage *cloneimage = NULL; 146 147 SetStatus(DllExports::GdipCloneImage(nativeImage, &cloneimage)); 148 149 return new Image(cloneimage, lastResult); 150} 151 152// Encorder Parameter 153 154inline UINT 155Image::GetEncoderParameterListSize( 156 IN const CLSID* clsidEncoder 157 ) 158{ 159 UINT size = 0; 160 161 SetStatus(DllExports::GdipGetEncoderParameterListSize(nativeImage, 162 clsidEncoder, 163 &size)); 164 return size; 165} 166 167inline Status 168Image::GetEncoderParameterList( 169 IN const CLSID* clsidEncoder, 170 IN UINT size, 171 OUT EncoderParameters* buffer 172 ) 173{ 174 return SetStatus(DllExports::GdipGetEncoderParameterList(nativeImage, 175 clsidEncoder, 176 size, 177 buffer)); 178} 179 180// Save images 181 182inline Status 183Image::Save( 184 IN const WCHAR* filename, 185 IN const CLSID* clsidEncoder, 186 IN const EncoderParameters *encoderParams 187 ) 188{ 189 return SetStatus(DllExports::GdipSaveImageToFile(nativeImage, 190 filename, 191 clsidEncoder, 192 encoderParams)); 193} 194 195inline Status 196Image::Save( 197 IN IStream* stream, 198 IN const CLSID* clsidEncoder, 199 IN const EncoderParameters *encoderParams 200 ) 201{ 202 return SetStatus(DllExports::GdipSaveImageToStream(nativeImage, 203 stream, 204 clsidEncoder, 205 encoderParams)); 206} 207 208inline Status 209Image::SaveAdd( 210 IN const EncoderParameters *encoderParams 211 ) 212{ 213 return SetStatus(DllExports::GdipSaveAdd(nativeImage, 214 encoderParams)); 215} 216 217inline Status 218Image::SaveAdd( 219 IN Image* newImage, 220 IN const EncoderParameters *encoderParams 221 ) 222{ 223 if ( newImage == NULL ) 224 { 225 return SetStatus(InvalidParameter); 226 } 227 228 return SetStatus(DllExports::GdipSaveAddImage(nativeImage, 229 newImage->nativeImage, 230 encoderParams)); 231} 232 233// Get size and type information 234inline ImageType 235Image::GetType() const 236{ 237 ImageType type = ImageTypeUnknown; 238 239 SetStatus(DllExports::GdipGetImageType(nativeImage, &type)); 240 241 return type; 242} 243 244inline Status 245Image::GetPhysicalDimension( 246 OUT SizeF* size 247 ) 248{ 249 if (size == NULL) 250 { 251 return SetStatus(InvalidParameter); 252 } 253 254 REAL width, height; 255 Status status; 256 257 status = SetStatus(DllExports::GdipGetImageDimension(nativeImage, 258 &width, &height)); 259 260 size->Width = width; 261 size->Height = height; 262 263 return status; 264} 265 266inline Status 267Image::GetBounds( 268 OUT RectF *srcRect, 269 OUT Unit *srcUnit 270 ) 271{ 272 return SetStatus(DllExports::GdipGetImageBounds(nativeImage, 273 srcRect, srcUnit)); 274} 275 276inline UINT 277Image::GetWidth() 278{ 279 UINT width = 0; 280 281 SetStatus(DllExports::GdipGetImageWidth(nativeImage, &width)); 282 283 return width; 284} 285 286inline UINT 287Image::GetHeight() 288{ 289 UINT height = 0; 290 291 SetStatus(DllExports::GdipGetImageHeight(nativeImage, &height)); 292 293 return height; 294} 295 296inline REAL 297Image::GetHorizontalResolution() 298{ 299 REAL resolution = 0.0f; 300 301 SetStatus(DllExports::GdipGetImageHorizontalResolution(nativeImage, &resolution)); 302 303 return resolution; 304} 305 306inline REAL 307Image::GetVerticalResolution() 308{ 309 REAL resolution = 0.0f; 310 311 SetStatus(DllExports::GdipGetImageVerticalResolution(nativeImage, &resolution)); 312 313 return resolution; 314} 315 316inline UINT 317Image::GetFlags() 318{ 319 UINT flags = 0; 320 321 SetStatus(DllExports::GdipGetImageFlags(nativeImage, &flags)); 322 323 return flags; 324} 325 326inline Status 327Image::GetRawFormat(OUT GUID *format) 328{ 329 return SetStatus(DllExports::GdipGetImageRawFormat(nativeImage, format)); 330} 331 332inline PixelFormat 333Image::GetPixelFormat() 334{ 335 PixelFormat format; 336 337 SetStatus(DllExports::GdipGetImagePixelFormat(nativeImage, &format)); 338 339 return format; 340} 341 342inline INT 343Image::GetPaletteSize() 344{ 345 INT size = 0; 346 347 SetStatus(DllExports::GdipGetImagePaletteSize(nativeImage, &size)); 348 349 return size; 350} 351 352inline Status 353Image::GetPalette( 354 OUT ColorPalette *palette, 355 IN INT size 356) 357{ 358 return SetStatus(DllExports::GdipGetImagePalette(nativeImage, palette, size)); 359} 360 361inline Status 362Image::SetPalette( 363 IN const ColorPalette *palette 364 ) 365{ 366 return SetStatus(DllExports::GdipSetImagePalette(nativeImage, palette)); 367} 368 369// Thumbnail support 370 371inline Image* 372Image::GetThumbnailImage( 373 IN UINT thumbWidth, 374 IN UINT thumbHeight, 375 IN GetThumbnailImageAbort callback, 376 IN VOID* callbackData 377 ) 378{ 379 GpImage *thumbimage = NULL; 380 381 SetStatus(DllExports::GdipGetImageThumbnail(nativeImage, 382 thumbWidth, thumbHeight, 383 &thumbimage, 384 callback, callbackData)); 385 386 Image *newImage = new Image(thumbimage, lastResult); 387 388 if (newImage == NULL) 389 { 390 DllExports::GdipDisposeImage(thumbimage); 391 } 392 393 return newImage; 394} 395 396// Multi-frame support 397inline UINT 398Image::GetFrameDimensionsCount() 399{ 400 UINT count = 0; 401 402 SetStatus(DllExports::GdipImageGetFrameDimensionsCount(nativeImage, 403 &count)); 404 405 return count; 406} 407 408inline Status 409Image::GetFrameDimensionsList( 410 OUT GUID* dimensionIDs, 411 IN UINT count 412 ) 413{ 414 return SetStatus(DllExports::GdipImageGetFrameDimensionsList(nativeImage, 415 dimensionIDs, 416 count)); 417} 418 419inline UINT 420Image::GetFrameCount( 421 IN const GUID* dimensionID 422 ) 423{ 424 UINT count = 0; 425 426 SetStatus(DllExports::GdipImageGetFrameCount(nativeImage, 427 dimensionID, 428 &count)); 429 return count; 430} 431 432inline Status 433Image::SelectActiveFrame( 434 IN const GUID *dimensionID, 435 IN UINT frameIndex 436 ) 437{ 438 return SetStatus(DllExports::GdipImageSelectActiveFrame(nativeImage, 439 dimensionID, 440 frameIndex)); 441} 442 443inline Status 444Image::RotateFlip( 445 IN RotateFlipType rotateFlipType 446 ) 447{ 448 return SetStatus(DllExports::GdipImageRotateFlip(nativeImage, 449 rotateFlipType)); 450} 451 452// Image property related functions 453 454inline UINT 455Image::GetPropertyCount() 456{ 457 UINT numProperty = 0; 458 459 SetStatus(DllExports::GdipGetPropertyCount(nativeImage, 460 &numProperty)); 461 462 return numProperty; 463} 464 465inline Status 466Image::GetPropertyIdList( 467 IN UINT numOfProperty, 468 OUT PROPID* list 469 ) 470{ 471 return SetStatus(DllExports::GdipGetPropertyIdList(nativeImage, 472 numOfProperty, list)); 473} 474 475inline UINT 476Image::GetPropertyItemSize( 477 IN PROPID propId 478 ) 479{ 480 UINT size = 0; 481 482 SetStatus(DllExports::GdipGetPropertyItemSize(nativeImage, 483 propId, 484 &size)); 485 486 return size; 487} 488 489inline Status 490Image::GetPropertyItem( 491 IN PROPID propId, 492 IN UINT propSize, 493 OUT PropertyItem* buffer 494 ) 495{ 496 return SetStatus(DllExports::GdipGetPropertyItem(nativeImage, 497 propId, propSize, buffer)); 498} 499 500inline Status 501Image::GetPropertySize( 502 OUT UINT* totalBufferSize, 503 OUT UINT* numProperties 504 ) 505{ 506 return SetStatus(DllExports::GdipGetPropertySize(nativeImage, 507 totalBufferSize, 508 numProperties)); 509} 510 511inline Status 512Image::GetAllPropertyItems( 513 IN UINT totalBufferSize, 514 IN UINT numProperties, 515 OUT PropertyItem* allItems 516 ) 517{ 518 if (allItems == NULL) 519 { 520 return SetStatus(InvalidParameter); 521 } 522 return SetStatus(DllExports::GdipGetAllPropertyItems(nativeImage, 523 totalBufferSize, 524 numProperties, 525 allItems)); 526} 527 528inline Status 529Image::RemovePropertyItem( 530 IN PROPID propId 531 ) 532{ 533 return SetStatus(DllExports::GdipRemovePropertyItem(nativeImage, propId)); 534} 535 536inline Status 537Image::SetPropertyItem( 538 IN const PropertyItem* item 539 ) 540{ 541 return SetStatus(DllExports::GdipSetPropertyItem(nativeImage, item)); 542} 543 544// Get/SetLayout 545// Support for Middle East localization (right-to-left mirroring) 546 547inline ImageLayout 548Image::GetLayout() const 549{ 550 ImageLayout layout; 551 552 SetStatus(DllExports::GdipGetImageLayout(nativeImage, &layout)); 553 554 return layout; 555} 556 557inline Status 558Image::SetLayout(IN const ImageLayout layout) 559{ 560 return SetStatus( 561 DllExports::GdipSetImageLayout(nativeImage, layout) 562 ); 563} 564 565inline Status 566Image::GetLastStatus() const 567{ 568 Status lastStatus = lastResult; 569 lastResult = Ok; 570 571 return lastStatus; 572} 573 574inline 575Image::Image(GpImage *nativeImage, Status status) 576{ 577 SetNativeImage(nativeImage); 578 lastResult = status; 579} 580 581inline VOID 582Image::SetNativeImage(GpImage *nativeImage) 583{ 584 this->nativeImage = nativeImage; 585} 586 587inline 588Bitmap::Bitmap( 589 IN const WCHAR *filename, 590 IN BOOL useEmbeddedColorManagement 591 ) 592{ 593 GpBitmap *bitmap = NULL; 594 595 if(useEmbeddedColorManagement) 596 { 597 lastResult = DllExports::GdipCreateBitmapFromFileICM(filename, &bitmap); 598 } 599 else 600 { 601 lastResult = DllExports::GdipCreateBitmapFromFile(filename, &bitmap); 602 } 603 604 SetNativeImage(bitmap); 605} 606 607inline 608Bitmap::Bitmap( 609 IN IStream *stream, 610 IN BOOL useEmbeddedColorManagement 611 ) 612{ 613 GpBitmap *bitmap = NULL; 614 615 if(useEmbeddedColorManagement) 616 { 617 lastResult = DllExports::GdipCreateBitmapFromStreamICM(stream, &bitmap); 618 } 619 else 620 { 621 lastResult = DllExports::GdipCreateBitmapFromStream(stream, &bitmap); 622 } 623 624 SetNativeImage(bitmap); 625} 626 627inline 628Bitmap::Bitmap( 629 IN INT width, 630 IN INT height, 631 IN INT stride, 632 IN PixelFormat format, 633 IN BYTE *scan0 634 ) 635{ 636 GpBitmap *bitmap = NULL; 637 638 lastResult = DllExports::GdipCreateBitmapFromScan0(width, 639 height, 640 stride, 641 format, 642 scan0, 643 &bitmap); 644 645 SetNativeImage(bitmap); 646} 647 648inline 649Bitmap::Bitmap( 650 IN INT width, 651 IN INT height, 652 IN PixelFormat format 653 ) 654{ 655 GpBitmap *bitmap = NULL; 656 657 lastResult = DllExports::GdipCreateBitmapFromScan0(width, 658 height, 659 0, 660 format, 661 NULL, 662 &bitmap); 663 664 SetNativeImage(bitmap); 665} 666 667inline 668Bitmap::Bitmap( 669 IN INT width, 670 IN INT height, 671 IN Graphics* target) 672{ 673 GpBitmap *bitmap = NULL; 674 675 lastResult = DllExports::GdipCreateBitmapFromGraphics(width, 676 height, 677 target->nativeGraphics, 678 &bitmap); 679 680 SetNativeImage(bitmap); 681} 682 683inline 684Bitmap::Bitmap( 685 IN IDirectDrawSurface7 * surface 686 ) 687{ 688 GpBitmap *bitmap = NULL; 689 690 lastResult = DllExports::GdipCreateBitmapFromDirectDrawSurface(surface, 691 &bitmap); 692 693 SetNativeImage(bitmap); 694} 695 696inline 697Bitmap::Bitmap( 698 IN const BITMAPINFO* gdiBitmapInfo, 699 IN VOID* gdiBitmapData 700 ) 701{ 702 GpBitmap *bitmap = NULL; 703 704 lastResult = DllExports::GdipCreateBitmapFromGdiDib(gdiBitmapInfo, 705 gdiBitmapData, 706 &bitmap); 707 708 SetNativeImage(bitmap); 709} 710 711inline 712Bitmap::Bitmap( 713 IN HBITMAP hbm, 714 IN HPALETTE hpal 715 ) 716{ 717 GpBitmap *bitmap = NULL; 718 719 lastResult = DllExports::GdipCreateBitmapFromHBITMAP(hbm, hpal, &bitmap); 720 721 SetNativeImage(bitmap); 722} 723 724inline 725Bitmap::Bitmap( 726 IN HICON hicon 727 ) 728{ 729 GpBitmap *bitmap = NULL; 730 731 lastResult = DllExports::GdipCreateBitmapFromHICON(hicon, &bitmap); 732 733 SetNativeImage(bitmap); 734} 735 736inline 737Bitmap::Bitmap( 738 IN HINSTANCE hInstance, 739 IN const WCHAR *bitmapName 740 ) 741{ 742 GpBitmap *bitmap = NULL; 743 744 lastResult = DllExports::GdipCreateBitmapFromResource(hInstance, 745 bitmapName, 746 &bitmap); 747 748 SetNativeImage(bitmap); 749} 750 751 752inline Bitmap* 753Bitmap::FromFile( 754 IN const WCHAR *filename, 755 IN BOOL useEmbeddedColorManagement 756 ) 757{ 758 return new Bitmap( 759 filename, 760 useEmbeddedColorManagement 761 ); 762} 763 764inline Bitmap* 765Bitmap::FromStream( 766 IN IStream *stream, 767 IN BOOL useEmbeddedColorManagement 768 ) 769{ 770 return new Bitmap( 771 stream, 772 useEmbeddedColorManagement 773 ); 774} 775 776inline Bitmap* 777Bitmap::FromDirectDrawSurface7( 778 IN IDirectDrawSurface7* surface 779 ) 780{ 781 return new Bitmap(surface); 782} 783 784inline Bitmap* 785Bitmap::FromBITMAPINFO( 786 IN const BITMAPINFO* gdiBitmapInfo, 787 IN VOID* gdiBitmapData) 788{ 789 return new Bitmap(gdiBitmapInfo, gdiBitmapData); 790} 791 792inline Bitmap* 793Bitmap::FromHBITMAP( 794 IN HBITMAP hbm, 795 IN HPALETTE hpal 796 ) 797{ 798 return new Bitmap(hbm, hpal); 799} 800 801inline Bitmap* 802Bitmap::FromHICON( 803 IN HICON hicon 804 ) 805{ 806 return new Bitmap(hicon); 807} 808 809inline Bitmap* 810Bitmap::FromResource( 811 IN HINSTANCE hInstance, 812 IN const WCHAR *bitmapName) 813{ 814 return new Bitmap(hInstance, bitmapName); 815} 816 817inline Status 818Bitmap::GetHBITMAP( 819 IN const Color& colorBackground, 820 OUT HBITMAP* hbmReturn 821 ) 822{ 823 return SetStatus(DllExports::GdipCreateHBITMAPFromBitmap( 824 static_cast<GpBitmap*>(nativeImage), 825 hbmReturn, 826 colorBackground.GetValue())); 827} 828 829inline Status 830Bitmap::GetHICON( 831 OUT HICON* hiconReturn 832 ) 833{ 834 return SetStatus(DllExports::GdipCreateHICONFromBitmap( 835 static_cast<GpBitmap*>(nativeImage), 836 hiconReturn)); 837} 838 839inline Bitmap* 840Bitmap::Clone( 841 IN const Rect& rect, 842 IN PixelFormat format 843 ) 844{ 845 return Clone(rect.X, rect.Y, rect.Width, rect.Height, format); 846} 847 848inline Bitmap* 849Bitmap::Clone( 850 IN INT x, 851 IN INT y, 852 IN INT width, 853 IN INT height, 854 IN PixelFormat format 855 ) 856{ 857 GpBitmap* gpdstBitmap = NULL; 858 Bitmap* bitmap; 859 860 lastResult = DllExports::GdipCloneBitmapAreaI( 861 x, 862 y, 863 width, 864 height, 865 format, 866 (GpBitmap *)nativeImage, 867 &gpdstBitmap); 868 869 if (lastResult == Ok) 870 { 871 bitmap = new Bitmap(gpdstBitmap); 872 873 if (bitmap == NULL) 874 { 875 DllExports::GdipDisposeImage(gpdstBitmap); 876 } 877 878 return bitmap; 879 } 880 else 881 return NULL; 882} 883 884inline Bitmap* 885Bitmap::Clone( 886 IN const RectF& rect, 887 IN PixelFormat format 888 ) 889{ 890 return Clone(rect.X, rect.Y, rect.Width, rect.Height, format); 891} 892 893inline Bitmap* 894Bitmap::Clone( 895 IN REAL x, 896 IN REAL y, 897 IN REAL width, 898 IN REAL height, 899 IN PixelFormat format 900 ) 901{ 902 GpBitmap* gpdstBitmap = NULL; 903 Bitmap* bitmap; 904 905 SetStatus(DllExports::GdipCloneBitmapArea( 906 x, 907 y, 908 width, 909 height, 910 format, 911 (GpBitmap *)nativeImage, 912 &gpdstBitmap)); 913 914 if (lastResult == Ok) 915 { 916 bitmap = new Bitmap(gpdstBitmap); 917 918 if (bitmap == NULL) 919 { 920 DllExports::GdipDisposeImage(gpdstBitmap); 921 } 922 923 return bitmap; 924 } 925 else 926 return NULL; 927} 928 929inline Bitmap::Bitmap(GpBitmap *nativeBitmap) 930{ 931 lastResult = Ok; 932 933 SetNativeImage(nativeBitmap); 934} 935 936inline Status 937Bitmap::LockBits( 938 IN const Rect& rect, 939 IN UINT flags, 940 IN PixelFormat format, 941 OUT BitmapData* lockedBitmapData 942) 943{ 944 return SetStatus(DllExports::GdipBitmapLockBits( 945 static_cast<GpBitmap*>(nativeImage), 946 &rect, 947 flags, 948 format, 949 lockedBitmapData)); 950} 951 952inline Status 953Bitmap::UnlockBits( 954 IN BitmapData* lockedBitmapData 955 ) 956{ 957 return SetStatus(DllExports::GdipBitmapUnlockBits( 958 static_cast<GpBitmap*>(nativeImage), 959 lockedBitmapData)); 960} 961 962inline Status 963Bitmap::GetPixel( 964 IN INT x, 965 IN INT y, 966 OUT Color *color) 967{ 968 ARGB argb; 969 970 Status status = SetStatus(DllExports::GdipBitmapGetPixel( 971 static_cast<GpBitmap *>(nativeImage), 972 x, y, 973 &argb)); 974 975 if (status == Ok) 976 { 977 color->SetValue(argb); 978 } 979 980 return status; 981} 982 983inline Status 984Bitmap::SetPixel( 985 IN INT x, 986 IN INT y, 987 IN const Color& color) 988{ 989 return SetStatus(DllExports::GdipBitmapSetPixel( 990 static_cast<GpBitmap *>(nativeImage), 991 x, y, 992 color.GetValue())); 993} 994 995inline Status 996Bitmap::SetResolution( 997 IN REAL xdpi, 998 IN REAL ydpi) 999{ 1000 return SetStatus(DllExports::GdipBitmapSetResolution( 1001 static_cast<GpBitmap *>(nativeImage), 1002 xdpi, ydpi)); 1003} 1004#endif 1005