• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef PHOTOEDITOR_JNI_UTILS_H_
18 #define PHOTOEDITOR_JNI_UTILS_H_
19 
20 #include <android/bitmap.h>
21 #include <android/log.h>
22 #include <jni.h>
23 
24 #define  LOG_TAG    "libjni_photoeditor"
25 #define  LOGI(...)  __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
26 #define  LOGE(...)  __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
27 
28 #define MIN3(x, y, z)  ((y) <= (z) ? \
29                          ((x) <= (y) ? (x) : (y)) \
30                      : \
31                          ((x) <= (z) ? (x) : (z)))
32 
33 #define MAX3(x, y, z)  ((y) >= (z) ? \
34                          ((x) >= (y) ? (x) : (y)) \
35                      : \
36                          ((x) >= (z) ? (x) : (z)))
37 
38 namespace android {
39 namespace apps {
40 namespace photoeditor {
41 namespace utils {
42 
clamp(int x,int min,int max)43 inline int clamp(int x, int min, int max) {
44   return (x < min ? min : ((x > max) ? max : x));
45 }
46 
47 union pixel32_t {
48   uint32_t rgba32;
49   uint8_t rgba8[4];  // 0: red 1:green 2:blue 3:alpha
50 };
51 
52 typedef union pixel32_t pixel32_t;
53 
54 int ExtractInfoFromBitmap(JNIEnv *env,
55     AndroidBitmapInfo *src_info, AndroidBitmapInfo *dst_info,
56     jobject src_bitmap, jobject dst_bitmap);
57 
58 int LockBitmaps(JNIEnv* env, jobject src_bitmap, jobject dst_bitmap,
59     AndroidBitmapInfo* src_info, AndroidBitmapInfo* dst_info,
60     void** src_pixels, void** dst_pixels);
61 
62 void UnlockBitmaps(JNIEnv* env, jobject src_bitmap, jobject dst_bitmap);
63 
64 }  // namespace utils
65 }  // namespace photoeditor
66 }  // namespace apps
67 }  // namespace android
68 
69 
70 #endif  // PHOTOEDITOR_JNI_UTILS_H_
71