cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % V V IIIII FFFFF FFFFF % |
| 7 | % V V I F F % |
| 8 | % V V I FFF FFF % |
| 9 | % V V I F F % |
| 10 | % V IIIII F F % |
| 11 | % % |
| 12 | % % |
| 13 | % Read/Write Khoros Visualization 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/attribute.h" |
| 44 | #include "MagickCore/blob.h" |
| 45 | #include "MagickCore/blob-private.h" |
| 46 | #include "MagickCore/cache.h" |
| 47 | #include "MagickCore/color.h" |
| 48 | #include "MagickCore/color-private.h" |
| 49 | #include "MagickCore/colormap.h" |
cristy | e5d2138 | 2014-11-29 15:28:30 +0000 | [diff] [blame] | 50 | #include "MagickCore/colormap-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 51 | #include "MagickCore/colorspace.h" |
cristy | 510d06a | 2011-07-06 23:43:54 +0000 | [diff] [blame] | 52 | #include "MagickCore/colorspace-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 53 | #include "MagickCore/exception.h" |
| 54 | #include "MagickCore/exception-private.h" |
| 55 | #include "MagickCore/image.h" |
| 56 | #include "MagickCore/image-private.h" |
| 57 | #include "MagickCore/list.h" |
| 58 | #include "MagickCore/magick.h" |
| 59 | #include "MagickCore/memory_.h" |
| 60 | #include "MagickCore/monitor.h" |
| 61 | #include "MagickCore/monitor-private.h" |
| 62 | #include "MagickCore/pixel-accessor.h" |
| 63 | #include "MagickCore/property.h" |
| 64 | #include "MagickCore/quantum-private.h" |
| 65 | #include "MagickCore/static.h" |
| 66 | #include "MagickCore/string_.h" |
| 67 | #include "MagickCore/module.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 68 | |
| 69 | /* |
| 70 | Forward declarations. |
| 71 | */ |
| 72 | static MagickBooleanType |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 73 | WriteVIFFImage(const ImageInfo *,Image *,ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 74 | |
| 75 | /* |
| 76 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 77 | % % |
| 78 | % % |
| 79 | % % |
| 80 | % I s V I F F % |
| 81 | % % |
| 82 | % % |
| 83 | % % |
| 84 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 85 | % |
| 86 | % IsVIFF() returns MagickTrue if the image format type, identified by the |
| 87 | % magick string, is VIFF. |
| 88 | % |
| 89 | % The format of the IsVIFF method is: |
| 90 | % |
| 91 | % MagickBooleanType IsVIFF(const unsigned char *magick,const size_t length) |
| 92 | % |
| 93 | % A description of each parameter follows: |
| 94 | % |
| 95 | % o magick: compare image format pattern against these bytes. |
| 96 | % |
| 97 | % o length: Specifies the length of the magick string. |
| 98 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 99 | */ |
| 100 | static MagickBooleanType IsVIFF(const unsigned char *magick,const size_t length) |
| 101 | { |
| 102 | if (length < 2) |
| 103 | return(MagickFalse); |
| 104 | if (memcmp(magick,"\253\001",2) == 0) |
| 105 | return(MagickTrue); |
| 106 | return(MagickFalse); |
| 107 | } |
| 108 | |
| 109 | /* |
| 110 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 111 | % % |
| 112 | % % |
| 113 | % % |
| 114 | % R e a d V I F F I m a g e % |
| 115 | % % |
| 116 | % % |
| 117 | % % |
| 118 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 119 | % |
| 120 | % ReadVIFFImage() reads a Khoros Visualization image file and returns |
| 121 | % it. It allocates the memory necessary for the new Image structure and |
| 122 | % returns a pointer to the new image. |
| 123 | % |
| 124 | % The format of the ReadVIFFImage method is: |
| 125 | % |
| 126 | % Image *ReadVIFFImage(const ImageInfo *image_info, |
| 127 | % ExceptionInfo *exception) |
| 128 | % |
| 129 | % A description of each parameter follows: |
| 130 | % |
| 131 | % o image: Method ReadVIFFImage returns a pointer to the image after |
| 132 | % reading. A null image is returned if there is a memory shortage or if |
| 133 | % the image cannot be read. |
| 134 | % |
| 135 | % o image_info: the image info. |
| 136 | % |
| 137 | % o exception: return any errors or warnings in this structure. |
| 138 | % |
| 139 | */ |
| 140 | static Image *ReadVIFFImage(const ImageInfo *image_info, |
| 141 | ExceptionInfo *exception) |
| 142 | { |
| 143 | #define VFF_CM_genericRGB 15 |
| 144 | #define VFF_CM_ntscRGB 1 |
| 145 | #define VFF_CM_NONE 0 |
| 146 | #define VFF_DEP_DECORDER 0x4 |
| 147 | #define VFF_DEP_NSORDER 0x8 |
| 148 | #define VFF_DES_RAW 0 |
| 149 | #define VFF_LOC_IMPLICIT 1 |
| 150 | #define VFF_MAPTYP_NONE 0 |
| 151 | #define VFF_MAPTYP_1_BYTE 1 |
| 152 | #define VFF_MAPTYP_2_BYTE 2 |
| 153 | #define VFF_MAPTYP_4_BYTE 4 |
| 154 | #define VFF_MAPTYP_FLOAT 5 |
| 155 | #define VFF_MAPTYP_DOUBLE 7 |
| 156 | #define VFF_MS_NONE 0 |
| 157 | #define VFF_MS_ONEPERBAND 1 |
| 158 | #define VFF_MS_SHARED 3 |
| 159 | #define VFF_TYP_BIT 0 |
| 160 | #define VFF_TYP_1_BYTE 1 |
| 161 | #define VFF_TYP_2_BYTE 2 |
| 162 | #define VFF_TYP_4_BYTE 4 |
| 163 | #define VFF_TYP_FLOAT 5 |
| 164 | #define VFF_TYP_DOUBLE 9 |
| 165 | |
| 166 | typedef struct _ViffInfo |
| 167 | { |
| 168 | unsigned char |
| 169 | identifier, |
| 170 | file_type, |
| 171 | release, |
| 172 | version, |
| 173 | machine_dependency, |
| 174 | reserve[3]; |
| 175 | |
| 176 | char |
| 177 | comment[512]; |
| 178 | |
cristy | 5d89f43 | 2010-05-30 00:00:26 +0000 | [diff] [blame] | 179 | unsigned int |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 180 | rows, |
| 181 | columns, |
| 182 | subrows; |
| 183 | |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 184 | int |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 185 | x_offset, |
| 186 | y_offset; |
| 187 | |
| 188 | float |
| 189 | x_bits_per_pixel, |
| 190 | y_bits_per_pixel; |
| 191 | |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 192 | unsigned int |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 193 | location_type, |
| 194 | location_dimension, |
| 195 | number_of_images, |
| 196 | number_data_bands, |
| 197 | data_storage_type, |
| 198 | data_encode_scheme, |
| 199 | map_scheme, |
| 200 | map_storage_type, |
| 201 | map_rows, |
| 202 | map_columns, |
| 203 | map_subrows, |
| 204 | map_enable, |
| 205 | maps_per_cycle, |
| 206 | color_space_model; |
| 207 | } ViffInfo; |
| 208 | |
| 209 | double |
| 210 | min_value, |
| 211 | scale_factor, |
| 212 | value; |
| 213 | |
| 214 | Image |
| 215 | *image; |
| 216 | |
| 217 | int |
| 218 | bit; |
| 219 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 220 | MagickBooleanType |
| 221 | status; |
| 222 | |
| 223 | MagickSizeType |
| 224 | number_pixels; |
| 225 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 226 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 227 | x; |
| 228 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 229 | register Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 230 | *q; |
| 231 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 232 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 233 | i; |
| 234 | |
| 235 | register unsigned char |
| 236 | *p; |
| 237 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 238 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 239 | bytes_per_pixel, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 240 | max_packets, |
| 241 | quantum; |
| 242 | |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 243 | ssize_t |
| 244 | count, |
| 245 | y; |
| 246 | |
| 247 | unsigned char |
cristy | 5def203 | 2013-06-30 17:44:08 +0000 | [diff] [blame] | 248 | *pixels; |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 249 | |
Cristy | 66d1345 | 2015-09-20 09:56:47 -0400 | [diff] [blame] | 250 | unsigned long |
| 251 | lsb_first; |
| 252 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 253 | ViffInfo |
| 254 | viff_info; |
| 255 | |
| 256 | /* |
| 257 | Open image file. |
| 258 | */ |
| 259 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 260 | assert(image_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 261 | if (image_info->debug != MagickFalse) |
| 262 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 263 | image_info->filename); |
| 264 | assert(exception != (ExceptionInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 265 | assert(exception->signature == MagickCoreSignature); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 266 | image=AcquireImage(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 267 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 268 | if (status == MagickFalse) |
| 269 | { |
| 270 | image=DestroyImageList(image); |
| 271 | return((Image *) NULL); |
| 272 | } |
| 273 | /* |
| 274 | Read VIFF header (1024 bytes). |
| 275 | */ |
| 276 | count=ReadBlob(image,1,&viff_info.identifier); |
| 277 | do |
| 278 | { |
| 279 | /* |
| 280 | Verify VIFF identifier. |
| 281 | */ |
cristy | 22e1306 | 2015-01-03 18:09:40 +0000 | [diff] [blame] | 282 | if ((count != 1) || ((unsigned char) viff_info.identifier != 0xab)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 283 | ThrowReaderException(CorruptImageError,"NotAVIFFImage"); |
| 284 | /* |
| 285 | Initialize VIFF image. |
| 286 | */ |
cristy | 0f18a50 | 2014-11-28 14:16:00 +0000 | [diff] [blame] | 287 | (void) ReadBlob(image,sizeof(viff_info.file_type),&viff_info.file_type); |
| 288 | (void) ReadBlob(image,sizeof(viff_info.release),&viff_info.release); |
| 289 | (void) ReadBlob(image,sizeof(viff_info.version),&viff_info.version); |
| 290 | (void) ReadBlob(image,sizeof(viff_info.machine_dependency), |
| 291 | &viff_info.machine_dependency); |
| 292 | (void) ReadBlob(image,sizeof(viff_info.reserve),viff_info.reserve); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 293 | count=ReadBlob(image,512,(unsigned char *) viff_info.comment); |
| 294 | viff_info.comment[511]='\0'; |
| 295 | if (strlen(viff_info.comment) > 4) |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 296 | (void) SetImageProperty(image,"comment",viff_info.comment,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 297 | if ((viff_info.machine_dependency == VFF_DEP_DECORDER) || |
| 298 | (viff_info.machine_dependency == VFF_DEP_NSORDER)) |
cristy | 0f18a50 | 2014-11-28 14:16:00 +0000 | [diff] [blame] | 299 | image->endian=LSBEndian; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 300 | else |
cristy | 0f18a50 | 2014-11-28 14:16:00 +0000 | [diff] [blame] | 301 | image->endian=MSBEndian; |
| 302 | viff_info.rows=ReadBlobLong(image); |
| 303 | viff_info.columns=ReadBlobLong(image); |
| 304 | viff_info.subrows=ReadBlobLong(image); |
| 305 | viff_info.x_offset=(int) ReadBlobLong(image); |
| 306 | viff_info.y_offset=(int) ReadBlobLong(image); |
| 307 | viff_info.x_bits_per_pixel=(float) ReadBlobLong(image); |
| 308 | viff_info.y_bits_per_pixel=(float) ReadBlobLong(image); |
| 309 | viff_info.location_type=ReadBlobLong(image); |
| 310 | viff_info.location_dimension=ReadBlobLong(image); |
| 311 | viff_info.number_of_images=ReadBlobLong(image); |
| 312 | viff_info.number_data_bands=ReadBlobLong(image); |
| 313 | viff_info.data_storage_type=ReadBlobLong(image); |
| 314 | viff_info.data_encode_scheme=ReadBlobLong(image); |
| 315 | viff_info.map_scheme=ReadBlobLong(image); |
| 316 | viff_info.map_storage_type=ReadBlobLong(image); |
| 317 | viff_info.map_rows=ReadBlobLong(image); |
| 318 | viff_info.map_columns=ReadBlobLong(image); |
| 319 | viff_info.map_subrows=ReadBlobLong(image); |
| 320 | viff_info.map_enable=ReadBlobLong(image); |
| 321 | viff_info.maps_per_cycle=ReadBlobLong(image); |
| 322 | viff_info.color_space_model=ReadBlobLong(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 323 | for (i=0; i < 420; i++) |
| 324 | (void) ReadBlobByte(image); |
cristy | 32afe8c | 2015-01-03 18:09:13 +0000 | [diff] [blame] | 325 | if (EOFBlob(image) != MagickFalse) |
| 326 | ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 327 | image->columns=viff_info.rows; |
| 328 | image->rows=viff_info.columns; |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 329 | image->depth=viff_info.x_bits_per_pixel <= 8 ? 8UL : |
| 330 | MAGICKCORE_QUANTUM_DEPTH; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 331 | /* |
| 332 | Verify that we can read this VIFF image. |
| 333 | */ |
| 334 | number_pixels=(MagickSizeType) viff_info.columns*viff_info.rows; |
| 335 | if (number_pixels != (size_t) number_pixels) |
| 336 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 337 | if (number_pixels == 0) |
| 338 | ThrowReaderException(CoderError,"ImageColumnOrRowSizeIsNotSupported"); |
| 339 | if ((viff_info.number_data_bands < 1) || (viff_info.number_data_bands > 4)) |
| 340 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| 341 | if ((viff_info.data_storage_type != VFF_TYP_BIT) && |
| 342 | (viff_info.data_storage_type != VFF_TYP_1_BYTE) && |
| 343 | (viff_info.data_storage_type != VFF_TYP_2_BYTE) && |
| 344 | (viff_info.data_storage_type != VFF_TYP_4_BYTE) && |
| 345 | (viff_info.data_storage_type != VFF_TYP_FLOAT) && |
| 346 | (viff_info.data_storage_type != VFF_TYP_DOUBLE)) |
| 347 | ThrowReaderException(CoderError,"DataStorageTypeIsNotSupported"); |
| 348 | if (viff_info.data_encode_scheme != VFF_DES_RAW) |
| 349 | ThrowReaderException(CoderError,"DataEncodingSchemeIsNotSupported"); |
| 350 | if ((viff_info.map_storage_type != VFF_MAPTYP_NONE) && |
| 351 | (viff_info.map_storage_type != VFF_MAPTYP_1_BYTE) && |
| 352 | (viff_info.map_storage_type != VFF_MAPTYP_2_BYTE) && |
| 353 | (viff_info.map_storage_type != VFF_MAPTYP_4_BYTE) && |
| 354 | (viff_info.map_storage_type != VFF_MAPTYP_FLOAT) && |
| 355 | (viff_info.map_storage_type != VFF_MAPTYP_DOUBLE)) |
| 356 | ThrowReaderException(CoderError,"MapStorageTypeIsNotSupported"); |
| 357 | if ((viff_info.color_space_model != VFF_CM_NONE) && |
| 358 | (viff_info.color_space_model != VFF_CM_ntscRGB) && |
| 359 | (viff_info.color_space_model != VFF_CM_genericRGB)) |
| 360 | ThrowReaderException(CoderError,"ColorspaceModelIsNotSupported"); |
| 361 | if (viff_info.location_type != VFF_LOC_IMPLICIT) |
| 362 | ThrowReaderException(CoderError,"LocationTypeIsNotSupported"); |
| 363 | if (viff_info.number_of_images != 1) |
| 364 | ThrowReaderException(CoderError,"NumberOfImagesIsNotSupported"); |
| 365 | if (viff_info.map_rows == 0) |
| 366 | viff_info.map_scheme=VFF_MS_NONE; |
| 367 | switch ((int) viff_info.map_scheme) |
| 368 | { |
| 369 | case VFF_MS_NONE: |
| 370 | { |
| 371 | if (viff_info.number_data_bands < 3) |
| 372 | { |
| 373 | /* |
| 374 | Create linear color ramp. |
| 375 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 376 | if (viff_info.data_storage_type == VFF_TYP_BIT) |
| 377 | image->colors=2; |
dirk | 549cd1f | 2013-09-19 19:03:25 +0000 | [diff] [blame] | 378 | else |
cristy | 1b1868b | 2014-05-18 11:37:46 +0000 | [diff] [blame] | 379 | if (viff_info.data_storage_type == VFF_MAPTYP_1_BYTE) |
| 380 | image->colors=256UL; |
| 381 | else |
| 382 | image->colors=image->depth <= 8 ? 256UL : 65536UL; |
| 383 | status=AcquireImageColormap(image,image->colors,exception); |
| 384 | if (status == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 385 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 386 | } |
| 387 | break; |
| 388 | } |
| 389 | case VFF_MS_ONEPERBAND: |
| 390 | case VFF_MS_SHARED: |
| 391 | { |
| 392 | unsigned char |
| 393 | *viff_colormap; |
| 394 | |
| 395 | /* |
| 396 | Allocate VIFF colormap. |
| 397 | */ |
| 398 | switch ((int) viff_info.map_storage_type) |
| 399 | { |
| 400 | case VFF_MAPTYP_1_BYTE: bytes_per_pixel=1; break; |
| 401 | case VFF_MAPTYP_2_BYTE: bytes_per_pixel=2; break; |
| 402 | case VFF_MAPTYP_4_BYTE: bytes_per_pixel=4; break; |
| 403 | case VFF_MAPTYP_FLOAT: bytes_per_pixel=4; break; |
| 404 | case VFF_MAPTYP_DOUBLE: bytes_per_pixel=8; break; |
| 405 | default: bytes_per_pixel=1; break; |
| 406 | } |
| 407 | image->colors=viff_info.map_columns; |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 408 | if (AcquireImageColormap(image,image->colors,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 409 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
dirk | ecf3f09 | 2016-01-15 01:34:57 +0100 | [diff] [blame] | 410 | if (viff_info.map_rows > |
Cristy | 2174484 | 2016-01-13 18:31:21 -0500 | [diff] [blame] | 411 | (viff_info.map_rows*bytes_per_pixel*sizeof(*viff_colormap))) |
| 412 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 413 | viff_colormap=(unsigned char *) AcquireQuantumMemory(image->colors, |
| 414 | viff_info.map_rows*bytes_per_pixel*sizeof(*viff_colormap)); |
| 415 | if (viff_colormap == (unsigned char *) NULL) |
| 416 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 417 | /* |
| 418 | Read VIFF raster colormap. |
| 419 | */ |
| 420 | count=ReadBlob(image,bytes_per_pixel*image->colors*viff_info.map_rows, |
| 421 | viff_colormap); |
| 422 | lsb_first=1; |
| 423 | if (*(char *) &lsb_first && |
| 424 | ((viff_info.machine_dependency != VFF_DEP_DECORDER) && |
| 425 | (viff_info.machine_dependency != VFF_DEP_NSORDER))) |
| 426 | switch ((int) viff_info.map_storage_type) |
| 427 | { |
| 428 | case VFF_MAPTYP_2_BYTE: |
| 429 | { |
| 430 | MSBOrderShort(viff_colormap,(bytes_per_pixel*image->colors* |
| 431 | viff_info.map_rows)); |
| 432 | break; |
| 433 | } |
| 434 | case VFF_MAPTYP_4_BYTE: |
| 435 | case VFF_MAPTYP_FLOAT: |
| 436 | { |
| 437 | MSBOrderLong(viff_colormap,(bytes_per_pixel*image->colors* |
| 438 | viff_info.map_rows)); |
| 439 | break; |
| 440 | } |
| 441 | default: break; |
| 442 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 443 | for (i=0; i < (ssize_t) (viff_info.map_rows*image->colors); i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 444 | { |
| 445 | switch ((int) viff_info.map_storage_type) |
| 446 | { |
| 447 | case VFF_MAPTYP_2_BYTE: value=1.0*((short *) viff_colormap)[i]; break; |
| 448 | case VFF_MAPTYP_4_BYTE: value=1.0*((int *) viff_colormap)[i]; break; |
| 449 | case VFF_MAPTYP_FLOAT: value=((float *) viff_colormap)[i]; break; |
| 450 | case VFF_MAPTYP_DOUBLE: value=((double *) viff_colormap)[i]; break; |
| 451 | default: value=1.0*viff_colormap[i]; break; |
| 452 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 453 | if (i < (ssize_t) image->colors) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 454 | { |
| 455 | image->colormap[i].red=ScaleCharToQuantum((unsigned char) value); |
| 456 | image->colormap[i].green= |
| 457 | ScaleCharToQuantum((unsigned char) value); |
| 458 | image->colormap[i].blue=ScaleCharToQuantum((unsigned char) value); |
| 459 | } |
| 460 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 461 | if (i < (ssize_t) (2*image->colors)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 462 | image->colormap[i % image->colors].green= |
| 463 | ScaleCharToQuantum((unsigned char) value); |
| 464 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 465 | if (i < (ssize_t) (3*image->colors)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 466 | image->colormap[i % image->colors].blue= |
| 467 | ScaleCharToQuantum((unsigned char) value); |
| 468 | } |
| 469 | viff_colormap=(unsigned char *) RelinquishMagickMemory(viff_colormap); |
| 470 | break; |
| 471 | } |
| 472 | default: |
| 473 | ThrowReaderException(CoderError,"ColormapTypeNotSupported"); |
| 474 | } |
| 475 | /* |
| 476 | Initialize image structure. |
| 477 | */ |
cristy | b0a657e | 2012-08-29 00:45:37 +0000 | [diff] [blame] | 478 | image->alpha_trait=viff_info.number_data_bands == 4 ? BlendPixelTrait : |
| 479 | UndefinedPixelTrait; |
| 480 | image->storage_class=(viff_info.number_data_bands < 3 ? PseudoClass : |
| 481 | DirectClass); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 482 | image->columns=viff_info.rows; |
| 483 | image->rows=viff_info.columns; |
| 484 | if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0)) |
| 485 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 486 | break; |
cristy | acabb84 | 2014-12-14 23:36:33 +0000 | [diff] [blame] | 487 | status=SetImageExtent(image,image->columns,image->rows,exception); |
| 488 | if (status == MagickFalse) |
| 489 | return(DestroyImageList(image)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 490 | /* |
| 491 | Allocate VIFF pixels. |
| 492 | */ |
| 493 | switch ((int) viff_info.data_storage_type) |
| 494 | { |
| 495 | case VFF_TYP_2_BYTE: bytes_per_pixel=2; break; |
| 496 | case VFF_TYP_4_BYTE: bytes_per_pixel=4; break; |
| 497 | case VFF_TYP_FLOAT: bytes_per_pixel=4; break; |
| 498 | case VFF_TYP_DOUBLE: bytes_per_pixel=8; break; |
| 499 | default: bytes_per_pixel=1; break; |
| 500 | } |
| 501 | if (viff_info.data_storage_type == VFF_TYP_BIT) |
| 502 | max_packets=((image->columns+7UL) >> 3UL)*image->rows; |
| 503 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 504 | max_packets=(size_t) (number_pixels*viff_info.number_data_bands); |
Cristy | 7be16a2 | 2016-01-24 17:43:46 -0500 | [diff] [blame] | 505 | pixels=(unsigned char *) AcquireQuantumMemory(MagickMax(number_pixels, |
| 506 | max_packets),bytes_per_pixel*sizeof(*pixels)); |
cristy | 5def203 | 2013-06-30 17:44:08 +0000 | [diff] [blame] | 507 | if (pixels == (unsigned char *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 508 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
cristy | 5def203 | 2013-06-30 17:44:08 +0000 | [diff] [blame] | 509 | count=ReadBlob(image,bytes_per_pixel*max_packets,pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 510 | lsb_first=1; |
| 511 | if (*(char *) &lsb_first && |
| 512 | ((viff_info.machine_dependency != VFF_DEP_DECORDER) && |
| 513 | (viff_info.machine_dependency != VFF_DEP_NSORDER))) |
| 514 | switch ((int) viff_info.data_storage_type) |
| 515 | { |
| 516 | case VFF_TYP_2_BYTE: |
| 517 | { |
cristy | 5def203 | 2013-06-30 17:44:08 +0000 | [diff] [blame] | 518 | MSBOrderShort(pixels,bytes_per_pixel*max_packets); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 519 | break; |
| 520 | } |
| 521 | case VFF_TYP_4_BYTE: |
| 522 | case VFF_TYP_FLOAT: |
| 523 | { |
cristy | 5def203 | 2013-06-30 17:44:08 +0000 | [diff] [blame] | 524 | MSBOrderLong(pixels,bytes_per_pixel*max_packets); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 525 | break; |
| 526 | } |
| 527 | default: break; |
| 528 | } |
| 529 | min_value=0.0; |
| 530 | scale_factor=1.0; |
| 531 | if ((viff_info.data_storage_type != VFF_TYP_1_BYTE) && |
| 532 | (viff_info.map_scheme == VFF_MS_NONE)) |
| 533 | { |
| 534 | double |
| 535 | max_value; |
| 536 | |
| 537 | /* |
| 538 | Determine scale factor. |
| 539 | */ |
| 540 | switch ((int) viff_info.data_storage_type) |
| 541 | { |
cristy | 5def203 | 2013-06-30 17:44:08 +0000 | [diff] [blame] | 542 | case VFF_TYP_2_BYTE: value=1.0*((short *) pixels)[0]; break; |
| 543 | case VFF_TYP_4_BYTE: value=1.0*((int *) pixels)[0]; break; |
| 544 | case VFF_TYP_FLOAT: value=((float *) pixels)[0]; break; |
| 545 | case VFF_TYP_DOUBLE: value=((double *) pixels)[0]; break; |
| 546 | default: value=1.0*pixels[0]; break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 547 | } |
| 548 | max_value=value; |
| 549 | min_value=value; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 550 | for (i=0; i < (ssize_t) max_packets; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 551 | { |
| 552 | switch ((int) viff_info.data_storage_type) |
| 553 | { |
cristy | 5def203 | 2013-06-30 17:44:08 +0000 | [diff] [blame] | 554 | case VFF_TYP_2_BYTE: value=1.0*((short *) pixels)[i]; break; |
| 555 | case VFF_TYP_4_BYTE: value=1.0*((int *) pixels)[i]; break; |
| 556 | case VFF_TYP_FLOAT: value=((float *) pixels)[i]; break; |
| 557 | case VFF_TYP_DOUBLE: value=((double *) pixels)[i]; break; |
| 558 | default: value=1.0*pixels[i]; break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 559 | } |
| 560 | if (value > max_value) |
| 561 | max_value=value; |
| 562 | else |
| 563 | if (value < min_value) |
| 564 | min_value=value; |
| 565 | } |
| 566 | if ((min_value == 0) && (max_value == 0)) |
| 567 | scale_factor=0; |
| 568 | else |
| 569 | if (min_value == max_value) |
| 570 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 571 | scale_factor=(double) QuantumRange/min_value; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 572 | min_value=0; |
| 573 | } |
| 574 | else |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 575 | scale_factor=(double) QuantumRange/(max_value-min_value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 576 | } |
| 577 | /* |
| 578 | Convert pixels to Quantum size. |
| 579 | */ |
cristy | 5def203 | 2013-06-30 17:44:08 +0000 | [diff] [blame] | 580 | p=(unsigned char *) pixels; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 581 | for (i=0; i < (ssize_t) max_packets; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 582 | { |
| 583 | switch ((int) viff_info.data_storage_type) |
| 584 | { |
cristy | 5def203 | 2013-06-30 17:44:08 +0000 | [diff] [blame] | 585 | case VFF_TYP_2_BYTE: value=1.0*((short *) pixels)[i]; break; |
| 586 | case VFF_TYP_4_BYTE: value=1.0*((int *) pixels)[i]; break; |
| 587 | case VFF_TYP_FLOAT: value=((float *) pixels)[i]; break; |
| 588 | case VFF_TYP_DOUBLE: value=((double *) pixels)[i]; break; |
| 589 | default: value=1.0*pixels[i]; break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 590 | } |
| 591 | if (viff_info.map_scheme == VFF_MS_NONE) |
| 592 | { |
| 593 | value=(value-min_value)*scale_factor; |
| 594 | if (value > QuantumRange) |
| 595 | value=QuantumRange; |
| 596 | else |
| 597 | if (value < 0) |
| 598 | value=0; |
| 599 | } |
cristy | 2338982 | 2015-07-19 12:58:13 +0000 | [diff] [blame] | 600 | *p=(unsigned char) ((Quantum) value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 601 | p++; |
| 602 | } |
| 603 | /* |
| 604 | Convert VIFF raster image to pixel packets. |
| 605 | */ |
cristy | 5def203 | 2013-06-30 17:44:08 +0000 | [diff] [blame] | 606 | p=(unsigned char *) pixels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 607 | if (viff_info.data_storage_type == VFF_TYP_BIT) |
| 608 | { |
| 609 | /* |
| 610 | Convert bitmap scanline. |
| 611 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 612 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 613 | { |
| 614 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 615 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 616 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 617 | for (x=0; x < (ssize_t) (image->columns-7); x+=8) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 618 | { |
| 619 | for (bit=0; bit < 8; bit++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 620 | { |
cristy | 0f18a50 | 2014-11-28 14:16:00 +0000 | [diff] [blame] | 621 | quantum=(size_t) ((*p) & (0x01 << bit) ? 0 : 1); |
cristy | 822251f | 2015-01-01 00:28:58 +0000 | [diff] [blame] | 622 | SetPixelRed(image,quantum == 0 ? 0 : QuantumRange,q); |
| 623 | SetPixelGreen(image,quantum == 0 ? 0 : QuantumRange,q); |
| 624 | SetPixelBlue(image,quantum == 0 ? 0 : QuantumRange,q); |
| 625 | if (image->storage_class == PseudoClass) |
dirk | 1678aec | 2015-08-30 12:07:29 +0200 | [diff] [blame] | 626 | SetPixelIndex(image,(Quantum) quantum,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 627 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 628 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 629 | p++; |
| 630 | } |
| 631 | if ((image->columns % 8) != 0) |
| 632 | { |
cristy | 0f18a50 | 2014-11-28 14:16:00 +0000 | [diff] [blame] | 633 | for (bit=0; bit < (int) (image->columns % 8); bit++) |
cristy | 940942b | 2014-05-18 11:32:34 +0000 | [diff] [blame] | 634 | { |
cristy | 0f18a50 | 2014-11-28 14:16:00 +0000 | [diff] [blame] | 635 | quantum=(size_t) ((*p) & (0x01 << bit) ? 0 : 1); |
cristy | 822251f | 2015-01-01 00:28:58 +0000 | [diff] [blame] | 636 | SetPixelRed(image,quantum == 0 ? 0 : QuantumRange,q); |
| 637 | SetPixelGreen(image,quantum == 0 ? 0 : QuantumRange,q); |
| 638 | SetPixelBlue(image,quantum == 0 ? 0 : QuantumRange,q); |
| 639 | if (image->storage_class == PseudoClass) |
dirk | 1678aec | 2015-08-30 12:07:29 +0200 | [diff] [blame] | 640 | SetPixelIndex(image,(Quantum) quantum,q); |
cristy | 940942b | 2014-05-18 11:32:34 +0000 | [diff] [blame] | 641 | q+=GetPixelChannels(image); |
| 642 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 643 | p++; |
| 644 | } |
| 645 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 646 | break; |
| 647 | if (image->previous == (Image *) NULL) |
| 648 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 649 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
| 650 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 651 | if (status == MagickFalse) |
| 652 | break; |
| 653 | } |
| 654 | } |
| 655 | } |
| 656 | else |
| 657 | if (image->storage_class == PseudoClass) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 658 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 659 | { |
| 660 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 661 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 662 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 663 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 664 | { |
| 665 | SetPixelIndex(image,*p++,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 666 | q+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 667 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 668 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 669 | break; |
| 670 | if (image->previous == (Image *) NULL) |
| 671 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 672 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
| 673 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 674 | if (status == MagickFalse) |
| 675 | break; |
| 676 | } |
| 677 | } |
| 678 | else |
| 679 | { |
| 680 | /* |
| 681 | Convert DirectColor scanline. |
| 682 | */ |
| 683 | number_pixels=(MagickSizeType) image->columns*image->rows; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 684 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 685 | { |
| 686 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 687 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 688 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 689 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 690 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 691 | SetPixelRed(image,ScaleCharToQuantum(*p),q); |
| 692 | SetPixelGreen(image,ScaleCharToQuantum(*(p+number_pixels)),q); |
| 693 | SetPixelBlue(image,ScaleCharToQuantum(*(p+2*number_pixels)),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 694 | if (image->colors != 0) |
| 695 | { |
cristy | e5d2138 | 2014-11-29 15:28:30 +0000 | [diff] [blame] | 696 | ssize_t |
| 697 | index; |
| 698 | |
| 699 | index=(ssize_t) GetPixelRed(image,q); |
| 700 | SetPixelRed(image,image->colormap[ |
| 701 | ConstrainColormapIndex(image,index,exception)].red,q); |
| 702 | index=(ssize_t) GetPixelGreen(image,q); |
| 703 | SetPixelGreen(image,image->colormap[ |
| 704 | ConstrainColormapIndex(image,index,exception)].green,q); |
| 705 | index=(ssize_t) GetPixelBlue(image,q); |
| 706 | SetPixelBlue(image,image->colormap[ |
| 707 | ConstrainColormapIndex(image,index,exception)].blue,q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 708 | } |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 709 | SetPixelAlpha(image,image->alpha_trait != UndefinedPixelTrait ? |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 710 | ScaleCharToQuantum(*(p+number_pixels*3)) : OpaqueAlpha,q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 711 | p++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 712 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 713 | } |
| 714 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 715 | break; |
| 716 | if (image->previous == (Image *) NULL) |
| 717 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 718 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
| 719 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 720 | if (status == MagickFalse) |
| 721 | break; |
| 722 | } |
| 723 | } |
| 724 | } |
cristy | 5def203 | 2013-06-30 17:44:08 +0000 | [diff] [blame] | 725 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 726 | if (image->storage_class == PseudoClass) |
cristy | ea1a8aa | 2011-10-20 13:24:06 +0000 | [diff] [blame] | 727 | (void) SyncImage(image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 728 | if (EOFBlob(image) != MagickFalse) |
| 729 | { |
| 730 | ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", |
| 731 | image->filename); |
| 732 | break; |
| 733 | } |
| 734 | /* |
| 735 | Proceed to next image. |
| 736 | */ |
| 737 | if (image_info->number_scenes != 0) |
| 738 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 739 | break; |
| 740 | count=ReadBlob(image,1,&viff_info.identifier); |
| 741 | if ((count != 0) && (viff_info.identifier == 0xab)) |
| 742 | { |
| 743 | /* |
| 744 | Allocate next image structure. |
| 745 | */ |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 746 | AcquireNextImage(image_info,image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 747 | if (GetNextImageInList(image) == (Image *) NULL) |
| 748 | { |
| 749 | image=DestroyImageList(image); |
| 750 | return((Image *) NULL); |
| 751 | } |
| 752 | image=SyncNextImageInList(image); |
| 753 | status=SetImageProgress(image,LoadImagesTag,TellBlob(image), |
| 754 | GetBlobSize(image)); |
| 755 | if (status == MagickFalse) |
| 756 | break; |
| 757 | } |
| 758 | } while ((count != 0) && (viff_info.identifier == 0xab)); |
| 759 | (void) CloseBlob(image); |
| 760 | return(GetFirstImageInList(image)); |
| 761 | } |
| 762 | |
| 763 | /* |
| 764 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 765 | % % |
| 766 | % % |
| 767 | % % |
| 768 | % R e g i s t e r V I F F I m a g e % |
| 769 | % % |
| 770 | % % |
| 771 | % % |
| 772 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 773 | % |
| 774 | % RegisterVIFFImage() adds properties for the VIFF image format to |
| 775 | % the list of supported formats. The properties include the image format |
| 776 | % tag, a method to read and/or write the format, whether the format |
| 777 | % supports the saving of more than one frame to the same file or blob, |
| 778 | % whether the format supports native in-memory I/O, and a brief |
| 779 | % description of the format. |
| 780 | % |
| 781 | % The format of the RegisterVIFFImage method is: |
| 782 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 783 | % size_t RegisterVIFFImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 784 | % |
| 785 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 786 | ModuleExport size_t RegisterVIFFImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 787 | { |
| 788 | MagickInfo |
| 789 | *entry; |
| 790 | |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 791 | entry=AcquireMagickInfo("VIFF","VIFF","Khoros Visualization image"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 792 | entry->decoder=(DecodeImageHandler *) ReadVIFFImage; |
| 793 | entry->encoder=(EncodeImageHandler *) WriteVIFFImage; |
| 794 | entry->magick=(IsImageFormatHandler *) IsVIFF; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 795 | (void) RegisterMagickInfo(entry); |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 796 | entry=AcquireMagickInfo("VIFF","XV","Khoros Visualization image"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 797 | entry->decoder=(DecodeImageHandler *) ReadVIFFImage; |
| 798 | entry->encoder=(EncodeImageHandler *) WriteVIFFImage; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 799 | (void) RegisterMagickInfo(entry); |
| 800 | return(MagickImageCoderSignature); |
| 801 | } |
| 802 | |
| 803 | /* |
| 804 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 805 | % % |
| 806 | % % |
| 807 | % % |
| 808 | % U n r e g i s t e r V I F F I m a g e % |
| 809 | % % |
| 810 | % % |
| 811 | % % |
| 812 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 813 | % |
| 814 | % UnregisterVIFFImage() removes format registrations made by the |
| 815 | % VIFF module from the list of supported formats. |
| 816 | % |
| 817 | % The format of the UnregisterVIFFImage method is: |
| 818 | % |
| 819 | % UnregisterVIFFImage(void) |
| 820 | % |
| 821 | */ |
| 822 | ModuleExport void UnregisterVIFFImage(void) |
| 823 | { |
| 824 | (void) UnregisterMagickInfo("VIFF"); |
| 825 | (void) UnregisterMagickInfo("XV"); |
| 826 | } |
| 827 | |
| 828 | /* |
| 829 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 830 | % % |
| 831 | % % |
| 832 | % % |
| 833 | % W r i t e V I F F I m a g e % |
| 834 | % % |
| 835 | % % |
| 836 | % % |
| 837 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 838 | % |
| 839 | % WriteVIFFImage() writes an image to a file in the VIFF image format. |
| 840 | % |
| 841 | % The format of the WriteVIFFImage method is: |
| 842 | % |
| 843 | % MagickBooleanType WriteVIFFImage(const ImageInfo *image_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 844 | % Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 845 | % |
| 846 | % A description of each parameter follows. |
| 847 | % |
| 848 | % o image_info: the image info. |
| 849 | % |
| 850 | % o image: The image. |
| 851 | % |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 852 | % o exception: return any errors or warnings in this structure. |
| 853 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 854 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 855 | static MagickBooleanType WriteVIFFImage(const ImageInfo *image_info, |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 856 | Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 857 | { |
| 858 | #define VFF_CM_genericRGB 15 |
| 859 | #define VFF_CM_NONE 0 |
| 860 | #define VFF_DEP_IEEEORDER 0x2 |
| 861 | #define VFF_DES_RAW 0 |
| 862 | #define VFF_LOC_IMPLICIT 1 |
| 863 | #define VFF_MAPTYP_NONE 0 |
| 864 | #define VFF_MAPTYP_1_BYTE 1 |
| 865 | #define VFF_MS_NONE 0 |
| 866 | #define VFF_MS_ONEPERBAND 1 |
| 867 | #define VFF_TYP_BIT 0 |
| 868 | #define VFF_TYP_1_BYTE 1 |
| 869 | |
| 870 | typedef struct _ViffInfo |
| 871 | { |
| 872 | char |
| 873 | identifier, |
| 874 | file_type, |
| 875 | release, |
| 876 | version, |
| 877 | machine_dependency, |
| 878 | reserve[3], |
| 879 | comment[512]; |
| 880 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 881 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 882 | rows, |
| 883 | columns, |
| 884 | subrows; |
| 885 | |
cristy | 5d89f43 | 2010-05-30 00:00:26 +0000 | [diff] [blame] | 886 | int |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 887 | x_offset, |
| 888 | y_offset; |
| 889 | |
| 890 | unsigned int |
| 891 | x_bits_per_pixel, |
cristy | 5d89f43 | 2010-05-30 00:00:26 +0000 | [diff] [blame] | 892 | y_bits_per_pixel, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 893 | location_type, |
| 894 | location_dimension, |
| 895 | number_of_images, |
| 896 | number_data_bands, |
| 897 | data_storage_type, |
| 898 | data_encode_scheme, |
| 899 | map_scheme, |
| 900 | map_storage_type, |
| 901 | map_rows, |
| 902 | map_columns, |
| 903 | map_subrows, |
| 904 | map_enable, |
| 905 | maps_per_cycle, |
| 906 | color_space_model; |
| 907 | } ViffInfo; |
| 908 | |
| 909 | const char |
| 910 | *value; |
| 911 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 912 | MagickBooleanType |
| 913 | status; |
| 914 | |
| 915 | MagickOffsetType |
| 916 | scene; |
| 917 | |
| 918 | MagickSizeType |
| 919 | number_pixels, |
| 920 | packets; |
| 921 | |
cristy | 5def203 | 2013-06-30 17:44:08 +0000 | [diff] [blame] | 922 | MemoryInfo |
| 923 | *pixel_info; |
| 924 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 925 | register const Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 926 | *p; |
| 927 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 928 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 929 | x; |
| 930 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 931 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 932 | i; |
| 933 | |
| 934 | register unsigned char |
| 935 | *q; |
| 936 | |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 937 | ssize_t |
| 938 | y; |
| 939 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 940 | unsigned char |
cristy | 5def203 | 2013-06-30 17:44:08 +0000 | [diff] [blame] | 941 | *pixels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 942 | |
| 943 | ViffInfo |
| 944 | viff_info; |
| 945 | |
| 946 | /* |
| 947 | Open output image file. |
| 948 | */ |
| 949 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 950 | assert(image_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 951 | assert(image != (Image *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 952 | assert(image->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 953 | if (image->debug != MagickFalse) |
| 954 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 955 | assert(exception != (ExceptionInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 956 | assert(exception->signature == MagickCoreSignature); |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 957 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 958 | if (status == MagickFalse) |
| 959 | return(status); |
| 960 | (void) ResetMagickMemory(&viff_info,0,sizeof(ViffInfo)); |
| 961 | scene=0; |
| 962 | do |
| 963 | { |
| 964 | /* |
| 965 | Initialize VIFF image structure. |
| 966 | */ |
cristy | af8d391 | 2014-02-21 14:50:33 +0000 | [diff] [blame] | 967 | (void) TransformImageColorspace(image,sRGBColorspace,exception); |
dirk | 93b02b7 | 2013-11-16 16:03:36 +0000 | [diff] [blame] | 968 | DisableMSCWarning(4310) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 969 | viff_info.identifier=(char) 0xab; |
dirk | 93b02b7 | 2013-11-16 16:03:36 +0000 | [diff] [blame] | 970 | RestoreMSCWarning |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 971 | viff_info.file_type=1; |
| 972 | viff_info.release=1; |
| 973 | viff_info.version=3; |
| 974 | viff_info.machine_dependency=VFF_DEP_IEEEORDER; /* IEEE byte ordering */ |
| 975 | *viff_info.comment='\0'; |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 976 | value=GetImageProperty(image,"comment",exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 977 | if (value != (const char *) NULL) |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 978 | (void) CopyMagickString(viff_info.comment,value,MagickMin(strlen(value), |
| 979 | 511)+1); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 980 | viff_info.rows=image->columns; |
| 981 | viff_info.columns=image->rows; |
| 982 | viff_info.subrows=0; |
| 983 | viff_info.x_offset=(~0); |
| 984 | viff_info.y_offset=(~0); |
| 985 | viff_info.x_bits_per_pixel=0; |
| 986 | viff_info.y_bits_per_pixel=0; |
| 987 | viff_info.location_type=VFF_LOC_IMPLICIT; |
| 988 | viff_info.location_dimension=0; |
| 989 | viff_info.number_of_images=1; |
| 990 | viff_info.data_encode_scheme=VFF_DES_RAW; |
| 991 | viff_info.map_scheme=VFF_MS_NONE; |
| 992 | viff_info.map_storage_type=VFF_MAPTYP_NONE; |
| 993 | viff_info.map_rows=0; |
| 994 | viff_info.map_columns=0; |
| 995 | viff_info.map_subrows=0; |
| 996 | viff_info.map_enable=1; /* no colormap */ |
| 997 | viff_info.maps_per_cycle=0; |
| 998 | number_pixels=(MagickSizeType) image->columns*image->rows; |
| 999 | if (image->storage_class == DirectClass) |
| 1000 | { |
| 1001 | /* |
| 1002 | Full color VIFF raster. |
| 1003 | */ |
cristy | 0f18a50 | 2014-11-28 14:16:00 +0000 | [diff] [blame] | 1004 | viff_info.number_data_bands=image->alpha_trait ? 4U : 3U; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1005 | viff_info.color_space_model=VFF_CM_genericRGB; |
| 1006 | viff_info.data_storage_type=VFF_TYP_1_BYTE; |
| 1007 | packets=viff_info.number_data_bands*number_pixels; |
| 1008 | } |
| 1009 | else |
| 1010 | { |
| 1011 | viff_info.number_data_bands=1; |
| 1012 | viff_info.color_space_model=VFF_CM_NONE; |
| 1013 | viff_info.data_storage_type=VFF_TYP_1_BYTE; |
| 1014 | packets=number_pixels; |
dirk | f1d8548 | 2015-04-06 00:36:00 +0000 | [diff] [blame] | 1015 | if (SetImageGray(image,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1016 | { |
| 1017 | /* |
| 1018 | Colormapped VIFF raster. |
| 1019 | */ |
| 1020 | viff_info.map_scheme=VFF_MS_ONEPERBAND; |
| 1021 | viff_info.map_storage_type=VFF_MAPTYP_1_BYTE; |
| 1022 | viff_info.map_rows=3; |
cristy | 0b29b25 | 2010-05-30 01:59:46 +0000 | [diff] [blame] | 1023 | viff_info.map_columns=(unsigned int) image->colors; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1024 | } |
| 1025 | else |
| 1026 | if (image->colors <= 2) |
| 1027 | { |
| 1028 | /* |
| 1029 | Monochrome VIFF raster. |
| 1030 | */ |
| 1031 | viff_info.data_storage_type=VFF_TYP_BIT; |
| 1032 | packets=((image->columns+7) >> 3)*image->rows; |
| 1033 | } |
| 1034 | } |
| 1035 | /* |
| 1036 | Write VIFF image header (pad to 1024 bytes). |
| 1037 | */ |
cristy | 0f18a50 | 2014-11-28 14:16:00 +0000 | [diff] [blame] | 1038 | (void) WriteBlob(image,sizeof(viff_info.identifier),(unsigned char *) |
| 1039 | &viff_info.identifier); |
| 1040 | (void) WriteBlob(image,sizeof(viff_info.file_type),(unsigned char *) |
| 1041 | &viff_info.file_type); |
| 1042 | (void) WriteBlob(image,sizeof(viff_info.release),(unsigned char *) |
| 1043 | &viff_info.release); |
| 1044 | (void) WriteBlob(image,sizeof(viff_info.version),(unsigned char *) |
| 1045 | &viff_info.version); |
| 1046 | (void) WriteBlob(image,sizeof(viff_info.machine_dependency), |
| 1047 | (unsigned char *) &viff_info.machine_dependency); |
| 1048 | (void) WriteBlob(image,sizeof(viff_info.reserve),(unsigned char *) |
| 1049 | viff_info.reserve); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1050 | (void) WriteBlob(image,512,(unsigned char *) viff_info.comment); |
cristy | 0b29b25 | 2010-05-30 01:59:46 +0000 | [diff] [blame] | 1051 | (void) WriteBlobMSBLong(image,(unsigned int) viff_info.rows); |
| 1052 | (void) WriteBlobMSBLong(image,(unsigned int) viff_info.columns); |
cristy | f6fe0a1 | 2010-05-30 00:44:47 +0000 | [diff] [blame] | 1053 | (void) WriteBlobMSBLong(image,(unsigned int) viff_info.subrows); |
| 1054 | (void) WriteBlobMSBLong(image,(unsigned int) viff_info.x_offset); |
| 1055 | (void) WriteBlobMSBLong(image,(unsigned int) viff_info.y_offset); |
cristy | 0f18a50 | 2014-11-28 14:16:00 +0000 | [diff] [blame] | 1056 | viff_info.x_bits_per_pixel=(unsigned int) ((63 << 24) | (128 << 16)); |
cristy | f6fe0a1 | 2010-05-30 00:44:47 +0000 | [diff] [blame] | 1057 | (void) WriteBlobMSBLong(image,(unsigned int) viff_info.x_bits_per_pixel); |
cristy | 0f18a50 | 2014-11-28 14:16:00 +0000 | [diff] [blame] | 1058 | viff_info.y_bits_per_pixel=(unsigned int) ((63 << 24) | (128 << 16)); |
cristy | f6fe0a1 | 2010-05-30 00:44:47 +0000 | [diff] [blame] | 1059 | (void) WriteBlobMSBLong(image,(unsigned int) viff_info.y_bits_per_pixel); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1060 | (void) WriteBlobMSBLong(image,viff_info.location_type); |
| 1061 | (void) WriteBlobMSBLong(image,viff_info.location_dimension); |
cristy | f6fe0a1 | 2010-05-30 00:44:47 +0000 | [diff] [blame] | 1062 | (void) WriteBlobMSBLong(image,(unsigned int) viff_info.number_of_images); |
| 1063 | (void) WriteBlobMSBLong(image,(unsigned int) viff_info.number_data_bands); |
| 1064 | (void) WriteBlobMSBLong(image,(unsigned int) viff_info.data_storage_type); |
| 1065 | (void) WriteBlobMSBLong(image,(unsigned int) viff_info.data_encode_scheme); |
| 1066 | (void) WriteBlobMSBLong(image,(unsigned int) viff_info.map_scheme); |
| 1067 | (void) WriteBlobMSBLong(image,(unsigned int) viff_info.map_storage_type); |
| 1068 | (void) WriteBlobMSBLong(image,(unsigned int) viff_info.map_rows); |
| 1069 | (void) WriteBlobMSBLong(image,(unsigned int) viff_info.map_columns); |
| 1070 | (void) WriteBlobMSBLong(image,(unsigned int) viff_info.map_subrows); |
| 1071 | (void) WriteBlobMSBLong(image,(unsigned int) viff_info.map_enable); |
| 1072 | (void) WriteBlobMSBLong(image,(unsigned int) viff_info.maps_per_cycle); |
| 1073 | (void) WriteBlobMSBLong(image,(unsigned int) viff_info.color_space_model); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1074 | for (i=0; i < 420; i++) |
| 1075 | (void) WriteBlobByte(image,'\0'); |
| 1076 | /* |
| 1077 | Convert MIFF to VIFF raster pixels. |
| 1078 | */ |
cristy | 5def203 | 2013-06-30 17:44:08 +0000 | [diff] [blame] | 1079 | pixel_info=AcquireVirtualMemory((size_t) packets,sizeof(*pixels)); |
| 1080 | if (pixel_info == (MemoryInfo *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1081 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
cristy | 5def203 | 2013-06-30 17:44:08 +0000 | [diff] [blame] | 1082 | pixels=(unsigned char *) GetVirtualMemoryBlob(pixel_info); |
| 1083 | q=pixels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1084 | if (image->storage_class == DirectClass) |
| 1085 | { |
| 1086 | /* |
| 1087 | Convert DirectClass packet to VIFF RGB pixel. |
| 1088 | */ |
| 1089 | number_pixels=(MagickSizeType) image->columns*image->rows; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1090 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1091 | { |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1092 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1093 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1094 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1095 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1096 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1097 | *q=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 1098 | *(q+number_pixels)=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 1099 | *(q+number_pixels*2)=ScaleQuantumToChar(GetPixelBlue(image,p)); |
cristy | 17f11b0 | 2014-12-20 19:37:04 +0000 | [diff] [blame] | 1100 | if (image->alpha_trait != UndefinedPixelTrait) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1101 | *(q+number_pixels*3)=ScaleQuantumToChar((Quantum) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1102 | (GetPixelAlpha(image,p))); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1103 | p+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1104 | q++; |
| 1105 | } |
| 1106 | if (image->previous == (Image *) NULL) |
| 1107 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 1108 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 1109 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1110 | if (status == MagickFalse) |
| 1111 | break; |
| 1112 | } |
| 1113 | } |
| 1114 | } |
| 1115 | else |
dirk | f1d8548 | 2015-04-06 00:36:00 +0000 | [diff] [blame] | 1116 | if (SetImageGray(image,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1117 | { |
| 1118 | unsigned char |
| 1119 | *viff_colormap; |
| 1120 | |
| 1121 | /* |
| 1122 | Dump colormap to file. |
| 1123 | */ |
| 1124 | viff_colormap=(unsigned char *) AcquireQuantumMemory(image->colors, |
| 1125 | 3*sizeof(*viff_colormap)); |
| 1126 | if (viff_colormap == (unsigned char *) NULL) |
| 1127 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
| 1128 | q=viff_colormap; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1129 | for (i=0; i < (ssize_t) image->colors; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1130 | *q++=ScaleQuantumToChar(image->colormap[i].red); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1131 | for (i=0; i < (ssize_t) image->colors; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1132 | *q++=ScaleQuantumToChar(image->colormap[i].green); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1133 | for (i=0; i < (ssize_t) image->colors; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1134 | *q++=ScaleQuantumToChar(image->colormap[i].blue); |
| 1135 | (void) WriteBlob(image,3*image->colors,viff_colormap); |
| 1136 | viff_colormap=(unsigned char *) RelinquishMagickMemory(viff_colormap); |
| 1137 | /* |
| 1138 | Convert PseudoClass packet to VIFF colormapped pixels. |
| 1139 | */ |
cristy | 5def203 | 2013-06-30 17:44:08 +0000 | [diff] [blame] | 1140 | q=pixels; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1141 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1142 | { |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1143 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1144 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1145 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1146 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1147 | { |
| 1148 | *q++=(unsigned char) GetPixelIndex(image,p); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1149 | p+=GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1150 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1151 | if (image->previous == (Image *) NULL) |
| 1152 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 1153 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 1154 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1155 | if (status == MagickFalse) |
| 1156 | break; |
| 1157 | } |
| 1158 | } |
| 1159 | } |
| 1160 | else |
| 1161 | if (image->colors <= 2) |
| 1162 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1163 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1164 | x, |
| 1165 | y; |
| 1166 | |
| 1167 | register unsigned char |
| 1168 | bit, |
| 1169 | byte; |
| 1170 | |
| 1171 | /* |
| 1172 | Convert PseudoClass image to a VIFF monochrome image. |
| 1173 | */ |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1174 | (void) SetImageType(image,BilevelType,exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1175 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1176 | { |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1177 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1178 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1179 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1180 | bit=0; |
| 1181 | byte=0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1182 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1183 | { |
| 1184 | byte>>=1; |
cristy | d032322 | 2013-04-07 16:13:21 +0000 | [diff] [blame] | 1185 | if (GetPixelLuma(image,p) < (QuantumRange/2.0)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1186 | byte|=0x80; |
| 1187 | bit++; |
| 1188 | if (bit == 8) |
| 1189 | { |
| 1190 | *q++=byte; |
| 1191 | bit=0; |
| 1192 | byte=0; |
| 1193 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1194 | p+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1195 | } |
| 1196 | if (bit != 0) |
| 1197 | *q++=byte >> (8-bit); |
| 1198 | if (image->previous == (Image *) NULL) |
| 1199 | { |
cristy | 5d89f43 | 2010-05-30 00:00:26 +0000 | [diff] [blame] | 1200 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) |
| 1201 | y,image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1202 | if (status == MagickFalse) |
| 1203 | break; |
| 1204 | } |
| 1205 | } |
| 1206 | } |
| 1207 | else |
| 1208 | { |
| 1209 | /* |
| 1210 | Convert PseudoClass packet to VIFF grayscale pixel. |
| 1211 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1212 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1213 | { |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1214 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1215 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1216 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1217 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1218 | { |
cristy | d032322 | 2013-04-07 16:13:21 +0000 | [diff] [blame] | 1219 | *q++=(unsigned char) ClampToQuantum(GetPixelLuma(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1220 | p+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1221 | } |
| 1222 | if (image->previous == (Image *) NULL) |
| 1223 | { |
cristy | 5d89f43 | 2010-05-30 00:00:26 +0000 | [diff] [blame] | 1224 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) |
| 1225 | y,image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1226 | if (status == MagickFalse) |
| 1227 | break; |
| 1228 | } |
| 1229 | } |
| 1230 | } |
cristy | 5def203 | 2013-06-30 17:44:08 +0000 | [diff] [blame] | 1231 | (void) WriteBlob(image,(size_t) packets,pixels); |
| 1232 | pixel_info=RelinquishVirtualMemory(pixel_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1233 | if (GetNextImageInList(image) == (Image *) NULL) |
| 1234 | break; |
| 1235 | image=SyncNextImageInList(image); |
| 1236 | status=SetImageProgress(image,SaveImagesTag,scene++, |
| 1237 | GetImageListLength(image)); |
| 1238 | if (status == MagickFalse) |
| 1239 | break; |
| 1240 | } while (image_info->adjoin != MagickFalse); |
| 1241 | (void) CloseBlob(image); |
| 1242 | return(MagickTrue); |
| 1243 | } |