Editing 32-bit Windows bitmaps with alpha channel

Posted by: Roger

Editing 32-bit Windows bitmaps with alpha channel - 28/01/2004 14:42

Any applications out there that can edit a BMP file that's got an alpha channel (and preserve the alpha channel)? Preferably free.

I'm trying to spruce up a toolbar for an application that I'm hacking on. It uses 32-bit toolbar buttons, so it'd be even better if the application had a good zoom/grid mode.
Posted by: peter

Re: Editing 32-bit Windows bitmaps with alpha chan - 29/01/2004 05:57

Any applications out there that can edit a BMP file that's got an alpha channel (and preserve the alpha channel)? Preferably free.
Gimp understands both BMPs and alpha channels, so although I can't find a definite reference to it understanding BMPs with alpha channels, it sounds worth a shot. Some psycho has ported it to Windows, but I bet the Linux one is more stable.

Peter
Posted by: Roger

Re: Editing 32-bit Windows bitmaps with alpha chan - 29/01/2004 06:56

understanding BMPs with alpha channels

Gimp 1.2.3 certainly doesn't: it loads the bitmap successfully, but only shows 3 channels (R, G and B).

Time to upgrade my Debian box to sarge, maybe?

Alternatively, I think I might cobble something together to separate the alpha channel out as a separate monochrome bitmap, and then recombine them after I've edited both (which I think I can do by telling PSP to load the separate bitmap as an alpha channel).

Posted by: peter

Re: Editing 32-bit Windows bitmaps with alpha chan - 29/01/2004 07:05

Gimp 1.2.3 certainly doesn't: it loads the bitmap successfully, but only shows 3 channels (R, G and B).

Time to upgrade my Debian box to sarge, maybe?
Might not help. I've just tried 1.2.5 and that doesn't grok it either . Shame.

Peter
Posted by: Roger

Re: Editing 32-bit Windows bitmaps with alpha chan - 30/01/2004 03:26

I think I might cobble something together to separate the alpha channel out as a separate monochrome bitmap

This works fine: I can load the RGB bitmap into Paintshop Pro, and then load the alpha channel separately (I wrote something that exports it as a 24bpp grayscale bitmap for simplicity).

I can then edit the bitmap, although I have to edit the RGB layer and the alpha layer separately (e.g. when moving tiles) which is a pain, but I can live with it.

Unfortunately, I can't find any way to get PSP to save the damn alpha layer as a monochrome .BMP file, which means that there's not much point in me writing the rest (24+A -> 32) of the utility.

Bugger.

Any more suggestions?

I can't even find a way to get the Gimp to load the second bitmap as an alpha channel.
Posted by: hybrid8

Re: Editing 32-bit Windows bitmaps with alpha chan - 31/01/2004 10:08

Photoshop. Not free.

However I don't see why PSP should not be able to handle the job. As long as it supports editing 24bit with transparency, then you should be able to manually get what you want. The transparency is defined with an 8bit alpha channel, whether or not it shows you that channel from its interface. And whether or not it saves compatible BMP files.

The two methods I see: 1 manual pixel pushing, making two images (as you have already touched upon) and 2, creating one image with transparency, saving it in a format that preserves that transparency, and then finding a converter on the net, or making your own to rework the headers nd byte order into your BMP format. Photoshop files, TIFF, TARGA and PNG should be suitable formats for the initial save.

Method #1 is what I use (with Photoshop) to make Icons with an alpha channel for Mac OS X. I don't have the time to describe the complete process, but basically I work on an image in layers, all of which have transparency, some of which have only 100% opaque pixels and some which have variable transparency. I always keep my source file layered - this is good in case you need to come back later and make edits you may not be able to make once flattening or merging some portions.

Using Photoshop it's very easy to select only the portions of the canvas containing pixels (control (or is it alt?) clicking the desired layer in the layer palette will do this). There should be something similar is PSP. Once you have that election (which itself knows about the transparency values of the pixels it contains), you can (with Photoshop) save the selection into a channel. This can be your mask or may need to be inverted to create your mask (the icon software I use treats black as "show" and white as "hide" with values in between being translucent of course). Now you'll also need to save the image that will be masked. I do this by creating a new black background behind it and then saving it flat. The black background is there because the mask will be used so that portions of the image taht are translucent will darken the background they're placed on, not lighten it. This way a shadow will be invisible when placed on a black background, instead of showing up as greys and white (this is what would happe if the file had been saved composited onto a white background). However, if your item is a highlight and not a shadow, you'd want the reverse to be true.

I add both the imge and the mask into the icon program which support locations for each. Either that or they're used in custom software and dealt with by the programmer and Mac OS's support for masks.

I hope the info helps, even if not specific to your intended usage. Again, the process may need to change depending on how your target will use its files.


Bruno
Posted by: Roger

Re: Editing 32-bit Windows bitmaps with alpha chan - 31/01/2004 11:10

However I don't see why PSP should not be able to handle the job.

It turns out that it's because PSP can't handle 32-bpp raster images. According to JASC support:

Paint Shop Pro does not support 32-bit images. Hence it will not support the format that you are trying to create.


More specifically, it'll do all the layering and stuff while editing the file, but when you go to save it to a BMP or PNG file, it flattens everything down to 24 bits, and strips out the alpha channel.

This means that I can't use it to save a 32-bpp PNG file (because it doesn't actually seem to write them) even if I spend the time to write a PNG to BMP convertor (which should be trivial, given libpng).

So, frankly, I think I'll opt for manual pixel pushing -- editing the 24bpp image and the alpha separately, and then writing a utility to merge them back together. This way I get to use the copy of PSP5 that I've had for years, and I don't need to spend any more money.
Posted by: wfaulk

Re: Editing 32-bit Windows bitmaps with alpha channel - 31/01/2004 12:22

Can you post a sample image?
Posted by: Roger

Re: Editing 32-bit Windows bitmaps with alpha channel - 31/01/2004 12:24

Sure, but there's nothing particularly clever about the image format.
Posted by: Roger

Re: Editing 32-bit Windows bitmaps with alpha channel - 31/01/2004 12:37

...and the (admittedly quite nasty) code that I cobbled together the other day to separate out the channels.

Posted by: wfaulk

Re: Editing 32-bit Windows bitmaps with alpha channel - 31/01/2004 12:42

Other than I didn't have a sample to test.

Is this what you're looking for? I don't have a good way easily available to test it.
Posted by: Roger

Re: Editing 32-bit Windows bitmaps with alpha channel - 31/01/2004 12:50

Is this what you're looking for?

Not really. I can (assuming I do a little hacking with libpng) already turn a ABGR bitmap file into an RGBA PNG file and vice versa. What I'm having trouble with is finding something that will let me edit them interactively.

Or am I missing something and you're showing me something else?
Posted by: wfaulk

Re: Editing 32-bit Windows bitmaps with alpha channel - 31/01/2004 12:56

You just want something that will natively edit ABGR bmps rather than having to do conversions manually at either end?

Well, my tool should be able to do that, too. GraphicConverter. Of course, you'll have to invest in a Mac, and transferring the files between the two computers would probably be at least as intensive as doing the conversion back and forth.
Posted by: Roger

Re: Editing 32-bit Windows bitmaps with alpha channel - 31/01/2004 13:51

You just want something that will natively edit ABGR bmps rather than having to do conversions manually at either end?

Yes, because it's not only doing the manual conversions.

If I'm just doing rudimentary editing, for example swapping buttons around, or stealing some buttons from another app until I can pay for or some original artwork, then it's a PITA to have to do it all on pairs of bitmaps.

Obviously, if it's more intensive editing, then I'd be doing it on multiple layers, which is almost the same amount of work as multiple bitmaps.
Posted by: peter

Re: Editing 32-bit Windows bitmaps with alpha chan - 31/01/2004 14:44

Not really. I can (assuming I do a little hacking with libpng) already turn a ABGR bitmap file into an RGBA PNG file and vice versa. What I'm having trouble with is finding something that will let me edit them interactively.
But once it's an RGBA PNG then the Gimp will edit it fine. Unless I'm missing something.

Peter
Posted by: Roger

Re: Editing 32-bit Windows bitmaps with alpha chan - 31/01/2004 15:39

But once it's an RGBA PNG then the Gimp will edit it fine. Unless I'm missing something.

Good spot. Indeed it will. Time to cobble together a BMP <-> PNG convertor that deals with 32-bpp, unless I can find one on the 'net.
Posted by: peter

Re: Editing 32-bit Windows bitmaps with alpha chan - 31/01/2004 15:50

Good spot. Indeed it will. Time to cobble together a BMP <-> PNG convertor that deals with 32-bpp, unless I can find one on the 'net.
Imagemagick's convert(1)? I'd guess that's what Bitt used.

Peter
Posted by: Roger

Re: Editing 32-bit Windows bitmaps with alpha chan - 31/01/2004 16:13

Imagemagick's convert(1)?

What incantation do you need to use? I can't get it to keep the alpha channel in the BMP->PNG conversion. I've not tried the other direction yet.
Posted by: peter

Re: Editing 32-bit Windows bitmaps with alpha chan - 31/01/2004 16:32

What incantation do you need to use? I can't get it to keep the alpha channel in the BMP->PNG conversion. I've not tried the other direction yet.
I just used "convert thing.bmp thing.png". What version of Imagemagick have you got? Mine is 5.5.8, though there seems to be a 6.0.0 now.

Peter
Posted by: Roger

Re: Editing 32-bit Windows bitmaps with alpha chan - 31/01/2004 16:58

What version of Imagemagick have you got?

5.4.4. I'll build a 6.0.0 tomorrow and see if I have any luck...
Posted by: wfaulk

Re: Editing 32-bit Windows bitmaps with alpha chan - 01/02/2004 02:40

Nah. Like I said, GraphicConverter. FWIW, it seems netpbm doesn't understand 32-bit BMPs, either.
Posted by: Roger

Re: Editing 32-bit Windows bitmaps with alpha chan - 01/02/2004 03:59

though there seems to be a 6.0.0 now.

Which doesn't appear to work properly -- it creates an empty alpha channel in the PNG (and to get that I had to "convert thing.bmp png32:thing.png"). I'll grab a copy of 5.5.8, and see if I can get that to work.
Posted by: Roger

Re: Editing 32-bit Windows bitmaps with alpha chan - 01/02/2004 04:12

I'll grab a copy of 5.5.8, and see if I can get that to work

Nope. 5.5.7 -- the latest stable one listed on http://www.imagemagick.org/ -- still strips the alpha channel out, if I run it the way you did.

Posted by: ricin

Re: Editing 32-bit Windows bitmaps with alpha chan - 01/02/2004 14:47

Uhm. Doesn't convert -transparent black toolbar32.bmp toolbar32.png work?
Posted by: ricin

Re: Editing 32-bit Windows bitmaps with alpha chan - 01/02/2004 14:49



No?
Posted by: Roger

Re: Editing 32-bit Windows bitmaps with alpha chan - 01/02/2004 15:27

convert -transparent black

No, because it strips out the alpha channel (which is an 8-bit quantity) and replaces it with a 1-bit mask. Unless the man page is not telling me something.
Posted by: wfaulk

Re: Editing 32-bit Windows bitmaps with alpha chan - 01/02/2004 17:45

Well, there would be no guarantee that the transparent part would be black, or even any single color, not to mention ignoring the levels of transparency. For example, look a magnified version of the image you posted back:



Look at all those nearly-black artifacts, especially on the X and the disk.