/// <summary>
 ///
 /// </summary>
 /// <param name="sizex">Image width</param>
 /// <param name="sizey">Image height</param>
 /// <param name="scene">Scene description</param>
 /// <param name="frame">Number of frame rendered</param>
 /// <param name="quality">Render quality (default: Medium)</param>
 public RayProcessor(int sizex, int sizey, SceneDescription scene, int frame, RenderQuality quality, string outputPath)
 {
     this.sizex       = sizex;
     this.sizey       = sizey;
     this.frame       = frame;
     sceneDescription = scene;
     this.Quality     = quality;
     this.OutputPath  = outputPath;
 }
示例#2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="sizex">Image width</param>
 /// <param name="sizey">Image height</param>
 /// <param name="scene">Scene description</param>
 /// <param name="frame">Number of frame rendered</param>
 /// <param name="quality">Render quality (default: Medium)</param>
 public RayProcessor(int sizex, int sizey, SceneDescription scene, int frame, RenderQuality quality, string outputPath)
 {
     this.sizex = sizex;
     this.sizey = sizey;
     this.frame = frame;
     sceneDescription = scene;
     this.Quality = quality;
     this.OutputPath = outputPath;
 }
 public double GetTime(RenderQuality quality)
 {
     switch (quality)
     {
         case RenderQuality.Fast:
             return (_fastCount == 0) ? -1 : _fastTime / _fastCount;
         case RenderQuality.HighQuality:
             return (_highQualityCount == 0) ? -1 : _highQualityTime / _highQualityCount;
     }
     return 0;
 }
 // Note: we can refactor this to keep track of the average
 public void SaveTime(double time, RenderQuality quality)
 {
     switch (quality)
     {
         case RenderQuality.Fast:
             _fastTime += time;
             _fastCount++;
             break;
         case RenderQuality.HighQuality:
             _highQualityTime += time;
             _highQualityCount++;
             break;
     }
 }
示例#5
0
        public static bool PerformanceMode(this RenderQuality quality)
        {
            switch (quality)
            {
            case RenderQuality.MaxPerformance:
            case RenderQuality.Performance:
                return(true);

            case RenderQuality.Quality:
            case RenderQuality.MaxQuality:
                return(false);

            default:
                throw new ArgumentOutOfRangeException("quality");
            }
        }
示例#6
0
        public static TextureFormat GetTextureFormat(this RenderQuality quality)
        {
            switch (quality)
            {
            case RenderQuality.MaxPerformance:
                return(TextureFormat.Unorm8);

            case RenderQuality.Performance:
                return(TextureFormat.Float16);

            case RenderQuality.Quality:
                return(TextureFormat.Unorm16);

            case RenderQuality.MaxQuality:
                return(TextureFormat.Float32);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
示例#7
0
 public static bool QualityMode(this RenderQuality quality)
 {
     return(!PerformanceMode(quality));
 }
示例#8
0
        public override void DrawFromGlyphPlans(GlyphPlanSequence seq, int startAt, int len, float left, float top)
        {
            if (StartDrawOnLeftTop)
            {
                //version 2
                //offset y down
                top += this.FontLineSpacingPx;
            }

            float fontSizePoint = this.FontSizeInPoints;
            float scale         = _currentTypeface.CalculateScaleToPixelFromPointSize(fontSizePoint);

            //4. render each glyph
            float ox = _painter.OriginX;
            float oy = _painter.OriginY;


            Typography.OpenFont.Tables.COLR colrTable = _currentTypeface.COLRTable;
            Typography.OpenFont.Tables.CPAL cpalTable = _currentTypeface.CPALTable;
            bool hasColorGlyphs = (colrTable != null) && (cpalTable != null);

            //---------------------------------------------------
            _glyphMeshStore.SetHintTechnique(this.HintTechnique);
            _glyphMeshStore.SetFont(_currentTypeface, fontSizePoint);
            _glyphMeshStore.SimulateOblique = this.SimulateSlant;
            //---------------------------------------------------


            if (_currentTypeface.HasSvgTable())
            {
                _glyphSvgStore.SetCurrentTypeface(_currentTypeface);
                int seqLen = seq.Count;
                if (len > seqLen)
                {
                    len = seqLen;
                }

                var snapToPx = new GlyphPlanSequenceSnapPixelScaleLayout(seq, startAt, len, scale);
                while (snapToPx.Read())
                {
                    _painter.SetOrigin((float)Math.Round(left + snapToPx.ExactX) + 0.33f, (float)Math.Floor(top + snapToPx.ExactY));

                    GlyphBitmap glyphBmp = _glyphSvgStore.GetGlyphBitmap(snapToPx.CurrentGlyphIndex);
                    //how to draw the image
                    //1.
                    if (glyphBmp != null)
                    {
                        _painter.DrawImage(glyphBmp.Bitmap);
                    }
                }
            }
            else if (_currentTypeface.IsBitmapFont)
            {
                //check if we have exported all the glyph bitmap
                //to some 'ready' form?
                //if not then create it
                _glyphBitmapStore.SetCurrentTypeface(_currentTypeface);

                int seqLen = seq.Count;

                if (len > seqLen)
                {
                    len = seqLen;
                }

                var snapToPx = new GlyphPlanSequenceSnapPixelScaleLayout(seq, startAt, len, scale);
                while (snapToPx.Read())
                {
                    _painter.SetOrigin((float)Math.Round(left + snapToPx.ExactX) + 0.33f, (float)Math.Floor(top + snapToPx.ExactY));
                    GlyphBitmap glyphBmp = _glyphBitmapStore.GetGlyphBitmap(snapToPx.CurrentGlyphIndex);
                    //how to draw the image
                    //1.
                    _painter.DrawImage(glyphBmp.Bitmap);
                }
            }
            else
            {
                if (!hasColorGlyphs)
                {
                    bool          savedUseLcdMode   = _painter.UseSubPixelLcdEffect; //save,restore later
                    RenderQuality savedRederQuality = _painter.RenderQuality;
                    _painter.RenderQuality        = RenderQuality.HighQuality;
                    _painter.UseSubPixelLcdEffect = true;

                    int seqLen = seq.Count;

                    if (len > seqLen)
                    {
                        len = seqLen;
                    }

                    var snapToPx = new GlyphPlanSequenceSnapPixelScaleLayout(seq, startAt, len, scale);
                    while (snapToPx.Read())
                    {
                        _painter.SetOrigin((float)Math.Round(left + snapToPx.ExactX) + 0.33f, (float)Math.Floor(top + snapToPx.ExactY));
                        _painter.Fill(_glyphMeshStore.GetGlyphMesh(snapToPx.CurrentGlyphIndex));
                    }

                    //restore
                    _painter.RenderQuality        = savedRederQuality;
                    _painter.UseSubPixelLcdEffect = savedUseLcdMode;
                }
                else
                {
                    //-------------
                    //this glyph has color information
                    //-------------
                    Color originalFillColor = _painter.FillColor;
                    int   seqLen            = seq.Count;

                    if (len > seqLen)
                    {
                        len = seqLen;
                    }

                    var snapToPx = new GlyphPlanSequenceSnapPixelScaleLayout(seq, startAt, len, scale);
                    while (snapToPx.Read())
                    {
                        _painter.SetOrigin((float)Math.Round(left + snapToPx.ExactX), (float)Math.Floor(top + snapToPx.ExactY));

                        ushort colorLayerStart;
                        if (colrTable.LayerIndices.TryGetValue(snapToPx.CurrentGlyphIndex, out colorLayerStart))
                        {
                            //TODO: optimize this
                            //we found color info for this glyph
                            ushort colorLayerCount = colrTable.LayerCounts[snapToPx.CurrentGlyphIndex];
                            byte   r, g, b, a;
                            for (int c = colorLayerStart; c < colorLayerStart + colorLayerCount; ++c)
                            {
                                ushort gIndex = colrTable.GlyphLayers[c];

                                int palette = 0;                                              // FIXME: assume palette 0 for now
                                cpalTable.GetColor(
                                    cpalTable.Palettes[palette] + colrTable.GlyphPalettes[c], //index
                                    out r, out g, out b, out a);
                                //-----------
                                _painter.FillColor = new Color(r, g, b);//? a component
                                _painter.Fill(_glyphMeshStore.GetGlyphMesh(gIndex));
                            }
                        }
                        else
                        {
                            //-----------------------------------
                            //TODO: review here ***
                            //PERFORMANCE revisit here
                            //if we have create a vxs we can cache it for later use?
                            //-----------------------------------
                            _painter.Fill(_glyphMeshStore.GetGlyphMesh(snapToPx.CurrentGlyphIndex));
                        }
                    }

                    _painter.FillColor = originalFillColor; //restore color
                }
            }
            //restore prev origin
            _painter.SetOrigin(ox, oy);
        }
        Bitmap RenderPageCore(int pageNum, Size maxSize, RenderQuality quality)
        {
            ArgCheck.InRange(pageNum, 0, PageCount, "pageNum");

            _pdfDoc.o.CurrentPage = pageNum;

            _pdfDoc.o.UseMuPDF = false;
            if (_pdfDoc.o.SupportsMuPDF && quality == RenderQuality.HighQuality) 
            { 
                _pdfDoc.o.UseMuPDF = true; 
            }

            // Scale
            Size pageSize = new Size(_pdfDoc.o.PageWidth, _pdfDoc.o.PageHeight);
            Size size = pageSize.ScaleToFitBounds(maxSize);

            // 24bpp format for compatibility with AForge
            Bitmap bitmap = new Bitmap(size.Width, size.Height, PixelFormat.Format24bppRgb);

            using (Graphics g = Graphics.FromImage(bitmap))
            {
                _pdfDoc.o.Zoom = ZoomConst * (double)bitmap.Width / _pdfDoc.o.PageWidth;
                try
                {
                    // Note: not certain what the params mean.
                    // Simple RenderPage sometimes does not zoom properly
                    _pdfDoc.o.RenderPage(g.GetHdc(), true, false);
                    g.ReleaseHdc();
                }
                finally
                {
                    _pdfDoc.o.Zoom = ZoomConst;
                }

                Rectangle bounds = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
                g.FillRectangle(Brushes.White, bounds);

                _pdfDoc.o.ClientBounds = bounds;
                _pdfDoc.o.DrawPageHDC(g.GetHdc());
                g.ReleaseHdc();
            }

            return bitmap;
        }
        public Bitmap RenderPageImage(int pageNum, Size maxSize, RenderQuality quality = RenderQuality.Optimal)
        {
            if (pageNum < 1) { throw new ArgumentException("pageNum < 1. Should start at 1"); }
            AssertPdfDocLoaded();

            // Get quality, high by default
            if (quality == RenderQuality.Optimal)
            {
                quality = PerfInfo.QualityToUse;
            }

            DateTime startTime = DateTime.Now;
            Bitmap image = RenderPageCore(pageNum, maxSize, quality);

            double time = (DateTime.Now - startTime).TotalMilliseconds;
            PerfInfo.SaveTime(time, quality);

            return image;
        }
 public Bitmap RenderPageImage(int pageNum, Size maxSize, RenderQuality quality = RenderQuality.HighQuality)
 {
     if (maxSize == Size.Empty) { return new Bitmap(PageSize.Width, PageSize.Height); }
     return new Bitmap(maxSize.Width, PageSize.Height);
 }
示例#12
0
        /// <summary>
        /// Creates a LensFlare instance with custom settings. The graphics device
        /// will be reused, but will not be disposed of at instance destruction.
        /// </summary>
        /// <param name="device">The graphics device to use.</param>
        /// <param name="context">The device context to use.</param>
        /// <param name="quality">The required render quality.</param>
        /// <param name="profile">The desired optical profile.</param>
        /// <param name="options">The desired diffraction options.</param>
        public EyeDiffraction(Device device, DeviceContext context, RenderQuality quality, OpticalProfile profile, DiffractionOptions options)
        {
            Pass = new SurfacePass(device);
            composer = new ApertureComposer(device);

            Device = device;            /* Store the device. */
            Context = context;          /* Save the context. */
            Quality = quality;          /* Validate quality. */
            Profile = profile;          /* Use lens profile. */
            Options = options;          /* Save the options. */
        }
示例#13
0
 private Size DiffractionSize(RenderQuality quality)
 {
     switch (quality)
     {
         case RenderQuality.Low:             return new Size( 256,  256);
         case RenderQuality.Medium:          return new Size( 512,  512);
         case RenderQuality.High:            return new Size(1024, 1024);
         case RenderQuality.Optimal:         return new Size(2048, 2048);
         default: throw new ArgumentException("Unknown render quality.");
     }
 }
示例#14
0
 private Size ConvolutionSize(RenderQuality quality)
 {
     return new Size(DiffractionSize(quality).Width  * 2,
                     DiffractionSize(quality).Height * 2);
 }