Hydrogen Framework  1.3.1
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Hydrogen.Texture Class Reference

Additional static functions used to extend existing Texture support inside of Unity. More...

Public Types

enum  WebColor {
  WebColor.None = 0, WebColor.AliceBlue = 0xf0f8ff, WebColor.Gainsboro = 0xdcdcdc, WebColor.MistyRose = 0xffe4e1,
  WebColor.AntiqueWhite = 0xfaebd7, WebColor.GhostWhite = 0xf8f8ff, WebColor.Moccasin = 0xffe4b5, WebColor.Aqua = 0x00ffff,
  WebColor.Gold = 0xffd700, WebColor.NavajoWhite = 0xffdead, WebColor.Aquamarine = 0x7fffd4, WebColor.Goldenrod = 0xdaa520,
  WebColor.Navy = 0x000080, WebColor.Azure = 0xf0ffff, WebColor.Gray = 0x808080, WebColor.OldLace = 0xfdf5e6,
  WebColor.Beige = 0xf5f5dc, WebColor.Green = 0x008000, WebColor.Olive = 0x808000, WebColor.Bisque = 0xffe4c4,
  WebColor.GreenYellow = 0xadff2f, WebColor.OliveDrab = 0x6b8e23, WebColor.Black = 0x000000, WebColor.Grey = 0x808080,
  WebColor.Orange = 0xffa500, WebColor.BlanchedAlmond = 0xffebcd, WebColor.Honeydew = 0xf0fff0, WebColor.OrangeRed = 0xff4500,
  WebColor.Blue = 0x0000ff, WebColor.HotPink = 0xff69b4, WebColor.Orchid = 0xda70d6, WebColor.BlueViolet = 0x8a2be2,
  WebColor.IndianRed = 0xcd5c5c, WebColor.PaleGoldenrod = 0xeee8aa, WebColor.Brown = 0xa52a2a, WebColor.Indigo = 0x4b0082,
  WebColor.PaleGreen = 0x98fb98, WebColor.Burlywood = 0xdeb887, WebColor.Ivory = 0xfffff0, WebColor.PaleTurquoise = 0xafeeee,
  WebColor.CadetBlue = 0x5f9ea0, WebColor.Khaki = 0xf0e68c, WebColor.PaleVioletRed = 0xdb7093, WebColor.Chartreuse = 0x7fff00,
  WebColor.Lavender = 0xe6e6fa, WebColor.PapayaWhip = 0xffefd5, WebColor.Chocolate = 0xd2691e, WebColor.LavenderBlush = 0xfff0f5,
  WebColor.PeachPuff = 0xffdab9, WebColor.Coral = 0xff7f50, WebColor.LawnGreen = 0x7cfc00, WebColor.Peru = 0xcd853f,
  WebColor.CornflowerBlue = 0x6495ed, WebColor.LemonChiffon = 0xfffacd, WebColor.Pink = 0xffc0cb, WebColor.Cornsilk = 0xfff8dc,
  WebColor.LightBlue = 0xadd8e6, WebColor.Plum = 0xdda0dd, WebColor.Crimson = 0xdc143c, WebColor.LightCoral = 0xf08080,
  WebColor.PowderBlue = 0xb0e0e6, WebColor.Cyan = 0x00ffff, WebColor.LightCyan = 0xe0ffff, WebColor.Purple = 0x800080,
  WebColor.DarkBlue = 0x00008b, WebColor.LightGoldenrodyellow = 0xfafad2, WebColor.Red = 0xff0000, WebColor.DarkCyan = 0x008b8b,
  WebColor.LightGray = 0xd3d3d3, WebColor.RosyBrown = 0xbc8f8f, WebColor.DarkGoldenrod = 0xb8860b, WebColor.LightGreen = 0x90ee90,
  WebColor.RoyalBlue = 0x4169e1, WebColor.DarkGray = 0xa9a9a9, WebColor.LightGrey = 0xd3d3d3, WebColor.SaddleBrown = 0x8b4513,
  WebColor.DarkGreen = 0x006400, WebColor.LightPink = 0xffb6c1, WebColor.Salmon = 0xfa8072, WebColor.DarkGrey = 0xa9a9a9,
  WebColor.LightSalmon = 0xffa07a, WebColor.SandyBrown = 0xf4a460, WebColor.DarkKhaki = 0xbdb76b, WebColor.LightSeagreen = 0x20b2aa,
  WebColor.SeaGreen = 0x2e8b57, WebColor.DarkMagenta = 0x8b008b, WebColor.LightSkyblue = 0x87cefa, WebColor.SeaShell = 0xfff5ee,
  WebColor.DarkOlivegreen = 0x556b2f, WebColor.LightSlategray = 0x778899, WebColor.Sienna = 0xa0522d, WebColor.DarkOrange = 0xff8c00,
  WebColor.LightSlategrey = 0x778899, WebColor.Silver = 0xc0c0c0, WebColor.DarkOrchid = 0x9932cc, WebColor.LightSteelblue = 0xb0c4de,
  WebColor.SkyBlue = 0x87ceeb, WebColor.DarkRed = 0x8b0000, WebColor.LightYellow = 0xffffe0, WebColor.SlateBlue = 0x6a5acd,
  WebColor.DarkSalmon = 0xe9967a, WebColor.Lime = 0x00ff00, WebColor.SlateGray = 0x708090, WebColor.DarkSeagreen = 0x8fbc8f,
  WebColor.LimeGreen = 0x32cd32, WebColor.SlateGrey = 0x708090, WebColor.DarkSlateblue = 0x483d8b, WebColor.Linen = 0xfaf0e6,
  WebColor.Snow = 0xfffafa, WebColor.DarkSlategray = 0x2f4f4f, WebColor.Magenta = 0xff00ff, WebColor.SpringGreen = 0x00ff7f,
  WebColor.DarkSlategrey = 0x2f4f4f, WebColor.Maroon = 0x800000, WebColor.SteelBlue = 0x4682b4, WebColor.DarkTurquoise = 0x00ced1,
  WebColor.MediumAquamarine = 0x66cdaa, WebColor.Tan = 0xd2b48c, WebColor.DarkViolet = 0x9400d3, WebColor.MediumBlue = 0x0000cd,
  WebColor.Teal = 0x008080, WebColor.DeepPink = 0xff1493, WebColor.MediumOrchid = 0xba55d3, WebColor.Thistle = 0xd8bfd8,
  WebColor.DeepSkyblue = 0x00bfff, WebColor.MediumPurple = 0x9370db, WebColor.Tomato = 0xff6347, WebColor.DimGray = 0x696969,
  WebColor.MediumSeaGreen = 0x3cb371, WebColor.Turquoise = 0x40e0d0, WebColor.DimGrey = 0x696969, WebColor.MediumSlateBlue = 0x7b68ee,
  WebColor.Violet = 0xee82ee, WebColor.DodgerBlue = 0x1e90ff, WebColor.MediumSpringGreen = 0x00fa9a, WebColor.Wheat = 0xf5deb3,
  WebColor.FireBrick = 0xb22222, WebColor.MediumTurquoise = 0x48d1cc, WebColor.White = 0xffffff, WebColor.FloralWhite = 0xfffaf0,
  WebColor.MediumBioletRed = 0xc71585, WebColor.WhiteSmoke = 0xf5f5f5, WebColor.ForestGreen = 0x228b22, WebColor.MidnightBlue = 0x191970,
  WebColor.Yellow = 0xffff00, WebColor.Fuchsia = 0xff00ff, WebColor.MintCream = 0xf5fffa, WebColor.YellowGreen = 0x9acd32
}
 Web Colors More...
 

Static Public Member Functions

static Color ToColor (this WebColor color)
 Convert a WebColor to a UnityEngine.Color More...
 
static Color ToColor (WebColor color, float alpha)
 Convert a WebColor to a UnityEngine.Color More...
 
static Texture2D AutoCrop (this Texture2D texture, Color borderColor)
 Autocrop the texture removes the borders from the texture. It searches the active layer for the largest possible border area that's color matches borderColor, and then crops this area from the image, as if you had used the Crop tool. More...
 
static void Blit (Texture2D destinationTexture, Texture2D sourceTexture, int offsetX, int offsetY)
 The pixels (RGB) of both the destinationTexture and the sourceTexture are combined bitwise according to the simplified overwrite raster operation, and the result is then written to the destinationTexture. More...
 
static void BlitAlpha (Texture2D destinationTexture, Texture2D sourceTexture, int offsetX, int offsetY)
 The pixels (RGBA) of both the destinationTexture and the sourceTexture are combined bitwise according to the simplified overwrite raster operation, and the result is then written to the destinationTexture. More...
 
static Texture2D Crop (this Texture2D sourceTexture, int offsetX, int offsetY, int width, int height)
 Crop the specified texture starting at (X,Y) and extending out based on the width and height. More...
 
static Texture2D FlipHorizontally (this Texture2D texture)
 Flip texture horizontally. More...
 
