Diff of /tiff.c [0a87db] .. [8fbc76]  Maximize  Restore

  Switch to unified view

a/tiff.c b/tiff.c
...
...
35
#include "metadata.h"
35
#include "metadata.h"
36
#include "ptstitch.h"
36
#include "ptstitch.h"
37
37
38
38
39
int readplanarTIFF(Image * im, TIFF * tif);
39
int readplanarTIFF(Image * im, TIFF * tif);
40
void RGBAtoARGB(UCHAR * buf, int width, int bitsPerPixel);
40
void RGBAtoARGB(uint8_t * buf, int width, int bitsPerPixel);
41
void ARGBtoRGBA(UCHAR * buf, int width, int bitsPerPixel);
41
void ARGBtoRGBA(uint8_t * buf, int width, int bitsPerPixel);
42
int readtif(Image * im, TIFF * tif);
42
int readtif(Image * im, TIFF * tif);
43
43
44
44
45
int readplanarTIFF(Image * im, TIFF * tif)
45
int readplanarTIFF(Image * im, TIFF * tif)
46
{
46
{
47
    UCHAR *buf;
47
    uint8_t *buf;
48
    int32_t y;
48
    int32_t y;
49
    short SamplesPerPixel;
49
    short SamplesPerPixel;
50
50
51
    TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &SamplesPerPixel);
51
    TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &SamplesPerPixel);
52
    if (SamplesPerPixel > 4)
52
    if (SamplesPerPixel > 4)
...
...
55
    {
55
    {
56
        im->bitsPerPixel = im->bitsPerPixel * 3 / 4;
56
        im->bitsPerPixel = im->bitsPerPixel * 3 / 4;
57
        im->bytesPerLine = im->bytesPerLine * 3 / 4;
57
        im->bytesPerLine = im->bytesPerLine * 3 / 4;
58
    }
58
    }
59
59
60
    buf = (UCHAR *) malloc((size_t) TIFFScanlineSize(tif));
60
    buf = (uint8_t *) malloc((size_t) TIFFScanlineSize(tif));
61
    if (buf == NULL)
61
    if (buf == NULL)
62
    {
62
    {
63
        PrintError("Not enough memory");
63
        PrintError("Not enough memory");
64
        return -1;
64
        return -1;
65
    }
65
    }
...
...
109
    {
109
    {
110
        PrintError("Not enough memory");
110
        PrintError("Not enough memory");
111
        return -1;
111
        return -1;
112
    }
112
    }
113
113
114
    im->data = (UCHAR **) hdl_raster;
114
    im->data = (uint8_t **) hdl_raster;
115
115
116
    if (tPhotoMetric == PHOTOMETRIC_RGB && config == PLANARCONFIG_CONTIG)
116
    if (tPhotoMetric == PHOTOMETRIC_RGB && config == PLANARCONFIG_CONTIG)
117
    {
117
    {
118
        return readplanarTIFF(im, tif);
118
        return readplanarTIFF(im, tif);
119
    }
119
    }
