/* main.c : morph main program // // A GUI or command line user interface to a mesh warping algorithm // Written and Copyright (C) 1994-2000 by Michael J. Gourlay This file is part of Xmorph. Xmorph is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. Xmorph is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Xmorph; see the file LICENSE. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include "mesh.h" #include "RgbaImage.h" #ifdef X_GUI #include #include "xmorph.h" #endif #include "../xmorph/main.h" #define cl_match_arg(cmd) (!strcmp(argv[apc], cmd) && ((apc+1)ncols != src_imgP->ncols) || (dst_imgP->nrows != src_imgP->nrows)) { fprintf(stderr, "%s: images are not the same size\n", argv[0]); return 1; } } else { rgbaImageAlloc(dst_imgP, src_imgP->ncols, src_imgP->nrows); rgbaImageTestCreate(dst_imgP, 1); } #ifdef X_GUI { XtAppContext app; app = initialize_application(src_imgP->ncols, src_imgP->nrows, src_mesh_fn, dst_mesh_fn, &argc, argv, TRUE); XtAppMainLoop(app); } #else /* Command line interface */ if(verbose) fprintf(stderr, "morph_tween : %g\n", morph_tween); if(verbose) fprintf(stderr, "dissolve_tween: %g\n", dissolve_tween); { MeshT *src_mesh = meshNew(4,4); MeshT *dst_mesh = meshNew(4,4); if (NULL != src_mesh_fn) { if(meshRead(src_mesh, src_mesh_fn)) { fprintf(stderr, "%s: ERROR: failed to read src mesh '%s'\n", argv[0], src_mesh_fn); rgbaImageFree(src_imgP); rgbaImageFree(dst_imgP); meshDelete(src_mesh); meshDelete(dst_mesh); return 1; } } else { meshReset(src_mesh, src_imgP->ncols, src_imgP->nrows); } meshScale(src_mesh, src_imgP->ncols, src_imgP->nrows); if (NULL != dst_mesh_fn) { if(meshRead(dst_mesh, dst_mesh_fn)) { fprintf(stderr, "%s: ERROR: failed to read dst mesh '%s'\n", argv[0], dst_mesh_fn); rgbaImageFree(dst_imgP); rgbaImageFree(dst_imgP); meshFree(src_mesh); meshDelete(src_mesh); meshDelete(dst_mesh); return 1; } } else { meshReset(dst_mesh, dst_imgP->ncols, dst_imgP->nrows); } meshScale(dst_mesh, dst_imgP->ncols, dst_imgP->nrows); { RgbaImageT *src_warped = rgbaImageNew(); RgbaImageT *dst_warped = rgbaImageNew(); if(!skip_warp) { if(verbose) printf("."); rgbaImageWarp(src_imgP, src_warped, src_mesh, dst_mesh, morph_tween); if(verbose) printf("."); rgbaImageWarp(dst_imgP, dst_warped, dst_mesh, src_mesh, morph_tween); if(verbose) printf("."); rgbaImageWrite(out_img_fn, src_warped, dst_warped, dissolve_tween); if(verbose) printf(".\n"); } else { rgbaImageWrite(out_img_fn, src_imgP, dst_imgP, dissolve_tween); } rgbaImageFree(dst_warped); rgbaImageDelete(dst_warped); rgbaImageFree(src_warped); rgbaImageDelete(src_warped); } meshBackupFree(); meshFree(src_mesh); meshDelete(src_mesh); meshFree(dst_mesh); meshDelete(dst_mesh); } #endif rgbaImageFree(src_imgP); rgbaImageFree(dst_imgP); return 0; }