/// <summary> /// Loads output.dct /// initializes data /// uses DctImageProcessor::UncoProcess /// in a thread to display a JPEG image /// </summary> /// <param name="sender">c# params</param> /// <param name="e">c# params</param> private void openCompressedToolStripMenuItem_Click(object sender, EventArgs e) { if (FOpen.ShowDialog() != DialogResult.OK) { return; } try { Stream raw = FOpen.OpenFile(); using (MemoryStream ms = new MemoryStream()) { raw.CopyTo(ms); Manager = new DataManager(); leftPicture.Image = null; rightPicture.Image = null; Manager.LoadedData = ms.ToArray().Select(s => (sbyte)s).ToArray(); SetSizeToolStrip(Manager.LoadedData.Length); Manager.box = leftPicture; Manager.rbox = rightPicture; } } catch (Exception ex) { MessageBox.Show(@"Error: Could not read file from disk. Original error: " + ex.Message); } DctImageProcessor processor = new DctImageProcessor(Manager); Task.Run(() => processor.UndoProcess()); }
/// <summary> /// Loads an image and uses /// splits it into YCBCR arrays /// subsamples CB and CR using 4:2:0 /// DctImageProcessor::Process function to /// compress image with /// DCT => QUantize => ZigZag => RLE => File (output.dct) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void compressToolStripMenuItem_Click(object sender, EventArgs e) { if (FOpen.ShowDialog() != DialogResult.OK) { return; } try { Image image = Image.FromStream(FOpen.OpenFile()); Manager.SetLeftPicture(image); leftPicture.Image = Manager.LeftImageBitmap; MemoryStream ms = new MemoryStream(); image.Save(ms, ImageFormat.Bmp); int bytes = (int)ms.Length; SetSizeToolStrip(bytes); ms.Close(); } catch (Exception ex) { MessageBox.Show(@"Error: Could not read file from disk. Original error: " + ex.Message); } Manager.SplitBytesIntoColorSpaces(); Manager.DrawYcbcrOnRightBitmap(1); rightPicture.Image = Manager.RightImageBitmap; DctImageProcessor imageProcessor = new DctImageProcessor(Manager); Task.Run(() => imageProcessor.Process()); }
private void HandleRightContext(object sender, ToolStripItemClickedEventArgs e) { if (e.ClickedItem.Text == @"Set Image") { contextMenuStrip2.Hide(); SetRightImage(); } else if (e.ClickedItem.Text == @"Open Compressed") { contextMenuStrip2.Hide(); if (FOpen.ShowDialog() != DialogResult.OK) { return; } try { Stream raw = FOpen.OpenFile(); using (MemoryStream ms = new MemoryStream()) { raw.CopyTo(ms); Manager = new DataManager(); leftPicture.Image = null; rightPicture.Image = null; Manager.LoadedData = ms.ToArray().Select(s => (sbyte)s).ToArray(); SetSizeToolStrip(Manager.LoadedData.Length); Manager.box = leftPicture; Manager.rbox = rightPicture; } } catch (Exception ex) { MessageBox.Show(@"Error: Could not read file from disk. Original error: " + ex.Message); } DctImageProcessor processor = new DctImageProcessor(Manager); Task.Run(() => processor.UndoProcess()); } else { contextMenuStrip2.Hide(); RightImageClear(); } }
/// <summary> /// Loads output.dct /// initializes data /// uses DctImageProcessor::UncoProcess /// in a thread to display a JPEG image /// </summary> /// <param name="sender">c# params</param> /// <param name="e">c# params</param> private void openCompressedToolStripMenuItem_Click(object sender, EventArgs e) { if (FOpen.ShowDialog() != DialogResult.OK) return; try { Stream raw = FOpen.OpenFile(); using (MemoryStream ms = new MemoryStream()) { raw.CopyTo(ms); Manager = new DataManager(); leftPicture.Image = null; rightPicture.Image = null; Manager.LoadedData = ms.ToArray().Select(s=>(sbyte)s).ToArray(); SetSizeToolStrip(Manager.LoadedData.Length); Manager.box = leftPicture; Manager.rbox = rightPicture; } } catch (Exception ex) { MessageBox.Show(@"Error: Could not read file from disk. Original error: " + ex.Message); } DctImageProcessor processor = new DctImageProcessor(Manager); Task.Run(()=>processor.UndoProcess()); }
private void HandleRightContext(object sender, ToolStripItemClickedEventArgs e) { if(e.ClickedItem.Text == @"Set Image") { contextMenuStrip2.Hide(); SetRightImage(); }else if (e.ClickedItem.Text == @"Open Compressed") { contextMenuStrip2.Hide(); if(FOpen.ShowDialog() != DialogResult.OK) return; try { Stream raw = FOpen.OpenFile(); using(MemoryStream ms = new MemoryStream()) { raw.CopyTo(ms); Manager = new DataManager(); leftPicture.Image = null; rightPicture.Image = null; Manager.LoadedData = ms.ToArray().Select(s => (sbyte)s).ToArray(); SetSizeToolStrip(Manager.LoadedData.Length); Manager.box = leftPicture; Manager.rbox = rightPicture; } } catch(Exception ex) { MessageBox.Show(@"Error: Could not read file from disk. Original error: " + ex.Message); } DctImageProcessor processor = new DctImageProcessor(Manager); Task.Run(() => processor.UndoProcess()); } else { contextMenuStrip2.Hide(); RightImageClear(); } }
private void HandleLeftContext(object sender, ToolStripItemClickedEventArgs e) { if (e.ClickedItem.Text== @"Compress Image") { contextMenuStrip1.Hide(); if(FOpen.ShowDialog() != DialogResult.OK) return; try { Image image = Image.FromStream(FOpen.OpenFile()); Manager.SetLeftPicture(image); leftPicture.Image = Manager.LeftImageBitmap; MemoryStream ms = new MemoryStream(); image.Save(ms, ImageFormat.Bmp); int bytes = (int)ms.Length; SetSizeToolStrip(bytes); ms.Close(); } catch(Exception ex) { MessageBox.Show(@"Error: Could not read file from disk. Original error: " + ex.Message); } Manager.SplitBytesIntoColorSpaces(); Manager.DrawYcbcrOnRightBitmap(1); rightPicture.Image = Manager.RightImageBitmap; DctImageProcessor imageProcessor = new DctImageProcessor(Manager); Task.Run(() => imageProcessor.Process()); }else if (e.ClickedItem.Text == @"Set Image") { contextMenuStrip1.Hide(); SetLeftImage(); } else { contextMenuStrip1.Hide(); LeftImageClear(); } }
/// <summary> /// Method to decompress MPEG /// opens a file selector /// reads data /// initializes its data /// sends it off to DctImageProcessor::UntoRippeg function /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void decompressToolStripMenuItem2_Click(object sender, EventArgs e) { if (FOpen.ShowDialog() != DialogResult.OK) return; try { Stream raw = FOpen.OpenFile(); using (MemoryStream ms = new MemoryStream()) { raw.CopyTo(ms); MPEGData[0] = new DataManager(); leftPicture.Image = null; rightPicture.Image = null; MPEGData[0].LoadedData = ms.ToArray().Select(s => (sbyte)s).ToArray(); SetSizeToolStrip(MPEGData[0].LoadedData.Length); MPEGData[0].box = leftPicture; } } catch (Exception ex) { MessageBox.Show(@"Error: Could not read file from disk. Original error: " + ex.Message); } DctImageProcessor processor = new DctImageProcessor(MPEGData[0]); await Task.Run(() => processor.UndoRippeg()); //now we just have to use the vector info to move blocks around. Bitmap newmap = new Bitmap(MPEGData[0].ImageSize, MPEGData[0].ImageSize); for (int i = 0; i < MPEGData[0].ImageSize; i++) { for (int j = 0; j < MPEGData[0].ImageSize; j++) { newmap.SetPixel(i, j, MPEGData[0].UncutBitmap.GetPixel(i, j)); } } using (Graphics g = Graphics.FromImage(newmap)) { Pen p2 = new Pen(Color.White, 1); Pen p = new Pen(Color.Black, 2); foreach (Tuple<Point, Point> mV in MPEGData[0].MVs) { for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { newmap.SetPixel( i + mV.Item2.X, j + mV.Item2.Y, MPEGData[0].UncutBitmap.GetPixel(i + mV.Item1.X, j + mV.Item1.Y) ); } } g.DrawLine(p, mV.Item1, mV.Item2); g.DrawLine(p2, mV.Item1, mV.Item2); } } rightPicture.Image = Padder.CropImage(newmap, new Rectangle(0, 0, MPEGData[0].RealWidth, MPEGData[0].RealHeight)); }
/// <summary> /// Method to decompress MPEG /// opens a file selector /// reads data /// initializes its data /// sends it off to DctImageProcessor::UntoRippeg function /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void decompressToolStripMenuItem2_Click(object sender, EventArgs e) { if (FOpen.ShowDialog() != DialogResult.OK) { return; } try { Stream raw = FOpen.OpenFile(); using (MemoryStream ms = new MemoryStream()) { raw.CopyTo(ms); MPEGData[0] = new DataManager(); leftPicture.Image = null; rightPicture.Image = null; MPEGData[0].LoadedData = ms.ToArray().Select(s => (sbyte)s).ToArray(); SetSizeToolStrip(MPEGData[0].LoadedData.Length); MPEGData[0].box = leftPicture; } } catch (Exception ex) { MessageBox.Show(@"Error: Could not read file from disk. Original error: " + ex.Message); } DctImageProcessor processor = new DctImageProcessor(MPEGData[0]); await Task.Run(() => processor.UndoRippeg()); //now we just have to use the vector info to move blocks around. Bitmap newmap = new Bitmap(MPEGData[0].ImageSize, MPEGData[0].ImageSize); for (int i = 0; i < MPEGData[0].ImageSize; i++) { for (int j = 0; j < MPEGData[0].ImageSize; j++) { newmap.SetPixel(i, j, MPEGData[0].UncutBitmap.GetPixel(i, j)); } } using (Graphics g = Graphics.FromImage(newmap)) { Pen p2 = new Pen(Color.White, 1); Pen p = new Pen(Color.Black, 2); foreach (Tuple <Point, Point> mV in MPEGData[0].MVs) { for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { newmap.SetPixel( i + mV.Item2.X, j + mV.Item2.Y, MPEGData[0].UncutBitmap.GetPixel(i + mV.Item1.X, j + mV.Item1.Y) ); } } g.DrawLine(p, mV.Item1, mV.Item2); g.DrawLine(p2, mV.Item1, mV.Item2); } } rightPicture.Image = Padder.CropImage(newmap, new Rectangle(0, 0, MPEGData[0].RealWidth, MPEGData[0].RealHeight)); }