BrawlCrate v0.41
Wii File Editor
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Properties | List of all members
BrawlLib.Wii.Textures.TextureConverter Class Referenceabstract
Inheritance diagram for BrawlLib.Wii.Textures.TextureConverter:
BrawlLib.Wii.Textures.CMPR BrawlLib.Wii.Textures.IA4

Public Member Functions

int GetMipOffset (int width, int height, int mipLevel)
 
int GetMipOffset (ref int width, ref int height, int mipLevel)
 
int GetFileSize (int width, int height, int mipLevels)
 
virtual FileMap EncodeTPLTextureIndexed (Bitmap src, int numColors, WiiPaletteFormat format, QuantizationAlgorithm algorithm, out FileMap paletteFile)
 
virtual FileMap EncodeTextureIndexed (Bitmap src, int mipLevels, int numColors, WiiPaletteFormat format, QuantizationAlgorithm algorithm, out FileMap paletteFile)
 
virtual FileMap EncodeREFTTextureIndexed (Bitmap src, int mipLevels, int numColors, WiiPaletteFormat format, QuantizationAlgorithm algorithm)
 
virtual FileMap EncodeTPLTextureIndexed (Bitmap src, int mipLevels, WiiPaletteFormat format, out FileMap paletteFile)
 
virtual FileMap EncodeREFTTextureIndexed (Bitmap src, int mipLevels, WiiPaletteFormat format)
 
virtual FileMap EncodeTEX0TextureIndexed (Bitmap src, int mipLevels, WiiPaletteFormat format, out FileMap paletteFile)
 
virtual FileMap EncodeREFTTexture (Bitmap src, int mipLevels, WiiPaletteFormat format)
 
virtual FileMap EncodeTEX0Texture (Bitmap src, int mipLevels)
 
virtual FileMap EncodeTPLTexture (Bitmap src, int mipLevels)
 
Bitmap DecodeTexture (TEX0v1 *texture)
 
virtual Bitmap DecodeTexture (TEX0v1 *texture, int mipLevel)
 
virtual Bitmap DecodeTexture (VoidPtr addr, int w, int h, int mipLevel)
 
virtual Bitmap DecodeTextureIndexed (TEX0v1 *texture, PLT0v1 *palette, int mipLevel)
 
virtual Bitmap DecodeTextureIndexed (TEX0v1 *texture, ColorPalette palette, int mipLevel)
 
virtual Bitmap DecodeTextureIndexed (VoidPtr addr, int w, int h, ColorPalette palette, int mipLevel, WiiPixelFormat fmt)
 

Static Public Member Functions

static Bitmap Decode (VoidPtr addr, int w, int h, int mipLevel, WiiPixelFormat fmt)
 
static TextureConverter Get (WiiPixelFormat format)
 
static Bitmap Decode (TEX0v1 *texture, int mipLevel)
 
static Bitmap DecodeIndexed (TEX0v1 *texture, PLT0v1 *palette, int mipLevel)
 
static Bitmap DecodeIndexed (TEX0v1 *texture, ColorPalette palette, int mipLevel)
 
static Bitmap DecodeIndexed (VoidPtr addr, int w, int h, ColorPalette palette, int mipLevel, WiiPixelFormat fmt)
 
static FileMap EncodePLT0Palette (ColorPalette pal, WiiPaletteFormat format)
 
static FileMap EncodeTPLPalette (ColorPalette pal, WiiPaletteFormat format)
 
static FileMap EncodePalette (ColorPalette pal, WiiPaletteFormat format)
 
static void EncodePalette (VoidPtr destAddr, ColorPalette pal, WiiPaletteFormat format)
 
static ColorPalette DecodePalette (PLT0v1 *palette)
 
static ColorPalette DecodePalette (VoidPtr address, int count, WiiPaletteFormat format)
 

Static Public Attributes

static readonly TextureConverter I4 = new I4()
 
static readonly TextureConverter IA4 = new IA4()
 
static readonly TextureConverter I8 = new I8()
 
static readonly TextureConverter IA8 = new IA8()
 
static readonly TextureConverter RGB565 = new RGB565()
 
static readonly TextureConverter RGB5A3 = new RGB5A3()
 
static readonly TextureConverter CI4 = new CI4()
 
static readonly TextureConverter CI8 = new CI8()
 
static readonly CMPR CMPR = new CMPR()
 
static readonly TextureConverter RGBA8 = new RGBA8()
 

Protected Member Functions

abstract void EncodeBlock (ARGBPixel *sPtr, VoidPtr blockAddr, int width)
 
abstract void DecodeBlock (VoidPtr blockAddr, ARGBPixel *destAddr, int width)
 

Protected Attributes

ColorPalette _workingPalette
 

Properties

abstract WiiPixelFormat RawFormat [get]
 
abstract int BitsPerPixel [get]
 
abstract int BlockWidth [get]
 
abstract int BlockHeight [get]
 
bool IsIndexed [get]
 

Member Function Documentation

◆ Decode() [1/2]

static Bitmap BrawlLib.Wii.Textures.TextureConverter.Decode ( TEX0v1 texture,
int  mipLevel 
)
inlinestatic
435 {
436 return Get(texture->PixelFormat).DecodeTexture(texture, mipLevel);
437 }
Bitmap DecodeTexture(TEX0v1 *texture)
Definition: TextureConverter.cs:323
static TextureConverter Get(WiiPixelFormat format)
Definition: TextureConverter.cs:415
WiiPixelFormat PixelFormat
Definition: TEX0.cs:57

◆ Decode() [2/2]

static Bitmap BrawlLib.Wii.Textures.TextureConverter.Decode ( VoidPtr  addr,
int  w,
int  h,
int  mipLevel,
WiiPixelFormat  fmt 
)
inlinestatic
353 {
354 return Get(fmt).DecodeTexture(addr, w, h, mipLevel);
355 }

◆ DecodeBlock()

abstract void BrawlLib.Wii.Textures.TextureConverter.DecodeBlock ( VoidPtr  blockAddr,
ARGBPixel destAddr,
int  width 
)
protectedpure virtual

◆ DecodeIndexed() [1/3]

static Bitmap BrawlLib.Wii.Textures.TextureConverter.DecodeIndexed ( TEX0v1 texture,
ColorPalette  palette,
int  mipLevel 
)
inlinestatic
445 {
446 return Get(texture->PixelFormat).DecodeTextureIndexed(texture, palette, mipLevel);
447 }
virtual Bitmap DecodeTextureIndexed(TEX0v1 *texture, PLT0v1 *palette, int mipLevel)
Definition: TextureConverter.cs:381

◆ DecodeIndexed() [2/3]

static Bitmap BrawlLib.Wii.Textures.TextureConverter.DecodeIndexed ( TEX0v1 texture,
PLT0v1 palette,
int  mipLevel 
)
inlinestatic
440 {
441 return Get(texture->PixelFormat).DecodeTextureIndexed(texture, palette, mipLevel);
442 }

◆ DecodeIndexed() [3/3]

static Bitmap BrawlLib.Wii.Textures.TextureConverter.DecodeIndexed ( VoidPtr  addr,
int  w,
int  h,
ColorPalette  palette,
int  mipLevel,
WiiPixelFormat  fmt 
)
inlinestatic
451 {
452 return Get(fmt).DecodeTextureIndexed(addr, w, h, palette, mipLevel, fmt);
453 }

◆ DecodePalette() [1/2]

static ColorPalette BrawlLib.Wii.Textures.TextureConverter.DecodePalette ( PLT0v1 palette)
inlinestatic
559 {
560 int count = palette->_numEntries;
561 ColorPalette pal = ColorPaletteExtension.CreatePalette(ColorPaletteFlags.HasAlpha, count);
562 switch (palette->PaletteFormat)
563 {
564 case WiiPaletteFormat.IA8:
565 {
566 IA8Pixel* sPtr = (IA8Pixel*) palette->PaletteData;
567 for (int i = 0; i < count; i++)
568 {
569 pal.Entries[i] = (Color) sPtr[i];
570 }
571
572 break;
573 }
574
575 case WiiPaletteFormat.RGB565:
576 {
577 wRGB565Pixel* sPtr = (wRGB565Pixel*) palette->PaletteData;
578 for (int i = 0; i < count; i++)
579 {
580 pal.Entries[i] = (Color) sPtr[i];
581 }
582
583 break;
584 }
585
586 case WiiPaletteFormat.RGB5A3:
587 {
588 wRGB5A3Pixel* sPtr = (wRGB5A3Pixel*) palette->PaletteData;
589 for (int i = 0; i < count; i++)
590 {
591 pal.Entries[i] = (Color) (ARGBPixel) sPtr[i];
592 }
593
594 break;
595 }
596 }
597
598 return pal;
599 }
Definition: ColorPaletteExtension.cs:20
static ColorPalette CreatePalette(ColorPaletteFlags flags, int entries)
Definition: ColorPaletteExtension.cs:21
ColorPaletteFlags
Definition: ColorPaletteExtension.cs:12
WiiPaletteFormat
Definition: Enum.cs:57
Definition: PixelTypes.cs:16
WiiPaletteFormat PaletteFormat
Definition: PLT0.cs:53
VoidPtr PaletteData
Definition: PLT0.cs:49
bshort _numEntries
Definition: PLT0.cs:17

