Skip to content

Commit

Permalink
Unexported NewFrameData and FrameDataFrame
Browse files Browse the repository at this point in the history
  • Loading branch information
asticode committed Jan 26, 2024
1 parent cc9ebd8 commit 89578fa
Show file tree
Hide file tree
Showing 5 changed files with 337 additions and 326 deletions.
2 changes: 1 addition & 1 deletion frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (f *Frame) SetColorRange(r ColorRange) {
}

func (f *Frame) Data() *FrameData {
return NewFrameData(newFrameDataFrame(f))
return newFrameData(newFrameDataFrame(f))
}

func (f *Frame) Height() int {
Expand Down
94 changes: 47 additions & 47 deletions frame_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import (
"strings"
)

type FrameDataFrame interface {
type FrameData struct {
f frameDataFramer
}

type frameDataFramer interface {
Height() int
ImageBufferSize(align int) (int, error)
ImageCopyToBuffer(b []byte, align int) (int, error)
Expand All @@ -19,52 +23,7 @@ type FrameDataFrame interface {
Width() int
}

var _ FrameDataFrame = (*frameDataFrame)(nil)

type frameDataFrame struct {
f *Frame
}

func newFrameDataFrame(f *Frame) *frameDataFrame {
return &frameDataFrame{f: f}
}

func (f *frameDataFrame) Height() int {
return f.f.Height()
}

func (f *frameDataFrame) ImageBufferSize(align int) (int, error) {
return f.f.ImageBufferSize(align)
}

func (f *frameDataFrame) ImageCopyToBuffer(b []byte, align int) (int, error) {
return f.f.ImageCopyToBuffer(b, align)
}

func (f *frameDataFrame) Linesize(i int) int {
return f.f.Linesize()[i]
}

func (f *frameDataFrame) PixelFormat() PixelFormat {
return f.f.PixelFormat()
}

func (f *frameDataFrame) PlaneBytes(i int) []byte {
return bytesFromC(func(size *cUlong) *C.uint8_t {
*size = cUlong(int(f.f.c.linesize[i]) * f.f.Height())
return f.f.c.data[i]
})
}

func (f *frameDataFrame) Width() int {
return f.f.Width()
}

type FrameData struct {
f FrameDataFrame
}

func NewFrameData(f FrameDataFrame) *FrameData {
func newFrameData(f frameDataFramer) *FrameData {
return &FrameData{f: f}
}

Expand Down Expand Up @@ -213,3 +172,44 @@ func (d *FrameData) ToImage(dst image.Image) error {
}
return nil
}

var _ frameDataFramer = (*frameDataFrame)(nil)

type frameDataFrame struct {
f *Frame
}

func newFrameDataFrame(f *Frame) *frameDataFrame {
return &frameDataFrame{f: f}
}

func (f *frameDataFrame) Height() int {
return f.f.Height()
}

func (f *frameDataFrame) ImageBufferSize(align int) (int, error) {
return f.f.ImageBufferSize(align)
}

func (f *frameDataFrame) ImageCopyToBuffer(b []byte, align int) (int, error) {
return f.f.ImageCopyToBuffer(b, align)
}

func (f *frameDataFrame) Linesize(i int) int {
return f.f.Linesize()[i]
}

func (f *frameDataFrame) PixelFormat() PixelFormat {
return f.f.PixelFormat()
}

func (f *frameDataFrame) PlaneBytes(i int) []byte {
return bytesFromC(func(size *cUlong) *C.uint8_t {
*size = cUlong(int(f.f.c.linesize[i]) * f.f.Height())
return f.f.c.data[i]
})
}

func (f *frameDataFrame) Width() int {
return f.f.Width()
}
Loading

0 comments on commit 89578fa

Please sign in to comment.