root / ImageMagick / trunk / utilities / convert.c

Revision 10625, 5.7 kB (checked in by cristy, 4 months ago)
Line 
1/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3%                                                                             %
4%                                                                             %
5%                                                                             %
6%                CCCC   OOO   N   N  V   V  EEEEE  RRRR   TTTTT               %
7%               C      O   O  NN  N  V   V  E      R   R    T                 %
8%               C      O   O  N N N  V   V  EEE    RRRR     T                 %
9%               C      O   O  N  NN   V V   E      R R      T                 %
10%                CCCC   OOO   N   N    V    EEEEE  R  R     T                 %
11%                                                                             %
12%                                                                             %
13%                Convert an image from one format to another.                 %
14%                                                                             %
15%                              Software Design                                %
16%                                John Cristy                                  %
17%                                April 1992                                   %
18%                                                                             %
19%                                                                             %
20%  Copyright 1999-2008 ImageMagick Studio LLC, a non-profit organization      %
21%  dedicated to making software imaging solutions freely available.           %
22%                                                                             %
23%  You may not use this file except in compliance with the License.  You may  %
24%  obtain a copy of the License at                                            %
25%                                                                             %
26%    http://www.imagemagick.org/script/license.php                            %
27%                                                                             %
28%  Unless required by applicable law or agreed to in writing, software        %
29%  distributed under the License is distributed on an "AS IS" BASIS,          %
30%  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
31%  See the License for the specific language governing permissions and        %
32%  limitations under the License.                                             %
33%                                                                             %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36%  Convert converts an input file using one image format to an output file
37%  with a differing image format. By default, the image format is determined
38%  by its magic number. To specify a particular image format, precede the
39%  filename with an image format name and a colon (i.e. ps:image) or specify
40%  the image type as the filename suffix (i.e. image.ps). Specify file as -
41%  for standard input or output. If file has the extension .Z, the file is
42%  decoded with uncompress.
43%
44%
45*/
46
47/*
48  Include declarations.
49*/
50#include <stdio.h>
51#include <stdlib.h>
52#include <string.h>
53#include <time.h>
54#include <math.h>
55#include "wand/MagickWand.h"
56#if defined(__WINDOWS__)
57#include <windows.h>
58#endif
59
60/*
61%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62%                                                                             %
63%                                                                             %
64%                                                                             %
65%  M a i n                                                                    %
66%                                                                             %
67%                                                                             %
68%                                                                             %
69%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70%
71%
72*/
73int main(int argc,char **argv)
74{
75  char
76    *option;
77
78  double
79    elapsed_time,
80    user_time;
81
82  ExceptionInfo
83    *exception;
84
85  ImageInfo
86    *image_info;
87
88  MagickBooleanType
89    regard_warnings,
90    status;
91
92  register long
93    i;
94
95  TimerInfo
96    timer;
97
98  unsigned long
99    iterations;
100
101  MagickCoreGenesis(*argv,MagickTrue);
102  exception=AcquireExceptionInfo();
103  iterations=1;
104  status=MagickFalse;
105  regard_warnings=MagickFalse;
106  for (i=1; i < (long) (argc-1); i++)
107  {
108    option=argv[i];
109    if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
110      continue;
111    if (LocaleCompare("bench",option+1) == 0)
112      iterations=(unsigned long) atol(argv[++i]);
113    if (LocaleCompare("debug",option+1) == 0)
114      (void) SetLogEventMask(argv[++i]);
115    if (LocaleCompare("regard-warnings",option+1) == 0)
116      regard_warnings=MagickTrue;
117  }
118  GetTimerInfo(&timer);
119  for (i=0; i < (long) iterations; i++)
120  {
121    image_info=AcquireImageInfo();
122    status=ConvertImageCommand(image_info,argc,argv,(char **) NULL,exception);
123    if (exception->severity != UndefinedException)
124      {
125        if ((exception->severity > ErrorException) ||
126            (regard_warnings != MagickFalse))
127          status=MagickTrue;
128        CatchException(exception);
129      }
130    image_info=DestroyImageInfo(image_info);
131  }
132  if (iterations > 1)
133    {
134      elapsed_time=GetElapsedTime(&timer);
135      user_time=GetUserTime(&timer);
136      (void) fprintf(stderr,"Performance: %gips %0.3fu %ld:%02ld\n",1.0*
137        iterations/elapsed_time,user_time,(long) (elapsed_time/60.0+0.5),(long)
138        ceil(fmod(elapsed_time,60.0)));
139    }
140  exception=DestroyExceptionInfo(exception);
141  MagickCoreTerminus();
142  return(status == MagickFalse ? 0 : 1);
143}
Note: See TracBrowser for help on using the browser.