◆ DecodePalette() [2/2]

static ColorPalette BrawlLib.Wii.Textures.TextureConverter.DecodePalette ( VoidPtr  address,
int  count,
WiiPaletteFormat  format 
)
inlinestatic
602 {
603 ColorPalette pal = ColorPaletteExtension.CreatePalette(ColorPaletteFlags.HasAlpha, count);
604 switch (format)
605 {
606 case WiiPaletteFormat.IA8:
607 {
608 IA8Pixel* sPtr = (IA8Pixel*) address;
609 for (int i = 0; i < count; i++)
610 {
611 pal.Entries[i] = (Color) sPtr[i];
612 }
613
614 break;
615 }
616
617 case WiiPaletteFormat.RGB565:
618 {
619 wRGB565Pixel* sPtr = (wRGB565Pixel*) address;
620 for (int i = 0; i < count; i++)
621 {
622 pal.Entries[i] = (Color) sPtr[i];
623 }
624
625 break;
626 }
627
628 case WiiPaletteFormat.RGB5A3:
629 {
630 wRGB5A3Pixel* sPtr = (wRGB5A3Pixel*) address;
631 for (int i = 0; i < count; i++)
632 {
633 pal.Entries[i] = (Color) (ARGBPixel) sPtr[i];
634 }
635
636 break;
637 }
638 }
639
640 return pal;
641 }

◆ DecodeTexture() [1/3]

Bitmap BrawlLib.Wii.Textures.TextureConverter.DecodeTexture ( TEX0v1 texture)
inline
324 {
325 return DecodeTexture(texture, 1);
326 }

◆ DecodeTexture() [2/3]

virtual Bitmap BrawlLib.Wii.Textures.TextureConverter.DecodeTexture ( TEX0v1 texture,
int  mipLevel 
)
inlinevirtual
329 {
330 int w = (ushort) texture->_width, h = (ushort) texture->_height;
331 VoidPtr addr = texture->PixelData + GetMipOffset(ref w, ref h, mipLevel);
332 int aw = w.Align(BlockWidth), ah = h.Align(BlockHeight);
333
334 using (DIB dib = new DIB(w, h, BlockWidth, BlockHeight, PixelFormat.Format32bppArgb))
335 {
336 int sStep = BlockWidth * BlockHeight * BitsPerPixel / 8;
337 int bStride = aw * BitsPerPixel / 8;
338 for (int y = 0; y < ah; y += BlockHeight)
339 {
340 ARGBPixel* dPtr = (ARGBPixel*) dib.Scan0 + y * aw;
341 VoidPtr sPtr = addr + y * bStride;
342 for (int x = 0; x < aw; x += BlockWidth, dPtr += BlockWidth, sPtr += sStep)
343 {
344 DecodeBlock(sPtr, dPtr, aw);
345 }
346 }
347
348 return dib.ToBitmap();
349 }
350 }
abstract int BlockHeight
Definition: TextureConverter.cs:30
abstract void DecodeBlock(VoidPtr blockAddr, ARGBPixel *destAddr, int width)
abstract int BlockWidth
Definition: TextureConverter.cs:29
int GetMipOffset(int width, int height, int mipLevel)
Definition: TextureConverter.cs:35
abstract int BitsPerPixel
Definition: TextureConverter.cs:28
Definition: VoidPtr.cs:9
VoidPtr PixelData
Definition: TEX0.cs:53
bshort _height
Definition: TEX0.cs:18
bshort _width
Definition: TEX0.cs:17

◆ DecodeTexture() [3/3]

virtual Bitmap BrawlLib.Wii.Textures.TextureConverter.DecodeTexture ( VoidPtr  addr,
int  w,
int  h,
int  mipLevel 
)
inlinevirtual
358 {
359 addr += GetMipOffset(ref w, ref h, mipLevel);
360
361 int aw = w.Align(BlockWidth), ah = h.Align(BlockHeight);
362
363 using (DIB dib = new DIB(w, h, BlockWidth, BlockHeight, PixelFormat.Format32bppArgb))
364 {
365 int sStep = BlockWidth * BlockHeight * BitsPerPixel / 8;
366 int bStride = aw * BitsPerPixel / 8;
367 for (int y = 0; y < ah; y += BlockHeight)
368 {
369 ARGBPixel* dPtr = (ARGBPixel*) dib.Scan0 + y * aw;
370 VoidPtr sPtr = addr + y * bStride;
371 for (int x = 0; x < aw; x += BlockWidth, dPtr += BlockWidth, sPtr += sStep)
372 {
373 DecodeBlock(sPtr, dPtr, aw);
374 }
375 }
376
377 return dib.ToBitmap();
378 }
379 }

