Skip to content

Commit 401299c

Browse files
committed
encoding bug fixes
1 parent a9e11e0 commit 401299c

File tree

5 files changed

+26
-15
lines changed

5 files changed

+26
-15
lines changed

.swiftpm/xcode/xcuserdata/radzivonbartoshyk.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<key>JxlCoder.xcscheme_^#shared#^_</key>
1818
<dict>
1919
<key>orderHint</key>
20-
<integer>2</integer>
20+
<integer>1</integer>
2121
</dict>
2222
<key>jxlcoder.xcscheme_^#shared#^_</key>
2323
<dict>

JxlCoder.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'JxlCoder'
3-
s.version = '1.2.4'
3+
s.version = '1.2.5'
44
s.summary = 'JXL coder for iOS and MacOS'
55
s.description = 'Provides support for JXL files in iOS and MacOS'
66
s.homepage = 'https://github.com/awxkee/jxl-coder-swift'

Sources/jxlc/JxlInternalCoder.mm

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ static inline float JXLGetDistance(const int quality)
4646
{
4747
if (quality == 0)
4848
return(1.0f);
49-
if (quality >= 30)
50-
return std::clamp((0.1f+(float) (100-std::min(100.0f, (float)quality))*0.09f), 0.0f, 15.0f);
51-
return std::clamp((6.24f+(float) pow(2.5f,(30.0-(float)quality)/5.0)/6.25f), 0.0f, 15.0f);
49+
float distance = quality >= 100 ? 0.0
50+
: quality >= 30
51+
? 0.1 + (100 - quality) * 0.09
52+
: 53.0 / 3000.0 * quality * quality -
53+
23.0 / 20.0 * quality + 25.0;
54+
return distance;
5255
}
5356

5457
@implementation JxlInternalCoder

Sources/jxlc/JxlWorker.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,7 @@ bool EncodeJxlOneshot(const std::vector<uint8_t> &pixels, const uint32_t xsize,
259259
JxlEncoderInitBasicInfo(&basic_info);
260260
basic_info.xsize = xsize;
261261
basic_info.ysize = ysize;
262-
basic_info.bits_per_sample = 32;
263-
basic_info.exponent_bits_per_sample = 8;
262+
basic_info.bits_per_sample = 8;
264263
basic_info.uses_original_profile = compression_option == loosy ? JXL_FALSE : JXL_TRUE;
265264
basic_info.num_color_channels = 3;
266265

@@ -299,18 +298,19 @@ bool EncodeJxlOneshot(const std::vector<uint8_t> &pixels, const uint32_t xsize,
299298
JxlEncoderFrameSettings *frameSettings =
300299
JxlEncoderFrameSettingsCreate(enc.get(), nullptr);
301300

302-
if (JXL_ENC_SUCCESS !=
303-
JxlEncoderAddImageFrame(frameSettings, &pixel_format,
304-
(void *) pixels.data(),
305-
sizeof(uint8_t) * pixels.size())) {
301+
JxlBitDepth depth;
302+
depth.bits_per_sample = 8;
303+
depth.exponent_bits_per_sample = 0;
304+
depth.type = JXL_BIT_DEPTH_FROM_PIXEL_FORMAT;
305+
if (JXL_ENC_SUCCESS != JxlEncoderSetFrameBitDepth(frameSettings, &depth)) {
306306
return false;
307307
}
308308

309-
if (compression_option == loseless &&
310-
JXL_ENC_SUCCESS != JxlEncoderSetFrameDistance(frameSettings, JXL_TRUE)) {
309+
if (JXL_ENC_SUCCESS != JxlEncoderSetFrameLossless(frameSettings, compression_option == loseless)) {
311310
return false;
312-
} else if (compression_option == loosy &&
313-
JXL_ENC_SUCCESS !=
311+
}
312+
313+
if (JXL_ENC_SUCCESS !=
314314
JxlEncoderSetFrameDistance(frameSettings, compression_distance)) {
315315
return false;
316316
}
@@ -320,6 +320,13 @@ bool EncodeJxlOneshot(const std::vector<uint8_t> &pixels, const uint32_t xsize,
320320
return false;
321321
}
322322

323+
if (JXL_ENC_SUCCESS !=
324+
JxlEncoderAddImageFrame(frameSettings, &pixel_format,
325+
(void *) pixels.data(),
326+
sizeof(uint8_t) * pixels.size())) {
327+
return false;
328+
}
329+
323330
JxlEncoderCloseInput(enc.get());
324331

325332
compressed->resize(64);

Sources/jxlc/half.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
// check C++11 language features
4040
#if defined(__clang__) // clang
41+
#pragma clang fp contract(fast) exceptions(ignore) reassociate(on)
4142
#if __has_feature(cxx_static_assert) && !defined(HALF_ENABLE_CPP11_STATIC_ASSERT)
4243
#define HALF_ENABLE_CPP11_STATIC_ASSERT 1
4344
#endif

0 commit comments

Comments
 (0)