Revision: 76018
http://sourceforge.net/p/brlcad/code/76018
Author: starseeker
Date: 2020-06-04 13:32:27 +0000 (Thu, 04 Jun 2020)
Log Message:
-----------
Add an option to cap the width and height read from the image - this allows the
extraction of arbitrary rectangular subsets from images.
Modified Paths:
--------------
brlcad/branches/dm-fb-merge/include/dm.h
brlcad/branches/dm-fb-merge/src/libdm/fb_generic.c
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 12:44:10 UTC (rev
76017)
+++ brlcad/branches/dm-fb-merge/include/dm.h 2020-06-04 13:32:27 UTC (rev
76018)
@@ -409,7 +409,7 @@
DM_EXPORT extern int fb_common_name_size(size_t *widthp, size_t *heightp,
const char *name);
DM_EXPORT extern int fb_write_fp(struct fb *ifp, FILE *fp, int req_width, int
req_height, int crunch, int inverse, struct bu_vls *result);
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 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 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 void fb_set_interface(struct fb *ifp, const char
*interface_type);
Modified: brlcad/branches/dm-fb-merge/src/libdm/fb_generic.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/fb_generic.c 2020-06-04 12:44:10 UTC
(rev 76017)
+++ brlcad/branches/dm-fb-merge/src/libdm/fb_generic.c 2020-06-04 13:32:27 UTC
(rev 76018)
@@ -638,8 +638,13 @@
int
-fb_read_icv(struct fb *ifp, icv_image_t *img, 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, struct bu_vls *result)
+fb_read_icv(struct fb *ifp, icv_image_t *img_in, int file_xoff_in, int
file_yoff_in, int file_maxwidth_in, int file_maxheight_in, int scr_xoff, int
scr_yoff, int clear, int zoom, int inverse, int one_line_only, int
multiple_lines, struct bu_vls *result)
{
+ /* Sanity */
+ if (!ifp || !img_in) {
+ return BRLCAD_ERROR;
+ }
+
int y;
int xout, yout, m, xstart;
unsigned char **scanline; /* 1 scanline pixel buffer */
@@ -648,6 +653,27 @@
int scr_width;
int scr_height;
+ /* Make a copy so we can edit if the options require */
+ icv_image_t *img = icv_create(img_in->width, img_in->height,
img_in->color_space);
+ memcpy(img->data, img_in->data, img_in->width * img_in->height *
img_in->channels * sizeof(double));
+
+ int file_xoff = file_xoff_in;
+ int file_yoff = file_yoff_in;
+ int file_maxwidth = file_maxwidth_in;
+ int file_maxheight = file_maxheight_in;
+
+ /* Crop the image, if the file_ variables indicate we need to */
+ if (file_xoff || file_yoff || file_maxwidth || file_maxheight) {
+ file_maxwidth = (file_maxwidth) ? file_maxwidth : (int)img->width -
file_xoff;
+ file_maxheight = (file_maxheight) ? file_maxheight : (int)img->height -
file_yoff;
+ icv_rect(img, file_xoff, file_yoff, file_maxwidth, file_maxheight);
+ // After resize, file offsets are zero. TODO - simplify below logic
+ // to eliminate references to these variables, they should no longer
+ // be needed...
+ file_xoff = 0;
+ file_yoff = 0;
+ }
+
unsigned char *data = icv_data2uchar(img);
/* create rows array */
scanline = (unsigned char **)bu_calloc(img->height, sizeof(unsigned char
*), "scanline");
@@ -671,9 +697,10 @@
if (xout < 0) {
bu_free(data, "unsigned char image data");
bu_free(scanline, "scanline");
+ icv_destroy(img);
return BRLCAD_OK;
}
- V_MIN(xout, (((int)img->width)-file_xoff));
+ V_MIN(xout, (int)img->width);
scanpix = xout; /* # pixels on scanline */
if (inverse)
@@ -683,9 +710,10 @@
if (yout < 0) {
bu_free(data, "unsigned char image data");
bu_free(scanline, "scanline");
+ icv_destroy(img);
return BRLCAD_OK;
}
- V_MIN(yout, (((int)img->height)-file_yoff));
+ V_MIN(yout, (int)img->height);
/* Only in the simplest case use multi-line writes */
if (!one_line_only && multiple_lines > 0 && !inverse && !zoom &&
@@ -762,6 +790,7 @@
bu_free(data, "unsigned char image data");
bu_free(scanline, "scanline");
+ icv_destroy(img);
return BRLCAD_OK;
}
Modified: brlcad/branches/dm-fb-merge/src/libged/icvfb.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/libged/icvfb.c 2020-06-04 12:44:10 UTC
(rev 76017)
+++ brlcad/branches/dm-fb-merge/src/libged/icvfb.c 2020-06-04 13:32:27 UTC
(rev 76018)
@@ -69,6 +69,8 @@
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;
@@ -83,11 +85,11 @@
bu_mime_image_t type = BU_MIME_IMAGE_UNKNOWN;
static char usage[] = "\
-Usage: icv2fb [-h -H -i -c -v -z -1] [-m #lines]\n\
- [-x file_xoff] [-y file_yoff] [-X scr_xoff] [-Y scr_yoff]\n\
- [-S squarescrsize] [--format fmt] [file.img]\n";
+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[17];
+ 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");
@@ -96,15 +98,17 @@
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], "X", "scr_xoff", "#", &bu_opt_int, &scr_xoff,
"X drawing offset in framebuffer");
- BU_OPT(d[9], "Y", "scr_yoff", "#", &bu_opt_int, &scr_yoff,
"Y drawing offset in framebuffer");
- BU_OPT(d[10], "w", "width", "#", &bu_opt_int, &width,
"image width");
- BU_OPT(d[11], "n", "height", "#", &bu_opt_int, &height,
"image height");
- BU_OPT(d[12], "S", "size", "#", &bu_opt_int, &square,
"image width/height (for square image)");
- BU_OPT(d[13], "", "format", "fmt", &image_mime, &type,
"image file format");
- BU_OPT(d[14], "1", "one-line-only", "", NULL, &one_line_only,
"Insist on 1-line writes");
- BU_OPT(d[15], "m", "multiple-lines", "#", &bu_opt_int,
&multiple_lines, "multple lines");
- BU_OPT_NULL(d[16]);
+ 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);
@@ -214,6 +218,7 @@
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,
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