281 return green(format);
483 return alpha(format);
659 return red(format) == -1;
668 const auto a =
alpha(format);
753[[nodiscard]]
constexpr uint16_t
getMipDim(uint8_t mip, uint16_t dim,
bool addCompressedFormatPadding =
false) {
757 for (
int i = 0; i < mip && dim > 1; i++) {
760 if (addCompressedFormatPadding) {
774[[nodiscard]]
constexpr std::pair<uint16_t, uint16_t>
getMipDims(uint8_t mip, uint16_t width, uint16_t height,
bool addCompressedFormatPadding =
false) {
775 for (
int i = 0; i < mip && (width > 1 || height > 1); i++) {
776 if ((width >>= 1) < 1) width = 1;
777 if ((height >>= 1) < 1) height = 1;
779 if (addCompressedFormatPadding) {
783 return {width, height};
795[[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) {
796 for (
int i = 0; i < mip && (width > 1 || height > 1 || depth > 1); i++) {
797 if ((width >>= 1) < 1) width = 1;
798 if ((height >>= 1) < 1) height = 1;
799 if ((depth >>= 1) < 1) depth = 1;
801 if (addCompressedFormatPadding) {
805 return {width, height, depth};
817[[nodiscard]]
constexpr uint8_t
getMaximumMipCount(uint16_t width, uint16_t height, uint16_t depth = 1) {
818 uint8_t numMipLevels = 1;
819 if (width && height && depth) {
820 while (width > 1 || height > 1 || depth > 1) {
821 if ((width >>= 1) < 1) width = 1;
822 if ((height >>= 1) < 1) height = 1;
823 if ((depth >>= 1) < 1) depth = 1;
832namespace ImageFormatDetails {
844 return ((width + 3) / 4) * ((height + 3) / 4) * depth *
bpp(format) * 2;
846 return width * height * depth * (
bpp(format) / 8);
861[[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) {
863 for (
int i = mipCount - 1; i >= 0; i--) {
886[[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) {
888 for (
int j = 0; j < frameCount; j++) {
889 for (
int i = 0; i < mipCount; i++) {
893 if (padded && j + 1 != frameCount && length > 512) {
917[[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) {
920 for (
int i = mipCount - 1; i >= 0; i--) {
922 for (
int j = 0; j < frameCount; j++) {
923 for (
int k = 0; k < faceCount; k++) {
924 for (
int l = 0; l < mipDepth; l++) {
926 if (i == mip && j == frame && k == face && l == slice) {
959[[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) {
962 for (
int j = 0; j < frameCount; j++) {
963 for (
int k = 0; k < faceCount; k++) {
964 for (
int i = 0; i < mipCount; i++) {
966 for (
int l = 0; l < mipDepth; l++) {
968 if (i == mip && j == frame && k == face && l == slice) {
976 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.
@ CONSOLE_ARGB8888_LINEAR
@ CONSOLE_BGRX8888_LINEAR
@ CONSOLE_RGBA8888_LINEAR
@ CONSOLE_ABGR8888_LINEAR
@ CONSOLE_BGRX5551_LINEAR
@ CONSOLE_BGRA8888_LINEAR
@ CONSOLE_RGBA16161616_LINEAR