Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
Data Structures | Macros | Typedefs | Functions | Variables
rleClock.c File Reference
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include "rle.h"
#include <sys/types.h>
#include <time.h>
#include "font.h"
Include dependency graph for rleClock.c:

Go to the source code of this file.

Data Structures

struct  color_t
 
struct  _urt_stack
 

Macros

#define XSIZE   128
 
#define YTEXTSIZE   0
 
#define YCLOCKSIZE   XSIZE
 
#define TICKS   12
 
#define DOTS   1
 
#define FORMATSTRING   "%02l:%02b"
 
#define FACE_EDGE_COLOR   { 255, 255, 255 }
 
#define HAND_COLOR   { 255, 255, 255 }
 
#define TEXT_COLOR   { 255, 255, 255 }
 
#define LITTLEHANDSCALE   12
 
#define BIGHANDSCALE   60
 
#define HANDWIDTH   0.075
 
#define TRUE   1
 
#define FALSE   0
 
#define RAST_FACE_EDGE   1
 
#define RAST_FACE_MASK   2
 
#define RAST_LHAND_EDGE   4
 
#define RAST_LHAND_MASK   8
 
#define RAST_BHAND_EDGE   16
 
#define RAST_BHAND_MASK   32
 
#define RAST_TEXT   64
 
#define RAST_TEXT_BACK   128
 
#define CHARPAD   25
 
#define NORTH   0
 
#define WEST   1
 
#define SOUTH   2
 
#define EAST   3
 

Typedefs

typedef char bool
 

Functions

void main ()
 
void ifImageSet ()
 
void drawHand ()
 
void rasterAddBits ()
 
void polarLine ()
 
void setDot ()
 
int polarToX ()
 
int polarToY ()
 
double radians ()
 
rle_pixel ** rasterAllocate ()
 
void rasterWrite ()
 
void lineDots ()
 
void procargs ()
 
bool argGiven ()
 
void usageExit ()
 
void charMinMaxWidth ()
 
void charMinMaxHeight ()
 
char * formatInterp ()
 
void drawText ()
 
void areaFlood ()
 
void stackPush ()
 
int stackPop ()
 
void main (int argc, argv)
 
void ifImageSet (int i, int j, int value, color_t *color)
 
void drawHand (double place, double scale, double radius, int mask, int edge)
 
void rasterAddBits (int mask, int match, int value)
 
void polarLine (double r0, double a0, double r1, double a1, int arg1, int arg2)
 
void setDot (int x, int y, int arg1, int arg2)
 
int polarToX (double fRadius, double angle)
 
int polarToY (double fRadius, double angle)
 
double radians (double degrees)
 
rle_pixel ** rasterAllocate (int height, int width)
 
void rasterWrite (FILE *fd)
 
void lineDots (int x0, int y0, int x1, int y1, void(*func)(), int arg1, int arg2)
 
void procargs (int argc, argv)
 
bool argGiven (char *argVar)
 
void usageExit (char *pgm)
 
void charMinMaxWidth (int ch, int *min, int *max)
 
void charMinMaxHeight (int ch, int *min, int *max)
 
char * formatInterp (char *str) const
 
void areaFlood (int firstX, int firstY, int mask, int match, int value)
 
void stackPush (int x, int y, int dir)
 

Variables

static char rcsid [] = "$Header: /l/spencer/src/urt/tools/clock/RCS/rleClock.c,v 3.0.1.2 1992/04/30 14:19:38 spencer Exp $"
 
color_t FaceEdgeColor = { 255, 255, 255 }
 
color_t FaceColor
 
color_t HandEdgeColor
 
color_t HandColor = { 255, 255, 255 }
 
color_t TextColor = { 255, 255, 255 }
 
color_t TextBackColor
 
rle_pixel ** RedLine
 
rle_pixel ** GreenLine
 
rle_pixel ** BlueLine
 
rle_pixel ** Raster
 
rle_pixel ** AlphaLine
 
int XSize = 128
 
int YSize
 
int YClockSize = 128
 
int YTextSize = 0
 
int XRadius
 
int YRadius
 
int Ticks = 12
 
bool DebugAlpha = 0
 
bool Debug = 0
 
int Dots = 1
 
float BigHandValue
 
float LittleHandValue
 
float LittleHandScale = 12
 
float BigHandScale = 60
 
const char * FormatString = "%02l:%02b"
 
move_t Moves []
 
int Base []
 
char ** gargv
 
struct {
enum  {
  INT, FLOAT, STRING, BOOL,
  COLOR, HELP, TEXT
}
 
   bool   show
 
   const char *   arg
 
   enum { ... }    type
 
   const char *   description
 
   const char *   value
 
   bool   given
 
Args []
 
struct {
   _urt_stack *   s
 
   int   top
 
