public override void SetModuleSettings(IModule module) { // GVM archive if (module is GvmArchiveWriter) { GvmArchiveWriter archive = (GvmArchiveWriter)module; archive.HasFilenames = hasFilenamesCheckbox.Checked; archive.HasGlobalIndexes = hasGlobalIndexesCheckbox.Checked; archive.HasFormats = hasFormatsCheckbox.Checked; archive.HasDimensions = hasDimensionsCheckbox.Checked; } // PVM archive else if (module is PvmArchiveWriter) { PvmArchiveWriter archive = (PvmArchiveWriter)module; archive.HasFilenames = hasFilenamesCheckbox.Checked; archive.HasGlobalIndexes = hasGlobalIndexesCheckbox.Checked; archive.HasFormats = hasFormatsCheckbox.Checked; archive.HasDimensions = hasDimensionsCheckbox.Checked; } }
private void SaveTextures() { byte[] data; using (MemoryStream str = new MemoryStream()) { PvmArchiveWriter writer = new PvmArchiveWriter(str); foreach (TextureInfo tex in textures) { if (tex.DataFormat != PvrDataFormat.Index4 && tex.DataFormat != PvrDataFormat.Index8) { System.Drawing.Imaging.BitmapData bmpd = tex.Image.LockBits(new Rectangle(Point.Empty, tex.Image.Size), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); int stride = bmpd.Stride; byte[] bits = new byte[Math.Abs(stride) * bmpd.Height]; System.Runtime.InteropServices.Marshal.Copy(bmpd.Scan0, bits, 0, bits.Length); tex.Image.UnlockBits(bmpd); int tlevels = 0; for (int y = 0; y < tex.Image.Height; y++) { int srcaddr = y * Math.Abs(stride); for (int x = 0; x < tex.Image.Width; x++) { Color c = Color.FromArgb(BitConverter.ToInt32(bits, srcaddr + (x * 4))); if (c.A == 0) tlevels = 1; else if (c.A < 255) { tlevels = 2; break; } } if (tlevels == 2) break; } if (tlevels == 0) tex.PixelFormat = PvrPixelFormat.Rgb565; else if (tlevels == 1) tex.PixelFormat = PvrPixelFormat.Argb1555; else if (tlevels == 2) tex.PixelFormat = PvrPixelFormat.Argb4444; if (tex.Image.Width == tex.Image.Height) if (tex.Mipmap) tex.DataFormat = PvrDataFormat.SquareTwiddledMipmaps; else tex.DataFormat = PvrDataFormat.SquareTwiddled; else tex.DataFormat = PvrDataFormat.Rectangle; } PvrTextureEncoder encoder = new PvrTextureEncoder(tex.Image, tex.PixelFormat, tex.DataFormat); encoder.GlobalIndex = tex.GlobalIndex; MemoryStream pvr = new MemoryStream(); encoder.Save(pvr); pvr.Seek(0, SeekOrigin.Begin); writer.CreateEntry(pvr, tex.Name); } writer.Flush(); data = str.ToArray(); str.Close(); } if (Path.GetExtension(filename).Equals(".prs", StringComparison.OrdinalIgnoreCase)) FraGag.Compression.Prs.Compress(data, filename); else File.WriteAllBytes(filename, data); }