diff --git a/build.gradle b/build.gradle index 4cfb714..dc62b48 100644 --- a/build.gradle +++ b/build.gradle @@ -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 { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 6154b02..556a77c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/renderscript-toolkit/build.gradle b/renderscript-toolkit/build.gradle index 7d62b0e..9c9bcc5 100644 --- a/renderscript-toolkit/build.gradle +++ b/renderscript-toolkit/build.gradle @@ -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" @@ -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' + } diff --git a/renderscript-toolkit/consumer-rules.pro b/renderscript-toolkit/consumer-rules.pro deleted file mode 100644 index e69de29..0000000 diff --git a/renderscript-toolkit/src/main/cpp/RenderScriptToolkit.h b/renderscript-toolkit/src/main/cpp/RenderScriptToolkit.h index 5315a93..fe0b80c 100644 --- a/renderscript-toolkit/src/main/cpp/RenderScriptToolkit.h +++ b/renderscript-toolkit/src/main/cpp/RenderScriptToolkit.h @@ -508,8 +508,10 @@ class RenderScriptToolkit { * The YUV formats supported by yuvToRgb. */ enum class YuvFormat { + NV12 = 0x10, NV21 = 0x11, YV12 = 0x32315659, + YV21 = 0x32315660, }; /** diff --git a/renderscript-toolkit/src/main/cpp/YuvToRgb.cpp b/renderscript-toolkit/src/main/cpp/YuvToRgb.cpp index 741bcc4..efbab4d 100644 --- a/renderscript-toolkit/src/main/cpp/YuvToRgb.cpp +++ b/renderscript-toolkit/src/main/cpp/YuvToRgb.cpp @@ -48,6 +48,15 @@ class YuvToRgbTask : public Task { RenderScriptToolkit::YuvFormat format) : Task{sizeX, sizeY, 4, false, nullptr}, mOut{reinterpret_cast(output)} { switch (format) { + case RenderScriptToolkit::YuvFormat::NV12: + mCstep = 2; + mStrideY = sizeX; + mStrideU = mStrideY; + mStrideV = mStrideY; + mInY = reinterpret_cast(input); + mInU = reinterpret_cast(input + mStrideY * sizeY); + mInV = mInU + 1; + break; case RenderScriptToolkit::YuvFormat::NV21: mCstep = 2; mStrideY = sizeX; @@ -66,6 +75,15 @@ class YuvToRgbTask : public Task { mInU = reinterpret_cast(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(input); + mInV = reinterpret_cast(input + mStrideY * sizeY); + mInU = mInV + mStrideU * sizeY / 2; + break; } } }; diff --git a/renderscript-toolkit/src/main/java/com/google/android/renderscript/Toolkit.kt b/renderscript-toolkit/src/main/java/com/google/android/renderscript/Toolkit.kt index 8d761cb..fb12c29 100644 --- a/renderscript-toolkit/src/main/java/com/google/android/renderscript/Toolkit.kt +++ b/renderscript-toolkit/src/main/java/com/google/android/renderscript/Toolkit.kt @@ -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. * @@ -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. * @@ -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), } /** @@ -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?, diff --git a/test-app/build.gradle b/test-app/build.gradle index c7de909..572e4f4 100644 --- a/test-app/build.gradle +++ b/test-app/build.gradle @@ -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" } @@ -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' + } diff --git a/test-app/src/main/java/com/google/android/renderscript_test/BufferUtils.kt b/test-app/src/main/java/com/google/android/renderscript_test/BufferUtils.kt index 51ece8e..c750677 100644 --- a/test-app/src/main/java/com/google/android/renderscript_test/BufferUtils.kt +++ b/test-app/src/main/java/com/google/android/renderscript_test/BufferUtils.kt @@ -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