cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % CCCC AAA L SSSSS % |
| 7 | % C A A L SS % |
| 8 | % C AAAAA L SSS % |
| 9 | % C A A L SS % |
| 10 | % CCCC A A LLLLL SSSSS % |
| 11 | % % |
| 12 | % % |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 13 | % Read/Write CALS Raster Group 1 Image Format % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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 | f6ff9ea | 2016-12-05 09:53:35 -0500 | [diff] [blame] | 20 | % Copyright 1999-2017 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 | % % |
Cristy | f19d414 | 2017-04-24 11:34:30 -0400 | [diff] [blame] | 26 | % https://www.imagemagick.org/script/license.php % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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 | % The CALS raster format is a standard developed by the Computer Aided |
| 37 | % Acquisition and Logistics Support (CALS) office of the United States |
| 38 | % Department of Defense to standardize graphics data interchange for |
| 39 | % electronic publishing, especially in the areas of technical graphics, |
| 40 | % CAD/CAM, and image processing applications. |
| 41 | % |
| 42 | */ |
| 43 | |
| 44 | /* |
| 45 | Include declarations. |
| 46 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 47 | #include "MagickCore/studio.h" |
| 48 | #include "MagickCore/blob.h" |
| 49 | #include "MagickCore/blob-private.h" |
| 50 | #include "MagickCore/cache.h" |
| 51 | #include "MagickCore/colorspace.h" |
cristy | 3f858f4 | 2012-01-07 00:03:25 +0000 | [diff] [blame] | 52 | #include "MagickCore/constitute.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/geometry.h" |
| 56 | #include "MagickCore/image.h" |
| 57 | #include "MagickCore/image-private.h" |
| 58 | #include "MagickCore/list.h" |
| 59 | #include "MagickCore/magick.h" |
| 60 | #include "MagickCore/memory_.h" |
| 61 | #include "MagickCore/monitor.h" |
| 62 | #include "MagickCore/monitor-private.h" |
| 63 | #include "MagickCore/option.h" |
| 64 | #include "MagickCore/quantum-private.h" |
| 65 | #include "MagickCore/resource_.h" |
| 66 | #include "MagickCore/static.h" |
| 67 | #include "MagickCore/string_.h" |
| 68 | #include "MagickCore/module.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 69 | |
cristy | 20a78b2 | 2010-04-05 01:22:12 +0000 | [diff] [blame] | 70 | #if defined(MAGICKCORE_TIFF_DELEGATE) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 71 | /* |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 72 | Forward declarations. |
| 73 | */ |
| 74 | static MagickBooleanType |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 75 | WriteCALSImage(const ImageInfo *,Image *,ExceptionInfo *); |
cristy | 20a78b2 | 2010-04-05 01:22:12 +0000 | [diff] [blame] | 76 | #endif |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 77 | |
| 78 | /* |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 79 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 80 | % % |
| 81 | % % |
| 82 | % % |
| 83 | % I s C A L S % |
| 84 | % % |
| 85 | % % |
| 86 | % % |
| 87 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 88 | % |
| 89 | % IsCALS() returns MagickTrue if the image format type, identified by the |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 90 | % magick string, is CALS Raster Group 1. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 91 | % |
| 92 | % The format of the IsCALS method is: |
| 93 | % |
| 94 | % MagickBooleanType IsCALS(const unsigned char *magick,const size_t length) |
| 95 | % |
| 96 | % A description of each parameter follows: |
| 97 | % |
| 98 | % o magick: compare image format pattern against these bytes. |
| 99 | % |
| 100 | % o length: Specifies the length of the magick string. |
| 101 | % |
| 102 | */ |
| 103 | static MagickBooleanType IsCALS(const unsigned char *magick,const size_t length) |
| 104 | { |
| 105 | if (length < 128) |
| 106 | return(MagickFalse); |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 107 | if (LocaleNCompare((const char *) magick,"version: MIL-STD-1840",21) == 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 108 | return(MagickTrue); |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 109 | if (LocaleNCompare((const char *) magick,"srcdocid:",9) == 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 110 | return(MagickTrue); |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 111 | if (LocaleNCompare((const char *) magick,"rorient:",8) == 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 112 | return(MagickTrue); |
| 113 | return(MagickFalse); |
| 114 | } |
| 115 | |
| 116 | /* |
| 117 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 118 | % % |
| 119 | % % |
| 120 | % % |
| 121 | % R e a d C A L S I m a g e % |
| 122 | % % |
| 123 | % % |
| 124 | % % |
| 125 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 126 | % |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 127 | % ReadCALSImage() reads an CALS Raster Group 1 image format image file and |
| 128 | % returns it. It allocates the memory necessary for the new Image structure |
| 129 | % and returns a pointer to the new image. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 130 | % |
| 131 | % The format of the ReadCALSImage method is: |
| 132 | % |
| 133 | % Image *ReadCALSImage(const ImageInfo *image_info, |
| 134 | % ExceptionInfo *exception) |
| 135 | % |
| 136 | % A description of each parameter follows: |
| 137 | % |
| 138 | % o image_info: the image info. |
| 139 | % |
| 140 | % o exception: return any errors or warnings in this structure. |
| 141 | % |
| 142 | */ |
cristy | 2d6ccc3 | 2009-09-25 03:18:25 +0000 | [diff] [blame] | 143 | static Image *ReadCALSImage(const ImageInfo *image_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 144 | ExceptionInfo *exception) |
| 145 | { |
| 146 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 147 | filename[MagickPathExtent], |
| 148 | header[MagickPathExtent], |
| 149 | message[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 150 | |
| 151 | FILE |
| 152 | *file; |
| 153 | |
| 154 | Image |
cristy | 2d6ccc3 | 2009-09-25 03:18:25 +0000 | [diff] [blame] | 155 | *image; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 156 | |
| 157 | ImageInfo |
| 158 | *read_info; |
| 159 | |
| 160 | int |
| 161 | c, |
| 162 | unique_file; |
| 163 | |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 164 | MagickBooleanType |
| 165 | status; |
| 166 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 167 | register ssize_t |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 168 | i; |
| 169 | |
cristy | b5af3b0 | 2011-04-24 03:01:28 +0000 | [diff] [blame] | 170 | unsigned long |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 171 | density, |
| 172 | direction, |
| 173 | height, |
| 174 | orientation, |
| 175 | pel_path, |
| 176 | type, |
| 177 | width; |
| 178 | |
| 179 | /* |
| 180 | Open image file. |
| 181 | */ |
| 182 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 183 | assert(image_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 184 | if (image_info->debug != MagickFalse) |
| 185 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 186 | image_info->filename); |
| 187 | assert(exception != (ExceptionInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 188 | assert(exception->signature == MagickCoreSignature); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 189 | image=AcquireImage(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 190 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 191 | if (status == MagickFalse) |
| 192 | { |
| 193 | image=DestroyImageList(image); |
| 194 | return((Image *) NULL); |
| 195 | } |
| 196 | /* |
| 197 | Read CALS header. |
| 198 | */ |
| 199 | (void) ResetMagickMemory(header,0,sizeof(header)); |
| 200 | density=0; |
| 201 | direction=0; |
| 202 | orientation=1; |
| 203 | pel_path=0; |
| 204 | type=1; |
| 205 | width=0; |
| 206 | height=0; |
| 207 | for (i=0; i < 16; i++) |
| 208 | { |
| 209 | if (ReadBlob(image,128,(unsigned char *) header) != 128) |
| 210 | break; |
| 211 | switch (*header) |
| 212 | { |
| 213 | case 'R': |
| 214 | case 'r': |
| 215 | { |
| 216 | if (LocaleNCompare(header,"rdensty:",8) == 0) |
| 217 | { |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 218 | (void) sscanf(header+8,"%lu",&density); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 219 | break; |
| 220 | } |
| 221 | if (LocaleNCompare(header,"rpelcnt:",8) == 0) |
| 222 | { |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 223 | (void) sscanf(header+8,"%lu,%lu",&width,&height); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 224 | break; |
| 225 | } |
| 226 | if (LocaleNCompare(header,"rorient:",8) == 0) |
| 227 | { |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 228 | (void) sscanf(header+8,"%lu,%lu",&pel_path,&direction); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 229 | if (pel_path == 90) |
| 230 | orientation=5; |
| 231 | else |
cristy | 2e68c0c | 2010-04-06 13:10:46 +0000 | [diff] [blame] | 232 | if (pel_path == 180) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 233 | orientation=3; |
| 234 | else |
| 235 | if (pel_path == 270) |
| 236 | orientation=7; |
| 237 | if (direction == 90) |
| 238 | orientation++; |
| 239 | break; |
| 240 | } |
| 241 | if (LocaleNCompare(header,"rtype:",6) == 0) |
| 242 | { |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 243 | (void) sscanf(header+6,"%lu",&type); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 244 | break; |
| 245 | } |
| 246 | break; |
| 247 | } |
| 248 | } |
| 249 | } |
cristy | 2d6ccc3 | 2009-09-25 03:18:25 +0000 | [diff] [blame] | 250 | /* |
| 251 | Read CALS pixels. |
| 252 | */ |
| 253 | file=(FILE *) NULL; |
| 254 | unique_file=AcquireUniqueFileResource(filename); |
| 255 | if (unique_file != -1) |
| 256 | file=fdopen(unique_file,"wb"); |
| 257 | if ((unique_file == -1) || (file == (FILE *) NULL)) |
| 258 | ThrowImageException(FileOpenError,"UnableToCreateTemporaryFile"); |
| 259 | while ((c=ReadBlobByte(image)) != EOF) |
| 260 | (void) fputc(c,file); |
| 261 | (void) fclose(file); |
| 262 | (void) CloseBlob(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 263 | image=DestroyImage(image); |
cristy | 2d6ccc3 | 2009-09-25 03:18:25 +0000 | [diff] [blame] | 264 | read_info=CloneImageInfo(image_info); |
| 265 | SetImageInfoBlob(read_info,(void *) NULL,0); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 266 | (void) FormatLocaleString(read_info->filename,MagickPathExtent,"group4:%s", |
cristy | 2d6ccc3 | 2009-09-25 03:18:25 +0000 | [diff] [blame] | 267 | filename); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 268 | (void) FormatLocaleString(message,MagickPathExtent,"%lux%lu",width,height); |
cristy | a2fdc91 | 2011-10-21 11:36:39 +0000 | [diff] [blame] | 269 | (void) CloneString(&read_info->size,message); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 270 | (void) FormatLocaleString(message,MagickPathExtent,"%lu",density); |
cristy | a2fdc91 | 2011-10-21 11:36:39 +0000 | [diff] [blame] | 271 | (void) CloneString(&read_info->density,message); |
cristy | 2d6ccc3 | 2009-09-25 03:18:25 +0000 | [diff] [blame] | 272 | read_info->orientation=(OrientationType) orientation; |
| 273 | image=ReadImage(read_info,exception); |
| 274 | if (image != (Image *) NULL) |
| 275 | { |
| 276 | (void) CopyMagickString(image->filename,image_info->filename, |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 277 | MagickPathExtent); |
cristy | 2d6ccc3 | 2009-09-25 03:18:25 +0000 | [diff] [blame] | 278 | (void) CopyMagickString(image->magick_filename,image_info->filename, |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 279 | MagickPathExtent); |
| 280 | (void) CopyMagickString(image->magick,"CALS",MagickPathExtent); |
cristy | 2d6ccc3 | 2009-09-25 03:18:25 +0000 | [diff] [blame] | 281 | } |
| 282 | read_info=DestroyImageInfo(read_info); |
| 283 | (void) RelinquishUniqueFileResource(filename); |
| 284 | return(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | /* |
| 288 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 289 | % % |
| 290 | % % |
| 291 | % % |
| 292 | % R e g i s t e r C A L S I m a g e % |
| 293 | % % |
| 294 | % % |
| 295 | % % |
| 296 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 297 | % |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 298 | % RegisterCALSImage() adds attributes for the CALS Raster Group 1 image file |
| 299 | % image format to the list of supported formats. The attributes include the |
| 300 | % image format tag, a method to read and/or write the format, whether the |
| 301 | % format supports the saving of more than one frame to the same file or blob, |
| 302 | % whether the format supports native in-memory I/O, and a brief description |
| 303 | % of the format. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 304 | % |
| 305 | % The format of the RegisterCALSImage method is: |
| 306 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 307 | % size_t RegisterCALSImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 308 | % |
| 309 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 310 | ModuleExport size_t RegisterCALSImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 311 | { |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 312 | #define CALSDescription "Continuous Acquisition and Life-cycle Support Type 1" |
| 313 | #define CALSNote "Specified in MIL-R-28002 and MIL-PRF-28002" |
| 314 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 315 | MagickInfo |
| 316 | *entry; |
| 317 | |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 318 | entry=AcquireMagickInfo("CALS","CAL",CALSDescription); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 319 | entry->decoder=(DecodeImageHandler *) ReadCALSImage; |
cristy | 9ca5955 | 2009-09-23 13:40:25 +0000 | [diff] [blame] | 320 | #if defined(MAGICKCORE_TIFF_DELEGATE) |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 321 | entry->encoder=(EncodeImageHandler *) WriteCALSImage; |
cristy | 9ca5955 | 2009-09-23 13:40:25 +0000 | [diff] [blame] | 322 | #endif |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 323 | entry->flags^=CoderAdjoinFlag; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 324 | entry->magick=(IsImageFormatHandler *) IsCALS; |
cristy | 9ca5955 | 2009-09-23 13:40:25 +0000 | [diff] [blame] | 325 | entry->note=ConstantString(CALSNote); |
cristy | 9ca5955 | 2009-09-23 13:40:25 +0000 | [diff] [blame] | 326 | (void) RegisterMagickInfo(entry); |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 327 | entry=AcquireMagickInfo("CALS","CALS",CALSDescription); |
cristy | 9ca5955 | 2009-09-23 13:40:25 +0000 | [diff] [blame] | 328 | entry->decoder=(DecodeImageHandler *) ReadCALSImage; |
| 329 | #if defined(MAGICKCORE_TIFF_DELEGATE) |
| 330 | entry->encoder=(EncodeImageHandler *) WriteCALSImage; |
| 331 | #endif |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 332 | entry->flags^=CoderAdjoinFlag; |
cristy | 9ca5955 | 2009-09-23 13:40:25 +0000 | [diff] [blame] | 333 | entry->magick=(IsImageFormatHandler *) IsCALS; |
cristy | 9ca5955 | 2009-09-23 13:40:25 +0000 | [diff] [blame] | 334 | entry->note=ConstantString(CALSNote); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 335 | (void) RegisterMagickInfo(entry); |
| 336 | return(MagickImageCoderSignature); |
| 337 | } |
| 338 | |
| 339 | /* |
| 340 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 341 | % % |
| 342 | % % |
| 343 | % % |
| 344 | % U n r e g i s t e r C A L S I m a g e % |
| 345 | % % |
| 346 | % % |
| 347 | % % |
| 348 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 349 | % |
| 350 | % UnregisterCALSImage() removes format registrations made by the |
| 351 | % CALS module from the list of supported formats. |
| 352 | % |
| 353 | % The format of the UnregisterCALSImage method is: |
| 354 | % |
| 355 | % UnregisterCALSImage(void) |
| 356 | % |
| 357 | */ |
| 358 | ModuleExport void UnregisterCALSImage(void) |
| 359 | { |
cristy | 9ca5955 | 2009-09-23 13:40:25 +0000 | [diff] [blame] | 360 | (void) UnregisterMagickInfo("CAL"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 361 | (void) UnregisterMagickInfo("CALS"); |
| 362 | } |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 363 | |
cristy | 316dac1 | 2009-12-07 17:19:28 +0000 | [diff] [blame] | 364 | #if defined(MAGICKCORE_TIFF_DELEGATE) |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 365 | /* |
| 366 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 367 | % % |
| 368 | % % |
| 369 | % % |
| 370 | % W r i t e C A L S I m a g e % |
| 371 | % % |
| 372 | % % |
| 373 | % % |
| 374 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 375 | % |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 376 | % WriteCALSImage() writes an image to a file in CALS Raster Group 1 image |
| 377 | % format. |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 378 | % |
| 379 | % The format of the WriteCALSImage method is: |
| 380 | % |
| 381 | % MagickBooleanType WriteCALSImage(const ImageInfo *image_info, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 382 | % Image *image,ExceptionInfo *exception) |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 383 | % |
| 384 | % A description of each parameter follows. |
| 385 | % |
| 386 | % o image_info: the image info. |
| 387 | % |
| 388 | % o image: The image. |
| 389 | % |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 390 | % o exception: return any errors or warnings in this structure. |
| 391 | % |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 392 | */ |
| 393 | |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 394 | static ssize_t WriteCALSRecord(Image *image,const char *data) |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 395 | { |
| 396 | char |
| 397 | pad[128]; |
| 398 | |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 399 | register const char |
| 400 | *p; |
| 401 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 402 | register ssize_t |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 403 | i; |
| 404 | |
cristy | 4e82e51 | 2011-04-24 01:33:42 +0000 | [diff] [blame] | 405 | ssize_t |
| 406 | count; |
| 407 | |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 408 | i=0; |
cristy | 564a569 | 2012-01-20 23:56:26 +0000 | [diff] [blame] | 409 | count=0; |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 410 | if (data != (const char *) NULL) |
| 411 | { |
| 412 | p=data; |
| 413 | for (i=0; (i < 128) && (p[i] != '\0'); i++); |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 414 | count=WriteBlob(image,(size_t) i,(const unsigned char *) data); |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 415 | } |
| 416 | if (i < 128) |
| 417 | { |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 418 | i=128-i; |
cristy | 9f027d1 | 2011-09-21 01:17:17 +0000 | [diff] [blame] | 419 | (void) ResetMagickMemory(pad,' ',(size_t) i); |
cristy | 47b838c | 2009-09-19 16:09:30 +0000 | [diff] [blame] | 420 | count=WriteBlob(image,(size_t) i,(const unsigned char *) pad); |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 421 | } |
| 422 | return(count); |
| 423 | } |
| 424 | |
| 425 | static MagickBooleanType WriteCALSImage(const ImageInfo *image_info, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 426 | Image *image,ExceptionInfo *exception) |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 427 | { |
| 428 | char |
cristy | 2d6ccc3 | 2009-09-25 03:18:25 +0000 | [diff] [blame] | 429 | header[129]; |
| 430 | |
| 431 | Image |
| 432 | *group4_image; |
| 433 | |
| 434 | ImageInfo |
| 435 | *write_info; |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 436 | |
| 437 | MagickBooleanType |
| 438 | status; |
| 439 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 440 | register ssize_t |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 441 | i; |
| 442 | |
cristy | 4e82e51 | 2011-04-24 01:33:42 +0000 | [diff] [blame] | 443 | size_t |
| 444 | density, |
| 445 | length, |
| 446 | orient_x, |
| 447 | orient_y; |
| 448 | |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 449 | ssize_t |
| 450 | count; |
| 451 | |
cristy | 2d6ccc3 | 2009-09-25 03:18:25 +0000 | [diff] [blame] | 452 | unsigned char |
| 453 | *group4; |
| 454 | |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 455 | /* |
| 456 | Open output image file. |
| 457 | */ |
| 458 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 459 | assert(image_info->signature == MagickCoreSignature); |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 460 | assert(image != (Image *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 461 | assert(image->signature == MagickCoreSignature); |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 462 | if (image->debug != MagickFalse) |
| 463 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 464 | assert(exception != (ExceptionInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 465 | assert(exception->signature == MagickCoreSignature); |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 466 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 467 | if (status == MagickFalse) |
| 468 | return(status); |
| 469 | /* |
| 470 | Create standard CALS header. |
| 471 | */ |
| 472 | count=WriteCALSRecord(image,"srcdocid: NONE"); |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 473 | (void) count; |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 474 | count=WriteCALSRecord(image,"dstdocid: NONE"); |
| 475 | count=WriteCALSRecord(image,"txtfilid: NONE"); |
| 476 | count=WriteCALSRecord(image,"figid: NONE"); |
| 477 | count=WriteCALSRecord(image,"srcgph: NONE"); |
dirk | b69086d | 2016-01-21 12:53:52 +0100 | [diff] [blame] | 478 | count=WriteCALSRecord(image,"doccls: NONE"); |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 479 | count=WriteCALSRecord(image,"rtype: 1"); |
cristy | 43b2de0 | 2009-09-19 16:19:31 +0000 | [diff] [blame] | 480 | orient_x=0; |
| 481 | orient_y=0; |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 482 | switch (image->orientation) |
| 483 | { |
| 484 | case TopRightOrientation: |
| 485 | { |
| 486 | orient_x=180; |
| 487 | orient_y=270; |
| 488 | break; |
| 489 | } |
| 490 | case BottomRightOrientation: |
| 491 | { |
| 492 | orient_x=180; |
| 493 | orient_y=90; |
| 494 | break; |
| 495 | } |
| 496 | case BottomLeftOrientation: |
cristy | 43b2de0 | 2009-09-19 16:19:31 +0000 | [diff] [blame] | 497 | { |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 498 | orient_y=90; |
| 499 | break; |
cristy | 43b2de0 | 2009-09-19 16:19:31 +0000 | [diff] [blame] | 500 | } |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 501 | case LeftTopOrientation: |
| 502 | { |
| 503 | orient_x=270; |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 504 | break; |
| 505 | } |
| 506 | case RightTopOrientation: |
| 507 | { |
| 508 | orient_x=270; |
| 509 | orient_y=180; |
| 510 | break; |
| 511 | } |
| 512 | case RightBottomOrientation: |
| 513 | { |
| 514 | orient_x=90; |
| 515 | orient_y=180; |
| 516 | break; |
| 517 | } |
| 518 | case LeftBottomOrientation: |
| 519 | { |
| 520 | orient_x=90; |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 521 | break; |
| 522 | } |
| 523 | default: |
| 524 | { |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 525 | orient_y=270; |
cristy | f2a82ee | 2014-05-26 17:49:54 +0000 | [diff] [blame] | 526 | break; |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 527 | } |
| 528 | } |
cristy | f2a82ee | 2014-05-26 17:49:54 +0000 | [diff] [blame] | 529 | (void) FormatLocaleString(header,sizeof(header),"rorient: %03ld,%03ld", |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 530 | (long) orient_x,(long) orient_y); |
cristy | 2d6ccc3 | 2009-09-25 03:18:25 +0000 | [diff] [blame] | 531 | count=WriteCALSRecord(image,header); |
cristy | f2a82ee | 2014-05-26 17:49:54 +0000 | [diff] [blame] | 532 | (void) FormatLocaleString(header,sizeof(header),"rpelcnt: %06lu,%06lu", |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 533 | (unsigned long) image->columns,(unsigned long) image->rows); |
cristy | 2d6ccc3 | 2009-09-25 03:18:25 +0000 | [diff] [blame] | 534 | count=WriteCALSRecord(image,header); |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 535 | density=200; |
| 536 | if (image_info->density != (char *) NULL) |
| 537 | { |
| 538 | GeometryInfo |
| 539 | geometry_info; |
| 540 | |
| 541 | (void) ParseGeometry(image_info->density,&geometry_info); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 542 | density=(size_t) floor(geometry_info.rho+0.5); |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 543 | } |
cristy | f2a82ee | 2014-05-26 17:49:54 +0000 | [diff] [blame] | 544 | (void) FormatLocaleString(header,sizeof(header),"rdensty: %04lu", |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 545 | (unsigned long) density); |
cristy | 2d6ccc3 | 2009-09-25 03:18:25 +0000 | [diff] [blame] | 546 | count=WriteCALSRecord(image,header); |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 547 | count=WriteCALSRecord(image,"notes: NONE"); |
cristy | 2d6ccc3 | 2009-09-25 03:18:25 +0000 | [diff] [blame] | 548 | (void) ResetMagickMemory(header,' ',128); |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 549 | for (i=0; i < 5; i++) |
cristy | 2d6ccc3 | 2009-09-25 03:18:25 +0000 | [diff] [blame] | 550 | (void) WriteBlob(image,128,(unsigned char *) header); |
| 551 | /* |
| 552 | Write CALS pixels. |
| 553 | */ |
| 554 | write_info=CloneImageInfo(image_info); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 555 | (void) CopyMagickString(write_info->filename,"GROUP4:",MagickPathExtent); |
| 556 | (void) CopyMagickString(write_info->magick,"GROUP4",MagickPathExtent); |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 557 | group4_image=CloneImage(image,0,0,MagickTrue,exception); |
cristy | 2d6ccc3 | 2009-09-25 03:18:25 +0000 | [diff] [blame] | 558 | if (group4_image == (Image *) NULL) |
| 559 | { |
Cristy | 73b6c35 | 2017-07-16 20:33:35 -0400 | [diff] [blame^] | 560 | write_info=DestroyImageInfo(write_info); |
cristy | 2d6ccc3 | 2009-09-25 03:18:25 +0000 | [diff] [blame] | 561 | (void) CloseBlob(image); |
| 562 | return(MagickFalse); |
| 563 | } |
| 564 | group4=(unsigned char *) ImageToBlob(write_info,group4_image,&length, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 565 | exception); |
cristy | 2d6ccc3 | 2009-09-25 03:18:25 +0000 | [diff] [blame] | 566 | group4_image=DestroyImage(group4_image); |
| 567 | if (group4 == (unsigned char *) NULL) |
| 568 | { |
Cristy | 73b6c35 | 2017-07-16 20:33:35 -0400 | [diff] [blame^] | 569 | write_info=DestroyImageInfo(write_info); |
cristy | 2d6ccc3 | 2009-09-25 03:18:25 +0000 | [diff] [blame] | 570 | (void) CloseBlob(image); |
| 571 | return(MagickFalse); |
| 572 | } |
| 573 | write_info=DestroyImageInfo(write_info); |
| 574 | if (WriteBlob(image,length,group4) != (ssize_t) length) |
| 575 | status=MagickFalse; |
| 576 | group4=(unsigned char *) RelinquishMagickMemory(group4); |
cristy | 0311700 | 2009-09-19 02:10:44 +0000 | [diff] [blame] | 577 | (void) CloseBlob(image); |
| 578 | return(status); |
| 579 | } |
cristy | 316dac1 | 2009-12-07 17:19:28 +0000 | [diff] [blame] | 580 | #endif |