pict 0.1.1

Half-baked PICT resource rendering in rust
Documentation
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
use binrw::{BinRead, BinReaderExt, BinResult, binread};
use packbits_rle::PackBitsReaderExt;

use super::shared::*;

#[derive(BinRead, Debug)]
#[br(big)]
pub struct FixedRect {
    pub left: Fixed,
    pub top: Fixed,
    pub right: Fixed,
    pub bottom: Fixed,
}

#[derive(BinRead, Debug)]
#[br(big)]
pub enum MinorVersion {
    #[br(magic(-1i32))]
    Normal,
    #[br(magic(-2i32))]
    Extended,
}

#[binread]
#[derive(Debug)]
#[br(big)]
pub struct Header {
    pub version: MinorVersion,
    /// fixed-point bounding rectangle for picture
    pub bounds: FixedRect,
    #[br(temp, assert(reserved == 0x00000000u32))]
    /// reserved
    pub reserved: u32,
}

#[derive(BinRead, Debug)]
#[br(big)]
pub enum Opcode {
    /// No operation
    #[br(magic(0x0000u16))]
    NOP,
    /// Clipping region
    #[br(magic(0x0001u16))]
    Clip(Region),
    /// Background pattern
    #[br(magic(0x0002u16))]
    BkPat(Pattern),
    /// Font number for text
    #[br(magic(0x0003u16))]
    TxFont(Integer),
    /// Text's font style
    #[br(magic(0x0004u16))]
    TxFace(u8),
    /// Source mode
    #[br(magic(0x0005u16))]
    TxMode(u16),
    /// Extra space (Fixed)
    #[br(magic(0x0006u16))]
    SpExtra(Fixed),
    /// Pen size (Point)
    #[br(magic(0x0007u16))]
    PnSize(Point),
    /// Pen mode
    #[br(magic(0x0008u16))]
    PnMode(Integer),
    /// Pen pattern
    #[br(magic(0x0009u16))]
    PnPat(Pattern),
    /// Fill pattern
    #[br(magic(0x000Au16))]
    FillPat(Pattern),
    /// Oval size
    #[br(magic(0x000Bu16))]
    OvSize(Point),
    /// dh, dv
    #[br(magic(0x000Cu16))]
    Origin(Integer, Integer),
    /// Text size
    #[br(magic(0x000Du16))]
    TxSize(Integer),
    /// Foreground color
    #[br(magic(0x000Eu16))]
    FgColor(Long),
    /// Background color
    #[br(magic(0x000Fu16))]
    BkColor(Long),
    /// Numerator (Point), denominator (Point)
    #[br(magic(0x0010u16))]
    TxRatio(Point, Point),
    /// Version
    #[br(magic(0x0011u16))]
    VersionOp,
    /// Background pixel pattern    Variable; see Listing A-1 on page A-17
    #[br(magic(0x0012u16))]
    BkPixPat,
    /// Pen pixel pattern    Variable; see Listing A-1 on page A-17
    #[br(magic(0x0013u16))]
    PnPixPat,
    /// Fill pixel pattern    Variable; see Listing A-1 on page A-17
    #[br(magic(0x0014u16))]
    FillPixPat,
    /// Fractional pen position (Integer - low word of Fixed); if value is not 0.5, pen position is always set to the picture before each text-drawing operation. 2
    #[br(magic(0x0015u16))]
    PnLocHFrac,
    /// Added width for non-space characters
    #[br(magic(0x0016u16))]
    ChExtra(Integer),
    /// use Notdetermined
    #[br(magic(0x0017u16))]
    ReservedForAppleUse,
    /// use Notdetermined
    #[br(magic(0x0018u16))]
    ReservedForAppleUse1,
    /// use Notdetermined
    #[br(magic(0x0019u16))]
    ReservedForAppleUse2,
    /// Foreground color
    #[br(magic(0x001Au16))]
    RGBFgColor(RGBColor),
    /// Background color
    #[br(magic(0x001Bu16))]
    RGBBkCol(RGBColor),
    /// Highlight mode flag: no data; this opcode is sent before a drawing operation that uses the highlight mode
    #[br(magic(0x001Cu16))]
    HiliteMode,
    /// Highlight color
    #[br(magic(0x001Du16))]
    HiliteColor(RGBColor),
    /// Use default highlight color; no data; set highlight to default (from low memory)
    #[br(magic(0x001Eu16))]
    DefHilite,
    /// Opcolor
    #[br(magic(0x001Fu16))]
    OpColor(RGBColor),
    /// pnLoc (Point), newPt (Point)
    #[br(magic(0x0020u16))]
    Line(Point, Point),
    /// newPt
    #[br(magic(0x0021u16))]
    LineFrom(Point),
    /// pnLoc (Point), dh (-128..127), dv (-128..127)
    #[br(magic(0x0022u16))]
    ShortLine(Point, i8, i8),
    /// dh (-128..127), dv (-128..127)
    #[br(magic(0x0023u16))]
    ShortLineFrom(i8, i8),
    /// Data length (Integer), data
    #[br(magic(0x0024u16))]
    ReservedForAppleUse3(u16, #[br(count(self_0))] Vec<u8>),
    /// Data length (Integer), data
    #[br(magic(0x0025u16))]
    ReservedForAppleUse4(u16, #[br(count(self_0))] Vec<u8>),
    /// Data length (Integer), data
    #[br(magic(0x0026u16))]
    ReservedForAppleUse5(u16, #[br(count(self_0))] Vec<u8>),
    /// Data length (Integer), data
    #[br(magic(0x0027u16))]
    ReservedForAppleUse6(u16, #[br(count(self_0))] Vec<u8>),
    /// txLoc (Point), count (0..255), text
    #[br(magic(0x0028u16))]
    LongText(Point, ShortString),
    /// dh (0..255), count (0..255), text
    #[br(magic(0x0029u16))]
    DHText(u8, ShortString),
    /// dv (0..255), count (0..255), text
    #[br(magic(0x002Au16))]
    DVText(u8, ShortString),
    /// dh (0..255), dv (0..255), count (0..255), text
    #[br(magic(0x002Bu16))]
    DHDVText(u8, u8, ShortString),
    /// Data length (Integer), old font ID (Integer), name length (0..255), font name*
    #[br(magic(0x002Cu16))]
    FontName(Integer, Integer, ShortString),
    /// Operand data length (Integer), intercharacter spacing (Fixed), total extra space for justification (Fixed)†
    #[br(magic(0x002Du16))]
    LineJustify(Integer, Fixed, Fixed),
    /// Data length (word), followed by these 1-byte Boolean values: outline preferred, preserve glyph, fractional widths, scaling disabled        8
    #[br(magic(0x002Eu16))]
    GlyphState(Word, u8, u8, u8, u8),
    /// Data length (Integer), data
    #[br(magic(0x002Fu16))]
    ReservedForAppleUse7(u16, #[br(count(self_0))] Vec<u8>),
    /// Rectangle (Rect)
    #[br(magic(0x0030u16))]
    FrameRect(Rect),
    /// Rectangle (Rect)
    #[br(magic(0x0031u16))]
    PaintRect(Rect),
    /// Rectangle (Rect)
    #[br(magic(0x0032u16))]
    EraseRect(Rect),
    /// Rectangle (Rect)
    #[br(magic(0x0033u16))]
    InvertRect(Rect),
    /// Rectangle (Rect)
    #[br(magic(0x0034u16))]
    FillRect(Rect),
    /// 8 bytes of data
    #[br(magic(0x0035u16))]
    ReservedForAppleUse8(Rect),
    /// 8 bytes of data
    #[br(magic(0x0036u16))]
    ReservedForAppleUse9(Rect),
    /// 8 bytes of data
    #[br(magic(0x0037u16))]
    ReservedForAppleUse10(Rect),
    /// Rectangle (Rect)
    #[br(magic(0x0038u16))]
    FrameSameRect,
    /// Rectangle (Rect)
    #[br(magic(0x0039u16))]
    PaintSameRect,
    /// Rectangle (Rect)
    #[br(magic(0x003Au16))]
    EraseSameRect,
    /// Rectangle (Rect)
    #[br(magic(0x003Bu16))]
    InvertSameRect,
    /// Rectangle (Rect)
    #[br(magic(0x003Cu16))]
    FillSameRect,
    #[br(magic(0x003Du16))]
    ReservedForAppleUse11,
    #[br(magic(0x003Eu16))]
    ReservedForAppleUse12,
    #[br(magic(0x003Fu16))]
    ReservedForAppleUse13,
    /// ‡ Rectangle (Rect)
    #[br(magic(0x0040u16))]
    FrameRRect(Rect),
    /// Rectangle (Rect)‡
    #[br(magic(0x0041u16))]
    PaintRRect(Rect),
    /// Rectangle (Rect)‡
    #[br(magic(0x0042u16))]
    EraseRRect(Rect),
    /// Rectangle (Rect)‡
    #[br(magic(0x0043u16))]
    InvertRRect(Rect),
    /// Rectangle (Rect)‡
    #[br(magic(0x0044u16))]
    FillRRect(Rect),
    /// 8 bytes of data
    #[br(magic(0x0045u16))]
    ReservedForAppleUse14(Rect),
    /// 8 bytes of data
    #[br(magic(0x0046u16))]
    ReservedForAppleUse15(Rect),
    /// 8 bytes of data
    #[br(magic(0x0047u16))]
    ReservedForAppleUse16(Rect),
    /// Rectangle (Rect)
    #[br(magic(0x0048u16))]
    FrameSameRRect,
    /// Rectangle (Rect)
    #[br(magic(0x0049u16))]
    PaintSameRRect,
    /// Rectangle (Rect)
    #[br(magic(0x004Au16))]
    EraseSameRRect,
    /// Rectangle (Rect)
    #[br(magic(0x004Bu16))]
    InvertSameRRect,
    /// Rectangle (Rect)
    #[br(magic(0x004Cu16))]
    FillSameRRect,
    #[br(magic(0x004Du16))]
    ReservedForAppleUse17,
    #[br(magic(0x004Eu16))]
    ReservedForAppleUse18,
    #[br(magic(0x004Fu16))]
    ReservedForAppleUse19,
    /// Rectangle (Rect)
    #[br(magic(0x0050u16))]
    FrameOval(Rect),
    /// Rectangle (Rect)
    #[br(magic(0x0051u16))]
    PaintOval(Rect),
    /// Rectangle (Rect)
    #[br(magic(0x0052u16))]
    EraseOval(Rect),
    /// Rectangle (Rect)
    #[br(magic(0x0053u16))]
    InvertOval(Rect),
    /// Rectangle (Rect)
    #[br(magic(0x0054u16))]
    FillOval(Rect),
    /// 8 bytes of data
    #[br(magic(0x0055u16))]
    ReservedForAppleUse20(Rect),
    /// 8 bytes of data
    #[br(magic(0x0056u16))]
    ReservedForAppleUse21(Rect),
    /// 8 bytes of data
    #[br(magic(0x0057u16))]
    ReservedForAppleUse22(Rect),
    /// Rectangle (Rect)
    #[br(magic(0x0058u16))]
    FrameSameOval,
    /// Rectangle (Rect)
    #[br(magic(0x0059u16))]
    PaintSameOval,
    /// Rectangle (Rect)
    #[br(magic(0x005Au16))]
    EraseSameOval,
    /// Rectangle (Rect)
    #[br(magic(0x005Bu16))]
    InvertSameOval,
    /// Rectangle (Rect)
    #[br(magic(0x005Cu16))]
    FillSameOval,
    #[br(magic(0x005Du16))]
    ReservedForAppleUse23,
    #[br(magic(0x005Eu16))]
    ReservedForAppleUse24,
    #[br(magic(0x005Fu16))]
    ReservedForAppleUse25,
    /// Rectangle (Rect), startAngle, arcAngle
    #[br(magic(0x0060u16))]
    FrameArc(Rect, u16, u16),
    /// Rectangle (Rect), startAngle, arcAngle
    #[br(magic(0x0061u16))]
    PaintArc(Rect, u16, u16),
    /// Rectangle (Rect), startAngle, arcAngle
    #[br(magic(0x0062u16))]
    EraseArc(Rect, u16, u16),
    /// Rectangle (Rect), startAngle, arcAngle
    #[br(magic(0x0063u16))]
    InvertArc(Rect, u16, u16),
    /// Rectangle (Rect), startAngle, arcAngle
    #[br(magic(0x0064u16))]
    FillArc(Rect, u16, u16),
    /// 12 bytes of data
    #[br(magic(0x0065u16))]
    ReservedForAppleUse26(Rect, u16, u16),
    /// 12 bytes of data
    #[br(magic(0x0066u16))]
    ReservedForAppleUse27(Rect, u16, u16),
    /// 12 bytes of data
    #[br(magic(0x0067u16))]
    ReservedForAppleUse28(Rect, u16, u16),
    /// Rectangle (Rect)
    #[br(magic(0x0068u16))]
    FrameSameArc(u16, u16),
    /// Rectangle (Rect)
    #[br(magic(0x0069u16))]
    PaintSameArc(u16, u16),
    /// Rectangle (Rect)
    #[br(magic(0x006Au16))]
    EraseSameArc(u16, u16),
    /// Rectangle (Rect)
    #[br(magic(0x006Bu16))]
    InvertSameArc(u16, u16),
    /// Rectangle (Rect)
    #[br(magic(0x006Cu16))]
    FillSameArc(u16, u16),
    /// 4 bytes of data
    #[br(magic(0x006Du16))]
    ReservedForAppleUse29(u16, u16),
    /// 4 bytes of data
    #[br(magic(0x006Eu16))]
    ReservedForAppleUse30(u16, u16),
    /// 4 bytes of data
    #[br(magic(0x006Fu16))]
    ReservedForAppleUse31(u16, u16),
    /// Polygon (Poly)
    #[br(magic(0x0070u16))]
    FramePoly(Polygon),
    /// Polygon (Poly)
    #[br(magic(0x0071u16))]
    PaintPoly(Polygon),
    /// Polygon (Poly)
    #[br(magic(0x0072u16))]
    ErasePoly(Polygon),
    /// Polygon (Poly)
    #[br(magic(0x0073u16))]
    InvertPoly(Polygon),
    /// Polygon (Poly)
    #[br(magic(0x0074u16))]
    FillPoly(Polygon),
    /// Polygon (Poly)
    #[br(magic(0x0075u16))]
    ReservedForAppleUse32(Polygon),
    /// Polygon (Poly)
    #[br(magic(0x0076u16))]
    ReservedForAppleUse33(Polygon),
    /// Polygon (Poly)
    #[br(magic(0x0077u16))]
    ReservedForAppleUse34(Polygon),
    /// (Not yet implemented)
    #[br(magic(0x0078u16))]
    FrameSamePoly,
    /// (Not yet implemented)
    #[br(magic(0x0079u16))]
    PaintSamePoly,
    /// (Not yet implemented)
    #[br(magic(0x007Au16))]
    EraseSamePoly,
    /// (Not yet implemented)
    #[br(magic(0x007Bu16))]
    InvertSamePoly,
    /// (Not yet implemented)
    #[br(magic(0x007Cu16))]
    FillSamePoly,
    #[br(magic(0x007Du16))]
    ReservedForAppleUse35,
    #[br(magic(0x007Eu16))]
    ReservedForAppleUse36,
    #[br(magic(0x007Fu16))]
    ReservedForAppleUse37,
    /// Region(Rgn)
    #[br(magic(0x0080u16))]
    FrameRgn(Region),
    /// Region(Rgn)
    #[br(magic(0x0081u16))]
    PaintRgn(Region),
    /// Region(Rgn)
    #[br(magic(0x0082u16))]
    EraseRgn(Region),
    /// Region(Rgn)
    #[br(magic(0x0083u16))]
    InvertRgn(Region),
    /// Region (Rgn)
    #[br(magic(0x0084u16))]
    FillRgn(Region),
    /// Region (Rgn)
    #[br(magic(0x0085u16))]
    ReservedForAppleUse38(Region),
    /// Region (Rgn)
    #[br(magic(0x0086u16))]
    ReservedForAppleUse39(Region),
    /// Region (Rgn)
    #[br(magic(0x0087u16))]
    ReservedForAppleUse40(Region),
    /// (Not yet implemented)
    #[br(magic(0x0088u16))]
    FrameSameRgn,
    /// (Not yet implemented)
    #[br(magic(0x0089u16))]
    PaintSameRgn,
    /// (Not yet implemented)
    #[br(magic(0x008Au16))]
    EraseSameRgn,
    /// (Not yet implemented)
    #[br(magic(0x008Bu16))]
    InvertSameRgn,
    /// (Not yet implemented)
    #[br(magic(0x008Cu16))]
    FillSameRgn,
    #[br(magic(0x008Du16))]
    ReservedForAppleUse41,
    #[br(magic(0x008Eu16))]
    ReservedForAppleUse42,
    #[br(magic(0x008Fu16))]
    ReservedForAppleUse43,
    /// CopyBits with clipped rectangle     Variable§¶; see Listing A-2 on page A-17
    #[br(magic(0x0090u16))]
    BitsRect(#[br(args(true, false))] CopyBits),
    /// CopyBits with clipped region     Variable§¶; see Listing A-3 on page A-18
    #[br(magic(0x0091u16))]
    BitsRgn(#[br(args(false, false))] CopyBits),
    /// Data length (Integer), data
    #[br(magic(0x0092u16))]
    ReservedForAppleUse44(Integer, #[br(count(self_0))] Vec<u8>),
    /// Data length (Integer), data
    #[br(magic(0x0093u16))]
    ReservedForAppleUse45(Integer, #[br(count(self_0))] Vec<u8>),
    /// Data length (Integer), data
    #[br(magic(0x0094u16))]
    ReservedForAppleUse46(Integer, #[br(count(self_0))] Vec<u8>),
    /// Data length (Integer), data
    #[br(magic(0x0095u16))]
    ReservedForAppleUse47(Integer, #[br(count(self_0))] Vec<u8>),
    /// Data length (Integer), data
    #[br(magic(0x0096u16))]
    ReservedForAppleUse48(Integer, #[br(count(self_0))] Vec<u8>),
    /// Data length (Integer), data
    #[br(magic(0x0097u16))]
    ReservedForAppleUse49(Integer, #[br(count(self_0))] Vec<u8>),
    /// Packed CopyBits with clipped rectangle
    #[br(magic(0x0098u16))]
    PackBitsRect(#[br(args(true, false))] CopyBits),
    /// Packed CopyBits with clipped rectangle
    #[br(magic(0x0099u16))]
    PackBitsRgn(#[br(args(true, true))] CopyBits),
    /// PixMap, srcRect, dstRect, mode (Integer), PixData
    #[br(magic(0x009Au16))]
    DirectBitsRect(#[br(args(false))] DirectBits),
    /// PixMap, srcRect, dstRect, mode (Integer), maskRgn, PixData
    #[br(magic(0x009Bu16))]
    DirectBitsRgn(#[br(args(true))] DirectBits),
    /// Data length (Integer), data
    #[br(magic(0x009Cu16))]
    ReservedForAppleUse50(Integer, #[br(count(self_0))] Vec<u8>),
    /// Data length (Integer), data
    #[br(magic(0x009Du16))]
    ReservedForAppleUse51(Integer, #[br(count(self_0))] Vec<u8>),
    /// Data length (Integer), data
    #[br(magic(0x009Eu16))]
    ReservedForAppleUse52(Integer, #[br(count(self_0))] Vec<u8>),
    /// Data length (Integer), data
    #[br(magic(0x009Fu16))]
    ReservedForAppleUse53(Integer, #[br(count(self_0))] Vec<u8>),
    /// Kind (Integer)
    #[br(magic(0x00A0u16))]
    ShortComment(CommentKind),
    /// Kind (Integer), size (Integer), data
    #[br(magic(0x00A1u16))]
    LongComment(CommentKind, Integer, #[br(count(self_1))] Vec<u8>),
    /// Data length (Integer), data
    #[br(magic(0x00A2u16))]
    ReservedForAppleUse54(Integer, #[br(count(self_0))] Vec<u8>),
    // ...
    /// Data length (Integer), data
    #[br(magic(0x00AFu16))]
    ReservedForAppleUse55(Integer, #[br(count(self_0))] Vec<u8>),
    #[br(magic(0x00B0u16))]
    ReservedForAppleUse56,
    // ...
    #[br(magic(0x00CFu16))]
    ReservedForAppleUse57,
    /// Data length (Long), data
    #[br(magic(0x00D0u16))]
    ReservedForAppleUse58(Long, #[br(count(self_0))] Vec<u8>),
    // ...
    /// Data length (Long), data
    #[br(magic(0x00FEu16))]
    ReservedForAppleUse59(Long, #[br(count(self_0))] Vec<u8>),
    /// End of picture
    #[br(magic(0x00FFu16))]
    OpEndPic,
    /// 2 bytes of data
    #[br(magic(0x0100u16))]
    ReservedForAppleUse60(u16),
    // ...
    /// 2 bytes of data
    #[br(magic(0x01FFu16))]
    ReservedForAppleUse61(u16),
    /// 4 bytes of data
    #[br(magic(0x0200u16))]
    ReservedForAppleUse62(u32),
    /// Version number of picture
    #[br(magic(0x02FFu16))]
    Version,
    // ...
    /// 22 bytes of data
    #[br(magic(0x0BFFu16))]
    ReservedForAppleUse63([u8; 22]),
    /// For extended version 2: version  (Integer), reserved (Integer), hRes, vRes (Fixed), srcRect, reserved (Long); for version 2: opcode
    #[br(magic(0x0C00u16))]
    HeaderOp(Header),
    /// 24 bytes of data
    #[br(magic(0x0C01u16))]
    ReservedForAppleUse64([u8; 24]),
    // ...
    /// 254 bytes of data
    #[br(magic(0x7F00u16))]
    ReservedForAppleUse65([u8; 254]),
    // ...
    #[br(magic(0x7FFFu16))]
    ReservedForAppleUse66([u8; 254]),
    #[br(magic(0x8000u16))]
    ReservedForAppleUse67,
    // ...
    #[br(magic(0x80FFu16))]
    ReservedForAppleUse68,
    /// Data length (Long), data
    #[br(magic(0x8100u16))]
    ReservedForAppleUse69(Long, #[br(count(self_0))] Vec<u8>),
    // ...
    /// Data length (Long), data (private to QuickTime)
    #[br(magic(0x8200u16))]
    CompressedQuickTime(Long, #[br(count(self_0))] Vec<u8>),
    /// Data length (Long), data (private to QuickTime)
    #[br(magic(0x8201u16))]
    UncompressedQuickTime(Long, #[br(count(self_0))] Vec<u8>),
    /// Data length (Long), data
    #[br(magic(0xFFFFu16))]
    ReservedForAppleUse70(Long, #[br(count(self_0))] Vec<u8>),

    Unknown(u16),
}

#[derive(Debug)]
pub struct DirectBits {
    pub pix_map: PixMap,
    pub src_rect: Rect,
    pub dst_rect: Rect,
    pub mode: Short,
    pub mask: Option<Region>,
    pub data: Vec<u8>,
}

impl BinRead for DirectBits {
    type Args<'a> = (bool,);

    fn read_options<R: std::io::Read + std::io::Seek>(
        reader: &mut R,
        _endian: binrw::Endian,
        (masked,): Self::Args<'_>,
    ) -> BinResult<Self> {
        let _base_address: u32 = reader.read_be()?;
        let row_bytes_and_flags_hi: u8 = reader.read_be()?;
        let result: BinResult<PixMap> = reader.read_be_args((row_bytes_and_flags_hi,));
        let pix_map: PixMap = result?;
        let src_rect = reader.read_be()?;
        let dst_rect = reader.read_be()?;
        let mode = reader.read_be()?;
        let mask = if masked {
            Some(reader.read_be()?)
        } else {
            None
        };

        let scanline_count = pix_map.bounds.height() as usize;
        let scanline_size = pix_map.component_count as usize * pix_map.bounds.width() as usize;
        let unpacked_size = scanline_count * scanline_size;
        let mut data = vec![0u8; unpacked_size];

        for y in 0..scanline_count {
            #[allow(unused)]
            let packed_scanline_size: usize = if scanline_size > 250 {
                reader.read_be::<u16>()?.into()
            } else {
                reader.read_be::<u8>()?.into()
            };

            // TODO: Use packed_scanline_size to limit bytes read
            let unpacked_scanline_range = (y * scanline_size)..((y + 1) * scanline_size);
            reader.read_packbits(&mut data[unpacked_scanline_range])?;
        }

        Ok(DirectBits {
            pix_map,
            src_rect,
            dst_rect,
            mode,
            mask,
            data,
        })
    }
}