MCPcopy Create free account
hub / github.com/KhronosGroup/KTX-Software / astcSwizzle

Function astcSwizzle

lib/astc_codec.cpp:774–804  ·  view source on GitHub ↗

* @memberof ktxTexture * @internal * @ingroup writer * @~English * @brief Creates valid ASTC encoder swizzle from string. * * @return Valid astcenc_swizzle from string */

Source from the content-addressed store, hash-verified

772 * @return Valid astcenc_swizzle from string
773 */
774static astcenc_swizzle
775astcSwizzle(const ktxAstcParams &params) {
776
777 astcenc_swizzle swizzle{ASTCENC_SWZ_R, ASTCENC_SWZ_G, ASTCENC_SWZ_B, ASTCENC_SWZ_A};
778
779 std::vector<astcenc_swz*> swizzle_array{&swizzle.r, &swizzle.g, &swizzle.b, &swizzle.a};
780 // For historical reasons params.inputSwizzle[0] == '\0' is interpreted to mean no
781 // swizzle. The docs says it must match the regular expression /^[rgba01]{4}$/.
782 if (params.inputSwizzle[0] != '\0') {
783 std::string inputSwizzle(params.inputSwizzle, sizeof(params.inputSwizzle));
784 // TODO: Check for RE match.
785 for (int i = 0; i < 4; i++) {
786 if (inputSwizzle[i] == 'r')
787 *swizzle_array[i] = ASTCENC_SWZ_R;
788 else if (inputSwizzle[i] == 'g')
789 *swizzle_array[i] = ASTCENC_SWZ_G;
790 else if (inputSwizzle[i] == 'b')
791 *swizzle_array[i] = ASTCENC_SWZ_B;
792 else if (inputSwizzle[i] == 'a')
793 *swizzle_array[i] = ASTCENC_SWZ_A;
794 else if (inputSwizzle[i] == '0')
795 *swizzle_array[i] = ASTCENC_SWZ_0;
796 else if (inputSwizzle[i] == '1')
797 *swizzle_array[i] = ASTCENC_SWZ_1;
798 }
799 } else if (params.normalMap) {
800 return {ASTCENC_SWZ_R, ASTCENC_SWZ_R, ASTCENC_SWZ_R, ASTCENC_SWZ_G};
801 }
802
803 return swizzle;
804}
805
806static void
807astcBlockDimensions(ktx_uint32_t block_size,

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected