[solved] Help with DDS mipmaps and alphas

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
LDAsh
Posts: 35
Joined: 2015-04-27T23:10:58-07:00
Authentication code: 6789

[solved] Help with DDS mipmaps and alphas

Post by LDAsh »

I've been writing BAT files to perform operations and convert DDS files, mainly concerning a sequence of adjustments to each mipmap stage, and with great success so far. I can feed it a TGA and do things like hue-shifts and brighten/darken while resizing down by 50% each time, then combine all those files back into a DDS. The idea is to do things like make some decals more transparent at angles/distance and do things like give grass and carpet a kind of velvet appearance, and some other neat effects with ice and lava, etc.

The next step is to work with alpha channels, but I'm having a lot of trouble figuring it out. I've been grazing through the documentation and experimenting, and ended up trying to extract the alpha channel using convert color.tga -channel alpha -separate alpha.tga and then make adjustments separately, which works thus far, but can't seem to figure out how to successfully combine them back again, using -combine in various ways, I always get strange results like the image being completely white.

I've also tried to not separate, and try experimenting with -alpha type in various lines, but none of those options seem to allow me to do things with only the alpha and not affect RGB channels. I'm not entirely clear if that's the implied usage. I read that many operations won't work anyway and I'm led to believe that this isn't the right approach, and so I should be looking at an approach involving separating>operating>combining.

Finally, I realised that doing these operations on images that use alphas, despite not wanting to actually adjust the alpha, still has an effect by default, it seems. What I means is, if I want to darken an image with an alpha, then it darkens only positively or negatively, while what I need is to completely ignore the alpha without losing it. I've tried -alpha deactivate and -alpha disassociate but to no avail. I guess I may have to separate and combine the alpha, even if I don't wish to do any operations on it. I don't mind that approach.

So I guess my basic question is - what should I be looking at to 1) ONLY operate on an alpha and 2) ONLY operate on RGB channels, ignoring the alpha but without losing it?

Thanks for your time!
Last edited by LDAsh on 2016-10-03T06:21:36-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Help with DDS mipmaps and alphas

Post by snibgo »

(1) "-channel A {blah} +channel" will do operations {blah} only on the alpha channel. You may need "-alpha set" first, to ensure you have an alpha.

(2) "-channel RGB {blah} +channel" will do operations {blah} only on the RGB channels, not alpha. For some purposes, you should use "-channel RGB,sync".
snibgo's IM pages: im.snibgo.com
LDAsh
Posts: 35
Joined: 2015-04-27T23:10:58-07:00
Authentication code: 6789

Re: Help with DDS mipmaps and alphas

Post by LDAsh »

Thanks for your reply. I have since decided, despite some extra effort and mess, it's probably better (more powerful) to just separate all 4 of the channels, operate on them independently, and then combine them all back together again. I couldn't seem to RGB+A using "-combine" (that's where I was going wrong) but I can R+G+B+A without any issues. I followed your advice but I can only assume there is something wrong with the syntax of my command, so here it is:-

Code: Select all

mogrify color.tga -channel RGB -filter Blackman -resize 50%% -sharpen 0x1.4 +channel -channel alpha -set option:modulate:colorspace hsb -modulate 74,100,100 +channel color.tga
The desire is to darken the alpha but only resize, filter and sharpen the color, not darken it. The result is that only the RGB channels are being darkened and nothing is happening with the alpha. Just out of curiosity, though.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Help with DDS mipmaps and alphas

Post by snibgo »

"-modulate" isn't sensitive to a "-channel" setting. It changes the brightness, saturation and hue of an image, so it uses the colour channels, and only the colour channels. If you want to lower the value of alpha, you can use "-channel alpha +level A,B +channel".

"-resize" will always resize all the channels.

"-sharpen" is the only operation in your command that is sensitive to "-channel".
snibgo's IM pages: im.snibgo.com
LDAsh
Posts: 35
Joined: 2015-04-27T23:10:58-07:00
Authentication code: 6789

Re: [solved] Help with DDS mipmaps and alphas

Post by LDAsh »

Okay, I really appreciate the clarification. It seems the best way is indeed to separate all 4 channels and just do any operations, instead of being confined within the limitations of using "channel".
Post Reply