-
Notifications
You must be signed in to change notification settings - Fork 217
/
swftypes.h
499 lines (443 loc) · 8.13 KB
/
swftypes.h
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
#ifndef SWFTYPES_H
#define SWFTYPES_H
#include <stdint.h>
#include <iostream>
#include <fstream>
#include <vector>
class UI32
{
private:
uint32_t val;
public:
UI32():val(0){}
UI32(uint32_t v):val(v){}
operator uint32_t(){ return val; }
};
class UI16
{
private:
uint16_t val;
public:
UI16():val(0){}
UI16(uint16_t v):val(v){}
operator uint16_t() const { return val; }
operator UI32() const { return val; }
};
class UI8
{
private:
uint8_t val;
public:
UI8():val(0){}
UI8(uint8_t v):val(v){}
operator uint8_t() const { return val; }
operator UI16(){ return val; }
};
class SI16
{
private:
int16_t val;
public:
SI16():val(0){}
SI16(int16_t v):val(v){}
operator int16_t(){ return val; }
};
typedef UI16 RECORDHEADER;
class RGB
{
public:
RGB(){};
RGB(int r,int g, int b):Red(r),Green(g),Blue(b){};
UI8 Red;
UI8 Green;
UI8 Blue;
};
class RGBA
{
public:
UI8 Red;
UI8 Green;
UI8 Blue;
UI8 Alpha;
RGBA& operator=(const RGB& r)
{
Red=r.Red;
Green=r.Green;
Blue=r.Blue;
Alpha=255;
}
};
typedef UI32 SI32;
typedef UI8 LANGCODE;
std::istream& operator>>(std::istream& s, RGB& v);
inline std::istream& operator>>(std::istream& s, UI8& v)
{
s.read((char*)&v,1);
return s;
}
inline std::istream& operator>>(std::istream& s, SI16& v)
{
s.read((char*)&v,2);
return s;
}
inline std::istream& operator>>(std::istream& s, UI16& v)
{
s.read((char*)&v,2);
return s;
}
inline std::istream& operator>>(std::istream& s, UI32& v)
{
s.read((char*)&v,4);
return s;
}
inline int min(int a,int b)
{
return (a<b)?a:b;
}
inline int max(int a,int b)
{
return (a>b)?a:b;
}
class BitStream
{
public:
std::istream& f;
unsigned char buffer;
unsigned char pos;
public:
BitStream(std::istream& in):f(in),pos(0){};
unsigned int readBits(unsigned int num)
{
unsigned int ret=0;
while(num)
{
if(!pos)
{
pos=8;
f.read((char*)&buffer,1);
}
ret<<=1;
ret|=(buffer>>(pos-1))&1;
pos--;
num--;
}
return ret;
}
};
class FB
{
uint32_t buf;
int size;
public:
FB() { buf=0; }
FB(int s,BitStream& stream):size(s)
{
if(s>32)
throw "FB too big\n";
buf=stream.readBits(s);
}
operator float() const
{
return (buf>>16)+(buf&0xffff)/65535.0f; //TODO: Oppure 65536?
}
};
class UB
{
uint32_t buf;
int size;
public:
UB() { buf=0; }
UB(int s,BitStream& stream):size(s)
{
/* if(s%8)
buf=new uint8_t[s/8+1];
else
buf=new uint8_t[s/8];
int i=0;
while(!s)
{
buf[i]=stream.readBits(min(s,8));
s-=min(s,8);
i++;
}*/
if(s>32)
throw "UB too big\n";
buf=stream.readBits(s);
}
operator int() const
{
return buf;
}
};
class SB
{
int32_t buf;
int size;
public:
SB() { buf=0; }
SB(int s,BitStream& stream):size(s)
{
if(s>32)
throw "SB too big\n";
buf=stream.readBits(s);
if(buf>>(s-1)&1)
{
for(int i=31;i>=s;i--)
buf|=(1<<i);
}
}
operator int() const
{
return buf;
}
};
class RECT
{
friend std::ostream& operator<<(std::ostream& s, const RECT& r);
friend std::istream& operator>>(std::istream& stream, RECT& v);
public:
UB NBits;
SB Xmin;
SB Xmax;
SB Ymin;
SB Ymax;
public:
RECT();
// RECT(FILE* in);
};
class FILLSTYLE
{
public:
UI8 FillStyleType;
RGB Color;
};
class MORPHFILLSTYLE
{
public:
UI8 FillStyleType;
RGBA StartColor;
RGBA EndColor;
};
class LINESTYLE
{
public:
UI16 Width;
RGB Color;
};
class MORPHLINESTYLE
{
public:
UI16 StartWidth;
UI16 EndWidth;
RGBA StartColor;
RGBA EndColor;
};
class LINESTYLEARRAY
{
public:
UI8 LineStyleCount;
LINESTYLE* LineStyles;
};
class MORPHLINESTYLEARRAY
{
public:
UI8 LineStyleCount;
MORPHLINESTYLE* LineStyles;
};
class FILLSTYLEARRAY
{
public:
UI8 FillStyleCount;
FILLSTYLE* FillStyles;
};
class MORPHFILLSTYLEARRAY
{
public:
UI8 FillStyleCount;
MORPHFILLSTYLE* FillStyles;
};
class SHAPE;
class SHAPEWITHSTYLE;
class SHAPERECORD
{
public:
SHAPE* parent;
UB TypeFlag;
UB StateNewStyles;
UB StateLineStyle;
UB StateFillStyle1;
UB StateFillStyle0;
UB StateMoveTo;
UB MoveBits;
SB MoveDeltaX;
SB MoveDeltaY;
UB FillStyle1;
UB FillStyle0;
UB LineStyle;
//Edge record
UB StraightFlag;
UB NumBits;
UB GeneralLineFlag;
UB VertLineFlag;
SB DeltaX;
SB DeltaY;
SB ControlDeltaX;
SB ControlDeltaY;
SB AnchorDeltaX;
SB AnchorDeltaY;
SHAPERECORD* next;
SHAPERECORD():next(0){};
SHAPERECORD(SHAPE* p,BitStream& bs);
};
class TEXTRECORD;
class GLYPHENTRY
{
public:
UB GlyphIndex;
SB GlyphAdvance;
TEXTRECORD* parent;
GLYPHENTRY(TEXTRECORD* p,BitStream& bs);
};
class DefineTextTag;
class TEXTRECORD
{
public:
UB TextRecordType;
UB StyleFlagsReserved;
UB StyleFlagsHasFont;
UB StyleFlagsHasColor;
UB StyleFlagsHasYOffset;
UB StyleFlagsHasXOffset;
UI16 FontID;
RGBA TextColor;
SI16 XOffset;
SI16 YOffset;
UI16 TextHeight;
UI8 GlyphCount;
std::vector <GLYPHENTRY> GlyphEntries;
DefineTextTag* parent;
TEXTRECORD(DefineTextTag* p):parent(p){}
};
class Shape;
class SHAPE
{
friend std::istream& operator>>(std::istream& stream, SHAPE& v);
friend std::istream& operator>>(std::istream& stream, SHAPEWITHSTYLE& v);
friend class SHAPERECORD;
friend class DefineShapeTag;
friend class DefineShape2Tag;
friend class DefineMorphShapeTag;
friend class DefineTextTag;
friend class DefineFontTag;
friend class DefineFont2Tag;
private:
UB NumFillBits;
UB NumLineBits;
SHAPERECORD ShapeRecords;
};
class SHAPEWITHSTYLE : public SHAPE
{
friend std::istream& operator>>(std::istream& stream, SHAPEWITHSTYLE& v);
public:
int version;
FILLSTYLEARRAY FillStyles;
LINESTYLEARRAY LineStyles;
public:
// SHAPEWITHSTYLE(){}
};
class CXFORMWITHALPHA
{
friend std::istream& operator>>(std::istream& stream, CXFORMWITHALPHA& v);
private:
UB HasAddTerms;
UB HasMultTerms;
UB NBits;
SB RedMultTerm;
SB GreenMultTerm;
SB BlueMultTerm;
SB AlphaMultTerm;
SB RedAddTerm;
SB GreenAddTerm;
SB BlueAddTerm;
SB AlphaAddTerm;
};
class STRING
{
public:
std::vector<UI8> String;
};
class CLIPACTIONS
{
};
class MATRIX
{
friend std::istream& operator>>(std::istream& stream, MATRIX& v);
friend std::ostream& operator<<(std::ostream& s, const MATRIX& r);
private:
int size;
UB HasScale;
UB NScaleBits;
FB ScaleX;
FB ScaleY;
UB HasRotate;
UB NRotateBits;
FB RotateSkew0;
FB RotateSkew1;
UB NTranslateBits;
SB TranslateX;
SB TranslateY;
public:
MATRIX():size(0){}
void get4DMatrix(float matrix[16]);
//int getSize(){return size;}
};
class CXFORM
{
};
class FILTERLIST
{
};
class BUTTONRECORD
{
public:
UB ButtonReserved;
UB ButtonHasBlendMode;
UB ButtonHasFilterList;
UB ButtonStateHitTest;
UB ButtonStateDown;
UB ButtonStateOver;
UB ButtonStateUp;
UI16 CharacterID;
UI16 PlaceDepth;
MATRIX PlaceMatrix;
CXFORMWITHALPHA ColorTransform;
FILTERLIST FilterList;
UI8 BlendMode;
bool isNull() const
{
return !(ButtonReserved | ButtonHasBlendMode | ButtonHasFilterList | ButtonStateHitTest | ButtonStateDown | ButtonStateOver | ButtonStateUp);
}
};
std::ostream& operator<<(std::ostream& s, const RECT& r);
std::ostream& operator<<(std::ostream& s, const RGB& r);
std::ostream& operator<<(std::ostream& s, const RGBA& r);
std::ostream& operator<<(std::ostream& s, const STRING& r);
std::istream& operator>>(std::istream& s, RECT& v);
std::istream& operator>>(std::istream& stream, SHAPEWITHSTYLE& v);
std::istream& operator>>(std::istream& stream, SHAPE& v);
std::istream& operator>>(std::istream& stream, FILLSTYLEARRAY& v);
std::istream& operator>>(std::istream& stream, MORPHFILLSTYLEARRAY& v);
std::istream& operator>>(std::istream& stream, LINESTYLEARRAY& v);
std::istream& operator>>(std::istream& stream, MORPHLINESTYLEARRAY& v);
std::istream& operator>>(std::istream& stream, LINESTYLE& v);
std::istream& operator>>(std::istream& stream, MORPHLINESTYLE& v);
std::istream& operator>>(std::istream& stream, FILLSTYLE& v);
std::istream& operator>>(std::istream& stream, MORPHFILLSTYLE& v);
std::istream& operator>>(std::istream& stream, SHAPERECORD& v);
std::istream& operator>>(std::istream& stream, TEXTRECORD& v);
std::istream& operator>>(std::istream& stream, MATRIX& v);
std::istream& operator>>(std::istream& stream, CXFORMWITHALPHA& v);
std::istream& operator>>(std::istream& stream, GLYPHENTRY& v);
std::istream& operator>>(std::istream& stream, STRING& v);
std::istream& operator>>(std::istream& stream, BUTTONRECORD& v);
#endif