| 1 |
/* |
| 2 |
* Copyright(C) 1999-2020, 2022, 2023 National Technology & Engineering Solutions |
| 3 |
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 4 |
* NTESS, the U.S. Government retains certain rights in this software. |
| 5 |
* |
| 6 |
* See packages/seacas/LICENSE for details |
| 7 |
*/ |
| 8 |
/* |
| 9 |
* SUN DEC/ULTRIX ALLIANT : C routines must have underscores |
| 10 |
* SGI CONVEX : C routines must have underscores |
| 11 |
* |
| 12 |
* VAX HP IBM/aix : C routines do not have underscores |
| 13 |
* |
| 14 |
* CRAY/UNICOS : C routines must be capitalized, |
| 15 |
* and no underscores |
| 16 |
*/ |
| 17 |
|
| 18 |
#if !defined(CRA) && !defined(ADDC_) && !defined(COUGAR) |
| 19 |
#define vdmova wmetmv |
| 20 |
#define vdmoni wmetmo |
| 21 |
#define vdgnam wmetgn |
| 22 |
#define vbiqdv wmetiv |
| 23 |
#define vbiqpk wmetqp |
| 24 |
#define vdlina wmetln |
| 25 |
#define vdtext wmettx |
| 26 |
#define vdpnta wmetpt |
| 27 |
#define vdpoly wmetpy |
| 28 |
#define vdiqcp wmetcp |
| 29 |
#define vdstos wmetos |
| 30 |
#define vdiqos wmetio |
| 31 |
#define vdstfc wmetfc |
| 32 |
#define vdstbc wmetbc |
| 33 |
#define vdstin wmetin |
| 34 |
#define vdstls wmetls |
| 35 |
#define vdstlw wmetlw |
| 36 |
#define vdstcs wmetcs |
| 37 |
#define vdaabu wmetbu |
| 38 |
#define vdaloc wmetlo |
| 39 |
#define vdabgl wmetbl |
| 40 |
#define vdakgl wmetkl |
| 41 |
#define vdstla wmetla |
| 42 |
#define vdinit wmetnt |
| 43 |
#define vdfram wmetfr |
| 44 |
#define vdterm wmettr |
| 45 |
#define vdiqdc wmetdc |
| 46 |
#define vdnwpg wmetpg |
| 47 |
#define vdbell wmetbe |
| 48 |
#define vdwait wmetwt |
| 49 |
#define vdbufl wmetfl |
| 50 |
#define vdstco wmetco |
| 51 |
#define vdiqco wmetic |
| 52 |
#define vdescp wmetes |
| 53 |
#define vdiqes wmetie |
| 54 |
#define vdiqnd wmetid |
| 55 |
#define vimova wmetim |
| 56 |
#define vilina wmetil |
| 57 |
#define vipnta wmetip |
| 58 |
#define vitext wmetix |
| 59 |
#define viinit wmetii |
| 60 |
#define viterm wmetit |
| 61 |
#define vinwpg wmetig |
| 62 |
#define vcjob vcjob |
| 63 |
#define vberrh wmeter |
| 64 |
#define vdloge wmetle |
| 65 |
#define cdrwfs wmetwf |
| 66 |
#define cdrrfs wmetrf |
| 67 |
#define cdrofs wmetof |
| 68 |
#define cdrof3 wmeto3 |
| 69 |
#define cdrcfs wmetcf |
| 70 |
#define cdroff wmetff |
| 71 |
#define cdroab wmetab |
| 72 |
#define bgpbuf wmetbf |
| 73 |
#define qmsbuf wmetqm |
| 74 |
#define qmsbu1 wmetbf |
| 75 |
#define ddcbuf wmetbf |
| 76 |
#define h75buf wmetbf |
| 77 |
#define btkbuf wmetbf |
| 78 |
#define nmtbuf wmetbf |
| 79 |
#define vbimbf wmetib |
| 80 |
#define vbpkg wmetpk |
| 81 |
#define vbdev wmetdv |
| 82 |
#define vdiqrs wmetqr |
| 83 |
#define vdstmp wmetmp |
| 84 |
#define vdstrs wmetrs |
| 85 |
#define vdstrv wmetrv |
| 86 |
#define vdbrgb wmetbg |
| 87 |
#define vdfrgb wmetfg |
| 88 |
#define vdpixl wmetpx |
| 89 |
#define vdpixi wmetpi |
| 90 |
#define vdrpix wmetrp |
| 91 |
#define vdrpxi wmetri |
| 92 |
#define vdrscl wmetrl |
| 93 |
#define vdiqci wmetci |
| 94 |
#define vbstmp wmet01 |
| 95 |
#define vifram wmet02 |
| 96 |
#define vcndcm wmet03 |
| 97 |
#define vcattr wmet04 |
| 98 |
#define vbini1 wmet05 |
| 99 |
#define vb2hls wmet06 |
| 100 |
#define vb2rgb wmet07 |
| 101 |
#define vccolt wmet08 |
| 102 |
#define vccrps wmet09 |
| 103 |
#define vcscal wmet10 |
| 104 |
#define vcddim wmet11 |
| 105 |
#define vipoly wmet12 |
| 106 |
#define vbout wmet13 |
| 107 |
#define cgixxx cgimet |
| 108 |
#endif |
| 109 |
#if defined(CRA) |
| 110 |
#define vdmova WMETMV |
| 111 |
#define vdmoni WMETMO |
| 112 |
#define vdgnam WMETGN |
| 113 |
#define vbiqdv WMETIV |
| 114 |
#define vbiqpk WMETQP |
| 115 |
#define vdlina WMETLN |
| 116 |
#define vdtext WMETTX |
| 117 |
#define vdpnta WMETPT |
| 118 |
#define vdpoly WMETPY |
| 119 |
#define vdiqcp WMETCP |
| 120 |
#define vdstos WMETOS |
| 121 |
#define vdiqos WMETIO |
| 122 |
#define vdstfc WMETFC |
| 123 |
#define vdstbc WMETBC |
| 124 |
#define vdstin WMETIN |
| 125 |
#define vdstls WMETLS |
| 126 |
#define vdstlw WMETLW |
| 127 |
#define vdstcs WMETCS |
| 128 |
#define vdaabu WMETBU |
| 129 |
#define vdaloc WMETLO |
| 130 |
#define vdabgl WMETBL |
| 131 |
#define vdakgl WMETKL |
| 132 |
#define vdstla WMETLA |
| 133 |
#define vdinit WMETNT |
| 134 |
#define vdfram WMETFR |
| 135 |
#define vdterm WMETTR |
| 136 |
#define vdiqdc WMETDC |
| 137 |
#define vdnwpg WMETPG |
| 138 |
#define vdbell WMETBE |
| 139 |
#define vdwait WMETWT |
| 140 |
#define vdbufl WMETFL |
| 141 |
#define vdstco WMETCO |
| 142 |
#define vdiqco WMETIC |
| 143 |
#define vdescp WMETES |
| 144 |
#define vdiqes WMETIE |
| 145 |
#define vdiqnd WMETID |
| 146 |
#define vimova WMETIM |
| 147 |
#define vilina WMETIL |
| 148 |
#define vipnta WMETIP |
| 149 |
#define vitext WMETIX |
| 150 |
#define viinit WMETII |
| 151 |
#define viterm WMETIT |
| 152 |
#define vinwpg WMETIG |
| 153 |
#define cdrcom CDRCOM |
| 154 |
#define vcjob VCJOB |
| 155 |
#define vconod VCONOD |
| 156 |
#define vberrh WMETER |
| 157 |
#define vdloge WMETLE |
| 158 |
#define cdrwfs WMETWF |
| 159 |
#define cdrrfs WMETRF |
| 160 |
#define cdrofs WMETOF |
| 161 |
#define cdrof3 WMETO3 |
| 162 |
#define cdrcfs WMETCF |
| 163 |
#define cdroff WMETFF |
| 164 |
#define cdroab WMETAB |
| 165 |
#define bgpbuf WMETBF |
| 166 |
#define qmsbuf WMETQM |
| 167 |
#define qmsbu1 WMETBF |
| 168 |
#define ddcbuf WMETBF |
| 169 |
#define h75buf WMETBF |
| 170 |
#define btkbuf WMETBF |
| 171 |
#define nmtbuf WMETBF |
| 172 |
#define vbimbf WMETIB |
| 173 |
#define vbpkg WMETPK |
| 174 |
#define vbdev WMETDV |
| 175 |
#define vdiqrs WMETQR |
| 176 |
#define vdstmp WMETMP |
| 177 |
#define vdstrs WMETRS |
| 178 |
#define vdstrv WMETRV |
| 179 |
#define vdbrgb WMETBG |
| 180 |
#define vdfrgb WMETFG |
| 181 |
#define vdpixl WMETPX |
| 182 |
#define vdpixi WMETPI |
| 183 |
#define vdrpix WMETRP |
| 184 |
#define vdrpxi WMETRI |
| 185 |
#define vdrscl WMETRL |
| 186 |
#define vdiqci WMETCI |
| 187 |
#define vbstmp WMET01 |
| 188 |
#define vifram WMET02 |
| 189 |
#define vcndcm WMET03 |
| 190 |
#define vcattr WMET04 |
| 191 |
#define vbini1 WMET05 |
| 192 |
#define vb2hls WMET06 |
| 193 |
#define vb2rgb WMET07 |
| 194 |
#define vccolt WMET08 |
| 195 |
#define vccrps WMET09 |
| 196 |
#define vcscal WMET10 |
| 197 |
#define vcddim WMET11 |
| 198 |
#define vipoly WMET12 |
| 199 |
#define vbout WMET13 |
| 200 |
#define wmetzz WMETZZ |
| 201 |
#define cgixxx CGIMET |
| 202 |
#endif |
| 203 |
#if defined(ADDC_) || defined(COUGAR) |
| 204 |
#define vdmova wmetmv_ |
| 205 |
#define vdmoni wmetmo_ |
| 206 |
#define vdgnam wmetgn_ |
| 207 |
#define vbiqdv wmetiv_ |
| 208 |
#define vbiqpk wmetqp_ |
| 209 |
#define vdlina wmetln_ |
| 210 |
#define vdtext wmettx_ |
| 211 |
#define vdpnta wmetpt_ |
| 212 |
#define vdpoly wmetpy_ |
| 213 |
#define vdiqcp wmetcp_ |
| 214 |
#define vdstos wmetos_ |
| 215 |
#define vdiqos wmetio_ |
| 216 |
#define vdstfc wmetfc_ |
| 217 |
#define vdstbc wmetbc_ |
| 218 |
#define vdstin wmetin_ |
| 219 |
#define vdstls wmetls_ |
| 220 |
#define vdstlw wmetlw_ |
| 221 |
#define vdstcs wmetcs_ |
| 222 |
#define vdaabu wmetbu_ |
| 223 |
#define vdaloc wmetlo_ |
| 224 |
#define vdabgl wmetbl_ |
| 225 |
#define vdakgl wmetkl_ |
| 226 |
#define vdstla wmetla_ |
| 227 |
#define vdinit wmetnt_ |
| 228 |
#define vdfram wmetfr_ |
| 229 |
#define vdterm wmettr_ |
| 230 |
#define vdiqdc wmetdc_ |
| 231 |
#define vdnwpg wmetpg_ |
| 232 |
#define vdbell wmetbe_ |
| 233 |
#define vdwait wmetwt_ |
| 234 |
#define vdbufl wmetfl_ |
| 235 |
#define vdstco wmetco_ |
| 236 |
#define vdiqco wmetic_ |
| 237 |
#define vdescp wmetes_ |
| 238 |
#define vdiqes wmetie_ |
| 239 |
#define vdiqnd wmetid_ |
| 240 |
#define vimova wmetim_ |
| 241 |
#define vilina wmetil_ |
| 242 |
#define vipnta wmetip_ |
| 243 |
#define vitext wmetix_ |
| 244 |
#define viinit wmetii_ |
| 245 |
#define viterm wmetit_ |
| 246 |
#define vinwpg wmetig_ |
| 247 |
#define cdrcom cdrcom_ |
| 248 |
#define vcjob vcjob_ |
| 249 |
#define vconod vconod_ |
| 250 |
#define vberrh wmeter_ |
| 251 |
#define vdloge wmetle_ |
| 252 |
#define cdrwfs wmetwf_ |
| 253 |
#define cdrrfs wmetrf_ |
| 254 |
#define cdrofs wmetof_ |
| 255 |
#define cdrof3 wmeto3_ |
| 256 |
#define cdrcfs wmetcf_ |
| 257 |
#define cdroff wmetff_ |
| 258 |
#define cdroab wmetab_ |
| 259 |
#define bgpbuf wmetbf_ |
| 260 |
#define qmsbuf wmetqm_ |
| 261 |
#define qmsbu1 wmetbf_ |
| 262 |
#define ddcbuf wmetbf_ |
| 263 |
#define h75buf wmetbf_ |
| 264 |
#define btkbuf wmetbf_ |
| 265 |
#define nmtbuf wmetbf_ |
| 266 |
#define vbimbf wmetib_ |
| 267 |
#define vbpkg wmetpk_ |
| 268 |
#define vbdev wmetdv_ |
| 269 |
#define vdiqrs wmetqr_ |
| 270 |
#define vdstmp wmetmp_ |
| 271 |
#define vdstrs wmetrs_ |
| 272 |
#define vdstrv wmetrv_ |
| 273 |
#define vdbrgb wmetbg_ |
| 274 |
#define vdfrgb wmetfg_ |
| 275 |
#define vdpixl wmetpx_ |
| 276 |
#define vdpixi wmetpi_ |
| 277 |
#define vdrpix wmetrp_ |
| 278 |
#define vdrpxi wmetri_ |
| 279 |
#define vdrscl wmetrl_ |
| 280 |
#define vdiqci wmetci_ |
| 281 |
#define vbstmp wmet01_ |
| 282 |
#define vifram wmet02_ |
| 283 |
#define vcndcm wmet03_ |
| 284 |
#define vcattr wmet04_ |
| 285 |
#define vbini1 wmet05_ |
| 286 |
#define vb2hls wmet06_ |
| 287 |
#define vb2rgb wmet07_ |
| 288 |
#define vccolt wmet08_ |
| 289 |
#define vccrps wmet09_ |
| 290 |
#define vcscal wmet10_ |
| 291 |
#define vcddim wmet11_ |
| 292 |
#define vipoly wmet12_ |
| 293 |
#define vbout wmet13_ |
| 294 |
#define wmetbf wmetbf_ |
| 295 |
#define wmetzz wmetzz_ |
| 296 |
#define cgixxx cgimet_ |
| 297 |
#endif |
| 298 |
#if defined(CONVEX) |
| 299 |
#define cdrcom_ _cdrcom_ |
| 300 |
#define cdrcm2_ _cdrcm2_ |
| 301 |
#define vcjob_ _vcjob_ |
| 302 |
#define vconod_ _vconod_ |
| 303 |
#define cdrunx_ _cdrunx_ |
| 304 |
#endif |
| 305 |
|
| 306 |
/* cgimet.h - header file to define device dependent stuff for driver |
| 307 |
* Metafile (met) |
| 308 |
* Sandia National Laboratories, Div 2634 |
| 309 |
* Sun Nov 19 12:02:43 MST 1989 - last date modified |
| 310 |
*/ |
| 311 |
|
| 312 |
#include "svdi.h" |
| 313 |
|
| 314 |
/******************************************************************************/ |
| 315 |
/* */ |
| 316 |
/* type and constant declarations */ |
| 317 |
/* */ |
| 318 |
/******************************************************************************/ |
| 319 |
|
| 320 |
#define MAX_DEVICE_SURFACES 6 /* num of surfaces device supports */ |
| 321 |
/* ...set to 1 for interactive device */ |
| 322 |
#define ERROR_LIST_SIZE 10 /* number of errors stored */ |
| 323 |
#define COLOR_TABLE_SIZE 256 /* max color table for SVDI is 256 */ |
| 324 |
#define MAX_TEXT_LENGTH 136 /* max text length for SVDI is 136 */ |
| 325 |
#define MAX_POLYLINE -1 /* -1 = no limit */ |
| 326 |
#define MAX_DJ_POLYLINE -1 /* -1 = no limit */ |
| 327 |
#define MAX_POLYMARKER -1 /* -1 = no limit */ |
| 328 |
#define MAX_POLYGON 2000 /* uses min of this and SVDI limit */ |
| 329 |
#define MAX_ARRAY 1 /* for pixel array and cell array */ |
| 330 |
/* ...set to 1 for non raster device */ |
| 331 |
#define BUFFER_SIZE 1440 /* for batch device buffer routines */ |
| 332 |
/* ...set to 1 for interactive device */ |
| 333 |
#define DEFAULT_OUTFILE_NAME "" /* not used, driver builds the name */ |
| 334 |
|
| 335 |
/* end cgimet.h */ |
| 336 |
#include "data_def.h" |
| 337 |
|
| 338 |
#include <assert.h> |
| 339 |
#include <ctype.h> |
| 340 |
#include <math.h> |
| 341 |
#include <stdio.h> |
| 342 |
#include <stdlib.h> |
| 343 |
#include <string.h> |
| 344 |
#include <unistd.h> |
| 345 |
#if defined(CRA) || (defined(SUN) && (defined(SYSV) || defined(SVR4))) |
| 346 |
#include <fcntl.h> |
| 347 |
#include <sys/types.h> |
| 348 |
#endif |
| 349 |
#include "cdrcom.h" |
| 350 |
#include "cgi.h" |
| 351 |
#include "cgidef.h" |
| 352 |
#include "devid.h" |
| 353 |
#include "fortyp.h" |
| 354 |
#include "stdtyp.h" |
| 355 |
#include <sys/file.h> |
| 356 |
|
| 357 |
/* ------------------------------------------------------------*/ |
| 358 |
/* >> FUNCTION PROTOTYPES */ |
| 359 |
/*-------------------------------------------------------------*/ |
| 360 |
/* cgi/vdi routines */ |
| 361 |
static void xactivate(anything **surf_list); |
| 362 |
static void xdeactivate(anything **surf_list); |
| 363 |
static void xci(anything **params, int num_surfaces, anything **surf_list); |
| 364 |
static void xct(int num_surfaces, anything **surf_list); |
| 365 |
static void xcxdfac(int num_surfaces, anything **surf_list); |
| 366 |
static void xcpds(anything **params, int num_surfaces, anything **surf_list); |
| 367 |
static void xcendpg(int num_surfaces, anything **surf_list); |
| 368 |
static void xcbc(anything **params, int num_surfaces, anything **surf_list); |
| 369 |
static void xcvdcx(anything **params, int num_surfaces, anything **surf_list); |
| 370 |
static void xcv(anything **params, int num_surfaces, anything **surf_list); |
| 371 |
static void xccl(anything **params, int num_surfaces, anything **surf_list); |
| 372 |
static void xcdscl(anything **params, int num_surfaces, anything **surf_list); |
| 373 |
static void xcdqerr(anything **params, anything **surf_list); |
| 374 |
static void xcerhct(anything **params, int num_surfaces, anything **surf_list); |
| 375 |
static void xccixp(anything **params, int num_surfaces, anything **surf_list); |
| 376 |
static void xcesc(anything **params, int num_surfaces, anything **surf_list); |
| 377 |
static void xcqid(anything **params, anything **surf_list); |
| 378 |
static void xcqd(anything **params, anything **surf_list); |
| 379 |
static void xclf(anything **params, anything **surf_list); |
| 380 |
static void xclpr(anything **params, anything **surf_list); |
| 381 |
static void xcqsp(anything **params, anything **surf_list); |
| 382 |
static void xclesc(anything **params, anything **surf_list); |
| 383 |
static void xcqp(anything **params, anything **surf_list); |
| 384 |
static void xcqcl(anything **params, anything **surf_list); |
| 385 |
static void xcpl(anything **params, int num_surfaces, anything **surf_list); |
| 386 |
static void xcdjpl(anything **params, int num_surfaces, anything **surf_list); |
| 387 |
static void xcpm(anything **params, int num_surfaces, anything **surf_list); |
| 388 |
static void xctx(anything **params, int num_surfaces, anything **surf_list); |
| 389 |
static void xcpg(anything **params, int num_surfaces, anything **surf_list); |
| 390 |
static void xcca(anything **params, int num_surfaces, anything **surf_list); |
| 391 |
static void xcpxa(anything **params, int num_surfaces, anything **surf_list); |
| 392 |
static void xclnt(anything **params, int num_surfaces, anything **surf_list); |
| 393 |
static void xclnw(anything **params, int num_surfaces, anything **surf_list); |
| 394 |
static void xclnc(anything **params, int num_surfaces, anything **surf_list); |
| 395 |
static void xcmkt(int num_surfaces, anything **surf_list); |
| 396 |
static void xcmks(anything **params, int num_surfaces, anything **surf_list); |
| 397 |
static void xcmkc(anything **params, int num_surfaces, anything **surf_list); |
| 398 |
static void xctxp(anything **params, int num_surfaces, anything **surf_list); |
| 399 |
static void xctxc(anything **params, int num_surfaces, anything **surf_list); |
| 400 |
static void xcchh(anything **params, int num_surfaces, anything **surf_list); |
| 401 |
static void xccho(anything **params, int num_surfaces, anything **surf_list); |
| 402 |
static void xcis(anything **params, int num_surfaces, anything **surf_list); |
| 403 |
static void xcflc(anything **params, int num_surfaces, anything **surf_list); |
| 404 |
static void xccsm(anything **params, int num_surfaces, anything **surf_list); |
| 405 |
static void xcct(anything **params, int num_surfaces, anything **surf_list); |
| 406 |
static void xcgtxx(anything **params, anything **surf_list); |
| 407 |
static void xcqprl(anything **params, anything **surf_list); |
| 408 |
static void xcqln(anything **params, anything **surf_list); |
| 409 |
static void xcqlnt(anything **params, anything **surf_list); |
| 410 |
static void xcqslw(anything **params, anything **surf_list); |
| 411 |
static void xcqmk(anything **params, anything **surf_list); |
| 412 |
static void xcqmkt(anything **params, anything **surf_list); |
| 413 |
static void xcqsms(anything **params, anything **surf_list); |
| 414 |
static void xcqchh(anything **params, anything **surf_list); |
| 415 |
static void xcqfl(anything **params, anything **surf_list); |
| 416 |
static void xcqc(anything **params, anything **surf_list); |
| 417 |
static void xcqlna(anything **params, anything **surf_list); |
| 418 |
static void xcqmka(anything **params, anything **surf_list); |
| 419 |
static void xcqtxa(anything **params, anything **surf_list); |
| 420 |
static void xcqfla(anything **params, anything **surf_list); |
| 421 |
static void xcqcte(anything **params, anything **surf_list); |
| 422 |
static void xcili(anything **params, anything **surf_list); |
| 423 |
static void xcrqlc(anything **params, anything **surf_list); |
| 424 |
/* utility routines */ |
| 425 |
static void init_state(surf_statelist *surf_state); |
| 426 |
static void set_dev_descrip(void); |
| 427 |
static void reset_vdi(surf_statelist *surf_state); |
| 428 |
static void set_mapping(surf_statelist *surf_state); |
| 429 |
static void set_clipping(surf_statelist *cur_state); |
| 430 |
static void set_foreground_color(surf_statelist *surf_state, int *colors); |
| 431 |
static void set_background_color(surf_statelist *surf_state, int *colors); |
| 432 |
static void report_error(surf_statelist *surf_state, int e_class, int e_num, int f_id); |
| 433 |
static void gettoken(int *index_p, int *numrecs_p, char *data_p, int max_chars, char *outtoken_p); |
| 434 |
static int poly_clip(point *cmin, point *cmax, float *vx, float *vy, int vlen, float *xout, |
| 435 |
float *yout, int *lenout); |
| 436 |
static int inside_bnd(point *v, point *bmin, point *bmax, int bound_num); |
| 437 |
static point intersect_bnd(point *p1, point *p2, point *bmin, point *bmax, int bound_num); |
| 438 |
/* cdr routines */ |
| 439 |
/* -- not used with interactive devices */ |
| 440 |
void cdrofs(int *); |
| 441 |
void cdrof3(int *, int *); |
| 442 |
void cdroff(int *, int *, int *, int *); |
| 443 |
void cdrrfs(int *, int *, char *, int *); |
| 444 |
void cdrwfs(int *, int *, char *, int *); |
| 445 |
void cdrcfs(int *, int *); |
| 446 |
void cdroab(int *, int *); |
| 447 |
|
| 448 |
static char *copy_string(char *dest, char const *source, long int elements) |
| 449 |
{ |
| 450 |
char *d; |
| 451 |
for (d = dest; d + 1 < dest + elements && *source; d++, source++) { |
| 452 |
*d = *source; |
| 453 |
} |
| 454 |
*d = '\0'; |
| 455 |
return d; |
| 456 |
} |
| 457 |
|
| 458 |
/*-------------------------------------------------------------*/ |
| 459 |
/* >> GLOBAL VARIABLE DECLARATIONS */ |
| 460 |
/*-------------------------------------------------------------*/ |
| 461 |
|
| 462 |
/* variables used to maintain state list, free list */ |
| 463 |
static int first_free_state = -1; |
| 464 |
static int last_alloc_state = -1; |
| 465 |
|
| 466 |
/* declare one statelist per surface */ |
| 467 |
static surf_statelist surf_states[MAX_DEVICE_SURFACES]; |
| 468 |
|
| 469 |
/* declare one description table per device */ |
| 470 |
static dev_descrip_table dev_descrip; |
| 471 |
|
| 472 |
/* variable to keep track of current statelist */ |
| 473 |
/* -- this is global so CDR can know which state to look at */ |
| 474 |
static surf_statelist *cur_state; |
| 475 |
|
| 476 |
/* These arrays are global because of size. Used in cell and pixel array */ |
| 477 |
static float rarray[MAX_ARRAY], garray[MAX_ARRAY], barray[MAX_ARRAY]; |
| 478 |
static int varray[MAX_ARRAY]; |
| 479 |
|
| 480 |
/*-------------------------------------------------------------*/ |
| 481 |
/* >> CGI/SVDI DEVICE DRIVER ROUTINES */ |
| 482 |
/*-------------------------------------------------------------*/ |
| 483 |
|
| 484 |
void cgixxx(anything *params[], int num_surfaces, anything *surf_list[]) |
| 485 |
{ |
| 486 |
/* Main entry point */ |
| 487 |
switch (*(short *)params[0]) { |
| 488 |
case ACTIVATE_FN: xactivate(surf_list); break; |
| 489 |
case DEACTIVATE_FN: xdeactivate(surf_list); break; |
| 490 |
case CI_FN: xci(params, num_surfaces, surf_list); break; |
| 491 |
case CT_FN: xct(num_surfaces, surf_list); break; |
| 492 |
case CXDFAC_FN: xcxdfac(num_surfaces, surf_list); break; |
| 493 |
case CPDS_FN: xcpds(params, num_surfaces, surf_list); break; |
| 494 |
case CENDPG_FN: xcendpg(num_surfaces, surf_list); break; |
| 495 |
case CBC_FN: xcbc(params, num_surfaces, surf_list); break; |
| 496 |
case CVDCX_FN: xcvdcx(params, num_surfaces, surf_list); break; |
| 497 |
case CV_FN: xcv(params, num_surfaces, surf_list); break; |
| 498 |
case CCL_FN: xccl(params, num_surfaces, surf_list); break; |
| 499 |
case CDSCL_FN: xcdscl(params, num_surfaces, surf_list); break; |
| 500 |
case CDQERR_FN: xcdqerr(params, surf_list); break; |
| 501 |
case CERHCT_FN: xcerhct(params, num_surfaces, surf_list); break; |
| 502 |
case CCIXP_FN: xccixp(params, num_surfaces, surf_list); break; |
| 503 |
case CESC_FN: xcesc(params, num_surfaces, surf_list); break; |
| 504 |
case CQID_FN: xcqid(params, surf_list); break; |
| 505 |
case CQD_FN: xcqd(params, surf_list); break; |
| 506 |
case CLF_FN: xclf(params, surf_list); break; |
| 507 |
#ifndef sgi |
| 508 |
case CLPR_FN: xclpr(params, surf_list); break; |
| 509 |
#endif |
| 510 |
case CQSP_FN: xcqsp(params, surf_list); break; |
| 511 |
case CLESC_FN: xclesc(params, surf_list); break; |
| 512 |
case CQP_FN: xcqp(params, surf_list); break; |
| 513 |
case CQCL_FN: xcqcl(params, surf_list); break; |
| 514 |
case CPL_FN: xcpl(params, num_surfaces, surf_list); break; |
| 515 |
case CDJPL_FN: xcdjpl(params, num_surfaces, surf_list); break; |
| 516 |
case CPM_FN: xcpm(params, num_surfaces, surf_list); break; |
| 517 |
case CTX_FN: xctx(params, num_surfaces, surf_list); break; |
| 518 |
case CPG_FN: xcpg(params, num_surfaces, surf_list); break; |
| 519 |
case CCA_FN: xcca(params, num_surfaces, surf_list); break; |
| 520 |
case CPXA_FN: xcpxa(params, num_surfaces, surf_list); break; |
| 521 |
case CLNT_FN: xclnt(params, num_surfaces, surf_list); break; |
| 522 |
case CLNW_FN: xclnw(params, num_surfaces, surf_list); break; |
| 523 |
case CLNC_FN: xclnc(params, num_surfaces, surf_list); break; |
| 524 |
case CMKT_FN: xcmkt(num_surfaces, surf_list); break; |
| 525 |
case CMKS_FN: xcmks(params, num_surfaces, surf_list); break; |
| 526 |
case CMKC_FN: xcmkc(params, num_surfaces, surf_list); break; |
| 527 |
case CTXP_FN: xctxp(params, num_surfaces, surf_list); break; |
| 528 |
case CTXC_FN: xctxc(params, num_surfaces, surf_list); break; |
| 529 |
case CCHH_FN: xcchh(params, num_surfaces, surf_list); break; |
| 530 |
case CCHO_FN: xccho(params, num_surfaces, surf_list); break; |
| 531 |
case CIS_FN: xcis(params, num_surfaces, surf_list); break; |
| 532 |
case CFLC_FN: xcflc(params, num_surfaces, surf_list); break; |
| 533 |
case CCSM_FN: xccsm(params, num_surfaces, surf_list); break; |
| 534 |
case CCT_FN: xcct(params, num_surfaces, surf_list); break; |
| 535 |
case CGTXX_FN: xcgtxx(params, surf_list); break; |
| 536 |
case CQPRL_FN: xcqprl(params, surf_list); break; |
| 537 |
case CQLN_FN: xcqln(params, surf_list); break; |
| 538 |
case CQLNT_FN: xcqlnt(params, surf_list); break; |
| 539 |
case CQSLW_FN: xcqslw(params, surf_list); break; |
| 540 |
case CQMK_FN: xcqmk(params, surf_list); break; |
| 541 |
case CQMKT_FN: xcqmkt(params, surf_list); break; |
| 542 |
case CQSMS_FN: xcqsms(params, surf_list); break; |
| 543 |
case CQCHH_FN: xcqchh(params, surf_list); break; |
| 544 |
case CQFL_FN: xcqfl(params, surf_list); break; |
| 545 |
case CQC_FN: xcqc(params, surf_list); break; |
| 546 |
case CQLNA_FN: xcqlna(params, surf_list); break; |
| 547 |
case CQMKA_FN: xcqmka(params, surf_list); break; |
| 548 |
case CQTXA_FN: xcqtxa(params, surf_list); break; |
| 549 |
case CQFLA_FN: xcqfla(params, surf_list); break; |
| 550 |
case CQCTE_FN: xcqcte(params, surf_list); break; |
| 551 |
case CILI_FN: xcili(params, surf_list); break; |
| 552 |
case CRQLC_FN: xcrqlc(params, surf_list); break; |
| 553 |
} /* end switch */ |
| 554 |
} /* end cgixxx */ |
| 555 |
|
| 556 |
/* ACTIVATE */ |
| 557 |
static void xactivate(anything **surf_list) |
| 558 |
{ |
| 559 |
int new_state; /* index of new state to use */ |
| 560 |
|
| 561 |
if (first_free_state >= 0) { /* there is free one, use it */ |
| 562 |
new_state = first_free_state; |
| 563 |
first_free_state = surf_states[new_state].next_free_state; |
| 564 |
} |
| 565 |
else if (last_alloc_state < MAX_DEVICE_SURFACES - 1) { |
| 566 |
new_state = last_alloc_state + 1; /* can alloc one */ |
| 567 |
++last_alloc_state; |
| 568 |
} |
| 569 |
else { /* none available */ |
| 570 |
new_state = -1; |
| 571 |
} /* end if */ |
| 572 |
|
| 573 |
if (new_state < 0) { /* problem, report error & go away */ |
| 574 |
surf_list[0] = NULL; |
| 575 |
return; |
| 576 |
} /* end if problem */ |
| 577 |
|
| 578 |
/* got new state, init it */ |
| 579 |
surf_states[new_state].cgi_inited = CNO; |
| 580 |
surf_states[new_state].this_index = new_state; /* save for dealloc */ |
| 581 |
/* -- for batch devices */ |
| 582 |
copy_string(surf_states[new_state].filename, DEFAULT_OUTFILE_NAME, 100); |
| 583 |
surf_states[new_state].file_d = -1; |
| 584 |
|
| 585 |
/* set surface state_list pointer to point to this state list */ |
| 586 |
surf_list[0] = (anything *)&(surf_states[new_state]); |
| 587 |
|
| 588 |
} /* end xactivate */ |
| 589 |
|
| 590 |
/* DEACTIVATE */ |
| 591 |
static void xdeactivate(anything **surf_list) |
| 592 |
{ |
| 593 |
/* deallocate memory allocated for cgi state list */ |
| 594 |
|
| 595 |
int index; /* which state is this surface linked to */ |
| 596 |
|
| 597 |
index = ((surf_statelist *)surf_list[0])->this_index; |
| 598 |
if ((index >= 0) && (index < MAX_DEVICE_SURFACES)) { |
| 599 |
surf_states[index].next_free_state = first_free_state; |
| 600 |
first_free_state = index; |
| 601 |
} /* end if */ |
| 602 |
|
| 603 |
/* unlink cgi state list from surface */ |
| 604 |
surf_list[0] = NULL; |
| 605 |
|
| 606 |
} /* end xdeactivate */ |
| 607 |
|
| 608 |
/* INITIALIZE */ |
| 609 |
static void xci(anything **params, int num_surfaces, anything **surf_list) |
| 610 |
{ |
| 611 |
int i; /* index for loop on surf_list */ |
| 612 |
float zero = 0.; |
| 613 |
int izero = 0; |
| 614 |
|
| 615 |
for (i = 0; i < num_surfaces; ++i) { |
| 616 |
|
| 617 |
/* cur_state is global - points to current statelist */ |
| 618 |
cur_state = (surf_statelist *)surf_list[i]; |
| 619 |
|
| 620 |
/* initialize/reinit SVDI and/or set device descript table */ |
| 621 |
/* -- this needs to happen before calling init_state */ |
| 622 |
|
| 623 |
if (cur_state->cgi_inited == CNO) { /* this surface has never been |
| 624 |
initialized */ |
| 625 |
vdinit(&zero, &izero); |
| 626 |
|
| 627 |
/* set device descript table for this device only once */ |
| 628 |
if (dev_descrip.set_flag == FALSE) { |
| 629 |
set_dev_descrip(); |
| 630 |
dev_descrip.set_flag = TRUE; |
| 631 |
} /* end if set_flag */ |
| 632 |
} /* end if surface not initialized */ |
| 633 |
|
| 634 |
else { /* this surface has been initialized once already */ |
| 635 |
|
| 636 |
/* reset SVDI attributes */ |
| 637 |
reset_vdi(cur_state); |
| 638 |
|
| 639 |
/* if prepare drawing surface, issue a new page */ |
| 640 |
if (*(int *)params[1] == CYES) { |
| 641 |
vdnwpg(); |
| 642 |
} |
| 643 |
} /* end else surface initialized */ |
| 644 |
|
| 645 |
/* initialize/reinitialize the default device state */ |
| 646 |
init_state(cur_state); |
| 647 |
|
| 648 |
/* set cgi_inited to initialized */ |
| 649 |
cur_state->cgi_inited = CYES; |
| 650 |
|
| 651 |
} /* end for each surface */ |
| 652 |
} /* end xci */ |
| 653 |
|
| 654 |
/* TERMINATE */ |
| 655 |
static void xct(int num_surfaces, anything **surf_list) |
| 656 |
{ |
| 657 |
int i; /* index for loop on surfaces */ |
| 658 |
|
| 659 |
for (i = 0; i < num_surfaces; ++i) { |
| 660 |
|
| 661 |
cur_state = (surf_statelist *)surf_list[i]; |
| 662 |
if (cur_state->cgi_inited != CYES) { |
| 663 |
break; |
| 664 |
} |
| 665 |
|
| 666 |
/* terminate and set state to uninitialized */ |
| 667 |
vdterm(); |
| 668 |
cur_state->cgi_inited = CNO; |
| 669 |
|
| 670 |
} /* end for each surface */ |
| 671 |
} /* end xct */ |
| 672 |
|
| 673 |
/* EXECUTE DEFERRED ACTIONS */ |
| 674 |
static void xcxdfac(int num_surfaces, anything **surf_list) |
| 675 |
{ |
| 676 |
int i; /* index for loop on surfaces */ |
| 677 |
|
| 678 |
for (i = 0; i < num_surfaces; ++i) { |
| 679 |
|
| 680 |
cur_state = (surf_statelist *)surf_list[i]; |
| 681 |
if (cur_state->cgi_inited != CYES) { |
| 682 |
break; |
| 683 |
} |
| 684 |
|
| 685 |
vdbufl(); |
| 686 |
|
| 687 |
} /* end for each surface */ |
| 688 |
} /* end xcxdfac */ |
| 689 |
|
| 690 |
/* PREPARE DRAWING SURFACE */ |
| 691 |
static void xcpds(anything **params, int num_surfaces, anything **surf_list) |
| 692 |
{ |
| 693 |
int i; /* index for loop on surfaces */ |
| 694 |
|
| 695 |
for (i = 0; i < num_surfaces; ++i) { |
| 696 |
|
| 697 |
cur_state = (surf_statelist *)surf_list[i]; |
| 698 |
if (cur_state->cgi_inited != CYES) { |
| 699 |
break; |
| 700 |
} |
| 701 |
|
| 702 |
/* new page if page has been marked or parameter is forced */ |
| 703 |
if (cur_state->pic_dirty == CDIRTY || *(int *)params[1] == CFORCC) { |
| 704 |
vdnwpg(); |
| 705 |
cur_state->pic_dirty = CCLEAN; |
| 706 |
} |
| 707 |
|
| 708 |
} /* end for each surface */ |
| 709 |
} /* end xcpds */ |
| 710 |
|
| 711 |
/* END PAGE */ |
| 712 |
static void xcendpg(int num_surfaces, anything **surf_list) |
| 713 |
{ |
| 714 |
int i; /* index for loop on surfaces */ |
| 715 |
|
| 716 |
for (i = 0; i < num_surfaces; ++i) { |
| 717 |
|
| 718 |
cur_state = (surf_statelist *)surf_list[i]; |
| 719 |
if (cur_state->cgi_inited != CYES) { |
| 720 |
break; |
| 721 |
} |
| 722 |
|
| 723 |
/* perform an implicit execute deferred actions */ |
| 724 |
vdbufl(); |
| 725 |
|
| 726 |
/* for hardcopy, call new page only if page has been marked */ |
| 727 |
if (dev_descrip.copy_class == CHARD) { |
| 728 |
if (cur_state->pic_dirty == CDIRTY) { |
| 729 |
vdnwpg(); |
| 730 |
cur_state->pic_dirty = CCLEAN; |
| 731 |
} /* end if dirty page */ |
| 732 |
} |
| 733 |
|
| 734 |
} /* end for each surface */ |
| 735 |
} /* end xcendpg */ |
| 736 |
|
| 737 |
/* BACKGROUND COLOR */ |
| 738 |
static void xcbc(anything **params, int num_surfaces, anything **surf_list) |
| 739 |
{ |
| 740 |
int i; /* index for loop on surfaces */ |
| 741 |
int bg_color[3]; /* temporary array */ |
| 742 |
|
| 743 |
bg_color[0] = *(int *)params[1]; |
| 744 |
bg_color[1] = *(int *)params[2]; |
| 745 |
bg_color[2] = *(int *)params[3]; |
| 746 |
|
| 747 |
for (i = 0; i < num_surfaces; ++i) { |
| 748 |
|
| 749 |
cur_state = (surf_statelist *)surf_list[i]; |
| 750 |
if (cur_state->cgi_inited != CYES) { |
| 751 |
break; |
| 752 |
} |
| 753 |
|
| 754 |
set_background_color(cur_state, bg_color); |
| 755 |
|
| 756 |
} /* end for each surface */ |
| 757 |
} /* end xcbc */ |
| 758 |
|
| 759 |
/* VDC EXTENT */ |
| 760 |
static void xcvdcx(anything **params, int num_surfaces, anything **surf_list) |
| 761 |
{ |
| 762 |
int i; /* index for loop on surfaces */ |
| 763 |
|
| 764 |
for (i = 0; i < num_surfaces; ++i) { |
| 765 |
|
| 766 |
cur_state = (surf_statelist *)surf_list[i]; |
| 767 |
if (cur_state->cgi_inited != CYES) { |
| 768 |
break; |
| 769 |
} |
| 770 |
|
| 771 |
/* store the values in the state list */ |
| 772 |
/* default integer precision is 16 - check range */ |
| 773 |
if (*(float *)params[1] > 32767.0f || *(float *)params[2] > 32767.0f || |
| 774 |
*(float *)params[3] > 32767.0f || *(float *)params[4] > 32767.0f || |
| 775 |
*(float *)params[1] < -32767.0f || *(float *)params[2] < -32767.0f || |
| 776 |
*(float *)params[3] < -32767.0f || *(float *)params[4] < -32767.0f) { |
| 777 |
/* error 1:-103 VDC Extent out of range. Function ignored */ |
| 778 |
report_error(cur_state, 1, -103, *(short *)params[0]); |
| 779 |
return; |
| 780 |
} /* end if error */ |
| 781 |
|
| 782 |
/* no error */ |
| 783 |
cur_state->vdc1.x = *(float *)params[1]; |
| 784 |
cur_state->vdc1.y = *(float *)params[2]; |
| 785 |
cur_state->vdc2.x = *(float *)params[3]; |
| 786 |
cur_state->vdc2.y = *(float *)params[4]; |
| 787 |
/* end else no error */ |
| 788 |
|
| 789 |
/* VDC to viewport (in NDC) mapping */ |
| 790 |
/* -- this routine sets effective viewport in VDC and |
| 791 |
NDC (forcing isotropic mapping) and the mapping scale */ |
| 792 |
set_mapping(cur_state); |
| 793 |
|
| 794 |
/* determine new effective clipping rectangle */ |
| 795 |
/* ..First figure out the min and max VDC points. Since |
| 796 |
* the user cannot change the clip rectangle, the min and |
| 797 |
* max clip rectangle points are known. (min = clip_rect1 = [0,0]; |
| 798 |
* max = clip_rect2 = [32767.,32767.]) |
| 799 |
*/ |
| 800 |
/* need to check for degenerate case */ |
| 801 |
cur_state->eff_clip_rect1.x = |
| 802 |
max(min(cur_state->vdc1.x, cur_state->vdc2.x), cur_state->clip_rect1.x); |
| 803 |
cur_state->eff_clip_rect1.y = |
| 804 |
max(min(cur_state->vdc1.y, cur_state->vdc2.y), cur_state->clip_rect1.y); |
| 805 |
cur_state->eff_clip_rect2.x = |
| 806 |
min(max(cur_state->vdc1.x, cur_state->vdc2.x), cur_state->clip_rect2.x); |
| 807 |
cur_state->eff_clip_rect2.y = |
| 808 |
min(max(cur_state->vdc1.y, cur_state->vdc2.y), cur_state->clip_rect2.y); |
| 809 |
|
| 810 |
/* set clipping region */ |
| 811 |
set_clipping(cur_state); |
| 812 |
|
| 813 |
} /* end for each surface */ |
| 814 |
} /* end xcvdcx */ |
| 815 |
|
| 816 |
/* DEVICE VIEWPORT */ |
| 817 |
static void xcv(anything **params, int num_surfaces, anything **surf_list) |
| 818 |
{ |
| 819 |
int i; /* index for loop on surfaces */ |
| 820 |
|
| 821 |
for (i = 0; i < num_surfaces; ++i) { |
| 822 |
|
| 823 |
cur_state = (surf_statelist *)surf_list[i]; |
| 824 |
if (cur_state->cgi_inited != CYES) { |
| 825 |
break; |
| 826 |
} |
| 827 |
|
| 828 |
/* viewport - default viewport specification mode is FRACTION OF |
| 829 |
* DRAWING SURFACE. Thus, the viewport (0,0),(1,1) corresponds to |
| 830 |
* the lower and upper corners, respectively, of the default |
| 831 |
* device viewport, which is the largest unrotated rectangular area |
| 832 |
* visible on the drawing surface. Numbers outside the range |
| 833 |
* [0.0...1.0] may be specified. |
| 834 |
*/ |
| 835 |
|
| 836 |
/* store values in state list */ |
| 837 |
cur_state->vp1.x = *(float *)params[1]; |
| 838 |
cur_state->vp1.y = *(float *)params[2]; |
| 839 |
cur_state->vp2.x = *(float *)params[3]; |
| 840 |
cur_state->vp2.y = *(float *)params[4]; |
| 841 |
|
| 842 |
/* do VDC to NDC mapping */ |
| 843 |
/* -- this routine sets effective viewports in VDC and |
| 844 |
NDC (forcing isotropic mapping) and the mapping scale */ |
| 845 |
set_mapping(cur_state); |
| 846 |
|
| 847 |
/* set clipping region */ |
| 848 |
set_clipping(cur_state); |
| 849 |
|
| 850 |
} /* end for each surface */ |
| 851 |
} /* end xcv */ |
| 852 |
|
| 853 |
/* CLIP INDICATOR */ |
| 854 |
static void xccl(anything **params, int num_surfaces, anything **surf_list) |
| 855 |
{ |
| 856 |
int i; /* index for loop on surfaces */ |
| 857 |
|
| 858 |
for (i = 0; i < num_surfaces; ++i) { |
| 859 |
|
| 860 |
cur_state = (surf_statelist *)surf_list[i]; |
| 861 |
if (cur_state->cgi_inited != CYES) { |
| 862 |
break; |
| 863 |
} |
| 864 |
|
| 865 |
/* check for a legal enumerated value, store in state table |
| 866 |
and set the clipping region */ |
| 867 |
if (*(int *)params[1] == CON || *(int *)params[1] == COFF) { |
| 868 |
cur_state->clip_indicator = *(int *)params[1]; |
| 869 |
set_clipping(cur_state); |
| 870 |
} |
| 871 |
else { |
| 872 |
/* error 1:-101 Enumerated parameter out of range. Function ignored */ |
| 873 |
report_error(cur_state, 1, -101, *(short *)params[0]); |
| 874 |
} |
| 875 |
|
| 876 |
} /* end for each surface */ |
| 877 |
} /* end xccl */ |
| 878 |
|
| 879 |
/* DRAWING SURFACE CLIP INDICATOR */ |
| 880 |
static void xcdscl(anything **params, int num_surfaces, anything **surf_list) |
| 881 |
{ |
| 882 |
int i; /* index for loop on surfaces */ |
| 883 |
|
| 884 |
for (i = 0; i < num_surfaces; ++i) { |
| 885 |
|
| 886 |
cur_state = (surf_statelist *)surf_list[i]; |
| 887 |
if (cur_state->cgi_inited != CYES) { |
| 888 |
break; |
| 889 |
} |
| 890 |
|
| 891 |
/* check for a legal enumerated value, store in state table |
| 892 |
and set the clipping region */ |
| 893 |
if (*(int *)params[1] == CDCOFF || *(int *)params[1] == CDCREC || *(int *)params[1] == CVPORT) { |
| 894 |
cur_state->ds_clip_indicator = *(int *)params[1]; |
| 895 |
set_clipping(cur_state); |
| 896 |
} |
| 897 |
else { |
| 898 |
/* error 1:-101 Enumerated parameter out of range. Function ignored */ |
| 899 |
report_error(cur_state, 1, -101, *(short *)params[0]); |
| 900 |
} |
| 901 |
|
| 902 |
} /* end for each surface */ |
| 903 |
} /* end xcdscl */ |
| 904 |
|
| 905 |
/* DEQUEUE ERROR REPORTS */ |
| 906 |
static void xcdqerr(anything **params, anything **surf_list) |
| 907 |
{ |
| 908 |
int i; /* loop variable */ |
| 909 |
int max_ret; /* max number of errors to return */ |
| 910 |
|
| 911 |
/* there is only one surface for inquiries */ |
| 912 |
cur_state = (surf_statelist *)surf_list[0]; |
| 913 |
if (cur_state->cgi_inited != CYES) { |
| 914 |
return; |
| 915 |
} |
| 916 |
|
| 917 |
/* find the number of errors to be returned */ |
| 918 |
max_ret = (*(int *)params[1] < cur_state->err_count) ? *(int *)params[1] : cur_state->err_count; |
| 919 |
|
| 920 |
for (i = 0; i < max_ret; i++) { |
| 921 |
|
| 922 |
((int *)params[5])[i] = cur_state->err_queue[cur_state->err_head_ptr].err_class; |
| 923 |
((int *)params[6])[i] = cur_state->err_queue[cur_state->err_head_ptr].err_num; |
| 924 |
((int *)params[7])[i] = cur_state->err_queue[cur_state->err_head_ptr].func_id; |
| 925 |
|
| 926 |
/* update the head of list ptr */ |
| 927 |
cur_state->err_head_ptr++; |
| 928 |
if (cur_state->err_head_ptr == ERROR_LIST_SIZE) { |
| 929 |
cur_state->err_head_ptr = 0; |
| 930 |
} |
| 931 |
|
| 932 |
/* decrement the count of errors */ |
| 933 |
cur_state->err_count--; |
| 934 |
|
| 935 |
} /* end for i */ |
| 936 |
|
| 937 |
/* number of reports remaining in the queue */ |
| 938 |
*(int *)params[3] = cur_state->err_count; |
| 939 |
|
| 940 |
/* number of reports returned */ |
| 941 |
*(int *)params[4] = i; |
| 942 |
|
| 943 |
/* validity flag */ |
| 944 |
*(int *)params[2] = CVAL; |
| 945 |
|
| 946 |
} /* end xcdqerr */ |
| 947 |
|
| 948 |
/* ERROR HANDLING CONTROL */ |
| 949 |
static void xcerhct(anything **params, int num_surfaces, anything **surf_list) |
| 950 |
{ |
| 951 |
int i, j; /* loop indices */ |
| 952 |
|
| 953 |
for (i = 0; i < num_surfaces; ++i) { |
| 954 |
|
| 955 |
cur_state = (surf_statelist *)surf_list[i]; |
| 956 |
if (cur_state->cgi_inited != CYES) { |
| 957 |
break; |
| 958 |
} |
| 959 |
|
| 960 |
/* store error control level in state list */ |
| 961 |
for (j = 0; j < *(int *)params[1]; j++) { |
| 962 |
|
| 963 |
/* check enumeration types */ |
| 964 |
if (((int *)params[3])[j] != CEHON && ((int *)params[3])[j] != CEHROF && |
| 965 |
((int *)params[3])[j] != CEHDOF) { |
| 966 |
/* error 1:-101 Enumerated parameter out of range. Function ignored */ |
| 967 |
report_error(cur_state, 1, -101, *(short *)params[0]); |
| 968 |
|
| 969 |
/* check for legal index */ |
| 970 |
} |
| 971 |
else if (((int *)params[2])[j] < 1 || ((int *)params[2])[j] > MAX_ERROR_CLASS) { |
| 972 |
/* error 1:-102 Index out of range. Function ignored */ |
| 973 |
report_error(cur_state, 1, -102, *(short *)params[0]); |
| 974 |
} |
| 975 |
else { |
| 976 |
cur_state->err_flag[((int *)params[2])[j] - 1] = ((int *)params[3])[j]; |
| 977 |
} |
| 978 |
} /* end for j */ |
| 979 |
|
| 980 |
} /* end for each surface */ |
| 981 |
} /* end xcerhct */ |
| 982 |
|
| 983 |
/* COLOR INDEX PRECISION */ |
| 984 |
static void xccixp(anything **params, int num_surfaces, anything **surf_list) |
| 985 |
{ |
| 986 |
int i; /* index for loop on surfaces */ |
| 987 |
|
| 988 |
/* I'm not doing anything with color index precision now */ |
| 989 |
|
| 990 |
for (i = 0; i < num_surfaces; ++i) { |
| 991 |
|
| 992 |
cur_state = (surf_statelist *)surf_list[i]; |
| 993 |
if (cur_state->cgi_inited != CYES) { |
| 994 |
break; |
| 995 |
} |
| 996 |
|
| 997 |
if (*(int *)params[1] == 8 || *(int *)params[1] == 16 || *(int *)params[1] == 24 || |
| 998 |
*(int *)params[1] == 32) { |
| 999 |
cur_state->color_index_prec = *(int *)params[1]; |
| 1000 |
} |
| 1001 |
else { |
| 1002 |
/* error 3:204 Selected precision not supported */ |
| 1003 |
report_error(cur_state, 3, 204, *(short *)params[0]); |
| 1004 |
} |
| 1005 |
|
| 1006 |
} /* end for each surface */ |
| 1007 |
} /* end xccixp */ |
| 1008 |
|
| 1009 |
/* ESCAPE */ |
| 1010 |
static void xcesc(anything **params, int num_surfaces, anything **surf_list) |
| 1011 |
{ |
| 1012 |
int i; /* index for loop on surfaces */ |
| 1013 |
int j; /* loop index */ |
| 1014 |
int first; /* logical; TRUE = first time through */ |
| 1015 |
char data[80]; /* temp for parsing data record */ |
| 1016 |
char c; /* single character */ |
| 1017 |
int vdi_esc; /* used for SVDI escape call */ |
| 1018 |
int count; /* used for SVDI escape call */ |
| 1019 |
float args[10]; /* used for SVDI escape call */ |
| 1020 |
int tokenindex; /* index in data record of first char */ |
| 1021 |
/* after end of token*/ |
| 1022 |
first = TRUE; |
| 1023 |
|
| 1024 |
for (i = 0; i < num_surfaces; ++i) { |
| 1025 |
|
| 1026 |
cur_state = (surf_statelist *)surf_list[i]; |
| 1027 |
|
| 1028 |
switch (*(int *)params[1]) { |
| 1029 |
|
| 1030 |
case XEMFNM: /* file name */ |
| 1031 |
|
| 1032 |
if (first) { |
| 1033 |
tokenindex = 0; /* first char of data record */ |
| 1034 |
|
| 1035 |
/* params[4] is an added parameter - contains the string length */ |
| 1036 |
gettoken(&tokenindex, (int *)params[2], (char *)params[3], 80, data); |
| 1037 |
|
| 1038 |
first = FALSE; |
| 1039 |
} /* end if first */ |
| 1040 |
|
| 1041 |
/* this function must be called before CI */ |
| 1042 |
/* ...error message if not?? check for legal file name?? */ |
| 1043 |
if (cur_state->cgi_inited != CYES) { |
| 1044 |
copy_string(cur_state->filename, data, 100); |
| 1045 |
} |
| 1046 |
|
| 1047 |
break; |
| 1048 |
|
| 1049 |
case XEAGMD: /* set terminal to alpha/graphics */ |
| 1050 |
|
| 1051 |
if (first) { |
| 1052 |
tokenindex = 0; /* first char of data record */ |
| 1053 |
|
| 1054 |
/* params[4] is an added parameter - contains the string length */ |
| 1055 |
gettoken(&tokenindex, (int *)params[2], (char *)params[3], 80, data); |
| 1056 |
|
| 1057 |
/* SVDI takes care of 'graphics', check for 'alpha' */ |
| 1058 |
j = 0; |
| 1059 |
while ((c = data[j++])) { |
| 1060 |
if (isalpha(c) && isupper(c)) { |
| 1061 |
data[j - 1] = tolower(c); |
| 1062 |
} |
| 1063 |
} |
| 1064 |
|
| 1065 |
first = FALSE; |
| 1066 |
} /* end if first */ |
| 1067 |
|
| 1068 |
if (strncmp(data, "alpha", 5) == 0) { |
| 1069 |
vdbufl(); |
| 1070 |
} |
| 1071 |
|
| 1072 |
break; |
| 1073 |
|
| 1074 |
case XESVDI: /* SVDI escape */ |
| 1075 |
|
| 1076 |
if (first) { |
| 1077 |
tokenindex = 0; /* first char of data record */ |
| 1078 |
|
| 1079 |
/* first token is SVDI escape number */ |
| 1080 |
gettoken(&tokenindex, (int *)params[2], (char *)params[3], 80, data); |
| 1081 |
vdi_esc = strtol(data, NULL, 10); |
| 1082 |
|
| 1083 |
/* second token is number of parameters to SVDI escape */ |
| 1084 |
gettoken(&tokenindex, (int *)params[2], (char *)params[3], 80, data); |
| 1085 |
count = strtol(data, NULL, 10); |
| 1086 |
|
| 1087 |
/* the rest of the tokens contain the arguments */ |
| 1088 |
for (j = 0; j < count && j < 10; j++) { |
| 1089 |
gettoken(&tokenindex, (int *)params[2], (char *)params[3], 80, data); |
| 1090 |
args[j] = (float)strtod(data, NULL); |
| 1091 |
} |
| 1092 |
|
| 1093 |
first = FALSE; |
| 1094 |
} /* end if first */ |
| 1095 |
|
| 1096 |
vdescp(&vdi_esc, &count, args); |
| 1097 |
|
| 1098 |
break; |
| 1099 |
|
| 1100 |
case XEPGSZ: /* Page size */ |
| 1101 |
|
| 1102 |
if (first) { |
| 1103 |
tokenindex = 0; /* first char of data record */ |
| 1104 |
|
| 1105 |
/* first token is page size in x */ |
| 1106 |
gettoken(&tokenindex, (int *)params[2], (char *)params[3], 80, data); |
| 1107 |
args[0] = (float)strtod(data, NULL); |
| 1108 |
|
| 1109 |
/* second token is page size in y */ |
| 1110 |
gettoken(&tokenindex, (int *)params[2], (char *)params[3], 80, data); |
| 1111 |
args[1] = (float)strtod(data, NULL); |
| 1112 |
|
| 1113 |
/* page size svdi number is 1400 */ |
| 1114 |
vdi_esc = 1400; |
| 1115 |
count = 2; |
| 1116 |
|
| 1117 |
first = FALSE; |
| 1118 |
} /* end if first */ |
| 1119 |
|
| 1120 |
vdescp(&vdi_esc, &count, args); |
| 1121 |
|
| 1122 |
break; |
| 1123 |
|
| 1124 |
case XEBELL: /* Ring the bell */ vdbell(); break; |
| 1125 |
|
| 1126 |
default: |
| 1127 |
/* error 2:001 Request unsupported feature. Function ignored */ |
| 1128 |
report_error(cur_state, 2, 001, *(short *)params[0]); |
| 1129 |
break; |
| 1130 |
|
| 1131 |
} /* end switch */ |
| 1132 |
} /* end for i */ |
| 1133 |
} /* end xcesc */ |
| 1134 |
|
| 1135 |
/* INQUIRE DEVICE IDENTIFICATION */ |
| 1136 |
static void xcqid(anything **params, anything **surf_list) |
| 1137 |
{ |
| 1138 |
char *cgi_devid; /* pointer to character device id */ |
| 1139 |
int maxchr; /* max number of chars in device id */ |
| 1140 |
int qdc_index = 23; /* index for inquiries to vdiqdc */ |
| 1141 |
float value; /* value returned by vdiqdc */ |
| 1142 |
static int set = FALSE; /* flag whether values have been set yet */ |
| 1143 |
|
| 1144 |
/* there is only one surface for inquiries */ |
| 1145 |
cur_state = (surf_statelist *)surf_list[0]; |
| 1146 |
if (cur_state->cgi_inited != CYES) { |
| 1147 |
return; |
| 1148 |
} |
| 1149 |
|
| 1150 |
if (!set) { /* values have't been set, inquire SVDI */ |
| 1151 |
|
| 1152 |
set = TRUE; |
| 1153 |
|
| 1154 |
/* device id */ |
| 1155 |
vdiqdc(&qdc_index, &value); |
| 1156 |
cgi_devid = get_devid_char(value); |
| 1157 |
if (cgi_devid != NULL) { |
| 1158 |
copy_string(dev_descrip.dev_id, cgi_devid, 4); |
| 1159 |
} |
| 1160 |
|
| 1161 |
} /* end if not set */ |
| 1162 |
|
| 1163 |
/* response validity */ |
| 1164 |
*(int *)params[2] = CVAL; |
| 1165 |
|
| 1166 |
/* return device class - this is set in set_dev_descrip() */ |
| 1167 |
*(int *)params[3] = dev_descrip.dev_class; |
| 1168 |
|
| 1169 |
/* return device id */ |
| 1170 |
maxchr = (*(int *)params[1] > 3) ? 3 : *(int *)params[1]; |
| 1171 |
copy_string((char *)params[4], dev_descrip.dev_id, maxchr); |
| 1172 |
*((char *)params[4] + maxchr) = '\0'; |
| 1173 |
|
| 1174 |
} /* end xcqid */ |
| 1175 |
|
| 1176 |
/* INQUIRE DEVICE DESCRIPTION */ |
| 1177 |
static void xcqd(anything **params, anything **surf_list) |
| 1178 |
{ |
| 1179 |
int qdc_index; /* index for inquiries to vdiqdc */ |
| 1180 |
float value; /* value returned by vdiqdc */ |
| 1181 |
static int set = FALSE; /* flag whether values have been set */ |
| 1182 |
|
| 1183 |
/* there is only one surface for inquiries */ |
| 1184 |
cur_state = (surf_statelist *)surf_list[0]; |
| 1185 |
if (cur_state->cgi_inited != CYES) { |
| 1186 |
return; |
| 1187 |
} |
| 1188 |
|
| 1189 |
if (!set) { /* values have't been set, inquire SVDI */ |
| 1190 |
|
| 1191 |
set = TRUE; |
| 1192 |
|
| 1193 |
/* display type */ |
| 1194 |
qdc_index = 2; |
| 1195 |
vdiqdc(&qdc_index, &value); |
| 1196 |
if (value == 0.0f) { |
| 1197 |
dev_descrip.display_type = CVECT; |
| 1198 |
} |
| 1199 |
else if (value == 1.0f) { |
| 1200 |
dev_descrip.display_type = CRAST; |
| 1201 |
} |
| 1202 |
else { |
| 1203 |
dev_descrip.display_type = COTHER; |
| 1204 |
} |
| 1205 |
|
| 1206 |
/* background color capability */ |
| 1207 |
qdc_index = 32; |
| 1208 |
vdiqdc(&qdc_index, &value); |
| 1209 |
dev_descrip.bcolor_cap = (value == 1.0f) ? CYES : CNO; |
| 1210 |
|
| 1211 |
/* dynamic modification for background color */ |
| 1212 |
dev_descrip.dynamic_mod_bg = CIRG; |
| 1213 |
|
| 1214 |
/* dynamic modification for VDC to device mapping */ |
| 1215 |
dev_descrip.dynamic_mod_map = CIRG; |
| 1216 |
|
| 1217 |
/* width and height in millimeters */ |
| 1218 |
/* ...SVDI returns 0 if it doesn't know. CGI does this also */ |
| 1219 |
qdc_index = 17; |
| 1220 |
vdiqdc(&qdc_index, &dev_descrip.draw_surf_width); |
| 1221 |
qdc_index = 18; |
| 1222 |
vdiqdc(&qdc_index, &dev_descrip.draw_surf_height); |
| 1223 |
|
| 1224 |
/* pixel location relative to coordinates */ |
| 1225 |
dev_descrip.pix_loc = CPXON; |
| 1226 |
|
| 1227 |
} /* end haven't been set */ |
| 1228 |
|
| 1229 |
/* validity flag */ |
| 1230 |
*(int *)params[1] = CVAL; |
| 1231 |
|
| 1232 |
/* stuff info into return values */ |
| 1233 |
/* ...copy_class and device corners are set in set_dev_descrip() */ |
| 1234 |
*(int *)params[2] = dev_descrip.copy_class; |
| 1235 |
*(int *)params[3] = dev_descrip.display_type; |
| 1236 |
*(int *)params[4] = dev_descrip.bcolor_cap; |
| 1237 |
*(int *)params[5] = dev_descrip.dynamic_mod_bg; |
| 1238 |
*(int *)params[6] = dev_descrip.dynamic_mod_map; |
| 1239 |
*(int *)params[7] = dev_descrip.dc1.x; |
| 1240 |
*(int *)params[8] = dev_descrip.dc1.y; |
| 1241 |
*(int *)params[9] = dev_descrip.dc2.x; |
| 1242 |
*(int *)params[10] = dev_descrip.dc2.y; |
| 1243 |
*(float *)params[11] = dev_descrip.draw_surf_width; |
| 1244 |
*(float *)params[12] = dev_descrip.draw_surf_height; |
| 1245 |
*(int *)params[13] = dev_descrip.pix_loc; |
| 1246 |
|
| 1247 |
} /* end xcqd */ |
| 1248 |
|
| 1249 |
/* LOOKUP FUNCTION SUPPORT */ |
| 1250 |
static void xclf(anything **params, anything **surf_list) |
| 1251 |
{ |
| 1252 |
int i; /* index for loop on surfaces */ |
| 1253 |
int qdc_index = 24; /* for inquire SVDI */ |
| 1254 |
static float poly_support = -1.; /* level of SVDI poly support */ |
| 1255 |
|
| 1256 |
/* there is only one surface for inquiries */ |
| 1257 |
cur_state = (surf_statelist *)surf_list[0]; |
| 1258 |
if (cur_state->cgi_inited != CYES) { |
| 1259 |
return; |
| 1260 |
} |
| 1261 |
|
| 1262 |
for (i = 0; i < *(int *)params[1]; i++) { |
| 1263 |
|
| 1264 |
switch (*(short *)params[0]) { |
| 1265 |
case ACTIVATE_FN: ((int *)params[5])[i] = CSYES; break; |
| 1266 |
case DEACTIVATE_FN: ((int *)params[5])[i] = CSYES; break; |
| 1267 |
case CI_FN: ((int *)params[5])[i] = CSYES; break; |
| 1268 |
case CT_FN: ((int *)params[5])[i] = CSYES; break; |
| 1269 |
case CXDFAC_FN: ((int *)params[5])[i] = CSYES; break; |
| 1270 |
case CPDS_FN: ((int *)params[5])[i] = CSYES; break; |
| 1271 |
case CENDPG_FN: ((int *)params[5])[i] = CSYES; break; |
| 1272 |
case CBC_FN: ((int *)params[5])[i] = CSYES; break; |
| 1273 |
case CVDCX_FN: ((int *)params[5])[i] = CSYES; break; |
| 1274 |
case CV_FN: ((int *)params[5])[i] = CSYES; break; |
| 1275 |
case CCL_FN: ((int *)params[5])[i] = CSYES; break; |
| 1276 |
case CDSCL_FN: ((int *)params[5])[i] = CSYES; break; |
| 1277 |
case CDQERR_FN: ((int *)params[5])[i] = CSYES; break; |
| 1278 |
case CERHCT_FN: ((int *)params[5])[i] = CSYES; break; |
| 1279 |
case CCIXP_FN: ((int *)params[5])[i] = CSNO; break; |
| 1280 |
case CESC_FN: ((int *)params[5])[i] = CSYES; break; |
| 1281 |
case CQID_FN: ((int *)params[5])[i] = CSYES; break; |
| 1282 |
case CQD_FN: ((int *)params[5])[i] = CSYES; break; |
| 1283 |
case CLF_FN: ((int *)params[5])[i] = CSYES; break; |
| 1284 |
case CLPR_FN: ((int *)params[5])[i] = CSYES; break; |
| 1285 |
case CQSP_FN: ((int *)params[5])[i] = CSYES; break; |
| 1286 |
case CLESC_FN: ((int *)params[5])[i] = CSYES; break; |
| 1287 |
case CQP_FN: ((int *)params[5])[i] = CSYES; break; |
| 1288 |
case CQCL_FN: ((int *)params[5])[i] = CSYES; break; |
| 1289 |
case CPL_FN: ((int *)params[5])[i] = CSYES; break; |
| 1290 |
case CDJPL_FN: ((int *)params[5])[i] = CSYES; break; |
| 1291 |
case CPM_FN: ((int *)params[5])[i] = CSYES; break; |
| 1292 |
case CTX_FN: ((int *)params[5])[i] = CSYES; break; |
| 1293 |
case CPG_FN: |
| 1294 |
if (poly_support == -1.0f) { |
| 1295 |
vdiqdc(&qdc_index, &poly_support); |
| 1296 |
} |
| 1297 |
if (poly_support < 3.0f) { |
| 1298 |
((int *)params[5])[i] = CSNO; |
| 1299 |
} |
| 1300 |
else { |
| 1301 |
((int *)params[5])[i] = CSYES; |
| 1302 |
} |
| 1303 |
break; |
| 1304 |
case CCA_FN: ((int *)params[5])[i] = CSYES; break; |
| 1305 |
case CPXA_FN: ((int *)params[5])[i] = CSYES; break; |
| 1306 |
case CLNT_FN: ((int *)params[5])[i] = CSYES; break; |
| 1307 |
case CLNW_FN: ((int *)params[5])[i] = CSYES; break; |
| 1308 |
case CLNC_FN: ((int *)params[5])[i] = CSYES; break; |
| 1309 |
case CMKT_FN: ((int *)params[5])[i] = CSYES; break; |
| 1310 |
case CMKS_FN: ((int *)params[5])[i] = CSNO; break; |
| 1311 |
case CMKC_FN: ((int *)params[5])[i] = CSYES; break; |
| 1312 |
case CTXP_FN: ((int *)params[5])[i] = CSNO; break; |
| 1313 |
case CTXC_FN: ((int *)params[5])[i] = CSNO; break; |
| 1314 |
case CCHH_FN: ((int *)params[5])[i] = CSYES; break; |
| 1315 |
case CCHO_FN: ((int *)params[5])[i] = CSNO; break; |
| 1316 |
case CIS_FN: ((int *)params[5])[i] = CSYES; break; |
| 1317 |
case CFLC_FN: ((int *)params[5])[i] = CSYES; break; |
| 1318 |
case CCSM_FN: ((int *)params[5])[i] = CSYES; break; |
| 1319 |
case CCT_FN: ((int *)params[5])[i] = CSYES; break; |
| 1320 |
case CGTXX_FN: ((int *)params[5])[i] = CSYES; break; |
| 1321 |
case CQPRL_FN: ((int *)params[5])[i] = CSYES; break; |
| 1322 |
case CQLN_FN: ((int *)params[5])[i] = CSYES; break; |
| 1323 |
case CQLNT_FN: ((int *)params[5])[i] = CSYES; break; |
| 1324 |
case CQSLW_FN: ((int *)params[5])[i] = CSNO; break; |
| 1325 |
case CQMK_FN: ((int *)params[5])[i] = CSNO; break; |
| 1326 |
case CQMKT_FN: ((int *)params[5])[i] = CSYES; break; |
| 1327 |
case CQSMS_FN: ((int *)params[5])[i] = CSNO; break; |
| 1328 |
case CQCHH_FN: ((int *)params[5])[i] = CSYES; break; |
| 1329 |
case CQFL_FN: ((int *)params[5])[i] = CSYES; break; |
| 1330 |
case CQC_FN: ((int *)params[5])[i] = CSYES; break; |
| 1331 |
case CQLNA_FN: ((int *)params[5])[i] = CSYES; break; |
| 1332 |
case CQMKA_FN: ((int *)params[5])[i] = CSNO; break; |
| 1333 |
case CQTXA_FN: ((int *)params[5])[i] = CSYES; break; |
| 1334 |
case CQFLA_FN: ((int *)params[5])[i] = CSNO; break; |
| 1335 |
case CQCTE_FN: ((int *)params[5])[i] = CSYES; break; |
| 1336 |
case CILI_FN: ((int *)params[5])[i] = CSYES; break; |
| 1337 |
case CRQLC_FN: ((int *)params[5])[i] = CSYES; break; |
| 1338 |
default: ((int *)params[5])[i] = CSNO; break; |
| 1339 |
} /* end switch */ |
| 1340 |
} |
| 1341 |
|
| 1342 |
/* validity flag */ |
| 1343 |
*(int *)params[4] = CVAL; |
| 1344 |
|
| 1345 |
} /* end xclf */ |
| 1346 |
|
| 1347 |
/* LOOKUP PROFILE SUPPORT */ |
| 1348 |
static void xclpr(anything **params, anything **surf_list) |
| 1349 |
{ |
| 1350 |
int i; /* index for loop on surfaces */ |
| 1351 |
|
| 1352 |
/* there is only one surface for inquiries */ |
| 1353 |
cur_state = (surf_statelist *)surf_list[0]; |
| 1354 |
if (cur_state->cgi_inited != CYES) { |
| 1355 |
return; |
| 1356 |
} |
| 1357 |
|
| 1358 |
for (i = 0; i < *(int *)params[1]; i++) { |
| 1359 |
if (strncmp(((char **)params[2])[i], "1-WAY-OUTPUT", 12) != 0 || |
| 1360 |
strncmp(((char **)params[2])[i], "2-WAY-OUTPUT", 12) || |
| 1361 |
strncmp(((char **)params[2])[i], "SLATEC 1", 8) != 0) { |
| 1362 |
((int *)params[4])[i] = CSYES; |
| 1363 |
} |
| 1364 |
else { |
| 1365 |
((int *)params[4])[i] = CSNO; |
| 1366 |
} |
| 1367 |
} |
| 1368 |
/* validity flag */ |
| 1369 |
*(int *)params[3] = CVAL; |
| 1370 |
|
| 1371 |
} /* end xclpr */ |
| 1372 |
|
| 1373 |
/* INQUIRE SUPPORTED PRECISIONS */ |
| 1374 |
static void xcqsp(anything **params, anything **surf_list) |
| 1375 |
{ |
| 1376 |
/* there is only one surface for inquiries */ |
| 1377 |
cur_state = (surf_statelist *)surf_list[0]; |
| 1378 |
if (cur_state->cgi_inited != CYES) { |
| 1379 |
return; |
| 1380 |
} |
| 1381 |
|
| 1382 |
/* this stuff is basically machine dependent. I return INVAL and |
| 1383 |
leave it at that */ |
| 1384 |
*(int *)params[1] = CINVAL; |
| 1385 |
|
| 1386 |
} /* end xcqsp */ |
| 1387 |
|
| 1388 |
/* LOOKUP ESCAPE SUPPORT */ |
| 1389 |
static void xclesc(anything **params, anything **surf_list) |
| 1390 |
{ |
| 1391 |
int i; /* loop index */ |
| 1392 |
int esc = 1400; /* for inquire escape */ |
| 1393 |
int support; /* for inquire escape */ |
| 1394 |
|
| 1395 |
/* there is only one surface for inquiries */ |
| 1396 |
cur_state = (surf_statelist *)surf_list[0]; |
| 1397 |
if (cur_state->cgi_inited != CYES) { |
| 1398 |
return; |
| 1399 |
} |
| 1400 |
|
| 1401 |
for (i = 0; i < *(int *)params[1]; i++) { |
| 1402 |
|
| 1403 |
/* return YES for supported escapes, else return NO */ |
| 1404 |
switch (((int *)params[2])[i]) { |
| 1405 |
case XEMFNM: ((int *)params[4])[i] = CSYES; break; |
| 1406 |
case XEAGMD: ((int *)params[4])[i] = CSYES; break; |
| 1407 |
case XESVDI: ((int *)params[4])[i] = CSYES; break; |
| 1408 |
case XEBELL: ((int *)params[4])[i] = CSYES; break; |
| 1409 |
case XEPGSZ: |
| 1410 |
vdiqes(&esc, &support); |
| 1411 |
if (support == 1 || support == 2) { |
| 1412 |
((int *)params[4])[i] = CSYES; |
| 1413 |
} |
| 1414 |
else { |
| 1415 |
((int *)params[4])[i] = CSNO; |
| 1416 |
} |
| 1417 |
break; |
| 1418 |
|
| 1419 |
default: ((int *)params[4])[i] = CSNO; break; |
| 1420 |
} /* end switch */ |
| 1421 |
} |
| 1422 |
|
| 1423 |
/* validity flag */ |
| 1424 |
*(int *)params[3] = CVAL; |
| 1425 |
|
| 1426 |
} /* end xclesc */ |
| 1427 |
|
| 1428 |
/* INQUIRE CURRENT PRECISIONS */ |
| 1429 |
static void xcqp(anything **params, anything **surf_list) |
| 1430 |
{ |
| 1431 |
/* there is only one surface for inquiries */ |
| 1432 |
cur_state = (surf_statelist *)surf_list[0]; |
| 1433 |
if (cur_state->cgi_inited != CYES) { |
| 1434 |
return; |
| 1435 |
} |
| 1436 |
|
| 1437 |
/* validity flag */ |
| 1438 |
*(int *)params[1] = CINVAL; |
| 1439 |
|
| 1440 |
} /* end xcqp */ |
| 1441 |
|
| 1442 |
/* INQUIRE CLIPPING */ |
| 1443 |
static void xcqcl(anything **params, anything **surf_list) |
| 1444 |
{ |
| 1445 |
/* there is only one surface for inquiries */ |
| 1446 |
cur_state = (surf_statelist *)surf_list[0]; |
| 1447 |
if (cur_state->cgi_inited != CYES) { |
| 1448 |
return; |
| 1449 |
} |
| 1450 |
|
| 1451 |
/* clip indicator */ |
| 1452 |
*(int *)params[2] = cur_state->clip_indicator; |
| 1453 |
|
| 1454 |
/* clip rectangle */ |
| 1455 |
((float *)params[3])[0] = cur_state->clip_rect1.x; |
| 1456 |
((float *)params[3])[1] = cur_state->clip_rect1.y; |
| 1457 |
((float *)params[3])[2] = cur_state->clip_rect2.x; |
| 1458 |
((float *)params[3])[3] = cur_state->clip_rect2.y; |
| 1459 |
|
| 1460 |
/* drawing surface clip indicator */ |
| 1461 |
*(int *)params[4] = cur_state->ds_clip_indicator; |
| 1462 |
|
| 1463 |
/* drawing surface clip rectangle */ |
| 1464 |
/* Default is the whole drawing surface; routines to change the |
| 1465 |
* drawing surface clip rectangle are not included. Since veiwport |
| 1466 |
* specification mode is FRACTION OF DRAWING SURFACE, units for |
| 1467 |
* rectangle are 0 - 1 */ |
| 1468 |
((float *)params[5])[0] = 0.; |
| 1469 |
((float *)params[5])[1] = 0.; |
| 1470 |
((float *)params[5])[2] = 1.; |
| 1471 |
((float *)params[5])[3] = 1.; |
| 1472 |
|
| 1473 |
/* validity flag */ |
| 1474 |
*(int *)params[1] = CVAL; |
| 1475 |
|
| 1476 |
} /* end xcqcl */ |
| 1477 |
|
| 1478 |
/* POLYLINE */ |
| 1479 |
static void xcpl(anything **params, int num_surfaces, anything **surf_list) |
| 1480 |
{ |
| 1481 |
int i, j; /* indices for loops */ |
| 1482 |
int np; /* number of points in polyline */ |
| 1483 |
float prev_x, prev_y; /* line end points */ |
| 1484 |
float cur_x, cur_y; /* line end points */ |
| 1485 |
float save_x, save_y; /* used for clipping */ |
| 1486 |
int prev_code, cur_code; /* encoded endpoints - for clipping */ |
| 1487 |
int mode = 0, done; /* stuff used for clipping */ |
| 1488 |
static unsigned mask = ~(~0u << 1); /* for masking off bits */ |
| 1489 |
|
| 1490 |
for (i = 0; i < num_surfaces; ++i) { |
| 1491 |
|
| 1492 |
cur_state = (surf_statelist *)surf_list[i]; |
| 1493 |
if (cur_state->cgi_inited != CYES) { |
| 1494 |
break; |
| 1495 |
} |
| 1496 |
|
| 1497 |
/* do some error checking */ |
| 1498 |
if (MAX_POLYLINE != -1 && *(int *)params[1] > MAX_POLYLINE) { |
| 1499 |
/* error 6:301 - Number of points too large. Max is used */ |
| 1500 |
report_error(cur_state, 6, 301, *(short *)params[0]); |
| 1501 |
np = MAX_POLYLINE; |
| 1502 |
} |
| 1503 |
else { |
| 1504 |
np = *(int *)params[1]; |
| 1505 |
} |
| 1506 |
|
| 1507 |
/* set SVDI foreground color if needed */ |
| 1508 |
set_foreground_color(cur_state, cur_state->line_color); |
| 1509 |
|
| 1510 |
/* take a short cut if no clipping is on */ |
| 1511 |
if (!cur_state->clip_on) { |
| 1512 |
for (j = 0; j < np; j++) { |
| 1513 |
|
| 1514 |
/* map VDC to NDC */ |
| 1515 |
cur_x = *((float *)params[2] + j) * cur_state->xscale + cur_state->xoffset; |
| 1516 |
cur_y = *((float *)params[3] + j) * cur_state->yscale + cur_state->yoffset; |
| 1517 |
if (j == 0) { |
| 1518 |
vdmova(&cur_x, &cur_y); |
| 1519 |
} |
| 1520 |
else { |
| 1521 |
vdlina(&cur_x, &cur_y); |
| 1522 |
} |
| 1523 |
} /* end for j */ |
| 1524 |
} /* end no clipping on */ |
| 1525 |
|
| 1526 |
else { /* clipping is on */ |
| 1527 |
|
| 1528 |
/* This clipping algorithm is loosely based on the Cohen- |
| 1529 |
* Sutherland algorithm. This algorithm takes into account |
| 1530 |
* the fact that points are consecutive, ie., it tries to |
| 1531 |
* encode each point only once. Everything is done |
| 1532 |
* inline for efficiency |
| 1533 |
*/ |
| 1534 |
|
| 1535 |
/* convert VDC to NDC */ |
| 1536 |
prev_x = *((float *)params[2]) * cur_state->xscale + cur_state->xoffset; |
| 1537 |
prev_y = *((float *)params[3]) * cur_state->yscale + cur_state->yoffset; |
| 1538 |
|
| 1539 |
/* encode the point */ |
| 1540 |
prev_code = 0; |
| 1541 |
if ((cur_state->clipmax.y - prev_y) < 0) { |
| 1542 |
prev_code = prev_code | (1 << 3); |
| 1543 |
} |
| 1544 |
else if ((prev_y - cur_state->clipmin.y) < 0) { |
| 1545 |
prev_code = prev_code | (1 << 2); |
| 1546 |
} |
| 1547 |
|
| 1548 |
if ((cur_state->clipmax.x - prev_x) < 0) { |
| 1549 |
prev_code = prev_code | (1 << 1); |
| 1550 |
} |
| 1551 |
else if ((prev_x - cur_state->clipmin.x) < 0) { |
| 1552 |
prev_code = prev_code | (1 << 0); |
| 1553 |
} |
| 1554 |
|
| 1555 |
if (!prev_code) { |
| 1556 |
vdmova(&prev_x, &prev_y); |
| 1557 |
} |
| 1558 |
|
| 1559 |
j = 0; |
| 1560 |
while (++j < np) { |
| 1561 |
|
| 1562 |
/* convert VDC to NDC */ |
| 1563 |
cur_x = *((float *)params[2] + j) * cur_state->xscale + cur_state->xoffset; |
| 1564 |
cur_y = *((float *)params[3] + j) * cur_state->yscale + cur_state->yoffset; |
| 1565 |
|
| 1566 |
/* encode the endpoint */ |
| 1567 |
cur_code = 0; |
| 1568 |
if ((cur_state->clipmax.y - cur_y) < 0) { |
| 1569 |
cur_code = cur_code | (1 << 3); |
| 1570 |
} |
| 1571 |
else if ((cur_y - cur_state->clipmin.y) < 0) { |
| 1572 |
cur_code = cur_code | (1 << 2); |
| 1573 |
} |
| 1574 |
|
| 1575 |
if ((cur_state->clipmax.x - cur_x) < 0) { |
| 1576 |
cur_code = cur_code | (1 << 1); |
| 1577 |
} |
| 1578 |
else if ((cur_x - cur_state->clipmin.x) < 0) { |
| 1579 |
cur_code = cur_code | (1 << 0); |
| 1580 |
} |
| 1581 |
|
| 1582 |
/* determine which case this is */ |
| 1583 |
if (!prev_code && !cur_code) { /* trivial accept */ |
| 1584 |
vdlina(&cur_x, &cur_y); |
| 1585 |
prev_x = cur_x; |
| 1586 |
prev_y = cur_y; |
| 1587 |
done = TRUE; |
| 1588 |
} /* end trivial accept */ |
| 1589 |
|
| 1590 |
else if (prev_code & cur_code) { /* trivial reject */ |
| 1591 |
prev_x = cur_x; |
| 1592 |
prev_y = cur_y; |
| 1593 |
prev_code = cur_code; |
| 1594 |
done = TRUE; |
| 1595 |
} |
| 1596 |
|
| 1597 |
else { |
| 1598 |
done = FALSE; |
| 1599 |
if (prev_code) { |
| 1600 |
if (cur_code) { |
| 1601 |
mode = 2; /* both out */ |
| 1602 |
} |
| 1603 |
else { |
| 1604 |
mode = 1; /* prev out; cur in */ |
| 1605 |
} |
| 1606 |
} |
| 1607 |
else { |
| 1608 |
mode = 3; /* prev in; cur out */ |
| 1609 |
} |
| 1610 |
} |
| 1611 |
|
| 1612 |
while (!done) { |
| 1613 |
|
| 1614 |
switch (mode) { |
| 1615 |
|
| 1616 |
case 1: /* prev out, cur in... clip */ |
| 1617 |
case 2: /* both out, clip prev first */ |
| 1618 |
|
| 1619 |
if (prev_code & mask) { /* clip at left edge */ |
| 1620 |
prev_y = |
| 1621 |
prev_y + (cur_y - prev_y) * (cur_state->clipmin.x - prev_x) / (cur_x - prev_x); |
| 1622 |
prev_x = cur_state->clipmin.x; |
| 1623 |
} |
| 1624 |
else if ((prev_code >> 1) & mask) { /* clip at right edge */ |
| 1625 |
prev_y = |
| 1626 |
prev_y + (cur_y - prev_y) * (cur_state->clipmax.x - prev_x) / (cur_x - prev_x); |
| 1627 |
prev_x = cur_state->clipmax.x; |
| 1628 |
} |
| 1629 |
|
| 1630 |
if ((prev_code >> 2) & mask) { /* clip at bottom edge */ |
| 1631 |
prev_x = |
| 1632 |
prev_x + (cur_x - prev_x) * (cur_state->clipmin.y - prev_y) / (cur_y - prev_y); |
| 1633 |
prev_y = cur_state->clipmin.y; |
| 1634 |
} |
| 1635 |
else if ((prev_code >> 3) & mask) { /* clip at top edge */ |
| 1636 |
prev_x = |
| 1637 |
prev_x + (cur_x - prev_x) * (cur_state->clipmax.y - prev_y) / (cur_y - prev_y); |
| 1638 |
prev_y = cur_state->clipmax.y; |
| 1639 |
} |
| 1640 |
|
| 1641 |
switch (mode) { |
| 1642 |
case 1: /* not looping through, draw it */ |
| 1643 |
vdmova(&prev_x, &prev_y); |
| 1644 |
vdlina(&cur_x, &cur_y); |
| 1645 |
prev_x = cur_x; |
| 1646 |
prev_y = cur_y; |
| 1647 |
prev_code = cur_code; |
| 1648 |
done = TRUE; |
| 1649 |
break; |
| 1650 |
|
| 1651 |
case 2: /* both were out, encode new point */ |
| 1652 |
prev_code = 0; |
| 1653 |
if ((cur_state->clipmax.y - prev_y) < 0) { |
| 1654 |
prev_code = prev_code | (1 << 3); |
| 1655 |
} |
| 1656 |
else if ((prev_y - cur_state->clipmin.y) < 0) { |
| 1657 |
prev_code = prev_code | (1 << 2); |
| 1658 |
} |
| 1659 |
|
| 1660 |
if ((cur_state->clipmax.x - prev_x) < 0) { |
| 1661 |
prev_code = prev_code | (1 << 1); |
| 1662 |
} |
| 1663 |
else if ((prev_x - cur_state->clipmin.x) < 0) { |
| 1664 |
prev_code = prev_code | (1 << 0); |
| 1665 |
} |
| 1666 |
|
| 1667 |
if (prev_code) { /* reject it */ |
| 1668 |
prev_x = cur_x; |
| 1669 |
prev_y = cur_y; |
| 1670 |
prev_code = cur_code; |
| 1671 |
done = TRUE; |
| 1672 |
} |
| 1673 |
else { /* prev is in */ |
| 1674 |
vdmova(&prev_x, &prev_y); |
| 1675 |
mode = 3; /* cur is still out, go through again */ |
| 1676 |
} |
| 1677 |
break; |
| 1678 |
} /* end inner switch */ |
| 1679 |
break; |
| 1680 |
|
| 1681 |
case 3: /* prev in, cur out...clip */ |
| 1682 |
save_x = cur_x; |
| 1683 |
save_y = cur_y; |
| 1684 |
|
| 1685 |
if (cur_code & mask) { /* clip at left edge */ |
| 1686 |
cur_y = cur_y + (prev_y - cur_y) * (cur_state->clipmin.x - cur_x) / (prev_x - cur_x); |
| 1687 |
cur_x = cur_state->clipmin.x; |
| 1688 |
} |
| 1689 |
else if ((cur_code >> 1) & mask) { /* clip at right edge */ |
| 1690 |
cur_y = cur_y + (prev_y - cur_y) * (cur_state->clipmax.x - cur_x) / (prev_x - cur_x); |
| 1691 |
cur_x = cur_state->clipmax.x; |
| 1692 |
} |
| 1693 |
|
| 1694 |
if ((cur_code >> 2) & mask) { /* clip at bottom edge */ |
| 1695 |
cur_x = cur_x + (prev_x - cur_x) * (cur_state->clipmin.y - cur_y) / (prev_y - cur_y); |
| 1696 |
cur_y = cur_state->clipmin.y; |
| 1697 |
} |
| 1698 |
else if ((cur_code >> 3) & mask) { /* clip at top edge */ |
| 1699 |
cur_x = cur_x + (prev_x - cur_x) * (cur_state->clipmax.y - cur_y) / (prev_y - cur_y); |
| 1700 |
cur_y = cur_state->clipmax.y; |
| 1701 |
} |
| 1702 |
|
| 1703 |
vdlina(&cur_x, &cur_y); |
| 1704 |
prev_x = save_x; |
| 1705 |
prev_y = save_y; |
| 1706 |
prev_code = cur_code; |
| 1707 |
done = TRUE; |
| 1708 |
break; |
| 1709 |
|
| 1710 |
default: done = TRUE; break; |
| 1711 |
} /* end switch */ |
| 1712 |
} /* end while !done */ |
| 1713 |
} /* end while j*/ |
| 1714 |
|
| 1715 |
} /* end else clipping is on */ |
| 1716 |
|
| 1717 |
/* flag that the page has been marked */ |
| 1718 |
cur_state->pic_dirty = CDIRTY; |
| 1719 |
|
| 1720 |
} /* end for i */ |
| 1721 |
} /* end xcpl */ |
| 1722 |
|
| 1723 |
/* DISJOINT POLYLINE */ |
| 1724 |
static void xcdjpl(anything **params, int num_surfaces, anything **surf_list) |
| 1725 |
{ |
| 1726 |
int i, j; /* indices for loops */ |
| 1727 |
int np; /* number of points in polyline */ |
| 1728 |
float x1, y1, x2, y2; /* line endpoints in NDC */ |
| 1729 |
int code1, code2; /* encoded endpoints for clipping */ |
| 1730 |
int mode = 0, done; /* variables used for clipping */ |
| 1731 |
static unsigned mask = ~(~0u << 1); /* for masking off bits */ |
| 1732 |
|
| 1733 |
for (i = 0; i < num_surfaces; ++i) { |
| 1734 |
|
| 1735 |
cur_state = (surf_statelist *)surf_list[i]; |
| 1736 |
if (cur_state->cgi_inited != CYES) { |
| 1737 |
break; |
| 1738 |
} |
| 1739 |
|
| 1740 |
/* check for errors */ |
| 1741 |
if (MAX_DJ_POLYLINE != -1 && *(int *)params[1] > MAX_DJ_POLYLINE) { |
| 1742 |
/* error 6:301 - Number of points too large. Max is used */ |
| 1743 |
report_error(cur_state, 6, 301, *(short *)params[0]); |
| 1744 |
np = MAX_DJ_POLYLINE; |
| 1745 |
} |
| 1746 |
else { |
| 1747 |
np = *(int *)params[1]; |
| 1748 |
} |
| 1749 |
|
| 1750 |
/* set SVDI foreground color if needed */ |
| 1751 |
set_foreground_color(cur_state, cur_state->line_color); |
| 1752 |
|
| 1753 |
/* if clipping is off, just do it */ |
| 1754 |
if (!cur_state->clip_on) { |
| 1755 |
|
| 1756 |
for (j = 0; j < np - 1; j = j + 2) { |
| 1757 |
|
| 1758 |
/* map VDC to NDC */ |
| 1759 |
x1 = *((float *)params[2] + j) * cur_state->xscale + cur_state->xoffset; |
| 1760 |
y1 = *((float *)params[3] + j) * cur_state->yscale + cur_state->yoffset; |
| 1761 |
x2 = *((float *)params[2] + j + 1) * cur_state->xscale + cur_state->xoffset; |
| 1762 |
y2 = *((float *)params[3] + j + 1) * cur_state->yscale + cur_state->yoffset; |
| 1763 |
|
| 1764 |
vdmova(&x1, &y1); |
| 1765 |
vdlina(&x2, &y2); |
| 1766 |
|
| 1767 |
} /* end for j */ |
| 1768 |
} /* end if clipping is off */ |
| 1769 |
|
| 1770 |
else { /* clipping is on */ |
| 1771 |
|
| 1772 |
/* Clip a line. Kind of based on Cohen-Sutherland algorithm. |
| 1773 |
* Everything is done inline for efficiency. |
| 1774 |
*/ |
| 1775 |
|
| 1776 |
for (j = 0; j < np - 1; j = j + 2) { |
| 1777 |
|
| 1778 |
/* map VDC to NDC */ |
| 1779 |
x1 = *((float *)params[2] + j) * cur_state->xscale + cur_state->xoffset; |
| 1780 |
y1 = *((float *)params[3] + j) * cur_state->yscale + cur_state->yoffset; |
| 1781 |
x2 = *((float *)params[2] + j + 1) * cur_state->xscale + cur_state->xoffset; |
| 1782 |
y2 = *((float *)params[3] + j + 1) * cur_state->yscale + cur_state->yoffset; |
| 1783 |
|
| 1784 |
/* encode the two points */ |
| 1785 |
code1 = 0; |
| 1786 |
if ((cur_state->clipmax.y - y1) < 0) { |
| 1787 |
code1 = code1 | (1 << 3); |
| 1788 |
} |
| 1789 |
else if ((y1 - cur_state->clipmin.y) < 0) { |
| 1790 |
code1 = code1 | (1 << 2); |
| 1791 |
} |
| 1792 |
|
| 1793 |
if ((cur_state->clipmax.x - x1) < 0) { |
| 1794 |
code1 = code1 | (1 << 1); |
| 1795 |
} |
| 1796 |
else if ((x1 - cur_state->clipmin.x) < 0) { |
| 1797 |
code1 = code1 | (1 << 0); |
| 1798 |
} |
| 1799 |
|
| 1800 |
code2 = 0; |
| 1801 |
if ((cur_state->clipmax.y - y2) < 0) { |
| 1802 |
code2 = code2 | (1 << 3); |
| 1803 |
} |
| 1804 |
else if ((y2 - cur_state->clipmin.y) < 0) { |
| 1805 |
code2 = code2 | (1 << 2); |
| 1806 |
} |
| 1807 |
|
| 1808 |
if ((cur_state->clipmax.x - x2) < 0) { |
| 1809 |
code2 = code2 | (1 << 1); |
| 1810 |
} |
| 1811 |
else if ((x2 - cur_state->clipmin.x) < 0) { |
| 1812 |
code2 = code2 | (1 << 0); |
| 1813 |
} |
| 1814 |
|
| 1815 |
/* determine which case this is */ |
| 1816 |
if (!code1 && !code2) { /* trivial accept - draw it */ |
| 1817 |
vdmova(&x1, &y1); |
| 1818 |
vdlina(&x2, &y2); |
| 1819 |
done = TRUE; |
| 1820 |
} /* end trivial accept */ |
| 1821 |
|
| 1822 |
else if (code1 & code2) { /* trivial reject - do nothing */ |
| 1823 |
done = TRUE; |
| 1824 |
} |
| 1825 |
else { |
| 1826 |
done = FALSE; |
| 1827 |
if (code1) { |
| 1828 |
if (code2) { |
| 1829 |
mode = 2; /* both out */ |
| 1830 |
} |
| 1831 |
else { |
| 1832 |
mode = 1; /* x1,y1 out; x2,y2 in */ |
| 1833 |
} |
| 1834 |
} |
| 1835 |
else { |
| 1836 |
mode = 3; /* x1,y1 in; x2,y2 out */ |
| 1837 |
} |
| 1838 |
} |
| 1839 |
|
| 1840 |
while (!done) { |
| 1841 |
|
| 1842 |
switch (mode) { |
| 1843 |
|
| 1844 |
case 1: /* x1,y1 out, x2,y2 in... clip x1,y1*/ |
| 1845 |
case 2: /* both out, clip x1,y1 first */ |
| 1846 |
|
| 1847 |
if (code1 & mask) { /* clip at left edge */ |
| 1848 |
y1 = y1 + (y2 - y1) * (cur_state->clipmin.x - x1) / (x2 - x1); |
| 1849 |
x1 = cur_state->clipmin.x; |
| 1850 |
} |
| 1851 |
else if ((code1 >> 1) & mask) { /* clip at right edge */ |
| 1852 |
y1 = y1 + (y2 - y1) * (cur_state->clipmax.x - x1) / (x2 - x1); |
| 1853 |
x1 = cur_state->clipmax.x; |
| 1854 |
} |
| 1855 |
|
| 1856 |
if ((code1 >> 2) & mask) { /* clip at bottom edge */ |
| 1857 |
x1 = x1 + (x2 - x1) * (cur_state->clipmin.y - y1) / (y2 - y1); |
| 1858 |
y1 = cur_state->clipmin.y; |
| 1859 |
} |
| 1860 |
else if ((code1 >> 3) & mask) { /* clip at top edge */ |
| 1861 |
x1 = x1 + (x2 - x1) * (cur_state->clipmax.y - y1) / (y2 - y1); |
| 1862 |
y1 = cur_state->clipmax.y; |
| 1863 |
} |
| 1864 |
|
| 1865 |
switch (mode) { |
| 1866 |
case 1: /* not looping through, draw it */ |
| 1867 |
vdmova(&x1, &y1); |
| 1868 |
vdlina(&x2, &y2); |
| 1869 |
done = TRUE; |
| 1870 |
break; |
| 1871 |
|
| 1872 |
case 2: /* both were out, encode new point */ |
| 1873 |
code1 = 0; |
| 1874 |
if ((cur_state->clipmax.y - y1) < 0) { |
| 1875 |
code1 = code1 | (1 << 3); |
| 1876 |
} |
| 1877 |
else if ((y1 - cur_state->clipmin.y) < 0) { |
| 1878 |
code1 = code1 | (1 << 2); |
| 1879 |
} |
| 1880 |
|
| 1881 |
if ((cur_state->clipmax.x - x1) < 0) { |
| 1882 |
code1 = code1 | (1 << 1); |
| 1883 |
} |
| 1884 |
else if ((x1 - cur_state->clipmin.x) < 0) { |
| 1885 |
code1 = code1 | (1 << 0); |
| 1886 |
} |
| 1887 |
|
| 1888 |
if (code1) { |
| 1889 |
done = TRUE; /* new point is out, reject */ |
| 1890 |
} |
| 1891 |
else { |
| 1892 |
mode = 3; /* x1,y1 in; x2,y2 out; clip x2,y2 */ |
| 1893 |
} |
| 1894 |
break; |
| 1895 |
|
| 1896 |
} /* end inner switch */ |
| 1897 |
|
| 1898 |
break; |
| 1899 |
|
| 1900 |
case 3: /* x1,y1 in, x2,y2 out...clip */ |
| 1901 |
|
| 1902 |
if (code2 & mask) { /* clip at left edge */ |
| 1903 |
y2 = y2 + (y1 - y2) * (cur_state->clipmin.x - x2) / (x1 - x2); |
| 1904 |
x2 = cur_state->clipmin.x; |
| 1905 |
} |
| 1906 |
else if ((code2 >> 1) & mask) { /* clip at right edge */ |
| 1907 |
y2 = y2 + (y1 - y2) * (cur_state->clipmax.x - x2) / (x1 - x2); |
| 1908 |
x2 = cur_state->clipmax.x; |
| 1909 |
} |
| 1910 |
|
| 1911 |
if ((code2 >> 2) & mask) { /* clip at bottom edge */ |
| 1912 |
x2 = x2 + (x1 - x2) * (cur_state->clipmin.y - y2) / (y1 - y2); |
| 1913 |
y2 = cur_state->clipmin.y; |
| 1914 |
} |
| 1915 |
|
| 1916 |
else if ((code2 >> 3) & mask) { /* clip at top edge */ |
| 1917 |
x2 = x2 + (x1 - x2) * (cur_state->clipmax.y - y2) / (y1 - y2); |
| 1918 |
y2 = cur_state->clipmax.y; |
| 1919 |
} |
| 1920 |
|
| 1921 |
vdmova(&x1, &y1); |
| 1922 |
vdlina(&x2, &y2); |
| 1923 |
done = TRUE; |
| 1924 |
break; |
| 1925 |
|
| 1926 |
default: done = TRUE; break; |
| 1927 |
|
| 1928 |
} /* end switch */ |
| 1929 |
} /* end while !done */ |
| 1930 |
} /* end for j */ |
| 1931 |
} /* end else clipping is on */ |
| 1932 |
|
| 1933 |
/* flag that the page has been marked */ |
| 1934 |
cur_state->pic_dirty = CDIRTY; |
| 1935 |
|
| 1936 |
} /* end for i */ |
| 1937 |
} /* end xcdjpl */ |
| 1938 |
|
| 1939 |
/* POLYMARKER */ |
| 1940 |
static void xcpm(anything **params, int num_surfaces, anything **surf_list) |
| 1941 |
{ |
| 1942 |
int i, j; /* indices for loops */ |
| 1943 |
int np; /* number of points */ |
| 1944 |
float *x, *y; /* x,y values */ |
| 1945 |
float x_vdi, y_vdi; /* x,y values in NDC */ |
| 1946 |
int ok; /* flag TRUE =mark lies in clip region */ |
| 1947 |
|
| 1948 |
for (i = 0; i < num_surfaces; ++i) { |
| 1949 |
|
| 1950 |
np = *(int *)params[1]; |
| 1951 |
x = (float *)params[2]; |
| 1952 |
y = (float *)params[3]; |
| 1953 |
|
| 1954 |
cur_state = (surf_statelist *)surf_list[i]; |
| 1955 |
if (cur_state->cgi_inited != CYES) { |
| 1956 |
break; |
| 1957 |
} |
| 1958 |
|
| 1959 |
/* check for errors */ |
| 1960 |
if (MAX_POLYMARKER != -1 && *(int *)params[1] > MAX_POLYMARKER) { |
| 1961 |
/* error 6:301 - Number of points too large. Max is used */ |
| 1962 |
report_error(cur_state, 6, 301, *(short *)params[0]); |
| 1963 |
np = MAX_POLYMARKER; |
| 1964 |
} |
| 1965 |
else { |
| 1966 |
np = *(int *)params[1]; |
| 1967 |
} |
| 1968 |
|
| 1969 |
/* set SVDI foreground color if needed */ |
| 1970 |
set_foreground_color(cur_state, cur_state->mark_color); |
| 1971 |
|
| 1972 |
/* set marker type */ |
| 1973 |
/* --only support "dot" for now - so nothing to set */ |
| 1974 |
|
| 1975 |
/* set marker size */ |
| 1976 |
/* --only support "dot" for now - so nothing to set */ |
| 1977 |
|
| 1978 |
for (j = 0; j < np; j++) { |
| 1979 |
|
| 1980 |
/* map VDC to NDC */ |
| 1981 |
x_vdi = x[j] * cur_state->xscale + cur_state->xoffset; |
| 1982 |
y_vdi = y[j] * cur_state->yscale + cur_state->yoffset; |
| 1983 |
|
| 1984 |
ok = TRUE; |
| 1985 |
if (cur_state->clip_on) { /* clip is on */ |
| 1986 |
/* ...clip the whole polymarker - it's in or it's out */ |
| 1987 |
ok = ((x_vdi <= cur_state->clipmax.x && x_vdi >= cur_state->clipmin.x) && |
| 1988 |
(y_vdi <= cur_state->clipmax.y && y_vdi >= cur_state->clipmin.y)); |
| 1989 |
} |
| 1990 |
|
| 1991 |
if (ok) { |
| 1992 |
vdpnta(&x_vdi, &y_vdi); |
| 1993 |
} |
| 1994 |
|
| 1995 |
} /* end for j */ |
| 1996 |
|
| 1997 |
/* flag that the page has been marked */ |
| 1998 |
cur_state->pic_dirty = CDIRTY; |
| 1999 |
|
| 2000 |
} /* end for i */ |
| 2001 |
} /* end xcpm */ |
| 2002 |
|
| 2003 |
/* TEXT */ |
| 2004 |
static void xctx(anything **params, int num_surfaces, anything **surf_list) |
| 2005 |
{ |
| 2006 |
int i, j; /* indices for loops */ |
| 2007 |
float x, y; /* x,y starting position */ |
| 2008 |
char *ch; /* input character string */ |
| 2009 |
char c; /* 1 character */ |
| 2010 |
int np; /* number of chars in text string */ |
| 2011 |
int ich[MAX_TEXT_LENGTH]; /* array of ascii chars to pass SVDI */ |
| 2012 |
int ok; /* flag TRUE =line lies in clip region */ |
| 2013 |
float temp_array[14]; /* used for SVDI inquiries */ |
| 2014 |
float char_height; /* char height, in VDC or NDC */ |
| 2015 |
float char_width; /* char width, in VDC or NDC */ |
| 2016 |
int skip; /* nbr of chars to skip when clipping */ |
| 2017 |
|
| 2018 |
for (i = 0; i < num_surfaces; ++i) { |
| 2019 |
|
| 2020 |
cur_state = (surf_statelist *)surf_list[i]; |
| 2021 |
if (cur_state->cgi_inited != CYES) { |
| 2022 |
break; |
| 2023 |
} |
| 2024 |
|
| 2025 |
/* error checking */ |
| 2026 |
if (*(int *)params[3] != CFINAL) { |
| 2027 |
/* compound text not supported */ |
| 2028 |
/* error 2:001 - Request for unsupported feature. Function ignored */ |
| 2029 |
report_error(cur_state, 2, 001, *(short *)params[0]); |
| 2030 |
break; |
| 2031 |
} |
| 2032 |
/* params[5] is an added parameter which is length of string */ |
| 2033 |
else if (MAX_TEXT_LENGTH != -1 && *(int *)params[5] > MAX_TEXT_LENGTH) { |
| 2034 |
/* error 6:301 - Number of points too large. Max is used */ |
| 2035 |
report_error(cur_state, 6, 301, *(short *)params[0]); |
| 2036 |
np = MAX_TEXT_LENGTH; |
| 2037 |
} |
| 2038 |
else { |
| 2039 |
np = *(int *)params[5]; |
| 2040 |
} |
| 2041 |
|
| 2042 |
/* if there is nothing to draw, break */ |
| 2043 |
if (np <= 0) { |
| 2044 |
break; |
| 2045 |
} |
| 2046 |
|
| 2047 |
/* set SVDI foreground color if needed */ |
| 2048 |
set_foreground_color(cur_state, cur_state->text_color); |
| 2049 |
|
| 2050 |
/* find out what the SVDI character height/width is */ |
| 2051 |
vdiqos(&temp_array[1]); |
| 2052 |
|
| 2053 |
/* convert stuff to NDC */ |
| 2054 |
char_width = temp_array[7]; |
| 2055 |
char_height = temp_array[6]; |
| 2056 |
/* map VDC to NDC */ |
| 2057 |
x = *(float *)params[1] * cur_state->xscale + cur_state->xoffset; |
| 2058 |
y = *(float *)params[2] * cur_state->yscale + cur_state->yoffset; |
| 2059 |
|
| 2060 |
ok = TRUE; |
| 2061 |
skip = 0; |
| 2062 |
|
| 2063 |
/* this text clipping assumes no backspaces, etc.,and only the |
| 2064 |
* default character orientation. |
| 2065 |
*/ |
| 2066 |
if (cur_state->clip_on) { /* clipping is on, do it */ |
| 2067 |
|
| 2068 |
/* if the string doesn't fit in y, reject it */ |
| 2069 |
ok = (y >= cur_state->clipmin.y && (y + char_height) <= cur_state->clipmax.y); |
| 2070 |
|
| 2071 |
if (ok) { /* ok in y, check it in x */ |
| 2072 |
|
| 2073 |
/* check for trivial reject */ |
| 2074 |
ok = (x < cur_state->clipmax.x && (x + (np * char_width)) > cur_state->clipmin.x); |
| 2075 |
|
| 2076 |
if (ok) { /* it's in there, clip it */ |
| 2077 |
|
| 2078 |
/* clip to left edge */ |
| 2079 |
if (x < cur_state->clipmin.x) { |
| 2080 |
|
| 2081 |
/* ...compute how many chars to skip */ |
| 2082 |
skip = ceil((cur_state->clipmin.x - x) / char_width); |
| 2083 |
/* ...compute new x */ |
| 2084 |
x = x + ((float)skip * char_width); |
| 2085 |
/* ...compute new number of chars */ |
| 2086 |
np = np - skip; |
| 2087 |
} |
| 2088 |
|
| 2089 |
/* clip to right edge */ |
| 2090 |
if (x + (np * char_width) > cur_state->clipmax.x) { |
| 2091 |
|
| 2092 |
/* ...compute how many chars fit */ |
| 2093 |
np = (int)((cur_state->clipmax.x - x) / char_width); |
| 2094 |
} |
| 2095 |
} /* end if ok in x */ |
| 2096 |
} /* end if ok in y */ |
| 2097 |
} /* end if clip_on */ |
| 2098 |
|
| 2099 |
ok = ok && np > 0; /* make sure there is still some text left */ |
| 2100 |
|
| 2101 |
if (ok) { /* everything is still ok */ |
| 2102 |
|
| 2103 |
/* move to position, and draw the text */ |
| 2104 |
vdmova(&x, &y); |
| 2105 |
|
| 2106 |
ch = &(((char *)params[4])[skip]); |
| 2107 |
for (j = 0; j < np; j++) { |
| 2108 |
c = *ch++; |
| 2109 |
/* this works for ASCII machines */ |
| 2110 |
ich[j] = (int)c; |
| 2111 |
} |
| 2112 |
vdtext(&j, ich); |
| 2113 |
|
| 2114 |
} /* end if ok */ |
| 2115 |
|
| 2116 |
} /* end for each surface */ |
| 2117 |
} /* end xctx */ |
| 2118 |
|
| 2119 |
/* POLYGON */ |
| 2120 |
static void xcpg(anything **params, int num_surfaces, anything **surf_list) |
| 2121 |
{ |
| 2122 |
int i, j; /* indices for loops */ |
| 2123 |
int np; /* number of points */ |
| 2124 |
float *x, *y; /* x,y VDC values */ |
| 2125 |
float xnew[MAX_POLYGON]; /* clipped x,y values (VDC or NDC) */ |
| 2126 |
float ynew[MAX_POLYGON]; |
| 2127 |
int npnew; /* number of points after clip */ |
| 2128 |
float temp_array[14]; /* temp used for SVDI inquire */ |
| 2129 |
int qdc_index; /* for inquire SVDI */ |
| 2130 |
int vdi_ls; /* SVDI linestyle */ |
| 2131 |
int ok; /* flag TRUE =line lies in clip region */ |
| 2132 |
static float poly_support = -1.; /* save whether SVDI does polygons */ |
| 2133 |
static float vdi_polymax = -1.; /* store SVDI polygon max value */ |
| 2134 |
|
| 2135 |
/* find out SVDI support for polygons. */ |
| 2136 |
if (poly_support == -1.0f) { |
| 2137 |
qdc_index = 24; |
| 2138 |
vdiqdc(&qdc_index, &poly_support); |
| 2139 |
} |
| 2140 |
|
| 2141 |
/* get and store max polygon points from SVDI */ |
| 2142 |
if (vdi_polymax == -1.0f) { |
| 2143 |
qdc_index = 25; |
| 2144 |
vdiqdc(&qdc_index, &vdi_polymax); |
| 2145 |
} |
| 2146 |
|
| 2147 |
for (i = 0; i < num_surfaces; ++i) { |
| 2148 |
|
| 2149 |
cur_state = (surf_statelist *)surf_list[i]; |
| 2150 |
if (cur_state->cgi_inited != CYES) { |
| 2151 |
break; |
| 2152 |
} |
| 2153 |
|
| 2154 |
/* error checking */ |
| 2155 |
if (MAX_POLYGON != -1 && (*(int *)params[1] > MAX_POLYGON || *(int *)params[1] > vdi_polymax)) { |
| 2156 |
/* error 6:302 - Number of points in polygon too large. Max used */ |
| 2157 |
report_error(cur_state, 6, 302, *(short *)params[0]); |
| 2158 |
np = (MAX_POLYGON < vdi_polymax) ? MAX_POLYGON : vdi_polymax; |
| 2159 |
} |
| 2160 |
else { |
| 2161 |
np = *(int *)params[1]; |
| 2162 |
} |
| 2163 |
|
| 2164 |
x = (float *)params[2]; |
| 2165 |
y = (float *)params[3]; |
| 2166 |
|
| 2167 |
/* set SVDI foreground color if needed */ |
| 2168 |
set_foreground_color(cur_state, cur_state->fill_color); |
| 2169 |
|
| 2170 |
/* map VDC to NDC */ |
| 2171 |
for (j = 0; j < np; j++) { |
| 2172 |
|
| 2173 |
xnew[j] = *x++ * cur_state->xscale + cur_state->xoffset; |
| 2174 |
ynew[j] = *y++ * cur_state->yscale + cur_state->yoffset; |
| 2175 |
|
| 2176 |
} /* end for j */ |
| 2177 |
|
| 2178 |
ok = TRUE; |
| 2179 |
if (cur_state->clip_on) { /* clip is on */ |
| 2180 |
|
| 2181 |
/* poly clip returns new x,y values and a count */ |
| 2182 |
/* this routine should be done inline for efficiency */ |
| 2183 |
ok = poly_clip(&cur_state->clipmin, &cur_state->clipmax, xnew, ynew, np, xnew, ynew, &npnew); |
| 2184 |
} |
| 2185 |
else { /* no clpping */ |
| 2186 |
npnew = np; |
| 2187 |
} |
| 2188 |
|
| 2189 |
if (ok) { /* everything's ok, do the polygon */ |
| 2190 |
|
| 2191 |
/* if hollow or if no polygon support, draw the border lines. |
| 2192 |
if solid, call vdpoly */ |
| 2193 |
if ((cur_state->interior_style == CHOLLO) || /* hallow OR */ |
| 2194 |
(poly_support < 3.0f)) { /*no poly supp */ |
| 2195 |
|
| 2196 |
vdiqos(&temp_array[1]); /* make sure line style is solid */ |
| 2197 |
if (temp_array[4] != 0) { |
| 2198 |
vdi_ls = 0; |
| 2199 |
vdstls(&vdi_ls); |
| 2200 |
} |
| 2201 |
|
| 2202 |
vdmova(&xnew[0], &ynew[0]); |
| 2203 |
for (j = 1; j < npnew; j++) { |
| 2204 |
vdlina(&xnew[j], &ynew[j]); |
| 2205 |
} |
| 2206 |
vdlina(&xnew[0], &ynew[0]); |
| 2207 |
if (temp_array[4] != 0) { /* set line style back */ |
| 2208 |
vdi_ls = (int)temp_array[4]; |
| 2209 |
vdstls(&vdi_ls); |
| 2210 |
} |
| 2211 |
} /* end if hollow OR no poly support */ |
| 2212 |
else { /* solid polygon */ |
| 2213 |
vdpoly(xnew, ynew, &npnew); |
| 2214 |
} |
| 2215 |
|
| 2216 |
/* flag that the page has been marked */ |
| 2217 |
cur_state->pic_dirty = CDIRTY; |
| 2218 |
|
| 2219 |
} /*end if ok */ |
| 2220 |
|
| 2221 |
} /* end for i */ |
| 2222 |
} /* end xcpg */ |
| 2223 |
|
| 2224 |
/* CELL ARRAY */ |
| 2225 |
static void xcca(anything **params, int num_surfaces, anything **surf_list) |
| 2226 |
{ |
| 2227 |
int i; /* index for loop on surfaces */ |
| 2228 |
int j, k; /* loop indices */ |
| 2229 |
int index, index_inc, count; /* array indices */ |
| 2230 |
int nx, ny; /* number of cells in x,y */ |
| 2231 |
int nx1, ny1; /* number of cells in x,y after clipping */ |
| 2232 |
int *cells; /* color values */ |
| 2233 |
int ix, iy, yinc; /* SVDI logical raster coordinates */ |
| 2234 |
float x1, x2, y1, y2; /* corners of rectangle in NDC */ |
| 2235 |
float xmin, xmax, ymin, ymax; /* SVDI raster viewport (NDC) */ |
| 2236 |
int xdir, ydir; /* x,y directions on the device */ |
| 2237 |
int imap; |
| 2238 |
float xcell, ycell; /* area per cell */ |
| 2239 |
int ok; /* flag TRUE =line lies in clip region */ |
| 2240 |
int skipx, skipy; /* number of cells clipped in xmin,ymin */ |
| 2241 |
|
| 2242 |
/* if there isn't anything to draw, return */ |
| 2243 |
if (*(int *)params[7] == 0 || *(int *)params[8] == 0) { |
| 2244 |
return; |
| 2245 |
} |
| 2246 |
|
| 2247 |
/* if cell array has negative dimension, use absolute values */ |
| 2248 |
nx = nx1 = abs(*(int *)params[7]); |
| 2249 |
ny = ny1 = abs(*(int *)params[8]); |
| 2250 |
|
| 2251 |
cells = (int *)params[10]; |
| 2252 |
|
| 2253 |
for (i = 0; i < num_surfaces; ++i) { |
| 2254 |
|
| 2255 |
cur_state = (surf_statelist *)surf_list[i]; |
| 2256 |
if (cur_state->cgi_inited != CYES) { |
| 2257 |
break; |
| 2258 |
} |
| 2259 |
|
| 2260 |
/* if color selection mode is in error, ignore function */ |
| 2261 |
if (cur_state->csm == -1) { |
| 2262 |
break; |
| 2263 |
} |
| 2264 |
|
| 2265 |
/* for now, only allow 4 cases (same as pixel array), |
| 2266 |
* where nx runs only horizontal, and ny runs vertical. |
| 2267 |
* this routine needs to be fixed to allow all 8 cases |
| 2268 |
* Also, this routine does not allow skewing. |
| 2269 |
*/ |
| 2270 |
if (*(float *)params[2] != *(float *)params[6] || *(float *)params[3] != *(float *)params[5]) { |
| 2271 |
/* error 1:-106 Illegal cell array. Function ignored */ |
| 2272 |
report_error(cur_state, 1, -106, *(short *)params[0]); |
| 2273 |
return; |
| 2274 |
} |
| 2275 |
|
| 2276 |
/* map corners to NDC */ |
| 2277 |
x1 = *(float *)params[1] * cur_state->xscale + cur_state->xoffset; |
| 2278 |
x2 = *(float *)params[3] * cur_state->xscale + cur_state->xoffset; |
| 2279 |
|
| 2280 |
y1 = *(float *)params[2] * cur_state->yscale + cur_state->yoffset; |
| 2281 |
y2 = *(float *)params[4] * cur_state->yscale + cur_state->yoffset; |
| 2282 |
|
| 2283 |
/* figure out the raster viewport limits, and figure |
| 2284 |
* out x and y directions based on mappings and |
| 2285 |
* rectangle orientation. |
| 2286 |
*/ |
| 2287 |
if (x1 < x2) { |
| 2288 |
xmin = x1; |
| 2289 |
xmax = x2; |
| 2290 |
xdir = CINCR; |
| 2291 |
} |
| 2292 |
else { |
| 2293 |
xmin = x2; |
| 2294 |
xmax = x1; |
| 2295 |
xdir = CDECR; |
| 2296 |
} |
| 2297 |
|
| 2298 |
if (y1 < y2) { |
| 2299 |
ymin = y1; |
| 2300 |
ymax = y2; |
| 2301 |
ydir = CINCR; |
| 2302 |
} |
| 2303 |
else { |
| 2304 |
ymin = y2; |
| 2305 |
ymax = y1; |
| 2306 |
ydir = CDECR; |
| 2307 |
} |
| 2308 |
|
| 2309 |
ok = TRUE; |
| 2310 |
skipx = skipy = 0; |
| 2311 |
|
| 2312 |
if (cur_state->clip_on) { /* clipping is on, do it */ |
| 2313 |
|
| 2314 |
/* trivial reject */ |
| 2315 |
ok = ((xmin < cur_state->clipmax.x && xmax > cur_state->clipmin.x) && |
| 2316 |
(ymin < cur_state->clipmax.y && ymax > cur_state->clipmin.y)); |
| 2317 |
|
| 2318 |
if (ok) { /* it's in there, clip it */ |
| 2319 |
|
| 2320 |
/* clip in x first */ |
| 2321 |
xcell = (xmax - xmin) / nx; /* area per cell */ |
| 2322 |
|
| 2323 |
/* clip at left edge */ |
| 2324 |
if (xmin < cur_state->clipmin.x) { |
| 2325 |
|
| 2326 |
/* ...compute how many cells to skip */ |
| 2327 |
skipx = ceil((cur_state->clipmin.x - xmin) / xcell); |
| 2328 |
/* ...compute new xmin */ |
| 2329 |
xmin = xmin + ((float)skipx * xcell); |
| 2330 |
/* ...compute new nx */ |
| 2331 |
nx1 = nx - skipx; |
| 2332 |
} /* end clip at left edge */ |
| 2333 |
|
| 2334 |
/* clip at right edge */ |
| 2335 |
if (xmax > cur_state->clipmax.x) { |
| 2336 |
|
| 2337 |
/* ...compute new nx - how much will fit */ |
| 2338 |
nx1 = (int)((cur_state->clipmax.x - xmin) / xcell); |
| 2339 |
/* ...compute new xmax */ |
| 2340 |
xmax = xmin + (nx1 * xcell); |
| 2341 |
} /* end clip at right edge */ |
| 2342 |
|
| 2343 |
/* now clip in y */ |
| 2344 |
ycell = (ymax - ymin) / ny; /* area per cell */ |
| 2345 |
|
| 2346 |
/* clip at bottom edge */ |
| 2347 |
if (ymin < cur_state->clipmin.y) { |
| 2348 |
|
| 2349 |
/* ...compute how many cells to skip */ |
| 2350 |
skipy = ceil((cur_state->clipmin.y - ymin) / ycell); |
| 2351 |
/* ...compute new ymin */ |
| 2352 |
ymin = ymin + ((float)skipy * ycell); |
| 2353 |
/* ...compute new ny */ |
| 2354 |
ny1 = ny - skipy; |
| 2355 |
} /* end clip at bottom edge */ |
| 2356 |
|
| 2357 |
/* clip at top edge */ |
| 2358 |
if (ymax > cur_state->clipmax.y) { |
| 2359 |
|
| 2360 |
/* ...compute new ny - how much will fit */ |
| 2361 |
ny1 = (int)((cur_state->clipmax.y - ymin) / ycell); |
| 2362 |
/* ...compute new ymax */ |
| 2363 |
ymax = ymin + (ny1 * ycell); |
| 2364 |
} /* end clip at top edge */ |
| 2365 |
|
| 2366 |
} /* end if ok */ |
| 2367 |
} /* end if clip is on */ |
| 2368 |
|
| 2369 |
/* make sure there is still something left */ |
| 2370 |
ok = ok && (nx1 > 0 && ny1 > 0); |
| 2371 |
|
| 2372 |
if (ok) { /* everything is still ok */ |
| 2373 |
|
| 2374 |
/* set the raster space */ |
| 2375 |
vdstrs(&nx1, &ny1); |
| 2376 |
|
| 2377 |
imap = 3; |
| 2378 |
vbstmp(&imap); |
| 2379 |
imap = 5; |
| 2380 |
vbstmp(&imap); |
| 2381 |
|
| 2382 |
/* set the raster viewport */ |
| 2383 |
vdstrv(&xmin, &xmax, &ymin, &ymax); |
| 2384 |
|
| 2385 |
/* direct color or indexed */ |
| 2386 |
if (cur_state->csm == CINDEX) { /* indexed color */ |
| 2387 |
|
| 2388 |
/* Indexing into the cell array is based on clipping info |
| 2389 |
* and the orientation of the rectangle. SVDI+raster puts |
| 2390 |
* [0,0] at the top left corner. |
| 2391 |
*/ |
| 2392 |
|
| 2393 |
/* There are 4 different cases based on the orientation |
| 2394 |
* of the rectangle. ( really, there are 8, but I'm not |
| 2395 |
* supporting the other 4 right now ). If x is increasing, |
| 2396 |
* the most natural case, the cell array will be written |
| 2397 |
* out one raster line at a time, either top to bottom or |
| 2398 |
* bottom to top depending on the y direction. If x is |
| 2399 |
* decreasing, the cell array will have to be copied and |
| 2400 |
* reordered, so it will be written out in chunks. In this |
| 2401 |
* case, it will always be written out top to bottom. |
| 2402 |
*/ |
| 2403 |
|
| 2404 |
if (xdir == CINCR) { /* x increasing */ |
| 2405 |
|
| 2406 |
ix = 0; |
| 2407 |
/* compute iy and y increment based on y direction */ |
| 2408 |
if (ydir == CINCR) { /* y increasing */ |
| 2409 |
iy = ny1 - 1; |
| 2410 |
yinc = -1; |
| 2411 |
} |
| 2412 |
else { |
| 2413 |
iy = 0; |
| 2414 |
yinc = 1; |
| 2415 |
} |
| 2416 |
|
| 2417 |
/* This special case is for efficiency, since is will probably |
| 2418 |
* be most of the cases: If no clipping is on and [0,0] is at |
| 2419 |
* the top left (like SVDI+raster) draw the whole cell array. |
| 2420 |
*/ |
| 2421 |
if (!cur_state->clip_on && iy == 0) { |
| 2422 |
count = nx * ny; |
| 2423 |
vdpixi(&ix, &iy, &cells[0], &count); |
| 2424 |
} /* end special case */ |
| 2425 |
|
| 2426 |
else { /* special case doesn't apply, draw one line at a time */ |
| 2427 |
|
| 2428 |
/* starting index based on clipping info */ |
| 2429 |
index = (ny - ny1 - skipy) * nx + skipx; |
| 2430 |
|
| 2431 |
/* output one raster line at a time */ |
| 2432 |
for (k = 0; k < ny1; k++) { |
| 2433 |
vdpixi(&ix, &iy, &cells[index], &nx1); |
| 2434 |
index = index + nx; /* compute next index */ |
| 2435 |
iy = iy + yinc; /* compute next raster line */ |
| 2436 |
} /* end for k */ |
| 2437 |
} /* end else no special case */ |
| 2438 |
} /* end x increasing */ |
| 2439 |
|
| 2440 |
else { /* x decreasing */ |
| 2441 |
|
| 2442 |
/* always write top to bottom */ |
| 2443 |
ix = iy = count = 0; |
| 2444 |
|
| 2445 |
/* starting index and index increment are based on |
| 2446 |
clipping info and the y direction*/ |
| 2447 |
|
| 2448 |
if (ydir == CINCR) { /* y increasing */ |
| 2449 |
index = (ny1 + skipy) * nx - skipx - 1; |
| 2450 |
index_inc = -nx + nx1; |
| 2451 |
yinc = -1; |
| 2452 |
} |
| 2453 |
else { /* y decreasing */ |
| 2454 |
index = (ny - ny1 - skipy) * nx + (nx - 1) - skipx; |
| 2455 |
index_inc = nx + nx1; |
| 2456 |
yinc = 1; |
| 2457 |
} |
| 2458 |
|
| 2459 |
/* reorder the cell colors */ |
| 2460 |
for (k = 0; k < ny1; k++) { |
| 2461 |
for (j = 0; j < nx1; j++) { |
| 2462 |
assert(count < MAX_ARRAY); |
| 2463 |
varray[count++] = cells[index--]; |
| 2464 |
} |
| 2465 |
|
| 2466 |
/* if another row won't fit, or done, output varray */ |
| 2467 |
if (count + nx1 > MAX_ARRAY || k == ny1 - 1) { |
| 2468 |
vdpixi(&ix, &iy, varray, &count); |
| 2469 |
count = 0; /* reset varray counter */ |
| 2470 |
iy = iy + (yinc * (k + 1)); /* update iy */ |
| 2471 |
} |
| 2472 |
|
| 2473 |
/* compute next index */ |
| 2474 |
index = index + index_inc; |
| 2475 |
|
| 2476 |
} /* end for k */ |
| 2477 |
} /* end x decreasing */ |
| 2478 |
} /* end if indexed color */ |
| 2479 |
|
| 2480 |
else { /* direct color */ |
| 2481 |
|
| 2482 |
/* Indexing into the cells array is based on clipping info, |
| 2483 |
* and the orientation of the cell array. In SVDI+raster, |
| 2484 |
* the top left corner is [0,0]. For direct color, the cell |
| 2485 |
* array is always drawn from top to bottom. If the cell array |
| 2486 |
* is oriented with [0,0] at the the bottom left corner, the |
| 2487 |
* way the cells array is indexed takes care of the flipping. |
| 2488 |
*/ |
| 2489 |
|
| 2490 |
ix = iy = count = 0; |
| 2491 |
|
| 2492 |
if (xdir == CINCR) { /* x increasing */ |
| 2493 |
|
| 2494 |
/* starting index and index increment are based on |
| 2495 |
clipping info and the y direction */ |
| 2496 |
if (ydir == CINCR) { /* y increasing */ |
| 2497 |
index = ((ny1 + skipy - 1) * nx * 3) + (skipx * 3); |
| 2498 |
index_inc = -(nx + nx1) * 3; |
| 2499 |
} |
| 2500 |
else { /* y decreasing */ |
| 2501 |
index = (ny - ny1 - skipy) * nx * 3 + (skipx * 3); |
| 2502 |
index_inc = (nx - nx1) * 3; |
| 2503 |
} |
| 2504 |
|
| 2505 |
/* store as much info as possible before calling vdpixl */ |
| 2506 |
for (k = 0; k < ny1; k++) { |
| 2507 |
for (j = 0; j < nx1; j++) { |
| 2508 |
assert(count < MAX_ARRAY); |
| 2509 |
rarray[count] = (float)cells[index++] / 255.0f; |
| 2510 |
garray[count] = (float)cells[index++] / 255.0f; |
| 2511 |
barray[count] = (float)cells[index++] / 255.0f; |
| 2512 |
count++; |
| 2513 |
} /* end for j */ |
| 2514 |
|
| 2515 |
/* if another row won't fit, or done, output rgb arrays */ |
| 2516 |
if (count + nx1 > MAX_ARRAY || k == ny1 - 1) { |
| 2517 |
vdpixl(&ix, &iy, rarray, garray, barray, &count); |
| 2518 |
count = 0; /* reset rgb array counter */ |
| 2519 |
iy = k + 1; /* update iy */ |
| 2520 |
} |
| 2521 |
|
| 2522 |
/* compute next index into the cells array */ |
| 2523 |
index = index + index_inc; |
| 2524 |
|
| 2525 |
} /* end for k */ |
| 2526 |
} /* end if x increasing */ |
| 2527 |
|
| 2528 |
else { /* x decreasing */ |
| 2529 |
|
| 2530 |
/* starting index and index increment are based on |
| 2531 |
clipping info and the y direction */ |
| 2532 |
if (ydir == CINCR) { /* y increasing */ |
| 2533 |
index = (ny1 + skipy) * nx * 3 - (skipx * 3) - 3; |
| 2534 |
index_inc = (-nx + nx1) * 3; |
| 2535 |
} |
| 2536 |
else { /* y decreasing */ |
| 2537 |
index = (ny - ny1 - skipy) * nx * 3 + ((nx - 1) * 3) - (skipx * 3); |
| 2538 |
index_inc = (nx + nx1) * 3; |
| 2539 |
} |
| 2540 |
|
| 2541 |
/* store as much info as possible before calling vdpixl */ |
| 2542 |
for (k = 0; k < ny1; k++) { |
| 2543 |
for (j = 0; j < nx1; j++) { |
| 2544 |
assert(count < MAX_ARRAY); |
| 2545 |
rarray[count] = (float)cells[index] / 255.0f; |
| 2546 |
garray[count] = (float)cells[index + 1] / 255.0f; |
| 2547 |
barray[count] = (float)cells[index + 2] / 255.0f; |
| 2548 |
index = index - 3; |
| 2549 |
count++; |
| 2550 |
} /* end for j */ |
| 2551 |
|
| 2552 |
/* if another row won't fit, or done, output rgb arrays */ |
| 2553 |
if (count + nx1 > MAX_ARRAY || k == ny1 - 1) { |
| 2554 |
vdpixl(&ix, &iy, rarray, garray, barray, &count); |
| 2555 |
count = 0; /* reset rgb array counter */ |
| 2556 |
iy = k + 1; /* update iy */ |
| 2557 |
} |
| 2558 |
|
| 2559 |
/* compute next index into the cells array */ |
| 2560 |
index = index + index_inc; |
| 2561 |
|
| 2562 |
} /* end for k */ |
| 2563 |
} /* end else x decreasing */ |
| 2564 |
} /* end else direct color */ |
| 2565 |
|
| 2566 |
/* flag that the page has been marked */ |
| 2567 |
cur_state->pic_dirty = CDIRTY; |
| 2568 |
|
| 2569 |
} /* end if ok */ |
| 2570 |
} /* end for each surface */ |
| 2571 |
} /* end xcca */ |
| 2572 |
|
| 2573 |
/* PIXEL ARRAY */ |
| 2574 |
static void xcpxa(anything **params, int num_surfaces, anything **surf_list) |
| 2575 |
{ |
| 2576 |
int i; /* index for loop on surfaces */ |
| 2577 |
int j, k; /* loop indices */ |
| 2578 |
int *pxclrs; /* pixel color values */ |
| 2579 |
int nx, ny; /* size of pixel color array */ |
| 2580 |
int nx1, ny1; /* number of pixels after clipping */ |
| 2581 |
int index, index_inc; /* index into pxclrs array */ |
| 2582 |
int count; /* index into temp pixel arrays */ |
| 2583 |
int repx, repy; /* replication in x and y */ |
| 2584 |
int xdir, ydir; /* x and y direction on the DEVICE */ |
| 2585 |
float x_orig, y_orig; /* x and y origin */ |
| 2586 |
float x_dist, y_dist; /* distance pixels run from the origin */ |
| 2587 |
int ix, iy, yinc; /* SVDI logical raster coordinates */ |
| 2588 |
float xmin, xmax, ymin, ymax; /* SVDI raster viewport after clipping */ |
| 2589 |
int ok; /* flag TRUE =line lies in clip region */ |
| 2590 |
int skipx, skipy; /* count pixels skipped in xmin,ymin */ |
| 2591 |
int imap; |
| 2592 |
int qrs_index; /* index for SVDI inquiries */ |
| 2593 |
float temp_array[2]; /* temporary array for SVDI inquiries */ |
| 2594 |
float x_pxl_scale; /* for converting pixels to NDC/VDC space */ |
| 2595 |
float y_pxl_scale; |
| 2596 |
static float x_pixels = -1.; /* number of pixels in full NDC space */ |
| 2597 |
static float y_pixels = -1.; |
| 2598 |
float zero = 0.0; |
| 2599 |
|
| 2600 |
/* if nx,ny,repx,or repy are non positive, nothing is drawn */ |
| 2601 |
if (*(int *)params[3] < 0 || *(int *)params[4] < 0 || *(int *)params[5] < 0 || |
| 2602 |
*(int *)params[6] < 0) { |
| 2603 |
return; |
| 2604 |
} |
| 2605 |
|
| 2606 |
/* set up initial values */ |
| 2607 |
nx = nx1 = *(int *)params[3]; |
| 2608 |
ny = ny1 = *(int *)params[4]; |
| 2609 |
repx = *(int *)params[5]; |
| 2610 |
repy = *(int *)params[6]; |
| 2611 |
pxclrs = (int *)params[9]; |
| 2612 |
|
| 2613 |
/* find (and save) the number of pixels in full NDC space */ |
| 2614 |
if (x_pixels == -1.0f && y_pixels == -1.0f) { |
| 2615 |
vdstrv(&zero, &dev_descrip.xndc_max, &zero, &dev_descrip.yndc_max); |
| 2616 |
qrs_index = 2; |
| 2617 |
vdiqrs(&qrs_index, temp_array); |
| 2618 |
x_pixels = temp_array[0]; |
| 2619 |
y_pixels = temp_array[1]; |
| 2620 |
} /* end find number of pixels */ |
| 2621 |
|
| 2622 |
/* loop through surfaces */ |
| 2623 |
for (i = 0; i < num_surfaces; ++i) { |
| 2624 |
|
| 2625 |
cur_state = (surf_statelist *)surf_list[i]; |
| 2626 |
if (cur_state->cgi_inited != CYES) { |
| 2627 |
break; |
| 2628 |
} |
| 2629 |
|
| 2630 |
/* if color selection mode is in error, ignore function */ |
| 2631 |
if (cur_state->csm == -1) { |
| 2632 |
break; |
| 2633 |
} |
| 2634 |
|
| 2635 |
/* check enumerated types */ |
| 2636 |
if ((*(int *)params[7] != CINCR && *(int *)params[7] != CDECR) || |
| 2637 |
(*(int *)params[8] != CINCR && *(int *)params[8] != CDECR)) { |
| 2638 |
/* error 1:-101 enumerated parameter out of range. Function ignored */ |
| 2639 |
report_error(cur_state, 1, -101, *(short *)params[0]); |
| 2640 |
break; |
| 2641 |
} |
| 2642 |
|
| 2643 |
/* figure out what x direction and y direction are in terms |
| 2644 |
* of the device, since x direction and y direction are dependent |
| 2645 |
* on the VDC to device mapping. If xscale is positive, then |
| 2646 |
* VDC and VP are either both increasing or both decreasing and |
| 2647 |
* x direction on the device is the same as x direction in VDC. |
| 2648 |
* If xscale is negative, one is increasing and one is decreasing, |
| 2649 |
* and x direction on the device is opposite of x direction in |
| 2650 |
* VDC. Same holds for y (where "increasing" means bottom to top) |
| 2651 |
*/ |
| 2652 |
if (cur_state->xscale > 0) { |
| 2653 |
xdir = *(int *)params[7]; |
| 2654 |
} |
| 2655 |
else { |
| 2656 |
xdir = (*(int *)params[7] == CINCR) ? CDECR : CINCR; |
| 2657 |
} |
| 2658 |
|
| 2659 |
if (cur_state->yscale > 0) { |
| 2660 |
ydir = *(int *)params[8]; |
| 2661 |
} |
| 2662 |
else { |
| 2663 |
ydir = (*(int *)params[8] == CINCR) ? CDECR : CINCR; |
| 2664 |
} |
| 2665 |
|
| 2666 |
/* map to NDC */ |
| 2667 |
|
| 2668 |
/* origin */ |
| 2669 |
x_orig = *(float *)params[1] * cur_state->xscale + cur_state->xoffset; |
| 2670 |
y_orig = *(float *)params[2] * cur_state->yscale + cur_state->yoffset; |
| 2671 |
|
| 2672 |
/* scale to convert pixels to NDC space */ |
| 2673 |
x_pxl_scale = dev_descrip.xndc_max / x_pixels; |
| 2674 |
y_pxl_scale = dev_descrip.yndc_max / y_pixels; |
| 2675 |
|
| 2676 |
/* figure out raster viewport mins and maxes */ |
| 2677 |
x_dist = nx * repx * x_pxl_scale; |
| 2678 |
y_dist = ny * repy * y_pxl_scale; |
| 2679 |
|
| 2680 |
/* ...x is increasing or decreasing */ |
| 2681 |
if (xdir == CINCR) { |
| 2682 |
xmin = x_orig; |
| 2683 |
xmax = x_orig + x_dist; |
| 2684 |
} |
| 2685 |
else { |
| 2686 |
xmin = x_orig - x_dist; |
| 2687 |
xmax = x_orig; |
| 2688 |
} |
| 2689 |
/* y is increasing or decreasing */ |
| 2690 |
if (ydir == CINCR) { |
| 2691 |
ymin = y_orig; |
| 2692 |
ymax = y_orig + y_dist; |
| 2693 |
} |
| 2694 |
else { |
| 2695 |
ymin = y_orig - y_dist; |
| 2696 |
ymax = y_orig; |
| 2697 |
} |
| 2698 |
|
| 2699 |
ok = TRUE; |
| 2700 |
skipx = skipy = 0; |
| 2701 |
|
| 2702 |
if (cur_state->clip_on) { /* do the clipping */ |
| 2703 |
|
| 2704 |
/* trivial reject */ |
| 2705 |
ok = ((xmin < cur_state->clipmax.x && xmax > cur_state->clipmin.x) && |
| 2706 |
(ymin < cur_state->clipmax.y && ymax > cur_state->clipmin.y)); |
| 2707 |
|
| 2708 |
if (ok) { /* it's in there, clip it */ |
| 2709 |
|
| 2710 |
/* clip in x first */ |
| 2711 |
if (xmin < cur_state->clipmin.x) { /* ...left edge */ |
| 2712 |
|
| 2713 |
/* ...compute how many pixels to skip */ |
| 2714 |
skipx = ceil((cur_state->clipmin.x - xmin) / (x_pxl_scale * repx)); |
| 2715 |
/* ...compute new xmin */ |
| 2716 |
xmin = xmin + ((float)skipx * x_pxl_scale * repx); |
| 2717 |
/* ...compute new nx */ |
| 2718 |
nx1 = nx - skipx; |
| 2719 |
} /* end clip left edge */ |
| 2720 |
|
| 2721 |
if (xmax > cur_state->clipmax.x) { /* ...right edge */ |
| 2722 |
|
| 2723 |
/* ...compute new nx */ |
| 2724 |
nx1 = (int)((cur_state->clipmax.x - xmin) / (x_pxl_scale * repx)); |
| 2725 |
/* ...compute new xmax */ |
| 2726 |
xmax = xmin + (nx1 * x_pxl_scale * repx); |
| 2727 |
} /* end clip right edge */ |
| 2728 |
|
| 2729 |
/* now clip in y */ |
| 2730 |
if (ymin < cur_state->clipmin.y) { /* ...bottom edge */ |
| 2731 |
|
| 2732 |
/* ...compute how many pixels to skip */ |
| 2733 |
skipy = ceil((cur_state->clipmin.y - ymin) / (y_pxl_scale * repy)); |
| 2734 |
/* ...compute new ymin */ |
| 2735 |
ymin = ymin + ((float)skipy * y_pxl_scale * repy); |
| 2736 |
/* ...compute new ny */ |
| 2737 |
ny1 = ny - skipy; |
| 2738 |
} /* end bottom left edge */ |
| 2739 |
|
| 2740 |
if (ymax > cur_state->clipmax.y) { /* ...top edge */ |
| 2741 |
|
| 2742 |
/* ...compute new ny */ |
| 2743 |
ny1 = (int)((cur_state->clipmax.y - ymin) / (y_pxl_scale * repy)); |
| 2744 |
/* ...comput new ymax */ |
| 2745 |
ymax = ymin + (ny1 * y_pxl_scale * repy); |
| 2746 |
} /* end clip top edge */ |
| 2747 |
|
| 2748 |
} /* end if ok */ |
| 2749 |
} /* end if clip_on */ |
| 2750 |
|
| 2751 |
/* make sure there is still something to draw */ |
| 2752 |
ok = ok && (nx1 > 0 && ny1 > 0); |
| 2753 |
|
| 2754 |
if (ok) { /* everything is still ok */ |
| 2755 |
|
| 2756 |
/* set the raster viewport */ |
| 2757 |
vdstrv(&xmin, &xmax, &ymin, &ymax); |
| 2758 |
|
| 2759 |
imap = 2; |
| 2760 |
vbstmp(&imap); |
| 2761 |
imap = 5; |
| 2762 |
vbstmp(&imap); |
| 2763 |
|
| 2764 |
/* set the raster space to number of device pixels in viewport */ |
| 2765 |
vdstrs(&nx1, &ny1); |
| 2766 |
|
| 2767 |
/* direct color or indexed */ |
| 2768 |
if (cur_state->csm == CINDEX) { /* indexed color */ |
| 2769 |
|
| 2770 |
/* Indexing into the pixel array is based on clipping info |
| 2771 |
* and the orientation of the pixel array, which is |
| 2772 |
* determined by whether x and y are increasing or |
| 2773 |
* decreasing in VDC from the origin. SVDI+raster puts |
| 2774 |
* [0,0] at the top left corner. |
| 2775 |
*/ |
| 2776 |
|
| 2777 |
/* There are 4 different cases based on the x and y |
| 2778 |
* directions. If x is increasing, the most natural |
| 2779 |
* case, the pixel array will be written out one raster |
| 2780 |
* line at a time, either top to bottom or bottom to |
| 2781 |
* top depending on the y direction. If x is decreasing, |
| 2782 |
* the pixel array will have to be copied and reordered, |
| 2783 |
* so it will be written out in chunks. In this case, |
| 2784 |
* it will always be written out top to bottom. |
| 2785 |
*/ |
| 2786 |
|
| 2787 |
if (xdir == CINCR) { /* x increasing */ |
| 2788 |
|
| 2789 |
ix = 0; |
| 2790 |
/* compute iy and y increment based on y direction */ |
| 2791 |
if (ydir == CINCR) { /* y increasing */ |
| 2792 |
iy = ny1 - 1; |
| 2793 |
yinc = -1; |
| 2794 |
} |
| 2795 |
else { /* y decreasing */ |
| 2796 |
iy = 0; |
| 2797 |
yinc = 1; |
| 2798 |
} |
| 2799 |
|
| 2800 |
/* This special case is for efficiency, since is will probably |
| 2801 |
* be most of the cases: If no clipping is on and [0,0] is at |
| 2802 |
* the top left (like SVDI+raster) draw the whole pixel array. |
| 2803 |
*/ |
| 2804 |
if (!cur_state->clip_on && iy == 0) { |
| 2805 |
count = nx * ny; |
| 2806 |
vdpixi(&ix, &iy, &pxclrs[0], &count); |
| 2807 |
} /* end special case */ |
| 2808 |
|
| 2809 |
else { /* special case doesn't apply, draw one line at a time */ |
| 2810 |
|
| 2811 |
/* starting index based on clipping info */ |
| 2812 |
index = (ny - ny1 - skipy) * nx + skipx; |
| 2813 |
|
| 2814 |
/* output one raster line at a time */ |
| 2815 |
for (k = 0; k < ny1; k++) { |
| 2816 |
vdpixi(&ix, &iy, &pxclrs[index], &nx1); |
| 2817 |
index = index + nx; /* compute next index */ |
| 2818 |
iy = iy + yinc; /* compute next raster line */ |
| 2819 |
} /* end for k */ |
| 2820 |
} /* end else no special case */ |
| 2821 |
} /* end x increasing */ |
| 2822 |
|
| 2823 |
else { /* x decreasing */ |
| 2824 |
|
| 2825 |
/* always write top to bottom */ |
| 2826 |
ix = iy = count = 0; |
| 2827 |
|
| 2828 |
/* starting index and index increment are based on |
| 2829 |
clipping info and the y direction*/ |
| 2830 |
|
| 2831 |
if (ydir == CINCR) { /* y increasing */ |
| 2832 |
index = (ny1 + skipy) * nx - skipx - 1; |
| 2833 |
index_inc = -nx + nx1; |
| 2834 |
yinc = -1; |
| 2835 |
} |
| 2836 |
else { /* y decreasing */ |
| 2837 |
index = (ny - ny1 - skipy) * nx + (nx - 1) - skipx; |
| 2838 |
index_inc = nx + nx1; |
| 2839 |
yinc = 1; |
| 2840 |
} |
| 2841 |
|
| 2842 |
/* reorder the pixel colors */ |
| 2843 |
for (k = 0; k < ny1; k++) { |
| 2844 |
for (j = 0; j < nx1; j++) { |
| 2845 |
assert(count < MAX_ARRAY); |
| 2846 |
varray[count++] = pxclrs[index--]; |
| 2847 |
} |
| 2848 |
|
| 2849 |
/* if another row won't fit, or done, output varray */ |
| 2850 |
if (count + nx1 > MAX_ARRAY || k == ny1 - 1) { |
| 2851 |
vdpixi(&ix, &iy, varray, &count); |
| 2852 |
count = 0; /* reset varray counter */ |
| 2853 |
iy = iy + (yinc * (k + 1)); /* update iy */ |
| 2854 |
} |
| 2855 |
|
| 2856 |
/* compute next index */ |
| 2857 |
index = index + index_inc; |
| 2858 |
|
| 2859 |
} /* end for k */ |
| 2860 |
} /* end x decreasing */ |
| 2861 |
} /* end if indexed color */ |
| 2862 |
|
| 2863 |
else { /* direct color */ |
| 2864 |
|
| 2865 |
/* For direct color, the color values always have to be |
| 2866 |
* copied, so the raster lines are written out in chucks. |
| 2867 |
* The raster lines will always be written top to bottom; |
| 2868 |
* indexing and reordering of the color values will be |
| 2869 |
* based on x and y direction. |
| 2870 |
*/ |
| 2871 |
|
| 2872 |
ix = iy = count = 0; |
| 2873 |
|
| 2874 |
if (xdir == CINCR) { /* x increasing */ |
| 2875 |
|
| 2876 |
/* starting index and index increment are based on |
| 2877 |
clipping info and the y direction */ |
| 2878 |
if (ydir == CINCR) { /* y increasing */ |
| 2879 |
index = ((ny1 + skipy - 1) * nx * 3) + (skipx * 3); |
| 2880 |
index_inc = -(nx + nx1) * 3; |
| 2881 |
} |
| 2882 |
else { /* y decreasing */ |
| 2883 |
index = (ny - ny1 - skipy) * nx * 3 + (skipx * 3); |
| 2884 |
index_inc = (nx - nx1) * 3; |
| 2885 |
} |
| 2886 |
|
| 2887 |
/* store as much info as possible before calling vdpixl */ |
| 2888 |
for (k = 0; k < ny1; k++) { |
| 2889 |
for (j = 0; j < nx1; j++) { |
| 2890 |
assert(count < MAX_ARRAY); |
| 2891 |
rarray[count] = (float)pxclrs[index++] / 255.0f; |
| 2892 |
garray[count] = (float)pxclrs[index++] / 255.0f; |
| 2893 |
barray[count] = (float)pxclrs[index++] / 255.0f; |
| 2894 |
count++; |
| 2895 |
} /* end for j */ |
| 2896 |
|
| 2897 |
/* if another row won't fit, or done, output rgb arrays */ |
| 2898 |
if (count + nx1 > MAX_ARRAY || k == ny1 - 1) { |
| 2899 |
vdpixl(&ix, &iy, rarray, garray, barray, &count); |
| 2900 |
count = 0; /* reset rgb array counter */ |
| 2901 |
iy = k + 1; /* update iy */ |
| 2902 |
} |
| 2903 |
|
| 2904 |
/* compute next index into the pxclrs array */ |
| 2905 |
index = index + index_inc; |
| 2906 |
|
| 2907 |
} /* end for k */ |
| 2908 |
} /* end if x increasing */ |
| 2909 |
|
| 2910 |
else { /* x decreasing */ |
| 2911 |
|
| 2912 |
/* starting index and index increment are based on |
| 2913 |
clipping info and the y direction */ |
| 2914 |
if (ydir == CINCR) { /* y increasing */ |
| 2915 |
index = (ny1 + skipy) * nx * 3 - (skipx * 3) - 3; |
| 2916 |
index_inc = (-nx + nx1) * 3; |
| 2917 |
} |
| 2918 |
else { /* y decreasing */ |
| 2919 |
index = (ny - ny1 - skipy) * nx * 3 + ((nx - 1) * 3) - (skipx * 3); |
| 2920 |
index_inc = (nx + nx1) * 3; |
| 2921 |
} |
| 2922 |
|
| 2923 |
/* store as much info as possible before calling vdpixl */ |
| 2924 |
for (k = 0; k < ny1; k++) { |
| 2925 |
for (j = 0; j < nx1; j++) { |
| 2926 |
assert(count < MAX_ARRAY); |
| 2927 |
rarray[count] = (float)pxclrs[index] / 255.0f; |
| 2928 |
garray[count] = (float)pxclrs[index + 1] / 255.0f; |
| 2929 |
barray[count] = (float)pxclrs[index + 2] / 255.0f; |
| 2930 |
index = index - 3; |
| 2931 |
count++; |
| 2932 |
} /* end for j */ |
| 2933 |
|
| 2934 |
/* if another row won't fit, or done, output rgb arrays */ |
| 2935 |
if (count + nx1 > MAX_ARRAY || k == ny1 - 1) { |
| 2936 |
vdpixl(&ix, &iy, rarray, garray, barray, &count); |
| 2937 |
count = 0; /* reset rgb array counter */ |
| 2938 |
iy = k + 1; /* update iy */ |
| 2939 |
} |
| 2940 |
|
| 2941 |
/* compute next index into the pxclrs array */ |
| 2942 |
index = index + index_inc; |
| 2943 |
|
| 2944 |
} /* end for k */ |
| 2945 |
} /* end else x decreasing */ |
| 2946 |
} /* end else direct color */ |
| 2947 |
|
| 2948 |
/* flag that the page has been marked */ |
| 2949 |
cur_state->pic_dirty = CDIRTY; |
| 2950 |
|
| 2951 |
} /* end if ok */ |
| 2952 |
} /* end for each surface */ |
| 2953 |
} /* end xcpxa */ |
| 2954 |
|
| 2955 |
/* LINE TYPE */ |
| 2956 |
static void xclnt(anything **params, int num_surfaces, anything **surf_list) |
| 2957 |
{ |
| 2958 |
|
| 2959 |
int i; /* index for loop on surfaces */ |
| 2960 |
int vdi_style; /* SVDI linestyle */ |
| 2961 |
|
| 2962 |
/* CGI line types: */ |
| 2963 |
/* 1: solid - supported |
| 2964 |
* 2: dash - supported |
| 2965 |
* 3: dot - supported |
| 2966 |
* 4: dash dot - supported |
| 2967 |
* 5: dash dot dot - not supported |
| 2968 |
*/ |
| 2969 |
|
| 2970 |
/* SVDI linestyles: */ |
| 2971 |
/* 0: solid |
| 2972 |
* 1: dotted |
| 2973 |
* 2: dot dash |
| 2974 |
* 3: short dash |
| 2975 |
* 4: long dash |
| 2976 |
* 5: medium dash |
| 2977 |
*/ |
| 2978 |
|
| 2979 |
for (i = 0; i < num_surfaces; ++i) { |
| 2980 |
|
| 2981 |
cur_state = (surf_statelist *)surf_list[i]; |
| 2982 |
if (cur_state->cgi_inited != CYES) { |
| 2983 |
break; |
| 2984 |
} |
| 2985 |
|
| 2986 |
/* let SVDI catch any out of range indices */ |
| 2987 |
cur_state->line_type = *(int *)params[1]; |
| 2988 |
|
| 2989 |
/* make sure it really needs to be set */ |
| 2990 |
if (cur_state->line_type != cur_state->vdi_attrib.line_type) { |
| 2991 |
|
| 2992 |
cur_state->vdi_attrib.line_type = cur_state->line_type; |
| 2993 |
|
| 2994 |
/* map to SVDI styles */ |
| 2995 |
switch (cur_state->line_type) { |
| 2996 |
case 1: vdi_style = 0; break; |
| 2997 |
case 2: vdi_style = 5; break; |
| 2998 |
case 3: vdi_style = 1; break; |
| 2999 |
case 4: vdi_style = 2; break; |
| 3000 |
case 5: vdi_style = 0; break; /* not supported, set to solid */ |
| 3001 |
default: vdi_style = cur_state->line_type; break; |
| 3002 |
} /* end switch */ |
| 3003 |
|
| 3004 |
vdstls(&vdi_style); |
| 3005 |
} /* end it needs to be set */ |
| 3006 |
|
| 3007 |
} /* end for each surface */ |
| 3008 |
} /* end xclnt */ |
| 3009 |
|
| 3010 |
/* LINE WIDTH */ |
| 3011 |
static void xclnw(anything **params, int num_surfaces, anything **surf_list) |
| 3012 |
{ |
| 3013 |
|
| 3014 |
int i; /* index for loop on surfaces */ |
| 3015 |
float vdi_lw; /* SVDI linewidth */ |
| 3016 |
float temp_array[14]; /* use for SVDI inquiry */ |
| 3017 |
|
| 3018 |
for (i = 0; i < num_surfaces; ++i) { |
| 3019 |
|
| 3020 |
cur_state = (surf_statelist *)surf_list[i]; |
| 3021 |
if (cur_state->cgi_inited != CYES) { |
| 3022 |
break; |
| 3023 |
} |
| 3024 |
|
| 3025 |
/* make sure it needs to be updated */ |
| 3026 |
if (*(float *)params[1] != cur_state->vdi_attrib.line_width) { |
| 3027 |
|
| 3028 |
/* save the original in vdi_attrib array */ |
| 3029 |
cur_state->vdi_attrib.line_width = *(float *)params[1]; |
| 3030 |
|
| 3031 |
/* convert to NDC and set the linewidth */ |
| 3032 |
vdi_lw = dev_descrip.linewidth_nominal * *(float *)params[1] * fabs(cur_state->xscale); |
| 3033 |
vdstlw(&vdi_lw); |
| 3034 |
|
| 3035 |
/* find out what it really got set at */ |
| 3036 |
vdiqos(&temp_array[1]); |
| 3037 |
|
| 3038 |
/* map it back to (scaled) VDC and store it in state table */ |
| 3039 |
cur_state->line_width = |
| 3040 |
(temp_array[5] * fabs(cur_state->xscale) * 100) / dev_descrip.linewidth_nominal; |
| 3041 |
|
| 3042 |
} /* end it needs to be updated */ |
| 3043 |
|
| 3044 |
} /* end for each surface */ |
| 3045 |
} /* end xclnw */ |
| 3046 |
|
| 3047 |
/* LINE COLOR */ |
| 3048 |
static void xclnc(anything **params, int num_surfaces, anything **surf_list) |
| 3049 |
{ |
| 3050 |
int i; /* index for loop on surfaces */ |
| 3051 |
|
| 3052 |
for (i = 0; i < num_surfaces; ++i) { |
| 3053 |
|
| 3054 |
cur_state = (surf_statelist *)surf_list[i]; |
| 3055 |
if (cur_state->cgi_inited != CYES) { |
| 3056 |
break; |
| 3057 |
} |
| 3058 |
|
| 3059 |
/* if color selection mode is in error, ignore function */ |
| 3060 |
if (cur_state->csm == -1) { |
| 3061 |
break; |
| 3062 |
} |
| 3063 |
|
| 3064 |
if (cur_state->csm == CINDEX) { /* indexed mode */ |
| 3065 |
|
| 3066 |
/* let SVDI catch out of range indices */ |
| 3067 |
cur_state->line_csm = CINDEX; |
| 3068 |
cur_state->line_color[0] = *(int *)params[1]; |
| 3069 |
} /* end indexed mode */ |
| 3070 |
|
| 3071 |
else { /* direct color mode */ |
| 3072 |
|
| 3073 |
/* let SVDI catch illegal color values */ |
| 3074 |
cur_state->line_csm = CDRECT; |
| 3075 |
cur_state->line_color[0] = *((int *)params[1] + 0); |
| 3076 |
cur_state->line_color[1] = *((int *)params[1] + 1); |
| 3077 |
cur_state->line_color[2] = *((int *)params[1] + 2); |
| 3078 |
} /* end direct color mode */ |
| 3079 |
|
| 3080 |
} /* end for each surface */ |
| 3081 |
} /* end xclnc */ |
| 3082 |
|
| 3083 |
/* MARKER TYPE */ |
| 3084 |
static void xcmkt(int num_surfaces, anything **surf_list) |
| 3085 |
{ |
| 3086 |
/* CGI marker types: */ |
| 3087 |
/* 1: dot - supported |
| 3088 |
* 2: plus - not supported |
| 3089 |
* 3: asterisk - not supported |
| 3090 |
* 4: circle - not supported |
| 3091 |
* 5: cross - not supported |
| 3092 |
*/ |
| 3093 |
|
| 3094 |
/* SVDI only supports a dot, which is the default */ |
| 3095 |
|
| 3096 |
/* An unsupported index is mapped to a supported value, such |
| 3097 |
* as the default, without error. So can just ignore this |
| 3098 |
* function. |
| 3099 |
*/ |
| 3100 |
|
| 3101 |
} /* end xcmkt */ |
| 3102 |
|
| 3103 |
/* MARKER SIZE */ |
| 3104 |
static void xcmks(anything **params, int num_surfaces, anything **surf_list) |
| 3105 |
{ |
| 3106 |
/* marker size is mapped to nearest avail marker size on |
| 3107 |
* the device. SVDI only supports 1 marker size, which is |
| 3108 |
* the default size, so this function not supported. |
| 3109 |
*/ |
| 3110 |
/* error 4:001 - Function not supported. Function ignored */ |
| 3111 |
report_error(cur_state, 4, 001, *(short *)params[0]); |
| 3112 |
|
| 3113 |
} /* end xcmks */ |
| 3114 |
|
| 3115 |
/* MARKER COLOR */ |
| 3116 |
static void xcmkc(anything **params, int num_surfaces, anything **surf_list) |
| 3117 |
{ |
| 3118 |
int i; /* index for loop on surfaces */ |
| 3119 |
|
| 3120 |
for (i = 0; i < num_surfaces; ++i) { |
| 3121 |
|
| 3122 |
cur_state = (surf_statelist *)surf_list[i]; |
| 3123 |
if (cur_state->cgi_inited != CYES) { |
| 3124 |
break; |
| 3125 |
} |
| 3126 |
|
| 3127 |
/* if color selection mode is in error, ignore function */ |
| 3128 |
if (cur_state->csm == -1) { |
| 3129 |
break; |
| 3130 |
} |
| 3131 |
|
| 3132 |
if (cur_state->csm == CINDEX) { /* indexed mode */ |
| 3133 |
|
| 3134 |
/* let SVDI catch out of range indices */ |
| 3135 |
cur_state->mark_csm = CINDEX; |
| 3136 |
cur_state->mark_color[0] = *(int *)params[1]; |
| 3137 |
} /* end indexed mode */ |
| 3138 |
|
| 3139 |
else { /* direct color mode */ |
| 3140 |
|
| 3141 |
/* let SVDI catch illegal color values */ |
| 3142 |
cur_state->mark_csm = CDRECT; |
| 3143 |
cur_state->mark_color[0] = *((int *)params[1] + 0); |
| 3144 |
cur_state->mark_color[1] = *((int *)params[1] + 1); |
| 3145 |
cur_state->mark_color[2] = *((int *)params[1] + 2); |
| 3146 |
} /* end direct color mode */ |
| 3147 |
|
| 3148 |
} /* end for each surface */ |
| 3149 |
} /* end xcmkc */ |
| 3150 |
|
| 3151 |
/* TEXT PRECISION */ |
| 3152 |
static void xctxp(anything **params, int num_surfaces, anything **surf_list) |
| 3153 |
{ |
| 3154 |
/* error 4:001 - Function not supported. Function ignored */ |
| 3155 |
report_error(cur_state, 4, 001, *(short *)params[0]); |
| 3156 |
|
| 3157 |
} /* end xctxp */ |
| 3158 |
|
| 3159 |
/* TEXT COLOR */ |
| 3160 |
static void xctxc(anything **params, int num_surfaces, anything **surf_list) |
| 3161 |
{ |
| 3162 |
int i; /* index for loop on surfaces */ |
| 3163 |
|
| 3164 |
for (i = 0; i < num_surfaces; ++i) { |
| 3165 |
|
| 3166 |
cur_state = (surf_statelist *)surf_list[i]; |
| 3167 |
if (cur_state->cgi_inited != CYES) { |
| 3168 |
break; |
| 3169 |
} |
| 3170 |
|
| 3171 |
/* if color selection mode is in error, ignore function */ |
| 3172 |
if (cur_state->csm == -1) { |
| 3173 |
break; |
| 3174 |
} |
| 3175 |
|
| 3176 |
if (cur_state->csm == CINDEX) { /* indexed mode */ |
| 3177 |
|
| 3178 |
/* let SVDI catch out of range indices */ |
| 3179 |
cur_state->text_csm = CINDEX; |
| 3180 |
cur_state->text_color[0] = *(int *)params[1]; |
| 3181 |
} /* end indexed mode */ |
| 3182 |
|
| 3183 |
else { /* direct color mode */ |
| 3184 |
|
| 3185 |
/* let SVDI catch illegal color values */ |
| 3186 |
cur_state->text_csm = CDRECT; |
| 3187 |
cur_state->text_color[0] = *((int *)params[1] + 0); |
| 3188 |
cur_state->text_color[1] = *((int *)params[1] + 1); |
| 3189 |
cur_state->text_color[2] = *((int *)params[1] + 2); |
| 3190 |
} /* end direct mode */ |
| 3191 |
|
| 3192 |
} /* end for each surface */ |
| 3193 |
} /* end xctxc */ |
| 3194 |
|
| 3195 |
/* CHARACTER HEIGHT */ |
| 3196 |
static void xcchh(anything **params, int num_surfaces, anything **surf_list) |
| 3197 |
{ |
| 3198 |
int i; /* index for loop on surfaces */ |
| 3199 |
float vdi_cs; /* SVDI character size */ |
| 3200 |
float temp_array[14]; /* used for SVDI inquire */ |
| 3201 |
|
| 3202 |
for (i = 0; i < num_surfaces; ++i) { |
| 3203 |
|
| 3204 |
cur_state = (surf_statelist *)surf_list[i]; |
| 3205 |
if (cur_state->cgi_inited != CYES) { |
| 3206 |
break; |
| 3207 |
} |
| 3208 |
|
| 3209 |
/* set SVDI character size if needed */ |
| 3210 |
if (*(float *)params[1] != cur_state->vdi_attrib.char_x) { |
| 3211 |
|
| 3212 |
/* let SVDI catch illegal character height */ |
| 3213 |
cur_state->vdi_attrib.char_x = *(float *)params[1]; |
| 3214 |
|
| 3215 |
/* map to NDC */ |
| 3216 |
vdi_cs = *(float *)params[1] * fabs(cur_state->xscale); |
| 3217 |
vdstcs(&vdi_cs); |
| 3218 |
|
| 3219 |
/* inquire to find out what it really got set to */ |
| 3220 |
vdiqos(&temp_array[1]); |
| 3221 |
|
| 3222 |
/* map back to VDC and store in state table */ |
| 3223 |
cur_state->char_height = temp_array[6] / fabs(cur_state->xscale); |
| 3224 |
|
| 3225 |
} /* end if char size needs to be set */ |
| 3226 |
|
| 3227 |
} /* end for each surface */ |
| 3228 |
} /* end xcchh */ |
| 3229 |
|
| 3230 |
/* CHARACTER ORIENTATION */ |
| 3231 |
static void xccho(anything **params, int num_surfaces, anything **surf_list) |
| 3232 |
{ |
| 3233 |
/* error 4:001 - Function not supported. Function ignored */ |
| 3234 |
report_error(cur_state, 4, 001, *(short *)params[0]); |
| 3235 |
|
| 3236 |
} /* end xccho */ |
| 3237 |
|
| 3238 |
/* INTERIOR STYLE */ |
| 3239 |
static void xcis(anything **params, int num_surfaces, anything **surf_list) |
| 3240 |
{ |
| 3241 |
int i; /* index for loop on surfaces */ |
| 3242 |
|
| 3243 |
/* CGI interior styles: */ |
| 3244 |
/* hollow - supported |
| 3245 |
* solid - supported |
| 3246 |
* pattern - not supported |
| 3247 |
* hatch - not supported |
| 3248 |
* empty - not supported |
| 3249 |
* bitmap - not supported |
| 3250 |
*/ |
| 3251 |
|
| 3252 |
for (i = 0; i < num_surfaces; ++i) { |
| 3253 |
|
| 3254 |
cur_state = (surf_statelist *)surf_list[i]; |
| 3255 |
if (cur_state->cgi_inited != CYES) { |
| 3256 |
break; |
| 3257 |
} |
| 3258 |
|
| 3259 |
/* check for legal enumerated value */ |
| 3260 |
if (*(int *)params[1] == CHOLLO || *(int *)params[1] == CSOLID) { |
| 3261 |
cur_state->interior_style = *(int *)params[1]; |
| 3262 |
} |
| 3263 |
else { |
| 3264 |
/* error 1:-101 Enumerated parameter out of range. Function ignored */ |
| 3265 |
report_error(cur_state, 1, -101, *(short *)params[0]); |
| 3266 |
} |
| 3267 |
|
| 3268 |
} /* end for each surface */ |
| 3269 |
} /* end xcis */ |
| 3270 |
|
| 3271 |
/* FILL COLOR */ |
| 3272 |
static void xcflc(anything **params, int num_surfaces, anything **surf_list) |
| 3273 |
{ |
| 3274 |
int i; /* index for loop on surfaces */ |
| 3275 |
|
| 3276 |
for (i = 0; i < num_surfaces; ++i) { |
| 3277 |
|
| 3278 |
cur_state = (surf_statelist *)surf_list[i]; |
| 3279 |
if (cur_state->cgi_inited != CYES) { |
| 3280 |
break; |
| 3281 |
} |
| 3282 |
|
| 3283 |
/* if color selection mode is in error, ignore function */ |
| 3284 |
if (cur_state->csm == -1) { |
| 3285 |
break; |
| 3286 |
} |
| 3287 |
|
| 3288 |
if (cur_state->csm == CINDEX) { /* indexed mode */ |
| 3289 |
|
| 3290 |
/* let SVDI catch out of range indices */ |
| 3291 |
cur_state->fill_csm = CINDEX; |
| 3292 |
cur_state->fill_color[0] = *(int *)params[1]; |
| 3293 |
} /* end indexed color */ |
| 3294 |
|
| 3295 |
else { /* direct color mode */ |
| 3296 |
|
| 3297 |
/* let SVDI catch illegal color values */ |
| 3298 |
cur_state->fill_csm = CDRECT; |
| 3299 |
cur_state->fill_color[0] = *((int *)params[1] + 0); |
| 3300 |
cur_state->fill_color[1] = *((int *)params[1] + 1); |
| 3301 |
cur_state->fill_color[2] = *((int *)params[1] + 2); |
| 3302 |
} /* end direct color mode */ |
| 3303 |
|
| 3304 |
} /* end for each surface */ |
| 3305 |
} /* end xcflc */ |
| 3306 |
|
| 3307 |
/* COLOR SELECTION MODE */ |
| 3308 |
static void xccsm(anything **params, int num_surfaces, anything **surf_list) |
| 3309 |
{ |
| 3310 |
int i; /* index for loop on surfaces */ |
| 3311 |
|
| 3312 |
for (i = 0; i < num_surfaces; ++i) { |
| 3313 |
|
| 3314 |
cur_state = (surf_statelist *)surf_list[i]; |
| 3315 |
if (cur_state->cgi_inited != CYES) { |
| 3316 |
break; |
| 3317 |
} |
| 3318 |
|
| 3319 |
/* check enumerated parameters */ |
| 3320 |
if (*(int *)params[1] != CDRECT && *(int *)params[1] != CINDEX) { |
| 3321 |
/* error 1:-101 enumerated parameter out of range. Function ignored */ |
| 3322 |
report_error(cur_state, 1, -101, *(short *)params[0]); |
| 3323 |
} |
| 3324 |
else { |
| 3325 |
|
| 3326 |
/* if the device supports both index and direct, or the |
| 3327 |
request if only for index, everything is honky-dory */ |
| 3328 |
if (dev_descrip.csm_avail == CCLRID || *(int *)params[1] == CINDEX) { |
| 3329 |
cur_state->csm = *(int *)params[1]; |
| 3330 |
} |
| 3331 |
else { /* must be an error */ |
| 3332 |
/* error 3:305 - Color selection mode not supported. All |
| 3333 |
functions with affected parameters ignored until reset */ |
| 3334 |
report_error(cur_state, 3, 305, *(short *)params[0]); |
| 3335 |
cur_state->csm = -1; /* flag error condition */ |
| 3336 |
} /* end else must be an error */ |
| 3337 |
} /* end else */ |
| 3338 |
|
| 3339 |
} /* end for each surface */ |
| 3340 |
} /* end xccsm */ |
| 3341 |
|
| 3342 |
/* COLOR TABLE */ |
| 3343 |
static void xcct(anything **params, int num_surfaces, anything **surf_list) |
| 3344 |
{ |
| 3345 |
int i; /* index for loop on surfaces */ |
| 3346 |
int j, k; /* indices for looping */ |
| 3347 |
int starti; /* starting color index */ |
| 3348 |
int num_cols; /* number of colors in color list */ |
| 3349 |
int tmp_array[3]; /* temp array used for setting bg color */ |
| 3350 |
float color_array[256][3]; /* used for setting SVDI color table */ |
| 3351 |
int num_set; /* number of colors being set, for SVDI */ |
| 3352 |
int maxindex; /* max color index to set */ |
| 3353 |
int indx_ptr; /* for keeping track of color indices */ |
| 3354 |
int index1, index2; /* defines a range of indices to set */ |
| 3355 |
int first; /* marks first time through loop */ |
| 3356 |
int one = 1; |
| 3357 |
|
| 3358 |
first = TRUE; |
| 3359 |
|
| 3360 |
/* loop through surfaces */ |
| 3361 |
for (i = 0; i < num_surfaces; ++i) { |
| 3362 |
|
| 3363 |
cur_state = (surf_statelist *)surf_list[i]; |
| 3364 |
if (cur_state->cgi_inited != CYES) { |
| 3365 |
break; |
| 3366 |
} |
| 3367 |
|
| 3368 |
/* starting color index and number of colors */ |
| 3369 |
starti = *(int *)params[1]; |
| 3370 |
num_cols = *(int *)params[2]; |
| 3371 |
|
| 3372 |
/* error checking */ |
| 3373 |
/* an out of range index in an index definition function should |
| 3374 |
be ignored. should an error be reported ?? */ |
| 3375 |
if (starti < 0) { |
| 3376 |
starti = 0; |
| 3377 |
} |
| 3378 |
|
| 3379 |
if ((starti + num_cols - 1) > dev_descrip.num_cols) { |
| 3380 |
/* error 6:308 - Too many color specifiers. Discard extras */ |
| 3381 |
report_error(cur_state, 6, 308, *(short *)params[0]); |
| 3382 |
num_cols = dev_descrip.num_cols - starti + 1; |
| 3383 |
} /* end error */ |
| 3384 |
|
| 3385 |
/* convert rgb to lie between 0. and 1. */ |
| 3386 |
/* ...only do this once */ |
| 3387 |
if (first) { |
| 3388 |
k = 0; |
| 3389 |
for (j = starti; j < starti + num_cols; j++) { |
| 3390 |
color_array[j][0] = (float)((int *)params[3])[k++] / 255.0f; |
| 3391 |
color_array[j][1] = (float)((int *)params[3])[k++] / 255.0f; |
| 3392 |
color_array[j][2] = (float)((int *)params[3])[k++] / 255.0f; |
| 3393 |
} |
| 3394 |
first = FALSE; |
| 3395 |
} |
| 3396 |
|
| 3397 |
/* mark that the color table has been set */ |
| 3398 |
cur_state->color_set = TRUE; |
| 3399 |
|
| 3400 |
/* update the current state color table */ |
| 3401 |
k = 0; |
| 3402 |
for (j = starti; j < starti + num_cols; j++) { |
| 3403 |
cur_state->color_table[j].r = ((int *)params[3])[k++]; |
| 3404 |
cur_state->color_table[j].g = ((int *)params[3])[k++]; |
| 3405 |
cur_state->color_table[j].b = ((int *)params[3])[k++]; |
| 3406 |
} |
| 3407 |
|
| 3408 |
/* set the SVDI color table */ |
| 3409 |
/* color indices are mapped so that fg and bg colors are |
| 3410 |
* 'reasonable' colors. If the user sets either the fg index |
| 3411 |
* color or bg color index, map those colors so that the |
| 3412 |
* fg and bg colors won't change |
| 3413 |
*/ |
| 3414 |
/* color index mappings: |
| 3415 |
* if set index 0 --> set bg_index |
| 3416 |
* if set index 1 --> set fg_index |
| 3417 |
* if set bg_index --> set 0 |
| 3418 |
* if set fg_index --> set 1 |
| 3419 |
*/ |
| 3420 |
|
| 3421 |
/* set the special cases first */ |
| 3422 |
/* 1. caller setting index 0 - set the background color */ |
| 3423 |
/* --set_background_color() will set color table entry bg_index */ |
| 3424 |
if (starti == 0) { |
| 3425 |
tmp_array[0] = cur_state->color_table[0].r; |
| 3426 |
tmp_array[1] = cur_state->color_table[0].g; |
| 3427 |
tmp_array[2] = cur_state->color_table[0].b; |
| 3428 |
set_background_color(cur_state, tmp_array); |
| 3429 |
} |
| 3430 |
|
| 3431 |
/* 2. caller setting index 1 - set index fg_index */ |
| 3432 |
if (starti <= 1 && (starti + num_cols > 1)) { |
| 3433 |
vdstco(&one, &dev_descrip.index_array[cur_state->fg_index], &color_array[1], |
| 3434 |
&dev_descrip.col_mode); |
| 3435 |
} |
| 3436 |
|
| 3437 |
/* 3. caller setting index bg_index - set index 0 */ |
| 3438 |
if (cur_state->bg_index != 0) { /* .. don't do it twice */ |
| 3439 |
if (starti <= cur_state->bg_index && (starti + num_cols > cur_state->bg_index)) { |
| 3440 |
vdstco(&one, &dev_descrip.index_array[0], &color_array[cur_state->bg_index], |
| 3441 |
&dev_descrip.col_mode); |
| 3442 |
} |
| 3443 |
} |
| 3444 |
|
| 3445 |
/* 4. caller setting index fg_index - set index 1 */ |
| 3446 |
if (cur_state->fg_index != 1) { /* .. don't do it twice */ |
| 3447 |
if (starti <= cur_state->fg_index && (starti + num_cols > cur_state->fg_index)) { |
| 3448 |
vdstco(&one, &dev_descrip.index_array[1], &color_array[cur_state->fg_index], |
| 3449 |
&dev_descrip.col_mode); |
| 3450 |
} |
| 3451 |
} |
| 3452 |
|
| 3453 |
/* now do all the rest */ |
| 3454 |
/* ...sort for convenience */ |
| 3455 |
if (cur_state->fg_index < cur_state->bg_index) { |
| 3456 |
index1 = cur_state->fg_index; |
| 3457 |
index2 = cur_state->bg_index; |
| 3458 |
} |
| 3459 |
else { |
| 3460 |
index1 = cur_state->bg_index; |
| 3461 |
index2 = cur_state->fg_index; |
| 3462 |
} /* end sort */ |
| 3463 |
|
| 3464 |
maxindex = starti + num_cols - 1; |
| 3465 |
indx_ptr = starti; |
| 3466 |
if (indx_ptr < 2) { |
| 3467 |
indx_ptr = 2; |
| 3468 |
} |
| 3469 |
|
| 3470 |
/* 1. set color table between index 1 and index1 */ |
| 3471 |
if (indx_ptr <= 2) { |
| 3472 |
num_set = min(index1 - 2, maxindex - 1); |
| 3473 |
if (num_set > 0) { |
| 3474 |
vdstco(&num_set, &dev_descrip.index_array[2], &color_array[2], &dev_descrip.col_mode); |
| 3475 |
indx_ptr = index1 + 1; |
| 3476 |
} |
| 3477 |
} |
| 3478 |
|
| 3479 |
if (indx_ptr == index1) { /* update indx_ptr */ |
| 3480 |
indx_ptr = indx_ptr + 1; |
| 3481 |
} |
| 3482 |
|
| 3483 |
/* 2. set color table between index1 and index2 */ |
| 3484 |
if (indx_ptr < index2) { |
| 3485 |
num_set = min(index2 - indx_ptr, maxindex - indx_ptr + 1); |
| 3486 |
if (num_set > 0) { |
| 3487 |
vdstco(&num_set, &dev_descrip.index_array[indx_ptr], &color_array[indx_ptr], |
| 3488 |
&dev_descrip.col_mode); |
| 3489 |
indx_ptr = index2 + 1; |
| 3490 |
} |
| 3491 |
} |
| 3492 |
|
| 3493 |
if (indx_ptr == index2) { /* update indx_ptr */ |
| 3494 |
indx_ptr = indx_ptr + 1; |
| 3495 |
} |
| 3496 |
|
| 3497 |
/* 3. set color table after index 2 */ |
| 3498 |
if (indx_ptr >= index2 + 1) { |
| 3499 |
num_set = maxindex - indx_ptr + 1; |
| 3500 |
if (num_set > 0) { |
| 3501 |
vdstco(&num_set, &dev_descrip.index_array[indx_ptr], &color_array[indx_ptr], |
| 3502 |
&dev_descrip.col_mode); |
| 3503 |
} |
| 3504 |
} |
| 3505 |
} /* end for each surface */ |
| 3506 |
} /* end xcct */ |
| 3507 |
|
| 3508 |
/* GET TEXT EXTENT */ |
| 3509 |
static void xcgtxx(anything **params, anything **surf_list) |
| 3510 |
{ |
| 3511 |
float act_h, act_w; /* actual char height and width (VDC) */ |
| 3512 |
float x1, y1, x2; /* parrallelogram parts */ |
| 3513 |
float save, temp_h; /* temporary variables */ |
| 3514 |
float temp_array[14]; /* temp array used for SVDI inquires */ |
| 3515 |
|
| 3516 |
/* there is only one surface for inquiries */ |
| 3517 |
cur_state = (surf_statelist *)surf_list[0]; |
| 3518 |
if (cur_state->cgi_inited != CYES) { |
| 3519 |
return; |
| 3520 |
} |
| 3521 |
|
| 3522 |
/* find out actual height and width from SVDI for this size */ |
| 3523 |
/* ..save the old value */ |
| 3524 |
vdiqos(&temp_array[1]); |
| 3525 |
save = temp_array[6]; |
| 3526 |
|
| 3527 |
/* ..set current height value */ |
| 3528 |
temp_h = cur_state->char_height * fabs(cur_state->xscale); |
| 3529 |
vdstcs(&temp_h); |
| 3530 |
|
| 3531 |
/* ..find out actual height and width */ |
| 3532 |
vdiqos(&temp_array[1]); |
| 3533 |
act_h = temp_array[6] / fabs(cur_state->xscale); |
| 3534 |
act_w = temp_array[7] / fabs(cur_state->xscale); |
| 3535 |
|
| 3536 |
/* set it back to original */ |
| 3537 |
vdstcs(&save); |
| 3538 |
|
| 3539 |
/* parallelogram */ |
| 3540 |
/* x1, y1 = bottom left corner of string */ |
| 3541 |
x1 = *(float *)params[1]; |
| 3542 |
y1 = *(float *)params[2]; |
| 3543 |
*(float *)params[8] = x1; |
| 3544 |
*(float *)params[9] = y1; |
| 3545 |
|
| 3546 |
/* x2, y2 = bottom right corner of string */ |
| 3547 |
/* params[4] is an added parameter that contains string size */ |
| 3548 |
x2 = x1 + (*(int *)params[16] * act_w); |
| 3549 |
*(float *)params[10] = x2; |
| 3550 |
*(float *)params[11] = y1; |
| 3551 |
|
| 3552 |
/* x3, y3 = top right corner of string ( x3 = x2 )*/ |
| 3553 |
*(float *)params[12] = x2; |
| 3554 |
*(float *)params[13] = y1 + act_h; |
| 3555 |
|
| 3556 |
/* x4, y4 = top left corner of string ( y4 = y3 )*/ |
| 3557 |
*(float *)params[14] = x1; |
| 3558 |
*(float *)params[15] = y1 + act_h; |
| 3559 |
|
| 3560 |
/* concatenation point is bottom right corner ( x2, y2 )*/ |
| 3561 |
*(float *)params[6] = x2; |
| 3562 |
*(float *)params[7] = y1; |
| 3563 |
|
| 3564 |
/* validity flags */ |
| 3565 |
*(int *)params[4] = CVAL; |
| 3566 |
*(int *)params[5] = CVAL; |
| 3567 |
|
| 3568 |
} /* end xcgtxx */ |
| 3569 |
|
| 3570 |
/* INQUIRE PRIMITIVE SUPPORT LEVELS */ |
| 3571 |
static void xcqprl(anything **params, anything **surf_list) |
| 3572 |
{ |
| 3573 |
int qdc_index = 25; /* index for inquiries to vdiqdc */ |
| 3574 |
float value; /* value returned by vdiqdc */ |
| 3575 |
static int set = FALSE; /* flag whether values have been set */ |
| 3576 |
|
| 3577 |
/* there is only one surface for inquiries */ |
| 3578 |
cur_state = (surf_statelist *)surf_list[0]; |
| 3579 |
if (cur_state->cgi_inited != CYES) { |
| 3580 |
return; |
| 3581 |
} |
| 3582 |
|
| 3583 |
if (!set) { /* values have't been set, inquire SVDI */ |
| 3584 |
|
| 3585 |
set = TRUE; |
| 3586 |
|
| 3587 |
/* max points for a polyline */ |
| 3588 |
dev_descrip.max_pts_polyline = MAX_POLYLINE; |
| 3589 |
|
| 3590 |
/* max points for a disjoint polyline */ |
| 3591 |
dev_descrip.max_pts_disj_polyline = MAX_DJ_POLYLINE; |
| 3592 |
|
| 3593 |
/* max points for a polygon */ |
| 3594 |
vdiqdc(&qdc_index, &value); |
| 3595 |
dev_descrip.max_pts_polygon = (value == 99999.) ? MAX_POLYGON : min((int)value, MAX_POLYGON); |
| 3596 |
|
| 3597 |
/* max points for a polygon set */ |
| 3598 |
/* --not supported */ |
| 3599 |
dev_descrip.max_pts_polygon_set = 0; |
| 3600 |
|
| 3601 |
/* max points for a polymarker */ |
| 3602 |
dev_descrip.max_pts_polymarker = MAX_POLYMARKER; |
| 3603 |
|
| 3604 |
/* max number of points for a closed figure */ |
| 3605 |
/* --not supported */ |
| 3606 |
dev_descrip.max_pts_closed_fig = 0; |
| 3607 |
|
| 3608 |
/* max characters of text */ |
| 3609 |
dev_descrip.max_chars_text = MAX_TEXT_LENGTH; |
| 3610 |
|
| 3611 |
/* max number of cell color specifiers for cell array */ |
| 3612 |
dev_descrip.max_pts_cellarray = -1; |
| 3613 |
|
| 3614 |
/* cell array fill capability */ |
| 3615 |
dev_descrip.cellarray_fill_cap = CFILLD; |
| 3616 |
|
| 3617 |
/* cell array alignment */ |
| 3618 |
dev_descrip.cellarray_align_cap = CAXIS; |
| 3619 |
|
| 3620 |
/* compound text capability */ |
| 3621 |
dev_descrip.compound_text_cap = CCNONE; |
| 3622 |
|
| 3623 |
/* closed figure capability */ |
| 3624 |
dev_descrip.compound_fig_cap = CCNONE; |
| 3625 |
|
| 3626 |
} /* end if not set */ |
| 3627 |
|
| 3628 |
/* validity flag */ |
| 3629 |
*(int *)params[1] = CVAL; |
| 3630 |
|
| 3631 |
/* stuff all the values into the return parameters */ |
| 3632 |
*(int *)params[2] = dev_descrip.max_pts_polyline; |
| 3633 |
*(int *)params[3] = dev_descrip.max_pts_disj_polyline; |
| 3634 |
*(int *)params[4] = dev_descrip.max_pts_polygon; |
| 3635 |
*(int *)params[5] = dev_descrip.max_pts_polygon_set; |
| 3636 |
*(int *)params[6] = dev_descrip.max_pts_polymarker; |
| 3637 |
*(int *)params[7] = dev_descrip.max_pts_closed_fig; |
| 3638 |
*(int *)params[8] = dev_descrip.max_chars_text; |
| 3639 |
*(int *)params[9] = dev_descrip.max_pts_cellarray; |
| 3640 |
*(int *)params[10] = dev_descrip.cellarray_fill_cap; |
| 3641 |
*(int *)params[11] = dev_descrip.cellarray_align_cap; |
| 3642 |
*(int *)params[12] = dev_descrip.compound_text_cap; |
| 3643 |
*(int *)params[13] = dev_descrip.compound_fig_cap; |
| 3644 |
|
| 3645 |
} /* end xcqprl */ |
| 3646 |
|
| 3647 |
/* INQUIRE LINE CAPABILITY */ |
| 3648 |
static void xcqln(anything **params, anything **surf_list) |
| 3649 |
{ |
| 3650 |
|
| 3651 |
/* there is only one surface for inquiries */ |
| 3652 |
cur_state = (surf_statelist *)surf_list[0]; |
| 3653 |
if (cur_state->cgi_inited != CYES) { |
| 3654 |
return; |
| 3655 |
} |
| 3656 |
|
| 3657 |
/* set the validity flag */ |
| 3658 |
*(int *)params[1] = CVAL; |
| 3659 |
|
| 3660 |
/* number of predefined line bundles - bundles not supported */ |
| 3661 |
*(int *)params[2] = 0; |
| 3662 |
|
| 3663 |
/* number of settable line bundles - bundles not supported */ |
| 3664 |
*(int *)params[3] = 0; |
| 3665 |
|
| 3666 |
/* max line bundle index - bundles not supported */ |
| 3667 |
*(int *)params[4] = 0; |
| 3668 |
|
| 3669 |
/* dynamic modification for line bundles- bundles not supported */ |
| 3670 |
*(int *)params[5] = 0; |
| 3671 |
|
| 3672 |
/* nom, min, max, get set in set_dev_descrip() at initialization */ |
| 3673 |
*(int *)params[6] = dev_descrip.linewidth_nominal; |
| 3674 |
*(int *)params[7] = dev_descrip.linewidth_min; |
| 3675 |
*(int *)params[8] = dev_descrip.linewidth_max; |
| 3676 |
|
| 3677 |
} /* end xcqln */ |
| 3678 |
|
| 3679 |
/* INQUIRE LIST OF AVAILABLE LINE TYPES */ |
| 3680 |
static void xcqlnt(anything **params, anything **surf_list) |
| 3681 |
{ |
| 3682 |
int i, j; /* loop indices */ |
| 3683 |
int qdc_index = 6; /* index for inquiries to vdiqdc */ |
| 3684 |
float value; /* value returned by vdiqdc */ |
| 3685 |
static int set = FALSE; /* flag whether values have been set */ |
| 3686 |
static int ntotal; /* save total nbr of linestyles */ |
| 3687 |
|
| 3688 |
static unsigned mask = ~(~0u << 1); |
| 3689 |
|
| 3690 |
/* there is only one surface for inquiries */ |
| 3691 |
cur_state = (surf_statelist *)surf_list[0]; |
| 3692 |
if (cur_state->cgi_inited != CYES) { |
| 3693 |
return; |
| 3694 |
} |
| 3695 |
|
| 3696 |
if (!set) { /* values have't been set, inquire SVDI */ |
| 3697 |
|
| 3698 |
set = TRUE; |
| 3699 |
|
| 3700 |
/* inquire supported linestyles from SVDI */ |
| 3701 |
vdiqdc(&qdc_index, &value); |
| 3702 |
|
| 3703 |
/* SVDI always supports linestyle 0 */ |
| 3704 |
ntotal = 0; |
| 3705 |
dev_descrip.line_types[ntotal++] = 0; |
| 3706 |
|
| 3707 |
/* find all SVDI linestyles supported by looking at bits */ |
| 3708 |
for (i = 0; i < 5; i++) { |
| 3709 |
if (((int)value & mask << i) >> i == 1) { |
| 3710 |
dev_descrip.line_types[ntotal++] = i + 1; |
| 3711 |
} |
| 3712 |
} |
| 3713 |
/* map to CGI linestyles */ |
| 3714 |
/* cgi linestyles: 1 - solid 2 - dash 3 - dot, |
| 3715 |
* 4 - dashdot 5 - dash dot dot |
| 3716 |
* vdi linestyles: 0 - solid 1 - dotted 2 - dot dash |
| 3717 |
* 3 - short dash 4 - long dash 5 - medium dash |
| 3718 |
*/ |
| 3719 |
for (i = 0; i < ntotal; i++) { |
| 3720 |
switch (dev_descrip.line_types[i]) { |
| 3721 |
case 0: dev_descrip.line_types[i] = 1; break; |
| 3722 |
case 1: dev_descrip.line_types[i] = 3; break; |
| 3723 |
case 2: dev_descrip.line_types[i] = 4; break; |
| 3724 |
/* ...all SVDI dashes map to cgi dash */ |
| 3725 |
case 3: dev_descrip.line_types[i] = 2; break; |
| 3726 |
case 4: dev_descrip.line_types[i] = 2; break; |
| 3727 |
case 5: dev_descrip.line_types[i] = 2; break; |
| 3728 |
default: break; |
| 3729 |
} /* end switch */ |
| 3730 |
} |
| 3731 |
|
| 3732 |
/* take out duplicates */ |
| 3733 |
for (i = 0; i < ntotal; i++) { |
| 3734 |
if (dev_descrip.line_types[i] == 2) { |
| 3735 |
break; |
| 3736 |
} |
| 3737 |
ntotal = i + 1; |
| 3738 |
} |
| 3739 |
} /* end if not set */ |
| 3740 |
|
| 3741 |
/* set the total */ |
| 3742 |
*(int *)params[4] = ntotal; |
| 3743 |
|
| 3744 |
/* do some error checking */ |
| 3745 |
if (*(int *)params[2] < 1) { |
| 3746 |
/* error - set validity flag to invalid */ |
| 3747 |
*(int *)params[3] = CINVAL; |
| 3748 |
} |
| 3749 |
else { /* send back only the ones requested - zero out the rest */ |
| 3750 |
|
| 3751 |
i = *(int *)params[2] - 1; |
| 3752 |
j = 0; |
| 3753 |
*(int *)params[5] = 0; /* actual number of list elements sent back */ |
| 3754 |
while (j < ntotal) { |
| 3755 |
if (j < *(int *)params[1] && i < ntotal) { |
| 3756 |
((int *)params[6])[j++] = dev_descrip.line_types[i++]; |
| 3757 |
(*(int *)params[5])++; |
| 3758 |
} |
| 3759 |
else { |
| 3760 |
((int *)params[6])[j++] = 0; |
| 3761 |
} |
| 3762 |
} |
| 3763 |
/* set validity flag */ |
| 3764 |
*(int *)params[3] = CVAL; |
| 3765 |
} /* end else send back */ |
| 3766 |
|
| 3767 |
} /* end xcqlnt */ |
| 3768 |
|
| 3769 |
/* INQUIRE LIST OF AVAILABLE SCALED LINE WIDTHS */ |
| 3770 |
static void xcqslw(anything **params, anything **surf_list) |
| 3771 |
{ |
| 3772 |
int qdc_index = 5; /* index for inquiries to vdiqdc */ |
| 3773 |
float value; /* value returned by vdiqdc */ |
| 3774 |
static int set = FALSE; /* flag whether values have been set */ |
| 3775 |
static int ntotal; /* save total nbr of linewidths */ |
| 3776 |
|
| 3777 |
/* there is only one surface for inquiries */ |
| 3778 |
cur_state = (surf_statelist *)surf_list[0]; |
| 3779 |
if (cur_state->cgi_inited != CYES) { |
| 3780 |
return; |
| 3781 |
} |
| 3782 |
|
| 3783 |
if (!set) { /* values have't been set, inquire SVDI */ |
| 3784 |
|
| 3785 |
set = TRUE; |
| 3786 |
|
| 3787 |
/* number of linewidths available */ |
| 3788 |
vdiqdc(&qdc_index, &value); |
| 3789 |
ntotal = (int)value; |
| 3790 |
|
| 3791 |
} /* end if not set */ |
| 3792 |
|
| 3793 |
/* validity flag */ |
| 3794 |
*(int *)params[3] = CVAL; |
| 3795 |
*(int *)params[4] = ntotal; |
| 3796 |
|
| 3797 |
/* nlist = 0 means empty list ( continuous range ) */ |
| 3798 |
/* --leave list (params[6]) untouched */ |
| 3799 |
*(int *)params[5] = 0; |
| 3800 |
|
| 3801 |
} /* end xcqslw */ |
| 3802 |
|
| 3803 |
/* INQUIRE MARKER CAPABILITY */ |
| 3804 |
static void xcqmk(anything **params, anything **surf_list) |
| 3805 |
{ |
| 3806 |
/* there is only one surface for inquiries */ |
| 3807 |
cur_state = (surf_statelist *)surf_list[0]; |
| 3808 |
if (cur_state->cgi_inited != CYES) { |
| 3809 |
return; |
| 3810 |
} |
| 3811 |
|
| 3812 |
/* set the validity flag */ |
| 3813 |
*(int *)params[1] = CVAL; |
| 3814 |
|
| 3815 |
/* number of predefined marker bundles - bundles not supported */ |
| 3816 |
*(int *)params[2] = 0; |
| 3817 |
|
| 3818 |
/* number of settable marker bundles - bundles not supported */ |
| 3819 |
*(int *)params[3] = 0; |
| 3820 |
|
| 3821 |
/* max marker bundle index - bundles not supported */ |
| 3822 |
*(int *)params[4] = 0; |
| 3823 |
|
| 3824 |
/* dynamic modification for marker bundles- bundles not supported */ |
| 3825 |
*(int *)params[5] = 0; |
| 3826 |
|
| 3827 |
/* nom, min, max, get set in set_dev_descrip() at initialization */ |
| 3828 |
*(int *)params[6] = dev_descrip.mark_nominal; |
| 3829 |
*(int *)params[7] = dev_descrip.mark_min; |
| 3830 |
*(int *)params[8] = dev_descrip.mark_max; |
| 3831 |
|
| 3832 |
} /* end xcqmk */ |
| 3833 |
|
| 3834 |
/* INQUIRE LIST OF AVAILABLE MARKER TYPES */ |
| 3835 |
static void xcqmkt(anything **params, anything **surf_list) |
| 3836 |
{ |
| 3837 |
static int set = FALSE; /* flag whether values have been set */ |
| 3838 |
static int ntotal; /* save total nbr of linestyles */ |
| 3839 |
|
| 3840 |
/* there is only one surface for inquiries */ |
| 3841 |
cur_state = (surf_statelist *)surf_list[0]; |
| 3842 |
if (cur_state->cgi_inited != CYES) { |
| 3843 |
return; |
| 3844 |
} |
| 3845 |
|
| 3846 |
if (!set) { /* values have't been set, inquire SVDI */ |
| 3847 |
|
| 3848 |
set = TRUE; |
| 3849 |
|
| 3850 |
/* SVDI only supports 1 marker type - "dot" */ |
| 3851 |
ntotal = 1; |
| 3852 |
dev_descrip.mark_types[0] = 1; |
| 3853 |
|
| 3854 |
} /* end if not set */ |
| 3855 |
|
| 3856 |
/* set validity flag */ |
| 3857 |
*(int *)params[3] = CVAL; |
| 3858 |
|
| 3859 |
*(int *)params[4] = ntotal; |
| 3860 |
|
| 3861 |
if (*(int *)params[1] > 0) { |
| 3862 |
*(int *)params[5] = 1; |
| 3863 |
((int *)params[6])[0] = dev_descrip.mark_types[0]; |
| 3864 |
} |
| 3865 |
else { |
| 3866 |
*(int *)params[5] = 0; |
| 3867 |
} |
| 3868 |
|
| 3869 |
} /* end xcqmkt */ |
| 3870 |
|
| 3871 |
/* INQUIRE LIST OF AVAILABLE SCALED MARKER SIZES */ |
| 3872 |
static void xcqsms(anything **params, anything **surf_list) |
| 3873 |
{ |
| 3874 |
/* there is only one surface for inquiries */ |
| 3875 |
cur_state = (surf_statelist *)surf_list[0]; |
| 3876 |
if (cur_state->cgi_inited != CYES) { |
| 3877 |
return; |
| 3878 |
} |
| 3879 |
|
| 3880 |
/* validity flag */ |
| 3881 |
*(int *)params[3] = CVAL; |
| 3882 |
|
| 3883 |
/* there is only 1 size */ |
| 3884 |
*(int *)params[4] = 1; |
| 3885 |
*(int *)params[5] = 1; |
| 3886 |
((int *)params[6])[0] = dev_descrip.mark_nominal; |
| 3887 |
|
| 3888 |
} /* end xcqsms */ |
| 3889 |
|
| 3890 |
/* INQUIRE LIST OF AVAILABLE CHARACTER HEIGHTS */ |
| 3891 |
static void xcqchh(anything **params, anything **surf_list) |
| 3892 |
{ |
| 3893 |
int qdc_index = 7; /* index for inquiries to vdiqdc */ |
| 3894 |
float value; /* value returned by vdiqdc */ |
| 3895 |
static int set = FALSE; /* flag whether values have been set */ |
| 3896 |
static int ntotal; /* save total nbr of char heights */ |
| 3897 |
|
| 3898 |
/* there is only one surface for inquiries */ |
| 3899 |
cur_state = (surf_statelist *)surf_list[0]; |
| 3900 |
if (cur_state->cgi_inited != CYES) { |
| 3901 |
return; |
| 3902 |
} |
| 3903 |
|
| 3904 |
if (!set) { /* values have't been set, inquire SVDI */ |
| 3905 |
|
| 3906 |
set = TRUE; |
| 3907 |
|
| 3908 |
/* number of char sizes */ |
| 3909 |
vdiqdc(&qdc_index, &value); |
| 3910 |
ntotal = (int)value; |
| 3911 |
|
| 3912 |
} /* end if not set */ |
| 3913 |
|
| 3914 |
/* font - SRCP does not support multiple fonts; use null string */ |
| 3915 |
/* I don't check for font, anything goes */ |
| 3916 |
|
| 3917 |
/* only string precision is supported */ |
| 3918 |
if (*(int *)params[2] == CSTRNG) { |
| 3919 |
|
| 3920 |
/* total number of character heights */ |
| 3921 |
*(int *)params[6] = ntotal; |
| 3922 |
|
| 3923 |
/* set nlist = 0 means empty list ( continuous range ) */ |
| 3924 |
/* --leave list (params[8]) untouched */ |
| 3925 |
*(int *)params[7] = 0; |
| 3926 |
|
| 3927 |
/* validity flag */ |
| 3928 |
*(int *)params[5] = CVAL; |
| 3929 |
} /* end if */ |
| 3930 |
|
| 3931 |
else { |
| 3932 |
*(int *)params[5] = CINVAL; |
| 3933 |
} |
| 3934 |
|
| 3935 |
} /* end xcqchh */ |
| 3936 |
|
| 3937 |
/* INQUIRE FILL CAPABILITY */ |
| 3938 |
static void xcqfl(anything **params, anything **surf_list) |
| 3939 |
{ |
| 3940 |
static int set = FALSE; /* flag whether values have been set */ |
| 3941 |
static int ntotal; /* save total nbr of fill styles */ |
| 3942 |
|
| 3943 |
/* there is only one surface for inquiries */ |
| 3944 |
cur_state = (surf_statelist *)surf_list[0]; |
| 3945 |
if (cur_state->cgi_inited != CYES) { |
| 3946 |
return; |
| 3947 |
} |
| 3948 |
|
| 3949 |
if (!set) { /* values have't been set */ |
| 3950 |
|
| 3951 |
set = TRUE; |
| 3952 |
|
| 3953 |
ntotal = 2; |
| 3954 |
dev_descrip.interior_styles[0] = CHOLLO; |
| 3955 |
dev_descrip.interior_styles[1] = CSOLID; |
| 3956 |
|
| 3957 |
} /* end if not set */ |
| 3958 |
|
| 3959 |
/* set the validity flag */ |
| 3960 |
*(int *)params[1] = CVAL; |
| 3961 |
|
| 3962 |
/* number of predefined fill bundles - bundles not supported */ |
| 3963 |
*(int *)params[2] = 0; |
| 3964 |
|
| 3965 |
/* number of settable fill bundles - bundles not supported */ |
| 3966 |
*(int *)params[3] = 0; |
| 3967 |
|
| 3968 |
/* max fill bundle index - bundles not supported */ |
| 3969 |
*(int *)params[4] = 0; |
| 3970 |
|
| 3971 |
/* dynamic modification for fill bundles- bundles not supported */ |
| 3972 |
*(int *)params[5] = 0; |
| 3973 |
|
| 3974 |
/* interior styles */ |
| 3975 |
*(int *)params[6] = ntotal; |
| 3976 |
((int *)params[7])[0] = dev_descrip.interior_styles[0]; |
| 3977 |
((int *)params[7])[1] = dev_descrip.interior_styles[1]; |
| 3978 |
|
| 3979 |
/* number of predefined patterns - patterns not supported */ |
| 3980 |
*(int *)params[8] = 0; |
| 3981 |
|
| 3982 |
/* number of settable patterns - patterns not supported */ |
| 3983 |
*(int *)params[9] = 0; |
| 3984 |
|
| 3985 |
/* maximum pattern index - patterns not supported */ |
| 3986 |
*(int *)params[10] = 0; |
| 3987 |
|
| 3988 |
/* preferred pattern size divisor - patterns not supported */ |
| 3989 |
*(int *)params[11] = 0; |
| 3990 |
|
| 3991 |
/* maximum pattern size - patterns not supported */ |
| 3992 |
*(int *)params[12] = 0; |
| 3993 |
*(int *)params[13] = 0; |
| 3994 |
|
| 3995 |
/* pattern transformation support - patterns not supported */ |
| 3996 |
*(int *)params[14] = CPTNO; |
| 3997 |
|
| 3998 |
} /* end xcqfl */ |
| 3999 |
|
| 4000 |
/* INQUIRE COLOR CAPABILITIES */ |
| 4001 |
static void xcqc(anything **params, anything **surf_list) |
| 4002 |
{ |
| 4003 |
int qdc_index; /* index for inquiries to vdiqdc */ |
| 4004 |
float value; /* value returned by vdiqdc */ |
| 4005 |
static int set = FALSE; /* flag whether values have been set */ |
| 4006 |
|
| 4007 |
/* there is only one surface for inquiries */ |
| 4008 |
cur_state = (surf_statelist *)surf_list[0]; |
| 4009 |
if (cur_state->cgi_inited != CYES) { |
| 4010 |
return; |
| 4011 |
} |
| 4012 |
|
| 4013 |
if (!set) { /* values have't been set, inquire SVDI */ |
| 4014 |
|
| 4015 |
set = TRUE; |
| 4016 |
|
| 4017 |
/* number of simultaneous colors */ |
| 4018 |
dev_descrip.num_simul_colors = dev_descrip.num_cols; |
| 4019 |
|
| 4020 |
/* number of available colors */ |
| 4021 |
qdc_index = 27; |
| 4022 |
vdiqdc(&qdc_index, &value); |
| 4023 |
dev_descrip.num_avail_colors = (int)value; |
| 4024 |
|
| 4025 |
/* number of available intensities */ |
| 4026 |
/* --see 7.1.4 about direct color */ |
| 4027 |
qdc_index = 3; |
| 4028 |
vdiqdc(&qdc_index, &value); |
| 4029 |
dev_descrip.num_avail_int = (int)value; |
| 4030 |
|
| 4031 |
/* dynamic modification accepted for color table */ |
| 4032 |
dev_descrip.dynamic_mod_ct = CIRG; |
| 4033 |
|
| 4034 |
/* color overwrite capability */ |
| 4035 |
/* --what is the answer?? */ |
| 4036 |
/* dev_descrip. color_overwrite = ??; */ |
| 4037 |
|
| 4038 |
/* monochromatic device */ |
| 4039 |
qdc_index = 32; |
| 4040 |
vdiqdc(&qdc_index, &value); |
| 4041 |
dev_descrip.monochrome_device = (value == 0.0) ? CYES : CNO; |
| 4042 |
|
| 4043 |
} /* end not set */ |
| 4044 |
|
| 4045 |
/* validity flag */ |
| 4046 |
*(int *)params[1] = CVAL; |
| 4047 |
|
| 4048 |
/* return the answers */ |
| 4049 |
*(int *)params[2] = dev_descrip.num_simul_colors; |
| 4050 |
*(int *)params[3] = dev_descrip.num_avail_colors; |
| 4051 |
((int *)params[4])[0] = dev_descrip.num_avail_int; |
| 4052 |
*(int *)params[5] = dev_descrip.csm_avail; /* set in set_dev_descrip()*/ |
| 4053 |
*(int *)params[6] = dev_descrip.dynamic_mod_ct; |
| 4054 |
*(int *)params[7] = dev_descrip.color_overwrite; |
| 4055 |
*(int *)params[8] = dev_descrip.monochrome_device; |
| 4056 |
|
| 4057 |
} /* end xcqc */ |
| 4058 |
|
| 4059 |
/* INQUIRE LINE ATTRIBUTES */ |
| 4060 |
static void xcqlna(anything **params, anything **surf_list) |
| 4061 |
{ |
| 4062 |
|
| 4063 |
/* there is only one surface for inquiries */ |
| 4064 |
cur_state = (surf_statelist *)surf_list[0]; |
| 4065 |
if (cur_state->cgi_inited != CYES) { |
| 4066 |
return; |
| 4067 |
} |
| 4068 |
|
| 4069 |
/* validity flag */ |
| 4070 |
*(int *)params[1] = CVAL; |
| 4071 |
|
| 4072 |
/* line bundle index - bundles not supported */ |
| 4073 |
*(int *)params[2] = 0; |
| 4074 |
|
| 4075 |
/* line type */ |
| 4076 |
*(int *)params[3] = cur_state->line_type; |
| 4077 |
|
| 4078 |
/* line width specification mode - only support scaled */ |
| 4079 |
*(int *)params[4] = CSCA; |
| 4080 |
|
| 4081 |
/* line width */ |
| 4082 |
*(float *)params[5] = cur_state->line_width; |
| 4083 |
|
| 4084 |
/* color selection mode in which line color was last specified */ |
| 4085 |
*(int *)params[6] = cur_state->line_csm; |
| 4086 |
|
| 4087 |
/* line color in color selection mode last specified */ |
| 4088 |
((int *)params[7])[0] = cur_state->line_color[0]; |
| 4089 |
if (cur_state->line_csm == CDRECT) { |
| 4090 |
((int *)params[7])[1] = cur_state->line_color[1]; |
| 4091 |
((int *)params[7])[2] = cur_state->line_color[2]; |
| 4092 |
} |
| 4093 |
|
| 4094 |
/* line clipping mode */ |
| 4095 |
*(int *)params[8] = CLOCUS; |
| 4096 |
|
| 4097 |
} /* end xcqlna */ |
| 4098 |
|
| 4099 |
/* INQUIRE MARKER ATTRIBUTES */ |
| 4100 |
static void xcqmka(anything **params, anything **surf_list) |
| 4101 |
{ |
| 4102 |
|
| 4103 |
/* there is only one surface for inquiries */ |
| 4104 |
cur_state = (surf_statelist *)surf_list[0]; |
| 4105 |
if (cur_state->cgi_inited != CYES) { |
| 4106 |
return; |
| 4107 |
} |
| 4108 |
|
| 4109 |
/* validity flag */ |
| 4110 |
*(int *)params[1] = CVAL; |
| 4111 |
|
| 4112 |
/* marker bundle index - bundles not supported */ |
| 4113 |
*(int *)params[2] = 0; |
| 4114 |
|
| 4115 |
/* marker type */ |
| 4116 |
*(int *)params[3] = cur_state->mark_type; |
| 4117 |
|
| 4118 |
/* marker size specification mode - only support scaled */ |
| 4119 |
*(int *)params[4] = CSCA; |
| 4120 |
|
| 4121 |
/* marker size */ |
| 4122 |
*(float *)params[5] = cur_state->mark_size; |
| 4123 |
|
| 4124 |
/* color selection mode in which marker color was last specified */ |
| 4125 |
*(int *)params[6] = cur_state->mark_csm; |
| 4126 |
|
| 4127 |
/* marker color in color selection mode last specified */ |
| 4128 |
((int *)params[7])[0] = cur_state->mark_color[0]; |
| 4129 |
if (cur_state->mark_csm == CDRECT) { |
| 4130 |
((int *)params[7])[1] = cur_state->mark_color[1]; |
| 4131 |
((int *)params[7])[2] = cur_state->mark_color[2]; |
| 4132 |
} |
| 4133 |
|
| 4134 |
/* marker clipping mode */ |
| 4135 |
*(int *)params[8] = CLOCUS; |
| 4136 |
|
| 4137 |
} /* end xcqmka */ |
| 4138 |
|
| 4139 |
/* INQUIRE TEXT ATTRIBUTES */ |
| 4140 |
static void xcqtxa(anything **params, anything **surf_list) |
| 4141 |
{ |
| 4142 |
|
| 4143 |
/* there is only one surface for inquiries */ |
| 4144 |
cur_state = (surf_statelist *)surf_list[0]; |
| 4145 |
if (cur_state->cgi_inited != CYES) { |
| 4146 |
return; |
| 4147 |
} |
| 4148 |
|
| 4149 |
/* validity flag */ |
| 4150 |
*(int *)params[1] = CVAL; |
| 4151 |
|
| 4152 |
/* text bundle index - bundles not supported */ |
| 4153 |
*(int *)params[2] = 0; |
| 4154 |
|
| 4155 |
/* font index - only the default font is supported */ |
| 4156 |
*(int *)params[3] = 1; |
| 4157 |
|
| 4158 |
/* font precision */ |
| 4159 |
*(int *)params[4] = CSTRNG; |
| 4160 |
|
| 4161 |
/* character expansion factor */ |
| 4162 |
*(float *)params[5] = 1.0; |
| 4163 |
|
| 4164 |
/* character spacing */ |
| 4165 |
*(float *)params[6] = 0.0; |
| 4166 |
|
| 4167 |
/* color selection mode in which text color was last specified */ |
| 4168 |
*(int *)params[7] = cur_state->text_csm; |
| 4169 |
|
| 4170 |
/* text color in color selection mode last specified */ |
| 4171 |
((int *)params[8])[0] = cur_state->text_color[0]; |
| 4172 |
if (cur_state->text_csm == CDRECT) { |
| 4173 |
((int *)params[8])[1] = cur_state->text_color[1]; |
| 4174 |
((int *)params[8])[2] = cur_state->text_color[2]; |
| 4175 |
} |
| 4176 |
|
| 4177 |
/* character height */ |
| 4178 |
*(float *)params[9] = cur_state->char_height; |
| 4179 |
|
| 4180 |
/* character orientation */ |
| 4181 |
((float *)params[10])[0] = 0.; |
| 4182 |
((float *)params[10])[1] = 1.; |
| 4183 |
((float *)params[10])[2] = 1.; |
| 4184 |
((float *)params[10])[3] = 0.; |
| 4185 |
|
| 4186 |
/* text path */ |
| 4187 |
*(int *)params[11] = CTPRIT; |
| 4188 |
|
| 4189 |
/* horizontal alignment */ |
| 4190 |
*(int *)params[12] = CTANH; |
| 4191 |
|
| 4192 |
/* continuous horizontal alignment */ |
| 4193 |
*(float *)params[13] = 1.0; |
| 4194 |
|
| 4195 |
/* vertical alignment */ |
| 4196 |
*(int *)params[14] = CTANV; |
| 4197 |
|
| 4198 |
/* continuous horizontal alignment */ |
| 4199 |
*(float *)params[15] = 1.0; |
| 4200 |
|
| 4201 |
/* character set index ?? */ |
| 4202 |
*(int *)params[16] = 1; |
| 4203 |
|
| 4204 |
/* alternate character set index ?? */ |
| 4205 |
*(int *)params[17] = 1; |
| 4206 |
|
| 4207 |
} /* end xcqtxa */ |
| 4208 |
|
| 4209 |
/* INQUIRE FILL ATTRIBUTES */ |
| 4210 |
static void xcqfla(anything **params, anything **surf_list) |
| 4211 |
{ |
| 4212 |
|
| 4213 |
/* there is only one surface for inquiries */ |
| 4214 |
cur_state = (surf_statelist *)surf_list[0]; |
| 4215 |
if (cur_state->cgi_inited != CYES) { |
| 4216 |
return; |
| 4217 |
} |
| 4218 |
|
| 4219 |
/* validity flag */ |
| 4220 |
*(int *)params[1] = CVAL; |
| 4221 |
|
| 4222 |
/* fill bundle index - bundles not supported */ |
| 4223 |
*(int *)params[2] = 0; |
| 4224 |
|
| 4225 |
/* interior style */ |
| 4226 |
*(int *)params[3] = cur_state->interior_style; |
| 4227 |
|
| 4228 |
/* color selection mode in which fill color was last specified */ |
| 4229 |
*(int *)params[4] = cur_state->fill_csm; |
| 4230 |
|
| 4231 |
/* fill color in color selection mode last specified */ |
| 4232 |
((int *)params[5])[0] = cur_state->fill_color[0]; |
| 4233 |
if (cur_state->fill_csm == CDRECT) { |
| 4234 |
((int *)params[5])[1] = cur_state->fill_color[1]; |
| 4235 |
((int *)params[5])[2] = cur_state->fill_color[2]; |
| 4236 |
} |
| 4237 |
|
| 4238 |
/* hatch index - not supported */ |
| 4239 |
*(int *)params[6] = 0; |
| 4240 |
|
| 4241 |
/* pattern index - not supported */ |
| 4242 |
*(int *)params[7] = 0; |
| 4243 |
|
| 4244 |
/* --i don't know what any of the following means */ |
| 4245 |
/* fill bitmap identifier */ |
| 4246 |
*(int *)params[8] = 0; |
| 4247 |
|
| 4248 |
/* fill bitmap region */ |
| 4249 |
*(float *)params[9] = 0.; |
| 4250 |
*(float *)params[10] = 0.; |
| 4251 |
*(float *)params[11] = 0.; |
| 4252 |
*(float *)params[12] = 0.; |
| 4253 |
|
| 4254 |
/* fill reference point */ |
| 4255 |
*(float *)params[13] = 0.; |
| 4256 |
*(float *)params[14] = 0.; |
| 4257 |
|
| 4258 |
/* pattern orientation and size */ |
| 4259 |
*(float *)params[15] = 0.; |
| 4260 |
*(float *)params[16] = 0.; |
| 4261 |
*(float *)params[17] = 0.; |
| 4262 |
*(float *)params[18] = 0.; |
| 4263 |
|
| 4264 |
} /* end xcqfla */ |
| 4265 |
|
| 4266 |
/* INQUIRE LIST OF COLOR TABLE ENTRIES */ |
| 4267 |
static void xcqcte(anything **params, anything **surf_list) |
| 4268 |
{ |
| 4269 |
int i; /* loop index */ |
| 4270 |
int first; /* index of first element to return */ |
| 4271 |
int nreq; /* number of list elements requested */ |
| 4272 |
int j = 0; /* array index */ |
| 4273 |
|
| 4274 |
/* there is only one surface for inquiries */ |
| 4275 |
cur_state = (surf_statelist *)surf_list[0]; |
| 4276 |
if (cur_state->cgi_inited != CYES) { |
| 4277 |
return; |
| 4278 |
} |
| 4279 |
|
| 4280 |
/* number of requested elements, and the first index */ |
| 4281 |
nreq = *(int *)params[1]; |
| 4282 |
first = *(int *)params[2]; |
| 4283 |
|
| 4284 |
/* error checking */ |
| 4285 |
if (first < 1) { |
| 4286 |
first = 1; |
| 4287 |
} |
| 4288 |
|
| 4289 |
if ((first + nreq - 1) > dev_descrip.num_cols) { |
| 4290 |
nreq = dev_descrip.num_cols - first + 1; |
| 4291 |
} |
| 4292 |
|
| 4293 |
/* actual number of colors returned */ |
| 4294 |
*(int *)params[5] = nreq; |
| 4295 |
|
| 4296 |
for (i = first; i < (first + *(int *)params[5]); i++) { |
| 4297 |
|
| 4298 |
((int *)params[6])[j++] = cur_state->color_table[i - 1].r; |
| 4299 |
((int *)params[6])[j++] = cur_state->color_table[i - 1].g; |
| 4300 |
((int *)params[6])[j++] = cur_state->color_table[i - 1].b; |
| 4301 |
} /* end for i */ |
| 4302 |
|
| 4303 |
/* return total number of colors */ |
| 4304 |
*(int *)params[4] = dev_descrip.num_cols; |
| 4305 |
|
| 4306 |
/* validity flag */ |
| 4307 |
*(int *)params[3] = CVAL; |
| 4308 |
|
| 4309 |
} /* end xcqcte */ |
| 4310 |
|
| 4311 |
/* INITIALIZE LOGICAL INPUT DEVICE */ |
| 4312 |
static void xcili(anything **params, anything **surf_list) |
| 4313 |
{ |
| 4314 |
/* there is only one surface for input */ |
| 4315 |
cur_state = (surf_statelist *)surf_list[0]; |
| 4316 |
if (cur_state->cgi_inited != CYES) { |
| 4317 |
return; |
| 4318 |
} |
| 4319 |
|
| 4320 |
/* only support locator */ |
| 4321 |
if (*(int *)params[1] != CLOCAT) { |
| 4322 |
/* error 2:001 - Request for an unsupported feature. Function ignored */ |
| 4323 |
report_error(cur_state, 2, 001, *(short *)params[0]); |
| 4324 |
} |
| 4325 |
else if (*(int *)params[2] != 1) { |
| 4326 |
/* error 3:501 - LID index exceeds number of this class of LID. |
| 4327 |
Function ignored */ |
| 4328 |
report_error(cur_state, 3, 501, *(short *)params[0]); |
| 4329 |
} |
| 4330 |
else if (dev_descrip.dev_class == CINPUT || |
| 4331 |
dev_descrip.dev_class == COUTIN) { /* device does input */ |
| 4332 |
|
| 4333 |
cur_state->input_dev_class = CLOCAT; |
| 4334 |
cur_state->input_dev_index = 1; |
| 4335 |
cur_state->input_dev_state = CREADY; |
| 4336 |
|
| 4337 |
} /* end if device does input */ |
| 4338 |
|
| 4339 |
} /* end xcili */ |
| 4340 |
|
| 4341 |
/* REQUEST LOCATOR */ |
| 4342 |
static void xcrqlc(anything **params, anything **surf_list) |
| 4343 |
{ |
| 4344 |
float x, y; /* x,y values of locator */ |
| 4345 |
|
| 4346 |
/* there is only one surface for input */ |
| 4347 |
cur_state = (surf_statelist *)surf_list[0]; |
| 4348 |
if (cur_state->cgi_inited != CYES) { |
| 4349 |
return; |
| 4350 |
} |
| 4351 |
|
| 4352 |
/* check if device has been initialized */ |
| 4353 |
/* ...only support input device index 1 */ |
| 4354 |
if (*(int *)params[1] != 1 || cur_state->input_dev_state != CREADY) { |
| 4355 |
/* error 5:501 - Function illegal in LID state RELEASED. |
| 4356 |
Function ignored */ |
| 4357 |
report_error(cur_state, 5, 501, *(short *)params[0]); |
| 4358 |
*(int *)params[3] = CINVAL; |
| 4359 |
} |
| 4360 |
|
| 4361 |
else if (dev_descrip.dev_class == CINPUT || |
| 4362 |
dev_descrip.dev_class == COUTIN) { /* device does input */ |
| 4363 |
|
| 4364 |
/* for now only allow limited timeout */ |
| 4365 |
/* positive and negative values = wait forever, 0 = no wait */ |
| 4366 |
if (*(int *)params[2] == 0) { |
| 4367 |
*(int *)params[3] = CINVAL; |
| 4368 |
return; |
| 4369 |
} |
| 4370 |
|
| 4371 |
/* get location and trigger */ |
| 4372 |
vdakgl((int *)params[6], &x, &y); |
| 4373 |
|
| 4374 |
/* convert location from NDC to VDC */ |
| 4375 |
*(float *)params[7] = |
| 4376 |
(x - (cur_state->vp1.x * dev_descrip.xndc_max)) / cur_state->xscale + cur_state->vdc1.x; |
| 4377 |
|
| 4378 |
*(float *)params[8] = |
| 4379 |
(y - (cur_state->vp1.y * dev_descrip.yndc_max)) / cur_state->yscale + cur_state->vdc1.y; |
| 4380 |
|
| 4381 |
/* response validity */ |
| 4382 |
*(int *)params[3] = CVAL; |
| 4383 |
|
| 4384 |
/* request status, SVDI only has trigger */ |
| 4385 |
*(int *)params[4] = CTRIGR; |
| 4386 |
|
| 4387 |
/* measure validity */ |
| 4388 |
/* --i'm not sure when measure validity is invalid */ |
| 4389 |
*(int *)params[5] = CVAL; |
| 4390 |
|
| 4391 |
} /* end else device does input */ |
| 4392 |
|
| 4393 |
else { /* device doesn't do input */ |
| 4394 |
/* response validity */ |
| 4395 |
*(int *)params[3] = CVAL; |
| 4396 |
} |
| 4397 |
|
| 4398 |
} /* end xcrqlc */ |
| 4399 |
|
| 4400 |
/*-------------------------------------------------------------*/ |
| 4401 |
/* >> UTILITY ROUTINES */ |
| 4402 |
/*-------------------------------------------------------------*/ |
| 4403 |
|
| 4404 |
/* init_state */ |
| 4405 |
/* Initialize the state list */ |
| 4406 |
static void init_state(surf_statelist *surf_state) |
| 4407 |
/* surface statelist to init */ |
| 4408 |
{ |
| 4409 |
int i; /* loop index */ |
| 4410 |
float tmp_array[1][3]; /* temp array to set SVDI color table */ |
| 4411 |
int one = 1; |
| 4412 |
|
| 4413 |
/* set default error control: class 1 : DETECTION OFF |
| 4414 |
class 2 - MAX_ERROR_CLASS : REPORTING OFF */ |
| 4415 |
surf_state->err_flag[0] = CEHDOF; |
| 4416 |
for (i = 1; i < MAX_ERROR_CLASS; i++) { |
| 4417 |
surf_state->err_flag[i] = CEHROF; |
| 4418 |
} |
| 4419 |
|
| 4420 |
/* initialize to 0 errors */ |
| 4421 |
surf_state->err_head_ptr = 0; |
| 4422 |
surf_state->err_count = 0; |
| 4423 |
|
| 4424 |
/* default vdc extent */ |
| 4425 |
surf_state->vdc1.x = 0.0; |
| 4426 |
surf_state->vdc1.y = 0.0; |
| 4427 |
surf_state->vdc2.x = 32767.; |
| 4428 |
surf_state->vdc2.y = 32767.; |
| 4429 |
|
| 4430 |
/* viewport - default viewport specification mode is FRACTION OF |
| 4431 |
* DRAWING SURFACE. Thus, the viewport (0,0),(1,1) corresponds to |
| 4432 |
* the lower and upper corners, respectively, of the default |
| 4433 |
* device viewport, which is the largest unrotated rectangular area |
| 4434 |
* visible on the drawing surface. |
| 4435 |
*/ |
| 4436 |
/* default viewport is (0,0),(1,1) */ |
| 4437 |
surf_state->vp1.x = 0.0; |
| 4438 |
surf_state->vp1.y = 0.0; |
| 4439 |
surf_state->vp2.x = 1.0; |
| 4440 |
surf_state->vp2.y = 1.0; |
| 4441 |
|
| 4442 |
/* VDC to viewport in NDC mapping */ |
| 4443 |
/* --device viewport mapping defaults are: isotropy forced, |
| 4444 |
horizontal alignment left, vertical alignment bottom */ |
| 4445 |
/* -- this routine sets effective viewport in VDC and |
| 4446 |
NDC (forcing isotropic mapping) and the mapping scale */ |
| 4447 |
set_mapping(surf_state); |
| 4448 |
|
| 4449 |
/* default clip indicator is off (VDC clipping) */ |
| 4450 |
surf_state->clip_indicator = COFF; |
| 4451 |
|
| 4452 |
/* default view surface clip indicator is viewport */ |
| 4453 |
surf_state->ds_clip_indicator = CVPORT; |
| 4454 |
|
| 4455 |
/* default clip rectangle is (0,0) (32767,32767) */ |
| 4456 |
/* ...can't be changed in SS-CGI */ |
| 4457 |
surf_state->clip_rect1.x = 0.0; |
| 4458 |
surf_state->clip_rect1.y = 0.0; |
| 4459 |
surf_state->clip_rect2.x = 32767.; |
| 4460 |
surf_state->clip_rect2.y = 32767.; |
| 4461 |
|
| 4462 |
/* effective clip rectangle is intersection of VDC extent and |
| 4463 |
clip rectangle */ |
| 4464 |
surf_state->eff_clip_rect1.x = 0.0; |
| 4465 |
surf_state->eff_clip_rect1.y = 0.0; |
| 4466 |
surf_state->eff_clip_rect2.x = 32767.; |
| 4467 |
surf_state->eff_clip_rect2.y = 32767.; |
| 4468 |
|
| 4469 |
/* set the clip region */ |
| 4470 |
set_clipping(surf_state); |
| 4471 |
|
| 4472 |
/* default color mode is indexed */ |
| 4473 |
surf_state->csm = CINDEX; |
| 4474 |
|
| 4475 |
/* default line, fill, text, and marker color indices */ |
| 4476 |
surf_state->line_color[0] = 1; |
| 4477 |
surf_state->fill_color[0] = 1; |
| 4478 |
surf_state->text_color[0] = 1; |
| 4479 |
surf_state->mark_color[0] = 1; |
| 4480 |
|
| 4481 |
/* default line type is solid */ |
| 4482 |
surf_state->line_type = 1; |
| 4483 |
|
| 4484 |
/* default interior style is hollow */ |
| 4485 |
surf_state->interior_style = CHOLLO; |
| 4486 |
|
| 4487 |
/* char size is in VDC - default is 1/100 of default VDC extent */ |
| 4488 |
surf_state->char_height = 327.; |
| 4489 |
|
| 4490 |
/* default line width specification mode is scaled, default |
| 4491 |
linewidth is 1. */ |
| 4492 |
surf_state->line_width = 1.; |
| 4493 |
|
| 4494 |
/* default marker specification mode is scaled, default |
| 4495 |
marker size is 1. */ |
| 4496 |
surf_state->mark_size = 1.; |
| 4497 |
|
| 4498 |
/* the only default colors defined in CGI are index 0 = background, |
| 4499 |
* and index 1 = foreground. Use SVDI's bg and fg until the user |
| 4500 |
* sets the color table. |
| 4501 |
*/ |
| 4502 |
if (dev_descrip.svdi_type == 0) { /* vector SVDI */ |
| 4503 |
|
| 4504 |
/* set up the fg and bg mappings */ |
| 4505 |
surf_state->bg_index = dev_descrip.att_array[2]; |
| 4506 |
surf_state->fg_index = dev_descrip.att_array[1]; |
| 4507 |
|
| 4508 |
/* set the current surface color table */ |
| 4509 |
vdiqco(&one, &dev_descrip.index_array[surf_state->bg_index], tmp_array, &dev_descrip.col_mode); |
| 4510 |
surf_state->color_table[0].r = (int)(tmp_array[0][0] * 255.0f); |
| 4511 |
surf_state->color_table[0].g = (int)(tmp_array[0][1] * 255.0f); |
| 4512 |
surf_state->color_table[0].b = (int)(tmp_array[0][2] * 255.0f); |
| 4513 |
vdiqco(&one, &dev_descrip.index_array[surf_state->fg_index], tmp_array, &dev_descrip.col_mode); |
| 4514 |
surf_state->color_table[1].r = (int)(tmp_array[0][0] * 255.0f); |
| 4515 |
surf_state->color_table[1].g = (int)(tmp_array[0][1] * 255.0f); |
| 4516 |
surf_state->color_table[1].b = (int)(tmp_array[0][2] * 255.0f); |
| 4517 |
} /* end if vector SVDI */ |
| 4518 |
|
| 4519 |
else { /* raster SVDI */ |
| 4520 |
|
| 4521 |
vdiqci(&dev_descrip.att_array[11], &dev_descrip.att_array[12], &dev_descrip.att_array[13], |
| 4522 |
&surf_state->bg_index); |
| 4523 |
vdiqci(&dev_descrip.att_array[8], &dev_descrip.att_array[9], &dev_descrip.att_array[10], |
| 4524 |
&surf_state->fg_index); |
| 4525 |
|
| 4526 |
/* set the current surface color table */ |
| 4527 |
surf_state->color_table[0].r = (int)(dev_descrip.att_array[8] * 255.0f); |
| 4528 |
surf_state->color_table[0].g = (int)(dev_descrip.att_array[9] * 255.0f); |
| 4529 |
surf_state->color_table[0].b = (int)(dev_descrip.att_array[10] * 255.0f); |
| 4530 |
surf_state->color_table[1].r = (int)(dev_descrip.att_array[11] * 255.0f); |
| 4531 |
surf_state->color_table[1].g = (int)(dev_descrip.att_array[12] * 255.0f); |
| 4532 |
surf_state->color_table[1].b = (int)(dev_descrip.att_array[13] * 255.0f); |
| 4533 |
} /* end else raster SVDI */ |
| 4534 |
|
| 4535 |
/* set/reset the SVDI attribute array */ |
| 4536 |
/* --set everything to -1 to force resetting of attributes */ |
| 4537 |
surf_state->vdi_attrib.fg_color = -1; |
| 4538 |
surf_state->vdi_attrib.bg_color = -1; |
| 4539 |
surf_state->vdi_attrib.intensity = -1.0; |
| 4540 |
surf_state->vdi_attrib.line_type = -1; |
| 4541 |
surf_state->vdi_attrib.line_width = -1.0; |
| 4542 |
surf_state->vdi_attrib.char_x = -1.0; |
| 4543 |
surf_state->vdi_attrib.char_y = -1.0; |
| 4544 |
surf_state->vdi_attrib.fg_rgb[0] = -1.0; |
| 4545 |
surf_state->vdi_attrib.fg_rgb[1] = -1.0; |
| 4546 |
surf_state->vdi_attrib.fg_rgb[2] = -1.0; |
| 4547 |
surf_state->vdi_attrib.bg_rgb[0] = -1.0; |
| 4548 |
surf_state->vdi_attrib.bg_rgb[1] = -1.0; |
| 4549 |
surf_state->vdi_attrib.bg_rgb[2] = -1.0; |
| 4550 |
|
| 4551 |
/* set color_set flag to false = color table not set by user */ |
| 4552 |
surf_state->color_set = FALSE; |
| 4553 |
|
| 4554 |
/* set picture state to clean */ |
| 4555 |
surf_state->pic_dirty = CCLEAN; |
| 4556 |
|
| 4557 |
} /* end init_state */ |
| 4558 |
|
| 4559 |
/* set_dev_descrip */ |
| 4560 |
/* Set the device description table */ |
| 4561 |
static void set_dev_descrip(void) |
| 4562 |
{ |
| 4563 |
/* dev_descrip is global */ |
| 4564 |
int j; /* loop index */ |
| 4565 |
int qdc_index; /* used for inquiring SVDI */ |
| 4566 |
float value; /* value returned from inquire SVDI */ |
| 4567 |
|
| 4568 |
/* set copy_class */ |
| 4569 |
qdc_index = 1; |
| 4570 |
vdiqdc(&qdc_index, &value); |
| 4571 |
if (value == 0.) { |
| 4572 |
dev_descrip.copy_class = CHARD; |
| 4573 |
} |
| 4574 |
else { |
| 4575 |
dev_descrip.copy_class = CSOFT; |
| 4576 |
} |
| 4577 |
|
| 4578 |
/* device corners in device coords */ |
| 4579 |
dev_descrip.dc1.x = 0; |
| 4580 |
dev_descrip.dc1.y = 0; |
| 4581 |
qdc_index = 15; |
| 4582 |
vdiqdc(&qdc_index, &value); |
| 4583 |
dev_descrip.dc2.x = (int)value; |
| 4584 |
qdc_index = 16; |
| 4585 |
vdiqdc(&qdc_index, &value); |
| 4586 |
dev_descrip.dc2.y = (int)value; |
| 4587 |
|
| 4588 |
/* vector or raster SVDI (0=vector, 1=raster) */ |
| 4589 |
qdc_index = 29; |
| 4590 |
vdiqdc(&qdc_index, &value); |
| 4591 |
dev_descrip.svdi_type = (int)value; |
| 4592 |
|
| 4593 |
/* vector SVDI only does indexed color, raster does both */ |
| 4594 |
if (dev_descrip.svdi_type == 0) { |
| 4595 |
dev_descrip.csm_avail = CCLRI; |
| 4596 |
} |
| 4597 |
else { |
| 4598 |
dev_descrip.csm_avail = CCLRID; |
| 4599 |
} |
| 4600 |
|
| 4601 |
/* device class */ |
| 4602 |
qdc_index = 13; |
| 4603 |
vdiqdc(&qdc_index, &value); |
| 4604 |
dev_descrip.dev_class = (value == 0.) ? COUTPT : COUTIN; |
| 4605 |
|
| 4606 |
/* NDC space */ |
| 4607 |
vdiqnd(&dev_descrip.xndc_max, &dev_descrip.yndc_max); |
| 4608 |
|
| 4609 |
/* output status */ |
| 4610 |
vdiqos(&dev_descrip.att_array[1]); |
| 4611 |
|
| 4612 |
/* min line width - SVDI returns value in DC */ |
| 4613 |
qdc_index = 19; |
| 4614 |
vdiqdc(&qdc_index, &value); |
| 4615 |
dev_descrip.linewidth_min = (int)value; |
| 4616 |
|
| 4617 |
/* max line width - SVDI returns value in DC */ |
| 4618 |
qdc_index = 31; |
| 4619 |
vdiqdc(&qdc_index, &value); |
| 4620 |
dev_descrip.linewidth_max = (int)value; |
| 4621 |
|
| 4622 |
/* use the default SVDI linewidth as nominal */ |
| 4623 |
/* --convert to device coordinates */ |
| 4624 |
value = (dev_descrip.att_array[5] / dev_descrip.xndc_max) * .01 * |
| 4625 |
(dev_descrip.dc2.x - dev_descrip.dc1.x); |
| 4626 |
dev_descrip.linewidth_nominal = (int)max(value, 1.); |
| 4627 |
|
| 4628 |
/* --make sure that for some reason it isn't out of range */ |
| 4629 |
dev_descrip.linewidth_nominal = |
| 4630 |
max(min(dev_descrip.linewidth_nominal, dev_descrip.linewidth_max), dev_descrip.linewidth_min); |
| 4631 |
|
| 4632 |
/* nominal,min,max marker size - only one size */ |
| 4633 |
qdc_index = 20; |
| 4634 |
vdiqdc(&qdc_index, &value); |
| 4635 |
dev_descrip.mark_nominal = (int)value; |
| 4636 |
dev_descrip.mark_min = (int)value; |
| 4637 |
dev_descrip.mark_max = (int)value; |
| 4638 |
|
| 4639 |
/* inquire the number of colors */ |
| 4640 |
qdc_index = 4; |
| 4641 |
vdiqdc(&qdc_index, &value); |
| 4642 |
|
| 4643 |
/* check for max colors */ |
| 4644 |
dev_descrip.num_cols = ((int)value > COLOR_TABLE_SIZE) ? COLOR_TABLE_SIZE : (int)value; |
| 4645 |
|
| 4646 |
/* set up a color index array for use in color table stuff */ |
| 4647 |
for (j = 0; j < 256; j++) { |
| 4648 |
dev_descrip.index_array[j] = j; |
| 4649 |
} |
| 4650 |
|
| 4651 |
/* set SVDI color mode */ |
| 4652 |
dev_descrip.col_mode = 0; |
| 4653 |
|
| 4654 |
/* inquire default SVDI color table. */ |
| 4655 |
vdiqco(&dev_descrip.num_cols, dev_descrip.index_array, dev_descrip.color_array, |
| 4656 |
&dev_descrip.col_mode); |
| 4657 |
|
| 4658 |
} /* end set_dev_descrip */ |
| 4659 |
|
| 4660 |
/* reset_vdi */ |
| 4661 |
/* Reset SVDI values. Used if CI is called twice */ |
| 4662 |
static void reset_vdi(surf_statelist *surf_state) |
| 4663 |
/* current surface statelist */ |
| 4664 |
{ |
| 4665 |
|
| 4666 |
/* reset the output status */ |
| 4667 |
vdstos(&dev_descrip.att_array[1]); |
| 4668 |
|
| 4669 |
/* only reset color table is user has changed it */ |
| 4670 |
if (surf_state->color_set) { |
| 4671 |
vdstco(&dev_descrip.num_cols, dev_descrip.index_array, dev_descrip.color_array, |
| 4672 |
&dev_descrip.col_mode); |
| 4673 |
} |
| 4674 |
} /* end reset_vdi */ |
| 4675 |
|
| 4676 |
/* set_mapping */ |
| 4677 |
/* Set up the VDC to NDC mappings. Also sets the effective viewports |
| 4678 |
* in NDC and VDC. |
| 4679 |
*/ |
| 4680 |
static void set_mapping(surf_statelist *surf_state) |
| 4681 |
{ |
| 4682 |
point ndc_vp1, ndc_vp2; |
| 4683 |
|
| 4684 |
/* viewport in NDC space */ |
| 4685 |
ndc_vp1.x = cur_state->vp1.x * dev_descrip.xndc_max; |
| 4686 |
ndc_vp1.y = cur_state->vp1.y * dev_descrip.yndc_max; |
| 4687 |
ndc_vp2.x = cur_state->vp2.x * dev_descrip.xndc_max; |
| 4688 |
ndc_vp2.y = cur_state->vp2.y * dev_descrip.yndc_max; |
| 4689 |
|
| 4690 |
/* x and y scale maps VDC to viewport in NDC (ISOTROPIC Mapping) */ |
| 4691 |
/* ...smallest scale magnitude, but keep the original sign */ |
| 4692 |
surf_state->xscale = (ndc_vp2.x - ndc_vp1.x) / (surf_state->vdc2.x - surf_state->vdc1.x); |
| 4693 |
surf_state->yscale = (ndc_vp2.y - ndc_vp1.y) / (surf_state->vdc2.y - surf_state->vdc1.y); |
| 4694 |
|
| 4695 |
if (fabs(surf_state->xscale) < fabs(surf_state->yscale)) { |
| 4696 |
surf_state->yscale = |
| 4697 |
(surf_state->yscale < 0) ? -1 * fabs(surf_state->xscale) : fabs(surf_state->xscale); |
| 4698 |
} |
| 4699 |
else { |
| 4700 |
surf_state->xscale = |
| 4701 |
(surf_state->xscale < 0) ? -1 * fabs(surf_state->yscale) : fabs(surf_state->yscale); |
| 4702 |
} |
| 4703 |
|
| 4704 |
/* x and y offset for VDC to NDC mapping */ |
| 4705 |
surf_state->xoffset = (ndc_vp1.x < ndc_vp2.x) |
| 4706 |
? ndc_vp1.x - surf_state->vdc1.x * surf_state->xscale |
| 4707 |
: ndc_vp2.x - surf_state->vdc2.x * surf_state->xscale; |
| 4708 |
|
| 4709 |
surf_state->yoffset = (ndc_vp1.y < ndc_vp2.y) |
| 4710 |
? ndc_vp1.y - surf_state->vdc1.y * surf_state->yscale |
| 4711 |
: ndc_vp2.y - surf_state->vdc2.y * surf_state->yscale; |
| 4712 |
|
| 4713 |
/* effective viewport */ |
| 4714 |
/* - mode is FRACTION OF DRAWING SURFACE */ |
| 4715 |
surf_state->eff_vp1.x = cur_state->vp1.x; |
| 4716 |
surf_state->eff_vp1.y = cur_state->vp1.y; |
| 4717 |
surf_state->eff_vp2.x = |
| 4718 |
(surf_state->vdc2.x * surf_state->xscale + surf_state->xoffset) / dev_descrip.xndc_max; |
| 4719 |
surf_state->eff_vp2.y = |
| 4720 |
(surf_state->vdc2.y * surf_state->yscale + surf_state->yoffset) / dev_descrip.yndc_max; |
| 4721 |
|
| 4722 |
} /* end set_mapping */ |
| 4723 |
|
| 4724 |
/* set_clipping */ |
| 4725 |
/* Set up the clip region. */ |
| 4726 |
static void set_clipping(surf_statelist *my_cur_state) |
| 4727 |
{ |
| 4728 |
point clip1, clip2; /* temp clip values */ |
| 4729 |
clip1.x = clip1.y = clip2.x = clip2.y = 0; |
| 4730 |
|
| 4731 |
/* The clip region depends on clip indicator and drawing surface |
| 4732 |
* clip indicator. |
| 4733 |
*/ |
| 4734 |
switch (my_cur_state->clip_indicator) { |
| 4735 |
case CON: |
| 4736 |
|
| 4737 |
/* VDC clipping is on */ |
| 4738 |
switch (my_cur_state->ds_clip_indicator) { |
| 4739 |
|
| 4740 |
case CDCOFF: /* view surface clipping off */ |
| 4741 |
|
| 4742 |
/* map the effective clip rectangle to NDC */ |
| 4743 |
my_cur_state->clip_on = TRUE; |
| 4744 |
clip1.x = my_cur_state->eff_clip_rect1.x * my_cur_state->xscale + my_cur_state->xoffset; |
| 4745 |
clip1.y = my_cur_state->eff_clip_rect1.y * my_cur_state->yscale + my_cur_state->yoffset; |
| 4746 |
clip2.x = my_cur_state->eff_clip_rect2.x * my_cur_state->xscale + my_cur_state->xoffset; |
| 4747 |
clip2.y = my_cur_state->eff_clip_rect2.y * my_cur_state->yscale + my_cur_state->yoffset; |
| 4748 |
|
| 4749 |
break; /* end case CDCOFF */ |
| 4750 |
|
| 4751 |
case CVPORT: /* clip at viewport */ |
| 4752 |
|
| 4753 |
/* map the effective clip rectangle to NDC */ |
| 4754 |
my_cur_state->clip_on = TRUE; |
| 4755 |
|
| 4756 |
clip1.x = my_cur_state->eff_clip_rect1.x * my_cur_state->xscale + my_cur_state->xoffset; |
| 4757 |
clip1.y = my_cur_state->eff_clip_rect1.y * my_cur_state->yscale + my_cur_state->yoffset; |
| 4758 |
clip2.x = my_cur_state->eff_clip_rect2.x * my_cur_state->xscale + my_cur_state->xoffset; |
| 4759 |
clip2.y = my_cur_state->eff_clip_rect2.y * my_cur_state->yscale + my_cur_state->yoffset; |
| 4760 |
|
| 4761 |
break; /* end case CVPORT */ |
| 4762 |
|
| 4763 |
case CDCREC: /* clip at display surface */ |
| 4764 |
|
| 4765 |
/* map the effective clip rectangle to NDC and intersect it |
| 4766 |
with the max NDC space */ |
| 4767 |
my_cur_state->clip_on = TRUE; |
| 4768 |
|
| 4769 |
clip1.x = my_cur_state->eff_clip_rect1.x * my_cur_state->xscale + my_cur_state->xoffset; |
| 4770 |
clip1.y = my_cur_state->eff_clip_rect1.y * my_cur_state->yscale + my_cur_state->yoffset; |
| 4771 |
clip2.x = my_cur_state->eff_clip_rect2.x * my_cur_state->xscale + my_cur_state->xoffset; |
| 4772 |
clip2.y = my_cur_state->eff_clip_rect2.y * my_cur_state->yscale + my_cur_state->yoffset; |
| 4773 |
|
| 4774 |
clip1.x = max(min(clip1.x, clip2.x), 0.0); |
| 4775 |
clip1.y = max(min(clip1.y, clip2.y), 0.0); |
| 4776 |
clip2.x = min(max(clip1.x, clip2.x), dev_descrip.xndc_max); |
| 4777 |
clip2.y = min(max(clip1.y, clip2.y), dev_descrip.yndc_max); |
| 4778 |
|
| 4779 |
break; /* end case CDCREC */ |
| 4780 |
|
| 4781 |
default: |
| 4782 |
/* illegal enumeration type - ignore function */ |
| 4783 |
break; |
| 4784 |
|
| 4785 |
} /* end switch ds_clip_indicator */ |
| 4786 |
|
| 4787 |
break; /* end case CON */ |
| 4788 |
|
| 4789 |
case COFF: |
| 4790 |
|
| 4791 |
/* VDC clipping is off */ |
| 4792 |
switch (my_cur_state->ds_clip_indicator) { |
| 4793 |
|
| 4794 |
case CDCOFF: /* display surface clipping off */ |
| 4795 |
|
| 4796 |
/* no clip */ |
| 4797 |
my_cur_state->clip_on = FALSE; |
| 4798 |
break; /* end case CDCOFF */ |
| 4799 |
|
| 4800 |
case CVPORT: /* clip at viewport */ |
| 4801 |
|
| 4802 |
/* clip at NDC effective viewport */ |
| 4803 |
my_cur_state->clip_on = TRUE; |
| 4804 |
clip1.x = my_cur_state->eff_vp1.x * dev_descrip.xndc_max; |
| 4805 |
clip1.y = my_cur_state->eff_vp1.y * dev_descrip.yndc_max; |
| 4806 |
clip2.x = my_cur_state->eff_vp2.x * dev_descrip.xndc_max; |
| 4807 |
clip2.y = my_cur_state->eff_vp2.y * dev_descrip.yndc_max; |
| 4808 |
break; /* end case CVPORT */ |
| 4809 |
|
| 4810 |
case CDCREC: /* clip at display surface */ |
| 4811 |
|
| 4812 |
/* clip at max NDC space */ |
| 4813 |
my_cur_state->clip_on = TRUE; |
| 4814 |
clip1.x = 0.0; |
| 4815 |
clip1.y = 0.0; |
| 4816 |
clip2.x = dev_descrip.xndc_max; |
| 4817 |
clip2.y = dev_descrip.yndc_max; |
| 4818 |
break; /* end case CDCREC */ |
| 4819 |
|
| 4820 |
default: |
| 4821 |
/* illegal enumeration type - ignore function */ |
| 4822 |
break; |
| 4823 |
|
| 4824 |
} /* end switch ds_clip_indicator */ |
| 4825 |
|
| 4826 |
break; /* end case COFF */ |
| 4827 |
|
| 4828 |
default: |
| 4829 |
/* illegal enumeration type - ignore function */ |
| 4830 |
break; |
| 4831 |
|
| 4832 |
} /* end switch clip_indicator */ |
| 4833 |
|
| 4834 |
/* set clipmin and clipmax such that clipmin is the minimum corner of |
| 4835 |
* the clipping window, and clipmax is the maximum. This is done |
| 4836 |
* so that the clipping algorithms work correctly with mirroring. |
| 4837 |
*/ |
| 4838 |
if (my_cur_state->clip_on) { |
| 4839 |
my_cur_state->clipmin.x = min(clip1.x, clip2.x); |
| 4840 |
my_cur_state->clipmax.x = max(clip1.x, clip2.x); |
| 4841 |
my_cur_state->clipmin.y = min(clip1.y, clip2.y); |
| 4842 |
my_cur_state->clipmax.y = max(clip1.y, clip2.y); |
| 4843 |
} |
| 4844 |
} /* end set_clipping */ |
| 4845 |
|
| 4846 |
/* set_foreground_color */ |
| 4847 |
/* Set the SVDI foreground color */ |
| 4848 |
static void set_foreground_color(surf_statelist *surf_state, int *colors) |
| 4849 |
{ |
| 4850 |
int zero = 0; |
| 4851 |
int one = 1; |
| 4852 |
|
| 4853 |
/* if color selection mode is in error, ignore function */ |
| 4854 |
if (surf_state->csm == -1) { |
| 4855 |
return; |
| 4856 |
} |
| 4857 |
|
| 4858 |
/* indexed or direct color? */ |
| 4859 |
/* --vector SVDI only does indexed color */ |
| 4860 |
if (surf_state->csm == CINDEX || dev_descrip.svdi_type == 0) { |
| 4861 |
|
| 4862 |
/* does foreground need to be updated? */ |
| 4863 |
if (colors[0] != cur_state->vdi_attrib.fg_color) { |
| 4864 |
|
| 4865 |
/* color index mappings: |
| 4866 |
* if set index 0 --> set bg_index |
| 4867 |
* if set index 1 --> set fg_index |
| 4868 |
* if set bg_index --> set 0 |
| 4869 |
* if set fg_index --> set 1 |
| 4870 |
*/ |
| 4871 |
if (colors[0] == 0) { |
| 4872 |
vdstfc(&cur_state->bg_index); |
| 4873 |
} |
| 4874 |
else if (colors[0] == 1) { |
| 4875 |
vdstfc(&cur_state->fg_index); |
| 4876 |
} |
| 4877 |
else if (colors[0] == cur_state->bg_index) { |
| 4878 |
vdstfc(&zero); |
| 4879 |
} |
| 4880 |
else if (colors[0] == cur_state->fg_index) { |
| 4881 |
vdstfc(&one); |
| 4882 |
} |
| 4883 |
else { |
| 4884 |
vdstfc(&colors[0]); |
| 4885 |
} |
| 4886 |
|
| 4887 |
/* update att_array */ |
| 4888 |
cur_state->vdi_attrib.fg_color = colors[0]; |
| 4889 |
|
| 4890 |
/* flag (direct) that foreground color has changed */ |
| 4891 |
/* do i need to do this? */ |
| 4892 |
cur_state->vdi_attrib.fg_rgb[0] = -1.0; |
| 4893 |
cur_state->vdi_attrib.fg_rgb[1] = -1.0; |
| 4894 |
cur_state->vdi_attrib.fg_rgb[2] = -1.0; |
| 4895 |
} /* end does foreground... */ |
| 4896 |
} /* end indexed color */ |
| 4897 |
|
| 4898 |
else /* direct color */ |
| 4899 |
|
| 4900 |
/* does foreground need to be updated? */ |
| 4901 |
/* -- i need to check this out - might need to store as int */ |
| 4902 |
if (colors[0] != (int)(cur_state->vdi_attrib.fg_rgb[0] * 255.0f) || |
| 4903 |
colors[1] != (int)(cur_state->vdi_attrib.fg_rgb[1] * 255.0f) || |
| 4904 |
colors[2] != (int)(cur_state->vdi_attrib.fg_rgb[2] * 255.0f)) { |
| 4905 |
|
| 4906 |
/* update att_array */ |
| 4907 |
cur_state->vdi_attrib.fg_rgb[0] = (float)colors[0] / 255.0f; |
| 4908 |
cur_state->vdi_attrib.fg_rgb[1] = (float)colors[1] / 255.0f; |
| 4909 |
cur_state->vdi_attrib.fg_rgb[2] = (float)colors[2] / 255.0f; |
| 4910 |
|
| 4911 |
/* set new foreground color */ |
| 4912 |
vdfrgb(&cur_state->vdi_attrib.fg_rgb[0], &cur_state->vdi_attrib.fg_rgb[1], |
| 4913 |
&cur_state->vdi_attrib.fg_rgb[2]); |
| 4914 |
|
| 4915 |
/* flag (indexed) that foreground color has changed */ |
| 4916 |
/* do i need to do this? */ |
| 4917 |
cur_state->vdi_attrib.fg_color = -1; |
| 4918 |
} /* end does foreground... */ |
| 4919 |
|
| 4920 |
} /* end set_foreground_color */ |
| 4921 |
|
| 4922 |
/* set_background_color */ |
| 4923 |
/* Set the SVDI background color */ |
| 4924 |
static void set_background_color(surf_statelist *surf_state, int *colors) |
| 4925 |
{ |
| 4926 |
int i; /* loop index */ |
| 4927 |
int index = 0; /* color index */ |
| 4928 |
float dr, dg, db, dmin, dist; /* for finding the closet index */ |
| 4929 |
int one = 1; |
| 4930 |
float epsilon = .001; |
| 4931 |
|
| 4932 |
/* does background need to be updated */ |
| 4933 |
/* --background color is saved in att_array, even for vector */ |
| 4934 |
if (colors[0] != (int)(cur_state->vdi_attrib.bg_rgb[0] * 255.0f) || |
| 4935 |
colors[1] != (int)(cur_state->vdi_attrib.bg_rgb[1] * 255.0f) || |
| 4936 |
colors[2] != (int)(cur_state->vdi_attrib.bg_rgb[2] * 255.0f)) { |
| 4937 |
|
| 4938 |
/* store new values in att_array */ |
| 4939 |
cur_state->vdi_attrib.bg_rgb[0] = (float)colors[0] / 255.0f; |
| 4940 |
cur_state->vdi_attrib.bg_rgb[1] = (float)colors[1] / 255.0f; |
| 4941 |
cur_state->vdi_attrib.bg_rgb[2] = (float)colors[2] / 255.0f; |
| 4942 |
|
| 4943 |
/* set the cgi state color table - index 0 */ |
| 4944 |
cur_state->color_table[0].r = colors[0]; |
| 4945 |
cur_state->color_table[0].g = colors[1]; |
| 4946 |
cur_state->color_table[0].b = colors[2]; |
| 4947 |
|
| 4948 |
/* has the SVDI color table ever been set */ |
| 4949 |
if (!surf_state->color_set) { /* has never been set */ |
| 4950 |
|
| 4951 |
/* find out if default SVDI table contains this color */ |
| 4952 |
if (dev_descrip.svdi_type == 1) { /* raster SVDI */ |
| 4953 |
|
| 4954 |
vdiqci(&cur_state->vdi_attrib.bg_rgb[0], &cur_state->vdi_attrib.bg_rgb[1], |
| 4955 |
&cur_state->vdi_attrib.bg_rgb[2], &i); |
| 4956 |
|
| 4957 |
/* does it match */ |
| 4958 |
dr = cur_state->vdi_attrib.bg_rgb[0] - dev_descrip.color_array[i][0]; |
| 4959 |
dg = cur_state->vdi_attrib.bg_rgb[1] - dev_descrip.color_array[i][1]; |
| 4960 |
db = cur_state->vdi_attrib.bg_rgb[2] - dev_descrip.color_array[i][2]; |
| 4961 |
dmin = dr * dr + dg * dg + db * db; |
| 4962 |
} /* end raster SVDI */ |
| 4963 |
|
| 4964 |
else { /* vector SVDI */ |
| 4965 |
|
| 4966 |
for (i = 0; i < 8; i++) { |
| 4967 |
dr = cur_state->vdi_attrib.bg_rgb[0] - dev_descrip.color_array[i][0]; |
| 4968 |
dg = cur_state->vdi_attrib.bg_rgb[1] - dev_descrip.color_array[i][1]; |
| 4969 |
db = cur_state->vdi_attrib.bg_rgb[2] - dev_descrip.color_array[i][2]; |
| 4970 |
dist = dr * dr + dg * dg + db * db; |
| 4971 |
|
| 4972 |
if (i == 0 || dist < dmin) { |
| 4973 |
dmin = dist; |
| 4974 |
index = i; |
| 4975 |
} |
| 4976 |
} /* end for i */ |
| 4977 |
} /* end vector SVDI */ |
| 4978 |
|
| 4979 |
/* is it close enough? */ |
| 4980 |
if (dmin <= epsilon) { |
| 4981 |
cur_state->bg_index = index; |
| 4982 |
} |
| 4983 |
else { /* not close enough, set SVDI color table */ |
| 4984 |
|
| 4985 |
cur_state->bg_index = 0; |
| 4986 |
vdstco(&one, &dev_descrip.index_array[cur_state->bg_index], &cur_state->vdi_attrib.bg_rgb, |
| 4987 |
&dev_descrip.col_mode); |
| 4988 |
cur_state->color_set = TRUE; /* flag that CT has been set */ |
| 4989 |
} /* end else not close enough */ |
| 4990 |
|
| 4991 |
} /* end has never been set */ |
| 4992 |
|
| 4993 |
else { /* color table has been set */ |
| 4994 |
|
| 4995 |
/* set SVDI color table */ |
| 4996 |
vdstco(&one, &dev_descrip.index_array[cur_state->bg_index], &cur_state->vdi_attrib.bg_rgb, |
| 4997 |
&dev_descrip.col_mode); |
| 4998 |
|
| 4999 |
} /* end else has been set */ |
| 5000 |
|
| 5001 |
/* set the SVDI background color */ |
| 5002 |
if (dev_descrip.svdi_type == 1) { /* raster SVDI */ |
| 5003 |
vdbrgb(&cur_state->vdi_attrib.bg_rgb[0], &cur_state->vdi_attrib.bg_rgb[1], |
| 5004 |
&cur_state->vdi_attrib.bg_rgb[2]); |
| 5005 |
} |
| 5006 |
else /* vector SVDI */ |
| 5007 |
|
| 5008 |
/* once the ct has been set, bg_index never changes */ |
| 5009 |
if (!cur_state->color_set) { |
| 5010 |
vdstbc(&cur_state->bg_index); |
| 5011 |
} |
| 5012 |
|
| 5013 |
} /* end does background need to be updated */ |
| 5014 |
} /* end set_background_color */ |
| 5015 |
|
| 5016 |
/* report_error */ |
| 5017 |
/* Stuff the error info into the error queue */ |
| 5018 |
static void report_error(surf_statelist *surf_state, int e_class, int e_num, int f_id) |
| 5019 |
{ |
| 5020 |
int err_slot; /* slot in the queue to put the error */ |
| 5021 |
|
| 5022 |
/* is error reporting on for this class? */ |
| 5023 |
if (surf_state->err_flag[e_class - 1] == CEHON) { |
| 5024 |
|
| 5025 |
/* figure out where the next slot is */ |
| 5026 |
err_slot = surf_state->err_head_ptr + surf_state->err_count; |
| 5027 |
if (err_slot >= ERROR_LIST_SIZE) { |
| 5028 |
err_slot = err_slot - ERROR_LIST_SIZE; |
| 5029 |
} |
| 5030 |
|
| 5031 |
/* store errors if there is room in the queue */ |
| 5032 |
if (surf_state->err_count < ERROR_LIST_SIZE) { |
| 5033 |
surf_state->err_queue[err_slot].err_class = e_class; |
| 5034 |
surf_state->err_queue[err_slot].err_num = e_num; |
| 5035 |
surf_state->err_queue[err_slot].func_id = f_id; |
| 5036 |
surf_state->err_count++; |
| 5037 |
} /* end if room in the queue */ |
| 5038 |
|
| 5039 |
else { /* not enuff room in the queue */ |
| 5040 |
|
| 5041 |
/* if the most recent error is ERROR REPORTS LOST, increase count |
| 5042 |
of errors lost by one (count is stored in func_id) */ |
| 5043 |
if (surf_state->err_queue[err_slot - 1].err_class == -1 && |
| 5044 |
surf_state->err_queue[err_slot - 1].err_num == 0) { |
| 5045 |
surf_state->err_queue[err_slot - 1].func_id++; |
| 5046 |
} |
| 5047 |
else { /* create an ERROR REPORTS LOST error */ |
| 5048 |
/* The format for an ERROR REPORTS LOST has not yet |
| 5049 |
* been defined. For now, use error class -1, error |
| 5050 |
* number 0, and the count in function id. |
| 5051 |
* (as defined in SRCP document) |
| 5052 |
*/ |
| 5053 |
surf_state->err_queue[err_slot - 1].err_class = -1; |
| 5054 |
surf_state->err_queue[err_slot - 1].err_num = 0; |
| 5055 |
surf_state->err_queue[err_slot - 1].func_id = 2; |
| 5056 |
} /* end else create */ |
| 5057 |
} /* end not enuff room in the queue */ |
| 5058 |
|
| 5059 |
} /* end if error reporting is on */ |
| 5060 |
} /* end report_error */ |
| 5061 |
|
| 5062 |
/* gettoken */ |
| 5063 |
/* Return one token from data record....written by Pat MaGee, LANL */ |
| 5064 |
static void gettoken(int *index_p, int *numrecs_p, char *data_p, int max_chars, char *outtoken_p) |
| 5065 |
/* in: 1st char of whitespace before token */ |
| 5066 |
/* out: 1st char past token */ |
| 5067 |
/* in: number of data records */ |
| 5068 |
/* in: 80 character records */ |
| 5069 |
/* in: max # of chars to put into outtoken */ |
| 5070 |
/* out: where to put output token */ |
| 5071 |
{ |
| 5072 |
char c; /* char from data record */ |
| 5073 |
int num_chars; /* # chars put into outtoken so far */ |
| 5074 |
int workstate; /* 0=whitespace,1=nonwhite,2=endofstring */ |
| 5075 |
|
| 5076 |
num_chars = 0; |
| 5077 |
|
| 5078 |
workstate = 0; |
| 5079 |
if (*index_p >= (*numrecs_p * 80)) { |
| 5080 |
workstate = 2; |
| 5081 |
} |
| 5082 |
|
| 5083 |
while (workstate == 0) { /* while scanning whitespace */ |
| 5084 |
c = data_p[*index_p]; |
| 5085 |
if ((c == ' ') || (c == '\t') || (c == '\r')) { |
| 5086 |
/* c is whitespace, keep scanning */ |
| 5087 |
++(*index_p); |
| 5088 |
if (*index_p >= *numrecs_p * 80) { |
| 5089 |
workstate = 2; |
| 5090 |
} /* end if off end of data */ |
| 5091 |
} |
| 5092 |
else { |
| 5093 |
/* c is not whitespace, is start of token */ |
| 5094 |
workstate = 1; |
| 5095 |
} /* end if c is whitespace */ |
| 5096 |
} /* end while skipping whitespace */ |
| 5097 |
|
| 5098 |
while (workstate == 1) { /* while in token */ |
| 5099 |
c = data_p[*index_p]; |
| 5100 |
if (num_chars >= max_chars) { |
| 5101 |
workstate = 3; |
| 5102 |
} |
| 5103 |
if ((c == ' ') || (c == '\t') || (c == '\r')) { |
| 5104 |
workstate = 0; |
| 5105 |
} |
| 5106 |
else { /* c is not whitespace, output and keep scanning */ |
| 5107 |
outtoken_p[num_chars] = c; |
| 5108 |
++num_chars; |
| 5109 |
++(*index_p); |
| 5110 |
if (*index_p >= *numrecs_p * 80) { |
| 5111 |
workstate = 2; |
| 5112 |
} /* end if off end of data */ |
| 5113 |
} /* end if c is whitespace */ |
| 5114 |
|
| 5115 |
} /* end while putting chars into outtoken */ |
| 5116 |
|
| 5117 |
outtoken_p[num_chars] = 0; |
| 5118 |
|
| 5119 |
} /* end gettoken */ |
| 5120 |
|
| 5121 |
/* poly_clip */ |
| 5122 |
/* Clip a polygon. Based on Sutherland - Hodgman algorithm |
| 5123 |
* Returns the new polygon vertices, and the new vertex count. |
| 5124 |
* One day, I need to make this more efficient by moving everything |
| 5125 |
* inline. |
| 5126 |
*/ |
| 5127 |
static int poly_clip(point *cmin, point *cmax, float *vx, float *vy, int vlen, float *xout, |
| 5128 |
float *yout, int *lenout) |
| 5129 |
{ |
| 5130 |
point s, p, t; |
| 5131 |
int i, j, bnd, curlen; |
| 5132 |
float xtemp[MAX_POLYGON]; |
| 5133 |
float ytemp[MAX_POLYGON]; |
| 5134 |
|
| 5135 |
/* make sure there is something to clip */ |
| 5136 |
if (vlen <= 0) { |
| 5137 |
return (FALSE); |
| 5138 |
} |
| 5139 |
|
| 5140 |
for (bnd = 0; bnd < 4; bnd++) { /* loop through all boundaries */ |
| 5141 |
|
| 5142 |
/* start with last vertex */ |
| 5143 |
if (bnd == 0) { /* 1st time through use original vertex list */ |
| 5144 |
curlen = vlen; |
| 5145 |
*lenout = 0; |
| 5146 |
s.x = vx[curlen - 1]; |
| 5147 |
s.y = vy[curlen - 1]; |
| 5148 |
} |
| 5149 |
else { /* after 1st time through, use new vertex list */ |
| 5150 |
curlen = *lenout; |
| 5151 |
*lenout = 0; |
| 5152 |
if (curlen > 0) { |
| 5153 |
s.x = xout[curlen - 1]; |
| 5154 |
s.y = yout[curlen - 1]; |
| 5155 |
} |
| 5156 |
} |
| 5157 |
|
| 5158 |
for (i = 0; i < curlen; i++) { /* loop through all vertices */ |
| 5159 |
|
| 5160 |
if (bnd == 0) { |
| 5161 |
p.x = vx[i]; |
| 5162 |
p.y = vy[i]; |
| 5163 |
} |
| 5164 |
else { |
| 5165 |
p.x = xout[i]; |
| 5166 |
p.y = yout[i]; |
| 5167 |
} |
| 5168 |
|
| 5169 |
/* is vertex p 'inside' current boundary */ |
| 5170 |
if (inside_bnd(&p, cmin, cmax, bnd)) { |
| 5171 |
|
| 5172 |
/* is vertex s 'inside' current boundary */ |
| 5173 |
if (inside_bnd(&s, cmin, cmax, bnd)) { |
| 5174 |
|
| 5175 |
/* both p and s are inside, add p to vertex list */ |
| 5176 |
xtemp[*lenout] = p.x; |
| 5177 |
ytemp[(*lenout)++] = p.y; |
| 5178 |
} /* end s is inside */ |
| 5179 |
|
| 5180 |
else { /* p is inside, s is outside, intersect */ |
| 5181 |
|
| 5182 |
t = intersect_bnd(&s, &p, cmin, cmax, bnd); |
| 5183 |
|
| 5184 |
/* add t and p to the vertex list */ |
| 5185 |
xtemp[*lenout] = t.x; |
| 5186 |
ytemp[(*lenout)++] = t.y; |
| 5187 |
xtemp[*lenout] = p.x; |
| 5188 |
ytemp[(*lenout)++] = p.y; |
| 5189 |
} /* end else intersect */ |
| 5190 |
|
| 5191 |
} /* end if p is inside */ |
| 5192 |
|
| 5193 |
else { /* p is outside, is s inside */ |
| 5194 |
|
| 5195 |
if (inside_bnd(&s, cmin, cmax, bnd)) { |
| 5196 |
|
| 5197 |
/* p is outside, s is inside, intersect */ |
| 5198 |
t = intersect_bnd(&s, &p, cmin, cmax, bnd); |
| 5199 |
|
| 5200 |
/* add t to the vertex list */ |
| 5201 |
xtemp[*lenout] = t.x; |
| 5202 |
ytemp[(*lenout)++] = t.y; |
| 5203 |
} /* end intersect */ |
| 5204 |
} /* end else p outside, s inside */ |
| 5205 |
|
| 5206 |
s.x = p.x; |
| 5207 |
s.y = p.y; |
| 5208 |
} /* end for i */ |
| 5209 |
|
| 5210 |
for (j = 0; j < *lenout; j++) { |
| 5211 |
xout[j] = xtemp[j]; |
| 5212 |
yout[j] = ytemp[j]; |
| 5213 |
} /* end for j */ |
| 5214 |
|
| 5215 |
} /* end for bnd */ |
| 5216 |
|
| 5217 |
if (*lenout <= 0) { |
| 5218 |
return (FALSE); |
| 5219 |
} |
| 5220 |
return (TRUE); |
| 5221 |
} /* end poly_clip */ |
| 5222 |
|
| 5223 |
/* inside_bnd */ |
| 5224 |
/* Used by poly_clip and returns true if the vertex is within the |
| 5225 |
* boundary. ( where the boundaries are numbered 1-4,corresponding to |
| 5226 |
* top, right, bottom, left ) |
| 5227 |
*/ |
| 5228 |
static int inside_bnd(point *v, point *bmin, point *bmax, int bound_num) |
| 5229 |
{ |
| 5230 |
/* this routine assumes a rectangular boundary */ |
| 5231 |
switch (bound_num) { |
| 5232 |
case 0: return (v->y <= bmax->y); break; /* top */ |
| 5233 |
case 1: return (v->x <= bmax->x); break; /* right */ |
| 5234 |
case 2: return (v->y >= bmin->y); break; /* bottom */ |
| 5235 |
case 3: return (v->x >= bmin->x); break; /* left */ |
| 5236 |
default: return (FALSE); break; |
| 5237 |
} /* end switch */ |
| 5238 |
} /* end inside_bnd */ |
| 5239 |
|
| 5240 |
/* intersect_bnd */ |
| 5241 |
/* Used by poly_clip. Returns the the intersection point of a polygon |
| 5242 |
* edge with a clip boundary. The clip boundary is coded 1-4, corresponding |
| 5243 |
* to top, right, bottom, and left boundary edges, respectively. |
| 5244 |
*/ |
| 5245 |
static point intersect_bnd(point *p1, point *p2, point *bmin, point *bmax, int bound_num) |
| 5246 |
{ |
| 5247 |
point temp; |
| 5248 |
temp.x = 0; |
| 5249 |
temp.y = 0; |
| 5250 |
|
| 5251 |
switch (bound_num) { |
| 5252 |
case 0: /* top */ |
| 5253 |
temp.x = p1->x + (p2->x - p1->x) * (bmax->y - p1->y) / (p2->y - p1->y); |
| 5254 |
temp.y = bmax->y; |
| 5255 |
break; |
| 5256 |
|
| 5257 |
case 1: /* right */ |
| 5258 |
temp.y = p1->y + (p2->y - p1->y) * (bmax->x - p1->x) / (p2->x - p1->x); |
| 5259 |
temp.x = bmax->x; |
| 5260 |
break; |
| 5261 |
|
| 5262 |
case 2: /* bottom */ |
| 5263 |
temp.x = p1->x + (p2->x - p1->x) * (bmin->y - p1->y) / (p2->y - p1->y); |
| 5264 |
temp.y = bmin->y; |
| 5265 |
break; |
| 5266 |
|
| 5267 |
case 3: /* left */ |
| 5268 |
temp.y = p1->y + (p2->y - p1->y) * (bmin->y - p1->x) / (p2->x - p1->x); |
| 5269 |
temp.x = bmin->x; |
| 5270 |
break; |
| 5271 |
|
| 5272 |
default: |
| 5273 |
/* error check ? */ |
| 5274 |
break; |
| 5275 |
|
| 5276 |
} /* end switch */ |
| 5277 |
return temp; |
| 5278 |
} /* end intersect_bnd */ |
| 5279 |
|
| 5280 |
/*-------------------------------------------------------------*/ |
| 5281 |
/* >> CDR ROUTINES */ |
| 5282 |
/*-------------------------------------------------------------*/ |
| 5283 |
|
| 5284 |
/* cur_state is global - points to current statelist */ |
| 5285 |
/* |
| 5286 |
Open file for sequential access. FORTRAN unit number is ignored. |
| 5287 |
File descriptor which is returned from open is stored in current |
| 5288 |
statelist |
| 5289 |
*/ |
| 5290 |
void cdrofs(int *ifilcd) |
| 5291 |
{ |
| 5292 |
int errnum, errsev; |
| 5293 |
char symbol[1024]; |
| 5294 |
int qdc_index; |
| 5295 |
float value; |
| 5296 |
char *devid; |
| 5297 |
char *env; |
| 5298 |
static int file_cnt = 1; |
| 5299 |
|
| 5300 |
/* if user hasn't named the file, build a default */ |
| 5301 |
if (!cur_state->filename[0]) { /* filename is blank */ |
| 5302 |
/* get the SVDI device code */ |
| 5303 |
qdc_index = 23; |
| 5304 |
vdiqdc(&qdc_index, &value); |
| 5305 |
devid = get_devid_char(value); |
| 5306 |
if (devid != NULL) { |
| 5307 |
snprintf(cur_state->filename, 100, "cgi%s%d", devid, file_cnt++); |
| 5308 |
} |
| 5309 |
else { |
| 5310 |
snprintf(cur_state->filename, 100, "cgiout%d", file_cnt++); |
| 5311 |
} |
| 5312 |
} |
| 5313 |
|
| 5314 |
/* copy filename to symbol */ |
| 5315 |
copy_string(symbol, cur_state->filename, 1024); |
| 5316 |
|
| 5317 |
/* check the environment to see if a file name has been assigned */ |
| 5318 |
env = getenv(symbol); |
| 5319 |
if (env != 0 && strlen(env) < 1024) { |
| 5320 |
snprintf(symbol, 1024, "%s", env); |
| 5321 |
} |
| 5322 |
|
| 5323 |
/* open the file - if it doesn't exist, create it with mode 664 */ |
| 5324 |
/* -- open returns a file descriptor which is stored in the statelist */ |
| 5325 |
/* -- O_TRUNC ??? read/writing??? */ |
| 5326 |
if ((cur_state->file_d = open(symbol, (O_CREAT | O_TRUNC | O_RDWR), 0664)) == -1) { |
| 5327 |
errnum = 722; |
| 5328 |
errsev = 10; |
| 5329 |
char err[50]; |
| 5330 |
snprintf(err, 50, "SVDI ERROR NUMBER %d SEVERITY CODE %d", errnum, errsev); |
| 5331 |
perror(err); |
| 5332 |
} |
| 5333 |
} |
| 5334 |
|
| 5335 |
/* this routine is here only for compatibility with SVDI drivers */ |
| 5336 |
void cdrof3(int *ifilcd, int *idum) { cdrofs(ifilcd); } |
| 5337 |
|
| 5338 |
/* this routine is here only for compatibility with SVDI drivers */ |
| 5339 |
void cdroff(int *ifilcd, int *idum1, int *idum2, int *idum3) { cdrofs(ifilcd); } |
| 5340 |
|
| 5341 |
/* |
| 5342 |
Try to read LENGTH words from the file. Return the actual number |
| 5343 |
of words read. FORTRAN unit number is ignored, file descriptor is |
| 5344 |
gotten from the current statelist |
| 5345 |
*/ |
| 5346 |
void cdrrfs(int *ifilcd, int *length, char *buffer, int *istat) |
| 5347 |
{ |
| 5348 |
|
| 5349 |
/* if the file hasn't been opened, open it */ |
| 5350 |
if (cur_state->file_d == -1) { |
| 5351 |
cdrofs(ifilcd); |
| 5352 |
} |
| 5353 |
|
| 5354 |
/* read the data as a byte stream */ |
| 5355 |
if ((*istat = read(cur_state->file_d, buffer, (*length * cdrcom.KCPW))) != -1) { |
| 5356 |
*istat = *istat / cdrcom.KCPW; |
| 5357 |
} |
| 5358 |
} |
| 5359 |
|
| 5360 |
/* |
| 5361 |
Write LENGTH words from BUFFER to the file. FORTRAN unit number is |
| 5362 |
ignored, file descriptor is gotten from the current state list |
| 5363 |
*/ |
| 5364 |
void cdrwfs(int *ifilcd, int *length, char *buffer, int *istat) |
| 5365 |
{ |
| 5366 |
|
| 5367 |
/* if the file hasn't been opened, open it */ |
| 5368 |
if (cur_state->file_d == 0) { |
| 5369 |
cdrofs(ifilcd); |
| 5370 |
} |
| 5371 |
|
| 5372 |
/* write out the data as a byte stream. */ |
| 5373 |
if ((*istat = write(cur_state->file_d, buffer, (*length * cdrcom.KCPW))) == -1) { |
| 5374 |
*istat = 1; |
| 5375 |
} |
| 5376 |
else { |
| 5377 |
*istat = 0; |
| 5378 |
} |
| 5379 |
} |
| 5380 |
|
| 5381 |
/* |
| 5382 |
Close file sequential. FORTRAN unit number is ignore and file |
| 5383 |
descriptor is gotten from current state |
| 5384 |
*/ |
| 5385 |
void cdrcfs(int *ifilcd, int *eof) |
| 5386 |
{ |
| 5387 |
int istat; |
| 5388 |
char buf[4]; |
| 5389 |
|
| 5390 |
/* if eof = 1 then write eof on file */ |
| 5391 |
if (*eof == 1) { |
| 5392 |
*buf = EOF; |
| 5393 |
if ((istat = write(cur_state->file_d, buf, 4)) == -1) { |
| 5394 |
char err[50]; |
| 5395 |
snprintf(err, 50, "%s", "CDRCFS error"); |
| 5396 |
perror(err); |
| 5397 |
} |
| 5398 |
} |
| 5399 |
|
| 5400 |
/* close the file */ |
| 5401 |
close(cur_state->file_d); |
| 5402 |
} |
| 5403 |
|
| 5404 |
/* open routine for the Abekas */ |
| 5405 |
void cdroab(int *ifilcd, int *frame) |
| 5406 |
{ |
| 5407 |
char ic[5]; |
| 5408 |
int i, inbr; |
| 5409 |
|
| 5410 |
/* form the file name from the frame number */ |
| 5411 |
inbr = *frame; |
| 5412 |
for (i = 3; i >= 0; i--) { |
| 5413 |
ic[i] = inbr % 10 + '0'; |
| 5414 |
inbr = inbr / 10; |
| 5415 |
} |
| 5416 |
ic[4] = '\0'; |
| 5417 |
|
| 5418 |
/* set the file name in the state list */ |
| 5419 |
snprintf(cur_state->filename, 100, "%s.RGB", ic); |
| 5420 |
|
| 5421 |
cdrofs(ifilcd); |
| 5422 |
} |
| 5423 |
|
| 5424 |
/* |
| 5425 |
Metafile buffering routine. (device dependent ) |
| 5426 |
Metafile driver passes OUTARY as an integer array, always with |
| 5427 |
16 bits/word, right justified. This buffering routine assumes |
| 5428 |
16 bits/word and assumes 8 bit bytes. |
| 5429 |
*/ |
| 5430 |
void nmtbuf(int *numwds, unsigned outary[]) |
| 5431 |
{ |
| 5432 |
static unsigned mask1 = ~(~0u << 8) << 8; /* mask off higher 8 bits */ |
| 5433 |
static unsigned mask2 = ~(~0u << 8); /* mask off lower 8 bits */ |
| 5434 |
|
| 5435 |
int i; /* loop variable */ |
| 5436 |
int istat; /* error reporting */ |
| 5437 |
|
| 5438 |
/* cur_state is global and points to the current state */ |
| 5439 |
|
| 5440 |
/* check for buffer flush and if there is something to flush */ |
| 5441 |
if (*numwds <= 0 && cur_state->buff_ptr > 0) { |
| 5442 |
|
| 5443 |
/* write out the data as a byte stream. */ |
| 5444 |
if ((istat = write(cur_state->file_d, cur_state->buffer, cur_state->buff_ptr)) == -1) { |
| 5445 |
char err[50]; /* for error reporting */ |
| 5446 |
snprintf(err, 50, "%s", "NMTBUF: write error"); |
| 5447 |
perror(err); |
| 5448 |
} /* end write buffer */ |
| 5449 |
|
| 5450 |
/* reset buff pointer */ |
| 5451 |
cur_state->buff_ptr = 0; |
| 5452 |
|
| 5453 |
} /* end if buffer flush */ |
| 5454 |
|
| 5455 |
else { /* pack outary into buffer */ |
| 5456 |
|
| 5457 |
for (i = 0; i < *numwds; i++) { |
| 5458 |
cur_state->buffer[cur_state->buff_ptr++] = (outary[i] & mask1) >> 8; |
| 5459 |
cur_state->buffer[cur_state->buff_ptr++] = (outary[i] & mask2); |
| 5460 |
|
| 5461 |
if (cur_state->buff_ptr > BUFFER_SIZE - 2) { |
| 5462 |
|
| 5463 |
/* write out the data as a byte stream. */ |
| 5464 |
if ((istat = write(cur_state->file_d, cur_state->buffer, cur_state->buff_ptr)) == -1) { |
| 5465 |
char err[50]; /* for error reporting */ |
| 5466 |
snprintf(err, 50, "%s", "NMTBUF: write error"); |
| 5467 |
perror(err); |
| 5468 |
|
| 5469 |
} /* end write buffer */ |
| 5470 |
|
| 5471 |
/* reset buff pointer */ |
| 5472 |
cur_state->buff_ptr = 0; |
| 5473 |
|
| 5474 |
} /* end if > BUFFER_SIZE */ |
| 5475 |
} /* end for i=... */ |
| 5476 |
} |
| 5477 |
} /* end nmtbuf */ |