I'm developing an Android app what uses some native code to process Bitmap. In the native code, I call three methods in sequency from Java code and each one gives a value to the extern ints. The 3rd method needs the values of the first and second extern ints produced by the method 1 and 2 but they return 0, the default value of declaration.
/*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;
}}
The result is 0 for blu1, 0 for green1 and the correct value for red1. How can I keep the values of blu1 and green1 after the re-call of the class?