MCPcopy Create free account
hub / github.com/DentonW/DevIL / DecompressDXT5

Function DecompressDXT5

DevIL/src-IL/src/il_dds.cpp:1120–1236  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1118
1119
1120ILboolean DecompressDXT5(ILimage *lImage, ILubyte *lCompData)
1121{
1122 ILuint x, y, z, i, j, k, Select;
1123 ILubyte *Temp; //, r0, g0, b0, r1, g1, b1;
1124 Color8888 colours[4], *col;
1125 ILuint bitmask, Offset;
1126 ILubyte alphas[8], *alphamask;
1127 ILuint bits;
1128
1129 if (!lCompData)
1130 return IL_FALSE;
1131
1132 Temp = lCompData;
1133 for (z = 0; z < lImage->Depth; z++) {
1134 for (y = 0; y < lImage->Height; y += 4) {
1135 for (x = 0; x < lImage->Width; x += 4) {
1136 if (y >= lImage->Height || x >= lImage->Width)
1137 break;
1138 alphas[0] = Temp[0];
1139 alphas[1] = Temp[1];
1140 alphamask = Temp + 2;
1141 Temp += 8;
1142
1143 DxtcReadColors(Temp, colours);
1144 bitmask = ((ILuint*)Temp)[1];
1145 UInt(&bitmask);
1146 Temp += 8;
1147
1148 // Four-color block: derive the other two colors.
1149 // 00 = color_0, 01 = color_1, 10 = color_2, 11 = color_3
1150 // These 2-bit codes correspond to the 2-bit fields
1151 // stored in the 64-bit block.
1152 colours[2].b = (2 * colours[0].b + colours[1].b + 1) / 3;
1153 colours[2].g = (2 * colours[0].g + colours[1].g + 1) / 3;
1154 colours[2].r = (2 * colours[0].r + colours[1].r + 1) / 3;
1155 //colours[2].a = 0xFF;
1156
1157 colours[3].b = (colours[0].b + 2 * colours[1].b + 1) / 3;
1158 colours[3].g = (colours[0].g + 2 * colours[1].g + 1) / 3;
1159 colours[3].r = (colours[0].r + 2 * colours[1].r + 1) / 3;
1160 //colours[3].a = 0xFF;
1161
1162 k = 0;
1163 for (j = 0; j < 4; j++) {
1164 for (i = 0; i < 4; i++, k++) {
1165
1166 Select = (bitmask & (0x03 << k*2)) >> k*2;
1167 col = &colours[Select];
1168
1169 // only put pixels out < width or height
1170 if (((x + i) < lImage->Width) && ((y + j) < lImage->Height)) {
1171 Offset = z * lImage->SizeOfPlane + (y + j) * lImage->Bps + (x + i) * lImage->Bpp;
1172 lImage->Data[Offset + 0] = col->r;
1173 lImage->Data[Offset + 1] = col->g;
1174 lImage->Data[Offset + 2] = col->b;
1175 }
1176 }
1177 }

Callers 6

iLoadBlpInternalFunction · 0.85
iLoadVtfInternalFunction · 0.85
DdsDecompressFunction · 0.85
DecompressDXT4Function · 0.85
iLoadRotInternalFunction · 0.85
IwiReadImageFunction · 0.85

Calls 1

DxtcReadColorsFunction · 0.85

Tested by

no test coverage detected