static Texture2D FlipVertically (this Texture2D texture)
 Flip texture vertically. More...
 
static Texture2D Resize (this Texture2D sourceTexture, int newWidth, int newHeight)
 Resize the texture to a specific width and height using bilinear filtering. More...
 
static Texture2D RotateClockwise90Degrees (this Texture2D texture)
 Rotate texture clockwise, 90 degrees. More...
 
static Texture2D RotateCounterClockwise90Degrees (this Texture2D texture)
 Rotate texture counter clockwise, 90 degrees. More...
 
static Texture2D Tile (this Texture2D texture, int horizontalTiles, int verticalTiles)
 Tile the specified texture as outlined. More...
 
static Texture2D Transpose (this Texture2D texture)
 Transpose texture. More...
 
static Texture2D TransposePerpendicular (this Texture2D texture)
 Transpose texture perpendicularily. More...
 

Public Attributes

const float HexInverse = 0.00392156863f
 Handy 1/255, useful for calculating color values. More...
 

Detailed Description

Additional static functions used to extend existing Texture support inside of Unity.

Definition at line 37 of file Texture.cs.

Member Enumeration Documentation

Web Colors

Enumerator
None 
AliceBlue 
Gainsboro 
MistyRose 
AntiqueWhite 
GhostWhite 
Moccasin 
Aqua 
Gold 
NavajoWhite 
Aquamarine 
Goldenrod 
Navy 
Azure 
Gray 
OldLace 
Beige 
Green 
Olive 
Bisque 
GreenYellow 
OliveDrab 
Black 
Grey 
Orange 
BlanchedAlmond 
Honeydew 
OrangeRed 
Blue 
HotPink 
Orchid 
BlueViolet 
IndianRed 
PaleGoldenrod 
Brown 
Indigo 
PaleGreen 
Burlywood 
Ivory 
PaleTurquoise 
CadetBlue 
Khaki 
PaleVioletRed 
Chartreuse 
Lavender 
PapayaWhip 
Chocolate 
LavenderBlush 
PeachPuff 
Coral 
LawnGreen 
Peru 
CornflowerBlue 
LemonChiffon 
Pink 
Cornsilk 
LightBlue 
Plum 
Crimson 
LightCoral 
PowderBlue 
Cyan 
LightCyan 
Purple 
DarkBlue 
LightGoldenrodyellow 
Red 
DarkCyan 
LightGray 
RosyBrown 
DarkGoldenrod 
LightGreen 
RoyalBlue 
DarkGray 
LightGrey 
SaddleBrown 
DarkGreen 
LightPink 
Salmon 
DarkGrey 
LightSalmon 
SandyBrown 
DarkKhaki 
LightSeagreen 
SeaGreen 
DarkMagenta 
LightSkyblue 
SeaShell 
DarkOlivegreen 
LightSlategray 
Sienna 
DarkOrange 
LightSlategrey 
Silver 
DarkOrchid 
LightSteelblue 
SkyBlue 
DarkRed 
LightYellow 
SlateBlue 
DarkSalmon 
Lime 
SlateGray 
DarkSeagreen 
LimeGreen 
SlateGrey 
DarkSlateblue 
Linen 
Snow 
DarkSlategray 
Magenta 
SpringGreen 
DarkSlategrey 
Maroon 
SteelBlue 
DarkTurquoise 
MediumAquamarine 
Tan 
DarkViolet 
MediumBlue 
Teal 
DeepPink 
MediumOrchid 
Thistle 
DeepSkyblue 
MediumPurple 
Tomato 
DimGray 
MediumSeaGreen 
Turquoise 
DimGrey 
MediumSlateBlue 
Violet 
DodgerBlue 
MediumSpringGreen 
Wheat 
FireBrick 
MediumTurquoise 
White 
FloralWhite 
MediumBioletRed 
WhiteSmoke 
ForestGreen 
MidnightBlue 
Yellow 
Fuchsia 
MintCream 
YellowGreen 

Definition at line 47 of file Texture.cs.

