// Effortlessly reordering channels with no modification. assert(RGB(1, 2, 3).channelMap!BGR == BGR(3, 2, 1)); // Perform per-channel transformations. assert(RGB(1, 2, 3).channelMap!(v => cast(ubyte)(v + 1)) == RGB(2, 3, 4)); // Perform per-channel transformations with a different resulting type, implicitly. assert(RGB(1, 2, 3).channelMap!(v => cast(ushort)(v + 1)) == RGB16(2, 3, 4)); // Perform per-channel transformations with a different resulting type, explicitly. assert(RGB(1, 2, 3).channelMap!(RGB16, v => cast(ubyte)(v + 1)) == RGB16(2, 3, 4)); // Ditto, with a ref parameter instead of return. assert(RGB(1, 2, 3).channelMap!(RGB16, (a, ref b) { b = a; b++; }) == RGB16(2, 3, 4)); // Effortlessly convert an image import ae.utils.graphics.image : Image, colorMap, copy; Image!BGR i = Image!RGB().colorMap!(channelMap!BGR).copy();
Applies a transformation per-channel. expr may be in the form of a => ..., or (a, ref b) { b = ...; } (only if T is explicitly specified).