所谓Lomo效果无非就是四角变暗,然后加上颜色矩阵变换。
以下是通过c代码实现的Lomo效果,效果有待优化:
/** LOMO效果
*/
jintArray ToLOMO(JNIEnv *env, jobject obj, jintArray srcPixels, jint width,
jint height, jfloat factor)
{
jint* pixels = NULL;
pixels = env->GetIntArrayElements(srcPixels, JNI_FALSE);
if (pixels == NULL)
{
return srcPixels;
}
int size = width * height;
int result[size];
int ratio =
width > height ? height * 32768 / width : width * 32768 / height;
int cx = width >> 1;
int cy = height >> 1;
int max = cx * cx + cy * cy;
int min = (int) (max * (1 - 0.8f));
int diff = max - min;
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
int current_color = pixels[i * width + j];
int r0 = red(current_color);
int g0 = green(current_color);
int b0 = blue(current_color);
int a0 = alpha(current_color);
int value = r0 < 128 ? r0 : 256 - r0;
int newR = (value * value * value) / 64 / 256;
newR = r0 < 128 ? newR : 255 - newR;
value = g0 < 128 ? g0 : 256 - g0;
int newG = (value * value) / 128;
newG = (g0 < 128 ? newG : 255 - newG);
int newB = b0 / 2 + 0x25;
/*****************边缘黑暗**************/
int dx = cx - j;
int dy = cy - i;
if (width > height)
{
dx = (dx * ratio) >> 15;
} else
{
dy = (dy * ratio) >> 15;
}
int distSq = dx * dx + dy * dy;
if (distSq > min)
{
int v = ((max - distSq) << 8) / diff;
v *= v;
int ri = (int) (newR * v) >> 16;
int gi = (int) (newG * v) >> 16;
int bi = (int) (newB * v) >> 16;
newR = ri > 255 ? 255 : (ri < 0 ? 0 : ri);
newG = gi > 255 ? 255 : (gi < 0 ? 0 : gi);
newB = bi > 255 ? 255 : (bi < 0 ? 0 : bi);
}
/**********************边缘黑暗end*****************/
current_color = ARGB(a0, newR, newG, newB);
result[i * width + j] = current_color;
}
}
jintArray resultArray = env->NewIntArray(size);
env->SetIntArrayRegion(resultArray, 0, size, result);
env->ReleaseIntArrayElements(srcPixels, pixels, 0);
return resultArray;
}
以上仅供参考,但是效率不是很高,不过还有一种实现方式,就是利用图层混合处理算法,此算法等我总结出来释放demo