@@ -138,7 +138,7 @@ - (nullable NSData *)encode:(nonnull JXLSystemImage *)platformImage
138138 }
139139}
140140
141- - (CGSize)getSize : (nonnull NSInputStream *)inputStream error : (NSError *_Nullable * _Nullable)error {
141+ - (CGSize)getSize : (nonnull NSInputStream *)inputStream error : (NSError *_Nullable * _Nullable)error {
142142 try {
143143 int buffer_length = 30196 ;
144144 std::vector<uint8_t > buffer;
@@ -188,8 +188,9 @@ - (CGSize)getSize:(nonnull NSInputStream *)inputStream error:(NSError *_Nullabl
188188}
189189
190190- (nullable JXLSystemImage *)decode : (nonnull NSInputStream *)inputStream
191- sampleSize : (CGSize)sampleSize
192- error : (NSError *_Nullable * _Nullable)error {
191+ sampleSize : (CGSize)sampleSize
192+ pixelFormat : (JXLPreferredPixelFormat)pixelFormat
193+ error : (NSError *_Nullable * _Nullable)error {
193194 try {
194195 int buffer_length = 30196 ;
195196 std::vector<uint8_t > buffer;
@@ -234,9 +235,23 @@ - (nullable JXLSystemImage *)decode:(nonnull NSInputStream *)inputStream
234235 std::vector<uint8_t > outputData;
235236 int components;
236237 JxlExposedOrientation jxlExposedOrientation = Identity;
238+ JxlDecodingPixelFormat pixelFormat;
239+ switch (pixelFormat) {
240+ case optimal:
241+ pixelFormat = optimal;
242+ break ;
243+ case r8:
244+ pixelFormat = r8;
245+ break ;
246+ case float16:
247+ pixelFormat = float16;
248+ break ;
249+ }
237250 auto decoded = DecodeJpegXlOneShot (imageData.data (), imageData.size (),
238251 &outputData, &xSize, &ySize,
239- &iccProfile, &depth, &components, &useFloats, &jxlExposedOrientation);
252+ &iccProfile, &depth, &components,
253+ &useFloats, &jxlExposedOrientation,
254+ pixelFormat);
240255 if (!decoded) {
241256 *error = [[NSError alloc ] initWithDomain: @" JXLCoder" code: 500 userInfo: @{ NSLocalizedDescriptionKey : @" Failed to decode JXL image" }];
242257 return nil ;
@@ -252,8 +267,8 @@ - (nullable JXLSystemImage *)decode:(nonnull NSInputStream *)inputStream
252267
253268 if (sampleSize.width > 0 && sampleSize.height > 0 ) {
254269 auto scaleResult = [RgbaScaler scaleData: outputData width: (int )xSize height: (int )ySize
255- newWidth: (int )sampleSize.width newHeight: (int )sampleSize.height
256- components: components pixelFormat: useFloats ? kF16 : kU8 ];
270+ newWidth: (int )sampleSize.width newHeight: (int )sampleSize.height
271+ components: components pixelFormat: useFloats ? kF16 : kU8 ];
257272 if (!scaleResult) {
258273 *error = [[NSError alloc ] initWithDomain: @" JXLCoder" code: 500 userInfo: @{ NSLocalizedDescriptionKey : @" Rescale image has failed" }];
259274 return nil ;
0 commit comments