Esempio n. 1
0
        public static unsafe void Clamp(this Bitmap bmp, WiiPixelFormat format)
        {
            int        w = bmp.Width, h = bmp.Height;
            BitmapData data = bmp.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);

            PixelClamper clmp;

            switch (format)
            {
            case WiiPixelFormat.I4: { clmp = p => { *p = ((I4Pixel)(*p))[0]; }; break; }

            case WiiPixelFormat.I8: { clmp = p => { *p = (ARGBPixel)(I8Pixel)(*p); }; break; }

            case WiiPixelFormat.IA4: { clmp = p => { *p = (ARGBPixel)(IA4Pixel)(*p); }; break; }

            case WiiPixelFormat.IA8: { clmp = p => { *p = (ARGBPixel)(IA8Pixel)(*p); }; break; }

            case WiiPixelFormat.RGB565: { clmp = p => { *p = (ARGBPixel)(wRGB565Pixel)(*p); }; break; }

            case WiiPixelFormat.RGB5A3: { clmp = p => { *p = (ARGBPixel)(wRGB5A3Pixel)(*p); }; break; }

            case WiiPixelFormat.RGBA8:
            default: { clmp = p => { }; break; }
            }

            for (ARGBPixel *ptr = (ARGBPixel *)data.Scan0, ceil = ptr + (w * h); ptr < ceil;)
            {
                clmp(ptr++);
            }

            bmp.UnlockBits(data);
        }
Esempio n. 2
0
        public static TextureConverter Get(WiiPixelFormat format)
        {
            switch (format)
            {
            case WiiPixelFormat.I4: return(I4);

            case WiiPixelFormat.IA4: return(IA4);

            case WiiPixelFormat.I8: return(I8);

            case WiiPixelFormat.IA8: return(IA8);

            case WiiPixelFormat.RGB565: return(RGB565);

            case WiiPixelFormat.RGB5A3: return(RGB5A3);

            case WiiPixelFormat.CI4: return(CI4);

            case WiiPixelFormat.CI8: return(CI8);

            case WiiPixelFormat.CMPR: return(CMPR);

            case WiiPixelFormat.RGBA8: return(RGBA8);
            }
            return(null);
        }
Esempio n. 3
0
 public static Bitmap Quantize(Bitmap bmp, int colors, WiiPixelFormat texFormat, WiiPaletteFormat palFormat,
                               IProgressTracker progress)
 {
     using (MedianCut mc = new MedianCut(bmp, texFormat, palFormat))
     {
         return(mc.Quantize(colors, progress));
     }
 }
Esempio n. 4
0
 public virtual Bitmap DecodeTextureIndexed(VoidPtr addr, int w, int h, ColorPalette palette, int mipLevel,
                                            WiiPixelFormat fmt)
 {
     _workingPalette = palette;
     try
     {
         return(Decode(addr, w, h, mipLevel, fmt));
     }
     finally
     {
         _workingPalette = null;
     }
 }
Esempio n. 5
0
        protected override bool OnInitialize()
        {
            base.OnInitialize();

            _unk       = Header->_unknown;
            _format    = (WiiPixelFormat)Header->_format;
            _pltFormat = (WiiPaletteFormat)Header->_pltFormat;
            numColors  = Header->_colorCount;
            _imgLen    = (int)Header->_imagelen;
            _width     = Header->_width;
            _height    = Header->_height;

            return(false);
        }
Esempio n. 6
0
        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 *));
        }
Esempio n. 7
0
        protected override bool OnInitialize()
        {
            base.OnInitialize();

            if ((_name == null) && (Header->_stringOffset != 0))
            {
                _name = Header->ResourceString;
            }

            _width      = Header->_width;
            _height     = Header->_height;
            _format     = Header->PixelFormat;
            _lod        = Header->_levelOfDetail;
            _hasPalette = Header->HasPalette;

            return(false);
        }
