В моей программе RenderScript я хочу вернуть 32-битное целое число, представляющее цвет (чтобы быть непосредственно цветом в среде Java), поэтому я делаю это следующим образом:
Код RS:
static const uchar k = 51;
static const uchar d = 5;
static int32_t histo[52][52][52];
....
int __attribute__((kernel)) getResult() {
int maximum = 0;
uchar3 vect = {0, 0, 0};
....
loops through histogram and puts max's coordinates into vect
...
// Convert coords back to [0, 255] space
vect.r = (uchar) (vect.s0*d + d/2);
vect.g = (uchar) (vect.s1*d + d/2);
vect.b = (uchar) (vect.s2*d + d/2);
return (0xff) << 24 | (vect.r & 0xff) << 16 | (vect.g & 0xff) << 8 | (vect.b & 0xff);
}
Java-код:
Allocation bmpAlloc = Allocation.createFromBitmap(rs, bitmap);
// Allocation where to store the result color (for output purposes)
Allocation colorAlloc = Allocation.createSized(rs, Element.I32(rs), 1);
ScriptC_findcolor scriptC = new ScriptC_findcolor(rs);
scriptC.forEach_channelHist(bmpAlloc);
scriptC.forEach_getResult(colorAlloc);
int[] a = new int[1];
colorAlloc.copyTo(a);
int color = a[0];
Он отлично работает при использовании эмулятора x86, но по какой-то причине с реальным устройством значение, полученное на стороне Java, совершенно случайно.
Как видите, альфа-канал жестко закодирован в 255 (0xff) в скрипте .rs, но на стороне Java значение совсем не равно 255 (102, 164 ...).
Может кто-нибудь помочь? Спасибо