static int PaletteSize(byte[] dibBuffer) { BITMAPINFOHEADER infoHeader = BinaryStructConverter.FromByteArray <BITMAPINFOHEADER>(dibBuffer); BITMAPCOREHEADER coreHeader = BinaryStructConverter.FromByteArray <BITMAPCOREHEADER>(dibBuffer); if (infoHeader.biSize == System.Runtime.InteropServices.Marshal.SizeOf(infoHeader)) { return(DIBNumColors(dibBuffer) * System.Runtime.InteropServices.Marshal.SizeOf(typeof(RGBQUAD))); } return(DIBNumColors(dibBuffer) * System.Runtime.InteropServices.Marshal.SizeOf(typeof(RGBTRIPLE))); }
public void PopulateWithData(byte[] data, int StartAddress) { bmciHeader = new BITMAPCOREHEADER(); bmciHeader.PopulateWithData(data, StartAddress + 0); bmciColors = new RGBTRIPLE(); bmciColors.PopulateWithData(data, StartAddress + 12); }
static int DIBNumColors(byte[] dibBuffer) { BITMAPINFOHEADER infoHeader = BinaryStructConverter.FromByteArray <BITMAPINFOHEADER>(dibBuffer); /* If this is a Windows-style DIB, the number of colors in the * color table can be less than the number of bits per pixel * allows for (i.e. lpbi->biClrUsed can be set to some value). * If this is the case, return the appropriate value. */ if (infoHeader.biSize == System.Runtime.InteropServices.Marshal.SizeOf(infoHeader)) { if (infoHeader.biClrUsed > 0) { return(infoHeader.biClrUsed); } } /* Calculate the number of colors in the color table based on * the number of bits per pixel for the DIB. */ int bitCount = 0; if (infoHeader.biSize == System.Runtime.InteropServices.Marshal.SizeOf(infoHeader)) { bitCount = infoHeader.biBitCount; } else { BITMAPCOREHEADER coreHeader = BinaryStructConverter.FromByteArray <BITMAPCOREHEADER>(dibBuffer); bitCount = coreHeader.bcBitCount; } /* return number of colors based on bits per pixel */ switch (bitCount) { case 1: return(2); case 4: return(16); case 8: return(256); } return(0); }