Пример #1
0
 public PWM(IO60P16Module parentModule, PwmPin pin, uint period, uint duration, ScaleFactor scale, bool invertOutput)
 {
     _parentModule = parentModule;
     _pin = pin;
     _period_ns = period * (uint)scale;
     _duration_ns = duration * (uint)scale;
     _scale = scale;
     _invertOutput = invertOutput;
 }
Пример #2
0
        /// <summary>
        /// Build an instance of the PWM type
        /// </summary>
        /// <param name="channel">The channel</param>
        /// <param name="period">The period of the pulse</param>
        /// <param name="duration">The duration of the pulse.  The value should be a fraction of the period</param>
        /// <param name="scale">The scale factor for the period/duration (nS, uS, mS)</param>
        /// <param name="invert">Whether the output should be inverted or not</param>
        public PWM(Cpu.PWMChannel channel, uint period, uint duration, ScaleFactor scale, bool invert)
        {
            HardwareProvider hwProvider = HardwareProvider.HwProvider;

            if (hwProvider == null) throw new InvalidOperationException();

            m_pin      = hwProvider.GetPwmPinForChannel(channel);
            m_channel  = channel;
            //--//
            m_period   = period;
            m_duration = duration;
            m_scale    = scale;
            m_invert   = invert;
            //--//
            try
            {
                Init();
                
                Commit();
                
                Port.ReservePin(m_pin, true);
            }
            catch
            {
                Dispose(false);
            }
        }
Пример #3
0
 private static double FrequencyFromPeriod(double period, ScaleFactor scale)
 {
     return ((uint)scale / period);
 }
Пример #4
0
        //--//

        private static uint PeriodFromFrequency(double f, out ScaleFactor scale)
        {
            if(f >= 1000.0)
            {
                scale = ScaleFactor.Nanoseconds;
                return (uint)(((uint)ScaleFactor.Nanoseconds / f) + 0.5);
            }
            else if(f >= 1.0)
            {
                scale = ScaleFactor.Microseconds;
                return (uint)(((uint)ScaleFactor.Microseconds / f) + 0.5);
            }
            else
            {
                scale = ScaleFactor.Milliseconds;
                return (uint)(((uint)ScaleFactor.Milliseconds / f) + 0.5);
            }
        }
Пример #5
0
 internal PwmChannel(IPwmController controller, uint channel, uint period, uint duration, ScaleFactor scale)
 {
     this.channel    = channel;
     this.period     = period;
     this.duration   = duration;
     this.scale      = scale;
     this.controller = controller;
     try
     {
         AllocateChannel(channel);
         Init();
         Commit();
     }
     catch
     {
         Dispose(false);
     }
 }
Пример #6
0
        private static Texture2D GetLayerTexture(PsdDocument psdDoc, PsdLayer psdLayer, ScaleFactor scaleFactor)
        {
            if (psdLayer == null || psdLayer.IsGroup)
            {
                return(null);
            }

            Texture2D layerTexture = GetTexture(psdLayer);

            if (scaleFactor != ScaleFactor.Full)
            {
                int mipMapLevel = scaleFactor == ScaleFactor.Half ? 1 : 2;
                layerTexture = ScaleTextureByMipmap(layerTexture, mipMapLevel);
            }
            return(layerTexture);
        }
Пример #7
0
        public bool GenerateFromBitmap(string file, ScaleFactor f)
        {
            try
            {
                m_name = Path.GetFileName(file);
                Bitmap bm = new Bitmap(file);
                // add 3d points
                for (int y = 0; y < bm.Height; y++)
                {
                    for (int x = 0; x < bm.Width; x++)
                    {
                        Color   clr = bm.GetPixel(x, y);
                        Point3d pnt = new Point3d();
                        pnt.x = f.x * ((double)x);
                        pnt.y = f.y * ((double)y);
                        pnt.z = f.z * ((double)clr.R);
                        m_lstpoints.Add(pnt);
                    }
                }
                // now generate polys
                for (int y = 0; y < bm.Height; y++)
                {
                    for (int x = 0; x < bm.Width; x++)
                    {
                        if (y == (bm.Height - 1))
                        {
                            continue;
                        }
                        if (x == (bm.Width - 1))
                        {
                            continue;
                        }
                        Polygon ply = new Polygon();
                        ply.m_points = new Point3d[3];
                        int idx1 = (y * bm.Width) + x;
                        int idx2 = (y * bm.Width) + x + 1;
                        int idx3 = (y * bm.Width) + x + bm.Width;
                        ply.m_points[0] = (Point3d)m_lstpoints[idx1];
                        ply.m_points[1] = (Point3d)m_lstpoints[idx2];
                        ply.m_points[2] = (Point3d)m_lstpoints[idx3];
                        ply.CalcCenter();
                        ply.CalcNormal();
                        m_lstpolys.Add(ply);


                        Polygon ply2 = new Polygon();
                        ply2.m_points    = new Point3d[3];
                        idx1             = (y * bm.Width) + x + 1;
                        idx2             = (y * bm.Width) + x + bm.Width + 1;
                        idx3             = (y * bm.Width) + x + bm.Width;
                        ply2.m_points[0] = (Point3d)m_lstpoints[idx1];
                        ply2.m_points[1] = (Point3d)m_lstpoints[idx2];
                        ply2.m_points[2] = (Point3d)m_lstpoints[idx3];

                        ply2.CalcCenter();
                        ply2.CalcNormal();
                        m_lstpolys.Add(ply2);
                    }
                }
                Update();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
 private void QuickSelectApplySettings(SpriteAlignment alignment, Vector2 pivot, ScaleFactor scale, bool defaults)
 {
     if (defaults)
     {
         alignment = importSettings.DefaultAlignment;
         pivot     = importSettings.DefaultPivot;
         scale     = importSettings.ScaleFactor;
     }
     foreach (int[] layerIdx in quickSelect)
     {
         var layer = GetLayerData(layerIdx);
         if (layer == null || layer.Childs.Count > 0)
         {
             continue;
         }
         layer.useDefaults = defaults;
         layer.Alignment   = alignment;
         layer.Pivot       = pivot;
         layer.ScaleFactor = scale;
     }
 }
Пример #9
0
 private void ToggleCropMode()
 {
     if (this._isInSetResetCrop)
     {
         return;
     }
     if (this._inCropMode)
     {
         this._inCropMode           = false;
         this._inSelectOwnPhotoArea = false;
         ((UIElement)this.gridChooseThumbnail).Visibility = Visibility.Collapsed;
         ((UIElement)this.gridCropLines).Visibility       = Visibility.Collapsed;
         ((UIElement)this.gridCrop).Visibility            = Visibility.Collapsed;
         this.imageViewer.Mode = ImageViewerMode.Normal;
         ((UIElement)this.stackPanelEffects).Visibility = Visibility.Visible;
         ((UIElement)this.stackPanelCrop).Visibility    = Visibility.Collapsed;
         this.UpdateImageAndEllipseSelectOpacity(1);
     }
     else
     {
         this._inCropMode = true;
         Picture     galleryImage     = this._imageEditorVM.GetGalleryImage(this._albumId, this.CurrentPhotoSeqNo);
         bool        rotated90        = false;
         Size        correctImageSize = this._imageEditorVM.GetCorrectImageSize(galleryImage, this._albumId, this.CurrentPhotoSeqNo, out rotated90);
         BitmapImage bitmapImage      = new BitmapImage();
         Point       point            = new Point();
         Size        viewportSize     = this._imageEditorVM.ViewportSize;
         // ISSUE: explicit reference operation
         double num1 = ((Size)@viewportSize).Width * 2.0;
         viewportSize = this._imageEditorVM.ViewportSize;
         // ISSUE: explicit reference operation
         double num2 = ((Size)@viewportSize).Height * 2.0;
         Size   size = new Size(num1, num2);
         Rect   fit1 = RectangleUtils.ResizeToFit(new Rect(point, size), correctImageSize);
         // ISSUE: explicit reference operation
         if (((Rect)@fit1).Height < (double)galleryImage.Height)
         {
             // ISSUE: explicit reference operation
             // ISSUE: explicit reference operation
             bitmapImage.DecodePixelHeight = (rotated90 ? (int)((Rect)@fit1).Height : (int)((Rect)@fit1).Width);
         }
         ((BitmapSource)bitmapImage).SetSource(galleryImage.GetImage());
         this.imageViewer.CurrentImage.Source = ((ImageSource)this._imageEditorVM.RotateIfNeeded(this._albumId, this.CurrentPhotoSeqNo, new WriteableBitmap((BitmapSource)bitmapImage)));
         this.imageViewer.RectangleFill       = ScaleFactor.GetScaleFactor() != 150 ? new Rect(12.0, 136.0, 456.0, 456.0) : new Rect(12.0, 163.0, 456.0, 456.0);
         this.imageViewer.Mode = ImageViewerMode.RectangleFill;
         ImageEffectsInfo imageEffectsInfo = this._imageEditorVM.GetImageEffectsInfo(this._albumId, this.CurrentPhotoSeqNo);
         if (imageEffectsInfo.CropRect != null)
         {
             Rect rect1 = new Rect();
             // ISSUE: explicit reference operation
             rect1.X = ((double)imageEffectsInfo.CropRect.X);
             // ISSUE: explicit reference operation
             rect1.Y = ((double)imageEffectsInfo.CropRect.Y);
             // ISSUE: explicit reference operation
             rect1.Width = ((double)imageEffectsInfo.CropRect.Width);
             // ISSUE: explicit reference operation
             rect1.Height = ((double)imageEffectsInfo.CropRect.Height);
             Rect rect2 = rect1;
             Rect fit2  = RectangleUtils.ResizeToFit(new Rect(new Point(), new Size(((FrameworkElement)this.imageViewer).Width, ((FrameworkElement)this.imageViewer).Height)), correctImageSize);
             ((UIElement)this.imageViewer.CurrentImage).RenderTransform = ((Transform)RectangleUtils.TransformRect(((GeneralTransform)RectangleUtils.TransformRect(new Rect(new Point(), correctImageSize), fit2, false)).TransformBounds(rect2), this.imageViewer.RectangleFill, false));
         }
         else
         {
             this.imageViewer.AnimateToRectangleFill();
         }
         galleryImage.Dispose();
         this.ShowHideGridFilters(false);
         ((UIElement)this.gridCropLines).Visibility     = Visibility.Visible;
         ((UIElement)this.gridCrop).Visibility          = Visibility.Visible;
         ((UIElement)this.stackPanelEffects).Visibility = Visibility.Collapsed;
         ((UIElement)this.stackPanelCrop).Visibility    = Visibility.Visible;
         this.UpdateImageAndEllipseSelectOpacity(0);
     }
 }
Пример #10
0
        public string GetAppropriateForScaleFactor(double requiredHeight, int reduceSizeForLowMemoryDeviceFactor = 1)
        {
            int    realScaleFactor = ScaleFactor.GetRealScaleFactor();
            double num1            = (double)this.width / (double)this.height;

            if (MemoryInfo.IsLowMemDevice && reduceSizeForLowMemoryDeviceFactor > 0)
            {
                requiredHeight /= (double)reduceSizeForLowMemoryDeviceFactor;
            }
            requiredHeight *= (double)realScaleFactor / 100.0;
            double val2 = requiredHeight * num1;
            double num2 = Math.Max(requiredHeight, val2);
            string str  = "";

            if (!string.IsNullOrEmpty(this.photo_75))
            {
                if (num2 <= 75.0)
                {
                    return(this.photo_75);
                }
                str = this.photo_75;
            }
            if (!string.IsNullOrEmpty(this.photo_130))
            {
                if (num2 <= 130.0)
                {
                    return(this.photo_130);
                }
                str = this.photo_130;
            }
            if (!string.IsNullOrEmpty(this.photo_604))
            {
                if (num2 <= 604.0)
                {
                    return(this.photo_604);
                }
                str = this.photo_604;
            }
            if (!string.IsNullOrEmpty(this.photo_807))
            {
                if (num2 <= 807.0)
                {
                    return(this.photo_807);
                }
                str = this.photo_807;
            }
            if (!string.IsNullOrEmpty(this.photo_1280))
            {
                if (num2 <= 1280.0)
                {
                    return(this.photo_1280);
                }
                str = this.photo_1280;
            }
            if (!string.IsNullOrEmpty(this.photo_2560))
            {
                if (num2 <= 2560.0)
                {
                    return(this.photo_2560);
                }
                str = this.photo_2560;
            }
            return(str);
        }
Пример #11
0
        public string GetAppropriateForScaleFactor(Size size)
        {
            int realScaleFactor = ScaleFactor.GetRealScaleFactor();
            // ISSUE: explicit reference operation
            double width = ((Size)@size).Width;
            // ISSUE: explicit reference operation
            double height = ((Size)@size).Height;
            double num1   = width * ((double)realScaleFactor / 100.0);
            double num2   = height * ((double)realScaleFactor / 100.0);
            double num3   = (double)this.width / (double)this.height;
            double val1   = num1 * num3;
            double val2   = num2 / num3;
            double num4   = num3 >= 1.0 ? (num3 <= 1.0 ? Math.Min(val1, val2) : (val2 > 0.0 ? val2 : val1)) : (val1 > 0.0 ? val1 : val2);

            if (num4 == 0.0)
            {
                return("");
            }
            string str = "";

            if (!string.IsNullOrEmpty(this.photo_75))
            {
                if (num4 <= 75.0)
                {
                    return(this.photo_75);
                }
                str = this.photo_75;
            }
            if (!string.IsNullOrEmpty(this.photo_130))
            {
                if (num4 <= 130.0)
                {
                    return(this.photo_130);
                }
                str = this.photo_130;
            }
            if (!string.IsNullOrEmpty(this.photo_604))
            {
                if (num4 <= 604.0)
                {
                    return(this.photo_604);
                }
                str = this.photo_604;
            }
            if (!string.IsNullOrEmpty(this.photo_807))
            {
                if (num4 <= 807.0)
                {
                    return(this.photo_807);
                }
                str = this.photo_807;
            }
            if (!string.IsNullOrEmpty(this.photo_1280))
            {
                if (num4 <= 1280.0)
                {
                    return(this.photo_1280);
                }
                str = this.photo_1280;
            }
            if (!string.IsNullOrEmpty(this.photo_2560))
            {
                if (num4 <= 2560.0)
                {
                    return(this.photo_2560);
                }
                str = this.photo_2560;
            }
            return(str);
        }
Пример #12
0
 public SpriteItem(SpriteDescription vertSpriteDesc, SpriteDescription horSpriteDesc, bool isHorizontal)
     : base(0.0)
 {
     this._vertSpriteDescription = vertSpriteDesc;
     this._horSpriteDescription  = horSpriteDesc;
     this._verticalWidth         = (double)vertSpriteDesc.WidthInPixels * 100.0 / (double)ScaleFactor.GetRealScaleFactor();
     this._horizontalWidth       = (double)horSpriteDesc.WidthInPixels * 100.0 / (double)ScaleFactor.GetRealScaleFactor();
     this._verticalHeight        = (double)vertSpriteDesc.HeightInPixels * 100.0 / (double)ScaleFactor.GetRealScaleFactor();
     this._horizontalHeight      = (double)horSpriteDesc.HeightInPixels * 100.0 / (double)ScaleFactor.GetRealScaleFactor();
     this._isHorizontal          = isHorizontal;
     this.Width = this._isHorizontal ? this._horizontalWidth : this._verticalWidth;
 }