BRL-CAD
fbclear.c
Go to the documentation of this file.
1 /* F B C L E A R . C
2  * BRL-CAD
3  *
4  * Copyright (c) 1986-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  *
20  */
21 /** @file libged/fbclear.c
22  *
23  * Clear a framebuffer.
24  *
25  */
26 
27 #include "common.h"
28 
29 #include <stdlib.h>
30 #ifdef HAVE_SYS_TYPES_H
31 # include <sys/types.h>
32 #endif
33 #ifdef HAVE_SYS_STAT_H
34 # include <sys/stat.h>
35 #endif
36 #ifdef HAVE_WINSOCK_H
37 # include <winsock.h>
38 #endif
39 
40 #include "fb.h"
41 #include "ged.h"
42 
43 
44 #define FB_CONSTRAIN(_v, _a, _b) \
45  (((_v) > (_a)) ? ((_v) < (_b) ? (_v) : (_b)) : (_a))
46 
47 int
48 ged_fbclear(struct ged *gedp, int argc, const char *argv[])
49 {
50  static const char usage[] = "\nUsage: fbclear [rgb]";
51 
52  int ret;
53  unsigned char clearColor[3] = {0.0, 0.0 ,0.0};
54 
58  GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
59 
60  /* initialize result */
61  bu_vls_trunc(gedp->ged_result_str, 0);
62 
63  if (argc == 2) {
64  int r, g, b;
65 
66  if (sscanf(argv[1], "%d %d %d", &r, &g, &b) != 3) {
67  bu_log("fb_clear: bad color spec - %s", argv[1]);
68  return GED_ERROR;
69  }
70 
71  clearColor[RED] = FB_CONSTRAIN(r, 0, 255);
72  clearColor[GRN] = FB_CONSTRAIN(g, 0, 255);
73  clearColor[BLU] = FB_CONSTRAIN(b, 0, 255);
74 
75  } else if (argc > 2) {
76  bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
77  return GED_ERROR;
78  }
79 
80  ret = fb_clear(gedp->ged_fbsp->fbs_fbp, clearColor);
81 
82  if (ret)
83  return GED_ERROR;
84 
85  return GED_OK;
86 }
87 
88 
89 /*
90  * Local Variables:
91  * mode: C
92  * tab-width: 8
93  * indent-tabs-mode: t
94  * c-file-style: "stroustrup"
95  * End:
96  * ex: shiftwidth=4 tabstop=8
97  */
void usage(struct ged *gedp)
Definition: coil.c:315
#define GED_OK
Definition: ged.h:55
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176
Definition: ged.h:338
#define RED
Definition: color.h:39
void bu_vls_trunc(struct bu_vls *vp, int len)
Definition: vls.c:198
#define GED_CHECK_ARGC_GT_0(_gedp, _argc, _flags)
Definition: ged.h:202
struct fbserv_obj * ged_fbsp
Definition: ged.h:362
Header file for the BRL-CAD common definitions.
#define BLU
Definition: color.h:41
#define GED_ERROR
Definition: ged.h:61
#define FB_CONSTRAIN(_v, _a, _b)
Definition: fbclear.c:44
#define GED_CHECK_DATABASE_OPEN(_gedp, _flags)
Definition: ged.h:114
#define GED_CHECK_FBSERV(_gedp, _flags)
Definition: ged.h:150
struct bu_vls * ged_result_str
Definition: ged.h:357
#define GED_CHECK_FBSERV_FBP(_gedp, _flags)
Definition: ged.h:160
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
int fb_clear(fb *ifp, unsigned char *pp)
Definition: fb_generic.c:268
int ged_fbclear(struct ged *gedp, int argc, const char *argv[])
Definition: fbclear.c:48
#define GRN
Definition: color.h:40