|
26 | 26 | ; blue : the Blue colormap vector (for PseudoColor images)
|
27 | 27 | ;
|
28 | 28 | ; RESTRICTIONS:
|
29 |
| -; Requires ImageMagick or GraphicsMagick |
| 29 | +; Requires ImageMagick or GraphicsMagick. |
30 | 30 | ;
|
31 | 31 | ; PROCEDURE:
|
32 |
| -; Use ImageMagick to write the data as requested |
| 32 | +; Uses ImageMagick to write the data as requested |
33 | 33 | ;
|
34 | 34 | ; EXAMPLE:
|
35 | 35 | ; Currently no example is available
|
36 | 36 | ;
|
37 | 37 | ; MODIFICATION HISTORY:
|
38 |
| -; Written by: Jeongbin Park 2015-04-03, based on write_png.pro |
39 |
| -; |
| 38 | +; Written by James Tappin, based on the extant routine attempt to |
| 39 | +; discern what is meant to happen. |
40 | 40 | ;-
|
41 | 41 | ; LICENCE:
|
42 |
| -; Copyright (C) 2015: JP |
| 42 | +; Copyright (C) 2021: SJT |
43 | 43 | ; This program is free software; you can redistribute it and/or modify
|
44 | 44 | ; it under the terms of the GNU General Public License as published by
|
45 | 45 | ; the Free Software Foundation; either version 2 of the License, or
|
46 | 46 | ; (at your option) any later version.
|
47 |
| -; |
48 |
| -;- |
49 |
| -; |
50 |
| -pro WRITE_TIFF, filename, image, bits_per_sample, red=red, green=green, blue=blue, $ |
51 |
| - compression=compression, verbose=verbose, help=help, test=test, $ |
52 |
| - debug=debug |
53 |
| -; lacks: /APPEND, /BIGTIFF, /CMYK, DESCRIPTION=, DOCUMENT_NAME=, DOT_RANGE=, GEOTIFF=, |
54 |
| -; /COMPLEX, /DCOMPLEX , /DOUBLE , /L64, /LONG, /SHORT , /FLOAT, ICC_PROFILE=, |
55 |
| -; ORIENTATION=, PHOTOSHOP=, PLANARCONFIG=, /SIGNED, UNITS=, XPOSITION=, XRESOL, |
56 |
| -; YPOSITION=, YRESOL= |
57 |
| -; |
| 47 | + |
| 48 | +pro WRITE_TIFF, filename, image, bits_per_sample, $ |
| 49 | + red = red, green = green, blue = blue, $ |
| 50 | + compression = compression, verbose = verbose, $ |
| 51 | + help = help, test = test, $ |
| 52 | + debug = debug, order = order |
| 53 | + |
58 | 54 | ; this line allows to compile also in IDL ...
|
59 |
| -FORWARD_FUNCTION MAGICK_EXISTS, MAGICK_PING, MAGICK_READ |
60 |
| -; |
61 |
| -;if ~KEYWORD_SET(debug) then ON_ERROR, 2 |
62 |
| -; |
63 |
| -if KEYWORD_SET(help) then begin |
64 |
| - print, 'pro WRITE_TIFF, filename, image, bits_per_sample, red=red, green=green, blue=blue, $' |
65 |
| - print, ' compression=compression, verbose=verbose, help=help, test=test, $' |
66 |
| - print, ' debug=debug $' |
67 |
| - return |
68 |
| -endif |
69 |
| -; |
70 |
| -; Do we have access to ImageMagick functionnalities ?? |
71 |
| -; |
72 |
| -if (MAGICK_EXISTS() EQ 0) then begin |
73 |
| - MESSAGE, /continue, "GDL was compiled without ImageMagick support." |
74 |
| - MESSAGE, "You must have ImageMagick support to use this functionaly." |
75 |
| -endif |
76 |
| -; |
77 |
| -rgb=1 |
78 |
| -; |
79 |
| -nb_dims=SIZE(image, /n_dimensions) |
80 |
| -; |
81 |
| -if (nb_dims LT 2) OR (nb_dims GT 3) then begin |
82 |
| - MESSAGE, "Image array must be (n,m) or (k,n,m)." |
83 |
| -endif |
84 |
| -if (nb_dims eq 3) then begin |
85 |
| - MESSAGE, "Image array with (k,n,m) is not supported yet!" |
86 |
| -endif |
87 |
| -; |
88 |
| -im_size=SIZE(image,/dimensions) |
89 |
| -; |
90 |
| -if (nb_dims EQ 2) then mid=MAGICK_CREATE(im_size[0],im_size[1]) |
91 |
| -; |
92 |
| -if KEYWORD_SET(red) AND KEYWORD_SET(green) AND KEYWORD_SET(blue) then begin |
93 |
| - TVLCT, red, green, blue, /get |
94 |
| -endif else begin |
95 |
| - red = BINDGEN(256) |
96 |
| - green = BINDGEN(256) |
97 |
| - blue = BINDGEN(256) |
98 |
| -endelse |
99 |
| -MAGICK_WRITECOLORTABLE, mid, red, green, blue |
100 |
| -_image=TRANSPOSE([[[red [image]]],$ |
101 |
| - [[green[image]]],$ |
102 |
| - [[blue [image]]]],$ |
103 |
| - [2,0,1]) |
| 55 | + forward_function magick_exists, magick_ping, magick_read |
| 56 | + |
| 57 | + |
| 58 | + if keyword_set(help) then begin |
| 59 | + print, ' RITE_TIFF, filename, image, bits_per_sample, red=red, green=green, blue=blue, $' |
| 60 | + print, ' compression=compression, verbose=verbose, help=help, test=test, $' |
| 61 | + print, ' debug=debug' |
| 62 | + return |
| 63 | + endif |
| 64 | +; |
| 65 | +; Do we have access to ImageMagick functionalities ?? |
| 66 | +; |
| 67 | + if (MAGICK_EXISTS() EQ 0) then begin |
| 68 | + MESSAGE, /continue, $ |
| 69 | + "GDL was compiled without ImageMagick/GraphicsMagick support." |
| 70 | + MESSAGE, "You must have one of these to use this functionality." |
| 71 | + endif |
| 72 | + |
| 73 | + sz = size(image) |
| 74 | + |
| 75 | + case sz[0] of |
| 76 | + 2: begin |
| 77 | + mid = magick_create(sz[1], sz[2]) |
| 78 | + psflag = 1b |
| 79 | + end |
| 80 | + 3: begin |
| 81 | + md = min(sz[1:3], imd) |
| 82 | + psflag = md eq 2 ; Pseudo colour with transparency |
| 83 | + if md ne 3 then begin |
| 84 | + message, /continue, $ |
| 85 | + "Images with transparency aren't properly " + $ |
| 86 | + "supported yet" |
| 87 | + message, /continue, $ |
| 88 | + "the result will be corrupted." |
| 89 | + endif |
| 90 | + case imd of |
| 91 | + 0: begin |
| 92 | + seq = [0, 1, 2] |
| 93 | + mid = magick_create(sz[2], sz[3]) |
| 94 | + end |
| 95 | + 1: begin |
| 96 | + seq = [1, 0, 2] |
| 97 | + mid = magick_create(sz[1], sz[3]) |
| 98 | + end |
| 99 | + 2: begin |
| 100 | + seq = [2, 0, 1] |
| 101 | + mid = magick_create(sz[1], sz[2]) |
| 102 | + end |
| 103 | + endcase |
| 104 | + end |
| 105 | + else: message, "Image array must be of dimension (n,m) or (k,n,m)." |
| 106 | + endcase |
| 107 | + |
| 108 | + if psflag then begin |
| 109 | + if ~keyword_set(red) then red = bindgen(256) |
| 110 | + if ~keyword_set(green) then green = bindgen(256) |
| 111 | + if ~keyword_set(blue) then blue = bindgen(256) |
| 112 | + |
| 113 | + if sz[0] eq 2 then begin |
| 114 | + timage = transpose([[[red [image]]], $ |
| 115 | + [[green[image]]], $ |
| 116 | + [[blue [image]]]], $ |
| 117 | + [2, 0, 1]) |
| 118 | + endif else begin |
| 119 | + case imd of |
| 120 | + 0: begin |
| 121 | + fci = reform(image[0, *, *]) |
| 122 | + tri = reform(image[1, *, *]) |
| 123 | + end |
| 124 | + 1: begin |
| 125 | + fci = reform(image[*, 0, *]) |
| 126 | + tri = reform(image[*, 1, *]) |
| 127 | + end |
| 128 | + 2: begin |
| 129 | + fci = reform(image[*, *, 0]) |
| 130 | + tri = reform(image[*, *, 1]) |
| 131 | + end |
| 132 | + endcase |
| 133 | + timage = transpose([[[red [fci]]], $ |
| 134 | + [[green[fci]]], $ |
| 135 | + [[blue [fci]]], $ |
| 136 | + [[tri]]], $ |
| 137 | + [2, 0, 1]) |
| 138 | + endelse |
| 139 | + endif else begin |
| 140 | + if imd eq 0 then timage = image $ |
| 141 | + else timage = transpose(image, seq) |
| 142 | + endelse |
| 143 | + |
| 144 | + if keyword_set(order) then timage = reverse(timage, 3) |
| 145 | + |
| 146 | + magick_write, mid, timage, rgb = 1s |
| 147 | + magick_writefile, mid, filename, 'TIFF' |
| 148 | + magick_close, mid |
104 | 149 |
|
105 |
| -MAGICK_WRITE, mid, _image, rgb=1 |
106 |
| -MAGICK_WRITEFILE, mid, filename, "TIFF" |
107 |
| -MAGICK_CLOSE, mid |
108 |
| -; |
109 |
| -if KEYWORD_SET(test) OR KEYWORD_SET(debug) then STOP |
110 |
| -; |
111 | 150 | end
|
0 commit comments