public static void WriteToDxgi(this DdsImage dds, string fileName) { if (dds.FormatCode == (int)FourCC.XBOX) { dds = dds.AsUncompressed(); } dds.WriteToDisk(fileName); }
private bool SaveImage(IBitmap bitmap, string baseDir) { var extracted = 0; for (int i = 0; i < bitmap.SubmapCount; i++) { var fileName = MakePath(bitmap.Class, bitmap.Name, baseDir); var ext = "." + Settings.BitmapFormat.ToString().ToLower(); if (bitmap.SubmapCount > 1) { fileName += $"[{i}]"; } if (Settings.BitmapFormat == BitmapFormat.DDS) { if (Settings.OverwriteExisting || !File.Exists(fileName + ext)) { var rawDds = bitmap.ToDds(i); rawDds.WriteToDxgi(fileName + ext); extracted++; } continue; } var outputs = new List <Tuple <string, DecompressOptions> >(); ImageFormat format; if (Settings.BitmapFormat == BitmapFormat.PNG) { format = ImageFormat.Png; } else if (Settings.BitmapFormat == BitmapFormat.TIF) { format = ImageFormat.Tiff; } else if (Settings.BitmapFormat == BitmapFormat.JPEG) { format = ImageFormat.Jpeg; } else //if (Settings.BitmapFormat == BitmapFormat.TGA) { format = null; } if (Settings.BitmapMode == BitmapMode.Default) { outputs.Add(Tuple.Create(fileName + ext, DecompressOptions.Default)); } else if (Settings.BitmapMode == BitmapMode.Bgr24) { outputs.Add(Tuple.Create(fileName + ext, DecompressOptions.Bgr24)); } else if (Settings.BitmapMode == BitmapMode.IsolateAlpha) { outputs.AddRange(GetParamsIsolateAlpha(fileName, ext)); } else if (Settings.BitmapMode == BitmapMode.IsolateAll) { outputs.AddRange(GetParamsIsolateAll(fileName, ext)); } else if (Settings.BitmapMode == BitmapMode.MixedIsolate) { outputs.AddRange(GetParamsMixedIsolate(fileName, ext)); } DdsImage dds = null; foreach (var param in outputs) { if (!Settings.OverwriteExisting && File.Exists(param.Item1)) { continue; } if (dds == null) { dds = bitmap.ToDds(i); } var args = new DdsOutputArgs(param.Item2, bitmap.CubeLayout); if (format != null) { dds.WriteToDisk(param.Item1, format, args); } else //if (Settings.BitmapFormat == BitmapFormat.TGA) { dds.WriteToTarga(param.Item1, args); } extracted++; } } return(extracted > 0); }