~ubuntu-branches/ubuntu/trusty/digikam/trusty

« back to all changes in this revision

Viewing changes to core/libs/dimg/loaders/tiffloader.cpp

  • Committer: Package Import Robot
  • Author(s): Rohan Garg
  • Date: 2012-11-26 18:24:20 UTC
  • mfrom: (1.9.1) (3.1.23 experimental)
  • Revision ID: package-import@ubuntu.com-20121126182420-qoy6z0nx4ai0wzcl
Tags: 4:3.0.0~beta3-0ubuntu1
* New upstream release
  - Add build-deps :  libhupnp-dev, libqtgstreamer-dev, libmagickcore-dev
* Merge from debian, remaining changes:
  - Make sure libqt4-opengl-dev, libgl1-mesa-dev and libglu1-mesa-dev only
    install on i386,amd64 and powerpc
  - Depend on libtiff-dev instead of libtiff4-dev
  - Drop digikam breaks/replaces kipi-plugins-common since we're past the
    LTS release now
  - digikam to recommend mplayerthumbs | ffmpegthumbs. We currently only
    have latter in the archives, even though former is also supposed to
    be part of kdemultimedia. (LP: #890059)
  - kipi-plugins to recommend www-browser rather than konqueror directly
    since 2.8 no direct usage of konqueror is present in the flickr
    plugin anymore (LP: #1011211)
  - Keep kubuntu_mysqld_executable_name.diff
  - Don't install libkipi translations
  - Keep deps on libcv-dev, libcvaux-dev
  - Keep split packaging of libraries
  - Replace icons from KDE 3 time in debian/xpm.d/*.xpm with the new
    versions (LP: #658047)
* Update debian/not-installed

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 * Date        : 2005-06-17
7
7
 * Description : A TIFF IO file for DImg framework
8
8
 *
9
 
 * Copyright (C) 2005 by Renchi Raju <renchi@pooh.tam.uiuc.edu>
10
 
 * Copyright (C) 2006-2011 by Gilles Caulier <caulier dot gilles at gmail dot com>
 
9
 * Copyright (C) 2005      by Renchi Raju <renchi dot raju at gmail dot com>
 
10
 * Copyright (C) 2006-2012 by Gilles Caulier <caulier dot gilles at gmail dot com>
11
11
 *
12
12
 * Specifications & references:
13
13
 * - TIFF 6.0  : http://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf
97
97
#endif
98
98
}
99
99
 
100
 
TIFFLoader::TIFFLoader(DImg* image)
 
100
TIFFLoader::TIFFLoader(DImg* const image)
101
101
    : DImgLoader(image)
102
102
{
103
103
    m_hasAlpha   = false;
104
104
    m_sixteenBit = false;
105
105
}
106
106
 
107
 
bool TIFFLoader::load(const QString& filePath, DImgLoaderObserver* observer)
 
107
bool TIFFLoader::load(const QString& filePath, DImgLoaderObserver* const observer)
108
108
{
109
109
    readMetadata(filePath, DImg::TIFF);
110
110
 
294
294
 
295
295
        if (bits_per_sample == 16)          // 16 bits image.
296
296
        {
297
 
            data.reset(new_failureTolerant(w * h * 8));
 
297
            data.reset(new_failureTolerant(w, h, 8));
298
298
            QScopedArrayPointer<uchar> strip(new_failureTolerant(strip_size));
299
299
 
300
300
            if (!data || strip.isNull())
355
355
                        // We have to read two bytes for one pixel
356
356
                        p = dataPtr;
357
357
 
358
 
                        // See B.K.O #148037 : take a care about byte order with Motorola computers.
359
 
                        if (QSysInfo::ByteOrder == QSysInfo::BigEndian)     // PPC
360
 
                        {
361
 
                            p[3] = 0xFFFF;
362
 
                            p[0] = *stripPtr;
363
 
                            p[1] = *stripPtr;
364
 
                            p[2] = *stripPtr++;
365
 
                        }
366
 
                        else
367
 
                        {
368
 
                            p[0] = *stripPtr;      // RGB have to be set to the _same_ value
369
 
                            p[1] = *stripPtr;
370
 
                            p[2] = *stripPtr++;
371
 
                            p[3] = 0xFFFF;         // set alpha to 100%
372
 
                        }
 
358
                        p[0] = *stripPtr;      // RGB have to be set to the _same_ value
 
359
                        p[1] = *stripPtr;
 
360
                        p[2] = *stripPtr++;
 
361
                        p[3] = 0xFFFF;         // set alpha to 100%
373
362
 
374
363
                        dataPtr += 4;
375
364
                    }
382
371
                    {
383
372
                        p = dataPtr;
384
373
 
385
 
                        // See B.K.O #148037 : take a care about byte order with Motorola computers.
386
 
                        if (QSysInfo::ByteOrder == QSysInfo::BigEndian)     // PPC
387
 
                        {
388
 
                            p[3] = *stripPtr++;
389
 
                            p[0] = *stripPtr++;
390
 
                            p[1] = *stripPtr++;
391
 
                            p[2] = 0xFFFF;
392
 
                        }
393
 
                        else
394
 
                        {
395
 
                            p[2] = *stripPtr++;
396
 
                            p[1] = *stripPtr++;
397
 
                            p[0] = *stripPtr++;
398
 
                            p[3] = 0xFFFF;
399
 
                        }
 
374
                        p[2] = *stripPtr++;
 
375
                        p[1] = *stripPtr++;
 
376
                        p[0] = *stripPtr++;
 
377
                        p[3] = 0xFFFF;
400
378
 
401
379
                        dataPtr += 4;
402
380
                    }
409
387
                    {
410
388
                        p = dataPtr;
411
389
 
412
 
                        // See B.K.O #148037 : take a care about byte order with Motorola computers.
413
 
                        if (QSysInfo::ByteOrder == QSysInfo::BigEndian)     // PPC
414
 
                        {
415
 
                            switch ((st / (num_of_strips / samples_per_pixel)))
416
 
                            {
417
 
                                case 0:
418
 
                                    p[3] = *stripPtr++;
419
 
                                    p[2] = 0xFFFF;
420
 
                                    break;
421
 
 
422
 
                                case 1:
423
 
                                    p[0] = *stripPtr++;
424
 
                                    break;
425
 
 
426
 
                                case 2:
427
 
                                    p[1] = *stripPtr++;
428
 
                                    break;
429
 
                            }
430
 
                        }
431
 
                        else
432
 
                        {
433
 
                            switch ((st / (num_of_strips / samples_per_pixel)))
434
 
                            {
435
 
                                case 0:
436
 
                                    p[2] = *stripPtr++;
437
 
                                    p[3] = 0xFFFF;
438
 
                                    break;
439
 
 
440
 
                                case 1:
441
 
                                    p[1] = *stripPtr++;
442
 
                                    break;
443
 
 
444
 
                                case 2:
445
 
                                    p[0] = *stripPtr++;
446
 
                                    break;
447
 
                            }
 
390
                        switch ((st / (num_of_strips / samples_per_pixel)))
 
391
                        {
 
392
                            case 0:
 
393
                                p[2] = *stripPtr++;
 
394
                                p[3] = 0xFFFF;
 
395
                                break;
 
396
 
 
397
                            case 1:
 
398
                                p[1] = *stripPtr++;
 
399
                                break;
 
400
 
 
401
                            case 2:
 
402
                                p[0] = *stripPtr++;
 
403
                                break;
448
404
                        }
449
405
 
450
406
                        dataPtr += 4;
458
414
                    {
459
415
                        p = dataPtr;
460
416
 
461
 
                        // See B.K.O #148037 : take a care about byte order with Motorola computers.
462
 
                        if (QSysInfo::ByteOrder == QSysInfo::BigEndian)     // PPC
463
 
                        {
464
 
                            p[3] = *stripPtr++;
465
 
                            p[0] = *stripPtr++;
466
 
                            p[1] = *stripPtr++;
467
 
                            p[2] = *stripPtr++;
468
 
                        }
469
 
                        else
470
 
                        {
471
 
                            p[2] = *stripPtr++;
472
 
                            p[1] = *stripPtr++;
473
 
                            p[0] = *stripPtr++;
474
 
                            p[3] = *stripPtr++;
475
 
                        }
 
417
                        p[2] = *stripPtr++;
 
418
                        p[1] = *stripPtr++;
 
419
                        p[0] = *stripPtr++;
 
420
                        p[3] = *stripPtr++;
476
421
 
477
422
                        dataPtr += 4;
478
423
                    }
485
430
                    {
486
431
                        p = dataPtr;
487
432
 
488
 
                        // See B.K.O #148037 : take a care about byte order with Motorola computers.
489
 
                        if (QSysInfo::ByteOrder == QSysInfo::BigEndian)     // PPC
490
 
                        {
491
 
                            switch ((st / (num_of_strips / samples_per_pixel)))
492
 
                            {
493
 
                                case 0:
494
 
                                    p[3] = *stripPtr++;
495
 
                                    break;
496
 
 
497
 
                                case 1:
498
 
                                    p[0] = *stripPtr++;
499
 
                                    break;
500
 
 
501
 
                                case 2:
502
 
                                    p[1] = *stripPtr++;
503
 
                                    break;
504
 
 
505
 
                                case 3:
506
 
                                    p[2] = *stripPtr++;
507
 
                                    break;
508
 
                            }
509
 
                        }
510
 
                        else
511
 
                        {
512
 
                            switch ((st / (num_of_strips / samples_per_pixel)))
513
 
                            {
514
 
                                case 0:
515
 
                                    p[2] = *stripPtr++;
516
 
                                    break;
517
 
 
518
 
                                case 1:
519
 
                                    p[1] = *stripPtr++;
520
 
                                    break;
521
 
 
522
 
                                case 2:
523
 
                                    p[0] = *stripPtr++;
524
 
                                    break;
525
 
 
526
 
                                case 3:
527
 
                                    p[3] = *stripPtr++;
528
 
                                    break;
529
 
                            }
 
433
                        switch ((st / (num_of_strips / samples_per_pixel)))
 
434
                        {
 
435
                            case 0:
 
436
                                p[2] = *stripPtr++;
 
437
                                break;
 
438
 
 
439
                            case 1:
 
440
                                p[1] = *stripPtr++;
 
441
                                break;
 
442
 
 
443
                            case 2:
 
444
                                p[0] = *stripPtr++;
 
445
                                break;
 
446
 
 
447
                            case 3:
 
448
                                p[3] = *stripPtr++;
 
449
                                break;
530
450
                        }
531
451
 
532
452
                        dataPtr += 4;
538
458
        }
539
459
        else       // Non 16 bits images ==> get it on BGRA 8 bits.
540
460
        {
541
 
            data.reset(new_failureTolerant(w * h * 4));
542
 
            QScopedArrayPointer<uchar> strip(new_failureTolerant(w * rows_per_strip * 4));
 
461
            data.reset(new_failureTolerant(w, h, 4));
 
462
            QScopedArrayPointer<uchar> strip(new_failureTolerant(w, rows_per_strip, 4));
543
463
 
544
464
            if (!data || strip.isNull())
545
465
            {
625
545
                {
626
546
                    p = dataPtr;
627
547
 
628
 
                    // See B.K.O #148037 : take a care about byte order with Motorola computers.
629
 
                    if (QSysInfo::ByteOrder == QSysInfo::BigEndian)     // PPC
630
 
                    {
631
 
                        p[3] = *stripPtr++;
632
 
                        p[0] = *stripPtr++;
633
 
                        p[1] = *stripPtr++;
634
 
                        p[2] = *stripPtr++;
635
 
                    }
636
 
                    else
637
 
                    {
638
 
                        p[2] = *stripPtr++;
639
 
                        p[1] = *stripPtr++;
640
 
                        p[0] = *stripPtr++;
641
 
                        p[3] = *stripPtr++;
642
 
                    }
 
548
                    p[2] = *stripPtr++;
 
549
                    p[1] = *stripPtr++;
 
550
                    p[0] = *stripPtr++;
 
551
                    p[3] = *stripPtr++;
643
552
 
644
553
                    dataPtr += 4;
645
554
                }
671
580
    return true;
672
581
}
673
582
 
674
 
bool TIFFLoader::save(const QString& filePath, DImgLoaderObserver* observer)
 
583
bool TIFFLoader::save(const QString& filePath, DImgLoaderObserver* const observer)
675
584
{
676
585
    uint32 w     = imageWidth();
677
586
    uint32 h     = imageHeight();
807
716
    }
808
717
 
809
718
    uchar*  pixel;
 
719
    uint16* pixel16;
810
720
    double  alpha_factor;
811
721
    uint32  x, y;
812
722
    uint8   r8, g8, b8, a8 = 0;
814
724
    int     i = 0;
815
725
 
816
726
    uint8* buf = (uint8*)_TIFFmalloc(TIFFScanlineSize(tif));
 
727
    uint16* buf16;
817
728
 
818
729
    if (!buf)
819
730
    {
849
760
 
850
761
            if (imageSixteenBit())          // 16 bits image.
851
762
            {
852
 
                b16 = (uint16)(pixel[0] + 256 * pixel[1]);
853
 
                g16 = (uint16)(pixel[2] + 256 * pixel[3]);
854
 
                r16 = (uint16)(pixel[4] + 256 * pixel[5]);
 
763
                pixel16 = (ushort*)pixel;
 
764
                b16 = pixel16[0];
 
765
                g16 = pixel16[1];
 
766
                r16 = pixel16[2];
855
767
 
856
768
                if (imageHasAlpha())
857
769
                {
858
770
                    // TIFF makes you pre-mutiply the RGB components by alpha
859
771
 
860
 
                    a16          = (uint16)(pixel[6] + 256 * pixel[7]);
 
772
                    a16          = pixel16[3];
861
773
                    alpha_factor = ((double)a16 / 65535.0);
862
774
                    r16          = (uint16)(r16 * alpha_factor);
863
775
                    g16          = (uint16)(g16 * alpha_factor);
866
778
 
867
779
                // This might be endian dependent
868
780
 
869
 
                buf[i++] = (uint8)(r16);
870
 
                buf[i++] = (uint8)(r16 >> 8);
871
 
                buf[i++] = (uint8)(g16);
872
 
                buf[i++] = (uint8)(g16 >> 8);
873
 
                buf[i++] = (uint8)(b16);
874
 
                buf[i++] = (uint8)(b16 >> 8);
 
781
                buf16 = (ushort*)(buf+i);
 
782
                *buf16++ = r16;
 
783
                *buf16++ = g16;
 
784
                *buf16++ = b16;
 
785
                i+= 6;
875
786
 
876
787
                if (imageHasAlpha())
877
788
                {
878
 
                    buf[i++] = (uint8)(a16) ;
879
 
                    buf[i++] = (uint8)(a16 >> 8) ;
 
789
                    *buf16++ = a16;
 
790
                    i += 2;
880
791
                }
881
792
            }
882
793
            else                            // 8 bits image.
1005
916
    return m_sixteenBit;
1006
917
}
1007
918
 
1008
 
void TIFFLoader::tiffSetExifAsciiTag(TIFF* tif, ttag_t tiffTag,
1009
 
                                     const DMetadata& metaData, const char* exifTagName)
 
919
void TIFFLoader::tiffSetExifAsciiTag(TIFF* const tif, ttag_t tiffTag,
 
920
                                     const DMetadata& metaData, const char* const exifTagName)
1010
921
{
1011
922
    QByteArray tag = metaData.getExifTagData(exifTagName);
1012
923
 
1017
928
    }
1018
929
}
1019
930
 
1020
 
void TIFFLoader::tiffSetExifDataTag(TIFF* tif, ttag_t tiffTag,
1021
 
                                    const DMetadata& metaData, const char* exifTagName)
 
931
void TIFFLoader::tiffSetExifDataTag(TIFF* const tif, ttag_t tiffTag,
 
932
                                    const DMetadata& metaData, const char* const exifTagName)
1022
933
{
1023
934
    QByteArray tag = metaData.getExifTagData(exifTagName);
1024
935
 
1028
939
    }
1029
940
}
1030
941
 
 
942
bool TIFFLoader::isReadOnly() const
 
943
{
 
944
    return false;
 
945
}
 
946
 
1031
947
}  // namespace Digikam