2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Write X-Motif UIL Table. %
20 % Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
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. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "magick/studio.h"
43 #include "magick/blob.h"
44 #include "magick/blob-private.h"
45 #include "magick/cache.h"
46 #include "magick/color.h"
47 #include "magick/color-private.h"
48 #include "magick/colorspace.h"
49 #include "magick/exception.h"
50 #include "magick/exception-private.h"
51 #include "magick/image-private.h"
52 #include "magick/magick.h"
53 #include "magick/memory_.h"
54 #include "magick/monitor.h"
55 #include "magick/monitor-private.h"
56 #include "magick/pixel-private.h"
57 #include "magick/quantum-private.h"
58 #include "magick/static.h"
59 #include "magick/string_.h"
60 #include "magick/module.h"
61 #include "magick/utility.h"
66 static MagickBooleanType
67 WriteUILImage(const ImageInfo *,Image *);
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74 % R e g i s t e r U I L I m a g e %
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 % RegisterUILImage() adds attributes for the UIL image format to
81 % the list of supported formats. The attributes include the image format
82 % tag, a method to read and/or write the format, whether the format
83 % supports the saving of more than one frame to the same file or blob,
84 % whether the format supports native in-memory I/O, and a brief
85 % description of the format.
87 % The format of the RegisterUILImage method is:
89 % unsigned long RegisterUILImage(void)
92 ModuleExport unsigned long RegisterUILImage(void)
97 entry=SetMagickInfo("UIL");
98 entry->encoder=(EncodeImageHandler *) WriteUILImage;
99 entry->adjoin=MagickFalse;
100 entry->description=ConstantString("X-Motif UIL table");
101 entry->module=ConstantString("UIL");
102 (void) RegisterMagickInfo(entry);
103 return(MagickImageCoderSignature);
107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111 % U n r e g i s t e r U I L I m a g e %
115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117 % UnregisterUILImage() removes format registrations made by the
118 % UIL module from the list of supported formats.
120 % The format of the UnregisterUILImage method is:
122 % UnregisterUILImage(void)
125 ModuleExport void UnregisterUILImage(void)
127 (void) UnregisterMagickInfo("UIL");
131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135 % W r i t e U I L I m a g e %
139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141 % Procedure WriteUILImage() writes an image to a file in the X-Motif UIL table
144 % The format of the WriteUILImage method is:
146 % MagickBooleanType WriteUILImage(const ImageInfo *image_info,Image *image)
148 % A description of each parameter follows.
150 % o image_info: the image info.
152 % o image: The image.
155 static MagickBooleanType WriteUILImage(const ImageInfo *image_info,Image *image)
160 basename[MaxTextExtent],
161 buffer[MaxTextExtent],
185 register const IndexPacket
188 register const PixelPacket
196 Cixel[MaxCixels+1] = " .XoO+@#$%&*=-;:>,<1234567890qwertyuipasdfghjk"
197 "lzxcvbnmMNBVCZASDFGHJKLPIUYTREWQ!~^/()_`'][{}|";
200 characters_per_pixel,
204 Open output image file.
206 assert(image_info != (const ImageInfo *) NULL);
207 assert(image_info->signature == MagickSignature);
208 assert(image != (Image *) NULL);
209 assert(image->signature == MagickSignature);
210 if (image->debug != MagickFalse)
211 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
212 status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
213 if (status == MagickFalse)
215 if (image->colorspace != RGBColorspace)
216 (void) TransformImageColorspace(image,RGBColorspace);
217 exception=(&image->exception);
218 transparent=MagickFalse;
220 p=(const PixelPacket *) NULL;
221 if (image->storage_class == PseudoClass)
222 colors=image->colors;
229 Convert DirectClass to PseudoClass image.
231 matte_image=(unsigned char *) NULL;
232 if (image->matte != MagickFalse)
235 Map all the transparent pixels.
237 number_pixels=(MagickSizeType) image->columns*image->rows;
238 if (number_pixels != ((MagickSizeType) (size_t) number_pixels))
239 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
240 matte_image=(unsigned char *) AcquireQuantumMemory(image->columns,
241 image->rows*sizeof(*matte_image));
242 if (matte_image == (unsigned char *) NULL)
243 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
244 for (y=0; y < (long) image->rows; y++)
246 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
247 if (p == (const PixelPacket *) NULL)
249 for (x=0; x < (long) image->columns; x++)
251 matte_image[i]=(unsigned char)
252 (p->opacity == (Quantum) TransparentOpacity ? 1 : 0);
253 if (matte_image[i] != 0)
254 transparent=MagickTrue;
260 (void) SetImageType(image,PaletteType);
261 colors=image->colors;
262 if (transparent != MagickFalse)
271 for (y=0; y < (long) image->rows; y++)
273 q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
274 if (q == (PixelPacket *) NULL)
276 indexes=GetAuthenticIndexQueue(image);
277 for (x=0; x < (long) image->columns; x++)
279 if (matte_image[i] != 0)
280 indexes[x]=(IndexPacket) image->colors;
285 if (matte_image != (unsigned char *) NULL)
286 matte_image=(unsigned char *) RelinquishMagickMemory(matte_image);
289 Compute the character per pixel.
291 characters_per_pixel=1;
292 for (k=MaxCixels; (long) colors > k; k*=MaxCixels)
293 characters_per_pixel++;
297 symbol=AcquireString("");
298 (void) WriteBlobString(image,"/* UIL */\n");
299 GetPathComponent(image->filename,BasePath,basename);
300 (void) FormatMagickString(buffer,MaxTextExtent,
301 "value\n %s_ct : color_table(\n",basename);
302 (void) WriteBlobString(image,buffer);
303 GetMagickPixelPacket(image,&pixel);
304 for (i=0; i < (long) colors; i++)
309 SetMagickPixelPacket(image,image->colormap+i,(IndexPacket *) NULL,&pixel);
310 pixel.colorspace=RGBColorspace;
312 pixel.opacity=(MagickRealType) OpaqueOpacity;
313 GetColorTuple(&pixel,MagickTrue,name);
314 if (transparent != MagickFalse)
315 if (i == (long) (colors-1))
316 (void) CopyMagickString(name,"None",MaxTextExtent);
322 for (j=1; j < (int) characters_per_pixel; j++)
324 k=((i-k)/MaxCixels) % MaxCixels;
328 (void) SubstituteString(&symbol,"'","''");
329 if (LocaleCompare(name,"None") == 0)
330 (void) FormatMagickString(buffer,MaxTextExtent,
331 " background color = '%s'",symbol);
333 (void) FormatMagickString(buffer,MaxTextExtent,
334 " color('%s',%s) = '%s'",name,
335 PixelIntensityToQuantum(image->colormap+i) <
336 ((Quantum) QuantumRange/2) ? "background" : "foreground",symbol);
337 (void) WriteBlobString(image,buffer);
338 (void) FormatMagickString(buffer,MaxTextExtent,"%s",
339 (i == (long) (colors-1) ? ");\n" : ",\n"));
340 (void) WriteBlobString(image,buffer);
345 GetPathComponent(image->filename,BasePath,basename);
346 (void) FormatMagickString(buffer,MaxTextExtent,
347 " %s_icon : icon(color_table = %s_ct,\n",basename,basename);
348 (void) WriteBlobString(image,buffer);
349 for (y=0; y < (long) image->rows; y++)
351 p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
352 if (p == (const PixelPacket *) NULL)
354 indexes=GetVirtualIndexQueue(image);
355 (void) WriteBlobString(image," \"");
356 for (x=0; x < (long) image->columns; x++)
358 k=((long) indexes[x] % MaxCixels);
360 for (j=1; j < (int) characters_per_pixel; j++)
362 k=(((int) indexes[x]-k)/MaxCixels) % MaxCixels;
366 (void) CopyMagickString(buffer,symbol,MaxTextExtent);
367 (void) WriteBlobString(image,buffer);
370 (void) FormatMagickString(buffer,MaxTextExtent,"\"%s\n",
371 (y == (long) (image->rows-1) ? ");" : ","));
372 (void) WriteBlobString(image,buffer);
373 status=SetImageProgress(image,SaveImageTag,y,image->rows);
374 if (status == MagickFalse)
377 symbol=DestroyString(symbol);
378 (void) CloseBlob(image);