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/caption.c

Go to the documentation of this file.
00001 /* 00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00003 % % 00004 % % 00005 % % 00006 % CCCC AAA PPPP TTTTT IIIII OOO N N % 00007 % C A A P P T I O O NN N % 00008 % C AAAAA PPPP T I O O N N N % 00009 % C A A P T I O O N NN % 00010 % CCCC A A P T IIIII OOO N N % 00011 % % 00012 % % 00013 % Read Text Caption. % 00014 % % 00015 % Software Design % 00016 % John Cristy % 00017 % February 2002 % 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 00057 /* 00058 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00059 % % 00060 % % 00061 % % 00062 % R e a d C A P T I O N I m a g e % 00063 % % 00064 % % 00065 % % 00066 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00067 % 00068 % ReadCAPTIONImage() reads a CAPTION image file and returns it. It 00069 % allocates the memory necessary for the new Image structure and returns a 00070 % pointer to the new image. 00071 % 00072 % The format of the ReadCAPTIONImage method is: 00073 % 00074 % Image *ReadCAPTIONImage(const ImageInfo *image_info, 00075 % ExceptionInfo *exception) 00076 % 00077 % A description of each parameter follows: 00078 % 00079 % o image_info: The image info. 00080 % 00081 % o exception: return any errors or warnings in this structure. 00082 % 00083 % 00084 */ 00085 static Image *ReadCAPTIONImage(const ImageInfo *image_info, 00086 ExceptionInfo *exception) 00087 { 00088 char 00089 *caption, 00090 geometry[MaxTextExtent]; 00091 00092 DrawInfo 00093 *draw_info; 00094 00095 Image 00096 *image; 00097 00098 MagickBooleanType 00099 status; 00100 00101 register char 00102 *p, 00103 *q; 00104 00105 register long 00106 i; 00107 00108 TypeMetric 00109 metrics; 00110 00111 /* 00112 Initialize Image structure. 00113 */ 00114 assert(image_info != (const ImageInfo *) NULL); 00115 assert(image_info->signature == MagickSignature); 00116 if (image_info->debug != MagickFalse) 00117 (void) LogMagickEvent(TraceEvent,GetMagickModule(),image_info->filename); 00118 assert(exception != (ExceptionInfo *) NULL); 00119 assert(exception->signature == MagickSignature); 00120 image=AllocateImage(image_info); 00121 if (image->columns == 0) 00122 ThrowReaderException(OptionError,"MustSpecifyImageSize"); 00123 if (*image_info->filename != '@') 00124 caption=AcquireString(image_info->filename); 00125 else 00126 { 00127 size_t 00128 length; 00129 00130 /* 00131 Read caption. 00132 */ 00133 (void) CopyMagickString(image->filename,image_info->filename+1, 00134 MaxTextExtent-2); 00135 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); 00136 if (status == MagickFalse) 00137 { 00138 DestroyImageList(image); 00139 return((Image *) NULL); 00140 } 00141 length=MaxTextExtent; 00142 caption=AcquireString((char *) NULL); 00143 p=caption; 00144 while (ReadBlobString(image,p) != (char *) NULL) 00145 { 00146 p+=strlen(p); 00147 if ((size_t) (p-caption+MaxTextExtent) < length) 00148 continue; 00149 length<<=1; 00150 caption=(char *) ResizeMagickMemory(caption, 00151 (length+MaxTextExtent)*sizeof(*caption)); 00152 if (caption == (char *) NULL) 00153 break; 00154 p=caption+strlen(caption); 00155 } 00156 if (caption == (char *) NULL) 00157 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); 00158 CloseBlob(image); 00159 } 00160 /* 00161 Format caption. 00162 */ 00163 draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL); 00164 draw_info->fill=image_info->pen; 00165 draw_info->text=AcquireString(caption); 00166 p=caption; 00167 q=draw_info->text; 00168 for (i=0; *p != '\0'; p++) 00169 { 00170 *q++=(*p); 00171 *q='\0'; 00172 status=GetTypeMetrics(image,draw_info,&metrics); 00173 if (status == MagickFalse) 00174 ThrowReaderException(TypeError,"UnableToGetTypeMetrics"); 00175 if ((metrics.width+metrics.max_advance/2) < (double) image->columns) 00176 continue; 00177 for (p--; (isspace((int) ((unsigned char) *p)) == 0) && (p > caption); p--); 00178 *p++='\n'; 00179 q=draw_info->text; 00180 i++; 00181 } 00182 if (image->rows == 0) 00183 image->rows=(unsigned long) ((i+1)*(metrics.ascent-metrics.descent)); 00184 SetImage(image,OpaqueOpacity); 00185 /* 00186 Draw caption. 00187 */ 00188 (void) strcpy(draw_info->text,caption); 00189 (void) FormatMagickString(geometry,MaxTextExtent,"+%g+%g", 00190 metrics.max_advance/4,metrics.ascent); 00191 draw_info->geometry=AcquireString(geometry); 00192 (void) AnnotateImage(image,draw_info); 00193 draw_info=DestroyDrawInfo(draw_info); 00194 caption=(char *) RelinquishMagickMemory(caption); 00195 return(GetFirstImageInList(image)); 00196 } 00197 00198 /* 00199 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00200 % % 00201 % % 00202 % % 00203 % R e g i s t e r C A P T I O N I m a g e % 00204 % % 00205 % % 00206 % % 00207 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00208 % 00209 % RegisterCAPTIONImage() adds attributes for the CAPTION image format to 00210 % the list of supported formats. The attributes include the image format 00211 % tag, a method to read and/or write the format, whether the format 00212 % supports the saving of more than one frame to the same file or blob, 00213 % whether the format supports native in-memory I/O, and a brief 00214 % description of the format. 00215 % 00216 % The format of the RegisterCAPTIONImage method is: 00217 % 00218 % RegisterCAPTIONImage(void) 00219 % 00220 */ 00221 ModuleExport void RegisterCAPTIONImage(void) 00222 { 00223 MagickInfo 00224 *entry; 00225 00226 entry=SetMagickInfo("CAPTION"); 00227 entry->decoder=(DecoderHandler *) ReadCAPTIONImage; 00228 entry->adjoin=MagickFalse; 00229 entry->description=AcquireString("Image caption"); 00230 entry->module=AcquireString("CAPTION"); 00231 (void) RegisterMagickInfo(entry); 00232 } 00233 00234 /* 00235 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00236 % % 00237 % % 00238 % % 00239 % U n r e g i s t e r C A P T I O N I m a g e % 00240 % % 00241 % % 00242 % % 00243 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00244 % 00245 % UnregisterCAPTIONImage() removes format registrations made by the 00246 % CAPTION module from the list of supported formats. 00247 % 00248 % The format of the UnregisterCAPTIONImage method is: 00249 % 00250 % UnregisterCAPTIONImage(void) 00251 % 00252 */ 00253 ModuleExport void UnregisterCAPTIONImage(void) 00254 { 00255 (void) UnregisterMagickInfo("CAPTION"); 00256 }

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