1 /* 2 * Copyright (C) 2012 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 // Some native low-level image processing functions. 18 19 20 #ifndef ANDROID_FILTERFW_JNI_IMGPROCUTIL_H 21 #define ANDROID_FILTERFW_JNI_IMGPROCUTIL_H 22 23 inline int getIntensityFast(int R, int G, int B) { 24 return (R + R + R + B + G + G + G + G) >> 3; // see http://stackoverflow.com/a/596241 25 } 26 27 inline int clamp(int min, int val, int max) { 28 return val < min ? min : (val > max ? max : val); 29 // Note that for performance reasons, this function does *not* check if min < max! 30 } 31 32 #endif // ANDROID_FILTERFW_JNI_IMGPROCUTIL_H 33