◆ DecodeTextureIndexed() [1/3]

virtual Bitmap BrawlLib.Wii.Textures.TextureConverter.DecodeTextureIndexed ( TEX0v1 texture,
ColorPalette  palette,
int  mipLevel 
)
inlinevirtual
387 {
388 _workingPalette = palette;
389 try
390 {
391 return DecodeTexture(texture, mipLevel);
392 }
393 finally
394 {
395 _workingPalette = null;
396 }
397 }
ColorPalette _workingPalette
Definition: TextureConverter.cs:33

◆ DecodeTextureIndexed() [2/3]

virtual Bitmap BrawlLib.Wii.Textures.TextureConverter.DecodeTextureIndexed ( TEX0v1 texture,
PLT0v1 palette,
int  mipLevel 
)
inlinevirtual
382 {
383 return DecodeTextureIndexed(texture, DecodePalette(palette), mipLevel);
384 }
static ColorPalette DecodePalette(PLT0v1 *palette)
Definition: TextureConverter.cs:558

◆ DecodeTextureIndexed() [3/3]

virtual Bitmap BrawlLib.Wii.Textures.TextureConverter.DecodeTextureIndexed ( VoidPtr  addr,
int  w,
int  h,
ColorPalette  palette,
int  mipLevel,
WiiPixelFormat  fmt 
)
inlinevirtual
401 {
402 _workingPalette = palette;
403 try
404 {
405 return Decode(addr, w, h, mipLevel, fmt);
406 }
407 finally
408 {
409 _workingPalette = null;
410 }
411 }
static Bitmap Decode(VoidPtr addr, int w, int h, int mipLevel, WiiPixelFormat fmt)
Definition: TextureConverter.cs:352

◆ EncodeBlock()

abstract void BrawlLib.Wii.Textures.TextureConverter.EncodeBlock ( ARGBPixel sPtr,
VoidPtr  blockAddr,
int  width 
)
protectedpure virtual

◆ EncodePalette() [1/2]

static FileMap BrawlLib.Wii.Textures.TextureConverter.EncodePalette ( ColorPalette  pal,
WiiPaletteFormat  format 
)
inlinestatic
500 {
501 FileMap fileView = FileMap.FromTempFile(pal.Entries.Length * 2);
502 try
503 {
504 EncodePalette(fileView.Address, pal, format);
505 return fileView;
506 }
507 catch (Exception)
508 {
509 fileView.Dispose();
510 throw;
511 //MessageBox.Show(x.ToString());
512 //fileView.Dispose();
513 //return null;
514 }
515 }
Definition: FileMap.cs:10
static FileMap FromTempFile(int length)
Definition: FileMap.cs:96
VoidPtr Address
Definition: FileMap.cs:16
virtual void Dispose()
Definition: FileMap.cs:33
static FileMap EncodePalette(ColorPalette pal, WiiPaletteFormat format)
Definition: TextureConverter.cs:499

◆ EncodePalette() [2/2]

static void BrawlLib.Wii.Textures.TextureConverter.EncodePalette ( VoidPtr  destAddr,
ColorPalette  pal,
WiiPaletteFormat  format 
)
inlinestatic
518 {
519 int count = pal.Entries.Length;
520
521 switch (format)
522 {
523 case WiiPaletteFormat.IA8:
524 {
525 IA8Pixel* dPtr = (IA8Pixel*) destAddr;
526 for (int i = 0; i < count; i++)
527 {
528 dPtr[i] = (IA8Pixel) pal.Entries[i];
529 }
530
531 break;
532 }
533
534 case WiiPaletteFormat.RGB565:
535 {
536 wRGB565Pixel* dPtr = (wRGB565Pixel*) destAddr;
537 for (int i = 0; i < count; i++)
538 {
539 dPtr[i] = (wRGB565Pixel) pal.Entries[i];
540 }
541
542 break;
543 }
544
545 case WiiPaletteFormat.RGB5A3:
546 {
547 wRGB5A3Pixel* dPtr = (wRGB5A3Pixel*) destAddr;
548 for (int i = 0; i < count; i++)
549 {
550 dPtr[i] = (wRGB5A3Pixel) pal.Entries[i];
551 }
552
553 break;
554 }
555 }
556 }

◆ EncodePLT0Palette()

static FileMap BrawlLib.Wii.Textures.TextureConverter.EncodePLT0Palette ( ColorPalette  pal,
WiiPaletteFormat  format 
)
inlinestatic
456 {
457 FileMap fileView = FileMap.FromTempFile(pal.Entries.Length * 2 + 0x40);
458 try
459 {
460 PLT0v1* header = (PLT0v1*) fileView.Address;
461 *header = new PLT0v1(pal.Entries.Length, format);
462
463 EncodePalette(fileView.Address + 0x40, pal, format);
464 return fileView;
465 }
466 catch (Exception)
467 {
468 fileView.Dispose();
469 throw;
470 //MessageBox.Show(x.ToString());
471 //fileView.Dispose();
472 //return null;
473 }
474 }
Definition: PLT0.cs:9

◆ EncodeREFTTexture()

virtual FileMap BrawlLib.Wii.Textures.TextureConverter.EncodeREFTTexture ( Bitmap  src,
int  mipLevels,
WiiPaletteFormat  format 
)
inlinevirtual
122 {
123 int w = src.Width, h = src.Height;
124 int bw = BlockWidth, bh = BlockHeight;
125
126 ColorPalette pal = src.Palette;
127
128 PixelFormat fmt = src.IsIndexed() ? src.PixelFormat : PixelFormat.Format32bppArgb;
129
130 FileMap fileView =
131 FileMap.FromTempFile(GetFileSize(w, h, mipLevels) + 0x20 + (pal != null ? pal.Entries.Length * 2 : 0));
132 try
133 {
134 //Build REFT image header
135 REFTImageHeader* header = (REFTImageHeader*) fileView.Address;
136 *header = new REFTImageHeader((ushort) w, (ushort) h, (byte) RawFormat, (byte) format,
137 (ushort) (pal != null ? pal.Entries.Length : 0),
138 (uint) fileView.Length - 0x20 - (uint) (pal != null ? pal.Entries.Length * 2 : 0),
139 (byte) (mipLevels - 1));
140
141 int sStep = bw * Image.GetPixelFormatSize(fmt) / 8;
142 int dStep = bw * bh * BitsPerPixel / 8;
143
144 using (DIB dib = DIB.FromBitmap(src, bw, bh, fmt))
145 {
146 for (int i = 1; i <= mipLevels; i++)
147 {
148 EncodeLevel((VoidPtr) header + 0x20, dib, src, dStep, sStep, i);
149 }
150 }
151
152 if (pal != null)
153 {
154 int count = pal.Entries.Length;
155
156 switch (format)
157 {
158 case WiiPaletteFormat.IA8:
159 {
160 IA8Pixel* dPtr = (IA8Pixel*) header->PaletteData;
161 for (int i = 0; i < count; i++)
162 {
163 dPtr[i] = (IA8Pixel) pal.Entries[i];
164 }
165
166 break;
167 }
168
169 case WiiPaletteFormat.RGB565:
170 {
171 wRGB565Pixel* dPtr = (wRGB565Pixel*) header->PaletteData;
172 for (int i = 0; i < count; i++)
173 {
174 dPtr[i] = (wRGB565Pixel) pal.Entries[i];
175 }
176
177 break;
178 }
179
180 case WiiPaletteFormat.RGB5A3:
181 {
182 wRGB5A3Pixel* dPtr = (wRGB5A3Pixel*) header->PaletteData;
183 for (int i = 0; i < count; i++)
184 {
185 dPtr[i] = (wRGB5A3Pixel) pal.Entries[i];
186 }
187
188 break;
189 }
190 }
191 }
192
193 return fileView;
194 }
195 catch (Exception x)
196 {
197 MessageBox.Show(x.ToString());
198 fileView.Dispose();
199 return null;
200 }
201 }
int GetFileSize(int width, int height, int mipLevels)
Definition: TextureConverter.cs:53
abstract WiiPixelFormat RawFormat
Definition: TextureConverter.cs:27
VoidPtr PaletteData
Definition: REFT.cs:181

◆ EncodeREFTTextureIndexed() [1/2]

