Skip to content

Commit

Permalink
Chroma adopt
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed Feb 19, 2024
1 parent ebc9d4d commit 53b82a7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 26 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/com/awxkee/jxlcoder/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ class MainActivity : ComponentActivity() {
if (largeImageSize != null) {
var srcImage = JxlCoder().decodeSampled(
buffer4,
largeImageSize.width / 5,
largeImageSize.height / 5,
largeImageSize.width / 3,
largeImageSize.height / 3,
preferredColorConfig = PreferredColorConfig.RGBA_8888,
com.awxkee.jxlcoder.ScaleMode.FIT,
JxlResizeFilter.BICUBIC,
Expand Down
2 changes: 2 additions & 0 deletions jxlcoder/src/main/cpp/JniDecoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ jobject decodeSampledImageImpl(JNIEnv *env, std::vector<uint8_t> &imageData, jin
gamma = colorEncoding.gamma;
} else if (colorEncoding.transfer_function == JXL_TRANSFER_FUNCTION_709) {
function = EOTF_BT709;
} else if (colorEncoding.transfer_function == JXL_TRANSFER_FUNCTION_SRGB) {
function = EOTF_SRGB;
}

if (colorEncoding.primaries == JXL_PRIMARIES_2100) {
Expand Down
47 changes: 24 additions & 23 deletions jxlcoder/src/main/cpp/colorspaces/HDRTransferAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ namespace coder::HWY_NAMESPACE {
Eigen::Matrix3f *conversion,
const float gamma,
const bool useChromaticAdaptation) {
auto r = (float) half(data[0]);
auto g = (float) half(data[1]);
auto b = (float) half(data[2]);
float r = half_to_float(data[0]);
float g = half_to_float(data[1]);
float b = half_to_float(data[2]);

const auto adopt = getBradfordAdaptation();

Expand Down Expand Up @@ -186,16 +186,17 @@ namespace coder::HWY_NAMESPACE {
}

HWY_FAST_MATH_INLINE void
TransferROWU8(uint8_t *data, const float maxColors,
TransferROWU8(uint8_t *data,
const float maxColors,
const GammaCurve gammaCorrection,
const GamutTransferFunction function,
ToneMapper<FixedTag<float, 4>> *toneMapper,
Eigen::Matrix3f *conversion,
const float gamma,
bool useChromaticAdaptation) {
auto r = (float) data[0] / (float) maxColors;
auto g = (float) data[1] / (float) maxColors;
auto b = (float) data[2] / (float) maxColors;
float r = (float) data[0] / (float) maxColors;
float g = (float) data[1] / (float) maxColors;
float b = (float) data[2] / (float) maxColors;

const auto adopt = getBradfordAdaptation();

Expand Down Expand Up @@ -287,40 +288,40 @@ namespace coder::HWY_NAMESPACE {
}

if (gammaCorrection == Rec2020) {
data[0] = (uint8_t) clamp((float) bt2020GammaCorrection(r * maxColors), 0.0f,
data[0] = (uint8_t) clamp((float) bt2020GammaCorrection(r) * maxColors, 0.0f,
maxColors);
data[1] = (uint8_t) clamp((float) bt2020GammaCorrection(g * maxColors), 0.0f,
data[1] = (uint8_t) clamp((float) bt2020GammaCorrection(g) * maxColors, 0.0f,
maxColors);
data[2] = (uint8_t) clamp((float) bt2020GammaCorrection(b * maxColors), 0.0f,
data[2] = (uint8_t) clamp((float) bt2020GammaCorrection(b) * maxColors, 0.0f,
maxColors);
} else if (gammaCorrection == DCIP3) {
data[0] = (uint8_t) clamp((float) dciP3PQGammaCorrection(r * maxColors), 0.0f,
data[0] = (uint8_t) clamp((float) dciP3PQGammaCorrection(r) * maxColors, 0.0f,
maxColors);
data[1] = (uint8_t) clamp((float) dciP3PQGammaCorrection(g * maxColors), 0.0f,
data[1] = (uint8_t) clamp((float) dciP3PQGammaCorrection(g) * maxColors, 0.0f,
maxColors);
data[2] = (uint8_t) clamp((float) dciP3PQGammaCorrection(b * maxColors), 0.0f,
data[2] = (uint8_t) clamp((float) dciP3PQGammaCorrection(b) * maxColors, 0.0f,
maxColors);
} else if (gammaCorrection == GAMMA) {
const float gammaEval = 1.f / gamma;
data[0] = (uint8_t) clamp((float) gammaOtf(r * maxColors, gammaEval), 0.0f,
data[0] = (uint8_t) clamp((float) gammaOtf(r, gammaEval) * maxColors, 0.0f,
maxColors);
data[1] = (uint8_t) clamp((float) gammaOtf(g * maxColors, gammaEval), 0.0f,
data[1] = (uint8_t) clamp((float) gammaOtf(g, gammaEval) * maxColors, 0.0f,
maxColors);
data[2] = (uint8_t) clamp((float) gammaOtf(b * maxColors, gammaEval), 0.0f,
data[2] = (uint8_t) clamp((float) gammaOtf(b, gammaEval) * maxColors, 0.0f,
maxColors);
} else if (gammaCorrection == Rec709) {
data[0] = (uint8_t) clamp((float) LinearITUR709ToITUR709(r * maxColors), 0.0f,
data[0] = (uint8_t) clamp((float) LinearITUR709ToITUR709(r) * maxColors, 0.0f,
maxColors);
data[1] = (uint8_t) clamp((float) LinearITUR709ToITUR709(g * maxColors), 0.0f,
data[1] = (uint8_t) clamp((float) LinearITUR709ToITUR709(g) * maxColors, 0.0f,
maxColors);
data[2] = (uint8_t) clamp((float) LinearITUR709ToITUR709(b * maxColors), 0.0f,
data[2] = (uint8_t) clamp((float) LinearITUR709ToITUR709(b) * maxColors, 0.0f,
maxColors);
} else if (gammaCorrection == sRGB) {
data[0] = (uint8_t) clamp((float) LinearSRGBTosRGB(r * maxColors), 0.0f,
data[0] = (uint8_t) clamp((float) LinearSRGBTosRGB(r) * maxColors, 0.0f,
maxColors);
data[1] = (uint8_t) clamp((float) LinearSRGBTosRGB(g * maxColors), 0.0f,
data[1] = (uint8_t) clamp((float) LinearSRGBTosRGB(g) * maxColors, 0.0f,
maxColors);
data[2] = (uint8_t) clamp((float) LinearSRGBTosRGB(b * maxColors), 0.0f,
data[2] = (uint8_t) clamp((float) LinearSRGBTosRGB(b) * maxColors, 0.0f,
maxColors);
} else {
data[0] = (uint8_t) clamp((float) r * maxColors, 0.0f, maxColors);
Expand Down Expand Up @@ -932,7 +933,7 @@ namespace coder {
}

void HDRTransferAdapter::transfer() {
auto maxColors = powf(2, (float) this->bitDepth) - 1;
auto maxColors = std::pow(2, (float) this->bitDepth) - 1;
coder::ProcessCPUDispatcher(this->rgbaData, this->width, this->height, this->halfFloats,
this->stride, maxColors, this->gammaCorrection,
this->function, this->toneMapper,
Expand Down
2 changes: 1 addition & 1 deletion jxlcoder/src/main/cpp/colorspaces/eotf-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ namespace coder::HWY_NAMESPACE {
if (linear <= 0.0031308f) {
return 12.92f * linear;
} else {
return 1.055f * pow(linear, 1.0f / 2.4f) - 0.055f;
return 1.055f * std::pow(linear, 1.0f / 2.4f) - 0.055f;
}
}

Expand Down

0 comments on commit 53b82a7

Please sign in to comment.