2010-11-25 9 views
1

ピクセルが白であるかどうかをチェックするビンボーディングを支援する簡単なループを書きました。そうであれば、100%透明に設定します。私はネイティブコードでこのループのJavaに相当するので、遅すぎる256x256ビットマップのために実行するために19秒かかったので、それを書いた。Cコードが正しくコンパイルされていない

コンパイルする場合:

#include "org_me_renderscene_Billboard.h" 

#include <stdio.h> 
#include <stdlib.h> 

JNIEXPORT jintArray JNICALL Java_org_me_renderscene_Billboard_NativeSetAlphaWhereWhite 
    (JNIEnv *envptr, jclass jClass, jintArray pixels, jint length) 
{ 
    int *mPixels = (*int)malloc(length * 4); 

    static int currentcolor; 
    static int writecolor; 
    static int red, green, blue; 

    for(int x = 0; x < length; x++) 
    { 
     currentcolor = pixels[x]; 

     red = currentcolor << 16; 
     green = currentcolor << 8; 
     blue = currentcolor; 
     if((red == 0) && (green == 0) && (blue == 0)) 
     { 
      mPixels[x] = 0x00000000; 
     } 
     else 
     { 
      mPixels[x] = currentcolor; 
     } 
    } 

    return mPixels; 

}

をしているため、自動生成されたスタブ:

/* DO NOT EDIT THIS FILE - it is machine generated */ 
#include <jni.h> 
/* Header for class org_me_renderscene_Billboard */ 

#ifndef _Included_org_me_renderscene_Billboard 
#define _Included_org_me_renderscene_Billboard 
#ifdef __cplusplus 
extern "C" { 
#endif 
/* 
* Class:  org_me_renderscene_Billboard 
* Method: NativeSetAlphaWhereWhite 
* Signature: ([II)[I 
*/ 
JNIEXPORT jintArray JNICALL Java_org_me_renderscene_Billboard_NativeSetAlphaWhereWhite 
    (JNIEnv *, jclass, jintArray, jint); 

#ifdef __cplusplus 
} 
#endif 
#endif 

私はこれらのエラーを取得:

[email protected]:~/Documents/LinuxProgramming/EclipseWorkspace/RenderScene$ /home/thomas/Documents/LinuxProgramming/AndroidSDKs/android-ndk-r4b/ndk-build 
Compile thumb : Billboardlib <= /home/thomas/Documents/LinuxProgramming/EclipseWorkspace/RenderScene/jni/org_me_renderscene_Billboard.c 
/home/thomas/Documents/LinuxProgramming/EclipseWorkspace/RenderScene/jni/org_me_renderscene_Billboard.c: In function 'Java_org_me_renderscene_Billboard_NativeSetAlphaWhereWhite': 
/home/thomas/Documents/LinuxProgramming/EclipseWorkspace/RenderScene/jni/org_me_renderscene_Billboard.c:9: error: expected expression before 'int' 
/home/thomas/Documents/LinuxProgramming/EclipseWorkspace/RenderScene/jni/org_me_renderscene_Billboard.c:9: error: expected ',' or ';' before 'malloc' 
/home/thomas/Documents/LinuxProgramming/EclipseWorkspace/RenderScene/jni/org_me_renderscene_Billboard.c:15: error: 'for' loop initial declarations are only allowed in C99 mode 
/home/thomas/Documents/LinuxProgramming/EclipseWorkspace/RenderScene/jni/org_me_renderscene_Billboard.c:15: note: use option -std=c99 or -std=gnu99 to compile your code 
/home/thomas/Documents/LinuxProgramming/EclipseWorkspace/RenderScene/jni/org_me_renderscene_Billboard.c:17: warning: dereferencing 'void *' pointer 
/home/thomas/Documents/LinuxProgramming/EclipseWorkspace/RenderScene/jni/org_me_renderscene_Billboard.c:17: error: void value not ignored as it ought to be 
make: *** [/home/thomas/Documents/LinuxProgramming/EclipseWorkspace/RenderScene/obj/local/armeabi/objs/Billboardlib/org_me_renderscene_Billboard.o] Error 1 

理由ですハプニング?私のCコードはうまくいくはずですが、これらのエラーはあまり意味がありません。

答えて

2
int *mPixels = (*int)malloc(length * 4); 

(int*)をお試しください:

red = currentcolor << 16; 
green = currentcolor << 8; 
blue = currentcolor; 

は、あなただけのゼロのためにチェックしていることを考えると、あなたが本当に個々のRGB値を気にしない、あなたはおそらくわずかの距離で得ることができます。

if ((currentcolor & 0x00FFFFFF) == 0) 

これはアルファゼロになりますそのピクセルからは、RGB部分だけが残されます。そのすべてがゼロの場合、各色はゼロでなければならないので、各色を個別にチェックする必要はありません。

決勝の思考:

私は、特にAndroidのとあまり行っていないが、0x000000を白と黒の0xFFFFFFのではないでしょうか?実際にはここでは白の代わりに黒でマッチングしています。

3

int *mPixels = (int*)malloc(length * 4); 

またはより良い

int *mPixels = (int*)malloc(length * sizeof(int)); 

ともこれが適切に、赤、緑、青を分離しないことに注意する必要があります代わりに(*int)

3

Android.mkではどのようなフラグを使用していますか?

あなたがLOCAL_CFLAGSを設定しました:= -std = c99を

あなたはこの

int *mPixels = (int*)malloc(length * 4); 
に変更する必要があります
関連する問題