summaryrefslogtreecommitdiffstats
path: root/chalk/core/kis_exif_value.cpp
blob: 134d4009aee5bd99784ed2be91f8080f1d5012a4 (plain)
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
/*
 * This file is part of Chalk
 *
 *  Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include "kis_exif_value.h"

#include <kdebug.h>
#include <kmdcodec.h>

namespace {
void set16Bit (unsigned char *data, ExifValue::ByteOrder order, const TQ_UINT16* value)
{
    switch (order) {
        case ExifValue::BYTE_ORDER_MOTOROLA:
            data[0] = (unsigned char) (*value >> 8);
            data[1] = (unsigned char) *value;
            break;
        case ExifValue::BYTE_ORDER_INTEL:
            data[0] = (unsigned char) *value;
            data[1] = (unsigned char) (*value >> 8);
            break;
    }
}

void get16Bit (const unsigned char *data, ExifValue::ByteOrder order, TQ_UINT16* value)
{
    switch (order) {
        case ExifValue::BYTE_ORDER_MOTOROLA:
            *value = ((data[0] << 8) | data[1]);
            break;
        case ExifValue::BYTE_ORDER_INTEL:
            *value = ((data[1] << 8) | data[0]);
            break;
    }
}

void get32Bit (const unsigned char *data, ExifValue::ByteOrder order, TQ_UINT32* value)
{
    switch (order) {
        case ExifValue::BYTE_ORDER_MOTOROLA:
            *value = ((data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]);
            break;
        case ExifValue::BYTE_ORDER_INTEL:
            *value = ((data[3] << 24) | (data[2] << 16) | (data[1] << 8) | data[0]);
    }
}

void set32Bit(unsigned char *data, ExifValue::ByteOrder order, const TQ_UINT32* value)
{
    switch (order) {
        case ExifValue::BYTE_ORDER_MOTOROLA:
            data[0] = (unsigned char) (*value >> 24);
            data[1] = (unsigned char) (*value >> 16);
            data[2] = (unsigned char) (*value >> 8);
            data[3] = (unsigned char) *value;
            break;
        case ExifValue::BYTE_ORDER_INTEL:
            data[3] = (unsigned char) (*value >> 24);
            data[2] = (unsigned char) (*value >> 16);
            data[1] = (unsigned char) (*value >> 8);
            data[0] = (unsigned char) *value;
            break;
    }
}

void get64Bit (const unsigned char *data, ExifValue::ByteOrder order, TQ_UINT64* value)
{
    switch (order) {
        case ExifValue::BYTE_ORDER_MOTOROLA:
            *value = (((TQ_UINT64)data[0] << 56) | ((TQ_UINT64)data[1] << 48) | ((TQ_UINT64)data[2] << 40) | ((TQ_UINT64)data[3] << 32) | ((TQ_UINT64)data[4] << 24) | ((TQ_UINT64)data[5] << 16) | ((TQ_UINT64)data[6] << 8) | (TQ_UINT64)data[7]);
            break;
        case ExifValue::BYTE_ORDER_INTEL:
            *value = (((TQ_UINT64)data[7] << 56) | ((TQ_UINT64)data[6] << 48) | ((TQ_UINT64)data[5] << 40) | ((TQ_UINT64)data[4] << 32) | ((TQ_UINT64)data[3] << 24) | ((TQ_UINT64)data[2] << 16) | ((TQ_UINT64)data[1] << 8) | (TQ_UINT64)data[0]);
    }
}

void set64Bit(unsigned char *data, ExifValue::ByteOrder order, const TQ_UINT64* value)
{
    switch (order) {
        case ExifValue::BYTE_ORDER_MOTOROLA:
            data[0] = (unsigned char) (*value >> 56);
            data[1] = (unsigned char) (*value >> 48);
            data[2] = (unsigned char) (*value >> 40);
            data[3] = (unsigned char) (*value >> 32);
            data[4] = (unsigned char) (*value >> 24);
            data[5] = (unsigned char) (*value >> 16);
            data[6] = (unsigned char) (*value >> 8);
            data[7] = (unsigned char) *value;
            break;
        case ExifValue::BYTE_ORDER_INTEL:
            data[7] = (unsigned char) (*value >> 56);
            data[6] = (unsigned char) (*value >> 48);
            data[5] = (unsigned char) (*value >> 40);
            data[4] = (unsigned char) (*value >> 32);
            data[3] = (unsigned char) (*value >> 24);
            data[2] = (unsigned char) (*value >> 16);
            data[1] = (unsigned char) (*value >> 8);
            data[0] = (unsigned char) *value;
            break;
    }
}


}

ExifValue::ExifValue(ExifType ntype, unsigned char *data, unsigned int size, int ifd, uint ncomponents, ExifValue::ByteOrder order ) : m_ifd(ifd), m_type(ntype), m_components(ncomponents), m_value(0)
{
    allocData();
    setValue(data, size, order);
}

void ExifValue::allocData()
{
    if( type() != EXIF_TYPE_ASCII && type() != EXIF_TYPE_UNDEFINED)
    {
        m_value = new ExifNumber[components()];
    } else if ( type() == EXIF_TYPE_ASCII )
    {
        m_value = new TQString();
    } else if ( type() == EXIF_TYPE_UNDEFINED)
    {
        m_value = new UByteArray();
    }
}

bool ExifValue::load(const TQDomElement& elmt)
{
    TQString attr;
    if( (attr = elmt.attribute("ifd")).isNull() )
        return false;
    m_ifd = attr.toInt();
    if( (attr = elmt.attribute("components")).isNull() )
        return false;
    m_components = attr.toInt();
    if( (attr = elmt.attribute("type")).isNull() )
        return false;
    m_type = (ExifValue::ExifType)attr.toInt();
    allocData();
    switch(type())
    {
        case EXIF_TYPE_BYTE:
            for(uint i = 0; i < components(); i++)
            {
                if( (attr = elmt.attribute(TQString("value%1").arg(i) ) ).isNull() )
                {
                    setValue(i, (TQ_UINT8)0);
                } else {
                    setValue(i, (TQ_UINT8) attr.toUInt());
                }
            }
            break;
        case EXIF_TYPE_ASCII:
            setAsAscii( elmt.attribute("value" ) );
            break;
        case EXIF_TYPE_SHORT:
            for(uint i = 0; i < components(); i++)
            {
                if( (attr = elmt.attribute(TQString("value%1").arg(i) ) ).isNull() )
                {
                    setValue(i, (TQ_UINT16)0);
                } else {
                    setValue(i, (TQ_UINT16) attr.toUInt());
                }
            }
            break;
        case EXIF_TYPE_LONG:
            for(uint i = 0; i < components(); i++)
            {
                if( (attr = elmt.attribute(TQString("value%1").arg(i) ) ).isNull() )
                {
                    setValue(i, (TQ_UINT32)0);
                } else {
                    setValue(i, (TQ_UINT32) attr.toUInt());
                }
            }
            break;
        case EXIF_TYPE_RATIONAL:
            for(uint i = 0; i < components(); i++)
            {
                KisExifRational r;
                if( (attr = elmt.attribute(TQString("numerator%1").arg(i) ) ).isNull() )
                {
                    r.numerator = (TQ_UINT32)0;
                } else {
                    r.numerator = (TQ_UINT32) attr.toUInt();
                }
                if( (attr = elmt.attribute(TQString("denominator%1").arg(i) ) ).isNull() )
                {
                    r.denominator = (TQ_UINT32)0;
                } else {
                    r.denominator = (TQ_UINT32) attr.toUInt();
                }
                setValue(i, r);
            }
            break;
        case EXIF_TYPE_SBYTE:
            for(uint i = 0; i < components(); i++)
            {
                if( (attr = elmt.attribute(TQString("value%1").arg(i) ) ).isNull() )
                {
                    setValue(i, (TQ_INT8)0);
                } else {
                    setValue(i, (TQ_INT8) attr.toInt());
                }
            }
            break;
        case EXIF_TYPE_UNDEFINED:
        {
            TQString instr = elmt.attribute("value");
            TQByteArray out;
            TQByteArray in = instr.utf8();
            KCodecs::base64Decode( in, out);
            out.resize(out.size() - 2 );
            setAsUndefined((uchar*)out.data(), out.size() );
        }
        break;
        case EXIF_TYPE_SSHORT:
            for(uint i = 0; i < components(); i++)
            {
                if( (attr = elmt.attribute(TQString("value%1").arg(i) ) ).isNull() )
                {
                    setValue(i, (TQ_INT16)0);
                } else {
                    setValue(i, (TQ_INT16) attr.toInt());
                }
            }
            break;
        case EXIF_TYPE_SLONG:
            for(uint i = 0; i < components(); i++)
            {
                if( (attr = elmt.attribute(TQString("value%1").arg(i) ) ).isNull() )
                {
                    setValue(i, (TQ_INT32)0);
                } else {
                    setValue(i, (TQ_INT32) attr.toInt());
                }
            }
            break;
        case EXIF_TYPE_SRATIONAL:
            for(uint i = 0; i < components(); i++)
            {
                KisExifSRational r;
                if( (attr = elmt.attribute(TQString("numerator%1").arg(i) ) ).isNull() )
                {
                    r.numerator = (TQ_INT32)0;
                } else {
                    r.numerator = (TQ_INT32) attr.toInt();
                }
                if( (attr = elmt.attribute(TQString("denominator%1").arg(i) ) ).isNull() )
                {
                    r.denominator = (TQ_UINT32)0;
                } else {
                    r.denominator = (TQ_UINT32) attr.toInt();
                }
                setValue(i, r);
            }
            break;
        case EXIF_TYPE_FLOAT:
            for(uint i = 0; i < components(); i++)
            {
                if( (attr = elmt.attribute(TQString("value%1").arg(i) ) ).isNull() )
                {
                    setValue(i, (float)0);
                } else {
                    setValue(i, (float) attr.toFloat());
                }
            }
            break;
        case EXIF_TYPE_DOUBLE:
            for(uint i = 0; i < components(); i++)
            {
                if( (attr = elmt.attribute(TQString("value%1").arg(i) ) ).isNull() )
                {
                    setValue(i, (double)0);
                } else {
                    setValue(i, (double) attr.toDouble());
                }
            }
            break;
        case EXIF_TYPE_UNKNOW:
            break;

    }
    return true;
}

TQDomElement ExifValue::save(TQDomDocument& doc)
{
    TQDomElement elmt = doc.createElement("ExifValue");
    elmt.setAttribute("ifd", ifd());
    elmt.setAttribute("components", components() );
    elmt.setAttribute("type", type() );
    switch(type())
    {
        case EXIF_TYPE_BYTE:
            for(uint i = 0; i < components(); i++)
                elmt.setAttribute(TQString("value%1").arg(i), asByte( i ) );
            break;
        case EXIF_TYPE_ASCII:
            elmt.setAttribute("value", asAscii() );
            break;
        case EXIF_TYPE_SHORT:
            for(uint i = 0; i < components(); i++)
                elmt.setAttribute(TQString("value%1").arg(i), asShort( i ) );
            break;
        case EXIF_TYPE_LONG:
            for(uint i = 0; i < components(); i++)
                elmt.setAttribute(TQString("value%1").arg(i), asLong( i ) );
            break;
        case EXIF_TYPE_RATIONAL:
            for(uint i = 0; i < components(); i++)
            {
                KisExifRational r = asRational(i);
                elmt.setAttribute(TQString("numerator%1").arg(i), r.numerator );
                elmt.setAttribute(TQString("denominator%1").arg(i), r.denominator );
            }
            break;
        case EXIF_TYPE_SBYTE:
            for(uint i = 0; i < components(); i++)
                elmt.setAttribute(TQString("value%1").arg(i), asSByte( i ) );
            break;
        case EXIF_TYPE_UNDEFINED:
        {
            UByteArray value = asUndefined();
            TQByteArray data;
            data.setRawData((char*)value.data(), value.size());
            TQByteArray encodedData;
            KCodecs::base64Encode( data, encodedData );
            data.resetRawData( (char*)value.data(), value.size());
            elmt.setAttribute("value", TQString(encodedData));
        }
            break;
        case EXIF_TYPE_SSHORT:
            for(uint i = 0; i < components(); i++)
                elmt.setAttribute(TQString("value%1").arg(i), asSShort( i ) );
            break;
        case EXIF_TYPE_SLONG:
            for(uint i = 0; i < components(); i++)
                elmt.setAttribute(TQString("value%1").arg(i), asSLong( i ) );
            break;
        case EXIF_TYPE_SRATIONAL:
            for(uint i = 0; i < components(); i++)
            {
                KisExifSRational r = asSRational(i);
                elmt.setAttribute(TQString("numerator%1").arg(i), r.numerator );
                elmt.setAttribute(TQString("denominator%1").arg(i), r.denominator );
            }
            break;
        case EXIF_TYPE_FLOAT:
            for(uint i = 0; i < components(); i++)
                elmt.setAttribute(TQString("value%1").arg(i), asFloat( i ) );
            break;
        case EXIF_TYPE_DOUBLE:
            for(uint i = 0; i < components(); i++)
                elmt.setAttribute(TQString("value%1").arg(i), asDouble( i ) );
            break;
        case EXIF_TYPE_UNKNOW:
            break;
    }
    return elmt;
}


void ExifValue::setValue(const unsigned char *data, unsigned int size, ExifValue::ByteOrder order)
{
    switch(type())
    {
        case EXIF_TYPE_BYTE:
            if( size == components() )
            {
                ExifNumber n;
                for(uint i = 0; i < components(); i++)
                {
                    n.m_byte = data[i];
                    setAsExifNumber( i, n);
                }
            }
            break;
        case EXIF_TYPE_ASCII:
            setAsAscii((char*) data);
            break;
        case EXIF_TYPE_SHORT:
            if( size == 2*components() )
            {
                ExifNumber n;
                for(uint i = 0; i < components(); i++)
                {
                    get16Bit( data + 2 * i, order, &n.m_short);
                    setAsExifNumber( i, n);
                }
            }
            break;
        case EXIF_TYPE_LONG:
            if( size == 4*components() )
            {
                ExifNumber n;
                for(uint i = 0; i < components(); i++)
                {
                    get32Bit( data + 4 * i, order, &n.m_long);
                    setAsExifNumber( i, n);
                }
            }
            break;
        case EXIF_TYPE_RATIONAL:
            if( size == 8*components() )
            {
                ExifNumber n;
                for(uint i = 0; i < components(); i++)
                {
                    get32Bit( data + 8 * i, order, &n.m_rational.numerator);
                    get32Bit( data + 8 * i + 4, order, &n.m_rational.denominator);
                    setAsExifNumber( i, n);
                }
            }
            break;
        case EXIF_TYPE_SBYTE:
            if( size == components() )
            {
                ExifNumber n;
                for(uint i = 0; i < components(); i++)
                {
                    n.m_sbyte = ((TQ_INT8*)data)[i];
                    setAsExifNumber( i, n);
                }
            }
            break;
        case EXIF_TYPE_UNDEFINED:
            setAsUndefined(data, size);
            break;
        case EXIF_TYPE_SSHORT:
            if( size == 2*components() )
            {
                ExifNumber n;
                for(uint i = 0; i < components(); i++)
                {
                    get16Bit( data + 2 * i, order, (TQ_UINT16*)&n.m_sshort);
                    setAsExifNumber( i, n);
                }
            }
            break;
        case EXIF_TYPE_SLONG:
            if( size == 4*components() )
            {
                ExifNumber n;
                for(uint i = 0; i < components(); i++)
                {
                    get32Bit( data + 4 * i, order, (TQ_UINT32*)&n.m_slong);
                    setAsExifNumber( i, n);
                }
            }
            break;
        case EXIF_TYPE_SRATIONAL:
            if( size == 8*components() )
            {
                ExifNumber n;
                for(uint i = 0; i < components(); i++)
                {
                    get32Bit( data + 8 * i, order, (TQ_UINT32*)&n.m_srational.numerator);
                    get32Bit( data + 8 * i + 4, order, (TQ_UINT32*)&n.m_srational.denominator);
                    setAsExifNumber( i, n);
                }
            }
            break;
        case EXIF_TYPE_FLOAT:
            if( size == 4*components() )
            {
                ExifNumber n;
                for(uint i = 0; i < components(); i++)
                {
                    get32Bit( data + 4 * i, order, (TQ_UINT32*)&n.m_float);
                    setAsExifNumber( i, n);
                }
            }
            break;
        case EXIF_TYPE_DOUBLE:
            if( size == 8*components() )
            {
                ExifNumber n;
                for(uint i = 0; i < components(); i++)
                {
                    get64Bit( data + 8 * i, order, (TQ_UINT64*)&n.m_double);
                    setAsExifNumber( i, n);
                }
            }
            break;
        case EXIF_TYPE_UNKNOW:
            break;
    }
}

void ExifValue::convertToData(unsigned char ** data, unsigned int* size, ExifValue::ByteOrder order)
{
    switch(type())
    {
        case EXIF_TYPE_BYTE:
            *size = components();
            *data = new uchar[*size];
            for(uint i = 0; i < components(); i++)
            {
                (*data)[i] = asExifNumber(i).m_byte;
            }
            return;
        case EXIF_TYPE_ASCII:
        {
            TQString str = asAscii();
            *size = str.length();
            *data = new uchar[ *size ];
            uchar* ptr = *data;
            memcpy(ptr, str.ascii(), (*size)*sizeof(uchar));
        }
        return;
        break;
        case EXIF_TYPE_SHORT:
        {
            *size = 2*components();
            *data = new uchar[*size];
            for(uint i = 0; i < components(); i++)
            {
                TQ_UINT16 aenms = asExifNumber(i).m_short;
                set16Bit( (*data) + 2 * i, order, &aenms);
            }
            return;
        }
        case EXIF_TYPE_LONG:
        {
            *size = 4*components();
            *data = new uchar[*size];
            for(uint i = 0; i < components(); i++)
            {
                TQ_UINT32 aenml = asExifNumber(i).m_long;
                set32Bit( (*data) + 4 * i, order, &aenml);
            }
            return;
        }
        case EXIF_TYPE_RATIONAL:
            *size = 8*components();
            *data = new uchar[*size];
            for(uint i = 0; i < components(); i++)
            {
                ExifNumber n = asExifNumber(i);
                set32Bit( (*data) + 8 * i, order, &n.m_rational.numerator);
                set32Bit( (*data) + 8 * i + 4, order, &n.m_rational.denominator);
            }
            return;
        case EXIF_TYPE_SBYTE:
            *size = components();
            *data = new uchar[*size];
            for(uint i = 0; i < components(); i++)
            {
                *(((TQ_INT8*)*data) + i) = asExifNumber(i).m_sbyte;
            }
            return;
        case EXIF_TYPE_UNDEFINED:
        {
            UByteArray array = asUndefined();
            *size = array.size();
            *data = new uchar[*size];
            memcpy( *data, array.data(), (*size)*sizeof(unsigned char));
        }
        return;
        case EXIF_TYPE_SSHORT:
            *size = 2*components();
            *data = new uchar[*size];
            for(uint i = 0; i < components(); i++)
            {
                TQ_INT16 aenmss = asExifNumber(i).m_sshort;
                set16Bit( (*data) + 2 * i, order, (TQ_UINT16*)&aenmss);
            }
            return;
        case EXIF_TYPE_SLONG:
            *size = 4*components();
            *data = new uchar[*size];
            for(uint i = 0; i < components(); i++)
            {
                TQ_INT32 aenmsl = asExifNumber(i).m_slong;
                set32Bit( (*data) + 4 * i, order, (TQ_UINT32*)&aenmsl);
            }
            return;
        case EXIF_TYPE_SRATIONAL:
            *size = 8*components();
            *data = new uchar[*size];
            for(uint i = 0; i < components(); i++)
            {
                ExifNumber n = asExifNumber(i);
                TQ_INT32 aenmsr_numerator = asExifNumber(i).m_srational.numerator;
                TQ_INT32 aenmsr_denominator = asExifNumber(i).m_srational.denominator;
                set32Bit( (*data) + 4 * i, order, (TQ_UINT32*)&aenmsr_numerator);
                set32Bit( (*data) + 4 * i + 4, order, (TQ_UINT32*)&aenmsr_denominator);
            }
            return;
        case EXIF_TYPE_FLOAT:
            *size = 4*components();
            *data = new uchar[*size];
            for(uint i = 0; i < components(); i++)
            {
                float aenmf = asExifNumber(i).m_float;
                set32Bit( (*data) + 4 * i, order, (TQ_UINT32*)&aenmf);
            }
            return;
        case EXIF_TYPE_DOUBLE:
            *size = 8*components();
            *data = new uchar[*size];
            for(uint i = 0; i < components(); i++)
            {
                double aenmd = asExifNumber(i).m_double;
                set64Bit( (*data) + 4 * i, order, (TQ_UINT64*)&aenmd);
            }
            return;
        case EXIF_TYPE_UNKNOW:
            break;
    }
}

TQString ExifValue::toString()
{
    switch(type())
    {
        case EXIF_TYPE_ASCII:
            return asAscii();
        case EXIF_TYPE_UNDEFINED:
        {
            TQString undefined = "undefined";
            UByteArray array = asUndefined();
            for(uint i = 0; i < components(); i++)
            {
                undefined += "\\" + TQString().setNum( array[i] );
            }
            return undefined;
        }
        default:
        {
            TQString str = "";
            for(uint i = 0; i < components(); i++)
            {
                str += toString(i);
            }
            return str;
        }
    }
}

TQString ExifValue::toString(uint i)
{
    switch(type())
    {
        case EXIF_TYPE_BYTE:
            return TQString("%1 ").arg( asExifNumber( i ).m_byte );
        case EXIF_TYPE_SHORT:
            return TQString("%1 ").arg( asExifNumber( i ).m_short );
        case EXIF_TYPE_LONG:
            return TQString("%1 ").arg( asExifNumber( i ).m_long );
        case EXIF_TYPE_RATIONAL:
            return TQString("%1 / %2 ").arg( asExifNumber( i ).m_rational.numerator ).arg( asExifNumber( i ).m_rational.denominator );
        case EXIF_TYPE_SBYTE: {
            /* workaround to compiler bug on Raspbian Wheezy */
            TQ_INT8 o_sbyte = asExifNumber( i ).m_sbyte;
            return TQString("%1 ").arg( o_sbyte );
        }
        case EXIF_TYPE_SSHORT:
            return TQString("%1 ").arg( asExifNumber( i ).m_sshort );
        case EXIF_TYPE_SLONG:
            return TQString("%1 ").arg( asExifNumber( i ).m_slong );
        case EXIF_TYPE_SRATIONAL:
            return TQString("%1 / %2 ").arg( asExifNumber( i ).m_srational.numerator ).arg( asExifNumber( i ).m_srational.denominator );
        case EXIF_TYPE_FLOAT:
            return TQString("%1 ").arg( asExifNumber( i ).m_float );
        case EXIF_TYPE_DOUBLE:
            return TQString("%1 ").arg( asExifNumber( i ).m_double );
        default:
            return "unknow ";
    }
}