コード例 #1
0
        public static DDSEncoderResult EncodeTex(DDSLoadResult img)
        {
            var numMips   = 1;
            var alignment = 512;

            var fmt = EncoderTable[img.Format];

            var blockHeight         = Utils.getBlockHeight(Utils.DIV_ROUND_UP(img.height, fmt.blkHeight));
            var blockHeightLog2     = Utils.Log2(blockHeight);
            var linesPerBlockHeight = blockHeight * 8;

            var surfSize         = 0;
            var blockHeightShift = 0;

            List <int>  mipOfsets = new List <int>();
            List <byte> res       = new List <byte>();

            for (int mipLevel = 0; mipLevel < numMips; mipLevel++)
            {
                var    offSize = getCurrentMipOffset_Size(img.width, img.height, fmt.blkWidth, fmt.blkHeight, fmt.bpp, mipLevel);
                byte[] data    = new byte[offSize.Item2];
                Array.Copy(img.data, offSize.Item1, data, 0, offSize.Item2);
                var width_         = Math.Max(1, img.width >> mipLevel);
                var height_        = Math.Max(1, img.height >> mipLevel);
                var width__        = Utils.DIV_ROUND_UP(width_, fmt.blkWidth);
                var height__       = Utils.DIV_ROUND_UP(height_, fmt.blkHeight);
                int dataAlignBytes = Utils.round_up(surfSize, alignment) - surfSize;
                surfSize += dataAlignBytes;
                mipOfsets.Add(surfSize);
                if (Utils.pow2_round_up(height__) < linesPerBlockHeight)
                {
                    blockHeightShift += 1;
                }
                var pitch = Utils.round_up(width__ * fmt.bpp, 64);
                surfSize += pitch * Utils.round_up(height__, Math.Max(1, blockHeight >> blockHeightShift) * 8);

                if (dataAlignBytes != 0)
                {
                    res.AddRange(new byte[dataAlignBytes]);
                }
                res.AddRange(Swizzle.swizzle(width_, height_, fmt.blkWidth, fmt.blkHeight, true, fmt.bpp, 0, Math.Max(0, blockHeightLog2 - blockHeightShift), data, true));
            }

            return(new DDSEncoderResult {
                Data = res.ToArray(), blockHeightLog2 = blockHeightLog2, format = fmt
            });
        }
コード例 #2
0
ファイル: App.cs プロジェクト: kvm1st/SwitchThemeInjector
        public static byte[] Make(SarcData input, DDSLoadResult dds, PatchTemplate targetPatch, LayoutPatch layout)
        {
            if (layout != null)
            {
                var layoutres = SwitchThemesCommon.PatchLayouts(input, layout.Files);
                if (layoutres == BflytFile.PatchResult.Fail)
                {
                    Window.Alert("One of the target files for the selected layout patch is missing in the SZS, you are probably using an already patched SZS or the wrong layout");
                    return(null);
                }
                else if (layoutres == BflytFile.PatchResult.CorruptedFile)
                {
                    Window.Alert("A layout in this SZS is missing a pane required for the selected layout patch, you are probably using an already patched SZS or the wrong layout");
                    return(null);
                }
            }

            if (SwitchThemesCommon.PatchBntx(input, dds, targetPatch) == BflytFile.PatchResult.Fail)
            {
                Window.Alert(
                    "Can't build this theme: the szs you opened doesn't contain some information needed to patch the bntx," +
                    "without this information it is not possible to rebuild the bntx." +
                    "You should use an original or at least working szs");
                return(null);
            }
            var res = SwitchThemesCommon.PatchBgLayouts(input, targetPatch);

            if (res == BflytFile.PatchResult.Fail)
            {
                Window.Alert("Couldn't patch this file, it might have been already modified or it's from an unsupported system version.");
                return(null);
            }
            else if (res == BflytFile.PatchResult.CorruptedFile)
            {
                Window.Alert("This file has been already patched with another tool and is not compatible, you should get an unmodified layout.");
                return(null);
            }
            var sarc = SARC.PackN(input);

            return(ManagedYaz0.Compress(sarc.Item2, 1, (int)sarc.Item1));
        }