Public Shared Function DecodeData(NCGRfile As Byte(), NSCRfile As Byte(), NCLRfile As Byte()) As Byte()
Dim bmp_size, pixel, width, x_number, height, y_number, color_mode, clr16_number, hv_mode, i, j, k, templow, temphigh, tempscr, tempclr, tempR, tempG, tempB As Integer
Dim ncgr As New MemoryStream(NCGRfile)
Dim nscr As New MemoryStream(NSCRfile)
Dim nclr As New MemoryStream(NCLRfile)
fseek(nscr, 24, 0)
templow = getc(nscr)
temphigh = getc(nscr)
width = templow + (temphigh << 8)
x_number = width \ 8
templow = getc(nscr)
temphigh = getc(nscr)
height = templow + (temphigh << 8)
y_number = height \ 8
pixel = width * height
bmp_size = N + pixel
Dim bmpbuff(bmp_size - 1) As Byte
Dim bmp As New MemoryStream(bmpbuff)
fseek(bmp, 0, 0)
fprintf(bmp, "%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", Asc("B"), Asc("M"),
bmp_size And &HFF, bmp_size >> 8 And &HFF,
bmp_size >> 16 And &HFF, bmp_size >> 24 And &HFF, 0, 0, 0, 0,
54, 4, 0, 0, 40, 0,
0, 0, width And &HFF, width >> 8 And &HFF, 0, 0,
height And &HFF, height >> 8 And &HFF, 0, 0, 1, 0,
8, 0, 0, 0, 0, 0,
pixel And &HFF, pixel >> 8 And &HFF, pixel >> 16 And &HFF, pixel >> 24 And &HFF)
fseek(bmp, 54, 0)
fseek(nclr, 40, 0)
For i = 0 To 255
templow = getc(nclr)
temphigh = getc(nclr)
tempclr = templow + (temphigh << 8)
tempR = (tempclr And &H1F) * 8
tempG = (tempclr >> 5 And &H1F) * 8
tempB = (tempclr >> 10 And &H1F) * 8
fprintf(bmp, "%c%c%c%c", tempB, tempG, tempR, 0)
Next
fseek(nclr, 24, 0)
color_mode = getc(nclr)
fclose(nclr)
fseek(nscr, 36, 0)
Const Color_256 = 4
Const Color_16 = 3
Const Rotate_None = 0
Const Rotate_H = 4
Const Rotate_V = 8
Const Rotate_HV = 12
If color_mode = Color_256 Then
For i = 0 To x_number * y_number - 1
templow = getc(nscr)
temphigh = getc(nscr)
hv_mode = temphigh And &HC
temphigh = temphigh And 3
tempscr = templow + (temphigh << 8)
fseek(ncgr, M + tempscr * 64, 0)
If hv_mode = Rotate_None Then
fseek(bmp, -(i \ x_number * width * 8 + width - (i Mod x_number) * 8), SeekOrigin.End)
For j = 0 To 7
For k = 0 To 7
putc(getc(ncgr), bmp)
Next
fseek(bmp, -(width + 8), SeekOrigin.Current)
Next
ElseIf hv_mode = Rotate_H Then