virtual FileMap BrawlLib.Wii.Textures.TextureConverter.EncodeREFTTextureIndexed ( Bitmap  src,
int  mipLevels,
int  numColors,
WiiPaletteFormat  format,
QuantizationAlgorithm  algorithm 
)
inlinevirtual
78 {
79 using (Bitmap indexed = src.Quantize(algorithm, numColors, RawFormat, format, null))
80 {
81 return EncodeREFTTextureIndexed(indexed, mipLevels, format);
82 }
83 }
virtual FileMap EncodeREFTTextureIndexed(Bitmap src, int mipLevels, int numColors, WiiPaletteFormat format, QuantizationAlgorithm algorithm)
Definition: TextureConverter.cs:76

◆ EncodeREFTTextureIndexed() [2/2]

virtual FileMap BrawlLib.Wii.Textures.TextureConverter.EncodeREFTTextureIndexed ( Bitmap  src,
int  mipLevels,
WiiPaletteFormat  format 
)
inlinevirtual
99 {
100 if (!src.IsIndexed())
101 {
102 throw new ArgumentException("Source image must be indexed.");
103 }
104
105 return EncodeREFTTexture(src, mipLevels, format);
106 }
virtual FileMap EncodeREFTTexture(Bitmap src, int mipLevels, WiiPaletteFormat format)
Definition: TextureConverter.cs:121

◆ EncodeTEX0Texture()

virtual FileMap BrawlLib.Wii.Textures.TextureConverter.EncodeTEX0Texture ( Bitmap  src,
int  mipLevels 
)
inlinevirtual
204 {
205 int w = src.Width, h = src.Height;
206 int bw = BlockWidth, bh = BlockHeight;
207
208 PixelFormat fmt;
209 switch (RawFormat)
210 {
211 case WiiPixelFormat.CI4:
212 case WiiPixelFormat.CI8:
213 case WiiPixelFormat.CMPR:
214 fmt = src.IsIndexed() ? src.PixelFormat : PixelFormat.Format32bppArgb;
215 break;
216 default:
217 fmt = PixelFormat.Format32bppArgb;
218 break;
219 }
220
221 FileMap fileView = FileMap.FromTempFile(GetFileSize(w, h, mipLevels) + 0x40);
222 try
223 {
224 //Build TEX header
225 TEX0v1* header = (TEX0v1*) fileView.Address;
226 *header = new TEX0v1(w, h, RawFormat, mipLevels);
227
228 int sStep = bw * Image.GetPixelFormatSize(fmt) / 8;
229 int dStep = bw * bh * BitsPerPixel / 8;
230
231 using (DIB dib = DIB.FromBitmap(src, bw, bh, fmt))
232 {
233 for (int i = 1; i <= mipLevels; i++)
234 {
235 EncodeLevel(header->PixelData, dib, src, dStep, sStep, i);
236 }
237 }
238
239 return fileView;
240 }
241 catch (Exception x)
242 {
243 MessageBox.Show(x.ToString());
244 fileView.Dispose();
245 return null;
246 }
247 }
WiiPixelFormat
Definition: Enum.cs:4
Definition: TEX0.cs:9

◆ EncodeTEX0TextureIndexed()

virtual FileMap BrawlLib.Wii.Textures.TextureConverter.EncodeTEX0TextureIndexed ( Bitmap  src,
int  mipLevels,
WiiPaletteFormat  format,
out FileMap  paletteFile 
)
inlinevirtual
110 {
111 if (!src.IsIndexed())
112 {
113 throw new ArgumentException("Source image must be indexed.");
114 }
115
116 FileMap texMap = EncodeTEX0Texture(src, mipLevels);
117 paletteFile = EncodePLT0Palette(src.Palette, format);
118 return texMap;
119 }
virtual FileMap EncodeTEX0Texture(Bitmap src, int mipLevels)
Definition: TextureConverter.cs:203
static FileMap EncodePLT0Palette(ColorPalette pal, WiiPaletteFormat format)
Definition: TextureConverter.cs:455

◆ EncodeTextureIndexed()

virtual FileMap BrawlLib.Wii.Textures.TextureConverter.EncodeTextureIndexed ( Bitmap  src,
int  mipLevels,
int  numColors,
WiiPaletteFormat  format,
QuantizationAlgorithm  algorithm,
out FileMap  paletteFile 
)
inlinevirtual
69 {
70 using (Bitmap indexed = src.Quantize(algorithm, numColors, RawFormat, format, null))
71 {
72 return EncodeTEX0TextureIndexed(indexed, mipLevels, format, out paletteFile);
73 }
74 }
virtual FileMap EncodeTEX0TextureIndexed(Bitmap src, int mipLevels, WiiPaletteFormat format, out FileMap paletteFile)
Definition: TextureConverter.cs:108

◆ EncodeTPLPalette()

static FileMap BrawlLib.Wii.Textures.TextureConverter.EncodeTPLPalette ( ColorPalette  pal,
WiiPaletteFormat  format 
)
inlinestatic
477 {
478 FileMap fileView = FileMap.FromTempFile(pal.Entries.Length * 2 + 0xC);
479 try
480 {
481 TPLPaletteHeader* header = (TPLPaletteHeader*) fileView.Address;
482 header->_format = (uint) format;
483 header->_numEntries = (ushort) pal.Entries.Length;
484 header->_data = 0xC;
485
486 EncodePalette(fileView.Address + 0xC, pal, format);
487 return fileView;
488 }
489 catch (Exception)
490 {
491 fileView.Dispose();
492 throw;
493 //MessageBox.Show(x.ToString());
494 //fileView.Dispose();
495 //return null;
496 }
497 }

◆ EncodeTPLTexture()

virtual FileMap BrawlLib.Wii.Textures.TextureConverter.EncodeTPLTexture ( Bitmap  src,
int  mipLevels 
)
inlinevirtual
250 {
251 int w = src.Width, h = src.Height;
252 int bw = BlockWidth, bh = BlockHeight;
253
254 PixelFormat fmt = src.IsIndexed() ? src.PixelFormat : PixelFormat.Format32bppArgb;
255
256 FileMap fileView = FileMap.FromTempFile(GetFileSize(w, h, mipLevels) + TPLTextureHeader.Size);
257 try
258 {
259 //Build TPL header
260 TPLTextureHeader* tex = (TPLTextureHeader*) fileView.Address;
261 tex->_wrapS = 0;
262 tex->_wrapT = 0;
263 tex->_minFilter = 1;
264 tex->_magFilter = 1;
265 tex->_minLOD = 0;
266 tex->_maxLOD = (byte) (mipLevels - 1);
267 tex->PixelFormat = RawFormat;
268 tex->_width = (ushort) w;
269 tex->_height = (ushort) h;
270 tex->_data = TPLTextureHeader.Size;
271
272 int sStep = bw * Image.GetPixelFormatSize(fmt) / 8;
273 int dStep = bw * bh * BitsPerPixel / 8;
274 VoidPtr baseAddr = fileView.Address;
275
276 using (DIB dib = DIB.FromBitmap(src, bw, bh, fmt))
277 {
278 for (int i = 1; i <= mipLevels; i++)
279 {
280 EncodeLevel(baseAddr + tex->_data, dib, src, dStep, sStep, i);
281 }
282 }
283
284 return fileView;
285 }
286 catch (Exception x)
287 {
288 MessageBox.Show(x.ToString());
289 fileView.Dispose();
290 return null;
291 }
292 }

◆ EncodeTPLTextureIndexed() [1/2]

virtual FileMap BrawlLib.Wii.Textures.TextureConverter.EncodeTPLTextureIndexed ( Bitmap  src,
int  mipLevels,
WiiPaletteFormat  format,
out FileMap  paletteFile 
)
inlinevirtual
87 {
88 if (!src.IsIndexed())
89 {
90 throw new ArgumentException("Source image must be indexed.");
91 }
92
93 FileMap texMap = EncodeTPLTexture(src, mipLevels);
94 paletteFile = EncodeTPLPalette(src.Palette, format);
95 return texMap;
96 }
static FileMap EncodeTPLPalette(ColorPalette pal, WiiPaletteFormat format)
Definition: TextureConverter.cs:476
virtual FileMap EncodeTPLTexture(Bitmap src, int mipLevels)
Definition: TextureConverter.cs:249

◆ EncodeTPLTextureIndexed() [2/2]

virtual FileMap BrawlLib.Wii.Textures.TextureConverter.EncodeTPLTextureIndexed ( Bitmap  src,
int  numColors,
WiiPaletteFormat  format,
QuantizationAlgorithm  algorithm,
out FileMap  paletteFile 
)
inlinevirtual
60 {
61 using (Bitmap indexed = src.Quantize(algorithm, numColors, RawFormat, format, null))
62 {
63 return EncodeTPLTextureIndexed(indexed, 1, format, out paletteFile);
64 }
65 }
virtual FileMap EncodeTPLTextureIndexed(Bitmap src, int numColors, WiiPaletteFormat format, QuantizationAlgorithm algorithm, out FileMap paletteFile)
Definition: TextureConverter.cs:58

◆ Get()

