File: pixmap.c

package info (click to toggle)
swig1.3 1.3.24-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 19,336 kB
  • ctags: 10,604
  • sloc: cpp: 27,917; ansic: 24,160; yacc: 4,412; python: 4,255; java: 4,156; makefile: 3,735; sh: 3,552; cs: 2,250; ruby: 2,150; lisp: 1,605; tcl: 1,136; perl: 980; php: 879; ml: 825
file content (159 lines) | stat: -rw-r--r-- 4,158 bytes parent folder | download | duplicates (10)
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
/* ----------------------------------------------------------------------------- 
 * pixmap.c
 *
 *     Pixel maps (i.e., bitmaps)
 * 
 * Author(s) : David Beazley (beazley@cs.uchicago.edu)
 * Copyright (C) 1995-1996
 *
 * See the file LICENSE for information on usage and redistribution.	
 * ----------------------------------------------------------------------------- */

#define PIXMAP
#include "gifplot.h"

/* -----------------------------------------------------------------------
   PixMap *new_PixMap(int width, int height, int centerx, int centery)

   Create a new pixmap of given size
   ----------------------------------------------------------------------- */
PixMap *new_PixMap(int width, int height, int centerx, int centery) {
  PixMap *pm;
  if ((width > 0) && (height > 0)) {
    pm = (PixMap *) malloc(sizeof(PixMap));
    pm->width = width;
    pm->height = height;
    pm->centerx = centerx;
    pm->centery = centery;
    pm->map = (int *) malloc(height*width*sizeof(int));
    return pm;
  }
  return (PixMap *) 0;
}

/* --------------------------------------------------------------------------
   void delete_PixMap(PixMap *pm)

   Destroy a pixmap
   -------------------------------------------------------------------------- */

void delete_PixMap(PixMap *pm) {
  if (pm) {
    free((char *) pm->map);
    free((char *) pm);
  }
}

/* ---------------------------------------------------------------------------
   void PixMap_set(PixMap *pm, int x, int y, int pix)

   Set a pixel in the bitmap
   --------------------------------------------------------------------------- */
void
PixMap_set(PixMap *pm, int x, int y, int pix) {
  if ((x < 0) || (x>=pm->width)) return;
  if ((y < 0) || (y>=pm->height)) return;

  pm->map[pm->width*y + x] = pix;
}

/* -----------------------------------------------------------------------------
   void FrameBuffer_drawpixmap(FrameBuffer *f, PixMap *pm, int x, int y, int fgcolor, int bgcolor) 

   Draw a pixmap onto the framebuffer.   This is somewhat optimized for speed.
   ------------------------------------------------------------------------------ */

void
FrameBuffer_drawpixmap(FrameBuffer *f, PixMap *pm, int x, int y, int fgcolor, int bgcolor) {

  int startx, starty;         /* Starting location on framebuffer */
  int startpixx = 0, startpixy = 0;   /* Starting location in pixmap      */
  int endx, endy;             /* Ending location on framebuffer   */
  int i,j, px, py;
  int c;
  
  startx = x - pm->centerx;
  starty = y + pm->centery;
  endx = startx + pm->width;
  endy = starty - pm->height;

  /* Figure out if we need to clip */

  if (startx < f->xmin) {
    startpixx = f->xmin - startx;
    startx = f->xmin;
  }
  if (starty >= f->ymax) {
    startpixy = starty - f->ymax;
    starty = f->ymax-1;
  }
  if (endx >= f->xmax) {
    endx = f->xmax-1;
  }
  if (endy < f->ymin) {
    endy = f->ymin;
  }
  py = startpixy;
  for (j = starty; j >= endy; j--) {
    px = startpixx;
    for (i = startx; i < endx; i++) {
      c = pm->map[py*pm->width + px];
      switch (c) {
      case GIFPLOT_FOREGROUND:
	f->pixels[j][i] = fgcolor;
	break;
      case GIFPLOT_BACKGROUND:
	f->pixels[j][i] = bgcolor;
	break;
      default:
	break;
      }
      px++;
    }
    py++;
  }
}

/**************************************************************************
 * Some common PixMaps  (for plotting)
 *
 **************************************************************************/

int _SQUARE_MAP[] = {
  0,1,1,1,1,1,1,1,
  0,1,1,1,1,1,1,1,
  0,1,1,1,1,1,1,1,
  0,1,1,1,1,1,1,1,
  0,1,1,1,1,1,1,1,
  0,1,1,1,1,1,1,1,
  0,1,1,1,1,1,1,1,
  0,0,0,0,0,0,0,0 };

PixMap  PixMap_SQUARE = { 8,8,4,4, _SQUARE_MAP};

int _TRIANGLE_MAP[] = {
  0,0,0,1,0,0,0,0,
  0,0,0,1,0,0,0,0,
  0,0,1,1,1,0,0,0,
  0,0,1,1,1,0,0,0,
  0,1,1,1,1,1,0,0,
  0,1,1,1,1,1,0,0,
  1,1,1,1,1,1,1,0,
  0,0,0,0,0,0,0,0 };

PixMap  PixMap_TRIANGLE = { 8,8,4,4,_TRIANGLE_MAP};

int _CROSS_MAP[] = {
  0,0,0,1,0,0,0,0,
  0,0,0,1,0,0,0,0,
  0,0,0,1,0,0,0,0,
  1,1,1,1,1,1,1,0,
  0,0,0,1,0,0,0,0,
  0,0,0,1,0,0,0,0,
  0,0,0,1,0,0,0,0,
  0,0,0,0,0,0,0,0 };

PixMap  PixMap_CROSS = { 8,8,4,4,_CROSS_MAP};