home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / Sources / SLBitmap.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  13.1 KB  |  425 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                SLBitmap.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef SLPALETE_H
  13. #include "SLPalete.h"
  14. #endif
  15.  
  16. #ifndef SLBITMAP_H
  17. #include "SLBitmap.h"
  18. #endif
  19.  
  20. #ifndef PRBITMAP_H
  21. #include "PRBitmap.h"
  22. #endif
  23.  
  24. #ifndef PRPICTUR_H
  25. #include "PRPictur.h"
  26. #endif
  27.  
  28. #ifndef FWODEXCE_H
  29. #include "FWODExce.h"
  30. #endif
  31.  
  32. #ifndef FWSTRMRW_H
  33. #include "FWStrmRW.h"
  34. #endif
  35.  
  36. #ifdef FW_BUILD_MAC
  37. #pragma segment FWGraphics_Bitmap
  38. #endif
  39.  
  40. //----------------------------------------------------------------------------------------
  41. //    FW_PrivBitmap_CreateFromBits
  42. //----------------------------------------------------------------------------------------
  43.  
  44. FW_HBitmap SL_API FW_PrivBitmap_CreateFromBits(
  45.                                 short width, short height, short pixelSize, FW_Palette palette,
  46.                                 void* image, long imageSize, short rowBytes,
  47.                                 FW_PlatformError* error)
  48. {
  49.     FW_ERR_TRY
  50.     {
  51.         return FW_NEW(FW_CPrivBitmapRep, (width, height, pixelSize, palette, image, imageSize, rowBytes));
  52.     }
  53.     FW_ERR_CATCH
  54.     return 0;    
  55. }
  56.  
  57. //----------------------------------------------------------------------------------------
  58. //    FW_PrivBitmap_CreateFromPlatformBitmap
  59. //----------------------------------------------------------------------------------------
  60.  
  61. FW_HBitmap SL_API FW_PrivBitmap_CreateFromPlatformBitmap(
  62.                                 FW_PlatformBitmap platformBitmap,
  63.                                 FW_PlatformError* error)
  64. {
  65.     FW_ERR_TRY
  66.     {
  67.         return FW_NEW(FW_CPrivBitmapRep, (platformBitmap));
  68.     }
  69.     FW_ERR_CATCH
  70.     return 0;    
  71. }
  72.  
  73. //----------------------------------------------------------------------------------------
  74. //    FW_PrivBitmap_CreateFromResource
  75. //----------------------------------------------------------------------------------------
  76.  
  77. FW_HBitmap SL_API FW_PrivBitmap_CreateFromResource(
  78.                                 FW_OResourceFile* resourceFile,
  79.                                 FW_ResourceId resId,
  80.                                 FW_PlatformError* error)
  81. {
  82.     FW_ERR_TRY
  83.     {
  84.         return FW_NEW(FW_CPrivBitmapRep, (resourceFile, resId));
  85.     }
  86.     FW_ERR_CATCH
  87.     return 0;    
  88. }
  89.  
  90. //----------------------------------------------------------------------------------------
  91. //    FW_PrivBitmap_Copy
  92. //----------------------------------------------------------------------------------------
  93.  
  94. FW_HBitmap SL_API FW_PrivBitmap_Copy(FW_HBitmap bitmap, const FW_SRect& srcRect, FW_PlatformError* error)
  95. {
  96.     FW_ERR_TRY
  97.     {
  98.         return FW_NEW(FW_CPrivBitmapRep, (*bitmap, srcRect));
  99.     }
  100.     FW_ERR_CATCH
  101.     return 0;    
  102. }
  103.  
  104. //----------------------------------------------------------------------------------------
  105. //    FW_PrivBitmap_IsEqual
  106. //----------------------------------------------------------------------------------------
  107.  
  108. FW_Boolean SL_API FW_PrivBitmap_IsEqual(FW_HBitmap bitmap, FW_HBitmap bitmap2)
  109. {
  110.     // No try block necessary - Do not throw
  111.     return bitmap->IsEqual(*bitmap2);
  112. }
  113.  
  114. //----------------------------------------------------------------------------------------
  115. //    FW_PrivBitmap_Read
  116. //----------------------------------------------------------------------------------------
  117.  
  118. FW_HBitmap SL_API FW_PrivBitmap_Read(
  119.                                 FW_HReadableStream    hStream,
  120.                                 FW_Boolean             bDIBFileHeader,
  121.                                 FW_PlatformError*     error)
  122. {
  123.     FW_ERR_TRY
  124.     {
  125.         FW_CReadableStream stream(hStream);
  126.         return FW_NEW(FW_CPrivBitmapRep, (stream, bDIBFileHeader));
  127.     }
  128.     FW_ERR_CATCH
  129.     return 0;    
  130. }
  131.     
  132. //----------------------------------------------------------------------------------------
  133. //    FW_PrivBitmap_Write
  134. //----------------------------------------------------------------------------------------
  135.  
  136. void SL_API FW_PrivBitmap_Write(
  137.                                 FW_HBitmap             bitmap,
  138.                                 FW_HWritableStream    hStream,
  139.                                 FW_Boolean             bDIBFileHeader,
  140.                                 FW_PlatformError*    error)
  141. {
  142.     FW_ERR_TRY
  143.     {
  144.         FW_CWritableStream stream(hStream);
  145.         bitmap->Write(stream, bDIBFileHeader);
  146.     }
  147.     FW_ERR_CATCH
  148. }
  149.  
  150. //----------------------------------------------------------------------------------------
  151. //    FW_PrivBitmap_Acquire
  152. //----------------------------------------------------------------------------------------
  153.  
  154. void SL_API FW_PrivBitmap_Acquire(FW_HBitmap bitmap)
  155. {
  156.     // No try block necessary - Do not throw
  157.     bitmap->Acquire();
  158. }
  159.  
  160. //----------------------------------------------------------------------------------------
  161. //    FW_PrivBitmap_GetRefCount
  162. //----------------------------------------------------------------------------------------
  163.  
  164. long SL_API FW_PrivBitmap_GetRefCount(FW_HBitmap bitmap)
  165. {
  166.     // No try block necessary - Do not throw
  167.     return bitmap->GetRefCount();
  168. }
  169.  
  170. //----------------------------------------------------------------------------------------
  171. //    FW_PrivBitmap_Release
  172. //----------------------------------------------------------------------------------------
  173.  
  174. void SL_API FW_PrivBitmap_Release(FW_HBitmap bitmap)
  175. {
  176.     // No try block necessary - Do not throw
  177.     bitmap->Release();
  178. }
  179.  
  180. //----------------------------------------------------------------------------------------
  181. //    FW_PrivBitmap_GetPlatformBitmap
  182. //----------------------------------------------------------------------------------------
  183.  
  184. FW_PlatformBitmap SL_API FW_PrivBitmap_GetPlatformBitmap(FW_HBitmap bitmap)
  185. {
  186.     // No try block necessary - Do not throw
  187.     return bitmap->GetPlatformBitmap();
  188. }
  189.  
  190. //----------------------------------------------------------------------------------------
  191. //    FW_PrivBitmap_IsPlatformBitmapOrphan
  192. //----------------------------------------------------------------------------------------
  193.  
  194. FW_Boolean SL_API FW_PrivBitmap_IsPlatformBitmapOrphan(FW_HBitmap bitmap)
  195. {
  196.     // No try block necessary - Do not throw
  197.     return bitmap->IsPlatformBitmapOrphan();
  198. }
  199.  
  200. //----------------------------------------------------------------------------------------
  201. //    FW_PrivBitmap_OrphanPlatformBitmap
  202. //----------------------------------------------------------------------------------------
  203.  
  204. FW_PlatformBitmap SL_API FW_PrivBitmap_OrphanPlatformBitmap(FW_HBitmap bitmap)
  205. {
  206.     // No try block necessary - Do not throw
  207.     return bitmap->OrphanPlatformBitmap();
  208. }
  209.  
  210. //----------------------------------------------------------------------------------------
  211. //    FW_PrivBitmap_SetPlatformBitmap
  212. //----------------------------------------------------------------------------------------
  213.  
  214. FW_PlatformError SL_API FW_PrivBitmap_SetPlatformBitmap(FW_HBitmap bitmap, FW_PlatformBitmap newBitmap)
  215. {
  216.     // No try block necessary - Do not throw
  217.     bitmap->SetPlatformBitmap(newBitmap);
  218.     return FW_xNoError;
  219. }
  220.  
  221. //----------------------------------------------------------------------------------------
  222. //    FW_PrivBitmap_AdoptPlatformBitmap
  223. //----------------------------------------------------------------------------------------
  224.  
  225. FW_PlatformError SL_API FW_PrivBitmap_AdoptPlatformBitmap(FW_HBitmap bitmap, FW_PlatformBitmap newBitmap)
  226. {
  227.     // No try block necessary - Do not throw
  228.     bitmap->AdoptPlatformBitmap(newBitmap);
  229.     return FW_xNoError;
  230. }
  231.  
  232. //----------------------------------------------------------------------------------------
  233. //    FW_PrivBitmap_GetPalette
  234. //----------------------------------------------------------------------------------------
  235.  
  236. FW_Palette SL_API FW_PrivBitmap_GetPalette(FW_HBitmap bitmap, FW_PlatformError* error)
  237. {
  238.     FW_ERR_TRY
  239.     {
  240.         return bitmap->GetPalette();
  241.     }
  242.     FW_ERR_CATCH
  243.     return NULL;
  244. }
  245.  
  246. //----------------------------------------------------------------------------------------
  247. //    FW_PrivBitmap_SetPalette
  248. //----------------------------------------------------------------------------------------
  249.  
  250. FW_PlatformError SL_API FW_PrivBitmap_SetPalette(FW_HBitmap bitmap, FW_Palette palette)
  251. {
  252.     FW_RETURN_ERR_TRY
  253.     {
  254.         bitmap->SetPalette(palette);
  255.     }
  256.     FW_RETURN_ERR_CATCH
  257. }
  258.  
  259. //----------------------------------------------------------------------------------------
  260. //    FW_PrivBitmap_GetBitmapInfo
  261. //----------------------------------------------------------------------------------------
  262.  
  263. FW_PlatformError SL_API FW_PrivBitmap_GetBitmapInfo(
  264.                                 FW_HBitmap     bitmap,
  265.                                 short&        width,
  266.                                 short&        height, 
  267.                                 short&        rowBytes,
  268.                                 short&        pixelSize)
  269. {
  270.     // No try block necessary - Do not throw
  271.     bitmap->GetBitmapInfo(width, height, rowBytes, pixelSize);
  272.     return FW_xNoError;
  273. }
  274.  
  275. //----------------------------------------------------------------------------------------
  276. //    FW_PrivBitmap_GetBitmapBoundsGC
  277. //----------------------------------------------------------------------------------------
  278.  
  279. void SL_API FW_PrivBitmap_GetBitmapBoundsGC(Environment* ev, FW_HBitmap bitmap, FW_SGraphicContext& gc, FW_SRect& bounds)
  280. {
  281.     // No try block necessary - Do not throw
  282.     bitmap->GetBitmapBoundsGC(ev, gc, bounds);
  283. }
  284.  
  285. //----------------------------------------------------------------------------------------
  286. //    FW_PrivBitmap_GetBitmapBounds
  287. //----------------------------------------------------------------------------------------
  288.  
  289. void SL_API FW_PrivBitmap_GetBitmapBounds(FW_HBitmap bitmap, FW_SRect& bounds)
  290. {
  291.     bitmap->GetBitmapBounds(bounds);
  292. }
  293.  
  294. //----------------------------------------------------------------------------------------
  295. //    FW_PrivBitmap_ChangeBitmap
  296. //----------------------------------------------------------------------------------------
  297.  
  298. FW_PlatformError SL_API FW_PrivBitmap_ChangeBitmap(FW_HBitmap     bitmap,
  299.                                         void*        image,
  300.                                         long        imageSize,
  301.                                         short        rowBytes,
  302.                                         short        width,
  303.                                         short        height, 
  304.                                         short        pixelSize,
  305.                                         FW_Boolean    bScale)
  306. {
  307.     // No try block necessary - Do not throw
  308.     return bitmap->ChangeBitmap(image, imageSize, rowBytes, width, height, pixelSize, bScale);
  309. }
  310.                                     
  311. //----------------------------------------------------------------------------------------
  312. //    FW_PrivBitmap_ChangeBitmapGeometry
  313. //----------------------------------------------------------------------------------------
  314.  
  315. FW_PlatformError SL_API FW_PrivBitmap_ChangeBitmapGeometry(FW_HBitmap     bitmap,
  316.                                                 short        width,
  317.                                                 short        height, 
  318.                                                 short        pixelSize,
  319.                                                 FW_Boolean    bScale)
  320. {
  321.     // No try block necessary - Do not throw
  322.     return bitmap->ChangeBitmap(width, height, pixelSize, bScale);
  323. }
  324.                                     
  325. //----------------------------------------------------------------------------------------
  326. //    FW_PrivBitmap_SetImage
  327. //----------------------------------------------------------------------------------------
  328.  
  329. FW_PlatformError SL_API FW_PrivBitmap_SetImage(FW_HBitmap bitmap, 
  330.                                 void* image, 
  331.                                 long imageSize, 
  332.                                 short rowBytes)
  333. {
  334.     // No try block necessary - Do not throw
  335.     return bitmap->SetImage(image, imageSize, rowBytes);
  336. }
  337.  
  338. //----------------------------------------------------------------------------------------
  339. //    FW_PrivBitmap_CopyPixels
  340. //----------------------------------------------------------------------------------------
  341.  
  342. FW_PlatformError SL_API FW_PrivBitmap_CopyPixels(
  343.                                 FW_HBitmap    bitmapSrc, 
  344.                                 FW_HBitmap    bitmapDst,
  345.                                 FW_SRect&     boundsSrc, 
  346.                                 FW_SRect&    boundsDst)
  347. {
  348.     // No try block necessary - Do not throw
  349.     return bitmapSrc->CopyPixels(*bitmapDst, boundsSrc, boundsDst);
  350. }
  351.  
  352. #ifdef FW_BUILD_MAC
  353. //----------------------------------------------------------------------------------------
  354. //    FW_PrivBitmap_MacCreateFromPicture
  355. //----------------------------------------------------------------------------------------
  356.  
  357. FW_HBitmap SL_API FW_PrivBitmap_MacCreateFromPicture(
  358.                                 FW_HPicture picture, FW_SColor fillColor,
  359.                                 const FW_SRect& pictPart, FW_PlatformError* error)
  360. {
  361.     FW_ERR_TRY
  362.     {
  363.         return FW_NEW(FW_CPrivBitmapRep, (picture, fillColor, pictPart));
  364.     }
  365.     FW_ERR_CATCH
  366.     return NULL;
  367. }
  368. #endif
  369.  
  370. #ifdef FW_BUILD_MAC
  371. //----------------------------------------------------------------------------------------
  372. //    FW_PrivBitmap_MacGetAsPicture
  373. //----------------------------------------------------------------------------------------
  374.  
  375. FW_HPicture SL_API FW_PrivBitmap_MacGetAsPicture(FW_HBitmap bitmap, 
  376.                                                 const FW_SRect& bounds, 
  377.                                                 FW_PlatformError* error)
  378. {
  379.     FW_ERR_TRY
  380.     {
  381.         return bitmap->MacGetAsPicture(bounds);
  382.     }
  383.     FW_ERR_CATCH
  384.     return 0;
  385. }
  386. #endif
  387.  
  388. #ifdef FW_BUILD_MAC
  389. //----------------------------------------------------------------------------------------
  390. //    FW_PrivBitmap_MacLockPixels
  391. //----------------------------------------------------------------------------------------
  392.  
  393. PixMapHandle SL_API FW_PrivBitmap_MacLockPixels(FW_HBitmap bitmap)
  394. {
  395.     // No try block necessary - Do not throw
  396.     return bitmap->MacLockPixels();    // return NULL if fails
  397. }
  398. #endif
  399.  
  400. #ifdef FW_BUILD_MAC
  401. //----------------------------------------------------------------------------------------
  402. //    FW_PrivBitmap_MacUnlockPixels
  403. //----------------------------------------------------------------------------------------
  404.  
  405. FW_PlatformError SL_API FW_PrivBitmap_MacUnlockPixels(FW_HBitmap bitmap)
  406. {
  407.     // No try block necessary - Do not throw
  408.     bitmap->MacUnlockPixels();
  409.     return FW_xNoError;
  410. }
  411. #endif
  412.  
  413. #ifdef FW_BUILD_MAC
  414. //----------------------------------------------------------------------------------------
  415. //    FW_PrivBitmap_MacIsPixelsLocked
  416. //----------------------------------------------------------------------------------------
  417.  
  418. FW_Boolean SL_API FW_PrivBitmap_MacIsPixelsLocked(FW_HBitmap bitmap)
  419. {
  420.     // No try block necessary - Do not throw
  421.     return bitmap->MacIsPixelsLocked();
  422. }
  423.  
  424. #endif
  425.