Example #1
0
 private static void Rotate(IMagickImage output, UnperspectiveRotation rotation)
 {
     if (rotation != UnperspectiveRotation.None)
     {
         output.Rotate((int)rotation);
     }
 }
Example #2
0
        private void ExecuteInnerTrim(IMagickImage image, MagickColor borderColor)
        {
            var area = GetLargestArea(image, borderColor);

            image.Rotate(90);
            var rotatedArea = GetLargestArea(image, borderColor);

            if (rotatedArea > area)
            {
                Crop(image, rotatedArea);
                image.Rotate(-90);
            }
            else
            {
                image.Rotate(-90);
                Crop(image, area);
            }
        }
 private void RotateImage(IMagickImage image)
 {
     if (Rotation == TextCleanerRotation.None)
     {
         return;
     }
     if ((Layout == TextCleanerLayout.Portrait && image.Height < image.Width) ||
         (Layout == TextCleanerLayout.Landscape && image.Height > image.Width))
     {
         if (Rotation == TextCleanerRotation.Counterclockwise)
         {
             image.Rotate(90);
         }
         else
         {
             image.Rotate(-90);
         }
     }
 }
Example #4
0
 /// <summary>
 /// Realiza uma determinada ação na imagem
 /// </summary>
 /// <param name="acao">Ação a executar</param>
 /// <param name="imagem">Imagem</param>
 public void ProcessarAcao(Acao acao, IMagickImage imagem)
 {
     if (acao is AcaoEscala escala)
     {
         imagem.Scale(new Percentage(escala.Percentagem));
     }
     else if (acao is AcaoRotacao rotacionar)
     {
         imagem.Rotate(rotacionar.Angulo);
     }
     else if (acao is AcaoTranslacao translacao)
     {
         using (var imgOr = imagem.Clone())
         {
             imagem.Colorize(MagickColors.Black, new Percentage(100));
             imagem.Composite(imgOr, translacao.X, translacao.Y);
         }
     }
     else
     {
         ProcessarAcao(RecuperarDetalhes(acao), imagem);
     }
 }
Example #5
0
        private static void RotateImageBasedOnOrientation(IMagickImage image)
        {
            switch (image.Orientation)
            {
            case OrientationType.TopLeft:
                break;

            case OrientationType.TopRight:
                image.Flop();
                break;

            case OrientationType.BottomRight:
                image.Rotate(180);
                break;

            case OrientationType.BottomLeft:
                image.Flop();
                image.Rotate(180);
                break;

            case OrientationType.LeftTop:
                image.Flop();
                image.Rotate(-90);
                break;

            case OrientationType.RightTop:
                image.Rotate(90);
                break;

            case OrientationType.RightBottom:
                image.Flop();
                image.Rotate(90);
                break;

            case OrientationType.LeftBotom:
                image.Rotate(-90);
                break;

            default:
                break;
            }

            image.Orientation = OrientationType.TopLeft;
        }
Example #6
0
        private void DrawImage(MagickImage overlay, DrawableFixture fixture)
        {
            //MainForm.Log(string.Format("Image: {0} ({1}) ...", fixture.Name, fixture.NifName), MainForm.LogLevel.notice);
            string fileName    = System.IO.Path.GetFileNameWithoutExtension(fixture.NifName);
            string defaultTree = "elm1";

            // Load default tree
            if (!m_modelImages.ContainsKey(defaultTree))
            {
                string defaultTreeImage = string.Format("{0}\\data\\prerendered\\trees\\{1}.png", System.Windows.Forms.Application.StartupPath, defaultTree);
                if (System.IO.File.Exists(defaultTreeImage))
                {
                    MagickImage treeImage = new MagickImage(defaultTreeImage);
                    treeImage.Blur();
                    m_modelImages.Add(defaultTree, treeImage);
                }
                else
                {
                    m_modelImages.Add(fileName, null);
                }
            }

            // TreeClusters are sets of trees in a specified arrangement
            // They need to be drawe separately
            if (fixture.IsTreeCluster)
            {
                DrawTreeCluster(overlay, fixture);
                return;
            }

            // Load model image
            if (!m_modelImages.ContainsKey(fileName))
            {
                string objectImageFile = string.Format("{0}\\data\\prerendered\\objects\\{1}.png", System.Windows.Forms.Application.StartupPath, fileName);
                if (fixture.IsTree)
                {
                    objectImageFile = string.Format("{0}\\data\\prerendered\\trees\\{1}.png", System.Windows.Forms.Application.StartupPath, fileName);
                }

                if (System.IO.File.Exists(objectImageFile))
                {
                    MagickImage objectImage = new MagickImage(objectImageFile);
                    if (fixture.IsTree)
                    {
                        objectImage.Blur();
                    }
                    m_modelImages.Add(fileName, objectImage);
                }
                else
                {
                    if (fixture.IsTree)
                    {
                        MainForm.Log(string.Format("Can not find image for tree {0} ({1}), using default tree", fixture.Name, fixture.NifName), MainForm.LogLevel.warning);
                        m_modelImages.Add(fileName, m_modelImages[defaultTree]);
                    }
                    else
                    {
                        m_modelImages.Add(fileName, null);
                    }
                }
            }

            // Draw the image
            if (m_modelImages.ContainsKey(fileName) && m_modelImages[fileName] != null)
            {
                NifRow orginalNif = FixturesLoader.NifRows.Where(n => n.NifId == fixture.FixtureRow.NifId).FirstOrDefault();
                if (orginalNif == null)
                {
                    MainForm.Log(string.Format("Error with imaged nif ({0})!", fixture.FixtureRow.TextualName), MainForm.LogLevel.warning);
                }

                System.Drawing.SizeF objectSize = orginalNif.GetSize(0, 0);

                // The final image
                using (MagickImage modelImage = new MagickImage(MagickColors.Transparent, fixture.CanvasWidth, fixture.CanvasHeight))
                {
                    // Place the replacing image
                    using (IMagickImage newModelImage = m_modelImages[fileName].Clone())
                    {
                        newModelImage.BackgroundColor = MagickColors.Transparent;

                        double scaleWidthToTreeImage  = objectSize.Width / newModelImage.Width;
                        double scaleHeightToTreeImage = objectSize.Height / newModelImage.Height;
                        int    width  = Convert.ToInt32(newModelImage.Width * scaleWidthToTreeImage * fixture.Scale);
                        int    height = Convert.ToInt32(newModelImage.Height * scaleHeightToTreeImage * fixture.Scale);

                        // Resize to new size
                        newModelImage.FilterType         = FilterType.Gaussian;
                        newModelImage.VirtualPixelMethod = VirtualPixelMethod.Transparent;
                        newModelImage.Resize(width, height);

                        // Rotate the image
                        //newModelImage.Rotate(fixture.FixtureRow.A * -1 * fixture.FixtureRow.AxisZ3D);
                        newModelImage.Rotate((360d * fixture.FixtureRow.AxisZ3D - fixture.FixtureRow.A) * -1);

                        // Place in center of modelImage
                        modelImage.Composite(newModelImage, Gravity.Center, CompositeOperator.SrcOver);
                    }

                    // Draw the shaped model if wanted
                    if (fixture.RendererConf.HasLight)
                    {
                        using (MagickImage modelShaped = new MagickImage(MagickColors.Transparent, fixture.CanvasWidth, fixture.CanvasHeight))
                        {
                            foreach (DrawableElement drawableElement in fixture.DrawableElements)
                            {
                                var light = 1 - drawableElement.lightning;
                                modelShaped.Settings.FillColor = new MagickColor(
                                    Convert.ToUInt16(ushort.MaxValue * light),
                                    Convert.ToUInt16(ushort.MaxValue * light),
                                    Convert.ToUInt16(ushort.MaxValue * light)
                                    );

                                DrawablePolygon polyDraw = new DrawablePolygon(drawableElement.coordinates);
                                modelShaped.Draw(polyDraw);
                            }

                            using (MagickImage modelMask = new MagickImage(MagickColors.Transparent, fixture.CanvasWidth, fixture.CanvasHeight))
                            {
                                modelShaped.Blur();
                                modelMask.Composite(modelShaped, 0, 0, CompositeOperator.DstAtop);
                                modelMask.Composite(modelImage, 0, 0, CompositeOperator.DstIn);
                                modelMask.Level(new Percentage(20), new Percentage(100), Channels.All);
                                modelImage.Composite(modelMask, 0, 0, CompositeOperator.ColorDodge);
                            }
                        }
                    }

                    // Add the shadow if not a tree (tree shadow are substituted by a treeoverlay)
                    if (fixture.RendererConf.HasShadow && !fixture.IsTree)
                    {
                        CastShadow(
                            modelImage,
                            fixture.RendererConf.ShadowOffsetX,
                            fixture.RendererConf.ShadowOffsetY,
                            fixture.RendererConf.ShadowSize,
                            new Percentage(100 - fixture.RendererConf.ShadowTransparency),
                            fixture.RendererConf.ShadowColor
                            );

                        // Update the canvas position to match the new border
                        fixture.CanvasX -= fixture.RendererConf.ShadowSize;
                        fixture.CanvasY -= fixture.RendererConf.ShadowSize;
                    }

                    // Set transprency if not a tree (see shadow)
                    if (fixture.RendererConf.Transparency != 0 && !fixture.IsTree)
                    {
                        double divideValue = 100.0 / (100.0 - fixture.RendererConf.Transparency);
                        modelImage.Evaluate(Channels.Alpha, EvaluateOperator.Divide, divideValue);
                    }

                    // Place the image on the right position
                    overlay.Composite(modelImage, Convert.ToInt32(fixture.CanvasX), Convert.ToInt32(fixture.CanvasY), CompositeOperator.SrcOver);
                }
            }
        }