/// <summary> /// Checks if the transition has an effect. /// </summary> protected virtual bool TransitionHasEffect(ISystemContext context, uint transitionId) { uint[,] transitionMappings = TransitionMappings; if (transitionMappings == null) { return(false); } int length = transitionMappings.GetLength(0); for (int ii = 0; ii < length; ii++) { if (transitionMappings[ii, 0] == transitionId) { return(transitionMappings[ii, 3] != 0); } } return(false); }
static bool bisearch(uint rune, uint[,] table, out int width) { width = 0; var length = table.GetLength(0); if (length == 0 || rune < table[0, 0] || rune > table[length - 1, 1]) { return(false); } for (int i = 0; i < length; i++) { if (rune >= table[i, 0] && rune <= table[i, 1]) { width = (int)table[i, 2]; return(true); } } return(false); }
public ThemeTestModule() : base("Theme") { var align = new Alignment(0.0f, 0.0f, 1.0f, 1.0f); var theme_widget = new ThemeTestWidget(); align.Add(theme_widget); Add(align); ShowAll(); int state = 0; uint[,] borders = { { 0, 0, 0, 0 }, { 10, 0, 0, 0 }, { 0, 10, 0, 0 }, { 0, 0, 10, 0 }, { 0, 0, 0, 10 }, { 10, 10, 0, 0 }, { 10, 10, 10, 0 }, { 10, 10, 10, 10 }, { 10, 0, 0, 10 }, { 0, 10, 10, 0 } }; GLib.Timeout.Add(2000, delegate { Console.WriteLine(state); align.TopPadding = borders[state, 0]; align.RightPadding = borders[state, 1]; align.BottomPadding = borders[state, 2]; align.LeftPadding = borders[state, 3]; if (++state % borders.GetLength(0) == 0) { state = 0; } return(true); }); }
/// <summary> /// Number of column positions of a wide-character code. This is used to measure runes as displayed by text-based terminals. /// </summary> /// <returns>The width in columns, 0 if the argument is the null character, -1 if the value is not printable, otherwise the number of columsn that the rune occupies.</returns> /// <param name="r">The red component.</param> public static int ColumnWidth(Rune rune) { uint irune = (uint)rune; if (irune < 32) { return(0); } if (irune < 127) { return(1); } if (irune >= 0x7f && irune <= 0xa0) { return(0); } /* binary search in table of non-spacing characters */ if (bisearch(irune, combining, combining.GetLength(0) - 1) != 0) { return(0); } /* if we arrive here, ucs is not a combining or C0/C1 control character */ return(1 + ((irune >= 0x1100 && (irune <= 0x115f || /* Hangul Jamo init. consonants */ irune == 0x2329 || irune == 0x232a || (irune >= 0x2e80 && irune <= 0xa4cf && irune != 0x303f) || /* CJK ... Yi */ (irune >= 0xac00 && irune <= 0xd7a3) || /* Hangul Syllables */ (irune >= 0xf900 && irune <= 0xfaff) || /* CJK Compatibility Ideographs */ (irune >= 0xfe10 && irune <= 0xfe19) || /* Vertical forms */ (irune >= 0xfe30 && irune <= 0xfe6f) || /* CJK Compatibility Forms */ (irune >= 0xff00 && irune <= 0xff60) || /* Fullwidth Forms */ (irune >= 0xffe0 && irune <= 0xffe6) || (irune >= 0x20000 && irune <= 0x2fffd) || (irune >= 0x30000 && irune <= 0x3fffd))) ? 1 : 0)); }
internal static PSFFit GetPSFFitForPeakPixel( uint[,] data, PotentialStarStruct starToTest, float aboveNoiseLevelRequired, double minFWHM, double maxFWHM) { int STAR_MATRIX_FIT = TangraConfig.Settings.Special.StarFinderFitArea; double MIN_DISTANCE_OF_PEAK_PIXEL_FROM_CENTER = TangraConfig.Settings.Special.StarFinderMinDistanceOfPeakPixelFromCenter; PSFFit fit = new PSFFit(starToTest.X, starToTest.Y); int fitMatrix = (int)Math.Min(data.GetLength(0), STAR_MATRIX_FIT + 2); // Get a matrix with 1 pixel larger each way and set the border pixels to zero fit.Fit(data, fitMatrix, starToTest.X, starToTest.Y, true); if (fit.IsSolved) { double distanceFromCenter = ImagePixel.ComputeDistance(fit.X0_Matrix, fitMatrix / 2, fit.Y0_Matrix, fitMatrix / 2); if (fit.Certainty > 0 && fit.FWHM >= minFWHM && fit.FWHM <= maxFWHM && distanceFromCenter < MIN_DISTANCE_OF_PEAK_PIXEL_FROM_CENTER && fit.IMax > aboveNoiseLevelRequired) { //not good for lost tracking allow higher FWHM // This object passes all tests to be furhter considered as a star return(fit); } } return(null); }
public void Clear(uint color = 0x0) { if (color == 0x0) { Colors = new uint[Width, Height]; } else { for (int x = 0; x < Colors.GetLength(0); x++) { for (int y = 0; y < Colors.GetLength(1); y++) { Colors[x, y] = color; } } } Room.BroadcastToUsers(Util.BuildPacket(Network.Opcodes.SpanClearBoard, new object[] { color })); }
public void CreateVaultInRoom(Vault v, Room r) { uint[,] tileInts = v.tileInts; uint[,] spikeInts = v.spikeInts; for (int x = 0; x < tileInts.GetLength(0); x++) { for (int y = 0; y < tileInts.GetLength(1); y++) { uint rawTile = tileInts [x, y]; int tile = (int)(rawTile & ~(0xE0000000)); // ignore flipping and rotating // Tiled add's a 1 to the tile so that 0 can be blank tile--; Coordinates newCoords = new Coordinates(x, tileInts.GetLength(0) - 1 - y); newCoords.x += r.pos.x; newCoords.y += r.pos.y; newCoords.x -= r.size.x / 2; // newCoords.y -= r.size.y; newCoords.y -= r.size.y / 2; if (tile != -1) { map.SetTile(newCoords.x, newCoords.y, wallLayer, tile); } } } for (int x = 0; x < spikeInts.GetLength(0); x++) { for (int y = 0; y < spikeInts.GetLength(1); y++) { uint rawTile = spikeInts [x, y]; int tile = (int)(rawTile & ~(0xE0000000)); // ignore flipping and rotating // Tiled add's a 1 to the tile so that 0 can be blank tile--; Coordinates newCoords = new Coordinates(x, tileInts.GetLength(0) - 1 - y); newCoords.x += r.pos.x; newCoords.y += r.pos.y; newCoords.x -= r.size.x / 2; // newCoords.y -= r.size.y; newCoords.y -= r.size.y / 2; if (tile == spikeTile) { map.SetTile(newCoords.x, newCoords.y, (int)TileLayer.Spike, tile); } // Set tile flags bool flipHorizontal = (rawTile & 0x80000000) != 0; bool flipVertical = (rawTile & 0x40000000) != 0; bool flipDiagonal = (rawTile & 0x20000000) != 0; tk2dTileFlags tileFlags = 0; if (flipDiagonal) { tileFlags |= (tk2dTileFlags.Rot90 | tk2dTileFlags.FlipX); } if (flipHorizontal) { tileFlags ^= tk2dTileFlags.FlipX; } if (flipVertical) { tileFlags ^= tk2dTileFlags.FlipY; } map.SetTileFlags(newCoords.x, newCoords.y, (int)TileLayer.Spike, tileFlags); } } }
public IntelCPU(string name, uint family, uint model, uint stepping, uint[,] cpuidData, uint[,] cpuidExtData) { this.name = name; this.icon = Utilities.EmbeddedResources.GetImage("cpu.png"); this.family = family; this.model = model; this.stepping = stepping; logicalProcessors = 0; if (cpuidData.GetLength(0) > 0x0B) { uint eax, ebx, ecx, edx; WinRing0.CpuidEx(0x0B, 0, out eax, out ebx, out ecx, out edx); logicalProcessorsPerCore = ebx & 0xFF; if (logicalProcessorsPerCore > 0) { WinRing0.CpuidEx(0x0B, 1, out eax, out ebx, out ecx, out edx); logicalProcessors = ebx & 0xFF; } } if (logicalProcessors <= 0 && cpuidData.GetLength(0) > 0x04) { uint coresPerPackage = ((cpuidData[4, 0] >> 26) & 0x3F) + 1; uint logicalPerPackage = (cpuidData[1, 1] >> 16) & 0xFF; logicalProcessorsPerCore = logicalPerPackage / coresPerPackage; logicalProcessors = logicalPerPackage; } if (logicalProcessors <= 0 && cpuidData.GetLength(0) > 0x01) { uint logicalPerPackage = (cpuidData[1, 1] >> 16) & 0xFF; logicalProcessorsPerCore = logicalPerPackage; logicalProcessors = logicalPerPackage; } if (logicalProcessors <= 0) { logicalProcessors = 1; logicalProcessorsPerCore = 1; } IntPtr processMask, systemMask; GetProcessAffinityMask(Process.GetCurrentProcess().Handle, out processMask, out systemMask); affinityMask = (ulong)systemMask; // correct values in case HypeThreading is disabled if (logicalProcessorsPerCore > 1) { ulong affinity = affinityMask; int availableLogicalProcessors = 0; while (affinity != 0) { if ((affinity & 0x1) > 0) { availableLogicalProcessors++; } affinity >>= 1; } while (logicalProcessorsPerCore > 1 && availableLogicalProcessors < logicalProcessors) { logicalProcessors >>= 1; logicalProcessorsPerCore >>= 1; } } coreCount = logicalProcessors / logicalProcessorsPerCore; float tjMax; switch (family) { case 0x06: { switch (model) { case 0x0F: // Intel Core (65nm) switch (stepping) { case 0x06: // B2 switch (coreCount) { case 2: tjMax = 80 + 10; break; case 4: tjMax = 90 + 10; break; default: tjMax = 85 + 10; break; } tjMax = 80 + 10; break; case 0x0B: // G0 tjMax = 90 + 10; break; case 0x0D: // M0 tjMax = 85 + 10; break; default: tjMax = 85 + 10; break; } break; case 0x17: // Intel Core (45nm) tjMax = 100; break; case 0x1C: // Intel Atom tjMax = 90; break; case 0x1A: // Intel Core i7 LGA1366 (45nm) case 0x1E: // Intel Core i5, i7 LGA1156 (45nm) case 0x25: // Intel Core i3, i5, i7 LGA1156 (32nm) uint eax, edx; if (WinRing0.Rdmsr(IA32_TEMPERATURE_TARGET, out eax, out edx)) { tjMax = (eax >> 16) & 0xFF; } else { tjMax = 100; } if (WinRing0.Rdmsr(MSR_PLATFORM_INFO, out eax, out edx)) { maxNehalemMultiplier = (eax >> 8) & 0xff; } break; default: tjMax = 100; break; } } break; default: tjMax = 100; break; } // check if processor supports a digital thermal sensor if (cpuidData.GetLength(0) > 6 && (cpuidData[6, 0] & 1) != 0) { coreTemperatures = new Sensor[coreCount]; for (int i = 0; i < coreTemperatures.Length; i++) { coreTemperatures[i] = new Sensor(CoreString(i), i, tjMax, SensorType.Temperature, this, new ParameterDescription[] { new ParameterDescription( "TjMax", "TjMax temperature of the core.\n" + "Temperature = TjMax - TSlope * Value.", tjMax), new ParameterDescription( "TSlope", "Temperature slope of the digital thermal sensor.\n" + "Temperature = TjMax - TSlope * Value.", 1) }); } } else { coreTemperatures = new Sensor[0]; } if (coreCount > 1) { totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this); } else { totalLoad = null; } coreLoads = new Sensor[coreCount]; for (int i = 0; i < coreLoads.Length; i++) { coreLoads[i] = new Sensor(CoreString(i), i + 1, SensorType.Load, this); } cpuLoad = new CPULoad(coreCount, logicalProcessorsPerCore); if (cpuLoad.IsAvailable) { foreach (Sensor sensor in coreLoads) { ActivateSensor(sensor); } if (totalLoad != null) { ActivateSensor(totalLoad); } } lastCount = 0; lastTime = 0; busClock = new Sensor("Bus Speed", 0, SensorType.Clock, this); coreClocks = new Sensor[coreCount]; for (int i = 0; i < coreClocks.Length; i++) { coreClocks[i] = new Sensor(CoreString(i), i + 1, SensorType.Clock, this); ActivateSensor(coreClocks[i]); } Update(); }
public mxNumericArray(uint[,] realValues, uint[,] imgValues) : this(BitConverterExtesions.GetBytes(realValues), BitConverterExtesions.GetBytes(imgValues), realValues.GetLength(0), realValues.GetLength(1), mxNumericType.UINT32) { }
public uint[,] ApplyFrame(uint[,] oldFrame, ref uint[] palette) { var width = oldFrame.GetLength(1); var height = oldFrame.GetLength(0); var newFrame = new uint[height, width]; // We use Buffer.BlockCopy as Array.Copy does not properly handle 2d array! var shift = ((this.globalMotion?.X ?? 0) + (this.globalMotion?.Y ?? 0) * width) * 4; if (shift >= 0) { Buffer.BlockCopy(oldFrame, shift, newFrame, 0, oldFrame.Length * 4 - shift); } else { Buffer.BlockCopy(oldFrame, 0, newFrame, -shift, oldFrame.Length * 4 + shift); } if (this.colors != null) { this.colors.Position = 0; var firstIndex = this.colors.ReadUInt8(); var numColors = (this.colors.ReadUInt8() - 1) & 0xff; for (var i = 0; i <= numColors; i++) { palette[firstIndex + i] = (uint)((0xff << 24) | (this.colors.ReadUInt8() << 16) | (this.colors.ReadUInt8() << 8) | (this.colors.ReadUInt8() << 0)); } } if (this.video == null) { return(newFrame); } this.video.Position = 0; for (var by = 0; by < height / 4; by++) { for (var bx = 0; bx < width / 4;) { var blockTypes = this.video.ReadUInt8(); for (var i = 0; i < 4; i++, bx++) { var blockType = (blockTypes >> (6 - i * 2)) & 0x03; switch (blockType) { case 0: { break; } case 1: { var motion = this.video.ReadUInt8(); if (motion == 0) { for (var y = 0; y < 4; y++) { for (var x = 0; x < 4; x++) { newFrame[by * 4 + y, bx * 4 + x] = palette[this.video.ReadByte()]; } } } else { var motionX = ((motion & 0xf) ^ 8) - 8; var motionY = ((motion >> 4) ^ 8) - 8; for (var y = 0; y < 4; y++) { for (var x = 0; x < 4; x++) { newFrame[by * 4 + y, bx * 4 + x] = oldFrame[by * 4 + y + (this.globalMotion?.Y ?? 0) + motionY, bx * 4 + x + (this.globalMotion?.X ?? 0) + motionX]; } } } break; } case 2: { var color = palette[this.video.ReadUInt8()]; for (var y = 0; y < 4; y++) { for (var x = 0; x < 4; x++) { newFrame[by * 4 + y, bx * 4 + x] = color; } } break; } case 3: { var patternData = this.video.ReadUInt8(); var patternType = patternData >> 6; var pattern = VbcFrame.Patterns[patternData & 0x3f]; switch (patternType) { case 0: { var pixel0 = palette[this.video.ReadUInt8()]; var pixel1 = palette[this.video.ReadUInt8()]; for (var y = 0; y < 4; y++) { for (var x = 0; x < 4; x++) { newFrame[by * 4 + y, bx * 4 + x] = ((pattern >> (y * 4 + x)) & 1) == 0 ? pixel0 : pixel1; } } break; } case 1: { var pixel = palette[this.video.ReadUInt8()]; for (var y = 0; y < 4; y++) { for (var x = 0; x < 4; x++) { if (((pattern >> (y * 4 + x)) & 1) == 1) { newFrame[by * 4 + y, bx * 4 + x] = pixel; } } } break; } case 2: { var pixel = palette[this.video.ReadUInt8()]; for (var y = 0; y < 4; y++) { for (var x = 0; x < 4; x++) { if (((pattern >> (y * 4 + x)) & 1) == 0) { newFrame[by * 4 + y, bx * 4 + x] = pixel; } } } break; } } break; } } } } } return(newFrame); }
public static unsafe void ComputeDouble( uint[,] iterations, int startScanline, int increment, double offsetX, double offsetY, double zoom, uint maxIterations, ref bool cancel) { const int stride = 2; int height = iterations.GetLength(0); int width = iterations.GetLength(1); var maxIter = Vector128.Create((double)maxIterations); var limit = Vector128.Create(4.0); var one = Vector128.Create(1.0); var two = Vector128.Create(2.0); var results = stackalloc double[stride]; for (int i = startScanline; i < height && !cancel; i += increment) { for (int j = 0; j < width && !cancel; j += stride) { var c0 = Impl.GetPointCoordinate(j + 0, i, width, height, offsetX, offsetY, zoom); var c1 = Impl.GetPointCoordinate(j + 1, i, width, height, offsetX, offsetY, zoom); var cr = Vector128.Create(c0.X, c1.X); var ci = Vector128.Create(c0.Y, c1.Y); var zr = cr; var zi = ci; var it = Vector128.Create(0.0); for (;;) { var zr2 = Sse2.Multiply(zr, zr); var zi2 = Sse2.Multiply(zi, zi); var squaredMagnitude = Sse2.Add(zr2, zi2); var cond = Sse2.And( Sse2.CompareLessThanOrEqual(squaredMagnitude, limit), Sse2.CompareLessThanOrEqual(it, maxIter)); if (Sse2.MoveMask(cond) == 0) { Sse2.Store(results, it); if (j + 0 < width) { iterations[i, j + 0] = (uint)results[0] % maxIterations; } if (j + 1 < width) { iterations[i, j + 1] = (uint)results[1] % maxIterations; } break; } zi = Sse2.Add(Sse2.Multiply(two, Sse2.Multiply(zr, zi)), ci); zr = Sse2.Add(Sse2.Subtract(zr2, zi2), cr); it = Sse2.Add(it, Sse2.And(one, cond)); } } } }
void Gauss_Elimination() { uint row_adds = 0, row_swaps = 0; sw1.Restart(); for (uint p = 0; p < matrix.GetLength(0); p++) // number of rows { // find pivot row and swap for (uint i = p + 1; i < matrix.GetLength(0); i++) // { if (matrix[i, p] > matrix[p, p]) { #if _DEBUG WriteLine("Swap rows: {0} and {1}", p, i); #endif row_swaps++; for (uint j = 0; j < matrix.GetLength(1); j++) // length of the 2nd dimension / number of columns { uint t = matrix[i, j]; matrix[i, j] = matrix[p, j]; matrix[p, j] = t; } } if (matrix[i, p] == 1) // Add these rows if value in pivot column is 1 { #if _DEBUG WriteLine("Add row: {0} to row: {1}", p, i); #endif row_adds++; for (int j = 0; j < matrix.GetLength(1); j++) { matrix[i, j] ^= matrix[p, j]; } } } // for i } // for p sw1.Stop(); string strElapsed; if (sw1.ElapsedMilliseconds <= 1000) { strElapsed = String.Format("{0} ms", sw1.ElapsedMilliseconds); } else { strElapsed = String.Format("{0:F1} s", (float)sw1.Elapsed.Milliseconds / 1000); } string strValue = $"Row adds: {row_adds}\nRow swaps: {row_swaps}\nElapsed time: {strElapsed}\n"; WriteLine(strValue); }
public static List <PSFFit> GetStarsInArea( ref uint[,] data, int bpp, uint maxSignalValue, TangraConfig.PreProcessingFilter filter, List <PotentialStarStruct> allPotentialStars, List <PSFFit> allFoundStars, uint aboveNoiseLevelRequired, double minDistanceInPixels, bool useLPDFilter, Rectangle excludeArea, FilterPotentialStars filterCallback) { double minFWHM = TangraConfig.Settings.Special.StarFinderMinFWHM; double maxFWHM = TangraConfig.Settings.Special.StarFinderMaxFWHM; int STAR_MATRIX_FIT = TangraConfig.Settings.Special.StarFinderFitArea; Stopwatch sw = new Stopwatch(); sw.Start(); uint[,] lpdData; List <PotentialStarStruct> potentialStars = GetPeakPixelsInArea( data, out lpdData, bpp, maxSignalValue, aboveNoiseLevelRequired, minDistanceInPixels, useLPDFilter, excludeArea); if (filterCallback != null) { filterCallback(potentialStars); } sw.Stop(); Trace.WriteLine(string.Format("GetPeakPixelsInArea: {0} sec", sw.Elapsed.TotalSeconds.ToString("0.00"))); if (potentialStars.Count > 3) { // Only include the 3 brightest stars. The other ones cannot be stars potentialStars.Sort((x, y) => y.Z.CompareTo(x.Z)); potentialStars = potentialStars.Take(3).ToList(); } // Debugging purposes if (allPotentialStars != null) { allPotentialStars.AddRange(potentialStars); } uint[,] lpData = data; List <PSFFit> foundStars = new List <PSFFit>(); double MIN_DISTANCE_OF_PEAK_PIXEL_FROM_CENTER = TangraConfig.Settings.Special.StarFinderMinDistanceOfPeakPixelFromCenter; sw.Reset(); sw.Start(); foreach (PotentialStarStruct starToTest in potentialStars) { PSFFit fit = new PSFFit(starToTest.X, starToTest.Y); int fitMatrix = (int)Math.Min(data.GetLength(0), STAR_MATRIX_FIT + 2); // Get a matrix with 1 pixel larger each way and set the border pixels to zero fit.Fit(lpData, fitMatrix, starToTest.X, starToTest.Y, true); if (fit.IsSolved) { double distanceFromCenter = ImagePixel.ComputeDistance(fit.X0_Matrix, fitMatrix / 2, fit.Y0_Matrix, fitMatrix / 2); if (fit.Certainty > 0 && fit.FWHM >= minFWHM && fit.FWHM <= maxFWHM && distanceFromCenter < MIN_DISTANCE_OF_PEAK_PIXEL_FROM_CENTER && fit.IMax > aboveNoiseLevelRequired) { // This object passes all tests to be furhter considered as a star foundStars.Add(fit); } } if (allFoundStars != null) { allFoundStars.Add(fit); } } foundStars.Sort((f1, f2) => f1.IMax.CompareTo(f2.IMax)); PSFFit[] testStars = foundStars.ToArray(); for (int i = 0; i < testStars.Length; i++) { PSFFit fainterStar = testStars[i]; for (int j = i + 1; j < testStars.Length; j++) { PSFFit brighterStar = testStars[j]; if (fainterStar.UniqueId == brighterStar.UniqueId) { continue; } // If a the max of a fainter star is inside the fit of a brighter star // then see if it is simply not a point of the other star double dist = Math.Sqrt((fainterStar.XCenter - brighterStar.XCenter) * (fainterStar.XCenter - brighterStar.XCenter) + (fainterStar.YCenter - brighterStar.YCenter) * (fainterStar.YCenter - brighterStar.YCenter)); if (dist <= minDistanceInPixels) { if (foundStars.Contains(fainterStar)) { foundStars.Remove(fainterStar); } } } } sw.Stop(); Trace.WriteLine(string.Format("Doing PSFFitting: {0} sec", sw.Elapsed.TotalSeconds.ToString("0.00"))); switch (filter) { case TangraConfig.PreProcessingFilter.NoFilter: break; case TangraConfig.PreProcessingFilter.LowPassFilter: data = lpData; break; case TangraConfig.PreProcessingFilter.LowPassDifferenceFilter: data = lpdData; break; } return(foundStars); }
//https://social.msdn.microsoft.com/Forums/en-US/9d926a16-0051-4ca3-b77c-8095fb489ae2/flood-fill-c?forum=csharplanguage public static void FloodFill(Tilemap tilemap, int gridX, int gridY, uint[,] tileData) { float timeStamp; timeStamp = Time.realtimeSinceStartup; //float callTimeStamp = timeStamp; int patternW = tileData.GetLength(0); int patternH = tileData.GetLength(1); LinkedList <Point> check = new LinkedList <Point>(); uint floodFrom = tilemap.GetTileData(gridX, gridY); tilemap.SetTileData(gridX, gridY, tileData[(gridX % patternW + patternW) % patternW, (gridY % patternH + patternH) % patternH]); bool isBrush = Tileset.GetBrushIdFromTileData(floodFrom) != 0; //Debug.Log(" Flood Fill Starts +++++++++++++++ "); if ( (patternW > 0 && patternH > 0) && isBrush? Tileset.GetBrushIdFromTileData(floodFrom) != Tileset.GetBrushIdFromTileData(tileData[0, 0]) : floodFrom != tileData[0, 0] ) { check.AddLast(new Point(gridX, gridY)); while (check.Count > 0) { Point cur = check.First.Value; check.RemoveFirst(); foreach (Point off in new Point[] { new Point(0, -1), new Point(0, 1), new Point(-1, 0), new Point(1, 0) }) { Point next = new Point(cur.X + off.X, cur.Y + off.Y); uint nextTileData = tilemap.GetTileData(next.X, next.Y); if ( next.X >= tilemap.MinGridX && next.X <= tilemap.MaxGridX && next.Y >= tilemap.MinGridY && next.Y <= tilemap.MaxGridY ) { if ( isBrush? Tileset.GetBrushIdFromTileData(floodFrom) == Tileset.GetBrushIdFromTileData(nextTileData) : floodFrom == nextTileData ) { check.AddLast(next); tilemap.SetTileData(next.X, next.Y, tileData[(next.X % patternW + patternW) % patternW, (next.Y % patternH + patternH) % patternH]); } } } float timePast = Time.realtimeSinceStartup - timeStamp; if (timePast > k_timeToAbortFloodFill) { #if UNITY_EDITOR int result = UnityEditor.EditorUtility.DisplayDialogComplex("FloodFill is taking too much time", "Do you want to continue for another " + k_timeToAbortFloodFill + " seconds?", "Wait", "Cancel", "Wait and Don't ask again"); if (result == 0) { timeStamp = Time.realtimeSinceStartup; } else if (result == 1) { break; } else if (result == 2) { timeStamp = float.MaxValue; } #else check.Clear(); #endif } } } //Debug.Log("FloodFill Time " + (int)((Time.realtimeSinceStartup - callTimeStamp) * 1000) + "ms"); }
// Calculate shortest path(s) using Dijkstra's algorithm. Note that // the matrix contains edge distance between vertexes. A zero value // indicates no path between the verticies. Since zero could be a // concievable distance, we add 1 to all distances such that we can // use zero to indicate no path between the verticies. This means // the actual length is the distance value minus 1. public static uint[,] ShortestPaths(uint[,] graph, uint start, uint end) { // Do some validation. if (graph.Rank != 2) { throw(new InvalidOperationException("graph matrix must be two " + "dimensional")); } if (graph.GetLength(0) != graph.GetLength(1)) { throw(new InvalidOperationException("graph matrix must be square")); } // Create an array to hold the distance to each vertex while calculating // the shortest path. uint[] distance = new uint[graph.GetLength(0)]; for (uint i = 0; i < (uint)distance.Length; ++i) { distance[i] = uint.MaxValue; } // Set the distance of our start vertex to zero. This will cause it to // get sorted to the front of the queue and thus get processed first. distance[start] = 0; // This queue initially contains all the indexes. uint[] queue = new uint[distance.Length]; for (uint i = 0; i < (uint)queue.Length; ++i) { queue[i] = i; } int head = 0; IComparer distanceCompare = new DistanceCompare(distance); // Go until queue is empty. while (head != queue.Length) { // Sort the queue of indexes by distance. Array.Sort(queue, head, queue.Length - head, distanceCompare); // Get the vertex with the shortest distance. uint vertex = queue[head]; // Remove front of queue. head++; // Check each neighbor of vertex and see if we need to update // the distance to that neighbor. for (uint i = 0; i < (uint)graph.GetLength(0); ++i) { // Is this a neighbor? if (graph[vertex, i] > 1) { // If we found a shorter distance then update the distance. if (distance[i] > distance[vertex] + (graph[vertex, i] - 1)) { distance[i] = distance[vertex] + (graph[vertex, i] - 1); } } } } // If no path found then return null. if (distance[end] == uint.MaxValue) { return(null); } else { // Create a return graph with just lengths for the shortest // paths. Initialize all edges to 0 (meaning no path). uint[,] paths = new uint[graph.GetLength(0), graph.GetLength(1)]; for (uint i = 0; i < (uint)graph.GetLength(0); ++i) { for (uint j = 0; j < graph.GetLength(1); ++j) { paths[i, j] = 0; } } // Flags to tell whether we already handled a vertex when // generating the paths (eg. backtracing). bool[] handledVertex = new bool[graph.GetLength(0)]; for (uint i = 0; i < (uint)handledVertex.Length; ++i) { handledVertex[i] = false; } // Vertexes queue used when determining the paths. uint[] vertexes = new uint[graph.GetLength(0)]; vertexes[0] = end; uint cur = 0; uint avail = 1; // Go from end to start along the shortest paths found to // fill in the paths graph. while (cur != avail) { for (uint i = 0; i < (uint)graph.GetLength(0); ++i) { // Rows in the graph indicate outgoing edges from the vertex. // Columns in the graph indicate incoming edges to the vertex. // I'm checking down column vertexes[cur] to see if there // in an incoming edge from vertex i. if (graph[i, vertexes[cur]] > 1) { // If the edge was part of a shortest path, eg. distance // of current vertex is the sum of the distance of the // incoming vertex plus the edge, then the incoming vertex // was part of a shortest path. if (distance[vertexes[cur]] == (distance[i] + (graph[i, vertexes[cur]] - 1))) { // This incoming vertex was part of a shortest path // so copy over its edge from the original graph. paths[i, vertexes[cur]] = graph[i, vertexes[cur]]; // If we didn't handle this incoming vertex already // add it to the queue. if (handledVertex[i] == false) { vertexes[avail++] = i; handledVertex[i] = true; } } } } // Move to next vertex to process. cur++; } return(paths); } }
public static void DrawRect(Tilemap tilemap, Vector2 locPosA, Vector2 locPosB, uint[,] tileData, bool isFilled, bool is9Sliced = false) { int w = tileData.GetLength(0); int h = tileData.GetLength(1); int x0 = TilemapUtils.GetGridX(tilemap, locPosA); int y0 = TilemapUtils.GetGridY(tilemap, locPosA); int x1 = TilemapUtils.GetGridX(tilemap, locPosB); int y1 = TilemapUtils.GetGridY(tilemap, locPosB); if (x0 > x1) { Swap <int>(ref x0, ref x1); } if (y0 > y1) { Swap <int>(ref y0, ref y1); } TilemapDrawingUtils.Rect(x0, y0, x1, y1, isFilled, (x, y) => { if (is9Sliced) { if (x == x0 && y == y0) { tilemap.SetTileData(x, y, tileData[0, 0]); } else if (x == x0 && y == y1) { tilemap.SetTileData(x, y, tileData[0, h - 1]); } else if (x == x1 && y == y0) { tilemap.SetTileData(x, y, tileData[w - 1, 0]); } else if (x == x1 && y == y1) { tilemap.SetTileData(x, y, tileData[w - 1, h - 1]); } else { int cw = w - 2; int ch = h - 2; int cx = cw >= 1 ? 1 + (x % cw + cw) % cw : (x % w + w) % w; int cy = ch >= 1 ? 1 + (y % ch + ch) % ch : (y % h + h) % h; if (x == x0) { tilemap.SetTileData(x, y, tileData[0, cy]); } else if (x == x1) { tilemap.SetTileData(x, y, tileData[w - 1, cy]); } else if (y == y0) { tilemap.SetTileData(x, y, tileData[cx, 0]); } else if (y == y1) { tilemap.SetTileData(x, y, tileData[cx, h - 1]); } else { tilemap.SetTileData(x, y, tileData[cx, cy]); } } } else { tilemap.SetTileData(x, y, tileData[(x % w + w) % w, (y % h + h) % h]); } return(true); } ); }
static internal Bitmap DrawEAN13(string barCodeNum, float DPI = 300) { Bitmap barCodeBmp = new Bitmap((int)(TOTAL_WIDTH * DPI) + 1, (int)(TOTAL_HEIGHT * DPI) + 1); barCodeBmp.SetResolution(DPI, DPI); int w = (int)(barCodeBmp.Width + DPI * (SPACE_LEFT + SPACE_RIGHT)), h = (int)(barCodeBmp.Height + 2 * DPI * SPACE_UP_DOWN); Bitmap fullImage = new Bitmap(w, h); fullImage.SetResolution(DPI, DPI); Pen pen = new Pen(Color.White, TOTAL_WIDTH * DPI / 95f); float textSpace = 7f * pen.Width / 6f; PointF textPt = new PointF(0, TEXT_POS * DPI); //координаты текста Font f = new Font("Tahoma", TEXT_HEIGHT * 72f, FontStyle.Regular); using (Graphics g = Graphics.FromImage(barCodeBmp), g1 = Graphics.FromImage(fullImage)) { g.FillRectangle(Brushes.White, new Rectangle(0, 0, barCodeBmp.Width, barCodeBmp.Height)); //Разделитель слева float x = pen.Width / 2, y = SEPARATOR_LINE_LEN * DPI; for (int i = 0; i < 3; i++, x += pen.Width) { pen.Color = Divcode[0, i] == 0 ? Color.White : Color.Black; g.DrawLine(pen, x, 0, x, y); } //Левая половина кода int n; y = LINE_LEN * DPI; for (int i = 0; i < 6; i++, textPt.X += textSpace) { textPt.X = x; g.DrawString(barCodeNum[i].ToString(), f, Brushes.Black, textPt); n = int.Parse(barCodeNum[i].ToString()); for (int j = 0; j < Lcode.GetLength(1); j++, x += pen.Width) { pen.Color = Lcode[n, j] == 0 ? Color.White : Color.Black; g.DrawLine(pen, x, 0, x, y); } } //Разделитель по центру y = SEPARATOR_LINE_LEN * DPI; for (int i = 0; i < Divcode.GetLength(1); i++, x += pen.Width) { pen.Color = Divcode[1, i] == 0 ? Color.White : Color.Black; g.DrawLine(pen, x, 0, x, y); } //Правая половина кода y = LINE_LEN * DPI; for (int i = 6; i < barCodeNum.Length; i++, textPt.X += textSpace) { n = int.Parse(barCodeNum[i].ToString()); textPt.X = x; g.DrawString(barCodeNum[i].ToString(), f, Brushes.Black, textPt); for (int j = 0; j < Rcode.GetLength(1); j++, x += pen.Width) { pen.Color = Rcode[n, j] == 0 ? Color.White : Color.Black; g.DrawLine(pen, x, 0, x, y); } } //Разделитель справа y = SEPARATOR_LINE_LEN * DPI; for (int i = 0; i < 3; i++, x += pen.Width) { pen.Color = Divcode[2, i] == 0 ? Color.White : Color.Black; g.DrawLine(pen, x, 0, x, y); } g1.FillRectangle(Brushes.White, 0, 0, fullImage.Width, fullImage.Height); g1.DrawImage(barCodeBmp, DPI * SPACE_LEFT, DPI * SPACE_UP_DOWN); } return(fullImage); //return barCodeBmp; }
private void CalculateAndDisplayBackground(uint[,] backgroundPixels) { if (backgroundPixels != null) { int bgWidth = backgroundPixels.GetLength(0); int bgHeight = backgroundPixels.GetLength(1); var bgPixels = new List <uint>(); for (int x = 0; x < bgWidth; x++) { for (int y = 0; y < bgHeight; y++) { if (m_PSFFit == null || !m_PSFFit.IsSolved || ImagePixel.ComputeDistance(m_PSFFit.XCenter, x + bgWidth - m_PSFFit.MatrixSize, m_PSFFit.YCenter, y + bgHeight - m_PSFFit.MatrixSize) > 3 * m_PSFFit.FWHM) { bgPixels.Add(backgroundPixels[x, y]); } } } bgPixels.Sort(); double background = 0; if (bgPixels.Count > 1) { background = m_Bpp < 12 ? bgPixels[bgPixels.Count / 2] // for 8 bit videos Median background works better : bgPixels.Average(x => x); // for 12+bit videos average background works better } double residualsSquareSum = 0; foreach (uint bgPixel in bgPixels) { residualsSquareSum += (background - bgPixel) * (background - bgPixel); } double noise = Math.Sqrt(residualsSquareSum / (bgPixels.Count - 1)); lblBackground.Text = background.ToString("0.0"); lblNoise.Text = noise.ToString("0.0"); if (m_PSFFit != null) { double snr = m_PSFFit.GetSNR(); lblSNR.Text = snr.ToString("0.0"); } else { lblSNR.Text = "N/A"; } if (m_PSFFit != null) { lblFitVariance.Text = m_PSFFit.GetVariance().ToString("0.0"); lblFWHM.Text = m_PSFFit.FWHM.ToString("0.0"); } else { lblFitVariance.Text = "N/A"; lblFWHM.Text = "N/A"; } } else { lblBackground.Text = "N/A"; lblNoise.Text = "N/A"; lblSNR.Text = "N/A"; } }
// horizontalni algoritam private static uint[,] SeamCarvingStep(uint[,] a, ref int[] removed) { int n = a.GetLength(0); int m = a.GetLength(1); uint[,] dp = new uint[n, m]; short[,] dir = new short[n, m]; uint[,] b = new uint[n, m - 1]; for (int j = 0; j < m; j++) { dp[0, j] = 0; } for (int i = 1; i < n; i++) { for (int j = 0; j < m; j++) { dp[i, j] = dp[i - 1, j] + PixelDiff(a[i, j], a[i - 1, j]); dir[i, j] = 0; uint l = 0xffffffff, r = 0xffffffff; if (j > 0) { l = dp[i - 1, j - 1] + PixelDiff(a[i, j], a[i - 1, j - 1]); } if (j < m - 1) { r = dp[i - 1, j + 1] + PixelDiff(a[i, j], a[i - 1, j + 1]); } if (l < dp[i, j]) { dp[i, j] = l; dir[i, j] = -1; } if (r < dp[i, j]) { dp[i, j] = r; dir[i, j] = +1; } } } removed = new int[n]; int y0 = 0; for (int j = 1; j < m; j++) { if (dp[n - 1, j] < dp[n - 1, y0]) { y0 = j; } } int x = n - 1, y = y0; removed[x] = y; while (x > 0) { y += dir[x, y]; x -= 1; removed[x] = y; } for (int i = 0; i < n; i++) { int k = 0; for (int j = 0; j < m; j++) { if (j != removed[i]) { b[i, k] = a[i, j]; k++; } } } return(b); }
public string GetDataAsHtml(GameVersion version, string versionPostfix, GameLocale locale, WebsiteLanguage websiteLanguage, T8BTTA strategy, TSS.TSSFile stringDic, Dictionary <uint, TSS.TSSEntry> inGameIdDict) { StringBuilder sb = new StringBuilder(); //sb.Append( RefString ); sb.Append("<tr>"); int colspan = websiteLanguage.WantsBoth() ? 5 : 10; if (websiteLanguage.WantsJp()) { sb.Append("<td colspan=\"" + colspan + "\">"); sb.Append("<span class=\"itemname\">"); sb.Append(inGameIdDict[NameStringDicID].StringJpnHtml(version, inGameIdDict)); sb.Append("</span>"); sb.Append("<br>"); sb.Append(inGameIdDict[DescStringDicID].StringJpnHtml(version, inGameIdDict)); sb.Append("</td>"); } if (websiteLanguage.WantsEn()) { sb.Append("<td colspan=\"" + colspan + "\">"); sb.Append("<span class=\"itemname\">"); sb.Append(inGameIdDict[NameStringDicID].StringEngHtml(version, inGameIdDict)); sb.Append("</span>"); sb.Append("<br>"); sb.Append(inGameIdDict[DescStringDicID].StringEngHtml(version, inGameIdDict)); sb.Append("</td>"); } sb.Append("</tr>"); sb.Append("<tr>"); sb.Append("<td>"); sb.Append("</td>"); for (int i = 0; i < StrategyDefaults.GetLength(1); ++i) { sb.Append("<td class=\"strategychar\">"); Website.WebsiteGenerator.AppendCharacterBitfieldAsImageString(sb, inGameIdDict, version, 1u << i, websiteLanguage.MainJp()); sb.Append("</td>"); } sb.Append("</tr>"); for (uint xRaw = 0; xRaw < StrategyDefaults.GetLength(0); ++xRaw) { uint x = xRaw; // swap around OVL and FS because they're stored the wrong way around compared to how they show up ingame if (x == 6) { x = 7; } else if (x == 7) { x = 6; } sb.Append("<tr>"); sb.Append("<td>"); sb.Append("<span class=\"strategycat\">"); sb.Append(GetCategoryName(x, version, websiteLanguage, inGameIdDict)); sb.Append("</span>"); sb.Append("</td>"); for (uint y = 0; y < StrategyDefaults.GetLength(1); ++y) { if (y == 8 && !version.HasPS3Content()) { continue; } // skip patty strategy if we don't have her sb.Append("<td>"); var option = strategy.StrategyOptionDict[StrategyDefaults[x, y]]; sb.Append(inGameIdDict[option.NameStringDicID].StringEngOrJpnHtml(version, inGameIdDict, websiteLanguage)); sb.Append("</td>"); } sb.Append("</tr>"); } //sb.Append( "<td>" ); //for ( int i = 0; i < UnknownFloats1.Length; ++i ) { // sb.Append( UnknownFloats1[i] + " / " ); //} //sb.Append( "<br>" ); //for ( int i = 0; i < UnknownFloats2.Length; ++i ) { // sb.Append( UnknownFloats2[i] + " / " ); //} //sb.Append( "</td>" ); return(sb.ToString()); }
public SeamCarving(uint[,] pixels) { data = pixels; n = pixels.GetLength(0); m = pixels.GetLength(1); removedH = new int[n, m]; removedV = new int[m, n]; uint[,] tmp = pixels; // uradi sva horizontalna skaliranja for (int i = 1; i < m; i++) { int[] removed = null; tmp = SeamCarvingStep(tmp, ref removed); for (int j = 0; j < n; j++) { // nadji k-to prazno mesto int k = removed[j]; for (int l = 0; l < m; l++) { if (removedH[j, l] == 0) { if (k == 0) { removedH[j, l] = i; break; } else { k--; } } } } } // uradi sva vertikalna skaliranja (samo transponuj i zameni n, m) tmp = Transpose(pixels); for (int i = 1; i < n; i++) { int[] removed = null; tmp = SeamCarvingStep(tmp, ref removed); for (int j = 0; j < m; j++) { // nadji k-to prazno mesto int k = removed[j]; for (int l = 0; l < n; l++) { if (removedV[j, l] == 0) { if (k == 0) { removedV[j, l] = i; break; } else { k--; } } } } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (removedH[i, j] == 0) { removedH[i, j] = m; } if (removedV[j, i] == 0) { removedV[j, i] = n; } } } }
public IntelCPU(string name, uint family, uint model, uint stepping, uint[,] cpuidData, uint[,] cpuidExtData) { this.name = name; this.icon = Utilities.EmbeddedResources.GetImage("cpu.png"); this.family = family; this.model = model; this.stepping = stepping; logicalProcessors = 0; if (cpuidData.GetLength(0) > 0x0B) { uint eax, ebx, ecx, edx; WinRing0.CpuidEx(0x0B, 0, out eax, out ebx, out ecx, out edx); logicalProcessorsPerCore = ebx & 0xFF; if (logicalProcessorsPerCore > 0) { WinRing0.CpuidEx(0x0B, 1, out eax, out ebx, out ecx, out edx); logicalProcessors = ebx & 0xFF; } } if (logicalProcessors <= 0 && cpuidData.GetLength(0) > 0x04) { logicalProcessors = ((cpuidData[4, 0] >> 26) & 0x3F) + 1; logicalProcessorsPerCore = 1; } if (logicalProcessors <= 0) { logicalProcessors = 1; logicalProcessorsPerCore = 1; } coreCount = logicalProcessors / logicalProcessorsPerCore; // check if processor supports a digital thermal sensor if (cpuidData.GetLength(0) > 6 && (cpuidData[6, 0] & 1) != 0) { switch (family) { case 0x06: { switch (model) { case 0x0F: // Intel Core 65nm switch (stepping) { case 0x06: // B2 switch (coreCount) { case 2: tjMax = 80; break; case 4: tjMax = 90; break; default: tjMax = 85; break; } tjMax = 80; break; case 0x0B: // G0 tjMax = 90; break; case 0x0D: // M0 tjMax = 85; break; default: tjMax = 85; break; } break; case 0x17: // Intel Core 45nm tjMax = 100; break; case 0x1C: // Intel Atom tjMax = 90; break; case 0x1A: // Intel Core i7 case 0x1E: // Intel Core i5 uint eax, edx; if (WinRing0.Rdmsr(IA32_TEMPERATURE_TARGET, out eax, out edx)) { tjMax = (eax >> 16) & 0xFF; } else { tjMax = 100; } break; default: tjMax = 100; break; } } break; default: tjMax = 100; break; } if (family == 0x06 && model >= 0x1A) // Core i5, i7 { uint eax, edx; if (WinRing0.Rdmsr(MSR_PLATFORM_INFO, out eax, out edx)) { maxNehalemMultiplier = (eax >> 8) & 0xff; } } coreTemperatures = new Sensor[coreCount]; for (int i = 0; i < coreTemperatures.Length; i++) { coreTemperatures[i] = new Sensor("Core #" + (i + 1), i, tjMax, SensorType.Temperature, this); } } else { coreTemperatures = new Sensor[0]; } totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this); coreLoads = new Sensor[coreCount]; for (int i = 0; i < coreLoads.Length; i++) { coreLoads[i] = new Sensor("Core #" + (i + 1), i + 1, SensorType.Load, this); } cpuLoad = new CPULoad(coreCount, logicalProcessorsPerCore); if (cpuLoad.IsAvailable) { foreach (Sensor sensor in coreLoads) { ActivateSensor(sensor); } ActivateSensor(totalLoad); } lastCount = 0; lastTime = 0; busClock = new Sensor("Bus Speed", 0, SensorType.Clock, this); coreClocks = new Sensor[coreCount]; for (int i = 0; i < coreClocks.Length; i++) { coreClocks[i] = new Sensor("Core #" + (i + 1), i + 1, SensorType.Clock, this); ActivateSensor(coreClocks[i]); } Update(); }
public void Clear() { for (int y = 0; y < Map.GetLength(0); ++y) { for (int x = 0; x < Map.GetLength(1); ++x) { Map[y, x] = 0; } } }
public static void PrintBoard(uint[,] board, int[,] regions, TextWriter writer) { int HEIGHT = board.GetLength(0); int WIDTH = board.GetLength(1); uint allValuesMask = 0; for (int i = 0; i < HEIGHT; i++) { for (int j = 0; j < WIDTH; j++) { allValuesMask |= board[i, j]; } } allValuesMask &= ~valueSetMask; int maxValue = MaxValue(allValuesMask); int cellSize = (int)Math.Sqrt(maxValue); if (cellSize * cellSize != maxValue) { cellSize++; } cellSize = Math.Max(cellSize, 3); int numberSize = maxValue > 9 ? 2 : 1; int innerCellSize = cellSize * numberSize + cellSize - 1; int bigNumTotalPad1 = innerCellSize - 5; string bigNumLeftPad1 = new(' ', bigNumTotalPad1 / 2); string bugNumRightPad1 = new(' ', bigNumTotalPad1 - bigNumLeftPad1.Length); int bigNumTotalPad2 = Math.Max(0, innerCellSize - 11); string bigNumLeftPad2 = new(' ', bigNumTotalPad2 / 2); string bugNumRightPad2 = new(' ', bigNumTotalPad2 - bigNumLeftPad2.Length); int innerCellHeight = cellSize * 2 - 1; int bigNumTotalVPad = innerCellHeight - 5; int bigNumTopVPad = bigNumTotalVPad / 2; int bigNumBotVPad = bigNumTotalVPad - bigNumTopVPad; for (int i = 0; i < HEIGHT; i++) { for (int line = 0; line < cellSize * 2; line++) { for (int j = 0; j < WIDTH; j++) { bool thickV = i == 0 || regions[i - 1, j] != regions[i, j]; bool thickH = j == 0 || regions[i, j - 1] != regions[i, j]; if (line == 0) { bool drawThickLine = false; bool drawThinLine = false; if (i == 0) { if (j == 0) { writer.Write('╔'); drawThickLine = true; } else if (j == WIDTH) { writer.Write("╗"); } else if (thickH) { writer.Write('╦'); drawThickLine = true; } else { writer.Write('╤'); drawThickLine = true; } } else if (!thickV) { if (j == 0) { writer.Write("╟"); drawThinLine = true; } else { if (thickH) { writer.Write("╫"); drawThinLine = true; } else { Write("┼", writer, ConsoleColor.Gray); drawThinLine = true; } } } else { if (j == 0) { writer.Write('╠'); drawThickLine = true; } else { if (thickH) { writer.Write('╬'); drawThickLine = true; } else { writer.Write('╪'); drawThickLine = true; } } } if (drawThickLine) { writer.Write(new string('═', innerCellSize)); } else if (drawThinLine) { Write(new string('─', innerCellSize), writer, ConsoleColor.Gray); } } else { if (thickH) { writer.Write('║'); } else { Write("│", writer, ConsoleColor.Gray); } if (!IsValueSet(board[i, j])) { if ((line % 2) == 0) { writer.Write(new string(' ', innerCellSize)); } else { string s = ""; for (int x = 0; x < cellSize; x++) { int value = ((line - 1) / 2) * cellSize + x + 1; if (value <= maxValue && HasValue(board[i, j], value)) { if (value <= 9 && numberSize > 1) { s += new string(' ', numberSize - 1); } s += value.ToString(); } else { s += new string(' ', numberSize); } if (x != cellSize - 1) { s += " "; } } writer.Write(s); } } else { int bigNumLine = line - 1 - bigNumTopVPad; if (bigNumLine < 0 || bigNumLine >= bigNumbers[0].Length) { writer.Write(new string(' ', innerCellSize)); } else { int value = GetValue(board[i, j]); if (value <= 9) { writer.Write(bigNumLeftPad1); Write(bigNumbers[value][bigNumLine], writer, ConsoleColor.DarkCyan); writer.Write(bugNumRightPad1); } else { int value0 = value / 10; int value1 = value % 10; writer.Write(bigNumLeftPad2); Write(bigNumbers[value0][bigNumLine], writer, ConsoleColor.DarkCyan); writer.Write(' '); Write(bigNumbers[value1][bigNumLine], writer, ConsoleColor.DarkCyan); writer.Write(bugNumRightPad2); } } } } } if (line == 0) { if (i == 0) { writer.WriteLine("╗"); } else if (regions[i - 1, WIDTH - 1] != regions[i, WIDTH - 1]) { writer.WriteLine("╣"); } else { writer.WriteLine("╢"); } } else { writer.WriteLine("║"); } } } writer.Write('╚'); writer.Write(new string('═', innerCellSize)); for (int j = 1; j < WIDTH; j++) { if (regions[HEIGHT - 1, j - 1] != regions[HEIGHT - 1, j]) { writer.Write('╩'); } else { writer.Write('╧'); } writer.Write(new string('═', innerCellSize)); } writer.WriteLine("╝"); writer.WriteLine(); writer.Flush(); }
private static void MoveTopchenca(int currentRow, int currentCol, uint[,] matrix, string commands) { int counter = new int(); if (currentRow >= matrix.GetLength(0)) { currentRow = matrix.GetLength(0) - 1; } else if (currentRow < 0) { currentRow = 0; } if (currentCol >= matrix.GetLength(1)) { currentCol = matrix.GetLength(1) - 1; } else if (currentCol < 0) { currentCol = 0; } if (commands == "left") { for (int j = 0; j <= currentCol; j++) { if (matrix[currentRow, j] == 1) { counter++; matrix[currentRow, j] = 0; } } for (int j = 0; j < counter; j++) { matrix[currentRow, j] = 1; } } else if (commands == "right") { for (int j = currentCol; j < matrix.GetLength(1); j++) { if (matrix[currentRow, j] == 1) { counter++; matrix[currentRow, j] = 0; } } for (int j = matrix.GetLength(1) - 1; j >= matrix.GetLength(1) - counter; j--) { matrix[currentRow, j] = 1; } } else if (commands == "reset") { for (int row = 0; row < matrix.GetLength(0); row++) { for (int col = 0; col < matrix.GetLength(1); col++) { if (matrix[row, col] == 1) { counter++; matrix[row, col] = 0; } } for (int j = 0; j < counter; j++) { matrix[row, j] = 1; } counter = 0; } } }
internal bool IsBrightEnoughtForGuidingStar() { double signal; double sn; byte oneSigmaBg = 0; int from = 0; int to = m_ProcessingPixels.GetLength(0); double aboveMedianLevelRequired; if (LightCurveReductionContext.Instance.DigitalFilter != TangraConfig.PreProcessingFilter.NoFilter) { from++; to--; } switch (LightCurveReductionContext.Instance.DigitalFilter) { case TangraConfig.PreProcessingFilter.LowPassFilter: aboveMedianLevelRequired = TangraConfig.Settings.Special.AboveMedianThreasholdForGuiding * TangraConfig.Settings.Special.AboveMedianCoeffLP; break; case TangraConfig.PreProcessingFilter.LowPassDifferenceFilter: aboveMedianLevelRequired = TangraConfig.Settings.Special.AboveMedianThreasholdForGuiding * TangraConfig.Settings.Special.AboveMedianCoeffLPD; break; default: aboveMedianLevelRequired = TangraConfig.Settings.Special.AboveMedianThreasholdForGuiding; break; } List <uint> bgBytes = new List <uint>(); for (int x = from; x < to; x++) { for (int y = from; y < to; y++) { double distanceFromFit = ImagePixel.ComputeDistance(m_Gaussian.XCenter, x, m_Gaussian.YCenter, y); if (distanceFromFit > m_Gaussian.FWHM) { bgBytes.Add(m_ProcessingPixels[x, y]); } } } bgBytes.Sort(); uint median = 0; if (bgBytes.Count > 0) { median = bgBytes.Count % 2 == 1 ? bgBytes[bgBytes.Count / 2] : ((bgBytes[bgBytes.Count / 2] + bgBytes[(bgBytes.Count / 2) - 1]) / 2); } double var = 0; bgBytes.ForEach(b => var += (median - b) * (median - b)); oneSigmaBg = (byte)Math.Round(Math.Sqrt(var / Math.Max(1, bgBytes.Count - 1))); signal = m_Gaussian.IMax - median; sn = signal / oneSigmaBg; Trace.WriteLine(string.Format("Signal = {0}, S/N = {1}", signal.ToString("0.00"), sn.ToString("0.00"))); if (signal >= aboveMedianLevelRequired && sn >= TangraConfig.Settings.Special.SignalNoiseForGuiding) { return(true); } Trace.WriteLine(string.Format("Not good for a guiding star: Required Signal = {0}, Required S/N = {1}", aboveMedianLevelRequired.ToString("0.00"), TangraConfig.Settings.Special.SignalNoiseForGuiding.ToString("0.00"))); return(false); }
public IntelCPU(string name, uint family, uint model, uint stepping, uint[,] cpuidData, uint[,] cpuidExtData) { this.name = name; this.icon = Utilities.EmbeddedResources.GetImage("cpu.png"); logicalProcessors = 0; if (cpuidData.GetLength(0) > 0x0B) { uint eax, ebx, ecx, edx; WinRing0.CpuidEx(0x0B, 0, out eax, out ebx, out ecx, out edx); logicalProcessorsPerCore = ebx & 0xFF; if (logicalProcessorsPerCore > 0) { WinRing0.CpuidEx(0x0B, 1, out eax, out ebx, out ecx, out edx); logicalProcessors = ebx & 0xFF; } } if (logicalProcessors <= 0 && cpuidData.GetLength(0) > 0x04) { logicalProcessors = ((cpuidData[4, 0] >> 26) & 0x3F) + 1; logicalProcessorsPerCore = 1; } if (logicalProcessors <= 0) { logicalProcessors = 1; logicalProcessorsPerCore = 1; } coreCount = logicalProcessors / logicalProcessorsPerCore; switch (family) { case 0x06: { switch (model) { case 0x0F: // Intel Core 65nm switch (stepping) { case 0x06: // B2 switch (coreCount) { case 2: tjMax = 80; break; case 4: tjMax = 90; break; default: tjMax = 85; break; } tjMax = 80; break; case 0x0B: // G0 tjMax = 90; break; case 0x0D: // M0 tjMax = 85; break; default: tjMax = 85; break; } break; case 0x17: // Intel Core 45nm tjMax = 100; break; case 0x1C: // Intel Atom tjMax = 90; break; case 0x1A: uint eax = 0, edx = 0; if (WinRing0.RdmsrPx( IA32_TEMPERATURE_TARGET, ref eax, ref edx, (UIntPtr)1)) { tjMax = (eax >> 16) & 0xFF; } else { tjMax = 100; } break; default: tjMax = 100; break; } } break; default: tjMax = 100; break; } totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this); coreTemperatures = new Sensor[coreCount]; coreLoads = new Sensor[coreCount]; for (int i = 0; i < coreTemperatures.Length; i++) { coreTemperatures[i] = new Sensor("Core #" + (i + 1), i, tjMax, SensorType.Temperature, this); coreLoads[i] = new Sensor("Core #" + (i + 1), i + 1, SensorType.Load, this); } cpuLoad = new CPULoad(coreCount, logicalProcessorsPerCore); if (cpuLoad.IsAvailable) { foreach (Sensor sensor in coreLoads) { ActivateSensor(sensor); } ActivateSensor(totalLoad); } Update(); }
public mxNumericArray(uint[,] values) : this(BitConverterExtesions.GetBytes(values), values.GetLength(0), values.GetLength(1), mxNumericType.UINT32) { }
public static unsafe void ComputeSingle( uint[,] iterations, int startScanline, int increment, double offsetX, double offsetY, double zoom, uint maxIterations, ref bool cancel) { const int stride = 8; int height = iterations.GetLength(0); int width = iterations.GetLength(1); var maxIter = Vector256.Create((float)maxIterations); var limit = Vector256.Create(4.0f); var one = Vector256.Create(1.0f); var two = Vector256.Create(2.0f); float *results = stackalloc float[stride]; for (int i = startScanline; i < height && !cancel; i += increment) { for (int j = 0; j < width && !cancel; j += stride) { var c0 = Impl.GetPointCoordinate(j + 0, i, width, height, offsetX, offsetY, zoom); var c1 = Impl.GetPointCoordinate(j + 1, i, width, height, offsetX, offsetY, zoom); var c2 = Impl.GetPointCoordinate(j + 2, i, width, height, offsetX, offsetY, zoom); var c3 = Impl.GetPointCoordinate(j + 3, i, width, height, offsetX, offsetY, zoom); var c4 = Impl.GetPointCoordinate(j + 4, i, width, height, offsetX, offsetY, zoom); var c5 = Impl.GetPointCoordinate(j + 5, i, width, height, offsetX, offsetY, zoom); var c6 = Impl.GetPointCoordinate(j + 6, i, width, height, offsetX, offsetY, zoom); var c7 = Impl.GetPointCoordinate(j + 7, i, width, height, offsetX, offsetY, zoom); var cr = Vector256.Create((float)c0.X, (float)c1.X, (float)c2.X, (float)c3.X, (float)c4.X, (float)c5.X, (float)c6.X, (float)c7.X); var ci = Vector256.Create((float)c0.Y, (float)c1.Y, (float)c2.Y, (float)c3.Y, (float)c4.Y, (float)c5.Y, (float)c6.Y, (float)c7.Y); var zr = cr; var zi = ci; var it = Vector256.Create(0f); for (;;) { var zr2 = Avx.Multiply(zr, zr); var zi2 = Avx.Multiply(zi, zi); var squaredMagnitude = Avx.Add(zr2, zi2); var cond = Avx.And( Avx.Compare(squaredMagnitude, limit, FloatComparisonMode.OrderedLessThanOrEqualNonSignaling), Avx.Compare(it, maxIter, FloatComparisonMode.OrderedLessThanOrEqualNonSignaling)); if (Avx.MoveMask(cond) == 0) { Avx.Store(results, it); if (j + 0 < width) { iterations[i, j + 0] = (uint)results[0] % maxIterations; } if (j + 1 < width) { iterations[i, j + 1] = (uint)results[1] % maxIterations; } if (j + 2 < width) { iterations[i, j + 2] = (uint)results[2] % maxIterations; } if (j + 3 < width) { iterations[i, j + 3] = (uint)results[3] % maxIterations; } if (j + 4 < width) { iterations[i, j + 4] = (uint)results[4] % maxIterations; } if (j + 5 < width) { iterations[i, j + 5] = (uint)results[5] % maxIterations; } if (j + 6 < width) { iterations[i, j + 6] = (uint)results[6] % maxIterations; } if (j + 7 < width) { iterations[i, j + 7] = (uint)results[7] % maxIterations; } break; } zi = Fma.MultiplyAdd(two, Avx.Multiply(zr, zi), ci); zr = Avx.Add(Avx.Subtract(zr2, zi2), cr); it = Avx.Add(it, Avx.And(one, cond)); } } } }
public string GetDataAsHtml(GameVersion version, T8BTTA strategy, TSS.TSSFile stringDic, Dictionary <uint, TSS.TSSEntry> inGameIdDict) { StringBuilder sb = new StringBuilder(); //sb.Append( RefString ); sb.Append("<tr>"); sb.Append("<td colspan=\"5\">"); sb.Append("<span class=\"itemname\">"); sb.Append(inGameIdDict[NameStringDicID].StringJpnHtml(version)); sb.Append("</span>"); sb.Append("<br>"); sb.Append(inGameIdDict[DescStringDicID].StringJpnHtml(version)); sb.Append("</td>"); sb.Append("<td colspan=\"5\">"); sb.Append("<span class=\"itemname\">"); sb.Append(inGameIdDict[NameStringDicID].StringEngHtml(version)); sb.Append("</span>"); sb.Append("<br>"); sb.Append(inGameIdDict[DescStringDicID].StringEngHtml(version)); sb.Append("</td>"); sb.Append("</tr>"); sb.Append("<tr>"); sb.Append("<td>"); sb.Append("</td>"); for (int i = 0; i < StrategyDefaults.GetLength(1); ++i) { sb.Append("<td class=\"strategychar\">"); Website.GenerateWebsite.AppendCharacterBitfieldAsImageString(sb, version, 1u << i); sb.Append("</td>"); } sb.Append("</tr>"); for (uint xRaw = 0; xRaw < StrategyDefaults.GetLength(0); ++xRaw) { uint x = xRaw; // swap around OVL and FS because they're stored the wrong way around compared to how they show up ingame if (x == 6) { x = 7; } else if (x == 7) { x = 6; } sb.Append("<tr>"); sb.Append("<td>"); sb.Append("<span class=\"strategycat\">"); sb.Append(GetCategoryName(x, version, inGameIdDict)); sb.Append("</span>"); sb.Append("</td>"); for (uint y = 0; y < StrategyDefaults.GetLength(1); ++y) { if (version == GameVersion.X360 && y == 8) { continue; } sb.Append("<td>"); var option = strategy.StrategyOptionDict[StrategyDefaults[x, y]]; sb.Append(inGameIdDict[option.NameStringDicID].StringEngOrJpnHtml(version)); sb.Append("</td>"); } sb.Append("</tr>"); } //sb.Append( "<td>" ); //for ( int i = 0; i < UnknownFloats1.Length; ++i ) { // sb.Append( UnknownFloats1[i] + " / " ); //} //sb.Append( "<br>" ); //for ( int i = 0; i < UnknownFloats2.Length; ++i ) { // sb.Append( UnknownFloats2[i] + " / " ); //} //sb.Append( "</td>" ); return(sb.ToString()); }