static TextureConverter BrawlLib.Wii.Textures.TextureConverter.Get ( WiiPixelFormat  format)
inlinestatic
416 {
417 switch (format)
418 {
419 case WiiPixelFormat.I4: return I4;
420 case WiiPixelFormat.IA4: return IA4;
421 case WiiPixelFormat.I8: return I8;
422 case WiiPixelFormat.IA8: return IA8;
423 case WiiPixelFormat.RGB565: return RGB565;
424 case WiiPixelFormat.RGB5A3: return RGB5A3;
425 case WiiPixelFormat.CI4: return CI4;
426 case WiiPixelFormat.CI8: return CI8;
427 case WiiPixelFormat.CMPR: return CMPR;
428 case WiiPixelFormat.RGBA8: return RGBA8;
429 }
430
431 return null;
432 }
static readonly TextureConverter I4
Definition: TextureConverter.cs:16
static readonly CMPR CMPR
Definition: TextureConverter.cs:24
static readonly TextureConverter IA4
Definition: TextureConverter.cs:17
static readonly TextureConverter RGBA8
Definition: TextureConverter.cs:25
static readonly TextureConverter RGB565
Definition: TextureConverter.cs:20
static readonly TextureConverter CI4
Definition: TextureConverter.cs:22
static readonly TextureConverter CI8
Definition: TextureConverter.cs:23
static readonly TextureConverter RGB5A3
Definition: TextureConverter.cs:21
static readonly TextureConverter IA8
Definition: TextureConverter.cs:19
static readonly TextureConverter I8
Definition: TextureConverter.cs:18

◆ GetFileSize()

int BrawlLib.Wii.Textures.TextureConverter.GetFileSize ( int  width,
int  height,
int  mipLevels 
)
inline
54 {
55 return GetMipOffset(width, height, mipLevels + 1);
56 }

◆ GetMipOffset() [1/2]

int BrawlLib.Wii.Textures.TextureConverter.GetMipOffset ( int  width,
int  height,
int  mipLevel 
)
inline
36 {
37 return GetMipOffset(ref width, ref height, mipLevel);
38 }

◆ GetMipOffset() [2/2]

int BrawlLib.Wii.Textures.TextureConverter.GetMipOffset ( ref int  width,
ref int  height,
int  mipLevel 
)
inline
41 {
42 int offset = 0;
43 while (mipLevel-- > 1)
44 {
45 offset += (width.Align(BlockWidth) * height.Align(BlockHeight) * BitsPerPixel) >> 3;
46 width = Math.Max(width >> 1, 1);
47 height = Math.Max(height >> 1, 1);
48 }
49
50 return offset;
51 }

Member Data Documentation

◆ _workingPalette

ColorPalette BrawlLib.Wii.Textures.TextureConverter._workingPalette
protected

◆ CI4

readonly TextureConverter BrawlLib.Wii.Textures.TextureConverter.CI4 = new CI4()
static

◆ CI8

readonly TextureConverter BrawlLib.Wii.Textures.TextureConverter.CI8 = new CI8()
static

◆ CMPR

readonly CMPR BrawlLib.Wii.Textures.TextureConverter.CMPR = new CMPR()
static

◆ I4

readonly TextureConverter BrawlLib.Wii.Textures.TextureConverter.I4 = new I4()
static

◆ I8

readonly TextureConverter BrawlLib.Wii.Textures.TextureConverter.I8 = new I8()
static

◆ IA4

readonly TextureConverter BrawlLib.Wii.Textures.TextureConverter.IA4 = new IA4()
static

◆ IA8

readonly TextureConverter BrawlLib.Wii.Textures.TextureConverter.IA8 = new IA8()
static

◆ RGB565

readonly TextureConverter BrawlLib.Wii.Textures.TextureConverter.RGB565 = new RGB565()
static

◆ RGB5A3

readonly TextureConverter BrawlLib.Wii.Textures.TextureConverter.RGB5A3 = new RGB5A3()
static

◆ RGBA8

readonly TextureConverter BrawlLib.Wii.Textures.TextureConverter.RGBA8 = new RGBA8()
static

Property Documentation

◆ BitsPerPixel

abstract int BrawlLib.Wii.Textures.TextureConverter.BitsPerPixel
get
28{ get; }

◆ BlockHeight

abstract int BrawlLib.Wii.Textures.TextureConverter.BlockHeight
get
30{ get; }

◆ BlockWidth

abstract int BrawlLib.Wii.Textures.TextureConverter.BlockWidth
get
29{ get; }

◆ IsIndexed

bool BrawlLib.Wii.Textures.TextureConverter.IsIndexed
get

◆ RawFormat

abstract WiiPixelFormat BrawlLib.Wii.Textures.TextureConverter.RawFormat
get
27{ get; }

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