That fuck shit the fascists are using
at master 62 lines 2.2 kB view raw
1/** 2 * Source: https://github.com/hsch/blurhash-java 3 * 4 * Copyright (c) 2019 Hendrik Schnepel 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 7 * associated documentation files (the "Software"), to deal in the Software without restriction, 8 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 9 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 10 * furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included in all copies or 13 * substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 16 * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 */ 21package org.tm.archive.blurhash; 22 23final class BlurHashUtil { 24 25 static double sRGBToLinear(long value) { 26 double v = value / 255.0; 27 if (v <= 0.04045) { 28 return v / 12.92; 29 } else { 30 return Math.pow((v + 0.055) / 1.055, 2.4); 31 } 32 } 33 34 static long linearTosRGB(double value) { 35 double v = Math.max(0, Math.min(1, value)); 36 if (v <= 0.0031308) { 37 return (long)(v * 12.92 * 255 + 0.5); 38 } else { 39 return (long)((1.055 * Math.pow(v, 1 / 2.4) - 0.055) * 255 + 0.5); 40 } 41 } 42 43 static double signPow(double val, double exp) { 44 return Math.copySign(Math.pow(Math.abs(val), exp), val); 45 } 46 47 static double max(double[][] values, int from, int endExclusive) { 48 double result = Double.NEGATIVE_INFINITY; 49 for (int i = from; i < endExclusive; i++) { 50 for (int j = 0; j < values[i].length; j++) { 51 double value = values[i][j]; 52 if (value > result) { 53 result = value; 54 } 55 } 56 } 57 return result; 58 } 59 60 private BlurHashUtil() { 61 } 62}