Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

33
LINES

< > BotCompany Repo | #1034177 // Decolorizer

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (10423L/58K).

sinterface Decolorizer {
  int toGrayScale(int rgb);
  
  default int toGrayScale(Color color) {
    ret toGrayScale(colorToRGBInt(color));
  }
  
  srecord Red is Decolorizer {
    public int toGrayScale(int rgb) { ret (rgb >> 16) & 0xFF; }
  }
  
  srecord Green is Decolorizer {
    public int toGrayScale(int rgb) { ret (rgb >> 8) & 0xFF; }
  }
  
  srecord Blue is Decolorizer {
    public int toGrayScale(int rgb) { ret rgb & 0xFF; }
  }
  
  srecord Alpha is Decolorizer {
    public int toGrayScale(int rgb) { ret (rgb >> 24) & 0xFF; }
  }
  
  // just the average of the 3 channels
  srecord Simple is Decolorizer {
    public int toGrayScale(int rgb) {
      int r = (rgb >> 16) & 0xFF;
      int g = (rgb >> 8) & 0xFF;
      int b = rgb & 0xFF;
      ret (r+g+b+1)/3;
    }
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034177
Snippet name: Decolorizer
Eternal ID of this version: #1034177/7
Text MD5: c586f5983147301b206087a71a2b996b
Transpilation MD5: 05c57562e3d70589260b98f39ac7438d
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-08-02 20:35:45
Source code size: 822 bytes / 33 lines
Pitched / IR pitched: No / No
Views / Downloads: 169 / 312
Version history: 6 change(s)
Referenced in: #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167)