public static Bitmap DecompressHuffman(string imgSrc) { //moram da pocnem odmah otvaranjem fajla i ucitavanjem bajtova redom kako su upisivani byte[] bmpWidth; byte[] bmpHeight; byte[] stride; byte[] downsampleChannels; byte[] dictionarySize; byte[] dictionary; byte[] YDataLen; byte[] CbDataLen; byte[] CrDataLen; byte[] imageData; HuffmanTree tree = new HuffmanTree(); using (var reader = new BinaryReader(File.Open(imgSrc, FileMode.Open))) { bmpWidth = reader.ReadBytes(4); bmpHeight = reader.ReadBytes(4); stride = reader.ReadBytes(4); downsampleChannels = reader.ReadBytes(4); YDataLen = reader.ReadBytes(4); CbDataLen = reader.ReadBytes(4); CrDataLen = reader.ReadBytes(4); dictionarySize = reader.ReadBytes(4); int dictSize = BitConverter.ToInt32(dictionarySize, 0); dictionary = reader.ReadBytes(dictSize); tree.DeserializeDictionary(dictionary); List <byte> compressedData = new List <byte>(); while (reader.BaseStream.Position != reader.BaseStream.Length) { compressedData.Add(reader.ReadByte()); } imageData = tree.Decode(new BitArray(compressedData.ToArray())); } int width = BitConverter.ToInt32(bmpWidth, 0); int height = BitConverter.ToInt32(bmpHeight, 0); int strideInt = BitConverter.ToInt32(stride, 0); int downampleChannelsInt = BitConverter.ToInt32(downsampleChannels, 0); int yDataLen = BitConverter.ToInt32(YDataLen, 0); int cbDataLen = BitConverter.ToInt32(CbDataLen, 0); int crDataLen = BitConverter.ToInt32(CrDataLen, 0); DownsampleFormat format = new DownsampleFormat(strideInt, width, height, yDataLen, cbDataLen, crDataLen, downampleChannelsInt); format.data = imageData; Downsampling sampling = new Downsampling(); return(sampling.RestoreBitmap(format)); }
public void DownsampleClick() { this.channelsOn = true; this.view.MakeChannelsVisible(); Downsampling down = new Downsampling(this.model.getMainImage()); DownsampleFormat df1 = down.Downsample(1); DownsampleFormat df2 = down.Downsample(2); DownsampleFormat df3 = down.Downsample(2); //Compression.DownsamplingNew.Downsampling down = new Compression.DownsamplingNew.Downsampling(this.model.getMainImage()); //Compression.DownsamplingNew.DownsampleFormat df1 = down.DownsampleImage("YCb"); //Compression.DownsamplingNew.DownsampleFormat df2 = down.DownsampleImage("CbCr"); //Compression.DownsamplingNew.DownsampleFormat df3 = down.DownsampleImage("YCr"); this.model.setYChannel(down.RestoreBitmap(df1)); this.model.setCbChannel(down.RestoreBitmap(df2)); this.model.setCrChannel(down.RestoreBitmap(df3)); this.view.ShowImages(model.getMainImage(), model.getYChannel(), model.getCbChannel(), model.getCrChannel(), model.getImageName()); }