Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PictureInPicture function #68

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,13 @@ pass the `orientation` value given by the image's `ImageHeader`, then the
resulting image has its orientation normalized to the
default orientation.


```go
func (f *lilliput.Framebuffer) PictureInPicture(src *Framebuffer, x, y int)
```
Allows you to place `src` into the frame buffer which you are calling this from.
You can use `x` and `y` to set the co-ordinates where `src` will be placed.

```go
func (f *lilliput.Framebuffer) ResizeTo(width, height int, dst *lilliput.Framebuffer) error
```
Expand Down
7 changes: 7 additions & 0 deletions opencv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ void opencv_mat_resize(const opencv_mat src, opencv_mat dst, int width, int heig
cv::resize(*static_cast<const cv::Mat *>(src), *static_cast<cv::Mat *>(dst), cv::Size(width, height), 0, 0, interpolation);
}

void opencv_mat_picture_in_picture(const opencv_mat src, opencv_mat dst, int x, int y) {
auto dstMat = *static_cast<cv::Mat *>(dst);
auto srcMatPtr = static_cast<cv::Mat *>(src);
cv::Mat Region = dstMat(CvRect(x, y, srcMatPtr->cols, srcMatPtr->rows));
srcMatPtr->copyTo(Region);
}

opencv_mat opencv_mat_crop(const opencv_mat src, int x, int y, int width, int height) {
auto ret = new cv::Mat;
*ret = (*static_cast<const cv::Mat *>(src))(cv::Rect(x, y, width, height));
Expand Down
14 changes: 14 additions & 0 deletions opencv.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,20 @@ func (f *Framebuffer) ResizeTo(width, height int, dst *Framebuffer) error {
return nil
}

// PictureInPicture allows you to take the src and place it inside this buffer (the destination).
// The x/y arguments allow you to set the co-ordinates where this will be placed.
func (f *Framebuffer) PictureInPicture(src *Framebuffer, x, y int) {
if x < 1 {
x = 1
}

if y < 1 {
y = 1
}

C.opencv_mat_picture_in_picture(src.mat, f.mat, C.int(x), C.int(y))
}

// Fit performs a resizing and cropping transform on the Framebuffer and puts the result
// in the provided destination Framebuffer. This function does preserve aspect ratio
// but will crop columns or rows from the edges of the image as necessary in order to
Expand Down
1 change: 1 addition & 0 deletions opencv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ void opencv_mat_orientation_transform(CVImageOrientation orientation, opencv_mat
int opencv_mat_get_width(const opencv_mat mat);
int opencv_mat_get_height(const opencv_mat mat);
void *opencv_mat_get_data(const opencv_mat mat);
void opencv_mat_picture_in_picture(const opencv_mat src, opencv_mat dst, int x, int y);

opencv_encoder opencv_encoder_create(const char *ext, opencv_mat dst);
void opencv_encoder_release(opencv_encoder e);
Expand Down