All Projects → mrousavy → react-native-jsi-image

mrousavy / react-native-jsi-image

Licence: MIT license
🖼️ A writeable in-memory Image JSI Host Object

Programming Languages

C++
36643 projects - #6 most used programming language
Objective-C++
1391 projects
objective c
16641 projects - #2 most used programming language
typescript
32286 projects
java
68154 projects - #9 most used programming language
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to react-native-jsi-image

expo-doodle-jump
No description or website provided.
Stars: ✭ 44 (-82.04%)
Mutual labels:  native
NativeCompile
android 动态库远程依赖
Stars: ✭ 13 (-94.69%)
Mutual labels:  native
ult
The Ultimate Dev Stack
Stars: ✭ 54 (-77.96%)
Mutual labels:  native
nativescript-vue-examples
🍈 NativeScript and Vue code samples.
Stars: ✭ 13 (-94.69%)
Mutual labels:  native
hexen-dll-injector
HEX-EN DLL Injector
Stars: ✭ 20 (-91.84%)
Mutual labels:  native
blog
📓前端博客👏 ⭐⭐⭐鼓励一下👉
Stars: ✭ 41 (-83.27%)
Mutual labels:  native
janus-client
c/c++ webrtc native janus client Qt opengl video-meeting video-room video-call text-room meeting chat
Stars: ✭ 119 (-51.43%)
Mutual labels:  native
rust-flutter-reactive
This is a sample app to improve consistency over Mobile App Development.
Stars: ✭ 25 (-89.8%)
Mutual labels:  native
native-samples
Samples of modern build automation for native languages with Gradle
Stars: ✭ 140 (-42.86%)
Mutual labels:  native
ti.coremotion
Support for the native iOS CoreMotion framework in Appcelerator Titanium
Stars: ✭ 15 (-93.88%)
Mutual labels:  native
postsack
Visually cluster your emails by sender, domain, and more to identify waste
Stars: ✭ 288 (+17.55%)
Mutual labels:  native
status-bar-height
Listen to status bar changes during incoming calls and other multi-tasking events
Stars: ✭ 73 (-70.2%)
Mutual labels:  native
titanium-vue
Use Vue.js to easily create native mobile apps with Axway Appcelerator Titanium.
Stars: ✭ 45 (-81.63%)
Mutual labels:  native
Biometric-Authentication-Android
A sample implementation of AndroidX biometrics API using Kotlin. Authenticate using biometrics or PIN/Password if biometrics isn't available on device. Fully implemented in Jetpack compose using Material 3 dynamic theming and also has a separate implementation in xml with MDC 3.
Stars: ✭ 29 (-88.16%)
Mutual labels:  native
mixpanel-react-native
Official React Native Tracking Library for Mixpanel Analytics
Stars: ✭ 69 (-71.84%)
Mutual labels:  native
KaiUI
Useful native UI components for KaiOS
Stars: ✭ 29 (-88.16%)
Mutual labels:  native
av.imageview
Titanium native ImageView module that extends the default Titanium ImageView with more capabilities and a different caching system.
Stars: ✭ 97 (-60.41%)
Mutual labels:  native
Multiplatform-Log
Kotlin Multi Platform Logger, for android an ios : Logcat & print
Stars: ✭ 49 (-80%)
Mutual labels:  native
jspaint.exe
🌂JS Paint ~~ as a cross-platform native desktop app. In other words, the "🎨 Classic MS Paint, REVIVED + ✨Extras".exe hehe
Stars: ✭ 117 (-52.24%)
Mutual labels:  native
webgl-raub
WebGL bindings to desktop OpenGL
Stars: ✭ 66 (-73.06%)
Mutual labels:  native

🖼️ react-native-jsi-image

🏗️ This library is work in progress! 🏗️

A writeable in-memory Image JSI Host Object.

JSI-Image is a modern library that provides Image primitives for the native iOS and Android Platforms, neatly packaged together in one single fast JavaScript API.

There are 3 ways to create a JSI-Image instance:

  • Load from a file
  • Load from a Web-URL
  • Returned by another library, such as VisionCamera's takePhoto(...) function.

Why

Traditionally, Images in React Native could not be handled efficiently. To demonstrate this, let's take a look at how a Camera library might take a photo:

  1. [js] User taps capture button, takePhoto(...) is called.
  2. [native] Camera takes a photo. The library now has UIImage instance (photo) in-memory.
  3. [native] Library creates a new file on disk. (slow! 🐌)
  4. [native] Library writes the UIImage instance to the file. (slow! 🐌)
  5. [native] Library returns the path to the file to the caller (JS)
  6. [js] App now navigates to the "captured media" screen to display the media.
  7. [js] App passes the file path to a <FastImage> component.
  8. [native] <FastImage> component has to load the image from file. (slow! 🐌)
  9. [native] <FastImage> component then displays the UIImage from the file.

With JSI-Image, all the unnecessary slow file operations can be skipped, since the Image can be passed around in-memory.

  1. [js] User taps capture button, takePhoto(...) is called.
  2. [native] Camera takes a photo. The library now has UIImage instance (photo) in-memory.
  3. [native] Library returns the UIImage instance to the caller (JS) (fast! 🔥)
  4. [js] App now navigates to the "captured media" screen to display the media.
  5. [js] App passes the in-memory Image instance to a <FastImage> component.
  6. [native] <FastImage> component then displays the already in-memory UIImage instance. (fast! 🔥)

Benchmarks

Without JSI-Image

[log] Successfully took photo in 312ms!

With JSI-Image

[log] Successfully took photo in 95ms!

JSI-Image improved capture speed (takePhoto(...)) by more than 3x!

These improvements are even greater at more complicated image processing, such as rotating an image, applying image filters, resizing images, etc.

Installation

yarn add react-native-jsi-image
cd ios && pod install

Usage

Load from URL

import { loadImageFromUrl } from "react-native-jsi-image"

const image = await loadImageFromUrl('https://...')
console.log(`Successfully loaded ${image.width} x ${image.height} image!`)

Load from File

import { loadImageFromFile } from "react-native-jsi-image"

const image = await loadImageFromFile('file:///Users/Marc/image.png')
console.log(`Successfully loaded ${image.width} x ${image.height} image!`)

Inspect Image

const image = ...
const size = image.width * image.height
const realSize = size * image.scale
const orientation = image.orientation

for (const pixel of image.data) {
  console.log(`Pixel: ${pixel}`)
}

Rotate/Flip Image

const image = ...
console.log(image.isFlipped) // false
const flipped = image.flip()
console.log(flipped.isFlipped) // true

if (image.orientation === "up") {
  // rotates image in-memory
  image.orientation = "right"
}

Save modified Image to File

let image = ...
image = rotateImageCorrectly(image)
await image.save('file:///tmp/temp-image.png') // or .jpg

For Library Developers

To use JSI-Image in your native library, your functions must be JSI functions.

Accept Image Parameter

In your JSI Module:

#include <JsiImage/ImageHostObject.h>

// ...

jsi::Value myFunction(jsi::Runtime& runtime,
                      jsi::Value& thisArg,
                      jsi::Value* arguments,
                      size_t count) {
  auto imageHostObject = arguments[0].asObject(runtime).asHostObject<ImageHostObject>(runtime);
  auto uiImage = imageHostObject->image;
  // use uiImage here
}

In your TypeScript declaration:

import { Image } from 'react-native-jsi-image'

export function myFunction(image: Image): void

Return Image from your native module

In your JSI Module:

#include <JsiImage/ImageHostObject.h>

// ...

jsi::Value myFunction(jsi::Runtime& runtime,
                      jsi::Value& thisArg,
                      jsi::Value* arguments,
                      size_t count) {
  UIImage* image = // ...

  auto instance = std::make_shared<ImageHostObject>(image, promiseVendor);
  return jsi::Object::createFromHostObject(runtime, instance);
}

In your TypeScript declaration:

import { Image } from 'react-native-jsi-image'

export function myFunction(): Image

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].