-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroot.zig
More file actions
2715 lines (2392 loc) · 118 KB
/
root.zig
File metadata and controls
2715 lines (2392 loc) · 118 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const std = @import("std");
const config = @import("config");
const builtin = @import("builtin");
pub const c = @cImport({
@cInclude("jxl/cms.h");
@cInclude("jxl/cms_interface.h");
@cInclude("jxl/codestream_header.h");
@cInclude("jxl/color_encoding.h");
@cInclude("jxl/compressed_icc.h");
@cInclude("jxl/encode.h");
@cInclude("jxl/decode.h");
@cInclude("jxl/gain_map.h");
@cInclude("jxl/memory_manager.h");
@cInclude("jxl/parallel_runner.h");
@cInclude("jxl/resizable_parallel_runner.h");
@cInclude("jxl/stats.h");
@cInclude("jxl/thread_parallel_runner.h");
@cInclude("jxl/types.h");
@cInclude("jxl/version.h");
});
pub const InitOptions = struct {
/// This must be true for you to be able to call Codestream.BasicInfo.default
codestream_basic_info: bool = true,
/// This must be true for you to be able to call Codestream.ExtraChannelInfo.default
codestream_extra_channel_info: bool = true,
/// This must be true for you to be able to call Frame.BlendInfo.default
frame_blend_info: bool = true,
/// This must be true for you to be able to call Frame.Header.default
frame_header: bool = true,
};
pub fn init(options: InitOptions) !void {
if (options.codestream_basic_info) Codestream.BasicInfo._default_value = ._default();
if (options.codestream_extra_channel_info) {
inline for (@typeInfo(Codestream.ExtraChannelInfo._DefaultValues).@"struct".fields) |f| {
@field(Codestream.ExtraChannelInfo._default_values, f.name) = ._default(@field(Codestream.ExtraChannelType, f.name));
}
}
if (options.frame_blend_info) Frame.BlendInfo._default_value = ._default();
if (options.frame_header) Frame.Header._default_value = ._default();
Encoder._version_value = Encoder._version();
Decoder._version_value = Decoder._version();
}
pub const Cms = struct {
/// Represents an input or output colorspace to a color transform, as a serialized ICC profile.
pub const ColorProfile = extern struct {
/// The serialized ICC profile. This is guaranteed to be present and valid.
icc: ICCData,
/// Structured representation of the colorspace, if applicable. If all fields
/// are different from their "unknown" value, then this is equivalent to the
/// ICC representation of the colorspace. If some are "unknown", those that are
/// not are still valid and can still be used on their own if they are useful.
color_encoding: ColorEncoding,
/// Number of components per pixel. This can be deduced from the other
/// representations of the colorspace but is provided for convenience and
/// validation.
num_channels: usize,
pub const ICCData = extern struct {
data: [*]const u8,
size: usize,
test {
const T = @FieldType(c.JxlColorProfile, "icc");
std.debug.assert(@sizeOf(@This()) == @sizeOf(T));
inline for (@typeInfo(T).@"struct".fields, @typeInfo(@This()).@"struct".fields) |cf, f| {
std.debug.assert(@sizeOf(cf.type) == @sizeOf(f.type));
std.debug.assert(@bitOffsetOf(@This(), f.name) == @bitOffsetOf(T, cf.name));
}
}
};
test {
const T = c.JxlColorProfile;
std.debug.assert(@sizeOf(@This()) == @sizeOf(T));
inline for (@typeInfo(T).@"struct".fields, @typeInfo(@This()).@"struct".fields) |cf, f| {
std.debug.assert(@sizeOf(cf.type) == @sizeOf(f.type));
std.debug.assert(@bitOffsetOf(@This(), f.name) == @bitOffsetOf(T, cf.name));
}
}
};
/// Interface for performing colorspace transforms. The @c init function can be
/// called several times to instantiate several transforms, including before
/// other transforms have been destroyed.
pub const Interface = extern struct {
/// CMS-specific data that will be passed to @ref set_fields_from_icc.
_set_fields_data: ?*anyopaque,
/// Populates a @ref JxlColorEncoding from an ICC profile.
_set_fields_from_icc_fn: ?SetFieldsFromIccFn,
/// CMS-specific data that will be passed to @ref init.
_init_data: ?*anyopaque,
/// Prepares a colorspace transform as described in the documentation of @ref
/// jpegxl_cms_init_func.
_init_fn: InitFn,
/// Returns a buffer that can be used as input to @c run.
_get_src_buf_fn: GetBufferFn,
/// Returns a buffer that can be used as output from @c run.
_get_dst_buf_fn: GetBufferFn,
/// Executes the transform on a batch of pixels, per @ref jpegxl_cms_run_func.
_run_fn: RunFn,
/// Cleans up the transform.
_destroy_fn: DestroyFn,
/// Creates a CMS Interface from a Zig struct.
///
/// @param Instance: The type returned by `init` representing a specific transform session.
/// @param cms_ctx: Must implement `fn init(self, ...)` to create an Instance.
/// @param icc_ctx: May implement `fn setFieldsFromIcc(self, ...)` (Optional).
///
/// The context struct `Sub` must implement:
/// - `fn init(self: *Sub, num_threads: usize, pixels_per_thread: usize, input: *const ColorProfile, output: *const ColorProfile, intensity: f32) !?*Instance`
///
/// The `Instance` type returned by `init` must implement:
/// - `fn run(instance: *Instance, thread_id: usize, input: [*]const f32, output: [*]f32, num_pixels: usize) bool`
/// - `fn getSrcBuf(instance: *Instance, thread_id: usize) ?[*]f32`
/// - `fn getDstBuf(instance: *Instance, thread_id: usize) ?[*]f32`
/// - optional `fn destroy(instance: *Instance) void`
///
/// Additionally, `Sub` may implement:
/// - optional `fn setFieldsFromIcc(self: *Sub, icc: []const u8, encoding: *ColorEncoding, is_cmyk: *bool) bool`
/// Creates a CMS Interface from two Zig contexts.
///
///
/// Creates a CMS Interface from Zig contexts.
///
/// The `cms_ctx` must implement:
/// - `fn init(self: *Sub, num_threads: usize, pixels_per_thread: usize, in: *const ColorProfile, out: *const ColorProfile, intensity: f32) !*Instance`
/// Prepares a transformation session. Returns a pointer to a worker instance.
///
/// The `Instance` type returned by `init` must implement:
/// - `fn run(self: *Instance, thread_id: usize, input: [*]const f32, output: [*]f32, num_pixels: usize) bool`
/// Executes the color transform for a batch of pixels.
/// - `fn getSrcBuf(self: *Instance, thread_id: usize) ?[*]f32`
/// Returns a thread-local buffer for input data.
/// - `fn getDstBuf(self: *Instance, thread_id: usize) ?[*]f32`
/// Returns a thread-local buffer for output data.
/// - `fn destroy(self: *Instance) void`
/// Cleans up the instance context when the transform is no longer needed.
///
/// The `icc_ctx` (IccSub) may implement:
/// - `fn setFieldsFromIcc(self: *IccSub, icc: []const u8, encoding: *ColorEncoding, is_cmyk: *bool) bool`
/// Parses raw ICC profile data to populate structured color encoding fields.
pub fn fromContext(cms_ctx: anytype, icc_ctx: anytype) @This() {
const CmsT = @TypeOf(cms_ctx);
const IccT = @TypeOf(icc_ctx);
const CmsSub = if (@typeInfo(CmsT) == .pointer) @typeInfo(CmsT).pointer.child else CmsT;
const IccSub = if (@typeInfo(IccT) == .pointer) @typeInfo(IccT).pointer.child else IccT;
const InstanceT = @typeInfo(@FieldType(CmsT, "init")).@"fn".return_type.?;
const InstanceP = if (@typeInfo(InstanceT) == .error_union) @typeInfo(InstanceT).error_union.payload else InstanceT;
const VTable = struct {
fn getCms(p: ?*anyopaque) *CmsSub { return @alignCast(@ptrCast(p.?)); }
fn getIcc(p: ?*anyopaque) *IccSub { return @alignCast(@ptrCast(p.?)); }
fn getInstance(p: ?*anyopaque) InstanceP { return @alignCast(@ptrCast(p.?)); }
fn setFields(p: ?*anyopaque, icc_ptr: ?[*]const u8, icc_size: usize, c_enc: ?*ColorEncoding, cmyk: ?*c.JXL_BOOL) callconv(.c) c.JXL_BOOL {
var is_cmyk: bool = false;
const ok = getIcc(p).setFieldsFromIcc(icc_ptr.?[0..icc_size], c_enc.?, &is_cmyk);
if (cmyk) |out| out.* = if (is_cmyk) c.JXL_TRUE else c.JXL_FALSE;
return if (ok) c.JXL_TRUE else c.JXL_FALSE;
}
fn init(p: ?*anyopaque, num_threads: usize, pixels_per_thread: usize, in: ?*const ColorProfile, out: ?*const ColorProfile, intensity: f32) callconv(.c) ?*anyopaque {
return @ptrCast(getCms(p).init(num_threads, pixels_per_thread, in.?, out.?, intensity) catch null);
}
fn getSrcBuf(p: ?*anyopaque, thread: usize) callconv(.c) ?[*]f32 {
return getInstance(p).getSrcBuf(thread);
}
fn getDstBuf(p: ?*anyopaque, thread: usize) callconv(.c) ?[*]f32 {
return getInstance(p).getDstBuf(thread);
}
fn run(p: ?*anyopaque, thread: usize, in: ?[*]const f32, out: ?[*]f32, num_pix: usize) callconv(.c) c.JXL_BOOL {
return if (getInstance(p).run(thread, in.?, out.?, num_pix)) c.JXL_TRUE else c.JXL_FALSE;
}
fn destroy(p: ?*anyopaque) callconv(.c) void {
getInstance(p).destroy();
}
};
return .{
._set_fields_data = if (@bitSizeOf(IccSub) == 0) null else @ptrCast(icc_ctx),
._set_fields_from_icc_fn = if (@hasDecl(IccSub, "setFieldsFromIcc")) &VTable.setFields else null,
._init_data = if (@bitSizeOf(CmsSub) == 0) null else @ptrCast(cms_ctx),
._init_fn = &VTable.init,
._get_src_buf_fn = &VTable.getSrcBuf,
._get_dst_buf_fn = &VTable.getDstBuf,
._run_fn = &VTable.run,
._destroy_fn = &VTable.destroy,
};
}
test {
const T = c.JxlCmsInterface;
std.debug.assert(@sizeOf(@This()) == @sizeOf(T));
inline for (@typeInfo(T).@"struct".fields, @typeInfo(@This()).@"struct".fields) |cf, f| {
std.debug.assert(@sizeOf(cf.type) == @sizeOf(f.type));
std.debug.assert(@bitOffsetOf(@This(), f.name) == @bitOffsetOf(T, cf.name));
}
}
/// CMS interface function to parse an ICC profile and populate @p c and @p cmyk with the data.
pub const SetFieldsFromIccFn = *const fn (
user_data: ?*anyopaque,
icc_data: ?[*]const u8,
icc_size: usize,
color_encoding: ?*ColorEncoding,
cmyk: ?*c.JXL_BOOL
) callconv(.c) c.JXL_BOOL;
/// CMS interface function to allocate and return the data needed for parallel transforms.
pub const InitFn = *const fn (
init_data: ?*anyopaque,
num_threads: usize,
pixels_per_thread: usize,
input_profile: ?*const ColorProfile,
output_profile: ?*const ColorProfile,
intensity_target: f32,
) callconv(.c) ?*anyopaque;
/// CMS interface function to return a buffer for thread-local storage.
pub const GetBufferFn = *const fn (user_data: ?*anyopaque, thread: usize) callconv(.c) ?[*]f32;
/// CMS interface function to execute one transform batch.
pub const RunFn = *const fn (
user_data: ?*anyopaque,
thread: usize,
input_buffer: ?[*]const f32,
output_buffer: ?[*]f32,
num_pixels: usize,
) callconv(.c) c.JXL_BOOL;
/// CMS interface function to perform clean-up.
pub const DestroyFn = *const fn (user_data: ?*anyopaque) callconv(.c) void;
/// Returns the default CMS interface provided by libjxl.
pub fn getDefault() *const @This() {
return @ptrCast(c.JxlGetDefaultCms().?);
}
/// Forwarding wrapper for _set_fields_from_icc_fn.
pub fn setFieldsFromIcc(self: *const @This(), icc: []const u8, encoding: *ColorEncoding, is_cmyk: *bool) bool {
if (self._set_fields_from_icc_fn) |f| {
var c_cmyk: c.JXL_BOOL = c.JXL_FALSE;
const res = f(self._set_fields_data, icc.ptr, icc.len, encoding, &c_cmyk);
is_cmyk.* = c_cmyk == c.JXL_TRUE;
return res == c.JXL_TRUE;
}
return false;
}
pub const Instance = struct {
_interface: *const Interface,
_user_data: *opaque{},
pub fn getSrcBuf(self: @This(), thread_id: usize) error{Failed}![*]f32 {
return self._interface._get_src_buf_fn(@ptrCast(self._user_data), thread_id) orelse error.Failed;
}
pub fn getDstBuf(self: @This(), thread_id: usize) error{Failed}![*]f32 {
return self._interface._get_dst_buf_fn(@ptrCast(self._user_data), thread_id) orelse error.Failed;
}
pub fn run(self: @This(), thread_id: usize, input: [*]const f32, output: [*]f32, num_pixels: usize) error{Failed}!void {
if (self._interface._run_fn(@ptrCast(self._user_data), thread_id, input, output, num_pixels) != c.JXL_TRUE) return error.Failed;
}
pub fn deinit(self: @This()) void {
self._interface._destroy_fn(@ptrCast(self._user_data));
}
};
/// Prepares a colorspace transform.
pub fn init(
self: *const @This(),
num_threads: usize,
pixels_per_thread: usize,
input: *const ColorProfile,
output: *const ColorProfile,
intensity: f32,
) error{Failed}!Instance {
return .{
._interface = self,
._user_data = @ptrCast(self._init_fn(self._init_data, num_threads, pixels_per_thread, input, output, intensity) orelse return error.Failed),
};
}
};
};
pub const Codestream = struct {
/// Image orientation metadata.
/// Values 1..8 match the EXIF definitions.
/// The name indicates the operation to perform to transform from the encoded
/// image to the display image.
pub const Orientation = enum(c.JxlOrientation) {
identity = @bitCast(c.JXL_ORIENT_IDENTITY),
flip_horizontal = @bitCast(c.JXL_ORIENT_FLIP_HORIZONTAL),
rotate_180 = @bitCast(c.JXL_ORIENT_ROTATE_180),
flip_vertical = @bitCast(c.JXL_ORIENT_FLIP_VERTICAL),
transpose = @bitCast(c.JXL_ORIENT_TRANSPOSE),
rotate_90_cw = @bitCast(c.JXL_ORIENT_ROTATE_90_CW),
anti_transpose = @bitCast(c.JXL_ORIENT_ANTI_TRANSPOSE),
rotate_90_ccw = @bitCast(c.JXL_ORIENT_ROTATE_90_CCW),
};
/// Given type of an extra channel.
pub const ExtraChannelType = enum(c.JxlExtraChannelType) {
alpha = @bitCast(c.JXL_CHANNEL_ALPHA),
depth = @bitCast(c.JXL_CHANNEL_DEPTH),
spot_color = @bitCast(c.JXL_CHANNEL_SPOT_COLOR),
selection_mask = @bitCast(c.JXL_CHANNEL_SELECTION_MASK),
black = @bitCast(c.JXL_CHANNEL_BLACK),
cfa = @bitCast(c.JXL_CHANNEL_CFA),
thermal = @bitCast(c.JXL_CHANNEL_THERMAL),
unknown = @bitCast(c.JXL_CHANNEL_UNKNOWN),
optional = @bitCast(c.JXL_CHANNEL_OPTIONAL),
_, // future expansion
};
/// The codestream animation header, optionally present in the beginning of
/// the codestream, and if it is it applies to all animation frames, unlike @ref
/// JxlFrameHeader which applies to an individual frame.
pub const AnimationHeader = extern struct {
/// Numerator of ticks per second of a single animation frame time unit
tps_numerator: u32,
/// Denominator of ticks per second of a single animation frame time unit
tps_denominator: u32,
/// Amount of animation loops, or 0 to repeat infinitely
num_loops: u32,
/// Whether animation time codes are present at animation frames in the
/// codestream
have_timecodes: Types.Bool,
test {
const T = c.JxlAnimationHeader;
std.debug.assert(@sizeOf(@This()) == @sizeOf(T));
inline for (@typeInfo(T).@"struct".fields, @typeInfo(@This()).@"struct".fields) |cf, f| {
std.debug.assert(@sizeOf(cf.type) == @sizeOf(f.type));
std.debug.assert(@bitOffsetOf(@This(), f.name) == @bitOffsetOf(T, cf.name));
}
}
};
/// Basic image information. This information is available from the file
/// signature and first part of the codestream header.
pub const BasicInfo = extern struct {
/// Whether the codestream is embedded in the container format. If true,
/// metadata information and extensions may be available in addition to the
/// codestream.
have_container: Types.Bool,
/// Width of the image in pixels, before applying orientation.
xsize: u32,
/// Height of the image in pixels, before applying orientation.
ysize: u32,
/// Original image color channel bit depth.
bits_per_sample: u32,
/// Original image color channel floating point exponent bits, or 0 if they
/// are unsigned integer.
exponent_bits_per_sample: u32,
/// Upper bound on the intensity level present in the image in nits.
intensity_target: f32,
/// Lower bound on the intensity level present in the image.
min_nits: f32,
/// See the description of @see linear_below.
relative_to_max_display: Types.Bool,
/// Interpretation depends on relative_to_max_display.
linear_below: f32,
/// Whether the data in the codestream is encoded in the original color profile.
uses_original_profile: Types.Bool,
/// Indicates a preview image exists near the beginning of the codestream.
have_preview: Types.Bool,
/// Indicates animation frames exist in the codestream.
have_animation: Types.Bool,
/// Image orientation, value 1-8 matching EXIF.
orientation: Orientation,
/// Number of color channels encoded in the image (1 or 3).
num_color_channels: u32,
/// Number of additional image channels.
num_extra_channels: u32,
/// Bit depth of the encoded alpha channel, or 0 if none.
alpha_bits: u32,
/// Alpha channel floating point exponent bits, or 0 if unsigned.
alpha_exponent_bits: u32,
/// Whether the alpha channel is premultiplied.
alpha_premultiplied: Types.Bool,
/// Dimensions of encoded preview image.
preview: PreviewHeader,
/// Animation header with global animation properties.
animation: AnimationHeader,
/// Intrinsic width of the image.
intrinsic_xsize: u32,
/// Intrinsic height of the image.
intrinsic_ysize: u32,
/// Padding for forwards-compatibility.
padding: [100]u8,
test {
const T = c.JxlBasicInfo;
std.debug.assert(@sizeOf(@This()) == @sizeOf(T));
inline for (@typeInfo(T).@"struct".fields, @typeInfo(@This()).@"struct".fields) |cf, f| {
std.debug.assert(@sizeOf(cf.type) == @sizeOf(f.type));
std.debug.assert(@bitOffsetOf(@This(), f.name) == @bitOffsetOf(T, cf.name));
}
}
pub fn default() @This() { return _default_value; }
var _default_value: @This() = undefined;
pub fn _default() @This() {
var self: @This() = undefined;
c.JxlEncoderInitBasicInfo(@ptrCast(&self));
return self;
}
/// The codestream preview header
pub const PreviewHeader = extern struct {
/// Preview width in pixels
xsize: u32,
/// Preview height in pixels
ysize: u32,
test {
const T = c.JxlPreviewHeader;
std.debug.assert(@sizeOf(@This()) == @sizeOf(T));
inline for (@typeInfo(T).@"struct".fields, @typeInfo(@This()).@"struct".fields) |cf, f| {
std.debug.assert(@sizeOf(cf.type) == @sizeOf(f.type));
std.debug.assert(@bitOffsetOf(@This(), f.name) == @bitOffsetOf(T, cf.name));
}
}
};
};
/// Information for a single extra channel.
pub const ExtraChannelInfo = extern struct {
/// Given type of an extra channel.
type: ExtraChannelType,
/// Total bits per sample for this channel.
bits_per_sample: u32,
/// Floating point exponent bits per channel, or 0 if unsigned.
exponent_bits_per_sample: u32,
/// The exponent the channel is downsampled by on each axis.
dim_shift: u32,
/// Length of the extra channel name in bytes, excludes null terminator.
name_length: u32,
/// Whether alpha channel uses premultiplied alpha.
alpha_premultiplied: Types.Bool,
/// Spot color of the current spot channel in linear RGBA.
spot_color: [4]f32,
/// Only applicable if type is JXL_CHANNEL_CFA.
cfa_channel: u32,
test {
const T = c.JxlExtraChannelInfo;
std.debug.assert(@sizeOf(@This()) == @sizeOf(T));
inline for (@typeInfo(T).@"struct".fields, @typeInfo(@This()).@"struct".fields) |cf, f| {
std.debug.assert(@sizeOf(cf.type) == @sizeOf(f.type));
std.debug.assert(@bitOffsetOf(@This(), f.name) == @bitOffsetOf(T, cf.name));
}
}
pub fn default(comptime channel_type: Codestream.ExtraChannelType) @This() {
return @field(_default_values, @tagName(channel_type));
}
const _DefaultValues = @Type(.{
.@"struct" = .{
.layout = .auto,
.backing_integer = null,
.fields = blk: {
var filtered_fields: []const std.builtin.Type.EnumField = &.{};
for (@typeInfo(Codestream.ExtraChannelType).@"enum".fields) |f| {
filtered_fields = filtered_fields ++ &[_]std.builtin.Type.EnumField{f};
}
var fields: [filtered_fields.len]std.builtin.Type.StructField = undefined;
for (filtered_fields, 0..) |f, i| {
fields[i] = .{
.name = f.name,
.type = @This(),
.default_value_ptr = null,
.is_comptime = false,
.alignment = @alignOf(@This()),
};
}
const const_fields: [filtered_fields.len]std.builtin.Type.StructField = fields;
break :blk &const_fields;
},
.decls = &[_]std.builtin.Type.Declaration{},
.is_tuple = false,
},
});
var _default_values: _DefaultValues = undefined;
pub fn _default(channel_type: Codestream.ExtraChannelType) @This() {
var self: @This() = undefined;
c.JxlEncoderInitExtraChannelInfo(@intFromEnum(channel_type), @ptrCast(&self));
return self;
}
};
/// Extensions in the codestream header. Getting this is not yet implemented
pub const HeaderExtensions = extern struct {
/// Extension bits.
extensions: u64,
test {
const T = c.JxlHeaderExtensions;
std.debug.assert(@sizeOf(@This()) == @sizeOf(T));
inline for (@typeInfo(T).@"struct".fields, @typeInfo(@This()).@"struct".fields) |cf, f| {
std.debug.assert(@sizeOf(cf.type) == @sizeOf(f.type));
std.debug.assert(@bitOffsetOf(@This(), f.name) == @bitOffsetOf(T, cf.name));
}
}
};
};
pub const Frame = struct {
/// Frame blend modes.
pub const BlendMode = enum(c.JxlBlendMode) {
replace = @bitCast(c.JXL_BLEND_REPLACE),
add = @bitCast(c.JXL_BLEND_ADD),
blend = @bitCast(c.JXL_BLEND_BLEND),
muladd = @bitCast(c.JXL_BLEND_MULADD),
mul = @bitCast(c.JXL_BLEND_MUL),
};
/// The information about blending the color channels or a single extra channel.
pub const BlendInfo = extern struct {
/// Blend mode.
blendmode: BlendMode,
/// Reference frame ID to use as the 'bottom' layer (0-3).
source: u32,
/// Which extra channel to use as the 'alpha' channel.
alpha: u32,
/// Clamp values to [0,1] for the purpose of blending.
clamp: Types.Bool,
test {
const T = c.JxlBlendInfo;
std.debug.assert(@sizeOf(@This()) == @sizeOf(T));
inline for (@typeInfo(T).@"struct".fields, @typeInfo(@This()).@"struct".fields) |cf, f| {
std.debug.assert(@sizeOf(cf.type) == @sizeOf(f.type));
std.debug.assert(@bitOffsetOf(@This(), f.name) == @bitOffsetOf(T, cf.name));
}
}
pub fn default() @This() { return _default_value; }
var _default_value: @This() = undefined;
pub fn _default() @This() {
var self: @This() = undefined;
c.JxlEncoderInitBlendInfo(@ptrCast(&self));
return self;
}
};
/// The information about layers.
pub const LayerInfo = extern struct {
/// Whether cropping is applied for this frame.
have_crop: Types.Bool,
/// Horizontal offset of the frame (can be negative).
crop_x0: i32,
/// Vertical offset of the frame (can be negative).
crop_y0: i32,
/// Width of the frame (number of columns).
xsize: u32,
/// Height of the frame (number of rows).
ysize: u32,
/// The blending info for the color channels.
blend_info: BlendInfo,
/// After blending, save the frame as reference frame with this ID (0-3).
save_as_reference: u32,
test {
const T = c.JxlLayerInfo;
std.debug.assert(@sizeOf(@This()) == @sizeOf(T));
inline for (@typeInfo(T).@"struct".fields, @typeInfo(@This()).@"struct".fields) |cf, f| {
std.debug.assert(@sizeOf(cf.type) == @sizeOf(f.type));
std.debug.assert(@bitOffsetOf(@This(), f.name) == @bitOffsetOf(T, cf.name));
}
}
};
/// The header of one displayed frame or non-coalesced layer.
pub const Header = extern struct {
/// How long to wait after rendering in ticks.
duration: u32,
/// SMPTE timecode of the current frame in form 0xHHMMSSFF, or 0.
timecode: u32,
/// Length of the frame name in bytes, excludes null terminator.
name_length: u32,
/// Indicates this is the last animation frame.
is_last: Types.Bool,
/// Information about the layer in case of no coalescing.
layer_info: LayerInfo,
test {
const T = c.JxlFrameHeader;
std.debug.assert(@sizeOf(@This()) == @sizeOf(T));
inline for (@typeInfo(T).@"struct".fields, @typeInfo(@This()).@"struct".fields) |cf, f| {
std.debug.assert(@sizeOf(cf.type) == @sizeOf(f.type));
std.debug.assert(@bitOffsetOf(@This(), f.name) == @bitOffsetOf(T, cf.name));
}
}
pub fn default() @This() { return _default_value; }
var _default_value: @This() = undefined;
pub fn _default() @This() {
var self: @This() = undefined;
c.JxlEncoderInitFrameHeader(@ptrCast(&self));
return self;
}
};
};
/// Opaque structure that holds the JPEG XL decoder.
///
/// Allocated and initialized with @ref JxlDecoderCreate().
/// Cleaned up and deallocated with @ref JxlDecoderDestroy().
pub const Decoder = opaque {
/// Decoder library version.
///
/// @return the decoder library version as an integer:
/// MAJOR_VERSION * 1000000 + MINOR_VERSION * 1000 + PATCH_VERSION. For example,
/// version 1.2.3 would return 1002003.
pub fn version() u32 { return _version_value; }
var _version_value: u32 = undefined;
pub fn _version() u32 { return c.JxlDecoderVersion(); }
/// The result of @ref JxlSignatureCheck.
pub const Signature = enum(c.JxlSignature) {
/// Not enough bytes were passed to determine if a valid signature was found.
not_enough_bytes = @bitCast(c.JXL_SIG_NOT_ENOUGH_BYTES),
/// No valid JPEG XL header was found.
invalid = @bitCast(c.JXL_SIG_INVALID),
/// A valid JPEG XL codestream signature was found, that is a JPEG XL image
/// without container.
codestream = @bitCast(c.JXL_SIG_CODESTREAM),
/// A valid container signature was found, that is a JPEG XL image embedded
/// in a box format container.
container = @bitCast(c.JXL_SIG_CONTAINER),
};
/// JPEG XL signature identification.
///
/// Checks if the passed buffer contains a valid JPEG XL signature. The passed @p
/// buf of size @p size doesn't need to be a full image, only the beginning of the file.
///
/// @return a flag indicating if a JPEG XL signature was found and what type.
pub fn signatureCheck(buf: []const u8) Signature {
return @enumFromInt(c.JxlSignatureCheck(buf.ptr, buf.len));
}
/// Creates an instance of @ref JxlDecoder and initializes it.
///
/// @p memory_manager will be used for all the library dynamic allocations made
/// from this instance. The parameter may be NULL, in which case the default
/// allocator will be used. See jxl/memory_manager.h for details.
///
/// @param memory_manager custom allocator function. It may be NULL. The memory
/// manager will be copied internally.
/// @return pointer to initialized @ref JxlDecoder otherwise
pub fn create(memory_manager: ?*const MemoryManager) !*@This() {
return @ptrCast(c.JxlDecoderCreate(@ptrCast(memory_manager)) orelse return error.OutOfMemory);
}
/// Re-initializes a @ref JxlDecoder instance, so it can be re-used for decoding
/// another image. All state and settings are reset as if the object was
/// newly created with @ref JxlDecoderCreate, but the memory manager is kept.
///
/// @param dec instance to be re-initialized.
pub fn reset(dec: *@This()) void {
c.JxlDecoderReset(@ptrCast(dec));
}
/// Deinitializes and frees @ref JxlDecoder instance.
///
/// @param dec instance to be cleaned up and deallocated.
pub fn deinit(dec: *@This()) void {
c.JxlDecoderDestroy(@ptrCast(dec));
}
/// Return value for @ref JxlDecoderProcessInput. The values from ::JXL_DEC_BASIC_INFO onwards are optional informative
/// events that can be subscribed to, they are never returned if they have not been registered with @ref JxlDecoderSubscribeEvents.
pub const Status = enum(c.JxlDecoderStatus) {
/// Function call finished successfully, or decoding is finished and there is nothing more to be done.
success = @bitCast(c.JXL_DEC_SUCCESS),
/// An error occurred, for example invalid input file or out of memory.
@"error" = @bitCast(c.JXL_DEC_ERROR),
/// The decoder needs more input bytes to continue. Before the next @ref Decoder.processInput call, more input data must be set, by calling
/// @ref Decoder.releaseInput (if input was set previously) and then calling @ref Decoder.setInput.
need_more_input = @bitCast(c.JXL_DEC_NEED_MORE_INPUT),
/// The decoder is able to decode a preview image and requests setting a preview output buffer using @ref JxlDecoderSetPreviewOutBuffer.
need_preview_out_buffer = @bitCast(c.JXL_DEC_NEED_PREVIEW_OUT_BUFFER),
/// The decoder requests an output buffer to store the full resolution image, which can be set with @ref Decoder.setImageOutBuffer or with @ref Decoder.SetImageOutCallback.
need_image_out_buffer = @bitCast(c.JXL_DEC_NEED_IMAGE_OUT_BUFFER),
/// The JPEG reconstruction buffer is too small for reconstructed JPEG
/// codestream to fit. @ref JxlDecoderSetJPEGBuffer must be called again to
/// make room for remaining bytes.
jpeg_need_more_output = @bitCast(c.JXL_DEC_JPEG_NEED_MORE_OUTPUT),
/// The box contents output buffer is too small. @ref JxlDecoderSetBoxBuffer must be called again to make room for remaining bytes.
box_need_more_output = @bitCast(c.JXL_DEC_BOX_NEED_MORE_OUTPUT),
/// Informative event: Basic information such as image dimensions and extra channels. This event occurs max once per image.
basic_info = @bitCast(c.JXL_DEC_BASIC_INFO),
/// Informative event: Color encoding or ICC profile from the codestream header.
color_encoding = @bitCast(c.JXL_DEC_COLOR_ENCODING),
/// Informative event: Preview image, a small frame, decoded.
preview_image = @bitCast(c.JXL_DEC_PREVIEW_IMAGE),
/// Informative event: Beginning of a frame. @ref Decoder.getFrameHeader can be used at this point.
frame = @bitCast(c.JXL_DEC_FRAME),
/// Informative event: full frame (or layer, in case coalescing is disabled) is decoded.
full_image = @bitCast(c.JXL_DEC_FULL_IMAGE),
/// Informative event: JPEG reconstruction data decoded.
jpeg_reconstruction = @bitCast(c.JXL_DEC_JPEG_RECONSTRUCTION),
/// Informative event: The header of a box of the container format (BMFF) is decoded.
box = @bitCast(c.JXL_DEC_BOX),
/// Informative event: a progressive step in decoding the frame is reached.
frame_progression = @bitCast(c.JXL_DEC_FRAME_PROGRESSION),
/// The box being decoded is now complete. This is only emitted if a buffer was set for the box.
box_complete = @bitCast(c.JXL_DEC_BOX_COMPLETE),
_, // future expansion
pub const Set = error {
DecoderError,
DecoderNeedMoreInput,
DecoderNeedPreviewOutBuffer,
DecoderNeedImageOutBuffer,
DecoderJpegNeedMoreOutput,
DecoderBoxNeedMoreOutput,
DecoderBasicInfo,
DecoderColorEncoding,
DecoderPreviewImage,
DecoderFrame,
DecoderFullImage,
DecoderJpegReconstruction,
DecoderBox,
DecoderFrameProgression,
DecoderBoxComplete,
UnknownDecoderError,
};
pub fn check(self: c_uint) !void {
return switch (@as(@This(), @enumFromInt(self))) {
.success => {},
.@"error" => Set.DecoderError,
.need_more_input => Set.DecoderNeedMoreInput,
.need_preview_out_buffer => Set.DecoderNeedPreviewOutBuffer,
.need_image_out_buffer => Set.DecoderNeedImageOutBuffer,
.jpeg_need_more_output => Set.DecoderJpegNeedMoreOutput,
.box_need_more_output => Set.DecoderBoxNeedMoreOutput,
.basic_info => Set.DecoderBasicInfo,
.color_encoding => Set.DecoderColorEncoding,
.preview_image => Set.DecoderPreviewImage,
.frame => Set.DecoderFrame,
.full_image => Set.DecoderFullImage,
.jpeg_reconstruction => Set.DecoderJpegReconstruction,
.box => Set.DecoderBox,
.frame_progression => Set.DecoderFrameProgression,
.box_complete => Set.DecoderBoxComplete,
else => error.UnknownDecoderError
};
}
};
/// Types of progressive detail.
/// Setting a progressive detail with value N implies all progressive details
/// with smaller or equal value.
pub const ProgressiveDetail = enum(c.JxlProgressiveDetail) {
/// after completed kRegularFrames
frames = @bitCast(c.kFrames),
/// after completed DC (1:8)
dc = @bitCast(c.kDC),
/// after completed AC passes that are the last pass for their resolution
/// target.
last_passes = @bitCast(c.kLastPasses),
/// after completed AC passes that are not the last pass for their resolution
/// target.
passes = @bitCast(c.kPasses),
/// during DC frame when lower resolution are completed (1:32, 1:16)
dc_progressive = @bitCast(c.kDCProgressive),
/// after completed groups
dc_groups = @bitCast(c.kDCGroups),
/// after completed groups
groups = @bitCast(c.kGroups),
};
/// Rewinds decoder to the beginning. The same input must be given again from
/// the beginning of the file and the decoder will emit events from the beginning
/// again. When rewinding (as opposed to @ref JxlDecoderReset), the decoder can
/// keep state about the image, which it can use to skip to a requested frame
/// more efficiently with @ref JxlDecoderSkipFrames. Settings such as parallel
/// runner or subscribed events are kept.
pub fn rewind(dec: *@This()) void {
c.JxlDecoderRewind(@ptrCast(dec));
}
/// Makes the decoder skip the next `amount` frames. It still needs to process
/// the input, but will not output the frame events. It can be more efficient
/// when skipping frames, and even more so when using this after @ref DecoderRewind.
pub fn skipFrames(dec: *@This(), amount: usize) void {
c.JxlDecoderSkipFrames(@ptrCast(dec), amount);
}
/// Skips processing the current frame. Can be called after frame processing
/// already started, signaled by a ::JXL_DEC_NEED_IMAGE_OUT_BUFFER event,
/// but before the corresponding ::JXL_DEC_FULL_IMAGE event.
pub fn skipCurrentFrame(dec: *@This()) !void {
return Status.check(c.JxlDecoderSkipCurrentFrame(@ptrCast(dec)));
}
/// Set the parallel runner for multithreading. May only be set before starting decoding.
pub const setParallelRunner = if (config.threading) _setParallelRunner else null;
fn _setParallelRunner(dec: *@This(), parallel_runner: ParallelRunner.RunnerFn, parallel_runner_opaque: ?*ParallelRunner) !void {
return Status.check(c.JxlDecoderSetParallelRunner(@ptrCast(dec), parallel_runner, @ptrCast(parallel_runner_opaque)));
}
/// Returns a hint indicating how many more bytes the decoder is expected to
/// need to make @ref JxlDecoderGetBasicInfo available after the next @ref
/// JxlDecoderProcessInput call.
pub fn sizeHintBasicInfo(dec: *const @This()) usize {
return c.JxlDecoderSizeHintBasicInfo(@ptrCast(dec));
}
/// Select for which informative events, i.e. ::JXL_DEC_BASIC_INFO, etc., the
/// decoder should return with a status.
pub fn subscribeEvents(dec: *@This(), events_wanted: i32) !void {
return Status.check(c.JxlDecoderSubscribeEvents(@ptrCast(dec), events_wanted));
}
/// Enables or disables preserving of as-in-bitstream pixeldata
/// orientation.
pub fn setKeepOrientation(dec: *@This(), skip_reorientation: bool) !void {
return Status.check(c.JxlDecoderSetKeepOrientation(@ptrCast(dec), @intFromBool(skip_reorientation)));
}
/// Enables or disables preserving of associated alpha channels. If
/// unpremul_alpha is set to ::JXL_FALSE then for associated alpha channel,
/// the pixel data is returned with premultiplied colors.
pub fn setUnpremultiplyAlpha(dec: *@This(), unpremul_alpha: bool) !void {
return Status.check(c.JxlDecoderSetUnpremultiplyAlpha(@ptrCast(dec), @intFromBool(unpremul_alpha)));
}
/// Enables or disables rendering spot colors. By default, spot colors
/// are rendered, which is OK for viewing the decoded image.
pub fn setRenderSpotcolors(dec: *@This(), render_spotcolors: bool) !void {
return Status.check(c.JxlDecoderSetRenderSpotcolors(@ptrCast(dec), @intFromBool(render_spotcolors)));
}
/// Enables or disables coalescing of zero-duration frames. By default, frames
/// are returned with coalescing enabled, i.e. all frames have the image
/// dimensions, and are blended if needed.
pub fn setCoalescing(dec: *@This(), coalescing: bool) !void {
return Status.check(c.JxlDecoderSetCoalescing(@ptrCast(dec), @intFromBool(coalescing)));
}
/// Decodes JPEG XL file using the available bytes. Requires input has been
/// set with @ref JxlDecoderSetInput.
pub fn processInput(dec: *@This()) !void {
return Status.check(c.JxlDecoderProcessInput(@ptrCast(dec)));
}
/// Sets input data for @ref JxlDecoderProcessInput. The data is owned by the
/// caller and may be used by the decoder until @ref JxlDecoderReleaseInput is
/// called or the decoder is destroyed or reset so must be kept alive until then.
pub fn setInput(dec: *@This(), data: []const u8) !void {
return Status.check(c.JxlDecoderSetInput(@ptrCast(dec), data.ptr, data.len));
}
/// Releases input which was provided with @ref JxlDecoderSetInput.
pub fn releaseInput(dec: *@This()) usize {
return c.JxlDecoderReleaseInput(@ptrCast(dec));
}
/// Marks the input as finished, indicates that no more @ref JxlDecoderSetInput
/// will be called.
pub fn closeInput(dec: *@This()) void {
c.JxlDecoderCloseInput(@ptrCast(dec));
}
/// Outputs the basic image information, such as image dimensions, bit depth and
/// all other JxlBasicInfo fields, if available.
pub fn getBasicInfo(dec: *const @This(), info: ?*Codestream.BasicInfo) !void {
return Status.check(c.JxlDecoderGetBasicInfo(@ptrCast(dec), @ptrCast(info)));
}
/// Outputs information for extra channel at the given index. The index must be
/// smaller than num_extra_channels in the associated @ref JxlBasicInfo.
pub fn getExtraChannelInfo(dec: *const @This(), index: usize, info: ?*Codestream.ExtraChannelInfo) !void {
return Status.check(c.JxlDecoderGetExtraChannelInfo(@ptrCast(dec), index, @ptrCast(info)));
}
/// Outputs name for extra channel at the given index in UTF-8.
pub fn getExtraChannelName(dec: *const @This(), index: usize, name: []u8) !void {
return Status.check(c.JxlDecoderGetExtraChannelName(@ptrCast(dec), index, name.ptr, name.len));
}
/// Defines which color profile to get: the profile from the codestream
/// metadata header, which represents the color profile of the original image,
/// or the color profile from the pixel data produced by the decoder. Both are
/// the same if the JxlBasicInfo has uses_original_profile set.
pub const ColorProfileTarget = enum(c.JxlColorProfileTarget) {
/// Get the color profile of the original image from the metadata.
original = @bitCast(c.JXL_COLOR_PROFILE_TARGET_ORIGINAL),
/// Get the color profile of the pixel data the decoder outputs.
data = @bitCast(c.JXL_COLOR_PROFILE_TARGET_DATA),
};
/// Outputs the color profile as JPEG XL encoded structured data, if available.
/// This is an alternative to an ICC Profile, which can represent a more limited
/// amount of color spaces, but represents them exactly through enum values.
pub fn getColorAsEncodedProfile(dec: *const @This(), target: ColorProfileTarget, color_encoding: ?*ColorEncoding) !void {
return Status.check(c.JxlDecoderGetColorAsEncodedProfile(@ptrCast(dec), @intFromEnum(target), @ptrCast(color_encoding)));
}
pub fn _getICCProfileSize(dec: *const @This(), target: ColorProfileTarget, size: ?*usize) !void {
return Status.check(c.JxlDecoderGetICCProfileSize(@ptrCast(dec), @intFromEnum(target), size));
}
/// Outputs the size in bytes of the ICC profile returned by @ref JxlDecoderGetColorAsICCProfile, if available,
/// or indicates there is none available.
pub fn getICCProfileSize(dec: *const @This(), target: ColorProfileTarget) !usize {
var size: usize = undefined;
try _getICCProfileSize(dec, target, &size);
return size;
}
pub fn getICCProfileStatus(dec: *const @This(), target: ColorProfileTarget) !void {
return _getICCProfileSize(dec, target, null);
}
/// Outputs ICC profile if available. The profile is only available if @ref getICCProfileSize returns success.
pub fn getColorAsICCProfile(dec: *const @This(), target: ColorProfileTarget, icc_profile: []u8) !void {
return Status.check(c.JxlDecoderGetColorAsICCProfile(@ptrCast(dec), @intFromEnum(target), icc_profile.ptr, icc_profile.len));
}
/// Sets the desired output color profile of the decoded image by calling
/// @ref JxlDecoderSetOutputColorProfile, passing on @c color_encoding and
/// setting @c icc_data to NULL.
pub fn setPreferredColorProfile(dec: *@This(), color_encoding: *const ColorEncoding) !void {
return Status.check(c.JxlDecoderSetPreferredColorProfile(@ptrCast(dec), @ptrCast(color_encoding)));
}
/// Requests that the decoder perform tone mapping to the peak display luminance
/// passed as @c desired_intensity_target, if appropriate.
pub fn setDesiredIntensityTarget(dec: *@This(), desired_intensity_target: f32) !void {
return Status.check(c.JxlDecoderSetDesiredIntensityTarget(@ptrCast(dec), desired_intensity_target));
}
pub const OutputColorProfile = union(enum) {
color_encoding: *const ColorEncoding,
icc_data: []const u8,
none: void,
};
/// Sets the desired output color profile of the decoded image either from a color encoding or an ICC profile.
/// Valid calls of this function have either @c color_encoding or @c icc_data set to NULL.
pub fn setOutputColorProfile(dec: *@This(), profile: OutputColorProfile) !void {
return Status.check(c.JxlDecoderSetOutputColorProfile(
@ptrCast(dec),
if (profile == .color_encoding) @ptrCast(profile.color_encoding) else null,
if (profile == .icc_data) profile.icc_data.ptr else null,
if (profile == .icc_data) profile.icc_data.len else 0,
));
}
/// Sets the color management system (CMS) that will be used for color conversion (if applicable) during decoding.
pub fn setCms(dec: *@This(), cms: Cms.Interface) !void {
return Status.check(c.JxlDecoderSetCms(@ptrCast(dec), @bitCast(cms)));
}
/// Returns the minimum size in bytes of the preview image output pixel buffer for the given format.
pub fn previewOutBufferSize(dec: *const @This(), format: *const Types.PixelFormat) !usize {
var size: usize = undefined;