* @memberof ktxTexture2 * @~English * @brief Find the offset of an image within a ktxTexture's image data. * * As there is no such thing as a 3D cubemap we make the 3rd location parameter * do double duty. Only works for non-supercompressed textures as * there is no way to tell where an image is for a supercompressed one. * * @param[in] This pointer to the ktxTexture object of int
| 1889 | * @exception KTX_INVALID_VALID @p This is NULL. |
| 1890 | */ |
| 1891 | KTX_error_code |
| 1892 | ktxTexture2_GetImageOffset(ktxTexture2* This, ktx_uint32_t level, |
| 1893 | ktx_uint32_t layer, ktx_uint32_t faceSlice, |
| 1894 | ktx_size_t* pOffset) |
| 1895 | { |
| 1896 | if (This == NULL) |
| 1897 | return KTX_INVALID_VALUE; |
| 1898 | |
| 1899 | if (level >= This->numLevels || layer >= This->numLayers) |
| 1900 | return KTX_INVALID_OPERATION; |
| 1901 | |
| 1902 | if (This->supercompressionScheme != KTX_SS_NONE) |
| 1903 | return KTX_INVALID_OPERATION; |
| 1904 | |
| 1905 | if (This->isCubemap) { |
| 1906 | if (faceSlice >= This->numFaces) |
| 1907 | return KTX_INVALID_OPERATION; |
| 1908 | } else { |
| 1909 | ktx_uint32_t maxSlice = MAX(1, This->baseDepth >> level); |
| 1910 | if (faceSlice >= maxSlice) |
| 1911 | return KTX_INVALID_OPERATION; |
| 1912 | } |
| 1913 | |
| 1914 | // Get the offset of the start of the level. |
| 1915 | *pOffset = ktxTexture2_levelDataOffset(This, level); |
| 1916 | |
| 1917 | // All layers, faces & slices within a level are the same size. |
| 1918 | if (layer != 0) { |
| 1919 | ktx_size_t layerSize; |
| 1920 | layerSize = ktxTexture_layerSize(ktxTexture(This), level, |
| 1921 | KTX_FORMAT_VERSION_TWO); |
| 1922 | *pOffset += layer * layerSize; |
| 1923 | } |
| 1924 | if (faceSlice != 0) { |
| 1925 | ktx_size_t imageSize; |
| 1926 | imageSize = ktxTexture2_GetImageSize(This, level); |
| 1927 | *pOffset += faceSlice * imageSize; |
| 1928 | } |
| 1929 | return KTX_SUCCESS; |
| 1930 | } |
| 1931 | |
| 1932 | /** |
| 1933 | * @memberof ktxTexture2 |