Exemplo n.º 1
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;
 }
Exemplo n.º 2
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"));
            }
Exemplo n.º 3
0
        /// <summary>
        /// Takes an image and hides the stream(text) in the image
        /// Make sure Image width by heigth are big enough for the text
        /// also encrypts text
        /// </summary>
        /// <param name="originalImagePath">path to an image</param>
        /// <param name="textPath">A text</param>
        /// <returns>Bitmap of the mixed imaged and stream</returns>
        public Bitmap BlendWhole(string originalImagePath, string textPath)
        {
            string text;

            using (StreamReader sr = new StreamReader(textPath))
            {
                text = sr.ReadToEnd();
            }
            Bitmap originalImage = new Bitmap(originalImagePath);


            // we use the stream to turn it in to a image
            Bitmap image = new Bitmap(originalImage.Width, originalImage.Height);

            int counter = 0;                           // originalTextEnd

            Random      random         = new Random(); //not so random
            List <char> charactersUsed = new List <char>();

            //first line
            for (int x = UnitsSavedForSizeString, y = 0; x < image.Width; x++) //!!!!
            {
                if (counter < text.Length)
                {
                    int charectarAsInt = text[counter];
                    if (!charactersUsed.Contains((char)charectarAsInt))
                    {
                        charactersUsed.Add((char)charectarAsInt);
                    }

                    image.SetPixel(x, y, BlendMethod.BlendPixel(originalImage.GetPixel(x, y), charectarAsInt));
                    counter++;
                }
            }
            //second -> last line
            for (int y = 1; y < image.Height; y++)
            {
                for (int x = 0; x < image.Width; x++)
                {
                    if (counter < text.Length)
                    {
                        int charectarAsInt = text[counter];
                        if (!charactersUsed.Contains((char)charectarAsInt))
                        {
                            charactersUsed.Add((char)charectarAsInt);
                        }

                        image.SetPixel(x, y, BlendMethod.BlendPixel(originalImage.GetPixel(x, y), charectarAsInt));
                        counter++;
                    }
                    else
                    {
                        int charectarAsInt = charactersUsed[random.Next(0, charactersUsed.Count)];  //get a randon that has already been used in the string

                        image.SetPixel(x, y, BlendMethod.BlendPixel(originalImage.GetPixel(x, y), charectarAsInt));
                    }
                }
            }


            //"secretly" puts lenght of message at the start of the image
            byte[] lengthOfMSGinBytes = BitConverter.GetBytes(counter);
            for (int x = 0; x < 4; x++)
            {
                image.SetPixel(x, 0, BlendMethod.BlendPixel(originalImage.GetPixel(x, 0), lengthOfMSGinBytes[x]));
            }


            return(image);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Unblends the 2 images and returns the text
        /// </summary>
        /// <param name="originalImagePath"></param>
        /// <param name="blendedImagePath"></param>
        /// <returns> text</returns>
        public string UnblendWhole(string originalImagePath, string blendedImagePath)
        {
            Bitmap originalImage = new Bitmap(originalImagePath);
            Bitmap blendedImage  = new Bitmap(blendedImagePath);

            string text = "";

            int stopAtElementIndex  = 0;
            int currentElementIndex = 0;

            BlendMethod.UnblendPixel(blendedImage.GetPixel(0, 0), originalImage.GetPixel(0, 0));
            var byteArray = new Byte[] {
                (byte)BlendMethod.UnblendPixel(blendedImage.GetPixel(0, 0), originalImage.GetPixel(0, 0)),
                (byte)BlendMethod.UnblendPixel(blendedImage.GetPixel(1, 0), originalImage.GetPixel(1, 0)),
                (byte)BlendMethod.UnblendPixel(blendedImage.GetPixel(2, 0), originalImage.GetPixel(2, 0)),
                (byte)BlendMethod.UnblendPixel(blendedImage.GetPixel(3, 0), originalImage.GetPixel(3, 0))
            };

            string colorAsBinary = String.Format("{0}{1}{2}{3}",
                                                 Convert.ToString(byteArray[3], 2).PadLeft(8, '0'),
                                                 Convert.ToString(byteArray[2], 2).PadLeft(8, '0'),
                                                 Convert.ToString(byteArray[1], 2).PadLeft(8, '0'),
                                                 Convert.ToString(byteArray[0], 2).PadLeft(8, '0'));

            stopAtElementIndex = Convert.ToInt32(colorAsBinary, 2);


            for (int x = UnitsSavedForSizeString; x < originalImage.Width; x++)
            {
                //message end has not been reached
                if (currentElementIndex < stopAtElementIndex)
                {
                    char charFromColor = (char)BlendMethod.UnblendPixel(blendedImage.GetPixel(x, 0), originalImage.GetPixel(x, 0));
                    text += charFromColor;
                    currentElementIndex++;
                }
                else
                {
                    return(text);
                }
            }



            for (int y = 1; y < originalImage.Height; y++)
            {
                for (int x = 0; x < originalImage.Width; x++)
                {
                    //message end has not been reached
                    if (currentElementIndex < stopAtElementIndex)
                    {
                        var charFromColor = (char)BlendMethod.UnblendPixel(blendedImage.GetPixel(x, y), originalImage.GetPixel(x, y));
                        text += charFromColor;
                        currentElementIndex++;
                    }
                    else
                    {
                        return(text);
                    }
                }
            }


            return(text);
        }
Exemplo n.º 5
0
        public void blendMethodSelector(TextureEditGUI gui, ref BlendMethod blendMethod)
        {
            GUILayout.BeginVertical(GUI.skin.box, GUILayout.ExpandHeight(true));

            GUILayout.Label("Blend Method");

            int selection = (int)blendMethod;
            int oldSelection = selection;
            selection = GUILayout.SelectionGrid(selection, _blendMethodGrid, 2);

            if (oldSelection != selection)
            {
                blendMethod = (BlendMethod)selection;
                gui.setRemakePreview();
            }

            GUILayout.EndVertical();
        }
Exemplo n.º 6
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;
            }
        }
Exemplo 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);
            }
        }
Exemplo 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);
        }
Exemplo 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);
        }