-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The main benefit of libyuv, apart from shortening the video pipeline, is quite noticeable latency and CPU usage decrease due to various assembler/SIMD optimizations of the library. However, there is a drawback for macOS systems: libyuv cannot be downloaded as a compiled library and can only be built from the source, which means we should include a cropped source code of the library (~10K LoC) into the app or rise the complexity of macOS dev and run toolchains. The main target system -- Linux, and Windows will use compiled lib from the package managers and macOS will use the lib included as a shortened source-code. Building the app with the no_libyuv tag will force it to use libyuv from the provided source files.
- Loading branch information
1 parent
072b674
commit b1b3371
Showing
73 changed files
with
12,010 additions
and
1,536 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package bgra | ||
|
||
import ( | ||
"image" | ||
"image/color" | ||
) | ||
|
||
type BGRA struct { | ||
image.RGBA | ||
} | ||
|
||
var BGRAModel = color.ModelFunc(func(c color.Color) color.Color { | ||
if _, ok := c.(BGRAColor); ok { | ||
return c | ||
} | ||
r, g, b, a := c.RGBA() | ||
return BGRAColor{uint8(r >> 8), uint8(g >> 8), uint8(b >> 8), uint8(a >> 8)} | ||
}) | ||
|
||
// BGRAColor represents a BGRA color. | ||
type BGRAColor struct { | ||
R, G, B, A uint8 | ||
} | ||
|
||
func (c BGRAColor) RGBA() (r, g, b, a uint32) { | ||
r = uint32(c.B) | ||
r |= r << 8 | ||
g = uint32(c.G) | ||
g |= g << 8 | ||
b = uint32(c.R) | ||
b |= b << 8 | ||
a = uint32(255) //uint32(c.A) | ||
a |= a << 8 | ||
return | ||
} | ||
|
||
func NewBGRA(r image.Rectangle) *BGRA { | ||
return &BGRA{*image.NewRGBA(r)} | ||
} | ||
|
||
func (p *BGRA) ColorModel() color.Model { return BGRAModel } | ||
func (p *BGRA) At(x, y int) color.Color { | ||
i := p.PixOffset(x, y) | ||
s := p.Pix[i : i+4 : i+4] | ||
return BGRAColor{s[0], s[1], s[2], s[3]} | ||
} | ||
|
||
func (p *BGRA) Set(x, y int, c color.Color) { | ||
i := p.PixOffset(x, y) | ||
c1 := BGRAModel.Convert(c).(BGRAColor) | ||
s := p.Pix[i : i+4 : i+4] | ||
s[0] = c1.R | ||
s[1] = c1.G | ||
s[2] = c1.B | ||
s[3] = 255 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package rgb565 | ||
|
||
import ( | ||
"encoding/binary" | ||
"image" | ||
"image/color" | ||
"math" | ||
) | ||
|
||
// RGB565 is an in-memory image whose At method returns RGB565 values. | ||
type RGB565 struct { | ||
// Pix holds the image's pixels, as RGB565 values in big-endian format. The pixel at | ||
// (x, y) starts at Pix[(y-p.Rect.Min.Y)*p.Stride + (x-p.Rect.Min.X)*2]. | ||
Pix []uint8 | ||
// Stride is the Pix stride (in bytes) between vertically adjacent pixels. | ||
Stride int | ||
// Rect is the image's bounds. | ||
Rect image.Rectangle | ||
} | ||
|
||
// Model is the model for RGB565 colors. | ||
var Model = color.ModelFunc(func(c color.Color) color.Color { | ||
//if _, ok := c.(Color); ok { | ||
// return c | ||
//} | ||
r, g, b, _ := c.RGBA() | ||
return Color(uint16((r<<8)&rMask | (g<<3)&gMask | (b>>3)&bMask)) | ||
}) | ||
|
||
const ( | ||
rMask = 0b1111100000000000 | ||
gMask = 0b0000011111100000 | ||
bMask = 0b0000000000011111 | ||
) | ||
|
||
// Color represents an RGB565 color. | ||
type Color uint16 | ||
|
||
func (c Color) RGBA() (r, g, b, a uint32) { | ||
return uint32(math.Round(float64(c&rMask>>11)*255.0/31.0)) << 8, | ||
uint32(math.Round(float64(c&gMask>>5)*255.0/63.0)) << 8, | ||
uint32(math.Round(float64(c&bMask)*255.0/31.0)) << 8, | ||
0xffff | ||
} | ||
|
||
func NewRGB565(r image.Rectangle) *RGB565 { | ||
return &RGB565{Pix: make([]uint8, r.Dx()*r.Dy()<<1), Stride: r.Dx() << 1, Rect: r} | ||
} | ||
|
||
func (p *RGB565) Bounds() image.Rectangle { return p.Rect } | ||
func (p *RGB565) ColorModel() color.Model { return Model } | ||
func (p *RGB565) PixOffset(x, y int) int { return (x-p.Rect.Min.X)<<1 + (y-p.Rect.Min.Y)*p.Stride } | ||
|
||
func (p *RGB565) At(x, y int) color.Color { | ||
i := p.PixOffset(x, y) | ||
return Color(binary.LittleEndian.Uint16(p.Pix[i : i+2])) | ||
} | ||
|
||
func (p *RGB565) Set(x, y int, c color.Color) { | ||
i := p.PixOffset(x, y) | ||
binary.LittleEndian.PutUint16(p.Pix[i:i+2], uint16(Model.Convert(c).(Color))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package rgba | ||
|
||
import ( | ||
"image" | ||
"image/color" | ||
) | ||
|
||
func ToRGBA(img image.Image, flipped bool) *image.RGBA { | ||
bounds := img.Bounds() | ||
sw, sh := bounds.Dx(), bounds.Dy() | ||
dst := image.NewRGBA(image.Rect(0, 0, sw, sh)) | ||
for y := 0; y < sh; y++ { | ||
yy := y | ||
if flipped { | ||
yy = sh - y | ||
} | ||
for x := 0; x < sw; x++ { | ||
px := img.At(x, y) | ||
rgba := color.RGBAModel.Convert(px).(color.RGBA) | ||
dst.Set(x, yy, rgba) | ||
} | ||
} | ||
return dst | ||
} |
Oops, something went wrong.