-
Notifications
You must be signed in to change notification settings - Fork 23
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
feat: flip + rotation #25
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - this is a really interesting feature!
I know this is a draft PR, but I couldn't help and already leave a few thoughts on this, hope you don't mind 🙈
if (_rotatedBuffer == nullptr || _rotatedBuffer->getDirectSize() != argbSize) { | ||
_rotatedBuffer = allocateBuffer(argbSize, "_rotatedBuffer"); | ||
} | ||
|
||
FrameBuffer destination = { | ||
.width = rotatedWidth, | ||
.height = rotatedHeight, | ||
.pixelFormat = PixelFormat::ARGB, | ||
.dataType = DataType::UINT8, | ||
.buffer = _rotatedBuffer, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can avoid the copy and do this in-memory? The size is always the same, only width
height
and bytesPerRow
changes, no?
In vImage on iOS it can work in-memory. Might not be the case here for libyuv tho..
Also JFYI; I will only merge PRs that work the same on both iOS and Android, so we need iOS support here as well. I can work on that at some point, but right now I think I have other priorities (VisionCamera Android preview stretching) |
92d73e2
to
083914f
Compare
13093a9
to
690f60c
Compare
19d8e85
to
ab2f2bc
Compare
@@ -13,6 +13,7 @@ jsconfig.json | |||
# | |||
build/ | |||
*.pbxuser | |||
.xcode.env.local |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should not be sent to GitHub, as Xcode creates it at build time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but it might break builds if it gets generated and the user doesn't know about it. So I tend to leave it in gitignore, because then the user sees that this file was generated (in git status / GitHub desktop overview)
a77ff1e
to
ab460af
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heyo Rodrigo - this is amazing, thank you so much for this PR!
I have a few code nitpicks first to make sure this is as error-proof as possible, and as nice-to-use as possible :)
@@ -13,6 +13,7 @@ jsconfig.json | |||
# | |||
build/ | |||
*.pbxuser | |||
.xcode.env.local |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but it might break builds if it gets generated and the user doesn't know about it. So I tend to leave it in gitignore, because then the user sees that this file was generated (in git status / GitHub desktop overview)
@@ -150,12 +150,78 @@ FrameBuffer ResizePlugin::cropARGBBuffer(vision::FrameBuffer frameBuffer, int x, | |||
return destination; | |||
} | |||
|
|||
FrameBuffer ResizePlugin::flipARGBBuffer(FrameBuffer frameBuffer, bool flip) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename this entire thing (function and flip parameter) to "mirror" instead of "flip". Let's use the term mirror everywhere in the codebase.
@@ -277,8 +343,8 @@ FrameBuffer ResizePlugin::convertBufferToDataType(FrameBuffer frameBuffer, DataT | |||
} | |||
|
|||
jni::global_ref<jni::JByteBuffer> ResizePlugin::resize(jni::alias_ref<JImage> image, int cropX, int cropY, int cropWidth, int cropHeight, | |||
int scaleWidth, int scaleHeight, int /* PixelFormat */ pixelFormatOrdinal, | |||
int /* DataType */ dataTypeOrdinal) { | |||
int scaleWidth, int scaleHeight, int rotation, bool flip, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re my previous comment; rotation
should also be rotationOrdinal
- it should be an Enum in Kotlin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And rename flip
to mirror
again
android/src/main/java/com/visioncameraresizeplugin/ResizePlugin.kt
Outdated
Show resolved
Hide resolved
example/src/App.tsx
Outdated
|
||
export default function App() { | ||
const permission = useCameraPermission(); | ||
const device = useCameraDevice('back'); | ||
const device = useCameraDevice('front'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please revert
example/src/App.tsx
Outdated
@@ -35,6 +35,8 @@ export default function App() { | |||
}, | |||
pixelFormat: 'rgba', | |||
dataType: 'uint8', | |||
rotation: ROTATION.R90, | |||
flip: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flip -> mirror
package.json
Outdated
@@ -1,6 +1,6 @@ | |||
{ | |||
"name": "vision-camera-resize-plugin", | |||
"version": "2.0.1", | |||
"version": "2.1.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert
src/index.ts
Outdated
export enum ROTATION { | ||
R0 = 0, | ||
R90 = 90, | ||
R180 = 180, | ||
R270 = 270, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, no let's not use JS enums here. Check out how I built the pixelFormat
, this is a TS union instead of a JS enum. JS Enums just aren't that flexible.
I'm also not a big fan of the names here.
Let's try to do something like
rotate: '0deg' | '90deg' | '180deg' | '270deg'
Or
orientation: 'portrait' | 'landscape-right' | 'portrait-upside-down' | 'landscape-left'
where the latter defines the target orientation. As in, it makes sure to rotate the frame so it will later be in that exact orientation, no matter what input orientation it currently is in. Get what I mean?
Like if it currently is in portrait
, I want it to be in landscape-left
, it will rotate by however degrees it should to get to that orientation.
I think that makes more sense, no?
sorry i'm a bit confuse on what's your suggestion here, i'm my case the xcode build only finished successfully after i deleted this file |
Yea so this is a it weird - it seems like CocoaPods will generate this file, with an invalid path to node. Once you try to build the Xcode project after installing pods, it will fail. When the file is in .gitignore, the user (or developer; one of us) will never know why the build failed, it will be hard to pinpoint it to that specific file. If we instead leave this file in git, we will notice that this file was created because it will show up in 'ya know? It's kind of a weird problem but better to leave it in than silently fail |
3ed2cf6
to
39c8c85
Compare
the error (image bellow) is not a easy spot, and not descriptive at all i spent at least 40 min trying to figure out why my build was failing, would be nice if we can avoid this from happing with anyone else so i'm clarifying some things to make sure we are on the same page:
if you want to reproduce this replace the
|
39c8c85
to
42c2344
Compare
full disclosure: I don't want to be a nuisance here, I'm only insisting because I think what's happening isn't about you agreeing or disagreeing with the |
Yes I know that this file makes the build break - I tend to not put it into the gitignore so I can always see in my |
No description provided.