cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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 % |
cristy | de984cd | 2013-12-01 14:49:27 +0000 | [diff] [blame] | 16 | % Cristy % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 17 | % July 1992 % |
| 18 | % % |
| 19 | % % |
Cristy | 7ce65e7 | 2015-12-12 18:03:16 -0500 | [diff] [blame] | 20 | % Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 42 | #include "MagickCore/studio.h" |
| 43 | #include "MagickCore/blob.h" |
| 44 | #include "MagickCore/blob-private.h" |
| 45 | #include "MagickCore/cache.h" |
| 46 | #include "MagickCore/colorspace.h" |
| 47 | #include "MagickCore/exception.h" |
| 48 | #include "MagickCore/exception-private.h" |
| 49 | #include "MagickCore/image.h" |
| 50 | #include "MagickCore/image-private.h" |
| 51 | #include "MagickCore/list.h" |
| 52 | #include "MagickCore/magick.h" |
| 53 | #include "MagickCore/memory_.h" |
| 54 | #include "MagickCore/module.h" |
| 55 | #include "MagickCore/monitor.h" |
| 56 | #include "MagickCore/monitor-private.h" |
| 57 | #include "MagickCore/pixel-accessor.h" |
| 58 | #include "MagickCore/quantum-private.h" |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 59 | #include "MagickCore/resource_.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 60 | #include "MagickCore/static.h" |
| 61 | #include "MagickCore/string_.h" |
| 62 | #include "MagickCore/string-private.h" |
cristy | ccfffb4 | 2012-05-06 01:17:48 +0000 | [diff] [blame] | 63 | #include "MagickCore/thread-private.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 64 | |
| 65 | /* |
| 66 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 67 | % % |
| 68 | % % |
| 69 | % % |
| 70 | % R e a d H A L D I m a g e % |
| 71 | % % |
| 72 | % % |
| 73 | % % |
| 74 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 75 | % |
| 76 | % ReadHALDImage() creates a Hald color lookup table image and returns it. It |
| 77 | % allocates the memory necessary for the new Image structure and returns a |
| 78 | % pointer to the new image. |
| 79 | % |
| 80 | % The format of the ReadHALDImage method is: |
| 81 | % |
| 82 | % Image *ReadHALDImage(const ImageInfo *image_info, |
| 83 | % ExceptionInfo *exception) |
| 84 | % |
| 85 | % A description of each parameter follows: |
| 86 | % |
| 87 | % o image_info: the image info. |
| 88 | % |
| 89 | % o exception: return any errors or warnings in this structure. |
| 90 | % |
| 91 | */ |
| 92 | static Image *ReadHALDImage(const ImageInfo *image_info, |
| 93 | ExceptionInfo *exception) |
| 94 | { |
| 95 | Image |
| 96 | *image; |
| 97 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 98 | MagickBooleanType |
| 99 | status; |
| 100 | |
| 101 | size_t |
| 102 | cube_size, |
| 103 | level; |
| 104 | |
cristy | ebc891a | 2011-04-24 23:04:16 +0000 | [diff] [blame] | 105 | ssize_t |
| 106 | y; |
| 107 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 108 | /* |
| 109 | Create HALD color lookup table image. |
| 110 | */ |
| 111 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 112 | assert(image_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 113 | if (image_info->debug != MagickFalse) |
| 114 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 115 | image_info->filename); |
| 116 | assert(exception != (ExceptionInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 117 | assert(exception->signature == MagickCoreSignature); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 118 | image=AcquireImage(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 119 | level=0; |
| 120 | if (*image_info->filename != '\0') |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 121 | level=StringToUnsignedLong(image_info->filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 122 | if (level < 2) |
| 123 | level=8; |
| 124 | status=MagickTrue; |
| 125 | cube_size=level*level; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 126 | image->columns=(size_t) (level*cube_size); |
| 127 | image->rows=(size_t) (level*cube_size); |
cristy | acabb84 | 2014-12-14 23:36:33 +0000 | [diff] [blame] | 128 | status=SetImageExtent(image,image->columns,image->rows,exception); |
| 129 | if (status == MagickFalse) |
| 130 | return(DestroyImageList(image)); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 131 | for (y=0; y < (ssize_t) image->rows; y+=(ssize_t) level) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 132 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 133 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 134 | blue, |
| 135 | green, |
| 136 | red; |
| 137 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 138 | register Quantum |
dirk | 05d2ff7 | 2015-11-18 23:13:43 +0100 | [diff] [blame] | 139 | *magick_restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 140 | |
| 141 | if (status == MagickFalse) |
| 142 | continue; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 143 | q=QueueAuthenticPixels(image,0,y,image->columns,(size_t) level, |
cristy | aa74011 | 2010-03-30 17:58:44 +0000 | [diff] [blame] | 144 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 145 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 146 | { |
| 147 | status=MagickFalse; |
| 148 | continue; |
| 149 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 150 | blue=y/(ssize_t) level; |
| 151 | for (green=0; green < (ssize_t) cube_size; green++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 152 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 153 | for (red=0; red < (ssize_t) cube_size; red++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 154 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 155 | SetPixelRed(image,ClampToQuantum(QuantumRange*red/(cube_size-1.0)),q); |
cristy | 78778cb | 2012-01-17 14:48:47 +0000 | [diff] [blame] | 156 | SetPixelGreen(image,ClampToQuantum(QuantumRange*green/(cube_size-1.0)), |
| 157 | q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 158 | SetPixelBlue(image,ClampToQuantum(QuantumRange*blue/(cube_size-1.0)),q); |
| 159 | SetPixelAlpha(image,OpaqueAlpha,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 160 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 161 | } |
| 162 | } |
cristy | aa74011 | 2010-03-30 17:58:44 +0000 | [diff] [blame] | 163 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 164 | status=MagickFalse; |
| 165 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 166 | return(GetFirstImageInList(image)); |
| 167 | } |
| 168 | |
| 169 | /* |
| 170 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 171 | % % |
| 172 | % % |
| 173 | % % |
| 174 | % R e g i s t e r H A L D I m a g e % |
| 175 | % % |
| 176 | % % |
| 177 | % % |
| 178 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 179 | % |
| 180 | % RegisterHALDImage() adds attributes for the Hald color lookup table image |
| 181 | % format to the list of supported formats. The attributes include the image |
| 182 | % format tag, a method to read and/or write the format, whether the format |
| 183 | % supports the saving of more than one frame to the same file or blob, whether |
| 184 | % the format supports native in-memory I/O, and a brief description of the |
| 185 | % format. |
| 186 | % |
| 187 | % The format of the RegisterHALDImage method is: |
| 188 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 189 | % size_t RegisterHALDImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 190 | % |
| 191 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 192 | ModuleExport size_t RegisterHALDImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 193 | { |
| 194 | MagickInfo |
| 195 | *entry; |
| 196 | |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 197 | entry=AcquireMagickInfo("HALD","HALD", |
| 198 | "Identity Hald color lookup table image"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 199 | entry->decoder=(DecodeImageHandler *) ReadHALDImage; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 200 | entry->flags^=CoderAdjoinFlag; |
cristy | 009d739 | 2010-07-25 22:08:41 +0000 | [diff] [blame] | 201 | entry->format_type=ImplicitFormatType; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 202 | entry->flags|=CoderRawSupportFlag; |
| 203 | entry->flags|=CoderEndianSupportFlag; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 204 | (void) RegisterMagickInfo(entry); |
| 205 | return(MagickImageCoderSignature); |
| 206 | } |
| 207 | |
| 208 | /* |
| 209 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 210 | % % |
| 211 | % % |
| 212 | % % |
| 213 | % U n r e g i s t e r H A L D I m a g e % |
| 214 | % % |
| 215 | % % |
| 216 | % % |
| 217 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 218 | % |
| 219 | % UnregisterHALDImage() removes format registrations made by the |
| 220 | % HALD module from the list of supported formats. |
| 221 | % |
| 222 | % The format of the UnregisterHALDImage method is: |
| 223 | % |
| 224 | % UnregisterHALDImage(void) |
| 225 | % |
| 226 | */ |
| 227 | ModuleExport void UnregisterHALDImage(void) |
| 228 | { |
| 229 | (void) UnregisterMagickInfo("HALD"); |
| 230 | } |