-
Notifications
You must be signed in to change notification settings - Fork 127
A scaling function for ColorSampler #539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
solonovamax
left a comment
There was a problem hiding this 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
| private double lerp(double start, double end, double t) { | ||
| return start + t * (end - start); | ||
| } |
There was a problem hiding this comment.
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.
| 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); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as lerp
| 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; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ColorUtil
| private int clamp(double val) { | ||
| return Math.max(0, Math.min(255, (int) val)); | ||
| } |
There was a problem hiding this comment.
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
| 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); |
There was a problem hiding this comment.
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
| switch (method) { | ||
| case BILINEAR: | ||
| return applyBilinear(sx, sz); | ||
| case BICUBIC: | ||
| return applyBicubic(sx, sz); | ||
| case NEAREST: | ||
| default: | ||
| return sampler.apply((int) sx, (int) sz); | ||
| } |
There was a problem hiding this comment.
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
Pull Request
Description
Fixes/Addresses #537 and adds a new ScaleColorSampler.java to the image library addon
Changelog
Checklist
Mandatory checks
ver/prefix)or is a branch that is intended to be merged into a version branch.
CONTRIBUTING.mddocument in the root of the git repository.
Types of changes
Compatibility
Documentation
Testing
Licensing
release it under GPLv3.
released under GPLv3 or a compatible license.