cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
cristy | ebc891a | 2011-04-24 23:04:16 +0000 | [diff] [blame] | 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % IIIIIIIIII PPPPPPPP LL % |
| 7 | % II PP PP LL % |
| 8 | % II PP PP LL % |
| 9 | % II PP PP LL % |
| 10 | % II PPPPPPPP LL % |
| 11 | % II PP LL % |
| 12 | % II PP LL % |
| 13 | % IIIIIIIIII PP LLLLLLLL % |
| 14 | % % |
| 15 | % % |
| 16 | % % |
| 17 | % Read/Write Scanalytics IPLab Image Format % |
| 18 | % Sean Burke % |
| 19 | % 2008.05.07 % |
| 20 | % v 0.9 % |
| 21 | % % |
cristy | b56bb24 | 2014-11-25 17:12:48 +0000 | [diff] [blame] | 22 | % Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization % |
cristy | ebc891a | 2011-04-24 23:04:16 +0000 | [diff] [blame] | 23 | % dedicated to making software imaging solutions freely available. % |
| 24 | % % |
| 25 | % You may not use this file except in compliance with the License. You may % |
| 26 | % obtain a copy of the License at % |
| 27 | % % |
| 28 | % http://www.imagemagick.org/script/license.php % |
| 29 | % % |
| 30 | % Unless required by applicable law or agreed to in writing, software % |
| 31 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 32 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 33 | % See the License for the specific language governing permissions and % |
| 34 | % limitations under the License. % |
| 35 | % % |
| 36 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 37 | % |
| 38 | % |
| 39 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 40 | |
| 41 | /* |
| 42 | Include declarations. |
| 43 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 44 | #include "MagickCore/studio.h" |
| 45 | #include "MagickCore/blob.h" |
| 46 | #include "MagickCore/blob-private.h" |
| 47 | #include "MagickCore/cache.h" |
| 48 | #include "MagickCore/colorspace.h" |
cristy | 510d06a | 2011-07-06 23:43:54 +0000 | [diff] [blame] | 49 | #include "MagickCore/colorspace-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 50 | #include "MagickCore/exception.h" |
| 51 | #include "MagickCore/exception-private.h" |
| 52 | #include "MagickCore/image.h" |
| 53 | #include "MagickCore/image-private.h" |
| 54 | #include "MagickCore/list.h" |
| 55 | #include "MagickCore/magick.h" |
| 56 | #include "MagickCore/memory_.h" |
| 57 | #include "MagickCore/monitor.h" |
| 58 | #include "MagickCore/monitor-private.h" |
| 59 | #include "MagickCore/option.h" |
| 60 | #include "MagickCore/property.h" |
| 61 | #include "MagickCore/quantum-private.h" |
| 62 | #include "MagickCore/static.h" |
| 63 | #include "MagickCore/string_.h" |
| 64 | #include "MagickCore/module.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 65 | |
| 66 | /* |
| 67 | Tyedef declarations |
| 68 | */ |
| 69 | |
| 70 | typedef struct _IPLInfo |
| 71 | { |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 72 | unsigned int |
| 73 | tag, |
| 74 | size, |
| 75 | time, |
| 76 | z, |
| 77 | width, |
| 78 | height, |
| 79 | colors, |
| 80 | depth, |
| 81 | byteType; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 82 | } IPLInfo; |
| 83 | |
| 84 | static MagickBooleanType |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 85 | WriteIPLImage(const ImageInfo *,Image *,ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 86 | |
cristy | 58b6d83 | 2013-05-15 11:49:56 +0000 | [diff] [blame] | 87 | /* |
cristy | 4189984 | 2013-05-12 18:29:53 +0000 | [diff] [blame] | 88 | static void increase (void *pixel, int byteType){ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 89 | switch(byteType){ |
| 90 | case 0:(*((unsigned char *) pixel))++; break; |
| 91 | case 1:(*((signed int *) pixel))++; break; |
| 92 | case 2:(*((unsigned int *) pixel))++; break; |
| 93 | case 3:(*((signed long *) pixel))++; break; |
| 94 | default:(*((unsigned int *) pixel))++; break; |
| 95 | } |
| 96 | } |
cristy | 58b6d83 | 2013-05-15 11:49:56 +0000 | [diff] [blame] | 97 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 98 | |
| 99 | /* |
| 100 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 101 | % % |
| 102 | % % |
| 103 | % % |
| 104 | % I s I P L % |
| 105 | % % |
| 106 | % % |
| 107 | % % |
| 108 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 109 | % |
| 110 | % IsIPL() returns MagickTrue if the image format type, identified by the |
| 111 | % magick string, is IPL. |
| 112 | % |
| 113 | % The format of the IsIPL method is: |
| 114 | % |
| 115 | % MagickBooleanType IsIPL(const unsigned char *magick,const size_t length) |
| 116 | % |
| 117 | % A description of each parameter follows: |
| 118 | % |
| 119 | % o magick: compare image format pattern against these bytes. |
| 120 | % |
| 121 | % o length: Specifies the length of the magick string. |
| 122 | % |
| 123 | */ |
| 124 | static MagickBooleanType IsIPL(const unsigned char *magick,const size_t length) |
| 125 | { |
| 126 | if (length < 4) |
| 127 | return(MagickFalse); |
| 128 | if (LocaleNCompare((const char *) magick,"data",4) == 0) |
| 129 | return(MagickTrue); |
| 130 | return(MagickFalse); |
| 131 | } |
| 132 | |
| 133 | /* |
| 134 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 135 | % % |
| 136 | % % |
| 137 | % % |
| 138 | % R e a d I P L I m a g e % |
| 139 | % % |
| 140 | % % |
| 141 | % % |
| 142 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 143 | % |
| 144 | % ReadIPLImage() reads a Scanalytics IPLab image file and returns it. It |
| 145 | % allocates the memory necessary for the new Image structure and returns a |
| 146 | % pointer to the new image. |
| 147 | % |
| 148 | % According to the IPLab spec, the data is blocked out in five dimensions: |
| 149 | % { t, z, c, y, x }. When we return the image, the latter three are folded |
| 150 | % into the standard "Image" structure. The "scenes" (image_info->scene) |
| 151 | % correspond to the order: { {t0,z0}, {t0, z1}, ..., {t1,z0}, {t1,z1}... } |
| 152 | % The number of scenes is t*z. |
| 153 | % |
| 154 | % The format of the ReadIPLImage method is: |
| 155 | % |
| 156 | % Image *ReadIPLImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 157 | % |
| 158 | % A description of each parameter follows: |
| 159 | % |
| 160 | % o image_info: The image info. |
| 161 | % |
| 162 | % o exception: return any errors or warnings in this structure. |
| 163 | % |
| 164 | */ |
| 165 | |
cristy | 4189984 | 2013-05-12 18:29:53 +0000 | [diff] [blame] | 166 | static void SetHeaderFromIPL(Image *image, IPLInfo *ipl){ |
cristy | c5de699 | 2009-10-06 19:19:48 +0000 | [diff] [blame] | 167 | image->columns = ipl->width; |
| 168 | image->rows = ipl->height; |
| 169 | image->depth = ipl->depth; |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 170 | image->resolution.x = 1; |
| 171 | image->resolution.y = 1; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | |
| 175 | static Image *ReadIPLImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 176 | { |
| 177 | |
| 178 | /* |
| 179 | Declare variables |
| 180 | */ |
| 181 | Image *image; |
| 182 | |
| 183 | MagickBooleanType status; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 184 | register Quantum *q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 185 | unsigned char magick[12], *pixels; |
| 186 | ssize_t count; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 187 | ssize_t y; |
| 188 | size_t t_count=0; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 189 | size_t length; |
| 190 | IPLInfo |
| 191 | ipl_info; |
| 192 | QuantumFormatType |
| 193 | quantum_format; |
| 194 | QuantumInfo |
| 195 | *quantum_info; |
| 196 | QuantumType |
| 197 | quantum_type; |
| 198 | |
| 199 | /* |
| 200 | Open Image |
| 201 | */ |
| 202 | |
| 203 | assert(image_info != (const ImageInfo *) NULL); |
| 204 | assert(image_info->signature == MagickSignature); |
| 205 | if ( image_info->debug != MagickFalse) |
| 206 | (void) LogMagickEvent(TraceEvent, GetMagickModule(), "%s", |
| 207 | image_info->filename); |
| 208 | assert(exception != (ExceptionInfo *) NULL); |
| 209 | assert(exception->signature == MagickSignature); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 210 | image=AcquireImage(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 211 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 212 | if (status == MagickFalse) |
| 213 | { |
| 214 | image=DestroyImageList(image); |
| 215 | return((Image *) NULL); |
| 216 | } |
| 217 | |
| 218 | /* |
| 219 | Read IPL image |
| 220 | */ |
| 221 | |
| 222 | /* |
| 223 | Determine endianness |
| 224 | If we get back "iiii", we have LSB,"mmmm", MSB |
| 225 | */ |
| 226 | count=ReadBlob(image,4,magick); |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 227 | (void) count; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 228 | if((LocaleNCompare((char *) magick,"iiii",4) == 0)) |
| 229 | image->endian=LSBEndian; |
| 230 | else{ |
| 231 | if((LocaleNCompare((char *) magick,"mmmm",4) == 0)) |
| 232 | image->endian=MSBEndian; |
| 233 | else{ |
| 234 | ThrowReaderException(CorruptImageError, "ImproperImageHeader"); |
| 235 | } |
| 236 | } |
| 237 | /* Skip o'er the next 8 bytes (garbage) */ |
| 238 | count=ReadBlob(image, 8, magick); |
| 239 | /* |
| 240 | Excellent, now we read the header unimpeded. |
| 241 | */ |
| 242 | count=ReadBlob(image,4,magick); |
| 243 | if((LocaleNCompare((char *) magick,"data",4) != 0)) |
| 244 | ThrowReaderException(CorruptImageError, "ImproperImageHeader"); |
| 245 | ipl_info.size=ReadBlobLong(image); |
| 246 | ipl_info.width=ReadBlobLong(image); |
| 247 | ipl_info.height=ReadBlobLong(image); |
| 248 | if((ipl_info.width == 0UL) || (ipl_info.height == 0UL)) |
| 249 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| 250 | ipl_info.colors=ReadBlobLong(image); |
cristy | e2c4f18 | 2012-05-12 14:11:53 +0000 | [diff] [blame] | 251 | if(ipl_info.colors == 3){ SetImageColorspace(image,sRGBColorspace,exception);} |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 252 | else { image->colorspace = GRAYColorspace; } |
| 253 | ipl_info.z=ReadBlobLong(image); |
| 254 | ipl_info.time=ReadBlobLong(image); |
| 255 | |
| 256 | ipl_info.byteType=ReadBlobLong(image); |
| 257 | |
| 258 | |
| 259 | /* Initialize Quantum Info */ |
| 260 | |
| 261 | switch (ipl_info.byteType) { |
| 262 | case 0: |
| 263 | ipl_info.depth=8; |
| 264 | quantum_format = UnsignedQuantumFormat; |
| 265 | break; |
| 266 | case 1: |
| 267 | ipl_info.depth=16; |
| 268 | quantum_format = SignedQuantumFormat; |
| 269 | break; |
| 270 | case 2: |
| 271 | ipl_info.depth=16; |
| 272 | quantum_format = UnsignedQuantumFormat; |
| 273 | break; |
| 274 | case 3: |
| 275 | ipl_info.depth=32; |
| 276 | quantum_format = SignedQuantumFormat; |
| 277 | break; |
| 278 | case 4: ipl_info.depth=32; |
| 279 | quantum_format = FloatingPointQuantumFormat; |
| 280 | break; |
| 281 | case 5: |
| 282 | ipl_info.depth=8; |
| 283 | quantum_format = UnsignedQuantumFormat; |
| 284 | break; |
| 285 | case 6: |
| 286 | ipl_info.depth=16; |
| 287 | quantum_format = UnsignedQuantumFormat; |
| 288 | break; |
| 289 | case 10: |
| 290 | ipl_info.depth=64; |
| 291 | quantum_format = FloatingPointQuantumFormat; |
| 292 | break; |
| 293 | default: |
| 294 | ipl_info.depth=16; |
| 295 | quantum_format = UnsignedQuantumFormat; |
| 296 | break; |
| 297 | } |
| 298 | |
| 299 | /* |
| 300 | Set number of scenes of image |
| 301 | */ |
| 302 | |
| 303 | SetHeaderFromIPL(image, &ipl_info); |
| 304 | |
| 305 | /* Thats all we need if we are pinging. */ |
| 306 | if (image_info->ping != MagickFalse) |
cristy | acabb84 | 2014-12-14 23:36:33 +0000 | [diff] [blame] | 307 | { |
| 308 | (void) CloseBlob(image); |
| 309 | return(GetFirstImageInList(image)); |
| 310 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 311 | length=image->columns; |
| 312 | quantum_type=GetQuantumType(image,exception); |
| 313 | do |
| 314 | { |
| 315 | SetHeaderFromIPL(image, &ipl_info); |
| 316 | |
cristy | acabb84 | 2014-12-14 23:36:33 +0000 | [diff] [blame] | 317 | if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 318 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 319 | break; |
cristy | acabb84 | 2014-12-14 23:36:33 +0000 | [diff] [blame] | 320 | status=SetImageExtent(image,image->columns,image->rows,exception); |
| 321 | if (status == MagickFalse) |
| 322 | return(DestroyImageList(image)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 323 | /* |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 324 | printf("Length: %.20g, Memory size: %.20g\n", (double) length,(double) |
| 325 | image->depth); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 326 | */ |
cristy | 5f766ef | 2014-12-14 21:12:47 +0000 | [diff] [blame] | 327 | quantum_info=AcquireQuantumInfo(image_info,image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 328 | if (quantum_info == (QuantumInfo *) NULL) |
| 329 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 330 | status=SetQuantumFormat(image,quantum_info,quantum_format); |
| 331 | if (status == MagickFalse) |
| 332 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 333 | pixels=GetQuantumPixels(quantum_info); |
| 334 | if(image->columns != ipl_info.width){ |
| 335 | /* |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 336 | printf("Columns not set correctly! Wanted: %.20g, got: %.20g\n", |
| 337 | (double) ipl_info.width, (double) image->columns); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 338 | */ |
| 339 | } |
| 340 | |
| 341 | /* |
| 342 | Covert IPL binary to pixel packets |
| 343 | */ |
| 344 | |
| 345 | if(ipl_info.colors == 1){ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 346 | for(y = 0; y < (ssize_t) image->rows; y++){ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 347 | (void) ReadBlob(image, length*image->depth/8, pixels); |
| 348 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 349 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 350 | break; |
cristy | c5de699 | 2009-10-06 19:19:48 +0000 | [diff] [blame] | 351 | (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 352 | GrayQuantum,pixels,exception); |
| 353 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 354 | break; |
cristy | c5de699 | 2009-10-06 19:19:48 +0000 | [diff] [blame] | 355 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 356 | } |
| 357 | else{ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 358 | for(y = 0; y < (ssize_t) image->rows; y++){ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 359 | (void) ReadBlob(image, length*image->depth/8, pixels); |
| 360 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 361 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 362 | break; |
cristy | c5de699 | 2009-10-06 19:19:48 +0000 | [diff] [blame] | 363 | (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
| 364 | RedQuantum,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 365 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 366 | break; |
| 367 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 368 | for(y = 0; y < (ssize_t) image->rows; y++){ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 369 | (void) ReadBlob(image, length*image->depth/8, pixels); |
| 370 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 371 | if (q == (Quantum *) NULL) |
cristy | ebc891a | 2011-04-24 23:04:16 +0000 | [diff] [blame] | 372 | break; |
cristy | c5de699 | 2009-10-06 19:19:48 +0000 | [diff] [blame] | 373 | (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 374 | GreenQuantum,pixels,exception); |
| 375 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 376 | break; |
| 377 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 378 | for(y = 0; y < (ssize_t) image->rows; y++){ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 379 | (void) ReadBlob(image, length*image->depth/8, pixels); |
| 380 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 381 | if (q == (Quantum *) NULL) |
cristy | ebc891a | 2011-04-24 23:04:16 +0000 | [diff] [blame] | 382 | break; |
cristy | c5de699 | 2009-10-06 19:19:48 +0000 | [diff] [blame] | 383 | (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 384 | BlueQuantum,pixels,exception); |
| 385 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 386 | break; |
| 387 | } |
| 388 | } |
| 389 | SetQuantumImageType(image,quantum_type); |
| 390 | |
| 391 | t_count++; |
| 392 | quantum_info = DestroyQuantumInfo(quantum_info); |
| 393 | |
| 394 | if (EOFBlob(image) != MagickFalse) |
| 395 | { |
| 396 | ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", |
| 397 | image->filename); |
| 398 | break; |
| 399 | } |
| 400 | if(t_count < ipl_info.z * ipl_info.time){ |
| 401 | /* |
| 402 | Proceed to next image. |
| 403 | */ |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 404 | AcquireNextImage(image_info,image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 405 | if (GetNextImageInList(image) == (Image *) NULL) |
| 406 | { |
| 407 | image=DestroyImageList(image); |
| 408 | return((Image *) NULL); |
| 409 | } |
| 410 | image=SyncNextImageInList(image); |
| 411 | status=SetImageProgress(image,LoadImagesTag,TellBlob(image), |
| 412 | GetBlobSize(image)); |
| 413 | if (status == MagickFalse) |
| 414 | break; |
| 415 | } |
| 416 | } while (t_count < ipl_info.z*ipl_info.time); |
| 417 | CloseBlob(image); |
| 418 | return(GetFirstImageInList(image)); |
| 419 | } |
| 420 | |
| 421 | /* |
| 422 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 423 | % % |
| 424 | % % |
| 425 | % % |
| 426 | % R e g i s t e r I P L I m a g e % |
| 427 | % % |
| 428 | % % |
| 429 | % % |
| 430 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 431 | % |
| 432 | % RegisterIPLImage() add attributes for the Scanalytics IPL image format to the |
| 433 | % list of supported formats. |
| 434 | % |
| 435 | % |
| 436 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 437 | ModuleExport size_t RegisterIPLImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 438 | { |
| 439 | MagickInfo |
| 440 | *entry; |
| 441 | |
| 442 | entry=SetMagickInfo("IPL"); |
| 443 | entry->decoder=(DecodeImageHandler *) ReadIPLImage; |
| 444 | entry->encoder=(EncodeImageHandler *) WriteIPLImage; |
| 445 | entry->magick=(IsImageFormatHandler *) IsIPL; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame^] | 446 | entry->flags|=CoderEndianSupportFlag; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 447 | entry->description=ConstantString("IPL Image Sequence"); |
| 448 | entry->module=ConstantString("IPL"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 449 | (void) RegisterMagickInfo(entry); |
| 450 | return(MagickImageCoderSignature); |
| 451 | } |
| 452 | |
| 453 | /* |
| 454 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 455 | % % |
| 456 | % % |
| 457 | % % |
| 458 | % U n r e g i s t e r I P L I m a g e % |
| 459 | % % |
| 460 | % % |
| 461 | % % |
| 462 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 463 | % |
| 464 | % UnregisterIPLImage() removes format registrations made by the |
| 465 | % IPL module from the list of supported formats. |
| 466 | % |
| 467 | % The format of the UnregisterIPLImage method is: |
| 468 | % |
| 469 | % UnregisterIPLImage(void) |
| 470 | % |
| 471 | */ |
| 472 | ModuleExport void UnregisterIPLImage(void) |
| 473 | { |
| 474 | (void) UnregisterMagickInfo("IPL"); |
| 475 | } |
| 476 | |
| 477 | /* |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 478 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 479 | % % |
| 480 | % % |
| 481 | % % |
| 482 | % W r i t e I P L I m a g e % |
| 483 | % % |
| 484 | % % |
| 485 | % % |
| 486 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 487 | % |
| 488 | % WriteIPLImage() writes an image to a file in Scanalytics IPLabimage format. |
| 489 | % |
| 490 | % The format of the WriteIPLImage method is: |
| 491 | % |
| 492 | % MagickBooleanType WriteIPLImage(const ImageInfo *image_info,Image *image) |
| 493 | % Image *image,ExceptionInfo *exception) |
| 494 | % |
| 495 | % A description of each parameter follows. |
| 496 | % |
| 497 | % o image_info: The image info. |
| 498 | % |
| 499 | % o image: The image. |
| 500 | % |
| 501 | % o exception: return any errors or warnings in this structure. |
| 502 | % |
| 503 | */ |
| 504 | static MagickBooleanType WriteIPLImage(const ImageInfo *image_info,Image *image, |
| 505 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 506 | { |
cristy | ebc891a | 2011-04-24 23:04:16 +0000 | [diff] [blame] | 507 | IPLInfo |
| 508 | ipl_info; |
| 509 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 510 | MagickBooleanType |
| 511 | status; |
| 512 | |
| 513 | MagickOffsetType |
| 514 | scene; |
| 515 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 516 | register const Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 517 | *p; |
| 518 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 519 | QuantumInfo |
| 520 | *quantum_info; |
| 521 | |
cristy | ebc891a | 2011-04-24 23:04:16 +0000 | [diff] [blame] | 522 | ssize_t |
| 523 | y; |
| 524 | |
| 525 | unsigned char |
| 526 | *pixels; |
| 527 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 528 | /* |
| 529 | Open output image file. |
| 530 | */ |
| 531 | assert(image_info != (const ImageInfo *) NULL); |
| 532 | assert(image_info->signature == MagickSignature); |
| 533 | assert(image != (Image *) NULL); |
| 534 | assert(image->signature == MagickSignature); |
| 535 | if (image->debug != MagickFalse) |
| 536 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 537 | assert(exception != (ExceptionInfo *) NULL); |
| 538 | assert(exception->signature == MagickSignature); |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 539 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 540 | if (status == MagickFalse) |
| 541 | return(status); |
| 542 | scene=0; |
| 543 | |
| 544 | |
cristy | 5f766ef | 2014-12-14 21:12:47 +0000 | [diff] [blame] | 545 | quantum_info=AcquireQuantumInfo(image_info,image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 546 | if ((quantum_info->format == UndefinedQuantumFormat) && |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 547 | (IsHighDynamicRangeImage(image,exception) != MagickFalse)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 548 | SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat); |
| 549 | switch(quantum_info->depth){ |
| 550 | case 8: |
| 551 | ipl_info.byteType = 0; |
| 552 | break; |
| 553 | case 16: |
| 554 | if(quantum_info->format == SignedQuantumFormat){ |
| 555 | ipl_info.byteType = 2; |
| 556 | } |
| 557 | else{ |
| 558 | ipl_info.byteType = 1; |
| 559 | } |
| 560 | break; |
| 561 | case 32: |
| 562 | if(quantum_info->format == FloatingPointQuantumFormat){ |
| 563 | ipl_info.byteType = 3; |
| 564 | } |
| 565 | else{ |
| 566 | ipl_info.byteType = 4; |
| 567 | } |
| 568 | break; |
| 569 | case 64: |
| 570 | ipl_info.byteType = 10; |
| 571 | break; |
| 572 | default: |
| 573 | ipl_info.byteType = 2; |
| 574 | break; |
| 575 | |
| 576 | } |
cristy | 0b29b25 | 2010-05-30 01:59:46 +0000 | [diff] [blame] | 577 | ipl_info.z = (unsigned int) GetImageListLength(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 578 | /* There is no current method for detecting whether we have T or Z stacks */ |
| 579 | ipl_info.time = 1; |
cristy | 0b29b25 | 2010-05-30 01:59:46 +0000 | [diff] [blame] | 580 | ipl_info.width = (unsigned int) image->columns; |
| 581 | ipl_info.height = (unsigned int) image->rows; |
cristy | af8d391 | 2014-02-21 14:50:33 +0000 | [diff] [blame] | 582 | (void) TransformImageColorspace(image,sRGBColorspace,exception); |
cristy | cd8b331 | 2013-12-22 01:51:11 +0000 | [diff] [blame] | 583 | if(IssRGBCompatibleColorspace(image->colorspace) != MagickFalse) { ipl_info.colors = 3; } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 584 | else{ ipl_info.colors = 1; } |
| 585 | |
cristy | 0b29b25 | 2010-05-30 01:59:46 +0000 | [diff] [blame] | 586 | ipl_info.size = (unsigned int) (28 + |
| 587 | ((image->depth)/8)*ipl_info.height*ipl_info.width*ipl_info.colors*ipl_info.z); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 588 | |
| 589 | /* Ok! Calculations are done. Lets write this puppy down! */ |
| 590 | |
| 591 | /* |
| 592 | Write IPL header. |
| 593 | */ |
| 594 | /* Shockingly (maybe not if you have used IPLab), IPLab itself CANNOT read MSBEndian |
| 595 | files! The reader above can, but they cannot. For compatability reasons, I will leave |
| 596 | the code in here, but it is all but useless if you want to use IPLab. */ |
| 597 | |
| 598 | if(image_info->endian == MSBEndian) |
| 599 | (void) WriteBlob(image, 4, (const unsigned char *) "mmmm"); |
| 600 | else{ |
| 601 | image->endian = LSBEndian; |
| 602 | (void) WriteBlob(image, 4, (const unsigned char *) "iiii"); |
| 603 | } |
| 604 | (void) WriteBlobLong(image, 4); |
| 605 | (void) WriteBlob(image, 4, (const unsigned char *) "100f"); |
| 606 | (void) WriteBlob(image, 4, (const unsigned char *) "data"); |
| 607 | (void) WriteBlobLong(image, ipl_info.size); |
| 608 | (void) WriteBlobLong(image, ipl_info.width); |
| 609 | (void) WriteBlobLong(image, ipl_info.height); |
| 610 | (void) WriteBlobLong(image, ipl_info.colors); |
| 611 | if(image_info->adjoin == MagickFalse) |
| 612 | (void) WriteBlobLong(image, 1); |
| 613 | else |
| 614 | (void) WriteBlobLong(image, ipl_info.z); |
| 615 | (void) WriteBlobLong(image, ipl_info.time); |
| 616 | (void) WriteBlobLong(image, ipl_info.byteType); |
| 617 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 618 | do |
| 619 | { |
| 620 | /* |
| 621 | Convert MIFF to IPL raster pixels. |
| 622 | */ |
| 623 | pixels=GetQuantumPixels(quantum_info); |
| 624 | if(ipl_info.colors == 1){ |
| 625 | /* Red frame */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 626 | for(y = 0; y < (ssize_t) ipl_info.height; y++){ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 627 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
| 628 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 629 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 630 | (void) ExportQuantumPixels(image,(CacheView *) NULL, quantum_info, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 631 | GrayQuantum, pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 632 | (void) WriteBlob(image, image->columns*image->depth/8, pixels); |
| 633 | } |
| 634 | |
| 635 | } |
| 636 | if(ipl_info.colors == 3){ |
| 637 | /* Red frame */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 638 | for(y = 0; y < (ssize_t) ipl_info.height; y++){ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 639 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
| 640 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 641 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 642 | (void) ExportQuantumPixels(image,(CacheView *) NULL, quantum_info, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 643 | RedQuantum, pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 644 | (void) WriteBlob(image, image->columns*image->depth/8, pixels); |
| 645 | } |
| 646 | |
| 647 | /* Green frame */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 648 | for(y = 0; y < (ssize_t) ipl_info.height; y++){ |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 649 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 650 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 651 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 652 | (void) ExportQuantumPixels(image,(CacheView *) NULL, quantum_info, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 653 | GreenQuantum, pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 654 | (void) WriteBlob(image, image->columns*image->depth/8, pixels); |
| 655 | } |
| 656 | /* Blue frame */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 657 | for(y = 0; y < (ssize_t) ipl_info.height; y++){ |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 658 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 659 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 660 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 661 | (void) ExportQuantumPixels(image,(CacheView *) NULL, quantum_info, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 662 | BlueQuantum, pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 663 | (void) WriteBlob(image, image->columns*image->depth/8, pixels); |
| 664 | if (image->previous == (Image *) NULL) |
| 665 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 666 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 667 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 668 | if (status == MagickFalse) |
| 669 | break; |
| 670 | } |
| 671 | } |
| 672 | } |
| 673 | quantum_info=DestroyQuantumInfo(quantum_info); |
| 674 | if (GetNextImageInList(image) == (Image *) NULL) |
| 675 | break; |
| 676 | image=SyncNextImageInList(image); |
| 677 | status=SetImageProgress(image,SaveImagesTag,scene++, |
| 678 | GetImageListLength(image)); |
| 679 | if (status == MagickFalse) |
| 680 | break; |
| 681 | }while (image_info->adjoin != MagickFalse); |
| 682 | |
| 683 | (void) WriteBlob(image, 4, (const unsigned char *) "fini"); |
| 684 | (void) WriteBlobLong(image, 0); |
| 685 | |
| 686 | CloseBlob(image); |
| 687 | return(MagickTrue); |
| 688 | } |