312 return green(format);
534 return alpha(format);
720 return red(format) == -1;
747 const auto a =
alpha(format);
870[[nodiscard]]
constexpr uint16_t
getMipDim(uint8_t mip, uint16_t dim,
bool addCompressedFormatPadding =
false) {
874 for (
int i = 0; i < mip && dim > 1; i++) {
877 if (addCompressedFormatPadding) {
891[[nodiscard]]
constexpr std::pair<uint16_t, uint16_t>
getMipDims(uint8_t mip, uint16_t width, uint16_t height,
bool addCompressedFormatPadding =
false) {
892 const auto originalWidth = width, originalHeight = height;
893 for (
int i = 0; i < mip && (width > 1 || height > 1); i++) {
894 if ((width >>= 1) < 1) width = 1;
895 if ((height >>= 1) < 1) height = 1;
897 if (addCompressedFormatPadding) {
901 return {!originalWidth ? 0 : width, !originalHeight ? 0 : height};
913[[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) {
914 const auto originalWidth = width, originalHeight = height, originalDepth = depth;
915 for (
int i = 0; i < mip && (width > 1 || height > 1 || depth > 1); i++) {
916 if ((width >>= 1) < 1) width = 1;
917 if ((height >>= 1) < 1) height = 1;
918 if ((depth >>= 1) < 1) depth = 1;
920 if (addCompressedFormatPadding) {
924 return {!originalWidth ? 0 : width, !originalHeight ? 0 : height, !originalDepth ? 0 : depth};
936[[nodiscard]]
constexpr uint8_t
getMaximumMipCount(uint16_t width, uint16_t height, uint16_t depth = 1) {
937 uint8_t numMipLevels = 1;
938 if (width && height && depth) {
939 while (width > 1 || height > 1 || depth > 1) {
940 if ((width >>= 1) < 1) width = 1;
941 if ((height >>= 1) < 1) height = 1;
942 if ((depth >>= 1) < 1) depth = 1;
951namespace ImageFormatDetails {
963 return ((width + 3) / 4) * ((height + 3) / 4) * depth *
bpp(format) * 2;
965 return width * height * depth * (
bpp(format) / 8);
980[[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) {
982 for (
int i = mipCount - 1; i >= 0; i--) {
1005[[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) {
1006 uint32_t length = 0;
1007 for (
int j = 0; j < frameCount; j++) {
1008 for (
int i = 0; i < mipCount; i++) {
1012 if (padded && j + 1 != frameCount && length > 512) {
1036[[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) {
1039 for (
int i = mipCount - 1; i >= 0; i--) {
1041 for (
int j = 0; j < frameCount; j++) {
1042 for (
int k = 0; k < faceCount; k++) {
1043 for (
int l = 0; l < mipDepth; l++) {
1045 if (i == mip && j == frame && k == face && l == slice) {
1049 offset += imageSize;
1078[[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) {
1081 for (
int j = 0; j < frameCount; j++) {
1082 for (
int k = 0; k < faceCount; k++) {
1083 for (
int i = 0; i < mipCount; i++) {
1085 for (
int l = 0; l < mipDepth; l++) {
1087 if (i == mip && j == frame && k == face && l == slice) {
1091 offset += imageSize;
1095 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