48  {
49  None = 0,
50  AliceBlue = 0xf0f8ff,
51  Gainsboro = 0xdcdcdc,
52  MistyRose = 0xffe4e1,
53  AntiqueWhite = 0xfaebd7,
54  GhostWhite = 0xf8f8ff,
55  Moccasin = 0xffe4b5,
56  Aqua = 0x00ffff,
57  Gold = 0xffd700,
58  NavajoWhite = 0xffdead,
59  Aquamarine = 0x7fffd4,
60  Goldenrod = 0xdaa520,
61  Navy = 0x000080,
62  Azure = 0xf0ffff,
63  Gray = 0x808080,
64  OldLace = 0xfdf5e6,
65  Beige = 0xf5f5dc,
66  Green = 0x008000,
67  Olive = 0x808000,
68  Bisque = 0xffe4c4,
69  GreenYellow = 0xadff2f,
70  OliveDrab = 0x6b8e23,
71  Black = 0x000000,
72  Grey = 0x808080,
73  Orange = 0xffa500,
74  BlanchedAlmond = 0xffebcd,
75  Honeydew = 0xf0fff0,
76  OrangeRed = 0xff4500,
77  Blue = 0x0000ff,
78  HotPink = 0xff69b4,
79  Orchid = 0xda70d6,
80  BlueViolet = 0x8a2be2,
81  IndianRed = 0xcd5c5c,
82  PaleGoldenrod = 0xeee8aa,
83  Brown = 0xa52a2a,
84  Indigo = 0x4b0082,
85  PaleGreen = 0x98fb98,
86  Burlywood = 0xdeb887,
87  Ivory = 0xfffff0,
88  PaleTurquoise = 0xafeeee,
89  CadetBlue = 0x5f9ea0,
90  Khaki = 0xf0e68c,
91  PaleVioletRed = 0xdb7093,
92  Chartreuse = 0x7fff00,
93  Lavender = 0xe6e6fa,
94  PapayaWhip = 0xffefd5,
95  Chocolate = 0xd2691e,
96  LavenderBlush = 0xfff0f5,
97  PeachPuff = 0xffdab9,
98  Coral = 0xff7f50,
99  LawnGreen = 0x7cfc00,
100  Peru = 0xcd853f,
101  CornflowerBlue = 0x6495ed,
102  LemonChiffon = 0xfffacd,
103  Pink = 0xffc0cb,
104  Cornsilk = 0xfff8dc,
105  LightBlue = 0xadd8e6,
106  Plum = 0xdda0dd,
107  Crimson = 0xdc143c,
108  LightCoral = 0xf08080,
109  PowderBlue = 0xb0e0e6,
110  Cyan = 0x00ffff,
111  LightCyan = 0xe0ffff,
112  Purple = 0x800080,
113  DarkBlue = 0x00008b,
114  LightGoldenrodyellow = 0xfafad2,
115  Red = 0xff0000,
116  DarkCyan = 0x008b8b,
117  LightGray = 0xd3d3d3,
118  RosyBrown = 0xbc8f8f,
119  DarkGoldenrod = 0xb8860b,
120  LightGreen = 0x90ee90,
121  RoyalBlue = 0x4169e1,
122  DarkGray = 0xa9a9a9,
123  LightGrey = 0xd3d3d3,
124  SaddleBrown = 0x8b4513,
125  DarkGreen = 0x006400,
126  LightPink = 0xffb6c1,
127  Salmon = 0xfa8072,
128  DarkGrey = 0xa9a9a9,
129  LightSalmon = 0xffa07a,
130  SandyBrown = 0xf4a460,
131  DarkKhaki = 0xbdb76b,
132  LightSeagreen = 0x20b2aa,
133  SeaGreen = 0x2e8b57,
134  DarkMagenta = 0x8b008b,
135  LightSkyblue = 0x87cefa,
136  SeaShell = 0xfff5ee,
137  DarkOlivegreen = 0x556b2f,
138  LightSlategray = 0x778899,
139  Sienna = 0xa0522d,
140  DarkOrange = 0xff8c00,
141  LightSlategrey = 0x778899,
142  Silver = 0xc0c0c0,
143  DarkOrchid = 0x9932cc,
144  LightSteelblue = 0xb0c4de,
145  SkyBlue = 0x87ceeb,
146  DarkRed = 0x8b0000,
147  LightYellow = 0xffffe0,
148  SlateBlue = 0x6a5acd,
149  DarkSalmon = 0xe9967a,
150  Lime = 0x00ff00,
151  SlateGray = 0x708090,
152  DarkSeagreen = 0x8fbc8f,
153  LimeGreen = 0x32cd32,
154  SlateGrey = 0x708090,
155  DarkSlateblue = 0x483d8b,
156  Linen = 0xfaf0e6,
157  Snow = 0xfffafa,
158  DarkSlategray = 0x2f4f4f,
159  Magenta = 0xff00ff,
160  SpringGreen = 0x00ff7f,
161  DarkSlategrey = 0x2f4f4f,
162  Maroon = 0x800000,
163  SteelBlue = 0x4682b4,
164  DarkTurquoise = 0x00ced1,
165  MediumAquamarine = 0x66cdaa,
166  Tan = 0xd2b48c,
167  DarkViolet = 0x9400d3,
168  MediumBlue = 0x0000cd,
169  Teal = 0x008080,
170  DeepPink = 0xff1493,
171  MediumOrchid = 0xba55d3,
172  Thistle = 0xd8bfd8,
173  DeepSkyblue = 0x00bfff,
174  MediumPurple = 0x9370db,
175  Tomato = 0xff6347,
176  DimGray = 0x696969,
177  MediumSeaGreen = 0x3cb371,
178  Turquoise = 0x40e0d0,
179  DimGrey = 0x696969,
180  MediumSlateBlue = 0x7b68ee,
181  Violet = 0xee82ee,
182  DodgerBlue = 0x1e90ff,
183  MediumSpringGreen = 0x00fa9a,
184  Wheat = 0xf5deb3,
185  FireBrick = 0xb22222,
186  MediumTurquoise = 0x48d1cc,
187  White = 0xffffff,
188  FloralWhite = 0xfffaf0,
189  MediumBioletRed = 0xc71585,
190  WhiteSmoke = 0xf5f5f5,
191  ForestGreen = 0x228b22,
192  MidnightBlue = 0x191970,
193  Yellow = 0xffff00,
194  Fuchsia = 0xff00ff,
195  MintCream = 0xf5fffa,
196  YellowGreen = 0x9acd32
197  }

