| 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 |
#include "tiffiop.h" |
| 29 |
|
| 30 |
int TIFFFlush(TIFF *tif) |
| 31 |
{ |
| 32 |
if (tif->tif_mode == O_RDONLY) |
| 33 |
return 1; |
| 34 |
|
| 35 |
if (!TIFFFlushData(tif)) |
| 36 |
return (0); |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
if ((tif->tif_flags & TIFF_DIRTYSTRIP) && |
| 44 |
!(tif->tif_flags & TIFF_DIRTYDIRECT) && tif->tif_mode == O_RDWR) |
| 45 |
{ |
| 46 |
if (TIFFForceStrileArrayWriting(tif)) |
| 47 |
return 1; |
| 48 |
} |
| 49 |
|
| 50 |
if ((tif->tif_flags & (TIFF_DIRTYDIRECT | TIFF_DIRTYSTRIP)) && |
| 51 |
!TIFFRewriteDirectory(tif)) |
| 52 |
return (0); |
| 53 |
|
| 54 |
return (1); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
int TIFFForceStrileArrayWriting(TIFF *tif) |
| 77 |
{ |
| 78 |
static const char module[] = "TIFFForceStrileArrayWriting"; |
| 79 |
const int isTiled = TIFFIsTiled(tif); |
| 80 |
|
| 81 |
if (tif->tif_mode == O_RDONLY) |
| 82 |
{ |
| 83 |
TIFFErrorExtR(tif, tif->tif_name, "File opened in read-only mode"); |
| 84 |
return 0; |
| 85 |
} |
| 86 |
if (tif->tif_diroff == 0) |
| 87 |
{ |
| 88 |
TIFFErrorExtR(tif, module, "Directory has not yet been written"); |
| 89 |
return 0; |
| 90 |
} |
| 91 |
if ((tif->tif_flags & TIFF_DIRTYDIRECT) != 0) |
| 92 |
{ |
| 93 |
TIFFErrorExtR(tif, module, |
| 94 |
"Directory has changes other than the strile arrays. " |
| 95 |
"TIFFRewriteDirectory() should be called instead"); |
| 96 |
return 0; |
| 97 |
} |
| 98 |
|
| 99 |
if (!(tif->tif_flags & TIFF_DIRTYSTRIP)) |
| 100 |
{ |
| 101 |
if (!(tif->tif_dir.td_stripoffset_entry.tdir_tag != 0 && |
| 102 |
tif->tif_dir.td_stripoffset_entry.tdir_count == 0 && |
| 103 |
tif->tif_dir.td_stripoffset_entry.tdir_type == 0 && |
| 104 |
tif->tif_dir.td_stripoffset_entry.tdir_offset.toff_long8 == 0 && |
| 105 |
tif->tif_dir.td_stripbytecount_entry.tdir_tag != 0 && |
| 106 |
tif->tif_dir.td_stripbytecount_entry.tdir_count == 0 && |
| 107 |
tif->tif_dir.td_stripbytecount_entry.tdir_type == 0 && |
| 108 |
tif->tif_dir.td_stripbytecount_entry.tdir_offset.toff_long8 == 0)) |
| 109 |
{ |
| 110 |
TIFFErrorExtR(tif, module, |
| 111 |
"Function not called together with " |
| 112 |
"TIFFDeferStrileArrayWriting()"); |
| 113 |
return 0; |
| 114 |
} |
| 115 |
|
| 116 |
if (tif->tif_dir.td_stripoffset_p == NULL && !TIFFSetupStrips(tif)) |
| 117 |
return 0; |
| 118 |
} |
| 119 |
|
| 120 |
if (_TIFFRewriteField(tif, |
| 121 |
isTiled ? TIFFTAG_TILEOFFSETS : TIFFTAG_STRIPOFFSETS, |
| 122 |
TIFF_LONG8, tif->tif_dir.td_nstrips, |
| 123 |
tif->tif_dir.td_stripoffset_p) && |
| 124 |
_TIFFRewriteField( |
| 125 |
tif, isTiled ? TIFFTAG_TILEBYTECOUNTS : TIFFTAG_STRIPBYTECOUNTS, |
| 126 |
TIFF_LONG8, tif->tif_dir.td_nstrips, |
| 127 |
tif->tif_dir.td_stripbytecount_p)) |
| 128 |
{ |
| 129 |
tif->tif_flags &= ~TIFF_DIRTYSTRIP; |
| 130 |
tif->tif_flags &= ~TIFF_BEENWRITING; |
| 131 |
return 1; |
| 132 |
} |
| 133 |
|
| 134 |
return 0; |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
int TIFFFlushData(TIFF *tif) |
| 147 |
{ |
| 148 |
if ((tif->tif_flags & TIFF_BEENWRITING) == 0) |
| 149 |
return (1); |
| 150 |
if (tif->tif_flags & TIFF_POSTENCODE) |
| 151 |
{ |
| 152 |
tif->tif_flags &= ~TIFF_POSTENCODE; |
| 153 |
if (!(*tif->tif_postencode)(tif)) |
| 154 |
return (0); |
| 155 |
} |
| 156 |
return (TIFFFlushData1(tif)); |
| 157 |
} |