File: cgdriv.c

package info (click to toggle)
pgplot5 5.2.2-19.8
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 7,192 kB
  • sloc: fortran: 39,795; ansic: 22,554; objc: 1,534; sh: 1,298; makefile: 269; pascal: 233; perl: 209; tcl: 190; awk: 51; csh: 25
file content (763 lines) | stat: -rw-r--r-- 20,382 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
/*
 * PGPLOT CGM (Computer Graphics Metafile) Driver
 * Version: 1.0 - 17/12/97
 * 
 * Author: Robin Sergeant, Rutherford Appleton Laboratory (Oxfordshire, UK)
 * Email: rsergeant@clara.net
 * WWW: http://www.isis.rl.ac.uk/computing/cgmdriv.htm
 *
 * Output conforms to version 1 of the CGM specification
 *
 * NB Scaling information is ignored by some products (eg MS Word).
 *    However it has been included as some software will take advantage 
 *    of this.
 *
 */

#define DPI 1000            /* set the resoloution to 1000 dpi */
#define PAGE_WIDTH 7.8      /* set the page width to 7.8 inches */
#define PAGE_HEIGHT 10.5    /* set the page height to 10.5 inches */

typedef unsigned short WORD;
typedef unsigned char BYTE;

typedef struct rgb
{
    BYTE r;
    BYTE g;
    BYTE b;
    BYTE pad;		    /* So structure is aligned */
} COLOUR;

static int words_bigendian = 0;     /* Machine type (1 = Bigendian) */ 

/*
 * Certain symbols in fcntl.h may not get defined
 * unless the _POSIX_SOURCE feature-test macro is set.
 */
#ifndef _POSIX_SOURCE
#define _POSIX_SOURCE
#endif

#ifdef _WIN32
#define CGDRIV CGDRIV
#elif defined(PG_PPU)
#define CGDRIV cgdriv_
#else
#define CGDRIV cgdriv
#endif

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#ifndef convex
#include <string.h>
#endif

/*
 * VAX VMS includes etc..
 */
#ifdef VMS
#include <signal.h>  /* sleep() is prototyped here */
#include <unixio.h>  /* access() is prototyped here */
#include <descrip.h>
#include <ssdef.h>
#include <clidef.h>
#include <libclidef.h>
#include <lib$routines.h>

typedef struct dsc$descriptor_s VMS_string;

#define VMS_STRING(dsc, string) \
  dsc.dsc$w_length = strlen(string); \
  dsc.dsc$b_dtype = DSC$K_DTYPE_T; \
  dsc.dsc$b_class = DSC$K_CLASS_S; \
  dsc.dsc$a_pointer = string;

static int vms_define_command(char *file, char *command);
static int vms_spawn_nowait(char *command);
#endif

#ifndef VMS
#include <fcntl.h>

#if defined (HAVE_UNISTD_H)
#  include <unistd.h>
#endif /* HAVE_UNISTD_H */

#endif

static void pg_colour_setup(COLOUR *c)
{
    int count;
    c[0].r=255;c[0].g=255;c[0].b=255;       /* White (background) */
    c[1].r=0;c[1].g=0;c[1].b=0;             /* Black (default) */
    c[2].r=255;c[2].g=0;c[2].b=0;           /* Red */
    c[3].r=0;c[3].g=255;c[3].b=0;           /* Green */
    c[4].r=0;c[4].g=0;c[4].b=255;           /* Blue */
    c[5].r=0;c[5].g=255;c[5].b=255;         /* Cyan (Green + Blue) */
    c[6].r=255;c[6].g=0;c[6].b=255;         /* Magenta (Red + Blue) */
    c[7].r=255;c[7].g=255;c[7].b=0;         /* Yellow (Red + Green) */
    c[8].r=255;c[8].g=128;c[8].b=0;         /* Red + Yellow (Orange) */
    c[9].r=128;c[9].g=255;c[9].b=0;         /* Green + Yellow */
    c[10].r=0;c[10].g=255;c[10].b=128;      /* Green + Cyan */
    c[11].r=0;c[11].g=128;c[11].b=255;      /* Blue + Cyan */
    c[12].r=128;c[12].g=0;c[12].b=255;      /* Blue + Magenta */
    c[13].r=255;c[13].g=0;c[13].b=128;      /* Red + Magenta */
    c[14].r=84;c[14].g=84;c[14].b=84;       /* Dark Gray */
    c[15].r=168;c[15].g=168;c[15].b=168;    /* Light Gray */
    for (count=16;count<256;count++) {
        c[count].r=0;c[count].g=0;c[count].b=0; /* make the rest Black */
    }
    return;
}

static int write_byte(FILE *pt,BYTE b)
{
    int error = 0; /* clear error flag */
    if (putc(b,pt) == EOF)
        error = 1; /* set error flag */
    return error;
}

static int write_word(FILE *pt,WORD w)
{
    BYTE *cp;
    int error;
    cp=(BYTE*)&w;
    if (words_bigendian) {
        write_byte(pt,cp[0]);   /* write in big-endian format */
        error = write_byte(pt,cp[1]);
    } else {
        write_byte(pt,cp[1]);   /* write in big-endian format */
        error = write_byte(pt,cp[0]);
    }
    return error;
}

static void write_float(FILE *pt,float f)
{
    BYTE *cp;
    cp=(BYTE*)&f;
    if (words_bigendian) {
        write_byte(pt,cp[0]);   /* write in big-endian format */
        write_byte(pt,cp[1]);
        write_byte(pt,cp[2]);
        write_byte(pt,cp[3]);
    } else {        
        write_byte(pt,cp[3]);   /* write in big-endian format */
        write_byte(pt,cp[2]);
        write_byte(pt,cp[1]);
        write_byte(pt,cp[0]);
    }
    return;
}

static FILE* begin_metafile(const char *filename,const char *name)
{
    int c,length;
    FILE *pt;
    length=strlen(name);
    pt=fopen(filename,"wb");
    if (pt == NULL)
        return pt;
    if (length < 30)    /* use short format if possible */
        write_word(pt,(WORD)(0x0020+length+1));
    else {
        write_word(pt,0x003f);
        write_word(pt,(WORD)(length+1));
    }
    write_byte(pt,(BYTE)length);
    for (c=0;c<length;c++) {
        write_byte(pt,name[c]);
    }
    if (length%2 == 0)  /* pad with trailing null if necessary */
        write_byte(pt,0);
    return pt;
}

static void metafile_version(FILE *pt)
{
    write_word(pt,0x1022);
    write_word(pt,0x0001);
    return;
}

static void metafile_description(FILE *pt,const char *name)
{
    int c,length;
    length=strlen(name);
    if (length < 30)    /* use short format if possible */
        write_word(pt,(WORD)(0x1040+length+1));
    else {
        write_word(pt,0x105f);
        write_word(pt,(WORD)(length+1));
    }
    write_byte(pt,(BYTE)length);
    for (c=0;c<length;c++) {
        write_byte(pt,name[c]);
    }
    if (length%2 == 0)  /* pad with trailing null if necessary */
        write_byte(pt,0);
    return;
}

static void metafile_element_list(FILE *pt)
{
    write_word(pt,0x1166);
    write_word(pt,0x0001);
    write_word(pt,0xffff);
    write_word(pt,0x0001);
    return;
}

static void begin_picture(FILE *pt,char *name)
{
    int c,length;
    length = strlen(name);
    if (length < 30)    /* use short format if possible */
        write_word(pt,(WORD)(0x0060+length+1));
    else {
        write_word(pt,0x007f);
        write_word(pt,(WORD)(length+1));
    }
    write_byte(pt,(BYTE)length);
    for (c=0;c<length;c++) {
        write_byte(pt,name[c]);
    }
    if (length%2 == 0)  /* pad with trailing null if necessary */
        write_byte(pt,0);
    return;
}

static void colour_selection_mode(FILE *pt,int mode)
{
    write_word(pt,0x2042);
    write_word(pt,(WORD)mode);
    return;
}

