public RGBVideo(RGBVideo rGBVideo) { Source = rGBVideo.Source; Format = rGBVideo.Format; Frame = rGBVideo.Frame; Width = rGBVideo.Width; Height = rGBVideo.Height; }
private void MenuOpen_Click(object sender, RoutedEventArgs e) { if (fileOpened) { ResetWindow(); } OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "YUV files (*.yuv)|*.yuv"; openFileDialog.Title = "Select a valid YUV file..."; openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); byte[] fileData; if (openFileDialog.ShowDialog() == true) { PropertiesPage propertySet = new PropertiesPage(openFileDialog.FileName); if (!propertySet.ShowDialog() ?? false) { return; } fileOpened = true; openedVideo = new RGBVideo(propertySet.OpenedVideo); lblNoFileSelectedError.Visibility = Visibility.Hidden; mainGrid.Background.Opacity = 0.4; grdFileInfo.Visibility = Visibility.Visible; txtFileName.Content = openFileDialog.FileName; txtHeight.Content = openedVideo.Height; txtWidth.Content = openedVideo.Width; txtCreationTime.Content = File.GetCreationTime(openFileDialog.FileName); txtAttributes.Content = File.GetAttributes(openFileDialog.FileName).ToString(); } else { return; } try { fileData = File.ReadAllBytes(openFileDialog.FileName); } catch (Exception ex) { MessageBox.Show("File cannot be read!\n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } int width = openedVideo.Width, height = openedVideo.Height; openedVideo = RGBConvert.ConvertRGB(fileData, width, height, openedVideo.Format); txtFrame.Content = openedVideo.Frame; UpdateImage(); }
private void ResetWindow() { lblNoFileSelectedError.Visibility = Visibility.Visible; mainGrid.Background.Opacity = 0.7; grdFileInfo.Visibility = Visibility.Hidden; openedVideo = null; frameShowing = 0; timer = null; txtAttributes.Content = String.Empty; txtCreationTime.Content = String.Empty; txtCurrentFrame.Content = "1"; txtFileName.Content = String.Empty; txtFrame.Content = String.Empty; txtHeight.Content = String.Empty; txtWidth.Content = String.Empty; fileOpened = false; }
private static RGBVideo ConvertYUV422(byte[] data, int width, int height) { int pixelCount = width * height, frame = data.Length / (pixelCount * 2), yCount = pixelCount, uCount = yCount / 2, vCount = uCount, byteCount = pixelCount * 2; RGBVideo video = new RGBVideo(YUV.YUVFormat.YUV422, frame, width, height); byte[] rgbData = new byte[yCount * 3]; for (int f = 0, j = 0; f < frame; f++, j = 0) { //Unreadable, but compact :) byte[] y = new byte[yCount], u = new byte[uCount], v = new byte[vCount]; for (int p = 0, i = 0; p < yCount; p++) { y[i++] = data[f * byteCount + j++]; } for (int p = 0, i = 0; p < uCount; p++) { u[i++] = data[f * byteCount + j++]; } for (int p = 0, i = 0; p < vCount; p++) { v[i++] = data[f * byteCount + j++]; } for (int d = 0; d < yCount * 3; d++) { rgbData[d] = y[d / 3]; } Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb); BitmapData bitmapData = bitmap.LockBits( new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, bitmap.PixelFormat); Marshal.Copy(rgbData, 0, bitmapData.Scan0, rgbData.Length); bitmap.UnlockBits(bitmapData); video.Source[f] = bitmap; } return(video); }
private void BtnApply_Click(object sender, RoutedEventArgs e) { YUV.YUVFormat format = (cbYUV444.IsSelected) ? YUV.YUVFormat.YUV444 : (cbYUV422.IsSelected) ? YUV.YUVFormat.YUV422 : YUV.YUVFormat.YUV420; int width = 0, height = 0; if (!Int32.TryParse(txtWidth.Text, out width)) { MessageBox.Show("There was an error while parsing width value.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (!Int32.TryParse(txtHeight.Text, out height)) { MessageBox.Show("There was an error while parsing height value.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } OpenedVideo = new RGBVideo(format, width, height); DialogResult = true; }