From KTX official repo + my patches