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(); } } }
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(); } }
/// <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(); }
protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer) { if (!_videoFileDetected) { return; } InitFrameData(frame, out double intervalPos, out double intervalPosFactor, out double level, out double adjustedBrightness); InitialRender(intervalPos, intervalPosFactor); if (_fp != null) { _fp.Lock(); var bufferWi = BufferWi; var bufferHt = BufferHt; for (int x = 0; x < _imageWi; x++) { for (int y = 0; y < _imageHt; y++) { CalculatePixel(x, y, frameBuffer, frame, level, adjustedBrightness, ref bufferHt, ref bufferWi); } } _fp.Unlock(false); } }
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(); } }
//#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; }
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(); } }
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(); } }
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(); }
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); } } } }
protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer) { if (_image != null) { var dir = 360 - Direction; var intervalPos = GetEffectTimeIntervalPosition(frame); var intervalPosFactor = intervalPos * 100; double level = LevelCurve.GetValue(intervalPosFactor) / 100; double adjustedBrightness = (double)(CalculateIncreaseBrightness(intervalPosFactor)) / 10; 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 = CalculateXOffset(intervalPosFactor) * BufferWi / 100; int yOffsetAdj = CalculateYOffset(intervalPosFactor) * 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 * adjustedBrightness; 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, adjustedBrightness); frameBuffer.SetPixel(x - xoffset + xOffsetAdj, BufferHt + yoffset - y + yOffsetAdj, hsv); } break; case EffectType.RenderPictureWiggle: hsv = CustomColor(hsv, frame, level, fpColor, adjustedBrightness); frameBuffer.SetPixel(x + xoffset + xOffsetAdj, yoffset - y + yOffsetAdj, hsv); break; case EffectType.RenderPicturePeekaboo90: hsv = CustomColor(hsv, frame, level, fpColor, adjustedBrightness); frameBuffer.SetPixel(BufferWi + xoffset - y + xOffsetAdj, BufferHt - x - yoffset + yOffsetAdj, hsv); break; case EffectType.RenderPicturePeekaboo180: hsv = CustomColor(hsv, frame, level, fpColor, adjustedBrightness); if (StringOrientation == StringOrientation.Vertical) { frameBuffer.SetPixel((BufferWi - x) - xoffset + xOffsetAdj, y - yoffset + yOffsetAdj, hsv); } else { frameBuffer.SetPixel((BufferWi - x) - xoffset + xOffsetAdj - (BufferWi / 2), y - yoffset + yOffsetAdj, hsv); } break; case EffectType.RenderPicturePeekaboo270: hsv = CustomColor(hsv, frame, level, fpColor, adjustedBrightness); frameBuffer.SetPixel(y - xoffset + xOffsetAdj, BufferHt + yoffset - (BufferHt - x) + yOffsetAdj, hsv); break; case EffectType.RenderPictureLeft: // left int leftX = x + (BufferWi - (int)(_position * (imageWi + BufferWi))); hsv = CustomColor(hsv, frame, level, fpColor, adjustedBrightness); 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, adjustedBrightness); 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, adjustedBrightness); 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, adjustedBrightness); 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, adjustedBrightness); 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, adjustedBrightness); 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, adjustedBrightness); 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, adjustedBrightness); frameBuffer.SetPixel(x - xoffset + xOffsetAdj, downY + yOffsetAdj, hsv); break; case EffectType.RenderPictureNone: hsv = CustomColor(hsv, frame, level, fpColor, adjustedBrightness); frameBuffer.SetPixel(x - xoffset + xOffsetAdj, yoffset - y + yOffsetAdj, hsv); break; case EffectType.RenderPictureTiles: int colorX = x + Convert.ToInt32(_movementX) - (xOffsetAdj * BufferWi / 100); int colorY = y + Convert.ToInt32(_movementY) + (yOffsetAdj * 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, adjustedBrightness); frameBuffer.SetPixel(x, BufferHt - y - 1, hsv); } break; } } } _fp.Unlock(false); _fp.Dispose(); _scaledImage.Dispose(); } } }
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(); }
//#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; }
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(); }
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(); }
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(); }
/// <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; }
/// <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; }
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); } } } }
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(); }