public static void ToggleColourMapForm() { if (_colourMapForm != null) { _colourMapForm.Close(); return; } _colourMapForm = new ColourMap(); Properties.Settings userSettings = new Properties.Settings(); Point formLocation = userSettings.ColourListFormLocation; if (formLocation.IsEmpty) { PositionColourMapForm(); } else { _colourMapForm.Location = formLocation; } _colourMapForm.FormClosed += ChildFormClosed; _colourMapForm.Show(_mainForm); }
/// <summary> /// /// </summary> /// <param name="e"></param> protected override void OnLoad(EventArgs e) { Loader.UpdateSupportedGames(); ColourMap.UpdateSupportedColorMaps(); string[] args = Environment.GetCommandLineArgs(); bool fullScreen = false; for (int i = 1; i < args.Length; ++i) { if (args[i] == "-f") { fullScreen = true; } if (args[i] == "-g") { if (i < args.Length - 1) { if (File.Exists(args[i + 1])) { if (Path.GetExtension(args[i + 1]).ToUpper().Contains("ZIP")) { StopEmulation(); OpenZipFile(args[i + 1]); StartEmulation(); } } } } } base.OnLoad(e); if (fullScreen) { ToggleFullscreen(); } }
/// <summary> /// Convert a <see cref="string"/> to an <see cref="Color"/>. /// </summary> /// <param name="toConvert">The <see cref="string"/> to convert</param> /// <returns>The converted <see cref="string"/></returns> /// <exception cref="ArgumentNullException">If <see cref="null"/> is passed</exception> public override Color Convert(string toConvert) { if (toConvert is null) { throw new ArgumentNullException(nameof(toConvert)); } return(ColourMap.GetColourFor(toConvert)); }
public void ColourConverter_ConvertSupportedColour_Succeeds() { Color colour = Color.Blue; IConverter <string, Color> converter = new ColourConverter(); string expectedCode = ColourMap.GetCodeFor(colour); string converted = converter.Convert(colour); Assert.AreEqual(expectedCode, converted); }
public void ColourConverter_ConvertSupportedCode_Succeeds() { IConverter <string, Color> converter = new ColourConverter(); foreach (string code in ColourMap.GetAllCodes()) { Color colour = converter.Convert(code); Assert.AreEqual(ColourMap.GetColourFor(code), colour); } }
public object ReduceColourDepth(object o, BackgroundWorker w, DoWorkEventArgs e) { Console.WriteLine("Worker thread: " + this + "," + TargetColours + "," + ColourMap + "," + ColourMap.Count); // This case we're removing colours one at a time, replacing them with closest colours if (TargetColours > 0) { Console.WriteLine("ReduceColourDepth: initial nColours = " + ColourMap.Count + ", Target: " + TargetColours); int toRemove = ColourMap.Count - TargetColours; for (int i = 0; i < toRemove; i++) { if (w.CancellationPending) { e.Cancel = true; return(this); } IColourInfo least = ColourMap.GetLeastCommonColourInfo(true); RemoveFromPalette(least); UpdateColourMapFromImage(); w.ReportProgress(i * 100 / toRemove); } Console.WriteLine("ReduceColourDepth: final number of colours = " + ColourMap.Count); } else // This case we have no idea how many colours, we just want to fit the colour map. { Bitmap orig = mOutput; Bitmap b = new Bitmap(orig.Width, orig.Height, PixelFormat.Format24bppRgb); Console.WriteLine("ReduceColourDepth: initial nColours = " + ColourMap.Count); int i = 0; for (int x = 0; x < b.Width; x++) { for (int y = 0; y < b.Height; y++) { if (w.CancellationPending) { e.Cancel = true; return(this); } Color c = orig.GetPixel(x, y); Color newC = ColourMap.GetNearestColour(c); b.SetPixel(x, y, newC); w.ReportProgress((i++) * 100 / (b.Width * b.Height)); } } mOutput = b; } return(this); }
/// <summary> /// Resets ColourInfo.Frequency fields, and removes colour not present in Colourmap. /// If Image has N pixels, and ColourMap has M colours, total time = 3M + Nlog(M) ~= N /// </summary> public void UpdateColourMapFromImage() { if (mOutput == null || ColourMap == null) { return; } UpdateColourMapFrequency(); IColourInfo[] temp = ColourMap.ToArray(); foreach (IColourInfo col in temp) { if (col.Frequency < 1 && !col.IsChecked) { ColourMap.RemoveColour(col.Colour); } } }
/// <summary>Sets this colour from the given hex string.</summary> public void SetHex(string hex) { int r; int g; int b; int a; ColourMap.GetHexColour(hex, out r, out g, out b, out a); Count = 4; this[0] = new DecimalUnit((float)r / 255f); this[1] = new DecimalUnit((float)g / 255f); this[2] = new DecimalUnit((float)b / 255f); this[3] = new DecimalUnit((float)a / 255f); }
/// <summary> /// Resets ColourInfo.Frequency fields to the number of times that colour appears in the image. /// If Image has N pixels, and ColourMap has M colours, total time = M + Nlog(M) ~= N /// </summary> public void UpdateColourMapFrequency() { if (mOutput == null || ColourMap == null) { return; } ColourMap.ClearFrequencies(); // M Bitmap b = mOutput; for (int x = 0; x < b.Width; x++) // this loop iterates N times { for (int y = 0; y < b.Height; y++) { Color c = b.GetPixel(x, y); ColourMap.Colours[c].Frequency++; // Dictionary access is log(M)? } } }
/// <summary> /// Attempts to extract a zip file /// </summary> /// <param name="fileName"></param> void OpenZipFile(string fileName) { List <KeyValuePair <string, int> > data; if (Loader.SupportedGames.TryGetValue(Path.GetFileName(fileName), out data)) { ColourMap.SetColorMap(fileName); Sound.SetActiveSample(fileName); try { StopEmulation(); using (var file = File.OpenRead(fileName)) using (var zip = new ZipArchive(file, ZipArchiveMode.Read)) { m_machine.Reset(0); foreach (var f in data) { ZipArchiveEntry entry = zip.Entries.FirstOrDefault(a => a.Name == f.Key); if (entry != null) { using (var stream = entry.Open()) { using (var memoryStream = new MemoryStream()) { stream.CopyTo(memoryStream); memoryStream.ToArray().CopyTo(m_machine.RAM, f.Value); } } } } } } catch (Exception) { MessageBox.Show("Error loading game"); } } else { MessageBox.Show("Unsupported game"); } }
protected void CreateMesh(IEnumerable <double> x, IEnumerable <double> y, IEnumerable <double> z, int xLength, int yLength) { lengthU = xLength; lengthV = yLength; bounds = new Cuboid(x.Min(), y.Min(), z.Min(), x.Max(), y.Max(), z.Max()); Cuboid modelBounds = new Cuboid(new System.Windows.Media.Media3D.Point3D(-10, -10, -10), new System.Windows.Media.Media3D.Point3D(10, 10, 10)); UpdateModelVertices(x, y, z, xLength, yLength); CreateVertsAndInds(); colourMap = new ColourMap(ColourMapType.HSV, 256); colourMapIndices = FalseColourImage.IEnumerableToIndexArray(z, xLength, yLength, 256); SetColorFromIndices(); colourMapUpdateTimer = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(0.2) }; colourMapUpdateTimer.Tick += new EventHandler(colourMapUpdateTimer_Tick); lights = new List <SharpDX.Direct3D9.Light>(); SharpDX.Direct3D9.Light light = new SharpDX.Direct3D9.Light() { Type = LightType.Directional }; light.Diffuse = new Color4(0.4f, 0.4f, 0.4f, 1.0f); light.Direction = new Vector3(0.3f, 0.3f, -0.7f); light.Specular = new Color4(0.05f, 0.05f, 0.05f, 1.0f); lights.Add(light); light = new SharpDX.Direct3D9.Light() { Type = LightType.Directional }; light.Diffuse = new Color4(0.4f, 0.4f, 0.4f, 1.0f); light.Direction = new Vector3(-0.3f, -0.3f, -0.7f); light.Specular = new Color4(0.05f, 0.05f, 0.05f, 1.0f); lights.Add(light); material = new SharpDX.Direct3D9.Material(); material.Specular = new Color4(0.0f, 0.0f, 0.0f, 1.0f); material.Diffuse = new Color4(0.0f, 0.0f, 0.0f, 1.0f); material.Ambient = new Color4(0.0f, 0.0f, 0.0f, 1.0f); material.Power = 10; }
protected void CreateMeshILArray(ILArray <double> x, ILArray <double> y, ILArray <double> z) { bounds = new Cuboid(x.MinValue, y.MinValue, z.MinValue, x.MaxValue, y.MaxValue, z.MaxValue); lengthU = x.Dimensions[0]; lengthV = x.Dimensions[1]; ILArray <double> xs, ys, zs; if (x.IsReference) { xs = x.Clone() as ILArray <double>; } else { xs = x; } if (y.IsReference) { ys = y.Clone() as ILArray <double>; } else { ys = y; } if (z.IsReference) { zs = z.Clone() as ILArray <double>; } else { zs = z; } //if (x.IsReference || y.IsReference || z.IsReference) throw new Exception("x, y and z must be solid arrays"); double[] xa = xs.InternalArray4Experts; double[] ya = ys.InternalArray4Experts; double[] za = zs.InternalArray4Experts; Cuboid modelBounds = new Cuboid(new System.Windows.Media.Media3D.Point3D(-10, -10, -10), new System.Windows.Media.Media3D.Point3D(10, 10, 10)); UpdateModelVertices(xa, ya, za, lengthU, lengthV); CreateVertsAndInds(); colourMap = new ColourMap(ColourMapType.Jet, 256); colourMapIndices = FalseColourImage.IEnumerableToIndexArray(za, lengthU, lengthV, 256); SetColorFromIndices(); }
public ObjectResult Get(string name) { Color colour; try { colour = ColourMap.GetColourByName(name); } catch (InvalidColourNameException invalidName) { return(BadRequest(invalidName.Message)); } try { return(Ok(ApplyAdapter(repository.GetByFavouriteColour(colour)))); } catch (Exception ex) { Logger.Log(ex); return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
public static void ChildFormClosed(object sender, FormClosedEventArgs e) { if (sender is ColourMap) { _colourMapForm = null; } else if (sender is MappingListForm) { _mapListForm = null; } else if (sender is HelpForm) { _helpForm = null; } else if (sender is ColourEditor) { ColourEditor ce = (ColourEditor)sender; if (editorForms.ContainsKey(ce.Effect)) { editorForms.Remove(ce.Effect); } } _mainForm.RegenerateMenuExternal(); }
public void RemoveFromPalette(Color colorToRemove) { ColourMap.RemoveColour(colorToRemove); ReplaceColour(colorToRemove, ColourMap.GetNearestColour(colorToRemove)); }
/// <summary> /// Convert an <see cref="Color"/> to a <see cref="string"/>. /// </summary> /// <param name="toConvert">The <see cref="Color"/> to convert</param> /// <returns>The converted <see cref="Color"/></returns> public override string Convert(Color toConvert) => ColourMap.GetCodeFor(toConvert);
protected void CreateMeshILArray(ILArray<double> x, ILArray<double> y, ILArray<double> z) { bounds = new Cuboid(x.MinValue, y.MinValue, z.MinValue, x.MaxValue, y.MaxValue, z.MaxValue); lengthU = x.Dimensions[0]; lengthV = x.Dimensions[1]; ILArray<double> xs, ys, zs; if (x.IsReference) xs = x.Clone() as ILArray<double>; else xs = x; if (y.IsReference) ys = y.Clone() as ILArray<double>; else ys = y; if (z.IsReference) zs = z.Clone() as ILArray<double>; else zs = z; //if (x.IsReference || y.IsReference || z.IsReference) throw new Exception("x, y and z must be solid arrays"); double[] xa = xs.InternalArray4Experts; double[] ya = ys.InternalArray4Experts; double[] za = zs.InternalArray4Experts; Cuboid modelBounds = new Cuboid(new System.Windows.Media.Media3D.Point3D(-10, -10, -10), new System.Windows.Media.Media3D.Point3D(10, 10, 10)); UpdateModelVertices(xa, ya, za, lengthU, lengthV); CreateVertsAndInds(); colourMap = new ColourMap(ColourMapType.Jet, 256); colourMapIndices = FalseColourImage.IEnumerableToIndexArray(za, lengthU, lengthV, 256); SetColorFromIndices(); }
protected void CreateMesh(IEnumerable<double> x, IEnumerable<double> y, IEnumerable<double> z, int xLength, int yLength) { lengthU = xLength; lengthV = yLength; bounds = new Cuboid(x.Min(), y.Min(), z.Min(), x.Max(), y.Max(), z.Max()); Cuboid modelBounds = new Cuboid(new System.Windows.Media.Media3D.Point3D(-10, -10, -10), new System.Windows.Media.Media3D.Point3D(10, 10, 10)); UpdateModelVertices(x, y, z, xLength, yLength); CreateVertsAndInds(); colourMap = new ColourMap(ColourMapType.HSV, 256); colourMapIndices = FalseColourImage.IEnumerableToIndexArray(z, xLength, yLength, 256); SetColorFromIndices(); colourMapUpdateTimer = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(0.2) }; colourMapUpdateTimer.Tick += new EventHandler(colourMapUpdateTimer_Tick); lights = new List<SharpDX.Direct3D9.Light>(); SharpDX.Direct3D9.Light light = new SharpDX.Direct3D9.Light() { Type = LightType.Directional }; light.Diffuse = new Color4(0.4f, 0.4f, 0.4f, 1.0f); light.Direction = new Vector3(0.3f, 0.3f, -0.7f); light.Specular = new Color4(0.05f, 0.05f, 0.05f, 1.0f); lights.Add(light); light = new SharpDX.Direct3D9.Light() { Type = LightType.Directional }; light.Diffuse = new Color4(0.4f, 0.4f, 0.4f, 1.0f); light.Direction = new Vector3(-0.3f, -0.3f, -0.7f); light.Specular = new Color4(0.05f, 0.05f, 0.05f, 1.0f); lights.Add(light); material = new SharpDX.Direct3D9.Material(); material.Specular = new Color4(0.0f, 0.0f, 0.0f, 1.0f); material.Diffuse = new Color4(0.0f, 0.0f, 0.0f, 1.0f); material.Ambient = new Color4(0.0f, 0.0f, 0.0f, 1.0f); material.Power = 10; }
private void SetupMaterial(ColourMap TypeMap, XbimGeometryHandle xgh, XbimModel model, Int32 ModelID) { if (xMaterials.ContainsKey(xgh.SurfaceStyle.IfcSurfaceStyleLabel.ToString()) && xLayers[xgh.SurfaceStyle.IfcSurfaceStyleLabel.ToString()].Count > MAX_LAYER_SIZE) { String LayerName = xgh.SurfaceStyle.IfcSurfaceStyleLabel.ToString(); while (xLayers.ContainsKey(LayerName)) { LayerName += "_"; } xLayers[LayerName] = xLayers[xgh.SurfaceStyle.IfcSurfaceStyleLabel.ToString()]; xMaterials[LayerName] = xMaterials[xgh.SurfaceStyle.IfcSurfaceStyleLabel.ToString()]; SetupNewLayer(xgh.SurfaceStyle, model); } else { if (xgh.SurfaceStyleLabel != 0 && !xMaterials.ContainsKey(xgh.SurfaceStyle.IfcSurfaceStyleLabel.ToString())) { SetupNewLayer(xgh.SurfaceStyle, model); } } }