Member Function Documentation

static Texture2D Hydrogen.Texture.AutoCrop ( this Texture2D  texture,
Color  borderColor 
)
static

Autocrop the texture removes the borders from the texture. It searches the active layer for the largest possible border area that's color matches borderColor, and then crops this area from the image, as if you had used the Crop tool.

Returns
The cropped image.
Parameters
textureThe source texture.
borderColorThe border color used in the crop calculations.

Definition at line 236 of file Texture.cs.

237  {
238  var image = texture.GetPixels ();
239  var width = texture.width;
240  var height = texture.height;
241 
242  var left = -1;
243  var right = -1;
244  var top = -1;
245  var bottom = -1;
246  var x = 0;
247  int y;
248 
249  while (left == -1 && x < width) {
250  for (y = 0; y < height; y++) {
251  if (!image [y * width + x].IsColorApproximatelySame (borderColor))
252  left = x;
253  }
254  x++;
255  }
256 
257  x = width - 1;
258 
259  while (right == -1 && x >= 0) {
260  for (y = 0; y < height; y++) {
261  if (!image [y * width + x].IsColorApproximatelySame (borderColor))
262  right = x;
263  }
264  x--;
265  }
266 
267  y = 0;
268 
269  while (top == -1 && y < height) {
270  for (x = 0; x < width; x++) {
271  if (!image [y * width + x].IsColorApproximatelySame (borderColor))
272  top = y;
273  }
274  y++;
275  }
276 
277  y = height - 1;
278 
279  while (bottom == -1 && y >= 0) {
280  for (x = 0; x < width; x++) {
281  if (!image [y * width + x].IsColorApproximatelySame (borderColor))
282  bottom = y;
283  }
284  y--;
285  }
286 
287  return Crop (texture, left, top, right - left, bottom - top);
288  }
static Texture2D Crop(this Texture2D sourceTexture, int offsetX, int offsetY, int width, int height)
Crop the specified texture starting at (X,Y) and extending out based on the width and height...
Definition: Texture.cs:359
static void Hydrogen.Texture.Blit ( Texture2D  destinationTexture,
Texture2D  sourceTexture,
int  offsetX,
int  offsetY 
)
static

The pixels (RGB) of both the destinationTexture and the sourceTexture are combined bitwise according to the simplified overwrite raster operation, and the result is then written to the destinationTexture.

