-
Notifications
You must be signed in to change notification settings - Fork 31
/
png.cpp
3086 lines (2723 loc) · 90.3 KB
/
png.cpp
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
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
#include <unordered_map>
#include "bt.h"
enum pngColorSpaceType : byte {
GrayScale = (byte) 0,
TrueColor = (byte) 2,
Indexed = (byte) 3,
AlphaGrayScale = (byte) 4,
AlphaTrueColor = (byte) 6,
};
std::vector<byte> pngColorSpaceType_values = { GrayScale, TrueColor, Indexed, AlphaGrayScale, AlphaTrueColor };
typedef enum pngColorSpaceType PNG_COLOR_SPACE_TYPE;
std::vector<byte> PNG_COLOR_SPACE_TYPE_values = { GrayScale, TrueColor, Indexed, AlphaGrayScale, AlphaTrueColor };
enum pngCompressionMethod : byte {
Deflate = (byte) 0,
};
std::vector<byte> pngCompressionMethod_values = { Deflate };
typedef enum pngCompressionMethod PNG_COMPR_METHOD;
std::vector<byte> PNG_COMPR_METHOD_values = { Deflate };
enum pngFilterMethod : byte {
AdaptiveFiltering = (byte) 0,
};
std::vector<byte> pngFilterMethod_values = { AdaptiveFiltering };
typedef enum pngFilterMethod PNG_FILTER_METHOD;
std::vector<byte> PNG_FILTER_METHOD_values = { AdaptiveFiltering };
enum pngInterlaceMethod : byte {
NoInterlace = (byte) 0,
Adam7Interlace = (byte) 1,
};
std::vector<byte> pngInterlaceMethod_values = { NoInterlace, Adam7Interlace };
typedef enum pngInterlaceMethod PNG_INTERLACE_METHOD;
std::vector<byte> PNG_INTERLACE_METHOD_values = { NoInterlace, Adam7Interlace };
enum PNG_SRGB_CHUNK_DATA_enum : byte {
Perceptual = (byte) 0,
RelativeColorimetric = (byte) 1,
Saturation = (byte) 2,
AbsoluteColorimetric = (byte) 3,
};
std::vector<byte> PNG_SRGB_CHUNK_DATA_enum_values = { Perceptual, RelativeColorimetric, Saturation, AbsoluteColorimetric };
typedef enum PNG_SRGB_CHUNK_DATA_enum PNG_SRGB_CHUNK_DATA;
std::vector<byte> PNG_SRGB_CHUNK_DATA_values = { Perceptual, RelativeColorimetric, Saturation, AbsoluteColorimetric };
enum APNG_DISPOSE_OP_enum : byte {
APNG_DISPOSE_OP_NONE = (byte) 0,
APNG_DISPOSE_OP_BACKGROUND = (byte) 1,
APNG_DISPOSE_OP_PREVIOUS = (byte) 2,
};
std::vector<byte> APNG_DISPOSE_OP_enum_values = { APNG_DISPOSE_OP_NONE, APNG_DISPOSE_OP_BACKGROUND, APNG_DISPOSE_OP_PREVIOUS };
typedef enum APNG_DISPOSE_OP_enum APNG_DISPOSE_OP;
std::vector<byte> APNG_DISPOSE_OP_values = { APNG_DISPOSE_OP_NONE, APNG_DISPOSE_OP_BACKGROUND, APNG_DISPOSE_OP_PREVIOUS };
enum APNG_BLEND_OP_enum : byte {
APNG_BLEND_OP_SOURCE = (byte) 0,
APNG_BLEND_OP_OVER = (byte) 1,
};
std::vector<byte> APNG_BLEND_OP_enum_values = { APNG_BLEND_OP_SOURCE, APNG_BLEND_OP_OVER };
typedef enum APNG_BLEND_OP_enum APNG_BLEND_OP;
std::vector<byte> APNG_BLEND_OP_values = { APNG_BLEND_OP_SOURCE, APNG_BLEND_OP_OVER };
class uint16_class {
int small;
std::vector<uint16> known_values;
uint16 value;
public:
int64 _startof = 0;
std::size_t _sizeof = sizeof(uint16);
uint16 operator () () { return value; }
uint16_class(int small, std::vector<uint16> known_values = {}) : small(small), known_values(known_values) {}
uint16 generate() {
_startof = FTell();
if (known_values.empty()) {
value = file_acc.file_integer(sizeof(uint16), 0, small);
} else {
value = file_acc.file_integer(sizeof(uint16), 0, known_values);
}
return value;
}
uint16 generate(std::vector<uint16> possible_values) {
_startof = FTell();
value = file_acc.file_integer(sizeof(uint16), 0, possible_values);
return value;
}
};
class uint16_array_class {
uint16_class& element;
std::unordered_map<int, std::vector<uint16>> element_known_values;
std::vector<uint16> value;
public:
int64 _startof = 0;
std::size_t _sizeof = 0;
std::vector<uint16> operator () () { return value; }
uint16 operator [] (int index) {
assert_cond((unsigned)index < value.size(), "array index out of bounds");
return value[index];
}
uint16_array_class(uint16_class& element, std::unordered_map<int, std::vector<uint16>> element_known_values = {})
: element(element), element_known_values(element_known_values) {}
std::vector<uint16> generate(unsigned size) {
check_array_length(size);
_startof = FTell();
value = {};
for (unsigned i = 0; i < size; ++i) {
auto known = element_known_values.find(i);
if (known == element_known_values.end()) {
value.push_back(element.generate());
_sizeof += element._sizeof;
} else {
value.push_back(file_acc.file_integer(sizeof(uint16), 0, known->second));
_sizeof += sizeof(uint16);
}
}
return value;
}
};
class PNG_SIGNATURE {
std::vector<PNG_SIGNATURE*>& instances;
std::vector<uint16> btPngSignature_var;
public:
bool btPngSignature_exists = false;
std::vector<uint16>& btPngSignature() {
assert_cond(btPngSignature_exists, "struct field btPngSignature does not exist");
return btPngSignature_var;
}
unsigned char generated = 0;
static int _parent_id;
static int _index_start;
int64 _startof = 0;
std::size_t _sizeof = 0;
PNG_SIGNATURE& operator () () { return *instances.back(); }
PNG_SIGNATURE& operator [] (int index) {
assert_cond((unsigned)(_index_start + index) < instances.size(), "instance index out of bounds");
return *instances[_index_start + index];
}
std::size_t array_size() {
return instances.size() - _index_start;
}
PNG_SIGNATURE(std::vector<PNG_SIGNATURE*>& instances) : instances(instances) { instances.push_back(this); }
~PNG_SIGNATURE() {
if (generated == 2)
return;
while (instances.size()) {
PNG_SIGNATURE* instance = instances.back();
instances.pop_back();
if (instance->generated == 2)
delete instance;
}
}
PNG_SIGNATURE* generate();
};
int PNG_SIGNATURE::_parent_id = 0;
int PNG_SIGNATURE::_index_start = 0;
class uint32_class {
int small;
std::vector<uint32> known_values;
uint32 value;
public:
int64 _startof = 0;
std::size_t _sizeof = sizeof(uint32);
uint32 operator () () { return value; }
uint32_class(int small, std::vector<uint32> known_values = {}) : small(small), known_values(known_values) {}
uint32 generate() {
_startof = FTell();
if (known_values.empty()) {
value = file_acc.file_integer(sizeof(uint32), 0, small);
} else {
value = file_acc.file_integer(sizeof(uint32), 0, known_values);
}
return value;
}
uint32 generate(std::vector<uint32> possible_values) {
_startof = FTell();
value = file_acc.file_integer(sizeof(uint32), 0, possible_values);
return value;
}
};
class char_class {
int small;
std::vector<char> known_values;
char value;
public:
int64 _startof = 0;
std::size_t _sizeof = sizeof(char);
char operator () () { return value; }
char_class(int small, std::vector<char> known_values = {}) : small(small), known_values(known_values) {}
char generate() {
_startof = FTell();
if (known_values.empty()) {
value = file_acc.file_integer(sizeof(char), 0, small);
} else {
value = file_acc.file_integer(sizeof(char), 0, known_values);
}
return value;
}
char generate(std::vector<char> possible_values) {
_startof = FTell();
value = file_acc.file_integer(sizeof(char), 0, possible_values);
return value;
}
};
class char_array_class {
char_class& element;
std::vector<std::string> known_values;
std::unordered_map<int, std::vector<char>> element_known_values;
std::string value;
public:
int64 _startof = 0;
std::size_t _sizeof = 0;
std::string operator () () { return value; }
char operator [] (int index) {
assert_cond((unsigned)index < value.size(), "array index out of bounds");
return value[index];
}
char_array_class(char_class& element, std::unordered_map<int, std::vector<char>> element_known_values = {})
: element(element), element_known_values(element_known_values) {}
char_array_class(char_class& element, std::vector<std::string> known_values)
: element(element), known_values(known_values) {}
std::string generate(unsigned size, std::vector<std::string> possible_values = {}) {
check_array_length(size);
_startof = FTell();
value = "";
if (possible_values.size()) {
value = file_acc.file_string(possible_values);
assert(value.length() == size);
_sizeof = size;
return value;
}
if (known_values.size()) {
value = file_acc.file_string(known_values);
assert(value.length() == size);
_sizeof = size;
return value;
}
if (!element_known_values.size()) {
if (size == 0)
return "";
value = file_acc.file_string(size);
_sizeof = size;
return value;
}
for (unsigned i = 0; i < size; ++i) {
auto known = element_known_values.find(i);
if (known == element_known_values.end()) {
value.push_back(element.generate());
_sizeof += element._sizeof;
} else {
value.push_back(file_acc.file_integer(sizeof(char), 0, known->second));
_sizeof += sizeof(char);
}
}
return value;
}
};
class CTYPE {
std::vector<CTYPE*>& instances;
// union {
std::string cname_var;
uint32 ctype_var;
// };
public:
bool cname_exists = false;
bool ctype_exists = false;
std::string& cname() {
assert_cond(cname_exists, "struct field cname does not exist");
return cname_var;
}
uint32& ctype() {
assert_cond(ctype_exists, "struct field ctype does not exist");
return ctype_var;
}
unsigned char generated = 0;
static int _parent_id;
static int _index_start;
int64 _startof = 0;
std::size_t _sizeof = 0;
CTYPE& operator () () { return *instances.back(); }
CTYPE& operator [] (int index) {
assert_cond((unsigned)(_index_start + index) < instances.size(), "instance index out of bounds");
return *instances[_index_start + index];
}
std::size_t array_size() {
return instances.size() - _index_start;
}
CTYPE(std::vector<CTYPE*>& instances) : instances(instances) { instances.push_back(this); }
~CTYPE() {
if (generated == 2)
return;
while (instances.size()) {
CTYPE* instance = instances.back();
instances.pop_back();
if (instance->generated == 2)
delete instance;
}
}
CTYPE* generate();
};
int CTYPE::_parent_id = 0;
int CTYPE::_index_start = 0;
const std::vector<byte> color_types = { GrayScale, TrueColor, Indexed, AlphaGrayScale, AlphaTrueColor };
class ubyte_class {
int small;
std::vector<ubyte> known_values;
ubyte value;
public:
int64 _startof = 0;
std::size_t _sizeof = sizeof(ubyte);
ubyte operator () () { return value; }
ubyte_class(int small, std::vector<ubyte> known_values = {}) : small(small), known_values(known_values) {}
ubyte generate() {
_startof = FTell();
if (known_values.empty()) {
value = file_acc.file_integer(sizeof(ubyte), 0, small);
} else {
value = file_acc.file_integer(sizeof(ubyte), 0, known_values);
}
return value;
}
ubyte generate(std::vector<ubyte> possible_values) {
_startof = FTell();
value = file_acc.file_integer(sizeof(ubyte), 0, possible_values);
return value;
}
};
PNG_COLOR_SPACE_TYPE PNG_COLOR_SPACE_TYPE_generate() {
return (PNG_COLOR_SPACE_TYPE) file_acc.file_integer(sizeof(byte), 0, PNG_COLOR_SPACE_TYPE_values);
}
PNG_COLOR_SPACE_TYPE PNG_COLOR_SPACE_TYPE_generate(std::vector<byte> known_values) {
return (PNG_COLOR_SPACE_TYPE) file_acc.file_integer(sizeof(byte), 0, known_values);
}
PNG_COMPR_METHOD PNG_COMPR_METHOD_generate() {
return (PNG_COMPR_METHOD) file_acc.file_integer(sizeof(byte), 0, PNG_COMPR_METHOD_values);
}
PNG_COMPR_METHOD PNG_COMPR_METHOD_generate(std::vector<byte> known_values) {
return (PNG_COMPR_METHOD) file_acc.file_integer(sizeof(byte), 0, known_values);
}
PNG_FILTER_METHOD PNG_FILTER_METHOD_generate() {
return (PNG_FILTER_METHOD) file_acc.file_integer(sizeof(byte), 0, PNG_FILTER_METHOD_values);
}
PNG_FILTER_METHOD PNG_FILTER_METHOD_generate(std::vector<byte> known_values) {
return (PNG_FILTER_METHOD) file_acc.file_integer(sizeof(byte), 0, known_values);
}
PNG_INTERLACE_METHOD PNG_INTERLACE_METHOD_generate() {
return (PNG_INTERLACE_METHOD) file_acc.file_integer(sizeof(byte), 0, PNG_INTERLACE_METHOD_values);
}
PNG_INTERLACE_METHOD PNG_INTERLACE_METHOD_generate(std::vector<byte> known_values) {
return (PNG_INTERLACE_METHOD) file_acc.file_integer(sizeof(byte), 0, known_values);
}
class PNG_CHUNK_IHDR {
std::vector<PNG_CHUNK_IHDR*>& instances;
uint32 width_var;
uint32 height_var;
ubyte bits_var;
byte color_type_var;
byte compr_method_var;
byte filter_method_var;
byte interlace_method_var;
public:
bool width_exists = false;
bool height_exists = false;
bool bits_exists = false;
bool color_type_exists = false;
bool compr_method_exists = false;
bool filter_method_exists = false;
bool interlace_method_exists = false;
uint32& width() {
assert_cond(width_exists, "struct field width does not exist");
return width_var;
}
uint32& height() {
assert_cond(height_exists, "struct field height does not exist");
return height_var;
}
ubyte& bits() {
assert_cond(bits_exists, "struct field bits does not exist");
return bits_var;
}
byte& color_type() {
assert_cond(color_type_exists, "struct field color_type does not exist");
return color_type_var;
}
byte& compr_method() {
assert_cond(compr_method_exists, "struct field compr_method does not exist");
return compr_method_var;
}
byte& filter_method() {
assert_cond(filter_method_exists, "struct field filter_method does not exist");
return filter_method_var;
}
byte& interlace_method() {
assert_cond(interlace_method_exists, "struct field interlace_method does not exist");
return interlace_method_var;
}
unsigned char generated = 0;
static int _parent_id;
static int _index_start;
int64 _startof = 0;
std::size_t _sizeof = 0;
PNG_CHUNK_IHDR& operator () () { return *instances.back(); }
PNG_CHUNK_IHDR& operator [] (int index) {
assert_cond((unsigned)(_index_start + index) < instances.size(), "instance index out of bounds");
return *instances[_index_start + index];
}
std::size_t array_size() {
return instances.size() - _index_start;
}
PNG_CHUNK_IHDR(std::vector<PNG_CHUNK_IHDR*>& instances) : instances(instances) { instances.push_back(this); }
~PNG_CHUNK_IHDR() {
if (generated == 2)
return;
while (instances.size()) {
PNG_CHUNK_IHDR* instance = instances.back();
instances.pop_back();
if (instance->generated == 2)
delete instance;
}
}
PNG_CHUNK_IHDR* generate();
};
int PNG_CHUNK_IHDR::_parent_id = 0;
int PNG_CHUNK_IHDR::_index_start = 0;
class string_class {
std::vector<std::string> known_values;
std::string value;
public:
int64 _startof = 0;
std::size_t _sizeof = 0;
std::string operator () () { return value; }
string_class(std::vector<std::string> known_values = {}) : known_values(known_values) {}
std::string generate() {
_startof = FTell();
if (known_values.empty()) {
value = file_acc.file_string();
} else {
value = file_acc.file_string(known_values);
}
_sizeof = value.length() + 1;
return value;
}
};
class PNG_CHUNK_TEXT {
std::vector<PNG_CHUNK_TEXT*>& instances;
std::string label_var;
std::string data_var;
public:
bool label_exists = false;
bool data_exists = false;
std::string& label() {
assert_cond(label_exists, "struct field label does not exist");
return label_var;
}
std::string& data() {
assert_cond(data_exists, "struct field data does not exist");
return data_var;
}
unsigned char generated = 0;
static int _parent_id;
static int _index_start;
int64 _startof = 0;
std::size_t _sizeof = 0;
PNG_CHUNK_TEXT& operator () () { return *instances.back(); }
PNG_CHUNK_TEXT& operator [] (int index) {
assert_cond((unsigned)(_index_start + index) < instances.size(), "instance index out of bounds");
return *instances[_index_start + index];
}
std::size_t array_size() {
return instances.size() - _index_start;
}
PNG_CHUNK_TEXT(std::vector<PNG_CHUNK_TEXT*>& instances) : instances(instances) { instances.push_back(this); }
~PNG_CHUNK_TEXT() {
if (generated == 2)
return;
while (instances.size()) {
PNG_CHUNK_TEXT* instance = instances.back();
instances.pop_back();
if (instance->generated == 2)
delete instance;
}
}
PNG_CHUNK_TEXT* generate();
};
int PNG_CHUNK_TEXT::_parent_id = 0;
int PNG_CHUNK_TEXT::_index_start = 0;
class byte_class {
int small;
std::vector<byte> known_values;
byte value;
public:
int64 _startof = 0;
std::size_t _sizeof = sizeof(byte);
byte operator () () { return value; }
byte_class(int small, std::vector<byte> known_values = {}) : small(small), known_values(known_values) {}
byte generate() {
_startof = FTell();
if (known_values.empty()) {
value = file_acc.file_integer(sizeof(byte), 0, small);
} else {
value = file_acc.file_integer(sizeof(byte), 0, known_values);
}
return value;
}
byte generate(std::vector<byte> possible_values) {
_startof = FTell();
value = file_acc.file_integer(sizeof(byte), 0, possible_values);
return value;
}
};
class PNG_PALETTE_PIXEL {
std::vector<PNG_PALETTE_PIXEL*>& instances;
byte btRed_var;
byte btGreen_var;
byte btBlue_var;
public:
bool btRed_exists = false;
bool btGreen_exists = false;
bool btBlue_exists = false;
byte& btRed() {
assert_cond(btRed_exists, "struct field btRed does not exist");
return btRed_var;
}
byte& btGreen() {
assert_cond(btGreen_exists, "struct field btGreen does not exist");
return btGreen_var;
}
byte& btBlue() {
assert_cond(btBlue_exists, "struct field btBlue does not exist");
return btBlue_var;
}
unsigned char generated = 0;
static int _parent_id;
static int _index_start;
int64 _startof = 0;
std::size_t _sizeof = 0;
PNG_PALETTE_PIXEL& operator () () { return *instances.back(); }
PNG_PALETTE_PIXEL& operator [] (int index) {
assert_cond((unsigned)(_index_start + index) < instances.size(), "instance index out of bounds");
return *instances[_index_start + index];
}
std::size_t array_size() {
return instances.size() - _index_start;
}
PNG_PALETTE_PIXEL(std::vector<PNG_PALETTE_PIXEL*>& instances) : instances(instances) { instances.push_back(this); }
~PNG_PALETTE_PIXEL() {
if (generated == 2)
return;
while (instances.size()) {
PNG_PALETTE_PIXEL* instance = instances.back();
instances.pop_back();
if (instance->generated == 2)
delete instance;
}
}
PNG_PALETTE_PIXEL* generate();
};
int PNG_PALETTE_PIXEL::_parent_id = 0;
int PNG_PALETTE_PIXEL::_index_start = 0;
class PNG_PALETTE_PIXEL_array_class {
PNG_PALETTE_PIXEL& element;
std::vector<PNG_PALETTE_PIXEL*> value;
public:
int64 _startof = 0;
std::size_t _sizeof = 0;
std::vector<PNG_PALETTE_PIXEL*> operator () () { return value; }
PNG_PALETTE_PIXEL operator [] (int index) {
assert_cond((unsigned)index < value.size(), "array index out of bounds");
return *value[index];
}
PNG_PALETTE_PIXEL_array_class(PNG_PALETTE_PIXEL& element) : element(element) {}
std::vector<PNG_PALETTE_PIXEL*> generate(unsigned size) {
check_array_length(size);
_startof = FTell();
value = {};
for (unsigned i = 0; i < size; ++i) {
value.push_back(element.generate());
_sizeof += element._sizeof;
}
return value;
}
};
class PNG_CHUNK_PLTE {
std::vector<PNG_CHUNK_PLTE*>& instances;
std::vector<PNG_PALETTE_PIXEL*> plteChunkData_var;
public:
bool plteChunkData_exists = false;
std::vector<PNG_PALETTE_PIXEL*>& plteChunkData() {
assert_cond(plteChunkData_exists, "struct field plteChunkData does not exist");
return plteChunkData_var;
}
unsigned char generated = 0;
static int _parent_id;
static int _index_start;
int64 _startof = 0;
std::size_t _sizeof = 0;
PNG_CHUNK_PLTE& operator () () { return *instances.back(); }
PNG_CHUNK_PLTE& operator [] (int index) {
assert_cond((unsigned)(_index_start + index) < instances.size(), "instance index out of bounds");
return *instances[_index_start + index];
}
std::size_t array_size() {
return instances.size() - _index_start;
}
PNG_CHUNK_PLTE(std::vector<PNG_CHUNK_PLTE*>& instances) : instances(instances) { instances.push_back(this); }
~PNG_CHUNK_PLTE() {
if (generated == 2)
return;
while (instances.size()) {
PNG_CHUNK_PLTE* instance = instances.back();
instances.pop_back();
if (instance->generated == 2)
delete instance;
}
}
PNG_CHUNK_PLTE* generate(int32 chunkLen);
};
int PNG_CHUNK_PLTE::_parent_id = 0;
int PNG_CHUNK_PLTE::_index_start = 0;
class PNG_POINT {
std::vector<PNG_POINT*>& instances;
uint32 x_var;
uint32 y_var;
public:
bool x_exists = false;
bool y_exists = false;
uint32& x() {
assert_cond(x_exists, "struct field x does not exist");
return x_var;
}
uint32& y() {
assert_cond(y_exists, "struct field y does not exist");
return y_var;
}
unsigned char generated = 0;
static int _parent_id;
static int _index_start;
int64 _startof = 0;
std::size_t _sizeof = 0;
PNG_POINT& operator () () { return *instances.back(); }
PNG_POINT& operator [] (int index) {
assert_cond((unsigned)(_index_start + index) < instances.size(), "instance index out of bounds");
return *instances[_index_start + index];
}
std::size_t array_size() {
return instances.size() - _index_start;
}
PNG_POINT(std::vector<PNG_POINT*>& instances) : instances(instances) { instances.push_back(this); }
~PNG_POINT() {
if (generated == 2)
return;
while (instances.size()) {
PNG_POINT* instance = instances.back();
instances.pop_back();
if (instance->generated == 2)
delete instance;
}
}
PNG_POINT* generate();
};
int PNG_POINT::_parent_id = 0;
int PNG_POINT::_index_start = 0;
class PNG_CHUNK_CHRM {
std::vector<PNG_CHUNK_CHRM*>& instances;
PNG_POINT* white_var;
PNG_POINT* red_var;
PNG_POINT* green_var;
PNG_POINT* blue_var;
public:
bool white_exists = false;
bool red_exists = false;
bool green_exists = false;
bool blue_exists = false;
PNG_POINT& white() {
assert_cond(white_exists, "struct field white does not exist");
return *white_var;
}
PNG_POINT& red() {
assert_cond(red_exists, "struct field red does not exist");
return *red_var;
}
PNG_POINT& green() {
assert_cond(green_exists, "struct field green does not exist");
return *green_var;
}
PNG_POINT& blue() {
assert_cond(blue_exists, "struct field blue does not exist");
return *blue_var;
}
unsigned char generated = 0;
static int _parent_id;
static int _index_start;
int64 _startof = 0;
std::size_t _sizeof = 0;
PNG_CHUNK_CHRM& operator () () { return *instances.back(); }
PNG_CHUNK_CHRM& operator [] (int index) {
assert_cond((unsigned)(_index_start + index) < instances.size(), "instance index out of bounds");
return *instances[_index_start + index];
}
std::size_t array_size() {
return instances.size() - _index_start;
}
PNG_CHUNK_CHRM(std::vector<PNG_CHUNK_CHRM*>& instances) : instances(instances) { instances.push_back(this); }
~PNG_CHUNK_CHRM() {
if (generated == 2)
return;
while (instances.size()) {
PNG_CHUNK_CHRM* instance = instances.back();
instances.pop_back();
if (instance->generated == 2)
delete instance;
}
}
PNG_CHUNK_CHRM* generate();
};
int PNG_CHUNK_CHRM::_parent_id = 0;
int PNG_CHUNK_CHRM::_index_start = 0;
PNG_SRGB_CHUNK_DATA PNG_SRGB_CHUNK_DATA_generate() {
return (PNG_SRGB_CHUNK_DATA) file_acc.file_integer(sizeof(byte), 0, PNG_SRGB_CHUNK_DATA_values);
}
PNG_SRGB_CHUNK_DATA PNG_SRGB_CHUNK_DATA_generate(std::vector<byte> known_values) {
return (PNG_SRGB_CHUNK_DATA) file_acc.file_integer(sizeof(byte), 0, known_values);
}
class PNG_CHUNK_SRGB {
std::vector<PNG_CHUNK_SRGB*>& instances;
byte srgbChunkData_var;
public:
bool srgbChunkData_exists = false;
byte& srgbChunkData() {
assert_cond(srgbChunkData_exists, "struct field srgbChunkData does not exist");
return srgbChunkData_var;
}
unsigned char generated = 0;
static int _parent_id;
static int _index_start;
int64 _startof = 0;
std::size_t _sizeof = 0;
PNG_CHUNK_SRGB& operator () () { return *instances.back(); }
PNG_CHUNK_SRGB& operator [] (int index) {
assert_cond((unsigned)(_index_start + index) < instances.size(), "instance index out of bounds");
return *instances[_index_start + index];
}
std::size_t array_size() {
return instances.size() - _index_start;
}
PNG_CHUNK_SRGB(std::vector<PNG_CHUNK_SRGB*>& instances) : instances(instances) { instances.push_back(this); }
~PNG_CHUNK_SRGB() {
if (generated == 2)
return;
while (instances.size()) {
PNG_CHUNK_SRGB* instance = instances.back();
instances.pop_back();
if (instance->generated == 2)
delete instance;
}
}
PNG_CHUNK_SRGB* generate();
};
int PNG_CHUNK_SRGB::_parent_id = 0;
int PNG_CHUNK_SRGB::_index_start = 0;
class PNG_CHUNK_ITXT {
std::vector<PNG_CHUNK_ITXT*>& instances;
std::string itxtIdChunkData_var;
byte itxtCompressionFlag_var;
byte itxtComprMethod_var;
std::string itxtLanguageTag_var;
std::string itxtTranslatedKeyword_var;
std::string itxtValChunkData_var;
public:
bool itxtIdChunkData_exists = false;
bool itxtCompressionFlag_exists = false;
bool itxtComprMethod_exists = false;
bool itxtLanguageTag_exists = false;
bool itxtTranslatedKeyword_exists = false;
bool itxtValChunkData_exists = false;
std::string& itxtIdChunkData() {
assert_cond(itxtIdChunkData_exists, "struct field itxtIdChunkData does not exist");
return itxtIdChunkData_var;
}
byte& itxtCompressionFlag() {
assert_cond(itxtCompressionFlag_exists, "struct field itxtCompressionFlag does not exist");
return itxtCompressionFlag_var;
}
byte& itxtComprMethod() {
assert_cond(itxtComprMethod_exists, "struct field itxtComprMethod does not exist");
return itxtComprMethod_var;
}
std::string& itxtLanguageTag() {
assert_cond(itxtLanguageTag_exists, "struct field itxtLanguageTag does not exist");
return itxtLanguageTag_var;
}
std::string& itxtTranslatedKeyword() {
assert_cond(itxtTranslatedKeyword_exists, "struct field itxtTranslatedKeyword does not exist");
return itxtTranslatedKeyword_var;
}
std::string& itxtValChunkData() {
assert_cond(itxtValChunkData_exists, "struct field itxtValChunkData does not exist");
return itxtValChunkData_var;
}
unsigned char generated = 0;
static int _parent_id;
static int _index_start;
int64 _startof = 0;
std::size_t _sizeof = 0;
PNG_CHUNK_ITXT& operator () () { return *instances.back(); }
PNG_CHUNK_ITXT& operator [] (int index) {
assert_cond((unsigned)(_index_start + index) < instances.size(), "instance index out of bounds");
return *instances[_index_start + index];
}
std::size_t array_size() {
return instances.size() - _index_start;
}
PNG_CHUNK_ITXT(std::vector<PNG_CHUNK_ITXT*>& instances) : instances(instances) { instances.push_back(this); }
~PNG_CHUNK_ITXT() {
if (generated == 2)
return;
while (instances.size()) {
PNG_CHUNK_ITXT* instance = instances.back();
instances.pop_back();
if (instance->generated == 2)
delete instance;
}
}
PNG_CHUNK_ITXT* generate(int32 chunkLen);
};
int PNG_CHUNK_ITXT::_parent_id = 0;
int PNG_CHUNK_ITXT::_index_start = 0;
class PNG_CHUNK_ZTXT {
std::vector<PNG_CHUNK_ZTXT*>& instances;
std::string ztxtIdChunkData_var;
byte comprMethod_var;
std::string ztxtValChunkData_var;
public:
bool ztxtIdChunkData_exists = false;
bool comprMethod_exists = false;
bool ztxtValChunkData_exists = false;
std::string& ztxtIdChunkData() {
assert_cond(ztxtIdChunkData_exists, "struct field ztxtIdChunkData does not exist");
return ztxtIdChunkData_var;
}
byte& comprMethod() {
assert_cond(comprMethod_exists, "struct field comprMethod does not exist");
return comprMethod_var;
}
std::string& ztxtValChunkData() {
assert_cond(ztxtValChunkData_exists, "struct field ztxtValChunkData does not exist");
return ztxtValChunkData_var;
}
unsigned char generated = 0;
static int _parent_id;
static int _index_start;
int64 _startof = 0;
std::size_t _sizeof = 0;
PNG_CHUNK_ZTXT& operator () () { return *instances.back(); }
PNG_CHUNK_ZTXT& operator [] (int index) {