Revision: 76021
http://sourceforge.net/p/brlcad/code/76021
Author: starseeker
Date: 2020-06-04 15:25:25 +0000 (Thu, 04 Jun 2020)
Log Message:
-----------
screengrab and overlay have the new icv logic - remove the icv2fb and fb2icv
commands. Restore png2fb for the moment to keep full compatibility for older
codes, but we should be well positioned to begin phasing out fb2pix, pix2fb and
png2fb in favor of more generic options. In the meantime screengrab and
overlay have new functionality.
Modified Paths:
--------------
brlcad/branches/dm-fb-merge/include/dm.h
brlcad/branches/dm-fb-merge/include/ged/framebuffer.h
brlcad/branches/dm-fb-merge/src/libdm/fb_generic.c
brlcad/branches/dm-fb-merge/src/libged/CMakeLists.txt
brlcad/branches/dm-fb-merge/src/libtclcad/tclcad_obj.c
brlcad/branches/dm-fb-merge/src/mged/setup.c
brlcad/branches/dm-fb-merge/src/tclscripts/lib/Ged.tcl
Added Paths:
-----------
brlcad/branches/dm-fb-merge/src/libged/png2fb.c
Removed Paths:
-------------
brlcad/branches/dm-fb-merge/src/libged/icvfb.c
Modified: brlcad/branches/dm-fb-merge/include/dm.h
===================================================================
--- brlcad/branches/dm-fb-merge/include/dm.h 2020-06-04 15:04:47 UTC (rev
76020)
+++ brlcad/branches/dm-fb-merge/include/dm.h 2020-06-04 15:25:25 UTC (rev
76021)
@@ -411,6 +411,7 @@
DM_EXPORT extern int fb_read_fd(struct fb *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);
DM_EXPORT extern int fb_read_icv(struct fb *ifp, icv_image_t *img, int
file_xoff, int file_yoff, int file_maxwidth, int file_maxheight, int scr_xoff,
int scr_yoff, int clear, int zoom, int inverse, int one_line_only, int
multiple_lines, struct bu_vls *result);
DM_EXPORT extern icv_image_t *fb_write_icv(struct fb *ifp, int scr_xoff, int
scr_yoff, int width, int height);
+DM_EXPORT extern int fb_read_png(struct fb *ifp, FILE *fp_in, int file_xoff,
int file_yoff, int scr_xoff, int scr_yoff, int clear, int zoom, int inverse,
int one_line_only, int multiple_lines, int verbose, int header_only, double
def_screen_gamma, struct bu_vls *result);
DM_EXPORT extern void fb_set_interface(struct fb *ifp, const char
*interface_type);
DM_EXPORT extern void fb_set_name(struct fb *ifp, const char *name);
Modified: brlcad/branches/dm-fb-merge/include/ged/framebuffer.h
===================================================================
--- brlcad/branches/dm-fb-merge/include/ged/framebuffer.h 2020-06-04
15:04:47 UTC (rev 76020)
+++ brlcad/branches/dm-fb-merge/include/ged/framebuffer.h 2020-06-04
15:25:25 UTC (rev 76021)
@@ -49,16 +49,11 @@
*/
GED_EXPORT extern int ged_pix2fb(struct ged *gedp, int argc, const char
*argv[]);
-#if 0
/**
* Png2fb reads a png file into a framebuffer.
*/
GED_EXPORT extern int ged_png2fb(struct ged *gedp, int argc, const char
*argv[]);
-#endif
-GED_EXPORT extern int ged_icv2fb(struct ged *gedp, int argc, const char
*argv[]);
-GED_EXPORT extern int ged_fb2icv(struct ged *gedp, int argc, const char
*argv[]);
-
__END_DECLS
#endif /* GED_FRAMEBUFFER_H */
Modified: brlcad/branches/dm-fb-merge/src/libdm/fb_generic.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/fb_generic.c 2020-06-04 15:04:47 UTC
(rev 76020)
+++ brlcad/branches/dm-fb-merge/src/libdm/fb_generic.c 2020-06-04 15:25:25 UTC
(rev 76021)
@@ -37,6 +37,7 @@
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
+#include "png.h"
#include "bsocket.h"
#include "bio.h"
@@ -757,7 +758,7 @@
scanline[file_yoff++]);
if (m != (int)img->width*height) {
bu_vls_printf(result,
- "png-fb: fb_writerect(x=%d, y=%d, w=%d, h=%d)
failure, ret=%d, s/b=%d\n",
+ "icv-fb: fb_writerect(x=%d, y=%d, w=%d, h=%d)
failure, ret=%d, s/b=%d\n",
scr_xoff, y,
(int)img->width, height, m, scanbytes);
}
@@ -769,7 +770,7 @@
m = fb_write(ifp, xstart, y, scanline[line--]+(3*file_xoff), xout);
if (m != xout) {
bu_vls_printf(result,
- "png-fb: fb_write(x=%d, y=%d, npix=%d) ret=%d,
s/b=%d\n",
+ "icv-fb: fb_write(x=%d, y=%d, npix=%d) ret=%d,
s/b=%d\n",
scr_xoff, y, xout,
m, xout);
}
@@ -781,7 +782,7 @@
m = fb_write(ifp, xstart, y, scanline[line--]+(3*file_xoff), xout);
if (m != xout) {
bu_vls_printf(result,
- "png-fb: fb_write(x=%d, y=%d, npix=%d) ret=%d,
s/b=%d\n",
+ "icv-fb: fb_write(x=%d, y=%d, npix=%d) ret=%d,
s/b=%d\n",
scr_xoff, y, xout,
m, xout);
}
@@ -808,6 +809,261 @@
return fbimg;
}
+static png_color_16 def_backgrd={ 0, 0, 0, 0, 0 };
+
+int
+fb_read_png(struct fb *ifp, FILE *fp_in, int file_xoff, int file_yoff, int
scr_xoff, int scr_yoff, int clear, int zoom, int inverse, int one_line_only,
int multiple_lines, int verbose, int header_only, double def_screen_gamma,
struct bu_vls *result)
+{
+ int y;
+ int i;
+ int xout, yout, m, xstart;
+ png_structp png_p;
+ png_infop info_p;
+ char header[8];
+ int bit_depth;
+ int color_type;
+ png_color_16p input_backgrd;
+ double gammaval=1.0;
+ int file_width, file_height;
+ unsigned char *image;
+ unsigned char **scanline; /* 1 scanline pixel buffer */
+ int scanbytes; /* # of bytes of scanline */
+ int scanpix; /* # of pixels of scanline */
+ int scr_width;
+ int scr_height;
+
+ if (fread(header, 8, 1, fp_in) != 1) {
+ bu_vls_printf(result, "png-fb: ERROR: Failed while reading file
header!!!\n");
+ return BRLCAD_ERROR;
+ }
+
+ if (png_sig_cmp((png_bytep)header, 0, 8)) {
+ bu_vls_printf(result, "png-fb: This is not a PNG file!!!\n");
+ return BRLCAD_ERROR;
+ }
+
+ png_p = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+ if (!png_p) {
+ bu_vls_printf(result, "png-fb: png_create_read_struct() failed!!\n");
+ return BRLCAD_ERROR;
+ }
+
+ info_p = png_create_info_struct(png_p);
+ if (!info_p) {
+ bu_vls_printf(result, "png-fb: png_create_info_struct() failed!!\n");
+ return BRLCAD_ERROR;
+ }
+
+ png_init_io(png_p, fp_in);
+
+ png_set_sig_bytes(png_p, 8);
+
+ png_read_info(png_p, info_p);
+
+ color_type = png_get_color_type(png_p, info_p);
+
+ png_set_expand(png_p);
+ bit_depth = png_get_bit_depth(png_p, info_p);
+ if (bit_depth == 16)
+ png_set_strip_16(png_p);
+
+ if (color_type == PNG_COLOR_TYPE_GRAY ||
+ color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+ png_set_gray_to_rgb(png_p);
+
+ file_width = png_get_image_width(png_p, info_p);
+ file_height = png_get_image_height(png_p, info_p);
+
+ if (verbose) {
+ switch (color_type) {
+ case PNG_COLOR_TYPE_GRAY:
+ bu_vls_printf(result, "color type: b/w (bit depth=%d)\n",
bit_depth);
+ break;
+ case PNG_COLOR_TYPE_GRAY_ALPHA:
+ bu_vls_printf(result, "color type: b/w with alpha channel (bit
depth=%d)\n", bit_depth);
+ break;
+ case PNG_COLOR_TYPE_PALETTE:
+ bu_vls_printf(result, "color type: color palette (bit
depth=%d)\n", bit_depth);
+ break;
+ case PNG_COLOR_TYPE_RGB:
+ bu_vls_printf(result, "color type: RGB (bit depth=%d)\n",
bit_depth);
+ break;
+ case PNG_COLOR_TYPE_RGB_ALPHA:
+ bu_vls_printf(result, "color type: RGB with alpha channel (bit
depth=%d)\n", bit_depth);
+ break;
+ default:
+ bu_vls_printf(result, "Unrecognized color type (bit
depth=%d)\n", bit_depth);
+ break;
+ }
+ bu_vls_printf(result, "Image size: %d X %d\n", file_width, file_height);
+ }
+
+ if (header_only) {
+ bu_vls_printf(result, "WIDTH=%d HEIGHT=%d\n", file_width, file_height);
+ return BRLCAD_OK;
+ }
+
+ if (png_get_bKGD(png_p, info_p, &input_backgrd)) {
+ if (verbose && (color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
+ color_type == PNG_COLOR_TYPE_RGB_ALPHA))
+ bu_vls_printf(result, "background color: %d %d %d\n",
input_backgrd->red, input_backgrd->green, input_backgrd->blue);
+ png_set_background(png_p, input_backgrd, PNG_BACKGROUND_GAMMA_FILE, 1,
1.0);
+ } else
+ png_set_background(png_p, &def_backgrd, PNG_BACKGROUND_GAMMA_FILE, 0,
1.0);
+
+ if (!png_get_gAMA(png_p, info_p, &gammaval))
+ gammaval = 0.5;
+ png_set_gamma(png_p, def_screen_gamma, gammaval);
+ if (verbose)
+ bu_vls_printf(result, "file gamma: %f, additional screen gamma: %f\n",
+ gammaval, def_screen_gamma);
+
+ if (verbose) {
+ if (png_get_interlace_type(png_p, info_p) == PNG_INTERLACE_NONE)
+ bu_vls_printf(result, "not interlaced\n");
+ else
+ bu_vls_printf(result, "interlaced\n");
+ }
+
+ png_read_update_info(png_p, info_p);
+
+ /* allocate memory for image */
+ image = (unsigned char *)bu_calloc(1, file_width*file_height*3, "image");
+
+ /* create rows array */
+ scanline = (unsigned char **)bu_calloc(file_height, sizeof(unsigned char
*), "scanline");
+ for (i=0; i<file_height; i++)
+ scanline[i] = image+(i*file_width*3);
+
+ png_read_image(png_p, scanline);
+
+ if (verbose) {
+ png_timep mod_time;
+ png_textp text;
+ int num_text;
+
+ png_read_end(png_p, info_p);
+ if (png_get_text(png_p, info_p, &text, &num_text)) {
+ for (i=0; i<num_text; i++)
+ bu_vls_printf(result, "%s: %s\n", text[i].key, text[i].text);
+ }
+ if (png_get_tIME(png_p, info_p, &mod_time))
+ bu_vls_printf(result, "Last modified: %d/%d/%d %d:%d:%d\n",
mod_time->month, mod_time->day,
+ mod_time->year, mod_time->hour, mod_time->minute,
mod_time->second);
+ }
+
+ /* 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;
+ xstart = 0;
+ } else {
+ xout = scr_width - scr_xoff;
+ xstart = scr_xoff;
+ }
+
+ if (xout < 0) {
+ bu_free(image, "image");
+ bu_free(scanline, "scanline");
+ return BRLCAD_OK;
+ }
+ V_MIN(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_free(image, "image");
+ bu_free(scanline, "scanline");
+ return BRLCAD_OK;
+ }
+ V_MIN(yout, (file_height-file_yoff));
+
+ /* Only in the simplest case use multi-line writes */
+ if (!one_line_only && multiple_lines > 0 && !inverse && !zoom &&
+ xout == file_width && file_xoff == 0 &&
+ file_width <= scr_width) {
+ scanpix *= multiple_lines;
+ }
+
+ scanbytes = scanpix * sizeof(RGBpixel);
+
+ if (clear) {
+ fb_clear(ifp, PIXEL_NULL);
+ }
+ if (zoom) {
+ /* Zoom in, and center the display. Use square zoom. */
+ int newzoom;
+ newzoom = scr_width/xout;
+ V_MIN(newzoom, scr_height/yout);
+
+ if (inverse) {
+ fb_view(ifp,
+ scr_xoff+xout/2, scr_height-1-(scr_yoff+yout/2),
+ newzoom, newzoom);
+ } else {
+ fb_view(ifp,
+ scr_xoff+xout/2, scr_yoff+yout/2,
+ newzoom, newzoom);
+ }
+ }
+
+ if (multiple_lines) {
+ /* Bottom to top with multi-line reads & writes */
+ int height=file_height;
+ for (y = scr_yoff; y < scr_yoff + yout; y += multiple_lines) {
+ /* Don't over-write */
+ if (y + height > scr_yoff + yout)
+ height = scr_yoff + yout - y;
+ if (height <= 0) break;
+ m = fb_writerect(ifp, scr_xoff, y,
+ file_width, height,
+ scanline[file_yoff++]);
+ if (m != file_width*height) {
+ bu_vls_printf(result,
+ "png-fb: fb_writerect(x=%d, y=%d, w=%d, h=%d)
failure, ret=%d, s/b=%d\n",
+ scr_xoff, y,
+ file_width, height, m, scanbytes);
+ }
+ }
+ } else if (!inverse) {
+ /* Normal way -- bottom to top */
+ int line=file_height-file_yoff-1;
+ for (y = scr_yoff; y < scr_yoff + yout; y++) {
+ m = fb_write(ifp, xstart, y, scanline[line--]+(3*file_xoff), xout);
+ if (m != xout) {
+ bu_vls_printf(result,
+ "png-fb: fb_write(x=%d, y=%d, npix=%d) ret=%d,
s/b=%d\n",
+ scr_xoff, y, xout,
+ m, xout);
+ }
+ }
+ } else {
+ /* Inverse -- top to bottom */
+ int line=file_height-file_yoff-1;
+ for (y = scr_height-1-scr_yoff; y >= scr_height-scr_yoff-yout; y--) {
+ m = fb_write(ifp, xstart, y, scanline[line--]+(3*file_xoff), xout);
+ if (m != xout) {
+ bu_vls_printf(result,
+ "png-fb: fb_write(x=%d, y=%d, npix=%d) ret=%d,
s/b=%d\n",
+ scr_xoff, y, xout,
+ m, xout);
+ }
+ }
+ }
+
+ bu_free(image, "image");
+ bu_free(scanline, "scanline");
+ return BRLCAD_OK;
+}
+
+
+
/*
* Local Variables:
* mode: C
Modified: brlcad/branches/dm-fb-merge/src/libged/CMakeLists.txt
===================================================================
--- brlcad/branches/dm-fb-merge/src/libged/CMakeLists.txt 2020-06-04
15:04:47 UTC (rev 76020)
+++ brlcad/branches/dm-fb-merge/src/libged/CMakeLists.txt 2020-06-04
15:25:25 UTC (rev 76021)
@@ -178,7 +178,6 @@
hide.c
how.c
human.c
- icvfb.c
illum.c
importFg4Section.c
inside.c
@@ -245,6 +244,7 @@
pmat.c
pmodel2view.c
png.c
+ png2fb.c
pnts_util.c
pnts.cpp
polyclip.cpp
Deleted: brlcad/branches/dm-fb-merge/src/libged/icvfb.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/libged/icvfb.c 2020-06-04 15:04:47 UTC
(rev 76020)
+++ brlcad/branches/dm-fb-merge/src/libged/icvfb.c 2020-06-04 15:25:25 UTC
(rev 76021)
@@ -1,359 +0,0 @@
-/* I C V F B . C
- * BRL-CAD
- *
- * Copyright (c) 1998-2020 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 icvfb.c
- *
- * Logic for sending image data to/from framebuffers.
- *
- */
-
-#include "common.h"
-
-#include <stdlib.h>
-#include <sys/stat.h>
-
-#include "bu/mime.h"
-#include "bu/opt.h"
-#include "bu/path.h"
-#include "dm.h"
-#include "icv.h"
-#include "ged.h"
-#include "./ged_private.h"
-
-static int
-image_mime(struct bu_vls *msg, size_t argc, const char **argv, void *set_mime)
-{
- int type_int;
- bu_mime_image_t type = BU_MIME_IMAGE_UNKNOWN;
- bu_mime_image_t *set_type = (bu_mime_image_t *)set_mime;
-
- BU_OPT_CHECK_ARGV0(msg, argc, argv, "mime format");
-
- type_int = bu_file_mime(argv[0], BU_MIME_IMAGE);
- type = (type_int < 0) ? BU_MIME_IMAGE_UNKNOWN : (bu_mime_image_t)type_int;
- if (type == BU_MIME_IMAGE_UNKNOWN) {
- if (msg) bu_vls_sprintf(msg, "Error - unknown geometry file type: %s
\n", argv[0]);
- return -1;
- }
- if (set_type) (*set_type) = type;
- return 1;
-}
-
-
-int
-ged_icv2fb(struct ged *gedp, int argc, const char *argv[])
-{
- int ret = GED_OK;
-
- int multiple_lines = 0; /* Streamlined operation */
-
- const char *file_name;
-
- int print_help = 0;
- int file_xoff = 0;
- int file_yoff = 0;
- int file_maxwidth = 0;
- int file_maxheight = 0;
- int scr_xoff=0;
- int scr_yoff=0;
- int clear = 0;
- int zoom = 0;
- int inverse = 0; /* Draw upside-down */
- int one_line_only = 0; /* insist on 1-line writes */
- int verbose = 0;
- int header_only = 0;
- int width = 0; /* may need to specify for some formats (such as PIX) */
- int height = 0; /* may need to specify for some formats (such as PIX) */
- int square = 0; /* may need to specify for some formats (such as PIX) */
- bu_mime_image_t type = BU_MIME_IMAGE_UNKNOWN;
-
- static char usage[] = "\
-Usage: icv2fb [-h -H -i -c -v -z -1] [-m #lines] [-X scr_xoff] [-Y scr_yoff]\n\
- [-x file_xoff] [-y file_yoff] [-W file_maxwidth] [-N file_maxheight]\n\
- [-w image_width] [-n image_height] [-S squarescrsize] [--format fmt]
[file.img]\n";
-
- struct bu_opt_desc d[19];
- BU_OPT(d[0], "h", "help", "", NULL, &print_help,
"Print help and exit");
- BU_OPT(d[1], "H", "header-only", "", NULL, &header_only,
"Print image size information");
- BU_OPT(d[2], "i", "inverse", "", NULL, &inverse,
"Draw upside-down");
- BU_OPT(d[3], "c", "clear", "", NULL, &clear,
"Clear framebuffer before drawing");
- BU_OPT(d[4], "v", "verbose", "", NULL, &verbose,
"Verbose reporting");
- BU_OPT(d[5], "z", "zoom", "", NULL, &zoom,
"Zoom image to fill screen");
- BU_OPT(d[6], "x", "file_xoff", "#", &bu_opt_int, &file_xoff,
"X offset reading from file");
- BU_OPT(d[7], "y", "file_yoff", "#", &bu_opt_int, &file_yoff,
"Y offset reading from file");
- BU_OPT(d[8], "W", "file_maxwidth", "#", &bu_opt_int, &file_maxwidth,
"Maximum image width to read");
- BU_OPT(d[9], "N", "file_maxheight", "#", &bu_opt_int,
&file_maxheight, "Maximum image height to read");
- BU_OPT(d[10], "X", "scr_xoff", "#", &bu_opt_int, &scr_xoff,
"X drawing offset in framebuffer");
- BU_OPT(d[11], "Y", "scr_yoff", "#", &bu_opt_int, &scr_yoff,
"Y drawing offset in framebuffer");
- BU_OPT(d[12], "w", "width", "#", &bu_opt_int, &width,
"image width");
- BU_OPT(d[13], "n", "height", "#", &bu_opt_int, &height,
"image height");
- BU_OPT(d[14], "S", "size", "#", &bu_opt_int, &square,
"image width/height (for square image)");
- BU_OPT(d[15], "", "format", "fmt", &image_mime, &type,
"image file format");
- BU_OPT(d[16], "1", "one-line-only", "", NULL, &one_line_only,
"Insist on 1-line writes");
- BU_OPT(d[17], "m", "multiple-lines", "#", &bu_opt_int,
&multiple_lines, "multple lines");
- BU_OPT_NULL(d[18]);
-
- GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR);
- GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
-
- if (!gedp->ged_dmp) {
- bu_vls_printf(gedp->ged_result_str, ": no display manager currently
active");
- return GED_ERROR;
- }
-
- struct dm *dmp = (struct dm *)gedp->ged_dmp;
- struct fb *fbp = dm_get_fb(dmp);
-
- if (!fbp) {
- bu_vls_printf(gedp->ged_result_str, ": display manager does not have a
framebuffer");
- return GED_ERROR;
- }
-
- /* initialize result */
- bu_vls_trunc(gedp->ged_result_str, 0);
-
- /* must be wanting help */
- if (argc == 1) {
- _ged_cmd_help(gedp, usage, d);
- return GED_HELP;
- }
-
- argc-=(argc>0); argv+=(argc>0); /* done with command name argv[0] */
-
- int opt_ret = bu_opt_parse(NULL, argc, argv, d);
-
- if (print_help) {
- _ged_cmd_help(gedp, usage, d);
- return GED_HELP;
- }
-
- argc = opt_ret;
-
- if (!argc) {
- if (isatty(fileno(stdin))) {
- bu_vls_printf(gedp->ged_result_str, ": no file specified, expected
valid stdin");
- return GED_ERROR;
- }
- if (type == BU_MIME_IMAGE_UNKNOWN) {
- bu_vls_printf(gedp->ged_result_str, ": reading from stdin, but no
format specified");
- return GED_ERROR;
- }
- file_name = NULL;
- } else {
-
- if (argc > 1) {
- bu_log("icvfb: Warning: excess argument(s) ignored\n");
- }
- file_name = argv[0];
-
- /* Find out what input file type we are dealing with */
- if (type == BU_MIME_IMAGE_UNKNOWN) {
- struct bu_vls c = BU_VLS_INIT_ZERO;
- if (bu_path_component(&c, file_name, BU_PATH_EXT)) {
- int itype = bu_file_mime(bu_vls_cstr(&c), BU_MIME_IMAGE);
- type = (bu_mime_image_t)itype;
- } else {
- bu_vls_printf(gedp->ged_result_str, "no input file image type
specified - need either a specified input image type or a path that provides
MIME information.\n");
- bu_vls_free(&c);
- return GED_ERROR;
- }
- bu_vls_free(&c);
- }
-
- // If we're square, let width and height know
- if (square && !width && !height) {
- width = square;
- height = square;
- }
-
- /* If we have no width or height specified, and we have an input format
that
- * does not encode that information, make an educated guess */
- if (!width && !height && (type == BU_MIME_IMAGE_PIX || type ==
BU_MIME_IMAGE_BW)) {
- struct stat sbuf;
- if (stat(file_name, &sbuf) < 0) {
- bu_vls_printf(gedp->ged_result_str, "unable to stat input
file");
- return GED_ERROR;
- }
- unsigned long lwidth, lheight;
- if (!icv_image_size(NULL, 0, (size_t)sbuf.st_size, type, &lwidth,
&lheight)) {
- bu_vls_printf(gedp->ged_result_str, "input image type does not
have dimension information encoded, and libicv was not able to deduce a size.
Please specify image width in pixels with the \"-w\" option and image height in
pixels with the \"-n\" option.\n");
- return GED_ERROR;
- } else {
- width = (int)lwidth;
- height = (int)lheight;
- }
- }
- }
-
- icv_image_t *img = icv_read(file_name, type, width, height);
-
- if (!img) {
- if (!argc) {
- bu_vls_printf(gedp->ged_result_str, "icv_read failed to read from
stdin.\n");
- } else {
- bu_vls_printf(gedp->ged_result_str, "icv_read failed to read
%s.\n", file_name);
- }
- icv_destroy(img);
- return GED_ERROR;
- }
-
- if (!header_only) {
-
- ret = fb_read_icv(fbp, img,
- file_xoff, file_yoff,
- file_maxwidth, file_maxheight,
- scr_xoff, scr_yoff,
- clear, zoom, inverse,
- one_line_only, multiple_lines,
- gedp->ged_result_str);
-
- (void)dm_draw_begin(dmp);
- fb_refresh(fbp, 0, 0, fb_getwidth(fbp), fb_getheight(fbp));
- (void)dm_draw_end(dmp);
-
- } else {
- bu_vls_printf(gedp->ged_result_str, "WIDTH=%zd HEIGHT=%zd\n",
img->width, img->height);
- }
-
- icv_destroy(img);
- return ret;
-}
-
-int
-ged_fb2icv(struct ged *gedp, int argc, const char *argv[])
-{
- int ret = GED_OK;
-
- const char *file_name;
-
- int print_help = 0;
- int scr_xoff=0;
- int scr_yoff=0;
- int width = 0;
- int height = 0;
- bu_mime_image_t type = BU_MIME_IMAGE_UNKNOWN;
-
- static char usage[] = "Usage: fb2icv [-h] [-X scr_xoff] [-Y scr_yoff]
[--format fmt] [file.img]\n";
-
- struct bu_opt_desc d[7];
- BU_OPT(d[0], "h", "help", "", NULL, &print_help,
"Print help and exit");
- BU_OPT(d[1], "X", "scr_xoff", "#", &bu_opt_int, &scr_xoff,
"X offset in framebuffer");
- BU_OPT(d[2], "Y", "scr_yoff", "#", &bu_opt_int, &scr_yoff,
"Y offset in framebuffer");
- BU_OPT(d[3], "w", "width", "#", &bu_opt_int, &width,
"image width");
- BU_OPT(d[4], "n", "height", "#", &bu_opt_int, &height,
"image height");
- BU_OPT(d[5], "", "format", "fmt", &image_mime, &type,
"image file format");
- BU_OPT_NULL(d[6]);
-
- if (!gedp->ged_dmp) {
- bu_vls_printf(gedp->ged_result_str, ": no display manager currently
active");
- return GED_ERROR;
- }
-
- struct dm *dmp = (struct dm *)gedp->ged_dmp;
- struct fb *fbp = dm_get_fb(dmp);
-
- if (!fbp) {
- bu_vls_printf(gedp->ged_result_str, ": display manager does not have a
framebuffer");
- return GED_ERROR;
- }
-
- /* initialize result */
- bu_vls_trunc(gedp->ged_result_str, 0);
-
- /* must be wanting help */
- if (argc == 1) {
- _ged_cmd_help(gedp, usage, d);
- return GED_HELP;
- }
-
- argc-=(argc>0); argv+=(argc>0); /* done with command name argv[0] */
-
- int opt_ret = bu_opt_parse(NULL, argc, argv, d);
-
- if (print_help) {
- _ged_cmd_help(gedp, usage, d);
- return GED_HELP;
- }
-
- argc = opt_ret;
-
- if (!argc) {
- if (isatty(fileno(stdout))) {
- bu_vls_printf(gedp->ged_result_str, ": no file specified, expected
valid stdout");
- return GED_ERROR;
- }
- if (type == BU_MIME_IMAGE_UNKNOWN) {
- type = BU_MIME_IMAGE_PIX;
- }
- file_name = NULL;
- } else {
-
- if (argc > 1) {
- bu_log("icvfb: Warning: excess argument(s) ignored\n");
- }
- file_name = argv[0];
-
- /* Find out what input file type we are dealing with */
- if (type == BU_MIME_IMAGE_UNKNOWN) {
- struct bu_vls c = BU_VLS_INIT_ZERO;
- if (bu_path_component(&c, file_name, BU_PATH_EXT)) {
- int itype = bu_file_mime(bu_vls_cstr(&c), BU_MIME_IMAGE);
- type = (bu_mime_image_t)itype;
- } else {
- bu_vls_printf(gedp->ged_result_str, "no input file image type
specified - need either a specified input image type or a path that provides
MIME information.\n");
- bu_vls_free(&c);
- return GED_ERROR;
- }
- bu_vls_free(&c);
- }
- }
-
- /* If we don't have a specified width/height, get them from the
framebuffer */
- if (!width) {
- width = fb_getwidth(fbp);
- }
- if (!height) {
- height = fb_getheight(fbp);
- }
-
- icv_image_t *img = fb_write_icv(fbp, scr_xoff, scr_yoff, width, height);
-
- if (!img) {
- bu_vls_printf(gedp->ged_result_str, "failed to generate icv image from
framebuffer.\n");
- return GED_ERROR;
- }
-
- icv_write(img, file_name, type);
- icv_destroy(img);
-
- return ret;
-}
-
-
-
-/*
- * Local Variables:
- * mode: C
- * tab-width: 8
- * indent-tabs-mode: t
- * c-file-style: "stroustrup"
- * End:
- * ex: shiftwidth=4 tabstop=8
- */
Added: brlcad/branches/dm-fb-merge/src/libged/png2fb.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/libged/png2fb.c
(rev 0)
+++ brlcad/branches/dm-fb-merge/src/libged/png2fb.c 2020-06-04 15:25:25 UTC
(rev 76021)
@@ -0,0 +1,200 @@
+/* P N G - F B . C
+ * BRL-CAD
+ *
+ * Copyright (c) 1998-2020 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 png-fb.c
+ *
+ * Program to take PNG (Portable Network Graphics) files and send them to a
framebuffer.
+ *
+ */
+
+#include "common.h"
+
+#include <stdlib.h>
+
+#include "bio.h"
+#include "bu/getopt.h"
+#include "dm.h"
+#include "ged.h"
+
+static int multiple_lines = 0; /* Streamlined operation */
+
+static char *file_name;
+static FILE *fp_in;
+
+static int file_xoff=0, file_yoff=0;
+static int scr_xoff=0, scr_yoff=0;
+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 verbose = 0;
+static int header_only = 0;
+
+static double def_screen_gamma=1.0; /* Don't add more gamma, by default */
+/* Particularly because on SGI, the system provides gamma correction,
+ * so programs like this one don't have to.
+ */
+
+static char usage[] = "\
+Usage: png2fb [-H -i -c -v -z -1] [-m #lines]\n\
+ [-g screen_gamma]\n\
+ [-x file_xoff] [-y file_yoff] [-X scr_xoff] [-Y scr_yoff]\n\
+ [-S squarescrsize] [file.png]\n";
+
+static int
+get_args(int argc, char **argv)
+{
+ int c;
+
+ bu_optind = 1;
+ while ((c = bu_getopt(argc, argv, "1m:g:HicvzF:x:y:X:Y:S:W:N:h?")) != -1) {
+ switch (c) {
+ case '1':
+ one_line_only = 1;
+ break;
+ case 'm':
+ multiple_lines = atoi(bu_optarg);
+ break;
+ case 'g':
+ def_screen_gamma = atof(bu_optarg);
+ break;
+ case 'H':
+ header_only = 1;
+ break;
+ case 'i':
+ inverse = 1;
+ break;
+ case 'c':
+ clear = 1;
+ break;
+ case 'v':
+ verbose = 1;
+ break;
+ case 'z':
+ zoom = 1;
+ 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;
+ default: /* '?''h' */
+ return 0;
+ }
+ }
+
+ if (bu_optind >= argc) {
+ if (isatty(fileno(stdin)))
+ return 0;
+ file_name = "-";
+ fp_in = stdin;
+ setmode(fileno(fp_in), O_BINARY);
+ } else {
+ file_name = argv[bu_optind];
+ if ((fp_in = fopen(file_name, "rb")) == NULL) {
+ perror(file_name);
+ fprintf(stderr,
+ "png-fb: cannot open \"%s\" for reading\n",
+ file_name);
+ return 0;
+ }
+ }
+
+ if (argc > ++bu_optind)
+ fprintf(stderr, "png-fb: excess argument(s) ignored\n");
+
+ return 1; /* OK */
+}
+
+
+int
+ged_png2fb(struct ged *gedp, int argc, const char *argv[])
+{
+ int ret;
+
+ GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR);
+ GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);
+
+ if (!gedp->ged_dmp) {
+ bu_vls_printf(gedp->ged_result_str, "no display manager currently
active");
+ return GED_ERROR;
+ }
+
+ struct dm *dmp = (struct dm *)gedp->ged_dmp;
+ struct fb *fbp = dm_get_fb(dmp);
+
+ if (!fbp) {
+ bu_vls_printf(gedp->ged_result_str, "display manager does not have a
framebuffer");
+ return 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_png(fbp, fp_in,
+ file_xoff, file_yoff,
+ scr_xoff, scr_yoff,
+ clear, zoom, inverse,
+ one_line_only, multiple_lines,
+ verbose, header_only,
+ def_screen_gamma,
+ gedp->ged_result_str);
+
+ if (fp_in != stdin)
+ fclose(fp_in);
+
+ (void)dm_draw_begin(dmp);
+ fb_refresh(fbp, 0, 0, fb_getwidth(fbp), fb_getheight(fbp));
+ (void)dm_draw_end(dmp);
+
+ 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/branches/dm-fb-merge/src/libged/png2fb.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: brlcad/branches/dm-fb-merge/src/libtclcad/tclcad_obj.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/libtclcad/tclcad_obj.c 2020-06-04
15:04:47 UTC (rev 76020)
+++ brlcad/branches/dm-fb-merge/src/libtclcad/tclcad_obj.c 2020-06-04
15:25:25 UTC (rev 76021)
@@ -1322,7 +1322,7 @@
{"pix", "file", TO_UNLIMITED, to_pix, GED_FUNC_PTR_NULL},
{"png", "file", TO_UNLIMITED, to_png, GED_FUNC_PTR_NULL},
#endif
- {"icv2fb", "[options] [file.png]", TO_UNLIMITED, to_view_func,
ged_icv2fb},
+ {"png2fb", "[options] [file.png]", TO_UNLIMITED, to_view_func,
ged_png2fb},
{"pngwf", "[options] file.png", 16, to_view_func, ged_png},
{"poly_circ_mode", "x y", TO_UNLIMITED, to_poly_circ_mode,
GED_FUNC_PTR_NULL},
{"poly_cont_build", "x y", TO_UNLIMITED, to_poly_cont_build,
GED_FUNC_PTR_NULL},
Modified: brlcad/branches/dm-fb-merge/src/mged/setup.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/mged/setup.c 2020-06-04 15:04:47 UTC
(rev 76020)
+++ brlcad/branches/dm-fb-merge/src/mged/setup.c 2020-06-04 15:25:25 UTC
(rev 76021)
@@ -154,8 +154,6 @@
{"exists", cmd_ged_plain_wrapper, ged_exists},
{"facedef", f_facedef, GED_FUNC_PTR_NULL},
{"facetize", cmd_ged_plain_wrapper, ged_facetize},
- {"fb2pix", cmd_ged_dm_wrapper, ged_fb2pix},
- {"fbclear", cmd_ged_dm_wrapper, ged_fbclear},
{"form", cmd_ged_plain_wrapper, ged_form},
{"fracture", cmd_ged_plain_wrapper, ged_fracture},
{"front", f_bv_front, GED_FUNC_PTR_NULL},
@@ -180,8 +178,6 @@
{"hist", cmd_hist, GED_FUNC_PTR_NULL},
{"history", f_history, GED_FUNC_PTR_NULL},
{"i", cmd_ged_plain_wrapper, ged_instance},
- {"icv2fb", cmd_ged_dm_wrapper, ged_icv2fb},
- {"fb2icv", cmd_ged_dm_wrapper, ged_fb2icv},
{"idents", cmd_ged_plain_wrapper, ged_tables},
{"ill", f_ill, GED_FUNC_PTR_NULL},
{"in", cmd_ged_in, ged_in},
@@ -261,10 +257,8 @@
{"pathlist", cmd_ged_plain_wrapper, ged_pathlist},
{"paths", cmd_ged_plain_wrapper, ged_pathsum},
{"permute", f_permute, GED_FUNC_PTR_NULL},
- {"pix2fb", cmd_ged_dm_wrapper, ged_pix2fb},
{"plot", cmd_ged_plain_wrapper, ged_plot},
{"png", cmd_ged_plain_wrapper, ged_png},
- {"icv2fb", cmd_ged_dm_wrapper, ged_icv2fb},
{"pnts", cmd_ged_plain_wrapper, ged_pnts},
{"prcolor", cmd_ged_plain_wrapper, ged_prcolor},
{"prefix", cmd_ged_plain_wrapper, ged_prefix},
Modified: brlcad/branches/dm-fb-merge/src/tclscripts/lib/Ged.tcl
===================================================================
--- brlcad/branches/dm-fb-merge/src/tclscripts/lib/Ged.tcl 2020-06-04
15:04:47 UTC (rev 76020)
+++ brlcad/branches/dm-fb-merge/src/tclscripts/lib/Ged.tcl 2020-06-04
15:25:25 UTC (rev 76021)
@@ -473,7 +473,7 @@
method pane_paint_rect_area {_pane args}
method pane_perspective {_pane args}
method pane_pix2fb {_pane args}
- method pane_icv2fb {_pane args}
+ method pane_png2fb {_pane args}
method pane_plot {_pane args}
method pane_pmat {_pane args}
method pane_pmodel2view {_pane args}
@@ -537,7 +537,7 @@
method perspective_all {args}
method pix {args}
method pix2fb {args}
- method icv2fb {args}
+ method png2fb {args}
method plot {args}
method pmat {args}
method pmodel2view {args}
@@ -3110,8 +3110,8 @@
eval $mGed pix2fb $itk_component($_pane) $args
}
-::itcl::body cadwidgets::Ged::pane_icv2fb {_pane args} {
- eval $mGed icv2fb $itk_component($_pane) $args
+::itcl::body cadwidgets::Ged::pane_png2fb {_pane args} {
+ eval $mGed png2fb $itk_component($_pane) $args
}
::itcl::body cadwidgets::Ged::pane_plot {_pane args} {
@@ -3381,8 +3381,8 @@
eval $mGed pix2fb $itk_component($itk_option(-pane)) $args
}
-::itcl::body cadwidgets::Ged::icv2fb {args} {
- eval $mGed icv2fb $itk_component($itk_option(-pane)) $args
+::itcl::body cadwidgets::Ged::png2fb {args} {
+ eval $mGed png2fb $itk_component($itk_option(-pane)) $args
}
::itcl::body cadwidgets::Ged::plot {args} {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits