com.parzivail.util.client.NativeImageUtil Maven / Gradle / Ivy
package com.parzivail.util.client;
import F;
import I;
import com.parzivail.util.data.TintedIdentifier;
import com.parzivail.util.math.MathUtil;
import net.minecraft.class_3532;
import net.minecraft.class_5253;
public class NativeImageUtil
{
public static int blendColorsOnSrcAlpha(int dest, int src, int tint, TintedIdentifier.Mode tintMode)
{
var destA = class_5253.class_8045.method_48342(dest) / 255f;
var destR = class_5253.class_8045.method_48345(dest);
var destG = class_5253.class_8045.method_48346(dest);
var destB = class_5253.class_8045.method_48347(dest);
src = tint(src, tint, tintMode);
var srcA = class_5253.class_8045.method_48342(src) / 255f;
var srcR = class_5253.class_8045.method_48345(src);
var srcG = class_5253.class_8045.method_48346(src);
var srcB = class_5253.class_8045.method_48347(src);
var a = MathUtil.clamp((int)((destA + srcA) * 255f), 0, 255);
var r = MathUtil.clamp((int)((1 - srcA) * destR + srcA * srcR), 0, 255);
var g = MathUtil.clamp((int)((1 - srcA) * destG + srcA * srcG), 0, 255);
var b = MathUtil.clamp((int)((1 - srcA) * destB + srcA * srcB), 0, 255);
return class_5253.class_8045.method_48344(a, b, g, r);
}
public static int tint(int src, int tint, TintedIdentifier.Mode tintMode)
{
var srcA = class_5253.class_8045.method_48342(src);
var srcR = class_5253.class_8045.method_48345(src);
var srcG = class_5253.class_8045.method_48346(src);
var srcB = class_5253.class_8045.method_48347(src);
var tintA = class_5253.class_8045.method_48342(tint);
if (tintA == 0)
tintA = 255;
var tintR = class_5253.class_8045.method_48345(tint);
var tintG = class_5253.class_8045.method_48346(tint);
var tintB = class_5253.class_8045.method_48347(tint);
switch (tintMode)
{
case Multiply ->
{
srcA = (srcA * tintA) / 255;
srcR = (srcR * tintR) / 255;
srcG = (srcG * tintG) / 255;
srcB = (srcB * tintB) / 255;
}
case Add ->
{
srcR = class_3532.method_15340(srcR + tintR, 0, 255);
srcG = class_3532.method_15340(srcG + tintG, 0, 255);
srcB = class_3532.method_15340(srcB + tintB, 0, 255);
}
case Overlay ->
{
var srcRf = srcR / 255f;
var srcGf = srcG / 255f;
var srcBf = srcB / 255f;
var tintRf = tintR / 255f;
var tintGf = tintG / 255f;
var tintBf = tintB / 255f;
srcR = (int)(255 * class_3532.method_15363(srcRf < 0.5 ? 2 * srcRf * tintRf : (1 - 2 * (1 - srcRf) * (1 - tintRf)), 0, 1));
srcG = (int)(255 * class_3532.method_15363(srcGf < 0.5 ? 2 * srcGf * tintGf : (1 - 2 * (1 - srcGf) * (1 - tintGf)), 0, 1));
srcB = (int)(255 * class_3532.method_15363(srcBf < 0.5 ? 2 * srcBf * tintBf : (1 - 2 * (1 - srcBf) * (1 - tintBf)), 0, 1));
}
}
return class_5253.class_8045.method_48344(srcA, srcB, srcG, srcR);
}
public static int argbToAbgr(int value)
{
return class_5253.class_8045.method_48344((value >>> 24) & 0xFF, (value) & 0xFF, (value >>> 8) & 0xFF, (value >>> 16) & 0xFF);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy