* @memberof ktxTexture2 * @ingroup reader * @~English * @brief Transcode a KTX2 texture with BasisLZ/ETC1S or UASTC images. * * If the texture contains BasisLZ supercompressed images, Inflates them from * back to ETC1S then transcodes them to the specified block-compressed * format. If the texture contains UASTC images, inflates them, if they have been * supercompressed with zstd, then tra
| 131 | * @exception KTX_OUT_OF_MEMORY Not enough memory to carry out transcoding. |
| 132 | */ |
| 133 | KTX_error_code |
| 134 | ktxTexture2_TranscodeBasis(ktxTexture2* This, |
| 135 | ktx_transcode_fmt_e outputFormat, |
| 136 | ktx_transcode_flags transcodeFlags) |
| 137 | { |
| 138 | uint32_t* BDB = This->pDfd + 1; |
| 139 | khr_df_model_e colorModel = (khr_df_model_e)KHR_DFDVAL(BDB, MODEL); |
| 140 | if (colorModel != KHR_DF_MODEL_UASTC |
| 141 | // Constructor has checked color model matches BASIS_LZ. |
| 142 | && This->supercompressionScheme != KTX_SS_BASIS_LZ) |
| 143 | { |
| 144 | return KTX_INVALID_OPERATION; // Not in a transcodable format. |
| 145 | } |
| 146 | |
| 147 | DECLARE_PRIVATE(priv, This); |
| 148 | if (This->supercompressionScheme == KTX_SS_BASIS_LZ) { |
| 149 | if (!priv._supercompressionGlobalData || priv._sgdByteLength == 0) |
| 150 | return KTX_INVALID_OPERATION; |
| 151 | } |
| 152 | |
| 153 | if (transcodeFlags & KTX_TF_PVRTC_DECODE_TO_NEXT_POW2) { |
| 154 | debug_printf("ktxTexture_TranscodeBasis: KTX_TF_PVRTC_DECODE_TO_NEXT_POW2 currently unsupported\n"); |
| 155 | return KTX_UNSUPPORTED_FEATURE; |
| 156 | } |
| 157 | |
| 158 | if (outputFormat == KTX_TTF_PVRTC1_4_RGB |
| 159 | || outputFormat == KTX_TTF_PVRTC1_4_RGBA) { |
| 160 | if ((!isPow2(This->baseWidth)) || (!isPow2(This->baseHeight))) { |
| 161 | debug_printf("ktxTexture_TranscodeBasis: PVRTC1 only supports power of 2 dimensions\n"); |
| 162 | return KTX_INVALID_OPERATION; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | const bool srgb = (KHR_DFDVAL(BDB, TRANSFER) == KHR_DF_TRANSFER_SRGB); |
| 167 | alpha_content_e alphaContent = eNone; |
| 168 | if (colorModel == KHR_DF_MODEL_ETC1S) { |
| 169 | if (KHR_DFDSAMPLECOUNT(BDB) == 2) { |
| 170 | uint32_t channelId = KHR_DFDSVAL(BDB, 1, CHANNELID); |
| 171 | if (channelId == KHR_DF_CHANNEL_ETC1S_AAA) { |
| 172 | alphaContent = eAlpha; |
| 173 | } else if (channelId == KHR_DF_CHANNEL_ETC1S_GGG){ |
| 174 | alphaContent = eGreen; |
| 175 | } else { |
| 176 | return KTX_FILE_DATA_ERROR; |
| 177 | } |
| 178 | } |
| 179 | } else { |
| 180 | uint32_t channelId = KHR_DFDSVAL(BDB, 0, CHANNELID); |
| 181 | if (channelId == KHR_DF_CHANNEL_UASTC_RGBA) |
| 182 | alphaContent = eAlpha; |
| 183 | else if (channelId == KHR_DF_CHANNEL_UASTC_RRRG) |
| 184 | alphaContent = eGreen; |
| 185 | } |
| 186 | |
| 187 | VkFormat vkFormat; |
| 188 | |
| 189 | // Do some format mapping. |
| 190 | switch (outputFormat) { |