public void SetBitmap(Bitmap bitmap) { Header.Width = (ushort)bitmap.Width; Header.Height = (ushort)(bitmap.Height / Header.TileCount); var ddsPF = DDSHelper.ConvertFromDDSAtlus(Header.PixelFormat); if (ddsPF == DDSFourCC.NONE) { var PF = DDSHelper.DDSAtlusToPixelFormat(Header.PixelFormat); if (bitmap.PixelFormat != PF) { bitmap = bitmap.ConvertTo(PF, null); } dataList[0] = bitmap.CopyData(); if (dataList.Count > 1) { } } else { DDSCompressor.DDSCompress(bitmap, ddsPF, out byte[] newData); dataList[0] = newData; if (dataList.Count > 1) { AuxiliaryLibraries.Media.Processing.Scale.Lanczos lanczos = new AuxiliaryLibraries.Media.Processing.Scale.Lanczos(); Bitmap temp = bitmap; for (int i = 1; i < dataList.Count; i++) { temp = lanczos.imageScale(temp, 0.5f, 0.5f); DDSCompressor.DDSCompress(temp.Width, temp.Height, temp.CopyData(), ddsPF, out newData); dataList[i] = newData; } } } Header.SizeTexture = dataList.Sum(x => x.Length); Header.SizeWOHeader = Header.SizeTexture + (LastBlock == null ? 0 : LastBlock.Length); this.bitmap = null; }
public Bitmap GetBitmap() { if (bitmap == null) { var ddsPF = DDSHelper.ConvertFromDDSAtlus(Header.PixelFormat); if (ddsPF == DDSFourCC.NONE) { var PF = DDSHelper.DDSAtlusToPixelFormat(Header.PixelFormat); bitmap = new Bitmap(Header.Width, Header.Height * Header.TileCount, PF, dataList[0], null); } else { DDSDecompressor.DDSDecompress(Header.Width, Header.Height * Header.TileCount, dataList[0], ddsPF, out byte[] newData); bitmap = new Bitmap(Header.Width, Header.Height * Header.TileCount, PixelFormats.Bgra32, newData, null); } } return(bitmap); }