How to set image memory to preallocated space without copying? #1059
-
|
Hello, I have raw image data on a preallocated memory space and I want to set this memory as ktx texture data to avoid extra copies. I scanned the examples and topics on libktx reference and couldn't find what I was looking for. I don't think something like So far, I can use The same thing is also needed when I query the meta data using Is simply setting the Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
|
A simple example of what I want to do is as following: // Following function allocates the memory and returns the data
stbi_uc *data = stbi_load(filename, &width, &height, &channels, STBI_rgb_alpha);
ktxTexture2 *texture;
ktxTextureCreateInfo textureCreateInfo = {...};
ktxTexture2_Create(&textureCreateInfo, KTX_TEXTURE_CREATE_NO_STORAGE, &texture);
// This needs allocation and uses copy, I don't want this
// ktxTexture_SetImageFromMemory(texture, ..., data, ...);
ktxTexture2_SetImageMemory((ktx_uint8_t *) data); // <-------- I NEED THIS
// Or simply: texture->pData = (ktx_uint8_t *) data; Is this safe???
// Now I should be able to use following functions in-place
ktxTexture2_CompressBasisEx(texture, ...);
ktxTexture2_TranscodeBasis(texture, ...);Is this safe? Because I don't think a function exists to do that safely. |
Beta Was this translation helpful? Give feedback.
Yes, it is safe provided the memory chunk with the data can be freed by a call to
free.ktxTexture2_destructwill free a non-zero texture->pData.But ...
... you must correctly initialize the DFD (texture->pDfd) for the data you have loaded. That includes the color space information. The correct transferFunction is vital for correct compression and eventually correct transcode results. Also the trans…