Swizzling Data

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
alecazam
Posts: 2
Joined: 2018-05-09T08:35:56-07:00
Authentication code: 1152

Swizzling Data

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Swizzling Data

Post by snibgo »

What is "swizzling"?
snibgo's IM pages: im.snibgo.com
alecazam
Posts: 2
Joined: 2018-05-09T08:35:56-07:00
Authentication code: 1152

Re: Swizzling Data

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Swizzling Data

Post 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 http://imagemagick.org/script/porting.php#cli
Post Reply