Esempio n. 8
0
        /// <summary>
        /// Replace the MenSelmapMark texture in toReplace with the image in newBitmap, flipping the channels if the image has solid black in all four corners.
        /// </summary>
        /// <param name="newBitmap">The new texture to use</param>
        /// <param name="toReplace">The TEX0 to insert the texture in</param>
        /// <param name="createNew">If true, the format of the existing texture will not be used as a fallback, even if useExistingAsFallback is true</param>
        private void ReplaceSelmapMark(Bitmap newBitmap, TEX0Node toReplace, bool createNew)
        {
            WiiPixelFormat format =
                selmapMarkFormat != null
                                        ? selmapMarkFormat.Value
                                : useExistingAsFallback && !createNew
                                        ? toReplace.Format
                                : BitmapUtilities.HasAlpha(newBitmap)
                                        ? WiiPixelFormat.IA4
                                        : WiiPixelFormat.I4;

            Console.WriteLine(format);
            Bitmap toEncode = BitmapUtilities.HasSolidCorners(newBitmap) ? BitmapUtilities.AlphaSwap(newBitmap) : newBitmap;

            BrawlLib.IO.FileMap tMap = TextureConverter.Get(format).EncodeTEX0Texture(toEncode, 1);
            toReplace.ReplaceRaw(tMap);
        }
Esempio n. 9
0
        public override bool OnInitialize()
        {
            base.OnInitialize();
            _headerLen = Header1->_headerLen;

            _sharesData = _headerLen > HeaderSize();
            if (_sharesData)
            {
                SetSizeInternal(ExclusiveEntrySize());
            }

            if (_version == 2)
            {
                if ((_name == null) && (Header2->_stringOffset != 0))
                {
                    _name = Header2->ResourceString;
                }

                _width      = Header2->_width;
                _height     = Header2->_height;
                _format     = Header2->PixelFormat;
                _lod        = Header2->_levelOfDetail;
                _hasPalette = Header2->HasPalette;
            }
            else
            {
                if ((_name == null) && (Header1->_stringOffset != 0))
                {
                    _name = Header1->ResourceString;
                }

                _width      = Header1->_width;
                _height     = Header1->_height;
                _format     = Header1->PixelFormat;
                _lod        = Header1->_levelOfDetail;
                _hasPalette = Header1->HasPalette;
            }

            if (_version == 3)
            {
                (_userEntries = new UserDataCollection()).Read(Header3->UserData);
            }

            return(false);
        }
Esempio n. 10
0
        public override bool OnInitialize()
        {
            base.OnInitialize();

            _unk       = Header->_unknown;
            _format    = (WiiPixelFormat)Header->_format;
            _pltFormat = (WiiPaletteFormat)Header->_pltFormat;
            numColors  = Header->_colorCount;
            _imgLen    = (int)Header->_imagelen;
            _width     = Header->_width;
            _height    = Header->_height;
            _pltLen    = (int)Header->_pltSize;
            _lod       = Header->_mipmap + 1;
            _minFltr   = Header->_min_filt;
            _magFltr   = Header->_mag_filt;

            return(false);
        }
Esempio n. 11
0
        public TEX0v1(int width, int height, WiiPixelFormat format, int mipLevels)
        {
            _header._tag        = Tag;
            _header._size       = TextureConverter.Get(format).GetMipOffset(width, height, mipLevels + 1) + Size;
            _header._version    = 1;
            _header._bresOffset = 0;

            _headerLen      = Size;
            _stringOffset   = 0;
            _hasPalette     = ((format == WiiPixelFormat.CI4) || (format == WiiPixelFormat.CI8)) ? 1 : 0;
            _width          = (short)width;
            _height         = (short)height;
            _pixelFormat    = (int)format;
            _levelOfDetail  = mipLevels;
            _minLod         = 0;
            _maxLod         = mipLevels - 1.0f;
            _origPathOffset = 0;
        }
