diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2006-10-18 17:20:56 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2006-10-18 17:20:56 +0000 |
commit | 34d905eb05083faa7267ea34550c54e7bd753e98 (patch) | |
tree | 5033b51c5d06079a5f764b57b4c89875d40f8cc2 | |
parent | d8d1608b90da80ce89870be7371624e14ba31974 (diff) | |
download | netpbm-mirror-34d905eb05083faa7267ea34550c54e7bd753e98.tar.gz netpbm-mirror-34d905eb05083faa7267ea34550c54e7bd753e98.tar.xz netpbm-mirror-34d905eb05083faa7267ea34550c54e7bd753e98.zip |
cleanup
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@86 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r-- | editor/pamperspective.c | 163 |
1 files changed, 86 insertions, 77 deletions
diff --git a/editor/pamperspective.c b/editor/pamperspective.c index 08011cc3..55ecd0f6 100644 --- a/editor/pamperspective.c +++ b/editor/pamperspective.c @@ -198,9 +198,12 @@ typedef struct { +typedef void interpolateFn(tuple, number, number); + /* The following are like MALLOCARRAY_NOFAIL and MALLOCVAR_NOFAIL, - but issue an error message instead of aborting. + but abort (fail) the program instead of killing the process with an + abort signal. */ #define MALLOCARRAY_SAFE(handle,length) \ @@ -1240,92 +1243,98 @@ static void linear_interpolation (tuple const dest, -int main (int argc, char* argv[]) -{ - FILE* infp; - struct pam inpam; - buffer inbuffer; - FILE* outfp; - struct pam outpam; - tuple* outrow; - option options; - world_data world; - int row,col; - number xi,yi; - void (*interpolate) (tuple, number, number); +static void +perspective(struct pam * const outpamP, + world_data * const worldP, + interpolateFn * interpolater) { - /* The usual initializations */ + tuple * outrow; + unsigned int row; - pnm_init (&argc, argv); - set_command_line_defaults (&options); - parse_command_line (argc, argv, &options); - infp = pm_openr (options.infilename); - pnm_readpaminit (infp, &inpam, PAM_STRUCT_SIZE(tuple_type)); + outrow = pnm_allocpamrow(outpamP); - /* Our own initializations */ + for (row = 0; row < outpamP->height; ++row) { + unsigned int col; - init_world (&options, &inpam, &world); - determine_world_parallelogram (&world, &options); - determine_output_width_and_height (&world, &options); - switch (options.enums[1]) { /* --output_system */ - case lattice: - determine_coefficients_lattice (&world, &options); - break; - case pixel_s: - determine_coefficients_pixel (&world, &options); - break; - }; + for (col = 0; col < outpamP->width; ++col) { + number xi,yi; + outpixel_to_inpixel(col, row, &xi, &yi, worldP); + interpolater(outrow[col], xi, yi); + } + pnm_writepamrow(outpamP, outrow); + } + pnm_freepamrow(outrow); +} - /* Initialize outpam */ - - outfp = pm_openw ("-"); - outpam.size = sizeof (outpam); - outpam.len = PAM_STRUCT_SIZE(bytes_per_sample); - outpam.file = outfp; - outpam.format = inpam.format; - outpam.plainformat = inpam.plainformat; - outpam.height = options.height; - outpam.width = options.width; - outpam.depth = inpam.depth; - outpam.maxval = inpam.maxval; - outpam.bytes_per_sample = inpam.bytes_per_sample; - pnm_writepaminit (&outpam); - - /* Initialize the actual calculation */ - - init_buffer (&inbuffer, &world, &options, &inpam, &outpam); - outrow = pnm_allocpamrow (&outpam); - init_interpolation_global_vars (&inbuffer,&inpam,&outpam); - switch (options.enums[3]) { /* --interpolation */ - case nearest: - interpolate = take_nearest; - break; - case linear: - interpolate = linear_interpolation; - break; - }; - /* Perform the actual calculation */ - for (row=0; row<outpam.height; row++) { - for (col=0; col<outpam.width; col++) { - outpixel_to_inpixel (col,row,&xi,&yi,&world); - interpolate(outrow[col],xi,yi); - } - pnm_writepamrow (&outpam, outrow); - } +int +main(int argc, char* argv[]) { - /* Close everything down nicely */ + FILE * ifP; + struct pam inpam; + buffer inbuffer; + struct pam outpam; + option options; + world_data world; + interpolateFn * interpolater; - clean_interpolation_global_vars (); - free_buffer (&inbuffer); - pnm_freepamrow (outrow); - free_option (&options); - pm_close (infp); - pm_close (outfp); - return 0; -} + pnm_init(&argc, argv); + set_command_line_defaults(&options); + parse_command_line(argc, argv, &options); + ifP = pm_openr(options.infilename); + pnm_readpaminit(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type)); + + /* Our own initializations */ + + init_world(&options, &inpam, &world); + determine_world_parallelogram(&world, &options); + determine_output_width_and_height(&world, &options); + switch (options.enums[1]) { /* --output_system */ + case lattice: + determine_coefficients_lattice(&world, &options); + break; + case pixel_s: + determine_coefficients_pixel(&world, &options); + break; + }; + + outpam.size = sizeof(outpam); + outpam.len = PAM_STRUCT_SIZE(bytes_per_sample); + outpam.file = stdout; + outpam.format = inpam.format; + outpam.plainformat = FALSE; + outpam.height = options.height; + outpam.width = options.width; + outpam.depth = inpam.depth; + outpam.maxval = inpam.maxval; + outpam.bytes_per_sample = inpam.bytes_per_sample; + pnm_writepaminit(&outpam); + + /* Initialize the actual calculation */ + + init_buffer(&inbuffer, &world, &options, &inpam, &outpam); + init_interpolation_global_vars(&inbuffer, &inpam, &outpam); + switch (options.enums[3]) { /* --interpolation */ + case nearest: + interpolater = take_nearest; + break; + case linear: + interpolater = linear_interpolation; + break; + }; + + perspective(&outpam, &world, interpolater); + + clean_interpolation_global_vars(); + free_buffer(&inbuffer); + free_option(&options); + pm_close(ifP); + pm_close(stdout); + + return 0; +} |