public UVRect(Rect fullUVRect, Rect subRect, RotateFlip rotateFlip) { _fullUVRect = fullUVRect; _subRect = subRect; _rotateFlip = rotateFlip; _correctedRect = new Rect(); CalcCorrectedRect(); }
public TextureStack Rotate(RotateFlip rotation) { if (!Infos.Any()) { return(this); } Infos.Last().Rotation = rotation; return(this); }
/// <summary> /// Overrides the ToString() method from the base class MediaUrlOptions /// </summary> /// <returns>The manipulated string</returns> public override string ToString() { if (UseCustomFunctions) { var urlString = new UrlString(); urlString.Add("useCustomFunctions", 1.ToString(CultureInfo.InvariantCulture)); if (KeepOrientation) { urlString.Add("keepOrientation", 1.ToString(CultureInfo.InvariantCulture)); } if (GreyScale) { urlString.Add("greyScale", 1.ToString(CultureInfo.InvariantCulture)); } if (!RotateFlip.ToString().Equals("RotateNoneFlipNone")) { urlString.Add("rotateFlip", RotateFlip.ToString()); } if (CenterCrop) { urlString.Add("centerCrop", 1.ToString(CultureInfo.InvariantCulture)); } if (ImageCrop != null) { urlString.Add("cropX", _mCropStartX.ToString(CultureInfo.InvariantCulture)); urlString.Add("cropY", _mCropStartY.ToString(CultureInfo.InvariantCulture)); } string finalString; if (!string.IsNullOrEmpty(base.ToString())) { finalString = "&" + urlString; } else { finalString = urlString.ToString(); } return(base.ToString() + finalString); } return(base.ToString()); }
/// <summary> /// Rotates, flips, or rotates and flips the <see cref="Image"/>, and returns re-sized image. /// </summary> /// <param name="dst">The destination <see cref="Image"/>. Can be <b>null</b>.</param> /// <param name="rotateFlipType">A <see cref="RotateFlip"/> member that specifies the type of rotation and flip to apply to the image.</param> /// <returns> /// The destination <see cref="Image"/>. /// </returns> public Image RotateFlip(Image dst, RotateFlip rotateFlipType) { switch (rotateFlipType) { case Imaging.RotateFlip.Rotate90FlipNone: case Imaging.RotateFlip.Rotate90FlipX: case Imaging.RotateFlip.Rotate90FlipY: dst = this.Rotate90(dst); break; case Imaging.RotateFlip.Rotate180FlipNone: case Imaging.RotateFlip.Rotate180FlipX: case Imaging.RotateFlip.Rotate180FlipY: dst = this.Flip(dst, FlipAxis.Both); break; case Imaging.RotateFlip.Rotate270FlipNone: case Imaging.RotateFlip.Rotate270FlipX: case Imaging.RotateFlip.Rotate270FlipY: dst = this.Rotate270(dst); break; default: dst = this.Copy(dst, true); break; } switch (rotateFlipType) { case Imaging.RotateFlip.RotateNoneFlipX: case Imaging.RotateFlip.Rotate90FlipX: case Imaging.RotateFlip.Rotate180FlipX: case Imaging.RotateFlip.Rotate270FlipX: dst = dst.Flip(dst, FlipAxis.Y); break; case Imaging.RotateFlip.RotateNoneFlipY: case Imaging.RotateFlip.Rotate90FlipY: case Imaging.RotateFlip.Rotate180FlipY: case Imaging.RotateFlip.Rotate270FlipY: dst = dst.Flip(dst, FlipAxis.X); break; } return(dst); }
public void RotateFlip(SKBitmap image, RotateFlip infoRotation) { switch (infoRotation) { case Imaging.RotateFlip.Rotate180FlipNone: Rotate(image, 180); break; case Imaging.RotateFlip.Rotate270FlipNone: Rotate(image, 270); break; case Imaging.RotateFlip.Rotate90FlipNone: Rotate(image, 90); break; } }
/// <summary> /// Rotates and flips an image by the given instructions. /// </summary> /// <param name="source">The image to resize.</param> /// <param name="rotateType">The <see cref="RotateType"/> to perform the rotation.</param> /// <param name="flipType">The <see cref="FlipType"/> to perform the flip.</param> /// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param> /// <returns>The <see cref="Image"/></returns> public static Image RotateFlip(this Image source, RotateType rotateType, FlipType flipType, ProgressEventHandler progressHandler = null) { RotateFlip processor = new RotateFlip(rotateType, flipType); processor.OnProgress += progressHandler; try { return source.Process(source.Width, source.Height, source.Bounds, source.Bounds, processor); } finally { processor.OnProgress -= progressHandler; } }
private TextureStack GetTexture(string name, long data, TextureTranslation translation = null, RotateFlip rot = RotateFlip.RotateNoneFlipNone) { string texturePath = null; if (texturesJson.ContainsKey(name)) { var texture = texturesJson[name]; if (texture.Subtextures.Count <= data || data < 0) { //Console.WriteLine("Index out of bounds during GetTexture for {0}", name); texturePath = texture.Subtextures.First().Path; } else { texturePath = texture.Subtextures[(int)data].Path; } } if (texturePath == null) { return(null); } return(new TextureStack(texturePath, translation, rot)); }
public void RotateFlip(Bitmap image, RotateFlip infoRotation) { image.RotateFlip((RotateFlipType)infoRotation); }
static void CreateMesh(Mesh m, Sprite sprite, Vector2 size, Color color, bool isClipped, Rect clip, bool hcomp, bool vcomp, Vector2 tileOffset, RotateFlip rotateFlip, AnchorTo anchorTo) { var vertices = new List <Vector3>(); var uvs = new List <Vector2>(); var triangles = new List <int>(); float hbleed = hcomp ? 0.5f : 0f, vbleed = vcomp ? 0.5f : 0f; Vector4 border = sprite.Border; Vector2 texelSize = new Vector2(sprite.TexelWidth, sprite.TexelHeight);; bool tileH = sprite.TileHorizontal; bool tileV = sprite.TileVertical; if (anchorTo == AnchorTo.Center) { clip.x -= size.x / 2f; clip.y -= size.y / 2f; } if (rotateFlip != RotateFlip.None && (border.sqrMagnitude != 0 || tileH || tileV)) { throw new NotImplementedException("Rotation and flipping are not implemented for 9slice sprites!"); } var outer = Rect.MinMaxRect(0f, 0f, size.x, size.y); var inner = Rect.MinMaxRect( border.x, border.y, size.x - border.z, size.y - border.w ); var outerUV = Rect.MinMaxRect( sprite.UV.xMin + (sprite.Border.x > 0f ? hbleed : 0f) * sprite.TexelWidth, sprite.UV.yMin + (sprite.Border.y > 0f ? vbleed : 0f) * sprite.TexelHeight, sprite.UV.xMax - (sprite.Border.z > 0f ? hbleed : 0f) * sprite.TexelWidth, sprite.UV.yMax - (sprite.Border.w > 0f ? vbleed : 0f) * sprite.TexelHeight ); var innerUV = Rect.MinMaxRect( sprite.UV.xMin + (sprite.Border.x > 0f ? sprite.Border.x : hbleed) * sprite.TexelWidth, sprite.UV.yMin + (sprite.Border.y > 0f ? sprite.Border.y : vbleed) * sprite.TexelHeight, sprite.UV.xMax - (sprite.Border.z > 0f ? sprite.Border.z : hbleed) * sprite.TexelWidth, sprite.UV.yMax - (sprite.Border.w > 0f ? sprite.Border.w : vbleed) * sprite.TexelHeight ); // lower left corner if (border.x > 0f && border.y > 0f) { CreateQuad( Rect.MinMaxRect(outer.xMin, outer.yMin, inner.xMin, inner.yMin), new UVRect(outerUV, Rect.MinMaxRect(outerUV.xMin, outerUV.yMin, innerUV.xMin, innerUV.yMin), rotateFlip), isClipped, clip, vertices, uvs, triangles ); } // lower right corner if (border.z > 0f && border.y > 0f) { CreateQuad( Rect.MinMaxRect(inner.xMax, outer.yMin, outer.xMax, inner.yMin), new UVRect(outerUV, Rect.MinMaxRect(innerUV.xMax, outerUV.yMin, outerUV.xMax, innerUV.yMin), rotateFlip), isClipped, clip, vertices, uvs, triangles ); } // upper left corner if (border.x > 0f && border.w > 0f) { CreateQuad( Rect.MinMaxRect(outer.xMin, inner.yMax, inner.xMin, outer.yMax), new UVRect(outerUV, Rect.MinMaxRect(outerUV.xMin, innerUV.yMax, innerUV.xMin, outerUV.yMax), rotateFlip), isClipped, clip, vertices, uvs, triangles ); } // upper right corner if (border.z > 0f && border.w > 0f) { CreateQuad( Rect.MinMaxRect(inner.xMax, inner.yMax, outer.xMax, outer.yMax), new UVRect(outerUV, Rect.MinMaxRect(innerUV.xMax, innerUV.yMax, outerUV.xMax, outerUV.yMax), rotateFlip), isClipped, clip, vertices, uvs, triangles ); } // left and right sides if (tileV) { var tHeight = innerUV.height / texelSize.y; var tOffset = tileOffset.y < 0f ? tHeight + tileOffset.y : tileOffset.y; var from = inner.yMin; var to = Math.Min(inner.yMin + (tHeight - tOffset), inner.yMax); var fromUV = innerUV.yMin + tOffset * texelSize.y; while (from < inner.yMax) { var toUV = fromUV + (to - from) * texelSize.y; // left if (border.x > 0f) { CreateQuad( Rect.MinMaxRect(outer.xMin, from, inner.xMin, to), new UVRect(outerUV, Rect.MinMaxRect(outerUV.xMin, fromUV, innerUV.xMin, toUV), rotateFlip), isClipped, clip, vertices, uvs, triangles ); } // right if (border.z > 0f) { CreateQuad( Rect.MinMaxRect(inner.xMax, from, outer.xMax, to), new UVRect(outerUV, Rect.MinMaxRect(innerUV.xMax, fromUV, outerUV.xMax, toUV), rotateFlip), isClipped, clip, vertices, uvs, triangles ); } // middle if (!sprite.IsHollow) { if (!tileH) { CreateQuad( Rect.MinMaxRect(inner.xMin, from, inner.xMax, to), new UVRect(outerUV, Rect.MinMaxRect(innerUV.xMin, fromUV, innerUV.xMax, toUV), rotateFlip), isClipped, clip, vertices, uvs, triangles ); } else { // awkward nested case here, tile the middle both ways var tWidth = innerUV.width / texelSize.x; var tOffsetW = tileOffset.x < 0f ? tWidth + tileOffset.x : tileOffset.x; var fromW = inner.xMin; var toW = Math.Min(inner.xMin + (tWidth - tOffsetW), inner.xMax); var fromUVW = innerUV.xMin + tOffsetW * texelSize.x; while (fromW < inner.xMax) { var toUVW = fromUVW + (toW - fromW) * texelSize.x; CreateQuad( Rect.MinMaxRect(fromW, from, toW, to), new UVRect(outerUV, Rect.MinMaxRect(fromUVW, fromUV, toUVW, toUV), rotateFlip), isClipped, clip, vertices, uvs, triangles ); fromW = toW; toW = Math.Min(toW + tWidth, inner.xMax); fromUVW = innerUV.xMin; } } } from = to; to = Math.Min(to + tHeight, inner.yMax); fromUV = innerUV.yMin; } } else { // left if (border.x > 0f) { CreateQuad( Rect.MinMaxRect(outer.xMin, inner.yMin, inner.xMin, inner.yMax), new UVRect(outerUV, Rect.MinMaxRect(outerUV.xMin, innerUV.yMin, innerUV.xMin, innerUV.yMax), rotateFlip), isClipped, clip, vertices, uvs, triangles ); } // right if (border.z > 0f) { CreateQuad( Rect.MinMaxRect(inner.xMax, inner.yMin, outer.xMax, inner.yMax), new UVRect(outerUV, Rect.MinMaxRect(innerUV.xMax, innerUV.yMin, outerUV.xMax, innerUV.yMax), rotateFlip), isClipped, clip, vertices, uvs, triangles ); } } // top and bottom sides if (tileH) { var tWidth = innerUV.width / texelSize.x; var tOffset = tileOffset.x < 0f ? tWidth + tileOffset.x : tileOffset.x; var from = inner.xMin; var to = Math.Min(inner.xMin + (tWidth - tOffset), inner.xMax); var fromUV = innerUV.xMin + tOffset * texelSize.x; while (from < inner.xMax) { var toUV = fromUV + (to - from) * texelSize.x; // bottom if (border.y > 0f) { CreateQuad( Rect.MinMaxRect(from, outer.yMin, to, inner.yMin), new UVRect(outerUV, Rect.MinMaxRect(fromUV, outerUV.yMin, toUV, innerUV.yMin), rotateFlip), isClipped, clip, vertices, uvs, triangles ); } // top if (border.w > 0f) { CreateQuad( Rect.MinMaxRect(from, inner.yMax, to, outer.yMax), new UVRect(outerUV, Rect.MinMaxRect(fromUV, innerUV.yMax, toUV, outerUV.yMax), rotateFlip), isClipped, clip, vertices, uvs, triangles ); } // middle if (!sprite.IsHollow && !tileV) { CreateQuad( Rect.MinMaxRect(from, inner.yMin, to, inner.yMax), new UVRect(outerUV, Rect.MinMaxRect(fromUV, innerUV.yMin, toUV, innerUV.yMax), rotateFlip), isClipped, clip, vertices, uvs, triangles ); } from = to; to = Math.Min(to + tWidth, inner.xMax); fromUV = innerUV.xMin; } } else { // bottom if (border.y > 0f) { CreateQuad( Rect.MinMaxRect(inner.xMin, outer.yMin, inner.xMax, inner.yMin), new UVRect(outerUV, Rect.MinMaxRect(innerUV.xMin, outerUV.yMin, innerUV.xMax, innerUV.yMin), rotateFlip), isClipped, clip, vertices, uvs, triangles ); } // top if (border.w > 0f) { CreateQuad( Rect.MinMaxRect(inner.xMin, inner.yMax, inner.xMax, outer.yMax), new UVRect(outerUV, Rect.MinMaxRect(innerUV.xMin, innerUV.yMax, innerUV.xMax, outerUV.yMax), rotateFlip), isClipped, clip, vertices, uvs, triangles ); } } // middle if (!tileH && !tileV && !sprite.IsHollow) { CreateQuad(inner, new UVRect(outerUV, innerUV, rotateFlip), isClipped, clip, vertices, uvs, triangles); } if (anchorTo == AnchorTo.Center) { var extents = new Vector3(size.x / 2f, size.y / 2f, 0f); m.vertices = vertices.Select(v => v - extents).ToArray(); } else { m.vertices = vertices.ToArray(); } m.uv = uvs.ToArray(); m.triangles = triangles.ToArray(); m.normals = vertices.Select(v => new Vector3(0f, 0f, -1f)).ToArray(); m.colors = vertices.Select(v => color).ToArray(); m.RecalculateBounds(); }
public TextureStack(string filename, TextureTranslation translation, RotateFlip rotation) { Infos.Add(new TextureInfo(filename, translation, rotation)); }
public TextureInfo(string filename, TextureTranslation translation, RotateFlip rotation) { Filename = filename; Translation = translation; Rotation = rotation; }