Powered by Pair ImageMagick logo
Image Magick
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages

ImageMagick-6.1.1/coders/label.c

Go to the documentation of this file.
00001 /* 00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00003 % % 00004 % % 00005 % % 00006 % L AAA BBBB EEEEE L % 00007 % L A A B B E L % 00008 % L AAAAA BBBB EEE L % 00009 % L A A B B E L % 00010 % LLLLL A A BBBB EEEEE LLLLL % 00011 % % 00012 % % 00013 % Read ASCII String As An Image. % 00014 % % 00015 % Software Design % 00016 % John Cristy % 00017 % July 1992 % 00018 % % 00019 % % 00020 % Copyright 1999-2004 ImageMagick Studio LLC, a non-profit organization % 00021 % dedicated to making software imaging solutions freely available. % 00022 % % 00023 % You may not use this file except in compliance with the License. You may % 00024 % obtain a copy of the License at % 00025 % % 00026 % http://www.imagemagick.org/www/Copyright.html % 00027 % % 00028 % Unless required by applicable law or agreed to in writing, software % 00029 % distributed under the License is distributed on an "AS IS" BASIS, % 00030 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % 00031 % See the License for the specific language governing permissions and % 00032 % limitations under the License. % 00033 % % 00034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00035 % 00036 % 00037 */ 00038 00039 /* 00040 Include declarations. 00041 */ 00042 #include "magick/studio.h" 00043 #include "magick/annotate.h" 00044 #include "magick/blob.h" 00045 #include "magick/blob_private.h" 00046 #include "magick/draw.h" 00047 #include "magick/error.h" 00048 #include "magick/error_private.h" 00049 #include "magick/image.h" 00050 #include "magick/image_private.h" 00051 #include "magick/list.h" 00052 #include "magick/magick.h" 00053 #include "magick/memory_.h" 00054 #include "magick/static.h" 00055 #include "magick/string_.h" 00056 #include "magick/utility.h" 00057 00058 /* 00059 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00060 % % 00061 % % 00062 % % 00063 % R e a d L A B E L I m a g e % 00064 % % 00065 % % 00066 % % 00067 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00068 % 00069 % ReadLABELImage() reads a LABEL image file and returns it. It 00070 % allocates the memory necessary for the new Image structure and returns a 00071 % pointer to the new image. 00072 % 00073 % The format of the ReadLABELImage method is: 00074 % 00075 % Image *ReadLABELImage(const ImageInfo *image_info, 00076 % ExceptionInfo *exception) 00077 % 00078 % A description of each parameter follows: 00079 % 00080 % o image_info: The image info. 00081 % 00082 % o exception: return any errors or warnings in this structure. 00083 % 00084 % 00085 */ 00086 static Image *ReadLABELImage(const ImageInfo *image_info, 00087 ExceptionInfo *exception) 00088 { 00089 char 00090 geometry[MaxTextExtent]; 00091 00092 DrawInfo 00093 *draw_info; 00094 00095 Image 00096 *image; 00097 00098 MagickBooleanType 00099 status; 00100 00101 TypeMetric 00102 metrics; 00103 00104 unsigned long 00105 height, 00106 width; 00107 00108 /* 00109 Initialize Image structure. 00110 */ 00111 assert(image_info != (const ImageInfo *) NULL); 00112 assert(image_info->signature == MagickSignature); 00113 if (image_info->debug != MagickFalse) 00114 (void) LogMagickEvent(TraceEvent,GetMagickModule(),image_info->filename); 00115 assert(exception != (ExceptionInfo *) NULL); 00116 assert(exception->signature == MagickSignature); 00117 image=AllocateImage(image_info); 00118 draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL); 00119 draw_info->fill=image_info->pen; 00120 draw_info->text=TranslateText(image_info,image,image_info->filename); 00121 if (draw_info->text == (char *) NULL) 00122 ThrowReaderException(CoderError,"UnableToTranslateText"); 00123 if ((image->columns != 0) || (image->rows != 0)) 00124 { 00125 /* 00126 Fit label to canvas size. 00127 */ 00128 status=GetTypeMetrics(image,draw_info,&metrics); 00129 for ( ; status != MagickFalse; draw_info->pointsize*=2) 00130 { 00131 width=(unsigned long) (metrics.width+metrics.max_advance/2+0.5); 00132 height=(unsigned long) (metrics.ascent-metrics.descent+0.5); 00133 if (((image->columns != 0) && (width >= image->columns)) || 00134 ((image->rows != 0) && (height >= image->rows))) 00135 break; 00136 status=GetTypeMetrics(image,draw_info,&metrics); 00137 } 00138 for ( ; status != MagickFalse; draw_info->pointsize--) 00139 { 00140 width=(unsigned long) (metrics.width+metrics.max_advance/2+0.5); 00141 height=(unsigned long) (metrics.ascent-metrics.descent+0.5); 00142 if ((image->columns != 0) && (width <= image->columns) && 00143 ((image->rows == 0) || (height <= image->rows))) 00144 break; 00145 if ((image->rows != 0) && (height <= image->rows) && 00146 ((image->columns == 0) || (width <= image->columns))) 00147 break; 00148 if (draw_info->pointsize < 2.0) 00149 break; 00150 status=GetTypeMetrics(image,draw_info,&metrics); 00151 } 00152 } 00153 status=GetTypeMetrics(image,draw_info,&metrics); 00154 if (status == MagickFalse) 00155 ThrowReaderException(TypeError,"UnableToGetTypeMetrics"); 00156 (void) FormatMagickString(geometry,MaxTextExtent,"+%g+%g", 00157 metrics.max_advance/4,metrics.ascent); 00158 if (image->columns == 0) 00159 image->columns=(unsigned long) (metrics.width+metrics.max_advance/2+0.5); 00160 if (image->rows == 0) 00161 { 00162 image->rows=(unsigned long) (metrics.ascent-metrics.descent+0.5); 00163 (void) FormatMagickString(geometry,MaxTextExtent,"+%g+%g", 00164 image->columns/2.0-metrics.width/2.0,metrics.ascent); 00165 } 00166 draw_info->geometry=AcquireString(geometry); 00167 SetImage(image,OpaqueOpacity); 00168 (void) AnnotateImage(image,draw_info); 00169 draw_info=DestroyDrawInfo(draw_info); 00170 return(GetFirstImageInList(image)); 00171 } 00172 00173 /* 00174 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00175 % % 00176 % % 00177 % % 00178 % R e g i s t e r L A B E L I m a g e % 00179 % % 00180 % % 00181 % % 00182 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00183 % 00184 % RegisterLABELImage() adds attributes for the LABEL image format to 00185 % the list of supported formats. The attributes include the image format 00186 % tag, a method to read and/or write the format, whether the format 00187 % supports the saving of more than one frame to the same file or blob, 00188 % whether the format supports native in-memory I/O, and a brief 00189 % description of the format. 00190 % 00191 % The format of the RegisterLABELImage method is: 00192 % 00193 % RegisterLABELImage(void) 00194 % 00195 */ 00196 ModuleExport void RegisterLABELImage(void) 00197 { 00198 MagickInfo 00199 *entry; 00200 00201 entry=SetMagickInfo("LABEL"); 00202 entry->decoder=(DecoderHandler *) ReadLABELImage; 00203 entry->adjoin=MagickFalse; 00204 entry->description=AcquireString("Image label"); 00205 entry->module=AcquireString("LABEL"); 00206 (void) RegisterMagickInfo(entry); 00207 } 00208 00209 /* 00210 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00211 % % 00212 % % 00213 % % 00214 % U n r e g i s t e r L A B E L I m a g e % 00215 % % 00216 % % 00217 % % 00218 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00219 % 00220 % UnregisterLABELImage() removes format registrations made by the 00221 % LABEL module from the list of supported formats. 00222 % 00223 % The format of the UnregisterLABELImage method is: 00224 % 00225 % UnregisterLABELImage(void) 00226 % 00227 */ 00228 ModuleExport void UnregisterLABELImage(void) 00229 { 00230 (void) UnregisterMagickInfo("LABEL"); 00231 }

Generated on Mon Oct 25 13:40:37 2004 for ImageMagick by doxygen 1.3.7
ImageMagick Copyright © 2004, ImageMagick Studio LLC