Parameters
destinationTextureThe destination texture.
sourceTextureThe source texture.
offsetXOffset X.
offsetYOffset Y.

Definition at line 298 of file Texture.cs.

299  {
300  var srcWidth = sourceTexture.width;
301  // int srcHeight = src.height;
302  var dstWidth = destinationTexture.width;
303  // int dstHeight = dst.height;
304  Color[] dstp = destinationTexture.GetPixels ();
305  Color[] srcp = sourceTexture.GetPixels ();
306 
307  for (int y = 0; y < sourceTexture.height; y++) {
308  for (int x = 0; x < sourceTexture.width; x++) {
309  dstp [(y + offsetY) * dstWidth + x + offsetX] = srcp [y * srcWidth + x];
310  }
311  }
312 
313  destinationTexture.SetPixels (dstp);
314  }
static void Hydrogen.Texture.BlitAlpha ( Texture2D  destinationTexture,
Texture2D  sourceTexture,
int  offsetX,
int  offsetY 
)
static

The pixels (RGBA) of both the destinationTexture and the sourceTexture are combined bitwise according to the simplified overwrite raster operation, and the result is then written to the destinationTexture.

Parameters
destinationTextureThe destination texture.
sourceTextureThe source texture.
offsetXOffset X.
offsetYOffset Y.

Definition at line 324 of file Texture.cs.

325  {
326  try {
327  var srcWidth = sourceTexture.width;
328  var srcHeight = sourceTexture.height;
329  var dstWidth = destinationTexture.width;
330  var dstps = destinationTexture.GetPixels ();
331  var srcps = sourceTexture.GetPixels ();
332  Color srcp;
333 
334  for (int y = 0; y < srcHeight; y++) {
335  for (int x = 0; x < srcWidth; x++) {
336  int dstOffset = (y + offsetY) * dstWidth + x + offsetX;
337  int srcOffset = y * srcWidth + x;
338  srcp = srcps [srcOffset];
339  if (srcp.a > 0.001f) {
340  dstps [dstOffset] = Color.Lerp (dstps [dstOffset], srcp, srcp.a);
341  }
342  }
343  }
344 
345  destinationTexture.SetPixels (dstps);
346  } catch (System.Exception e) {
347  Debug.Log ("[H] There was a problem Blitting the texture. " + e);
348  }
349  }
static Texture2D Hydrogen.Texture.Crop ( this Texture2D  sourceTexture,
int  offsetX,
int  offsetY,
int  width,
int  height 
)
static

Crop the specified texture starting at (X,Y) and extending out based on the width and height.

Parameters
sourceTextureThe texture to crop.
offsetXThe X offset coordinate.
offsetYThe Y offset coordinate.
widthTarget Width
heightTarget Height

Definition at line 359 of file Texture.cs.

360  {
361  var result = new Texture2D (width, height);
362 
363  result.SetPixels (sourceTexture.GetPixels (offsetX, offsetY, width, height));
364 
365  return result;
366  }
static Texture2D Hydrogen.Texture.FlipHorizontally ( this Texture2D  texture)
static

Flip texture horizontally.

Returns
The horizontally flipped texture.
Parameters
textureThe source texture.

Definition at line 373 of file Texture.cs.

374  {
375  var image = texture.GetPixels ();
376  var newImage = new Color[image.Length];
377 
378  var width = texture.width;
379  var height = texture.height;
380 
381  for (var y = 0; y < height; y++) {
382  for (var x = 0; x < width; x++) {
383  newImage [y * width + (x - width - 1)] = image [y * width + x];
384  }
385  }
386 
387  var result = new Texture2D (width, height);
388 
389  result.SetPixels (newImage);
390 
391  return result;
392  }
static Texture2D Hydrogen.Texture.FlipVertically ( this Texture2D  texture)
static

Flip texture vertically.

Returns
The vertically flipped texture.
Parameters
textureThe source texture..

Definition at line 399 of file Texture.cs.

400  {
401  var image = texture.GetPixels ();
402  var newImage = new Color[image.Length];
403 
404  var width = texture.width;
405  var height = texture.height;
406 
407  for (var y = 0; y < height; y++) {
408  for (var x = 0; x < width; x++) {
409  newImage [(height - y - 1) * width + x] = image [y * width + x];
410  }
411  }
412 
413  var result = new Texture2D (width, height);
414 
415  result.SetPixels (newImage);
416 
417  return result;
418  }
static Texture2D Hydrogen.Texture.Resize ( this Texture2D  sourceTexture,
int  newWidth,
int  newHeight 
)
static

