protected override void EncodeBlock(ARGBPixel *sPtr, VoidPtr blockAddr, int width) { wRGB565Pixel *dPtr = (wRGB565Pixel *)blockAddr; for (int y = 0; y < BlockHeight; y++, sPtr += width) { for (int x = 0; x < BlockWidth;) { *dPtr++ = (wRGB565Pixel)sPtr[x++]; } } }
protected override void DecodeBlock(VoidPtr blockAddr, ARGBPixel *dPtr, int width) { wRGB565Pixel *sPtr = (wRGB565Pixel *)blockAddr; //RGBPixel* dPtr = (RGBPixel*)destAddr; for (int y = 0; y < BlockHeight; y++, dPtr += width) { for (int x = 0; x < BlockWidth;) { dPtr[x++] = (ARGBPixel)(*sPtr++); } } }
public static ColorPalette DecodePalette(PLT0v1 *palette) { int count = palette->_numEntries; ColorPalette pal = ColorPaletteExtension.CreatePalette(ColorPaletteFlags.HasAlpha, count); switch (palette->PaletteFormat) { case WiiPaletteFormat.IA8: { IA8Pixel *sPtr = (IA8Pixel *)palette->PaletteData; for (int i = 0; i < count; i++) { pal.Entries[i] = (Color)sPtr[i]; } break; } case WiiPaletteFormat.RGB565: { wRGB565Pixel *sPtr = (wRGB565Pixel *)palette->PaletteData; for (int i = 0; i < count; i++) { pal.Entries[i] = (Color)sPtr[i]; } break; } case WiiPaletteFormat.RGB5A3: { wRGB5A3Pixel *sPtr = (wRGB5A3Pixel *)palette->PaletteData; for (int i = 0; i < count; i++) { pal.Entries[i] = (Color)(ARGBPixel)sPtr[i]; } break; } } return(pal); }
public static ColorPalette DecodePalette(VoidPtr address, int count, WiiPaletteFormat format) { ColorPalette pal = ColorPaletteExtension.CreatePalette(ColorPaletteFlags.HasAlpha, count); switch (format) { case WiiPaletteFormat.IA8: { IA8Pixel *sPtr = (IA8Pixel *)address; for (int i = 0; i < count; i++) { pal.Entries[i] = (Color)sPtr[i]; } break; } case WiiPaletteFormat.RGB565: { wRGB565Pixel *sPtr = (wRGB565Pixel *)address; for (int i = 0; i < count; i++) { pal.Entries[i] = (Color)sPtr[i]; } break; } case WiiPaletteFormat.RGB5A3: { wRGB5A3Pixel *sPtr = (wRGB5A3Pixel *)address; for (int i = 0; i < count; i++) { pal.Entries[i] = (Color)(ARGBPixel)sPtr[i]; } break; } } return(pal); }
public static void EncodePalette(VoidPtr destAddr, ColorPalette pal, WiiPaletteFormat format) { int count = pal.Entries.Length; PLT0 *header = (PLT0 *)destAddr; *header = new PLT0(count, format); switch (format) { case WiiPaletteFormat.IA8: { IA8Pixel *dPtr = (IA8Pixel *)header->PaletteData; for (int i = 0; i < count; i++) { dPtr[i] = (IA8Pixel)pal.Entries[i]; } break; } case WiiPaletteFormat.RGB565: { wRGB565Pixel *dPtr = (wRGB565Pixel *)header->PaletteData; for (int i = 0; i < count; i++) { dPtr[i] = (wRGB565Pixel)pal.Entries[i]; } break; } case WiiPaletteFormat.RGB5A3: { wRGB5A3Pixel *dPtr = (wRGB5A3Pixel *)header->PaletteData; for (int i = 0; i < count; i++) { dPtr[i] = (wRGB5A3Pixel)pal.Entries[i]; } break; } } }
public virtual FileMap EncodeREFTTexture(Bitmap src, int mipLevels, WiiPaletteFormat format) { int w = src.Width, h = src.Height; int bw = BlockWidth, bh = BlockHeight; ColorPalette pal = src.Palette; PixelFormat fmt = src.IsIndexed() ? src.PixelFormat : PixelFormat.Format32bppArgb; FileMap fileView = FileMap.FromTempFile(GetFileSize(w, h, mipLevels) + 0x20 + (pal != null ? (pal.Entries.Length * 2) : 0)); try { //Build REFT image header REFTImageHeader *header = (REFTImageHeader *)fileView.Address; *header = new REFTImageHeader((ushort)w, (ushort)h, (byte)RawFormat, (byte)format, (ushort)(pal != null ? pal.Entries.Length : 0), (uint)fileView.Length - 0x20 - (uint)(pal != null ? (pal.Entries.Length * 2) : 0), (byte)(mipLevels - 1)); int sStep = bw * Image.GetPixelFormatSize(fmt) / 8; int dStep = bw * bh * BitsPerPixel / 8; using (DIB dib = DIB.FromBitmap(src, bw, bh, fmt)) for (int i = 1; i <= mipLevels; i++) { EncodeLevel((VoidPtr)header + 0x20, dib, src, dStep, sStep, i); } if (pal != null) { int count = pal.Entries.Length; switch (format) { case WiiPaletteFormat.IA8: { IA8Pixel *dPtr = (IA8Pixel *)header->PaletteData; for (int i = 0; i < count; i++) { dPtr[i] = (IA8Pixel)pal.Entries[i]; } break; } case WiiPaletteFormat.RGB565: { wRGB565Pixel *dPtr = (wRGB565Pixel *)header->PaletteData; for (int i = 0; i < count; i++) { dPtr[i] = (wRGB565Pixel)pal.Entries[i]; } break; } case WiiPaletteFormat.RGB5A3: { wRGB5A3Pixel *dPtr = (wRGB5A3Pixel *)header->PaletteData; for (int i = 0; i < count; i++) { dPtr[i] = (wRGB5A3Pixel)pal.Entries[i]; } break; } } } return(fileView); } catch (Exception x) { MessageBox.Show(x.ToString()); fileView.Dispose(); return(null); } }
public static ARGBPixel[] ExtractColors(MDL0ColorData *colors) { int count = colors->_numEntries; ARGBPixel[] c = new ARGBPixel[count]; fixed(ARGBPixel *p = c) { ARGBPixel *dPtr = p; switch (colors->Type) { case WiiColorComponentType.RGB565: { wRGB565Pixel *sPtr = (wRGB565Pixel *)colors->Data; for (int i = 0; i < count; i++) { *dPtr++ = (ARGBPixel)(*sPtr++); } break; } case WiiColorComponentType.RGB8: { wRGBPixel *sPtr = (wRGBPixel *)colors->Data; for (int i = 0; i < count; i++) { *dPtr++ = (ARGBPixel)(*sPtr++); } break; } case WiiColorComponentType.RGBX8: { wRGBXPixel *sPtr = (wRGBXPixel *)colors->Data; for (int i = 0; i < count; i++) { *dPtr++ = (ARGBPixel)(*sPtr++); } break; } case WiiColorComponentType.RGBA4: { wRGBA4Pixel *sPtr = (wRGBA4Pixel *)colors->Data; for (int i = 0; i < count; i++) { *dPtr++ = (ARGBPixel)(*sPtr++); } break; } case WiiColorComponentType.RGBA6: { wRGBA6Pixel *sPtr = (wRGBA6Pixel *)colors->Data; for (int i = 0; i < count; i++) { *dPtr++ = (ARGBPixel)(*sPtr++); } break; } case WiiColorComponentType.RGBA8: { wRGBAPixel *sPtr = (wRGBAPixel *)colors->Data; for (int i = 0; i < count; i++) { *dPtr++ = (ARGBPixel)(*sPtr++); } break; } } } return(c); }
public virtual FileMap EncodeREFTTexture(Bitmap src, int mipLevels, WiiPaletteFormat format, bool usePalette) { int w = src.Width, h = src.Height; int bw = BlockWidth, bh = BlockHeight; //int aw = w.Align(bw), ah = h.Align(bh); ColorPalette pal = src.Palette; PixelFormat fmt = src.IsIndexed() ? src.PixelFormat : PixelFormat.Format32bppArgb; //int fileSize = GetMipOffset(w, h, mipLevels + 1) + 0x20; FileMap fileView = FileMap.FromTempFile(GetFileSize(w, h, mipLevels, true) + (usePalette ? (pal.Entries.Length * 2) : 0)); //FileMap fileView = FileMap.FromTempFile(fileSize); try { //Build REFT image header REFTData *header = (REFTData *)fileView.Address; * header = new REFTData((ushort)w, (ushort)h, (byte)RawFormat); header->_imagelen = (uint)fileView.Length - 0x20; int sStep = bw * Image.GetPixelFormatSize(fmt) / 8; int dStep = bw * bh * BitsPerPixel / 8; VoidPtr baseAddr = (byte *)header + 0x20; using (DIB dib = DIB.FromBitmap(src, bw, bh, fmt)) for (int i = 1; i <= mipLevels; i++) { EncodeLevel(baseAddr, dib, src, dStep, sStep, i); } if (usePalette) { int count = pal.Entries.Length; header->_colorCount = (ushort)count; header->_pltFormat = (byte)format; switch (format) { case WiiPaletteFormat.IA8: { IA8Pixel *dPtr = (IA8Pixel *)header->PaletteData; for (int i = 0; i < count; i++) { dPtr[i] = (IA8Pixel)pal.Entries[i]; } break; } case WiiPaletteFormat.RGB565: { wRGB565Pixel *dPtr = (wRGB565Pixel *)header->PaletteData; for (int i = 0; i < count; i++) { dPtr[i] = (wRGB565Pixel)pal.Entries[i]; } break; } case WiiPaletteFormat.RGB5A3: { wRGB5A3Pixel *dPtr = (wRGB5A3Pixel *)header->PaletteData; for (int i = 0; i < count; i++) { dPtr[i] = (wRGB5A3Pixel)pal.Entries[i]; } break; } } } return(fileView); } catch (Exception x) { //MessageBox.Show(x.ToString()); fileView.Dispose(); return(null); } }