/// <summary> /// Resets all values under advanced settings to their defaults, /// and asks the user whether to remove all stored bitmaps. /// </summary> public void ResetSettings() { SettingExtender.SaveDefaultSettings(); SettingManager.LoadSettings(); QuestionPopup.ActivatePopup(DeleteBitmapsPrompt, yes => { if (yes) { string path = Path.Combine(BitmapEncoding.PersistentPath, BitmapEncoding.BitmapFileName); if (File.Exists(path)) { File.Delete(path); } print("Deleted bitmaps"); TakePicture.Instance.storedBitmaps = BitmapEncoding.LoadBitmaps(); } }); }
private static byte[] FinalizeBitmap(IcoFrame source, BitmapEncoding encoding, Dialect dialect, ByteWriter writer, uint offsetToData, uint offsetToImageSize) { var offsetToEndOfData = writer.SeekOffset; if (dialect == Dialect.Ico) { var padding = writer.Data.Count % 4; var inferMaskFromAlpha = (source.Encoding.PixelFormat == BitmapEncoding.Pixel_argb32 && encoding != BitmapEncoding.Pixel_argb32); for (var y = source.CookedData.Height - 1; y >= 0; y--) { var bits = new BitWriter(writer); for (var x = 0; x < source.CookedData.Width; x++) { var mask = inferMaskFromAlpha ? (source.CookedData[x, y].A == 0) : source.Mask[x, y]; bits.AddBit1((byte)(mask ? 1 : 0)); } while ((writer.Data.Count % 4) != padding) { writer.AddUint8(0); } } } if (dialect != Dialect.Ico) { writer.SeekOffset = 2; writer.AddUint32((uint)writer.Data.Count); writer.SeekOffset = 10; writer.AddUint32(offsetToData); } writer.SeekOffset = (int)offsetToImageSize; writer.AddUint32((uint)(offsetToEndOfData - offsetToData)); // biSizeImage return(writer.Data.ToArray()); }
public static void Save(this BitmapSource source, Stream stream, BitmapEncoding enc, BitmapMetadata data) { BitmapEncoder encorder = null; switch (enc) { case BitmapEncoding.Bmp: encorder = new BmpBitmapEncoder(); break; case BitmapEncoding.Png: encorder = new PngBitmapEncoder(); break; case BitmapEncoding.Jpg: encorder = new JpegBitmapEncoder(); break; case BitmapEncoding.Tiff: encorder = new TiffBitmapEncoder(); break; case BitmapEncoding.Gif: encorder = new GifBitmapEncoder(); break; case BitmapEncoding.Wmp: encorder = new WmpBitmapEncoder(); break; case BitmapEncoding.Icon: throw new NotSupportedException("The icon format can only load!"); default: throw new NotImplementedException(); } encorder.Frames.Add(BitmapFrame.Create(source)); if (data != null) { encorder.Metadata = data; } encorder.Save(stream); }
private static void EncodeBitmapHeader(IcoFrame source, Dialect dialect, BitmapEncoding encoding, Rgba32[] colorTable, ByteWriter writer, out uint offsetToImageSize) { if (dialect != Dialect.Ico) { writer.AddUint16(FileFormatConstants._bitmapFileMagic); writer.AddUint32(0); // Size will be filled in later writer.AddUint32(0); // Reserved writer.AddUint32(0); // Offset will be filled in later } writer.AddUint32(FileFormatConstants._bitmapInfoHeaderSize); writer.AddUint32((uint)source.CookedData.Width); writer.AddUint32((uint)source.CookedData.Height * ((dialect == Dialect.Ico) ? 2u : 1u)); writer.AddUint16(1); // biPlanes writer.AddUint16((ushort)BmpUtil.GetBitDepthForPixelFormat(encoding)); // biBitCount writer.AddUint32(FileFormatConstants.BI_RGB); // biCompression offsetToImageSize = (uint)writer.SeekOffset; writer.AddUint32(0); // biSizeImage writer.AddUint32((dialect == Dialect.Ico) ? 0u : FileFormatConstants._72dpiInPixelsPerMeter); // biXPelsPerMeter writer.AddUint32((dialect == Dialect.Ico) ? 0u : FileFormatConstants._72dpiInPixelsPerMeter); // biYPelsPerMeter writer.AddUint32((uint)(colorTable?.Length ?? 0)); // biClrUsed writer.AddUint32(0); // biClrImportant if (colorTable != null) { foreach (var color in colorTable) { writer.AddUint8(color.B); writer.AddUint8(color.G); writer.AddUint8(color.R); writer.AddUint8(0); } } if (dialect != Dialect.Ico) { while (writer.Data.Count % 4 != 0) { writer.AddUint8(0); } } }
private static string StringFromPixelFormat(BitmapEncoding pixelFormat) { switch (pixelFormat) { case BitmapEncoding.Pixel_indexed1: return("1-bit indexed"); case BitmapEncoding.Pixel_indexed2: return("2-bit indexed"); case BitmapEncoding.Pixel_indexed4: return("4-bit indexed"); case BitmapEncoding.Pixel_indexed8: return("8-bit indexed"); case BitmapEncoding.Pixel_rgb15: return("15-bit RGB"); case BitmapEncoding.Pixel_rgb24: return("24-bit RGB"); case BitmapEncoding.Pixel_0rgb32: return("32-bit 0RGB"); case BitmapEncoding.Pixel_argb32: return("32-bit ARGB"); default: return("[unknown]"); } }
/// <summary> /// Resets the global variables to their initial values and prepares another scan. /// </summary> /// <param name="saveBitmaps">Whether to save the scanned bitmaps or not.</param> public void Reset(bool saveBitmaps) { //saves the bitmaps if the user wants to and the scan was a nonempty, correct sudoku if (success && saveBitmaps && !allZero) { Status = "Saving Bitmaps"; BitmapEncoding.SaveBitmaps(storedBitmaps, MaxStoredBitmapsPerDigit); } else { storedBitmaps = BitmapEncoding.LoadBitmaps(); } texture.Play(); Status = "Ready to take picture"; taken = false; TakePictureNow = false; success = false; debugText.enabled = false; SudokuPanel.transform.parent.gameObject.SetActive(false); PicturePanel.SetActive(true); CameraUI.transform.parent.gameObject.SetActive(true); }
public static BitmapSource Load(this BitmapSource source, String fileName, BitmapEncoding enc) { BitmapMetadata tmp; return Load(source, fileName, enc, out tmp); }
public static BitmapSource Load(this BitmapSource source, String fileName, BitmapEncoding enc, out BitmapMetadata data) { return(Load(source, fileName, enc, BitmapCreateOptions.None, BitmapCacheOption.None, out data)); }
public static void SaveAsImage(this UIElement element, Stream stream, BitmapEncoding encoding, int width, int height) { SaveAsImage(element, stream, encoding, width, height, 96d, 96d); }
public static void SaveAsImage(this UIElement element, Stream stream, BitmapEncoding encoding, BitmapMetadata metadata, int width, int height, double dpiX, double dpiY) { SaveAsImage(element, stream, encoding, metadata, width, height, dpiX, dpiY, PixelFormats.Pbgra32); }
public static void Save(this BitmapSource source, String fileName, BitmapEncoding enc) { Save(source, fileName, enc, null); }
public static void Save(this BitmapSource source, Stream stream, BitmapEncoding enc) { Save(source, stream, enc, null); }
public static BitmapSource Load(this BitmapSource source, Uri uri, BitmapEncoding enc) { BitmapMetadata tmp; return Load(source, uri, enc, out tmp); }
private static BitmapSource Load(object obj, BitmapEncoding enc, BitmapCreateOptions create, BitmapCacheOption cache, out BitmapMetadata data) { BitmapDecoder dec = null; if (obj is Stream) { Stream stream = obj as Stream; switch (enc) { case BitmapEncoding.Bmp: dec = new BmpBitmapDecoder(stream, create, cache); break; case BitmapEncoding.Png: dec = new PngBitmapDecoder(stream, create, cache); break; case BitmapEncoding.Jpg: dec = new JpegBitmapDecoder(stream, create, cache); break; case BitmapEncoding.Tiff: dec = new TiffBitmapDecoder(stream, create, cache); break; case BitmapEncoding.Gif: dec = new GifBitmapDecoder(stream, create, cache); break; case BitmapEncoding.Wmp: dec = new WmpBitmapDecoder(stream, create, cache); break; case BitmapEncoding.Icon: dec = new IconBitmapDecoder(stream, create, cache); break; default: throw new NotImplementedException(); } } else if (obj is Uri) { Uri stream = obj as Uri; switch (enc) { case BitmapEncoding.Bmp: dec = new BmpBitmapDecoder(stream, create, cache); break; case BitmapEncoding.Png: dec = new PngBitmapDecoder(stream, create, cache); break; case BitmapEncoding.Jpg: dec = new JpegBitmapDecoder(stream, create, cache); break; case BitmapEncoding.Tiff: dec = new TiffBitmapDecoder(stream, create, cache); break; case BitmapEncoding.Gif: dec = new GifBitmapDecoder(stream, create, cache); break; case BitmapEncoding.Wmp: dec = new WmpBitmapDecoder(stream, create, cache); break; case BitmapEncoding.Icon: dec = new IconBitmapDecoder(stream, create, cache); break; default: throw new NotImplementedException(); } } else { throw new ArgumentException(); } data = dec.Metadata; return(dec.Frames[0]); }
public static BitmapSource Load(this BitmapSource source, Stream stream, BitmapEncoding enc, BitmapCreateOptions create, BitmapCacheOption cache, out BitmapMetadata data) { return(Load(stream, enc, create, cache, out data)); }
/// <summary> /// Initialization code for the major parts of the application. /// </summary> void Start() { Screen.fullScreen = false; //set up references debugText = DebugTextInstance.GetComponent <Text>(); debugText.enabled = true; Instance = this; Popup.Instance = infoPopup; QuestionPopup.Instance = questionPopup; BitmapEncoding.PersistentPath = Application.persistentDataPath; foreach (var v in WebCamTexture.devices) { print("\"" + v.name + "\"" + (v.isFrontFacing ? " (Front facing)" : "")); } print("Persistent: " + BitmapEncoding.PersistentPath); //load persistent data Status = "Loading Digit Bitmaps"; storedBitmaps = BitmapEncoding.LoadBitmaps(); Status = "Loading Settings"; SettingManager.LoadSettings(); //start camera Status = "Looking for cameras"; try { texture = new WebCamTexture(CameraName); texture.Play(); if (WebCamTexture.devices.Length == 0) { throw new System.Exception(NoCamerasMessage); } } catch (System.Exception e) { Popup.ActivatePopup("Could not start the camera:" + System.Environment.NewLine + e.Message); CameraUI.enabled = OverlayUI.enabled = false; } textureWidth = texture.width; textureHeight = texture.height; side = Mathf.Min(textureWidth, textureHeight) - 10; //create overlay, rotate and stretch images correctly Status = "Assigning images"; Texture2D overlay = CreateOverlay(textureWidth, textureHeight, side); OverlayUI.texture = overlay; CameraUI.texture = texture; CameraUI.GetComponent <AspectRatioFitter>().aspectRatio = textureWidth / (float)textureHeight; if ((texture.videoRotationAngle + 360) % 180 == 90) { int i = textureWidth; textureWidth = textureHeight; textureHeight = i; } CameraUI.transform.parent.localEulerAngles = new Vector3(0, 0, -texture.videoRotationAngle); SudokuPanel.GetComponent <SudokuCreator>().Init(); Status = "Ready to take picture"; debugText.enabled = false; }
public static BitmapSource Load(this BitmapSource source, Uri uri, BitmapEncoding enc) { BitmapMetadata tmp; return(Load(source, uri, enc, out tmp)); }
public static BitmapSource Load(this BitmapSource source, Uri uri, BitmapEncoding enc, out BitmapMetadata data) { return(Load(source, uri, enc, BitmapCreateOptions.None, BitmapCacheOption.None, out data)); }
public static BitmapSource Load(this BitmapSource source, String fileName, BitmapEncoding enc) { BitmapMetadata tmp; return(Load(source, fileName, enc, out tmp)); }
public static BitmapSource Load(this BitmapSource source, Uri uri, BitmapEncoding enc, BitmapCreateOptions create, BitmapCacheOption cache, out BitmapMetadata data) { return Load(uri, enc, create, cache, out data); }
private static byte[] EncodeIndexedBitmap(ParseContext context, BitmapEncoding encoding, Dialect dialect, IcoFrame source) { var numBits = BmpUtil.GetBitDepthForPixelFormat(encoding); var colorTable = BuildColorTable(1u << numBits, context, source); if (colorTable == null) { context.LastEncodeError = IcoErrorCode.TooManyColorsForBitDepth; return(null); } var writer = new ByteWriter(ByteOrder.LittleEndian); EncodeBitmapHeader(source, dialect, encoding, colorTable, writer, out var offsetToImageSize); var reverseTable = new Dictionary <Rgba32, int>(); for (var i = 0; i < colorTable.Length; i++) { if (!reverseTable.ContainsKey(colorTable[i])) { reverseTable.Add(colorTable[i], i); } } var offsetToData = (uint)writer.Data.Count; var padding = writer.Data.Count % 4; for (var y = source.CookedData.Height - 1; y >= 0; y--) { var bits = new BitWriter(writer); for (var x = 0; x < source.CookedData.Width; x++) { var color = source.CookedData[x, y]; if (source.Mask[x, y]) { switch (context.MaskedImagePixelEmitOptions) { case StrictnessPolicy.Compliant: color = new Rgba32(0, 0, 0, 255); break; case StrictnessPolicy.PreserveSource: // Pass through whatever the original pixel was. break; case StrictnessPolicy.Loose: color = colorTable.First(); break; } } color.A = 255; var index = reverseTable[color]; bits.AddBits((uint)numBits, (byte)index); } while ((writer.Data.Count % 4) != padding) { writer.AddUint8(0); } } return(FinalizeBitmap(source, encoding, dialect, writer, offsetToData, offsetToImageSize)); }
public static BitmapSource Load(this BitmapSource source, Uri uri, BitmapEncoding enc, out BitmapMetadata data) { return Load(source, uri, enc, BitmapCreateOptions.None, BitmapCacheOption.None, out data); }
private static byte[] EncodeRgbBitmap(IcoFrame source, ParseContext context, BitmapEncoding encoding, Dialect dialect) { var writer = new ByteWriter(ByteOrder.LittleEndian); EncodeBitmapHeader(source, dialect, encoding, null, writer, out var offsetToImageSize); var offsetToData = (uint)writer.Data.Count; var padding = writer.Data.Count % 4; for (var y = source.CookedData.Height - 1; y >= 0; y--) { var bits = new BitWriter(writer); for (var x = 0; x < source.CookedData.Width; x++) { var color = source.CookedData[x, y]; if (source.Mask[x, y]) { switch (context.MaskedImagePixelEmitOptions) { case StrictnessPolicy.Compliant: case StrictnessPolicy.Loose: color = new Rgba32(0, 0, 0, 0); break; case StrictnessPolicy.PreserveSource: // Pass through whatever the original pixel was. break; } } switch (encoding) { case BitmapEncoding.Pixel_rgb15: var value = X8To5(color.R) << 10 | X8To5(color.G) << 5 | X8To5(color.B); writer.AddUint16((ushort)value); break; case BitmapEncoding.Pixel_rgb24: writer.AddUint8(color.B); writer.AddUint8(color.G); writer.AddUint8(color.R); break; case BitmapEncoding.Pixel_0rgb32: writer.AddUint8(color.B); writer.AddUint8(color.G); writer.AddUint8(color.R); writer.AddUint8(0); break; case BitmapEncoding.Pixel_argb32: writer.AddUint8(color.B); writer.AddUint8(color.G); writer.AddUint8(color.R); writer.AddUint8(color.A); break; } } while ((writer.Data.Count % 4) != padding) { writer.AddUint8(0); } } return(FinalizeBitmap(source, encoding, dialect, writer, offsetToData, offsetToImageSize)); }
public static void Save(this BitmapSource source, Stream stream, BitmapEncoding enc, BitmapMetadata data) { BitmapEncoder encorder = null; switch (enc) { case BitmapEncoding.Bmp: encorder = new BmpBitmapEncoder(); break; case BitmapEncoding.Png: encorder = new PngBitmapEncoder(); break; case BitmapEncoding.Jpg: encorder = new JpegBitmapEncoder(); break; case BitmapEncoding.Tiff: encorder = new TiffBitmapEncoder(); break; case BitmapEncoding.Gif: encorder = new GifBitmapEncoder(); break; case BitmapEncoding.Wmp: encorder = new WmpBitmapEncoder(); break; case BitmapEncoding.Icon: throw new NotSupportedException("The icon format can only load!"); default: throw new NotImplementedException(); } encorder.Frames.Add(BitmapFrame.Create(source)); if (data != null) encorder.Metadata = data; encorder.Save(stream); }
public static void Save(this BitmapSource source, String fileName, BitmapEncoding enc, BitmapMetadata data) { using (FileStream stream = new FileStream(fileName, FileMode.Create)) { Save(source, stream, enc, data); } }
private static BitmapSource Load(object obj, BitmapEncoding enc, BitmapCreateOptions create, BitmapCacheOption cache, out BitmapMetadata data) { BitmapDecoder dec = null; if (obj is Stream) { Stream stream = obj as Stream; switch (enc) { case BitmapEncoding.Bmp: dec = new BmpBitmapDecoder(stream, create, cache); break; case BitmapEncoding.Png: dec = new PngBitmapDecoder(stream, create, cache); break; case BitmapEncoding.Jpg: dec = new JpegBitmapDecoder(stream, create, cache); break; case BitmapEncoding.Tiff: dec = new TiffBitmapDecoder(stream, create, cache); break; case BitmapEncoding.Gif: dec = new GifBitmapDecoder(stream, create, cache); break; case BitmapEncoding.Wmp: dec = new WmpBitmapDecoder(stream, create, cache); break; case BitmapEncoding.Icon: dec = new IconBitmapDecoder(stream, create, cache); break; default: throw new NotImplementedException(); } } else if (obj is Uri) { Uri stream = obj as Uri; switch (enc) { case BitmapEncoding.Bmp: dec = new BmpBitmapDecoder(stream, create, cache); break; case BitmapEncoding.Png: dec = new PngBitmapDecoder(stream, create, cache); break; case BitmapEncoding.Jpg: dec = new JpegBitmapDecoder(stream, create, cache); break; case BitmapEncoding.Tiff: dec = new TiffBitmapDecoder(stream, create, cache); break; case BitmapEncoding.Gif: dec = new GifBitmapDecoder(stream, create, cache); break; case BitmapEncoding.Wmp: dec = new WmpBitmapDecoder(stream, create, cache); break; case BitmapEncoding.Icon: dec = new IconBitmapDecoder(stream, create, cache); break; default: throw new NotImplementedException(); } } else throw new ArgumentException(); data = dec.Metadata; return dec.Frames[0]; }
public static BitmapSource Load(this BitmapSource source, String fileName, BitmapEncoding enc, BitmapCreateOptions create, BitmapCacheOption cache, out BitmapMetadata data) { using (FileStream stream = new FileStream(fileName, FileMode.Open)) { return Load(source, stream, enc, create, cache, out data); } }
public static void SaveAsImage(this UIElement element, Stream stream, BitmapEncoding encoding, int width, int height, double dpiX, double dpiY) { SaveAsImage(element, stream, encoding, null, width, height, dpiX, dpiY); }
public static BitmapSource Load(this BitmapSource source, String fileName, BitmapEncoding enc, out BitmapMetadata data) { return Load(source, fileName, enc, BitmapCreateOptions.None, BitmapCacheOption.None, out data); }
public static void SaveAsImage(this Canvas canvas, Stream stream, BitmapEncoding encoding) { canvas.SaveAsImage(stream, encoding, (int)canvas.Width, (int)canvas.Height); }
public static BitmapSource Load(this BitmapSource source, Stream stream, BitmapEncoding enc) { BitmapMetadata tmp; return(Load(source, stream, enc, out tmp)); }
public static void SaveAsImage(this Canvas canvas, Stream stream, BitmapEncoding encoding) { canvas.SaveAsImage(stream, encoding, (int) canvas.Width, (int) canvas.Height); }
public static BitmapSource Load(this BitmapSource source, Stream stream, BitmapEncoding enc) { BitmapMetadata tmp; return Load(source, stream, enc, out tmp); }