FEDRA emulsion software from the OPERA Collaboration
imdisp.h
Go to the documentation of this file.
1/*******************************************************************
2 *
3 * COPYRIGHT (c) 2002 Matrox Electronic Systems Ltd.
4 * All Rights Reserved
5 *
6 *******************************************************************/
7
8#ifndef __IMDISP_H__
9#define __IMDISP_H__
10
11/********************************************************************
12 *
13 * File to be included by applications wishing to use a display
14 * on Odyssey (or GenesisPlus).
15 *
16 ********************************************************************/
17
18/* THIS FILE IS OBSOLETE, YOU DON'T NEED IT ANYMORE */
19#if 0
20
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24
25#include "imapi.h"
26
27#define DISPFILE "c:\\display.ini"
28#define DISP_MODE_VGA 1
29#define DISP_MODE_GENESIS 2
30
31#if defined (IM_DEV_ODYSSEY)
32#define DISP_FLAG 0x3000000
33#else
34#define DISP_FLAG 0x5000000
35#endif
36
37
38typedef struct
39{
40 long Mode;
41 long SizeX;
42 long SizeY;
43 long Bits;
44 long Bands;
45 long Address;
46 long Pitch;
47 long KeyVal;
48} _IM_DISP_PARAMS_ST;
49
50static _IM_DISP_PARAMS_ST DispParams;
51static long GetDisplayParams(_IM_DISP_PARAMS_ST *DispParams);
52
53void myDevAlloc(long System, long Node, char *ShellFile, long Mode, long *DevPtr);
54void myBufChild(long Thread, long Buf, long StartX, long StartY, long SizeX, long SizeY, long *ChildPtr);
55void myBufCopy(long Thread, long SrcBuf, long DstBuf, long Control, long OSB);
56void myBufCopyVM(long Thread, long SrcBuf, long DstBuf, long SrcControl, long DstControl, long OSB);
57void myBufClear(long Thread, long Buf, double Value, long OSB);
58long myDispInquire(long Thread, long Disp, long Item, void *ValuePtr);
59void myDispControl(long Thread, long Disp, long Control, long Mode);
60void myDispAlloc(long Thread, long System, long Display, char *DispFile, long Mode, long *DispPtr);
61void myDispFree(long Thread, long Display);
62
63
64void myDevAlloc(long System, long Node, char *ShellFile, long Mode, long *DevPtr)
65{
66 GetDisplayParams(&DispParams);
67
68 imDevAlloc(System, Node, ShellFile, Mode, DevPtr);
69}
70
71
72long myDispInquire(long Thread, long Disp, long Item, void *ValuePtr)
73{
74 long Value = 0;
75
76 Disp = Disp;
77
78/* The function is defined as synchronous */
79 imSyncHost(Thread, 0, IM_COMPLETED);
80
81 switch (Item)
82 {
83 case IM_DISP_MODE:
84 if (DispParams.Bands == 1)
85 Value = IM_DISP_MONO;
86 else if (DispParams.Bands == 3)
87 Value = IM_DISP_COLOR;
88 else
89 Value = IM_NONE;
90 break;
91
93 Value = DispParams.SizeX;
94 break;
95
97 Value = DispParams.SizeY;
98 break;
99
100 case IM_DISP_KEY_MODE:
101 Value = (DispParams.KeyVal >= 0) ? IM_KEY_IN_RANGE : IM_KEY_ALWAYS; // No keying currently means dual screen with no overlay
102 break;
103
104 case IM_DISP_KEY_LOW:
105 case IM_DISP_KEY_HIGH:
106 Value = DispParams.KeyVal;
107 break;
108
109 case IM_DISP_VGA_MODE:
110 Value = (DispParams.KeyVal >= 0) ? IM_SINGLE_SCREEN : IM_DUAL_SCREEN;
111 break;
112
113 case IM_DISP_PAN_X:
114 case IM_DISP_PAN_Y:
115 Value = 0;
116 break;
117
118 case IM_DISP_ZOOM:
119 Value = 1;
120 break;
121
122 case IM_DISP_WRTMSK:
123 Value = 0x00ffffff;
124 break;
125 }
126
127 if (ValuePtr)
128 *(long *)ValuePtr = Value;
129
130 return(Value);
131}
132
133
134void myDispControl(long Thread, long Disp, long Control, long Mode)
135{
136 Thread = Thread;
137 Disp = Disp;
138 Control = Control;
139 Mode = Mode;
140}
141
142
143void myDispAlloc(long Thread, long System, long Display, char *DispFile, long Mode, long *DispPtr)
144{
145 System = System;
146 Display = Display;
147 DispFile = DispFile;
148 Mode = Mode;
149
150/* The function is defined as synchronous */
151 imSyncHost(Thread, 0, IM_COMPLETED);
152
153 if (DispPtr)
154 *DispPtr = 1; // 0 would be an error
155}
156
157
158void myDispFree(long Thread, long Display)
159{
160 Thread = Thread;
161 Display = Display;
162}
163
164
165void myBufChild(long Thread, long Buf, long StartX, long StartY, long SizeX, long SizeY, long *ChildPtr)
166{
167 long Address[3], Pitch, BytesPerPixel, Type, NumBands;
168
169 if (Buf != IM_DISP && Buf != IM_DISP_COLOR)
170 {
171 imBufChild(Thread, Buf, StartX, StartY, SizeX, SizeY, ChildPtr);
172 return;
173 }
174
175 if (SizeX == IM_ALL || (StartX + SizeX ) > DispParams.SizeX)
176 SizeX = DispParams.SizeX - StartX;
177 if (SizeY == IM_ALL || (StartY + SizeY ) > DispParams.SizeY)
178 SizeY = DispParams.SizeY - StartY;
179
180 if (DispParams.Address != 0)
181 {
182 Address[0] = DispParams.Address;
183 Pitch = DispParams.Pitch;
184 NumBands = DispParams.Bands;
185
186 if (DispParams.Mode == DISP_MODE_VGA)
187 {
188 if (NumBands == 1)
189 {
190 BytesPerPixel = 1;
191 Type = IM_UBYTE;
192 }
193 else
194 {
195 BytesPerPixel = 4;
196 Type = IM_LONG;
197 }
198 Address[0] += (StartX * BytesPerPixel) + (StartY * Pitch);
199
200 imBufCreate(Thread, SizeX, SizeY, 1, Type, IM_NON_PAGED, (void **)Address, Pitch, ChildPtr);
201 }
202 else // Genesis
203 {
204 BytesPerPixel = 1;
205 Address[0] += (StartX * BytesPerPixel) + (StartY * Pitch);
206 if (NumBands == 3)
207 {
208 Address[1] = Address[0] + 0x200000;
209 Address[2] = Address[1] + 0x200000;
210 }
211
212 imBufCreate(Thread, SizeX, SizeY, NumBands, IM_UBYTE, IM_NON_PAGED, (void **)Address, Pitch, ChildPtr);
213 }
214 }
215 else
216 *ChildPtr = 0;
217}
218
219
220void myBufCopy(long Thread, long SrcBuf, long DstBuf, long Control, long OSB)
221{
222 if ((DstBuf & DISP_FLAG) != DISP_FLAG) // i.e. Not a special display buffer
223 {
224 imBufCopy(Thread, SrcBuf, DstBuf, Control, OSB);
225 return;
226 }
227
228 if (DispParams.Mode == DISP_MODE_VGA)
229 {
230#if defined(IM_DEV_ODYSSEY)
231 if (DispParams.Bands == 3)
232 imBufPutField(Thread, SrcBuf, IM_CTL_BYTE_SWAP, IM_ENABLE);
233
234 imBufCopyPCI(Thread, SrcBuf, DstBuf, SrcBuf, OSB);
235#else
236
237 if (DispParams.Bands == 1)
238 {
239 imBufCopyPCI(Thread, SrcBuf, DstBuf, 0, OSB);
240 }
241 else // color mode
242 {
243 long NumBands;
244
245 imBufInquire(Thread, SrcBuf, IM_BUF_NUM_BANDS, &NumBands);
246
247 /* The buffer must have 1 or 3 bands of 8 bits */
248 if (NumBands == 1)
249 {
250 long Bands[4], Buf4Band;
251
252 Bands[0] = Bands[1] = Bands[2] = Bands[3] = SrcBuf;
253 imBufCreate(Thread, 0, 0, 4, IM_UBYTE, IM_DEFAULT, (void **)Bands, 0, &Buf4Band);
254 imBufCopy(Thread, Buf4Band, DstBuf, 0, OSB);
255 imBufFree(Thread, Buf4Band);
256 }
257 else if (NumBands == 3)
258 {
259 imBufPutField(Thread, SrcBuf, IM_CTL_PACK, IM_24_TO_32);
260 imBufPutField(Thread, SrcBuf, IM_CTL_BYTE_SWAP, IM_ENABLE);
261 imBufCopyPCI(Thread, SrcBuf, DstBuf, SrcBuf, OSB);
262 }
263 }
264#endif
265 }
266
267 else // Display is on a Genesis
268 {
269#if defined(IM_DEV_ODYSSEY)
270 imBufCopyPCI(Thread, SrcBuf, DstBuf, 0, OSB);
271
272#else // Bug on Genesis prevents 1 band buffer being copied to all bands of a 3-band buffer
273 if (DispParams.Bands == 1)
274 {
275 imBufCopyPCI(Thread, SrcBuf, DstBuf, 0, OSB);
276 }
277 else // color mode
278 {
279 long NumBands;
280
281 imBufInquire(Thread, SrcBuf, IM_BUF_NUM_BANDS, &NumBands);
282
283 if (NumBands == 1)
284 {
285 long Bands[3], Buf3Band;
286
287 Bands[0] = Bands[1] = Bands[2] = SrcBuf;
288 imBufCreate(Thread, 0, 0, 3, IM_UBYTE, IM_DEFAULT, (void **)Bands, 0, &Buf3Band);
289 imBufCopy(Thread, Buf3Band, DstBuf, 0, OSB);
290 imBufFree(Thread, Buf3Band);
291 }
292 else if (NumBands == 3)
293 {
294 imBufCopyPCI(Thread, SrcBuf, DstBuf, 0, OSB);
295 }
296 }
297#endif
298 }
299}
300
301
302void myBufCopyVM(long Thread, long SrcBuf, long DstBuf, long SrcControl, long DstControl, long OSB)
303{
304 myBufCopy(Thread, SrcBuf, DstBuf, SrcControl, OSB);
305}
306
307
308void myBufClear(long Thread, long Buf, double Value, long OSB)
309{
310 long RGBValue = (long) Value;
311 long BGRValue = RGBValue;
312
313 if (DispParams.Mode == DISP_MODE_VGA && DispParams.Bands == 3) // Convert RGB to BGR
314 BGRValue = (RGBValue & 0x00ff00) | ((RGBValue >> 16) & 0xff) | ((RGBValue & 0xff) << 16);
315
316#if defined(IM_DEV_ODYSSEY)
317 if ((Buf & DISP_FLAG) != DISP_FLAG) // i.e. Not a special display buffer
318 {
319 imBufClear(Thread, Buf, Value, OSB);
320 return;
321 }
322 else // Clear not yet working on Odyssey for created buffer
323 {
324 long ProcBuf;
325
326 imBufClone(Thread, Buf, IM_PROC, &ProcBuf);
327 imBufClear(Thread, ProcBuf, BGRValue, 0);
328 imBufCopy(Thread, ProcBuf, Buf, 0, OSB);
329 imBufFree(Thread, ProcBuf);
330 }
331#else
332 imBufClear(Thread, Buf, BGRValue, OSB);
333#endif
334}
335
336#define MAX_LINE 120
337static long GetDisplayParams(_IM_DISP_PARAMS_ST *DispParams)
338{
339 char Line[120];
340 FILE *fp;
341 long status = 0;
342
343 memset(DispParams, sizeof(_IM_DISP_PARAMS_ST), 0);
344 DispParams->KeyVal = -1; // < 0 means keying disabled
345
346 fp = fopen(DISPFILE, "r");
347 if (fp != NULL)
348 {
349 while (fgets(Line, MAX_LINE-1, fp))
350 {
351 if (strstr(Line, "Mode ="))
352 {
353 if (strstr(Line, "VGA"))
354 DispParams->Mode = DISP_MODE_VGA;
355 else
356 DispParams->Mode = DISP_MODE_GENESIS;
357 }
358 else if (strstr(Line, "SizeX ="))
359 sscanf(strstr(Line, "=")+1, "%i", &DispParams->SizeX);
360 else if (strstr(Line, "SizeY ="))
361 sscanf(strstr(Line, "=")+1, "%i", &DispParams->SizeY);
362 else if (strstr(Line, "Bits ="))
363 sscanf(strstr(Line, "=")+1, "%i", &DispParams->Bits);
364 else if (strstr(Line, "Bands ="))
365 sscanf(strstr(Line, "=")+1, "%i", &DispParams->Bands);
366 else if (strstr(Line, "Address ="))
367 sscanf(strstr(Line, "=")+1, "%i", &DispParams->Address);
368 else if (strstr(Line, "Pitch ="))
369 sscanf(strstr(Line, "=")+1, "%i", &DispParams->Pitch);
370 else if (strstr(Line, "KeyVal ="))
371 sscanf(strstr(Line, "=")+1, "%i", &DispParams->KeyVal);
372 }
373
374 fclose(fp);
375 }
376// else
377// printf("Failed to open file %s\n", DISPFILE);
378
379 if (DispParams->Address == 0 || DispParams->SizeX == 0 || DispParams->SizeY == 0 || DispParams->Pitch == 0)
380 {
381#if defined(IM_DEV_ODYSSEY)
382 printf("*** The Odyssey display is not properly configured\n");
383#else
384 printf("*** The display is not properly configured\n");
385#endif
386 printf("*** Please configure it before running this application\n");
387 }
388 else
389 {
390 status = 1;
391 }
392
393 return status;
394}
395
396#define imDevAlloc(System, Node, ShellFile, Mode, DevPtr) myDevAlloc(System, Node, ShellFile, Mode, DevPtr)
397#define imBufChild(Thread, Buf, StartX, StartY, SizeX, SizeY, ChildPtr) myBufChild(Thread, Buf, StartX, StartY, SizeX, SizeY, ChildPtr)
398#define imBufCopy(Thread, SrcBuf, DstBuf, Control, OSB) myBufCopy(Thread, SrcBuf, DstBuf, Control, OSB)
399#define imBufCopyVM(Thread, SrcBuf, DstBuf, SrcControl, DstControl, OSB) myBufCopyVM(Thread, SrcBuf, DstBuf, SrcControl, DstControl, OSB)
400#define imBufClear(Thread, Buf, Value, OSB) myBufClear(Thread, Buf, Value, OSB)
401#define imDispInquire(Thread, Disp, Item, ValuePtr) myDispInquire(Thread, Disp, Item, ValuePtr)
402#define imDispControl(Thread, Disp, Control, Mode) myDispControl(Thread, Disp, Control, Mode)
403#define imDispAlloc(Thread, System, Display, DispFile, Mode, DispPtr) myDispAlloc(Thread, System, Display, DispFile, Mode, DispPtr)
404#define imDispFree(Thread, Display) myDispFree(Thread, Display)
405
406#endif /* #if 0 */
407
408#endif /* __IMDISP_H__ */
#define IM_DISP_RESOLUTION_X
Definition: imapidef.h:980
#define IM_ENABLE
Definition: imapidef.h:267
#define IM_DISP_PAN_X
Definition: imapidef.h:976
#define IM_DISP_VGA_MODE
Definition: imapidef.h:982
#define IM_DISP_KEY_MODE
Definition: imapidef.h:971
#define IM_DISP_MODE
Definition: imapidef.h:975
#define IM_DISP_COLOR
Definition: imapidef.h:839
#define IM_ALL
Definition: imapidef.h:266
#define IM_DUAL_SCREEN
Definition: imapidef.h:353
#define IM_DISP_KEY_HIGH
Definition: imapidef.h:973
#define IM_DISP_WRTMSK
Definition: imapidef.h:978
#define IM_KEY_ALWAYS
Definition: imapidef.h:347
#define IM_BUF_NUM_BANDS
Definition: imapidef.h:129
#define IM_DEFAULT
Definition: imapidef.h:262
#define IM_24_TO_32
Definition: imapidef.h:337
#define IM_DISP_ZOOM
Definition: imapidef.h:979
#define IM_DISP_PAN_Y
Definition: imapidef.h:977
#define IM_CTL_PACK
Definition: imapidef.h:910
#define IM_LONG
Definition: imapidef.h:50
#define IM_DISP
Definition: imapidef.h:454
#define IM_DISP_MONO
Definition: imapidef.h:838
#define IM_COMPLETED
Definition: imapidef.h:437
#define IM_PROC
Definition: imapidef.h:453
#define IM_CTL_BYTE_SWAP
Definition: imapidef.h:907
#define IM_SINGLE_SCREEN
Definition: imapidef.h:352
#define IM_DISP_RESOLUTION_Y
Definition: imapidef.h:981
#define IM_KEY_IN_RANGE
Definition: imapidef.h:348
#define IM_DISP_KEY_LOW
Definition: imapidef.h:972
#define IM_UBYTE
Definition: imapidef.h:45
#define IM_NON_PAGED
Definition: imapidef.h:456
#define IM_NONE
Definition: imapidef.h:263
IM_EXTC void IM_FTYPE imDevAlloc(long System, long ProcessingNode, char *ShellFile, long Mode, long *DevPtr) IM_LFTYPE
IM_EXTC void IM_FTYPE imBufClone(long Thread, long Buf, long NewLocation, long *NewBufPtr) IM_LFTYPE
IM_EXTC void IM_FTYPE imBufClear(long Thread, long Buf, double Value, long OSB) IM_LFTYPE
IM_EXTC void IM_FTYPE imBufCopyPCI(long Thread, long SrcBuf, long DstBuf, long Control, long OSB) IM_LFTYPE
IM_EXTC void IM_FTYPE imBufFree(long Thread, long Buf) IM_LFTYPE
IM_EXTC long IM_FTYPE imBufInquire(long Thread, long Buf, long Item, void *ValuePtr) IM_LFTYPE
IM_EXTC void IM_FTYPE imBufChild(long Thread, long Buf, long Xstart, long Ystart, long Xsize, long Ysize, long *ChildPtr) IM_LFTYPE
IM_EXTC void IM_FTYPE imBufCreate(long Thread, long Xsize, long Ysize, long Nbands, long Type, long Location, void **AddrPtr, long Pitch, long *BufPtr) IM_LFTYPE
IM_EXTC void IM_FTYPE imBufCopy(long Thread, long SrcBuf, long DstBuf, long Control, long OSB) IM_LFTYPE
IM_EXTC void IM_FTYPE imBufPutField(long Thread, long Buf, long Tag, double Value) IM_LFTYPE
IM_EXTC long IM_FTYPE imSyncHost(long Thread, long OSB, long State) IM_LFTYPE
fclose(pFile)
MFTYPE32 long(MFTYPE MPTYPE *MOCRHOOKFCTPTR)(long HookType
Definition: milocr.h:32
#define NULL
Definition: nidaqmx.h:84