private MedianCut(Bitmap bmp, WiiPixelFormat texFormat, WiiPaletteFormat palFormat) { //Set output format if (texFormat == WiiPixelFormat.CI4) { _outFormat = PixelFormat.Format4bppIndexed; } else if (texFormat == WiiPixelFormat.CI8) { _outFormat = PixelFormat.Format8bppIndexed; } else { throw new ArgumentException("Invalid pixel format."); } //Set conversion functions if (palFormat == WiiPaletteFormat.IA8) { _idFunc = IA8Handler; _idConv = IA8Converter; } else if (palFormat == WiiPaletteFormat.RGB565) { _idFunc = RGB565Handler; _idConv = RGB565Converter; } else { _idFunc = RGB5A3Handler; _idConv = RGB5A3Converter; } //Lock/set source data _srcBmp = bmp; _width = bmp.Width; _height = bmp.Height; _size = _width * _height; _srcData = bmp.LockBits(new Rectangle(0, 0, _width, _height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); _srcPixels = (ARGBPixel *)_srcData.Scan0; //Create buffers _boxes = (ColorBox *)Marshal.AllocHGlobal(256 * sizeof(ColorBox)); _groupTable = (ColorEntry **)Marshal.AllocHGlobal(65536 * sizeof(void *)); }
private MedianCut(Bitmap bmp, WiiPixelFormat texFormat, WiiPaletteFormat palFormat) { //Set output format if (texFormat == WiiPixelFormat.CI4) _outFormat = PixelFormat.Format4bppIndexed; else if (texFormat == WiiPixelFormat.CI8) _outFormat = PixelFormat.Format8bppIndexed; else throw new ArgumentException("Invalid pixel format."); //Set conversion functions if (palFormat == WiiPaletteFormat.IA8) { _idFunc = IA8Handler; _idConv = IA8Converter; } else if (palFormat == WiiPaletteFormat.RGB565) { _idFunc = RGB565Handler; _idConv = RGB565Converter; } else { _idFunc = RGB5A3Handler; _idConv = RGB5A3Converter; } //Lock/set source data _srcBmp = bmp; _width = bmp.Width; _height = bmp.Height; _size = _width * _height; _srcData = bmp.LockBits(new Rectangle(0, 0, _width, _height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); _srcPixels = (ARGBPixel*)_srcData.Scan0; //Create buffers _boxes = (ColorBox*)Marshal.AllocHGlobal(256 * sizeof(ColorBox)); _groupTable = (ColorEntry**)Marshal.AllocHGlobal(65536 * 4); }