Skip to content

Commit

Permalink
2.5.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
KrLite committed Jul 13, 2023
1 parent 78cf138 commit c8a0ba5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.awt.*;

import static net.krlite.equator.visual.color.Colorspace.*;
import static net.krlite.equator.visual.color.Palette.TRANSPARENT;
import static net.krlite.equator.visual.color.Palette.*;

public class AccurateColor {
// Static Constructors
Expand All @@ -16,6 +16,10 @@ public class AccurateColor {
return color == null ? TRANSPARENT : color;
}

public static @NotNull Colorspace notnull(@Nullable Colorspace colorspace) {
return colorspace == null ? RGB : colorspace;
}

public static AccurateColor fromARGB(long argb) {
return new AccurateColor(RGB.fromInt((int) argb), argb > 0xFFFFFF ? ((argb >> 24) & 0xFF) / 255.0 : 1);
}
Expand All @@ -28,8 +32,8 @@ public static AccurateColor fromRGB(int red, int green, int blue) {
return fromRGB(red, green, blue, 255);
}

public static AccurateColor fromColor(Color color) {
return new AccurateColor(RGB.fromColor(color), color.getAlpha() / 255.0);
public static AccurateColor fromColor(@Nullable Color color) {
return color == null ? TRANSPARENT : new AccurateColor(RGB.fromColor(color), color.getAlpha() / 255.0);
}

public static AccurateColor fromHexString(String hexString) {
Expand All @@ -39,14 +43,14 @@ public static AccurateColor fromHexString(String hexString) {

// Constructors

protected AccurateColor(Colorspace colorspace, double[] color, double opacity, boolean transparent) {
this.colorspace = colorspace;
protected AccurateColor(@Nullable Colorspace colorspace, double[] color, double opacity, boolean transparent) {
this.colorspace = notnull(colorspace);
this.color = color;
this.opacity = Theory.clamp(opacity, 0, 1);
this.transparent = transparent;
}

public AccurateColor(Colorspace colorspace, double[] color, double opacity) {
public AccurateColor(@Nullable Colorspace colorspace, double[] color, double opacity) {
this(colorspace, color, opacity, false);
}

Expand Down Expand Up @@ -74,8 +78,8 @@ public AccurateColor(double gray) {
this(gray, 1);
}

public AccurateColor(AccurateColor another, Colorspace colorspace) {
this(colorspace, colorspace.from(another.color(), another.colorspace()), another.opacity(), !another.hasColor());
public AccurateColor(@Nullable AccurateColor another, @Nullable Colorspace colorspace) {
this(colorspace, notnull(colorspace).from(notnull(another).color(), notnull(another).colorspace()), notnull(another).opacity(), !notnull(another).hasColor());
}

// Fields
Expand Down Expand Up @@ -219,7 +223,7 @@ public double H() {

// Mutators

public AccurateColor colorspace(Colorspace colorspace) {
public AccurateColor colorspace(@Nullable Colorspace colorspace) {
return colorspace() == colorspace ? this : new AccurateColor(this, colorspace);
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ minecraft_version = 1.19
yarn_mappings = 1.19+build.4
loader_version = 0.14.21

mod_version = 2.5.2
mod_version = 2.5.2.1
maven_group = net.krlite
archives_base_name = equator

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/krlite/equator/render/renderer/Flat.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public Rectangle(
this.colorTopRight = AccurateColor.notnull(colorTopRight) .colorspace(colorspace);

this.opacityMultiplier = Theory.clamp(opacityMultiplier, 0, 1);
this.colorspace = colorspace == null ? Colorspace.RGB : colorspace;
this.colorspace = AccurateColor.notnull(colorspace);
this.mode = mode;
}

Expand Down
22 changes: 13 additions & 9 deletions src/main/java/net/krlite/equator/visual/color/AccurateColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.awt.*;

import static net.krlite.equator.visual.color.Colorspace.*;
import static net.krlite.equator.visual.color.Palette.TRANSPARENT;
import static net.krlite.equator.visual.color.Palette.*;

public class AccurateColor {
// Static Constructors
Expand All @@ -16,6 +16,10 @@ public class AccurateColor {
return color == null ? TRANSPARENT : color;
}

public static @NotNull Colorspace notnull(@Nullable Colorspace colorspace) {
return colorspace == null ? RGB : colorspace;
}

public static AccurateColor fromARGB(long argb) {
return new AccurateColor(RGB.fromInt((int) argb), argb > 0xFFFFFF ? ((argb >> 24) & 0xFF) / 255.0 : 1);
}
Expand All @@ -28,8 +32,8 @@ public static AccurateColor fromRGB(int red, int green, int blue) {
return fromRGB(red, green, blue, 255);
}

public static AccurateColor fromColor(Color color) {
return new AccurateColor(RGB.fromColor(color), color.getAlpha() / 255.0);
public static AccurateColor fromColor(@Nullable Color color) {
return color == null ? TRANSPARENT : new AccurateColor(RGB.fromColor(color), color.getAlpha() / 255.0);
}

public static AccurateColor fromHexString(String hexString) {
Expand All @@ -39,14 +43,14 @@ public static AccurateColor fromHexString(String hexString) {

// Constructors

protected AccurateColor(Colorspace colorspace, double[] color, double opacity, boolean transparent) {
this.colorspace = colorspace;
protected AccurateColor(@Nullable Colorspace colorspace, double[] color, double opacity, boolean transparent) {
this.colorspace = notnull(colorspace);
this.color = color;
this.opacity = Theory.clamp(opacity, 0, 1);
this.transparent = transparent;
}

public AccurateColor(Colorspace colorspace, double[] color, double opacity) {
public AccurateColor(@Nullable Colorspace colorspace, double[] color, double opacity) {
this(colorspace, color, opacity, false);
}

Expand Down Expand Up @@ -74,8 +78,8 @@ public AccurateColor(double gray) {
this(gray, 1);
}

public AccurateColor(AccurateColor another, Colorspace colorspace) {
this(colorspace, colorspace.from(another.color(), another.colorspace()), another.opacity(), !another.hasColor());
public AccurateColor(@Nullable AccurateColor another, @Nullable Colorspace colorspace) {
this(colorspace, notnull(colorspace).from(notnull(another).color(), notnull(another).colorspace()), notnull(another).opacity(), !notnull(another).hasColor());
}

// Fields
Expand Down Expand Up @@ -219,7 +223,7 @@ public double H() {

// Mutators

public AccurateColor colorspace(Colorspace colorspace) {
public AccurateColor colorspace(@Nullable Colorspace colorspace) {
return colorspace() == colorspace ? this : new AccurateColor(this, colorspace);
}

Expand Down

0 comments on commit c8a0ba5

Please sign in to comment.