static RGBImage toGrayScale(RGBImage img, int bits) { int steps = 1 << bits; int w = img.getWidth(), h = img.getHeight(); RGBImage bw = new RGBImage(w, h); for (int y = 0; y < h; y++) for (int x = 0; x < w; x++) { float b = img.getPixel(x, y).getBrightness(); int bx = (int) (b*steps); double b2 = Math.min(1f, Math.max(0f, bx/(float) steps)); bw.setPixel(x, y, new RGB(b2)); } return bw; }
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1001445 |
Snippet name: | toGrayScale |
Eternal ID of this version: | #1001445/1 |
Text MD5: | e348ea765c17e5525734b94c038c9500 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-10-16 17:55:35 |
Source code size: | 444 bytes / 13 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 635 / 872 |
Referenced in: | #1002427 - Accellerating 629 (SPIKE) #1006654 - Standard functions list 2 (LIVE, continuation of #761) #3000382 - Answer for ferdie (>> t = 1, f = 0) #3000383 - Answer for funkoverflow (>> t=1, f=0 okay) |