Skip to content

Instantly share code, notes, and snippets.

View LiewJunTung's full-sized avatar

Liew Jun Tung LiewJunTung

View GitHub Profile
package com.liewjuntung.cameraxfacetracking
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.os.Bundle
import android.os.Handler
import android.os.HandlerThread
import android.renderscript.RenderScript
import android.util.Rational
import android.util.Size
fun rotateBitmap(context: Context, bitmap: Bitmap): Bitmap{
val rs = RenderScript.create(context)
val allocation = Allocation.createFromBitmap(rs, bitmap)
val rotated = Allocation.createTyped(rs, Type.createXY(rs, Element.RGBA_8888(rs), bitmap.height, bitmap.width))
ScriptC_rotator(rs).apply {
_inImage = allocation
_inHeight = bitmap.height
_inWidth = bitmap.width
forEach_rotate_270_clockwise(rotated, rotated)
@LiewJunTung
LiewJunTung / RgbConversion.kt
Created July 13, 2019 18:21
Best solution YUV -> RGB
class RgbConversion(val rs: RenderScript, private val feedSize: Size, private val hasRotate: Boolean = true) {
private var mInputAllocation: Allocation? = null
private var mOutputAllocation: Allocation? = null
private var mRotatedAllocation: Allocation? = null
private val yuvToRgb = ScriptIntrinsicYuvToRGB.create(rs, Element.U8_4(rs))
private val rotator = ScriptC_rotator(rs)
var bufferCallback: ((ByteBuffer) -> Unit)? = null
val inputSurface: Surface
get() = mInputAllocation!!.surface
abstract class SymbolicLinkTask : DefaultTask() {
var actualFilePath: String? = null
var symbolicDirPath: String? = null
var rename: String? = null
@TaskAction
fun link() {
val aPath = actualFilePath ?: throw Exception("actualPath not set")
val sPath = symbolicDirPath ?: throw Exception("symbolicPath not set")
@LiewJunTung
LiewJunTung / build.gradle.kts
Created July 29, 2019 16:24
Gradle plugin tutorial
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.3.41"
`java-gradle-plugin`
id("com.gradle.plugin-publish") version "0.10.0"
}
pluginBundle {
website = "<substitute your project website>"
package com.netvirta.ci_image_resize_plugin
import javax.imageio.ImageIO
import java.awt.image.BufferedImage;
import java.io.File
import javax.imageio.stream.ImageInputStream
class CiImageResize {
fun resize(inputJpgFilePath: String, outputJpgFilePath: String, outputWidth: Int, outputHeight: Int) {
extension NumberParsing on String {
int parseInt() {
return int.parse(this);
}
double parseDouble() {
return double.parse(this);
}
}
import 'dart:async';
Future<String> networkCallGetString() async {
await Future.delayed(Duration(seconds: 5));
return "Simulated Network Call";
}
doNetworkCall() async {
var result = networkCallGetString();
print(result);
class Dog {
String name;
int age;
Dog(this.name, this.age);
}
class Cat {
String name;
int age;