null.c revision b56bb24a985ca4366713bcd8ffdfacbb48a98a2f
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% Cristy % 17% July 1992 % 18% % 19% % 20% Copyright 1999-2015 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 "MagickCore/studio.h" 43#include "MagickCore/blob.h" 44#include "MagickCore/blob-private.h" 45#include "MagickCore/cache.h" 46#include "MagickCore/color.h" 47#include "MagickCore/color-private.h" 48#include "MagickCore/colorspace-private.h" 49#include "MagickCore/exception.h" 50#include "MagickCore/exception-private.h" 51#include "MagickCore/image.h" 52#include "MagickCore/image-private.h" 53#include "MagickCore/list.h" 54#include "MagickCore/magick.h" 55#include "MagickCore/memory_.h" 56#include "MagickCore/pixel-accessor.h" 57#include "MagickCore/quantum-private.h" 58#include "MagickCore/static.h" 59#include "MagickCore/string_.h" 60#include "MagickCore/module.h" 61 62/* 63 Forward declarations. 64*/ 65static MagickBooleanType 66 WriteNULLImage(const ImageInfo *,Image *,ExceptionInfo *); 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 PixelInfo 103 background; 104 105 register ssize_t 106 x; 107 108 register Quantum 109 *q; 110 111 ssize_t 112 y; 113 114 /* 115 Initialize Image structure. 116 */ 117 assert(image_info != (const ImageInfo *) NULL); 118 assert(image_info->signature == MagickSignature); 119 if (image_info->debug != MagickFalse) 120 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", 121 image_info->filename); 122 assert(exception != (ExceptionInfo *) NULL); 123 assert(exception->signature == MagickSignature); 124 image=AcquireImage(image_info,exception); 125 if (image->columns == 0) 126 image->columns=1; 127 if (image->rows == 0) 128 image->rows=1; 129 ConformPixelInfo(image,&image->background_color,&background,exception); 130 image->alpha_trait=BlendPixelTrait; 131 background.alpha=(double) TransparentAlpha; 132 for (y=0; y < (ssize_t) image->rows; y++) 133 { 134 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); 135 if (q == (Quantum *) NULL) 136 break; 137 for (x=0; x < (ssize_t) image->columns; x++) 138 { 139 SetPixelInfoPixel(image,&background,q); 140 q+=GetPixelChannels(image); 141 } 142 if (SyncAuthenticPixels(image,exception) == MagickFalse) 143 break; 144 } 145 return(GetFirstImageInList(image)); 146} 147 148/* 149%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 150% % 151% % 152% % 153% R e g i s t e r N U L L I m a g e % 154% % 155% % 156% % 157%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 158% 159% RegisterNULLImage() adds attributes for the NULL image format to 160% the list of supported formats. The attributes include the image format 161% tag, a method to read and/or write the format, whether the format 162% supports the saving of more than one frame to the same file or blob, 163% whether the format supports native in-memory I/O, and a brief 164% description of the format. 165% 166% The format of the RegisterNULLImage method is: 167% 168% size_t RegisterNULLImage(void) 169% 170*/ 171ModuleExport size_t RegisterNULLImage(void) 172{ 173 MagickInfo 174 *entry; 175 176 entry=SetMagickInfo("NULL"); 177 entry->decoder=(DecodeImageHandler *) ReadNULLImage; 178 entry->encoder=(EncodeImageHandler *) WriteNULLImage; 179 entry->adjoin=MagickFalse; 180 entry->format_type=ImplicitFormatType; 181 entry->description=ConstantString("Constant image of uniform color"); 182 entry->module=ConstantString("NULL"); 183 (void) RegisterMagickInfo(entry); 184 return(MagickImageCoderSignature); 185} 186 187/* 188%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 189% % 190% % 191% % 192% U n r e g i s t e r N U L L I m a g e % 193% % 194% % 195% % 196%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 197% 198% UnregisterNULLImage() removes format registrations made by the 199% NULL module from the list of supported formats. 200% 201% The format of the UnregisterNULLImage method is: 202% 203% UnregisterNULLImage(void) 204% 205*/ 206ModuleExport void UnregisterNULLImage(void) 207{ 208 (void) UnregisterMagickInfo("NULL"); 209} 210 211/* 212%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 213% % 214% % 215% % 216% W r i t e N U L L I m a g e % 217% % 218% % 219% % 220%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 221% 222% WriteNULLImage writes no output at all. It is useful when specified 223% as an output format when profiling. 224% 225% The format of the WriteNULLImage method is: 226% 227% MagickBooleanType WriteNULLImage(const ImageInfo *image_info, 228% Image *image,ExceptionInfo *exception) 229% 230% A description of each parameter follows. 231% 232% o image_info: the image info. 233% 234% o image: The image. 235% 236% o exception: return any errors or warnings in this structure. 237% 238*/ 239static MagickBooleanType WriteNULLImage(const ImageInfo *image_info, 240 Image *image,ExceptionInfo *exception) 241{ 242 assert(image_info != (const ImageInfo *) NULL); 243 assert(image_info->signature == MagickSignature); 244 assert(image != (Image *) NULL); 245 assert(image->signature == MagickSignature); 246 assert(exception != (ExceptionInfo *) NULL); 247 if (image->debug != MagickFalse) 248 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); 249 return(MagickTrue); 250} 251