Esempio n. 12
0
        public TEX0v1(int width, int height, WiiPixelFormat format, int mipLevels)
        {
            _header._tag = Tag;
            _header._size = TextureConverter.Get(format).GetMipOffset(width, height, mipLevels + 1) + Size;
            _header._version = 1;
            _header._bresOffset = 0;

            _headerLen = Size;
            _stringOffset = 0;
            _hasPalette = ((format == WiiPixelFormat.CI4) || (format == WiiPixelFormat.CI8)) ? 1 : 0;
            _width = (short)width;
            _height = (short)height;
            _pixelFormat = (int)format;
            _levelOfDetail = mipLevels;
            _minLod = 0;
            _maxLod = mipLevels - 1.0f;
            _origPathOffset = 0;
        }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
        public override bool OnInitialize()
        {
            base.OnInitialize();

            if ((_name == null) && (Header1->_stringOffset != 0))
            {
                _name = Header1->ResourceString;
            }

            _width      = Header1->_width;
            _height     = Header1->_height;
            _format     = Header1->PixelFormat;
            _lod        = Header1->_levelOfDetail;
            _hasPalette = Header1->HasPalette;
            _version    = Header1->_header._version;

            if (_version == 3)
            {
                (_userEntries = new UserDataCollection()).Read(Header3->UserData);
            }

            return(false);
        }
Esempio n. 15
0
        public TEX0(int width, int height, WiiPixelFormat format, int mipLevels)
        {
            _header._tag        = Tag;
            _header._size       = TextureConverter.Get(format).GetMipOffset(width, height, mipLevels + 1) + Size;
            _header._version    = 1;
            _header._bresOffset = 0;

            _headerLen     = Size;
            _stringOffset  = 0;
            _hasPalette    = ((format == WiiPixelFormat.CI4) || (format == WiiPixelFormat.CI8)) ? 1 : 0;
            _width         = (short)width;
            _height        = (short)height;
            _pixelFormat   = (int)format;
            _levelOfDetail = mipLevels;
            _unknown       = 0;
            _lodBias       = mipLevels - 1.0f;

            fixed(uint *p = _padding)
            for (int i = 0; i < 4; i++)
            {
                p[i] = 0;
            }
        }
Esempio n. 16
0
 public static Bitmap Decode(VoidPtr addr, int w, int h, int mipLevel, WiiPixelFormat fmt)
 {
     return(Get(fmt).DecodeTexture(addr, w, h, mipLevel));
 }
 public static TextureConverter Get(WiiPixelFormat format)
 {
     switch (format)
     {
         case WiiPixelFormat.I4: return I4;
         case WiiPixelFormat.IA4: return IA4;
         case WiiPixelFormat.I8: return I8;
         case WiiPixelFormat.IA8: return IA8;
         case WiiPixelFormat.RGB565: return RGB565;
         case WiiPixelFormat.RGB5A3: return RGB5A3;
         case WiiPixelFormat.CI4: return CI4;
         case WiiPixelFormat.CI8: return CI8;
         case WiiPixelFormat.CMPR: return CMPR;
         case WiiPixelFormat.RGBA8: return RGBA8;
     }
     return null;
 }
 public virtual Bitmap DecodeTextureIndexed(VoidPtr addr, int w, int h, ColorPalette palette, int mipLevel, WiiPixelFormat fmt)
 {
     _workingPalette = palette;
     try { return Decode(addr, w, h, mipLevel, fmt); }
     finally { _workingPalette = null; }
 }
 public static Bitmap Decode(VoidPtr addr, int w, int h, int mipLevel, WiiPixelFormat fmt)
 {
     return Get(fmt).DecodeTexture(addr, w, h, mipLevel);
 }