   int   allocked
 
Stack
 
int XMove [4] = {0, 1, 0, -1}
 
int YMove [4] = {1, 0, -1, 0}
 

Macro Definition Documentation

#define BIGHANDSCALE   60

Definition at line 60 of file rleClock.c.

#define CHARPAD   25

Definition at line 842 of file rleClock.c.

#define DOTS   1

Definition at line 54 of file rleClock.c.

#define EAST   3

Definition at line 917 of file rleClock.c.

#define FACE_EDGE_COLOR   { 255, 255, 255 }

Definition at line 56 of file rleClock.c.

#define FALSE   0

Definition at line 66 of file rleClock.c.

#define FORMATSTRING   "%02l:%02b"

Definition at line 55 of file rleClock.c.

#define HAND_COLOR   { 255, 255, 255 }

Definition at line 57 of file rleClock.c.

#define HANDWIDTH   0.075

Definition at line 62 of file rleClock.c.

#define LITTLEHANDSCALE   12

Definition at line 59 of file rleClock.c.

#define NORTH   0

Definition at line 914 of file rleClock.c.

#define RAST_BHAND_EDGE   16

Definition at line 78 of file rleClock.c.

#define RAST_BHAND_MASK   32

Definition at line 79 of file rleClock.c.

#define RAST_FACE_EDGE   1

Definition at line 74 of file rleClock.c.

#define RAST_FACE_MASK   2

Definition at line 75 of file rleClock.c.

#define RAST_LHAND_EDGE   4

Definition at line 76 of file rleClock.c.

#define RAST_LHAND_MASK   8

Definition at line 77 of file rleClock.c.

#define RAST_TEXT   64

Definition at line 80 of file rleClock.c.

#define RAST_TEXT_BACK   128

Definition at line 81 of file rleClock.c.

#define SOUTH   2

Definition at line 916 of file rleClock.c.

#define TEXT_COLOR   { 255, 255, 255 }

Definition at line 58 of file rleClock.c.

#define TICKS   12

Definition at line 53 of file rleClock.c.

#define TRUE   1

Definition at line 65 of file rleClock.c.

#define WEST   1

Definition at line 915 of file rleClock.c.

#define XSIZE   128

Definition at line 50 of file rleClock.c.

#define YCLOCKSIZE   XSIZE

Definition at line 52 of file rleClock.c.

#define YTEXTSIZE   0

Definition at line 51 of file rleClock.c.

Typedef Documentation

typedef char bool

Definition at line 68 of file rleClock.c.

Function Documentation

void areaFlood ( )
void areaFlood ( int  firstX,
int  firstY,
int  mask,
int  match,
int  value 
)

Definition at line 928 of file rleClock.c.

931 {
932  register _urt_stack *sp;
933 
934  Stack.s = (_urt_stack *) calloc(256, sizeof(_urt_stack));
935  Stack.allocked = 256;
936  Stack.top = -1;
937  stackPush(firstX, firstY, NORTH);
938 
939  while (Stack.top >= 0) {
940  sp = &Stack.s[Stack.top];
941  if ((Raster[sp->y][sp->x]&mask)==match && (Raster[sp->y][sp->x]&value)!=value) {
942  Raster[sp->y][sp->x] |= value;
943  if (Debug)
944  fprintf(stderr, "Marking %d, %d at stack %d\n", sp->x, sp->y, Stack.top);
945  stackPush(sp->x + XMove[sp->dir], sp->y + YMove[sp->dir],
946  NORTH);
947  } else {
948  do {
949  if (stackPop())
950  break;
951  sp = &Stack.s[Stack.top];
952  sp->dir++;
953  } while (sp->dir >= 4);
954  if (Stack.top >= 0)
955  stackPush(sp->x + XMove[sp->dir], sp->y + YMove[sp->dir],
956  NORTH);
957  }
958  }
959 }
static unsigned mask
Definition: mcut.c:162
struct @9 Stack
short y
Definition: rleClock.c:910
short x
Definition: rleClock.c:910
int XMove[4]
Definition: rleClock.c:924
rle_pixel ** Raster
Definition: rleClock.c:105
static char * match(char *n, char *v)
Definition: rle_getcom.c:50
bool Debug
Definition: rleClock.c:116
int YMove[4]
Definition: rleClock.c:925
const char * value
Definition: rleClock.c:574
void stackPush()
#define NORTH
Definition: rleClock.c:914
int stackPop()
Definition: rleClock.c:976
bool argGiven ( )
bool argGiven ( char *  argVar)

Definition at line 662 of file rleClock.c.

664 {
665  int i;
666 
667  for ( i=0 ; Args[i].arg != NULL ; i++) {
668  if (Args[i].value == argVar) {
669  return Args[i].given;
670  }
671  }
672  return FALSE;
673 }
#define FALSE
Definition: rleClock.c:66
struct @8 Args[]
int i
Definition: rletorla.c:82
const char * value
Definition: rleClock.c:574
void charMinMaxHeight ( )
void charMinMaxHeight ( int  ch,
int min,
int max 
)

Definition at line 747 of file rleClock.c.

Referenced by drawText().

750 {
751  int epos, pos;
752 
753  if (!isprint(ch)) {
754  *min = *max = 0;
755  return;
756  }
757  if (ch == ' ') {
758  ch = 'n';
759  }
760  *min = 999;
761  *max = -999;
762  epos = Base[(int)ch - 33 + 1];
763  pos = Base[(int)ch - 33];
764  for (; pos < epos; pos++) {
765  if (Moves[pos].y > *max) {
766  *max = Moves[pos].y;
767  }
768  if (Moves[pos].y < *min) {
769  *min = Moves[pos].y;
770  }
771  }
772 }
int Base[]
Definition: font.c:303
static int y
Definition: getami.c:691
#define min(a, b)
Definition: dvirle.h:51
int
Definition: getami.c:848
move_t Moves[]
Definition: font.c:2
int y
Definition: font.h:3

Here is the caller graph for this function:

void charMinMaxWidth ( )
void charMinMaxWidth ( int  ch,
int min,
int max 
)

Definition at line 719 of file rleClock.c.

Referenced by drawText().

722 {
723  int epos, pos;
724 
725  if (!isprint(ch)) {
726  *min = *max = 0;
727  return;
728  }
729  if (ch == ' ') {
730  ch = 'n';
731  }
732  *min = 999;
733  *max = -999;
734  epos = Base[(int)ch - 33 + 1];
735  pos = Base[(int)ch - 33];
736  for (; pos < epos; pos++) {
737  if (Moves[pos].x > *max) {
738  *max = Moves[pos].x;
739  }
740  if (Moves[pos].x < *min) {
741  *min = Moves[pos].x;
742  }
743  }
744 }
int Base[]
Definition: font.c:303
static int x
Definition: getami.c:691
#define min(a, b)
Definition: dvirle.h:51
int
Definition: getami.c:848
move_t Moves[]
Definition: font.c:2
int x
Definition: font.h:3

Here is the caller graph for this function:

void drawHand ( )
void drawHand ( double  place,
double  scale,
double  radius,
int  mask,
int  edge 
)

Definition at line 323 of file rleClock.c.

328 {
329  float angle;
330  angle = place / scale * 360;
331  polarLine(HANDWIDTH, angle+180.0, HANDWIDTH, angle-90.0, edge, 1);
332  polarLine(HANDWIDTH, angle-90.0, radius, angle, edge, 1);
333  polarLine(radius, angle, HANDWIDTH, angle+90.0, edge, 1);
334  polarLine(HANDWIDTH, angle+90.0, HANDWIDTH, angle+180.0, edge, 1);
335  areaFlood(polarToX(0.0, 0.0), polarToY(0.0, 0.0), edge, 0,
336  mask);
337  polarLine(HANDWIDTH, angle+180.0, HANDWIDTH, angle-90.0, edge, Dots);
338  polarLine(HANDWIDTH, angle-90.0, radius, angle, edge, Dots);
339  polarLine(radius, angle, HANDWIDTH, angle+90.0, edge, Dots);
340  polarLine(HANDWIDTH, angle+90.0, HANDWIDTH, angle+180.0, edge, Dots);
341  rasterAddBits(edge, edge, mask);
342 }
static unsigned mask
Definition: mcut.c:162
#define HANDWIDTH
Definition: rleClock.c:62
void polarLine()
int polarToY()
void areaFlood()
int polarToX()
void rasterAddBits()
int Dots
Definition: rleClock.c:117
void drawText ( )

Definition at line 845 of file rleClock.c.

References Base, charMinMaxHeight(), charMinMaxWidth(), Dots, formatInterp(), FormatString, lineDots(), Moves, Raster, setDot(), move_t::type, move_t::x, XSize, move_t::y, YClockSize, YSize, and YTextSize.

846 {
847  char *string;
848  int i, j, xsize, ysize, min, max, basex;
849  int curx, cury, x, y, pos, epos, charBasex;
850  float scale, scalex;
851 
852  string = formatInterp(FormatString);
853  xsize = CHARPAD+Dots;
854  ysize = 0;
855  for (i = 0; string[i] != 0; i++) {
856  charMinMaxWidth(string[i], &min, &max);
857  xsize += (max - min) + CHARPAD+Dots;
858  charMinMaxHeight(string[i], &min, &max);
859  if (ysize < (max - min)+Dots) {
860  ysize = max - min+Dots;
861  }
862  }
863  scale = (float) YTextSize / (float) ysize;
864  scalex = (float) XSize / (float) xsize;
865  if (scale > scalex) {
866  scale = scalex;
867  }
868  basex = (XSize - (int) ((float)xsize * scale)) / 2;
869  curx = cury = 0;
870  charBasex = CHARPAD;
871  for (i = 0; string[i] != 0; i++) {
872  if (isprint(string[i]) && string[i] != ' ') {
873  charMinMaxWidth(string[i], &min, &max);
874  epos = Base[((int) (string[i])) - 33 + 1];
875  for (pos = Base[(int) string[i] - 33]; pos < epos; pos++) {
876  x = basex + (int) (scale * (charBasex + Moves[pos].x + (-min)));
877  y = (int) (scale * Moves[pos].y);
878  if (Moves[pos].type == 'n') {
879  lineDots(curx, YClockSize + Dots + 1 + cury, x, YClockSize + Dots + 1 + y, setDot, RAST_TEXT, Dots);
880  }
881  curx = x;
882  cury = y;
883  }
884  }
885  charBasex += (max-min) + CHARPAD + Dots;
886  }
887  x = basex + (int)(scale * charBasex);
888  if (x > XSize) {
889  x = XSize;
890  }
891  y = scale * ysize + YClockSize+Dots+1;
892  if (y+Dots > YSize) {
893  y = YSize-Dots;
894  }
895  for (i = YClockSize+Dots; i < y+Dots ; i++) {
896  for (j = basex; j < x; j++) {
897  Raster[i][j] |= RAST_TEXT_BACK;
898  }
899  }
900 }
static int curx
Definition: gifencod.c:22
#define CHARPAD
Definition: rleClock.c:842
const char * FormatString
Definition: rleClock.c:122
int YClockSize
Definition: rleClock.c:110
int YTextSize
Definition: rleClock.c:111
void charMinMaxWidth()
int XSize
Definition: rleClock.c:108
int Base[]
Definition: font.c:303
int xsize
Definition: read98721.c:58
rle_pixel ** Raster
Definition: rleClock.c:105
void lineDots()
static int y
Definition: getami.c:691
int YSize
Definition: rleClock.c:109
enum @8::@10 type
void setDot()
void charMinMaxHeight()
static int x
Definition: getami.c:691
#define RAST_TEXT_BACK
Definition: rleClock.c:81
#define min(a, b)
Definition: dvirle.h:51
static int cury
Definition: gifencod.c:22
int
Definition: getami.c:848
int ysize
Definition: read98721.c:59
move_t Moves[]
Definition: font.c:2
char * formatInterp()
int i
Definition: rletorla.c:82
char * string
Definition: getbob.c:30
int Dots
Definition: rleClock.c:117
#define RAST_TEXT
Definition: rleClock.c:80

Here is the call graph for this function:

char* formatInterp ( )
char* formatInterp ( char *  str) const

Definition at line 782 of file rleClock.c.

Referenced by drawText().

784 {
785  char *buf, *bufp;
786  int state;
787  static char outBuf[1024];
788  char tmpBuf[1024];
789 
790  buf = (char *)malloc(strlen(str)*2+1);
791  bufp = buf;
792  state = 0;
793  strcpy(outBuf, "");
794  while ( *str != 0) {
795  switch (state) {
796  case 0:
797  *bufp++ = *str;
798  if (*str == '%') {
799  state = 1;
800  }
801  break;
802  case 1:
803  if (isdigit(*str) || *str == '.') {
804  *bufp++ = *str;
805  } else {
806  if ( *str=='B' || *str=='L') {
807  *bufp++ = 'f';
808  *bufp = 0;
809  sprintf(tmpBuf, buf, *str == 'B' ? (float)BigHandValue
810  : (float)LittleHandValue);
811  } else if ( *str=='b' || *str=='l') {
812  *bufp++ = 'd';
813  *bufp = 0;
814  sprintf(tmpBuf, buf, *str == 'b' ? (int)BigHandValue
815  : (int)LittleHandValue);
816  } else {
817  *bufp++ = *str;
818  *bufp = 0;
819  strcpy(tmpBuf, buf);
820  }
821  strcat(outBuf, tmpBuf);
822  bufp = buf;
823  state = 0;
824  }
825  break;
826  }
827  str++;
828  }
829  *bufp = 0;
830  strcat(outBuf, buf);
831  free(buf);
832  return outBuf;
833 }
static char buf[4096 +1]
Definition: into.c:46
float BigHandValue
Definition: rleClock.c:118
float LittleHandValue
Definition: rleClock.c:119
void * malloc()
char * str
Definition: rletorla.c:79

Here is the caller graph for this function:

void ifImageSet ( )
void ifImageSet ( int  i,
int  j,
int  value,
color_t color 
)

Definition at line 311 of file rleClock.c.

314 {
315  if (Raster[i][j] & value) {
316  RedLine[i][j] = color->red;
317  GreenLine[i][j] = color->green;
318  BlueLine[i][j] = color->blue;
319  }
320 }
unsigned char green
Definition: rleClock.c:88
unsigned char blue
Definition: rleClock.c:88
rle_pixel ** Raster
Definition: rleClock.c:105
rle_pixel ** GreenLine
Definition: rleClock.c:103
rle_pixel ** RedLine
Definition: rleClock.c:102
rle_pixel ** BlueLine
Definition: rleClock.c:104
int i
Definition: rletorla.c:82
const char * value
Definition: rleClock.c:574
unsigned char red
Definition: rleClock.c:88
void lineDots ( )
void lineDots ( int  x0,
int  y0,
int  x1,
int  y1,
void (*)()  func,
int  arg1,
int  arg2 
)

Definition at line 504 of file rleClock.c.

Referenced by drawText().

508 {
509  int e, x, y, delta_x, delta_y, tmp;
510  bool interchg = FALSE;
511  int dir_x, dir_y;
512  int two_dy, two_dx; /* calculated outside of loop */
513  register int i;
514 
515 
516  if (x0 == x1 && y0 == y1) { /* is starting point = end point ? */
517  (*func)(x0, y0, arg1, arg2);
518  return;
519  }
520  x = x0;
521  y = y0;
522 
523  delta_x = x1 - x0;
524  delta_y = y1 - y0;
525 
526  delta_x = delta_x > 0 ? delta_x : -delta_x; /* absolute value,
527  * abs(x1-x0) */
528  delta_y = delta_y > 0 ? delta_y : -delta_y; /* absolute value,
529  * abs(y1-x0) */
530 
531  dir_x = (x1 - x0) > 0 ? 1 : -1; /* sign (x1 - x0) */
532  dir_y = (y1 - y0) > 0 ? 1 : -1; /* sign (y1 - y0) */
533 
534  if (delta_y > delta_x) {
535  tmp = delta_x;
536  delta_x = delta_y;
537  delta_y = tmp;
538  interchg = TRUE;
539  }
540  two_dx = 2 * delta_x;
541  two_dy = 2 * delta_y;
542 
543  e = two_dy - delta_x;
544  for (i = 1; i <= delta_x; ++i) {
545  (*func) (x, y, arg1, arg2);
546  while (e >= 0) {
547  if (interchg)
548  x += dir_x;
549  else
550  y += dir_y;
551  e -= two_dx;
552  }
553  if (interchg)
554  y += dir_y;
555  else
556  x += dir_x;
557  e += two_dy;
558  }
559 }
#define FALSE
Definition: rleClock.c:66
static int y
Definition: getami.c:691
static int x
Definition: getami.c:691
#define TRUE
Definition: rleClock.c:65
int i
Definition: rletorla.c:82

Here is the caller graph for this function:

void main ( )

Definition at line 28 of file wedge.c.

References color_names, and raster.

29 {
30  register rle_pixel * rptr;
31  register int i,j,color, val;
32 
33  raster = (rle_pixel *) malloc( (STEPS * 2 + 2) * IMG_HEIGHT /*/4*/ );
34  rptr = raster;
35 
36  init_qcr( 1 );
37 
38  for (color = 0; color < 3; color++)
39  for (j = 0; j < IMG_HEIGHT/4; j++)
40  {
41  for (i = 0; i < STEPS; i++)
42  {
43  *rptr = IMG_WIDTH / STEPS;
44  val = i * (256 / (STEPS-1));
45  if (val >= 256)
46  {
47  val = 255;
48  /* Add round-off to fill out scanline */
49  *rptr += IMG_WIDTH - (STEPS * (IMG_WIDTH / STEPS));
50  }
51  rptr++;
52  *rptr++ = val;
53  }
54  }
55 
56  /* Do first three color bars. */
57  for (color = 0; color < 3; color++)
58  {
60  color * (IMG_HEIGHT/4) );
61 
62  fprintf(stderr, "Sending color %s...\n", color_names[color] );
63  write_qcr_cmd( RED_RLE + color );
64 
65  if (write_data( raster, (STEPS * 2) * (IMG_HEIGHT / 4) ) <= 0)
66  perror("wedge: error sending data");
67  qcr_wait_srq();
68  fprintf(stderr, "...sent\n\n");
69  }
70 
71  color = 3;
73  color * (IMG_HEIGHT/4) );
74 
75  fprintf(stderr, "Sending three passes (for gray)...\n");
77 
78  if (write_data( raster, ((STEPS * 2) * (IMG_HEIGHT / 4)) * 3 ) <= 0)
79  perror("wedge: error sending data");
80  qcr_wait_srq();
81  fprintf(stderr, "...sent\n\n");
82 }
qcr_wait_srq()
Definition: qcr.c:26
#define IMG_HEIGHT
Definition: wedge.c:16
write_qcr_cmd(int cmd)
Definition: qcr.c:55
int init_qcr(short verbose)
Definition: qcr.c:104
#define THREE_PASS_RLE
Definition: qcr.h:32
write_data(char *buff, int len)
Definition: qcr.c:74
static char * color_names[3]
Definition: wedge.c:26
#define RED_RLE
Definition: qcr.h:43
#define IMG_WIDTH
Definition: wedge.c:15
#define STEPS
Definition: wedge.c:22
unsigned char rle_pixel
Definition: rle.h:56
rle_pixel * raster
Definition: wedge.c:24
void * malloc()
int i
Definition: rletorla.c:82
set_up_qcr(int x_size, int y_size, int nslice, int offset)
Definition: qcr.c:303
void main ( int  argc,
argv   
)

Definition at line 185 of file rleClock.c.

188 {
189  int i, j;
190  float theta;
191  time_t now;
192  struct tm *tm, *localtime();
193  bool haveFaceColor;
194  bool haveHandEdgeColor;
195  bool haveTextBackColor;
196 
197  gargv = argv;
198 
199  procargs(argc, argv);
200  YRadius = (YClockSize - Dots) / 2;
201  XRadius = (XSize - Dots) / 2;
203  if (!argGiven((char *) &LittleHandValue) || !argGiven((char *) &BigHandValue)) {
204  (void)time(&now);
205  tm = localtime(&now);
206 
207  if (!argGiven((char *) &BigHandValue))
208  BigHandValue = (float) tm->tm_min;
209  if (!argGiven((char *) &LittleHandValue))
210  LittleHandValue = (float) ((tm->tm_hour % 12)) + BigHandValue / 60.0;
211  }
212  /*
213  * Allocate the storage for the raster
214  */
215 
221 
222  /*
223  * Initialize the raster to the background color
224  */
225 
226  for (i = 0; i < YSize; i++) {
227  for (j = 0; j < XSize; j++) {
228  Raster[i][j] = 0;
229  }
230  }
231 
232  /*
233  * Draw the clock face as a circle with tick marks
234  */
235 
236  for (i = 0; i < 360; i++) {
237  polarLine(1.0, (float) i, 1.0, (float) (i + 1), RAST_FACE_EDGE, Dots);
238  }
239  for (i = 0; i < Ticks; i++) {
240  theta = (float) i *360.0 / (float) Ticks;
241 
242  polarLine(1.0, theta, 0.85, theta, RAST_FACE_EDGE, Dots);
243  }
244 
245  /*
246  * Compute the RAST_FACE_MASK portion - includes what is inside the
247  * dial face plus the dial face itself. So first flood the inside, and
248  * then OR in the stuff under the face lines
249  */
250 
251  areaFlood(polarToX(0.0, 0.0), polarToY(0.0, 0.0), RAST_FACE_EDGE, 0, RAST_FACE_MASK);
253 
254  /*
255  * Draw the hands and the text...
256  */
257 
260  if (YTextSize > 0) {
261  drawText();
262  }
263  /*
264  * Compose the clock image from the generated raster and program
265  * arguments
266  */
267 
268  haveFaceColor = argGiven((char *)&FaceColor);
269  haveHandEdgeColor = argGiven((char *)&HandEdgeColor);
270  haveTextBackColor = argGiven((char *)&TextBackColor);
271  for (i = 0; i < YSize; i++) {
272  for (j = 0; j < XSize; j++) {
273  if (haveFaceColor) {
275  }
278  if (haveHandEdgeColor) {
280  }
281  if (haveTextBackColor) {
283  }
284  ifImageSet(i, j, RAST_TEXT, &TextColor);
285 
286  /*
287  * Now compute the Alpha channel
288  */
289 
290  if ( (haveFaceColor && (Raster[i][j]&RAST_FACE_MASK)!=0)
292  || (haveTextBackColor && (Raster[i][j] & RAST_TEXT_BACK)!=0)
293  || ((Raster[i][j] & RAST_TEXT)!=0)) {
294  AlphaLine[i][j] = 255;
295  } else {
296  AlphaLine[i][j] = 0;
297  }
298  }
299  }
300 
301  /*
302  * Dump the raster file to stdout...
303  */
304 
305  rasterWrite(stdout);
306 
307  exit(0);
308 }
int XRadius
Definition: rleClock.c:112
color_t FaceColor
Definition: rleClock.c:96
float LittleHandScale
Definition: rleClock.c:120
void rasterWrite()
int Ticks
Definition: rleClock.c:114
#define RAST_LHAND_EDGE
Definition: rleClock.c:76
int YClockSize
Definition: rleClock.c:110
int YTextSize
Definition: rleClock.c:111
#define RAST_LHAND_MASK
Definition: rleClock.c:77
#define RAST_BHAND_EDGE
Definition: rleClock.c:78
int XSize
Definition: rleClock.c:108
void polarLine()
void ifImageSet()
rle_pixel ** Raster
Definition: rleClock.c:105
int YRadius
Definition: rleClock.c:113
int YSize
Definition: rleClock.c:109
color_t TextBackColor
Definition: rleClock.c:100
int polarToY()
#define RAST_BHAND_MASK
Definition: rleClock.c:79
void areaFlood()
#define RAST_FACE_EDGE
Definition: rleClock.c:74
rle_pixel ** GreenLine
Definition: rleClock.c:103
color_t HandEdgeColor
Definition: rleClock.c:97
#define RAST_TEXT_BACK
Definition: rleClock.c:81
color_t FaceEdgeColor
Definition: rleClock.c:95
float BigHandValue
Definition: rleClock.c:118
rle_pixel ** RedLine
Definition: rleClock.c:102
bool argGiven()
void procargs()
#define RAST_FACE_MASK
Definition: rleClock.c:75
int polarToX()
rle_pixel ** rasterAllocate()
rle_pixel ** BlueLine
Definition: rleClock.c:104
float LittleHandValue
Definition: rleClock.c:119
if(tfd)
Definition: getami.c:852
unsigned char rle_pixel
Definition: rle.h:56
color_t TextColor
Definition: rleClock.c:99
rle_pixel ** AlphaLine
Definition: rleClock.c:106
void rasterAddBits()
int i
Definition: rletorla.c:82
void drawText()
Definition: rleClock.c:845
int Dots
Definition: rleClock.c:117
void drawHand()
color_t HandColor
Definition: rleClock.c:98
char ** gargv
Definition: rleClock.c:182
float BigHandScale
Definition: rleClock.c:121
#define RAST_TEXT
Definition: rleClock.c:80
void polarLine ( )
void polarLine ( double  r0,
double  a0,
double  r1,
double  a1,
int  arg1,
int  arg2 
)

