Example #1
0
        public void CreateAlphaBackground()
        {
            if (Background != null)
            {
                Color c;
                c = Color.FromArgb(255 - BackgroundAlpha, 0, 0, 0);

                //_backgroundAlphaImage = new Bitmap(Background.Width, Background.Height, PixelFormat.Format32bppPArgb);
                _backgroundAlphaImage = new Bitmap(Width, Height, PixelFormat.Format32bppPArgb);
                Graphics gfx = Graphics.FromImage(_backgroundAlphaImage);
                using (SolidBrush brush = new SolidBrush(c))
                {
                    gfx.FillRectangle(Brushes.Black, 0, 0, _backgroundAlphaImage.Width, _backgroundAlphaImage.Height);
                    gfx.DrawImage(Background, 0, 0, Background.Width, Background.Height);
                    gfx.FillRectangle(brush, 0, 0, Background.Width, Background.Height);
                }
                gfx.Dispose();
            }
            else
            {
                _backgroundAlphaImage = new Bitmap(Width, Height, PixelFormat.Format32bppPArgb);
                Graphics gfx = Graphics.FromImage(_backgroundAlphaImage);
                gfx.Clear(Color.Black);
                gfx.Dispose();
            }
            _fastPixel = new FastPixel.FastPixel(_backgroundAlphaImage.Width, _backgroundAlphaImage.Height);
        }
Example #2
0
        protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer)
        {
            var bufferHt = BufferHt;
            var bufferWi = BufferWi;

            using (var bitmap = new Bitmap(bufferWi, bufferHt))
            {
                InitialRender(frame, bitmap, bufferHt, bufferWi);
                if (_text.Count == 0 && !UseBaseColor)
                {
                    return;
                }
                _level = LevelCurve.GetValue(GetEffectTimeIntervalPosition(frame) * 100) / 100;
                FastPixel.FastPixel fp = new FastPixel.FastPixel(bitmap);
                fp.Lock();
                // copy to frameBuffer
                for (int x = 0; x < bufferWi; x++)
                {
                    for (int y = 0; y < bufferHt; y++)
                    {
                        CalculatePixel(x, y, ref bufferHt, fp, frameBuffer);
                    }
                }
                fp.Unlock(false);
                fp.Dispose();
            }
        }
Example #3
0
 public override void DrawSelectPoints(FastPixel.FastPixel fp)
 {
     if (_dragPoints != null)
     {
         foreach (PreviewDoublePoint point in _dragPoints)
         {
             if (point?.PointType == PreviewPoint.PointTypes.Size)
             {
                 int x = Convert.ToInt32(point.X - (double)SelectPointSize / 2);
                 int y = Convert.ToInt32(point.Y - (double)SelectPointSize / 2);
                 fp.DrawRectangle(
                     new Rectangle(x, y, SelectPointSize, SelectPointSize),
                     Color.White);
             }
             else
             {
                 if (point?.PointType == PreviewPoint.PointTypes.Rotate)
                 {
                     int x = Convert.ToInt32(point.X - (double)SelectPointSize / 2);
                     int y = Convert.ToInt32(point.Y - (double)SelectPointSize / 2);
                     fp.DrawCircle(
                         new Rectangle(x, y, SelectPointSize, SelectPointSize),
                         Color.White);
                 }
             }
         }
     }
 }
Example #4
0
 public void Draw(FastPixel.FastPixel fp, bool forceDraw)
 {
     if (forceDraw)
     {
         Draw(fp, color);
     }
 }
Example #5
0
        protected override void RenderEffectByLocation(int numFrames, PixelLocationFrameBuffer frameBuffer)
        {
            var nodes    = frameBuffer.ElementLocations.OrderBy(x => x.X).ThenBy(x => x.Y).GroupBy(x => x.X);
            var bufferHt = BufferHt;
            var bufferWi = BufferWi;

            for (int frame = 0; frame < numFrames; frame++)
            {
                frameBuffer.CurrentFrame = frame;
                _level = LevelCurve.GetValue(GetEffectTimeIntervalPosition(frame) * 100) / 100;
                using (var bitmap = new Bitmap(bufferWi, bufferHt))
                {
                    InitialRender(frame, bitmap, bufferHt, bufferWi);
                    FastPixel.FastPixel fp = new FastPixel.FastPixel(bitmap);
                    fp.Lock();
                    foreach (IGrouping <int, ElementLocation> elementLocations in nodes)
                    {
                        foreach (var elementLocation in elementLocations)
                        {
                            CalculatePixel(elementLocation.X, elementLocation.Y, ref bufferHt, fp, frameBuffer);
                        }
                    }
                    fp.Unlock(false);
                    fp.Dispose();
                }
            }
        }
Example #6
0
        public override void Draw(FastPixel.FastPixel fp, bool editMode, List <ElementNode> highlightedElements, bool selected,
                                  bool forceDraw)
        {
            //if (_strings != null) {
            //    _stringsInDegrees = (double) _stringCount*((double) _degrees/360);
            //    for (int i = 0; i < _stringsInDegrees; i++) {
            //        foreach (PreviewPixel pixel in _strings[i]._pixels) {
            //            //Console.WriteLine(pixel.X + ":" + pixel.Y);
            //            DrawPixel(pixel, fp, editMode, highlightedElements, selected, forceDraw);

            //            //if (highlightedElements.Contains(pixel.Node))
            //            //    pixel.Draw(fp, PreviewTools.HighlightedElementColor);
            //            //else
            //            //    pixel.Draw(fp, Color.White);
            //        }
            //    }
            //}

            //base.Draw(fp, editMode, highlightedElements, selected, forceDraw);

            // DB: Added 8/4/2013
            if (_strings != null)
            {
                //_stringsInDegrees = (double)_stringCount * ((double)_degrees / 360);
                for (int i = 0; i < StringCount; i++)
                {
                    foreach (PreviewPixel pixel in _strings[i]._pixels)
                    {
                        DrawPixel(pixel, fp, editMode, highlightedElements, selected, forceDraw);
                    }
                }
            }

            base.Draw(fp, editMode, highlightedElements, selected, forceDraw);
        }
Example #7
0
        private void CalculatePixel(int x, int y, ref int bufferHt, FastPixel.FastPixel bitmap, IPixelFrameBuffer frameBuffer)
        {
            Color color = bitmap.GetPixel(x, bufferHt - y - 1);

            if (!EmptyColor.Equals(color))
            {
                frameBuffer.SetPixel(x, y, color);
            }
        }
Example #8
0
 public override void Draw(FastPixel.FastPixel fp, bool editMode, List <ElementNode> highlightedElements, bool selected,
                           bool forceDraw)
 {
     foreach (PreviewBaseShape shape in Strings)
     {
         shape.Draw(fp, editMode, highlightedElements, selected, forceDraw);
     }
     DrawSelectPoints(fp);
 }
Example #9
0
        /// <inheritdoc />
        protected override void SetupRender()
        {
            var scaledImage = ScaleToGrid
                                ? Picture.Picture.ScalePictureImage(Image, BufferWi, BufferHt)
                                : Picture.Picture.ScaleImage(Image, (double)ScalePercent / 100);

            _fp = new FastPixel.FastPixel(scaledImage);
            _fp.Lock();
        }
Example #10
0
        public virtual void Draw(FastPixel.FastPixel fp, bool editMode, HashSet <Guid> highlightedElements, bool selected,
                                 bool forceDraw)
        {
            foreach (PreviewPixel pixel in Pixels)
            {
                DrawPixel(pixel, fp, editMode, highlightedElements, selected, forceDraw);
            }

            DrawSelectPoints(fp);
        }
Example #11
0
        public virtual void Draw(FastPixel.FastPixel fp, bool editMode, List <ElementNode> highlightedElements, bool selected,
                                 bool forceDraw)
        {
            //Pixels.AsParallel().ForAll(pixel => {
            foreach (PreviewPixel pixel in Pixels)
            {
                DrawPixel(pixel, fp, editMode, highlightedElements, selected, forceDraw);
            }
            //});

            DrawSelectPoints(fp);
        }
Example #12
0
 public override void Draw(FastPixel.FastPixel fp, bool editMode, List <ElementNode> highlightedElements, bool selected,
                           bool forceDraw)
 {
     foreach (PreviewPixel pixel in Pixels)
     {
         //if (highlightedElements != null && highlightedElements.Contains(pixel.Node))
         //    pixel.Draw(fp, Color.HotPink);
         //else
         //    pixel.Draw(fp, Color.White);
         DrawPixel(pixel, fp, editMode, highlightedElements, selected, forceDraw);
     }
 }
Example #13
0
 protected override void CleanUpRender()
 {
     _fp?.Dispose();
     _fp = null;
     if (_reader != null)
     {
         _reader.Close();
         _reader.Dispose();
         _reader = null;
     }
     _processVideo = true;
 }
Example #14
0
 public void Draw(FastPixel.FastPixel fp, bool forceDraw)
 {
     if (forceDraw)
     {
         Draw(fp, color);
     }
     else if (Node != null)
     {
         if (PreviewPixel.IntentNodeToColor.TryGetValue(Node, out color))
         {
             Draw(fp, color);
         }
     }
 }
Example #15
0
        public override void Draw(FastPixel.FastPixel fp, bool editMode, HashSet <Guid> highlightedElements, bool selected,
                                  bool forceDraw)
        {
            if (_strings != null)
            {
                for (int i = 0; i < StringCount; i++)
                {
                    foreach (PreviewPixel pixel in _strings[i]._pixels)
                    {
                        DrawPixel(pixel, fp, editMode, highlightedElements, selected, forceDraw);
                    }
                }
            }

            base.Draw(fp, editMode, highlightedElements, selected, forceDraw);
        }
Example #16
0
        private void buttonImport_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDlg = new OpenFileDialog();

            fileDlg.Filter = "Image Files (*.bmp, *.jpg, *.png)|*.bmp;*.jpg;*.png|All Files(*.*)|*.*";
            DialogResult result = fileDlg.ShowDialog();

            if (result == DialogResult.OK)
            {
                LipSyncMapItem mapItem;
                Color          pixelColor;

                Bitmap rawBitmap = new Bitmap(fileDlg.FileName);
                FastPixel.FastPixel scaledImage =
                    new FastPixel.FastPixel(new Bitmap(rawBitmap, CalcNumDataGridCols, CalcNumDataGridRows));

                int cols = CalcNumDataGridCols;
                int rows = CalcNumDataGridRows;

                scaledImage.Lock();
                for (int row = 0; row < rows; row++)
                {
                    DataRow dr = currentDataTable.Rows[row];
                    for (int col = 0; col < cols; col++)
                    {
                        mapItem = FindRenderMapItem(row, col);
                        if (mapItem != null)
                        {
                            pixelColor = scaledImage.GetPixel(col, row);
                            dr[col]    = pixelColor;
                            mapItem.PhonemeList[CurrentPhonemeString] = (pixelColor != Color.Black);
                        }
                        else
                        {
                            dr[col] = Color.Gray;
                        }
                    }
                }
                scaledImage.Unlock(false);

                BuildDialogFromMap(_newMapping);
                updatedataGridView1();
                Refresh();
            }
        }
Example #17
0
 public void DrawSelectPoints(FastPixel.FastPixel fp)
 {
     if (_selectPoints != null)
     {
         foreach (PreviewPoint point in _selectPoints)
         {
             if (point != null)
             {
                 if (point.PointType == PreviewPoint.PointTypes.Size)
                 {
                     fp.DrawRectangle(
                         new Rectangle(point.X - (SelectPointSize / 2), point.Y - (SelectPointSize / 2), SelectPointSize, SelectPointSize),
                         Color.White);
                 }
             }
         }
     }
 }
Example #18
0
        public virtual void DrawPixel(PreviewPixel pixel, FastPixel.FastPixel fp, bool editMode, HashSet <Guid> highlightedElements,
                                      bool selected, bool forceDraw)
        {
            int origPixelSize = pixel.PixelSize;

            if (forceDraw)
            {
                pixel.Draw(fp, forceDraw);
            }
            else
            {
                Color pixelColor = Color.White;
                if (StringType == StringTypes.Pixel && IsPixelOne(pixel))
                {
                    pixelColor      = Color.Yellow;
                    pixel.PixelSize = PixelSize + 2;
                }
                else
                {
                    if (selected)
                    {
                        pixelColor = PreviewTools.SelectedItemColor;
                    }
                    else
                    {
                        if (pixel.NodeId != Guid.Empty)
                        {
                            if (highlightedElements.Contains(pixel.NodeId))
                            {
                                pixelColor = Color.HotPink;
                            }
                            else
                            {
                                pixelColor = Color.Turquoise;
                            }
                        }
                    }
                }
                pixel.Draw(fp, pixelColor);
                //Restore the size if we changed it.
                pixel.PixelSize = origPixelSize;
            }
        }
Example #19
0
 public virtual void DrawPixel(PreviewPixel pixel, FastPixel.FastPixel fp, bool editMode, List <ElementNode> highlightedElements,
                               bool selected, bool forceDraw)
 {
     if (forceDraw)
     {
         pixel.Draw(fp, forceDraw);
     }
     else
     {
         Color pixelColor = Color.White;
         if (
             (_pixels.Count > 0) &&
             (pixel == _pixels[0] || (_strings != null && _strings.Count > 0 && _strings[0].Pixels != null && _strings[0].Pixels.Count > 0 && _strings[0].Pixels[0] == pixel))
             )
         {
             pixelColor      = Color.Yellow;
             pixel.PixelSize = PixelSize + 2;
         }
         else
         {
             if (selected)
             {
                 pixelColor = PreviewTools.SelectedItemColor;
             }
             else if (highlightedElements != null && highlightedElements.Contains(pixel.Node))
             {
                 pixelColor = Color.HotPink;
             }
             else
             {
                 if (pixel.Node != null)
                 {
                     pixelColor = Color.Turquoise;
                 }
                 else
                 {
                     pixelColor = Color.White;
                 }
             }
         }
         pixel.Draw(fp, pixelColor);
     }
 }
Example #20
0
        public void Draw(FastPixel.FastPixel fp, IIntentStates states, double zoomLevel)
        {
            if (_isDiscreteColored)
            {
                int       col      = 1;
                int       zoomedX  = (int)(Bounds.X * zoomLevel);
                Rectangle drawRect = new Rectangle(zoomedX, (int)(Bounds.Y * zoomLevel), Bounds.Width, Bounds.Height);
                // Get states for each color
                List <Color> colors = _discreteHandler.GetAlphaAffectedColor(states);
                foreach (Color c in colors)
                {
                    if (c != Color.Transparent && c.A > byte.MinValue)
                    {
                        fp.DrawCircle(drawRect, c);

                        if (col % 2 == 0)
                        {
                            drawRect.Y += PixelSize;
                            drawRect.X  = zoomedX;
                        }
                        else
                        {
                            drawRect.X = zoomedX + PixelSize;
                        }

                        col++;
                    }
                }
            }
            else
            {
                var state = states.FirstOrDefault();
                if (state != null)
                {
                    Color intentColor = _fullColorHandler.GetFullColor(state);
                    if (intentColor.A > 0)
                    {
                        Rectangle drawRect = zoomLevel != 1?new Rectangle((int)(Bounds.X * zoomLevel), (int)(Bounds.Y * zoomLevel), Bounds.Width, Bounds.Height):Bounds;
                        fp.DrawCircle(drawRect, intentColor);
                    }
                }
            }
        }
Example #21
0
        public void CreateAlphaBackground()
        {
            if (Width <= 0 || Height <= 0)
            {
                return;
            }

            int newWidth  = Convert.ToInt32(_background.Width * ZoomLevel);
            int newHeight = Convert.ToInt32(_background.Height * ZoomLevel);

            if (newWidth <= 0 || newHeight <= 0)
            {
                return;
            }

            if (Background != null)
            {
                Color c = Color.FromArgb(255 - BackgroundAlpha, 0, 0, 0);

                //_backgroundAlphaImage = new Bitmap(Background.Width, Background.Height, PixelFormat.Format32bppPArgb);
                _backgroundAlphaImage = new Bitmap(Width, Height, PixelFormat.Format32bppPArgb);
                Graphics gfx = Graphics.FromImage(_backgroundAlphaImage);
                using (SolidBrush brush = new SolidBrush(c))
                {
                    gfx.FillRectangle(Brushes.Black, 0, 0, Width, Height);
                    gfx.DrawImage(Background, 0, 0, newWidth, newHeight);
                    gfx.FillRectangle(brush, 0, 0, Width, Height);
                }
                gfx.Dispose();
            }
            else
            {
                _backgroundAlphaImage = new Bitmap(Width, Height, PixelFormat.Format32bppPArgb);
                Graphics gfx = Graphics.FromImage(_backgroundAlphaImage);
                gfx.Clear(Color.Black);
                gfx.Dispose();
            }
            _fastPixel = new FastPixel.FastPixel(_backgroundAlphaImage.Width, _backgroundAlphaImage.Height);
            BeginUpdate();
            EndUpdate();
            Invalidate();
        }
Example #22
0
 public virtual void DrawSelectPoints(FastPixel.FastPixel fp)
 {
     if (_selectPoints != null)
     {
         foreach (PreviewPoint point in _selectPoints)
         {
             if (point != null)
             {
                 if (point.PointType == PreviewPoint.PointTypes.Size)
                 {
                     int x = Convert.ToInt32((point.X) * ZoomLevel) - (SelectPointSize / 2);
                     int y = Convert.ToInt32(point.Y * ZoomLevel) - (SelectPointSize / 2);
                     fp.DrawRectangle(
                         new Rectangle(x, y, SelectPointSize, SelectPointSize),
                         Color.White);
                 }
             }
         }
     }
 }
Example #23
0
 public virtual void DrawPixel(PreviewPixel pixel, FastPixel.FastPixel fp, bool editMode, List <ElementNode> highlightedElements,
                               bool selected, bool forceDraw)
 {
     if (forceDraw)
     {
         pixel.Draw(fp, forceDraw);
     }
     else if (selected)
     {
         pixel.Draw(fp, PreviewTools.SelectedItemColor);
     }
     else if (highlightedElements != null && highlightedElements.Contains(pixel.Node))
     {
         pixel.Draw(fp, Color.HotPink);
     }
     else
     {
         pixel.Draw(fp, Color.White);
     }
 }
Example #24
0
        public void Draw(FastPixel.FastPixel fp, IIntentStates states)
        {
            if (_isDiscreteColored)
            {
                int       col      = 1;
                Rectangle drawRect = new Rectangle(drawArea.X, drawArea.Y, drawArea.Width, drawArea.Height);
                // Get states for each color
                List <Color> colors = _discreteHandler.GetAlphaAffectedColor(states);
                foreach (Color c in colors)
                {
                    if (c != Color.Transparent && c.A > byte.MinValue)
                    {
                        fp.DrawCircle(drawRect, c);

                        if (col % 2 == 0)
                        {
                            drawRect.Y += PixelSize;
                            drawRect.X  = drawArea.X;
                        }
                        else
                        {
                            drawRect.X = drawArea.X + PixelSize;
                        }

                        col++;
                    }
                }
            }
            else
            {
                var state = states.FirstOrDefault();
                if (state != null)
                {
                    Color intentColor = _fullColorHandler.GetFullColor(state);
                    if (intentColor.A > 0)
                    {
                        fp.DrawCircle(drawArea, intentColor);
                    }
                }
            }
        }
Example #25
0
        private void CalculateLocationPixel(int x, int y, ref int bufferHt, FastPixel.FastPixel bitmap, IPixelFrameBuffer frameBuffer)
        {
            int yCoord = y;
            int xCoord = x;

            //Flip me over so and offset my coordinates I can act like the string version
            y = Math.Abs((BufferHtOffset - y) + (bufferHt - 1 + BufferHtOffset));
            y = y - BufferHtOffset;
            x = x - BufferWiOffset;

            Color color = bitmap.GetPixel(x, bufferHt - y - 1);

            if (!EmptyColor.Equals(color))
            {
                frameBuffer.SetPixel(xCoord, yCoord, color);
            }
            else
            {
                //Set me to my base color or transparent
                frameBuffer.SetPixel(xCoord, yCoord, UseBaseColor ? BaseColor : Color.Transparent);
            }
        }
Example #26
0
        private void CalculatePixel(int x, int y, ref int bufferHt, FastPixel.FastPixel bitmap, IPixelFrameBuffer frameBuffer)
        {
            int yCoord = y;
            int xCoord = x;

            if (TargetPositioning == TargetPositioningType.Locations)
            {
                //Flip me over so and offset my coordinates I can act like the string version
                y = Math.Abs((BufferHtOffset - y) + (bufferHt - 1 + BufferHtOffset));
                y = y - BufferHtOffset;
                x = x - BufferWiOffset;
            }
            Color color = bitmap.GetPixel(x, bufferHt - y - 1);

            if (!_emptyColor.Equals(color))
            {
                frameBuffer.SetPixel(xCoord, yCoord, color);
            }
            else if (TargetPositioning == TargetPositioningType.Locations)
            {
                frameBuffer.SetPixel(xCoord, yCoord, Color.Transparent);
            }
        }
Example #27
0
        public void Draw(FastPixel.FastPixel fp, IIntentStates states)
        {
            if (_isDiscreteColored)
            {
                int       col      = 1;
                Rectangle drawRect = new Rectangle(drawArea.X, drawArea.Y, drawArea.Width, drawArea.Height);
                // Get states for each color
                IEnumerable <Color> colors = IntentHelpers.GetAlphaAffectedDiscreteColorsForIntents(states);
                foreach (Color c in colors)
                {
                    if (c != Color.Transparent && c.A > byte.MinValue)
                    {
                        fp.DrawCircle(drawRect, c);

                        if (col % 2 == 0)
                        {
                            drawRect.Y += PixelSize;
                            drawRect.X  = drawArea.X;
                        }
                        else
                        {
                            drawRect.X = drawArea.X + PixelSize;
                        }

                        col++;
                    }
                }
            }
            else
            {
                Color intentColor = IntentHelpers.GetAlphaRGBMaxColorForIntents(states);
                if (intentColor != Color.Transparent && intentColor.A > 0)
                {
                    fp.DrawCircle(drawArea, intentColor);
                }
            }
        }
Example #28
0
 protected override void CleanUpRender()
 {
     _fp?.Dispose();
     _fp       = null;
     _pictures = null;
 }
Example #29
0
        protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer)
        {
            double position = (GetEffectTimeIntervalPosition(frame) * Speed) % 1;
            double level = LevelCurve.GetValue(GetEffectTimeIntervalPosition(frame) * 100) / 100;

            // If we don't have any pictures, do nothing!
            if (_moviePicturesFileList == null || !_moviePicturesFileList.Any())
                return;

            int pictureCount = _moviePicturesFileList.Count;

            if (PlayBackSpeed > 0)
            {
                _currentMovieImageNum += ((PlayBackSpeed * .01) + 1);
            }
            else if (PlayBackSpeed < 0)
            {
                _currentMovieImageNum += (100 + PlayBackSpeed) * .01;
            }
            else
            {
                _currentMovieImageNum ++;
            }

            int currentImage = Convert.ToInt32(_currentMovieImageNum);
            if (currentImage >= pictureCount || currentImage < 0)
                _currentMovieImageNum = currentImage = 0;

            // copy image to buffer
            Bitmap resizeImage = new Bitmap(Image.FromFile(_moviePicturesFileList[currentImage]));
            FastPixel.FastPixel currentMovieImage = new FastPixel.FastPixel(new Bitmap(resizeImage));

            int imgwidth = currentMovieImage.Width;
            int imght = currentMovieImage.Height;
            int yoffset = (BufferHt + imght) / 2;
            int xoffset = (imgwidth - BufferWi) / 2;
            int xOffsetAdj = XOffset * BufferWi / 100;
            int yOffsetAdj = YOffset * BufferHt / 100;

            switch (Type)
            {
                case EffectType.RenderPicturePeekaboo0:
                case EffectType.RenderPicturePeekaboo180:
                    //Peek a boo
                    yoffset = -(BufferHt) + (int)((BufferHt + 5) * position * 2);
                    if (yoffset > 10)
                    {
                        yoffset = -yoffset + 10; //reverse direction
                    }
                    else if (yoffset >= -1)
                    {
                        yoffset = -1; //pause in middle
                    }

                    break;
                case EffectType.RenderPictureWiggle:
                    if (position >= 0.5)
                    {
                        xoffset += (int)(BufferWi * ((1.0 - position) * 2.0 - 0.5));
                    }
                    else
                    {
                        xoffset += (int)(BufferWi * (position * 2.0 - 0.5));
                    }
                    break;
                case EffectType.RenderPicturePeekaboo90: //peekaboo 90
                case EffectType.RenderPicturePeekaboo270: //peekaboo 270
                    if (Orientation == StringOrientation.Vertical)
                    {
                        yoffset = (imght - BufferWi) / 2; //adjust offsets for other axis
                        xoffset = -(BufferHt) + (int)((BufferHt + 5) * position * 2);
                    }
                    else
                    {
                        yoffset = (imgwidth - BufferHt) / 2; //adjust offsets for other axis
                        xoffset = -(BufferWi) + (int)((BufferWi + 5) * position * 2);
                    }
                    if (xoffset > 10)
                    {
                        xoffset = -xoffset + 10; //reverse direction
                    }
                    else if (xoffset >= -1)
                    {
                        xoffset = -1; //pause in middle
                    }

                    break;
            }

            currentMovieImage.Lock();
            Color fpColor = new Color();
            for (int x = 0; x < imgwidth; x++)
            {
                for (int y = 0; y < imght; y++)
                {
                    fpColor = currentMovieImage.GetPixel(x, y);
                    if (fpColor != Color.Transparent && fpColor != Color.Black)
                    {
                        var hsv = HSV.FromRGB(fpColor);
                        double tempV = hsv.V * level * ((double)(IncreaseBrightness)/10);
                        if (tempV > 1)
                            tempV = 1;
                        hsv.V = tempV;
                        int leftX, rightX, upY, downY;
                        switch (_data.EffectType)
                        {
                            case EffectType.RenderPictureLeft:
                                // left
                                leftX = x + (BufferWi - (int)(position * (imgwidth + BufferWi)));

                                frameBuffer.SetPixel(leftX + xOffsetAdj, yoffset - y + yOffsetAdj, hsv);
                                break;
                            case EffectType.RenderPictureRight:
                                // right
                                rightX = x + -imgwidth + (int)(position * (imgwidth + BufferWi));

                                frameBuffer.SetPixel(rightX + xOffsetAdj, yoffset - y + yOffsetAdj, hsv);
                                break;
                            case EffectType.RenderPictureUp:
                                // up
                                upY = (int)((imght + BufferHt) * position) - y;

                                frameBuffer.SetPixel(x - xoffset + xOffsetAdj, upY + yOffsetAdj, hsv);
                                break;
                            case EffectType.RenderPictureDown:
                                // down
                                downY = (BufferHt + imght - 1) - (int)((imght + BufferHt) * position) - y;

                                frameBuffer.SetPixel(x - xoffset + xOffsetAdj, downY + yOffsetAdj, hsv);
                                break;
                            case EffectType.RenderPictureUpleft:
                                // up-left
                                leftX = x + (BufferWi - (int)(position * (imgwidth + BufferWi)));
                                upY = (int)((imght + BufferHt) * position) - y;

                                frameBuffer.SetPixel(leftX + xOffsetAdj, upY + yOffsetAdj, hsv);
                                break;
                            case EffectType.RenderPictureDownleft:
                                // down-left
                                leftX = x + (BufferWi - (int)(position * (imgwidth + BufferWi)));
                                downY = (BufferHt + imght - 1) - (int)((imght + BufferHt) * position) - y;

                                frameBuffer.SetPixel(leftX + xOffsetAdj, downY + yOffsetAdj, hsv);
                                break;
                            case EffectType.RenderPictureUpright:
                                // up-right
                                upY = (int)((imght + BufferHt) * position) - y;
                                rightX = x + -imgwidth + (int)(position * (imgwidth + BufferWi));

                                frameBuffer.SetPixel(rightX + xOffsetAdj, upY + yOffsetAdj, hsv);
                                break;
                            case EffectType.RenderPictureDownright:
                                // down-right
                                downY = (BufferHt + imght - 1) - (int)((imght + BufferHt) * position) - y;
                                rightX = x + -imgwidth + (int)(position * (imgwidth + BufferWi));

                                frameBuffer.SetPixel(rightX + xOffsetAdj, downY + yOffsetAdj, hsv);
                                break;
                            case EffectType.RenderPicturePeekaboo0:
                                // Peek a boo 0
                                frameBuffer.SetPixel(x - xoffset + xOffsetAdj, BufferHt + yoffset - y + yOffsetAdj, hsv);
                                break;
                            case EffectType.RenderPictureWiggle:
                                // Wiggle
                                frameBuffer.SetPixel(x + xoffset + xOffsetAdj, yoffset - y + yOffsetAdj, hsv);
                                break;
                            case EffectType.RenderPicturePeekaboo90:
                                // Peekaboo90
                                frameBuffer.SetPixel(BufferWi + xoffset - y + xOffsetAdj, x - yoffset + yOffsetAdj, hsv);
                                break;
                            case EffectType.RenderPicturePeekaboo180:
                                // Peekaboo180
                                frameBuffer.SetPixel(x - xoffset + xOffsetAdj, y - yoffset + yOffsetAdj, hsv);
                                break;
                            case EffectType.RenderPicturePeekaboo270:
                                // Peekaboo270
                                frameBuffer.SetPixel(y - xoffset + xOffsetAdj, BufferHt + yoffset - x + yOffsetAdj, hsv);
                                break;
                            default:
                                // no movement - centered
                                frameBuffer.SetPixel(x - xoffset + xOffsetAdj, yoffset - y + yOffsetAdj, hsv);
                                break;
                        }
                    }
                }
            }
            currentMovieImage.Unlock(false);
            currentMovieImage.Dispose();
            resizeImage.Dispose();
        }
Example #30
0
        //#region "Update in a BeginInvoke"
        //public void ProcessUpdate(ElementIntentStates elementStates)
        //{
        //    renderTimer.Reset();
        //    renderTimer.Start();
        //    if (!_paused)
        //    {
        //        FastPixel fp = new FastPixel(new Bitmap(_alphaBackground));
        //        fp.Lock();
        //        Color c;
        //        foreach (var channelIntentState in elementStates)
        //        {
        //            var elementId = channelIntentState.Key;
        //            Element element = VixenSystem.Elements.GetElement(elementId);
        //            if (element == null) continue;
        //            ElementNode node = VixenSystem.Elements.GetElementNodeForElement(element);
        //            if (node == null) continue;
        //            foreach (IIntentState<LightingValue> intentState in channelIntentState.Value)
        //            {
        //                c = intentState.GetValue().GetAlphaChannelIntensityAffectedColor();
        //                if (_background != null)
        //                {
        //                    List<PreviewPixel> pixels;
        //                    if (NodeToPixel.TryGetValue(node, out pixels))
        //                    {
        //                        foreach (PreviewPixel pixel in pixels)
        //                        {
        //                            pixel.Draw(fp, c);
        //                        }
        //                    }
        //                }
        //            }
        //        }
        //        fp.Unlock(true);
        //        // First, draw our background image opaque
        //        bufferedGraphics.Graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
        //        bufferedGraphics.Graphics.DrawImage(fp.Bitmap, 0, 0, fp.Width, fp.Height);
        //        if (!this.Disposing && bufferedGraphics != null)
        //            bufferedGraphics.Render(Graphics.FromHwnd(this.Handle));
        //        fp = null;
        //    }
        //    renderTimer.Stop();
        //    lastRenderUpdateTime = renderTimer.ElapsedMilliseconds;
        //}
        //#endregion
        public void ProcessUpdateParallel(/*Vixen.Preview.PreviewElementIntentStates elementStates*/)
        {
            renderTimer.Reset();
            renderTimer.Start();
            CancellationTokenSource tokenSource = new CancellationTokenSource();
            if (!_paused)
            {
                Bitmap clone = (Bitmap)_alphaBackground.Clone();
                //BitmapData odata = _alphaBackground.LockBits(new Rectangle(0, 0, _alphaBackground.Width, _alphaBackground.Height), ImageLockMode.ReadWrite, _alphaBackground.PixelFormat);
                //BitmapData cdata = clone.LockBits(new Rectangle(0, 0, clone.Width, clone.Height), ImageLockMode.ReadWrite, clone.PixelFormat);
                //Assert.AreNotEqual(odata.Scan0, cdata.Scan0);
                //using (FastPixel fp = new FastPixel(new Bitmap(_alphaBackground)))
                using (FastPixel.FastPixel fp = new FastPixel.FastPixel(clone))
                {
                    try
                    {
                        fp.Lock();

                        Vixen.Preview.PreviewElementIntentStates elementStates =
                            new Vixen.Preview.PreviewElementIntentStates(VixenSystem.Elements.ToDictionary(x => x, x => x.State));

                        elementStates.AsParallel().WithCancellation(tokenSource.Token).ForAll(channelIntentState =>
                        {
                            //var elementId = channelIntentState.Key;
                            //Element element = VixenSystem.Elements.GetElement(elementId);
                            Element element = channelIntentState.Key;
                            if (element != null)
                            {
                                ElementNode node = VixenSystem.Elements.GetElementNodeForElement(element);
                                if (node != null)
                                {
                                    List<PreviewPixel> pixels;
                                    if (NodeToPixel.TryGetValue(node, out pixels))
                                    {
                                        foreach (PreviewPixel pixel in pixels)
                                        {
                                            pixel.Draw(fp, channelIntentState.Value);
                                        }
                                    }

                                    //foreach (IIntentState<LightingValue> intentState in channelIntentState.Value)
                                    //{
                                    //    Color c = ((IIntentState<LightingValue>)intentState).GetValue().GetAlphaChannelIntensityAffectedColor();
                                    //    if (_background != null)
                                    //    {
                                    //        List<PreviewPixel> pixels;
                                    //        if (NodeToPixel.TryGetValue(node, out pixels))
                                    //        {
                                    //            foreach (PreviewPixel pixel in pixels)
                                    //            {
                                    //                pixel.Draw(fp, c);
                                    //            }
                                    //        }
                                    //    }
                                    //}
                                }
                            }
                        });
                        //Console.WriteLine("2: " + renderTimer.ElapsedMilliseconds);renderTimer.Reset();
                        fp.Unlock(true);
                        RenderBufferedGraphics(fp);
                    }
                    catch (Exception)
                    {
                        tokenSource.Cancel();
                        //Console.WriteLine(e.Message);
                    }
                }
            }

            renderTimer.Stop();
            lastRenderUpdateTime = renderTimer.ElapsedMilliseconds;
        }
