| 1 | // Package v4l, a facade to the Video4Linux video capture interface |
| 2 | // Copyright (C) 2016 Zoltán Korándi <[email protected]> |
| 3 | // |
| 4 | // This program is free software: you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // |
| 9 | // This program is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | |
| 17 | //go:build linux |
| 18 | // +build linux |
| 19 | |
| 20 | package v4lscip-go gomod github.com/korandiz/v4l . `github.com/korandiz/v4l`/ |
| 21 | |
| 22 | // A Frac represents the fractional number N/D. |
| 23 | type Fracscip-go gomod github.com/korandiz/v4l . `github.com/korandiz/v4l`/Frac# struct { |
| 24 | Nscip-go gomod github.com/korandiz/v4l . `github.com/korandiz/v4l`/Frac#N. uint32 |
| 25 | Dscip-go gomod github.com/korandiz/v4l . `github.com/korandiz/v4l`/Frac#D. uint32 |
| 26 | } |
| 27 | |
| 28 | // Cmp returns -1, 0, or 1 if f is less then, equal to, or greater than g, |
| 29 | // respectively. |
| 30 | func (f Fracscip-go gomod github.com/korandiz/v4l . `github.com/korandiz/v4l`/Frac#) Cmpscip-go gomod github.com/korandiz/v4l . `github.com/korandiz/v4l`/Frac#Cmp().(g Fracscip-go gomod github.com/korandiz/v4l . `github.com/korandiz/v4l`/Frac#) int { |
| 31 | F := uint64(f.Nscip-go gomod github.com/korandiz/v4l . `github.com/korandiz/v4l`/Frac#N.) * uint64(g.Dscip-go gomod github.com/korandiz/v4l . `github.com/korandiz/v4l`/Frac#D.) |
| 32 | G := uint64(g.Nscip-go gomod github.com/korandiz/v4l . `github.com/korandiz/v4l`/Frac#N.) * uint64(f.Dscip-go gomod github.com/korandiz/v4l . `github.com/korandiz/v4l`/Frac#D.) |
| 33 | switch { |
| 34 | case F < G: |
| 35 | return -1 |
| 36 | case F > G: |
| 37 | return 1 |
| 38 | default: |
| 39 | return 0 |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | // Reduce returns f reduced to lowest terms. |
| 44 | func (f Fracscip-go gomod github.com/korandiz/v4l . `github.com/korandiz/v4l`/Frac#) Reducescip-go gomod github.com/korandiz/v4l . `github.com/korandiz/v4l`/Frac#Reduce().() Fracscip-go gomod github.com/korandiz/v4l . `github.com/korandiz/v4l`/Frac# { |
| 45 | gcd, r := f.Nscip-go gomod github.com/korandiz/v4l . `github.com/korandiz/v4l`/Frac#N., f.Dscip-go gomod github.com/korandiz/v4l . `github.com/korandiz/v4l`/Frac#D. |
| 46 | for r != 0 { |
| 47 | gcd, r = r, gcd%r |
| 48 | } |
| 49 | if gcd == 0 { |
| 50 | gcd = 1 |
| 51 | } |
| 52 | return Fracscip-go gomod github.com/korandiz/v4l . `github.com/korandiz/v4l`/Frac#{f.Nscip-go gomod github.com/korandiz/v4l . `github.com/korandiz/v4l`/Frac#N. / gcd, f.Dscip-go gomod github.com/korandiz/v4l . `github.com/korandiz/v4l`/Frac#D. / gcd} |
| 53 | } |