Definition at line 359 of file rleClock.c.

362 {
363  lineDots(polarToX(r0, a0),
364  polarToY(r0, a0),
365  polarToX(r1, a1),
366  polarToY(r1, a1),
367  setDot, arg1, arg2);
368 }
void lineDots()
int polarToY()
void setDot()
int polarToX()
int polarToX ( )
int polarToX ( double  fRadius,
double  angle 
)

Definition at line 402 of file rleClock.c.

405 {
406  return (int)(fRadius * sin(radians(angle)) * XRadius) + XSize/2;
407 }
int XRadius
Definition: rleClock.c:112
int XSize
Definition: rleClock.c:108
double radians()
int polarToY ( )
int polarToY ( double  fRadius,
double  angle 
)

Definition at line 410 of file rleClock.c.

413 {
414  return (int)(fRadius * cos(radians(angle)) * YRadius) + YRadius;
415 }
int YRadius
Definition: rleClock.c:113
double radians()
void procargs ( )
void procargs ( int  argc,
argv   
)

Definition at line 605 of file rleClock.c.

608 {
609  int arg, i;
610  color_t *color;
611 
612  for ( arg = 1 ; arg<argc ; arg++) {
613  for ( i=0 ; Args[i].arg != NULL ; i++) {
614  if (Args[i].type != TEXT && strcmp(argv[arg], Args[i].arg) == 0) {
615  break;
616  }
617  }
618  if (Args[i].arg==NULL) {
619  fprintf(stderr, "Unknown argument: \"%s\"\n", argv[arg]);
620  usageExit(argv[0]);
621  }
622  Args[i].given = TRUE;
623  switch (Args[i].type) {
624  case HELP:
625  usageExit(argv[0]);
626  break;
627  case INT:
628  arg += 1;
629  *(int *)Args[i].value = atoi(argv[arg]);
630  break;
631  case FLOAT:
632  arg += 1;
633  *(float *)Args[i].value = atof(argv[arg]);
634  break;
635  case BOOL:
636  *(bool *)Args[i].value = TRUE;
637  break;
638  case STRING:
639  arg += 1;
640  *(char **)Args[i].value = (char *)malloc(strlen(argv[arg])+1);
641  strcpy(*(char **)Args[i].value, argv[arg]);
642  break;
643  case COLOR:
644  color = (color_t *)Args[i].value;
645  if ( arg+3 >= argc || !isdigit(argv[arg+1][0])
646  || !isdigit(argv[arg+2][0])
647  || !isdigit(argv[arg+3][0])) {
648  fprintf(stderr, "%s: %s takes three numeric arguments\n", argv[0],
649  Args[i].arg);
650  usageExit(argv[0]);
651  }
652  color->red = atoi(argv[arg+1]);
653  color->green = atoi(argv[arg+2]);
654  color->blue = atoi(argv[arg+3]);
655  arg += 3;
656  break;
657  default:
658  break;
659  }
660  }
661 }
struct @8 Args[]
unsigned char green
Definition: rleClock.c:88
unsigned char blue
Definition: rleClock.c:88
void usageExit()
enum @8::@10 type
const char * arg
Definition: rleClock.c:571
#define TRUE
Definition: rleClock.c:65
void * malloc()
int i
Definition: rletorla.c:82
const char * value
Definition: rleClock.c:574
unsigned char red
Definition: rleClock.c:88
double radians ( )
double radians ( double  degrees)

Definition at line 418 of file rleClock.c.

420 {
421  return degrees/180.0 * 3.1415926;
422 }
void rasterAddBits ( )
void rasterAddBits ( int  mask,
int  match,
int  value 
)

Definition at line 345 of file rleClock.c.

347 {
348  int i, j;
349 
350  for (i = 0 ; i < YSize; i++) {
351  for (j = 0; j < XSize; j++) {
352  if ( (Raster[i][j]&mask) == match )
353  Raster[i][j] |= value;
354  }
355  }
356 }
static unsigned mask
Definition: mcut.c:162
int XSize
Definition: rleClock.c:108
rle_pixel ** Raster
Definition: rleClock.c:105
int YSize
Definition: rleClock.c:109
static char * match(char *n, char *v)
Definition: rle_getcom.c:50
int i
Definition: rletorla.c:82
const char * value
Definition: rleClock.c:574
rle_pixel** rasterAllocate ( )
rle_pixel** rasterAllocate ( int  height,
int  width 
)

Definition at line 432 of file rleClock.c.

434 {
435  rle_pixel **new, *row;
436  int i;
437 
438  new = (rle_pixel **)calloc(height, sizeof(rle_pixel *));
439  row = (rle_pixel *)calloc(height*width, sizeof(rle_pixel));
440  for ( i=0 ; i<height ; i++) {
441  new[i] = row;
442  row += width;
443  }
444  return new;
445 }
int width
Definition: pgmtorle.c:51
int height
Definition: pgmtorle.c:51
unsigned char rle_pixel
Definition: rle.h:56
int i
Definition: rletorla.c:82
int row
Definition: rle.c:27
void rasterWrite ( )
void rasterWrite ( FILE *  fd)

Definition at line 455 of file rleClock.c.

457 {
459  rle_pixel *rows[4];
460  int i;
461 
462  the_hdr = *rle_hdr_init( (rle_hdr *)NULL );
463  rle_names( &the_hdr, cmd_name( gargv ), NULL, 0 );
464 
465  RLE_SET_BIT(the_hdr, RLE_ALPHA);
466  the_hdr.rle_file = fd;
467  the_hdr.xmax = XSize;
468  the_hdr.ymax = YSize;
469  the_hdr.alpha = 1;
470  rle_addhist( gargv, NULL, &the_hdr );
471 
472  rle_put_setup(&the_hdr);
473  for (i = 0; i < YSize; i++) {
474  rows[0] = AlphaLine[i];
475  if (DebugAlpha) {
476  rows[1] = AlphaLine[i];
477  rows[2] = AlphaLine[i];
478  rows[3] = AlphaLine[i];
479  } else {
480  rows[1] = RedLine[i];
481  rows[2] = GreenLine[i];
482  rows[3] = BlueLine[i];
483  }
484  rle_putrow(rows + 1, XSize, &the_hdr);
485  }
486  rle_close_f( the_hdr.rle_file );
487 }
rle_hdr the_hdr
Definition: aliastorle.c:100
#define RLE_SET_BIT(glob, bit)
Definition: rle.h:122
bool DebugAlpha
Definition: rleClock.c:115
void rle_putrow(rle_pixel *rows[], int rowlen, rle_hdr *the_hdr)
int XSize
Definition: rleClock.c:108
void rle_addhist(char *argv[], rle_hdr *in_hdr, rle_hdr *out_hdr)
int YSize
Definition: rleClock.c:109
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
Definition: rle.h:96
void rle_close_f(FILE *fd)
Definition: rle_open_f.c:244
int xmax
Definition: rle.h:100
rle_pixel ** GreenLine
Definition: rleClock.c:103
rle_pixel ** RedLine
Definition: rleClock.c:102
rle_pixel ** rows
Definition: rletopaint.c:57
rle_pixel ** BlueLine
Definition: rleClock.c:104
int ymax
Definition: rle.h:100
FILE * fd
Definition: getfb.h:18
unsigned char rle_pixel
Definition: rle.h:56
rle_pixel ** AlphaLine
Definition: rleClock.c:106
int i
Definition: rletorla.c:82
int alpha
Definition: rle.h:100
#define RLE_ALPHA
Definition: rle.h:65
void rle_put_setup(rle_hdr *the_hdr)
Definition: rle_putrow.c:453
char ** gargv
Definition: rleClock.c:182
char * cmd_name(char **argv)
Definition: cmd_name.c:31
FILE * rle_file
Definition: rle.h:114
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267
void setDot ( )
void setDot ( int  x,
int  y,
int  arg1,
int  arg2 
)

