diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2018-12-29 16:32:28 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2018-12-29 16:32:28 +0000 |
commit | ee250e7490cbb3550fed22fdb98b7152cce20b72 (patch) | |
tree | 83fd278faf86341c5495567396e5abea2ec1a4a4 /generator/pamtris/pamtris.c | |
parent | ebf403d4015d30f19a37895efdce201300c9b418 (diff) | |
download | netpbm-mirror-ee250e7490cbb3550fed22fdb98b7152cce20b72.tar.gz netpbm-mirror-ee250e7490cbb3550fed22fdb98b7152cce20b72.tar.xz netpbm-mirror-ee250e7490cbb3550fed22fdb98b7152cce20b72.zip |
Promote current Development release as Advanced
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@3468 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'generator/pamtris/pamtris.c')
-rw-r--r-- | generator/pamtris/pamtris.c | 67 |
1 files changed, 49 insertions, 18 deletions
diff --git a/generator/pamtris/pamtris.c b/generator/pamtris/pamtris.c index 74663531..e0becf7a 100644 --- a/generator/pamtris/pamtris.c +++ b/generator/pamtris/pamtris.c @@ -29,19 +29,21 @@ parse_command_line(int * const argc_ptr, /* Instructions to pm_optParseOptions3 on how to parse our options */ unsigned int option_def_index; - char * tupletype_ptr; + char * tupletype_tmp; - unsigned int width_spec, height_spec, maxval_spec, attribs_spec; - unsigned int tupletype_spec; + unsigned int width_spec, height_spec, attribs_spec, tupletype_spec; + unsigned int rgb_spec, grayscale_spec, maxval_spec; MALLOCARRAY_NOFAIL(option_def, 100); option_def_index = 0; /* incremented by OPTENT3 */ OPTENT3(0, "width", OPT_INT, width, &width_spec, 0); OPTENT3(0, "height", OPT_INT, height, &height_spec, 0); - OPTENT3(0, "maxval", OPT_INT, maxval, &maxval_spec, 0); OPTENT3(0, "num_attribs", OPT_INT, num_attribs, &attribs_spec, 0); - OPTENT3(0, "tupletype", OPT_STRING, &tupletype_ptr, &tupletype_spec, 0); + OPTENT3(0, "tupletype", OPT_STRING, &tupletype_tmp, &tupletype_spec, 0); + OPTENT3(0, "rgb", OPT_FLAG, NULL, &rgb_spec, 0); + OPTENT3(0, "grayscale", OPT_FLAG, NULL, &grayscale_spec, 0); + OPTENT3(0, "maxval", OPT_INT, maxval, &maxval_spec, 0); opt.opt_table = option_def; opt.short_allowed = false; @@ -49,9 +51,17 @@ parse_command_line(int * const argc_ptr, pm_optParseOptions3(argc_ptr, (char **)argv, opt, sizeof(opt), 0); - if (!width_spec || !height_spec || !attribs_spec) { + if (!width_spec || !height_spec || (!attribs_spec && !(rgb_spec || grayscale_spec))) { pm_errormsg( - "you must at least specify -width, -height and -num_attribs."); + "you must at least specify -width, -height and " + "either -num_attribs, -rgb or -grayscale."); + + return 0; + } + + if (rgb_spec + grayscale_spec + attribs_spec != 1) { + pm_errormsg("you must provide either only -num_attribs, " + "-rgb or -grayscale; not a combination of those."); return 0; } @@ -70,8 +80,6 @@ parse_command_line(int * const argc_ptr, if (maxval_spec) { if (*maxval < 1 || *maxval > PAM_OVERALL_MAXVAL) { - - pm_errormsg("invalid maxval."); return 0; @@ -80,6 +88,16 @@ parse_command_line(int * const argc_ptr, *maxval = 255; } + if (rgb_spec) { + *num_attribs = 3; + set_tupletype("RGB_ALPHA", tupletype); + } + + if (grayscale_spec) { + *num_attribs = 1; + set_tupletype("GRAYSCALE_ALPHA", tupletype); + } + if (*num_attribs < 1 || *num_attribs > MAX_NUM_ATTRIBS) { pm_errormsg("invalid number of generic attributes per vertex."); @@ -87,8 +105,15 @@ parse_command_line(int * const argc_ptr, } if (tupletype_spec) { - if (!set_tupletype(tupletype_ptr, tupletype)) { - pm_errormsg("warning: invalid tuple type; using the null string."); + if(rgb_spec || grayscale_spec) { + pm_errormsg("you may not provide -tupletype together with " + "-rgb or -grayscale."); + + return 0; + } + + if (!set_tupletype(tupletype_tmp, tupletype)) { + pm_errormsg("warning: invalid tuple type; using empty string."); set_tupletype(NULL, tupletype); } @@ -106,15 +131,20 @@ main(int argc, const char ** argv) { framebuffer_info fbi; boundary_info bi; - input_info ii; + Input input; + bool no_more_commands; pm_proginit(&argc, (const char**)argv); set_tupletype(NULL, fbi.outpam.tuple_type); - if (!parse_command_line(&argc, argv, - &fbi.width, &fbi.height, &fbi.maxval, - &fbi.num_attribs, fbi.outpam.tuple_type)) { + if (!parse_command_line(&argc, + argv, + &fbi.width, + &fbi.height, + &fbi.maxval, + &fbi.num_attribs, + fbi.outpam.tuple_type)) { return 1; } @@ -126,11 +156,12 @@ main(int argc, const char ** argv) { init_boundary_buffer(&bi, fbi.height); - init_input_processor(&ii); + input_init(&input); - while (process_next_command(&ii, &bi, &fbi)); + for (no_more_commands = false; !no_more_commands; ) + input_process_next_command(&input, &bi, &fbi, &no_more_commands); - free_input_processor(&ii); + input_term(&input); free_boundary_buffer(&bi); free_framebuffer(&fbi); |