]> granicus.if.org Git - imagemagick/blob - coders/info.c
(no commit message)
[imagemagick] / coders / info.c
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %                                                                             %
4 %                                                                             %
5 %                                                                             %
6 %                        IIIII  N   N  FFFFF   OOO                            %
7 %                          I    NN  N  F      O   O                           %
8 %                          I    N N N  FFF    O   O                           %
9 %                          I    N  NN  F      O   O                           %
10 %                        IIIII  N   N  F       OOO                            %
11 %                                                                             %
12 %                                                                             %
13 %                         Write Info About the Image.                         %
14 %                                                                             %
15 %                              Software Design                                %
16 %                                John Cristy                                  %
17 %                                 July 1992                                   %
18 %                                                                             %
19 %                                                                             %
20 %  Copyright 1999-2011 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 %
37 */
38 \f
39 /*
40   Include declarations.
41 */
42 #include "magick/studio.h"
43 #include "magick/property.h"
44 #include "magick/blob.h"
45 #include "magick/blob-private.h"
46 #include "magick/colorspace.h"
47 #include "magick/exception.h"
48 #include "magick/exception-private.h"
49 #include "magick/identify.h"
50 #include "magick/image.h"
51 #include "magick/image-private.h"
52 #include "magick/list.h"
53 #include "magick/magick.h"
54 #include "magick/memory_.h"
55 #include "magick/monitor.h"
56 #include "magick/monitor-private.h"
57 #include "magick/option.h"
58 #include "magick/quantum-private.h"
59 #include "magick/static.h"
60 #include "magick/string_.h"
61 #include "magick/module.h"
62 #include "magick/utility.h"
63 \f
64 /*
65   Forward declarations.
66 */
67 static MagickBooleanType
68   WriteINFOImage(const ImageInfo *,Image *);
69 \f
70 /*
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 %                                                                             %
73 %                                                                             %
74 %                                                                             %
75 %   R e g i s t e r I N F O I m a g e                                         %
76 %                                                                             %
77 %                                                                             %
78 %                                                                             %
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 %
81 %  RegisterINFOImage() adds attributes for the INFO image format to
82 %  the list of supported formats.  The attributes include the image format
83 %  tag, a method to read and/or write the format, whether the format
84 %  supports the saving of more than one frame to the same file or blob,
85 %  whether the format supports native in-memory I/O, and a brief
86 %  description of the format.
87 %
88 %  The format of the RegisterINFOImage method is:
89 %
90 %      size_t RegisterINFOImage(void)
91 %
92 */
93 ModuleExport size_t RegisterINFOImage(void)
94 {
95   MagickInfo
96     *entry;
97
98   entry=SetMagickInfo("INFO");
99   entry->encoder=(EncodeImageHandler *) WriteINFOImage;
100   entry->blob_support=MagickFalse;
101   entry->description=ConstantString("The image format and characteristics");
102   entry->module=ConstantString("INFO");
103   (void) RegisterMagickInfo(entry);
104   return(MagickImageCoderSignature);
105 }
106 \f
107 /*
108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109 %                                                                             %
110 %                                                                             %
111 %                                                                             %
112 %   U n r e g i s t e r I N F O I m a g e                                     %
113 %                                                                             %
114 %                                                                             %
115 %                                                                             %
116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117 %
118 %  UnregisterINFOImage() removes format registrations made by the
119 %  INFO module from the list of supported formats.
120 %
121 %  The format of the UnregisterINFOImage method is:
122 %
123 %      UnregisterINFOImage(void)
124 %
125 */
126 ModuleExport void UnregisterINFOImage(void)
127 {
128   (void) UnregisterMagickInfo("INFO");
129 }
130 \f
131 /*
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133 %                                                                             %
134 %                                                                             %
135 %                                                                             %
136 %   W r i t e I N F O I m a g e                                               %
137 %                                                                             %
138 %                                                                             %
139 %                                                                             %
140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141 %
142 %  WriteINFOImage writes the pixel values as text numbers.
143 %
144 %  The format of the WriteINFOImage method is:
145 %
146 %      MagickBooleanType WriteINFOImage(const ImageInfo *image_info,
147 %        Image *image)
148 %
149 %  A description of each parameter follows.
150 %
151 %    o image_info: the image info.
152 %
153 %    o image:  The image.
154 %
155 */
156 static MagickBooleanType WriteINFOImage(const ImageInfo *image_info,
157   Image *image)
158 {
159   const char
160     *format;
161
162   MagickBooleanType
163     status;
164
165   MagickOffsetType
166     scene;
167
168   /*
169     Open output image file.
170   */
171   assert(image_info != (const ImageInfo *) NULL);
172   assert(image_info->signature == MagickSignature);
173   assert(image != (Image *) NULL);
174   assert(image->signature == MagickSignature);
175   if (image->debug != MagickFalse)
176     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
177   status=OpenBlob(image_info,image,WriteBlobMode,&image->exception);
178   if (status == MagickFalse)
179     return(status);
180   scene=0;
181   do
182   {
183     format=GetImageOption(image_info,"format");
184     if (format == (char *) NULL)
185       {
186         (void) CopyMagickString(image->filename,image->magick_filename,
187           MaxTextExtent);
188         image->magick_columns=image->columns;
189         image->magick_rows=image->rows;
190         (void) IdentifyImage(image,GetBlobFileHandle(image),
191           image_info->verbose);
192       }
193     else
194       {
195         char
196           *text;
197
198         text=InterpretImageProperties(image_info,image,format);
199         if (text != (char *) NULL)
200           {
201             (void) WriteBlobString(image,text);
202             (void) WriteBlobString(image,"\n");
203             text=DestroyString(text);
204           }
205       }
206     if (GetNextImageInList(image) == (Image *) NULL)
207       break;
208     image=SyncNextImageInList(image);
209     status=SetImageProgress(image,SaveImagesTag,scene++,
210       GetImageListLength(image));
211     if (status == MagickFalse)
212       break;
213   } while (image_info->adjoin != MagickFalse);
214   (void) CloseBlob(image);
215   return(MagickTrue);
216 }