private void convert_4x4texel_b(byte[] tex, int width, int height, byte[] data, Color[] pal, NSMBe4.NSBMD.ImageTexeler.LockBitmap rgbaOut) { var list1 = new List<uint>(); for (int i = 0; i < (tex.Length + 1) / 4; ++i) list1.Add(LibNDSFormats.Utils.Read4BytesAsUInt32(tex, i * 4)); var list2 = new List<UInt16>(); for (int i = 0; i < (data.Length + 1) / 2; ++i) list2.Add(LibNDSFormats.Utils.Read2BytesAsUInt16(data, i * 2)); var b = convert_4x4texel(list1.ToArray(), width, height, list2.ToArray(), pal, rgbaOut); }
private bool convert_4x4texel(uint[] tex, int width, int height, UInt16[] data, Color[] pal, NSMBe4.NSBMD.ImageTexeler.LockBitmap rgbaOut) { int w = width / 4; int h = height / 4; // traverse 'w x h blocks' of 4x4-texel for (int y = 0; y < h; y++) for (int x = 0; x < w; x++) { int index = y * w + x; UInt32 t = tex[index]; UInt16 d = data[index]; UInt16 addr = (ushort)(d & 0x3fff); UInt16 mode = (ushort)((d >> 14) & 3); // traverse every texel in the 4x4 texels for (int r = 0; r < 4; r++) for (int c = 0; c < 4; c++) { int texel = (int)((t >> ((r * 4 + c) * 2)) & 3); Color pixel = rgbaOut.GetPixel((x * 4 + c), (y * 4 + r)); switch (mode) { case 0: pixel = pal[(addr << 1) + texel]; if (texel == 3) pixel = Color.Transparent; // make it transparent, alpha = 0 break; case 2: pixel = pal[(addr << 1) + texel]; break; case 1: switch (texel) { case 0: case 1: pixel = pal[(addr << 1) + texel]; break; case 2: byte R = (byte)((pal[(addr << 1)].R + pal[(addr << 1) + 1].R) / 2L); byte G = (byte)((pal[(addr << 1)].G + pal[(addr << 1) + 1].G) / 2L); byte B = (byte)((pal[(addr << 1)].B + pal[(addr << 1) + 1].B) / 2L); byte A = 0xff; pixel = Color.FromArgb(A, R, G, B); break; case 3: pixel = Color.Transparent; // make it transparent, alpha = 0 break; } break; case 3: switch (texel) { case 0: case 1: pixel = pal[(addr << 1) + texel]; break; case 2: { byte R = (byte)((pal[(addr << 1)].R * 5L + pal[(addr << 1) + 1].R * 3L) / 8); byte G = (byte)((pal[(addr << 1)].G * 5L + pal[(addr << 1) + 1].G * 3L) / 8); byte B = (byte)((pal[(addr << 1)].B * 5L + pal[(addr << 1) + 1].B * 3L) / 8); byte A = 0xff; pixel = Color.FromArgb(A, R, G, B); break; } case 3: { byte R = (byte)((pal[(addr << 1)].R * 3L + pal[(addr << 1) + 1].R * 5L) / 8); byte G = (byte)((pal[(addr << 1)].G * 3L + pal[(addr << 1) + 1].G * 5L) / 8); byte B = (byte)((pal[(addr << 1)].B * 3L + pal[(addr << 1) + 1].B * 5L) / 8); byte A = 0xff; pixel = Color.FromArgb(A, R, G, B); break; } } break; } rgbaOut.SetPixel((x * 4 + c), (y * 4 + r), pixel); //rgbaOut[(y * 4 + r) * width + (x * 4 + c)] = pixel; } } return true; }