Libraryless. Click here for Pure Java version (9439L/52K).
1 | sclass SinglePixelPosterizer is IPosterizer { |
2 | int brightnessLevels; |
3 | double factor1, factor2; |
4 | settable double drift; // between -1 and 1, normally |
5 | settable double antiDrift; // between -1 and 1 |
6 | |
7 | *(int *brightnessLevels) { |
8 | factor1 = doubleRatio(brightnessLevels, 256); |
9 | factor2 = doubleRatio(255, brightnessLevels-1); |
10 | } |
11 | |
12 | // 0..255 to 0..255 |
13 | public int get(int brightness) { |
14 | var inner = brightness*factor1+drift; |
15 | var posterized = ifloor(inner)+antiDrift; |
16 | ret clampUByteInt(iround(posterized*factor2)); |
17 | } |
18 | |
19 | [stdEq] |
20 | } |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034808 |
Snippet name: | SinglePixelPosterizer |
Eternal ID of this version: | #1034808/11 |
Text MD5: | 2a05c9756ff4e81936c405cea005886a |
Transpilation MD5: | 83e427ef459d19f8c860df89d2937a63 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-08-21 12:45:58 |
Source code size: | 575 bytes / 20 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 185 / 326 |
Version history: | 10 change(s) |
Referenced in: | [show references] |