1 {
2     This file is part of the Free Pascal run time library.
3     Copyright (c) 2014 by Free Pascal development team
4 
5     cybergraphics.library functions
6 
7     See the file COPYING.FPC, included in this distribution,
8     for details about the copyright.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 
14  **********************************************************************}
15 
16 unit cybergraphics;
17 
18 interface
19 
20 uses
21   Exec, agraphics, utility;
22 
23 const
24   CYBERGFXNAME = 'cybergraphics.library';
25   CYBERGFX_INCLUDE_VERSION = 41;
26 
27   //  Definition of CyberModeNode (Returned in AllocModeList)
28 
29 type
30    PCyberModeNode = ^TCyberModeNode;
31    TCyberModeNode = record
32      Node: TNode;
33      ModeText: array[0..DISPLAYNAMELEN - 1] of Char; // name for this mode
34      DisplayID: ULONG;                               // display id associated with the node
35      Width: UWORD;                                   // visible width
36      Height: UWORD;                                  // visible height
37      Depth: UWORD;                                   // display depth
38      DisplayTagList: PTagItem;                       // taglist with extended ModeID information
39    end;
40 
41 
42 const
43 // Parameters for GetCyberMapAttr()
returnsnull44   CYBRMATTR_XMOD         = $80000001; // function returns BytesPerRow if its called with this parameter
45   CYBRMATTR_BPPIX        = $80000002; // BytesPerPixel shall be returned
46   CYBRMATTR_DISPADR      = $80000003; // do not use this ! private tag
47   CYBRMATTR_PIXFMT       = $80000004; // the pixel format is returned
48   CYBRMATTR_WIDTH        = $80000005; // returns width in pixels
49   CYBRMATTR_HEIGHT       = $80000006; // returns height in lines
50   CYBRMATTR_DEPTH        = $80000007; // returns bits per pixel
51   CYBRMATTR_ISCYBERGFX   = $80000008; // returns -1 if supplied bitmap is a cybergfx one
52   CYBRMATTR_ISLINEARMEM  = $80000009; // returns -1 if supplied bitmap is linear accessable
53   CYBRMATTR_PIXFMT_ALPHA = $8000000A;
54 // Parameters for GetCyberIDAttr()
55   CYBRIDATTR_PIXFMT     = $80000001; // the pixel format is returned
56   CYBRIDATTR_WIDTH      = $80000002; // returns visible width in pixels
57   CYBRIDATTR_HEIGHT     = $80000003; // returns visible height in lines
58   CYBRIDATTR_DEPTH      = $80000004; // returns bits per pixel
59   CYBRIDATTR_BPPIX      = $80000005; // BytesPerPixel shall be returned
60 // Tags for CyberModeRequest()
61   CYBRMREQ_TB = TAG_USER + $40000;
62   //  FilterTags
63   CYBRMREQ_MinDepth    = CYBRMREQ_TB + 0; // Minimum depth for displayed screenmode
64   CYBRMREQ_MaxDepth    = CYBRMREQ_TB + 1; // Maximum depth  "       "        "
65   CYBRMREQ_MinWidth    = CYBRMREQ_TB + 2; // Minumum width  "       "        "
66   CYBRMREQ_MaxWidth    = CYBRMREQ_TB + 3; // Maximum width  "       "        "
67   CYBRMREQ_MinHeight   = CYBRMREQ_TB + 4; // Minumum height "       "        "
68   CYBRMREQ_MaxHeight   = CYBRMREQ_TB + 5; // Minumum height "       "        "
69   CYBRMREQ_CModelArray = CYBRMREQ_TB + 6;
70   CYBRMREQ_WinTitle    = CYBRMREQ_TB + 20;
71   CYBRMREQ_OKText      = CYBRMREQ_TB + 21;
72   CYBRMREQ_CancelText  = CYBRMREQ_TB + 22;
73   CYBRMREQ_Screen      = CYBRMREQ_TB + 30; // Screen you wish the Requester to open on
74 // Tags for BestCyberModeID()
75   CYBRBIDTG_TB = TAG_USER + $50000;
76   // FilterTags
77   CYBRBIDTG_Depth         = CYBRBIDTG_TB + 0;
78   CYBRBIDTG_NominalWidth  = CYBRBIDTG_TB + 1;
79   CYBRBIDTG_NominalHeight = CYBRBIDTG_TB + 2;
80   CYBRBIDTG_MonitorID     = CYBRBIDTG_TB + 3;
81   CYBRBIDTG_BoardName     = CYBRBIDTG_TB + 5;
82 // definition of divers pixel formats
83   PIXFMT_LUT8    = 0;
84   PIXFMT_RGB15   = 1;
85   PIXFMT_BGR15   = 2;
86   PIXFMT_RGB15PC = 3;
87   PIXFMT_BGR15PC = 4;
88   PIXFMT_RGB16   = 5;
89   PIXFMT_BGR16   = 6;
90   PIXFMT_RGB16PC = 7;
91   PIXFMT_BGR16PC = 8;
92   PIXFMT_RGB24   = 9;
93   PIXFMT_BGR24   = 10;
94   PIXFMT_ARGB32  = 11;
95   PIXFMT_BGRA32  = 12;
96   PIXFMT_RGBA32  = 13;
97 // SrcRectangle formats defines for xxxPixelArray calls()
98   RECTFMT_RGB   = 0;
99   RECTFMT_RGBA  = 1;
100   RECTFMT_ARGB  = 2;
101   RECTFMT_LUT8  = 3;
102   RECTFMT_GREY8 = 4;
103   RECTFMT_RAW   = 5;
104   // AROS extensions
105 
106 // Parameters for CVideoCtrlTagList()
107   SETVC_DPMSLevel = $88002001;
108   DPMS_ON         = 0; // Full operation
109   DPMS_STANDBY    = 1; // Optional state of minimal power reduction
110   DPMS_SUSPEND    = 2; // Significant reduction of power consumption
111   DPMS_OFF        = 3; // Lowest level of power consumption
112 // Tags for LockBitMapTagList()
113   LBMI_WIDTH       = $84001001;
114   LBMI_HEIGHT      = $84001002;
115   LBMI_DEPTH       = $84001003;
116   LBMI_PIXFMT      = $84001004;
117   LBMI_BYTESPERPIX = $84001005;
118   LBMI_BYTESPERROW = $84001006;
119   LBMI_BASEADDRESS = $84001007;
120 // Tags for UnLockBitMapTagList()
121   UBMI_UPDATERECTS  = $85001001;
122   UBMI_REALLYUNLOCK = $85001002;
123 
124 type
125 // Message passed to the DoCDrawMethodTagList() hook function
PCDrawMsgnull126   PCDrawMsg = ^TCDrawMsg;
127   TCDrawMsg = record
128     cdm_MemPtr: APTR;
129     cdm_offx: ULONG;
130     cdm_offy: ULONG;
131     cdm_xsize: ULONG;
132     cdm_ysize: ULONG;
133     cdm_BytesPerRow: UWORD;
134     cdm_BytesPerPix: UWORD;
135     cdm_ColorModel: UWORD;
136   end;
137 
138 // Colour Table source formats for WriteLUTPixelArray()  ULONG [] table
139 const
140   CTABFMT_XRGB8 = 0;
141 // graphics.library/AllocBitMap() extended flags
142   BMB_SPECIALFMT = 7;
143   BMF_SPECIALFMT = 1 shl BMB_SPECIALFMT;
144 
145 var
146   CyberGfxBase: PLibrary = nil;
147   ICyberGfx: PInterface = nil;
148 
CyberGfxObtainnull149 function CyberGfxObtain(): LongWord; syscall ICyberGfx 60;
CyberGfxReleasenull150 function CyberGfxRelease(): LongWord; syscall ICyberGfx 64;
151 procedure CyberGfxExpunge(); syscall ICyberGfx 68;
CyberGfxClonenull152 function CyberGfxClone(): PInterface; syscall ICyberGfx 72;
153 // 76 - 88 Reserved
IsCyberModeIDnull154 function IsCyberModeID(displayID: LongWord): LongBool; syscall ICyberGfx 92;
BestCModeIDTagListnull155 function BestCModeIDTagList(BestModeIDTags: PTagItem): LongWord; syscall ICyberGfx 96;
156 // 100 BestCModeIDTags
CModeRequestTagListnull157 function CModeRequestTagList(ModeRequest: APTR; ModeRequestTags: PTagItem): LongWord; syscall ICyberGfx 104;
158 // 108 CModeRequestTags
AllocCModeListTagListnull159 function AllocCModeListTagList(ModeListTags: PTagItem): PList; syscall ICyberGfx 112;
160 // 116 AllocCModeListTags
161 procedure FreeCModeList(ModeList: PList); syscall ICyberGfx 120;
162 // 120 reserved
ScalePixelArraynull163 function ScalePixelArray(SrcRect: APTR; SrcW, SrcH, SrcMod: LongWord; RastPort: PRastPort; DestX, DestY: LongInt; DestW, DestH, SrcFormat: LongWord): LongInt; syscall ICyberGfx 128;
GetCyberMapAttrnull164 function GetCyberMapAttr(CyberGfxBitmap: PBitMap; CyberAttrTag: LongWord): LongWord; syscall ICyberGfx 132;
GetCyberIDAttrnull165 function GetCyberIDAttr(CyberIDAttr, CyberDisplayModeID: LongWord): LongWord; syscall ICyberGfx 136;
ReadRGBPixelnull166 function ReadRGBPixel(Rp: PRastPort; X, Y: LongInt): LongWord; syscall ICyberGfx 140;
WriteRGBPixelnull167 function WriteRGBPixel(Rp: PRastPort; X, Y: LongInt; Pixel: LongWord): LongInt; syscall ICyberGfx 144;
ReadPixelArraynull168 function ReadPixelArray(DestRect: APTR; DestX, DestY: LongInt; DestMod: LongWord; Rp: PRastPort; SrcX, SrcY: LongInt; Width, Height, DstFormat: LongWord): LongWord; syscall ICyberGfx 148;
WritePixelArraynull169 function WritePixelArray(SrcRect: APTR; SrcX, SrcY: LongInt; SrcMod: LongWord; Rp: PRastPort; DestX, DestY: LongInt; Width, Height, SrcFormat: LongWord): LongWord; syscall ICyberGfx 152;
MovePixelArraynull170 function MovePixelArray(SrcX, SrcY: LongWord; RastPort: PRastPort; DstX, DstY, SizeX, SizeY: LongWord): LongWord; syscall ICyberGfx 156;
171 // 160 reserved
InvertPixelArraynull172 function InvertPixelArray(Rp: PRastPort; DestX, DestY: LongInt; Width, Height: LongWord): LongWord; syscall ICyberGfx 164;
FillPixelArraynull173 function FillPixelArray(Rp: PRastPort; DestX, DestY: LongInt; Width, Height, Pixel: LongWord): LongWord; syscall ICyberGfx 168;
174 procedure DoCDrawMethodTagList(Hook: PHook; Rp: PRastPort; Tags: PTagItem); syscall ICyberGfx 172;
175 // 176 DoCDrawMethodTags
176 procedure CVideoCtrlTagList(Vp: PViewPort; TagList: PTagItem); syscall ICyberGfx 180;
177 // 184 CVideoCtrlTags
LockBitMapTagListnull178 function LockBitMapTagList(Bitmap: APTR; TagList: PTagItem): APTR; syscall ICyberGfx 188;
179 // 192 LockBitMapTags
180 procedure UnLockBitMap(Handle: APTR); syscall ICyberGfx 196;
181 procedure UnLockBitMapTagList(Handle: APTR; TagList: PTagItem); syscall ICyberGfx 200;
182 // 204 UnLockBitMapTags
ExtractColornull183 function ExtractColor(RastPort: PRastPort; SingleMap: PBitMap; Colour: LongWord; SX, SY, Width, Height: LongWord): LongWord; syscall ICyberGfx 208;
184 // 212 reserved
WriteLUTPixelArraynull185 function WriteLUTPixelArray(SrcRect: APTR; SrcX, SrcY: LongInt; SrcMod: LongWord; Rp: PRastPort; CTable: APTR; DestX, DestY: LongInt; SizeX, SizeY, CTabFormat: LongWord): LongInt; syscall ICyberGfx 216;
186 // 220 reserved
187 // 224 reserved
WritePixelArrayAlphanull188 function WritePixelArrayAlpha(Src: APTR; SrcX, SrcY, SrcMod: LongInt; Rp: PRastPort; DestX, DestY: LongInt; Width, Height, GlobalAlpha: LongWord): LongWord; syscall ICyberGfx 228;
189 procedure BltTemplateAlpha(SrcTemplate: APTR; SrcX, SrcY: LongInt; Rp: PRastPort; DestX, DestY: LongInt; Width, Height: LongWord); syscall ICyberGfx 232;
190 
191 // Functions and procedures with array of const go here
AllocCModeListTagsnull192 function AllocCModeListTags(const ModeListTags: array of PtrUInt): PList;
BestCModeIDTagsnull193 function BestCModeIDTags(const BestModeIDTags: array of PtrUInt): LongWord;
194 procedure CVideoCtrlTags(ViewPort: PViewPort; const TagList: array of PtrUInt);
195 procedure DoCDrawMethodTags(Hook: PHook; a1arg: PRastPort; const TagList: array of PtrUInt);
LockBitMapTagsnull196 function LockBitMapTags(BitMap: APTR; const TagList: array of PtrUInt): APTR;
197 procedure UnLockBitMapTags(Handle: APTR; const TagList: array of PtrUInt);
198 
SHIFT_PIXFMTnull199 function SHIFT_PIXFMT(fmt: LongInt): LongInt;
DOWNSHIFT_PIXFMTnull200 function DOWNSHIFT_PIXFMT(fmt: LongInt): LongInt;
201 
202 implementation
203 
204 // Functions and procedures with array of const go here
AllocCModeListTagsnull205 function AllocCModeListTags(const ModeListTags: array of PtrUInt): PList; inline;
206 begin
207   AllocCModeListTags := AllocCModeListTagList(@ModeListTags);
208 end;
209 
BestCModeIDTagsnull210 function BestCModeIDTags(const BestModeIDTags: array of PtrUInt): LongWord; inline;
211 begin
212   BestCModeIDTags := BestCModeIDTagList(@BestModeIDTags);
213 end;
214 
215 procedure CVideoCtrlTags(ViewPort: PViewPort; const TagList: array of PtrUInt); inline;
216 begin
217   CVideoCtrlTagList(ViewPort, @TagList);
218 end;
219 
220 procedure DoCDrawMethodTags(Hook: PHook; a1arg: PRastPort; const TagList: array of PtrUInt); inline;
221 begin
222   DoCDrawMethodTagList(Hook, a1arg, @TagList);
223 end;
224 
LockBitMapTagsnull225 function LockBitMapTags(BitMap: APTR; const TagList: array of PtrUInt): APTR; inline;
226 begin
227   LockBitMapTags := LockBitMapTagList(BitMap, @TagList);
228 end;
229 
230 procedure UnLockBitMapTags(Handle: APTR; const TagList: array of PtrUInt); inline;
231 begin
232   UnLockBitMapTagList(Handle, @TagList);
233 end;
234 
SHIFT_PIXFMTnull235 function SHIFT_PIXFMT(fmt: LongInt): LongInt;
236 begin
237   SHIFT_PIXFMT:=(ULONG(fmt)) shl 24;
238 end;
239 
DOWNSHIFT_PIXFMTnull240 function DOWNSHIFT_PIXFMT(fmt: LongInt): LongInt;
241 begin
242   DOWNSHIFT_PIXFMT:=(ULONG(fmt)) shr 24;
243 end;
244 
245 initialization
246   CyberGfxBase := OpenLibrary(CYBERGFXNAME, 0);
247   if Assigned(CyberGfxBase) then
248     ICyberGfx := GetInterface(CyberGfxBase, 'main', 1, nil);
249 finalization
250   if Assigned(ICyberGfx) then
251     DropInterface(ICyberGfx);
252   if Assigned(CyberGfxBase) then
253     CloseLibrary(CyberGfxBase);
254 end.
255 
256 
257 
258