Resize the texture to a specific width and height using bilinear filtering.

Parameters
sourceTextureThe source texture.
newWidthThe new resized width.
newHeightThe new resized height.

Definition at line 426 of file Texture.cs.

427  {
428  var resizedTexture = new Texture2D (newWidth, newHeight);
429  var resizeFactor = new Vector2 ((float)sourceTexture.width / (float)newWidth, (float)sourceTexture.height / (float)newHeight);
430 
431  Vector2 fraction;
432  Vector2 oneMinusFraction;
433  var one = new Vector2 (1f, 1f);
434 
435  Color c1;
436  Color c2;
437  Color c3;
438  Color c4;
439 
440  Color[] image = sourceTexture.GetPixels ();
441  Color[] result = resizedTexture.GetPixels ();
442 
443  for (var y = 0; y < newHeight; y++) {
444  for (var x = 0; x < newWidth; x++) {
445  var floorX = (int)Mathf.Floor (x * resizeFactor.x);
446  var floorY = (int)Mathf.Floor (y * resizeFactor.y);
447 
448  var ceilingX = floorX + 1;
449 
450  if (ceilingX >= sourceTexture.width)
451  ceilingX = floorX;
452 
453  var ceilingY = floorY + 1;
454  if (ceilingY >= sourceTexture.height)
455  ceilingY = floorY;
456 
457  fraction = new Vector2 (x * resizeFactor.x - floorX, y * resizeFactor.y - floorY);
458  oneMinusFraction = one - fraction;
459 
460  c1 = image [floorY * sourceTexture.width + floorX];
461  c2 = image [floorY * sourceTexture.width + ceilingX];
462  c3 = image [ceilingY * sourceTexture.width + floorX];
463  c4 = image [ceilingY * sourceTexture.width + ceilingX];
464 
465  // Blue
466  float b1 = (oneMinusFraction.x * c1.b + fraction.x * c2.b);
467  float b2 = (oneMinusFraction.x * c3.b + fraction.x * c4.b);
468 
469  float blue = (oneMinusFraction.y * b1 + fraction.y * b2);
470 
471  // Green
472  b1 = (oneMinusFraction.x * c1.g + fraction.x * c2.g);
473  b2 = (oneMinusFraction.x * c3.g + fraction.x * c4.g);
474 
475  float green = (oneMinusFraction.y * b1 + fraction.y * b2);
476 
477  // Red
478  b1 = (oneMinusFraction.x * c1.r + fraction.x * c2.r);
479  b2 = (oneMinusFraction.x * c3.r + fraction.x * c4.r);
480 
481  float red = (oneMinusFraction.y * b1 + fraction.y * b2);
482 
483  // Alpha
484  b1 = (oneMinusFraction.x * c1.a + fraction.x * c2.a);
485  b2 = (oneMinusFraction.x * c3.a + fraction.x * c4.a);
486 
487  float alpha = (oneMinusFraction.y * b1 + fraction.y * b2);
488 
489  result [y * resizedTexture.width + x] = new Color (red, green, blue, alpha);
490  }
491  }
492 
493  resizedTexture.SetPixels (result);
494 
495  return resizedTexture;
496  }
static Texture2D Hydrogen.Texture.RotateClockwise90Degrees ( this Texture2D  texture)
static

Rotate texture clockwise, 90 degrees.

Returns
The rotated texture.
Parameters
textureThe source texture.

Definition at line 503 of file Texture.cs.

504  {
505  var image = texture.GetPixels ();
506  var newImage = new Color[image.Length];
507 
508  var width = texture.width;
509  var height = texture.height;
510 
511  for (int y = 0; y < height; y++) {
512  for (int x = 0; x < width; x++) {
513  newImage [y * width + x] = image [(x * width) + (height - 1 - y)];
514  }
515  }
516 
517  var result = new Texture2D (width, height);
518 
519  result.SetPixels (newImage);
520 
521  return result;
522  }
static Texture2D Hydrogen.Texture.RotateCounterClockwise90Degrees ( this Texture2D  texture)
static

Rotate texture counter clockwise, 90 degrees.

Returns
The rotated texture.
Parameters
textureThe source texture.

Definition at line 529 of file Texture.cs.

530  {
531  var image = texture.GetPixels ();
532  var newImage = new Color[image.Length];
533 
534  var width = texture.width;
535  var height = texture.height;
536 
537  for (int y = 0; y < height; y++) {
538  for (int x = 0; x < width; x++) {
539  newImage [y * width + x] = image [(width - 1 - x) * width + y];
540  }
541  }
542 
543  var result = new Texture2D (width, height);
544 
545  result.SetPixels (newImage);
546 
547  return result;
548  }
static Texture2D Hydrogen.Texture.Tile ( this Texture2D  texture,
int  horizontalTiles,
int  verticalTiles 
)
static

Tile the specified texture as outlined.

Returns
The tiled texture.
Parameters
textureThe texture to tile.
horizontalTilesNumber of horizontal tiles.
verticalTilesNumber of vertical tiles.

Definition at line 557 of file Texture.cs.

558  {
559  // Sanity Check
560  if (horizontalTiles < 1)
561  horizontalTiles = 1;
562  if (verticalTiles < 1)
563  verticalTiles = 1;
564 
565  var tiledTexture = new Texture2D (texture.width * horizontalTiles, texture.height * verticalTiles);
566  var texturePixels = texture.GetPixels ();
567  for (var i = 0; i < horizontalTiles; i++) {
568  for (var j = 0; j < verticalTiles; j++)
569  tiledTexture.SetPixels (i * texture.width, j * texture.height, texture.width, texture.height, texturePixels);
570  }
571 
572  return tiledTexture;
573  }
static Color Hydrogen.Texture.ToColor ( this WebColor  color)
static

Convert a WebColor to a UnityEngine.Color

Returns
UnityEngine.Color.
Parameters
colorThe web color you wish to have returned in Unity format.

Definition at line 204 of file Texture.cs.

205  {
206 
207  return new Color (
208  (((int)color >> 16) & 0xFF) * HexInverse,
209  (((int)color >> 8) & 0xFF) * HexInverse,
210  ((int)color & 0xFF) * HexInverse
211 
212  );
213  }
const float HexInverse
Handy 1/255, useful for calculating color values.
Definition: Texture.cs:42
static Color Hydrogen.Texture.ToColor ( WebColor  color,
float  alpha 
)
static

Convert a WebColor to a UnityEngine.Color

Returns
UnityEngine.Color.
Parameters
colorThe web color you wish to have returned in Unity format.
alphaThe alpha value of the color you want returned.

Definition at line 221 of file Texture.cs.

222  {
223  Color newColor = ToColor (color);
224  newColor = new Color (newColor.r, newColor.g, newColor.b, alpha);
225  return newColor;
226  }
static Color ToColor(this WebColor color)
Convert a WebColor to a UnityEngine.Color
Definition: Texture.cs:204
static Texture2D Hydrogen.Texture.Transpose ( this Texture2D  texture)
static

Transpose texture.

Returns
The transposed texture.
Parameters
textureThe source texture.

Definition at line 580 of file Texture.cs.

581  {
582  var image = texture.GetPixels ();
583  var newImage = new Color[image.Length];
584 
585  var width = texture.width;
586  var height = texture.height;
587 
588  for (var y = 0; y < height; y++) {
589  for (var x = 0; x < width; x++) {
590  newImage [y * width + x] = image [x * width + y];
591  }
592  }
593 
594  var result = new Texture2D (width, height);
595 
596  result.SetPixels (newImage);
597 
598  return result;
599  }
static Texture2D Hydrogen.Texture.TransposePerpendicular ( this Texture2D  texture)
static

Transpose texture perpendicularily.

Returns
The transponsed texture.
Parameters
textureThe source texture.

Definition at line 606 of file Texture.cs.

607  {
608  var image = texture.GetPixels ();
609  var newImage = new Color[image.Length];
610 
611  var width = texture.width;
612  var height = texture.height;
613 
614  for (int y = 0; y < height; y++) {
615  for (int x = 0; x < width; x++) {
616  newImage [y * width + x] = image [(width - 1 - x) * width + (height - 1 - y)];
617  }
618  }
619 
620  var result = new Texture2D (width, height);
621 
622  result.SetPixels (newImage);
623 
624  return result;
625  }

Member Data Documentation

const float Hydrogen.Texture.HexInverse = 0.00392156863f

Handy 1/255, useful for calculating color values.

Definition at line 42 of file Texture.cs.