Esempio n. 20
0
        //public static unsafe ColorPalette GeneratePalette(this Bitmap bmp, QuantizationAlgorithm mode, int numColors)
        //{
        //    ColorInformation info = bmp.GetColorInformation();

        //    ColorPalette pal = ColorPaletteExtension.CreatePalette(ColorPaletteFlags.None, numColors);
        //    if (info.UniqueColors.Length <= numColors)
        //    {
        //        //Use original colors
        //        for (int i = 0; i < info.UniqueColors.Length; i++)
        //            pal.Entries[i] = (Color)info.UniqueColors[i];
        //    }
        //    else
        //    {
        //        switch (mode)
        //        {
        //            case QuantizationAlgorithm.WeightedAverage:
        //                {
        //                    pal = WeightedAverage.Process(bmp, numColors);
        //                    break;
        //                }
        //            //case QuantizationAlgorithm.MedianCut:
        //            //    {
        //            //        MedianCut.Quantize(bmp, numColors);
        //            //        break;
        //            //    }
        //        }
        //    }
        //    return pal;
        //}

        public static Bitmap Quantize(this Bitmap bmp, QuantizationAlgorithm algorithm, int numColors, WiiPixelFormat texFormat, WiiPaletteFormat palFormat, IProgressTracker progress)
        {
            return(MedianCut.Quantize(bmp, numColors, texFormat, palFormat, progress));
        }
 public static Bitmap DecodeIndexed(VoidPtr addr, int w, int h, ColorPalette palette, int mipLevel, WiiPixelFormat fmt)
 {
     return Get(fmt).DecodeTextureIndexed(addr, w, h, palette, mipLevel, fmt);
 }
Esempio n. 22
0
 public TEX0v1(int width, int height, WiiPixelFormat format, int mipLevels) : this(width, height, format, mipLevels, Size)
 {
 }
Esempio n. 23
0
        private void UpdatePreview()
        {
            if (_source == null)
            {
                return;
            }

            //Copy source to preview
            //Rectangle r = new Rectangle(0, 0, _source.Width, _source.Height);
            //BitmapData srcData = _source.LockBits(r, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
            //BitmapData dstData = _preview.LockBits(r, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);

            //Memory.Move(dstData.Scan0, srcData.Scan0, (uint)(srcData.Stride * _source.Height));

            //_preview.UnlockBits(dstData);
            //_source.UnlockBits(srcData);

            if (_cmprBuffer != null)
            {
                _cmprBuffer.Dispose(); _cmprBuffer = null;
            }
            if (_indexed != null)
            {
                _indexed.Dispose(); _indexed = null;
            }

            WiiPixelFormat format = (WiiPixelFormat)cboFormat.SelectedItem;

            switch (format)
            {
            case WiiPixelFormat.I4:     //_preview.Clamp(WiiPixelFormat.I4); break;
            case WiiPixelFormat.I8:     //_preview.Clamp(WiiPixelFormat.I8); break;
            case WiiPixelFormat.IA4:    //_preview.Clamp(WiiPixelFormat.IA4); break;
            case WiiPixelFormat.IA8:    //_preview.Clamp(WiiPixelFormat.IA8); break;
            case WiiPixelFormat.RGB565: //_preview.Clamp(WiiPixelFormat.RGB565); break;
            case WiiPixelFormat.RGB5A3: //_preview.Clamp(WiiPixelFormat.RGB5A3); break;
            case WiiPixelFormat.RGBA8:
            {
                CopyPreview(_source);
                _preview.Clamp(format);
                break;
            }

            case WiiPixelFormat.CMPR:
            {
                CopyPreview(_source);
                _cmprBuffer = TextureConverter.CMPR.GeneratePreview(_preview);
                break;
            }

            case WiiPixelFormat.CI4:
            case WiiPixelFormat.CI8:
            {
                _indexed = _source.Quantize((QuantizationAlgorithm)cboAlgorithm.SelectedItem, (int)numPaletteCount.Value, format, (WiiPaletteFormat)cboPaletteFormat.SelectedItem, null);
                CopyPreview(_indexed);
                break;
            }
            }

            UpdateSize();

            if (_previewing)
            {
                pictureBox1.Picture = _preview;
            }
            else
            {
                pictureBox1.Picture = _source;
            }
        }
