private void OnFormatChanged(object sender, SelectionChangedEventArgs e) { if (!loaded) { return; } var formats = (CompressionFormats[])Enum.GetValues(typeof(CompressionFormats)); for (int i = 0; i < formats.Length; i++) { if (((string)comboBoxFormat.SelectedItem) == formats[i].ToString()) { format = formats[i]; break; } } labelSettings.Visibility = Visibility.Hidden; spinnerQuality.Visibility = Visibility.Hidden; comboBoxSamplesPerBlock.Visibility = Visibility.Hidden; switch (format) { case CompressionFormats.ADPCM: labelSettings.Content = "Samples Per Block"; labelSettings.Visibility = Visibility.Visible; comboBoxSamplesPerBlock.Visibility = Visibility.Visible; break; case CompressionFormats.xWMA: labelSettings.Content = "Quility (1-100)"; labelSettings.Visibility = Visibility.Visible; spinnerQuality.Visibility = Visibility.Visible; break; } }
protected override void OnSaveT(Document input, Stream output, PropertyBasedSaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback) { PSPFile file = new PSPFile(); CompressionFormats format = (CompressionFormats)token.GetProperty(PropertyNames.CompressionType).Value; FileVersion version = (FileVersion)token.GetProperty(PropertyNames.FileVersion).Value; file.Save(input, output, format, scratchSurface, (ushort)version, progressCallback); }
private static PSPCompression CompressionFromTokenFormat(CompressionFormats format) { PSPCompression comp = PSPCompression.None; switch (format) { case CompressionFormats.LZ77: comp = PSPCompression.LZ77; break; } return(comp); }
public CompressionDialog() { InitializeComponent(); format = Config.Format; wmaQuality = Config.WMAQuality; samplesPerBlock = Config.SamplesPerBlock; var formats = (CompressionFormats[])Enum.GetValues(typeof(CompressionFormats)); for (int i = 0; i < formats.Length; i++) { comboBoxFormat.Items.Add(formats[i].ToString()); if (format == formats[i]) { comboBoxFormat.SelectedIndex = i; } } spinnerQuality.Value = Math.Max(1, Math.Min(100, wmaQuality)); var samples = (ADPCMSamplesPerBlock[])Enum.GetValues(typeof(ADPCMSamplesPerBlock)); for (int i = 0; i < samples.Length; i++) { comboBoxSamplesPerBlock.Items.Add(((int)samples[i]).ToString()); if (samplesPerBlock == samples[i]) { comboBoxSamplesPerBlock.SelectedIndex = i; } } labelSettings.Visibility = Visibility.Hidden; spinnerQuality.Visibility = Visibility.Hidden; comboBoxSamplesPerBlock.Visibility = Visibility.Hidden; switch (format) { case CompressionFormats.ADPCM: labelSettings.Content = "Samples Per Block"; labelSettings.Visibility = Visibility.Visible; comboBoxSamplesPerBlock.Visibility = Visibility.Visible; break; case CompressionFormats.xWMA: labelSettings.Content = "Quility (1-100)"; labelSettings.Visibility = Visibility.Visible; spinnerQuality.Visibility = Visibility.Visible; break; } }
/// <summary> /// Initialize the class /// </summary> /// /// <param name="Format">Compression engine</param> /// <param name="FolderOption">Compression all folders or top directory only</param> public Compress(CompressionFormats Format = CompressionFormats.Deflate, SearchOption FolderOption = SearchOption.AllDirectories) { CompressionFormat = Format; BlockSize = DEF_BLOCK; this.FolderOption = FolderOption; }
/// <summary> /// Create a Compression header from a folder path /// </summary> /// /// <param name="InputPath">The file to compress</param> /// <param name="Format">The compression format</param> /// <param name="FolderOption">The scope of the folder compression; top level or all sub-folders</param> /// /// <returns>An initialized CompressionHeader structure</returns> public static CompressionHeader CreateFolderHeader(string InputPath, CompressionFormats Format = CompressionFormats.Deflate, SearchOption FolderOption = SearchOption.AllDirectories) { if (!Directory.Exists(InputPath)) return new CompressionHeader(); CompressionHeader header = new CompressionHeader(); char[] names = GetNameArray(InputPath, FolderOption); header.Format = (int)Format; header.FileCount = GetFileCount(InputPath, FolderOption); header.NameSize = names.Length; header.FileSizes = GetFileSizes(InputPath, FolderOption); header.FileNames = names; return header; }
/// <summary> /// Create a Compression header from a file path /// </summary> /// /// <param name="InputFile">The file to compress</param> /// <param name="Format">The compression format</param> /// /// <returns>An initialized CompressionHeader structure</returns> public static CompressionHeader CreateFileHeader(string InputFile, CompressionFormats Format = CompressionFormats.Deflate) { if (!File.Exists(InputFile)) return new CompressionHeader(); CompressionHeader header = new CompressionHeader(); char[] name = Path.GetFileName(InputFile).ToCharArray(); header.Format = (int)Format; header.FileCount = 1; header.NameSize = name.Length; header.FileSizes = new Int64[1]; header.FileSizes[0] = GetFileSize(InputFile); header.FileNames = name; return header; }
/// <summary> /// Initialize the CompressionHeader structure /// </summary> /// /// <param name="FileCount">The number of compressed files</param> /// <param name="NameSize">Length of an array of file names</param> /// <param name="FileSizes">An array containing the size of each file in the archive</param> /// <param name="FileNames">An array containing the name and subfolder path of each file in the archive</param> /// <param name="Format">The compression format</param> public CompressionHeader(Int32 FileCount, Int32 NameSize, Int64[] FileSizes, char[] FileNames, CompressionFormats Format) { this.Format = (Int32)Format; this.FileCount = FileCount; this.NameSize = NameSize; this.FileSizes = FileSizes; this.FileNames = FileNames; }
/// <summary> /// Create an empty Compression header /// </summary> /// /// <param name="Format">The compression format</param> /// /// <returns>An initialized CompressionHeader structure</returns> public static CompressionHeader CreateFileHeader(CompressionFormats Format = CompressionFormats.Deflate) { CompressionHeader header = new CompressionHeader(); header.Format = (int)Format; header.FileCount = 0; header.NameSize = 0; header.FileSizes = new Int64[0]; header.FileSizes[0] = 1; header.FileNames = new char[0]; return header; }
public void Save(Document input, Stream output, CompressionFormats format, Surface scratchSurface, ushort majorVersion, ProgressEventHandler callback) { if (majorVersion == PSPConstants.majorVersion5 && input.Layers.Count > 64) { throw new FormatException(string.Format(Properties.Resources.MaxLayersFormat, 64)); } else if ((majorVersion == PSPConstants.majorVersion6 || majorVersion == PSPConstants.majorVersion7) && input.Layers.Count > 100) { throw new FormatException(string.Format(Properties.Resources.MaxLayersFormat, 100)); } using (BinaryWriterEx writer = new BinaryWriterEx(output, false)) { this.fileHeader = new FileHeader(majorVersion); this.imageAttributes = new GeneralImageAttributes( input.Width, input.Height, CompressionFromTokenFormat(format), 0, input.Layers.Count, majorVersion); switch (input.DpuUnit) { case MeasurementUnit.Centimeter: this.imageAttributes.ResValue = input.DpuX; this.imageAttributes.ResUnit = ResolutionMetric.Centimeter; break; case MeasurementUnit.Inch: this.imageAttributes.ResValue = input.DpuX; this.imageAttributes.ResUnit = ResolutionMetric.Inch; break; } this.totalProgress = 0; this.doneProgress = 0; bool flatImage = true; foreach (Layer item in input.Layers) { BitmapLayer layer = (BitmapLayer)item; Rectangle rect = PSPUtil.GetImageSaveRectangle(layer.Surface); if (!rect.IsEmpty) { if (LayerHasTransparency(layer.Surface, rect)) { this.totalProgress += 4; flatImage = false; } else { this.totalProgress += 3; } } } if (flatImage) { this.imageAttributes.SetGraphicContentFlag(PSPGraphicContents.FlatImage); } if (majorVersion > PSPConstants.majorVersion5) { CreateCompositeImageBlock(input, scratchSurface, callback, majorVersion); } else { CreateThumbnailBlock(input, scratchSurface, callback, majorVersion); } int layerCount = input.Layers.Count; LayerInfoChunk[] layerInfoChunks = new LayerInfoChunk[layerCount]; LayerBitmapInfoChunk[] layerBitmapChunks = new LayerBitmapInfoChunk[layerCount]; for (int i = 0; i < layerCount; i++) { BitmapLayer layer = (BitmapLayer)input.Layers[i]; Rectangle savedBounds = PSPUtil.GetImageSaveRectangle(layer.Surface); LayerInfoChunk infoChunk = new LayerInfoChunk(layer, BlendOptoBlendMode(layer.BlendOp), savedBounds, majorVersion); int channelCount = 3; int bitmapCount = 1; if (LayerHasTransparency(layer.Surface, savedBounds)) { channelCount = 4; bitmapCount = 2; } LayerBitmapInfoChunk biChunk = new LayerBitmapInfoChunk(bitmapCount, channelCount) { channels = SplitImageChannels(layer.Surface, savedBounds, channelCount, majorVersion, false, callback) }; if (majorVersion <= PSPConstants.majorVersion5) { infoChunk.v5BitmapCount = biChunk.bitmapCount; infoChunk.v5ChannelCount = biChunk.channelCount; } layerInfoChunks[i] = infoChunk; layerBitmapChunks[i] = biChunk; } this.layerBlock = new LayerBlock(layerInfoChunks, layerBitmapChunks); string creatorData = input.Metadata.GetUserValue(PSPCreatorMetaData); if (!string.IsNullOrEmpty(creatorData)) { this.creator = DeserializeFromBase64 <CreatorBlock>(creatorData); } else { this.creator = new CreatorBlock(); } writer.Write(PSPFileSig); this.fileHeader.Save(writer); this.imageAttributes.Save(writer); this.creator.Save(writer); if (this.compImage != null) { this.compImage.Save(writer); } else if (this.v5Thumbnail != null) { this.v5Thumbnail.Save(writer); } this.layerBlock.Save(writer, majorVersion); } }