mapeditor / tiled

Flexible level editor
https://www.mapeditor.org/
Other
11.09k stars 1.75k forks source link

Save as Image modifies alpha #549

Open turdparty opened 10 years ago

turdparty commented 10 years ago

I just noticed when you have a map with tiles using certain alpha values, and you go to File->Save as Image, then the image won't have the original colors from the tileset. I ran into this before in other editors, it's possible image loading already pre-multiplies the alpha values in colors. (Adobe's API does this too.)

In effect the tiles you see in the exported image will look like the tiles from your tileset, but they won't be equal. Here's an image to test, just make a map using this image as a tileset, paint some tiles, then do File->Save as Image and compare the color values from the exported file with this image in a graphics program like gimp or photoshop and you'll see the difference: test

bjorn commented 10 years ago

That's an interesting issue to be aware of, and indeed it is probably because internally Tiled uses QPixmap which for performance reasons likely uses pre-multiplied alpha.

Do you think this would ever be noticable? I mean, does it ever actually affect the color of the screen pixel? After all the color information that is lost due to pre-multiplying would go lost when rendering the original image anyway, right?

I just wonder if it makes sense at all to go through the trouble of making sure the 'Save as Image' function does not use pre-multiplied alpha. Though, this issue may go away anyway when we can close #505.

turdparty commented 10 years ago

I'm not sure. It kind of depends on what is done with the pixels. I just expected the output to be the same as the input, pre multplied or not. I depend on that for optimizations I do after my work in tiled so now I'm creating map images myself based on the tile indices. So you won't have to go through the trouble for my sake.

Pre multiplying has some weird side issues. There are a lot of people (and experts) arguing for and against. In my opinion things should be kept in original state until you are absolutely sure you don't want to edit anything anymore. You can also run into some rounding errors when converting to and from premultiplied to straight. http://dvd-hq.info/alpha_matting.php