Reputation: 1359
I want to be able to crop an image using RenderScript. Here is my crop function:
uchar4 __attribute__((kernel)) crop(const uchar4 in, uint32_t x, uint32_t y){
int minX = centerX - cropWidth;
int maxX = centerX + cropWidth;
int minY = centerY - cropHeight;
int maxY = centerY + cropHeight;
uchar4 out = in;
if((minX < x < maxX ) && (minY < y < maxY)){
return out;
}
else{
out.r = 0;
out.g = 0;
out.b = 255;
return out;
}
}
This is the desired logic:
If the pixel is not in the X Y bounds specified in the IF condition, then I want that pixel to be blue.
For some reason, no matter how strict my bounds are, none of the pixels are blue. Can someone explain to me why this is? And how to fix it?
If I replace the IF condition to just false (if(false)
, so it guarantees execution of the ELSE code), then all pixels are blue (as expected).
Upvotes: 0
Views: 507
Reputation: 2188
minX < x < maxX
isn't working the way you are expecting it to. What that code is doing is first checking if minX < x
, then casting the resulting Boolean to an Integer (will be 0 or 1), and finally checking if that Integer is less than maxX
(which it will always be). (Same thing is happening with the y
's). You need to rewrite that check like:
(minX < x && x < maxX ) && (minY < y && y < maxY)
Upvotes: 2