public void set4pixel(int x, int y, PixelSet pixelSet) { tex.SetPixel(x * 2, y * 2, colorSet[pixelSet.col[0]]); tex.SetPixel(x * 2 + 1, y * 2, colorSet[pixelSet.col[1]]); tex.SetPixel(x * 2, y * 2 + 1, colorSet[pixelSet.col[2]]); tex.SetPixel(x * 2 + 1, y * 2 + 1, colorSet[pixelSet.col[3]]); }
private void _RotateCorners(PixelSet pixelSet) { Matrix rotationMatrix = new Matrix(); rotationMatrix.RotateAt(_angle, pixelSet.MiddlePoint); rotationMatrix.TransformPoints(pixelSet.Corners); }
public void DrawImage() { int width = MainManager.width; int height = MainManager.height; colorSet = MainManager.colorSet; tex = new Texture2D(width * 2, height * 2, TextureFormat.RGBA32, false); tex.filterMode = FilterMode.Point; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { PixelSet pixelSet = new PixelSet(); if (enable4cdiff) { pixelSet = MainManager.FourCdiff(MainManager.frames[MainManager.selectFrame].colors[y * MainManager.width + x]); } else { pixelSet = MainManager.FindBetterColor(MainManager.frames[MainManager.selectFrame].colors[y * MainManager.width + x]); } tex.SetPixel(x * 2, y * 2, colorSet[pixelSet.col[0]]); set4pixel(x, y, pixelSet); } } tex.Apply(); image.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero); }
internal static void Apply(BorderStyle borderStyle, PixelSet pixelSet) { if (borderStyle == BorderStyle.Black) { ApplyBlack(pixelSet); } }
public override async Task Handle(CancellationToken cancellationToken) { var pixelTransition = new List <PixelSet>(); var zeroPixelSet = new PixelSet(); var pixelSet = new PixelSet(); var random = new Random(); int red, green, blue; do { red = possiblePixelValues[random.Next(3)]; green = possiblePixelValues[random.Next(3)]; blue = possiblePixelValues[random.Next(3)]; } while ((red == 0 && green == 0 && blue == 0) || (red == 20 && green == 20 && blue == 20)); for (var i = 0; i < Consts.PixelCount; i++) { zeroPixelSet.Pixels.Add(new Pixel(i, 0, 0, 0)); pixelSet.Pixels.Add(new Pixel(i, red, green, blue)); } pixelTransition.Add(pixelSet); pixelTransition.Add(zeroPixelSet); NeopixelCompiler.RunPixelTransition(5, pixelTransition); await CompleteJob(new { jobStatus = Statuses.Success.ToString() }); }
public void Process(PixelSet pixelSet) { pixelSet.MiddlePoint = (Point)(pixelSet.MiddlePoint + _vector); foreach (Point point in pixelSet.GetPoints()) { pixelSet.ChangeLocation(point, (Point)(point + _vector)); } }
public static PixelSet FourCdiff(Color goalColor) { PixelSet pixelSet = new PixelSet(); for (int i = 0; i < 4; i++) { pixelSet.col[i] = FindNearColor(goalColor, 4); goalColor -= colorSet[pixelSet.col[i]] / 4; } return(pixelSet); }
public override async Task Handle(CancellationToken cancellationToken) { var zeroPixelSet = new PixelSet(); for (var i = 0; i < Consts.PixelCount; i++) { zeroPixelSet.Pixels.Add(new Pixel(i, 0, 0, 0)); } NeopixelCompiler.SetPixels(zeroPixelSet.Pixels); await CompleteJob(new { jobStatus = Statuses.Success.ToString() }); }
public override void Draw(PaintTools paintTools) { PixelSet pixels = _rotator.GetRotated(_currentAngle); for (int i = 0; i < pixels.Locations.Length; ++i) { Point translatedPoint = (Point)(pixels.Locations[i] + _moveVector); paintTools.Bitmap.SetPixel(translatedPoint.X, translatedPoint.Y, pixels.Colors[i]); } }
public void ShouldAddBlackBorderNearSide() { PixelSet ps = new PixelSet(5, 5); ps.Pixels[2, 0] = Pixel.Red; BorderHelper.ApplyBlack(ps); ps.Pixels[2, 0].Should().Be(Pixel.Red); ps.Pixels[1, 0].Should().Be(Pixel.Black); ps.Pixels[3, 0].Should().Be(Pixel.Black); ps.Pixels[2, 1].Should().Be(Pixel.Black); }
// Update is called once per frame void Update() { if (testMode) { PixelSet pixelSet1 = FourCdiff(requestColor); PixelSet pixelSet2 = FindBetterColor(requestColor); requestImg.color = requestColor; showColorSources(0, pixelSet1.col[0], pixelSet1.col[1], pixelSet1.col[2], pixelSet1.col[3]); showColorSources(1, pixelSet2.col[0], pixelSet2.col[1], pixelSet2.col[2], pixelSet2.col[3]); resultImg[0].color = avg4color(pixelSet1); resultImg[1].color = avg4color(pixelSet2); resultImg[2].color = colorSet[FindNearColor(requestColor)]; } if (Input.GetKeyDown(KeyCode.RightArrow)) { selectFrame++; if (selectFrame >= frame) { selectFrame = 0; } originalManager.DrawImage(); resultManager.DrawImage(); } if (useLowspeedModel && Input.GetKeyDown(KeyCode.R)) { result4Manager[1].DrawImage(); } if (use4cdiff && Input.GetKeyDown(KeyCode.R)) { result4Manager[0].DrawImage(); } if (Input.GetKeyDown(KeyCode.E)) { if (useFloydSteinberg) { floyedManager.export(); } else if (use4cdiff) { result4Manager[0].export(); } else if (useLowspeedModel) { result4Manager[1].export(); } else if (useSimpleModel) { resultManager.export(); } } }
public override async Task Handle(CancellationToken cancellationToken) { const int TransitionSize = 60; const int Transition1Break = 60; const int Transition2Break = 120; const int Transition3Break = 180; const int Transition4Break = 240; const int Transition5Break = 300; var pixelTransition = new List <PixelSet>(); var zeroPixelSet = new PixelSet(); var pixelSet = new PixelSet(); var brightness = 0.25; for (var pixelIndex = 0; pixelIndex < Consts.PixelCount; pixelIndex++) { zeroPixelSet.Pixels.Add(new Pixel(pixelIndex, 0, 0, 0)); if (pixelIndex < Transition1Break) { pixelSet.Pixels.Add(new Pixel(pixelIndex, 255, 0 + 127 * pixelIndex / TransitionSize, 0, brightness)); } else if (pixelIndex < Transition2Break) { var transitionRelativePixelIndex = pixelIndex - Transition1Break; pixelSet.Pixels.Add(new Pixel(pixelIndex, 255, 127 + 128 * transitionRelativePixelIndex / TransitionSize, 0, brightness)); } else if (pixelIndex < Transition3Break) { var transitionRelativePixelIndex = pixelIndex - Transition2Break; pixelSet.Pixels.Add(new Pixel(pixelIndex, 255 - 255 * transitionRelativePixelIndex / TransitionSize, 255, 0, brightness)); } else if (pixelIndex < Transition4Break) { var transitionRelativePixelIndex = pixelIndex - Transition3Break; pixelSet.Pixels.Add(new Pixel(pixelIndex, 0, 255 - 255 * transitionRelativePixelIndex / TransitionSize, 0 + 255 * transitionRelativePixelIndex / TransitionSize, brightness)); } else if (pixelIndex < Transition5Break) { var transitionRelativePixelIndex = pixelIndex - Transition4Break; pixelSet.Pixels.Add(new Pixel(pixelIndex, 0 + 143 * transitionRelativePixelIndex / TransitionSize, 0, 255, brightness)); } } pixelTransition.Add(pixelSet); pixelTransition.Add(zeroPixelSet); NeopixelCompiler.RunPixelTransition(5, pixelTransition); await CompleteJob(new { jobStatus = Statuses.Success.ToString() }); }
public override void Process(PixelSet pixelSet) { _RotateCorners(pixelSet); Point[] rotatedPoints = (new PolygonPointsGenerator(pixelSet.Corners)).GetPoints(); Point[] initialPoints = _GetInitialPoints(_angle, rotatedPoints, pixelSet.MiddlePoint); Color[] colors = new Color[initialPoints.Length]; for (int i = 0; i < initialPoints.Length; ++i) { colors[i] = pixelSet.GetColor(initialPoints[i].X, initialPoints[i].Y); } pixelSet.SetPixels(rotatedPoints, colors); }
public override void Draw(PaintTools paintTools) { BezierCurve bezierCurve = _polyline.GetBezierCurve(); FreeVector tangentVector = bezierCurve.GetTangentVector(_bezierPointNumber); Point curvePoint = bezierCurve.GetPoint(_bezierPointNumber); float angle = (new FreeVector(new Point(1, 0))).GetAngleWith(tangentVector); PixelSet points = _rotator.GetRotated(angle); FreeVector translateVector = new FreeVector(_imageMiddle, curvePoint); for (int i = 0; i < points.Locations.Length; ++i) { Point translatedPoint = (Point)(points.Locations[i] + translateVector); paintTools.Bitmap.SetPixel(translatedPoint.X, translatedPoint.Y, points.Colors[i]); } }
public PixelSet LoadImage(string filename) { Image loadImage = Image.FromFile(filename); Bitmap bitmap = new Bitmap(loadImage); PixelSet pixelSet = new PixelSet(loadImage.Width, loadImage.Height); for (int i = 0; i < loadImage.Width - 1; i++) { for (int j = 0; j < loadImage.Height - 1; j++) { pixelSet.Pixels[i, j] = PixelHelper.Create(bitmap.GetPixel(i, j)); } } return(pixelSet); }
private Bitmap CreateImage(PixelSet pixelSet) { Pixel[,] pixels = pixelSet.Pixels; Bitmap previewImage = new Bitmap(pixelSet.Width, pixelSet.Height); for (int i = 0; i < pixelSet.Width - 1; i++) { for (int j = 0; j < pixelSet.Height - 1; j++) { Color col = PixelHelper.PixelColor(pixels[i, j]); previewImage.SetPixel(i, j, col); } } return(previewImage); }
public override async Task Handle(CancellationToken cancellationToken) { var length = Job.Payload.SelectToken("$.length")?.ToObject <int>(); var red = Job.Payload.SelectToken("$.red")?.ToObject <int>(); var green = Job.Payload.SelectToken("$.green")?.ToObject <int>(); var blue = Job.Payload.SelectToken("$.blue")?.ToObject <int>(); var pixelTransition = new List <PixelSet>(); for (var leadPixelIndex = 0; leadPixelIndex < Consts.PixelCount + length; leadPixelIndex++) { var pixelSet = new PixelSet(); pixelSet.Pixels.AddRange(GetPixels(leadPixelIndex, red ?? 0, green ?? 0, blue ?? 0, length ?? 5)); pixelTransition.Add(pixelSet); } NeopixelCompiler.RunPixelTransition(0, pixelTransition); await CompleteJob(new { jobStatus = Statuses.Success.ToString() }); }
public void export() { int width = MainManager.width; int height = MainManager.height; int frame = MainManager.frame; colorSet = MainManager.colorSet; int[,] idArray = new int[width * 2, height * 2]; string strOut = (width * 2).ToString() + "," + (height * 2).ToString() + "," + frame.ToString(); Debug.Log("Exporting" + width); for (int f = 0; f < frame; f++) { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { PixelSet pixelSet = new PixelSet(); if (enable4cdiff) { pixelSet = MainManager.FourCdiff(MainManager.frames[f].colors[y * MainManager.width + x]); } else { pixelSet = MainManager.FindBetterColor(MainManager.frames[f].colors[y * MainManager.width + x]); } idArray[x * 2, y * 2] = pixelSet.col[0]; idArray[x * 2, y * 2 + 1] = pixelSet.col[1]; idArray[x * 2 + 1, y * 2] = pixelSet.col[2]; idArray[x * 2 + 1, y * 2 + 1] = pixelSet.col[3]; } } for (int y = 0; y < height * 2; y++) { for (int x = 0; x < width * 2; x++) { strOut += "," + idArray[x, y].ToString(); } } } Debug.Log(strOut); Debug.Log(MainManager.exportPath); File.WriteAllText(MainManager.exportPath, strOut); }
internal static void ApplyBlack(PixelSet pixelSet) { for (int x = 0; x < pixelSet.Width; x++) { for (int y = 0; y < pixelSet.Height; y++) { if (!pixelSet.Pixels[x, y].IsEmpty && !pixelSet.Pixels[x, y].IsBlackout) { if (x < pixelSet.Width - 1) { if (pixelSet.Pixels[x + 1, y].IsEmpty) { pixelSet.SetPixel(x + 1, y, Pixel.Black); } } if (x > 0) { if (pixelSet.Pixels[x - 1, y].IsEmpty) { pixelSet.SetPixel(x - 1, y, Pixel.Black); } } if (y < pixelSet.Height - 1) { if (pixelSet.Pixels[x, y + 1].IsEmpty) { pixelSet.SetPixel(x, y + 1, Pixel.Black); } } if (y > 0) { if (pixelSet.Pixels[x, y - 1].IsEmpty) { pixelSet.SetPixel(x, y - 1, Pixel.Black); } } } } } }
public static PixelSet FindBetterColor(Color goalColor) { float minDiff = Mathf.Infinity; int colorA = 0; int colorB = 0; int colorC = 0; int colorD = 0; for (int a = 0; a < MainManager.colorCount; a++) { for (int b = 0; b < MainManager.colorCount; b++) { for (int c = 0; c < MainManager.colorCount; c++) { for (int d = 0; d < MainManager.colorCount; d++) { float diff = colorSqrtDiff(goalColor, colorEncoded[a, b, c, d]); if (minDiff > diff) { minDiff = diff; colorA = a; colorB = b; colorC = c; colorD = d; } } } } } PixelSet pixelSet = new PixelSet(); pixelSet.col[0] = colorA; pixelSet.col[1] = colorB; pixelSet.col[2] = colorC; pixelSet.col[3] = colorD; return(pixelSet); }
public abstract void Process(PixelSet pixelSet);
Color avg4color(PixelSet pixelSet) { return(avg4color(pixelSet.col[0], pixelSet.col[1], pixelSet.col[2], pixelSet.col[3])); }
private void InportFromUnity(object sender, EventArgs e) { string filename = @"C:\GitHub\eWolfPixel\Pixel\eWolfUnity3DParser.UnitTests\TestingData\Player04.png"; SpriteSheetData spriteSheetData = SpriteParser.ParseLoad(filename + ".meta"); // spin up a bitmap reader to read the image and create pixelSets for each sprite. PixelSet image = ServiceLocator.Instance.GetService <IPixelLoader>().LoadImage(filename); Dictionary <string, PixelSet> frames = image.CutFrames(spriteSheetData); ProjectHolder projectHolder = ServiceLocator.Instance.GetService <ProjectHolder>(); AnimationDetails ad = new AnimationDetails($"Walk", "\\Root\\Char1"); projectHolder.Items.Add(ad); ad.PostLoadFix(); // PL04_DownLeft_Walk0 List <PixelSet> leftWalk = new List <PixelSet>(); leftWalk.Add(frames["PL04_Left_Walk0"]); leftWalk.Add(frames["PL04_Left_Walk1"]); leftWalk.Add(frames["PL04_Left_Walk0"]); leftWalk.Add(frames["PL04_Left_Walk2"]); AddFrameToAnim(Directions8Way.Left, ad, leftWalk); List <PixelSet> downLeftWalk = new List <PixelSet>(); downLeftWalk.Add(frames["PL04_DownLeft_Walk0"]); downLeftWalk.Add(frames["PL04_DownLeft_Walk1"]); downLeftWalk.Add(frames["PL04_DownLeft_Walk0"]); downLeftWalk.Add(frames["PL04_DownLeft_Walk2"]); AddFrameToAnim(Directions8Way.DownLeft, ad, downLeftWalk); List <PixelSet> downRightWalk = new List <PixelSet>(); downRightWalk.Add(frames["PL04_DownRight_Walk0"]); downRightWalk.Add(frames["PL04_DownRight_Walk1"]); downRightWalk.Add(frames["PL04_DownRight_Walk0"]); downRightWalk.Add(frames["PL04_DownRight_Walk2"]); AddFrameToAnim(Directions8Way.DownRight, ad, downRightWalk); List <PixelSet> rightWalk = new List <PixelSet>(); rightWalk.Add(frames["PL04_Right_Walk0"]); rightWalk.Add(frames["PL04_Right_Walk1"]); rightWalk.Add(frames["PL04_Right_Walk0"]); rightWalk.Add(frames["PL04_Right_Walk2"]); AddFrameToAnim(Directions8Way.Right, ad, rightWalk); List <PixelSet> upLeftWalk = new List <PixelSet>(); upLeftWalk.Add(frames["PL04_UpLeft_Walk0"]); upLeftWalk.Add(frames["PL04_UpLeft_Walk1"]); upLeftWalk.Add(frames["PL04_UpLeft_Walk0"]); upLeftWalk.Add(frames["PL04_UpLeft_Walk2"]); AddFrameToAnim(Directions8Way.UpLeft, ad, upLeftWalk); List <PixelSet> upWalk = new List <PixelSet>(); upWalk.Add(frames["PL04_Up_Walk0"]); upWalk.Add(frames["PL04_Up_Walk1"]); upWalk.Add(frames["PL04_Up_Walk0"]); upWalk.Add(frames["PL04_Up_Walk2"]); AddFrameToAnim(Directions8Way.Up, ad, upWalk); List <PixelSet> downWalk = new List <PixelSet>(); downWalk.Add(frames["PL04_Down_Walk0"]); downWalk.Add(frames["PL04_Down_Walk1"]); downWalk.Add(frames["PL04_Down_Walk0"]); downWalk.Add(frames["PL04_Down_Walk2"]); AddFrameToAnim(Directions8Way.Down, ad, downWalk); List <PixelSet> upRightWalk = new List <PixelSet>(); upRightWalk.Add(frames["PL04_UpRight_Walk0"]); upRightWalk.Add(frames["PL04_UpRight_Walk1"]); upRightWalk.Add(frames["PL04_UpRight_Walk0"]); upRightWalk.Add(frames["PL04_UpRight_Walk2"]); AddFrameToAnim(Directions8Way.UpRight, ad, upRightWalk); ad.Save(projectHolder.ProjectPath); }