~ubuntu-branches/ubuntu/intrepid/plplot/intrepid

« back to all changes in this revision

Viewing changes to src/plbuf.c

  • Committer: Bazaar Package Importer
  • Author(s): Rafael Laboissiere
  • Date: 2006-11-04 10:19:34 UTC
  • mfrom: (2.1.8 edgy)
  • Revision ID: james.westby@ubuntu.com-20061104101934-mlirvdg4gpwi6i5q
Tags: 5.6.1-10
* Orphaning the package
* debian/control: Changed the maintainer to the Debian QA Group

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: plbuf.c,v 1.3 2004/01/31 06:39:53 airwin Exp $
 
1
/* $Id: plbuf.c,v 1.10 2005/05/10 12:37:41 tomduck Exp $
2
2
 
3
3
    Handle plot buffer.
4
4
 
5
5
    Copyright (C) 1992  Maurice LeBrun
6
6
    Copyright (C) 2004  Alan W. Irwin
 
7
    Copyright (C) 2005  Thomas J. Duck
7
8
 
8
9
    This file is part of PLplot.
9
10
 
19
20
 
20
21
    You should have received a copy of the GNU Library General Public License
21
22
    along with PLplot; if not, write to the Free Software
22
 
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
23
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
24
*/
24
25
 
25
26
#define NEED_PLDEBUG
189
190
    }
190
191
 
191
192
    case PLSTATE_COLOR0: {
192
 
        U_CHAR icol0 = pls->icol0;
 
193
        short icol0 = pls->icol0;
193
194
        U_CHAR r = pls->curcolor.r;
194
195
        U_CHAR g = pls->curcolor.g;
195
196
        U_CHAR b = pls->curcolor.b;
196
197
 
197
 
        fwrite(&icol0, sizeof(U_CHAR), 1, pls->plbufFile);
 
198
        fwrite(&icol0, sizeof(short), 1, pls->plbufFile);
198
199
        if (icol0 == PL_RGB_COLOR) {
199
200
            fwrite(&r, sizeof(U_CHAR), 1, pls->plbufFile);
200
201
            fwrite(&g, sizeof(U_CHAR), 1, pls->plbufFile);
204
205
    }
205
206
 
206
207
    case PLSTATE_COLOR1: {
207
 
        U_CHAR icol1 = pls->icol1;
 
208
        short icol1 = pls->icol1;
208
209
 
209
 
        fwrite(&icol1, sizeof(U_CHAR), 1, pls->plbufFile);
 
210
        fwrite(&icol1, sizeof(short), 1, pls->plbufFile);
210
211
        break;
211
212
    }
212
213
 
251
252
}
252
253
 
253
254
/*--------------------------------------------------------------------------*\
 
255
 * plbuf_text()
 
256
 *
 
257
 * Handle text call.
 
258
\*--------------------------------------------------------------------------*/
 
259
 
 
260
static void
 
261
plbuf_text(PLStream *pls, EscText *text)
 
262
{
 
263
  PLINT n;
 
264
  PLUNICODE fci;
 
265
 
 
266
  dbug_enter("plbuf_text");
 
267
  
 
268
  /* Retrieve the font characterization integer */
 
269
  plgfci(&fci);
 
270
 
 
271
  /* Write the text information */
 
272
 
 
273
  fwrite(&fci, sizeof(PLUNICODE), 1, pls->plbufFile);
 
274
 
 
275
  fwrite(&pls->chrht, sizeof(PLFLT), 1, pls->plbufFile);
 
276
  fwrite(&pls->diorot, sizeof(PLFLT), 1, pls->plbufFile);
 
277
  fwrite(&pls->clpxmi, sizeof(PLFLT), 1, pls->plbufFile);
 
278
  fwrite(&pls->clpxma, sizeof(PLFLT), 1, pls->plbufFile);
 
279
  fwrite(&pls->clpymi, sizeof(PLFLT), 1, pls->plbufFile);
 
280
  fwrite(&pls->clpyma, sizeof(PLFLT), 1, pls->plbufFile);
 
281
    
 
282
  fwrite(&text->base, sizeof(PLINT), 1, pls->plbufFile);
 
283
  fwrite(&text->just, sizeof(PLFLT), 1, pls->plbufFile);
 
284
  fwrite(text->xform, sizeof(PLFLT), 4, pls->plbufFile);
 
285
  fwrite(&text->x, sizeof(PLINT), 1, pls->plbufFile);
 
286
  fwrite(&text->y, sizeof(PLINT), 1, pls->plbufFile);
 
287
  fwrite(&text->refx, sizeof(PLINT), 1, pls->plbufFile);
 
288
  fwrite(&text->refy, sizeof(PLINT), 1, pls->plbufFile);
 
289
 
 
290
  fwrite(&text->unicode_array_len, sizeof(PLINT), 1, pls->plbufFile);
 
291
  if(text->unicode_array_len)
 
292
    fwrite(text->unicode_array, sizeof(PLUNICODE), 
 
293
           text->unicode_array_len, pls->plbufFile);
 
294
}
 
295
 
 
296
/*--------------------------------------------------------------------------*\
254
297
 * plbuf_esc()
255
298
 *
256
299
 * Escape function.  Note that any data written must be in device
261
304
 *      PLESC_FILL      Fill polygon
262
305
 *      PLESC_SWIN      Set plot window parameters
263
306
 *      PLESC_IMAGE     Draw image
 
307
 *      PLESC_HAS_TEXT  Draw PostScript text
264
308
\*--------------------------------------------------------------------------*/
265
309
 
266
310
void
281
325
    case PLESC_IMAGE:
282
326
        plbuf_image(pls, (IMG_DT *) ptr);
283
327
        break;
 
328
    case PLESC_HAS_TEXT:
 
329
      if(ptr!=NULL) /* Check required by GCW driver, please don't remove */
 
330
          plbuf_text(pls, (EscText *) ptr);
 
331
        break;
284
332
    }
285
333
}
286
334
 
431
479
    }
432
480
 
433
481
    case PLSTATE_COLOR0:{
434
 
        U_CHAR icol0, r, g, b;
 
482
        short icol0;
 
483
        U_CHAR r, g, b;
435
484
 
436
 
        fread(&icol0, sizeof(U_CHAR), 1, pls->plbufFile);
 
485
        fread(&icol0, sizeof(short), 1, pls->plbufFile);
437
486
        if (icol0 == PL_RGB_COLOR) {
438
487
            fread(&r, sizeof(U_CHAR), 1, pls->plbufFile);
439
488
            fread(&g, sizeof(U_CHAR), 1, pls->plbufFile);
440
489
            fread(&b, sizeof(U_CHAR), 1, pls->plbufFile);
441
490
        }
442
491
        else {
443
 
            if ((int) icol0 < 0 || (int) icol0 >= pls->ncol0) {
444
 
              char buffer[256];
445
 
              sprintf(buffer, "rdbuf_state: Invalid color map entry: %d", (int) icol0);
446
 
              plabort(buffer);
447
 
              return;
 
492
            if ((int) icol0 >= pls->ncol0) {
 
493
                char buffer[256];
 
494
                sprintf(buffer, "rdbuf_state: Invalid color map entry: %d", (int) icol0);
 
495
                plabort(buffer);
 
496
                return;
448
497
            }
449
498
            r = pls->cmap0[icol0].r;
450
499
            g = pls->cmap0[icol0].g;
460
509
    }
461
510
 
462
511
    case PLSTATE_COLOR1: {
463
 
        U_CHAR icol1;
 
512
        short icol1;
464
513
 
465
 
        fread(&icol1, sizeof(U_CHAR), 1, pls->plbufFile);
 
514
        fread(&icol1, sizeof(short), 1, pls->plbufFile);
466
515
 
467
516
        pls->icol1 = icol1;
468
517
        pls->curcolor.r = pls->cmap1[icol1].r;
500
549
 *      PLESC_FILL      Fill polygon
501
550
 *      PLESC_SWIN      Set plot window parameters
502
551
 *      PLESC_IMAGE     Draw image
 
552
 *      PLESC_HAS_TEXT  Draw PostScript text
503
553
\*--------------------------------------------------------------------------*/
504
554
 
505
555
static void
506
556
rdbuf_image(PLStream *pls);
507
557
 
508
558
static void
 
559
rdbuf_text(PLStream *pls);
 
560
 
 
561
static void
509
562
rdbuf_esc(PLStream *pls)
510
563
{
511
564
    U_CHAR op;
524
577
    case PLESC_IMAGE:
525
578
        rdbuf_image(pls);
526
579
        break;
 
580
    case PLESC_HAS_TEXT:
 
581
        rdbuf_text(pls);
 
582
        break;
527
583
    }
528
584
}
529
585
 
557
613
static void
558
614
rdbuf_image(PLStream *pls)
559
615
{
560
 
  short *dev_ix, *dev_iy;
561
 
  unsigned short *dev_z, dev_zmin, dev_zmax;
562
 
  PLINT nptsX,nptsY, npts;
563
 
  PLFLT xmin, ymin, dx, dy;
 
616
    short *dev_ix, *dev_iy;
 
617
    unsigned short *dev_z, dev_zmin, dev_zmax;
 
618
    PLINT nptsX,nptsY, npts;
 
619
    PLFLT xmin, ymin, dx, dy;
564
620
 
565
621
    dbug_enter("rdbuf_image");
566
622
 
616
672
}
617
673
 
618
674
/*--------------------------------------------------------------------------*\
 
675
 * rdbuf_text()
 
676
 *
 
677
 * Draw PostScript text.
 
678
\*--------------------------------------------------------------------------*/
 
679
 
 
680
static void
 
681
rdbuf_text(PLStream *pls)
 
682
{
 
683
  PLUNICODE(fci);
 
684
  EscText text;
 
685
  PLFLT xform[4];
 
686
  PLINT n;
 
687
  PLUNICODE* unicode;
 
688
 
 
689
  text.xform = xform;
 
690
 
 
691
 
 
692
  /* Read in the data */
 
693
 
 
694
  fread(&fci, sizeof(PLUNICODE), 1, pls->plbufFile);
 
695
 
 
696
  fread(&pls->chrht, sizeof(PLFLT), 1, pls->plbufFile);
 
697
  fread(&pls->diorot, sizeof(PLFLT), 1, pls->plbufFile);
 
698
  fread(&pls->clpxmi, sizeof(PLFLT), 1, pls->plbufFile);
 
699
  fread(&pls->clpxma, sizeof(PLFLT), 1, pls->plbufFile);
 
700
  fread(&pls->clpymi, sizeof(PLFLT), 1, pls->plbufFile);
 
701
  fread(&pls->clpyma, sizeof(PLFLT), 1, pls->plbufFile);
 
702
 
 
703
  fread(&text.base, sizeof(PLINT), 1, pls->plbufFile);
 
704
  fread(&text.just, sizeof(PLFLT), 1, pls->plbufFile);
 
705
  fread(text.xform, sizeof(PLFLT), 4, pls->plbufFile);
 
706
  fread(&text.x, sizeof(PLINT), 1, pls->plbufFile);
 
707
  fread(&text.y, sizeof(PLINT), 1, pls->plbufFile);
 
708
  fread(&text.refx, sizeof(PLINT), 1, pls->plbufFile);
 
709
  fread(&text.refy, sizeof(PLINT), 1, pls->plbufFile);
 
710
 
 
711
  fread(&text.unicode_array_len, sizeof(PLINT), 1, pls->plbufFile);
 
712
  if(text.unicode_array_len) {
 
713
    if((unicode=(PLUNICODE *)malloc(text.unicode_array_len*sizeof(PLUNICODE)))
 
714
       == NULL)
 
715
      plexit("rdbuf_text: Insufficient memory");
 
716
 
 
717
    fread(unicode, sizeof(PLUNICODE), text.unicode_array_len, pls->plbufFile);
 
718
    text.unicode_array = unicode;
 
719
  }
 
720
  else text.unicode_array = NULL;
 
721
 
 
722
  /* Make the call for unicode devices */
 
723
  if(pls->dev_unicode) {
 
724
    plsfci(fci);
 
725
    plP_esc(PLESC_HAS_TEXT,&text);
 
726
  }
 
727
}
 
728
 
 
729
/*--------------------------------------------------------------------------*\
619
730
 * plRemakePlot()
620
731
 *
621
732
 * Rebuilds plot from plot buffer, usually in response to a window