From: <bru...@us...> - 2009-02-04 22:33:46
|
Revision: 937 http://panotools.svn.sourceforge.net/panotools/?rev=937&view=rev Author: brunopostle Date: 2009-02-04 22:33:39 +0000 (Wed, 04 Feb 2009) Log Message: ----------- Existing implementation of WriteResults function uses two intermediate buffers for sprintf(3) and a considerable quantity of strcat(3) calls for copying data in the target buffer. This patch removes all strcat(3) calls and fulfils sprintf(3) in the target buffer directly. Patch #2118807 (Iouri Ivliev) Modified Paths: -------------- trunk/libpano/parser.c Modified: trunk/libpano/parser.c =================================================================== --- trunk/libpano/parser.c 2009-02-02 21:55:32 UTC (rev 936) +++ trunk/libpano/parser.c 2009-02-04 22:33:39 UTC (rev 937) @@ -630,7 +630,7 @@ void WriteResults( char* script, fullPath *sfile, AlignInfo *g, double ds( int i), int launch) { - char *res, **hres, line[LINE_LENGTH], cmd[LINE_LENGTH]; + char *res, **hres, *line; int optHfov; // Has hfov being optimized? int opta,optb,optc; // same for a,b,c - the polynomial corrections int format; @@ -644,17 +644,15 @@ PrintError("Not enough memory to create resultfile"); return; } - res = *hres; - *res = 0; - strcat( res, script ); - sprintf( line, "\n*\n\n" ); strcat( res, line ); - sprintf( line, "# ====================================================================\n");strcat( res, line ); - sprintf( line, "# Output generated by Panorama Tools\n\n" );strcat( res, line ); + line = res = *hres; + line += sprintf( line, "%s", script ); + line += sprintf( line, "\n*\n\n" ); + line += sprintf( line, "# ====================================================================\n"); + line += sprintf( line, "# Output generated by Panorama Tools\n\n" ); if( g->data != NULL ) - strcat( res, (char*) g->data ); - - - sprintf( line, "\n# Panorama description\n" );strcat( res, line ); + line += sprintf( line, "%s", (char*) g->data ); + + line += sprintf( line, "\n# Panorama description\n" ); switch( g->pano.format ) { case _rectilinear: format = PANO_FORMAT_RECTILINEAR; break; @@ -678,14 +676,12 @@ case _triplane: format = PANO_FORMAT_TRIPLANE; break; default: format = -1; break; } - - sprintf( line, "# p f%d w"FMT_INT32" h"FMT_INT32" v%g n\"%s\"\n\n", format, g->pano.width, g->pano.height, g->pano.hfov, g->pano.name );strcat( res, line ); - - - - sprintf( line, "# Parameters for Each Input Image:\n" );strcat( res, line ); - sprintf( line, "# (*) - optimized (p) - preset \n\n");strcat( res, line ); - + + line += sprintf( line, "# p f%d w"FMT_INT32" h"FMT_INT32" v%g n\"%s\"\n\n", format, g->pano.width, g->pano.height, g->pano.hfov, g->pano.name ); + + line += sprintf( line, "# Parameters for Each Input Image:\n" ); + line += sprintf( line, "# (*) - optimized (p) - preset \n\n"); + for( i=0; i<g->numIm; i++ ) { switch( g->im[i].format ) @@ -701,7 +697,6 @@ case _equisolid: format = IMAGE_FORMAT_FISHEYE_EQUISOLID; break; default: format = -1; break; } - sprintf( cmd, "o f%d ", format ); if( g->opt[i].hfov == 1 || ( g->opt[i].hfov > 1 && g->opt[g->opt[i].hfov-2].hfov == 1 )) @@ -727,8 +722,8 @@ else optc = 0; - sprintf( line, "# Image No %d:\n", i );strcat( res, line ); - sprintf( line, "# Yaw: %g deg (%c) Pitch: %g deg (%c) \n# Roll: %g deg (%c) HFov: %g deg (%c)\n# Polynomial Coefficients: a %f (%c); b %f (%c); c %f (%c)\n# Horizontal Shift: %f (%c) Vertical Shift: %f (%c)\n", + line += sprintf( line, "# Image No %d:\n", i ); + line += sprintf( line, "# Yaw: %g deg (%c) Pitch: %g deg (%c) \n# Roll: %g deg (%c) HFov: %g deg (%c)\n# Polynomial Coefficients: a %f (%c); b %f (%c); c %f (%c)\n# Horizontal Shift: %f (%c) Vertical Shift: %f (%c)\n", g->im[i].yaw, ( g->opt[i].yaw ? '*' : 'p' ), g->im[i].pitch, ( g->opt[i].pitch ? '*' : 'p' ), g->im[i].roll, ( g->opt[i].roll ? '*' : 'p' ), @@ -739,80 +734,74 @@ g->im[i].cP.horizontal_params[0], (g->opt[i].d ? '*':'p'), g->im[i].cP.vertical_params[0], (g->opt[i].e ? '*':'p') ); - strcat( res, line ); - sprintf( line, "r%g p%g y%g v%g ", g->im[i].roll,g->im[i].pitch,g->im[i].yaw,g->im[i].hfov); - strcat( cmd, line ); + if( opta || optb || optc ) + { + line += sprintf(line,"# 4th polynomial coefficient: %g\n", 1.0 - ( g->im[i].cP.radial_params[0][3] + + g->im[i].cP.radial_params[0][2] + + g->im[i].cP.radial_params[0][1] ) ); + } + line += sprintf(line, "# Command for Panorama Creation: \n" ); + line += sprintf( line, "o f%d r%g p%g y%g v%g ", format, g->im[i].roll,g->im[i].pitch,g->im[i].yaw,g->im[i].hfov); if( g->im[i].cP.radial ) { - sprintf( line, "a%f b%f c%f ", g->im[i].cP.radial_params[0][3], g->im[i].cP.radial_params[0][2], g->im[i].cP.radial_params[0][1]); - strcat( cmd, line ); + line += sprintf( line, "a%f b%f c%f ", g->im[i].cP.radial_params[0][3], g->im[i].cP.radial_params[0][2], g->im[i].cP.radial_params[0][1]); } if( g->im[i].cP.shear ) { - sprintf( line, "g%f t%f ", g->im[i].cP.shear_x, g->im[i].cP.shear_y); - strcat( cmd, line ); + line += sprintf( line, "g%f t%f ", g->im[i].cP.shear_x, g->im[i].cP.shear_y); } if( g->im[i].cP.cutFrame && !( g->im[i].selection.bottom != 0 || g->im[i].selection.right != 0 )) // g->im[i].format != _fisheye_circ && g->im[i].cP.cutFrame ) { if( g->im[i].cP.frame != 0 ) { - sprintf( line, "m%d ",g->im[i].cP.frame ); + line += sprintf( line, "m%d ",g->im[i].cP.frame ); } else { - sprintf( line, "mx%d my%d ",g->im[i].cP.fwidth, g->im[i].cP.fheight ); + line += sprintf( line, "mx%d my%d ",g->im[i].cP.fwidth, g->im[i].cP.fheight ); } - strcat( cmd, line ); } -// sprintf( line, "d%f e%f ", g->prefs[i]->c_prefs.horizontal_params[0], g->prefs[i]->c_prefs.vertical_params[0]); -// strcat( cmd, line ); +// line += sprintf( line, "d%f e%f ", g->prefs[i]->c_prefs.horizontal_params[0], g->prefs[i]->c_prefs.vertical_params[0]); #if 0 if( g->prefs[i]->colCorrect ) { - sprintf( line, "t%f,%f,%f,%f,%f,%f ", g->prefs[i]->ColCoeff[0][0], + line += sprintf( line, "t%f,%f,%f,%f,%f,%f ", g->prefs[i]->ColCoeff[0][0], g->prefs[i]->ColCoeff[0][1], g->prefs[i]->ColCoeff[1][0], g->prefs[i]->ColCoeff[1][1], g->prefs[i]->ColCoeff[2][0], g->prefs[i]->ColCoeff[2][1]); - strcat( cmd, line ); } #endif if( g->im[i].cP.horizontal ) { - sprintf( line, "d%f ",g->im[i].cP.horizontal_params[0]); - strcat( cmd, line ); + line += sprintf( line, "d%f ",g->im[i].cP.horizontal_params[0]); } if( g->im[i].cP.vertical ) { - sprintf( line, "e%f ",g->im[i].cP.vertical_params[0]); - strcat( cmd, line ); + line += sprintf( line, "e%f ",g->im[i].cP.vertical_params[0]); } if( g->im[i].cP.correction_mode & correction_mode_morph ) { - strcat( cmd, "o " ); + line += sprintf( line, "o " ); } if( g->im[i].selection.bottom != 0 || g->im[i].selection.right != 0 ){ if( g->im[i].cP.cutFrame ){ - sprintf( line, " C"FMT_INT32","FMT_INT32","FMT_INT32","FMT_INT32" ",g->im[i].selection.left, g->im[i].selection.right, + line += sprintf( line, " C"FMT_INT32","FMT_INT32","FMT_INT32","FMT_INT32" ",g->im[i].selection.left, g->im[i].selection.right, g->im[i].selection.top, g->im[i].selection.bottom ); }else{ - sprintf( line, " S"FMT_INT32","FMT_INT32","FMT_INT32","FMT_INT32" ",g->im[i].selection.left, g->im[i].selection.right, + line += sprintf( line, " S"FMT_INT32","FMT_INT32","FMT_INT32","FMT_INT32" ",g->im[i].selection.left, g->im[i].selection.right, g->im[i].selection.top, g->im[i].selection.bottom ); } - strcat( cmd, line ); } - - sprintf(line, "u%d ", g->st.feather); - strcat( cmd, line ); + line += sprintf(line, "u%d ", g->st.feather); #if 0 // Print filename if( g->im[i].name != NULL && strlen( g->im[i].name != 0 ) ){ - sprintf(line, " n\"%s\" ", g->im[i].name); - strcat( cmd, line ); + line += sprintf(line, " n\"%s\" ", g->im[i].name); } #endif @@ -821,48 +810,32 @@ // else add stitch commands if( !*(g->st.destName) ) { - if( i== 0 ) { - sprintf(line, "-%s ", g->st.srcName); - strcat( cmd, line ); + line += sprintf(line, "-%s ", g->st.srcName); } else if( i == g->numIm-1 ) { - sprintf(line, "+%s ", g->st.srcName); - strcat( cmd, line ); + line += sprintf(line, "+%s ", g->st.srcName); } else { - sprintf(line, "+%s -%s ", g->st.srcName, g->st.srcName); - strcat( cmd, line ); + line += sprintf(line, "+%s -%s ", g->st.srcName, g->st.srcName); } // Print Feather commands } - - - - if( opta || optb || optc ) - { - sprintf(line,"# 4th polynomial coefficient: %g\n", 1.0 - ( g->im[i].cP.radial_params[0][3] - + g->im[i].cP.radial_params[0][2] - + g->im[i].cP.radial_params[0][1] ) ); - strcat( res, line ); - } - sprintf(line, "# Command for Panorama Creation: \n%s\n", cmd ); - strcat( res, line ); - sprintf(line, "\n");strcat( res, line ); + line += sprintf(line, "\n\n"); } // numIm if( g->numPts > 0 ) // Display Controlpoint distances { - sprintf(line, "\n");strcat( res, line ); - sprintf( line, "# ==========================================================================\n");strcat( res, line ); - sprintf( line, "# Control Points: Distance between desired and fitted Position (in \"Pixels\")\n\n");strcat( res, line ); - + line += sprintf(line, "\n"); + line += sprintf( line, "# ==========================================================================\n"); + line += sprintf( line, "# Control Points: Distance between desired and fitted Position (in \"Pixels\")\n\n"); + for( i=0; i<g->numPts; i++ ) { - sprintf( line, "# Control Point No %d: %g\n", i , sqrt ( ds(i)) );strcat( res, line ); + line += sprintf( line, "# Control Point No %d: %g\n", i , sqrt ( ds(i)) ); } // Print optimum positions for points in panorama for( i=0; i<g->numPts; i++ ) @@ -879,8 +852,8 @@ { xd = (x[0]+x[1]) / 2.0; yd = (y[0]+y[1]) / 2.0; - sprintf( line, "C i%d x%g y%g X%g Y%g\n", g->cpt[i].num[0] , x[0], y[0], xd, yd );strcat( res, line ); - sprintf( line, "C i%d x%g y%g X%g Y%g\n", g->cpt[i].num[1] , x[1], y[1], xd, yd );strcat( res, line ); + line += sprintf( line, "C i%d x%g y%g X%g Y%g\n", g->cpt[i].num[0] , x[0], y[0], xd, yd ); + line += sprintf( line, "C i%d x%g y%g X%g Y%g\n", g->cpt[i].num[1] , x[1], y[1], xd, yd ); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |