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
<html> | |
<head> | |
<title>Html-Qrcode Demo</title> | |
<body> | |
<div id="qr-reader" style="width:500px"></div> | |
<div id="qr-reader-results"></div> | |
</body> | |
<script src="https://raw.githubusercontent.com/mebjas/html5-qrcode/master/minified/html5-qrcode.min.js"></script> | |
<script src="html5-qrcode-demo.js"></script> | |
</head> |
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
class YuvConvertor { | |
private final Allocation in, out; | |
private final ScriptIntrinsicYuvToRGB script; | |
static { | |
System.loadLibrary("yuv2rgb-lib"); | |
} | |
public YuvConvertor(Context context, int width, int height) { | |
RenderScript rs = RenderScript.create(context); |
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
static Bitmap yuv420ToBitmap(Image image, Context context) { | |
RenderScript rs = RenderScript.create(context); | |
ScriptIntrinsicYuvToRGB script = ScriptIntrinsicYuvToRGB.create( | |
rs, Element.U8_4(rs)); | |
// Refer the logic in a section below on how to convert a YUV_420_888 image | |
// to single channel flat 1D array. For sake of this example I'll abstract it | |
// as a method. | |
byte[] yuvByteArray = yuv420ToByteArray(image); |
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
struct RGBA_8888 { | |
uint8_t r; | |
uint8_t g; | |
uint8_t b; | |
uint8_t a = 255; | |
}; | |
RGBA_8888 yuv2rgb(uint8_t y, uint8_t u, uint8_t v) { | |
int r = y + (1.370705 * (v - 128)); | |
int g = y - (0.698001 * (v - 128)) - (0.337633 * (u - 128));; |
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
// Read the image | |
std::unique_ptr<Image> image = nullptr; | |
{ | |
std::string image_buffer; | |
image_buffer.resize(fd_length); | |
int remaining_length = read(fd, &image_buffer[0], length); | |
if (remaining_length != 0) { | |
return env->NewStringUTF("Failed to read full image"); | |
} |
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
class ImageFactory { | |
public: | |
// Decodes the `image_buffer` and returns Image instance. | |
// | |
// Suggestion for readers: Use absl::string_view instead of string here. | |
static std::unique_ptr<Image> FromString(const std::string& image_buffer); | |
// Creates an instance of 'Image' from the file descriptor 'fd'. | |
// |
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
#include "image.h" | |
#include <android/imagedecoder.h> | |
static std::unique_ptr<Image> ImageFactory::FromFd(int fd) { | |
// First create decoder from fd. | |
AImageDecoder* decoder; | |
int result = AImageDecoder_createFromFd(fd, &decoder); | |
if (result != ANDROID_IMAGE_DECODER_SUCCESS) { | |
// More info: https://developer.android.com/ndk/reference/group/image-decoder#aimagedecoder_createfromfd |
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
#include <memory> | |
#include <assert.h> | |
#include <android/imagedecoder.h> | |
// Data class for ARGB image (owns the memory associated with the image). | |
// | |
// Note for readers: Current implementation only allows read operations but can | |
// be extended to support write operations by overloading `()=` operator. | |
class Image { |
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
#include <jni.h> | |
// Corresponding to NativeImageLoader class in | |
// dev.minhazav.samples package. | |
extern "C" JNIEXPORT jstring JNICALL | |
Java_dev_minhazav_samples_NativeImageLoader_readFile( | |
JNIEnv* env, jclass, jint fd) { | |
if (fd < 0) { | |
return env->NewStringUTF("Invalid fd"); | |
} |
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
/** Wrapper class for loading image in native layer. */ | |
public final class NativeImageLoader { | |
static { | |
System.loadLibrary("image-loader-jni"); | |
} | |
/** Reads the image represented by {@code fd} in native layer. | |
* | |
* <p>For apparently no reason! |
NewerOlder