Example #31
0
        public void CreateAlphaBackground()
        {
            if (Background != null)
            {
                Color c;
                c = Color.FromArgb(255 - BackgroundAlpha, 0, 0, 0);

                //_backgroundAlphaImage = new Bitmap(Background.Width, Background.Height, PixelFormat.Format32bppPArgb);
                _backgroundAlphaImage = new Bitmap(Width, Height, PixelFormat.Format32bppPArgb);
                Graphics gfx = Graphics.FromImage(_backgroundAlphaImage);
                using (SolidBrush brush = new SolidBrush(c))
                {
                    gfx.FillRectangle(Brushes.Black, 0, 0, _backgroundAlphaImage.Width, _backgroundAlphaImage.Height);
                    gfx.DrawImage(Background, 0, 0, Background.Width, Background.Height);
                    gfx.FillRectangle(brush, 0, 0, Background.Width, Background.Height);
                }
                gfx.Dispose();
            }
            else
            {
                _backgroundAlphaImage = new Bitmap(Width, Height, PixelFormat.Format32bppPArgb);
                Graphics gfx = Graphics.FromImage(_backgroundAlphaImage);
                gfx.Clear(Color.Black);
                gfx.Dispose();
            }
            _fastPixel = new FastPixel.FastPixel(_backgroundAlphaImage.Width, _backgroundAlphaImage.Height);
        }
Example #32
0
        /// <summary>
        /// This is used in edit mode only!!
        /// Need to make it go away so we only have one render engine
        /// </summary>
        public void RenderInForeground()
        {
            renderTimer.Reset();
            renderTimer.Start();

            AllocateGraphicsBuffer();

            if (_background != null) {
                FastPixel.FastPixel fp = new FastPixel.FastPixel(new Bitmap(_alphaBackground));
                fp.Lock();
                foreach (DisplayItem displayItem in DisplayItems) {
                    if (_editMode) {
                        displayItem.Draw(fp, true, HighlightedElements, SelectedDisplayItems.Contains(displayItem), false);
                    }
                    else {
                        displayItem.Draw(fp, false, null, false, true);
                    }
                }
                fp.Unlock(true);

                if (ShowInfo && _editMode)
                {
                    foreach (DisplayItem displayItem in DisplayItems)
                    {
                        Graphics g = Graphics.FromImage(fp.Bitmap);
                        displayItem.DrawInfo(g);
                    }
                }

                // Finally, are we drawing a banded rectangle?
                if (_mouseCaptured && _selectedDisplayItem == null) {
                    Graphics g = Graphics.FromImage(fp.Bitmap);
                    g.DrawRectangle(Pens.White, _bandRect);
                }

                // First, draw our background image opaque
                bufferedGraphics.Graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
                // Now, draw our "pixel" image using alpha blending
                bufferedGraphics.Graphics.DrawImage(fp.Bitmap, 0, 0, fp.Width, fp.Height);
            }

            bufferedGraphics.Render(Graphics.FromHwnd(this.Handle));
            renderTimer.Stop();
            lastRenderUpdateTime = renderTimer.ElapsedMilliseconds;
        }
Example #33
0
		public void RenderPictures(int dir, string newPictureName, int gifSpeed, bool scaleToGrid, int scalePct)
		{
			if (String.IsNullOrEmpty(newPictureName)) return;
			const int speedfactor = 4;
			var effectType = (EffectType)dir;
			
			if (newPictureName != _pictureName)
			{
				try
				{
					//This crazyness is to allow the file handle to be released on the file we are using. Otherwise it is locked
					//And if you try to use the same image when you switch to picture tiles, it will have an 
					//file locked error
					using (var fs = new FileStream(Path.Combine(NutcrackerDescriptor.ModulePath, newPictureName), FileMode.Open, FileAccess.Read))
					{
						var ms = new MemoryStream();
						fs.CopyTo(ms);
						ms.Position = 0;
						if(_pictureImage!=null) _pictureImage.Dispose();
						_pictureImage = Image.FromStream(ms);
					}
					_pictureName = newPictureName;
				}
				catch (Exception e)
				{
					Logging.Error("Error loading pictue file for nutcracker pictures", e);
				}
				
			}

			var dimension = new FrameDimension(_pictureImage.FrameDimensionsList[0]);
			// Number of frames
			int frameCount = _pictureImage.GetFrameCount(dimension);

			if (frameCount > 1)
			{
				if (gifSpeed > 0)
				{
					_currentGifImageNum += ((gifSpeed * .05));
				}
				else
				{
					_currentGifImageNum++;
				}
				if (Convert.ToInt32(_currentGifImageNum) >= frameCount)
				{
					_currentGifImageNum = 0;
				}
				_pictureImage.SelectActiveFrame(dimension, Convert.ToInt32(_currentGifImageNum));

			}

			Image image = scaleToGrid ? ScaleImage(_pictureImage, BufferWi, BufferHt) : ScaleImage(_pictureImage, _pictureImage.Width * scalePct / 10, _pictureImage.Height * scalePct / 10);
			
			_fp = new FastPixel.FastPixel(new Bitmap(image));

			if (_fp != null)
			{
				int imgwidth = _fp.Width;
				int imght = _fp.Height;
				int yoffset = (BufferHt + imght) / 2;
				int xoffset = (imgwidth - BufferWi) / 2;
				//int limit = (dir < 2) ? imgwidth + BufferWi : imght + BufferHt;
				//int movement = Convert.ToInt32((State % (limit * speedfactor)) / speedfactor);


				switch (effectType)
				{
					case EffectType.RenderPicturePeekaboo0:
					case EffectType.RenderPicturePeekaboo180:
						//Peek a boo
						yoffset = Convert.ToInt32(State/speedfactor - BufferHt); // * speedfactor; //draw_at = (state < BufferHt)? state
						if (yoffset > 10)
						{
							yoffset = -yoffset + 10; //reverse direction
						}else if (yoffset > 0) {
							yoffset = 0; //pause in middle
						}
						break;
					case EffectType.RenderPictureWiggle: //wiggle left-right -DJ
						xoffset = Convert.ToInt32(State % (BufferWi / 4 * speedfactor));
						if (xoffset > BufferWi / 8 * speedfactor) {
							xoffset = BufferWi / 4 * speedfactor - xoffset; //reverse direction
						}
						xoffset -= BufferWi / 4; //* speedfactor; //center it on mid value
						xoffset += (imgwidth - BufferWi) / 2; //add in original xoffset from above
						break;
					case EffectType.RenderPicturePeekaboo90: //peekaboo 90
					case EffectType.RenderPicturePeekaboo270: //peekaboo 270
						yoffset = (imght - BufferWi) / 2; //adjust offsets for other axis
						xoffset = Convert.ToInt32(State / speedfactor - BufferHt); // * speedfactor; //draw_at = (state < BufferHt)? state
						if (xoffset > 10) {
							xoffset = -xoffset + 10; //reverse direction
						}
						else if (xoffset > 0){
							xoffset = 0; //pause in middle
						}
						break;
					default:
						break;
				}

				// copy image to buffer
				_fp.Lock();
				for (int x = 0; x < imgwidth; x++)
				{
					for (int y = 0; y < imght; y++)
					{
						//if (!image.IsTransparent(x,y))
						Color fpColor = _fp.GetPixel(x, y);
						if (fpColor != Color.Transparent)
						{
							switch (effectType)
							{
								case EffectType.RenderPictureLeft:
									// left
									SetPixel( Convert.ToInt32(x + BufferWi - (State % ((imgwidth + BufferWi) * speedfactor)) / speedfactor), yoffset - y, fpColor);
									break;
								case EffectType.RenderPictureRight:
									// right
									SetPixel(Convert.ToInt32(x + (State % ((imgwidth + BufferWi) * speedfactor)) / speedfactor - imgwidth), yoffset - y, fpColor);
									break;
								case EffectType.RenderPictureUp:
									// up
									SetPixel(x - xoffset,  Convert.ToInt32((State % ((imght + BufferHt) * speedfactor)) / speedfactor - y), fpColor);
									break;
								case EffectType.RenderPictureDown:
									// down
									SetPixel(x - xoffset, Convert.ToInt32(BufferHt + imght - y - (State % ((imght + BufferHt) * speedfactor)) / speedfactor), fpColor);
									break;
								case EffectType.RenderPictureUpleft:
									SetPixel(Convert.ToInt32(x + BufferWi - (State % ((imgwidth + BufferWi) * speedfactor)) / speedfactor), Convert.ToInt32((State % ((imght + BufferHt) * speedfactor)) / speedfactor - y), fpColor);
									break; // up-left
								case EffectType.RenderPictureDownleft: 
									SetPixel( Convert.ToInt32(x + BufferWi - (State % ((imgwidth + BufferWi) * speedfactor)) / speedfactor), Convert.ToInt32(BufferHt + imght - y - (State % ((imght + BufferHt) * speedfactor)) / speedfactor), fpColor);
									break; // down-left
								case EffectType.RenderPictureUpright:
									SetPixel(Convert.ToInt32(x + (State % ((imgwidth + BufferWi) * speedfactor)) / speedfactor - imgwidth), Convert.ToInt32((State % ((imght + BufferHt) * speedfactor)) / speedfactor - y), fpColor);
									break; // up-right
								case EffectType.RenderPictureDownright: 
									SetPixel(Convert.ToInt32(x + (State % ((imgwidth + BufferWi) * speedfactor)) / speedfactor - imgwidth), Convert.ToInt32(BufferHt + imght - y - (State % ((imght + BufferHt) * speedfactor)) / speedfactor), fpColor);
									break; // down-right
								case EffectType.RenderPicturePeekaboo0: 
									//Peek a boo
									SetPixel(x - xoffset, BufferHt + yoffset - y, fpColor); 
									break;
								case EffectType.RenderPictureWiggle: 
									SetPixel(x + xoffset, yoffset - y, fpColor);
									break;
								case EffectType.RenderPicturePeekaboo90:  
									SetPixel(BufferWi + xoffset - y, x - yoffset, fpColor);
									break;
								case EffectType.RenderPicturePeekaboo180:  
									SetPixel(x - xoffset, y - yoffset, fpColor);
									break;
								case EffectType.RenderPicturePeekaboo270: 
									SetPixel(y - xoffset, BufferHt + yoffset - x, fpColor);
									break;
								default:
									// no movement - centered
									SetPixel(x - xoffset, yoffset - y, fpColor);
									break;
							}
						}
					}
				}
				_fp.Unlock(false);
			}
			if (image != null)
				image.Dispose();
		}
Example #34
0
        public void LoadPictures(string DataFilePath)
        {
            moviePictures = new List<FastPixel.FastPixel>();
            if (Data.Movie_DataPath.Length > 0) {
                var imageFolder = System.IO.Path.Combine(NutcrackerDescriptor.ModulePath, DataFilePath);
                List<string> sortedFiles = Directory.GetFiles(imageFolder).OrderBy(f => f).ToList();

                foreach (string file in sortedFiles) {
                    Image image = Image.FromFile(file);
                    FastPixel.FastPixel imageFp = new FastPixel.FastPixel(new Bitmap(image));
                    moviePictures.Add(imageFp);
                }
            }
        }
Example #35
0
		//#region "Update in a BeginInvoke"
		//public void ProcessUpdate(ElementIntentStates elementStates)
		//{
		//    renderTimer.Reset();
		//    renderTimer.Start();
		//    if (!_paused)
		//    {
		//        FastPixel fp = new FastPixel(new Bitmap(_alphaBackground));

		//        fp.Lock();
		//        Color c;
		//        foreach (var channelIntentState in elementStates)
		//        {
		//            var elementId = channelIntentState.Key;
		//            Element element = VixenSystem.Elements.GetElement(elementId);
		//            if (element == null) continue;
		//            ElementNode node = VixenSystem.Elements.GetElementNodeForElement(element);
		//            if (node == null) continue;

		//            foreach (IIntentState<LightingValue> intentState in channelIntentState.Value)
		//            {
		//                c = intentState.GetValue().GetAlphaChannelIntensityAffectedColor();
		//                if (_background != null)
		//                {
		//                    List<PreviewPixel> pixels;
		//                    if (NodeToPixel.TryGetValue(node, out pixels))
		//                    {
		//                        foreach (PreviewPixel pixel in pixels)
		//                        {
		//                            pixel.Draw(fp, c);
		//                        }
		//                    }
		//                }
		//            }
		//        }

		//        fp.Unlock(true);

		//        // First, draw our background image opaque
		//        bufferedGraphics.Graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
		//        bufferedGraphics.Graphics.DrawImage(fp.Bitmap, 0, 0, fp.Width, fp.Height);

		//        if (!this.Disposing && bufferedGraphics != null)
		//            bufferedGraphics.Render(Graphics.FromHwnd(this.Handle));

		//        fp = null;
		//    }

		//    renderTimer.Stop();
		//    lastRenderUpdateTime = renderTimer.ElapsedMilliseconds;
		//}
		//#endregion

		public void ProcessUpdateParallel( /*Vixen.Preview.PreviewElementIntentStates elementStates*/)
		{
			renderTimer.Reset();
			renderTimer.Start();
			CancellationTokenSource tokenSource = new CancellationTokenSource();
			if (!_paused)
			{
				Bitmap clone = (Bitmap) _alphaBackground.Clone();
				using (FastPixel.FastPixel fp = new FastPixel.FastPixel(clone))
				{
					try
					{
						fp.Lock();

						Vixen.Preview.PreviewElementIntentStates elementStates =
							new Vixen.Preview.PreviewElementIntentStates(VixenSystem.Elements.ToDictionary(x => x, x => x.State));

						elementStates.AsParallel().WithCancellation(tokenSource.Token).ForAll(channelIntentState =>
						{
							Element element = channelIntentState.Key;
							if (element != null)
							{
								ElementNode node = VixenSystem.Elements.GetElementNodeForElement(element);
								if (node != null)
								{
									List<PreviewPixel> pixels;
									if (NodeToPixel.TryGetValue(node, out pixels))
									{
										foreach (PreviewPixel pixel in pixels)
										{
											pixel.Draw(fp, channelIntentState.Value);
										}
									}
								}
							}
						});
						fp.Unlock(true);
						RenderBufferedGraphics(fp);
					}
					catch (Exception)
					{
						tokenSource.Cancel();
					}
				}
			}

			renderTimer.Stop();
			lastRenderUpdateTime = renderTimer.ElapsedMilliseconds;
		}
Example #36
0
        protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer)
        {
            if (_image == null)
            {
                Logging.Error("Image object is null");
                return;
            }
            var dir = 360 - Direction;
            double level = LevelCurve.GetValue(GetEffectTimeIntervalPosition(frame) * 100) / 100;
            int speedFactor = 4;
            int state = MovementRate * frame;
            if (Type != EffectType.RenderPictureTiles && Type != EffectType.RenderPictureNone)
            {
                _position = ((GetEffectTimeIntervalPosition(frame) * Speed) % 1);
            }
            else if (frame == 0)
            {
                _position = ((GetEffectTimeIntervalPosition(frame + 1) * Speed) % 1);
            }

            CalculateImageNumberByPosition((GetEffectTimeIntervalPosition(frame)*GifSpeed)%1);
            _image.SelectActiveFrame(_dimension, (int) _currentGifImageNum);
            _scaledImage = ScaleToGrid
                ? ScalePictureImage(_image, BufferWi, BufferHt)
                : ScaleImage(_image, (double) ScalePercent/100);

            if (ColorEffect == ColorEffect.GreyScale)
            {
                _scaledImage = (Bitmap) ConvertToGrayScale(_scaledImage);
            }
            _fp = new FastPixel.FastPixel(_scaledImage);

            if (_fp != null)
            {
                int imageWidth = _fp.Width;
                int imageHeight = _fp.Height;
                double deltaX = 0;
                double deltaY = 0;
                double angleOffset;

                if (dir > 45 && dir <= 90)
                    angleOffset = -(dir - 90);
                else if (dir > 90 && dir <= 135)
                    angleOffset = dir - 90;
                else if (dir > 135 && dir <= 180)
                    angleOffset = -(dir - 180);
                else if (dir > 180 && dir <= 225)
                    angleOffset = dir - 180;
                else if (dir > 225 && dir <= 270)
                    angleOffset = -(dir - 270);
                else if (dir > 270 && dir <= 315)
                    angleOffset = dir - 270;
                else if (dir > 315 && dir <= 360)
                    angleOffset = -(dir - 360);
                else
                    angleOffset = dir;

                double imageSpeed = _position*(imageWidth/(Math.Cos((Math.PI/180)*angleOffset)));

                //Moving left and right
                if (dir > 0 && dir <= 90)
                {
                    deltaX = ((double) dir/90)*(imageSpeed);
                }
                else if (dir > 90 && dir <= 180)
                {
                    deltaX = ((double) Math.Abs(dir - 180)/90)*(imageSpeed);
                }
                else if (dir > 180 && dir <= 270)
                {
                    deltaX = -1*(((double) Math.Abs(dir - 180)/90)*(imageSpeed));
                }
                else if (dir > 270 && dir <= 360)
                {
                    deltaX = -1*(((double) Math.Abs(dir - 360)/90)*(imageSpeed));
                }

                //Moving up and down
                if (dir >= 0 && dir <= 90)
                {
                    deltaY = (((double) Math.Abs(dir - 90)/90))*(imageSpeed);
                }
                else if (dir > 90 && dir <= 180)
                {
                    deltaY = -1*(((double) Math.Abs(dir - 90)/90)*(imageSpeed));
                }
                else if (dir > 180 && dir <= 270)
                {
                    deltaY = -1*(((double) Math.Abs(dir - 270)/90)*(imageSpeed));
                }
                else if (dir > 270 && dir <= 360)
                {
                    deltaY = ((double) Math.Abs(270 - dir)/90)*(imageSpeed);
                }

                _movementX += deltaX;
                _movementY += deltaY;

                _fp.Lock();
                Color fpColor = new Color();

                int yoffset = (BufferHt + imageHeight)/2;
                int xoffset = (imageWidth - BufferWi)/2;
                int xOffsetAdj = XOffset*BufferWi/100;
                int yOffsetAdj = YOffset*BufferHt/100;
                int imageHt = imageHeight;
                int imageWi = imageWidth;

                switch (Type)
                {
                    case EffectType.RenderPicturePeekaboo0:
                    case EffectType.RenderPicturePeekaboo180:
                        //Peek a boo
                        yoffset = -(BufferHt) + (int) ((BufferHt + 5)*_position*2);
                        if (yoffset > 10)
                        {
                            yoffset = -yoffset + 10; //reverse direction
                        }
                        else if (yoffset >= -1)
                        {
                            yoffset = -1; //pause in middle
                        }
                        break;
                    case EffectType.RenderPictureWiggle:
                        if (_position >= 0.5)
                        {
                            xoffset += (int) (BufferWi*((1.0 - _position)*2.0 - 0.5));
                        }
                        else
                        {
                            xoffset += (int) (BufferWi*(_position*2.0 - 0.5));
                        }
                        break;
                    case EffectType.RenderPicturePeekaboo90: //peekaboo 90
                    case EffectType.RenderPicturePeekaboo270: //peekaboo 270
                        if (Orientation == StringOrientation.Vertical)
                        {
                            yoffset = (imageHt - BufferWi)/2; //adjust offsets for other axis
                        }
                        else
                        {
                            yoffset = (imageWi - BufferHt)/2; //adjust offsets for other axis
                        }

                        if (Orientation == StringOrientation.Vertical)
                        {
                            xoffset = -(BufferHt) + (int) ((BufferHt + 5)*_position*2);
                        }
                        else
                        {
                            xoffset = -(BufferWi) + (int) ((BufferWi + 5)*_position*2);
                        }
                        if (xoffset > 10)
                        {
                            xoffset = -xoffset + 10; //reverse direction
                        }
                        else if (xoffset >= -1)
                        {
                            xoffset = -1; //pause in middle
                        }

                        break;
                    case EffectType.RenderPictureTiles:
                        imageHt = BufferHt;
                        imageWi = BufferWi;
                        break;

                }
                for (int x = 0; x < imageWi; x++)
                {
                    for (int y = 0; y < imageHt; y++)
                    {
                        if (Type != EffectType.RenderPictureTiles) // change this so only when tiles are disabled
                        {
                            fpColor = _fp.GetPixel(x, y);
                        }

                        var hsv = HSV.FromRGB(fpColor);
                        double tempV = hsv.V*level*((double) (IncreaseBrightness)/10);
                        if (tempV > 1)
                            tempV = 1;
                        hsv.V = tempV;

                        switch (Type)
                        {
                            case EffectType.RenderPicturePeekaboo0:

                                if (fpColor != Color.Transparent)
                                {
                                    //Peek a boo
                                    hsv = CustomColor(hsv, frame, level, fpColor);
                                    frameBuffer.SetPixel(x - xoffset + xOffsetAdj, BufferHt + yoffset - y + yOffsetAdj, hsv);
                                }
                                break;
                            case EffectType.RenderPictureWiggle:
                                hsv = CustomColor(hsv, frame, level, fpColor);
                                frameBuffer.SetPixel(x + xoffset + xOffsetAdj, yoffset - y + yOffsetAdj, hsv);
                                break;
                            case EffectType.RenderPicturePeekaboo90:
                                hsv = CustomColor(hsv, frame, level, fpColor);
                                frameBuffer.SetPixel(BufferWi + xoffset - y + xOffsetAdj, x - yoffset + yOffsetAdj, hsv);
                                break;
                            case EffectType.RenderPicturePeekaboo180:
                                hsv = CustomColor(hsv, frame, level, fpColor);
                                frameBuffer.SetPixel(x - xoffset + xOffsetAdj, y - yoffset + yOffsetAdj, hsv);
                                break;
                            case EffectType.RenderPicturePeekaboo270:
                                hsv = CustomColor(hsv, frame, level, fpColor);
                                frameBuffer.SetPixel(y - xoffset + xOffsetAdj, BufferHt + yoffset - x + yOffsetAdj, hsv);
                                break;
                            case EffectType.RenderPictureLeft:
                                // left
                                int leftX = x + (BufferWi - (int) (_position*(imageWi + BufferWi)));
                                hsv = CustomColor(hsv, frame, level, fpColor);
                                frameBuffer.SetPixel(leftX + xOffsetAdj, yoffset - y + yOffsetAdj, hsv);
                                break;
                            case EffectType.RenderPictureRight:
                                // right
                                int rightX = x + -imageWi + (int) (_position*(imageWi + BufferWi));
                                hsv = CustomColor(hsv, frame, level, fpColor);
                                frameBuffer.SetPixel(rightX + xOffsetAdj, yoffset - y + yOffsetAdj, hsv);
                                break;
                            case EffectType.RenderPictureUp:
                                // up
                                int upY = (int) ((imageHt + BufferHt)*_position) - y;
                                hsv = CustomColor(hsv, frame, level, fpColor);
                                frameBuffer.SetPixel(x - xoffset + xOffsetAdj, upY + yOffsetAdj, hsv);
                                break;

                            case EffectType.RenderPictureUpleft:
                                int upLeftY = (int) ((imageHt + BufferHt)*_position) - y;
                                hsv = CustomColor(hsv, frame, level, fpColor);
                                frameBuffer.SetPixel(
                                    Convert.ToInt32(x + BufferWi - (state % ((imageWi + BufferWi) * speedFactor)) / speedFactor) + xOffsetAdj,
                                    upLeftY + yOffsetAdj, hsv);
                                break; // up-left
                            case EffectType.RenderPictureDownleft:
                                int downLeftY = BufferHt + imageHt - (int) ((imageHt + BufferHt)*_position) - y;
                                hsv = CustomColor(hsv, frame, level, fpColor);
                                frameBuffer.SetPixel(
                                    Convert.ToInt32(x + BufferWi - (state % ((imageWi + BufferWi) * speedFactor)) / speedFactor) + xOffsetAdj,
                                    downLeftY + yOffsetAdj, hsv);
                                break; // down-left
                            case EffectType.RenderPictureUpright:
                                int upRightY = (int) ((imageHt + BufferHt)*_position) - y;
                                hsv = CustomColor(hsv, frame, level, fpColor);
                                frameBuffer.SetPixel(
                                    Convert.ToInt32(x + (state % ((imageWi + BufferWi) * speedFactor)) / speedFactor - imageWi) + xOffsetAdj,
                                    upRightY + yOffsetAdj, hsv);
                                break; // up-right
                            case EffectType.RenderPictureDownright:
                                int downRightY = BufferHt + imageHt - (int) ((imageHt + BufferHt)*_position) - y;
                                hsv = CustomColor(hsv, frame, level, fpColor);
                                frameBuffer.SetPixel(
                                    Convert.ToInt32(x + (state % ((imageWi + BufferWi) * speedFactor)) / speedFactor - imageWi) + xOffsetAdj,
                                    downRightY + yOffsetAdj, hsv);
                                break; // down-right
                            case EffectType.RenderPictureDown:
                                // down
                                int downY = (BufferHt + imageHt - 1) - (int) ((imageHt + BufferHt)*_position) - y;
                                hsv = CustomColor(hsv, frame, level, fpColor);
                                frameBuffer.SetPixel(x - xoffset + xOffsetAdj, downY + yOffsetAdj, hsv);
                                break;
                            case EffectType.RenderPictureNone:
                                hsv = CustomColor(hsv, frame, level, fpColor);
                                frameBuffer.SetPixel(x - xoffset + xOffsetAdj, yoffset - y + yOffsetAdj, hsv);
                                break;
                            case EffectType.RenderPictureTiles:
                                int colorX = x + Convert.ToInt32(_movementX) - (XOffset*BufferWi/100);
                                int colorY = y + Convert.ToInt32(_movementY) + (YOffset*BufferHt/100);

                                if (colorX >= 0)
                                {
                                    colorX = colorX%imageWidth;
                                }
                                else if (colorX < 0)
                                {
                                    colorX = Convert.ToInt32(colorX%imageWidth) + imageWidth - 1;
                                }

                                if (colorY >= 0)
                                {
                                    colorY = Convert.ToInt32((colorY%imageHeight));
                                }
                                else if (colorY < 0)
                                {
                                    colorY = Convert.ToInt32(colorY%imageHeight) + imageHeight - 1;
                                }
                                if (colorX <= _fp.Width && colorY <= _fp.Height)
                                {
                                    fpColor = _fp.GetPixel(colorX, colorY);

                                    hsv = HSV.FromRGB(fpColor);
                                    hsv = CustomColor(hsv, frame, level, fpColor);
                                    frameBuffer.SetPixel(x, BufferHt - y - 1, hsv);
                                }
                                break;
                        }
                    }
                }
                _fp.Unlock(false);
                _fp.Dispose();
                _scaledImage.Dispose();
            }
        }
Example #37
0
        public void RenderPictureTile(int dir, double scale, bool useColor, bool useAlpha, int ColorReplacementSensitivity,
            string NewPictureName)
        {
            const int speedfactor = 4;
            Image image = null;
            try {

            if (NewPictureName == null || NewPictureName.Length == 0)
                return;

            if (State == 0) {
                lastState = 0;
                movementX = 0.0;
                movementY = 0.0;
                lastScale = -1;
            }

            if (NewPictureName != PictureTilePictureName || scale != lastScale) {
                if (IsNutcrackerResource(NewPictureName))
                {
                    using (var fs = typeof(Nutcracker).Assembly.GetManifestResourceStream(NewPictureName))
                    image = Image.FromStream(fs);
                }
                else if (File.Exists(NewPictureName))
                {
                    using (var fs = new FileStream(NewPictureName, FileMode.Open, FileAccess.Read))
                    {
                        image = Image.FromStream(fs);
                    }
                }
                else
                {
                    return;
                }
                if (scale != 0.0) {
                    image = ScaleImage(image, scale/100);
                }
                if (useColor) {
                    image = ConvertToGrayScale(image);
                }
                _fp = new FastPixel.FastPixel(new Bitmap(image));

                PictureTilePictureName = NewPictureName;
                lastScale = scale;
            }

            if (_fp != null) {
                int imageWidth = _fp.Width;
                int imageHeight = _fp.Height;
                double deltaX = 0;
                double deltaY = 0;

                if (dir > 0 && dir < 90) {
                    deltaX = (double) dir/90;
                }
                else if (dir > 90 && dir < 180) {
                    deltaX = (double) Math.Abs(dir - 180)/90;
                }
                else if (dir > 180 && dir < 270) {
                    deltaX = -1*((double) Math.Abs(dir - 180)/90);
                }
                else if (dir > 270 && dir < 360) {
                    deltaX = -1*((double) Math.Abs(dir - 360)/90);
                }

                if (dir >= 0 && dir < 90) {
                    deltaY = (double) Math.Abs(dir - 90)/90;
                }
                else if (dir > 90 && dir <= 180) {
                    deltaY = -1*((double) Math.Abs(dir - 90)/90);
                }
                else if (dir > 180 && dir < 270) {
                    deltaY = -1*((double) Math.Abs(dir - 270)/90);
                }
                else if (dir > 270 && dir <= 360) {
                    deltaY = (double) Math.Abs(270 - dir)/90;
                }

                movementX += (double) ((double) (State - lastState)/(double) speedfactor)*deltaX;
                movementY += (double) ((double) (State - lastState)/(double) speedfactor)*deltaY;
                lastState = (int) State;

                _fp.Lock();
                Color fpColor = new Color();
                int colorX = 0;
                int colorY = 0;

                for (int x = 0; x < BufferWi; x++) {
                    for (int y = 0; y < BufferHt; y++) {
                        colorX = x + Convert.ToInt32(movementX);
                        colorY = y + Convert.ToInt32(movementY);

                        if (colorX >= 0) {
                            colorX = colorX%imageWidth;
                        }
                        else if (colorX < 0) {
                            colorX = Convert.ToInt32(colorX%imageWidth) + imageWidth - 1;
                        }

                        if (colorY >= 0) {
                            colorY = Convert.ToInt32(colorY%imageHeight);
                        }
                        else if (colorY < 0) {
                            colorY = Convert.ToInt32(colorY%imageHeight) + imageHeight - 1;
                        }
                        if (colorX <= _fp.Width && colorY <= _fp.Height) {
                            fpColor = _fp.GetPixel(colorX, colorY);

                            if (fpColor != Color.Transparent) {
                                // Are we re-assigning the colors for this
                                if (useColor) {
                                    // For now, we're always going to use alpha. Maybe later, we'll
                                    // Convert black and white to a single color
                                    //if (useAlpha)
                                    //{
                                    Color newColor = Palette.GetColor(0);
                                    // TODO
                                    // How high can GetBrightness go? Is it 0-100?
                                    // How about alpha? Is it 0-255?
                                    int a = Convert.ToInt32(fpColor.GetBrightness()*255);
                                    fpColor = Color.FromArgb(a, newColor.R, newColor.G, newColor.B);
                                    //}
                                    //else
                                    //{
                                    //    fpColor = Palette.GetColor(0);
                                    //}
                                }
                                else {
                                    //fpColor = Color.FromArgb(255, fpColor);
                                }
                                // Tree is up-side down, so draw the bitmp up-side down so it is right-side up.
                                SetPixel(x, BufferHt - y - 1, fpColor);
                            }
                        }
                    }
                }
                _fp.Unlock(false);
            }
            } finally {
                if (image != null)
                    image.Dispose();
            }
        }
Example #38
0
        public override void Layout()
        {
            ElementNode node = null;

            if (PixelCount > 0)
            {
                node = _pixels[0].Node;
                _pixels.Clear();
            }
            else if (initiallyAssignedNode != null)
            {
                if (initiallyAssignedNode.IsLeaf)
                {
                    node = initiallyAssignedNode;
                }
            }

            Point boundsTopLeft = new Point();

            boundsTopLeft.X = Math.Min(_topLeft.X, Math.Min(Math.Min(_topRight.X, _bottomRight.X), _bottomLeft.X));
            boundsTopLeft.Y = Math.Min(_topLeft.Y, Math.Min(Math.Min(_topRight.Y, _bottomRight.Y), _bottomLeft.Y));
            Point bottomRight = new Point();

            bottomRight.X = Math.Max(_topLeft.X, Math.Max(Math.Max(_topRight.X, _bottomRight.X), _bottomLeft.X));
            bottomRight.Y = Math.Max(_topLeft.Y, Math.Max(Math.Max(_topRight.Y, _bottomRight.Y), _bottomLeft.Y));
            Rectangle rect = new Rectangle(boundsTopLeft,
                                           new Size(bottomRight.X - boundsTopLeft.X, bottomRight.Y - boundsTopLeft.Y));

            Point tL = new Point(_topLeft.X - boundsTopLeft.X, _topLeft.Y - boundsTopLeft.Y);
            Point tR = new Point(_topRight.X - boundsTopLeft.X, _topRight.Y - boundsTopLeft.Y);
            Point bL = new Point(_bottomLeft.X - boundsTopLeft.X, _bottomLeft.Y - boundsTopLeft.Y);
            Point bR = new Point(_bottomRight.X - boundsTopLeft.X, _bottomRight.Y - boundsTopLeft.Y);

            Point[] points = { tL, tR, bR, bL };

            if (rect.Width > 0 && rect.Height > 0)
            {
                using (var b = new Bitmap(rect.Width, rect.Height)) {
                    Graphics g = Graphics.FromImage(b);
                    g.Clear(Color.Transparent);
                    g.FillPolygon(Brushes.White, points);
                    using (FastPixel.FastPixel fp = new FastPixel.FastPixel(b)) {
                        fp.Lock();
                        int xCount   = 1;
                        int spacingY = _pixelSpacing;
                        for (int y = 0; y < rect.Height; y++)
                        {
                            if (spacingY % _pixelSpacing == 0)
                            {
                                int xDiv;
                                if (xCount % 2 == 0)
                                {
                                    xDiv = _pixelSpacing;
                                }
                                else
                                {
                                    xDiv = _pixelSpacing / 2;
                                }

                                for (int x = 0; x < rect.Width; x++)
                                {
                                    if ((x + xDiv) % _pixelSpacing == 0)
                                    {
                                        Color newColor = fp.GetPixel(x, y);
                                        if (newColor.A != 0)
                                        {
                                            PreviewPixel pixel = new PreviewPixel(x + boundsTopLeft.X, y + boundsTopLeft.Y, 0, PixelSize);
                                            pixel.Node = node;
                                            _pixels.Add(pixel);
                                        }
                                    }
                                }
                                xCount += 1;
                            }
                            spacingY += 1;
                        }
                        fp.Unlock(false);
                    }
                }
            }
        }
Example #39
0
        private void buttonImport_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDlg = new OpenFileDialog();
            fileDlg.Filter = "Image Files (*.bmp, *.jpg, *.png)|*.bmp;*.jpg;*.png|All Files(*.*)|*.*";
            DialogResult result = fileDlg.ShowDialog();
            if (result == DialogResult.OK)
            {
                LipSyncMapItem mapItem;
                Color pixelColor;

                Bitmap rawBitmap = new Bitmap(fileDlg.FileName);
                FastPixel.FastPixel scaledImage = 
                    new FastPixel.FastPixel(new Bitmap(rawBitmap, CalcNumDataGridCols, CalcNumDataGridRows));
                
                int cols = CalcNumDataGridCols;
                int rows = CalcNumDataGridRows;

                scaledImage.Lock();
                for (int row = 0; row < rows; row++)
                {
                    DataRow dr = currentDataTable.Rows[row];
                    for (int col = 0; col < cols; col++)
                    {
                        mapItem = FindRenderMapItem(row, col);
                        if (mapItem != null)
                        {
                            pixelColor = scaledImage.GetPixel(col, row);
                            dr[col] = pixelColor;
                            mapItem.PhonemeList[CurrentPhonemeString] = (pixelColor != Color.Black);
                        }
                        else
                        {
                            dr[col] = Color.Gray;
                        }
                    }
                }
                scaledImage.Unlock(false);

                BuildDialogFromMap(_newMapping);
                updatedataGridView1();
				Refresh();
            }
        }
Example #40
0
        private void InitialRender(int frame, double intervalPosFactor)
        {
            if (_fp != null || _pictures.Count > 0)
            {
                var dir = 360 - Direction;

                if (Type != EffectType.RenderPictureTiles && Type != EffectType.RenderPictureNone)
                {
                    _position = ((GetEffectTimeIntervalPosition(frame) * Speed) % 1);
                }
                else if (frame == 0)
                {
                    _position = ((GetEffectTimeIntervalPosition(frame + 1) * Speed) % 1);
                }

                if (_pictures.Count > 0)
                {
                    for (int i = 0; i < _pictures.Count; i++)
                    {
                        if (frame >= _pictures[i].frame)
                        {
                            _fp = new FastPixel.FastPixel(_pictures[i].bitmap);
                            _pictures.RemoveAt(i);
                            break;
                        }
                    }
                }

                _imageWidth  = _fp.Width;
                _imageHeight = _fp.Height;
                double deltaX = 0;
                double deltaY = 0;
                double angleOffset;

                if (dir > 45 && dir <= 90)
                {
                    angleOffset = -(dir - 90);
                }
                else if (dir > 90 && dir <= 135)
                {
                    angleOffset = dir - 90;
                }
                else if (dir > 135 && dir <= 180)
                {
                    angleOffset = -(dir - 180);
                }
                else if (dir > 180 && dir <= 225)
                {
                    angleOffset = dir - 180;
                }
                else if (dir > 225 && dir <= 270)
                {
                    angleOffset = -(dir - 270);
                }
                else if (dir > 270 && dir <= 315)
                {
                    angleOffset = dir - 270;
                }
                else if (dir > 315 && dir <= 360)
                {
                    angleOffset = -(dir - 360);
                }
                else
                {
                    angleOffset = dir;
                }

                double imageSpeed = _position * (_imageWidth / (Math.Cos((Math.PI / 180) * angleOffset)));

                //Moving left and right
                if (dir > 0 && dir <= 90)
                {
                    deltaX = ((double)dir / 90) * (imageSpeed);
                }
                else if (dir > 90 && dir <= 180)
                {
                    deltaX = ((double)Math.Abs(dir - 180) / 90) * (imageSpeed);
                }
                else if (dir > 180 && dir <= 270)
                {
                    deltaX = -1 * (((double)Math.Abs(dir - 180) / 90) * (imageSpeed));
                }
                else if (dir > 270 && dir <= 360)
                {
                    deltaX = -1 * (((double)Math.Abs(dir - 360) / 90) * (imageSpeed));
                }

                //Moving up and down
                if (dir >= 0 && dir <= 90)
                {
                    deltaY = (((double)Math.Abs(dir - 90) / 90)) * (imageSpeed);
                }
                else if (dir > 90 && dir <= 180)
                {
                    deltaY = -1 * (((double)Math.Abs(dir - 90) / 90) * (imageSpeed));
                }
                else if (dir > 180 && dir <= 270)
                {
                    deltaY = -1 * (((double)Math.Abs(dir - 270) / 90) * (imageSpeed));
                }
                else if (dir > 270 && dir <= 360)
                {
                    deltaY = ((double)Math.Abs(270 - dir) / 90) * (imageSpeed);
                }

                _movementX += deltaX;
                _movementY += deltaY;

                _yoffset    = ((BufferHt + _imageHeight) / 2) - 1;              //subtract 1 because we are zero based and inverting the y
                _xoffset    = (_imageWidth - BufferWi) / 2;
                _xOffsetAdj = CalculateXOffset(intervalPosFactor) * BufferWi / 100;
                _yOffsetAdj = CalculateYOffset(intervalPosFactor) * BufferHt / 100;
                _imageHt    = _imageHeight;
                _imageWi    = _imageWidth;

                switch (Type)
                {
                case EffectType.RenderPicturePeekaboo0:
                case EffectType.RenderPicturePeekaboo180:
                    //Peek a boo
                    _yoffset = -(BufferHt) + (int)((BufferHt + 5) * _position * 2);
                    if (_yoffset > 10)
                    {
                        _yoffset = -_yoffset + 10;                                 //reverse direction
                    }
                    else if (_yoffset >= -1)
                    {
                        _yoffset = -1;                                 //pause in middle
                    }
                    break;

                case EffectType.RenderPictureWiggle:
                    if (_position >= 0.5)
                    {
                        _xoffset += (int)(_imageWi * ((1.0 - _position) * 2.0 - 0.5));
                    }
                    else
                    {
                        _xoffset += (int)(_imageWi * (_position * 2.0 - 0.5));
                    }
                    break;

                case EffectType.RenderPicturePeekaboo90:                         //peekaboo 90
                case EffectType.RenderPicturePeekaboo270:                        //peekaboo 270
                    if (Orientation == StringOrientation.Horizontal || TargetPositioning == TargetPositioningType.Locations)
                    {
                        _yoffset = (BufferHt - _imageWi) / 2;                                 //adjust offsets for other axis
                        _xoffset = -(BufferWi) + (int)((BufferWi + 5) * _position * 2);
                    }
                    else
                    {
                        _yoffset = (BufferWi) / 2;                                 //adjust offsets for other axis
                        _xoffset = -(BufferHt) + (int)((BufferHt + 5) * _position * 2);
                    }

                    if (_xoffset > 10)
                    {
                        _xoffset = -_xoffset + 10;                                 //reverse direction
                    }
                    else if (_xoffset >= -1)
                    {
                        _xoffset = -1;                                 //pause in middle
                    }

                    break;

                case EffectType.RenderPictureTiles:
                    _imageHt = BufferHt;
                    _imageWi = BufferWi;
                    break;
                }
            }
        }
Example #41
0
		/// <summary>
		/// This is used in edit mode only!!
		/// Need to make it go away so we only have one render engine
		/// </summary>
		public void RenderInForeground()
		{
			renderTimer.Reset();
			renderTimer.Start();

			AllocateGraphicsBuffer(false);
			if (Background != null)
			{
				FastPixel.FastPixel fp = new FastPixel.FastPixel(new Bitmap(_alphaBackground));
				fp.Lock();
				foreach (DisplayItem displayItem in DisplayItems)
				{
					if (_editMode)
					{
						displayItem.Draw(fp, true, HighlightedElements, SelectedDisplayItems.Contains(displayItem), false);
					}
					else
					{
						displayItem.Draw(fp, false, null, false, true);
					}
				}
				fp.Unlock(true);

				if (ShowInfo && _editMode)
				{
					foreach (DisplayItem displayItem in DisplayItems)
					{
						Graphics g = Graphics.FromImage(fp.Bitmap);
						displayItem.DrawInfo(g);
					}
				}

				// Finally, are we drawing a banded rectangle?
				if (_mouseCaptured && _selectedDisplayItem == null)
				{
					Graphics g = Graphics.FromImage(fp.Bitmap);
					g.DrawRectangle(Pens.White, _bandRect);
				}

				bufferedGraphics.Graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;

				// Now, draw our "pixel" image using alpha blending
				if (vScroll.Visible && hScroll.Visible)
				{
					int drawWidth = Width - vScroll.Width + hScroll.Value;
					int drawHeight = Height - hScroll.Height + vScroll.Value;
					int drawX = -hScroll.Value;
					int drawY = -vScroll.Value;
					Rectangle dest = new Rectangle(0, 0, drawWidth, drawHeight);
					Rectangle src = new Rectangle(hScroll.Value, vScroll.Value, drawWidth, drawHeight);
					bufferedGraphics.Graphics.DrawImage(fp.Bitmap, dest, src, GraphicsUnit.Pixel);
				}
				else
				{
					Rectangle dest = new Rectangle(0, 0, Width, Height);
					Rectangle src = new Rectangle(0, 0, Width, Height);
					bufferedGraphics.Graphics.DrawImage(fp.Bitmap, dest, src, GraphicsUnit.Pixel);
				}
			}

			bufferedGraphics.Render(Graphics.FromHwnd(this.Handle));
			renderTimer.Stop();
			lastRenderUpdateTime = renderTimer.ElapsedMilliseconds;
		}
Example #42
0
        public override void Layout()
        {
            ElementNode node = null;

            if (PixelCount > 0) {
                node = _pixels[0].Node;
                _pixels.Clear();
            }
            else if (initiallyAssignedNode != null) {
                if (initiallyAssignedNode.IsLeaf) {
                    node = initiallyAssignedNode;
                }
            }

            Point boundsTopLeft = new Point();
            boundsTopLeft.X = Math.Min(_topLeft.X, Math.Min(Math.Min(_topRight.X, _bottomRight.X), _bottomLeft.X));
            boundsTopLeft.Y = Math.Min(_topLeft.Y, Math.Min(Math.Min(_topRight.Y, _bottomRight.Y), _bottomLeft.Y));
            Point bottomRight = new Point();
            bottomRight.X = Math.Max(_topLeft.X, Math.Max(Math.Max(_topRight.X, _bottomRight.X), _bottomLeft.X));
            bottomRight.Y = Math.Max(_topLeft.Y, Math.Max(Math.Max(_topRight.Y, _bottomRight.Y), _bottomLeft.Y));
            Rectangle rect = new Rectangle(boundsTopLeft,
                                           new Size(bottomRight.X - boundsTopLeft.X, bottomRight.Y - boundsTopLeft.Y));

            Point tL = new Point(_topLeft.X - boundsTopLeft.X, _topLeft.Y - boundsTopLeft.Y);
            Point tR = new Point(_topRight.X - boundsTopLeft.X, _topRight.Y - boundsTopLeft.Y);
            Point bL = new Point(_bottomLeft.X - boundsTopLeft.X, _bottomLeft.Y - boundsTopLeft.Y);
            Point bR = new Point(_bottomRight.X - boundsTopLeft.X, _bottomRight.Y - boundsTopLeft.Y);
            Point[] points = {tL, tR, bR, bL};

            if (rect.Width > 0 && rect.Height > 0) {
                using (var b = new Bitmap(rect.Width, rect.Height)) {
                    Graphics g = Graphics.FromImage(b);
                    g.Clear(Color.Transparent);
                    g.FillPolygon(Brushes.White, points);
                    using (FastPixel.FastPixel fp = new FastPixel.FastPixel(b)) {
                        fp.Lock();
                        int xCount = 1;
                        int spacingY = _pixelSpacing;
                        for (int y = 0; y < rect.Height; y++) {
                            if (spacingY%_pixelSpacing == 0) {
                                int xDiv;
                                if (xCount%2 == 0)
                                    xDiv = _pixelSpacing;
                                else
                                    xDiv = _pixelSpacing/2;

                                for (int x = 0; x < rect.Width; x++) {
                                    if ((x + xDiv)%_pixelSpacing == 0) {
                                        Color newColor = fp.GetPixel(x, y);
                                        if (newColor.A != 0) {
                                            PreviewPixel pixel = new PreviewPixel(x + boundsTopLeft.X, y + boundsTopLeft.Y, 0, PixelSize);
                                            pixel.Node = node;
                                            _pixels.Add(pixel);
                                        }
                                    }
                                }
                                xCount += 1;
                            }
                            spacingY += 1;
                        }
                        fp.Unlock(false);
                    }
                }
            }
        }
Example #43
0
        //
        // TODO: Load animated GIF images
        //
        public void RenderPictures(int dir, string NewPictureName, int GifSpeed)
        {
            const int speedfactor = 4;
            Image image = null;

            if (NewPictureName != PictureName) {
                image = Image.FromFile(NewPictureName);
                fp = new FastPixel.FastPixel(new Bitmap(image));

                //Console.WriteLine("Loaded picture: " + NewPictureName);
                //    imageCount = wxImage::GetImageCount(NewPictureName);
                //    imageIndex = 0;
                //    if (!image.LoadFile(NewPictureName,wxBITMAP_TYPE_ANY,0))
                //    {
                //        //wxMessageBox("Error loading image file: "+NewPictureName);
                //        image.Clear();
                //    }
                PictureName = NewPictureName;
                //    if (!image.IsOk())
                //        return;

                //}
                //if(imageCount>1)
                //{
                //    // The 10 could be animation speed. I did notice that state is jumping numbers
                //    // so state%someNumber == 0 may not hit every time. There could be a better way.
                //    if(state%(21-GifSpeed)==0)  // change 1-20 in Gimspeed to be 20 to 1. This makes right hand slider fastest
                //    {
                //        if(imageIndex == imageCount-1)
                //        {
                //            imageIndex = 0;
                //        }
                //        else
                //        {
                //            imageIndex++;
                //        }

                //        if (!image.LoadFile(PictureName,wxBITMAP_TYPE_ANY,imageIndex))
                //        {
                //            //wxMessageBox("Error loading image file: "+NewPictureName);
                //            image.Clear();
                //        }
                //        if (!image.IsOk())
                //            return;
                //    }
            }

            if (fp != null) {
                int imgwidth = fp.Width;
                int imght = fp.Height;
                int yoffset = (BufferHt + imght)/2;
                int xoffset = (imgwidth - BufferWi)/2;
                int limit = (dir < 2) ? imgwidth + BufferWi : imght + BufferHt;
                int movement = Convert.ToInt32((State%(limit*speedfactor))/speedfactor);

                // copy image to buffer
                fp.Lock();
                Color fpColor = new Color();
                for (int x = 0; x < imgwidth; x++) {
                    for (int y = 0; y < imght; y++) {
                        //if (!image.IsTransparent(x,y))
                        fpColor = fp.GetPixel(x, y);
                        if (fpColor != Color.Transparent) {
                            switch (dir) {
                                case 0:
                                    // left
                                    SetPixel(x + BufferWi - movement, yoffset - y-1, fpColor);
                                    break;
                                case 1:
                                    // right
                                    SetPixel(x + movement - imgwidth, yoffset - y, fpColor);
                                    break;
                                case 2:
                                    // up
                                    SetPixel(x - xoffset, movement - y, fpColor);
                                    break;
                                case 3:
                                    // down
                                    SetPixel(x - xoffset, BufferHt + imght - y - movement, fpColor);
                                    break;
                                default:
                                    // no movement - centered
                                    SetPixel(x - xoffset, yoffset - y, fpColor);
                                    break;
                            }
                        }
                    }
                }
                fp.Unlock(false);
            }
            if (image != null)
                image.Dispose();
        }
Example #44
0
        public void RenderMovie(int dir, string dataFilePath, int movieSpeed)
        {
            const int speedfactor = 4;

            if (_moviePicturesFileList == null || State == 0) {
                LoadMoviePictureFileList(dataFilePath);
            }

            // If we don't have any pictures, do nothing!
            if (_moviePicturesFileList == null || !_moviePicturesFileList.Any())
                return;

            int pictureCount = _moviePicturesFileList.Count;

            if (movieSpeed > 0) {
                currentMovieImageNum += ((movieSpeed*.01) + 1);
            }
            else if (movieSpeed < 0) {
                currentMovieImageNum += (100 + movieSpeed)*.01;
            }
            else {
                currentMovieImageNum++;
            }

            int currentImage = Convert.ToInt32(currentMovieImageNum);
            if (currentImage >= pictureCount || currentImage < 0)
                currentMovieImageNum = currentImage= 0;

            var currentMovieImage = new FastPixel.FastPixel(new Bitmap(Image.FromFile(_moviePicturesFileList[currentImage])));

            int imgwidth = currentMovieImage.Width;
            int imght = currentMovieImage.Height;
            int yoffset = (BufferHt + imght)/2;
            int xoffset = (imgwidth - BufferWi)/2;
            int limit = (dir < 2) ? imgwidth + BufferWi : imght + BufferHt;
            int movement = Convert.ToInt32((State%(limit*speedfactor))/speedfactor);

            // copy image to buffer
            currentMovieImage.Lock();
            Color fpColor = new Color();
            for (int x = 0; x < imgwidth; x++) {
                for (int y = 0; y < imght; y++) {
                    fpColor = currentMovieImage.GetPixel(x, y);
                    if (fpColor != Color.Transparent && fpColor != Color.Black) {
                        switch (dir) {
                            case 1:
                                // left
                                SetPixel(x + BufferWi - movement, yoffset - y, fpColor);
                                break;
                            case 2:
                                // right
                                SetPixel(x + movement - imgwidth, yoffset - y, fpColor);
                                break;
                            case 3:
                                // up
                                SetPixel(x - xoffset, movement - y, fpColor);
                                break;
                            case 4:
                                // down
                                SetPixel(x - xoffset, BufferHt + imght - y - movement, fpColor);
                                break;
                            default:
                                // no movement - centered
                                SetPixel(x - xoffset, yoffset - y, fpColor);
                                break;
                        }
                    }
                }
            }
            currentMovieImage.Unlock(false);
            currentMovieImage.Dispose();
        }
Example #45
0
		protected override void RenderEffect(int frame, ref PixelFrameBuffer frameBuffer)
		{
			if (_image == null) return;
			const int speedfactor = 4;
			double position = (GetEffectTimeIntervalPosition(frame) * Speed) % 1;
			double level = LevelCurve.GetValue(GetEffectTimeIntervalPosition(frame) * 100) / 100;
			
			CalculateImageNumberByPosition(position);
			_image.SelectActiveFrame(_dimension,(int) _currentGifImageNum);
				
			_scaledImage = ScaleToGrid ? ScaleImage(_image, BufferWi, BufferHt) : ScaleImage(_image, _image.Width * ScalePercent / 100, _image.Height * ScalePercent / 100);
			_fp = new FastPixel.FastPixel(_scaledImage);
			
			int imgwidth = _fp.Width;
			int imght = _fp.Height;
			int yoffset = (BufferHt + imght) / 2;
			int xoffset = (imgwidth - BufferWi) / 2;
			int state = Speed * frame;
			int xOffsetAdj = XOffset*BufferWi/100;
			int yOffsetAdj = YOffset*BufferHt/100;

			switch (Type)
			{
				case EffectType.RenderPicturePeekaboo0:
				case EffectType.RenderPicturePeekaboo180:
					//Peek a boo
					yoffset = -(BufferHt) + (int)((BufferHt+5)*position*2);
					if (yoffset > 10)
					{
						yoffset = -yoffset + 10; //reverse direction
					}
					else if (yoffset >= -1)
					{
						yoffset = -1; //pause in middle
					}
					
					break;
				case EffectType.RenderPictureWiggle:
					if (position >= 0.5)
					{
						xoffset += (int)(BufferWi * ((1.0 - position) * 2.0 - 0.5));
					}
					else
					{
						xoffset += (int)(BufferWi * (position * 2.0 - 0.5));
					}
					break;
				case EffectType.RenderPicturePeekaboo90: //peekaboo 90
				case EffectType.RenderPicturePeekaboo270: //peekaboo 270
					if (Orientation == StringOrientation.Vertical)
					{
						yoffset = (imght - BufferWi)/2; //adjust offsets for other axis
					}
					else
					{
						yoffset = (imgwidth - BufferHt) / 2; //adjust offsets for other axis	
					}

					if (Orientation == StringOrientation.Vertical)
					{
						xoffset = -(BufferHt) + (int) ((BufferHt + 5)*position*2);
					}
					else
					{
						xoffset = -(BufferWi) + (int)((BufferWi + 5) * position * 2);
					}
					if (xoffset > 10)
					{
						xoffset = -xoffset + 10; //reverse direction
					}
					else if (xoffset >= -1)
					{
						xoffset = -1; //pause in middle
					}
					
					break;
			}

			_fp.Lock();
			for (int x = 0; x < imgwidth; x++)
			{
				for (int y = 0; y < imght; y++)
				{
					//if (!image.IsTransparent(x,y))
					Color color = _fp.GetPixel(x, y);
					

					if (color != Color.Transparent)
					{
						var hsv = HSV.FromRGB(color);
						hsv.V = hsv.V * level;
						switch (Type)
						{
							case EffectType.RenderPictureLeft:
								// left
								int leftX = x + (BufferWi - (int)(position * (imgwidth + BufferWi)));
								
								frameBuffer.SetPixel(leftX + xOffsetAdj, yoffset - y + yOffsetAdj, hsv);
								break;
							case EffectType.RenderPictureRight:
								// right
								int rightX = x + -imgwidth + (int)(position * (imgwidth + BufferWi));
								
								frameBuffer.SetPixel(rightX + xOffsetAdj, yoffset - y + yOffsetAdj, hsv);
								break;
							case EffectType.RenderPictureUp:
								// up
								int upY = (int)((imght + BufferHt) *position) - y;
								
								frameBuffer.SetPixel(x - xoffset + xOffsetAdj, upY + yOffsetAdj, hsv);
								break;
							case EffectType.RenderPictureDown:
								// down
								int downY = (BufferHt + imght-1)  - (int)((imght + BufferHt) * position) - y;
								
								frameBuffer.SetPixel(x - xoffset + xOffsetAdj, downY+yOffsetAdj, hsv);
								break;
							case EffectType.RenderPictureUpleft:
								int upLeftY = (int)((imght + BufferHt) * position) - y;
								
								frameBuffer.SetPixel(Convert.ToInt32(x + BufferWi - (state % ((imgwidth + BufferWi) * speedfactor)) / speedfactor) + xOffsetAdj, upLeftY+yOffsetAdj, hsv);
								break; // up-left
							case EffectType.RenderPictureDownleft:
								int downLeftY = BufferHt + imght - (int)((imght + BufferHt) * position) - y;
								
								frameBuffer.SetPixel(Convert.ToInt32(x + BufferWi - (state % ((imgwidth + BufferWi) * speedfactor)) / speedfactor) + xOffsetAdj, downLeftY+yOffsetAdj, hsv);
								break; // down-left
							case EffectType.RenderPictureUpright:
								int upRightY = (int)((imght + BufferHt) * position) - y;
								
								frameBuffer.SetPixel(Convert.ToInt32(x + (state % ((imgwidth + BufferWi) * speedfactor)) / speedfactor - imgwidth)+xOffsetAdj, upRightY+yOffsetAdj, hsv);
								break; // up-right
							case EffectType.RenderPictureDownright:
								int downRightY = BufferHt + imght - (int)((imght + BufferHt) * position) - y;
								
								frameBuffer.SetPixel(Convert.ToInt32(x + (state % ((imgwidth + BufferWi) * speedfactor)) / speedfactor - imgwidth) + xOffsetAdj, downRightY+yOffsetAdj, hsv);
								break; // down-right
							case EffectType.RenderPicturePeekaboo0:
								//Peek a boo
								frameBuffer.SetPixel(x - xoffset + xOffsetAdj, BufferHt + yoffset - y+yOffsetAdj, hsv);
								break;
							case EffectType.RenderPictureWiggle:
								frameBuffer.SetPixel(x + xoffset + xOffsetAdj, yoffset - y + yOffsetAdj, hsv);
								break;
							case EffectType.RenderPicturePeekaboo90:
								frameBuffer.SetPixel(BufferWi + xoffset - y + xOffsetAdj, x - yoffset + yOffsetAdj, hsv);	
								break;
							case EffectType.RenderPicturePeekaboo180:
								frameBuffer.SetPixel(x - xoffset + xOffsetAdj, y - yoffset + yOffsetAdj, hsv);
								break;
							case EffectType.RenderPicturePeekaboo270:
								frameBuffer.SetPixel(y - xoffset + xOffsetAdj, BufferHt + yoffset - x + yOffsetAdj, hsv);
								break;
							default:
								// no movement - centered
								frameBuffer.SetPixel(x - xoffset + xOffsetAdj, yoffset - y + yOffsetAdj, hsv);
								break;
						}
					}
				}
			}
			_fp.Unlock(false);
			_fp.Dispose();
			_scaledImage.Dispose();
		}