46
46
#include "magick/cache.h"
47
47
#include "magick/color.h"
48
48
#include "magick/color-private.h"
49
#include "magick/colormap.h"
49
50
#include "magick/colorspace.h"
50
51
#include "magick/constitute.h"
51
52
#include "magick/enhance.h"
73
74
#include "magick/static.h"
74
75
#include "magick/statistic.h"
75
76
#include "magick/string_.h"
77
#include "magick/string-private.h"
76
78
#include "magick/thread_.h"
77
79
#include "magick/utility.h"
78
#include "magick/module.h"
79
80
#if defined(MAGICKCORE_TIFF_DELEGATE)
80
81
# if defined(MAGICKCORE_HAVE_TIFFCONF_H)
81
82
# include "tiffconf.h"
340
341
length=fwrite("\006\001\003\000\001\000\000\000\000\000\000\000",1,12,file);
341
342
length=fwrite("\021\001\003\000\001\000\000\000",1,8,file);
342
343
strip_offset=10+(12*14)+4+8;
343
length=WriteLSBLong(file,(unsigned long) strip_offset);
344
length=WriteLSBLong(file,(size_t) strip_offset);
344
345
length=fwrite("\022\001\003\000\001\000\000\000",1,8,file);
345
length=WriteLSBLong(file,(unsigned long) image_info->orientation);
346
length=WriteLSBLong(file,(size_t) image_info->orientation);
346
347
length=fwrite("\025\001\003\000\001\000\000\000\001\000\000\000",1,12,file);
347
348
length=fwrite("\026\001\004\000\001\000\000\000",1,8,file);
348
349
length=WriteLSBLong(file,image->rows);
349
350
length=fwrite("\027\001\004\000\001\000\000\000\000\000\000\000",1,12,file);
350
351
offset=(ssize_t) ftell(file)-4;
351
352
length=fwrite("\032\001\005\000\001\000\000\000",1,8,file);
352
length=WriteLSBLong(file,(unsigned long) (strip_offset-8));
353
length=WriteLSBLong(file,(size_t) (strip_offset-8));
353
354
length=fwrite("\033\001\005\000\001\000\000\000",1,8,file);
354
length=WriteLSBLong(file,(unsigned long) (strip_offset-8));
355
length=WriteLSBLong(file,(size_t) (strip_offset-8));
355
356
length=fwrite("\050\001\003\000\001\000\000\000\002\000\000\000",1,12,file);
356
357
length=fwrite("\000\000\000\000",1,4,file);
357
358
length=WriteLSBLong(file,image->x_resolution);
358
359
length=WriteLSBLong(file,1);
359
360
for (length=0; (c=ReadBlobByte(image)) != EOF; length++)
360
361
(void) fputc(c,file);
361
offset=(ssize_t) fseek(file,(long) offset,SEEK_SET);
362
offset=(ssize_t) fseek(file,(ssize_t) offset,SEEK_SET);
362
363
length=WriteLSBLong(file,(unsigned int) length);
363
364
(void) fclose(file);
364
365
(void) CloseBlob(image);
505
506
#if defined(TIFFTAG_ICCPROFILE)
507
508
if (TIFFGetField(tiff,TIFFTAG_ICCPROFILE,&length,&profile) == 1)
508
(void) ReadProfile(image,"icc",profile,(long) length);
509
(void) ReadProfile(image,"icc",profile,(ssize_t) length);
510
511
#if defined(TIFFTAG_PHOTOSHOP)
512
513
if (TIFFGetField(tiff,TIFFTAG_PHOTOSHOP,&length,&profile) == 1)
513
(void) ReadProfile(image,"8bim",profile,(long) length);
514
(void) ReadProfile(image,"8bim",profile,(ssize_t) length);
515
516
#if defined(TIFFTAG_RICHTIFFIPTC)
517
518
if (TIFFGetField(tiff,TIFFTAG_RICHTIFFIPTC,&length,&profile) == 1)
519
520
if (TIFFIsByteSwapped(tiff) != 0)
520
TIFFSwabArrayOfLong((uint32 *) profile,(unsigned long) length);
521
TIFFSwabArrayOfLong((uint32 *) profile,(size_t) length);
521
522
(void) ReadProfile(image,"iptc",profile,4L*length);
524
525
#if defined(TIFFTAG_XMLPACKET)
526
527
if (TIFFGetField(tiff,TIFFTAG_XMLPACKET,&length,&profile) == 1)
527
(void) ReadProfile(image,"xmp",profile,(long) length);
528
(void) ReadProfile(image,"xmp",profile,(ssize_t) length);
530
531
if (TIFFGetField(tiff,37724,&length,&profile) == 1)
531
(void) ReadProfile(image,"tiff:37724",profile,(long) length);
532
(void) ReadProfile(image,"tiff:37724",profile,(ssize_t) length);
534
535
static void TIFFGetProperties(TIFF *tiff,Image *image)
612
if (TIFFGetField(tiff,exif_info[i].tag,&longy) != 0)
613
(void) FormatMagickString(value,MaxTextExtent,"%d",longy);
613
if (TIFFGetField(tiff,exif_info[i].tag,&ssize_ty) != 0)
614
(void) FormatMagickString(value,MaxTextExtent,"%d",ssize_ty);
616
617
case TIFF_RATIONAL:
659
static int32 TIFFReadPixels(TIFF *tiff,unsigned long bits_per_sample,
660
tsample_t sample,long row,tdata_t scanline)
660
static int32 TIFFReadPixels(TIFF *tiff,size_t bits_per_sample,
661
tsample_t sample,ssize_t row,tdata_t scanline)
922
923
(void) LogMagickEvent(CoderEvent,GetMagickModule(),"Photometric "
923
924
"interpretation: %s",GetImageProperty(image,"tiff:photometric"));
925
image->columns=(unsigned long) width;
926
image->rows=(unsigned long) height;
927
image->depth=(unsigned long) bits_per_sample;
926
image->columns=(size_t) width;
927
image->rows=(size_t) height;
928
image->depth=(size_t) bits_per_sample;
928
929
if (image->debug != MagickFalse)
929
(void) LogMagickEvent(CoderEvent,GetMagickModule(),"Image depth: %lu",
930
(void) LogMagickEvent(CoderEvent,GetMagickModule(),"Image depth: %.20g",
931
(double) image->depth);
932
933
image->endian=MSBEndian;
933
934
if ((int) (*(char *) &lsb_first) != 0)
949
950
y_position=(float) image->page.y/y_resolution;
950
951
(void) TIFFGetFieldDefaulted(tiff,TIFFTAG_XPOSITION,&x_position);
951
952
(void) TIFFGetFieldDefaulted(tiff,TIFFTAG_YPOSITION,&y_position);
952
image->page.x=(long) (x_position*x_resolution+0.5);
953
image->page.y=(long) (y_position*y_resolution+0.5);
953
image->page.x=(ssize_t) ceil(x_position*x_resolution-0.5);
954
image->page.y=(ssize_t) ceil(y_position*y_resolution-0.5);
954
955
image->orientation=(OrientationType) orientation;
955
956
chromaticity=(float *) NULL;
956
957
(void) TIFFGetField(tiff,TIFFTAG_WHITEPOINT,&chromaticity);
1031
1032
quantum_info=AcquireQuantumInfo(image_info,image);
1032
1033
if (quantum_info == (QuantumInfo *) NULL)
1033
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1036
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1034
1038
if (sample_format == SAMPLEFORMAT_UINT)
1035
1039
status=SetQuantumFormat(image,quantum_info,UnsignedQuantumFormat);
1036
1040
if (sample_format == SAMPLEFORMAT_INT)
1038
1042
if (sample_format == SAMPLEFORMAT_IEEEFP)
1039
1043
status=SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat);
1040
1044
if (status == MagickFalse)
1041
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1047
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1042
1049
status=MagickTrue;
1043
1050
switch (photometric)
1065
1072
image->matte=MagickTrue;
1075
for (i=0; i < extra_samples; i++)
1069
if (samples_per_pixel > 3)
1071
image->matte=MagickTrue;
1072
associated_alpha=MagickFalse;
1074
if (sample_info[0] == EXTRASAMPLE_UNASSALPHA)
1076
image->matte=MagickTrue;
1077
associated_alpha=MagickFalse;
1079
if (sample_info[0] == EXTRASAMPLE_ASSOCALPHA)
1081
image->matte=MagickTrue;
1082
associated_alpha=MagickTrue;
1083
SetQuantumAlphaType(quantum_info,DisassociatedQuantumAlpha);
1077
image->matte=MagickTrue;
1078
if (sample_info[i] == EXTRASAMPLE_ASSOCALPHA)
1079
SetQuantumAlphaType(quantum_info,DisassociatedQuantumAlpha);
1086
1081
option=GetImageOption(image_info,"tiff:alpha");
1087
1082
if (option != (const char *) NULL)
1172
1167
(void) TIFFGetField(tiff,TIFFTAG_COLORMAP,&red_colormap,
1173
1168
&green_colormap,&blue_colormap);
1174
1169
range=255; /* might be old style 8-bit colormap */
1175
for (i=0; i < (long) image->colors; i++)
1170
for (i=0; i < (ssize_t) image->colors; i++)
1176
1171
if ((red_colormap[i] >= 256) || (green_colormap[i] >= 256) ||
1177
1172
(blue_colormap[i] >= 256))
1182
for (i=0; i < (long) image->colors; i++)
1177
for (i=0; i < (ssize_t) image->colors; i++)
1184
image->colormap[i].red=RoundToQuantum(((double) QuantumRange*
1179
image->colormap[i].red=ClampToQuantum(((double) QuantumRange*
1185
1180
red_colormap[i])/range);
1186
image->colormap[i].green=RoundToQuantum(((double) QuantumRange*
1181
image->colormap[i].green=ClampToQuantum(((double) QuantumRange*
1187
1182
green_colormap[i])/range);
1188
image->colormap[i].blue=RoundToQuantum(((double) QuantumRange*
1183
image->colormap[i].blue=ClampToQuantum(((double) QuantumRange*
1189
1184
blue_colormap[i])/range);
1214
1209
status=SetQuantumPad(image,quantum_info,pad*((bits_per_sample+7) >> 3));
1215
1210
if (status == MagickFalse)
1216
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1213
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1217
1215
pixels=GetQuantumPixels(quantum_info);
1218
for (y=0; y < (long) image->rows; y++)
1216
for (y=0; y < (ssize_t) image->rows; y++)
1223
1221
register PixelPacket
1226
1224
status=TIFFReadPixels(tiff,bits_per_sample,0,y,(char *) pixels);
1227
1225
if (status == -1)
1236
1234
if (image->previous == (Image *) NULL)
1238
status=SetImageProgress(image,LoadImageTag,y,image->rows);
1236
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
1239
1238
if (status == MagickFalse)
1267
1266
status=SetQuantumPad(image,quantum_info,pad*((bits_per_sample+7) >> 3));
1268
1267
if (status == MagickFalse)
1269
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1270
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1270
1272
pixels=GetQuantumPixels(quantum_info);
1271
for (y=0; y < (long) image->rows; y++)
1273
for (y=0; y < (ssize_t) image->rows; y++)
1276
1278
register PixelPacket
1279
1281
status=TIFFReadPixels(tiff,bits_per_sample,0,y,(char *) pixels);
1280
1282
if (status == -1)
1289
1291
if (image->previous == (Image *) NULL)
1291
status=SetImageProgress(image,LoadImageTag,y,image->rows);
1293
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
1292
1295
if (status == MagickFalse)
1344
1347
if (image->previous == (Image *) NULL)
1346
status=SetImageProgress(image,LoadImageTag,y,image->rows);
1349
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
1347
1351
if (status == MagickFalse)
1362
1366
p=(unsigned char *) NULL;
1363
for (y=0; y < (long) image->rows; y++)
1367
for (y=0; y < (ssize_t) image->rows; y++)
1368
1372
register PixelPacket
1371
1375
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
1372
1376
if (q == (PixelPacket *) NULL)
1376
1380
if (TIFFReadRGBAStrip(tiff,(tstrip_t) y,(uint32 *) pixels) == 0)
1378
i=(long) MagickMin((long) rows_per_strip,(long) image->rows-y);
1382
i=(ssize_t) MagickMin((ssize_t) rows_per_strip,(ssize_t)
1381
1386
p=pixels+image->columns*i;
1382
for (x=0; x < (long) image->columns; x++)
1387
for (x=0; x < (ssize_t) image->columns; x++)
1384
1389
q->red=ScaleCharToQuantum((unsigned char) (TIFFGetR(*p)));
1385
1390
q->green=ScaleCharToQuantum((unsigned char) (TIFFGetG(*p)));
1394
1399
if (image->previous == (Image *) NULL)
1396
status=SetImageProgress(image,LoadImageTag,y,image->rows);
1401
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
1397
1403
if (status == MagickFalse)
1431
1437
TIFFClose(tiff);
1432
1438
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1434
for (y=0; y < (long) image->rows; y+=rows)
1440
for (y=0; y < (ssize_t) image->rows; y+=rows)
1442
1448
register PixelPacket
1446
1452
columns_remaining,
1447
1453
rows_remaining;
1449
1455
rows_remaining=image->rows-y;
1450
if ((long) (y+rows) < (long) image->rows)
1456
if ((ssize_t) (y+rows) < (ssize_t) image->rows)
1451
1457
rows_remaining=rows;
1452
1458
tile=QueueAuthenticPixels(image,0,y,image->columns,rows_remaining,
1454
1460
if (tile == (PixelPacket *) NULL)
1456
for (x=0; x < (long) image->columns; x+=columns)
1462
for (x=0; x < (ssize_t) image->columns; x+=columns)
1462
1468
if (TIFFReadRGBATile(tiff,(uint32) x,(uint32) y,tile_pixels) == 0)
1464
1470
columns_remaining=image->columns-x;
1465
if ((long) (x+columns) < (long) image->columns)
1471
if ((ssize_t) (x+columns) < (ssize_t) image->columns)
1466
1472
columns_remaining=columns;
1467
1473
p=tile_pixels+(rows-rows_remaining)*columns;
1468
1474
q=tile+(image->columns*(rows_remaining-1)+x);
1497
1503
if (image->previous == (Image *) NULL)
1499
status=SetImageProgress(image,LoadImageTag,y,image->rows);
1505
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
1500
1507
if (status == MagickFalse)
1536
1543
Convert image to DirectClass pixel packets.
1538
1545
p=pixels+number_pixels-1;
1539
for (y=0; y < (long) image->rows; y++)
1546
for (y=0; y < (ssize_t) image->rows; y++)
1544
1551
register PixelPacket
1547
1554
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
1548
1555
if (q == (PixelPacket *) NULL)
1550
1557
q+=image->columns-1;
1551
for (x=0; x < (long) image->columns; x++)
1558
for (x=0; x < (ssize_t) image->columns; x++)
1553
1560
q->red=ScaleCharToQuantum((unsigned char) TIFFGetR(*p));
1554
1561
q->green=ScaleCharToQuantum((unsigned char) TIFFGetG(*p));
1563
1570
if (image->previous == (Image *) NULL)
1565
status=SetImageProgress(image,LoadImageTag,y,image->rows);
1572
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
1566
1574
if (status == MagickFalse)
1663
1671
if (tiff_semaphore == (SemaphoreInfo *) NULL)
1664
1672
tiff_semaphore=AllocateSemaphoreInfo();
1665
(void) LockSemaphoreInfo(tiff_semaphore);
1673
LockSemaphoreInfo(tiff_semaphore);
1666
1674
if (instantiate_key == MagickFalse)
1668
1676
if (MagickCreateThreadKey(&tiff_exception) == MagickFalse)
1669
1677
ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
1670
1678
instantiate_key=MagickTrue;
1672
(void) UnlockSemaphoreInfo(tiff_semaphore);
1680
UnlockSemaphoreInfo(tiff_semaphore);
1674
1682
#if defined(TIFF_VERSION)
1675
1683
(void) FormatMagickString(version,MaxTextExtent,"%d",TIFF_VERSION);
1784
1792
(void) UnregisterMagickInfo("TIF");
1785
1793
(void) UnregisterMagickInfo("TIFF");
1786
1794
(void) UnregisterMagickInfo("TIFF64");
1787
(void) LockSemaphoreInfo(tiff_semaphore);
1795
if (tiff_semaphore == (SemaphoreInfo *) NULL)
1796
tiff_semaphore=AllocateSemaphoreInfo();
1797
LockSemaphoreInfo(tiff_semaphore);
1788
1798
if (instantiate_key != MagickFalse)
1789
1799
if (MagickDeleteThreadKey(tiff_exception) == MagickFalse)
1790
1800
ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
1791
1801
instantiate_key=MagickFalse;
1792
(void) UnlockSemaphoreInfo(tiff_semaphore);
1802
UnlockSemaphoreInfo(tiff_semaphore);
1793
1803
DestroySemaphoreInfo(&tiff_semaphore);
1926
1936
return(MagickFalse);
1928
1938
strip_size=byte_count[0];
1929
for (i=1; i < (long) TIFFNumberOfStrips(tiff); i++)
1939
for (i=1; i < (ssize_t) TIFFNumberOfStrips(tiff); i++)
1930
1940
if (byte_count[i] > strip_size)
1931
1941
strip_size=byte_count[i];
1932
1942
buffer=(unsigned char *) AcquireQuantumMemory((size_t) strip_size,
1944
1954
Compress runlength encoded to 2D Huffman pixels.
1946
for (i=0; i < (long) TIFFNumberOfStrips(tiff); i++)
1956
for (i=0; i < (ssize_t) TIFFNumberOfStrips(tiff); i++)
1948
1958
count=(ssize_t) TIFFReadRawStrip(tiff,(uint32) i,buffer,strip_size);
1949
1959
if (WriteBlob(image,(size_t) count,buffer) != count)
2148
2158
Fill scanlines to tile height.
2150
i=(long) (row % tiff_info->tile_geometry.height)*TIFFScanlineSize(tiff);
2160
i=(ssize_t) (row % tiff_info->tile_geometry.height)*TIFFScanlineSize(tiff);
2151
2161
(void) CopyMagickMemory(tiff_info->scanlines+i,(char *) tiff_info->scanline,
2152
2162
(size_t) TIFFScanlineSize(tiff));
2153
if (((unsigned long) (row % tiff_info->tile_geometry.height) !=
2154
(tiff_info->tile_geometry.height-1)) && (row != (long) (image->rows-1)))
2163
if (((size_t) (row % tiff_info->tile_geometry.height) !=
2164
(tiff_info->tile_geometry.height-1)) && (row != (ssize_t) (image->rows-1)))
2157
2167
Write tile to TIFF image.
2160
bytes_per_pixel=TIFFTileSize(tiff)/(long) (tiff_info->tile_geometry.height*
2170
bytes_per_pixel=TIFFTileSize(tiff)/(ssize_t) (tiff_info->tile_geometry.height*
2161
2171
tiff_info->tile_geometry.width);
2162
2172
number_tiles=(image->columns+tiff_info->tile_geometry.width)/
2163
2173
tiff_info->tile_geometry.width;
2164
for (i=0; i < (long) number_tiles; i++)
2174
for (i=0; i < (ssize_t) number_tiles; i++)
2166
tile_width=(i == (long) (number_tiles-1)) ? image->columns-(i*
2176
tile_width=(i == (ssize_t) (number_tiles-1)) ? image->columns-(i*
2167
2177
tiff_info->tile_geometry.width) : tiff_info->tile_geometry.width;
2168
for (j=0; j < (long) ((row % tiff_info->tile_geometry.height)+1); j++)
2169
for (k=0; k < (long) tile_width; k++)
2178
for (j=0; j < (ssize_t) ((row % tiff_info->tile_geometry.height)+1); j++)
2179
for (k=0; k < (ssize_t) tile_width; k++)
2171
2181
if (bytes_per_pixel == 0)
2182
2192
for (l=0; l < bytes_per_pixel; l++)
2185
status=TIFFWriteTile(tiff,tiff_info->pixels,(uint32) (i*
2186
tiff_info->tile_geometry.width),(uint32) ((row/
2187
tiff_info->tile_geometry.height)*tiff_info->tile_geometry.height),0,
2195
if ((i*tiff_info->tile_geometry.width) != image->columns)
2196
status=TIFFWriteTile(tiff,tiff_info->pixels,(uint32) (i*
2197
tiff_info->tile_geometry.width),(uint32) ((row/
2198
tiff_info->tile_geometry.height)*tiff_info->tile_geometry.height),0,
2189
2200
if (status < 0)
2268
2279
if (value != (const char *) NULL)
2269
2280
(void) TIFFSetField(tiff,TIFFTAG_MODEL,value);
2270
2281
(void) TIFFSetField(tiff,TIFFTAG_SOFTWARE,
2271
GetMagickVersion((unsigned long *) NULL));
2282
GetMagickVersion((size_t *) NULL));
2272
2283
(void) TIFFSetField(tiff,TIFFTAG_DOCUMENTNAME,image->filename);
2273
2284
value=GetImageProperty(image,"tiff:copyright");
2274
2285
if (value != (const char *) NULL)
2324
shorty=(uint16) atoi(value);
2335
shorty=(uint16) StringToLong(value);
2325
2336
(void) TIFFSetField(tiff,exif_info[i].tag,shorty);
2328
2339
case TIFF_LONG:
2333
longy=(uint16) atol(value);
2334
(void) TIFFSetField(tiff,exif_info[i].tag,longy);
2344
ssize_ty=(uint16) StringToLong(value);
2345
(void) TIFFSetField(tiff,exif_info[i].tag,ssize_ty);
2337
2348
case TIFF_RATIONAL:
2538
2546
(void) ThrowMagickException(&image->exception,GetMagickModule(),
2539
2547
CoderError,"CompressionNotSupported","`%s'",MagickOptionToMnemonic(
2540
MagickCompressOptions,(long) compression));
2548
MagickCompressOptions,(ssize_t) compression));
2541
2549
compress_tag=COMPRESSION_NONE;
2542
2550
compression=NoCompression;
2567
2575
(void) ThrowMagickException(&image->exception,GetMagickModule(),
2568
2576
CoderError,"CompressionNotSupported","`%s'",MagickOptionToMnemonic(
2569
MagickCompressOptions,(long) compression));
2577
MagickCompressOptions,(ssize_t) compression));
2570
2578
compress_tag=COMPRESSION_NONE;
2571
2579
compression=NoCompression;
2680
2688
image->endian=MSBEndian;
2681
2689
if ((int) (*(char *) &lsb_first) != 0)
2682
2690
image->endian=LSBEndian;
2683
if ((compress_tag == COMPRESSION_JPEG) && (photometric != PHOTOMETRIC_RGB))
2684
compress_tag=COMPRESSION_NONE;
2691
if ((compress_tag == COMPRESSION_CCITTFAX3) &&
2692
(photometric != PHOTOMETRIC_MINISWHITE))
2694
compress_tag=COMPRESSION_NONE;
2695
endian=FILLORDER_MSB2LSB;
2686
if ((compress_tag == COMPRESSION_CCITTFAX3) &&
2687
(photometric != PHOTOMETRIC_MINISWHITE))
2689
compress_tag=COMPRESSION_NONE;
2690
endian=FILLORDER_MSB2LSB;
2693
if ((compress_tag == COMPRESSION_CCITTFAX4) &&
2694
(photometric != PHOTOMETRIC_MINISWHITE))
2696
compress_tag=COMPRESSION_NONE;
2697
endian=FILLORDER_MSB2LSB;
2698
if ((compress_tag == COMPRESSION_CCITTFAX4) &&
2699
(photometric != PHOTOMETRIC_MINISWHITE))
2701
compress_tag=COMPRESSION_NONE;
2702
endian=FILLORDER_MSB2LSB;
2699
2704
(void) TIFFSetField(tiff,TIFFTAG_COMPRESSION,compress_tag);
2700
2705
(void) TIFFSetField(tiff,TIFFTAG_FILLORDER,endian);
2701
2706
(void) TIFFSetField(tiff,TIFFTAG_BITSPERSAMPLE,quantum_info->depth);
2754
2759
(void) TIFFSetField(tiff,TIFFTAG_PLANARCONFIG,PLANARCONFIG_SEPARATE);
2755
2760
rows_per_strip=1;
2756
2761
if (TIFFScanlineSize(tiff) != 0)
2757
rows_per_strip=(unsigned long) MagickMax((size_t)
2758
TIFFDefaultStripSize(tiff,-1),1);
2762
rows_per_strip=(uint32) MagickMax((size_t) TIFFDefaultStripSize(tiff,0),
2759
2764
option=GetImageOption(image_info,"tiff:rows-per-strip");
2760
2765
if (option != (const char *) NULL)
2761
rows_per_strip=(unsigned long) strtol(option,(char **) NULL,10);
2766
rows_per_strip=(size_t) strtol(option,(char **) NULL,10);
2762
2767
switch (compress_tag)
2764
2769
case COMPRESSION_JPEG:
2781
2786
(void) TIFFSetField(tiff,TIFFTAG_JPEGCOLORMODE,JPEGCOLORMODE_RAW);
2782
2787
if (image->colorspace == RGBColorspace)
2784
2792
(void) TIFFSetField(tiff,TIFFTAG_JPEGCOLORMODE,JPEGCOLORMODE_RGB);
2785
2793
sampling_factor=(const char *) NULL;
2786
2794
value=GetImageProperty(image,"jpeg:sampling-factor");
2810
2818
case COMPRESSION_ADOBE_DEFLATE:
2812
rows_per_strip=image->rows;
2820
rows_per_strip=(uint32) image->rows;
2813
2821
(void) TIFFGetFieldDefaulted(tiff,TIFFTAG_BITSPERSAMPLE,
2814
2822
&bits_per_sample);
2815
2823
if (((photometric == PHOTOMETRIC_RGB) ||
2816
2824
(photometric == PHOTOMETRIC_MINISBLACK)) &&
2817
2825
((bits_per_sample == 8) || (bits_per_sample == 16)))
2818
2826
(void) TIFFSetField(tiff,TIFFTAG_PREDICTOR,2);
2819
(void) TIFFSetField(tiff,TIFFTAG_ZIPQUALITY,image_info->quality ==
2820
UndefinedCompressionQuality ? 7 : MagickMin(1L*image_info->quality/10,
2827
(void) TIFFSetField(tiff,TIFFTAG_ZIPQUALITY,(long) (
2828
image_info->quality == UndefinedCompressionQuality ? 7 :
2829
MagickMin((ssize_t) image_info->quality/10,9)));
2824
2832
case COMPRESSION_CCITTFAX3:
2827
2835
Byte-aligned EOL.
2829
rows_per_strip=image->rows;
2837
rows_per_strip=(uint32) image->rows;
2830
2838
(void) TIFFSetField(tiff,TIFFTAG_GROUP3OPTIONS,4);
2833
2841
case COMPRESSION_CCITTFAX4:
2835
rows_per_strip=image->rows;
2843
rows_per_strip=(uint32) image->rows;
2838
2846
case COMPRESSION_LZW:
2913
2921
page=(uint16) scene;
2914
pages=GetImageListLength(image);
2922
pages=(uint16) GetImageListLength(image);
2915
2923
if ((image_info->adjoin != MagickFalse) && (pages > 1))
2916
2924
(void) TIFFSetField(tiff,TIFFTAG_SUBFILETYPE,FILETYPE_PAGE);
2917
2925
(void) TIFFSetField(tiff,TIFFTAG_PAGENUMBER,page,pages);
2943
2951
quantum_type=RGBQuantum;
2944
2952
if (image->matte != MagickFalse)
2945
2953
quantum_type=RGBAQuantum;
2946
for (y=0; y < (long) image->rows; y++)
2954
for (y=0; y < (ssize_t) image->rows; y++)
2948
2956
register const PixelPacket
2951
2959
p=GetVirtualPixels(image,0,y,image->columns,1,
2952
2960
&image->exception);
2959
2967
if (image->previous == (Image *) NULL)
2961
status=SetImageProgress(image,SaveImageTag,y,image->rows);
2969
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
2962
2971
if (status == MagickFalse)
2972
2981
Plane interlacing: RRRRRR...GGGGGG...BBBBBB...
2974
for (y=0; y < (long) image->rows; y++)
2983
for (y=0; y < (ssize_t) image->rows; y++)
2976
2985
register const PixelPacket
2979
2988
p=GetVirtualPixels(image,0,y,image->columns,1,
2980
2989
&image->exception);
2991
3000
if (status == MagickFalse)
2994
for (y=0; y < (long) image->rows; y++)
3003
for (y=0; y < (ssize_t) image->rows; y++)
2996
3005
register const PixelPacket
2999
3008
p=GetVirtualPixels(image,0,y,image->columns,1,
3000
3009
&image->exception);
3011
3020
if (status == MagickFalse)
3014
for (y=0; y < (long) image->rows; y++)
3023
for (y=0; y < (ssize_t) image->rows; y++)
3016
3025
register const PixelPacket
3019
3028
p=GetVirtualPixels(image,0,y,image->columns,1,
3020
3029
&image->exception);
3034
3043
if (image->matte != MagickFalse)
3035
for (y=0; y < (long) image->rows; y++)
3044
for (y=0; y < (ssize_t) image->rows; y++)
3037
3046
register const PixelPacket
3040
3049
p=GetVirtualPixels(image,0,y,image->columns,1,
3041
3050
&image->exception);
3067
3076
quantum_type=CMYKAQuantum;
3068
3077
if (image->colorspace != CMYKColorspace)
3069
3078
(void) TransformImageColorspace(image,CMYKColorspace);
3070
for (y=0; y < (long) image->rows; y++)
3079
for (y=0; y < (ssize_t) image->rows; y++)
3072
3081
register const PixelPacket
3075
3084
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
3076
3085
if (p == (const PixelPacket *) NULL)
3082
3091
if (image->previous == (Image *) NULL)
3084
status=SetImageProgress(image,SaveImageTag,y,image->rows);
3093
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
3085
3095
if (status == MagickFalse)
3110
3120
(void) ResetMagickMemory(red,0,65536*sizeof(*red));
3111
3121
(void) ResetMagickMemory(green,0,65536*sizeof(*green));
3112
3122
(void) ResetMagickMemory(blue,0,65536*sizeof(*blue));
3113
for (i=0; i < (long) image->colors; i++)
3123
for (i=0; i < (ssize_t) image->colors; i++)
3115
3125
red[i]=ScaleQuantumToShort(image->colormap[i].red);
3116
3126
green[i]=ScaleQuantumToShort(image->colormap[i].green);
3138
3148
if (photometric != PHOTOMETRIC_PALETTE)
3139
3149
quantum_type=GrayQuantum;
3140
for (y=0; y < (long) image->rows; y++)
3150
for (y=0; y < (ssize_t) image->rows; y++)
3142
3152
register const PixelPacket
3145
3155
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
3146
3156
if (p == (const PixelPacket *) NULL)
3152
3162
if (image->previous == (Image *) NULL)
3154
status=SetImageProgress(image,SaveImageTag,y,image->rows);
3164
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
3155
3166
if (status == MagickFalse)