我想借這個公式:公式轉換成Java
,並轉換成Java代碼。我不認爲下面的代碼是正確的,因爲我認爲我得到了錯誤的結果。
return (int)(2 * a * b + Math.pow(a, 2) * (1 - 2 * b));
這裏是我一起工作的原始圖像: http://images2.fanpop.com/images/photos/4800000/Beach-beaches-4843817-1280-800.jpg
A =圖片鏈接
B =圖片鏈接
下面的反轉是我會期待什麼我輸出看起來像(PhotoShop的):
這是我的輸出實際上看起來像(我的應用程序):
Invert inv = new Invert();
inv.setStage(stage);
inv.setParent(this);
BufferedImage img = inv.filter();
int[] invPixels = new int[stage.width * stage.height];
img.getRGB(0, 0, stage.width, stage.height, invPixels, 0, stage.width);
for(int i = 0; i < ImageSync.originalPixels.length; i++){
int fg = invPixels[i];
int bg = ImageSync.originalPixels[i];
int color = Blends.softLight(fg, bg);
invPixels[i] = color;
}
img = new BufferedImage(stage.width, stage.height, BufferedImage.TYPE_INT_ARGB);
img.setRGB(0, 0, stage.width, stage.height, invPixels, 0, stage.width);
Preview.setImage(img);
stage.preview = Preview.getImage();
this.repaint();
柔光:
public static int softLight(int background, int foreground){
return (2 * background * foreground) + ((background * background) * (1 - 2 * foreground));
}
看起來很對我。我認爲如果你的回答不正確,你可能會遇到精度問題。 – femtoRgon
@JarrodRoberson。那麼,我沒有看到任何優先問題。 –
你能發表一個你認爲你的'錯誤結果'是什麼樣的例子嗎? –