public double TotalPixels(JPEG jpeg) { jpeg.Bytes(); //gets the bytes into memory BitmapWrapper wrapper = new BitmapWrapper(jpeg.ReturnBitmap()); return(wrapper.bitmap.Height * wrapper.bitmap.Width); }
public static Type GetImageFileTypeFromSignature(byte[] buffer) { if (TEXN.IsValid(buffer)) { return(typeof(TEXN)); } if (PVRT.IsValid(buffer)) { return(typeof(PVRT)); } if (DDS.IsValid(buffer)) { return(typeof(DDS)); } if (BMP.IsValid(buffer)) { return(typeof(BMP)); } if (JPEG.IsValid(buffer)) { return(typeof(JPEG)); } if (PNG.IsValid(buffer)) { return(typeof(PNG)); } return(null); }
/// <summary> /// Runs a number of single extractions from the IP camera /// Times the change to Bitmap and count of the pixels for /// These images /// </summary> public void RunBenchmarking(string logfile) { //extract the images List <String> saveLocations = new List <string>(); string url = "http://192.168.0.2/axis-cgi/mjpg/video.cgi?resolution="; List <String[]> resolutions = ReturnResolutions(); for (int i = 0; i < resolutions.Count; i++) { string actualurl = url + resolutions[i][0] + "x" + resolutions[i][1]; //set up the extractor ImageExtractor imageExtractor = new ImageExtractor(actualurl, "root", "root"); //set up the save file object ImageSaver imageSaver = new ImageSaver(0, 1); saveLocations.Add(imageSaver.CaptureDirectory); //create the validator ImageValidator imageValidator = new ImageValidator(); imageValidator.ListenForImages(imageExtractor); imageValidator.imageValidated += new ImageValidator.ImageValidatedEvent(imageSaver.ImageCreatedAsync);//subscribe to events from the validator imageExtractor.Run(true); System.Threading.Thread.Sleep(5000); //wait 5 seconds to let the async requests complete } //do the analysis for (int i = 0; i < saveLocations.Count; i++) { string header = resolutions[i][0] + "x" + resolutions[i][1]; Console.WriteLine(Environment.NewLine + resolutions[i][0] + "x" + resolutions[i][1]); JPEG jpeg = new JPEG(saveLocations[i] + @"\1\test_0.jpg"); string msToBitmap = MsToBitmap(jpeg).ToString(); string msToBitmapAndSumPixels = MsToBitmapAndSumPixels(jpeg).ToString(); string totalPixels = TotalPixels(jpeg).ToString(); Console.WriteLine(msToBitmap); Console.WriteLine(msToBitmapAndSumPixels); Console.WriteLine(totalPixels); using (System.IO.StreamWriter file = new System.IO.StreamWriter(logfile, true)) { file.WriteLine(header); file.WriteLine(msToBitmap); file.WriteLine(msToBitmapAndSumPixels); file.WriteLine(totalPixels); file.WriteLine("------------------------------"); } } }//RunBenchmarking
/// <summary> /// Returns the millseconds to turn a in memory JPEG into a Bitmap /// </summary> /// <returns></returns> public double MsToBitmap(JPEG jpeg) { jpeg.Bytes(); //gets the bytes into memory Stopwatch sw = new Stopwatch(); sw.Start(); BitmapWrapper wrapper = new BitmapWrapper(jpeg.ReturnBitmap()); sw.Stop(); return(sw.Elapsed.TotalMilliseconds); }
static void Main(string[] args) { Excel excel = new Excel(null); Number number = new Number(excel); JPEG jpeg = new JPEG(number); QuickBook quickBook = new QuickBook(jpeg); AccountingTool acc = new AccountingTool(quickBook); acc.startFormatting(); Console.ReadLine(); }
void PostJpeg() { try { JPEG jpeg = null; if (jpegQ.Count > 0) { jpeg = jpegQ.Dequeue(); } else { return; } if (jpeg == null) { return; } Image image = Bitmap.FromStream(new MemoryStream(jpeg.jpeg)); if (image == null) { return; } int index = 0; try { index = (int)m_ChannelIndexTable[jpeg.channel]; } catch { } m_JpegPlayControl[index].ReceivedImageNow(); m_UneditedImages[index].Bmp = (Bitmap)image; m_VideDisplayPBs[index].Image = image; PutChannelText(m_VideDisplayPBs[index], jpeg.channel); PutPlateNumber(m_VideDisplayPBs[index], jpeg.plateReading, index); PutTimeStamp(m_VideDisplayPBs[index], jpeg.timeStamp); DrawMinMaxBoxes(m_VideDisplayPBs[index]); m_VideDisplayPBs[index].Invalidate(); jpeg = null;// free it } catch (Exception ex) { MessageBox.Show(ex.Message); } }
static void Main(string[] args) { Console.OutputEncoding = Encoding.Default; Console.WriteLine($"\u001b[38;2;128;20;196m\u2580\u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588\u2589\u258A\u258B\u258C\u258D\u258E\u258F\u2590\u2591\u2592\u2593\u2594\u2595\u2596\u2597\u2598\u2599\u259A\u259B\u259C\u259D\u259E\u259F\u2615\u26Be\u001b[38;2;128;128;128m"); Console.WriteLine($"\u001b[38;2;128;20;196m\u2580\u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588\u2589\u258A\u258B\u258C\u258D\u258E\u258F\u2590\u2591\u2592\u2593\u2594\u2595\u2596\u2597\u2598\u2599\u259A\u259B\u259C\u259D\u259E\u259F\u2615\u26Be\u001b[38;2;128;128;128m"); Console.WriteLine($"\u001b[38;2;128;20;196m\u2580\u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588\u2589\u258A\u258B\u258C\u258D\u258E\u258F\u2590\u2591\u2592\u2593\u2594\u2595\u2596\u2597\u2598\u2599\u259A\u259B\u259C\u259D\u259E\u259F\u2615\u26Be\u001b[38;2;170;170;170m"); Console.WriteLine("▀▁▂▃▄▅▆▇█▉▊▋▌▍▎▏▐░▒▓▔▕▖▗▘▙▚▛▜▝▞▟☕⚾"); MP3 mp3 = new MP3(); //mp3.Decode($@"C:\Users\johnr\Downloads\MBR\warez.zip\Mp3\Contra.mp3"); mp3.Decode($@"C:\Users\johnr\Documents\outputWave1-ABR-192.mp3"); return; DirectoryInfo directoryInfo = new DirectoryInfo($@"c:\users\johnr\pictures"); //foreach (var file in directoryInfo.GetFiles()) //{ // if (new string[] { ".jpg", ".jpeg", ".jfif" }.Contains(file.Extension.ToLower())) // { // Console.WriteLine($"File: {file.FullName}"); // JPEG jpg = new JPEG(file.FullName); // } //} //JPEG jpeg = new JPEG($@"c:\users\johnr\pictures\Calculator1.jpg"); JPEG jpeg = new JPEG($@"c:\users\johnr\pictures\68518b2cd5485d576cc34355ffb0027d.jpg"); return; GIF gif = new GIF($@"c:\users\johnr\pictures\Calculator1.gif"); LZW lzw = new LZW(); BMP bmp = new BMP($@"c:\users\johnr\pictures\3Sphere_2c.bmp"); directoryInfo = new DirectoryInfo($@"c:\users\johnr\pictures"); foreach (var file in directoryInfo.GetFiles()) { if (file.Extension.ToLower() == ".png") { Console.WriteLine($"File: {file.FullName}"); PNG png = new PNG(file.FullName); var header = png.DataChunks.Where(x => x.ChunkType.ToLower() == "ihdr").FirstOrDefault(); var properties = (header.DataChunkRepresentation as PNG.DataChunk.HeaderChunkRepresentation).ToProperties(header.Data); //if ((byte)properties["ColorType"].Value == 6) // Console.ReadLine(); } } //Console.WriteLine("Enter PNG Filename:"); //string path = Console.ReadLine(); //PNG png = new PNG(path); }
public void loadFromStream(Stream stream) { size = stream.Length; if (JPEG.test(stream)) { _img = new JPEG(stream); type = JPEG.MIME; ((JPEG)_img).extractHeaders(); // preserve headers for later meta = ((JPEG)_img).metaInfo(); // save thumb data as Blob object thumbData; if (meta.ContainsKey("thumb") && ((Dictionary <string, object>)meta["thumb"]).TryGetValue("data", out thumbData)) { Blob blob = new Blob(new List <object> { (byte[])thumbData }, new Dictionary <string, string> { { "type", "image/jpeg" } }); Moxie.compFactory.add(blob.uid, blob); ((Dictionary <string, object>)meta["thumb"])["data"] = blob.ToObject(); } } else if (PNG.test(stream)) { _img = new PNG(stream); type = PNG.MIME; } else { Error(this, new ErrorEventArgs(ImageError.WRONG_FORMAT)); return; } Dictionary <string, int> info = _img.info(); if (info != null) { width = info["width"]; height = info["height"]; } BitmapImage bitmapImage = new BitmapImage(); bitmapImage.SetSource(stream); _bm = new WriteableBitmap(bitmapImage); Load(this, null); }
void OnNewJpeg(byte[] jpegData, string channel, string timeStamp, string plateReading) { JPEG jpeg = new JPEG(); jpeg.timeStamp = timeStamp; jpeg.jpeg = jpegData; jpeg.plateReading = plateReading; jpeg.channel = channel; jpegQ.Enqueue(jpeg); this.BeginInvoke((MethodInvoker) delegate { this.PostJpeg(); }); }
public void loadFromStream(Stream stream) { size = stream.Length; if (JPEG.test(stream)) { _img = new JPEG(stream); type = JPEG.MIME; ((JPEG)_img).extractHeaders(); // preserve headers for later meta = ((JPEG)_img).metaInfo(); } else if (PNG.test(stream)) { _img = new PNG(stream); type = PNG.MIME; } else { throw new ImageError(ImageError.WRONG_FORMAT); } Dictionary <string, int> info = _img.info(); if (info != null) { width = info["width"]; height = info["height"]; } BitmapImage bitmapImage = new BitmapImage(); bitmapImage.SetSource(stream); _bm = new WriteableBitmap(bitmapImage); Load(this, null); }
void PostJpeg( ) { try { JPEG jpeg = null; if (jpegQ.Count > 0) { jpeg = jpegQ.Dequeue(); } else { return; } if (jpeg == null) { return; } Image image = Bitmap.FromStream(new MemoryStream(jpeg.jpeg)); if (image == null) { return; } int index = 0; try { index = comboBoxSourceChannelList.Items.IndexOf(jpeg.channel); } catch { } switch (index) { case 0: pictureBoxVideoDisplay0.Image = image; pictureBoxVideoDisplay0.Invalidate(); labelDisplayFrameTime0.Text = (string)jpeg.timeStamp.Clone(); if (jpeg.plateReading.Length > 2) { labelPlateReadings0.Text = jpeg.plateReading; } break; case 1: pictureBoxVideoDisplay1.Image = image; pictureBoxVideoDisplay1.Invalidate(); labelDisplayFrameTime1.Text = (string)jpeg.timeStamp.Clone(); if (jpeg.plateReading.Length > 2) { labelPlateReadings1.Text = jpeg.plateReading; } break; case 2: pictureBoxVideoDisplay2.Image = image; pictureBoxVideoDisplay2.Invalidate(); labelDisplayFrameTime2.Text = (string)jpeg.timeStamp.Clone(); if (jpeg.plateReading.Length > 2) { labelPlateReadings2.Text = jpeg.plateReading; } break; case 3: pictureBoxVideoDisplay3.Image = image; pictureBoxVideoDisplay3.Invalidate(); labelDisplayFrameTime3.Text = (string)jpeg.timeStamp.Clone(); if (jpeg.plateReading.Length > 2) { labelPlateReadings3.Text = jpeg.plateReading; } break; } jpeg = null;// free it } catch { } }
private void button_Convert_Click(object sender, EventArgs e) { string outputFolder = textBox_OutputFolder.Text; if (String.IsNullOrEmpty(outputFolder)) { return; } if (!Directory.Exists(outputFolder)) { Directory.CreateDirectory(outputFolder); } List <BaseImage> images = new List <BaseImage>(); if (checkBox_ConvertSelected.Checked) { foreach (BaseImage img in listBox_Images.SelectedItems) { images.Add(img); } } else { foreach (BaseImage img in listBox_Images.Items) { images.Add(img); } } if ((Type)comboBox_ImageFormat.SelectedItem == typeof(PVRT)) { PVRTSettings settings = pvrtControl.Settings; foreach (BaseImage image in images) { PVRT pvrt = new PVRT(image); pvrt.PixelFormat = settings.PixelFormat; pvrt.DataFormat = settings.DataFormat; if (settings.CreateTEXN) { string srcFilename = Path.GetFileName(image.FilePath); string[] splitted = srcFilename.Split('.'); string texIDString = splitted[0]; UInt64 texID = Convert.ToUInt64(texIDString, 16); TEXN texn = new TEXN(); texn.TextureID.Data = texID; string filename = String.Format("{0}.{1}.TEXN", Helper.ByteArrayToString(BitConverter.GetBytes(texn.TextureID.Data)), texn.TextureID.Name.Replace("\0", "_")); string filepath = outputFolder + "\\" + filename; using (FileStream fileStream = new FileStream(filepath, FileMode.Create)) { using (BinaryWriter writer = new BinaryWriter(fileStream)) { long offset = fileStream.Position; texn.WriteHeader(writer); if (settings.InsertDDS && typeof(DDS).IsAssignableFrom(image.GetType())) { pvrt.WriteDDSRaw(writer, (DDS)image); } else { pvrt.Write(writer); } texn.EntrySize = (uint)(fileStream.Position - offset); fileStream.Seek(offset, SeekOrigin.Begin); texn.WriteHeader(writer); } } } else { string filepath = outputFolder + "\\" + Path.ChangeExtension(Path.GetFileName(image.FilePath), ".PVR"); using (FileStream fileStream = new FileStream(filepath, FileMode.Create)) { using (BinaryWriter writer = new BinaryWriter(fileStream)) { if (settings.InsertDDS && typeof(DDS).IsAssignableFrom(image.GetType())) { pvrt.WriteDDSRaw(writer, (DDS)image); } else { pvrt.Write(writer); } } } } } } else if ((Type)comboBox_ImageFormat.SelectedItem == typeof(DDS)) { DDSSettings settings = ddsControl.Settings; foreach (BaseImage image in images) { string filepath = outputFolder + "\\" + Path.ChangeExtension(Path.GetFileName(image.FilePath), ".dds"); DDS dds = new DDS(image); dds.AlphaSettings = settings.AlphaSettings; dds.MipHandling = settings.MipHandling; dds.FormatDetails = new DDSFormats.DDSFormatDetails(settings.DDSFormat, settings.DXGIFormat); dds.Write(filepath); } } else if ((Type)comboBox_ImageFormat.SelectedItem == typeof(PNG)) { foreach (BaseImage image in images) { string filepath = outputFolder + "\\" + Path.ChangeExtension(Path.GetFileName(image.FilePath), ".png"); PNG png = new PNG(image); png.Write(filepath); } } else if ((Type)comboBox_ImageFormat.SelectedItem == typeof(BMP)) { foreach (BaseImage image in images) { string filepath = outputFolder + "\\" + Path.ChangeExtension(Path.GetFileName(image.FilePath), ".bmp"); BMP bmp = new BMP(image); bmp.Write(filepath); } } else if ((Type)comboBox_ImageFormat.SelectedItem == typeof(JPEG)) { foreach (BaseImage image in images) { string filepath = outputFolder + "\\" + Path.ChangeExtension(Path.GetFileName(image.FilePath), ".jpg"); JPEG jpg = new JPEG(image); jpg.Write(filepath); } } }
void OnNewJpeg(byte[] jpegData, string channel, string timeStamp, string plateReading) { JPEG jpeg = new JPEG(); jpeg.timeStamp = timeStamp; jpeg.jpeg = jpegData; jpeg.plateReading = plateReading; jpeg.channel = channel; jpegQ.Enqueue(jpeg); this.BeginInvoke((MethodInvoker)delegate { this.PostJpeg(); }); }