327 return green(format);
561 return alpha(format);
753 return red(format) == -1;
780 const auto a =
alpha(format);
905[[nodiscard]]
constexpr uint16_t
getMipDim(uint8_t mip, uint16_t dim,
bool addCompressedFormatPadding =
false) {
909 for (
int i = 0; i < mip && dim > 1; i++) {
912 if (addCompressedFormatPadding) {
926[[nodiscard]]
constexpr std::pair<uint16_t, uint16_t>
getMipDims(uint8_t mip, uint16_t width, uint16_t height,
bool addCompressedFormatPadding =
false) {
927 const auto originalWidth = width, originalHeight = height;
928 for (
int i = 0; i < mip && (width > 1 || height > 1); i++) {
929 if ((width >>= 1) < 1) width = 1;
930 if ((height >>= 1) < 1) height = 1;
932 if (addCompressedFormatPadding) {
936 return {!originalWidth ? 0 : width, !originalHeight ? 0 : height};
948[[nodiscard]]
constexpr std::tuple<uint16_t, uint16_t, uint16_t>
getMipDims(uint8_t mip, uint16_t width, uint16_t height, uint16_t depth,
bool addCompressedFormatPadding =
false) {
949 const auto originalWidth = width, originalHeight = height, originalDepth = depth;
950 for (
int i = 0; i < mip && (width > 1 || height > 1 || depth > 1); i++) {
951 if ((width >>= 1) < 1) width = 1;
952 if ((height >>= 1) < 1) height = 1;
953 if ((depth >>= 1) < 1) depth = 1;
955 if (addCompressedFormatPadding) {
959 return {!originalWidth ? 0 : width, !originalHeight ? 0 : height, !originalDepth ? 0 : depth};
971[[nodiscard]]
constexpr uint8_t
getMaximumMipCount(uint16_t width, uint16_t height, uint16_t depth = 1) {
972 uint8_t numMipLevels = 1;
973 if (width && height && depth) {
974 while (width > 1 || height > 1 || depth > 1) {
975 if ((width >>= 1) < 1) width = 1;
976 if ((height >>= 1) < 1) height = 1;
977 if ((depth >>= 1) < 1) depth = 1;
986namespace ImageFormatDetails {
998 return ((width + 3) / 4) * ((height + 3) / 4) * depth *
bpp(format) * 2;
1000 return width * height * depth * (
bpp(format) / 8);
1015[[nodiscard]]
constexpr uint32_t
getDataLength(
ImageFormat format, uint8_t mipCount, uint16_t frameCount, uint8_t faceCount, uint16_t width, uint16_t height, uint16_t depth = 1) {
1016 uint32_t length = 0;
1017 for (
int i = mipCount - 1; i >= 0; i--) {
1040[[nodiscard]]
constexpr uint32_t
getDataLengthXBOX(
bool padded,
ImageFormat format, uint8_t mipCount, uint16_t frameCount, uint8_t faceCount, uint16_t width, uint16_t height, uint16_t depth = 1) {
1041 uint32_t length = 0;
1042 for (
int j = 0; j < frameCount; j++) {
1043 for (
int i = 0; i < mipCount; i++) {
1047 if (padded && j + 1 != frameCount && length > 512) {
1071[[nodiscard]]
constexpr bool getDataPosition(uint32_t& offset, uint32_t& length,
ImageFormat format, uint8_t mip, uint8_t mipCount, uint16_t frame, uint16_t frameCount, uint8_t face, uint8_t faceCount, uint16_t width, uint16_t height, uint16_t slice = 0, uint16_t depth = 1) {
1074 for (
int i = mipCount - 1; i >= 0; i--) {
1076 for (
int j = 0; j < frameCount; j++) {
1077 for (
int k = 0; k < faceCount; k++) {
1078 for (
int l = 0; l < mipDepth; l++) {
1080 if (i == mip && j == frame && k == face && l == slice) {
1084 offset += imageSize;
1113[[nodiscard]]
constexpr bool getDataPositionXBOX(uint32_t& offset, uint32_t& length,
bool padded,
ImageFormat format, uint8_t mip, uint8_t mipCount, uint16_t frame, uint16_t frameCount, uint8_t face, uint8_t faceCount, uint16_t width, uint16_t height, uint16_t slice = 0, uint16_t depth = 1) {
1116 for (
int j = 0; j < frameCount; j++) {
1117 for (
int k = 0; k < faceCount; k++) {
1118 for (
int i = 0; i < mipCount; i++) {
1120 for (
int l = 0; l < mipDepth; l++) {
1122 if (i == mip && j == frame && k == face && l == slice) {
1126 offset += imageSize;
1130 if (padded && j + 1 != frameCount && offset > 512) {
constexpr uint16_t paddingForAlignment(uint16_t alignment, uint64_t n)
constexpr uint8_t getMaximumMipCount(uint16_t width, uint16_t height, uint16_t depth=1)
Calculate the largest mip count a texture with the given width, height, and depth can contain.
constexpr std::pair< uint16_t, uint16_t > getMipDims(uint8_t mip, uint16_t width, uint16_t height, bool addCompressedFormatPadding=false)
Get the width and height at a given mip level.
constexpr uint16_t getMipDim(uint8_t mip, uint16_t dim, bool addCompressedFormatPadding=false)
Get the dimension at a given mip level.
@ SOURCEPP_CONSOLE_RGBA16161616_HDR
@ CONSOLE_ARGB8888_LINEAR
@ CONSOLE_BGRX8888_LINEAR
@ CONSOLE_RGBA8888_LINEAR
@ CONSOLE_ABGR8888_LINEAR
@ SOURCEPP_RGBA16161616_HDR
@ CONSOLE_BGRX5551_LINEAR
@ CONSOLE_BGRA8888_LINEAR
@ CONSOLE_RGBA16161616_LINEAR