static void colour_table(FILE *pt,BYTE index,BYTE r,BYTE g,BYTE b)
{
    write_word(pt,0x5444);
    write_byte(pt,index);
    write_byte(pt,r);
    write_byte(pt,g);
    write_byte(pt,b);
    return;
}

static void line_width_specification_mode(FILE *pt,WORD mode)
{
    write_word(pt,0x2062);
    write_word(pt,mode);
    return;
}

static void vdc_extent(FILE *pt,WORD x1,WORD y1,WORD x2,WORD y2)
{
    write_word(pt,0x20c8);
    write_word(pt,x1);
    write_word(pt,y1);
    write_word(pt,x2);
    write_word(pt,y2);
    return;
}

static void begin_picture_body(FILE *pt)
{
    write_word(pt,0x0080);
    return;
}

static void line_colour(FILE *pt,int colourMode,BYTE index,COLOUR colours[])
{
    if (colourMode == 0) {      /* write in indexed colour format */
        write_word(pt,0x5081);
        write_byte(pt,index);
    } else {                    /* write in direct colour format */
        write_word(pt,0x5083);
        write_byte(pt,colours[index].r);
        write_byte(pt,colours[index].g);
        write_byte(pt,colours[index].b);
    }
    write_byte(pt,0);
    return;
}

static void fill_colour(FILE *pt,int colourMode,BYTE index,COLOUR colours[])
{
    if (colourMode == 0) {      /* write in indexed colour format */
        write_word(pt,0x52e1);
        write_byte(pt,index);
    } else {                    /* write in direct colour format */
        write_word(pt,0x52e3);
        write_byte(pt,colours[index].r);
        write_byte(pt,colours[index].g);
        write_byte(pt,colours[index].b);
    }
    write_byte(pt,0);
    return;
}

static void line_width(FILE *pt,WORD width)
{
    write_word(pt,0x5062);
    write_word(pt,width);
    return;
}

static void interior_style(FILE *pt,WORD style)
{
    write_word(pt,0x52c2);
    write_word(pt,style);
    return;
}

static void polyline(FILE *pt,WORD points[],int length)
{
    int c;
    if (length < 16)    /* use short format if possible */
        write_word(pt,(WORD)(0x4020+length*2));
    else {
        write_word(pt,0x403f);
        write_word(pt,(WORD)(length*2));
    }
    for (c=0;c<length;c++) {
        write_word(pt,points[c]);
    }
    return;
}

static void line(FILE *pt,WORD x1,WORD y1,WORD x2,WORD y2)
{
    WORD points[4];
    points[0]=x1;
    points[1]=y1;
    points[2]=x2;
    points[3]=y2;
    polyline(pt,points,4);
    return;
}

static void polygon(FILE *pt,WORD points[],int length)
{
    int c;
    if (length < 16)    /* use short format if possible */
        write_word(pt,(WORD)(0x40e0+length*2));
    else {
        write_word(pt,0x40ff);
        write_word(pt,(WORD)(length*2));
    }
    for (c=0;c<length;c++) {
        write_word(pt,points[c]);
    }
    return;
}

static void rectangle(FILE *pt,WORD x1,WORD y1,WORD x2,WORD y2)
{
    write_word(pt,0x4168);
    write_word(pt,x1);
    write_word(pt,y1);
    write_word(pt,x2);
    write_word(pt,y2);
    return;
}

static void circle(FILE *pt,WORD centreX,WORD centreY,WORD radius)
{
    write_word(pt,0x4186);
    write_word(pt,centreX);
    write_word(pt,centreY);
    write_word(pt,radius);
}

static void end_picture(FILE *pt)
{
    write_word(pt,0x00a0);
    return;
}

static void end_metafile(FILE *pt)
{
    int error;
    error = write_word(pt,0x0040);
    if (error == 1)
        printf("CGMDRIV:Error writing bytes, file is incomplete\n");
    fclose(pt);
    return;
}

