Skip to content

Conversation

@ItsJuls
Copy link

@ItsJuls ItsJuls commented Dec 4, 2025

Pull Request

Description

Fixes/Addresses #537 and adds a new ScaleColorSampler.java to the image library addon

Changelog

  • Added ScaleColorSampler.java and its templates, registries
  • Tested within a development server with the interpolation features

Checklist

Mandatory checks

  • The base branch of this PR is an unreleased version branch (that has a ver/ prefix)
    or is a branch that is intended to be merged into a version branch.
  • There are no already existing PRs that provide the same changes.
  • The PR is within the scope of Terra (i.e. is something a configurable terrain generator should be doing).
  • Changes follow the code style for this project.
  • I have read the CONTRIBUTING.md
    document in the root of the git repository.

Types of changes

  • Bug Fix
  • Build system
  • Documentation
  • New Feature
  • Performance
  • Refactoring
  • Repository
  • Revert
  • Style
  • Tests
  • Translation

Compatibility

  • Introduces a breaking change
  • Introduces new functionality in a backwards compatible way.
  • Introduces bug fixes

Documentation

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

Testing

  • I have added tests to cover my changes.
  • All new and existing tests passed.

Licensing

  • I am the original author of this code, and I am willing to
    release it under GPLv3.
  • I am not the original author of this code, but it is in public domain or
    released under GPLv3 or a compatible license.

Copy link
Member

@solonovamax solonovamax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code also probably needs a reformat

Comment on lines +97 to +99
private double lerp(double start, double end, double t) {
return start + t * (end - start);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am very confident we have a lerp elsewhere, try to use that instead.

Comment on lines +101 to +103
private double cubic(double p0, double p1, double p2, double p3, double t) {
return 0.5 * ((2 * p1) + (-p0 + p2) * t + (2 * p0 - 5 * p1 + 4 * p2 - p3) * t * t + (-p0 + 3 * p1 - 3 * p2 + p3) * t * t * t);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as lerp

Comment on lines +105 to +112
private int getA(int c) { return (c >> 24) & 0xFF; }
private int getR(int c) { return (c >> 16) & 0xFF; }
private int getG(int c) { return (c >> 8) & 0xFF; }
private int getB(int c) { return c & 0xFF; }

private int argb(int a, int r, int g, int b) {
return (a << 24) | (r << 16) | (g << 8) | b;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ColorUtil

Comment on lines +114 to +116
private int clamp(double val) {
return Math.max(0, Math.min(255, (int) val));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be surprised if we don't have that elsewhere

Comment on lines +82 to +85
int a = (int) lerp(lerp(getA(c00), getA(c10), tx), lerp(getA(c01), getA(c11), tx), tz);
int r = (int) lerp(lerp(getR(c00), getR(c10), tx), lerp(getR(c01), getR(c11), tx), tz);
int g = (int) lerp(lerp(getG(c00), getG(c10), tx), lerp(getG(c01), getG(c11), tx), tz);
int b = (int) lerp(lerp(getB(c00), getB(c10), tx), lerp(getB(c01), getB(c11), tx), tz);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty sure the nested lerps will end up performing a few additional operations which could be factored out
no clue if the JVM will do that for you or not, though

Comment on lines +37 to +45
switch (method) {
case BILINEAR:
return applyBilinear(sx, sz);
case BICUBIC:
return applyBicubic(sx, sz);
case NEAREST:
default:
return sampler.apply((int) sx, (int) sz);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use an enhanced switch with the arrow syntax

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants