Ich versuche, einen Median-Filter in RenderScript zu implementieren. Aber die Arbeit des Codes ist nicht stabil. Lesen von Elementen, die nicht von der aktuellen Zeile stammen rsGetElementAt_uchar4 (inputAlloc, x, y + a) verursacht Fehler. Was ist das Problem ? Gibt es ein Beispiel für einen solchen Filter mit RenderScript?Probleme mit 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];
}