1 /*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <android/bitmap.h>
18 #include <assert.h>
19 #include <jni.h>
20
21 #include "RenderScriptToolkit.h"
22 #include "Utils.h"
23
24 #define LOG_TAG "renderscript.toolkit.JniEntryPoints"
25
26 using namespace android::renderscript;
27
28 /**
29 * I compared using env->GetPrimitiveArrayCritical vs. env->GetByteArrayElements to get access
30 * to the underlying data. On Pixel 4, it's actually faster to not use critical. The code is left
31 * here if you want to experiment. Note that USE_CRITICAL could block the garbage collector.
32 */
33 // #define USE_CRITICAL
34
35 class ByteArrayGuard {
36 private:
37 JNIEnv* env;
38 jbyteArray array;
39 jbyte* data;
40
41 public:
ByteArrayGuard(JNIEnv * env,jbyteArray array)42 ByteArrayGuard(JNIEnv* env, jbyteArray array) : env{env}, array{array} {
43 #ifdef USE_CRITICAL
44 data = reinterpret_cast<jbyte*>(env->GetPrimitiveArrayCritical(array, nullptr));
45 #else
46 data = env->GetByteArrayElements(array, nullptr);
47 #endif
48 }
~ByteArrayGuard()49 ~ByteArrayGuard() {
50 #ifdef USE_CRITICAL
51 env->ReleasePrimitiveArrayCritical(array, data, 0);
52 #else
53 env->ReleaseByteArrayElements(array, data, 0);
54 #endif
55 }
get()56 uint8_t* get() { return reinterpret_cast<uint8_t*>(data); }
57 };
58
59 class IntArrayGuard {
60 private:
61 JNIEnv* env;
62 jintArray array;
63 jint* data;
64
65 public:
IntArrayGuard(JNIEnv * env,jintArray array)66 IntArrayGuard(JNIEnv* env, jintArray array) : env{env}, array{array} {
67 #ifdef USE_CRITICAL
68 data = reinterpret_cast<jint*>(env->GetPrimitiveArrayCritical(array, nullptr));
69 #else
70 data = env->GetIntArrayElements(array, nullptr);
71 #endif
72 }
~IntArrayGuard()73 ~IntArrayGuard() {
74 #ifdef USE_CRITICAL
75 env->ReleasePrimitiveArrayCritical(array, data, 0);
76 #else
77 env->ReleaseIntArrayElements(array, data, 0);
78 #endif
79 }
get()80 int* get() { return reinterpret_cast<int*>(data); }
81 };
82
83 class FloatArrayGuard {
84 private:
85 JNIEnv* env;
86 jfloatArray array;
87 jfloat* data;
88
89 public:
FloatArrayGuard(JNIEnv * env,jfloatArray array)90 FloatArrayGuard(JNIEnv* env, jfloatArray array) : env{env}, array{array} {
91 #ifdef USE_CRITICAL
92 data = reinterpret_cast<jfloat*>(env->GetPrimitiveArrayCritical(array, nullptr));
93 #else
94 data = env->GetFloatArrayElements(array, nullptr);
95 #endif
96 }
~FloatArrayGuard()97 ~FloatArrayGuard() {
98 #ifdef USE_CRITICAL
99 env->ReleasePrimitiveArrayCritical(array, data, 0);
100 #else
101 env->ReleaseFloatArrayElements(array, data, 0);
102 #endif
103 }
get()104 float* get() { return reinterpret_cast<float*>(data); }
105 };
106
107 class BitmapGuard {
108 private:
109 JNIEnv* env;
110 jobject bitmap;
111 AndroidBitmapInfo info;
112 int bytesPerPixel;
113 void* bytes;
114 bool valid;
115
116 public:
BitmapGuard(JNIEnv * env,jobject jBitmap)117 BitmapGuard(JNIEnv* env, jobject jBitmap) : env{env}, bitmap{jBitmap}, bytes{nullptr} {
118 valid = false;
119 if (AndroidBitmap_getInfo(env, bitmap, &info) != ANDROID_BITMAP_RESULT_SUCCESS) {
120 ALOGE("AndroidBitmap_getInfo failed");
121 return;
122 }
123 if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888 &&
124 info.format != ANDROID_BITMAP_FORMAT_A_8) {
125 ALOGE("AndroidBitmap in the wrong format");
126 return;
127 }
128 bytesPerPixel = info.stride / info.width;
129 if (bytesPerPixel != 1 && bytesPerPixel != 4) {
130 ALOGE("Expected a vector size of 1 or 4. Got %d. Extra padding per line not currently "
131 "supported",
132 bytesPerPixel);
133 return;
134 }
135 if (AndroidBitmap_lockPixels(env, bitmap, &bytes) != ANDROID_BITMAP_RESULT_SUCCESS) {
136 ALOGE("AndroidBitmap_lockPixels failed");
137 return;
138 }
139 valid = true;
140 }
~BitmapGuard()141 ~BitmapGuard() {
142 if (valid) {
143 AndroidBitmap_unlockPixels(env, bitmap);
144 }
145 }
get() const146 uint8_t* get() const {
147 assert(valid);
148 return reinterpret_cast<uint8_t*>(bytes);
149 }
width() const150 int width() const { return info.width; }
height() const151 int height() const { return info.height; }
vectorSize() const152 int vectorSize() const { return bytesPerPixel; }
153 };
154
155 /**
156 * Copies the content of Kotlin Range2d object into the equivalent C++ struct.
157 */
158 class RestrictionParameter {
159 private:
160 bool isNull;
161 Restriction restriction;
162
163 public:
RestrictionParameter(JNIEnv * env,jobject jRestriction)164 RestrictionParameter(JNIEnv* env, jobject jRestriction) : isNull{jRestriction == nullptr} {
165 if (isNull) {
166 return;
167 }
168 /* TODO Measure how long FindClass and related functions take. Consider passing the
169 * four values instead. This would also require setting the default when Range2D is null.
170 */
171 jclass restrictionClass = env->FindClass("android/renderscript/toolkit/Range2d");
172 if (restrictionClass == nullptr) {
173 ALOGE("RenderScriptToolit. Internal error. Could not find the Kotlin Range2d class.");
174 isNull = true;
175 return;
176 }
177 jfieldID startXId = env->GetFieldID(restrictionClass, "startX", "I");
178 jfieldID startYId = env->GetFieldID(restrictionClass, "startY", "I");
179 jfieldID endXId = env->GetFieldID(restrictionClass, "endX", "I");
180 jfieldID endYId = env->GetFieldID(restrictionClass, "endY", "I");
181 restriction.startX = env->GetIntField(jRestriction, startXId);
182 restriction.startY = env->GetIntField(jRestriction, startYId);
183 restriction.endX = env->GetIntField(jRestriction, endXId);
184 restriction.endY = env->GetIntField(jRestriction, endYId);
185 }
get()186 Restriction* get() { return isNull ? nullptr : &restriction; }
187 };
188
189 extern "C" JNIEXPORT jlong JNICALL
Java_android_renderscript_toolkit_Toolkit_createNative(JNIEnv *,jobject)190 Java_android_renderscript_toolkit_Toolkit_createNative(JNIEnv* /*env*/, jobject /*thiz*/) {
191 return reinterpret_cast<jlong>(new RenderScriptToolkit());
192 }
193
Java_android_renderscript_toolkit_Toolkit_destroyNative(JNIEnv *,jobject,jlong native_handle)194 extern "C" JNIEXPORT void JNICALL Java_android_renderscript_toolkit_Toolkit_destroyNative(
195 JNIEnv* /*env*/, jobject /*thiz*/, jlong native_handle) {
196 RenderScriptToolkit* toolkit = reinterpret_cast<RenderScriptToolkit*>(native_handle);
197 delete toolkit;
198 }
199
Java_android_renderscript_toolkit_Toolkit_nativeBlend(JNIEnv * env,jobject,jlong native_handle,jint jmode,jbyteArray source_array,jbyteArray dest_array,jint size_x,jint size_y,jobject restriction)200 extern "C" JNIEXPORT void JNICALL Java_android_renderscript_toolkit_Toolkit_nativeBlend(
201 JNIEnv* env, jobject /*thiz*/, jlong native_handle, jint jmode, jbyteArray source_array,
202 jbyteArray dest_array, jint size_x, jint size_y, jobject restriction) {
203 auto toolkit = reinterpret_cast<RenderScriptToolkit*>(native_handle);
204 auto mode = static_cast<RenderScriptToolkit::BlendingMode>(jmode);
205 RestrictionParameter restrict {env, restriction};
206 ByteArrayGuard source{env, source_array};
207 ByteArrayGuard dest{env, dest_array};
208
209 toolkit->blend(mode, source.get(), dest.get(), size_x, size_y, restrict.get());
210 }
211
Java_android_renderscript_toolkit_Toolkit_nativeBlendBitmap(JNIEnv * env,jobject,jlong native_handle,jint jmode,jobject source_bitmap,jobject dest_bitmap,jobject restriction)212 extern "C" JNIEXPORT void JNICALL Java_android_renderscript_toolkit_Toolkit_nativeBlendBitmap(
213 JNIEnv* env, jobject /*thiz*/, jlong native_handle, jint jmode, jobject source_bitmap,
214 jobject dest_bitmap, jobject restriction) {
215 auto toolkit = reinterpret_cast<RenderScriptToolkit*>(native_handle);
216 auto mode = static_cast<RenderScriptToolkit::BlendingMode>(jmode);
217 RestrictionParameter restrict {env, restriction};
218 BitmapGuard source{env, source_bitmap};
219 BitmapGuard dest{env, dest_bitmap};
220
221 toolkit->blend(mode, source.get(), dest.get(), source.width(), source.height(), restrict.get());
222 }
223
Java_android_renderscript_toolkit_Toolkit_nativeBlur(JNIEnv * env,jobject,jlong native_handle,jbyteArray input_array,jint vectorSize,jint size_x,jint size_y,jint radius,jbyteArray output_array,jobject restriction)224 extern "C" JNIEXPORT void JNICALL Java_android_renderscript_toolkit_Toolkit_nativeBlur(
225 JNIEnv* env, jobject /*thiz*/, jlong native_handle, jbyteArray input_array, jint vectorSize,
226 jint size_x, jint size_y, jint radius, jbyteArray output_array, jobject restriction) {
227 RenderScriptToolkit* toolkit = reinterpret_cast<RenderScriptToolkit*>(native_handle);
228 RestrictionParameter restrict {env, restriction};
229 ByteArrayGuard input{env, input_array};
230 ByteArrayGuard output{env, output_array};
231
232 toolkit->blur(input.get(), output.get(), size_x, size_y, vectorSize, radius, restrict.get());
233 }
234
Java_android_renderscript_toolkit_Toolkit_nativeBlurBitmap(JNIEnv * env,jobject,jlong native_handle,jobject input_bitmap,jobject output_bitmap,jint radius,jobject restriction)235 extern "C" JNIEXPORT void JNICALL Java_android_renderscript_toolkit_Toolkit_nativeBlurBitmap(
236 JNIEnv* env, jobject /*thiz*/, jlong native_handle, jobject input_bitmap,
237 jobject output_bitmap, jint radius, jobject restriction) {
238 RenderScriptToolkit* toolkit = reinterpret_cast<RenderScriptToolkit*>(native_handle);
239 RestrictionParameter restrict {env, restriction};
240 BitmapGuard input{env, input_bitmap};
241 BitmapGuard output{env, output_bitmap};
242
243 toolkit->blur(input.get(), output.get(), input.width(), input.height(), input.vectorSize(),
244 radius, restrict.get());
245 }
246
Java_android_renderscript_toolkit_Toolkit_nativeColorMatrix(JNIEnv * env,jobject,jlong native_handle,jbyteArray input_array,jint input_vector_size,jint size_x,jint size_y,jbyteArray output_array,jint output_vector_size,jfloatArray jmatrix,jfloatArray add_vector,jobject restriction)247 extern "C" JNIEXPORT void JNICALL Java_android_renderscript_toolkit_Toolkit_nativeColorMatrix(
248 JNIEnv* env, jobject /*thiz*/, jlong native_handle, jbyteArray input_array,
249 jint input_vector_size, jint size_x, jint size_y, jbyteArray output_array,
250 jint output_vector_size, jfloatArray jmatrix, jfloatArray add_vector, jobject restriction) {
251 RenderScriptToolkit* toolkit = reinterpret_cast<RenderScriptToolkit*>(native_handle);
252 RestrictionParameter restrict {env, restriction};
253 ByteArrayGuard input{env, input_array};
254 ByteArrayGuard output{env, output_array};
255 FloatArrayGuard matrix{env, jmatrix};
256 FloatArrayGuard add{env, add_vector};
257
258 toolkit->colorMatrix(input.get(), output.get(), input_vector_size, output_vector_size, size_x,
259 size_y, matrix.get(), add.get(), restrict.get());
260 }
261
Java_android_renderscript_toolkit_Toolkit_nativeColorMatrixBitmap(JNIEnv * env,jobject,jlong native_handle,jobject input_bitmap,jobject output_bitmap,jfloatArray jmatrix,jfloatArray add_vector,jobject restriction)262 extern "C" JNIEXPORT void JNICALL Java_android_renderscript_toolkit_Toolkit_nativeColorMatrixBitmap(
263 JNIEnv* env, jobject /*thiz*/, jlong native_handle, jobject input_bitmap,
264 jobject output_bitmap, jfloatArray jmatrix, jfloatArray add_vector, jobject restriction) {
265 RenderScriptToolkit* toolkit = reinterpret_cast<RenderScriptToolkit*>(native_handle);
266 RestrictionParameter restrict {env, restriction};
267 BitmapGuard input{env, input_bitmap};
268 BitmapGuard output{env, output_bitmap};
269 FloatArrayGuard matrix{env, jmatrix};
270 FloatArrayGuard add{env, add_vector};
271
272 toolkit->colorMatrix(input.get(), output.get(), input.vectorSize(), output.vectorSize(),
273 input.width(), input.height(), matrix.get(), add.get(), restrict.get());
274 }
275
Java_android_renderscript_toolkit_Toolkit_nativeConvolve(JNIEnv * env,jobject,jlong native_handle,jbyteArray input_array,jint vectorSize,jint size_x,jint size_y,jbyteArray output_array,jfloatArray coefficients,jobject restriction)276 extern "C" JNIEXPORT void JNICALL Java_android_renderscript_toolkit_Toolkit_nativeConvolve(
277 JNIEnv* env, jobject /*thiz*/, jlong native_handle, jbyteArray input_array, jint vectorSize,
278 jint size_x, jint size_y, jbyteArray output_array, jfloatArray coefficients,
279 jobject restriction) {
280 RenderScriptToolkit* toolkit = reinterpret_cast<RenderScriptToolkit*>(native_handle);
281 RestrictionParameter restrict {env, restriction};
282 ByteArrayGuard input{env, input_array};
283 ByteArrayGuard output{env, output_array};
284 FloatArrayGuard coeffs{env, coefficients};
285
286 switch (env->GetArrayLength(coefficients)) {
287 case 9:
288 toolkit->convolve3x3(input.get(), output.get(), vectorSize, size_x, size_y,
289 coeffs.get(), restrict.get());
290 break;
291 case 25:
292 toolkit->convolve5x5(input.get(), output.get(), vectorSize, size_x, size_y,
293 coeffs.get(), restrict.get());
294 break;
295 }
296 }
297
Java_android_renderscript_toolkit_Toolkit_nativeConvolveBitmap(JNIEnv * env,jobject,jlong native_handle,jobject input_bitmap,jobject output_bitmap,jfloatArray coefficients,jobject restriction)298 extern "C" JNIEXPORT void JNICALL Java_android_renderscript_toolkit_Toolkit_nativeConvolveBitmap(
299 JNIEnv* env, jobject /*thiz*/, jlong native_handle, jobject input_bitmap,
300 jobject output_bitmap, jfloatArray coefficients, jobject restriction) {
301 RenderScriptToolkit* toolkit = reinterpret_cast<RenderScriptToolkit*>(native_handle);
302 RestrictionParameter restrict {env, restriction};
303 BitmapGuard input{env, input_bitmap};
304 BitmapGuard output{env, output_bitmap};
305 FloatArrayGuard coeffs{env, coefficients};
306
307 switch (env->GetArrayLength(coefficients)) {
308 case 9:
309 toolkit->convolve3x3(input.get(), output.get(), input.vectorSize(), input.width(),
310 input.height(), coeffs.get(), restrict.get());
311 break;
312 case 25:
313 toolkit->convolve5x5(input.get(), output.get(), input.vectorSize(), input.width(),
314 input.height(), coeffs.get(), restrict.get());
315 break;
316 }
317 }
318
Java_android_renderscript_toolkit_Toolkit_nativeHistogram(JNIEnv * env,jobject,jlong native_handle,jbyteArray input_array,jint vector_size,jint size_x,jint size_y,jintArray output_array,jobject restriction)319 extern "C" JNIEXPORT void JNICALL Java_android_renderscript_toolkit_Toolkit_nativeHistogram(
320 JNIEnv* env, jobject /*thiz*/, jlong native_handle, jbyteArray input_array,
321 jint vector_size, jint size_x, jint size_y, jintArray output_array, jobject restriction) {
322 RenderScriptToolkit* toolkit = reinterpret_cast<RenderScriptToolkit*>(native_handle);
323 RestrictionParameter restrict {env, restriction};
324 ByteArrayGuard input{env, input_array};
325 IntArrayGuard output{env, output_array};
326
327 toolkit->histogram(input.get(), output.get(), size_x, size_y, vector_size, restrict.get());
328 }
329
Java_android_renderscript_toolkit_Toolkit_nativeHistogramBitmap(JNIEnv * env,jobject,jlong native_handle,jobject input_bitmap,jintArray output_array,jobject restriction)330 extern "C" JNIEXPORT void JNICALL Java_android_renderscript_toolkit_Toolkit_nativeHistogramBitmap(
331 JNIEnv* env, jobject /*thiz*/, jlong native_handle, jobject input_bitmap,
332 jintArray output_array, jobject restriction) {
333 RenderScriptToolkit* toolkit = reinterpret_cast<RenderScriptToolkit*>(native_handle);
334 RestrictionParameter restrict {env, restriction};
335 BitmapGuard input{env, input_bitmap};
336 IntArrayGuard output{env, output_array};
337
338 toolkit->histogram(input.get(), output.get(), input.width(), input.height(), input.vectorSize(),
339 restrict.get());
340 }
341
Java_android_renderscript_toolkit_Toolkit_nativeHistogramDot(JNIEnv * env,jobject,jlong native_handle,jbyteArray input_array,jint vector_size,jint size_x,jint size_y,jintArray output_array,jfloatArray coefficients,jobject restriction)342 extern "C" JNIEXPORT void JNICALL Java_android_renderscript_toolkit_Toolkit_nativeHistogramDot(
343 JNIEnv* env, jobject /*thiz*/, jlong native_handle, jbyteArray input_array,
344 jint vector_size, jint size_x, jint size_y, jintArray output_array,
345 jfloatArray coefficients, jobject restriction) {
346 RenderScriptToolkit* toolkit = reinterpret_cast<RenderScriptToolkit*>(native_handle);
347 RestrictionParameter restrict {env, restriction};
348 ByteArrayGuard input{env, input_array};
349 IntArrayGuard output{env, output_array};
350 FloatArrayGuard coeffs{env, coefficients};
351
352 toolkit->histogramDot(input.get(), output.get(), size_x, size_y, vector_size, coeffs.get(),
353 restrict.get());
354 }
355
356 extern "C" JNIEXPORT
Java_android_renderscript_toolkit_Toolkit_nativeHistogramDotBitmap(JNIEnv * env,jobject,jlong native_handle,jobject input_bitmap,jintArray output_array,jfloatArray coefficients,jobject restriction)357 void JNICALL Java_android_renderscript_toolkit_Toolkit_nativeHistogramDotBitmap(
358 JNIEnv* env, jobject /*thiz*/, jlong native_handle, jobject input_bitmap,
359 jintArray output_array, jfloatArray coefficients, jobject restriction) {
360 RenderScriptToolkit* toolkit = reinterpret_cast<RenderScriptToolkit*>(native_handle);
361 RestrictionParameter restrict {env, restriction};
362 BitmapGuard input{env, input_bitmap};
363 IntArrayGuard output{env, output_array};
364 FloatArrayGuard coeffs{env, coefficients};
365
366 toolkit->histogramDot(input.get(), output.get(), input.width(), input.height(),
367 input.vectorSize(), coeffs.get(), restrict.get());
368 }
369
Java_android_renderscript_toolkit_Toolkit_nativeLut(JNIEnv * env,jobject,jlong native_handle,jbyteArray input_array,jbyteArray output_array,jint size_x,jint size_y,jbyteArray red_table,jbyteArray green_table,jbyteArray blue_table,jbyteArray alpha_table,jobject restriction)370 extern "C" JNIEXPORT void JNICALL Java_android_renderscript_toolkit_Toolkit_nativeLut(
371 JNIEnv* env, jobject /*thiz*/, jlong native_handle, jbyteArray input_array,
372 jbyteArray output_array, jint size_x, jint size_y, jbyteArray red_table,
373 jbyteArray green_table, jbyteArray blue_table, jbyteArray alpha_table,
374 jobject restriction) {
375 RenderScriptToolkit* toolkit = reinterpret_cast<RenderScriptToolkit*>(native_handle);
376 RestrictionParameter restrict {env, restriction};
377
378 ByteArrayGuard input{env, input_array};
379 ByteArrayGuard output{env, output_array};
380 ByteArrayGuard red{env, red_table};
381 ByteArrayGuard green{env, green_table};
382 ByteArrayGuard blue{env, blue_table};
383 ByteArrayGuard alpha{env, alpha_table};
384
385 toolkit->lut(input.get(), output.get(), size_x, size_y, red.get(), green.get(), blue.get(),
386 alpha.get(), restrict.get());
387 }
388
Java_android_renderscript_toolkit_Toolkit_nativeLutBitmap(JNIEnv * env,jobject,jlong native_handle,jobject input_bitmap,jobject output_bitmap,jbyteArray red_table,jbyteArray green_table,jbyteArray blue_table,jbyteArray alpha_table,jobject restriction)389 extern "C" JNIEXPORT void JNICALL Java_android_renderscript_toolkit_Toolkit_nativeLutBitmap(
390 JNIEnv* env, jobject /*thiz*/, jlong native_handle, jobject input_bitmap,
391 jobject output_bitmap, jbyteArray red_table, jbyteArray green_table, jbyteArray blue_table,
392 jbyteArray alpha_table, jobject restriction) {
393 RenderScriptToolkit* toolkit = reinterpret_cast<RenderScriptToolkit*>(native_handle);
394 RestrictionParameter restrict {env, restriction};
395
396 BitmapGuard input{env, input_bitmap};
397 BitmapGuard output{env, output_bitmap};
398 ByteArrayGuard red{env, red_table};
399 ByteArrayGuard green{env, green_table};
400 ByteArrayGuard blue{env, blue_table};
401 ByteArrayGuard alpha{env, alpha_table};
402
403 toolkit->lut(input.get(), output.get(), input.width(), input.height(), red.get(), green.get(),
404 blue.get(), alpha.get(), restrict.get());
405 }
406
Java_android_renderscript_toolkit_Toolkit_nativeLut3d(JNIEnv * env,jobject,jlong native_handle,jbyteArray input_array,jbyteArray output_array,jint size_x,jint size_y,jbyteArray cube_values,jint cubeSizeX,jint cubeSizeY,jint cubeSizeZ,jobject restriction)407 extern "C" JNIEXPORT void JNICALL Java_android_renderscript_toolkit_Toolkit_nativeLut3d(
408 JNIEnv* env, jobject /*thiz*/, jlong native_handle, jbyteArray input_array,
409 jbyteArray output_array, jint size_x, jint size_y, jbyteArray cube_values, jint cubeSizeX,
410 jint cubeSizeY, jint cubeSizeZ, jobject restriction) {
411 RenderScriptToolkit* toolkit = reinterpret_cast<RenderScriptToolkit*>(native_handle);
412 RestrictionParameter restrict {env, restriction};
413 ByteArrayGuard input{env, input_array};
414 ByteArrayGuard output{env, output_array};
415 ByteArrayGuard cube{env, cube_values};
416
417 toolkit->lut3d(input.get(), output.get(), size_x, size_y, cube.get(), cubeSizeX, cubeSizeY,
418 cubeSizeZ, restrict.get());
419 }
420
Java_android_renderscript_toolkit_Toolkit_nativeLut3dBitmap(JNIEnv * env,jobject,jlong native_handle,jobject input_bitmap,jobject output_bitmap,jbyteArray cube_values,jint cubeSizeX,jint cubeSizeY,jint cubeSizeZ,jobject restriction)421 extern "C" JNIEXPORT void JNICALL Java_android_renderscript_toolkit_Toolkit_nativeLut3dBitmap(
422 JNIEnv* env, jobject /*thiz*/, jlong native_handle, jobject input_bitmap,
423 jobject output_bitmap, jbyteArray cube_values, jint cubeSizeX, jint cubeSizeY,
424 jint cubeSizeZ, jobject restriction) {
425 RenderScriptToolkit* toolkit = reinterpret_cast<RenderScriptToolkit*>(native_handle);
426 RestrictionParameter restrict {env, restriction};
427 BitmapGuard input{env, input_bitmap};
428 BitmapGuard output{env, output_bitmap};
429 ByteArrayGuard cube{env, cube_values};
430
431 toolkit->lut3d(input.get(), output.get(), input.width(), input.height(), cube.get(), cubeSizeX,
432 cubeSizeY, cubeSizeZ, restrict.get());
433 }
434
Java_android_renderscript_toolkit_Toolkit_nativeResize(JNIEnv * env,jobject,jlong native_handle,jbyteArray input_array,jint vector_size,jint input_size_x,jint input_size_y,jbyteArray output_array,jint output_size_x,jint output_size_y,jobject restriction)435 extern "C" JNIEXPORT void JNICALL Java_android_renderscript_toolkit_Toolkit_nativeResize(
436 JNIEnv* env, jobject /*thiz*/, jlong native_handle, jbyteArray input_array,
437 jint vector_size, jint input_size_x, jint input_size_y, jbyteArray output_array,
438 jint output_size_x, jint output_size_y, jobject restriction) {
439 RenderScriptToolkit* toolkit = reinterpret_cast<RenderScriptToolkit*>(native_handle);
440 RestrictionParameter restrict {env, restriction};
441 ByteArrayGuard input{env, input_array};
442 ByteArrayGuard output{env, output_array};
443
444 toolkit->resize(input.get(), output.get(), input_size_x, input_size_y, vector_size,
445 output_size_x, output_size_y, restrict.get());
446 }
447
Java_android_renderscript_toolkit_Toolkit_nativeResizeBitmap(JNIEnv * env,jobject,jlong native_handle,jobject input_bitmap,jobject output_bitmap,jobject restriction)448 extern "C" JNIEXPORT void JNICALL Java_android_renderscript_toolkit_Toolkit_nativeResizeBitmap(
449 JNIEnv* env, jobject /*thiz*/, jlong native_handle, jobject input_bitmap,
450 jobject output_bitmap, jobject restriction) {
451 RenderScriptToolkit* toolkit = reinterpret_cast<RenderScriptToolkit*>(native_handle);
452 RestrictionParameter restrict {env, restriction};
453 BitmapGuard input{env, input_bitmap};
454 BitmapGuard output{env, output_bitmap};
455
456 toolkit->resize(input.get(), output.get(), input.width(), input.height(), input.vectorSize(),
457 output.width(), output.height(), restrict.get());
458 }
459
Java_android_renderscript_toolkit_Toolkit_nativeYuvToRgb(JNIEnv * env,jobject,jlong native_handle,jbyteArray input_array,jbyteArray output_array,jint size_x,jint size_y,jint format)460 extern "C" JNIEXPORT void JNICALL Java_android_renderscript_toolkit_Toolkit_nativeYuvToRgb(
461 JNIEnv* env, jobject /*thiz*/, jlong native_handle, jbyteArray input_array,
462 jbyteArray output_array, jint size_x, jint size_y, jint format) {
463 RenderScriptToolkit* toolkit = reinterpret_cast<RenderScriptToolkit*>(native_handle);
464 ByteArrayGuard input{env, input_array};
465 ByteArrayGuard output{env, output_array};
466
467 toolkit->yuvToRgb(input.get(), output.get(), size_x, size_y,
468 static_cast<RenderScriptToolkit::YuvFormat>(format));
469 }
470
Java_android_renderscript_toolkit_Toolkit_nativeYuvToRgbBitmap(JNIEnv * env,jobject,jlong native_handle,jbyteArray input_array,jint size_x,jint size_y,jobject output_bitmap,jint format)471 extern "C" JNIEXPORT void JNICALL Java_android_renderscript_toolkit_Toolkit_nativeYuvToRgbBitmap(
472 JNIEnv* env, jobject /*thiz*/, jlong native_handle, jbyteArray input_array, jint size_x,
473 jint size_y, jobject output_bitmap, jint format) {
474 RenderScriptToolkit* toolkit = reinterpret_cast<RenderScriptToolkit*>(native_handle);
475 BitmapGuard output{env, output_bitmap};
476 ByteArrayGuard input{env, input_array};
477
478 toolkit->yuvToRgb(input.get(), output.get(), size_x, size_y,
479 static_cast<RenderScriptToolkit::YuvFormat>(format));
480 }
481