1 /* 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 % % 4 % % 5 % % 6 % H H AAA L DDDD % 7 % H H A A L D D % 8 % HHHHH AAAAA L D D % 9 % H H A A L D D % 10 % H H A A LLLLL DDDD % 11 % % 12 % % 13 % Create Identity Hald CLUT Image Format % 14 % % 15 % Software Design % 16 % Cristy % 17 % July 1992 % 18 % % 19 % % 20 % Copyright 1999-2019 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 % https://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 /* 41 Include declarations. 42 */ 43 #include "MagickCore/studio.h" 44 #include "MagickCore/blob.h" 45 #include "MagickCore/blob-private.h" 46 #include "MagickCore/cache.h" 47 #include "MagickCore/colorspace.h" 48 #include "MagickCore/exception.h" 49 #include "MagickCore/exception-private.h" 50 #include "MagickCore/image.h" 51 #include "MagickCore/image-private.h" 52 #include "MagickCore/list.h" 53 #include "MagickCore/magick.h" 54 #include "MagickCore/memory_.h" 55 #include "MagickCore/module.h" 56 #include "MagickCore/monitor.h" 57 #include "MagickCore/monitor-private.h" 58 #include "MagickCore/pixel-accessor.h" 59 #include "MagickCore/quantum-private.h" 60 #include "MagickCore/resource_.h" 61 #include "MagickCore/static.h" 62 #include "MagickCore/string_.h" 63 #include "MagickCore/string-private.h" 64 #include "MagickCore/thread-private.h" 65 66 /* 68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 69 % % 70 % % 71 % % 72 % R e a d H A L D I m a g e % 73 % % 74 % % 75 % % 76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 77 % 78 % ReadHALDImage() creates a Hald color lookup table image and returns it. It 79 % allocates the memory necessary for the new Image structure and returns a 80 % pointer to the new image. 81 % 82 % The format of the ReadHALDImage method is: 83 % 84 % Image *ReadHALDImage(const ImageInfo *image_info, 85 % ExceptionInfo *exception) 86 % 87 % A description of each parameter follows: 88 % 89 % o image_info: the image info. 90 % 91 % o exception: return any errors or warnings in this structure. 92 % 93 */ 94 static Image *ReadHALDImage(const ImageInfo *image_info, 95 ExceptionInfo *exception) 96 { 97 Image 98 *image; 99 100 MagickBooleanType 101 status; 102 103 size_t 104 cube_size, 105 level; 106 107 ssize_t 108 i, 109 y; 110 111 /* 112 Create HALD color lookup table image. 113 */ 114 assert(image_info != (const ImageInfo *) NULL); 115 assert(image_info->signature == MagickCoreSignature); 116 if (image_info->debug != MagickFalse) 117 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", 118 image_info->filename); 119 assert(exception != (ExceptionInfo *) NULL); 120 assert(exception->signature == MagickCoreSignature); 121 image=AcquireImage(image_info,exception); 122 level=0; 123 if (*image_info->filename != '\0') 124 level=StringToUnsignedLong(image_info->filename); 125 if (image_info->scene != 0) 126 level=image_info->scene; 127 if ((level < 2) || (level > 256)) 128 level=8; 129 status=MagickTrue; 130 cube_size=level*level; 131 image->columns=(size_t) (level*cube_size); 132 image->rows=(size_t) (level*cube_size); 133 status=SetImageExtent(image,image->columns,image->rows,exception); 134 if (status == MagickFalse) 135 return(DestroyImageList(image)); 136 for (y=0; y < (ssize_t) image->rows; y+=(ssize_t) level) 137 { 138 ssize_t 139 blue, 140 green, 141 red; 142 143 register Quantum 144 *magick_restrict q; 145 146 if (status == MagickFalse) 147 continue; 148 q=QueueAuthenticPixels(image,0,y,image->columns,(size_t) level,exception); 149 if (q == (Quantum *) NULL) 150 { 151 status=MagickFalse; 152 continue; 153 } 154 blue=y/(ssize_t) level; 155 for (green=0; green < (ssize_t) cube_size; green++) 156 { 157 for (red=0; red < (ssize_t) cube_size; red++) 158 { 159 SetPixelRed(image,ClampToQuantum(QuantumRange*red/(cube_size-1.0)),q); 160 SetPixelGreen(image,ClampToQuantum(QuantumRange*green/(cube_size-1.0)), 161 q); 162 SetPixelBlue(image,ClampToQuantum(QuantumRange*blue/(cube_size-1.0)),q); 163 SetPixelAlpha(image,OpaqueAlpha,q); 164 q+=GetPixelChannels(image); 165 } 166 } 167 if (SyncAuthenticPixels(image,exception) == MagickFalse) 168 status=MagickFalse; 169 } 170 (void) CloseBlob(image); 171 if (status == MagickFalse) 172 return(DestroyImageList(image)); 173 if (image_info->scene != 0) 174 for (i=0; i < (ssize_t) image_info->scene; i++) 175 AppendImageToList(&image,CloneImage(image,0,0,MagickTrue,exception)); 176 return(GetFirstImageInList(image)); 177 } 178 179 /* 181 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 182 % % 183 % % 184 % % 185 % R e g i s t e r H A L D I m a g e % 186 % % 187 % % 188 % % 189 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 190 % 191 % RegisterHALDImage() adds attributes for the Hald color lookup table image 192 % format to the list of supported formats. The attributes include the image 193 % format tag, a method to read and/or write the format, whether the format 194 % supports the saving of more than one frame to the same file or blob, whether 195 % the format supports native in-memory I/O, and a brief description of the 196 % format. 197 % 198 % The format of the RegisterHALDImage method is: 199 % 200 % size_t RegisterHALDImage(void) 201 % 202 */ 203 ModuleExport size_t RegisterHALDImage(void) 204 { 205 MagickInfo 206 *entry; 207 208 entry=AcquireMagickInfo("HALD","HALD", 209 "Identity Hald color lookup table image"); 210 entry->decoder=(DecodeImageHandler *) ReadHALDImage; 211 entry->flags^=CoderAdjoinFlag; 212 entry->format_type=ImplicitFormatType; 213 entry->flags|=CoderRawSupportFlag; 214 entry->flags|=CoderEndianSupportFlag; 215 (void) RegisterMagickInfo(entry); 216 return(MagickImageCoderSignature); 217 } 218 219 /* 221 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 222 % % 223 % % 224 % % 225 % U n r e g i s t e r H A L D I m a g e % 226 % % 227 % % 228 % % 229 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 230 % 231 % UnregisterHALDImage() removes format registrations made by the 232 % HALD module from the list of supported formats. 233 % 234 % The format of the UnregisterHALDImage method is: 235 % 236 % UnregisterHALDImage(void) 237 % 238 */ 239 ModuleExport void UnregisterHALDImage(void) 240 { 241 (void) UnregisterMagickInfo("HALD"); 242 } 243