jimhourihan / gto

Production Kitchen Sink Computer Graphics File Format

This URL has Read+Write access

gto / patches / lucas-patch
100644 635 lines (574 sloc) 19.668 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
diff -ru gto-3.4.0/bin/gtoinfo/main.cpp gto-3.4.0-ilm/bin/gtoinfo/main.cpp
--- gto-3.4.0/bin/gtoinfo/main.cpp 2008-06-23 09:07:13.551766000 -0700
+++ gto-3.4.0-ilm/bin/gtoinfo/main.cpp 2007-11-05 15:59:04.866740000 -0800
@@ -32,6 +32,7 @@
 bool outputHeader = true;
 bool formatData = false;
 bool readAll = false;
+bool readAsLEC = false;
 bool numericStrings = false;
 bool filtered = false;
 bool outputInterp = false;
@@ -75,7 +76,7 @@
                                  const Gto::Reader::PropertyInfo &header);
 
     virtual void* data(const PropertyInfo&, size_t bytes);
- virtual void dataRead(const PropertyInfo&);
+ virtual void dataRead(const PropertyInfo&,char *buffer);
 
     virtual void data(const PropertyInfo&,
                              const float*, size_t numItems);
@@ -316,7 +317,7 @@
 }
 
 void
-Reader::dataRead(const PropertyInfo& info)
+Reader::dataRead(const PropertyInfo& info,char *)
 {
     void* buffer = (void*)&m_buffer.front();
 
@@ -683,6 +684,7 @@
          << "-a/--all dump data and header\n"
          << "-d/--dump dump data (no header)\n"
          << "-l/--line dump data/strings one per line\n"
+ << "-L/--LEC force read GTO file as LEC format\n"
          << "-h/--header header only (default)\n"
          << "-s/--strings output strings table\n"
          << "-n/--numeric-strings output string properties as string numbers\n"
@@ -743,6 +745,11 @@
             {
                 formatData = true;
             }
+ else if (!strcmp(arg, "-L") ||
+ !strcmp(arg, "--LEC"))
+ {
+ readAsLEC = true;
+ }
             else if (!strcmp(arg, "-n") ||
                      !strcmp(arg, "--numeric-strings"))
             {
@@ -783,6 +790,8 @@
 
     if (filterExpr != "") mode = Gto::Reader::RandomAccess;
 
+ if (readAsLEC) mode |= Gto::Reader::ReadAsLEC;
+
     Reader reader(mode);
 
     if ( !reader.open(inFile) )
diff -ru gto-3.4.0/lib/Gto/Header.h gto-3.4.0-ilm/lib/Gto/Header.h
--- gto-3.4.0/lib/Gto/Header.h 2008-06-23 09:07:35.517105000 -0700
+++ gto-3.4.0-ilm/lib/Gto/Header.h 2007-11-05 15:59:05.314773000 -0800
@@ -33,6 +33,8 @@
 
 #define GTO_MAGIC 0x29f
 #define GTO_MAGICl 0x9f020000
+#define GTO_MAGIC_LEC 0x39f
+#define GTO_MAGIC_LECl 0x9f030000
 #define GTO_MAGIC_TEXT 0x47544f61
 #define GTO_MAGIC_TEXTl 0x614f5447
 #define GTO_VERSION 3
@@ -54,6 +56,8 @@
     static const unsigned int CigamText = GTO_MAGIC_TEXTl;
     static const unsigned int Magic = GTO_MAGIC;
     static const unsigned int Cigam = GTO_MAGICl;
+ static const unsigned int MagicLEC = GTO_MAGIC_LEC;
+ static const unsigned int CigamLEC = GTO_MAGIC_LECl;
 
     uint32 magic;
     uint32 numStrings;
@@ -75,6 +79,14 @@
     uint32 pad;
 };
 
+struct ObjectHeaderLEC
+{
+ uint16 name; // string
+ uint16 protocolName; // string
+ uint8 protocolVersion;
+ uint16 numComponents;
+};
+
 struct ObjectHeader_v2
 {
     uint32 name; // string
@@ -102,6 +114,13 @@
     uint32 pad;
 };
 
+struct ComponentHeaderLEC
+{
+ uint16 name; // string
+ uint8 numProperties;
+ uint8 flags;
+};
+
 struct ComponentHeader_v2
 {
     uint32 name; // string
@@ -139,6 +158,14 @@
     uint32 pad;
 };
 
+struct PropertyHeaderLEC
+{
+ uint16 name; // string
+ uint32 size;
+ uint8 type;
+ uint8 width;
+};
+
 struct PropertyHeader_v2
 {
     uint32 name;
diff -ru gto-3.4.0/lib/Gto/RawData.cpp gto-3.4.0-ilm/lib/Gto/RawData.cpp
--- gto-3.4.0/lib/Gto/RawData.cpp 2008-06-23 09:09:24.555781000 -0700
+++ gto-3.4.0-ilm/lib/Gto/RawData.cpp 2007-11-05 15:59:05.433782000 -0800
@@ -199,7 +199,7 @@
 }
 
 void
-RawDataBaseReader::dataRead(const PropertyInfo& info)
+RawDataBaseReader::dataRead(const PropertyInfo& info,char *buffer)
 {
     //Object *o = reinterpret_cast<Object*>(info.component->object->objectData);
     //Component *c = reinterpret_cast<Component*>(info.component->componentData);
diff -ru gto-3.4.0/lib/Gto/RawData.h gto-3.4.0-ilm/lib/Gto/RawData.h
--- gto-3.4.0/lib/Gto/RawData.h 2008-06-23 09:09:24.560778000 -0700
+++ gto-3.4.0-ilm/lib/Gto/RawData.h 2007-11-05 15:59:05.448785000 -0800
@@ -162,7 +162,7 @@
                                  const PropertyInfo &header);
 
     virtual void* data(const PropertyInfo&, size_t bytes);
- virtual void dataRead(const PropertyInfo&);
+ virtual void dataRead(const PropertyInfo&,char *buffer);
 
 protected:
     RawDataBase* m_dataBase;
@@ -180,7 +180,7 @@
 class RawDataBaseWriter
 {
 public:
- RawDataBaseWriter() : m_writer() {}
+ RawDataBaseWriter(unsigned int mode = Writer::None) : m_writer(mode) {}
 
     bool write(const char *filename, const RawDataBase&,
                           Writer::FileType type=Writer::CompressedGTO);
diff -ru gto-3.4.0/lib/Gto/Reader.cpp gto-3.4.0-ilm/lib/Gto/Reader.cpp
--- gto-3.4.0/lib/Gto/Reader.cpp 2008-06-23 09:17:16.898688000 -0700
+++ gto-3.4.0-ilm/lib/Gto/Reader.cpp 2008-05-13 18:21:35.571434000 -0700
@@ -84,7 +84,9 @@
         readMagicNumber();
 
         if (m_header.magic != Header::Magic ||
- m_header.magic != Header::Cigam)
+ m_header.magic != Header::Cigam ||
+ m_header.magic != Header::MagicLEC ||
+ m_header.magic != Header::CigamLEC)
         {
             return false;
         }
@@ -112,7 +114,9 @@
         readMagicNumber();
 
         if (m_header.magic != Header::Magic ||
- m_header.magic != Header::Cigam)
+ m_header.magic != Header::Cigam ||
+ m_header.magic != Header::MagicLEC ||
+ m_header.magic != Header::CigamLEC)
         {
             return false;
         }
@@ -252,7 +256,7 @@
 Reader::Request Reader::component(const string&, const ComponentInfo &) { return Request(true); }
 Reader::Request Reader::property(const string&, const PropertyInfo &) { return Request(true); }
 void* Reader::data(const PropertyInfo&, size_t) { return 0; }
-void Reader::dataRead(const PropertyInfo&) {}
+void Reader::dataRead(const PropertyInfo&,char *buffer) {}
 void Reader::descriptionComplete() {}
 
 Reader::Request
@@ -321,12 +325,12 @@
     if (m_error) return;
     m_swapped = false;
 
- if (m_header.magic == Header::Cigam)
+ if (m_header.magic == Header::Cigam || m_header.magic == Header::CigamLEC)
     {
         m_swapped = true;
         swapWords(&m_header, sizeof(m_header) / sizeof(int));
     }
- else if (m_header.magic != Header::Magic)
+ else if (m_header.magic != Header::Magic && m_header.magic != Header::MagicLEC)
     {
         ostringstream str;
         str << "bad magic number (" << hex << m_header.magic << ")";
@@ -343,6 +347,12 @@
         return;
     }
 
+ // add option to force reading gto files as LEC
+ if (m_mode & ReadAsLEC)
+ {
+ m_header.magic = Header::MagicLEC;
+ }
+
     header(m_header);
 }
 
@@ -390,19 +400,41 @@
     {
         ObjectInfo o;
 
- if (m_header.version == 2)
+ if (m_header.magic == Header::MagicLEC)
         {
- read((char*)&o, sizeof(ObjectHeader_v2));
+ ObjectHeaderLEC ol;
+ read((char*)&ol, sizeof(ObjectHeaderLEC));
+
+ if (m_error) return;
+
+ if (m_swapped) {
+ swapShorts(&ol.name, 1);
+ swapShorts(&ol.protocolName, 1);
+ swapShorts(&ol.numComponents, 1);
+ }
+
+ o.name = ol.name;
+ o.protocolName = ol.protocolName;
+ o.protocolVersion = ol.protocolVersion;
+ o.numComponents = ol.numComponents;
             o.pad = 0;
         }
         else
         {
- read((char*)&o, sizeof(ObjectHeader));
- }
+ if (m_header.version == 2)
+ {
+ read((char*)&o, sizeof(ObjectHeader_v2));
+ o.pad = 0;
+ }
+ else
+ {
+ read((char*)&o, sizeof(ObjectHeader));
+ }
 
- if (m_error) return;
+ if (m_error) return;
 
- if (m_swapped) swapWords(&o, sizeof(ObjectHeader) / sizeof(int));
+ if (m_swapped) swapWords(&o, sizeof(ObjectHeader) / sizeof(int));
+ }
 
         stringFromId(o.name);
         stringFromId(o.protocolName);
@@ -445,20 +477,41 @@
         {
             ComponentInfo c;
 
- if (m_header.version == 2)
+ if (m_header.magic == Header::MagicLEC)
             {
- read((char*)&c, sizeof(ComponentHeader_v2));
- c.pad = 0;
+ ComponentHeaderLEC cl;
+ read((char*)&cl, sizeof(ComponentHeaderLEC));
+
+ if (m_error) return;
+
+ if (m_swapped)
+ {
+ swapShorts(&cl.name, 1);
+ }
+
+ c.name = cl.name;
+ c.numProperties = cl.numProperties;
+ c.flags = cl.flags;
                 c.interpretation = 0;
+ c.pad = 0;
             }
             else
             {
- read((char*)&c, sizeof(ComponentHeader));
- }
+ if (m_header.version == 2)
+ {
+ read((char*)&c, sizeof(ComponentHeader_v2));
+ c.pad = 0;
+ c.interpretation = 0;
+ }
+ else
+ {
+ read((char*)&c, sizeof(ComponentHeader));
+ }
 
- if (m_error) return;
+ if (m_error) return;
 
- if (m_swapped) swapWords(&c, sizeof(ComponentHeader) / sizeof(int));
+ if (m_swapped) swapWords(&c, sizeof(ComponentHeader) / sizeof(int));
+ }
 
             c.object = &o;
             c.poffset = poffset;
@@ -500,22 +553,45 @@
         {
             PropertyInfo p;
 
- if (m_header.version == 2)
+ if (m_header.magic == Header::MagicLEC)
             {
- read((char*)&p, sizeof(PropertyHeader_v2));
- p.pad = 0;
+ PropertyHeaderLEC pl;
+ read((char*)&pl, sizeof(PropertyHeaderLEC));
+
+ if (m_error) return;
+
+ if (m_swapped)
+ {
+ swapShorts(&pl.name, 1);
+ swapWords(&pl.size, 1);
+ }
+
+ p.name = pl.name;
+ p.size = pl.size;
+ p.type = pl.type;
+ p.width = pl.width;
                 p.interpretation = 0;
+ p.pad = 0;
             }
             else
             {
- read((char*)&p, sizeof(PropertyHeader));
- }
+ if (m_header.version == 2)
+ {
+ read((char*)&p, sizeof(PropertyHeader_v2));
+ p.pad = 0;
+ p.interpretation = 0;
+ }
+ else
+ {
+ read((char*)&p, sizeof(PropertyHeader));
+ }
 
- if (m_error) return;
+ if (m_error) return;
 
- if (m_swapped)
- {
- swapWords(&p, sizeof(PropertyHeader) / sizeof(int));
+ if (m_swapped)
+ {
+ swapWords(&p, sizeof(PropertyHeader) / sizeof(int));
+ }
             }
 
             p.component = &c;
@@ -728,7 +804,7 @@
             }
         }
 
- dataRead(prop);
+ dataRead(prop,buffer);
     }
 
 
@@ -1165,7 +1241,7 @@
         if (void* buffer = data(info, m_buffer.size()))
         {
             memcpy(buffer, &m_buffer.front(), m_buffer.size());
- dataRead(info);
+ dataRead(info,(char *)buffer);
         }
     }
 
diff -ru gto-3.4.0/lib/Gto/Reader.h gto-3.4.0-ilm/lib/Gto/Reader.h
--- gto-3.4.0/lib/Gto/Reader.h 2008-06-23 09:17:46.258481000 -0700
+++ gto-3.4.0-ilm/lib/Gto/Reader.h 2008-05-16 15:03:07.437316000 -0700
@@ -127,6 +127,7 @@
         RandomAccess = 1 << 1,
         BinaryOnly = 1 << 2,
         TextOnly = 1 << 3,
+ ReadAsLEC = 1 << 4,
     };
 
     explicit Reader(unsigned int mode = None);
@@ -275,7 +276,7 @@
     // succesfully read (so after the data() function is called)
     //
 
- virtual void dataRead(const PropertyInfo&);
+ virtual void dataRead(const PropertyInfo&,char *buffer);
 
     //------------------------------------------------------------
     //
diff -ru gto-3.4.0/lib/Gto/Utilities.cpp gto-3.4.0-ilm/lib/Gto/Utilities.cpp
--- gto-3.4.0/lib/Gto/Utilities.cpp 2008-06-23 09:13:29.202759000 -0700
+++ gto-3.4.0-ilm/lib/Gto/Utilities.cpp 2007-11-05 15:59:05.482789000 -0800
@@ -117,12 +117,12 @@
 
 bool isGTOFile(const char* infile)
 {
- Header header;
+ uint32 magic;
 
 #ifdef GTO_SUPPORT_ZIP
     if (gzFile file = gzopen(infile, "rb"))
     {
- if (gzread(file, &header, sizeof(header)) != sizeof(Header))
+ if (gzread(file, &magic, sizeof(uint32)) != sizeof(uint32))
         {
             gzclose(file);
             return false;
@@ -131,14 +131,16 @@
 #else
     ifstream file(infile);
     if (!file) return false;
- if (file.readsome((char*)&header, sizeof(Header)) != sizeof(Header)) return false;
+ if (file.readsome((char*)&magic, sizeof(uint32)) != sizeof(uint32)) return false;
     if (file.fail()) return false;
 #endif
 
- return header.magic == GTO_MAGIC ||
- header.magic == GTO_MAGICl ||
- header.magic == GTO_MAGIC_TEXT ||
- header.magic == GTO_MAGIC_TEXTl;
+ return magic == GTO_MAGIC ||
+ magic == GTO_MAGICl ||
+ magic == GTO_MAGIC_LEC ||
+ magic == GTO_MAGIC_LECl ||
+ magic == GTO_MAGIC_TEXT ||
+ magic == GTO_MAGIC_TEXTl;
 }
 
 } // Gto
diff -ru gto-3.4.0/lib/Gto/Writer.cpp gto-3.4.0-ilm/lib/Gto/Writer.cpp
--- gto-3.4.0/lib/Gto/Writer.cpp 2008-06-23 09:20:12.412421000 -0700
+++ gto-3.4.0-ilm/lib/Gto/Writer.cpp 2008-06-23 08:53:04.789802000 -0700
@@ -42,26 +42,28 @@
 using namespace std;
 
 
-Writer::Writer()
+Writer::Writer(unsigned int mode)
     : m_out(0),
       m_gzfile(0),
       m_needsClosing(false),
       m_error(false),
       m_tableFinished(false),
       m_currentProperty(0),
- m_type(CompressedGTO)
+ m_type(CompressedGTO),
+ m_mode(mode)
 {
     init(0);
 }
 
-Writer::Writer(ostream &o)
+Writer::Writer(ostream &o, unsigned int mode)
     : m_out(0),
       m_gzfile(0),
       m_needsClosing(false),
       m_error(false),
       m_tableFinished(false),
       m_currentProperty(0),
- m_type(CompressedGTO)
+ m_type(CompressedGTO),
+ m_mode(mode)
 {
     init(&o);
 }
@@ -608,6 +610,7 @@
 {
     Header header;
     header.magic = GTO_MAGIC;
+ if (m_mode & WriteAsLEC) header.magic = GTO_MAGIC_LEC;
     header.numObjects = m_objects.size();
     header.numStrings = m_strings.size();
     header.version = GTO_VERSION;
@@ -625,19 +628,98 @@
     for (size_t i=0; i < m_objects.size(); i++)
     {
         ObjectHeader &o = m_objects[i];
- write(&o, sizeof(ObjectHeader));
+
+ if (m_mode & WriteAsLEC)
+ {
+ if (o.name > std::numeric_limits<uint16>::max() ||
+ o.protocolName > std::numeric_limits<uint16>::max() ||
+ o.protocolVersion > std::numeric_limits<uint8>::max() ||
+ o.numComponents > std::numeric_limits<uint16>::max())
+ {
+ throw std::runtime_error("Gto::Writer::writeHead(): object "
+ "header values are out of range for "
+ "writing as LEC format.");
+ }
+
+ ObjectHeaderLEC ol;
+
+ ol.name = o.name;
+ ol.protocolName = o.protocolName;
+ ol.protocolVersion = o.protocolVersion;
+ ol.numComponents = o.numComponents;
+
+ write(&ol, sizeof(ObjectHeaderLEC));
+ }
+ else
+ {
+ write(&o, sizeof(ObjectHeader));
+ }
     }
 
     for (size_t i=0; i < m_components.size(); i++)
     {
         ComponentHeader &c = m_components[i];
- write(&c, sizeof(ComponentHeader));
+
+ if (m_mode & WriteAsLEC)
+ {
+ if (c.name > std::numeric_limits<uint16>::max() ||
+ c.numProperties > std::numeric_limits<uint8>::max() ||
+ c.flags > std::numeric_limits<uint8>::max())
+ {
+ throw std::runtime_error("Gto::Writer::writeHead(): component "
+ "header values are out of range for "
+ "writing as LEC format.");
+ }
+
+ if (c.interpretation != 0)
+ {
+ throw std::runtime_error("Gto::Writer::writeHead(): component "
+ "interpretation not allowed when "
+ "writing as LEC format.");
+ }
+
+ ComponentHeaderLEC cl;
+
+ cl.name = c.name;
+ cl.numProperties = c.numProperties;
+ cl.flags = c.flags;
+
+ write(&cl, sizeof(ComponentHeaderLEC));
+ }
+ else
+ {
+ write(&c, sizeof(ComponentHeader));
+ }
     }
 
     for (size_t i=0; i < m_properties.size(); i++)
     {
         PropertyHeader &p = m_properties[i];
- write(&p, sizeof(PropertyHeader));
+
+ if (m_mode & WriteAsLEC)
+ {
+ if (p.name > std::numeric_limits<uint16>::max() ||
+ p.type > std::numeric_limits<uint8>::max() ||
+ p.width > std::numeric_limits<uint8>::max())
+ {
+ throw std::runtime_error("Gto::Writer::writeHead(): property "
+ "header values are out of range for "
+ "writing as LEC format.");
+ }
+
+ PropertyHeaderLEC pl;
+
+ pl.name = p.name;
+ pl.size = p.size;
+ pl.type = p.type;
+ pl.width = p.width;
+
+ write(&pl, sizeof(PropertyHeaderLEC));
+ }
+ else
+ {
+ write(&p, sizeof(PropertyHeader));
+ }
     }
 
     flush();
diff -ru gto-3.4.0/lib/Gto/Writer.h gto-3.4.0-ilm/lib/Gto/Writer.h
--- gto-3.4.0/lib/Gto/Writer.h 2008-06-23 09:21:06.187709000 -0700
+++ gto-3.4.0-ilm/lib/Gto/Writer.h 2008-06-23 08:53:05.024808000 -0700
@@ -62,8 +62,14 @@
         TextGTO
     };
 
- Writer();
- explicit Writer(std::ostream&);
+ enum WriteMode
+ {
+ None = 0,
+ WriteAsLEC = 1 << 0,
+ };
+
+ explicit Writer(unsigned int mode = None);
+ Writer(std::ostream&,unsigned int mode = None);
     ~Writer();
 
     //
@@ -192,6 +198,7 @@
 
     void endData();
 
+
     //
     // Previously declared property data
     //
@@ -228,6 +235,7 @@
     std::string m_outName;
     size_t m_currentProperty;
     FileType m_type;
+ unsigned int m_mode;
 };
 
 template<typename T>