Page 1 of 1

Swizzling Data

Posted: 2018-05-09T08:48:02-07:00
by alecazam
Swizzling channels seems to be unreasonable difficult to do with the commands available.

Here's what I've tried so far:

convert -channel BA -fill '#000000FF' <- doesn't seem to do anything or produce a warning, I still see blue in the final image
convert -channel-fx 'red, red, red, white' <- despite docs, white, 0, 1, 255, 0xFF isn't accepted

This is the only thing that kind of works, but I'm still at a loss for why I can't just fill a channel to 0 or 1 with channel-fx

convert -channel-fx 'red=>green red=>blue' <- tried to add white=>alpha here

The convert command line really needs a simple swizzle command (command 238) using r,g,b,a,i,0,1,#FF or #FFFF for a number.

convert -swizzle rgb1
convert -swizzle rg01
convert -swizzle rrrr1
convert -swizzle gggr

Re: Swizzling Data

Posted: 2018-05-09T09:03:50-07:00
by snibgo
What is "swizzling"?

Re: Swizzling Data

Posted: 2018-05-11T17:07:08-07:00
by alecazam
This works and avoids the channel mask and fill. Be careful not to use commas or that will assign to the respective channels.

convert -channel-fx 'red=>green red=>blue alpha=100%' # rrr1

Re: Swizzling Data

Posted: 2018-05-13T20:29:49-07:00
by fmw42
In IM 6, you can do your rrr1 by:

Code: Select all

convert image.png -channel r -separate +channel -duplicate 2 -set colorspace sRGB -combine PNG32:image_rrr1.png
By default, alpha is fully opaque (alpha=1).

If you want rrr0, you can do

Code: Select all

convert image.png -channel r -separate +channel -duplicate 2 -set colorspace sRGB -combine -alpha transparent PNG32:image_rrr0.png

You can do rg01 by:

Code: Select all

convert image.png -channel b -evaluate set 0 +channel PNG32:image_rg01.png
IM 6 does not have -channel-fx. That is only in IM 7. See