BrawlCrate v0.41
Wii File Editor
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
BrawlLib.BrawlManagerLib.BitmapUtilities Class Reference

Static Public Member Functions

static Bitmap AlphaSwap (Bitmap source)
 Swaps the alpha and value channels of a monochrome image. Transparent areas become black, and black areas become transparent. More...
 
static Bitmap ApplyMask (Bitmap source, Bitmap mask)
 
static Bitmap Combine (Bitmap bg, Image fg)
 Combines two images. The size of the second (foreground) image will be used for the final image. More...
 
static Bitmap Invert (Bitmap source)
 Inverts the colors in a bitmap. More...
 
static Bitmap Resize (Bitmap orig, Size resizeTo)
 Makes a scaled version of an image using BrawlLib's texture converter. More...
 
static Bitmap Border (Bitmap orig, Color color, int penwidth=1)
 
static bool IsSolidColor (Bitmap bmp, out Color c)
 Checks if the given bitmap is a single color. If the result is true, its color will be stored in the second parameter. More...
 
static bool HasAlpha (Bitmap bmp)
 Checks if an image has any transparency. More...
 
static bool HasNonAlpha (Bitmap bmp)
 Checks if an image has varying RGB values among pixels that are partially or fully opaque. More...
 
static int CountColors (Bitmap bmp, int max)
 Counts the number of colors in a bitmap, up through the given maximum. If the maximum is reached, the method will return early. More...
 
static Bitmap Blur (Bitmap orig, Color blurColor)
 Creates a new image, 2 pixels wider and taller than the original. Each pixel's alpha value is the largest alpha value among adjacent pixels on the original image. The color of each pixel will be the color given in the second argument. More...
 
static Bitmap BlurCombine (Bitmap fg, Color blurColor)
 Creates a new bitmap with the original bitmap centered on top of the result of the Blur function. More...
 
static bool HasSolidCorners (Bitmap newBitmap)
 

Member Function Documentation

◆ AlphaSwap()

static Bitmap BrawlLib.BrawlManagerLib.BitmapUtilities.AlphaSwap ( Bitmap  source)
inlinestatic

Swaps the alpha and value channels of a monochrome image. Transparent areas become black, and black areas become transparent.

14 {
15 Color c;
16 if (IsSolidColor(source, out c) && c.A == 0)
17 {
18 // fully transparent image
19 return source;
20 }
21
22 Bitmap ret = new Bitmap(source.Width, source.Height);
23 for (int x = 0; x < ret.Width; x++)
24 {
25 for (int y = 0; y < ret.Height; y++)
26 {
27 Color fromColor = source.GetPixel(x, y);
28 int toColor = fromColor.A == 0 ? -0x01000000 : fromColor.A * 0x10101 + fromColor.R * 0x1000000;
29 ret.SetPixel(x, y, Color.FromArgb(toColor));
30 }
31 }
32
33 return ret;
34 }
static bool IsSolidColor(Bitmap bmp, out Color c)
Checks if the given bitmap is a single color. If the result is true, its color will be stored in the ...
Definition: BitmapUtilities.cs:107

◆ ApplyMask()

static Bitmap BrawlLib.BrawlManagerLib.BitmapUtilities.ApplyMask ( Bitmap  source,
Bitmap  mask 
)
inlinestatic
37 {
38 source = Resize(source, mask.Size);
39 Bitmap ret = new Bitmap(source.Width, source.Height);
40 for (int x = 0; x < ret.Width; x++)
41 {
42 for (int y = 0; y < ret.Height; y++)
43 {
44 Color c = source.GetPixel(x, y);
45 ret.SetPixel(x, y, Color.FromArgb(
46 mask.GetPixel(x, y).R,
47 c.R, c.G, c.B));
48 }
49 }
50
51 return ret;
52 }
static Bitmap Resize(Bitmap orig, Size resizeTo)
Makes a scaled version of an image using BrawlLib's texture converter.
Definition: BitmapUtilities.cs:88

◆ Blur()

static Bitmap BrawlLib.BrawlManagerLib.BitmapUtilities.Blur ( Bitmap  orig,
Color  blurColor 
)
inlinestatic

Creates a new image, 2 pixels wider and taller than the original. Each pixel's alpha value is the largest alpha value among adjacent pixels on the original image. The color of each pixel will be the color given in the second argument.

203 {
204 Bitmap b = new Bitmap(orig.Width + 2, orig.Height + 2);
205 for (int y = -1; y < orig.Height + 1; y++)
206 {
207 for (int x = -1; x < orig.Width + 1; x++)
208 {
209 byte[] vals =
210 {
211 TryGetAlpha(orig, x - 1, y - 1) ?? 0,
212 TryGetAlpha(orig, x - 1, y) ?? 0,
213 TryGetAlpha(orig, x - 1, y + 1) ?? 0,
214 TryGetAlpha(orig, x, y - 1) ?? 0,
215 TryGetAlpha(orig, x, y) ?? 0,
216 TryGetAlpha(orig, x, y + 1) ?? 0,
217 TryGetAlpha(orig, x + 1, y - 1) ?? 0,
218 TryGetAlpha(orig, x + 1, y) ?? 0,
219 TryGetAlpha(orig, x + 1, y + 1) ?? 0
220 };
221 byte alpha = vals.Max();
222 b.SetPixel(x + 1, y + 1, Color.FromArgb(alpha, blurColor));
223 }
224 }
225
226 return b;
227 }

◆ BlurCombine()

static Bitmap BrawlLib.BrawlManagerLib.BitmapUtilities.BlurCombine ( Bitmap  fg,
Color  blurColor 
)
inlinestatic

Creates a new bitmap with the original bitmap centered on top of the result of the Blur function.

246 {
247 Bitmap both = Blur(fg, blurColor);
248 Graphics g = Graphics.FromImage(both);
249 g.DrawImage(fg, 1, 1);
250 return both;
251 }
static Bitmap Blur(Bitmap orig, Color blurColor)
Creates a new image, 2 pixels wider and taller than the original. Each pixel's alpha value is the lar...
Definition: BitmapUtilities.cs:202

◆ Border()

static Bitmap BrawlLib.BrawlManagerLib.BitmapUtilities.Border ( Bitmap  orig,
Color  color,
int  penwidth = 1 
)
inlinestatic
94 {
95 Bitmap b = new Bitmap(orig.Width, orig.Height);
96 Graphics g = Graphics.FromImage(b);
97 g.DrawImage(orig, 0, 0);
98 g.DrawRectangle(new Pen(color, penwidth),
99 penwidth - 1, penwidth - 1,
100 orig.Width - penwidth, orig.Height - penwidth);
101 return b;
102 }

◆ Combine()

static Bitmap BrawlLib.BrawlManagerLib.BitmapUtilities.Combine ( Bitmap  bg,
Image  fg 
)
inlinestatic

Combines two images. The size of the second (foreground) image will be used for the final image.

58 {
59 int w = fg.Width, h = fg.Height;
60 Bitmap both = new Bitmap(w, h);
61 Graphics g = Graphics.FromImage(both);
62 g.DrawImage(Resize(bg, both.Size), 0, 0);
63 g.DrawImage(fg, 0, 0);
64 return both;
65 }

◆ CountColors()

static int BrawlLib.BrawlManagerLib.BitmapUtilities.CountColors ( Bitmap  bmp,
int  max 
)
inlinestatic

Counts the number of colors in a bitmap, up through the given maximum. If the maximum is reached, the method will return early.

178 {
179 int count = 0;
180 HashSet<Color> colors = new HashSet<Color>();
181 for (int y = 0; y < bmp.Height && count < max; y++)
182 {
183 for (int x = 0; x < bmp.Width && count < max; x++)
184 {
185 Color color = bmp.GetPixel(x, y);
186 if (!colors.Contains(color))
187 {
188 colors.Add(color);
189 count++;
190 }
191 }
192 }
193
194 return count;
195 }

◆ HasAlpha()

static bool BrawlLib.BrawlManagerLib.BitmapUtilities.HasAlpha ( Bitmap  bmp)
inlinestatic

Checks if an image has any transparency.

128 {
129 for (int y = 0; y < bmp.Height; y++)
130 {
131 for (int x = 0; x < bmp.Width; x++)
132 {
133 if (bmp.GetPixel(x, y).A < 255)
134 {
135 return true;
136 }
137 }
138 }
139
140 return false;
141 }

◆ HasNonAlpha()

static bool BrawlLib.BrawlManagerLib.BitmapUtilities.HasNonAlpha ( Bitmap  bmp)
inlinestatic

Checks if an image has varying RGB values among pixels that are partially or fully opaque.

147 {
148 int? found = null;
149 for (int y = 0; y < bmp.Height; y++)
150 {
151 for (int x = 0; x < bmp.Width; x++)
152 {
153 Color color = bmp.GetPixel(x, y);
154 if (color.A == 0)
155 {
156 continue;
157 }
158
159 int rgb = color.ToArgb() & 0xFFFFFF;
160 if (found == null)
161 {
162 found = rgb;
163 }
164 else if (rgb != found)
165 {
166 return true;
167 }
168 }
169 }
170
171 return false;
172 }

◆ HasSolidCorners()

static bool BrawlLib.BrawlManagerLib.BitmapUtilities.HasSolidCorners ( Bitmap  newBitmap)
inlinestatic
254 {
255 int w = newBitmap.Width;
256 int h = newBitmap.Height;
257 return newBitmap.GetPixel(0, 0).A == 255
258 && newBitmap.GetPixel(w - 1, 0).A == 255
259 && newBitmap.GetPixel(0, h - 1).A == 255
260 && newBitmap.GetPixel(w - 1, h - 1).A == 255;
261 }

◆ Invert()

static Bitmap BrawlLib.BrawlManagerLib.BitmapUtilities.Invert ( Bitmap  source)
inlinestatic

Inverts the colors in a bitmap.

71 {
72 Bitmap ret = new Bitmap(source.Width, source.Height);
73 for (int x = 0; x < ret.Width; x++)
74 {
75 for (int y = 0; y < ret.Height; y++)
76 {
77 Color c = source.GetPixel(x, y);
78 ret.SetPixel(x, y, Color.FromArgb(c.A, 255 - c.R, 255 - c.G, 255 - c.B));
79 }
80 }
81
82 return ret;
83 }

◆ IsSolidColor()

static bool BrawlLib.BrawlManagerLib.BitmapUtilities.IsSolidColor ( Bitmap  bmp,
out Color  c 
)
inlinestatic

Checks if the given bitmap is a single color. If the result is true, its color will be stored in the second parameter.

108 {
109 c = bmp.GetPixel(0, 0);
110 for (int y = 0; y < bmp.Height; y++)
111 {
112 for (int x = 0; x < bmp.Width; x++)
113 {
114 if (bmp.GetPixel(x, y) != c)
115 {
116 return false;
117 }
118 }
119 }
120
121 return true;
122 }

◆ Resize()

static Bitmap BrawlLib.BrawlManagerLib.BitmapUtilities.Resize ( Bitmap  orig,
Size  resizeTo 
)
inlinestatic

Makes a scaled version of an image using BrawlLib's texture converter.

89 {
90 return orig.Resize(resizeTo.Width, resizeTo.Height);
91 }

The documentation for this class was generated from the following file: