magick-wand.c

Go to the documentation of this file.
00001 /*
00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00003 %                                                                             %
00004 %                                                                             %
00005 %                                                                             %
00006 %                 M   M   AAA    GGGG  IIIII   CCCC  K   K                    %
00007 %                 MM MM  A   A  G        I    C      K  K                     %
00008 %                 M M M  AAAAA  G GGG    I    C      KKK                      %
00009 %                 M   M  A   A  G   G    I    C      K  K                     %
00010 %                 M   M  A   A   GGGG  IIIII   CCCC  K   K                    %
00011 %                                                                             %
00012 %                        W   W   AAA   N   N  DDDD                            %
00013 %                        W   W  A   A  NN  N  D   D                           %
00014 %                        W W W  AAAAA  N N N  D   D                           %
00015 %                        WW WW  A   A  N  NN  D   D                           %
00016 %                        W   W  A   A  N   N  DDDD                            %
00017 %                                                                             %
00018 %                                                                             %
00019 %                           MagickWand Wand Methods                           %
00020 %                                                                             %
00021 %                               Software Design                               %
00022 %                                 John Cristy                                 %
00023 %                                 August 2003                                 %
00024 %                                                                             %
00025 %                                                                             %
00026 %  Copyright 1999-2008 ImageMagick Studio LLC, a non-profit organization      %
00027 %  dedicated to making software imaging solutions freely available.           %
00028 %                                                                             %
00029 %  You may not use this file except in compliance with the License.  You may  %
00030 %  obtain a copy of the License at                                            %
00031 %                                                                             %
00032 %    http://www.imagemagick.org/script/license.php                            %
00033 %                                                                             %
00034 %  Unless required by applicable law or agreed to in writing, software        %
00035 %  distributed under the License is distributed on an "AS IS" BASIS,          %
00036 %  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
00037 %  See the License for the specific language governing permissions and        %
00038 %  limitations under the License.                                             %
00039 %                                                                             %
00040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00041 %
00042 %
00043 %
00044 */
00045 
00046 /*
00047   Include declarations.
00048 */
00049 #include "wand/studio.h"
00050 #include "wand/MagickWand.h"
00051 #include "wand/magick-wand-private.h"
00052 #include "wand/wand.h"
00053 
00054 /*
00055   Define declarations.
00056 */
00057 #define ThrowWandException(severity,tag,context) \
00058 { \
00059   (void) ThrowMagickException(wand->exception,GetMagickModule(),severity, \
00060     tag,"`%s'",context); \
00061   return(MagickFalse); \
00062 }
00063 
00064 /*
00065   Global declarations.
00066 */
00067 static unsigned long
00068   id = 0;
00069 
00070 /*
00071 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00072 %                                                                             %
00073 %                                                                             %
00074 %                                                                             %
00075 %   C l e a r M a g i c k W a n d                                             %
00076 %                                                                             %
00077 %                                                                             %
00078 %                                                                             %
00079 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00080 %
00081 %  ClearMagickWand() clears resources associated with the wand.
00082 %
00083 %  The format of the ClearMagickWand method is:
00084 %
00085 %      void ClearMagickWand(MagickWand *wand)
00086 %
00087 %  A description of each parameter follows:
00088 %
00089 %    o wand: the magick wand.
00090 %
00091 */
00092 WandExport void ClearMagickWand(MagickWand *wand)
00093 {
00094   assert(wand != (MagickWand *) NULL);
00095   assert(wand->signature == WandSignature);
00096   if (wand->debug != MagickFalse)
00097     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00098   wand->quantize_info=DestroyQuantizeInfo(wand->quantize_info);
00099   wand->image_info=DestroyImageInfo(wand->image_info);
00100   wand->images=DestroyImageList(wand->images);
00101   wand->quantize_info=CloneQuantizeInfo((QuantizeInfo *) NULL);
00102   wand->image_info=AcquireImageInfo();
00103   ClearMagickException(wand->exception);
00104   wand->debug=IsEventLogging();
00105 }
00106 
00107 /*
00108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00109 %                                                                             %
00110 %                                                                             %
00111 %                                                                             %
00112 %   C l o n e M a g i c k W a n d                                             %
00113 %                                                                             %
00114 %                                                                             %
00115 %                                                                             %
00116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00117 %
00118 %  CloneMagickWand() makes an exact copy of the specified wand.
00119 %
00120 %  The format of the CloneMagickWand method is:
00121 %
00122 %      MagickWand *CloneMagickWand(const MagickWand *wand)
00123 %
00124 %  A description of each parameter follows:
00125 %
00126 %    o wand: the magick wand.
00127 %
00128 */
00129 WandExport MagickWand *CloneMagickWand(const MagickWand *wand)
00130 {
00131   MagickWand
00132     *clone_wand;
00133 
00134   assert(wand != (MagickWand *) NULL);
00135   assert(wand->signature == WandSignature);
00136   if (wand->debug != MagickFalse)
00137     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00138   clone_wand=(MagickWand *) AcquireMagickMemory(sizeof(*clone_wand));
00139   if (clone_wand == (MagickWand *) NULL)
00140     ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
00141       wand->name);
00142   (void) ResetMagickMemory(clone_wand,0,sizeof(*clone_wand));
00143   clone_wand->id=AcquireWandId();
00144   (void) FormatMagickString(clone_wand->name,MaxTextExtent,"%s-%lu",
00145     MagickWandId,clone_wand->id);
00146   clone_wand->exception=AcquireExceptionInfo();
00147   InheritException(clone_wand->exception,wand->exception);
00148   clone_wand->image_info=CloneImageInfo(wand->image_info);
00149   clone_wand->quantize_info=CloneQuantizeInfo(wand->quantize_info);
00150   clone_wand->images=CloneImageList(wand->images,clone_wand->exception);
00151   clone_wand->debug=IsEventLogging();
00152   if (clone_wand->debug != MagickFalse)
00153     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",clone_wand->name);
00154   clone_wand->signature=WandSignature;
00155   return(clone_wand);
00156 }
00157 
00158 /*
00159 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00160 %                                                                             %
00161 %                                                                             %
00162 %                                                                             %
00163 %   D e s t r o y M a g i c k W a n d                                         %
00164 %                                                                             %
00165 %                                                                             %
00166 %                                                                             %
00167 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00168 %
00169 %  DestroyMagickWand() deallocates memory associated with an MagickWand.
00170 %
00171 %  The format of the DestroyMagickWand method is:
00172 %
00173 %      MagickWand *DestroyMagickWand(MagickWand *wand)
00174 %
00175 %  A description of each parameter follows:
00176 %
00177 %    o wand: the magick wand.
00178 %
00179 */
00180 WandExport MagickWand *DestroyMagickWand(MagickWand *wand)
00181 {
00182   assert(wand != (MagickWand *) NULL);
00183   assert(wand->signature == WandSignature);
00184   if (wand->debug != MagickFalse)
00185     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00186   wand->quantize_info=DestroyQuantizeInfo(wand->quantize_info);
00187   wand->image_info=DestroyImageInfo(wand->image_info);
00188   wand->images=DestroyImageList(wand->images);
00189   wand->exception=DestroyExceptionInfo(wand->exception);
00190   RelinquishWandId(wand->id);
00191   wand->signature=(~WandSignature);
00192   wand=(MagickWand *) RelinquishMagickMemory(wand);
00193   return(wand);
00194 }
00195 
00196 /*
00197 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00198 %                                                                             %
00199 %                                                                             %
00200 %                                                                             %
00201 %   I s M a g i c k W a n d                                                   %
00202 %                                                                             %
00203 %                                                                             %
00204 %                                                                             %
00205 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00206 %
00207 %  IsMagickWand() returns MagickTrue if the wand is verified as a magick wand.
00208 %
00209 %  The format of the IsMagickWand method is:
00210 %
00211 %      MagickBooleanType IsMagickWand(const MagickWand *wand)
00212 %
00213 %  A description of each parameter follows:
00214 %
00215 %    o wand: the magick wand.
00216 %
00217 */
00218 WandExport MagickBooleanType IsMagickWand(const MagickWand *wand)
00219 {
00220   if (wand == (const MagickWand *) NULL)
00221     return(MagickFalse);
00222   if (wand->signature != WandSignature)
00223     return(MagickFalse);
00224   if (LocaleNCompare(wand->name,MagickWandId,strlen(MagickWandId)) != 0)
00225     return(MagickFalse);
00226   return(MagickTrue);
00227 }
00228 
00229 /*
00230 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00231 %                                                                             %
00232 %                                                                             %
00233 %                                                                             %
00234 %   M a g i c k C l e a r E x c e p t i o n                                   %
00235 %                                                                             %
00236 %                                                                             %
00237 %                                                                             %
00238 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00239 %
00240 %  MagickClearException() clears any exceptions associated with the wand.
00241 %
00242 %  The format of the MagickClearException method is:
00243 %
00244 %      MagickBooleanType MagickClearException(MagickWand *wand)
00245 %
00246 %  A description of each parameter follows:
00247 %
00248 %    o wand: the magick wand.
00249 %
00250 */
00251 WandExport MagickBooleanType MagickClearException(MagickWand *wand)
00252 {
00253   assert(wand != (MagickWand *) NULL);
00254   assert(wand->signature == WandSignature);
00255   if (wand->debug != MagickFalse)
00256     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00257   ClearMagickException(wand->exception);
00258   return(MagickTrue);
00259 }
00260 
00261 /*
00262 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00263 %                                                                             %
00264 %                                                                             %
00265 %                                                                             %
00266 %   M a g i c k G e t E x c e p t i o n                                       %
00267 %                                                                             %
00268 %                                                                             %
00269 %                                                                             %
00270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00271 %
00272 %  MagickGetException() returns the severity, reason, and description of any
00273 %  error that occurs when using other methods in this API.
00274 %
00275 %  The format of the MagickGetException method is:
00276 %
00277 %      char *MagickGetException(const MagickWand *wand,ExceptionType *severity)
00278 %
00279 %  A description of each parameter follows:
00280 %
00281 %    o wand: the magick wand.
00282 %
00283 %    o severity: the severity of the error is returned here.
00284 %
00285 */
00286 WandExport char *MagickGetException(const MagickWand *wand,
00287   ExceptionType *severity)
00288 {
00289   char
00290     *description;
00291 
00292   assert(wand != (const MagickWand *) NULL);
00293   assert(wand->signature == WandSignature);
00294   if (wand->debug != MagickFalse)
00295     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00296   assert(severity != (ExceptionType *) NULL);
00297   *severity=wand->exception->severity;
00298   description=(char *) AcquireQuantumMemory(2UL*MaxTextExtent,
00299     sizeof(*description));
00300   if (description == (char *) NULL)
00301     {
00302       (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
00303         "MemoryAllocationFailed","`%s'",wand->name);
00304       return((char *) NULL);
00305     }
00306   *description='\0';
00307   if (wand->exception->reason != (char *) NULL)
00308     (void) CopyMagickString(description,GetLocaleExceptionMessage(
00309       wand->exception->severity,wand->exception->reason),MaxTextExtent);
00310   if (wand->exception->description != (char *) NULL)
00311     {
00312       (void) ConcatenateMagickString(description," (",MaxTextExtent);
00313       (void) ConcatenateMagickString(description,GetLocaleExceptionMessage(
00314         wand->exception->severity,wand->exception->description),MaxTextExtent);
00315       (void) ConcatenateMagickString(description,")",MaxTextExtent);
00316     }
00317   return(description);
00318 }
00319 
00320 /*
00321 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00322 %                                                                             %
00323 %                                                                             %
00324 %                                                                             %
00325 %   M a g i c k G e t  E x c e p t i o n T y p e                              %
00326 %                                                                             %
00327 %                                                                             %
00328 %                                                                             %
00329 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00330 %
00331 %  MagickGetExceptionType() returns the exception type associated with the
00332 %  wand.  If no exception has occurred, UndefinedExceptionType is returned.
00333 %
00334 %  The format of the MagickGetExceptionType method is:
00335 %
00336 %      ExceptionType MagickGetExceptionType(const MagickWand *wand)
00337 %
00338 %  A description of each parameter follows:
00339 %
00340 %    o wand: the magick wand.
00341 %
00342 */
00343 WandExport ExceptionType MagickGetExceptionType(const MagickWand *wand)
00344 {
00345   assert(wand != (MagickWand *) NULL);
00346   assert(wand->signature == WandSignature);
00347   if (wand->debug != MagickFalse)
00348     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00349   return(wand->exception->severity);
00350 }
00351 
00352 /*
00353 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00354 %                                                                             %
00355 %                                                                             %
00356 %                                                                             %
00357 %   M a g i c k G e t I t e r a t o r I n d e x                               %
00358 %                                                                             %
00359 %                                                                             %
00360 %                                                                             %
00361 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00362 %
00363 %  MagickGetIteratorIndex() returns the position of the iterator in the image
00364 %  list.
00365 %
00366 %  The format of the MagickGetIteratorIndex method is:
00367 %
00368 %      long MagickGetIteratorIndex(MagickWand *wand)
00369 %
00370 %  A description of each parameter follows:
00371 %
00372 %    o wand: the magick wand.
00373 %
00374 */
00375 WandExport long MagickGetIteratorIndex(MagickWand *wand)
00376 {
00377   assert(wand != (MagickWand *) NULL);
00378   assert(wand->signature == WandSignature);
00379   if (wand->debug != MagickFalse)
00380     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00381   if (wand->images == (Image *) NULL)
00382     {
00383       (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
00384         "ContainsNoIterators","`%s'",wand->name);
00385       return(-1);
00386     }
00387   return(GetImageIndexInList(wand->images));
00388 }
00389 
00390 /*
00391 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00392 %                                                                             %
00393 %                                                                             %
00394 %                                                                             %
00395 %   M a g i c k Q u e r y C o n f i g u r e O p t i o n                       %
00396 %                                                                             %
00397 %                                                                             %
00398 %                                                                             %
00399 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00400 %
00401 %  MagickQueryConfigureOption() returns the value associated with the specified
00402 %  configure option.
00403 %
00404 %  The format of the MagickQueryConfigureOption function is:
00405 %
00406 %      char *MagickQueryConfigureOption(const char *option)
00407 %
00408 %  A description of each parameter follows:
00409 %
00410 %    o option: the option name.
00411 %
00412 */
00413 WandExport char *MagickQueryConfigureOption(const char *option)
00414 {
00415   char
00416     *value;
00417 
00418   const ConfigureInfo
00419     **configure_info;
00420 
00421   ExceptionInfo
00422     *exception;
00423 
00424   unsigned long
00425     number_options;
00426 
00427   exception=AcquireExceptionInfo();
00428   configure_info=GetConfigureInfoList(option,&number_options,exception);
00429   exception=DestroyExceptionInfo(exception);
00430   if (configure_info == (const ConfigureInfo **) NULL)
00431     return((char *) NULL);
00432   value=AcquireString(configure_info[0]->value);
00433   configure_info=(const ConfigureInfo **)
00434     RelinquishMagickMemory((void *) configure_info);
00435   return(value);
00436 }
00437 
00438 /*
00439 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00440 %                                                                             %
00441 %                                                                             %
00442 %                                                                             %
00443 %   M a g i c k Q u e r y C o n f i g u r e O p t i o n s                     %
00444 %                                                                             %
00445 %                                                                             %
00446 %                                                                             %
00447 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00448 %
00449 %  MagickQueryConfigureOptions() returns any configure options that match the
00450 %  specified pattern (e.g.  "*" for all).  Options include NAME, VERSION,
00451 %  LIB_VERSION, etc.
00452 %
00453 %  The format of the MagickQueryConfigureOptions function is:
00454 %
00455 %      char **MagickQueryConfigureOptions(const char *pattern,
00456 %        unsigned long *number_options)
00457 %
00458 %  A description of each parameter follows:
00459 %
00460 %    o pattern: Specifies a pointer to a text string containing a pattern.
00461 %
00462 %    o number_options:  Returns the number of configure options in the list.
00463 %
00464 %
00465 */
00466 WandExport char **MagickQueryConfigureOptions(const char *pattern,
00467   unsigned long *number_options)
00468 {
00469   char
00470     **options;
00471 
00472   ExceptionInfo
00473     *exception;
00474 
00475   exception=AcquireExceptionInfo();
00476   options=GetConfigureList(pattern,number_options,exception);
00477   exception=DestroyExceptionInfo(exception);
00478   return(options);
00479 }
00480 
00481 /*
00482 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00483 %                                                                             %
00484 %                                                                             %
00485 %                                                                             %
00486 %   M a g i c k Q u e r y F o n t M e t r i c s                               %
00487 %                                                                             %
00488 %                                                                             %
00489 %                                                                             %
00490 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00491 %
00492 %  MagickQueryFontMetrics() returns a 13 element array representing the
00493 %  following font metrics:
00494 %
00495 %    Element Description
00496 %    -------------------------------------------------
00497 %          0 character width
00498 %          1 character height
00499 %          2 ascender
00500 %          3 descender
00501 %          4 text width
00502 %          5 text height
00503 %          6 maximum horizontal advance
00504 %          7 bounding box: x1
00505 %          8 bounding box: y1
00506 %          9 bounding box: x2
00507 %         10 bounding box: y2
00508 %         11 origin: x
00509 %         12 origin: y
00510 %
00511 %  The format of the MagickQueryFontMetrics method is:
00512 %
00513 %      double *MagickQueryFontMetrics(MagickWand *wand,
00514 %        const DrawingWand *drawing_wand,const char *text)
00515 %
00516 %  A description of each parameter follows:
00517 %
00518 %    o wand: the Magick wand.
00519 %
00520 %    o drawing_wand: the drawing wand.
00521 %
00522 %    o text: the text.
00523 %
00524 */
00525 WandExport double *MagickQueryFontMetrics(MagickWand *wand,
00526   const DrawingWand *drawing_wand,const char *text)
00527 {
00528   double
00529     *font_metrics;
00530 
00531   DrawInfo
00532     *draw_info;
00533 
00534   MagickBooleanType
00535     status;
00536 
00537   TypeMetric
00538     metrics;
00539 
00540   assert(wand != (MagickWand *) NULL);
00541   assert(wand->signature == WandSignature);
00542   if (wand->debug != MagickFalse)
00543     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00544   assert(drawing_wand != (const DrawingWand *) NULL);
00545   if (wand->images == (Image *) NULL)
00546     {
00547       (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
00548         "ContainsNoImages","`%s'",wand->name);
00549       return((double *) NULL);
00550     }
00551   font_metrics=(double *) AcquireQuantumMemory(13UL,sizeof(*font_metrics));
00552   if (font_metrics == (double *) NULL)
00553     return((double *) NULL);
00554   draw_info=PeekDrawingWand(drawing_wand);
00555   if (draw_info == (DrawInfo *) NULL)
00556     {
00557       font_metrics=(double *) RelinquishMagickMemory(font_metrics);
00558       return((double *) NULL);
00559     }
00560   (void) CloneString(&draw_info->text,text);
00561   (void) ResetMagickMemory(&metrics,0,sizeof(metrics));
00562   status=GetTypeMetrics(wand->images,draw_info,&metrics);
00563   draw_info=DestroyDrawInfo(draw_info);
00564   if (status == MagickFalse)
00565     {
00566       InheritException(wand->exception,&wand->images->exception);
00567       font_metrics=(double *) RelinquishMagickMemory(font_metrics);
00568       return((double *) NULL);
00569     }
00570   font_metrics[0]=metrics.pixels_per_em.x;
00571   font_metrics[1]=metrics.pixels_per_em.y;
00572   font_metrics[2]=metrics.ascent;
00573   font_metrics[3]=metrics.descent;
00574   font_metrics[4]=metrics.width;
00575   font_metrics[5]=metrics.height;
00576   font_metrics[6]=metrics.max_advance;
00577   font_metrics[7]=metrics.bounds.x1;
00578   font_metrics[8]=metrics.bounds.y1;
00579   font_metrics[9]=metrics.bounds.x2;
00580   font_metrics[10]=metrics.bounds.y2;
00581   font_metrics[11]=metrics.origin.x;
00582   font_metrics[12]=metrics.origin.y;
00583   return(font_metrics);
00584 }
00585 
00586 /*
00587 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00588 %                                                                             %
00589 %                                                                             %
00590 %                                                                             %
00591 %   M a g i c k Q u e r y M u l t i l i n e F o n t M e t r i c s             %
00592 %                                                                             %
00593 %                                                                             %
00594 %                                                                             %
00595 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00596 %
00597 %  MagickQueryMultilineFontMetrics() returns a 13 element array representing the
00598 %  following font metrics:
00599 %
00600 %    Element Description
00601 %    -------------------------------------------------
00602 %          0 character width
00603 %          1 character height
00604 %          2 ascender
00605 %          3 descender
00606 %          4 text width
00607 %          5 text height
00608 %          6 maximum horizontal advance
00609 %          7 bounding box: x1
00610 %          8 bounding box: y1
00611 %          9 bounding box: x2
00612 %         10 bounding box: y2
00613 %         11 origin: x
00614 %         12 origin: y
00615 %
00616 %  This method is like MagickQueryFontMetrics() but it returns the maximum text
00617 %  width and height for multiple lines of text.
00618 %
00619 %  The format of the MagickQueryFontMetrics method is:
00620 %
00621 %      double *MagickQueryMultilineFontMetrics(MagickWand *wand,
00622 %        const DrawingWand *drawing_wand,const char *text)
00623 %
00624 %  A description of each parameter follows:
00625 %
00626 %    o wand: the Magick wand.
00627 %
00628 %    o drawing_wand: the drawing wand.
00629 %
00630 %    o text: the text.
00631 %
00632 */
00633 WandExport double *MagickQueryMultilineFontMetrics(MagickWand *wand,
00634   const DrawingWand *drawing_wand,const char *text)
00635 {
00636   double
00637     *font_metrics;
00638 
00639   DrawInfo
00640     *draw_info;
00641 
00642   MagickBooleanType
00643     status;
00644 
00645   TypeMetric
00646     metrics;
00647 
00648   assert(wand != (MagickWand *) NULL);
00649   assert(wand->signature == WandSignature);
00650   if (wand->debug != MagickFalse)
00651     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00652   assert(drawing_wand != (const DrawingWand *) NULL);
00653   if (wand->images == (Image *) NULL)
00654     {
00655       (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError,
00656         "ContainsNoImages","`%s'",wand->name);
00657       return((double *) NULL);
00658     }
00659   font_metrics=(double *) AcquireQuantumMemory(13UL,sizeof(*font_metrics));
00660   if (font_metrics == (double *) NULL)
00661     return((double *) NULL);
00662   draw_info=PeekDrawingWand(drawing_wand);
00663   if (draw_info == (DrawInfo *) NULL)
00664     {
00665       font_metrics=(double *) RelinquishMagickMemory(font_metrics);
00666       return((double *) NULL);
00667     }
00668   (void) CloneString(&draw_info->text,text);
00669   (void) ResetMagickMemory(&metrics,0,sizeof(metrics));
00670   status=GetMultilineTypeMetrics(wand->images,draw_info,&metrics);
00671   draw_info=DestroyDrawInfo(draw_info);
00672   if (status == MagickFalse)
00673     {
00674       InheritException(wand->exception,&wand->images->exception);
00675       font_metrics=(double *) RelinquishMagickMemory(font_metrics);
00676       return((double *) NULL);
00677     }
00678   font_metrics[0]=metrics.pixels_per_em.x;
00679   font_metrics[1]=metrics.pixels_per_em.y;
00680   font_metrics[2]=metrics.ascent;
00681   font_metrics[3]=metrics.descent;
00682   font_metrics[4]=metrics.width;
00683   font_metrics[5]=metrics.height;
00684   font_metrics[6]=metrics.max_advance;
00685   font_metrics[7]=metrics.bounds.x1;
00686   font_metrics[8]=metrics.bounds.y1;
00687   font_metrics[9]=metrics.bounds.x2;
00688   font_metrics[10]=metrics.bounds.y2;
00689   font_metrics[11]=metrics.origin.x;
00690   font_metrics[12]=metrics.origin.y;
00691   return(font_metrics);
00692 }
00693 
00694 /*
00695 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00696 %                                                                             %
00697 %                                                                             %
00698 %                                                                             %
00699 %   M a g i c k Q u e r y F o n t s                                           %
00700 %                                                                             %
00701 %                                                                             %
00702 %                                                                             %
00703 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00704 %
00705 %  MagickQueryFonts() returns any font that match the specified pattern (e.g.
00706 %  "*" for all).
00707 %
00708 %  The format of the MagickQueryFonts function is:
00709 %
00710 %      char **MagickQueryFonts(const char *pattern,unsigned long *number_fonts)
00711 %
00712 %  A description of each parameter follows:
00713 %
00714 %    o pattern: Specifies a pointer to a text string containing a pattern.
00715 %
00716 %    o number_fonts:  Returns the number of fonts in the list.
00717 %
00718 %
00719 */
00720 WandExport char **MagickQueryFonts(const char *pattern,
00721   unsigned long *number_fonts)
00722 {
00723   char
00724     **fonts;
00725 
00726   ExceptionInfo
00727     *exception;
00728 
00729   exception=AcquireExceptionInfo();
00730   fonts=GetTypeList(pattern,number_fonts,exception);
00731   exception=DestroyExceptionInfo(exception);
00732   return(fonts);
00733 }
00734 
00735 /*
00736 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00737 %                                                                             %
00738 %                                                                             %
00739 %                                                                             %
00740 %   M a g i c k Q u e r y F o r m a t s                                       %
00741 %                                                                             %
00742 %                                                                             %
00743 %                                                                             %
00744 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00745 %
00746 %  MagickQueryFonts() returns any image formats that match the specified
00747 %  pattern (e.g.  "*" for all).
00748 %
00749 %  The format of the MagickQueryFonts function is:
00750 %
00751 %      char **MagickQueryFonts(const char *pattern,
00752 %        unsigned long *number_formats)
00753 %
00754 %  A description of each parameter follows:
00755 %
00756 %    o pattern: Specifies a pointer to a text string containing a pattern.
00757 %
00758 %    o number_formats:  This integer returns the number of image formats in the
00759 %      list.
00760 %
00761 */
00762 WandExport char **MagickQueryFormats(const char *pattern,
00763   unsigned long *number_formats)
00764 {
00765   char
00766     **formats;
00767 
00768   ExceptionInfo
00769     *exception;
00770 
00771   exception=AcquireExceptionInfo();
00772   formats=GetMagickList(pattern,number_formats,exception);
00773   exception=DestroyExceptionInfo(exception);
00774   return(formats);
00775 }
00776 
00777 /*
00778 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00779 %                                                                             %
00780 %                                                                             %
00781 %                                                                             %
00782 %   M a g i c k R e l i n q u i s h M e m o r y                               %
00783 %                                                                             %
00784 %                                                                             %
00785 %                                                                             %
00786 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00787 %
00788 %  MagickRelinquishMemory() relinquishes memory resources returned by such
00789 %  methods as MagickIdentifyImage(), MagickGetException(), etc.
00790 %
00791 %  The format of the MagickRelinquishMemory method is:
00792 %
00793 %      void *MagickRelinquishMemory(void *resource)
00794 %
00795 %  A description of each parameter follows:
00796 %
00797 %    o resource: Relinquish the memory associated with this resource.
00798 %
00799 %
00800 */
00801 WandExport void *MagickRelinquishMemory(void *memory)
00802 {
00803   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00804   return(RelinquishMagickMemory(memory));
00805 }
00806 
00807 /*
00808 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00809 %                                                                             %
00810 %                                                                             %
00811 %                                                                             %
00812 %   M a g i c k R e s e t I t e r a t o r                                     %
00813 %                                                                             %
00814 %                                                                             %
00815 %                                                                             %
00816 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00817 %
00818 %  MagickResetIterator() resets the wand iterator.  Use it in conjunction
00819 %  with MagickNextImage() to iterate over all the images in a wand
00820 %  container.
00821 %
00822 %  The format of the MagickResetIterator method is:
00823 %
00824 %      void MagickResetIterator(MagickWand *wand)
00825 %
00826 %  A description of each parameter follows:
00827 %
00828 %    o wand: the magick wand.
00829 %
00830 */
00831 WandExport void MagickResetIterator(MagickWand *wand)
00832 {
00833   assert(wand != (MagickWand *) NULL);
00834   assert(wand->signature == WandSignature);
00835   if (wand->debug != MagickFalse)
00836     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00837   wand->active=MagickFalse;
00838   wand->pend=MagickTrue;
00839   wand->images=GetFirstImageInList(wand->images);
00840 }
00841 
00842 /*
00843 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00844 %                                                                             %
00845 %                                                                             %
00846 %                                                                             %
00847 %   M a g i c k S e t F i r s t I t e r a t o r                               %
00848 %                                                                             %
00849 %                                                                             %
00850 %                                                                             %
00851 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00852 %
00853 %  MagickSetFirstIterator() sets the wand iterator to the first image.
00854 %
00855 %  The format of the MagickSetFirstIterator method is:
00856 %
00857 %      void MagickSetFirstIterator(MagickWand *wand)
00858 %
00859 %  A description of each parameter follows:
00860 %
00861 %    o wand: the magick wand.
00862 %
00863 */
00864 WandExport void MagickSetFirstIterator(MagickWand *wand)
00865 {
00866   assert(wand != (MagickWand *) NULL);
00867   assert(wand->signature == WandSignature);
00868   if (wand->debug != MagickFalse)
00869     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00870   wand->active=MagickTrue;
00871   wand->pend=MagickFalse;
00872   wand->images=GetFirstImageInList(wand->images);
00873 }
00874 
00875 /*
00876 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00877 %                                                                             %
00878 %                                                                             %
00879 %                                                                             %
00880 %   M a g i c k S e t I t e r a t o r I n d e x                               %
00881 %                                                                             %
00882 %                                                                             %
00883 %                                                                             %
00884 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00885 %
00886 %  MagickSetIteratorIndex() set the iterator to the position in the image list
00887 %  specified with the index parameter.
00888 %
00889 %  The format of the MagickSetIteratorIndex method is:
00890 %
00891 %      MagickBooleanType MagickSetIteratorIndex(MagickWand *wand,
00892 %        const long index)
00893 %
00894 %  A description of each parameter follows:
00895 %
00896 %    o wand: the magick wand.
00897 %
00898 %    o index: the scene number.
00899 %
00900 */
00901 WandExport MagickBooleanType MagickSetIteratorIndex(MagickWand *wand,
00902   const long index)
00903 {
00904   Image
00905     *image;
00906 
00907   assert(wand != (MagickWand *) NULL);
00908   assert(wand->signature == WandSignature);
00909   if (wand->debug != MagickFalse)
00910     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00911   if (wand->images == (Image *) NULL)
00912     return(MagickFalse);
00913   image=GetImageFromList(wand->images,index);
00914   if (image == (Image *) NULL)
00915     {
00916       InheritException(wand->exception,&wand->images->exception);
00917       return(MagickFalse);
00918     }
00919   wand->active=MagickTrue;
00920   wand->pend=MagickFalse;
00921   wand->images=image;
00922   return(MagickTrue);
00923 }
00924 /*
00925 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00926 %                                                                             %
00927 %                                                                             %
00928 %                                                                             %
00929 %   M a g i c k S e t L a s t I t e r a t o r                                 %
00930 %                                                                             %
00931 %                                                                             %
00932 %                                                                             %
00933 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00934 %
00935 %  MagickSetLastIterator() sets the wand iterator to the last image.
00936 %
00937 %  The format of the MagickSetLastIterator method is:
00938 %
00939 %      void MagickSetLastIterator(MagickWand *wand)
00940 %
00941 %  A description of each parameter follows:
00942 %
00943 %    o wand: the magick wand.
00944 %
00945 */
00946 WandExport void MagickSetLastIterator(MagickWand *wand)
00947 {
00948   assert(wand != (MagickWand *) NULL);
00949   assert(wand->signature == WandSignature);
00950   if (wand->debug != MagickFalse)
00951     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
00952   wand->active=MagickFalse;
00953   wand->pend=MagickTrue;
00954   wand->images=GetLastImageInList(wand->images);
00955 }
00956 
00957 /*
00958 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00959 %                                                                             %
00960 %                                                                             %
00961 %                                                                             %
00962 %   M a g i c k W a n d G e n e s i s                                         %
00963 %                                                                             %
00964 %                                                                             %
00965 %                                                                             %
00966 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00967 %
00968 %  MagickWandGenesis() initializes the MagickWand environment.
00969 %
00970 %  The format of the MagickWandGenesis method is:
00971 %
00972 %      void MagickWandGenesis(void)
00973 %
00974 */
00975 WandExport void MagickWandGenesis(void)
00976 {
00977   if (IsMagickInstantiated() == MagickFalse)
00978     MagickCoreGenesis((char *) NULL,MagickFalse);
00979   id=AcquireWandId();
00980 }
00981 
00982 /*
00983 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00984 %                                                                             %
00985 %                                                                             %
00986 %                                                                             %
00987 %   M a g i c k W a n d T e r m i n u s                                       %
00988 %                                                                             %
00989 %                                                                             %
00990 %                                                                             %
00991 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00992 %
00993 %  MagickWandTerminus() terminates the MagickWand environment.
00994 %
00995 %  The format of the MaickWandTerminus method is:
00996 %
00997 %      void MaickWandTerminus(void)
00998 %
00999 */
01000 WandExport void MagickWandTerminus(void)
01001 {
01002   RelinquishWandId(id);
01003   MagickCoreTerminus();
01004 }
01005 
01006 /*
01007 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01008 %                                                                             %
01009 %                                                                             %
01010 %                                                                             %
01011 %   N e w M a g i c k W a n d                                                 %
01012 %                                                                             %
01013 %                                                                             %
01014 %                                                                             %
01015 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01016 %
01017 %  NewMagickWand() returns a wand required for all other methods in the API.
01018 %
01019 %  The format of the NewMagickWand method is:
01020 %
01021 %      MagickWand *NewMagickWand(void)
01022 %
01023 */
01024 WandExport MagickWand *NewMagickWand(void)
01025 {
01026   const char
01027     *quantum;
01028 
01029   MagickWand
01030     *wand;
01031 
01032   unsigned long
01033     depth;
01034 
01035   depth=MAGICKCORE_QUANTUM_DEPTH;
01036   quantum=GetMagickQuantumDepth(&depth);
01037   if (depth != MAGICKCORE_QUANTUM_DEPTH)
01038     ThrowWandFatalException(WandError,"QuantumDepthMismatch",quantum);
01039   wand=(MagickWand *) AcquireMagickMemory(sizeof(*wand));
01040   if (wand == (MagickWand *) NULL)
01041     ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
01042       strerror(errno));
01043   (void) ResetMagickMemory(wand,0,sizeof(*wand));
01044   wand->id=AcquireWandId();
01045   (void) FormatMagickString(wand->name,MaxTextExtent,"%s-%lu",MagickWandId,
01046     wand->id);
01047   wand->exception=AcquireExceptionInfo();
01048   wand->image_info=AcquireImageInfo();
01049   wand->quantize_info=CloneQuantizeInfo((QuantizeInfo *) NULL);
01050   wand->images=NewImageList();
01051   wand->debug=IsEventLogging();
01052   if (wand->debug != MagickFalse)
01053     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
01054   wand->signature=WandSignature;
01055   return(wand);
01056 }
01057 
01058 /*
01059 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01060 %                                                                             %
01061 %                                                                             %
01062 %                                                                             %
01063 %   N e w M a g i c k W a n d F r o m I m a g e                               %
01064 %                                                                             %
01065 %                                                                             %
01066 %                                                                             %
01067 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01068 %
01069 %  NewMagickWandFromImage() returns a wand with an image.
01070 %
01071 %  The format of the NewMagickWandFromImage method is:
01072 %
01073 %      MagickWand NewMagickWandFromImage(const Image *image)
01074 %
01075 %  A description of each parameter follows:
01076 %
01077 %    o image: the image.
01078 %
01079 */
01080 WandExport MagickWand *NewMagickWandFromImage(const Image *image)
01081 {
01082   MagickWand
01083     *wand;
01084 
01085   wand=NewMagickWand();
01086   wand->images=CloneImage(image,0,0,MagickTrue,wand->exception);
01087   return(wand);
01088 }

Generated on Sat Nov 22 23:45:25 2008 for MagickWand by  doxygen 1.5.7.1