cybergraphics.pas 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. {
  2. This file is part of the Free Pascal MorphOS support package
  3. Copyright (c) 2015 Karoly Balogh
  4. member of the Free Pascal Development Team
  5. cybergraphics.library interface unit
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$mode fpc}
  13. {$packrecords 2}
  14. UNIT CYBERGRAPHICS;
  15. INTERFACE
  16. USES
  17. exec,agraphics,utility;
  18. VAR CyberGfxBase : pLibrary = nil;
  19. const
  20. CYBERGRAPHICSNAME : PChar = 'cybergraphics.library';
  21. {
  22. Contents of this file is based on cybergraphics.h from the MorphOS SDK:
  23. $VER: cybergraphics.h 50.12 (13.08.2008)
  24. include file for cybergraphics.library
  25. Copyright (c) 1996-2008 by Vision Factory Development
  26. All Rights reserved.
  27. }
  28. const
  29. CYBERGFXNAME = 'cybergraphics.library';
  30. CYBERGFX_INCLUDE_VERSION = 41;
  31. {
  32. Definition of CyberModeNode (Returned in AllocModeList)
  33. }
  34. type
  35. PCyberModeNode = ^tCyberModeNode;
  36. tCyberModeNode = record
  37. Node : tNode;
  38. ModeText : array[0..(DISPLAYNAMELEN)-1] of char; { name for this mode }
  39. DisplayID : ULONG; { display id associated with the node }
  40. Width : UWORD; { visible width }
  41. Height : UWORD; { visible height }
  42. Depth : UWORD; { display depth }
  43. DisplayTagList : PTagItem; { taglist with extended ModeID information }
  44. end;
  45. {
  46. Parameters for GetCyberMapAttr()
  47. }
  48. const
  49. { function returns BytesPerRow if its called with this parameter }
  50. CYBRMATTR_XMOD = $80000001;
  51. { BytesPerPixel shall be returned }
  52. CYBRMATTR_BPPIX = $80000002;
  53. { do not use this ! private tag }
  54. CYBRMATTR_DISPADR = $80000003;
  55. { the pixel format is returned }
  56. CYBRMATTR_PIXFMT = $80000004;
  57. { returns width in pixels }
  58. CYBRMATTR_WIDTH = $80000005;
  59. { returns height in lines }
  60. CYBRMATTR_HEIGHT = $80000006;
  61. { returns bits per pixel }
  62. CYBRMATTR_DEPTH = $80000007;
  63. { returns -1 if supplied bitmap is a cybergfx one }
  64. CYBRMATTR_ISCYBERGFX = $80000008;
  65. { returns -1 if supplied bitmap is linear accessable }
  66. CYBRMATTR_ISLINEARMEM = $80000009;
  67. { returns colormap associated with that bitmap (v50) }
  68. CYBRMATTR_COLORMAP = $8000000A;
  69. {
  70. Parameters for GetCyberIDAttr()
  71. }
  72. { the pixel format is returned }
  73. CYBRIDATTR_PIXFMT = $80000001;
  74. { returns visible width in pixels }
  75. CYBRIDATTR_WIDTH = $80000002;
  76. { returns visible height in lines }
  77. CYBRIDATTR_HEIGHT = $80000003;
  78. { returns bits per pixel }
  79. CYBRIDATTR_DEPTH = $80000004;
  80. { BytesPerPixel shall be returned }
  81. CYBRIDATTR_BPPIX = $80000005;
  82. {
  83. Tags for CyberModeRequest()
  84. }
  85. CYBRMREQ_TB = TAG_USER + $40000;
  86. {
  87. FilterTags
  88. }
  89. { Minimum depth for displayed screenmode }
  90. CYBRMREQ_MinDepth = CYBRMREQ_TB + 0;
  91. { Maximum depth " " " }
  92. CYBRMREQ_MaxDepth = CYBRMREQ_TB + 1;
  93. { Minumum width " " " }
  94. CYBRMREQ_MinWidth = CYBRMREQ_TB + 2;
  95. { Maximum width " " " }
  96. CYBRMREQ_MaxWidth = CYBRMREQ_TB + 3;
  97. { Minumum height " " " }
  98. CYBRMREQ_MinHeight = CYBRMREQ_TB + 4;
  99. { Minumum height " " " }
  100. CYBRMREQ_MaxHeight = CYBRMREQ_TB + 5;
  101. CYBRMREQ_CModelArray = CYBRMREQ_TB + 6;
  102. CYBRMREQ_WinTitle = CYBRMREQ_TB + 20;
  103. CYBRMREQ_OKText = CYBRMREQ_TB + 21;
  104. CYBRMREQ_CancelText = CYBRMREQ_TB + 22;
  105. { Screen you wish the Requester to open on }
  106. CYBRMREQ_Screen = CYBRMREQ_TB + 30;
  107. {
  108. Tags for BestCyberModeID()
  109. }
  110. CYBRBIDTG_TB = TAG_USER + $50000;
  111. { FilterTags }
  112. CYBRBIDTG_Depth = CYBRBIDTG_TB + 0;
  113. CYBRBIDTG_NominalWidth = CYBRBIDTG_TB + 1;
  114. CYBRBIDTG_NominalHeight = CYBRBIDTG_TB + 2;
  115. CYBRBIDTG_MonitorID = CYBRBIDTG_TB + 3;
  116. CYBRBIDTG_BoardName = CYBRBIDTG_TB + 5;
  117. {
  118. definition of divers pixel formats
  119. }
  120. PIXFMT_LUT8 = 0;
  121. PIXFMT_RGB15 = 1;
  122. PIXFMT_RGB15X = 2;
  123. PIXFMT_BGR15 = 2;
  124. PIXFMT_RGB15PC = 3;
  125. PIXFMT_BGR15PC = 4;
  126. PIXFMT_RGB16 = 5;
  127. PIXFMT_BGR16 = 6;
  128. PIXFMT_RGB16PC = 7;
  129. PIXFMT_BGR16PC = 8;
  130. PIXFMT_RGB24 = 9;
  131. PIXFMT_BGR24 = 10;
  132. PIXFMT_ARGB32 = 11;
  133. PIXFMT_BGRA32 = 12;
  134. PIXFMT_RGBA32 = 13;
  135. {
  136. SrcRectangle formats defines for xxxPixelArray calls()
  137. }
  138. RECTFMT_RGB = 0;
  139. RECTFMT_RGBA = 1;
  140. RECTFMT_ARGB = 2;
  141. RECTFMT_LUT8 = 3;
  142. RECTFMT_GREY8 = 4;
  143. RECTFMT_RAW = 5;
  144. {
  145. Parameters for CVideoCtrlTagList()
  146. }
  147. SETVC_DPMSLevel = $88002001;
  148. { Full operation }
  149. DPMS_ON = 0;
  150. { Optional state of minimal power reduction }
  151. DPMS_STANDBY = 1;
  152. { Significant reduction of power consumption }
  153. DPMS_SUSPEND = 2;
  154. { Lowest level of power consumption }
  155. DPMS_OFF = 3;
  156. {
  157. Tags for LockBitMapTagList()
  158. }
  159. LBMI_WIDTH = $84001001;
  160. LBMI_HEIGHT = $84001002;
  161. LBMI_DEPTH = $84001003;
  162. LBMI_PIXFMT = $84001004;
  163. LBMI_BYTESPERPIX = $84001005;
  164. LBMI_BYTESPERROW = $84001006;
  165. LBMI_BASEADDRESS = $84001007;
  166. {
  167. Tags for UnLockBitMapTagList()
  168. }
  169. UBMI_UPDATERECTS = $85001001;
  170. UBMI_REALLYUNLOCK = $85001002;
  171. {
  172. Message passed to the DoCDrawMethodTagList() hook function
  173. }
  174. type
  175. PCDrawMsg = ^tCDrawMsg;
  176. tCDrawMsg = record
  177. cdm_MemPtr : APTR;
  178. cdm_offx : ULONG;
  179. cdm_offy : ULONG;
  180. cdm_xsize : ULONG;
  181. cdm_ysize : ULONG;
  182. cdm_BytesPerRow : UWORD;
  183. cdm_BytesPerPix : UWORD;
  184. cdm_ColorModel : UWORD;
  185. end;
  186. {
  187. Colour Table source formats for WriteLUTPixelArray()
  188. }
  189. { ULONG [] table }
  190. const
  191. CTABFMT_XRGB8 = 0;
  192. {
  193. graphics.library/AllocBitMap() extended flags
  194. }
  195. BMB_SPECIALFMT = 7;
  196. BMF_SPECIALFMT = 1 shl BMB_SPECIALFMT;
  197. BMF_REQUESTVMEM = (BMF_MINPLANES or BMF_DISPLAYABLE);
  198. BMB_ROOTMAP = 5;
  199. BMF_ROOTMAP = 1 shl BMB_ROOTMAP;
  200. BMB_3DTARGET = 8;
  201. BMF_3DTARGET = 1 shl BMB_3DTARGET;
  202. {*
  203. * Operations for ProcessPixelArray() (v50)
  204. *
  205. *}
  206. const
  207. POP_BRIGHTEN = 0;
  208. POP_DARKEN = 1;
  209. POP_SETALPHA = 2;
  210. POP_TINT = 3;
  211. POP_BLUR = 4;
  212. POP_COLOR2GREY = 5;
  213. POP_NEGATIVE = 6;
  214. POP_NEGFADE = 7;
  215. POP_TINTFADE = 8;
  216. POP_GRADIENT = 9;
  217. POP_SHIFTRGB = 10;
  218. {*
  219. * Values for POP_SHIFTRGB
  220. *
  221. *}
  222. const
  223. RGBSHIFT_BGR = 1;
  224. RGBSHIFT_BRG = 2;
  225. RGBSHIFT_GBR = 3;
  226. RGBSHIFT_GRB = 4;
  227. RGBSHIFT_RBG = 5;
  228. {*
  229. * Tags for ProcessPixelArray() ops
  230. *
  231. *}
  232. const
  233. PPAOPTAG_FADEFULLSCALE = $85231020;
  234. PPAOPTAG_FADEOFFSET = $85231021;
  235. PPAOPTAG_GRADIENTTYPE = $85231022;
  236. GRADTYPE_HORIZONTAL = 0;
  237. GRADTYPE_VERTICAL = 1;
  238. {* yet unsupported gradient types follow *}
  239. GRADTYPE_RECTANGLE = 2;
  240. GRADTYPE_LINEAR_ANGLE = 3;
  241. GRADTYPE_RADIAL = 4; {* "circle" center-based *}
  242. GRADIENT_NUMTYPES = 2;
  243. PPAOPTAG_GRADCOLOR1 = $85231023;
  244. PPAOPTAG_GRADCOLOR2 = $85231024;
  245. PPAOPTAG_GRADFULLSCALE = PPAOPTAG_FADEFULLSCALE;
  246. PPAOPTAG_GRADOFFSET = PPAOPTAG_FADEOFFSET;
  247. PPAOPTAG_RGBMASK = $85231025;
  248. PPAOPTAG_GRADSYMCENTER = $85231026;
  249. {*
  250. * Tags for BltBitMap(RastPort)Alpha() (v50)
  251. *
  252. *}
  253. const
  254. BLTBMA_MIXLEVEL = $88802000; {* from 0(0%) to 0xFFFFFFFF (100%) *}
  255. BLTBMA_USESOURCEALPHA = $88802001;
  256. BLTBMA_GLOBALALPHA = BLTBMA_MIXLEVEL;
  257. BLTBMA_DESTALPHAVALUE = $88802002;
  258. DESTALPHAVALUE_UNDEFINED = 0; {* default *}
  259. DESTALPHAVALUE_ONE = 1;
  260. DESTALPHAVALUE_USESOURCE = 2;
  261. DESTALPHAVALUE_USEDEST = 3;
  262. FUNCTION AllocCModeListTagList(ModeListTags : pTagItem location 'a1') : pList; syscall CyberGfxBase 072;
  263. FUNCTION BestCModeIDTagList(BestModeIDTags : pTagItem location 'a0') : longword; syscall CyberGfxBase 060;
  264. FUNCTION CModeRequestTagList(ModeRequest : POINTER location 'a0'; ModeRequestTags : pTagItem location 'a1') : longword; syscall CyberGfxBase 066;
  265. PROCEDURE CVideoCtrlTagList(ViewPort : pViewPort location 'a0'; TagList : pTagItem location 'a1'); syscall CyberGfxBase 162;
  266. PROCEDURE DoCDrawMethodTagList(Hook : pHook location 'a0'; a1arg : pRastPort location 'a1'; TagList : pTagItem location 'a2'); syscall CyberGfxBase 156;
  267. FUNCTION ExtractColor(a0arg : pRastPort location 'a0'; BitMap : pBitMap location 'a1'; Colour : longword location 'd0'; SrcX : longword location 'd1'; SrcY : longword location 'd2'; Width : longword location 'd3'; Height : longword location 'd4') : longword; syscall CyberGfxBase 186;
  268. FUNCTION FillPixelArray(a1arg : pRastPort location 'a1'; DestX : WORD location 'd0'; DestY : WORD location 'd1'; SizeX : WORD location 'd2'; SizeY : WORD location 'd3'; ARGB : longword location 'd4') : longword; syscall CyberGfxBase 150;
  269. PROCEDURE FreeCModeList(ModeList : pList location 'a0'); syscall CyberGfxBase 078;
  270. FUNCTION GetCyberIDAttr(CyberIDAttr : longword location 'd0'; CyberDisplayModeID : longword location 'd1') : longword; syscall CyberGfxBase 102;
  271. FUNCTION GetCyberMapAttr(CyberGfxBitmap : pBitMap location 'a0'; CyberAttrTag : longword location 'd0') : longword; syscall CyberGfxBase 096;
  272. FUNCTION InvertPixelArray(a1arg : pRastPort location 'a1'; DestX : WORD location 'd0'; DestY : WORD location 'd1'; SizeX : WORD location 'd2'; SizeY : WORD location 'd3') : longword; syscall CyberGfxBase 144;
  273. FUNCTION IsCyberModeID(displayID : longword location 'd0') : wordbool; syscall CyberGfxBase 054;
  274. FUNCTION LockBitMapTagList(BitMap : POINTER location 'a0'; TagList : pTagItem location 'a1') : POINTER; syscall CyberGfxBase 168;
  275. FUNCTION MovePixelArray(SrcX : WORD location 'd0'; SrcY : WORD location 'd1'; a1arg : pRastPort location 'a1'; DestX : WORD location 'd2'; DestY : WORD location 'd3'; SizeX : WORD location 'd4'; SizeY : WORD location 'd5') : longword; syscall CyberGfxBase 132;
  276. FUNCTION ReadPixelArray(destRect : POINTER location 'a0'; destX : WORD location 'd0'; destY : WORD location 'd1'; destMod : WORD location 'd2'; a1arg : pRastPort location 'a1'; SrcX : WORD location 'd3'; SrcY : WORD location 'd4'; SizeX : WORD location 'd5'; SizeY : WORD location 'd6'; DestFormat : byte location 'd7') : longword; syscall CyberGfxBase 120;
  277. FUNCTION ReadRGBPixel(a1arg : pRastPort location 'a1'; x : WORD location 'd0'; y : WORD location 'd1') : longword; syscall CyberGfxBase 108;
  278. FUNCTION ScalePixelArray(srcRect : POINTER location 'a0'; SrcW : WORD location 'd0'; SrcH : WORD location 'd1'; SrcMod : WORD location 'd2'; a1arg : pRastPort location 'a1'; DestX : WORD location 'd3'; DestY : WORD location 'd4'; DestW : WORD location 'd5'; DestH : WORD location 'd6'; SrcFormat : byte location 'd7') : LONGINT; syscall CyberGfxBase 090;
  279. PROCEDURE UnLockBitMap(Handle : POINTER location 'a0'); syscall CyberGfxBase 174;
  280. PROCEDURE UnLockBitMapTagList(Handle : POINTER location 'a0'; TagList : pTagItem location 'a1'); syscall CyberGfxBase 180;
  281. FUNCTION WriteLUTPixelArray(srcRect : POINTER location 'a0'; SrcX : WORD location 'd0'; SrcY : WORD location 'd1'; SrcMod : WORD location 'd2'; a1arg : pRastPort location 'a1'; ColorTab : POINTER location 'a2'; DestX : WORD location 'd3'; DestY : WORD location 'd4'; SizeX : WORD location 'd5'; SizeY : WORD location 'd6'; CTFormat : byte location 'd7') : longword; syscall CyberGfxBase 198;
  282. FUNCTION WritePixelArray(srcRect : POINTER location 'a0'; SrcX : WORD location 'd0'; SrcY : WORD location 'd1'; SrcMod : WORD location 'd2'; a1arg : pRastPort location 'a1'; DestX : WORD location 'd3'; DestY : WORD location 'd4'; SizeX : WORD location 'd5'; SizeY : WORD location 'd6'; SrcFormat : byte location 'd7') : longword; syscall CyberGfxBase 126;
  283. FUNCTION WriteRGBPixel(a1arg : pRastPort location 'a1'; x : WORD location 'd0'; y : WORD location 'd1'; argb : longword location 'd2') : LONGINT; syscall CyberGfxBase 114;
  284. {*** v43 ***}
  285. FUNCTION WritePixelArrayAlpha(srcRect : POINTER location 'a0'; SrcX : WORD location 'd0'; SrcY : WORD location 'd1'; SrcMod : WORD location 'd2'; a1arg : pRastPort location 'a1'; DestX : WORD location 'd3'; DestY : WORD location 'd4'; SizeX : WORD location 'd5'; SizeY : WORD location 'd6'; globalAlpha : LongWord location 'd7') : longword; syscall CyberGfxBase 216;
  286. PROCEDURE BltTemplateAlpha(source : pWORD location 'a0'; xSrc : LongInt location 'd0'; srcMod : LongInt location 'd1'; destRP : pRastPort location 'a1'; xDest : LongInt location 'd2'; yDest : LongInt location 'd3'; xSize : LongInt location 'd4'; ySize : LongInt location 'd5'); SysCall CyberGfxBase 222;
  287. PROCEDURE ProcessPixelArray(rastPort: pRastPort location 'a0'; destX: LongWord location 'd0'; destY: LongWord location 'd1'; sizeX: LongWord location 'd2'; sizeY: LongWord location 'd3'; operation: LongWord location 'd4'; value: LongInt location 'd5'; taglist: pTagItem location 'a2'); syscall CyberGfxBase 228;
  288. {*** v50 ***}
  289. FUNCTION BltBitMapAlpha(srcBitMap : pBitMap location 'a0'; xSrc : LongInt location 'd0'; ySrc : LongInt location 'd1'; destBitMap : pBitMap location 'a1'; xDest : LongInt location 'd2'; yDest : LongInt location 'd3'; xSize : LongInt location 'd4'; ySize : LongInt location 'd5'; tagList : pTagItem location 'a2') : LongWord; syscall CyberGfxBase 234;
  290. FUNCTION BltBitMapRastPortAlpha(srcBitMap : pBitMap location 'a0'; xSrc : LongInt location 'd0'; ySrc : LongInt location 'd1'; destRP : pRastPort location 'a1'; xDest : LongInt location 'd2'; yDest : LongInt location 'd3'; xSize : LongInt location 'd4'; ySize : LongInt location 'd5'; tagList : pTagItem location 'd2') : LongWord; SysCall CyberGfxBase 240;
  291. FUNCTION ScalePixelArrayAlpha(srcRect : POINTER location 'a0'; SrcW : WORD location 'd0'; SrcH : WORD location 'd1'; SrcMod : WORD location 'd2'; a1arg : pRastPort location 'a1'; DestX : WORD location 'd3'; DestY : WORD location 'd4'; DestW : WORD location 'd5'; DestH : WORD location 'd6'; globalAlpha : LongWord location 'd7') : LONGINT; syscall CyberGfxBase 252;
  292. {
  293. Functions and procedures with array of const go here
  294. }
  295. {
  296. FUNCTION AllocCModeListTags(const ModeListTags : Array Of Const) : pList;
  297. FUNCTION BestCModeIDTags(const BestModeIDTags : Array Of Const) : longword;
  298. FUNCTION CModeRequestTags(ModeRequest : POINTER; const ModeRequestTags : Array Of Const) : longword;
  299. PROCEDURE CVideoCtrlTags(ViewPort : pViewPort; const TagList : Array Of Const);
  300. PROCEDURE DoCDrawMethodTags(Hook : pHook; a1arg : pRastPort; const TagList : Array Of Const);
  301. FUNCTION LockBitMapTags(BitMap : POINTER; const TagList : Array Of Const) : POINTER;
  302. PROCEDURE UnLockBitMapTags(Handle : POINTER; const TagList : Array Of Const);
  303. }
  304. function SHIFT_PIXFMT(fmt : longint) : longint;
  305. function InitCyberGfxLibrary: boolean;
  306. IMPLEMENTATION
  307. {uses
  308. tagsarray;}
  309. {
  310. Functions and procedures with array of const go here
  311. }
  312. {
  313. FUNCTION AllocCModeListTags(const ModeListTags : Array Of Const) : pList;
  314. begin
  315. AllocCModeListTags := AllocCModeListTagList(readintags(ModeListTags));
  316. end;
  317. FUNCTION BestCModeIDTags(const BestModeIDTags : Array Of Const) : longword;
  318. begin
  319. BestCModeIDTags := BestCModeIDTagList(readintags(BestModeIDTags));
  320. end;
  321. FUNCTION CModeRequestTags(ModeRequest : POINTER; const ModeRequestTags : Array Of Const) : longword;
  322. begin
  323. CModeRequestTags := CModeRequestTagList(ModeRequest , readintags(ModeRequestTags));
  324. end;
  325. PROCEDURE CVideoCtrlTags(ViewPort : pViewPort; const TagList : Array Of Const);
  326. begin
  327. CVideoCtrlTagList(ViewPort , readintags(TagList));
  328. end;
  329. PROCEDURE DoCDrawMethodTags(Hook : pHook; a1arg : pRastPort; const TagList : Array Of Const);
  330. begin
  331. DoCDrawMethodTagList(Hook , a1arg , readintags(TagList));
  332. end;
  333. FUNCTION LockBitMapTags(BitMap : POINTER; const TagList : Array Of Const) : POINTER;
  334. begin
  335. LockBitMapTags := LockBitMapTagList(BitMap , readintags(TagList));
  336. end;
  337. PROCEDURE UnLockBitMapTags(Handle : POINTER; const TagList : Array Of Const);
  338. begin
  339. UnLockBitMapTagList(Handle , readintags(TagList));
  340. end;
  341. }
  342. function SHIFT_PIXFMT(fmt : longint) : longint; inline;
  343. begin
  344. SHIFT_PIXFMT:=(ULONG(fmt)) shl 24;
  345. end;
  346. const
  347. { Change VERSION and LIBVERSION to proper values }
  348. VERSION : string[2] = '0';
  349. LIBVERSION : longword = 0;
  350. function InitCyberGfxLibrary: boolean;
  351. begin
  352. InitCyberGfxLibrary := Assigned(CyberGfxBase);
  353. end;
  354. initialization
  355. CyberGfxBase := OpenLibrary(CYBERGFXNAME,LIBVERSION);
  356. finalization
  357. if Assigned(CyberGfxBase) then
  358. CloseLibrary(CyberGfxBase);
  359. END. (* UNIT CYBERGRAPHICS *)