Revision: 43237
          http://brlcad.svn.sourceforge.net/brlcad/?rev=43237&view=rev
Author:   bob1961
Date:     2011-02-11 20:23:38 +0000 (Fri, 11 Feb 2011)

Log Message:
-----------
Added pix2fb and fb2pix to libged.

Modified Paths:
--------------
    brlcad/trunk/include/fb.h
    brlcad/trunk/include/fbserv_obj.h
    brlcad/trunk/include/ged.h
    brlcad/trunk/src/libfb/fb_generic.c
    brlcad/trunk/src/libged/Makefile.am
    brlcad/trunk/src/libtclcad/ged_obj.c
    brlcad/trunk/src/tclscripts/lib/Ged.tcl

Added Paths:
-----------
    brlcad/trunk/src/libged/fb2pix.c
    brlcad/trunk/src/libged/pix2fb.c

Modified: brlcad/trunk/include/fb.h
===================================================================
--- brlcad/trunk/include/fb.h   2011-02-11 20:11:10 UTC (rev 43236)
+++ brlcad/trunk/include/fb.h   2011-02-11 20:23:38 UTC (rev 43237)
@@ -92,6 +92,8 @@
 FB_EXPORT extern int fb_common_file_size(size_t *widthp, size_t *heightp, 
const char *filename, int pixel_size);
 FB_EXPORT extern int fb_common_image_size(size_t *widthp, size_t *heightp, 
size_t npixels);
 FB_EXPORT extern int fb_common_name_size(size_t *widthp, size_t *heightp, 
const char *name);
+FB_EXPORT extern int fb_write_fp(FBIO *ifp, FILE *fp, int req_width, int 
req_height, int crunch, int inverse, struct bu_vls *result);
+FB_EXPORT extern int fb_read_fd(FBIO *ifp, int fd,  int file_width, int 
file_height, int file_xoff, int file_yoff, int scr_width, int scr_height, int 
scr_xoff, int scr_yoff, int fileinput, char *file_name, int one_line_only, int 
multiple_lines, int autosize, int inverse, int clear, int zoom, struct bu_vls 
*result);
 
 /* color mapping */
 FB_EXPORT extern int fb_is_linear_cmap(const ColorMap *cmap);

Modified: brlcad/trunk/include/fbserv_obj.h
===================================================================
--- brlcad/trunk/include/fbserv_obj.h   2011-02-11 20:11:10 UTC (rev 43236)
+++ brlcad/trunk/include/fbserv_obj.h   2011-02-11 20:23:38 UTC (rev 43237)
@@ -32,6 +32,7 @@
 #define MAX_CLIENTS 32
 #define MAX_PORT_TRIES 100
 #define FBS_CALLBACK_NULL (void (*)())NULL
+#define FBSERV_OBJ_NULL (struct fbserv_obj *)NULL
 
 struct fbserv_listener {
     int fbsl_fd;                       /**< @brief socket to listen for 
connections */

Modified: brlcad/trunk/include/ged.h
===================================================================
--- brlcad/trunk/include/ged.h  2011-02-11 20:11:10 UTC (rev 43236)
+++ brlcad/trunk/include/ged.h  2011-02-11 20:23:38 UTC (rev 43237)
@@ -164,6 +164,26 @@
        return (_flags); \
     }
 
+#define GED_CHECK_FBSERV(_gedp, _flags) \
+    if (_gedp->ged_fbsp == FBSERV_OBJ_NULL) { \
+       int ged_check_view_quiet = (_flags) & GED_QUIET; \
+       if (!ged_check_view_quiet) { \
+           bu_vls_trunc(&(_gedp)->ged_result_str, 0); \
+           bu_vls_printf(&(_gedp)->ged_result_str, "A framebuffer server 
object does not exist."); \
+       } \
+       return (_flags); \
+    }
+
+#define GED_CHECK_FBSERV_FBP(_gedp, _flags) \
+    if (_gedp->ged_fbsp->fbs_fbp == FBIO_NULL) { \
+       int ged_check_view_quiet = (_flags) & GED_QUIET; \
+       if (!ged_check_view_quiet) { \
+           bu_vls_trunc(&(_gedp)->ged_result_str, 0); \
+           bu_vls_printf(&(_gedp)->ged_result_str, "A framebuffer IO structure 
does not exist."); \
+       } \
+       return (_flags); \
+    }
+
 /** Lookup database object */
 #define GED_CHECK_EXISTS(_gedp, _name, _noisy, _flags) \
     if (db_lookup((_gedp)->ged_wdbp->dbip, (_name), (_noisy)) != RT_DIR_NULL) 
{ \
@@ -494,6 +514,7 @@
 
     struct ged_drawable                *ged_gdp;
     struct ged_view            *ged_gvp;
+    struct fbserv_obj          *ged_fbsp;
 
     void                       *ged_dmp;
     void                       *ged_refresh_clientdata;        /**< @brief  
client data passed to refresh handler */
@@ -1601,6 +1622,11 @@
 GED_EXPORT BU_EXTERN(int ged_facetize, (struct ged *gedp, int argc, const char 
*argv[]));
 
 /**
+ * Fb2pix writes a framebuffer image to a .pix file.
+ */
+GED_EXPORT BU_EXTERN(int ged_fb2pix, (struct ged *gedp, int argc, const char 
*argv[]));
+
+/**
  * Find combinations that reference object
  */
 GED_EXPORT BU_EXTERN(int ged_find, (struct ged *gedp, int argc, const char 
*argv[]));
@@ -1939,6 +1965,11 @@
 GED_EXPORT BU_EXTERN(int ged_perspective, (struct ged *gedp, int argc, const 
char *argv[]));
 
 /**
+ * Pix2fb reads a pix file into a framebuffer.
+ */
+GED_EXPORT BU_EXTERN(int ged_pix2fb, (struct ged *gedp, int argc, const char 
*argv[]));
+
+/**
  * Create a unix plot file of the currently displayed objects.
  */
 GED_EXPORT BU_EXTERN(int ged_plot, (struct ged *gedp, int argc, const char 
*argv[]));

Modified: brlcad/trunk/src/libfb/fb_generic.c
===================================================================
--- brlcad/trunk/src/libfb/fb_generic.c 2011-02-11 20:11:10 UTC (rev 43236)
+++ brlcad/trunk/src/libfb/fb_generic.c 2011-02-11 20:23:38 UTC (rev 43237)
@@ -430,8 +430,278 @@
     }
 }
 
+static void
+fb_cmap_crunch(RGBpixel (*scan_buf), int pixel_ct, ColorMap *cmap)
+{
+    unsigned short     *rp = cmap->cm_red;
+    unsigned short     *gp = cmap->cm_green;
+    unsigned short     *bp = cmap->cm_blue;
 
+    /* noalias ? */
+    for (; pixel_ct > 0; pixel_ct--, scan_buf++ )  {
+       (*scan_buf)[RED] = rp[(*scan_buf)[RED]] >> 8;
+       (*scan_buf)[GRN] = gp[(*scan_buf)[GRN]] >> 8;
+       (*scan_buf)[BLU] = bp[(*scan_buf)[BLU]] >> 8;
+    }
+}
+
+int
+fb_write_fp(FBIO *ifp, FILE *fp, int req_width, int req_height, int crunch, 
int inverse, struct bu_vls *result)
+{
+    unsigned char *scanline;   /* 1 scanline pixel buffer */
+    int scanbytes;             /* # of bytes of scanline */
+    int scanpix;               /* # of pixels of scanline */
+    ColorMap cmap;             /* libfb color map */
+
+    scanpix = req_width;
+    scanbytes = scanpix * sizeof(RGBpixel);
+    if ((scanline = (unsigned char *)malloc(scanbytes)) == RGBPIXEL_NULL) {
+       bu_vls_printf(result, "fb_write_to_pix_fp: malloc(%d) failure", 
scanbytes);
+       return BRLCAD_ERROR;
+    }
+
+    if (req_height > fb_getheight(ifp))
+       req_height = fb_getheight(ifp);
+    if (req_width > fb_getwidth(ifp))
+       req_width = fb_getwidth(ifp);
+
+    if (crunch) {
+       if (fb_rmap(ifp, &cmap) == -1) {
+           crunch = 0;
+       } else if (fb_is_linear_cmap(&cmap)) {
+           crunch = 0;
+       }
+    }
+
+    if (!inverse) {
+       int y;
+
+       /* Regular -- read bottom to top */
+       for (y=0; y < req_height; y++) {
+           fb_read(ifp, 0, y, scanline, req_width);
+           if (crunch)
+               fb_cmap_crunch((RGBpixel *)scanline, scanpix, &cmap);
+           if (fwrite((char *)scanline, scanbytes, 1, fp) != 1) {
+               perror("fwrite");
+               break;
+           }
+       }
+    } else {
+       int y;
+
+       /* Inverse -- read top to bottom */
+       for (y = req_height-1; y >= 0; y--) {
+           fb_read(ifp, 0, y, scanline, req_width);
+           if (crunch)
+               fb_cmap_crunch((RGBpixel *)scanline, scanpix, &cmap);
+           if (fwrite((char *)scanline, scanbytes, 1, fp) != 1) {
+               perror("fwrite");
+               break;
+           }
+       }
+    }
+
+    bu_free((genptr_t)scanline, "fb_write_to_pix_fp(): scanline");
+    return BRLCAD_OK;
+}
+
 /*
+ * Throw bytes away.  Use reads into scanline buffer if a pipe, else seek.
+ */
+static int
+fb_skip_bytes(int fd, off_t num, int fileinput, int scanbytes, unsigned char 
*scanline)
+{
+    int n, try;
+
+    if (fileinput) {
+       (void)lseek(fd, (off_t)num, 1);
+       return 0;
+    }
+
+    while (num > 0) {
+       try = num > scanbytes ? scanbytes : num;
+       n = read(fd, scanline, try);
+       if (n <= 0) {
+           return -1;
+       }
+       num -= n;
+    }
+    return 0;
+}
+
+
+int
+fb_read_fd(FBIO *ifp, int fd, int file_width, int file_height, int file_xoff, 
int file_yoff, int scr_width, int scr_height, int scr_xoff, int scr_yoff, int 
fileinput, char *file_name, int one_line_only, int multiple_lines, int 
autosize, int inverse, int clear, int zoom, struct bu_vls *result)
+{
+    int y;
+    int xout, yout, n, m, xstart, xskip;
+    unsigned char *scanline;   /* 1 scanline pixel buffer */
+    int scanbytes;             /* # of bytes of scanline */
+    int scanpix;               /* # of pixels of scanline */
+
+    /* autosize input? */
+    if (fileinput && autosize) {
+       size_t w, h;
+       if (fb_common_file_size(&w, &h, file_name, 3)) {
+           file_width = w;
+           file_height = h;
+       } else {
+           fprintf(stderr, "pix-fb: unable to autosize\n");
+       }
+    }
+
+    /* If screen size was not set, track the file size */
+    if (scr_width == 0)
+       scr_width = file_width;
+    if (scr_height == 0)
+       scr_height = file_height;
+
+    /* Get the screen size we were given */
+    scr_width = fb_getwidth(ifp);
+    scr_height = fb_getheight(ifp);
+
+    /* compute number of pixels to be output to screen */
+    if (scr_xoff < 0) {
+       xout = scr_width + scr_xoff;
+       xskip = (-scr_xoff);
+       xstart = 0;
+    } else {
+       xout = scr_width - scr_xoff;
+       xskip = 0;
+       xstart = scr_xoff;
+    }
+
+    if (xout < 0)
+       bu_exit(0, NULL);                       /* off screen */
+    if ((size_t)xout > (file_width-file_xoff))
+       xout = (file_width-file_xoff);
+    scanpix = xout;                            /* # pixels on scanline */
+
+    if (inverse)
+       scr_yoff = (-scr_yoff);
+
+    yout = scr_height - scr_yoff;
+    if (yout < 0)
+       bu_exit(0, NULL);                       /* off screen */
+    if ((size_t)yout > (file_height-file_yoff))
+       yout = (file_height-file_yoff);
+
+    /* Only in the simplest case use multi-line writes */
+    if (!one_line_only
+       && multiple_lines > 0
+       && !inverse
+       && !zoom
+       && (size_t)xout == file_width
+       && file_width <= (size_t)scr_width)
+    {
+       scanpix *= multiple_lines;
+    }
+
+    scanbytes = scanpix * sizeof(RGBpixel);
+    if ((scanline = (unsigned char *)malloc(scanbytes)) == RGBPIXEL_NULL) {
+       fprintf(stderr,
+               "pix-fb:  malloc(%d) failure for scanline buffer\n",
+               scanbytes);
+       bu_exit(2, NULL);
+    }
+
+    if (clear) {
+       fb_clear(ifp, PIXEL_NULL);
+    }
+    if (zoom) {
+       /* Zoom in, and center the display.  Use square zoom. */
+       int zoomit;
+       zoomit = scr_width/xout;
+       if (scr_height/yout < zoomit) zoomit = scr_height/yout;
+       if (inverse) {
+           fb_view(ifp,
+                   scr_xoff+xout/2, scr_height-1-(scr_yoff+yout/2),
+                   zoomit, zoomit);
+       } else {
+           fb_view(ifp,
+                   scr_xoff+xout/2, scr_yoff+yout/2,
+                   zoomit, zoomit);
+       }
+    }
+
+    if (file_yoff != 0) fb_skip_bytes(fd, 
(off_t)file_yoff*(off_t)file_width*sizeof(RGBpixel), fileinput, scanbytes, 
scanline);
+
+    if (multiple_lines) {
+       /* Bottom to top with multi-line reads & writes */
+       unsigned long height;
+       for (y = scr_yoff; y < scr_yoff + yout; y += multiple_lines) {
+           n = bu_mread(fd, (char *)scanline, scanbytes);
+           if (n <= 0) break;
+           height = multiple_lines;
+           if (n != scanbytes) {
+               height = (n/sizeof(RGBpixel)+xout-1)/xout;
+               if (height <= 0) break;
+           }
+           /* Don't over-write */
+           if ((size_t)(y + height) > (size_t)(scr_yoff + yout))
+               height = scr_yoff + yout - y;
+           if (height <= 0) break;
+           m = fb_writerect(ifp, scr_xoff, y,
+                            file_width, height,
+                            scanline);
+           if ((size_t)m != file_width*height) {
+               fprintf(stderr,
+                       "pix-fb: fb_writerect(x=%d, y=%d, w=%lu, h=%lu) 
failure, ret=%d, s/b=%d\n",
+                       scr_xoff, y,
+                       (unsigned long)file_width, height, m, scanbytes);
+           }
+       }
+    } else if (!inverse) {
+       /* Normal way -- bottom to top */
+       for (y = scr_yoff; y < scr_yoff + yout; y++) {
+           if (y < 0 || y > scr_height) {
+               fb_skip_bytes(fd, (off_t)file_width*sizeof(RGBpixel), 
fileinput, scanbytes, scanline);
+               continue;
+           }
+           if (file_xoff+xskip != 0)
+               fb_skip_bytes(fd, (off_t)(file_xoff+xskip)*sizeof(RGBpixel), 
fileinput, scanbytes, scanline);
+           n = bu_mread(fd, (char *)scanline, scanbytes);
+           if (n <= 0) break;
+           m = fb_write(ifp, xstart, y, scanline, xout);
+           if (m != xout) {
+               fprintf(stderr,
+                       "pix-fb: fb_write(x=%d, y=%d, npix=%d) ret=%d, 
s/b=%d\n",
+                       scr_xoff, y, xout,
+                       m, xout);
+           }
+           /* slop at the end of the line? */
+           if ((size_t)file_xoff+xskip+scanpix < file_width)
+               fb_skip_bytes(fd, 
(off_t)(file_width-file_xoff-xskip-scanpix)*sizeof(RGBpixel), fileinput, 
scanbytes, scanline);
+       }
+    } else {
+       /* Inverse -- top to bottom */
+       for (y = scr_height-1-scr_yoff; y >= scr_height-scr_yoff-yout; y--) {
+           if (y < 0 || y >= scr_height) {
+               fb_skip_bytes(fd, (off_t)file_width*sizeof(RGBpixel), 
fileinput, scanbytes, scanline);
+               continue;
+           }
+           if (file_xoff+xskip != 0)
+               fb_skip_bytes(fd, (off_t)(file_xoff+xskip)*sizeof(RGBpixel), 
fileinput, scanbytes, scanline);
+           n = bu_mread(fd, (char *)scanline, scanbytes);
+           if (n <= 0) break;
+           m = fb_write(ifp, xstart, y, scanline, xout);
+           if (m != xout) {
+               fprintf(stderr,
+                       "pix-fb: fb_write(x=%d, y=%d, npix=%d) ret=%d, 
s/b=%d\n",
+                       scr_xoff, y, xout,
+                       m, xout);
+           }
+           /* slop at the end of the line? */
+           if ((size_t)file_xoff+xskip+scanpix < file_width)
+               fb_skip_bytes(fd, 
(off_t)(file_width-file_xoff-xskip-scanpix)*sizeof(RGBpixel), fileinput, 
scanbytes, scanline);
+       }
+    }
+
+    return BRLCAD_OK;
+}
+
+
+/*
  * Local Variables:
  * mode: C
  * tab-width: 8

Modified: brlcad/trunk/src/libged/Makefile.am
===================================================================
--- brlcad/trunk/src/libged/Makefile.am 2011-02-11 20:11:10 UTC (rev 43236)
+++ brlcad/trunk/src/libged/Makefile.am 2011-02-11 20:23:38 UTC (rev 43237)
@@ -73,6 +73,7 @@
        eye.c \
        eye_pos.c \
        facetize.c \
+       fb2pix.c \
        find.c \
        form.c \
        fracture.c \
@@ -143,6 +144,7 @@
        pathlist.c \
        pathsum.c \
        perspective.c \
+       pix2fb.c \
        plot.c \
        pmat.c \
        pmodel2view.c \
@@ -280,13 +282,14 @@
 libged_la_LDFLAGS = -version-info 19:1 -no-undefined -Wc,${FEXCEPTIONS}
 libged_la_LIBADD = \
        libged_nil.la \
+       ${FB} \
        ${GED_LIBS}
 
 EXTRA_DIST = \
        subtype.c \
         CMakeLists.txt
 
-DEPENDS = src/librt src/libwdb src/libanalyze
+DEPENDS = src/librt src/libwdb src/libanalyze src/libfb
 
 include $(top_srcdir)/misc/Makefile.defs
 

Added: brlcad/trunk/src/libged/fb2pix.c
===================================================================
--- brlcad/trunk/src/libged/fb2pix.c                            (rev 0)
+++ brlcad/trunk/src/libged/fb2pix.c    2011-02-11 20:23:38 UTC (rev 43237)
@@ -0,0 +1,168 @@
+/*                        F B 2 P I X . C
+ * BRL-CAD
+ *
+ * Copyright (c) 1986-2011 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ *
+ */
+/** @file fb2pix.c
+ *
+ * fb2pix writes a framebuffer image to a .pix file.
+ *
+ */
+
+#include "common.h"
+
+#include <stdlib.h>
+#include <sys/stat.h>
+#include "bio.h"
+
+#ifdef HAVE_WINSOCK_H
+#  include <winsock.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
+
+#include "bu.h"
+#include "fb.h"
+#include "fbserv_obj.h"
+
+#include "pkg.h"
+#include "ged.h"
+
+
+char *file_name;
+FILE *outfp;
+
+static int crunch = 0;         /* Color map crunch? */
+static int inverse = 0;                /* Draw upside-down */
+int screen_height;                     /* input height */
+int screen_width;                      /* input width */
+
+
+static int
+get_args(int argc, char **argv)
+{
+    int c;
+
+    bu_optind = 1;
+    while ((c = bu_getopt(argc, argv, "chiF:s:w:n:")) != EOF) {
+       switch (c) {
+           case 'c':
+               crunch = 1;
+               break;
+           case 'h':
+               /* high-res */
+               screen_height = screen_width = 1024;
+               break;
+           case 'i':
+               inverse = 1;
+               break;
+           case 's':
+               /* square size */
+               screen_height = screen_width = atoi(bu_optarg);
+               break;
+           case 'w':
+               screen_width = atoi(bu_optarg);
+               break;
+           case 'n':
+               screen_height = atoi(bu_optarg);
+               break;
+
+           default:            /* '?' */
+               return 0;
+       }
+    }
+
+    if (bu_optind >= argc) {
+       if (isatty(fileno(stdout)))
+           return 0;
+       file_name = "-";
+       outfp = stdout;
+    } else {
+       file_name = argv[bu_optind];
+       if ((outfp = fopen(file_name, "wb")) == NULL) {
+           (void)fprintf(stderr,
+                         "fb-pix: cannot open \"%s\" for writing\n",
+                         file_name);
+           return 0;
+       }
+       (void)bu_fchmod(outfp, 0444);
+    }
+
+    if (argc > ++bu_optind)
+       (void)fprintf(stderr, "fb-pix: excess argument(s) ignored\n");
+
+    return 1;          /* OK */
+}
+
+
+int
+ged_fb2pix(struct ged *gedp, int argc, const char *argv[])
+{
+    int ret;
+    char usage[] = "Usage: fb-pix [-h -i -c] \n\
+       [-s squaresize] [-w width] [-n height] [file.pix]\n";
+
+    GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR);
+    GED_CHECK_FBSERV(gedp, GED_ERROR);
+    GED_CHECK_FBSERV_FBP(gedp, GED_ERROR);
+    GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
+
+    /* initialize result */
+    bu_vls_trunc(&gedp->ged_result_str, 0);
+
+    /* must be wanting help */
+    if (argc == 1) {
+       bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
+       return GED_HELP;
+    }
+
+    screen_height = screen_width = 512;                /* Defaults */
+
+    if (!get_args(argc, (char **)argv)) {
+       bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
+       return GED_HELP;
+    }
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+    setmode(fileno(stdout), O_BINARY);
+#endif
+
+    ret = fb_write_fp(gedp->ged_fbsp->fbs_fbp, outfp,
+                     screen_width, screen_height,
+                     crunch, inverse, &gedp->ged_result_str);
+
+    if (outfp != stdout)
+       fclose(outfp);
+
+    if (ret == BRLCAD_OK)
+       return GED_OK;
+
+    return GED_ERROR;
+}
+
+
+/*
+ * Local Variables:
+ * mode: C
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */


Property changes on: brlcad/trunk/src/libged/fb2pix.c
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:eol-style
   + native

Added: brlcad/trunk/src/libged/pix2fb.c
===================================================================
--- brlcad/trunk/src/libged/pix2fb.c                            (rev 0)
+++ brlcad/trunk/src/libged/pix2fb.c    2011-02-11 20:23:38 UTC (rev 43237)
@@ -0,0 +1,232 @@
+/*                        P I X 2 F B . C
+ * BRL-CAD
+ *
+ * Copyright (c) 1986-2011 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ *
+ */
+/** @file pix2fb.c
+ *
+ * Program to take bottom-up pixel files and send them to a framebuffer.
+ *
+ */
+
+#include "common.h"
+
+#include <stdlib.h>
+#ifdef HAVE_SYS_TYPES_H
+#  include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+#  include <sys/stat.h>
+#endif
+#ifdef HAVE_WINSOCK_H
+#  include <winsock.h>
+#endif
+#include "bio.h"
+
+#include "bu.h"
+#include "fb.h"
+#include "fbserv_obj.h"
+
+#include "pkg.h"
+#include "ged.h"
+
+
+static int multiple_lines = 0; /* Streamlined operation */
+
+static char *file_name;
+static int infd;
+
+static int fileinput = 0;      /* file or pipe on input? */
+static int autosize = 0;       /* !0 to autosize input */
+
+static size_t file_width = 512;        /* default input width */
+static size_t file_height = 512;/* default input height */
+static int scr_width = 0;      /* screen tracks file if not given */
+static int scr_height = 0;
+static int file_xoff, file_yoff;
+static int scr_xoff, scr_yoff;
+static int clear = 0;
+static int zoom = 0;
+static int inverse = 0;                /* Draw upside-down */
+static int one_line_only = 0;  /* insist on 1-line writes */
+static int pause_sec = 0;      /* Pause that many seconds before
+                                  closing the FB and exiting */
+
+static char usage[] = "\
+Usage: pix-fb [-a -h -i -c -z -1] [-m #lines] [-F framebuffer]\n\
+       [-s squarefilesize] [-w file_width] [-n file_height]\n\
+       [-x file_xoff] [-y file_yoff] [-X scr_xoff] [-Y scr_yoff]\n\
+       [-S squarescrsize] [-W scr_width] [-N scr_height] [-p seconds]\n\
+       [file.pix]\n";
+
+static int
+get_args(int argc, char **argv)
+{
+    int c;
+
+    bu_optind = 1;
+    while ((c = bu_getopt(argc, argv, "1m:ahiczF:p:s:w:n:x:y:X:Y:S:W:N:")) != 
EOF) {
+       switch (c) {
+           case '1':
+               one_line_only = 1;
+               break;
+           case 'm':
+               multiple_lines = atoi(bu_optarg);
+               break;
+           case 'a':
+               autosize = 1;
+               break;
+           case 'h':
+               /* high-res */
+               file_height = file_width = 1024;
+               scr_height = scr_width = 1024;
+               autosize = 0;
+               break;
+           case 'i':
+               inverse = 1;
+               break;
+           case 'c':
+               clear = 1;
+               break;
+           case 'z':
+               zoom = 1;
+               break;
+           case 's':
+               /* square file size */
+               file_height = file_width = atoi(bu_optarg);
+               autosize = 0;
+               break;
+           case 'w':
+               file_width = atoi(bu_optarg);
+               autosize = 0;
+               break;
+           case 'n':
+               file_height = atoi(bu_optarg);
+               autosize = 0;
+               break;
+           case 'x':
+               file_xoff = atoi(bu_optarg);
+               break;
+           case 'y':
+               file_yoff = atoi(bu_optarg);
+               break;
+           case 'X':
+               scr_xoff = atoi(bu_optarg);
+               break;
+           case 'Y':
+               scr_yoff = atoi(bu_optarg);
+               break;
+           case 'S':
+               scr_height = scr_width = atoi(bu_optarg);
+               break;
+           case 'W':
+               scr_width = atoi(bu_optarg);
+               break;
+           case 'N':
+               scr_height = atoi(bu_optarg);
+               break;
+           case 'p':
+               pause_sec=atoi(bu_optarg);
+               break;
+
+           default:            /* '?' */
+               return 0;
+       }
+    }
+
+    if (bu_optind >= argc) {
+       if (isatty(fileno(stdin)))
+           return 0;
+       file_name = "-";
+       infd = 0;
+    } else {
+       file_name = argv[bu_optind];
+       if ((infd = open(file_name, 0)) < 0) {
+           perror(file_name);
+           (void)fprintf(stderr,
+                         "pix-fb: cannot open \"%s\" for reading\n",
+                         file_name);
+           bu_exit(1, NULL);
+       }
+#ifdef _WIN32
+       setmode(infd, O_BINARY);
+#endif
+       fileinput++;
+    }
+
+    if (argc > ++bu_optind)
+       (void)fprintf(stderr, "pix-fb: excess argument(s) ignored\n");
+
+    return 1;          /* OK */
+}
+
+
+int
+ged_pix2fb(struct ged *gedp, int argc, const char *argv[])
+{
+    int ret;
+
+    GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR);
+    GED_CHECK_FBSERV(gedp, GED_ERROR);
+    GED_CHECK_FBSERV_FBP(gedp, GED_ERROR);
+    GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
+
+    /* initialize result */
+    bu_vls_trunc(&gedp->ged_result_str, 0);
+
+    /* must be wanting help */
+    if (argc == 1) {
+       bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
+       return GED_HELP;
+    }
+
+    if (!get_args(argc, (char **)argv)) {
+       bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
+       return GED_HELP;
+    }
+
+    ret = fb_read_fd(gedp->ged_fbsp->fbs_fbp, infd,
+                    file_width, file_height,
+                    file_xoff, file_yoff,
+                    scr_width, scr_height,
+                    scr_xoff, scr_yoff,
+                    fileinput, file_name, one_line_only, multiple_lines,
+                    autosize, inverse, clear, zoom,
+                    &gedp->ged_result_str);
+
+    if (infd != 0)
+       close(infd);
+
+    sleep(pause_sec);
+
+    if (ret == BRLCAD_OK)
+       return GED_OK;
+
+    return GED_ERROR;
+}
+
+
+/*
+ * Local Variables:
+ * mode: C
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */


Property changes on: brlcad/trunk/src/libged/pix2fb.c
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:eol-style
   + native

Modified: brlcad/trunk/src/libtclcad/ged_obj.c
===================================================================
--- brlcad/trunk/src/libtclcad/ged_obj.c        2011-02-11 20:11:10 UTC (rev 
43236)
+++ brlcad/trunk/src/libtclcad/ged_obj.c        2011-02-11 20:23:38 UTC (rev 
43237)
@@ -762,6 +762,7 @@
     {"eye_pos",        "[x y z]", 5, go_view_func_plus, ged_eye_pos},
     {"faceplate",      "center_dot|prim_labels|view_params|view_scale 
color|draw [val(s)]", GO_UNLIMITED, go_faceplate, GED_FUNC_PTR_NULL},
     {"facetize",       (char *)0, GO_UNLIMITED, go_pass_through_func, 
ged_facetize},
+    {"fb2pix",         "[-h -i -c] [-s squaresize] [-w width] [-n height] 
[file.pix]", GO_UNLIMITED, go_view_func, ged_fb2pix},
     {"fontsize",       "[fontsize]", 3, go_fontsize, GED_FUNC_PTR_NULL},
     {"form",   (char *)0, GO_UNLIMITED, go_pass_through_func, ged_form},
     {"fracture",       (char *)0, GO_UNLIMITED, go_pass_through_func, 
ged_fracture},
@@ -856,6 +857,7 @@
     {"pathlist",       (char *)0, GO_UNLIMITED, go_pass_through_func, 
ged_pathlist},
     {"paths",  (char *)0, GO_UNLIMITED, go_pass_through_func, ged_pathsum},
     {"perspective",    "[angle]", 3, go_view_func_plus, ged_perspective},
+    {"pix2fb",         "[options] [file.pix]", GO_UNLIMITED, go_view_func, 
ged_pix2fb},
     {"plot",   "[options] file.pl", 16, go_view_func, ged_plot},
     {"pmat",   "[mat]", 3, go_view_func, ged_pmat},
     {"pmodel2view",    "vname", 2, go_view_func, ged_pmodel2view},
@@ -8460,6 +8462,7 @@
 
     /* Copy argv into av while skipping argv[1] (i.e. the view name) */
     gedp->ged_gvp = gdvp->gdv_view;
+    gedp->ged_fbsp = &gdvp->gdv_fbs;
     gedp->ged_refresh_clientdata = (void *)gdvp;
     av[0] = (char *)argv[0];
     ac = argc-1;

Modified: brlcad/trunk/src/tclscripts/lib/Ged.tcl
===================================================================
--- brlcad/trunk/src/tclscripts/lib/Ged.tcl     2011-02-11 20:11:10 UTC (rev 
43236)
+++ brlcad/trunk/src/tclscripts/lib/Ged.tcl     2011-02-11 20:23:38 UTC (rev 
43237)
@@ -183,6 +183,7 @@
        method eye_pos {args}
        method faceplate {args}
        method facetize {args}
+       method fb2pix {args}
        method fontsize {args}
        method form {args}
        method fracture {args}
@@ -284,6 +285,8 @@
        method pane_constrain_tmode {_pane args}
        method pane_eye {_pane args}
        method pane_eye_pos {_pane args}
+       method pane_fb2pix {_pane args}
+       method pane_fontsize {_pane args}
        method pane_get_eyemodel {_pane args}
        method pane_grid {_pane args}
        method pane_idle_mode {_pane args}
@@ -319,6 +322,7 @@
        method pane_otranslate_mode {_pane args}
        method pane_paint_rect_area {_pane args}
        method pane_perspective {_pane args}
+       method pane_pix2fb {_pane args}
        method pane_plot {_pane args}
        method pane_pmat {_pane args}
        method pane_pmodel2view {_pane args}
@@ -378,6 +382,7 @@
        method pathlist {args}
        method paths {args}
        method perspective {args}
+       method pix2fb {args}
        method plot {args}
        method pmat {args}
        method pmodel2view {args}
@@ -1259,6 +1264,10 @@
     eval $mGed facetize $args
 }
 
+::itcl::body cadwidgets::Ged::fb2pix {args} {
+    eval $mGed fb2pix $itk_component($itk_option(-pane)) $args
+}
+
 ::itcl::body cadwidgets::Ged::fontsize {args} {
     eval $mGed fontsize $itk_component($itk_option(-pane)) $args
 }
@@ -1671,6 +1680,14 @@
     eval $mGed eye_pos $itk_component($_pane) $args
 }
 
+::itcl::body cadwidgets::Ged::pane_fb2pix {_pane args} {
+    eval $mGed fb2pix $itk_component($_pane) $args
+}
+
+::itcl::body cadwidgets::Ged::pane_fontsize {_pane args} {
+    eval $mGed fontsize $itk_component($_pane) $args
+}
+
 ::itcl::body cadwidgets::Ged::pane_get_eyemodel {_pane args} {
     eval $mGed get_eyemodel $itk_component($_pane) $args
 }
@@ -1811,6 +1828,10 @@
     eval $mGed perspective $itk_component($_pane) $args
 }
 
+::itcl::body cadwidgets::Ged::pane_pix2fb {_pane args} {
+    eval $mGed pix2fb $itk_component($_pane) $args
+}
+
 ::itcl::body cadwidgets::Ged::pane_plot {_pane args} {
     eval $mGed plot $itk_component($_pane) $args
 }
@@ -2068,6 +2089,10 @@
     eval $mGed perspective $itk_component($itk_option(-pane)) $args
 }
 
+::itcl::body cadwidgets::Ged::pix2fb {args} {
+    eval $mGed pix2fb $itk_component($itk_option(-pane)) $args
+}
+
 ::itcl::body cadwidgets::Ged::plot {args} {
     eval $mGed plot $itk_component($itk_option(-pane)) $args
 }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to