DDS Textures

Member
Posts: 320
Joined: 2003.06
Post: #16
Skorche Wrote:Outdated? There are still good reasons to load (or save) textures with premultiplied alpha. It's the only good way that I know of to avoid fringes when scaling textures.

Yes, when scaling up images premultiplied alpha removes the artifacts of interpolation between opaque and transparent pixels. However that does not necessitate premultiplication when saving out the image. It can be done at load, a flag passed to quartz perhaps, and it's really just a hack anyway.

The better solution is having the correct colors in the transparent pixels to begin with. Extruding the opaque color values out through the transparent is an easy way of achieving this.

The majority of problems I've had with fringes have been when myself or a user has unknowingly had a pre-multiplied image and the software or API used has not been treating it as such. Hence the reason I claim it does more harm than good.

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #17
I never save as premultiplied, I multiply on load when I want it. I don't actually even know how to save an image as premultiplied with any of the tools that I have.

You mention smearing the edge pixels, but how in general is this possible? Photoshop can't do it as it RLEs the completely transparent areas. Also, this requires a special extra step when saving the image.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #18
I'll file a grievance to Apple about premultiplication in Quartz. I would like if everybody else here did as well. The significant bit here, as I see it, is that Quartz claims support for non-premultiplied graphics ( there's a parameter you can pass "kCGImageAlphaLast" I think ) which according to the docs gives you non-premultiplied data. But on 10.3 and 10.4 at least this prevented you from getting a context.

Anyway, there's nothing wrong with premultiplied data. I use it in particle systems for "burn" blending which is awesome.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #19
There's nothing wrong with premultiplication in a compositing model, which is what Quartz enforces when you create a bitmap context to draw into. For reference, see this table.

But image data can be premultiplied, or not, depending what you're doing with it. If you're not compositing, and just loading an arbitrary 4-channel chunk of data (for example, a normal map + specular map) then you really don't want your data to be destroyed by the premultiplication. Quartz supports non-pre-multiplied images, there's just no way to access the data without compositing.
Quote this message in a reply
Member
Posts: 320
Joined: 2003.06
Post: #20
Just wanted to say that I've enjoyed this discussion, it's turned my general anger at pre-multiplication into a more well formed opinion. It's a problem that doesn't have an easy solution.

Skorche, photoshop does on occasion extrude color out through transparent areas, I haven't managed to figure out under exactly what circumstances though. I was really saying that the maths involved is easy. Perhaps a tool is needed.

A few interesting things to do with this thread and my rants...

- pngcrush will remove gamma information and other rubbish from png files. You can get it from http://pngcrush.darwinports.com/ using MacPorts, and get rid of all the crap by running "pngcrush -rem cHRM -rem gAMA -rem iCCP -rem sRGB [inputFile] [outputFile]"

- GraphicConvertor allows you to see what color values you have in transparent pixels. From memory you just discard the alpha channel.

- rmagick (ruby bindings for ImageMagick), once you manage to install it is great for doing exactly what you want with images using ruby. The composite function will happily add an alpha channel to an image without premultiplying it.

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #21
reubert Wrote:- pngcrush will remove gamma information and other rubbish from png files. You can get it from...
The PNGpong widget (which wraps pngcrush) does a good job of this for anyone not interested in compiling the tool from scratch or messing with command lines.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #22
If you want to export from PS but don't want to lose color values where alpha=0, you can use the levels palette to bump your minimum alpha from 0 -> 1. Admittedly, this isn't ideal since maybe you really do want alpha=0 at some points. But in my experience this works well enough.

There's also a plugin for PS, "SuperPNG", which produces very high quality PNG output without killing color data, etc.
Quote this message in a reply
Moderator
Posts: 522
Joined: 2002.04
Post: #23
reubert Wrote:Skorche, photoshop does on occasion extrude color out through transparent areas, I haven't managed to figure out under exactly what circumstances though. I was really saying that the maths involved is easy. Perhaps a tool is needed.
We use the Solidify filter available for free here: http://www.flamingpear.com/download.html (Free plugins pack)

With it you can easily make an action to solidify your image and create an alpha channel. It works perfectly for all mipmap levels. When I get around to it I'm going to try and make a script in Unity that automatically does this on texture import. (aka whenever you hit Save in Photoshop Smile ) I don't at the moment know what their algorithm is, but I have some ideas to try.

-Jon
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #24
I know it's been a month, but for a quick update, as of this morning I have a functional DDS Quicklook plugin. It didn't take a month to write! I had other things to do...

In fact, it took only about 3 hours from start to finish. Most of that was trying to figure out why my generator was being ignored by Launch Services. I'm not 100% certain, but it seemed to have to do with UTIs. Declaring the DDS UTI in a standalone quicklook generator Info.plist didn't work -- I had to write a viewer app which declared the dds UTI and relevant inheritance metadata. Then, LS recognized the bundled quicklook plugin as a handler for the public.dds UTI.

I want to polish it a little -- the viewer app is a little sparse. But when it's ready I'll post it ( with source of course ) here.

For what it's worth, it's times like this that I remember how much I like Cocoa. I just subclassed NSCustomBitmapImageRep, filled in some boilerplate. Once that's done, NSImage ( in the same process only ) transparently supports DDS files. Awesome.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #25
So, if anybody cares, here you go:
http://shamyl.zakariya.net/apps/DDSViewer.zip

Technically, it's a viewer app. But it defines the dds UTI and bundles a quicklook plugin. As far as I can tell, it works great. Plus, full source is included if you're interested in quicklook or stuff like subclassing NSCustomBitmapImageRep.
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #26
Cool, thanks.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #27
If it's not painfully obvious, the app requires 10.5. The app itself doesn't do anything that needs 10.5 (outside of quicklook) but I thought I'd scope out IB's new support for toolbars.
Quote this message in a reply
Post Reply