/// <summary>
        /// Assigns a new Texture2D based on dye colour.
        /// </summary>
        public ImageData ChangeDye(ImageData imageData, DyeColors dye, DyeTargets target)
        {
            imageData.dfBitmap = ImageProcessing.ChangeDye(imageData.dfBitmap, dye, target);
            ImageReader.UpdateTexture(ref imageData);

            return(imageData);
        }
Пример #2
0
        /// <summary>
        /// Dye supported bitmap image based on dye index and type.
        /// </summary>
        /// <param name="srcBitmap">Source image.</param>
        /// <param name="dye">Dye index.</param>
        /// <param name="target">Dye target.</param>
        /// <returns>New DFBitmap dyed to specified colour.</returns>
        public static DFBitmap ChangeDye(DFBitmap srcBitmap, DyeColors dye, DyeTargets target)
        {
            const int clothingStart        = 0x60;
            const int weaponsAndArmorStart = 0x70;

            // Clone bitmap and get colour table for swaps
            DFBitmap dstBitmap = DFBitmap.CloneDFBitmap(srcBitmap, false);

            byte[] swaps = GetDyeColorTable(dye, target);

            // Swaps range is based on target type
            int start;

            switch (target)
            {
            case DyeTargets.Clothing:
                start = clothingStart;
                break;

            case DyeTargets.WeaponsAndArmor:
                start = weaponsAndArmorStart;
                break;

            default:
                return(dstBitmap);
            }

            // Swap indices start through start + 15 with colour table
            int rowPos;

            for (int y = 0; y < srcBitmap.Height; y++)
            {
                rowPos = y * srcBitmap.Width;
                for (int x = 0; x < srcBitmap.Width; x++)
                {
                    int  srcOffset = rowPos + x;
                    byte index     = srcBitmap.Data[srcOffset];

                    if (index >= start && index <= start + 0x0f)
                    {
                        int tintOffset = index - start;
                        dstBitmap.Data[srcOffset] = swaps[tintOffset];
                    }
                    else
                    {
                        dstBitmap.Data[srcOffset] = index;
                    }
                }
            }

            return(dstBitmap);
        }
        /// <summary>
        /// Dye supported bitmap image based on dye index and type.
        /// </summary>
        /// <param name="srcBitmap">Source image.</param>
        /// <param name="dye">Dye index.</param>
        /// <param name="target">Dye target.</param>
        /// <returns>New DFBitmap dyed to specified colour.</returns>
        public static DFBitmap ChangeDye(DFBitmap srcBitmap, DyeColors dye, DyeTargets target)
        {
            const int clothingStart = 0x60;
            const int weaponsAndArmorStart = 0x70;

            // Clone bitmap and get colour table for swaps
            DFBitmap dstBitmap = DFBitmap.CloneDFBitmap(srcBitmap, false);
            byte[] swaps = GetDyeColorTable(dye, target);

            // Swaps range is based on target type
            int start;
            switch(target)
            {
                case DyeTargets.Clothing:
                    start = clothingStart;
                    break;
                case DyeTargets.WeaponsAndArmor:
                    start = weaponsAndArmorStart;
                    break;
                default:
                    return dstBitmap;
            }

            // Swap indices start through start + 15 with colour table
            int rowPos;
            for (int y = 0; y < srcBitmap.Height; y++)
            {
                rowPos = y * srcBitmap.Width;
                for (int x = 0; x < srcBitmap.Width; x++)
                {
                    int srcOffset = rowPos + x;
                    byte index = srcBitmap.Data[srcOffset];

                    if (index >= start && index <= start + 0x0f)
                    {
                        int tintOffset = index - start;
                        dstBitmap.Data[srcOffset] = swaps[tintOffset];
                    }
                    else
                    {
                        dstBitmap.Data[srcOffset] = index;
                    }
                }
            }

            return dstBitmap;
        }
        /// <summary>
        /// Assigns a new Texture2D based on dye colour.
        /// </summary>
        public ImageData ChangeDye(ImageData imageData, DyeColors dye, DyeTargets target)
        {
            imageData.dfBitmap = ImageProcessing.ChangeDye(imageData.dfBitmap, dye, target);
            ImageReader.UpdateTexture(ref imageData);

            return imageData;
        }
        /// <summary>
        /// Gets colour table for all supported dyes.
        /// </summary>
        public static byte[] GetDyeColorTable(DyeColors dye, DyeTargets target)
        {
            // Dye targets require slightly different handling
            if (target == DyeTargets.Clothing)
            {
                // Clothing
                int start = 0x60;
                byte[] swaps = new byte[16];
                switch (dye)
                {
                    case DyeColors.Blue:
                        start = 0x60;
                        break;
                    case DyeColors.Grey:
                        start = 0x50;
                        break;
                    case DyeColors.Red:
                        start = 0xEF;
                        break;
                    case DyeColors.DarkBrown:
                        start = 0x20;
                        break;
                    case DyeColors.Purple:
                        start = 0x30;
                        break;
                    case DyeColors.LightBrown:
                        start = 0x40;
                        break;
                    case DyeColors.White:
                        start = 0x70;
                        break;
                    case DyeColors.Aquamarine:
                        start = 0x80;
                        break;
                    case DyeColors.Yellow:
                        start = 0x90;
                        break;
                    case DyeColors.Green:
                        start = 0xA0;
                        break;
                    default:
                        start = 0x60;
                        break;
                }

                // Geneate index swaps
                for (int i = 0; i < 16; i++)
                {
                    swaps[i] = (byte)(start + i);
                }

                return swaps;
            }
            else if (target == DyeTargets.WeaponsAndArmor)
            {
                // Metals
                switch (dye)
                {
                    case DyeColors.Iron:
                        return GetMetalColorTable(MetalTypes.Iron);
                    case DyeColors.Steel:
                        return GetMetalColorTable(MetalTypes.Steel);
                    case DyeColors.Chain:
                        return GetMetalColorTable(MetalTypes.Chain);
                    case DyeColors.SilverOrElven:
                        return GetMetalColorTable(MetalTypes.Silver);
                    case DyeColors.Dwarven:
                        return GetMetalColorTable(MetalTypes.Dwarven);
                    case DyeColors.Mithril:
                        return GetMetalColorTable(MetalTypes.Mithril);
                    case DyeColors.Adamantium:
                        return GetMetalColorTable(MetalTypes.Adamantium);
                    case DyeColors.Ebony:
                        return GetMetalColorTable(MetalTypes.Ebony);
                    case DyeColors.Orcish:
                        return GetMetalColorTable(MetalTypes.Orcish);
                    case DyeColors.Daedric:
                        return GetMetalColorTable(MetalTypes.Daedric);
                    default:
                        return GetMetalColorTable(MetalTypes.None);
                }
            }

            return null;
        }
Пример #6
0
        /// <summary>
        /// Gets colour table for all supported dyes.
        /// </summary>
        public static byte[] GetDyeColorTable(DyeColors dye, DyeTargets target)
        {
            // Dye targets require slightly different handling
            if (target == DyeTargets.Clothing)
            {
                // Clothing
                int    start = 0x60;
                byte[] swaps = new byte[16];
                switch (dye)
                {
                case DyeColors.Blue:
                    start = 0x60;
                    break;

                case DyeColors.Grey:
                    start = 0x50;
                    break;

                case DyeColors.Red:
                    start = 0xEF;
                    break;

                case DyeColors.DarkBrown:
                    start = 0x20;
                    break;

                case DyeColors.Purple:
                    start = 0x30;
                    break;

                case DyeColors.LightBrown:
                    start = 0x40;
                    break;

                case DyeColors.White:
                    start = 0x70;
                    break;

                case DyeColors.Aquamarine:
                    start = 0x80;
                    break;

                case DyeColors.Yellow:
                    start = 0x90;
                    break;

                case DyeColors.Green:
                    start = 0xA0;
                    break;

                default:
                    start = 0x60;
                    break;
                }

                // Geneate index swaps
                for (int i = 0; i < 16; i++)
                {
                    swaps[i] = (byte)(start + i);
                }

                return(swaps);
            }
            else if (target == DyeTargets.WeaponsAndArmor)
            {
                // Metals
                switch (dye)
                {
                case DyeColors.Iron:
                    return(GetMetalColorTable(MetalTypes.Iron));

                case DyeColors.Steel:
                    return(GetMetalColorTable(MetalTypes.Steel));

                case DyeColors.Silver:
                    return(GetMetalColorTable(MetalTypes.Silver));

                case DyeColors.Elven:
                    return(GetMetalColorTable(MetalTypes.Elven));

                case DyeColors.Dwarven:
                    return(GetMetalColorTable(MetalTypes.Dwarven));

                case DyeColors.Mithril:
                    return(GetMetalColorTable(MetalTypes.Mithril));

                case DyeColors.Adamantium:
                    return(GetMetalColorTable(MetalTypes.Adamantium));

                case DyeColors.Ebony:
                    return(GetMetalColorTable(MetalTypes.Ebony));

                case DyeColors.Orcish:
                    return(GetMetalColorTable(MetalTypes.Orcish));

                case DyeColors.Daedric:
                    return(GetMetalColorTable(MetalTypes.Daedric));

                default:
                    return(GetMetalColorTable(MetalTypes.None));
                }
            }

            return(null);
        }