home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / PRBitmap.h < prev    next >
Encoding:
Text File  |  1996-09-17  |  5.0 KB  |  193 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                PRBitmap.h
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef PRBITMAP_H
  11. #define PRBITMAP_H
  12.  
  13. #ifndef FWSTDDEF_H
  14. #include "FWStdDef.h"
  15. #endif
  16.  
  17. #ifndef SLGRDEF_H
  18. #include "SLGrDef.h"
  19. #endif
  20.  
  21. #ifndef SLPTRECT_H
  22. #include "SLPtRect.h"
  23. #endif
  24.  
  25. #ifndef PRGRREF_H
  26. #include "PRGrRef.h"
  27. #endif
  28.  
  29. #ifndef SLPALETE_H
  30. #include "SLPalete.h"
  31. #endif
  32.  
  33. #ifndef SLPICTUR_H
  34. #include "SLPictur.h"
  35. #endif
  36.  
  37. //========================================================================================
  38. //    Forward Declarations
  39. //========================================================================================
  40.  
  41. class FW_OResourceFile;
  42.  
  43. class FW_CReadableStream;
  44. class FW_CWritableStream;
  45.  
  46. class FW_CColor;
  47.  
  48. struct FW_SGraphicContext;
  49.  
  50. //========================================================================================
  51. //    class FW_CPrivBitmapRep
  52. //========================================================================================
  53.  
  54. class FW_CPrivBitmapRep : public FW_CPrivGrRefObj
  55. {
  56. public:
  57.     FW_DECLARE_AUTO(FW_CPrivBitmapRep)
  58.  
  59.     // ----- Construction -----
  60.                             FW_CPrivBitmapRep(
  61.                                 short width,  short height,
  62.                                 short pixelSize, FW_Palette palette,
  63.                                 void* image, long imageSize, short rowBytes);
  64.  
  65.                             FW_CPrivBitmapRep(FW_PlatformBitmap platformBitmap);
  66.  
  67.                             FW_CPrivBitmapRep(FW_OResourceFile* resourceFile, FW_ResourceID resID);
  68.  
  69.                             FW_CPrivBitmapRep(const FW_CPrivBitmapRep& bitmap, const FW_SRect& srcRect);
  70.                             
  71.                             ~FW_CPrivBitmapRep();
  72.  
  73.     // ----- Common operations -----
  74.     FW_Boolean                IsEqual(const FW_CPrivBitmapRep& bitmap) const;
  75.     
  76.     // ----- Streaming -----
  77.  
  78.     void                    Write(FW_CWritableStream& stream, FW_Boolean bDIBFileHeader);
  79.                             FW_CPrivBitmapRep(FW_CReadableStream& stream, FW_Boolean bDIBFileHeader);
  80.  
  81.     // ----- Handle operations -----
  82.     
  83.     FW_PlatformBitmap        GetPlatformBitmap() const;
  84.     FW_Boolean                IsPlatformBitmapOrphan() const;
  85.     FW_PlatformBitmap        OrphanPlatformBitmap();
  86.     
  87.     void                    SetPlatformBitmap(FW_PlatformBitmap newBitmap);
  88.     void                    AdoptPlatformBitmap(FW_PlatformBitmap newBitmap);
  89.  
  90.     // ----- Palette -----
  91.     
  92.     FW_Palette                GetPalette() const; 
  93.     void                    SetPalette(FW_Palette palette);
  94.  
  95.     // ----- Bitmap info -----
  96.  
  97.     void                    GetBitmapInfo(short& width, short& height, 
  98.                                       short& rowBytes, short& pixelSize) const;
  99.  
  100.     void                    GetBitmapBoundsGC(Environment* ev, FW_SGraphicContext& gc, FW_SRect& bounds) const;
  101.     void                    GetBitmapBounds(FW_SRect& bounds) const;
  102.  
  103.     // ----- Pixel Manipulations -----
  104.  
  105.     void                    GetPixelColor(short horiz, short vert, FW_CColor& color) const;
  106.     void                    SetPixelColor(short horiz, short vert, const FW_CColor& newColor);
  107.     
  108.     // ----- Changing the bitmap -----
  109.  
  110.     FW_PlatformError        ChangeBitmap(short width, 
  111.                                         short height, 
  112.                                         short pixelSize,
  113.                                         FW_Boolean bScale);
  114.     FW_PlatformError        ChangeBitmap(void* image, 
  115.                                         long imageSize, 
  116.                                         short rowBytes,
  117.                                         short width, 
  118.                                         short height, 
  119.                                         short pixelSize,
  120.                                         FW_Boolean bScale);                                
  121.     FW_PlatformError        SetImage(void* image, long imageSize, short rowBytes);
  122.  
  123.     // ----- Copy Pixels -----
  124.  
  125.     FW_PlatformError        CopyPixels(FW_CPrivBitmapRep& dstBitmap, 
  126.                                         const FW_SRect& boundsSrc, 
  127.                                         const FW_SRect& boundsDst) const;
  128.  
  129. #ifdef FW_BUILD_MAC
  130.  
  131.     // ----- Conversion -----
  132.  
  133.                             FW_CPrivBitmapRep(FW_HPicture picture,
  134.                                 FW_SColor fillColor, const FW_SRect& pictPart);
  135.  
  136.     FW_HPicture                MacGetAsPicture(const FW_SRect& bounds) const;
  137. #endif
  138.  
  139.     // ----- Mac Lock/Unlock -----
  140. #ifdef FW_BUILD_MAC
  141.     PixMapHandle            MacLockPixels();
  142.     void                    MacUnlockPixels();
  143.     FW_Boolean                MacIsPixelsLocked() const;
  144. #endif
  145.  
  146.     // ----- Implementation
  147. private:
  148.     void                    PrivDisposeBitmap();
  149.     void                    PrivMakeBitmap(short width, short height,
  150.                                 short pixelSize, FW_Palette palette);
  151.     void                    PrivReadFromStream(FW_CReadableStream& stream, FW_Boolean bDIBFileHeader);
  152.  
  153.     FW_Boolean                fOwnBitmap;
  154.     FW_PlatformBitmap        fPlatformBitmap;
  155.  
  156. #ifdef FW_BUILD_MAC
  157.     short                     fLockCount;
  158.     PixMapHandle            fPixMapHandle;
  159. #endif
  160. #ifdef FW_BUILD_WIN
  161.     // Windows GDI can only work with DDBs of two color depths: monochrome and whatever the
  162.     //    current display setting is.  But the user can ask for an aribtrary color depth!
  163.     //    To solve this, I have to remember the requested color depth and use what GDI can do
  164.     short                    fUserColorDepth;
  165.     FW_Palette                fWinPalette;
  166. #endif
  167. };
  168.  
  169. #ifdef FW_BUILD_MAC
  170.  
  171. //========================================================================================
  172. // CLASS FW_CPrivMacPixelLock
  173. //========================================================================================
  174.  
  175. class FW_CPrivMacPixelLock
  176. {
  177. public:
  178.     FW_DECLARE_AUTO(FW_CPrivMacPixelLock)
  179.  
  180.                     FW_CPrivMacPixelLock(FW_HBitmap);
  181.                     ~FW_CPrivMacPixelLock();
  182.  
  183.     PixMapHandle    GetPixMapHandle() const;
  184.     
  185. private:
  186.     FW_HBitmap        fBitmap;
  187.     PixMapHandle    fPixMapHandle;
  188. };
  189.  
  190. #endif
  191.  
  192. #endif // PRBITMAP_H
  193.