Ejemplo n.º 1
0
        public void blendHSV(Image overlay, IntVector2 position, AlphaOption alphaOption, byte textureAlpha, BoundingBox boundingBox = null)
        {
            int minX, minY, maxX, maxY;
            setMinMax(out minX, out minY, out maxX, out maxY, boundingBox);

            for (int i = 0; i < overlay.width; ++i)
            {
                for (int j = 0; j < overlay.height; ++j)
                {
                    int px = position.x + i;
                    int py = position.y + j;
                    if (px >= minX && px <= maxX && py >= minY && py <= maxY)
                    {
                        Color32 overlayColor = Utils.GetElement2D(overlay.pixels, i, j, overlay.width);
                        if (overlayColor.a > 0)
                        {
                            Color32 oldColor = Utils.GetElement2D(pixels, px, py, width);

                            RGB rgb1 = new RGB(oldColor);
                            RGB rgb2 = new RGB(overlayColor);
                            HSV hsv1 = rgb1.toHSV();
                            HSV hsv2 = rgb2.toHSV();
                            HSV hsv3 = hsv1.blend(hsv2, (float) overlayColor.a / 255f);
                            RGB rgb3 = hsv3.toRGB();

                            pixels[px + py * width].r = Math.Min((byte) (rgb3.r * 255f), (byte) 255);
                            pixels[px + py * width].g = Math.Min((byte) (rgb3.g * 255f), (byte) 255);
                            pixels[px + py * width].b = Math.Min((byte) (rgb3.b * 255f), (byte) 255);

                            if (alphaOption == AlphaOption.OVERWRITE) pixels[px + py * width].a = textureAlpha;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
 protected void copyFromOverlay(Overlay overlay)
 {
     copyFromImageModifer(overlay);
     _position = new IntVector2(overlay._position);
     _mirror = overlay._mirror;
     _alpha = overlay._alpha;
     _textureAlpha = overlay._textureAlpha;
     _alphaOption = overlay._alphaOption;
     _normalScale = overlay._normalScale;
     _normalOption = overlay._normalOption;
     _blendMethod = overlay._blendMethod;
     _rotation = overlay._rotation;
 }
Ejemplo n.º 3
0
            protected void loadOverlay(ConfigNode node)
            {
                _position = new IntVector2();
                _mirror = false;
                _alpha = 255;
                _textureAlpha = 0;
                _alphaOption = AlphaOption.USE_TEXTURE;
                _normalScale = 2.0f;
                _normalOption = NormalOption.USE_BACKGROUND;
                _blendMethod = BlendMethod.RGB;
                _rotation = Rotation.R0;

                if (node.HasValue("x")) _position.x = int.Parse(node.GetValue("x"));
                if (node.HasValue("y")) _position.y = int.Parse(node.GetValue("y"));
                if (node.HasValue("mirror")) _mirror = bool.Parse(node.GetValue("mirror"));
                if (node.HasValue("alpha")) _alpha = byte.Parse(node.GetValue("alpha"));
                if (node.HasValue("textureAlpha")) _textureAlpha = byte.Parse(node.GetValue("textureAlpha"));
                if (node.HasValue("alphaOption")) _alphaOption = (AlphaOption)ConfigNode.ParseEnum(typeof(AlphaOption), node.GetValue("alphaOption"));
                if (node.HasValue("normalScale")) _normalScale = int.Parse(node.GetValue("normalScale"));
                if (node.HasValue("normalOption")) _normalOption = (NormalOption)ConfigNode.ParseEnum(typeof(NormalOption), node.GetValue("normalOption"));
                if (node.HasValue("blendMethod")) _blendMethod = (BlendMethod)ConfigNode.ParseEnum(typeof(BlendMethod), node.GetValue("blendMethod"));
                if (node.HasValue("rotation")) _rotation = (Rotation)ConfigNode.ParseEnum(typeof(Rotation), node.GetValue("rotation"));
            }
Ejemplo n.º 4
0
        public void alphaOptionSelector(TextureEditGUI gui, ref AlphaOption alphaOption)
        {
            GUILayout.BeginVertical(GUI.skin.box, GUILayout.ExpandHeight(true));

            GUILayout.Label("Alpha Option");

            int selection = (int) alphaOption;
            int oldSelection = selection;
            selection = GUILayout.SelectionGrid(selection, _alphaOptionGrid, 1);

            if (oldSelection != selection)
            {
                alphaOption = (AlphaOption) selection;
                gui.setRemakePreview();
            }

            GUILayout.EndVertical();
        }
Ejemplo n.º 5
0
        public void blendImage(Image image, BlendMethod blendMethod, IntVector2 position, AlphaOption alphaOption, byte alpha, BoundingBox boundingBox = null)
        {
            switch (blendMethod)
            {
                case ASP.BlendMethod.HSV:
                    blendHSV(image, position, alphaOption, alpha, boundingBox);
                    break;

                case ASP.BlendMethod.RGB:
                    blendRGB(image, position, alphaOption, alpha, boundingBox);
                    break;

                case ASP.BlendMethod.PIXEL:
                default:
                    overlay(image, position, alphaOption, alpha, boundingBox);
                    break;
            }
        }
Ejemplo n.º 6
0
        public void overlay(Image overlay, IntVector2 position, AlphaOption alphaOption, byte textureAlpha, BoundingBox boundingBox = null)
        {
            int minX, minY, maxX, maxY;
            setMinMax(out minX, out minY, out maxX, out maxY, boundingBox);

            for (int i = 0; i < overlay.width; ++i)
            {
                for (int j = 0; j < overlay.height; ++j)
                {
                    int px = position.x + i;
                    int py = position.y + j;
                    if (px >= minX && px <= maxX && py >= minY && py <= maxY)
                    {
                        if (overlay.pixels[i + j * overlay.width].a > 127)
                        {
                            pixels[px + py * width].r = overlay.pixels[i + j * overlay.width].r;
                            pixels[px + py * width].g = overlay.pixels[i + j * overlay.width].g;
                            pixels[px + py * width].b = overlay.pixels[i + j * overlay.width].b;

                            if (alphaOption == AlphaOption.OVERWRITE) pixels[px + py * width].a = textureAlpha;
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public void drawText(string text, BitmapFont font, IntVector2 position, Rotation rotation, Color32 color, bool mirror, AlphaOption alphaOption,
                             byte textureAlpha, BlendMethod blendMethod, BoundingBox boundingBox = null)
        {
            if (Global.Debug2) Utils.Log("text {0}, x {1}, y {2}", text, position.x, position.y);

            IntVector2 charPos = new IntVector2(position);
            bool escapeMode = false;

            string textToWrite = string.Empty;
            if (mirror) textToWrite = ASP.Utils.Reverse(text);
            else textToWrite = text;

            foreach (char c in textToWrite)
            {
                if (c == '\\')
                {
                    escapeMode = !escapeMode;
                }

                if (escapeMode)
                {
                    if (c == 'n')
                    {
                        switch (rotation)
                        {
                            case Rotation.R90:
                                charPos.x -= font.size;
                                charPos.y = position.y;
                                break;
                            case Rotation.R270:
                                charPos.x += font.size;
                                charPos.y = position.y;
                                break;

                            case Rotation.R0:
                                charPos.y -= font.size;
                                charPos.x = position.x;
                                break;
                            case Rotation.R180:
                            default:
                                charPos.y += font.size;
                                charPos.x = position.x;
                                break;
                        }
                    }
                    if (c != '\\') escapeMode = false;
                }
                else drawCharacter(c, font, ref charPos, rotation, color, mirror, alphaOption, textureAlpha, blendMethod, boundingBox);
            }
        }
Ejemplo n.º 8
0
        public void drawText(string text, string fontName, int fontSize, IntVector2 position, Rotation rotation, Color32 color, bool mirror, AlphaOption alphaOption,
                             byte textureAlpha, BlendMethod blendMethod, BoundingBox boundingBox = null)
        {
            BitmapFont font = BitmapFontCache.Instance.getFontByNameSize(fontName, fontSize);
            if (font == null) font = BitmapFontCache.Instance.fonts.First();

            drawText(text, font, position, rotation, color, mirror, alphaOption, textureAlpha, blendMethod, boundingBox);
        }
Ejemplo n.º 9
0
        public void drawCharacter(char c, BitmapFont font, ref IntVector2 position, Rotation rotation, Color32 color, bool mirror, AlphaOption alphaOption,
                                  byte textureAlpha, BlendMethod blendMethod, BoundingBox boundingBox = null)
        {
            if (Global.Debug3) Utils.Log("char {0}, x {1}, y {2}", c, position.x, position.y);

            ASP.BitmapChar charMap;
            IntVector2 cPos = new IntVector2();

            if (font.characterMap.TryGetValue(c, out charMap) == false)
            {
                c = '?';
                if (font.characterMap.TryGetValue(c, out charMap) == false) return;
            }

            Image charImage = new Image(charMap.image);
            charImage.recolor(Global.Black32, color, false, true);

            if (mirror) charImage.flipHorizontally();

            switch (rotation)
            {
                case Rotation.R180:
                    charImage.rotate180();
                    cPos.x = position.x - ((int)charMap.vx + (int)charMap.vw);
                    cPos.y = position.y - (font.size + (int)charMap.vy);
                    position.x -= (int) charMap.cw;
                    break;

                case Rotation.R90:
                    charImage.flipXY(true);
                    cPos.x = position.x + (font.size + (int)charMap.vy + (int)charMap.vh);
                    cPos.y = position.y - ((int)charMap.vx + (int)charMap.vw);
                    position.y -= (int)charMap.cw;
                    break;

                case Rotation.R270:
                    charImage.flipXY(false);
                    cPos.x = position.x - (font.size + (int)charMap.vy);
                    cPos.y = position.y + (int)charMap.vx;
                    position.y += (int)charMap.cw;
                    break;

                case Rotation.R0:
                default:
                    cPos.x = position.x + (int)charMap.vx;
                    cPos.y = position.y + (font.size + (int)charMap.vy + (int)charMap.vh);
                    position.x += (int)charMap.cw;
                    break;
            }

            blendImage(charImage, blendMethod, cPos, alphaOption, textureAlpha, boundingBox);
        }
Ejemplo n.º 10
0
        public void blendRGB(Image overlay, IntVector2 position, AlphaOption alphaOption, byte textureAlpha, BoundingBox boundingBox = null)
        {
            int minX, minY, maxX, maxY;
            setMinMax(out minX, out minY, out maxX, out maxY, boundingBox);

            for (int i = 0; i < overlay.width; ++i)
            {
                for (int j = 0; j < overlay.height; ++j)
                {
                    int px = position.x + i;
                    int py = position.y + j;
                    if (px >= minX && px <= maxX && py >= minY && py <= maxY)
                    {
                        Color32 overlayColor = Utils.GetElement2D(overlay.pixels, i, j, overlay.width);

                        if (overlayColor.a > 0)
                        {
                            Color32 oldColor = Utils.GetElement2D(pixels, px, py, width);
                            Color32 newColor = Color32.Lerp(oldColor, overlayColor, (float) overlayColor.a / 255f);

                            pixels[px + py * width].r = newColor.r;
                            pixels[px + py * width].g = newColor.g;
                            pixels[px + py * width].b = newColor.b;

                            if (alphaOption == AlphaOption.OVERWRITE) pixels[px + py * width].a = textureAlpha;
                        }
                    }
                }
            }
        }
Ejemplo n.º 11
0
 public void SetAlpha(AlphaOption value)
 {
   IntPtr exception = IntPtr.Zero;
   #if ANYCPU
   if (NativeLibrary.Is64Bit)
   #endif
   #if WIN64 || ANYCPU
   NativeMethods.X64.MagickImage_SetAlpha(Instance, (UIntPtr)value, out exception);
   #endif
   #if ANYCPU
   else
   #endif
   #if !WIN64 || ANYCPU
   NativeMethods.X86.MagickImage_SetAlpha(Instance, (UIntPtr)value, out exception);
   #endif
   CheckException(exception);
 }