Taking a deep breath here...this problem is getting more complex, but I still think there is a bug.
After additional testing, I can report the following (using more concise and informative scripts).
Case 1 (Resize included, but no processing on the clones)
This WORKS:
Code: Select all
magick -quiet input.tif embedded.icc
magick -quiet -verbose input.tif ^
-profile Gray-elle-V2-g10.icc ^
-define filter:c=0.1601886205085204 -filter Cubic -distort Resize 500 +write tmp1 ^
( -clone 0 +write tmp2 ) ^
( -clone 0 ) ^
-delete 0 ^
( -clone 1 -auto-level ) ^
-compose over -composite +write tmp3 ^
-profile embedded.icc ^
output.tif
Code: Select all
input.tif TIFF 600x761 600x761+0+0 16-bit Grayscale Gray 942748B 0.078u 0:00.076
Gray-elle-V2-g10.icc ICC 1x1 1x1+0+0 16-bit sRGB 512B 0.000u 0:00.000
Affine Projection:
-distort AffineProjection \
'0.833333,-0.000000,-0.000000,0.833114,0.000000,0.000000'
Affine Distort, FX Equivelent:
-size 502x636 -page -1-1 xc: +insert \
-fx 'ii=i+page.x+0.5; jj=j+page.y+0.5;
xx=+1.200000*ii +0.000000*jj +0.000000;
yy=+0.000000*ii +1.200315*jj +0.000000;
v.p{ xx-v.page.x-.5, yy-v.page.y-.5 }' \
input.tif=>tmp1 TIFF 600x761=>500x634 16-bit Grayscale Gray 663416B 0.031u 0:00.007
input.tif=>tmp2 TIFF 600x761=>500x634 16-bit Grayscale Gray 663416B 0.000u 0:00.006
input.tif=>tmp3 TIFF 600x761=>500x634 16-bit Grayscale Gray 663504B 0.000u 0:00.006
embedded.icc ICC 1x1 1x1+0+0 16-bit sRGB 408B 0.000u 0:00.000
input.tif=>output.tif TIFF 600x761=>500x634 16-bit Grayscale Gray 663400B 0.156u 0:00.066
As you can see in the verbose output above, everything stays in "...Grayscale Gray..." throughout. (It does seem a bit odd that IM reports the profiles as being "sRGB" but I don't think that is the source of the problem...I suspect it is just an oddity of how -verbose works).
Case 2 (No resize, simple gamma conversion on the first clone)
This also WORKS:
Code: Select all
magick -quiet input.tif embedded.icc
magick -quiet -verbose input.tif ^
-profile Gray-elle-V2-g10.icc ^
( -clone 0 -gamma 3 -gamma 0.3333333333333333 +write tmp2 ) ^
( -clone 0 ) ^
-delete 0 ^
( -clone 1 -auto-level ) ^
-compose over -composite +write tmp3 ^
-profile embedded.icc ^
output.tif
Code: Select all
input.tif TIFF 600x761 600x761+0+0 16-bit Grayscale Gray 942748B 0.078u 0:00.078
Gray-elle-V2-g10.icc ICC 1x1 1x1+0+0 16-bit sRGB 512B 0.000u 0:00.000
input.tif=>tmp2 TIFF 600x761 600x761+0+0 16-bit Grayscale Gray 942616B 0.000u 0:00.007
input.tif=>tmp3 TIFF 600x761 600x761+0+0 16-bit Grayscale Gray 942704B 0.063u 0:00.010
embedded.icc ICC 1x1 1x1+0+0 16-bit sRGB 408B 0.000u 0:00.000
input.tif=>output.tif TIFF 600x761 600x761+0+0 16-bit Grayscale Gray 942600B 0.297u 0:00.097
As before, everything stays in "...Grayscale Gray..."
Case 3 (Resize included, AND simple gamma conversion on the first clone)
This FAILS!
Code: Select all
magick -quiet input.tif embedded.icc
magick -quiet -verbose input.tif ^
-profile Gray-elle-V2-g10.icc ^
-define filter:c=0.1601886205085204 -filter Cubic -distort Resize 500 +write tmp1 ^
( -clone 0 -gamma 3 -gamma 0.3333333333333333 +write tmp2 ) ^
( -clone 0 ) ^
-delete 0 ^
( -clone 1 -auto-level ) ^
-compose over -composite +write tmp3 ^
-profile embedded.icc ^
output.tif
Code: Select all
input.tif TIFF 600x761 600x761+0+0 16-bit Grayscale Gray 942748B 0.078u 0:00.078
Gray-elle-V2-g10.icc ICC 1x1 1x1+0+0 16-bit sRGB 512B 0.000u 0:00.000
Affine Projection:
-distort AffineProjection \
'0.833333,-0.000000,-0.000000,0.833114,0.000000,0.000000'
Affine Distort, FX Equivelent:
-size 502x636 -page -1-1 xc: +insert \
-fx 'ii=i+page.x+0.5; jj=j+page.y+0.5;
xx=+1.200000*ii +0.000000*jj +0.000000;
yy=+0.000000*ii +1.200315*jj +0.000000;
v.p{ xx-v.page.x-.5, yy-v.page.y-.5 }' \
input.tif=>tmp1 TIFF 600x761=>500x634 16-bit Grayscale Gray 663416B 0.031u 0:00.008
input.tif=>tmp2 TIFF 600x761=>500x634 16-bit Gray 1.84195MiB 0.000u 0:00.006
input.tif=>tmp3 TIFF 600x761=>500x634 16-bit sRGB 1931510B 0.063u 0:00.008
embedded.icc ICC 1x1 1x1+0+0 16-bit sRGB 408B 0.000u 0:00.000
magick: color profile operates on another colorspace `icc' @ error/profile.c/ProfileImage/1018.
In this case, something has happened on the first clone (with the gamma conversion) output (tmp2). Instead of "Grayscale Gray" being reported, we now see only "Gray". Furthermore, the composite output is now in sRGB!
I wrote a simple script to report selected "magick identify" information from each of the above tmp files and it produces the following:
Code: Select all
Image: tmp1
Colorspace: Gray
Type: Grayscale
Gamma: 0.454545
Profile: Gray-elle-V2-g10.icc
--------------------------
Image: tmp2
Colorspace: sRGB
Type: Grayscale
Gamma: 0.454545
Profile: Gray-elle-V2-g10.icc
--------------------------
Image: tmp3
Colorspace: sRGB
Type: Grayscale
Gamma: 0.454545
Profile: Gray-elle-V2-g10.icc
--------------------------
On tmp2 I see the Colorspace as "sRGB" and the Type as "Grayscale". Something is not right here and it appears this incongruity just carries forward and ultimately convinces the composite to create sRGB output which apparently causes the last "-profile" to barf and IM aborts.
@Alan and Fred: I also tested the above scenarios with "-evaluate pow .." as you suggested; NO CHANGE. Same results whether the clone is using -gamma or -evaluate pow.
For me, the data above demonstrates there is some weird interaction going on between the resize and the clone with a gamma (or eavluate pow) conversion, and this results in incorrect colorspace behavior downstream in the processing. Where do we go from here?
Thanks,
Dave