/// <summary> /// Converts the file data from the specified format /// </summary> /// <param name="inputFormat">The format to convert from</param> /// <param name="outputFormat">The format to convert to</param> /// <param name="currentFileStream">The current file stream</param> /// <param name="inputStream">The input file data stream to convert from</param> /// <param name="outputStream">The output stream for the converted data</param> /// <param name="manager">The manager</param> public void ConvertFrom(FileExtension inputFormat, FileExtension outputFormat, ArchiveFileStream currentFileStream, ArchiveFileStream inputStream, ArchiveFileStream outputStream, IArchiveDataManager manager) { // Load the bitmap using Bitmap bmp = new(inputStream.Stream); // Load the current file GF gf = GetFileContent(currentFileStream, manager); // IDEA: If bmp is not in supported format, then convert it? RawBitmapData rawBitmapData; // Get the bitmap lock using (BitmapLock bmpLock = new(bmp)) { // Get the raw bitmap data rawBitmapData = new RawBitmapData(bmp.Width, bmp.Height, bmpLock.Pixels, bmp.PixelFormat); // Force the new pixel format to be 888 or 8888 if set to do so if (Services.Data.Archive_GF_ForceGF8888Import) { gf.PixelFormat = gf.PixelFormat.SupportsTransparency() ? GF_Format.Format_32bpp_BGRA_8888 : GF_Format.Format_24bpp_BGR_888; } // Check if the format should be updated for transparency if (Services.Data.Archive_GF_UpdateTransparency != UserData_Archive_GF_TransparencyMode.PreserveFormat) { // NOTE: Only 24 and 32 bpp bitmaps are supported // Check if the imported file is transparent bool?isTransparent = bmp.PixelFormat switch { PixelFormat.Format32bppArgb => (Services.Data.Archive_GF_UpdateTransparency == UserData_Archive_GF_TransparencyMode.UpdateBasedOnPixelFormat || bmpLock.UtilizesAlpha()), PixelFormat.Format24bppRgb => false, _ => null }; // NOTE: Currently only supported for formats with 3 or 4 channels // Check if the format should be updated for transparency if (gf.Channels >= 3 && isTransparent != null) { // Update the format gf.PixelFormat = isTransparent.Value ? GF_Format.Format_32bpp_BGRA_8888 : GF_Format.Format_24bpp_BGR_888; } } } byte oldRepeatByte = gf.RepeatByte; OpenSpaceSettings settings = manager.Context !.GetSettings <OpenSpaceSettings>(); // Import the bitmap gf.ImportFromBitmap(settings, rawBitmapData, Services.Data.Archive_GF_GenerateMipmaps); Logger.Debug("The repeat byte has been updated for a .gf file from {0} to {1}", oldRepeatByte, gf.RepeatByte); // Serialize the data to get the bytes manager.Context.WriteStreamData(outputStream.Stream, gf, name: outputStream.Name, leaveOpen: true); }