30 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 $";
39 #include <sys/types.h>
55 #define FORMATSTRING "%02l:%02b"
56 #define FACE_EDGE_COLOR { 255
, 255
, 255
}
57 #define HAND_COLOR { 255
, 255
, 255
}
58 #define TEXT_COLOR { 255
, 255
, 255
}
59 #define LITTLEHANDSCALE 12
60 #define BIGHANDSCALE 60
62 #define HANDWIDTH 0.075
74 #define RAST_FACE_EDGE 1
75 #define RAST_FACE_MASK 2
76 #define RAST_LHAND_EDGE 4
77 #define RAST_LHAND_MASK 8
78 #define RAST_BHAND_EDGE 16
79 #define RAST_BHAND_MASK 32
81 #define RAST_TEXT_BACK 128
128 extern move_t
Moves[];
136 void main(
int argc,
char *argv[]);
137 void ifImageSet(
int i,
int j,
int value, color_t *color);
138 void drawHand(
double place,
double scale,
double radius,
int mask,
int edge);
140 void polarLine(
double r0,
double a0,
double r1,
double a1,
int arg1,
int arg2);
141 void setDot(
int x,
int y,
int arg1,
int arg2);
142 int polarToX(
double fRadius,
double angle);
143 int polarToY(
double fRadius,
double angle);
144 double radians(
double degrees);
147 void lineDots(
int x0,
int y0,
int x1,
int y1,
void (*func)(),
int arg1,
int arg2);
148 void procargs(
int argc,
char *argv[]);
155 void areaFlood(
int firstX,
int firstY,
int mask,
int match,
int value);
162 void rasterAddBits();
168 rle_pixel **rasterAllocate();
174 void charMinMaxWidth();
175 void charMinMaxHeight();
176 char *formatInterp();
192 struct tm *tm, *localtime();
194 bool haveHandEdgeColor;
195 bool haveTextBackColor;
205 tm = localtime(&now);
226 for (i = 0; i <
YSize; i++) {
227 for (j = 0; j <
XSize; j++) {
236 for (i = 0; i < 360; i++) {
239 for (i = 0; i <
Ticks; i++) {
240 theta = (
float) i *360.0 / (
float)
Ticks;
271 for (i = 0; i <
YSize; i++) {
272 for (j = 0; j <
XSize; j++) {
278 if (haveHandEdgeColor) {
281 if (haveTextBackColor) {
315 if (
Raster[i][j] & value) {
330 angle = place / scale * 360;
346 int mask, match, value;
350 for (i = 0 ; i <
YSize; i++) {
351 for (j = 0; j <
XSize; j++) {
352 if ( (
Raster[i][j]&mask) == match )
360 double r0, a0, r1, a1;
380 int x, y, arg1, arg2;
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++) {
421 return degrees/180.0 * 3.1415926;
440 for ( i=0 ; i<height ; i++) {
473 for (i = 0; i <
YSize; i++) {
509 int e, x, y, delta_x, delta_y, tmp;
516 if (x0 == x1 && y0 == y1) {
517 (*func)(x0, y0, arg1, arg2);
526 delta_x = delta_x > 0 ? delta_x : -delta_x;
528 delta_y = delta_y > 0 ? delta_y : -delta_y;
531 dir_x = (x1 - x0) > 0 ? 1 : -1;
532 dir_y = (y1 - y0) > 0 ? 1 : -1;
534 if (delta_y > delta_x) {
540 two_dx = 2 * delta_x;
541 two_dy = 2 * delta_y;
543 e = two_dy - delta_x;
544 for (i = 1; i <= delta_x; ++i) {
545 (*func) (x, y, arg1, arg2);
572 enum { INT, FLOAT, STRING, BOOL, COLOR, HELP, TEXT } type;
577 {
TRUE,
"-x", INT,
"Image width in pixels", (
char *)&
XSize },
578 {
TRUE,
"-cy", INT,
"Clock image height in pixels", (
char *)&
YClockSize },
579 {
TRUE,
"-ty", INT,
"Text image height in pixels", (
char *)&
YTextSize },
580 {
TRUE,
"-help", HELP,
"Prints this help message", NULL },
586 {
TRUE,
"-t", INT,
"Number of ticks around the face", (
char *)&
Ticks },
587 {
TRUE,
"-lw", INT,
"Line width in pixels", (
char *)&
Dots },
590 {
TRUE,
"-Fc", COLOR,
"Clock face background color", (
char *)&
FaceColor },
591 {
TRUE,
"", TEXT,
" - if omitted, then the clock is transparent" },
593 {
TRUE,
"", TEXT,
" - if omitted, no hand edges shown" },
594 {
TRUE,
"-Hc", COLOR,
"Clock hands fill color", (
char *)&
HandColor },
597 {
TRUE,
"", TEXT,
" - if omitted, then the text is transparent" },
599 {
FALSE,
"-Xm", BOOL,
"Output the alpha channel on RGB", (
char *)&
DebugAlpha },
600 {
FALSE,
"-D", BOOL,
"Turn on debugging", (
char *)&
Debug },
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) {
618 if (Args[i].arg==NULL) {
619 fprintf(stderr,
"Unknown argument: \"%s\"\n", argv[arg]);
622 Args[i].given =
TRUE;
623 switch (Args[i].type) {
629 *(
int *)Args[i].value = atoi(argv[arg]);
633 *(
float *)Args[i].value = atof(argv[arg]);
640 *(
char **)Args[i].value = (
char *)malloc(strlen(argv[arg])+1);
641 strcpy(*(
char **)Args[i].value, argv[arg]);
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],
652 color
->red = atoi(argv[arg+1]);
653 color
->green = atoi(argv[arg+2]);
654 color
->blue = atoi(argv[arg+3]);
667 for ( i=0 ; Args[i].arg != NULL ; i++) {
668 if (Args[i].value == argVar) {
669 return Args[i].given;
681 fprintf(stderr,
"Usage: %s [args]\n", pgm);
682 for (i = 0; Args[i].arg != NULL; i++) {
684 fprintf(stderr,
"\t%s", Args[i].arg);
685 switch (Args[i].type) {
687 fprintf(stderr,
" INT");
690 fprintf(stderr,
" FLOAT");
695 fprintf(stderr,
" STR");
698 fprintf(stderr,
" RED GREEN BLUE");
703 fprintf(stderr,
" ... %s\n", Args[i].description);
734 epos =
Base[(
int)ch - 33 + 1];
735 pos =
Base[(
int)ch - 33];
736 for (; pos < epos; pos++) {
762 epos =
Base[(
int)ch - 33 + 1];
763 pos =
Base[(
int)ch - 33];
764 for (; pos < epos; pos++) {
787 static char outBuf[1024];
790 buf = (
char *)malloc(strlen(str)*2+1);
803 if (isdigit(*str) || *str ==
'.') {
806 if ( *str==
'B' || *str==
'L') {
811 }
else if ( *str==
'b' || *str==
'l') {
821 strcat(outBuf, tmpBuf);
848 int i, j, xsize, ysize, min, max, basex;
849 int curx, cury, x, y, pos, epos, charBasex;
855 for (i = 0; string[i] != 0; i++) {
859 if (ysize < (max - min)+
Dots) {
860 ysize = max - min+
Dots;
863 scale = (
float)
YTextSize / (
float) ysize;
864 scalex = (
float)
XSize / (
float) xsize;
865 if (scale > scalex) {
868 basex = (
XSize - (
int) ((
float)xsize * scale)) / 2;
871 for (i = 0; string[i] != 0; i++) {
872 if (isprint(string[i]) && string[i] !=
' ') {
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);
887 x = basex + (
int)(scale * charBasex);
896 for (j = basex; j < x; j++) {
930 int mask, match, value;
932 register _urt_stack *sp;
934 Stack.s = (_urt_stack *) calloc(256,
sizeof(_urt_stack));
935 Stack.allocked = 256;
939 while (Stack.top >= 0) {
940 sp = &Stack.s[Stack.top];
944 fprintf(stderr,
"Marking %d, %d at stack %d\n", sp
->x, sp
->y, Stack.top);
951 sp = &Stack.s[Stack.top];
953 }
while (sp
->dir >= 4);
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);
970 Stack.s[Stack.top]
.x = x;
971 Stack.s[Stack.top]
.y = y;
972 Stack.s[Stack.top]
.dir = dir;
979 return Stack.top < 0;
#define RLE_SET_BIT(glob, bit)
const char * FormatString
void stackPush(int x, int y, int dir)
void drawHand(double place, double scale, double radius, int mask, int edge)
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
void rasterAddBits(int mask, int match, int value)
char * cmd_name(char **argv)
void rle_close_f(FILE *fd)
void polarLine(double r0, double a0, double r1, double a1, int arg1, int arg2)
void main(int argc, char **argv)
void charMinMaxWidth(int ch, int *min, int *max)
int polarToY(double fRadius, double angle)
int polarToX(double fRadius, double angle)
char * formatInterp(char *str) const
void charMinMaxHeight(int ch, int *min, int *max)
void rle_putrow(rows, int rowlen, rle_hdr *the_hdr)
void rasterWrite(FILE *fd)
void lineDots(int x0, int y0, int x1, int y1, void(*func)(), int arg1, int arg2)
void usageExit(char *pgm)
void areaFlood(int firstX, int firstY, int mask, int match, int value)
void rle_addhist(argv, rle_hdr *in_hdr, rle_hdr *out_hdr)
void procargs(int argc, argv)
bool argGiven(char *argVar)
void rle_put_setup(rle_hdr *the_hdr)
double radians(double degrees)
rle_pixel ** rasterAllocate(int height, int width)
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
void ifImageSet(int i, int j, int value, color_t *color)
void setDot(int x, int y, int arg1, int arg2)