Definition at line 379 of file rleClock.c.

Referenced by drawText().

381 {
382  int i, j;
383 
384 if(Debug)fprintf(stderr, "Setting %d, %d\n", x, y);
385  for (i = 0; i < arg2; i++) {
386  for (j = 0; j < arg2; j++) {
387  Raster[y+i][x+j] |= arg1;
388  }
389  }
390 }
rle_pixel ** Raster
Definition: rleClock.c:105
static int y
Definition: getami.c:691
static int x
Definition: getami.c:691
int i
Definition: rletorla.c:82
bool Debug
Definition: rleClock.c:116

Here is the caller graph for this function:

int stackPop ( )

Definition at line 976 of file rleClock.c.

977 {
978  Stack.top -= 1;
979  return Stack.top < 0;
980 }
struct @9 Stack
void stackPush ( )
void stackPush ( int  x,
int  y,
int  dir 
)

Definition at line 962 of file rleClock.c.

964 {
965  if (++Stack.top >= Stack.allocked) {
966  Stack.allocked += 256;
967  Stack.s = (_urt_stack *) realloc(Stack.s, Stack.allocked * sizeof(_urt_stack));
968 if(Debug)fprintf(stderr, "Stack growing to %d\n", Stack.allocked);
969  }
970  Stack.s[Stack.top].x = x;
971  Stack.s[Stack.top].y = y;
972  Stack.s[Stack.top].dir = dir;
973 }
struct @9 Stack
static int y
Definition: getami.c:691
static int x
Definition: getami.c:691
bool Debug
Definition: rleClock.c:116
void usageExit ( )
void usageExit ( char *  pgm)

Definition at line 676 of file rleClock.c.

678 {
679  int i;
680 
681  fprintf(stderr, "Usage: %s [args]\n", pgm);
682  for (i = 0; Args[i].arg != NULL; i++) {
683  if (Args[i].show) {
684  fprintf(stderr, "\t%s", Args[i].arg);
685  switch (Args[i].type) {
686  case INT:
687  fprintf(stderr, " INT");
688  break;
689  case FLOAT:
690  fprintf(stderr, " FLOAT");
691  break;
692  case BOOL:
693  break;
694  case STRING:
695  fprintf(stderr, " STR");
696  break;
697  case COLOR:
698  fprintf(stderr, " RED GREEN BLUE");
699  break;
700  default:
701  break;
702  }
703  fprintf(stderr, " ... %s\n", Args[i].description);
704  }
705  }
706  exit(1);
707 
708 }
const char * description
Definition: rleClock.c:573
struct @8 Args[]
bool show
Definition: rleClock.c:570
enum @8::@10 type
const char * arg
Definition: rleClock.c:571
int i
Definition: rletorla.c:82

Variable Documentation

int allocked

Definition at line 921 of file rleClock.c.

rle_pixel** AlphaLine

Definition at line 106 of file rleClock.c.

const char* arg

Definition at line 571 of file rleClock.c.

struct { ... } Args[]
Initial value:
={
{ 1 , "-x", INT, "Image width in pixels", (char *)&XSize },
{ 1 , "-cy", INT, "Clock image height in pixels", (char *)&YClockSize },
{ 1 , "-ty", INT, "Text image height in pixels", (char *)&YTextSize },
{ 1 , "-help", HELP, "Prints this help message", ((void *)0) },
{ 1 , "-bv", FLOAT, "Big hand value", (char *)&BigHandValue },
{ 1 , "-bs", FLOAT, "Big hand full scale value", (char *)&BigHandScale },
{ 1 , "-lv", FLOAT, "Little hand value", (char *)&LittleHandValue },
{ 1 , "-ls", FLOAT, "Little hand full scale value", (char *)&LittleHandScale },
{ 1 , "-t", INT, "Number of ticks around the face", (char *)&Ticks },
{ 1 , "-lw", INT, "Line width in pixels", (char *)&Dots },
{ 1 , "-fc", COLOR, "Clock face edges color", (char *)&FaceEdgeColor },
{ 1 , "-Fc", COLOR, "Clock face background color", (char *)&FaceColor },
{ 1 , "", TEXT, " - if omitted, then the clock is transparent" },
{ 1 , "-hc", COLOR, "Clock hands edges color", (char *)&HandEdgeColor },
{ 1 , "", TEXT, " - if omitted, no hand edges shown" },
{ 1 , "-Hc", COLOR, "Clock hands fill color", (char *)&HandColor },
{ 1 , "-tc", COLOR, "Text color", (char *)&TextColor},
{ 1 , "-Tc", COLOR, "Text background color", (char *)&TextBackColor},
{ 1 , "", TEXT, " - if omitted, then the text is transparent" },
{ 1 , "-tf", STRING, "Text area format string", (char *)&FormatString },
{ 0 , "-Xm", BOOL, "Output the alpha channel on RGB", (char *)&DebugAlpha },
{ 0 , "-D", BOOL, "Turn on debugging", (char *)&Debug },
{ 0 , ((void *)0) }
}
color_t FaceColor
Definition: rleClock.c:96
const char * FormatString
Definition: rleClock.c:122
float LittleHandScale
Definition: rleClock.c:120
int Ticks
Definition: rleClock.c:114
int YClockSize
Definition: rleClock.c:110
int YTextSize
Definition: rleClock.c:111
bool DebugAlpha
Definition: rleClock.c:115
int XSize
Definition: rleClock.c:108
color_t TextBackColor
Definition: rleClock.c:100
color_t HandEdgeColor
Definition: rleClock.c:97
color_t FaceEdgeColor
Definition: rleClock.c:95
float BigHandValue
Definition: rleClock.c:118
float LittleHandValue
Definition: rleClock.c:119
color_t TextColor
Definition: rleClock.c:99
bool Debug
Definition: rleClock.c:116
int Dots
Definition: rleClock.c:117
color_t HandColor
Definition: rleClock.c:98
float BigHandScale
Definition: rleClock.c:121
int Base[]

Definition at line 303 of file font.c.

Referenced by drawText().

float BigHandScale = 60

Definition at line 121 of file rleClock.c.

float BigHandValue

Definition at line 118 of file rleClock.c.

rle_pixel** BlueLine

Definition at line 104 of file rleClock.c.

bool Debug = 0

Definition at line 116 of file rleClock.c.

Referenced by EndPage(), ReadFonts(), and ReadInput().

bool DebugAlpha = 0

Definition at line 115 of file rleClock.c.

const char* description

Definition at line 573 of file rleClock.c.

int Dots = 1

Definition at line 117 of file rleClock.c.

Referenced by drawText().

color_t FaceColor

Definition at line 96 of file rleClock.c.

color_t FaceEdgeColor = { 255, 255, 255 }

Definition at line 95 of file rleClock.c.

const char* FormatString = "%02l:%02b"

Definition at line 122 of file rleClock.c.

Referenced by drawText().

char** gargv

Definition at line 182 of file rleClock.c.

bool given

Definition at line 575 of file rleClock.c.

rle_pixel** GreenLine

Definition at line 103 of file rleClock.c.

color_t HandColor = { 255, 255, 255 }

Definition at line 98 of file rleClock.c.

color_t HandEdgeColor

Definition at line 97 of file rleClock.c.

float LittleHandScale = 12

Definition at line 120 of file rleClock.c.

float LittleHandValue

Definition at line 119 of file rleClock.c.

move_t Moves[]

Definition at line 2 of file font.c.

Referenced by drawText().

rle_pixel** Raster

Definition at line 105 of file rleClock.c.

Referenced by drawText().

char rcsid[] = "$Header: /l/spencer/src/urt/tools/clock/RCS/rleClock.c,v 3.0.1.2 1992/04/30 14:19:38 spencer Exp $"
static

Definition at line 30 of file rleClock.c.

rle_pixel** RedLine

Definition at line 102 of file rleClock.c.

Definition at line 919 of file rleClock.c.

bool show

Definition at line 570 of file rleClock.c.

struct { ... } Stack
color_t TextBackColor

Definition at line 100 of file rleClock.c.

color_t TextColor = { 255, 255, 255 }

Definition at line 99 of file rleClock.c.

int Ticks = 12

Definition at line 114 of file rleClock.c.

int top

Definition at line 920 of file rleClock.c.

enum { ... } type
const char* value

Definition at line 574 of file rleClock.c.

int XMove[4] = {0, 1, 0, -1}

Definition at line 924 of file rleClock.c.

int XRadius

Definition at line 112 of file rleClock.c.

int XSize = 128

Definition at line 108 of file rleClock.c.

Referenced by drawText().

int YClockSize = 128

Definition at line 110 of file rleClock.c.

Referenced by drawText().

int YMove[4] = {1, 0, -1, 0}

Definition at line 925 of file rleClock.c.

int YRadius

Definition at line 113 of file rleClock.c.

int YSize

Definition at line 109 of file rleClock.c.

Referenced by drawText().

int YTextSize = 0

Definition at line 111 of file rleClock.c.

Referenced by drawText().