Esempio n. 24
0
        public override bool OnInitialize()
        {
            base.OnInitialize();

            _unk = Header->_unknown;
            _format = (WiiPixelFormat)Header->_format;
            _pltFormat = (WiiPaletteFormat)Header->_pltFormat;
            numColors = Header->_colorCount;
            _imgLen = (int)Header->_imagelen;
            _width = Header->_width;
            _height = Header->_height;
            _pltLen = (int)Header->_pltSize;
            _lod = Header->_mipmap + 1;
            _minFltr = Header->_min_filt;
            _magFltr = Header->_mag_filt;

            return false;
        }
 //public static unsafe ColorPalette GeneratePalette(this Bitmap bmp, QuantizationAlgorithm mode, int numColors)
 //{
 //    ColorInformation info = bmp.GetColorInformation();
 //    ColorPalette pal = ColorPaletteExtension.CreatePalette(ColorPaletteFlags.None, numColors);
 //    if (info.UniqueColors.Length <= numColors)
 //    {
 //        //Use original colors
 //        for (int i = 0; i < info.UniqueColors.Length; i++)
 //            pal.Entries[i] = (Color)info.UniqueColors[i];
 //    }
 //    else
 //    {
 //        switch (mode)
 //        {
 //            case QuantizationAlgorithm.WeightedAverage:
 //                {
 //                    pal = WeightedAverage.Process(bmp, numColors);
 //                    break;
 //                }
 //            //case QuantizationAlgorithm.MedianCut:
 //            //    {
 //            //        MedianCut.Quantize(bmp, numColors);
 //            //        break;
 //            //    }
 //        }
 //    }
 //    return pal;
 //}
 public static Bitmap Quantize(this Bitmap bmp, QuantizationAlgorithm algorithm, int numColors, WiiPixelFormat texFormat, WiiPaletteFormat palFormat, IProgressTracker progress)
 {
     return MedianCut.Quantize(bmp, numColors, texFormat, palFormat, progress);
 }
        public static unsafe void Clamp(this Bitmap bmp, WiiPixelFormat format)
        {
            int w = bmp.Width, h = bmp.Height;
            BitmapData data = bmp.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);

            PixelClamper clmp;
            switch (format)
            {
                case WiiPixelFormat.I4: { clmp = p => { *p = ((I4Pixel)(*p))[0]; }; break; }
                case WiiPixelFormat.I8: { clmp = p => { *p = (ARGBPixel)(I8Pixel)(*p); }; break; }
                case WiiPixelFormat.IA4: { clmp = p => { *p = (ARGBPixel)(IA4Pixel)(*p); }; break; }
                case WiiPixelFormat.IA8: { clmp = p => { *p = (ARGBPixel)(IA8Pixel)(*p); }; break; }
                case WiiPixelFormat.RGB565: { clmp = p => { *p = (ARGBPixel)(wRGB565Pixel)(*p); }; break; }
                case WiiPixelFormat.RGB5A3: { clmp = p => { *p = (ARGBPixel)(wRGB5A3Pixel)(*p); }; break; }
                case WiiPixelFormat.RGBA8:
                default: { clmp = p => { }; break; }
            }

            for (ARGBPixel* ptr = (ARGBPixel*)data.Scan0, ceil = ptr + (w * h); ptr < ceil; )
                clmp(ptr++);

            bmp.UnlockBits(data);
        }
Esempio n. 27
0
 public static Bitmap Quantize(Bitmap bmp, int colors, WiiPixelFormat texFormat, WiiPaletteFormat palFormat, IProgressTracker progress)
 {
     using (MedianCut mc = new MedianCut(bmp, texFormat, palFormat))
         return mc.Quantize(colors, progress);
 }
Esempio n. 28
0
 public static Bitmap DecodeIndexed(VoidPtr addr, int w, int h, ColorPalette palette, int mipLevel, WiiPixelFormat fmt)
 {
     return(Get(fmt).DecodeTextureIndexed(addr, w, h, palette, mipLevel, fmt));
 }
Esempio n. 29
0
        public override bool OnInitialize()
        {
            base.OnInitialize();

            _name = "Texture";

            _width = Header->_width;
            _height = Header->_height;
            _format = Header->PixelFormat;
            _uWrap = Header->_wrapS;
            _vWrap = Header->_wrapT;
            _minFltr = Header->_minFilter;
            _magFltr = Header->_magFilter;
            _lod = Header->_maxLOD + 1;
            _enableEdgeLod = Header->_edgeLODEnable;

            if (_replaced)
                _dataAddr = WorkingUncompressed.Address + Header->_data;

            return false;
        }