调用另一个方法时保持extern int值C.

时间:2015-11-02 09:48:30

标签: java android c++ c java-native-interface

我正在开发一个Android应用程序,它使用一些本机代码来处理Bitmap。在本机代码中,我从Java代码中按顺序调用了三个方法,每个方法都为extern int赋值。第三种方法需要方法1和2生成的第一个和第二个extern int的值,但它们返回0,即声明的默认值。

/*header.cpp*/
extern int red1=0;
extern int green1=0;
extern int blu1=0;

/*effect.c*/

static void harris1(AndroidBitmapInfo* info, void* pixels){
int xx, yy, green, red;
uint32_t* line;

for(yy = 0; yy < info->height; yy++){
        line = (uint32_t*)pixels;
        for(xx =0; xx < info->width; xx++){

            blu1 = (int) ((line[xx] & 0x00FF0000) >> 16);
            //private int
            green = (int)((line[xx] & 0x0000FF00) >> 8);
            red = (int) (line[xx] & 0x00000FF );

            blu1 = rgb_clamp((int)(blu1));
            green = rgb_clamp((int)(green));
            red = rgb_clamp((int)(red));

            line[xx] =
                     ((blu1 << 16) & 0x00FF0000) |
                     ((green << 8) & 0x0000FF00) |
                     (red & 0x000000FF);
                    }

            pixels = (char*)pixels + info->stride;
      }}




static void harris2(AndroidBitmapInfo* info, void* pixels){
int xx, yy, blue, red;
    uint32_t* line;

    for(yy = 0; yy < info->height; yy++){
            line = (uint32_t*)pixels;
            for(xx =0; xx < info->width; xx++){
                //private int
                blue = (int) ((line[xx] & 0x00FF0000) >> 16);

                green1 = (int)((line[xx] & 0x0000FF00) >> 8);

                //private int
                red = (int) (line[xx] & 0x00000FF );

                blue = rgb_clamp((int)(blue));
                green1 = rgb_clamp((int)(green1));
                red = rgb_clamp((int)(red));

                line[xx] =
                         ((blue << 16) & 0x00FF0000) |
                         ((green1 << 8) & 0x0000FF00) |
                         (red & 0x000000FF);
                        }

                pixels = (char*)pixels + info->stride;
    }}




static void harris3(AndroidBitmapInfo* info, void* pixels){
int xx, yy, blue, green;
    uint32_t* line;

    for(yy = 0; yy < info->height; yy++){
            line = (uint32_t*)pixels;
            for(xx =0; xx < info->width; xx++){
                //local int
                blue = (int) ((line[xx] & 0x00FF0000) >> 16);
                green = (int)((line[xx] & 0x0000FF00) >> 8);
                //the only values displayed in the final Bitmap
                red1 = (int) (line[xx] & 0x00000FF );

                blue = rgb_clamp((int)(blue));
                green = rgb_clamp((int)(green));
                red1 = rgb_clamp((int)(red1));

             //HERE I USE blu1, green1, red1
                line[xx] =
                         ((blu1 << 16) & 0x00FF0000) |
                         ((green1 << 8) & 0x0000FF00) |
                         (red1 & 0x000000FF);
                        }
            //blu1 and green1 are 0, red has the correct value

                pixels = (char*)pixels + info->stride;

      }}

对于blu1,结果为0,对于green1,结果为0,对于red1,结果为正确的值。 在重新调用类之后,如何保持blu1和green1的值?

0 个答案:

没有答案