private void extractToolStripMenuItem_Click(object sender, EventArgs e) { TreeNode node = this.resourceView.SelectedNode; SCI32Resource res = null; try { if (this.ResourceDirectories.TryGetResourceByFilename(node.Name, out res)) { string ext = SCI32Resource.ExtentionFromResourceType(res.ResourceType); saveFileDialog1.Filter = string.Format("SCI32 {0}|{1}", res.ResourceType, ext); saveFileDialog1.FileName = res.FileName; DialogResult result = saveFileDialog1.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { byte[] file = new byte[res.FileData.Length - 8]; Array.Copy(res.FileData, 8, file, 0, file.Length); string _file = Encoding.Default.GetString(file); try { bool compresed = res.CompressedLength != res.UnCompressedLength; if (compresed) { LZWDecoder decoder = new LZWDecoder(); string sfile = decoder.Decode(_file); //file = Encoding.ASCII.GetBytes(sfile); } File.WriteAllBytes(saveFileDialog1.FileName, file); } catch (Exception ex) { MessageBox.Show(string.Format("Unable to save file {0}, Error was {1}", res.FileName, ex.Message)); } } } } catch { } }
/// <summary> /// Reads from the specified stream. /// </summary> /// <param name="stream">The stream.</param> /// <param name="descriptor">The descriptor.</param> /// <returns> /// The resulting FrameIndices object /// </returns> public static FrameIndices Read(Stream stream, ImageDescriptor descriptor) { var DataSize = stream.ReadByte(); var Decoder = new LZWDecoder(stream); return(new FrameIndices(Decoder.Decode(descriptor.Width, descriptor.Height, DataSize), 0)); }
public static byte[] decompress(byte[] compressed, CompressionMethod compId, int expectedByteCount) { switch (compId) { case CompressionMethod.UNCOMPRESSED: return(compressed); case CompressionMethod.LZW: var lzwDecoder = new LZWDecoder(); string decompressed = lzwDecoder.Decode(compressed); byte[] bytes = new byte[expectedByteCount]; for (int i = 0; i < bytes.Length; i++) { bytes[i] = (byte)decompressed[i]; } return(bytes); case CompressionMethod.DEFLATE: case CompressionMethod.ADOBE_DEFLATE: return(deflateDecompress(compressed, expectedByteCount)); case CompressionMethod.PACKBITS: return(packbitsDecompress(compressed, expectedByteCount)); default: throw new ReadFileException("Unsupported comnpression"); } }
public static void Decode(string arquivo) { //Carrega arquivo comprimido byte[] dados = Arquivo.AbrirEmBytes(arquivo); BitArray bits = new BitArray(dados); Console.WriteLine("Iniciada a decompressão"); DateTime dataInicial = DateTime.Now; HuffmanTree huffman = new HuffmanTree(); //Decodificando a árvore huffman string huffmanDecoded = huffman.Decode(bits); LZWDecoder lZWDecoder = new LZWDecoder(); //Decodificando LZW string conteudo = lZWDecoder.Decode(huffmanDecoded); DateTime dataFinal = DateTime.Now; string tempoDecorrido = (dataFinal - dataInicial).TotalSeconds.ToString("N2"); //Contabiliza apenas os tempos para decompressão. Igora tempo de IO Console.WriteLine($"Arquivo descomprimido em {tempoDecorrido} segundos"); Arquivo.Gravar(conteudo, $"{arquivo.Split('.')[0]} - Descomprimido.txt"); }
public static void decode(string filename) { var fileContent = FileWrapper.openInBytes(filename); var deltaDecoded = Delta.decode(fileContent); var decoder = new LZWDecoder(); var lzwDecoded = decoder.Decode(deltaDecoded); FileWrapper.write(lzwDecoded, getDecodedFilename(filename)); }
public override byte[] Decompress(Stream s, int dataLen, uint key) { var sb = new List <byte>(); var decoder = new LZWDecoder(); while (sb.Count < dataLen) { sb.AddRange(decoder.Decode(s.ReadBytes(s.ReadInt32()))); } return(sb.ToArray()); }
public override byte[] Decompress(Stream s, int dataLen, uint key) { var sb = new List<byte>(); var decoder = new LZWDecoder(); while (sb.Count < dataLen) { sb.AddRange(decoder.Decode(s.ReadBytes(s.ReadInt32()))); } return sb.ToArray(); }
public static byte[] LzwDecode(byte[] data) { try { LZWDecoder lzw = new LZWDecoder(); MemoryStream stream = new MemoryStream(); lzw.Decode(data, stream); return stream.GetBuffer(); } catch (Exception e) { MessageBox.Show(e.ToString() ); } return new byte[0]; }