null.c revision 3ed852eea50f9d4cd633efb8c2b054b8e33c2530
1/* 2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3% % 4% % 5% % 6% N N U U L L % 7% NN N U U L L % 8% N N N U U L L % 9% N NN U U L L % 10% N N UUU LLLLL LLLLL % 11% % 12% % 13% Read/Write Image Of Uniform Color. % 14% % 15% Software Design % 16% John Cristy % 17% July 1992 % 18% % 19% % 20% Copyright 1999-2009 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 39/* 40 Include declarations. 41*/ 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-private.h" 49#include "magick/exception.h" 50#include "magick/exception-private.h" 51#include "magick/image.h" 52#include "magick/image-private.h" 53#include "magick/list.h" 54#include "magick/magick.h" 55#include "magick/memory_.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 62/* 63 Forward declarations. 64*/ 65static MagickBooleanType 66 WriteNULLImage(const ImageInfo *,Image *); 67 68/* 69%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 70% % 71% % 72% % 73% R e a d N U L L I m a g e % 74% % 75% % 76% % 77%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 78% 79% ReadNULLImage creates a constant image and initializes it to the 80% X server color as specified by the filename. It allocates the memory 81% necessary for the new Image structure and returns a pointer to the new 82% image. 83% 84% The format of the ReadNULLImage method is: 85% 86% Image *ReadNULLImage(const ImageInfo *image_info, 87% ExceptionInfo *exception) 88% 89% A description of each parameter follows: 90% 91% o image_info: the image info. 92% 93% o exception: return any errors or warnings in this structure. 94% 95*/ 96static Image *ReadNULLImage(const ImageInfo *image_info, 97 ExceptionInfo *exception) 98{ 99 Image 100 *image; 101 102 long 103 y; 104 105 MagickPixelPacket 106 background; 107 108 register IndexPacket 109 *indexes; 110 111 register long 112 x; 113 114 register PixelPacket 115 *q; 116 117 /* 118 Initialize Image structure. 119 */ 120 assert(image_info != (const ImageInfo *) NULL); 121 assert(image_info->signature == MagickSignature); 122 if (image_info->debug != MagickFalse) 123 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", 124 image_info->filename); 125 assert(exception != (ExceptionInfo *) NULL); 126 assert(exception->signature == MagickSignature); 127 image=AcquireImage(image_info); 128 if (image->columns == 0) 129 image->columns=1; 130 if (image->rows == 0) 131 image->rows=1; 132 image->matte=MagickTrue; 133 GetMagickPixelPacket(image,&background); 134 background.opacity=(MagickRealType) TransparentOpacity; 135 if (image->colorspace == CMYKColorspace) 136 ConvertRGBToCMYK(&background); 137 for (y=0; y < (long) image->rows; y++) 138 { 139 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); 140 if (q == (PixelPacket *) NULL) 141 break; 142 indexes=GetAuthenticIndexQueue(image); 143 for (x=0; x < (long) image->columns; x++) 144 { 145 SetPixelPacket(image,&background,q,indexes); 146 q++; 147 indexes++; 148 } 149 if (SyncAuthenticPixels(image,exception) == MagickFalse) 150 break; 151 } 152 return(GetFirstImageInList(image)); 153} 154 155/* 156%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 157% % 158% % 159% % 160% R e g i s t e r N U L L I m a g e % 161% % 162% % 163% % 164%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 165% 166% RegisterNULLImage() adds attributes for the NULL image format to 167% the list of supported formats. The attributes include the image format 168% tag, a method to read and/or write the format, whether the format 169% supports the saving of more than one frame to the same file or blob, 170% whether the format supports native in-memory I/O, and a brief 171% description of the format. 172% 173% The format of the RegisterNULLImage method is: 174% 175% unsigned long RegisterNULLImage(void) 176% 177*/ 178ModuleExport unsigned long RegisterNULLImage(void) 179{ 180 MagickInfo 181 *entry; 182 183 entry=SetMagickInfo("NULL"); 184 entry->decoder=(DecodeImageHandler *) ReadNULLImage; 185 entry->encoder=(EncodeImageHandler *) WriteNULLImage; 186 entry->adjoin=MagickFalse; 187 entry->format_type=ExplicitFormatType; 188 entry->description=ConstantString("Constant image of uniform color"); 189 entry->module=ConstantString("NULL"); 190 (void) RegisterMagickInfo(entry); 191 return(MagickImageCoderSignature); 192} 193 194/* 195%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 196% % 197% % 198% % 199% U n r e g i s t e r N U L L I m a g e % 200% % 201% % 202% % 203%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 204% 205% UnregisterNULLImage() removes format registrations made by the 206% NULL module from the list of supported formats. 207% 208% The format of the UnregisterNULLImage method is: 209% 210% UnregisterNULLImage(void) 211% 212*/ 213ModuleExport void UnregisterNULLImage(void) 214{ 215 (void) UnregisterMagickInfo("NULL"); 216} 217 218/* 219%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 220% % 221% % 222% % 223% W r i t e N U L L I m a g e % 224% % 225% % 226% % 227%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 228% 229% WriteNULLImage writes no output at all. It is useful when specified 230% as an output format when profiling. 231% 232% The format of the WriteNULLImage method is: 233% 234% MagickBooleanType WriteNULLImage(const ImageInfo *image_info, 235% Image *image) 236% 237% A description of each parameter follows. 238% 239% o image_info: the image info. 240% 241% o image: The image. 242% 243*/ 244static MagickBooleanType WriteNULLImage(const ImageInfo *image_info, 245 Image *image) 246{ 247 assert(image_info != (const ImageInfo *) NULL); 248 assert(image_info->signature == MagickSignature); 249 assert(image != (Image *) NULL); 250 assert(image->signature == MagickSignature); 251 if (image->debug != MagickFalse) 252 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); 253 return(MagickTrue); 254} 255