1 /* 2 * Copyright (C) 2010 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 <jni.h> 19 20 #include <cstdlib> 21 22 #include "utils.h" 23 #include "_jni.h" 24 25 using android::apps::photoeditor::utils::LockBitmaps; 26 using android::apps::photoeditor::utils::UnlockBitmaps; 27 28 namespace { 29 30 extern "C" JNIEXPORT void JNICALL Java_com_android_photoeditor_filters_ImageUtils_nativeCopy( 31 JNIEnv *env, jobject obj, jobject src_bitmap, jobject dst_bitmap) { 32 pCopyType f = (pCopyType)JNIFunc[JNI_Copy].func_ptr; 33 return f(env, obj, src_bitmap, dst_bitmap); 34 } 35 36 extern "C" void Copy( 37 JNIEnv *env, jobject obj, jobject src_bitmap, jobject dst_bitmap) { 38 AndroidBitmapInfo src_info; 39 AndroidBitmapInfo dst_info; 40 void* src_pixels; 41 void* dst_pixels; 42 43 int ret = LockBitmaps( 44 env, src_bitmap, dst_bitmap, &src_info, &dst_info, &src_pixels, &dst_pixels); 45 if (ret < 0) { 46 LOGE("LockBitmaps in Copy failed, error=%d", ret); 47 return; 48 } 49 50 memcpy(dst_pixels, src_pixels, src_info.stride * src_info.height); 51 52 UnlockBitmaps(env, src_bitmap, dst_bitmap); 53 } 54 55 } // namespace 56