Created
August 23, 2016 12:20
-
-
Save anonymous/bbc4af95cbc5ce434c8106060e2516ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef __ANDROID__ | |
#include "jni.h" | |
#include "android/log.h" | |
#define LOG_TAG "psx" | |
#define PRINTMSGS(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) | |
#endif | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <math.h> | |
JNIEXPORT jfloat JNICALL | |
Java_com_mofirst_launcher_Launcher_getPercentage(JNIEnv *env, jclass obj, jintArray arr, jint w, jint h){ | |
jsize len = (*env)->GetArrayLength(env, arr); | |
int i = 0, colorPixel = 0, right_corner_pixel =0, left_corner_pixel = 0; | |
float percentage = 0.0f; | |
clock_t start, end; | |
int left = 100, right = 0, top = 100, bottom = 0; | |
start = clock(); | |
jint *body = (*env)->GetIntArrayElements(env, arr, 0); | |
for (i=0; i<len; i++) { | |
if((body[i] >> 24) != 0){ | |
colorPixel++; | |
if(top > i/h) top = i; | |
if(bottom < i/h) bottom = i; | |
if(left > i%h) left=i; | |
if(right < i%h) right=i; | |
} | |
} | |
int shape =0; | |
if((float)abs(bottom-top) / abs(right-left) > 0.9f) | |
shape = 100; | |
percentage = (float)colorPixel/len; | |
(*env)->ReleaseIntArrayElements(env, arr, body, 0); | |
end = clock(); | |
return percentage + shape; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment