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