Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.
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
11 changes: 6 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.5.31"

ext.kotlin_version = "1.8.10"

repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.0.3'
classpath 'com.android.tools.build:gradle:7.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}

}

allprojects {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Mar 30 16:57:53 PDT 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
26 changes: 15 additions & 11 deletions renderscript-toolkit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ plugins {
}

android {
compileSdkVersion 31
buildToolsVersion "31.0.0"

compileSdk 34
ndkVersion "27.1.12297006"

defaultConfig {
minSdkVersion 16
targetSdkVersion 31
minSdk 16
targetSdk 34
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
externalNativeBuild {
cmake {
cppFlags "-std=c++17"
Expand All @@ -28,22 +26,28 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}

kotlinOptions {
jvmTarget = '1.8'
jvmTarget = '11'
}

externalNativeBuild {
cmake {
path file('src/main/cpp/CMakeLists.txt')
//version "3.22.1"
}
}

}

dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.core:core-ktx:1.9.0'

}
Empty file.
2 changes: 2 additions & 0 deletions renderscript-toolkit/src/main/cpp/RenderScriptToolkit.h
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,10 @@ class RenderScriptToolkit {
* The YUV formats supported by yuvToRgb.
*/
enum class YuvFormat {
NV12 = 0x10,
NV21 = 0x11,
YV12 = 0x32315659,
YV21 = 0x32315660,
};

/**
Expand Down
18 changes: 18 additions & 0 deletions renderscript-toolkit/src/main/cpp/YuvToRgb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ class YuvToRgbTask : public Task {
RenderScriptToolkit::YuvFormat format)
: Task{sizeX, sizeY, 4, false, nullptr}, mOut{reinterpret_cast<uchar4*>(output)} {
switch (format) {
case RenderScriptToolkit::YuvFormat::NV12:
mCstep = 2;
mStrideY = sizeX;
mStrideU = mStrideY;
mStrideV = mStrideY;
mInY = reinterpret_cast<const uchar*>(input);
mInU = reinterpret_cast<const uchar*>(input + mStrideY * sizeY);
mInV = mInU + 1;
break;
case RenderScriptToolkit::YuvFormat::NV21:
mCstep = 2;
mStrideY = sizeX;
Expand All @@ -66,6 +75,15 @@ class YuvToRgbTask : public Task {
mInU = reinterpret_cast<const uchar*>(input + mStrideY * sizeY);
mInV = mInU + mStrideV * sizeY / 2;
break;
case RenderScriptToolkit::YuvFormat::YV21:
mCstep = 1;
mStrideY = roundUpTo16(sizeX);
mStrideU = roundUpTo16(mStrideY >> 1u);
mStrideV = mStrideU;
mInY = reinterpret_cast<const uchar*>(input);
mInV = reinterpret_cast<const uchar*>(input + mStrideY * sizeY);
mInU = mInV + mStrideU * sizeY / 2;
break;
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,11 @@ object Toolkit {
/**
* Convert an image from YUV to RGB.
*
* YV12
* I420 = IYUV = YUV420p (sometimes YUV420p can refer to YV12)
* NV21
* NV12 = YUV420sp (sometimes YUV420sp can refer to NV21)
*
* Converts a YUV buffer to RGB. The input array should be supplied in a supported YUV format.
* The output is RGBA; the alpha channel will be set to 255.
*
Expand All @@ -1064,6 +1069,11 @@ object Toolkit {
/**
* Convert an image from YUV to an RGB Bitmap.
*
* YV12 = YUV420p, YUV420pp
* I420 = IYUV = YUV420p (sometimes YUV420p can refer to YV12)
* NV21
* NV12 = YUV420sp, YUV420psp
*
* Converts a YUV buffer to an RGB Bitmap. The input array should be supplied in a supported
* YUV format. The output is RGBA; the alpha channel will be set to 255.
*
Expand Down Expand Up @@ -1421,8 +1431,10 @@ class LookupTable {
* The YUV formats supported by yuvToRgb.
*/
enum class YuvFormat(val value: Int) {
NV12(0x10),
NV21(0x11),
YV12(0x32315659),
YV21(0x32315660),
}

/**
Expand Down Expand Up @@ -1498,7 +1510,7 @@ internal fun validateBitmap(
}

internal fun createCompatibleBitmap(inputBitmap: Bitmap) =
Bitmap.createBitmap(inputBitmap.width, inputBitmap.height, inputBitmap.config)
Bitmap.createBitmap(inputBitmap.width, inputBitmap.height, inputBitmap.config!!)

internal fun validateHistogramDotCoefficients(
coefficients: FloatArray?,
Expand Down
24 changes: 15 additions & 9 deletions test-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ plugins {
}

android {
compileSdkVersion 31
buildToolsVersion "31.0.0"

compileSdk 34

defaultConfig {
applicationId "com.google.android.renderscript_test"
minSdkVersion 21
targetSdkVersion 31
minSdk 21
targetSdk 34
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand All @@ -23,22 +22,29 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}

kotlinOptions {
jvmTarget = '1.8'
jvmTarget = '11'
}

}

dependencies {
implementation project(":renderscript-toolkit")

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'

implementation project(":renderscript-toolkit")

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

}
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ fun vectorSizeOfBitmap(bitmap: Bitmap): Int {
}

fun duplicateBitmap(original: Bitmap): Bitmap {
val copy = Bitmap.createBitmap(original.width, original.height, original.config)
val copy = Bitmap.createBitmap(original.width, original.height, original.config!!)
val canvas = Canvas(copy)
canvas.drawBitmap(original, 0f, 0f, null)
return copy
Expand Down