Skip to content

Commit 5d4e0ca

Browse files
authored
should make colormap images (palette images) OK. (#1864)
1 parent d6d8c4a commit 5d4e0ca

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

src/pro/write_bmp.pro

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,8 @@ endif else begin
9696
MAGICK_WRITE, mid,_image,rgb=rgb
9797
if (N_ELEMENTS(red) eq N_ELEMENTS(green) and $
9898
N_ELEMENTS(red) eq N_ELEMENTS(blue)) then begin
99+
MAGICK_WRITEColorTable,mid,red,green,blue
99100
MAGICK_QUANTIZE,mid,long(N_ELEMENTS(red))
100-
;;
101-
;; MAGICK_WRITEIndexes,mid,image
102-
;; MAGICK_WRITEColorTable,mid,red,green,blue
103-
;;
104101
MAGICK_WRITEFILE, mid, filename, "BMP"
105102
MAGICK_CLOSE, mid
106103
endif

src/pro/write_jpeg.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ pro WRITE_JPEG, filename, image, true=true, $
124124
endif else begin
125125
mid=MAGICK_CREATE(im_size[0],im_size[1]) ; only 2 dimensions allowed here
126126
; create a greyscale colormap
127-
cmap=indgen(256)
128-
MAGICK_WRITECOLORTABLE, mid,cmap,cmap,cmap
127+
;; cmap=indgen(256)
129128
MAGICK_WRITE, mid, image
129+
;; MAGICK_WRITECOLORTABLE, mid,cmap,cmap,cmap
130130
if (KEYWORD_SET(progressive)) then MAGICK_INTERLACE, mid, /LINEINTERLACE
131131
if (KEYWORD_SET(order)) then MAGICK_FLIP,mid
132132
q=75

src/pro/write_pict.pro

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,8 @@ if (n eq 2) then begin
8383
MAGICK_FLIP,mid
8484
if(N_ELEMENTS(red) eq N_ELEMENTS(green) and $
8585
N_ELEMENTS(red) eq N_ELEMENTS(blue)) then begin
86+
MAGICK_WRITEColorTable,mid,red,green,blue
8687
MAGICK_QUANTIZE,mid,long(N_ELEMENTS(red))
87-
;;
88-
;; MAGICK_WRITEIndexes,mid,image
89-
;; MAGICK_WRITEColorTable,mid,red,green,blue
90-
;;
9188
MAGICK_WRITEfile,mid,filename,"PICT"
9289
MAGICK_CLOSE,mid
9390
endif

src/pro/write_png.pro

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,15 @@ if (nb_channels eq 1) then begin
126126
alpha=image*0+255
127127
MAGICK_MATTE, mid
128128
endif
129-
;;
130-
MAGICK_WRITECOLORTABLE, mid, red, green, blue
129+
;; for some reason imagemagick does not use colortables when writing PNG files with 1 channel images.
130+
;; Better to do it by hand:
131+
rr=image & gg=image & bb=image
132+
for i=0,im_size[0]*im_size[1]-1 do rr[i]=red[rr[i]]
133+
for i=0,im_size[0]*im_size[1]-1 do gg[i]=green[gg[i]]
134+
for i=0,im_size[0]*im_size[1]-1 do bb[i]=blue[bb[i]]
135+
image=transpose([[[rr]],[[gg]],[[bb]]],[2,0,1])
131136
MAGICK_WRITE, mid, image, rgb=rgb
137+
;; MAGICK_WRITECOLORTABLE, mid, red, green, blue
132138
if (KEYWORD_SET(order)) then MAGICK_FLIP, mid
133139
MAGICK_WRITEFILE, mid, filename, "PNG"
134140
MAGICK_CLOSE, mid

src/pro/write_ppm.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ pro write_ppm, file, image, help = help
4141
if sz[0] eq 2 then begin ; PGM
4242
mid = magick_create(sz[1], sz[2])
4343
cmap = indgen(256)
44-
magick_writecolortable, mid, cmap, cmap, cmap
4544
magick_write, mid, reverse(image, 2)
45+
magick_writecolortable, mid, cmap, cmap, cmap
4646
magick_writefile, mid, file, 'PGM'
4747
endif else if sz[0] eq 3 && sz[1] eq 3 then begin ; PPM
4848
mid = magick_create(sz[2], sz[3])

0 commit comments

Comments
 (0)