...
...
315
315
316
int writeCroppedTIFF(Image * im, fullPath * sfile, CropInfo * crop_info)
316
int writeCroppedTIFF(Image * im, fullPath * sfile, CropInfo * crop_info)
317
{
317
{
318
    char string[512];
318
    char string[512];
319
    TIFF *tif;
319
    TIFF *tif;
320
    UCHAR *buf;
320
    uint8_t *buf;
321
    unsigned int y;
321
    unsigned int y;
322
    size_t bufsize;
322
    size_t bufsize;
323
323
324
#ifdef __Mac__
324
#ifdef __Mac__
325
    unsigned char the_pcUnixFilePath[512];      //added by Kekus Digital
325
    unsigned char the_pcUnixFilePath[512];      //added by Kekus Digital
...
...
434
        setCropInformationInTiff(tif, crop_info);
434
        setCropInformationInTiff(tif, crop_info);
435
435
436
    bufsize = TIFFScanlineSize(tif);
436
    bufsize = TIFFScanlineSize(tif);
437
    if ((uint32_t)bufsize < im->bytesPerLine)
437
    if ((uint32_t)bufsize < im->bytesPerLine)
438
        bufsize = im->bytesPerLine;
438
        bufsize = im->bytesPerLine;
439
    buf = (UCHAR *) malloc(bufsize);
439
    buf = (uint8_t *) malloc(bufsize);
440
    if (buf == NULL)
440
    if (buf == NULL)
441
    {
441
    {
442
        PrintError("Not enough memory");
442
        PrintError("Not enough memory");
443
        return -1;
443
        return -1;
444
    }
444
    }
...
...
462
    return writeCroppedTIFF(im, sfile, &(im->cropInformation));
462
    return writeCroppedTIFF(im, sfile, &(im->cropInformation));
463
}
463
}
464
464
465
465
466
466
467
void RGBAtoARGB(UCHAR * buf, int width, int bitsPerPixel)
467
void RGBAtoARGB(uint8_t * buf, int width, int bitsPerPixel)
468
{
468
{
469
    int x;
469
    int x;
470
    switch (bitsPerPixel)
470
    switch (bitsPerPixel)
471
    {
471
    {
472
    case 32:
472
    case 32:
473
        {
473
        {
474
            UCHAR pix;
474
            uint8_t pix;
475
            for (x = 0; x < width; x++, buf += 4)
475
            for (x = 0; x < width; x++, buf += 4)
476
            {
476
            {
477
                pix = buf[3];
477
                pix = buf[3];
478
                buf[3] = buf[2];
478
                buf[3] = buf[2];
479
                buf[2] = buf[1];
479
                buf[2] = buf[1];
...
...
482
            }
482
            }
483
        }
483
        }
484
        break;
484
        break;
485
    case 64:
485
    case 64:
486
        {
486
        {
487
            USHORT *bufs = (USHORT *) buf, pix;
487
            uint16_t *bufs = (uint16_t *) buf, pix;
488
            for (x = 0; x < width; x++, bufs += 4)
488
            for (x = 0; x < width; x++, bufs += 4)
489
            {
489
            {
490
                pix = bufs[3];
490
                pix = bufs[3];
491
                bufs[3] = bufs[2];
491
                bufs[3] = bufs[2];
492
                bufs[2] = bufs[1];
492
                bufs[2] = bufs[1];
...
...
509
        }
509
        }
510
        break;
510
        break;
511
    }
511
    }
512
}
512
}
513
513
514
void ARGBtoRGBA(UCHAR * buf, int width, int bitsPerPixel)
514
void ARGBtoRGBA(uint8_t * buf, int width, int bitsPerPixel)
515
{
515
{
516
    int x;
516
    int x;
517
    switch (bitsPerPixel)
517
    switch (bitsPerPixel)
518
    {
518
    {
519
    case 32:
519
    case 32:
520
        {
520
        {
521
            UCHAR pix;
521
            uint8_t pix;
522
            for (x = 0; x < width; x++, buf += 4)
522
            for (x = 0; x < width; x++, buf += 4)
523
            {
523
            {
524
                pix = buf[0];
524
                pix = buf[0];
525
                buf[0] = buf[1];
525
                buf[0] = buf[1];
526
                buf[1] = buf[2];
526
                buf[1] = buf[2];
...
...
529
            }
529
            }
530
        }
530
        }
531
        break;
531
        break;
532
    case 64:
532
    case 64:
533
        {
533
        {
534
            USHORT *bufs = (USHORT *) buf, pix;
534
            uint16_t *bufs = (uint16_t *) buf, pix;
535
            for (x = 0; x < width; x++, bufs += 4)
535
            for (x = 0; x < width; x++, bufs += 4)
536
            {
536
            {
537
                pix = bufs[0];
537
                pix = bufs[0];
538
                bufs[0] = bufs[1];
538
                bufs[0] = bufs[1];
539
                bufs[1] = bufs[2];
539
                bufs[1] = bufs[2];
...
...
780
780
781
    bzero(buffer, bytesPerLine);
781
    bzero(buffer, bytesPerLine);
782
782
783
    if (panoTiffRowInsideROI(file, row)) {
783
    if (panoTiffRowInsideROI(file, row)) {
784
        if (TIFFReadScanline
784
        if (TIFFReadScanline
785
            (file->tiff, (UCHAR *)(buffer) + panoTiffXOffset(file) * bytesPerPixel,
785
            (file->tiff, (uint8_t *)(buffer) + panoTiffXOffset(file) * bytesPerPixel,
786
             row - panoTiffYOffset(file), 0) != 1) {
786
             row - panoTiffYOffset(file), 0) != 1) {
787
            PrintError("Error reading row %d in tiff file", row);
787
            PrintError("Error reading row %d in tiff file", row);
788
            return FALSE;
788
            return FALSE;
789
        }
789
        }
790
    }
790
    }
...
...
811
           panoTiffFullImageWidth(file) == panoTiffImageWidth(file));
811
           panoTiffFullImageWidth(file) == panoTiffImageWidth(file));
812
812
813
813
814
    if (panoTiffRowInsideROI(file, row)) {
814
    if (panoTiffRowInsideROI(file, row)) {
815
        if (TIFFWriteScanline
815
        if (TIFFWriteScanline
816
            (file->tiff, (UCHAR *)(buffer) + panoTiffXOffset(file) * bytesPerPixel,
816
            (file->tiff, (uint8_t *)(buffer) + panoTiffXOffset(file) * bytesPerPixel,
817
             row - panoTiffYOffset(file), 0) != 1) {
817
             row - panoTiffYOffset(file), 0) != 1) {
818
            PrintError("Error writing row %d in tiff file", row);
818
            PrintError("Error writing row %d in tiff file", row);
819
            return FALSE;
819
            return FALSE;
820
        }
820
        }
821
    }
821
    }
...
...
1139
1139
1140
1140
1141
1141
1142
int panoTiffReadPlannar(Image * im, pano_Tiff * tif)
1142
int panoTiffReadPlannar(Image * im, pano_Tiff * tif)
1143
{
1143
{
1144
    UCHAR *buf;
1144
    uint8_t *buf;
1145
    uint32 row;
1145
    uint32 row;
1146
    short samplesPerPixel;
1146
    short samplesPerPixel;
1147
    int bytesRead;
1147
    int bytesRead;
1148
    int bitsPerPixel;
1148
    int bitsPerPixel;
1149
1149
...
...
1634
    panoTiffSetErrorHandler();
1634
    panoTiffSetErrorHandler();
1635
1635
1636
    // Open TIFFs
1636
    // Open TIFFs
1637
1637
1638
    firstFile = panoTiffOpen(tiffFiles[0].name);
1638
    firstFile = panoTiffOpen(tiffFiles[0].name);
1639
    firstCropInfo = &firstFile->metadata.cropInfo;
1640
1641
1639
1642
    if (firstFile == NULL) {
1640
    if (firstFile == NULL) {
1643
        PrintError("Unable to read tiff file %s", tiffFiles[0].name);
1641
        PrintError("Unable to read tiff file %s", tiffFiles[0].name);
1644
        return FALSE;
1642
        return FALSE;
1645
    }
1643
    }
1644
1645
    firstCropInfo = &firstFile->metadata.cropInfo;
1646
1646
1647
    // Compare the metadata of the current file with each of the other ones
1647
    // Compare the metadata of the current file with each of the other ones
1648
    for (currentImage = 1; currentImage < numberImages; currentImage++) {
1648
    for (currentImage = 1; currentImage < numberImages; currentImage++) {
1649
1649
1650
        otherFile = panoTiffOpen(tiffFiles[currentImage].name);
1650
        otherFile = panoTiffOpen(tiffFiles[currentImage].name);