static void real_precision(FILE *pt,WORD p1,WORD p2,WORD p3)
{
    write_word(pt,0x10a6);
    write_word(pt,p1);
    write_word(pt,p2);
    write_word(pt,p3);
    return;
}

static void scaling_mode(FILE *pt,float scale)
{
    write_word(pt,0x2026);
    write_word(pt,1);
    write_float(pt,scale);
    return;
}

#ifdef _WIN32
void __stdcall CGDRIV(ifunc, rbuf, nbuf, chr, len, lchr, mode)
    int   *ifunc, *nbuf, *lchr, *mode;
    unsigned len;
    float rbuf[];
    char  *chr;
{
#elif defined(VMS)
void CGDRIV(ifunc, rbuf, nbuf, chrdsc, lchr, mode)
     int *ifunc;
     float rbuf[];
     int *nbuf;
     struct dsc$descriptor_s *chrdsc; /* VMS FORTRAN string descriptor */
     int *lchr;
     int *mode;
{
    int len = chrdsc->dsc$w_length;
    char *chr = chrdsc->dsc$a_pointer;
#else
void CGDRIV(ifunc, rbuf, nbuf, chr, lchr, mode, len)
    int *ifunc, *nbuf, *lchr, *mode;
    int len;
    float rbuf[];
    char *chr;
{
#endif

    static FILE *pt;
    static COLOUR colours[256];
    static int width = 1;
    static int state = 0;       /* Device state (1 = open) */
    static int picture;         /* Picture number */
    static int colourMode;      /* 0 = indexed, 1 = direct */
    static int status = 0;      /* Driver status (1 = called) */

    colourMode = *mode - 1;
    if (!status) {              /* Check machine type on first call */
        WORD test = 0x100;
        BYTE* cp;
        cp = (BYTE*)&test;
        if (cp[0] == 1) {
            words_bigendian = 1;
        }
        status = 1;
    }
    switch(*ifunc) {

/*--- IFUNC=1, Return device name ---------------------------------------*/

    case 1:
    {
        const char *dev_name;
        int c;
        if (*mode == 1)
            dev_name = "CGM (CGM file, indexed colour selection mode)";
        else
            dev_name = "CGMD (CGM file, direct colour selection mode)";
        *lchr = strlen(dev_name);
        strncpy(chr, dev_name, len);
        for (c = *lchr;c<(int)len;c++)
            chr[c] = ' ';
    };
    break;

/*--- IFUNC=2, Return physical min and max for plot device, and range
               of color indices -----------------------------------------*/
    case 2:
        rbuf[0] = 0.0;
        rbuf[1] = 32767.0;
        rbuf[2] = 0.0;
        rbuf[3] = 32767.0;
        rbuf[4] = 0.0;
        rbuf[5] = 255.0;
        *nbuf = 6;
        break;

/*--- IFUNC=3, Return device resolution ---------------------------------*/

    case 3:
        rbuf[0] = DPI;   /* device coordinates per inch */
        rbuf[1] = DPI;
        rbuf[2] = 1.0;		/* Device coordinates per pixel */
        *nbuf = 3;
        break;

/*--- IFUNC=4, Return misc device info ----------------------------------*/

    case 4:
        chr[0] = 'H'; /* Hardcopy device */
        chr[1] = 'N'; /* Cursor is not available */
        chr[2] = 'N'; /* No dashed lines */
        chr[3] = 'A'; /* Area fill available */
        chr[4] = 'T'; /* Thick lines available*/
        chr[5] = 'R'; /* Rectangle fill available */
        chr[6] = 'P'; /* Line of pixels available */
        chr[7] = 'N'; /* Do not prompt on close */
        chr[8] = 'Y'; /* Can return color representation */
        chr[9] = 'N'; /* Not used */
        chr[10] = 'N'; /* Not used */
        *lchr = 11;
        break;

/*--- IFUNC=5, Return default file name ---------------------------------*/

    case 5:
    {
        const char *file_name;
        int c;
        file_name = "pgplot.cgm";
        *lchr = strlen(file_name);
        strncpy(chr, file_name, len);
        for (c = *lchr;c<(int)len;c++)
            chr[c] = ' ';
    }
    break;

/*--- IFUNC=6, Return default physical size of plot ---------------------*/

    case 6:
	    rbuf[0] = 0.0;
	    rbuf[1] = PAGE_WIDTH * DPI;
	    rbuf[2] = 0.0;
	    rbuf[3] = PAGE_HEIGHT * DPI;
        *nbuf = 4;
        break;

/*--- IFUNC=7, Return misc defaults -------------------------------------*/

    case 7:
        rbuf[0] = 1.0;
        *nbuf = 1;
        break;

/*--- IFUNC=8, Select plot ----------------------------------------------*/

    case 8:
        break;

/*--- IFUNC=9, Open workstation -----------------------------------------*/

    case 9:
    {
        const char *name = "PGPLOT CGM File";
        const char *desc = "$Revision: 1.19 $";
        char *filename;
        if (state == 1) {       /* only allow one device */
            printf("CGMDRIV:Error a CGM file is already open\n");
            rbuf[1] = 0.0;  /* error while opening device */
            return;
        }
        filename = (char*)malloc(*lchr * sizeof(char) + 1);
        strncpy(filename, chr, *lchr);
	    filename[*lchr] = '\0';
        pt = begin_metafile(filename, name);
        free(filename);
        if (pt != NULL) {
            state = 1;
            picture = 0;
            pg_colour_setup(colours);
            metafile_version(pt);
            metafile_description(pt,desc);
            real_precision(pt,0,9,23);  /* set to 32-bit floating point */
            metafile_element_list(pt);        
            rbuf[0] = 1.0;
            rbuf[1] = 1.0;  /* no error */
        } else
            rbuf[1] = 0.0;  /* error while opening device */
        *nbuf = 2;
    }
    break;

/*--- IFUNC=10, Close workstation ---------------------------------------*/

    case 10:
        state = 0;
        end_metafile(pt);    
        break;

/*--- IFUNC=11, Begin picture -------------------------------------------*/

    case 11:
    {
        int c;
        char name[60];
        picture++;
        sprintf(name,"Picture %d",picture);
        begin_picture(pt,name);
        colour_selection_mode(pt,colourMode);
        line_width_specification_mode(pt,0);
        vdc_extent(pt,0x0000,0x0000,(WORD)(rbuf[0]+0.5),(WORD)(rbuf[1]+0.5));
        scaling_mode(pt,0.0254F); /* 1 VDC pixel = 0.0254mm or 1/1000" */
        begin_picture_body(pt);
        interior_style(pt,1);
        if (colourMode == 0)    /* add colour table entries if needed */
        {
            for (c=0;c<16;c++)
                colour_table(pt,(BYTE)c,colours[c].r,colours[c].g,colours[c].b);
        }
    }    
    break;

/*--- IFUNC=12, Draw line -----------------------------------------------*/

    case 12:
        line(pt,(WORD)(rbuf[0]+0.5),(WORD)(rbuf[1]+0.5),(WORD)(rbuf[2]+0.5),(WORD)(rbuf[3]+0.5));
        break;

/*--- IFUNC=13, Draw dot ------------------------------------------------*/

    case 13:
        circle(pt,(WORD)(rbuf[0]+0.5),(WORD)(rbuf[1]+0.5),(WORD)width);
        break;

/*--- IFUNC=14, End picture ---------------------------------------------*/

    case 14:
        end_picture(pt);
        break;

/*--- IFUNC=15, Select color index --------------------------------------*/

    case 15:
    {
        int i = (int)(rbuf[0]+0.5);
        line_colour(pt,colourMode,(BYTE)i,colours);
        fill_colour(pt,colourMode,(BYTE)i,colours);
    }  
    break;

/*--- IFUNC=16, Flush buffer. -------------------------------------------*/

    case 16:
        break;

/*--- IFUNC=17, Read cursor. --------------------------------------------*/

    case 17:
        *nbuf = -1;
        break;

/*--- IFUNC=18, Erase alpha screen. -------------------------------------*/
 
    case 18:
        break;

/*--- IFUNC=19, Set line style. -----------------------------------------*/

    case 19:
        *nbuf = -1;
        break;

/*--- IFUNC=20, Polygon fill. -------------------------------------------*/

    case 20:
    {
        static int n = 0;   /* set no. of points to 0 (no polygon) */
        static int c;
        static WORD *points;
        if (n==0) {     /* first call for this polygon? */
            n = (int)(rbuf[0]+0.5)*2; /* if so, set n and allocate memory */
            c = 0;  /* point counter */
            points = (WORD*)malloc(sizeof(WORD)*n);
        } else {
            points[c] = (WORD)(rbuf[0]+0.5);     /* add points to array */
            points[c+1] = (WORD)(rbuf[1]+0.5);
            if (c==n-2) {   /* final set of points? */
                polygon(pt,points,n);   /* if so, create polygon */
                n = 0;
                free(points);
            } else
                c = c+2;
        }    
    }
    break;

/*--- IFUNC=21, Set color representation. -------------------------------*/

    case 21:
    {
        int i = (int)(rbuf[0]+0.5);
        colours[i].r = (int)(255*rbuf[1]+0.5);  /* convert from rgb scales to rgb values */
        colours[i].g = (int)(255*rbuf[2]+0.5);
        colours[i].b = (int)(255*rbuf[3]+0.5);
        if (colourMode == 0)    /* add colour table entry if needed */
            colour_table(pt,(BYTE)i,colours[i].r,colours[i].g,colours[i].b);
    }
    break;

/*--- IFUNC=22, Set line width. -----------------------------------------*/

    case 22:
        width = (int)(rbuf[0]*0.005*DPI+0.5);
        if (width == 0)
            width = 1;
        line_width(pt,(WORD)width);
        break;

/*--- IFUNC=23, Escape --------------------------------------------------*/

    case 23:
        break;

/*--- IFUNC=24, Rectangle Fill. -----------------------------------------*/

    case 24:
        rectangle(pt,(WORD)(rbuf[0]+0.5),(WORD)(rbuf[1]+0.5),(WORD)(rbuf[2]+0.5),(WORD)(rbuf[3]+0.5));
        break;

/*--- IFUNC=25, ---------------------------------------------------------*/

    case 25:
        break;

/*--- IFUNC=26, Line of pixels ------------------------------------------*/

    case 26:
    {
        int x,y,c,i,oldi,x1;
        if (width > 1)      /* make sure the width is 1 */
            line_width(pt,1);
        x = (int)(rbuf[0]+0.5);   /* start co-ordinates */
        y = (int)(rbuf[1]+0.5);
        x1 = 0;     /* set line offset to 0 */
        oldi = (int)(rbuf[2]+0.5);    /* set old colour index to the first */
        for (c=0;c<*nbuf-2;c++)
        {
            i = (int)(rbuf[c+2]+0.5);
            if (i != oldi) {    /* if colour changed then draw line */
                line_colour(pt,colourMode,(BYTE)oldi,colours);
                line(pt,(WORD)(x+x1),(WORD)y,(WORD)(x+c),(WORD)y);
                x1 = c;     /* reset line offset */
            }
            oldi = i;
        }
        line_colour(pt,colourMode,(BYTE)oldi,colours);
        line(pt,(WORD)(x+x1),(WORD)y,(WORD)(x+c),(WORD)y);    /* add final line */
        if (width > 1) 
            line_width(pt,(WORD)width);   /* reset width if changed above */ 
    }
    break;

/*--- IFUNC=29, Query color representation ------------------------------*/
    case 29:
    {
        int i = (int)(rbuf[0]+0.5);
        rbuf[1] = (float)colours[i].r/255;  /* convert from rgb values to rgb scales */
        rbuf[2] = (float)colours[i].g/255;
        rbuf[3] = (float)colours[i].b/255;
        *nbuf = 4;
    }
    break;
  };
  return;
}