Example #1
0
icv_image_t *
dpix_read(const char *filename, int width, int height)
{
    icv_image_t *bif;
    int fd;
    size_t size;
    ssize_t ret;

    if (width == 0 || height == 0) {
	bu_log("dpix_read : Using default size.\n");
	height = 512;
	width = 512;
    }

    if (filename == NULL)
	fd = fileno(stdin);
    else if ((fd = open(filename, O_RDONLY|O_BINARY, WRMODE)) <0) {
	bu_log("dpix_read : Cannot open file %s for reading\n, ", filename);
	return NULL;
    }

    bif = icv_create(width, height, ICV_COLOR_SPACE_RGB);

    /* Size in Bytes for reading. */
    size = width*height*3*sizeof(bif->data[0]);

    /* read dpix data */
    ret = read(fd, bif->data, size);

    if (ret != (ssize_t)size) {
	bu_log("dpix_read : Error while reading\n");
	icv_destroy(bif);
	return NULL;
    }

    icv_normalize(bif);

    return bif;
}
Example #2
0
int main(int argc, char* argv[])
{
    char *out_file = NULL;
    char *in_file = NULL;
    int inx=0, iny=0;
    icv_image_t *bif;
    ICV_IMAGE_FORMAT format=ICV_IMAGE_AUTO;
    int c;

    if (argc<2) {
	usage();
	return 1;
    }

    while ((c = bu_getopt(argc, argv, "s:o:w:nbpdmh?")) != -1) {
	switch (c) {
	    case 'o' :
		bu_log("out_file = %s\n", bu_optarg);
		out_file = bu_optarg;
		break;
	    case 's' :
	       inx = iny = atoi(bu_optarg);
	       break;
	    case 'w' :
	       inx = atoi(bu_optarg);
	       break;
	    case 'n' :
	       iny = atoi(bu_optarg);
	       break;
	    case 'b' :
		bu_log("There was in bw\n");
		format = ICV_IMAGE_BW;
		break;
	    case 'p' :
		format = ICV_IMAGE_PIX;
		break;
	    case 'd' :
		format = ICV_IMAGE_DPIX;
		break;
	    case 'm' :
		format = ICV_IMAGE_PPM;
		break;
	    case 'h':
	    default:
		usage();
		return 1;

	}

	bu_log("C= %c, optind = %d\n", c, bu_optind);
    }
    if (bu_optind >= argc) {
	if (isatty(fileno(stdin))) {
	    usage();
	    return 1;
	}
    }
    else {
	in_file = argv[bu_optind];
	bu_optind++;
    }

    bu_log("in_file = %s, out_file = %s\n", in_file, out_file);

    bif = icv_read(in_file, format, inx, iny);
    icv_write(bif,out_file, format);
    icv_destroy(bif);

    return 0;
}
Example #3
0
int main(int argc, char* argv[])
{
    char *out_file = NULL;
    char *in_file = NULL;
    int c;
    int inx=0, iny=0;
    int factor=2;
    icv_image_t *bif;
    ICV_IMAGE_FORMAT format=ICV_IMAGE_AUTO;
    ICV_RESIZE_METHOD method = ICV_RESIZE_SHRINK;
    size_t index;

    if (argc<2) {
        usage();
        return 1;
    }

    while ((c = bu_getopt(argc, argv, "s:w:n:M:f:o:bpdmh?")) != -1) {
        switch (c) {
        case 's':
            inx = iny = atoi(bu_optarg);
            break;
        case 'w':
            inx = atoi(bu_optarg);
            break;
        case 'n':
            iny = atoi(bu_optarg);
            break;
        case 'o':
            out_file = bu_optarg;
            break;
        case 'M':
            if (BU_STR_EQUAL(bu_optarg, "under_sample"))
                method = ICV_RESIZE_UNDERSAMPLE;
            else if (BU_STR_EQUAL(bu_optarg, "shrink"))
                method = ICV_RESIZE_SHRINK;
            else {
                usage();
                bu_exit(1, "Wrong Input Argument\n");
            }
            break;
        case 'f':
            factor = atoi(bu_optarg);
            break;
        case 'b':
            format = ICV_IMAGE_BW;
            break;
        case 'p':
            format = ICV_IMAGE_PIX;
            break;
        case 'd':
            format = ICV_IMAGE_DPIX;
            break;
        case 'm':
            format = ICV_IMAGE_PPM;
            break;
        case 'h':
        default:
            usage();
            return 1;

        }
    }
    if (bu_optind >= argc) {
        if (isatty(fileno(stdin))) {
            usage();
            return 1;
        }
    }
    else {
        in_file = argv[bu_optind];
        bu_optind++;
    }

    bif = icv_read(in_file, format, inx, iny);
    icv_resize(bif, method, 0, 0, (unsigned int) factor);
    bu_log("File information width %d height%d\n", bif->width, bif->height);

    for (index = 0; index < 65536; index++)
        bu_log("index = %ld, data = %f\n", index, bif->data[index]);


    icv_write(bif,out_file, format);
    bu_log("File information width %d height%d channels = %d\n", bif->width, bif->height, bif->channels);
    icv_destroy(bif);

    return 0;
}
Example #4
0
/* !!! FIXME: this command should not be directly utilizing LIBDM or
 * LIBFB as this breaks library encapsulation.  Generic functionality
 * should be moved out of LIBDM into LIBICV, or be handled by the
 * application logic calling this routine.
 */
int
ged_screen_grab(struct ged *gedp, int argc, const char *argv[])
{

    int i;
    int width = 0;
    int height = 0;
    int bytes_per_pixel = 0;
    int bytes_per_line = 0;
    static const char *usage = "image_name.ext";
    unsigned char **rows = NULL;
    unsigned char *idata = NULL;
    struct icv_image *bif = NULL;	/**< icv image container for saving images */

    if (gedp->ged_dmp_is_null) {
        bu_vls_printf(gedp->ged_result_str, "Bad display pointer.");
        return GED_ERROR;
    }

    if (gedp->ged_dm_get_display_image == NULL) {
        bu_vls_printf(gedp->ged_result_str, "Bad display function pointer.");
        return GED_ERROR;
    }

    GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR);
    GED_CHECK_VIEW(gedp, GED_ERROR);
    GED_CHECK_DRAWABLE(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 (argc != 2) {
        bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
        return GED_ERROR;
    }

    width = gedp->ged_dm_width;
    height = gedp->ged_dm_height;

    if (width <= 0 || height <= 0) {
        bu_vls_printf(gedp->ged_result_str, "%s: invalid screen dimensions.", argv[1]);
        return GED_ERROR;
    }

    bytes_per_pixel = 3;
    bytes_per_line = width * bytes_per_pixel;

    /* create image file */

    if ((bif = icv_create(width, height, ICV_COLOR_SPACE_RGB)) == NULL) {
        bu_vls_printf(gedp->ged_result_str, "%s: could not create icv_image write structure.", argv[1]);
        return GED_ERROR;
    }

    rows = (unsigned char **)bu_calloc(height, sizeof(unsigned char *), "rows");

    gedp->ged_dm_get_display_image(gedp, &idata);

    for (i = 0; i < height; ++i) {
        rows[i] = (unsigned char *)(idata + ((height-i-1)*bytes_per_line));
        /* TODO : Add double type data to maintain resolution */
        icv_writeline(bif, i, rows[i], ICV_DATA_UCHAR);
    }

    if (bif != NULL) {
        icv_write(bif, argv[1], ICV_IMAGE_AUTO);
        icv_destroy(bif);
        bif = NULL;
    }

    bu_free(rows, "rows");
    bu_free(idata, "image data");

    return GED_OK;
}
Example #5
0
int main(int argc, char* argv[])
{
    char *out_file = NULL;
    char *in_file = NULL;
    int c;
    int inx=0, iny=0;
    icv_image_t *bif;
    ICV_IMAGE_FORMAT format=ICV_IMAGE_AUTO;
    double multiplier=0.2;
    if (argc<2) {
	usage();
	return 1;
    }

    while ((c = bu_getopt(argc, argv, "s:w:n:o:%:f:bpdmh?")) != -1) {
	switch (c) {
	    case 's':
		inx = iny = atoi(bu_optarg);
		break;
	    case 'w':
		inx = atoi(bu_optarg);
		break;
	    case 'n':
		iny = atoi(bu_optarg);
		break;
	    case 'o':
		out_file = bu_optarg;
		break;
	    case '%':
		multiplier = atof(bu_optarg) / 100.0;
		if (multiplier < 0.0)
		    bu_exit (1, "tester_icv_fade : percent is negative");
		break;
	    case 'f':
		multiplier = atof(bu_optarg);
		if (multiplier < 0.0)
		    bu_exit(1,"tester_icv_fade : fraction is negative");
		break;
	    case 'b' :
		format = ICV_IMAGE_BW;
		break;
	    case 'p' :
		format = ICV_IMAGE_PIX;
		break;
	    case 'd' :
		format = ICV_IMAGE_DPIX;
		break;
	    case 'm' :
		format = ICV_IMAGE_PPM;
		break;
	    case 'h':
	    default:
		usage();
		return 1;

	}
    }
    if (bu_optind >= argc) {
	if (isatty(fileno(stdin))) {
	    usage();
	    return 1;
	}
    }
    else {
	in_file = argv[bu_optind];
	bu_optind++;
    }

    bif = icv_read(in_file, format, inx, iny);
    icv_fade(bif, multiplier);
    icv_write(bif,out_file, format);
    icv_destroy(bif);

    return 0;
}