Comments (8)
There is already a bit in the flags field of the data format descriptor (DFD) in KTX2. There is nothing that can be done for KTX1 except using metadata.
Two values for the bit are defined in khr_df.h
: KHR_DF_FLAG_ALPHA_STRAIGHT (=0) and KHR_DF_FLAG_ALPHA_PREMULTIPLIED (=1). In libktx
the bit can be accessed in a ktxTexture2
object called ktex by
bool isPremultiplied = KHR_DFDVAL(ktex->dfd, FLAGS) & KHR_DF_FLAG_ALPHA_PREMULTIPLIED
In libktx, we need to make sure that this bit is preserved along with the transfer function and primaries when the DFD is rewritten during supercompression to Basis. We also need to provide a way to create pre-multiplied textures. currently toktx
accepts PNG and Netpbm formats. Neither appears to support premultiplied. So what to do? I will leave this issue open to track resolution of these 2 points.
from ktx-software.
I like that header spec a lot, it's very explicit. My only concern is that this flag not be restricted to DXT2/4 type formats. Basically any compressed or uncompressed endpoints with alpha should be valid to have premultiplied alpha applied, and that bit set if I'm understanding it correctly. The spec only stated usage on DXT2/4.
And yes, have libktx hand premultiplication of alpha would be a big help, since if work is done on the gpu, then this is a cheap multiply operation in addition to the required sRGB conversions that are best done on GPU.
from ktx-software.
My only concern is that this flag not be restricted to DXT2/4 type formats.
It can be set for any descriptor. It only makes sense for the RGBDSA and compressed texture color models and only when an alpha channel is present. See Table 90 in Chapter 11, Example format descriptors.
And yes, have libktx hand premultiplication of alpha would be a big help
I don't understand what you are trying to say here.
from ktx-software.
I don't understand what you are trying to say here.
I just meant that doing srgb -> linear, linear * a, then linear * a -> srgb could be done entirely on the gpu in libktx. Otherwise, it's simple done with a 3x 2d table lookups on ra, ga, ba. Just that that ordering should be honored for correctness and to avoid clamping. Bits will be lost on low alpha values being stored in 8-bit components regardless.
from ktx-software.
Ahh! So s/hand/handle/. Are you suggesting an option to toktx to premultiply the incoming images?
The parts of libktx involved in creating .ktx2 files do not use the GPU. They can run anywhere. As creation doesn't seem particularly time critical I'm loathe to add the complexity of checking for and using a GPU and dealing with the resulting dependencies. A premultiplication option can be implemented on the CPU of course.
The only parts that do use the GPU are the OpenGL and Vulkan loaders. By that point the data should already be premultiplied.
from ktx-software.
PIng! Are you asking for a pre-multiplication option to toktx? Should I add an isPremultiplied() function to ktxTexture2 or is accessing the DFD sufficient?
from ktx-software.
No, the "bool isPremultiplied = ..." example that you provided is probably sufficient.
I do think that premultiplication of the values should happen in the texture encoder, but it's complicated with the low-bit depth of BC1-BC3. With ASTC, the endpoints are 8-bit, but sometimes split into a base + delta. And finally, many of the existing compressors just take the srgb colors and then fit the endpoints to those. That doesn't seem right, since that's not a linear color space.
So ideally for srgb:
- convert colors from srgb to 10-bit or 8-bit linear. Conversion to 565 isn't enough bits.
- do rgb * alpha
- fit endpoints to the premultiplied linear rgb values
- remap the rgb endpoints back to srgb
The gpu does the reverse of step 4 before storing the colors in the texture cache. That way bi/tri-linear filtering are correct in linear space. On a simpler note, EAC/BC4/5 can also be stored at higher precision in the texture cache, since they're only 1-2 channels.
For rgb, it's easy since it's just step 2 and 3 only.
from ktx-software.
The only encoder within libktx is the BasisU encoder which is incorporated as a git subrepo. You should probably open an issue at https://github.com/BinomialLLC/basis_universal requesting this. I don't think there is anything to do in the rest of libktx so I'm going to close this. Note that there is now a ktxTexture2_GetPremultipliedAlpha function to find out if the bit is set or not.
from ktx-software.
Related Issues (20)
- Allow A8B8G8R8 PACK32 formats
- Loading KTX1 and KTX2 file on Linux/OpenGL 4.3 leads to weird error if not luch the program with sudo HOT 4
- Project install installs fmt lib HOT 1
- Preceding `ktx` command name with option leads to error HOT 1
- WebGL test gets shader compile error
- Converting transfer functions (using assign-oetf and convert-oetf) HOT 15
- samplePositions possibly incorrect for single-plane 4:2:2 YUV formats HOT 4
- The JNI binding for input swizzling is broken
- No option to apply `zstd`/`zlib` compression via JNI HOT 21
- Improvements for the Java/JNI bindings HOT 4
- Synchronizing auto-generated files with bindings HOT 2
- How to call `CreateFromMemory`? HOT 2
- Memoy leak when ktxTexture2_DeflateZstd fails
- Running in docker container (GLIBC not found error) HOT 2
- CI build scripts prevent local use with test updates by initializing CTS submodule
- Skipping mipmaps when loading from disk HOT 2
- The execution speed of the ktxTexture2_CompressBasisEx method is quite slow HOT 15
- No definition for ktxTexture2_Destroy in ktx.h HOT 3
- Enabling Automatic Mipmap Generation Causes Validation Error HOT 1
- ktxTexture_SetImageFromMemory should document pointer lifetime guarantees HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ktx-software.