📄 cplayer.java
字号:
// Hard Light Mode (same as Overlay with A and B swapped)
// If A <= 0.5 C = (A*aa*(1-ab) + B*ab*(1-aa) + aa*ab*(2*A*B) / (aa + ab - aa*ab)
// If A > 0.5 C = (A*aa*(1-ab) + B*ab*(1-aa) + aa*ab*(1 - 2*(1-A)*(1-B)) / (aa + ab - aa*ab)
public void fusionWithHardLightFullAlpha(CPLayer fusion, CPRect rc) {
CPRect rect = new CPRect(0, 0, width, height);
rect.clip(rc);
for (int j = rect.top; j < rect.bottom; j++) {
int off = rect.left + j * width;
for (int i = rect.left; i < rect.right; i++, off++) {
int color1 = data[off];
int alpha1 = (color1 >>> 24) * alpha / 100;
if (alpha1 == 0) {
continue;
}
int color2 = fusion.data[off];
int alpha2 = (color2 >>> 24) * fusion.alpha / 100;
int newAlpha = alpha1 + alpha2 - alpha1 * alpha2 / 255;
if (newAlpha > 0) {
int alpha12 = alpha1 * alpha2 / 255;
int alpha1n2 = alpha1 * (alpha2 ^ 0xff) / 255;
int alphan12 = (alpha1 ^ 0xff) * alpha2 / 255;
int color = newAlpha << 24;
int c1, c2;
c1 = (color1 >>> 16 & 0xff);
c2 = (color2 >>> 16 & 0xff);
color |= (alpha1n2 * c1 + alphan12 * c2 + ((c1 <= 127) ? (alpha12 * 2 * c1 * c2 / 255)
: (alpha12 * ((2 * (c1 ^ 0xff) * (c2 ^ 0xff) / 255) ^ 0xff))))
/ newAlpha << 16;
c1 = (color1 >>> 8 & 0xff);
c2 = (color2 >>> 8 & 0xff);
color |= (alpha1n2 * c1 + alphan12 * c2 + ((c1 <= 127) ? (alpha12 * 2 * c1 * c2 / 255)
: (alpha12 * ((2 * (c1 ^ 0xff) * (c2 ^ 0xff) / 255) ^ 0xff))))
/ newAlpha << 8;
c1 = color1 & 0xff;
c2 = color2 & 0xff;
color |= (alpha1n2 * c1 + alphan12 * c2 + ((c1 <= 127) ? (alpha12 * 2 * c1 * c2 / 255)
: (alpha12 * ((2 * (c1 ^ 0xff) * (c2 ^ 0xff) / 255) ^ 0xff))))
/ newAlpha;
fusion.data[off] = color;
}
}
}
fusion.alpha = 100;
}
// Soft Light Mode
// A < 0.5 => C = (2*A - 1) * (B - B^2) + B
// A > 0.5 => C = (2*A - 1) * (sqrt(B) - B) + B
public void fusionWithSoftLightFullAlpha(CPLayer fusion, CPRect rc) {
CPRect rect = new CPRect(0, 0, width, height);
rect.clip(rc);
for (int j = rect.top; j < rect.bottom; j++) {
int off = rect.left + j * width;
for (int i = rect.left; i < rect.right; i++, off++) {
int color1 = data[off];
int alpha1 = (color1 >>> 24) * alpha / 100;
if (alpha1 == 0) {
continue;
}
int color2 = fusion.data[off];
int alpha2 = (color2 >>> 24) * fusion.alpha / 100;
int newAlpha = alpha1 + alpha2 - alpha1 * alpha2 / 255;
if (newAlpha > 0) {
int alpha12 = alpha1 * alpha2 / 255;
int alpha1n2 = alpha1 * (alpha2 ^ 0xff) / 255;
int alphan12 = (alpha1 ^ 0xff) * alpha2 / 255;
int color = newAlpha << 24;
int c1, c2;
c1 = (color1 >>> 16 & 0xff);
c2 = (color2 >>> 16 & 0xff);
color |= (alpha1n2 * c1 + alphan12 * c2 + ((c1 <= 127) ? (alpha12 * ((2 * c1 - 255)
* softLightLUTSquare[c2] / 255 + c2)) : (alpha12 * ((2 * c1 - 255)
* softLightLUTSquareRoot[c2] / 255 + c2))))
/ newAlpha << 16;
c1 = (color1 >>> 8 & 0xff);
c2 = (color2 >>> 8 & 0xff);
color |= (alpha1n2 * c1 + alphan12 * c2 + ((c1 <= 127) ? (alpha12 * ((2 * c1 - 255)
* softLightLUTSquare[c2] / 255 + c2)) : (alpha12 * ((2 * c1 - 255)
* softLightLUTSquareRoot[c2] / 255 + c2))))
/ newAlpha << 8;
c1 = color1 & 0xff;
c2 = color2 & 0xff;
color |= (alpha1n2 * c1 + alphan12 * c2 + ((c1 <= 127) ? (alpha12 * ((2 * c1 - 255)
* softLightLUTSquare[c2] / 255 + c2)) : (alpha12 * ((2 * c1 - 255)
* softLightLUTSquareRoot[c2] / 255 + c2))))
/ newAlpha;
fusion.data[off] = color;
}
}
}
fusion.alpha = 100;
}
// Vivid Light Mode
// A < 0.5 => C = 1 - (1-B) / (2*A)
// A > 0.5 => C = B / (2*(1-A))
public void fusionWithVividLightFullAlpha(CPLayer fusion, CPRect rc) {
CPRect rect = new CPRect(0, 0, width, height);
rect.clip(rc);
for (int j = rect.top; j < rect.bottom; j++) {
int off = rect.left + j * width;
for (int i = rect.left; i < rect.right; i++, off++) {
int color1 = data[off];
int alpha1 = (color1 >>> 24) * alpha / 100;
if (alpha1 == 0) {
continue;
}
int color2 = fusion.data[off];
int alpha2 = (color2 >>> 24) * fusion.alpha / 100;
int newAlpha = alpha1 + alpha2 - alpha1 * alpha2 / 255;
if (newAlpha > 0) {
int alpha12 = alpha1 * alpha2 / 255;
int alpha1n2 = alpha1 * (alpha2 ^ 0xff) / 255;
int alphan12 = (alpha1 ^ 0xff) * alpha2 / 255;
int color = newAlpha << 24;
int c1, c2;
c1 = (color1 >>> 16 & 0xff);
c2 = (color2 >>> 16 & 0xff);
color |= (alpha1n2 * c1 + alphan12 * c2 + ((c1 <= 127) ? (alpha12 * ((c1 == 0) ? 0 : 255 - Math
.min(255, (255 - c2) * 255 / (2 * c1)))) : (alpha12 * (c1 == 255 ? 255 : Math.min(255, c2
* 255 / (2 * (255 - c1)))))))
/ newAlpha << 16;
c1 = (color1 >>> 8 & 0xff);
c2 = (color2 >>> 8 & 0xff);
color |= (alpha1n2 * c1 + alphan12 * c2 + ((c1 <= 127) ? (alpha12 * ((c1 == 0) ? 0 : 255 - Math
.min(255, (255 - c2) * 255 / (2 * c1)))) : (alpha12 * (c1 == 255 ? 255 : Math.min(255, c2
* 255 / (2 * (255 - c1)))))))
/ newAlpha << 8;
c1 = color1 & 0xff;
c2 = color2 & 0xff;
color |= (alpha1n2 * c1 + alphan12 * c2 + ((c1 <= 127) ? (alpha12 * ((c1 == 0) ? 0 : 255 - Math
.min(255, (255 - c2) * 255 / (2 * c1)))) : (alpha12 * (c1 == 255 ? 255 : Math.min(255, c2
* 255 / (2 * (255 - c1)))))))
/ newAlpha;
fusion.data[off] = color;
}
}
}
fusion.alpha = 100;
}
// Linear Light Mode
// C = B + 2*A -1
public void fusionWithLinearLightFullAlpha(CPLayer fusion, CPRect rc) {
CPRect rect = new CPRect(0, 0, width, height);
rect.clip(rc);
for (int j = rect.top; j < rect.bottom; j++) {
int off = rect.left + j * width;
for (int i = rect.left; i < rect.right; i++, off++) {
int color1 = data[off];
int alpha1 = (color1 >>> 24) * alpha / 100;
if (alpha1 == 0) {
continue;
}
int color2 = fusion.data[off];
int alpha2 = (color2 >>> 24) * fusion.alpha / 100;
int newAlpha = alpha1 + alpha2 - alpha1 * alpha2 / 255;
if (newAlpha > 0) {
int alpha12 = alpha1 * alpha2 / 255;
int alpha1n2 = alpha1 * (alpha2 ^ 0xff) / 255;
int alphan12 = (alpha1 ^ 0xff) * alpha2 / 255;
int color = newAlpha << 24;
int c1, c2;
c1 = (color1 >>> 16 & 0xff);
c2 = (color2 >>> 16 & 0xff);
color |= (alpha1n2 * c1 + alphan12 * c2 + (alpha12 * Math.min(255, Math.max(0, c2 + 2 * c1 - 255))))
/ newAlpha << 16;
c1 = (color1 >>> 8 & 0xff);
c2 = (color2 >>> 8 & 0xff);
color |= (alpha1n2 * c1 + alphan12 * c2 + (alpha12 * Math.min(255, Math.max(0, c2 + 2 * c1 - 255))))
/ newAlpha << 8;
c1 = color1 & 0xff;
c2 = color2 & 0xff;
color |= (alpha1n2 * c1 + alphan12 * c2 + (alpha12 * Math.min(255, Math.max(0, c2 + 2 * c1 - 255))))
/ newAlpha;
fusion.data[off] = color;
}
}
}
fusion.alpha = 100;
}
// Pin Light Mode
// B > 2*A => C = 2*A
// B < 2*A-1 => C = 2*A-1
// else => C = B
public void fusionWithPinLightFullAlpha(CPLayer fusion, CPRect rc) {
CPRect rect = new CPRect(0, 0, width, height);
rect.clip(rc);
for (int j = rect.top; j < rect.bottom; j++) {
int off = rect.left + j * width;
for (int i = rect.left; i < rect.right; i++, off++) {
int color1 = data[off];
int alpha1 = (color1 >>> 24) * alpha / 100;
if (alpha1 == 0) {
continue;
}
int color2 = fusion.data[off];
int alpha2 = (color2 >>> 24) * fusion.alpha / 100;
int newAlpha = alpha1 + alpha2 - alpha1 * alpha2 / 255;
if (newAlpha > 0) {
int alpha12 = alpha1 * alpha2 / 255;
int alpha1n2 = alpha1 * (alpha2 ^ 0xff) / 255;
int alphan12 = (alpha1 ^ 0xff) * alpha2 / 255;
int color = newAlpha << 24;
int c1, c2, c3;
c1 = (color1 >>> 16 & 0xff);
c2 = (color2 >>> 16 & 0xff);
c3 = (c2 >= 2 * c1) ? (2 * c1) : (c2 <= 2 * c1 - 255) ? (2 * c1 - 255) : c2;
color |= (alpha1n2 * c1 + alphan12 * c2 + alpha12 * c3) / newAlpha << 16;
c1 = (color1 >>> 8 & 0xff);
c2 = (color2 >>> 8 & 0xff);
c3 = (c2 >= 2 * c1) ? (2 * c1) : (c2 <= 2 * c1 - 255) ? (2 * c1 - 255) : c2;
color |= (alpha1n2 * c1 + alphan12 * c2 + alpha12 * c3) / newAlpha << 8;
c1 = color1 & 0xff;
c2 = color2 & 0xff;
c3 = (c2 >= 2 * c1) ? (2 * c1) : (c2 <= 2 * c1 - 255) ? (2 * c1 - 255) : c2;
color |= (alpha1n2 * c1 + alphan12 * c2 + alpha12 * c3) / newAlpha;
fusion.data[off] = color;
}
}
}
fusion.alpha = 100;
}
public void setAlpha(int alpha) {
this.alpha = alpha;
}
public void setBlendMode(int blendMode) {
this.blendMode = blendMode;
}
public void rendererCheckboard(CPRect r) {
CPRect rect = new CPRect(0, 0, width, height);
rect.clip(r);
for (int j = rect.top; j < rect.bottom; j++) {
for (int i = rect.left; i < rect.right; i++) {
if ((i & 0x8) != 0 ^ (j & 0x8) != 0) {
data[i + j * width] = 0xffffffff;
} else {
data[i + j * width] = 0xffcccccc;
}
}
}
}
public void copyRegionHFlip(CPRect r, CPLayer source) {
CPRect rect = new CPRect(0, 0, width, height);
rect.clip(r);
for (int j = rect.top; j < rect.bottom; j++) {
for (int i = rect.left, s = rect.right - 1; i < rect.right; i++, s--) {
data[i + j * width] = source.data[s + j * width];
}
}
}
public void copyRegionVFlip(CPRect r, CPLayer source) {
CPRect rect = new CPRect(0, 0, width, height);
rect.clip(r);
for (int j = rect.top, s = rect.bottom - 1; j < rect.bottom; j++, s--) {
for (int i = rect.left; i < rect.right; i++) {
data[i + j * width] = source.data[i + s * width];
}
}
}
public void fillWithNoise(CPRect r) {
CPRect rect = new CPRect(0, 0, width, height);
rect.clip(r);
int value;
Random rnd = new Random();
for (int j = rect.top; j < rect.bottom; j++) {
for (int i = rect.left; i < rect.right; i++) {
value = rnd.nextInt();
value &= 0xff;
value |= (value << 8) | (value << 16) | 0xff000000;
data[i + j * width] = value;
}
}
}
public void fillWithColorNoise(CPRect r) {
CPRect rect = new CPRect(0, 0, width, height);
rect.clip(r);
Random rnd = new Random();
for (int j = rect.top; j < rect.bottom; j++) {
for (int i = rect.left; i < rect.right; i++) {
data[i + j * width] = rnd.nextInt() | 0xff000000;
}
}
}
public void invert(CPRect r) {
CPRect rect = new CPRect(0, 0, width, height);
rect.clip(r);
for (int j = rect.top; j < rect.bottom; j++) {
for (int i = rect.left; i < rect.right; i++) {
data[i + j * width] ^= 0xffffff;
}
}
}
public boolean hasAlpha() {
if (alpha != 100) {
return true;
}
int andPixels = 0xff000000;
int max = width * height;
for (int i = 0; i < max; i++) {
andPixels &= data[i];
}
return andPixels != 0xff000000;
}
public boolean hasAlpha(CPRect r) {
if (alpha != 100) {
return true;
}
CPRect rect = new CPRect(0, 0, width, height);
rect.clip(r);
int andPixels = 0xff000000;
for (int j = rect.top; j < rect.bottom; j++) {
int off = rect.left + j * width;
int max = off + rect.right - rect.left;
for (; off < max; off++) {
andPixels &= data[off];
}
}
return andPixels != 0xff000000;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -