private static void EncodeBitmapHeader(IcoFrame source, Dialect dialect, BitmapEncoding encoding, Rgba32[] colorTable, ByteWriter writer, out uint offsetToImageSize) { if (dialect != Dialect.Ico) { writer.AddUint16(FileFormatConstants._bitmapFileMagic); writer.AddUint32(0); // Size will be filled in later writer.AddUint32(0); // Reserved writer.AddUint32(0); // Offset will be filled in later } writer.AddUint32(FileFormatConstants._bitmapInfoHeaderSize); writer.AddUint32((uint)source.CookedData.Width); writer.AddUint32((uint)source.CookedData.Height * ((dialect == Dialect.Ico) ? 2u : 1u)); writer.AddUint16(1); // biPlanes writer.AddUint16((ushort)BmpUtil.GetBitDepthForPixelFormat(encoding)); // biBitCount writer.AddUint32(FileFormatConstants.BI_RGB); // biCompression offsetToImageSize = (uint)writer.SeekOffset; writer.AddUint32(0); // biSizeImage writer.AddUint32((dialect == Dialect.Ico) ? 0u : FileFormatConstants._72dpiInPixelsPerMeter); // biXPelsPerMeter writer.AddUint32((dialect == Dialect.Ico) ? 0u : FileFormatConstants._72dpiInPixelsPerMeter); // biYPelsPerMeter writer.AddUint32((uint)(colorTable?.Length ?? 0)); // biClrUsed writer.AddUint32(0); // biClrImportant if (colorTable != null) { foreach (var color in colorTable) { writer.AddUint8(color.B); writer.AddUint8(color.G); writer.AddUint8(color.R); writer.AddUint8(0); } } if (dialect != Dialect.Ico) { while (writer.Data.Count % 4 != 0) { writer.AddUint8(0); } } }