home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / Include / FWBitmap.h < prev    next >
Encoding:
Text File  |  1995-11-08  |  9.2 KB  |  315 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWBitmap.h
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWBITMAP_H
  11. #define FWBITMAP_H
  12.  
  13. #ifndef FWGROBJ_H
  14. #include "FWGrObj.h"
  15. #endif
  16.  
  17. #ifndef FWGCONST_H
  18. #include "FWGConst.h"
  19. #endif
  20.  
  21. #ifndef FWRECT_H
  22. #include "FWRect.h"
  23. #endif
  24.  
  25. #ifndef FWGRDEF_H
  26. #include "FWGrDef.h"
  27. #endif
  28.  
  29. #ifndef FWRESOUR_H
  30. #include "FWResour.h"
  31. #endif
  32.  
  33. #ifndef FWGC_H
  34. #include "FWGC.h"
  35. #endif
  36.  
  37. #ifndef FWPALETE_H
  38. #include "FWPalete.h"
  39. #endif
  40.  
  41. #if FW_LIB_EXPORT_PRAGMAS
  42. #pragma lib_export on
  43. #endif
  44.  
  45. const FW_PlatformError FW_xGraphicException = -30020;    // !!!JEL need offical value!!!
  46. const FW_PlatformError FW_xInvalidBitmapData = -30021;
  47.  
  48. //========================================================================================
  49. //    Forward Class Declarations
  50. //========================================================================================
  51.  
  52. class FW_CLASS_ATTR FW_CBitmapRep;
  53. class FW_CLASS_ATTR FW_CWritableStream;
  54. class FW_CLASS_ATTR FW_PPicture;
  55. class FW_CLASS_ATTR FW_CGraphicContext;
  56. class FW_CLASS_ATTR FW_CColor;
  57.  
  58. //========================================================================================
  59. //    class FW_PBitmap
  60. //========================================================================================
  61.  
  62. class FW_CLASS_ATTR FW_PBitmap : public FW_CGraphicCountedPtr
  63. {
  64. public:
  65.     FW_DECLARE_CLASS
  66.  
  67. public:
  68.     FW_PBitmap();
  69.     virtual    ~FW_PBitmap();
  70.     
  71.     FW_PBitmap(short width, short height, short pixelSize, FW_Palette palette = NULL);
  72.     FW_PBitmap(void* image, unsigned long imageSize, short width, short height, short pixelSize, FW_Palette palette = NULL);
  73.  
  74. #ifdef FW_BUILD_MAC
  75.     static const FW_CRect gWholePicture;
  76.     FW_PBitmap(FW_PPicture picture,
  77.               const FW_CColor& fillColor = FW_kRGBWhite,
  78.               const FW_CRect& pictPart = gWholePicture);                    // From a picture
  79. #endif
  80.  
  81.     FW_PBitmap(FW_CResourceFile& resourceFile, FW_ResourceId resId);        // From a Resource
  82.     
  83.     FW_PBitmap(FW_PlatformBitmap platformBitmap);                            // Set fOwnBitmap to FALSE
  84.     
  85.     FW_PBitmap(const FW_PBitmap& other);
  86.     
  87.     FW_PBitmap& operator=(const FW_PBitmap& other);
  88.         
  89.     FW_CBitmapRep* operator->();
  90.     const FW_CBitmapRep* operator->() const;
  91. };
  92.  
  93. //========================================================================================
  94. //    class FW_CBitmapRep
  95. //========================================================================================
  96.  
  97. class FW_CLASS_ATTR FW_CBitmapRep : public FW_CGraphicCountedPtrRep
  98. {
  99.     friend class FW_CLASS_ATTR FW_PBitmap;
  100.  
  101. public:
  102.     FW_DECLARE_CLASS
  103.  
  104. //----------------------------------------------------------------------------------------
  105. //    Constructors/Destructors
  106. //
  107. private:
  108.     FW_CBitmapRep(short width, short height, short pixelSize, FW_Palette palette);
  109.     FW_CBitmapRep(void* image, unsigned long imageSize, short width, short height, short pixelSize, FW_Palette palette);
  110.  
  111. #ifdef FW_BUILD_MAC
  112.     FW_CBitmapRep(FW_PPicture picture, const FW_CColor& fillColor, const FW_CRect& pictPart);
  113. #endif
  114.  
  115.     FW_CBitmapRep(FW_PlatformBitmap platformBitmap);
  116.     FW_CBitmapRep(FW_CResourceFile& resourceFile, FW_ResourceId resId);
  117.  
  118.     FW_CBitmapRep(FW_CReadableStream& archive, FW_Boolean dibFileHeader = TRUE);
  119.     
  120.     virtual ~FW_CBitmapRep();
  121.  
  122. //----------------------------------------------------------------------------------------
  123. //    Inherited API
  124. //
  125. public:
  126.     virtual void            Flatten(FW_CWritableStream& archive) const;
  127.     virtual FW_Boolean        IsEqual(const FW_CGraphicCountedPtrRep* other) const;
  128.     
  129. //----------------------------------------------------------------------------------------
  130. //    New API
  131. //
  132. public:
  133.     // ----- Copying -----
  134.     FW_PBitmap            Copy() const;
  135.     FW_PBitmap            Copy(const FW_CRect& srcRect) const;
  136.     
  137.     // ----- Get, Set, Adopt and Orphan
  138.     FW_PlatformBitmap    GetPlatformBitmap() const;                            // return fPlatformBitmap
  139.     FW_Boolean            IsPlatformBitmapOrphan() const;
  140.     FW_PlatformBitmap    OrphanPlatformBitmap();                                // return fPlatformBitmap, and change ownership 
  141.     
  142.     void                SetPlatformBitmap(FW_PlatformBitmap newBitmap);        // Set a new platform Bitmap (fOwnBitmap = FALSE)
  143.     void                AdoptPlatformBitmap(FW_PlatformBitmap newBitmap);    // Adopt a new platform Bitmap (fOwnBitmap = TRUE)
  144.     
  145.     // ----- Palette -----
  146.     
  147.     FW_Palette            GetPalette() const; 
  148.     void                SetPalette(FW_Palette palette);
  149.         // Bitmap always owns its palette
  150.  
  151.     // ----- Archiving -----
  152.     static void*        Read(FW_CReadableStream& archive);
  153.  
  154.     // ---- Geometry -----
  155.     void                GetBitmapInfo(short& width, short& height, 
  156.                                       short& rowBytes, short& pixelSize) const;                // Size in pixels
  157.  
  158.     void                GetBitmapBounds(FW_CRect& bounds) const;                            // Size in pixels
  159.     void                GetBitmapBounds(FW_CGraphicContext& gc, FW_CRect& bounds) const;    // Size in gc units
  160.     
  161.     
  162.     enum        // Options for ChangeBitmap
  163.     {
  164.         kChangeBitmap_Crop,
  165.         kChangeBitmap_Scale
  166.     };
  167.     
  168.     void                ChangeBitmap(void* image, short imageSize, 
  169.                                     short width, short height, 
  170.                                     short pixelSize,
  171.                                     short howToChangeSize);
  172.                                     
  173.     // ----- Copy Pixels -----
  174.     void                CopyPixels(FW_PBitmap dstBitmap, 
  175.                                     const FW_CRect& srcRect, 
  176.                                     const FW_CRect& dstRect) const;
  177.     
  178. #ifdef FW_BUILD_MAC
  179.     // ----- Conversion -----
  180.     FW_PPicture            GetAsPicture();
  181.     FW_PPicture            GetAsPicture(const FW_CRect& srcRect);
  182. #endif
  183.  
  184.     // ----- Mac Lock/Unlock -----
  185. #ifdef FW_BUILD_MAC
  186.     PixMapHandle        MacLockPixels();
  187.     void                MacUnlockPixels();
  188.     FW_Boolean            MacIsPixelsLocked() const;
  189. #endif
  190.     
  191. protected:
  192.     void                MakePlatformBitmap(short width, short height, short pixelSize, FW_Palette palette);
  193.     void                DisposePlatformBitmap();
  194.     void                SetImage(void* image, unsigned long imageSize);
  195.  
  196.     // ----- Reading and writing -----
  197. public:
  198.     void                WriteToPlatformFormat(const FW_CWritableStream& stream, FW_Boolean dibFileHeader) const;
  199.     
  200. private:
  201.     void                ReadFromPlatformFormat(const FW_CReadableStream& stream, FW_Boolean dibFileHeader);
  202.  
  203. //----------------------------------------------------------------------------------------
  204. //    Data Members
  205. //
  206. private:
  207.     FW_Boolean            fOwnBitmap;
  208.     FW_PlatformBitmap    fPlatformBitmap;
  209.     
  210. #ifdef FW_BUILD_MAC
  211.     short                 fLockCount;
  212.     PixMapHandle        fPixMapHandle;
  213. #endif
  214. #ifdef FW_BUILD_WIN
  215.     // Windows GDI can only work with DDBs of two color depths: monochrome and whatever the
  216.     //    current display setting is.  But the user can ask for an aribtrary color depth!
  217.     //    To solve this, I have to remember the requested color depth and use what GDI can do
  218.     short                fUserColorDepth;
  219.     FW_Palette            fWinPalette;
  220. #endif
  221. };
  222.  
  223. //========================================================================================
  224. //    class FW_CBitmapContext
  225. //========================================================================================
  226.  
  227. class FW_CLASS_ATTR FW_CBitmapContext : public FW_CGraphicContext
  228. {
  229. public:
  230.     FW_CBitmapContext(Environment* ev, FW_PBitmap& bitmap);
  231.     virtual ~FW_CBitmapContext();
  232.  
  233. private:
  234.     FW_PBitmap             fBitmap;
  235.     FW_CGraphicDevice*    fGraphicDevice;
  236.     
  237. #ifdef FW_BUILD_WIN
  238.     HBITMAP                fOldBitmap;
  239. #endif
  240. };
  241.  
  242. //========================================================================================
  243. //    Inlines
  244. //========================================================================================
  245.  
  246. //----------------------------------------------------------------------------------------
  247. //    FW_PBitmap::operator->
  248. //----------------------------------------------------------------------------------------
  249. inline FW_CBitmapRep* FW_PBitmap::operator->()
  250. {
  251.     return (FW_CBitmapRep*) GetRep();
  252. }
  253.  
  254.  
  255. //----------------------------------------------------------------------------------------
  256. //    FW_PBitmap::operator->
  257. //----------------------------------------------------------------------------------------
  258. inline const FW_CBitmapRep* FW_PBitmap::operator->() const
  259. {
  260.     return (const FW_CBitmapRep*) GetRep();
  261. }
  262.  
  263. #ifdef FW_BUILD_MAC
  264. //----------------------------------------------------------------------------------------
  265. //    FW_CBitmapRep::MacIsPixelsLocked
  266. //----------------------------------------------------------------------------------------
  267. inline FW_Boolean FW_CBitmapRep::MacIsPixelsLocked() const
  268. {
  269.     return fLockCount != 0;
  270. }
  271. #endif
  272.  
  273. //----------------------------------------------------------------------------------------
  274. //    FW_CBitmapRep::GetPlatformBitmap
  275. //----------------------------------------------------------------------------------------
  276. inline FW_PlatformBitmap FW_CBitmapRep::GetPlatformBitmap() const
  277. {
  278.     return fPlatformBitmap;
  279. }
  280.  
  281. //----------------------------------------------------------------------------------------
  282. //    FW_CBitmapRep::IsPlatformPictOrphan
  283. //----------------------------------------------------------------------------------------
  284. inline FW_Boolean FW_CBitmapRep::IsPlatformBitmapOrphan() const
  285. {
  286.     return !fOwnBitmap;
  287. }
  288.  
  289. #ifdef FW_BUILD_MAC
  290.  
  291. //========================================================================================
  292. // CLASS FW_CMacPixelLock
  293. //========================================================================================
  294.  
  295. class FW_CMacPixelLock FW_AUTO_DESTRUCT_OBJECT
  296. {
  297. public:
  298.                     FW_CMacPixelLock(FW_CBitmapRep* bitmapRep);
  299.     virtual            ~FW_CMacPixelLock();
  300.     
  301.     PixMapHandle    GetPixMapHandle() const;
  302.     
  303. private:
  304.     FW_CBitmapRep*    fBitmapRep;
  305.     PixMapHandle    fPixMapHandle;
  306. };
  307.  
  308. #endif
  309.  
  310. #if FW_LIB_EXPORT_PRAGMAS
  311. #pragma lib_export off
  312. #endif
  313.  
  314. #endif
  315.