Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

925 lines
20 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1998-2001, Microsoft Corp. All Rights Reserved.
  4. *
  5. * Module Name:
  6. *
  7. * GdiplusBitmap.h
  8. *
  9. * Abstract:
  10. *
  11. * GDI+ Bitmap class
  12. *
  13. \**************************************************************************/
  14. #ifndef _GDIPLUSBITMAP_H
  15. #define _GDIPLUSBITMAP_H
  16. inline
  17. Image::Image(
  18. IN const WCHAR* filename,
  19. IN BOOL useEmbeddedColorManagement
  20. )
  21. {
  22. nativeImage = NULL;
  23. if(useEmbeddedColorManagement)
  24. {
  25. lastResult = DllExports::GdipLoadImageFromFileICM(
  26. filename,
  27. &nativeImage
  28. );
  29. }
  30. else
  31. {
  32. lastResult = DllExports::GdipLoadImageFromFile(
  33. filename,
  34. &nativeImage
  35. );
  36. }
  37. }
  38. inline
  39. Image::Image(
  40. IN IStream* stream,
  41. IN BOOL useEmbeddedColorManagement
  42. )
  43. {
  44. nativeImage = NULL;
  45. if(useEmbeddedColorManagement)
  46. {
  47. lastResult = DllExports::GdipLoadImageFromStreamICM(
  48. stream,
  49. &nativeImage
  50. );
  51. }
  52. else
  53. {
  54. lastResult = DllExports::GdipLoadImageFromStream(
  55. stream,
  56. &nativeImage
  57. );
  58. }
  59. }
  60. inline Image*
  61. Image::FromFile(
  62. IN const WCHAR* filename,
  63. IN BOOL useEmbeddedColorManagement
  64. )
  65. {
  66. return new Image(
  67. filename,
  68. useEmbeddedColorManagement
  69. );
  70. }
  71. inline Image*
  72. Image::FromStream(
  73. IN IStream* stream,
  74. IN BOOL useEmbeddedColorManagement
  75. )
  76. {
  77. return new Image(
  78. stream,
  79. useEmbeddedColorManagement
  80. );
  81. }
  82. inline
  83. Image::~Image()
  84. {
  85. DllExports::GdipDisposeImage(nativeImage);
  86. }
  87. inline Image*
  88. Image::Clone()
  89. {
  90. GpImage *cloneimage = NULL;
  91. SetStatus(DllExports::GdipCloneImage(nativeImage, &cloneimage));
  92. return new Image(cloneimage, lastResult);
  93. }
  94. inline UINT
  95. Image::GetEncoderParameterListSize(
  96. IN const CLSID* clsidEncoder
  97. )
  98. {
  99. UINT size = 0;
  100. SetStatus(DllExports::GdipGetEncoderParameterListSize(nativeImage,
  101. clsidEncoder,
  102. &size));
  103. return size;
  104. }
  105. inline Status
  106. Image::GetEncoderParameterList(
  107. IN const CLSID* clsidEncoder,
  108. IN UINT size,
  109. OUT EncoderParameters* buffer
  110. )
  111. {
  112. return SetStatus(DllExports::GdipGetEncoderParameterList(nativeImage,
  113. clsidEncoder,
  114. size,
  115. buffer));
  116. }
  117. inline Status
  118. Image::Save(
  119. IN const WCHAR* filename,
  120. IN const CLSID* clsidEncoder,
  121. IN const EncoderParameters *encoderParams
  122. )
  123. {
  124. return SetStatus(DllExports::GdipSaveImageToFile(nativeImage,
  125. filename,
  126. clsidEncoder,
  127. encoderParams));
  128. }
  129. inline Status
  130. Image::Save(
  131. IN IStream* stream,
  132. IN const CLSID* clsidEncoder,
  133. IN const EncoderParameters *encoderParams
  134. )
  135. {
  136. return SetStatus(DllExports::GdipSaveImageToStream(nativeImage,
  137. stream,
  138. clsidEncoder,
  139. encoderParams));
  140. }
  141. inline Status
  142. Image::SaveAdd(
  143. IN const EncoderParameters *encoderParams
  144. )
  145. {
  146. return SetStatus(DllExports::GdipSaveAdd(nativeImage,
  147. encoderParams));
  148. }
  149. inline Status
  150. Image::SaveAdd(
  151. IN Image* newImage,
  152. IN const EncoderParameters *encoderParams
  153. )
  154. {
  155. if ( newImage == NULL )
  156. {
  157. return SetStatus(InvalidParameter);
  158. }
  159. return SetStatus(DllExports::GdipSaveAddImage(nativeImage,
  160. newImage->nativeImage,
  161. encoderParams));
  162. }
  163. inline ImageType
  164. Image::GetType() const
  165. {
  166. ImageType type = ImageTypeUnknown;
  167. SetStatus(DllExports::GdipGetImageType(nativeImage, &type));
  168. return type;
  169. }
  170. inline Status
  171. Image::GetPhysicalDimension(
  172. OUT SizeF* size
  173. )
  174. {
  175. if (size == NULL)
  176. {
  177. return SetStatus(InvalidParameter);
  178. }
  179. REAL width, height;
  180. Status status;
  181. status = SetStatus(DllExports::GdipGetImageDimension(nativeImage,
  182. &width, &height));
  183. size->Width = width;
  184. size->Height = height;
  185. return status;
  186. }
  187. inline Status
  188. Image::GetBounds(
  189. OUT RectF *srcRect,
  190. OUT Unit *srcUnit
  191. )
  192. {
  193. return SetStatus(DllExports::GdipGetImageBounds(nativeImage,
  194. srcRect, srcUnit));
  195. }
  196. inline UINT
  197. Image::GetWidth()
  198. {
  199. UINT width = 0;
  200. SetStatus(DllExports::GdipGetImageWidth(nativeImage, &width));
  201. return width;
  202. }
  203. inline UINT
  204. Image::GetHeight()
  205. {
  206. UINT height = 0;
  207. SetStatus(DllExports::GdipGetImageHeight(nativeImage, &height));
  208. return height;
  209. }
  210. inline REAL
  211. Image::GetHorizontalResolution()
  212. {
  213. REAL resolution = 0.0f;
  214. SetStatus(DllExports::GdipGetImageHorizontalResolution(nativeImage, &resolution));
  215. return resolution;
  216. }
  217. inline REAL
  218. Image::GetVerticalResolution()
  219. {
  220. REAL resolution = 0.0f;
  221. SetStatus(DllExports::GdipGetImageVerticalResolution(nativeImage, &resolution));
  222. return resolution;
  223. }
  224. inline UINT
  225. Image::GetFlags()
  226. {
  227. UINT flags = 0;
  228. SetStatus(DllExports::GdipGetImageFlags(nativeImage, &flags));
  229. return flags;
  230. }
  231. inline Status
  232. Image::GetRawFormat(OUT GUID *format)
  233. {
  234. return SetStatus(DllExports::GdipGetImageRawFormat(nativeImage, format));
  235. }
  236. inline PixelFormat
  237. Image::GetPixelFormat()
  238. {
  239. PixelFormat format;
  240. SetStatus(DllExports::GdipGetImagePixelFormat(nativeImage, &format));
  241. return format;
  242. }
  243. inline INT
  244. Image::GetPaletteSize()
  245. {
  246. INT size = 0;
  247. SetStatus(DllExports::GdipGetImagePaletteSize(nativeImage, &size));
  248. return size;
  249. }
  250. inline Status
  251. Image::GetPalette(
  252. OUT ColorPalette *palette,
  253. IN INT size
  254. )
  255. {
  256. return SetStatus(DllExports::GdipGetImagePalette(nativeImage, palette, size));
  257. }
  258. inline Status
  259. Image::SetPalette(
  260. IN const ColorPalette *palette
  261. )
  262. {
  263. return SetStatus(DllExports::GdipSetImagePalette(nativeImage, palette));
  264. }
  265. inline Image*
  266. Image::GetThumbnailImage(
  267. IN UINT thumbWidth,
  268. IN UINT thumbHeight,
  269. IN GetThumbnailImageAbort callback,
  270. IN VOID* callbackData
  271. )
  272. {
  273. GpImage *thumbimage = NULL;
  274. SetStatus(DllExports::GdipGetImageThumbnail(nativeImage,
  275. thumbWidth, thumbHeight,
  276. &thumbimage,
  277. callback, callbackData));
  278. Image *newImage = new Image(thumbimage, lastResult);
  279. if (newImage == NULL)
  280. {
  281. DllExports::GdipDisposeImage(thumbimage);
  282. }
  283. return newImage;
  284. }
  285. inline UINT
  286. Image::GetFrameDimensionsCount()
  287. {
  288. UINT count = 0;
  289. SetStatus(DllExports::GdipImageGetFrameDimensionsCount(nativeImage,
  290. &count));
  291. return count;
  292. }
  293. inline Status
  294. Image::GetFrameDimensionsList(
  295. OUT GUID* dimensionIDs,
  296. IN UINT count
  297. )
  298. {
  299. return SetStatus(DllExports::GdipImageGetFrameDimensionsList(nativeImage,
  300. dimensionIDs,
  301. count));
  302. }
  303. inline UINT
  304. Image::GetFrameCount(
  305. IN const GUID* dimensionID
  306. )
  307. {
  308. UINT count = 0;
  309. SetStatus(DllExports::GdipImageGetFrameCount(nativeImage,
  310. dimensionID,
  311. &count));
  312. return count;
  313. }
  314. inline Status
  315. Image::SelectActiveFrame(
  316. IN const GUID *dimensionID,
  317. IN UINT frameIndex
  318. )
  319. {
  320. return SetStatus(DllExports::GdipImageSelectActiveFrame(nativeImage,
  321. dimensionID,
  322. frameIndex));
  323. }
  324. inline Status
  325. Image::RotateFlip(
  326. IN RotateFlipType rotateFlipType
  327. )
  328. {
  329. return SetStatus(DllExports::GdipImageRotateFlip(nativeImage,
  330. rotateFlipType));
  331. }
  332. inline UINT
  333. Image::GetPropertyCount()
  334. {
  335. UINT numProperty = 0;
  336. SetStatus(DllExports::GdipGetPropertyCount(nativeImage,
  337. &numProperty));
  338. return numProperty;
  339. }
  340. inline Status
  341. Image::GetPropertyIdList(
  342. IN UINT numOfProperty,
  343. OUT PROPID* list
  344. )
  345. {
  346. return SetStatus(DllExports::GdipGetPropertyIdList(nativeImage,
  347. numOfProperty, list));
  348. }
  349. inline UINT
  350. Image::GetPropertyItemSize(
  351. IN PROPID propId
  352. )
  353. {
  354. UINT size = 0;
  355. SetStatus(DllExports::GdipGetPropertyItemSize(nativeImage,
  356. propId,
  357. &size));
  358. return size;
  359. }
  360. inline Status
  361. Image::GetPropertyItem(
  362. IN PROPID propId,
  363. IN UINT propSize,
  364. OUT PropertyItem* buffer
  365. )
  366. {
  367. return SetStatus(DllExports::GdipGetPropertyItem(nativeImage,
  368. propId, propSize, buffer));
  369. }
  370. inline Status
  371. Image::GetPropertySize(
  372. OUT UINT* totalBufferSize,
  373. OUT UINT* numProperties
  374. )
  375. {
  376. return SetStatus(DllExports::GdipGetPropertySize(nativeImage,
  377. totalBufferSize,
  378. numProperties));
  379. }
  380. inline Status
  381. Image::GetAllPropertyItems(
  382. IN UINT totalBufferSize,
  383. IN UINT numProperties,
  384. OUT PropertyItem* allItems
  385. )
  386. {
  387. if (allItems == NULL)
  388. {
  389. return SetStatus(InvalidParameter);
  390. }
  391. return SetStatus(DllExports::GdipGetAllPropertyItems(nativeImage,
  392. totalBufferSize,
  393. numProperties,
  394. allItems));
  395. }
  396. inline Status
  397. Image::RemovePropertyItem(
  398. IN PROPID propId
  399. )
  400. {
  401. return SetStatus(DllExports::GdipRemovePropertyItem(nativeImage, propId));
  402. }
  403. inline Status
  404. Image::SetPropertyItem(
  405. IN const PropertyItem* item
  406. )
  407. {
  408. return SetStatus(DllExports::GdipSetPropertyItem(nativeImage, item));
  409. }
  410. inline Status
  411. Image::GetLastStatus() const
  412. {
  413. Status lastStatus = lastResult;
  414. lastResult = Ok;
  415. return lastStatus;
  416. }
  417. inline
  418. Image::Image(GpImage *nativeImage, Status status)
  419. {
  420. SetNativeImage(nativeImage);
  421. lastResult = status;
  422. }
  423. inline VOID
  424. Image::SetNativeImage(GpImage *nativeImage)
  425. {
  426. this->nativeImage = nativeImage;
  427. }
  428. inline
  429. Bitmap::Bitmap(
  430. IN const WCHAR *filename,
  431. IN BOOL useEmbeddedColorManagement
  432. )
  433. {
  434. GpBitmap *bitmap = NULL;
  435. if(useEmbeddedColorManagement)
  436. {
  437. lastResult = DllExports::GdipCreateBitmapFromFileICM(filename, &bitmap);
  438. }
  439. else
  440. {
  441. lastResult = DllExports::GdipCreateBitmapFromFile(filename, &bitmap);
  442. }
  443. SetNativeImage(bitmap);
  444. }
  445. inline
  446. Bitmap::Bitmap(
  447. IN IStream *stream,
  448. IN BOOL useEmbeddedColorManagement
  449. )
  450. {
  451. GpBitmap *bitmap = NULL;
  452. if(useEmbeddedColorManagement)
  453. {
  454. lastResult = DllExports::GdipCreateBitmapFromStreamICM(stream, &bitmap);
  455. }
  456. else
  457. {
  458. lastResult = DllExports::GdipCreateBitmapFromStream(stream, &bitmap);
  459. }
  460. SetNativeImage(bitmap);
  461. }
  462. inline
  463. Bitmap::Bitmap(
  464. IN INT width,
  465. IN INT height,
  466. IN INT stride,
  467. IN PixelFormat format,
  468. IN BYTE *scan0
  469. )
  470. {
  471. GpBitmap *bitmap = NULL;
  472. lastResult = DllExports::GdipCreateBitmapFromScan0(width,
  473. height,
  474. stride,
  475. format,
  476. scan0,
  477. &bitmap);
  478. SetNativeImage(bitmap);
  479. }
  480. inline
  481. Bitmap::Bitmap(
  482. IN INT width,
  483. IN INT height,
  484. IN PixelFormat format
  485. )
  486. {
  487. GpBitmap *bitmap = NULL;
  488. lastResult = DllExports::GdipCreateBitmapFromScan0(width,
  489. height,
  490. 0,
  491. format,
  492. NULL,
  493. &bitmap);
  494. SetNativeImage(bitmap);
  495. }
  496. inline
  497. Bitmap::Bitmap(
  498. IN INT width,
  499. IN INT height,
  500. IN Graphics* target)
  501. {
  502. GpBitmap *bitmap = NULL;
  503. lastResult = DllExports::GdipCreateBitmapFromGraphics(width,
  504. height,
  505. target->nativeGraphics,
  506. &bitmap);
  507. SetNativeImage(bitmap);
  508. }
  509. inline
  510. Bitmap::Bitmap(
  511. IN IDirectDrawSurface7 * surface
  512. )
  513. {
  514. GpBitmap *bitmap = NULL;
  515. lastResult = DllExports::GdipCreateBitmapFromDirectDrawSurface(surface,
  516. &bitmap);
  517. SetNativeImage(bitmap);
  518. }
  519. inline
  520. Bitmap::Bitmap(
  521. IN const BITMAPINFO* gdiBitmapInfo,
  522. IN VOID* gdiBitmapData
  523. )
  524. {
  525. GpBitmap *bitmap = NULL;
  526. lastResult = DllExports::GdipCreateBitmapFromGdiDib(gdiBitmapInfo,
  527. gdiBitmapData,
  528. &bitmap);
  529. SetNativeImage(bitmap);
  530. }
  531. inline
  532. Bitmap::Bitmap(
  533. IN HBITMAP hbm,
  534. IN HPALETTE hpal
  535. )
  536. {
  537. GpBitmap *bitmap = NULL;
  538. lastResult = DllExports::GdipCreateBitmapFromHBITMAP(hbm, hpal, &bitmap);
  539. SetNativeImage(bitmap);
  540. }
  541. inline
  542. Bitmap::Bitmap(
  543. IN HICON hicon
  544. )
  545. {
  546. GpBitmap *bitmap = NULL;
  547. lastResult = DllExports::GdipCreateBitmapFromHICON(hicon, &bitmap);
  548. SetNativeImage(bitmap);
  549. }
  550. inline
  551. Bitmap::Bitmap(
  552. IN HINSTANCE hInstance,
  553. IN const WCHAR *bitmapName
  554. )
  555. {
  556. GpBitmap *bitmap = NULL;
  557. lastResult = DllExports::GdipCreateBitmapFromResource(hInstance,
  558. bitmapName,
  559. &bitmap);
  560. SetNativeImage(bitmap);
  561. }
  562. inline Bitmap*
  563. Bitmap::FromFile(
  564. IN const WCHAR *filename,
  565. IN BOOL useEmbeddedColorManagement
  566. )
  567. {
  568. return new Bitmap(
  569. filename,
  570. useEmbeddedColorManagement
  571. );
  572. }
  573. inline Bitmap*
  574. Bitmap::FromStream(
  575. IN IStream *stream,
  576. IN BOOL useEmbeddedColorManagement
  577. )
  578. {
  579. return new Bitmap(
  580. stream,
  581. useEmbeddedColorManagement
  582. );
  583. }
  584. inline Bitmap*
  585. Bitmap::FromDirectDrawSurface7(
  586. IN IDirectDrawSurface7* surface
  587. )
  588. {
  589. return new Bitmap(surface);
  590. }
  591. inline Bitmap*
  592. Bitmap::FromBITMAPINFO(
  593. IN const BITMAPINFO* gdiBitmapInfo,
  594. IN VOID* gdiBitmapData)
  595. {
  596. return new Bitmap(gdiBitmapInfo, gdiBitmapData);
  597. }
  598. inline Bitmap*
  599. Bitmap::FromHBITMAP(
  600. IN HBITMAP hbm,
  601. IN HPALETTE hpal
  602. )
  603. {
  604. return new Bitmap(hbm, hpal);
  605. }
  606. inline Bitmap*
  607. Bitmap::FromHICON(
  608. IN HICON hicon
  609. )
  610. {
  611. return new Bitmap(hicon);
  612. }
  613. inline Bitmap*
  614. Bitmap::FromResource(
  615. IN HINSTANCE hInstance,
  616. IN const WCHAR *bitmapName)
  617. {
  618. return new Bitmap(hInstance, bitmapName);
  619. }
  620. inline Status
  621. Bitmap::GetHBITMAP(
  622. IN const Color& colorBackground,
  623. OUT HBITMAP* hbmReturn
  624. )
  625. {
  626. return SetStatus(DllExports::GdipCreateHBITMAPFromBitmap(
  627. static_cast<GpBitmap*>(nativeImage),
  628. hbmReturn,
  629. colorBackground.GetValue()));
  630. }
  631. inline Status
  632. Bitmap::GetHICON(
  633. OUT HICON* hiconReturn
  634. )
  635. {
  636. return SetStatus(DllExports::GdipCreateHICONFromBitmap(
  637. static_cast<GpBitmap*>(nativeImage),
  638. hiconReturn));
  639. }
  640. inline Bitmap*
  641. Bitmap::Clone(
  642. IN const Rect& rect,
  643. IN PixelFormat format
  644. )
  645. {
  646. return Clone(rect.X, rect.Y, rect.Width, rect.Height, format);
  647. }
  648. inline Bitmap*
  649. Bitmap::Clone(
  650. IN INT x,
  651. IN INT y,
  652. IN INT width,
  653. IN INT height,
  654. IN PixelFormat format
  655. )
  656. {
  657. GpBitmap* gpdstBitmap = NULL;
  658. Bitmap* bitmap;
  659. lastResult = DllExports::GdipCloneBitmapAreaI(
  660. x,
  661. y,
  662. width,
  663. height,
  664. format,
  665. (GpBitmap *)nativeImage,
  666. &gpdstBitmap);
  667. if (lastResult == Ok)
  668. {
  669. bitmap = new Bitmap(gpdstBitmap);
  670. if (bitmap == NULL)
  671. {
  672. DllExports::GdipDisposeImage(gpdstBitmap);
  673. }
  674. return bitmap;
  675. }
  676. else
  677. return NULL;
  678. }
  679. inline Bitmap*
  680. Bitmap::Clone(
  681. IN const RectF& rect,
  682. IN PixelFormat format
  683. )
  684. {
  685. return Clone(rect.X, rect.Y, rect.Width, rect.Height, format);
  686. }
  687. inline Bitmap*
  688. Bitmap::Clone(
  689. IN REAL x,
  690. IN REAL y,
  691. IN REAL width,
  692. IN REAL height,
  693. IN PixelFormat format
  694. )
  695. {
  696. GpBitmap* gpdstBitmap = NULL;
  697. Bitmap* bitmap;
  698. SetStatus(DllExports::GdipCloneBitmapArea(
  699. x,
  700. y,
  701. width,
  702. height,
  703. format,
  704. (GpBitmap *)nativeImage,
  705. &gpdstBitmap));
  706. if (lastResult == Ok)
  707. {
  708. bitmap = new Bitmap(gpdstBitmap);
  709. if (bitmap == NULL)
  710. {
  711. DllExports::GdipDisposeImage(gpdstBitmap);
  712. }
  713. return bitmap;
  714. }
  715. else
  716. return NULL;
  717. }
  718. inline Bitmap::Bitmap(GpBitmap *nativeBitmap)
  719. {
  720. lastResult = Ok;
  721. SetNativeImage(nativeBitmap);
  722. }
  723. inline Status
  724. Bitmap::LockBits(
  725. IN const Rect* rect,
  726. IN UINT flags,
  727. IN PixelFormat format,
  728. OUT BitmapData* lockedBitmapData
  729. )
  730. {
  731. return SetStatus(DllExports::GdipBitmapLockBits(
  732. static_cast<GpBitmap*>(nativeImage),
  733. rect,
  734. flags,
  735. format,
  736. lockedBitmapData));
  737. }
  738. inline Status
  739. Bitmap::UnlockBits(
  740. IN BitmapData* lockedBitmapData
  741. )
  742. {
  743. return SetStatus(DllExports::GdipBitmapUnlockBits(
  744. static_cast<GpBitmap*>(nativeImage),
  745. lockedBitmapData));
  746. }
  747. inline Status
  748. Bitmap::GetPixel(
  749. IN INT x,
  750. IN INT y,
  751. OUT Color *color)
  752. {
  753. ARGB argb;
  754. Status status = SetStatus(DllExports::GdipBitmapGetPixel(
  755. static_cast<GpBitmap *>(nativeImage),
  756. x, y,
  757. &argb));
  758. if (status == Ok)
  759. {
  760. color->SetValue(argb);
  761. }
  762. return status;
  763. }
  764. inline Status
  765. Bitmap::SetPixel(
  766. IN INT x,
  767. IN INT y,
  768. IN const Color& color)
  769. {
  770. return SetStatus(DllExports::GdipBitmapSetPixel(
  771. static_cast<GpBitmap *>(nativeImage),
  772. x, y,
  773. color.GetValue()));
  774. }
  775. inline Status
  776. Bitmap::SetResolution(
  777. IN REAL xdpi,
  778. IN REAL ydpi)
  779. {
  780. return SetStatus(DllExports::GdipBitmapSetResolution(
  781. static_cast<GpBitmap *>(nativeImage),
  782. xdpi, ydpi));
  783. }
  784. #endif