Sorry for the beginner question, Iโm pretty new here
. The compiler is giving me 4 different syntax errors that all seem nonsensical, how would i correctly do this without several nested if else statements?
enum ImageFormats : u32 {
I4 = 0,
I8 = 1,
IA4 = 2,
IA8 = 3,
RGB565 = 4,
RGB5A3 = 5,
RGBA8 = 6,
C4 = 8,
C8 = 9,
C14X2 = 10,
CMPR = 14,
};
fn calculateImageSizeBytes(ImageFormats format, u16 width, u16 height) {
u16 blockWidth;
u16 blockHeight;
u32 bytesPerBlock;
switch (format) {
case I4:
case C4:
case CMPR:
blockWidth = 8;
blockHeight = 8;
bytesPerBlock = 32;
break;
case I8:
case IA4:
case C8:
blockWidth = 8;
blockHeight = 4;
bytesPerBlock = 32;
break;
case IA8:
case RGB565:
case RGB5A3:
case C14X2:
blockWidth = 4;
blockHeight = 4;
bytesPerBlock = 32;
break;
case RGBA8:
blockWidth = 4;
blockHeight = 4;
bytesPerBlock = 64;
break;
}
u32 total_blocks_width = width / blockWidth;
if (width % blockWidth > 0) {
total_blocks_width += 1;
}
u32 total_blocks_height = height / blockHeight;
if (height % blockHeight > 0) {
total_blocks_height += 1;
}
u32 totalBytes = total_blocks_width * total_blocks_height * bytesPerBlock;
return totalBytes;
}

