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