2017-05-20 1 views
0

J'essaie d'implémenter un filtre médian dans RenderScript. Mais le travail du code n'est pas stable. La lecture d'éléments n'appartenant pas à la ligne courante rsGetElementAt_uchar4 (inputAlloc, x, y + a) provoque des erreurs. Quel est le problème ? Existe-t-il un exemple d'un tel filtre utilisant RenderScript?Problèmes avec rsGetElementAt_uchar4

#pragma version(1) 
#pragma rs java_package_name(a.myapplication) 
#pragma rs_fp_relaxed 


rs_allocation inputAlloc; 
int bWidht, bHeight; 

static uchar4 arrpix[9]; 
static uchar4 buff; 

uchar4 __attribute__((kernel)) median(uchar4 in, uint32_t x, uint32_t y) 
{ 

uchar4 arrpix[9]; 
uchar4 buff; 

         if((x<bWidht) && (y<bHeight)){ 
     arrpix[0] = rsGetElementAt_uchar4(inputAlloc, x -1 , y - 1); 
     arrpix[1] = rsGetElementAt_uchar4(inputAlloc, x , y - 1); 
     arrpix[2] = rsGetElementAt_uchar4(inputAlloc, x +1 , y - 1); 


     arrpix[3] = rsGetElementAt_uchar4(inputAlloc, x -1 , y ); 
     arrpix[4] = in; 
     arrpix[5] = rsGetElementAt_uchar4(inputAlloc, x +1 , y ); 

     arrpix[6] = rsGetElementAt_uchar4(inputAlloc, x -1 , y + 1); 
     arrpix[7] = rsGetElementAt_uchar4(inputAlloc, x , y + 1); 
     arrpix[8] = rsGetElementAt_uchar4(inputAlloc, x +1 , y + 1); 


for(int i=0; i<4; i++) 

for(int i=0; i<=8; i++){ 

if(arrpix[i].r>arrpix[i+1].r){ 
buff.r = arrpix[i].r; arrpix[i].r = arrpix[i+1].r; 
arrpix[i+1].r = buff.r;} 

if(arrpix[i].g>arrpix[i+1].g){ 
buff.g = arrpix[i].g; arrpix[i].g = arrpix[i+1].g; 
arrpix[i+1].g = buff.g;} 

if(arrpix[i].b>arrpix[i+1].b){ 
buff.b = arrpix[i].b; arrpix[i].b = arrpix[i+1].b; 
arrpix[i+1].b = buff.b;} 

} 
} 
    return arrpix[4]; 
} 

Répondre

1

Vous devez vérifier x> 0 et y> 0 car 0-1 = -1

boucles de fond ne semblent pas non plus tout à fait correct. Pouvez-vous corriger l'espacement et voulez-vous utiliser i dans les deux boucles?