private void DrawBmp(BmpFile bmpFile) { Bitmap bmp = new Bitmap(bmpFile.DetailInfoHeader.bV4Width, bmpFile.DetailInfoHeader.bV4Height); //Because a single byte defines two pixel colours l/r the actual width of a data row is half the image width int actualWidth = bmpFile.DetailInfoHeader.bV4Width / 2; for (int y = 0; y < bmpFile.DetailInfoHeader.bV4Height; y++) { for (int x = 0; x < actualWidth - 1; x++) { var index = x + y * actualWidth; var pixelValue = bmpFile.PixelData[index]; var rightByte = pixelValue.GetRightNiblet(); var leftByte = pixelValue.GetLeftNiblet(); var rightPixelCol = bmpFile.Clut[rightByte]; var leftPixelCol = bmpFile.Clut[leftByte]; var actualX = x * 2; var actualY = (bmpFile.DetailInfoHeader.bV4Height - 1) - y; bmp.SetPixel(actualX, actualY, leftPixelCol); bmp.SetPixel(actualX + 1, actualY, rightPixelCol); } } BmpInjectPreviewPictureBox.Image = bmp; }
private void SelectBmpInjectButton_Click(object sender, EventArgs e) { OpenFileDialog fileDialog = new OpenFileDialog(); fileDialog.RestoreDirectory = true; fileDialog.Filter = "(bmp)|*.bmp"; if (fileDialog.ShowDialog() == DialogResult.OK) { string filePath = fileDialog.FileName; byte[] data = File.ReadAllBytes(filePath); BmpFile bmpFile = new BmpFile(data); InitPictureBox(bmpFile); DrawBmp(bmpFile); } }
/* ---------------------------------------------------------------------------------------------------------------------------------- */ public static bool TestRleConversionAgainstReferenceBmps(string rlesDirectory, string referenceBmpsDirectory, bool logInfo = true) { var rleFiles = Directory.GetFiles(rlesDirectory, "*.rle", SearchOption.AllDirectories); var referenceBmpFiles = Directory.GetFiles(referenceBmpsDirectory, "*.bmp", SearchOption.AllDirectories); foreach (var rlePath in rleFiles) { RleFile rle = RleFile.CreateFromFile(rlePath); BmpFile bmp = RleToBmp.Convert(rle); var convertedBmpPath = Path.ChangeExtension(rlePath, "bmp"); bmp.WriteToFile(convertedBmpPath); var referenceBmpPath = referenceBmpFiles.SingleOrDefault(b => Path.GetFileNameWithoutExtension(b) == Path.GetFileNameWithoutExtension(rlePath)); if (referenceBmpPath == null) { if (logInfo) { Console.WriteLine("ERROR. Ref bmp not found for " + rle); } continue; } bool areMd5Equal = ValidityUtils.AreMD5Equal(convertedBmpPath, referenceBmpPath); if (!areMd5Equal) { if (logInfo) { Console.WriteLine(string.Format("Converted BMP differs from the reference BMP: \nConverted: {0} \nReference: {1}", convertedBmpPath, referenceBmpPath)); } return(false); } File.Delete(convertedBmpPath); } return(true); }
public GraphicBmp(BmpFile aBmpFile) : base() { int lWidth = ( int )aBmpFile.bmpHeader.width; int lHeight = ( int )aBmpFile.bmpHeader.height; int lBitCount = aBmpFile.bmpHeader.bitCount; Byte[] lDataArray = aBmpFile.bmpData.dataArray; Color[] lColorArray = new Color[lWidth * lHeight]; if (lBitCount == 24) { for (int i = 0; i < lWidth * lHeight; i++) { byte b = lDataArray[i * 3 + 0]; byte g = lDataArray[i * 3 + 1]; byte r = lDataArray[i * 3 + 2]; lColorArray[i] = new Color(( float )r / 0x100, ( float )g / 0x100, ( float )b / 0x100); } } else if (lBitCount == 32) { for (int i = 0; i < lWidth * lHeight; i++) { byte b = lDataArray[i * 4 + 0]; byte g = lDataArray[i * 4 + 1]; byte r = lDataArray[i * 4 + 2]; byte a = lDataArray[i * 4 + 3]; lColorArray[i] = new Color(( float )r / 0x100, ( float )g / 0x100, ( float )b / 0x100, ( float )a / 0x100); } } else { Logger.LogError("Bit Count:" + lBitCount + " is not supported"); } texture = new Texture2D(( int )lWidth, ( int )lHeight, TextureFormat.RGBA32, false); texture.SetPixels(0, 0, ( int )lWidth, ( int )lHeight, lColorArray); texture.Apply(); }
private void InitPictureBox(BmpFile bmpFile) { BmpInjectPreviewPictureBox.Image?.Dispose(); BmpInjectPreviewPictureBox.Width = bmpFile.DetailInfoHeader.bV4Width; BmpInjectPreviewPictureBox.Height = bmpFile.DetailInfoHeader.bV4Height; }