Created
January 15, 2015 09:09
-
-
Save Manabu-GT/b8abc95cd15b7c547169 to your computer and use it in GitHub Desktop.
Mosaic RenderScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma version(1) | |
#pragma rs java_package_name(com.uievolution.vehicleinfo.android.util) | |
#pragma rs_fp_relaxed | |
rs_allocation pixels; | |
int dotSize; | |
void init() { | |
} | |
/* | |
* RenderScript kernel that performs mosaic manipulation. | |
*/ | |
uchar4 __attribute__((kernel)) mosaic(uint32_t x, uint32_t y) { | |
//rsDebug("x: %d y: %d", x, y); | |
int px = (x / dotSize) * dotSize; | |
int py = (y / dotSize) * dotSize; | |
int square = dotSize * dotSize; | |
int4 avg = {0, 0, 0, 255}; | |
for (int k = 0; k < dotSize; k++) { | |
for (int l = 0; l < dotSize; l++) { | |
uchar4 color = *(uchar4*)rsGetElementAt(pixels, px + k, py + l); | |
avg.r += color.r; | |
avg.g += color.g; | |
avg.b += color.b; | |
} | |
} | |
uchar4 out = {0, 0, 0, 255}; | |
out.r = avg.r / square; | |
out.g = avg.g / square; | |
out.b = avg.b / square; | |
return out; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment