@@ -42,19 +42,22 @@ source product.
42
42
*/
43
43
using System ;
44
44
using System . IO ;
45
+ using iText . Commons . Utils ;
45
46
using iText . IO . Codec ;
46
47
using iText . IO . Source ;
47
48
using iText . IO . Util ;
48
49
using iText . Test ;
49
50
50
51
namespace iText . IO . Image {
51
52
public class TiffTest : ExtendedITextTest {
52
- public static readonly String sourceFolder = iText . Test . TestUtil . GetParentProjectDirectory ( NUnit . Framework . TestContext
53
- . CurrentContext . TestDirectory ) + "/resources/itext/io/image/" ;
53
+ private const double DELTA = 1e-5 ;
54
+
55
+ public static readonly String SOURCE_FOLDER = iText . Test . TestUtil . GetParentProjectDirectory ( NUnit . Framework . TestContext
56
+ . CurrentContext . TestDirectory ) + "/resources/itext/io/image/TiffTest/" ;
54
57
55
58
[ NUnit . Framework . Test ]
56
59
public virtual void OpenTiff1 ( ) {
57
- byte [ ] imageBytes = StreamUtil . InputStreamToArray ( new FileStream ( sourceFolder + "WP_20140410_001.tif" , FileMode . Open
60
+ byte [ ] imageBytes = StreamUtil . InputStreamToArray ( new FileStream ( SOURCE_FOLDER + "WP_20140410_001.tif" , FileMode . Open
58
61
, FileAccess . Read ) ) ;
59
62
// Test a more specific entry point
60
63
ImageData img = ImageDataFactory . CreateTiff ( imageBytes , false , 1 , false ) ;
@@ -66,53 +69,221 @@ public virtual void OpenTiff1() {
66
69
[ NUnit . Framework . Test ]
67
70
public virtual void OpenTiff2 ( ) {
68
71
// Test a more specific entry point
69
- ImageData img = ImageDataFactory . CreateTiff ( UrlUtil . ToURL ( sourceFolder + "WP_20140410_001_gray.tiff" ) , false
70
- , 1 , false ) ;
71
- NUnit . Framework . Assert . AreEqual ( 2592 , img . GetWidth ( ) , 0 ) ;
72
- NUnit . Framework . Assert . AreEqual ( 1456 , img . GetHeight ( ) , 0 ) ;
73
- NUnit . Framework . Assert . AreEqual ( 8 , img . GetBpc ( ) ) ;
72
+ String sourceFile = SOURCE_FOLDER + "WP_20140410_001_gray.tiff" ;
73
+ CreateTiff ( sourceFile , 8 , 2592D , 1456D ) ;
74
74
}
75
75
76
76
[ NUnit . Framework . Test ]
77
77
public virtual void OpenTiff3 ( ) {
78
- ImageData img = ImageDataFactory . Create ( sourceFolder + "WP_20140410_001_monochrome.tiff" ) ;
78
+ ImageData img = ImageDataFactory . Create ( SOURCE_FOLDER + "WP_20140410_001_monochrome.tiff" ) ;
79
79
NUnit . Framework . Assert . AreEqual ( 2592 , img . GetWidth ( ) , 0 ) ;
80
80
NUnit . Framework . Assert . AreEqual ( 1456 , img . GetHeight ( ) , 0 ) ;
81
81
NUnit . Framework . Assert . AreEqual ( 8 , img . GetBpc ( ) ) ;
82
82
}
83
83
84
84
[ NUnit . Framework . Test ]
85
85
public virtual void OpenTiff4 ( ) {
86
- ImageData img = ImageDataFactory . Create ( sourceFolder + "WP_20140410_001_negate.tiff" ) ;
86
+ ImageData img = ImageDataFactory . Create ( SOURCE_FOLDER + "WP_20140410_001_negate.tiff" ) ;
87
87
NUnit . Framework . Assert . AreEqual ( 2592 , img . GetWidth ( ) , 0 ) ;
88
88
NUnit . Framework . Assert . AreEqual ( 1456 , img . GetHeight ( ) , 0 ) ;
89
89
NUnit . Framework . Assert . AreEqual ( 8 , img . GetBpc ( ) ) ;
90
90
}
91
91
92
92
[ NUnit . Framework . Test ]
93
93
public virtual void OpenTiff5 ( ) {
94
- ImageData img = ImageDataFactory . Create ( sourceFolder + "WP_20140410_001_year1900.tiff" ) ;
94
+ ImageData img = ImageDataFactory . Create ( SOURCE_FOLDER + "WP_20140410_001_year1900.tiff" ) ;
95
95
NUnit . Framework . Assert . AreEqual ( 2592 , img . GetWidth ( ) , 0 ) ;
96
96
NUnit . Framework . Assert . AreEqual ( 1456 , img . GetHeight ( ) , 0 ) ;
97
97
NUnit . Framework . Assert . AreEqual ( 8 , img . GetBpc ( ) ) ;
98
98
}
99
99
100
100
[ NUnit . Framework . Test ]
101
101
public virtual void OpenTiff6 ( ) {
102
- ImageData img = ImageDataFactory . Create ( sourceFolder + "WP_20140410_001_year1980.tiff" ) ;
102
+ ImageData img = ImageDataFactory . Create ( SOURCE_FOLDER + "WP_20140410_001_year1980.tiff" ) ;
103
103
NUnit . Framework . Assert . AreEqual ( 2592 , img . GetWidth ( ) , 0 ) ;
104
104
NUnit . Framework . Assert . AreEqual ( 1456 , img . GetHeight ( ) , 0 ) ;
105
105
NUnit . Framework . Assert . AreEqual ( 8 , img . GetBpc ( ) ) ;
106
106
}
107
107
108
108
[ NUnit . Framework . Test ]
109
109
public virtual void GetStringDataFromTiff ( ) {
110
- byte [ ] bytes = File . ReadAllBytes ( System . IO . Path . Combine ( sourceFolder , "img_cmyk.tif" ) ) ;
110
+ byte [ ] bytes = File . ReadAllBytes ( System . IO . Path . Combine ( SOURCE_FOLDER , "img_cmyk.tif" ) ) ;
111
111
TIFFDirectory dir = new TIFFDirectory ( new RandomAccessFileOrArray ( new RandomAccessSourceFactory ( ) . CreateSource
112
112
( bytes ) ) , 0 ) ;
113
113
String [ ] stringArray = new String [ ] { "iText? 7.1.7-SNAPSHOT ?2000-2019 iText Group NV (AGPL-version)\u0000 "
114
114
} ;
115
115
NUnit . Framework . Assert . AreEqual ( stringArray , dir . GetField ( 305 ) . GetAsStrings ( ) ) ;
116
116
}
117
+
118
+ [ NUnit . Framework . Test ]
119
+ public virtual void Group3CompressionCreateTiffImageTest ( ) {
120
+ // TODO: DEVSIX-5565 (update test when support for T4 compression tiff image will be realized)
121
+ Exception e = NUnit . Framework . Assert . Catch ( typeof ( iText . IO . Exceptions . IOException ) , ( ) => ImageDataFactory
122
+ . CreateTiff ( UrlUtil . ToURL ( SOURCE_FOLDER + "group3CompressionImage.tif" ) , false , 1 , false ) ) ;
123
+ NUnit . Framework . Assert . AreEqual ( MessageFormatUtil . Format ( iText . IO . Exceptions . IOException . CannotReadTiffImage
124
+ ) , e . Message ) ;
125
+ }
126
+
127
+ [ NUnit . Framework . Test ]
128
+ public virtual void Group3CompressionCreateImageDataTest ( ) {
129
+ // TODO: DEVSIX-5565 (update test when support for T4 compression tiff image will be realized)
130
+ Exception e = NUnit . Framework . Assert . Catch ( typeof ( iText . IO . Exceptions . IOException ) , ( ) => ImageDataFactory
131
+ . Create ( UrlUtil . ToURL ( SOURCE_FOLDER + "group3CompressionImage.tif" ) ) ) ;
132
+ NUnit . Framework . Assert . AreEqual ( MessageFormatUtil . Format ( iText . IO . Exceptions . IOException . CannotReadTiffImage
133
+ ) , e . Message ) ;
134
+ }
135
+
136
+ [ NUnit . Framework . Test ]
137
+ public virtual void Group4CompressionTiffImageTest ( ) {
138
+ String sourceFile = SOURCE_FOLDER + "group4CompressionImage.tif" ;
139
+ CreateTiff ( sourceFile , 1 , 1024D , 768D ) ;
140
+ }
141
+
142
+ [ NUnit . Framework . Test ]
143
+ public virtual void AdobeDeflateCompression1BitMinIsBlackTest ( ) {
144
+ String sourceFile = SOURCE_FOLDER + "adobeDeflateCompression1BitMinIsBlack.tif" ;
145
+ CreateTiff ( sourceFile , 1 , 1024D , 768D ) ;
146
+ }
147
+
148
+ [ NUnit . Framework . Test ]
149
+ public virtual void AdobeDeflateCompression1BitMinIsWhiteTest ( ) {
150
+ String sourceFile = SOURCE_FOLDER + "adobeDeflateCompression1BitMinIsWhite.tif" ;
151
+ CreateTiff ( sourceFile , 1 , 1024D , 768D ) ;
152
+ }
153
+
154
+ [ NUnit . Framework . Test ]
155
+ public virtual void AdobeDeflateCompression8BitMinIsBlackTest ( ) {
156
+ String sourceFile = SOURCE_FOLDER + "adobeDeflateCompression8BitMinIsBlack.tif" ;
157
+ CreateTiff ( sourceFile , 8 , 1024D , 768D ) ;
158
+ }
159
+
160
+ [ NUnit . Framework . Test ]
161
+ public virtual void AdobeDeflateCompression8BitMinIsWhiteTest ( ) {
162
+ String sourceFile = SOURCE_FOLDER + "adobeDeflateCompression8BitMinIsWhite.tif" ;
163
+ CreateTiff ( sourceFile , 8 , 1024D , 768D ) ;
164
+ }
165
+
166
+ [ NUnit . Framework . Test ]
167
+ public virtual void AdobeDeflateCompression8BitRgbTest ( ) {
168
+ String sourceFile = SOURCE_FOLDER + "adobeDeflateCompression8BitRgb.tif" ;
169
+ CreateTiff ( sourceFile , 8 , 1024D , 768D ) ;
170
+ }
171
+
172
+ [ NUnit . Framework . Test ]
173
+ public virtual void AdobeDeflateComp16BitMinIsBlackCreateTiffTest ( ) {
174
+ // TODO: DEVSIX-5565 (update test when support for adobeDeflate compression tiff image will be realized)
175
+ Exception e = NUnit . Framework . Assert . Catch ( typeof ( iText . IO . Exceptions . IOException ) , ( ) => ImageDataFactory
176
+ . CreateTiff ( UrlUtil . ToURL ( SOURCE_FOLDER + "adobeDeflateCompression16BitMinIsBlack.tif" ) , false , 1 , false
177
+ ) ) ;
178
+ NUnit . Framework . Assert . AreEqual ( MessageFormatUtil . Format ( iText . IO . Exceptions . IOException . CannotReadTiffImage
179
+ ) , e . Message ) ;
180
+ }
181
+
182
+ [ NUnit . Framework . Test ]
183
+ public virtual void AdobeDeflateComp16BitMinIsBlackCreateImageTest ( ) {
184
+ // TODO: DEVSIX-5565 (update test when support for adobeDeflate compression tiff image will be realized)
185
+ Exception e = NUnit . Framework . Assert . Catch ( typeof ( iText . IO . Exceptions . IOException ) , ( ) => ImageDataFactory
186
+ . Create ( UrlUtil . ToURL ( SOURCE_FOLDER + "adobeDeflateCompression16BitMinIsBlack.tif" ) ) ) ;
187
+ NUnit . Framework . Assert . AreEqual ( MessageFormatUtil . Format ( iText . IO . Exceptions . IOException . CannotReadTiffImage
188
+ ) , e . Message ) ;
189
+ }
190
+
191
+ [ NUnit . Framework . Test ]
192
+ public virtual void AdobeDeflateComp16BitMinIsWhiteCreateTiffTest ( ) {
193
+ // TODO: DEVSIX-5565 (update test when support for adobeDeflate compression tiff image will be realized)
194
+ Exception e = NUnit . Framework . Assert . Catch ( typeof ( iText . IO . Exceptions . IOException ) , ( ) => ImageDataFactory
195
+ . CreateTiff ( UrlUtil . ToURL ( SOURCE_FOLDER + "adobeDeflateCompression16BitMinIsWhite.tif" ) , false , 1 , false
196
+ ) ) ;
197
+ NUnit . Framework . Assert . AreEqual ( MessageFormatUtil . Format ( iText . IO . Exceptions . IOException . CannotReadTiffImage
198
+ ) , e . Message ) ;
199
+ }
200
+
201
+ [ NUnit . Framework . Test ]
202
+ public virtual void AdobeDeflateComp16BitMinIsWhiteCreateImageTest ( ) {
203
+ // TODO: DEVSIX-5565 (update test when support for adobeDeflate compression tiff image will be realized)
204
+ Exception e = NUnit . Framework . Assert . Catch ( typeof ( iText . IO . Exceptions . IOException ) , ( ) => ImageDataFactory
205
+ . Create ( UrlUtil . ToURL ( SOURCE_FOLDER + "adobeDeflateCompression16BitMinIsWhite.tif" ) ) ) ;
206
+ NUnit . Framework . Assert . AreEqual ( MessageFormatUtil . Format ( iText . IO . Exceptions . IOException . CannotReadTiffImage
207
+ ) , e . Message ) ;
208
+ }
209
+
210
+ [ NUnit . Framework . Test ]
211
+ public virtual void AdobeDeflateCompression16BitRgbCreateTiffTest ( ) {
212
+ // TODO: DEVSIX-5565 (update test when support for adobeDeflate compression tiff image will be realized)
213
+ Exception e = NUnit . Framework . Assert . Catch ( typeof ( iText . IO . Exceptions . IOException ) , ( ) => ImageDataFactory
214
+ . CreateTiff ( UrlUtil . ToURL ( SOURCE_FOLDER + "adobeDeflateCompression16BitRgb.tif" ) , false , 1 , false ) ) ;
215
+ NUnit . Framework . Assert . AreEqual ( MessageFormatUtil . Format ( iText . IO . Exceptions . IOException . CannotReadTiffImage
216
+ ) , e . Message ) ;
217
+ }
218
+
219
+ [ NUnit . Framework . Test ]
220
+ public virtual void AdobeDeflateCompression16BitRgbCreateImageTest ( ) {
221
+ // TODO: DEVSIX-5565 (update test when support for adobeDeflate compression tiff image will be realized)
222
+ Exception e = NUnit . Framework . Assert . Catch ( typeof ( iText . IO . Exceptions . IOException ) , ( ) => ImageDataFactory
223
+ . Create ( UrlUtil . ToURL ( SOURCE_FOLDER + "adobeDeflateCompression16BitRgb.tif" ) ) ) ;
224
+ NUnit . Framework . Assert . AreEqual ( MessageFormatUtil . Format ( iText . IO . Exceptions . IOException . CannotReadTiffImage
225
+ ) , e . Message ) ;
226
+ }
227
+
228
+ [ NUnit . Framework . Test ]
229
+ public virtual void CcittRleCompressionTest ( ) {
230
+ String sourceFile = SOURCE_FOLDER + "ccittRleCompression.tif" ;
231
+ CreateTiff ( sourceFile , 1 , 1024D , 768D ) ;
232
+ }
233
+
234
+ [ NUnit . Framework . Test ]
235
+ public virtual void DeflateCompression8BitRgbTest ( ) {
236
+ String sourceFile = SOURCE_FOLDER + "deflateCompression8BitRgb.tif" ;
237
+ CreateTiff ( sourceFile , 8 , 1024D , 768D ) ;
238
+ }
239
+
240
+ [ NUnit . Framework . Test ]
241
+ public virtual void DeflateCompression8BitPaletteTest ( ) {
242
+ String sourceFile = SOURCE_FOLDER + "deflateCompression8BitPalette.tif" ;
243
+ CreateTiff ( sourceFile , 8 , 1024D , 768D ) ;
244
+ }
245
+
246
+ [ NUnit . Framework . Test ]
247
+ public virtual void JpegCompression8BitYcbcrTest ( ) {
248
+ String sourceFile = SOURCE_FOLDER + "jpegCompression8BitYcbcr.tif" ;
249
+ CreateTiff ( sourceFile , 8 , 1024D , 768D ) ;
250
+ }
251
+
252
+ [ NUnit . Framework . Test ]
253
+ public virtual void OldJpegCompression8BitYcbcrTest ( ) {
254
+ String sourceFile = SOURCE_FOLDER + "oldJpegCompression8BitYcbcr.tif" ;
255
+ CreateTiff ( sourceFile , 8 , 1024D , 768D ) ;
256
+ }
257
+
258
+ [ NUnit . Framework . Test ]
259
+ public virtual void LzwCompression8BitRgbTest ( ) {
260
+ String sourceFile = SOURCE_FOLDER + "lzwCompression8BitRgb.tif" ;
261
+ CreateTiff ( sourceFile , 8 , 1024D , 768D ) ;
262
+ }
263
+
264
+ [ NUnit . Framework . Test ]
265
+ public virtual void LzwCompression8BitPaletteTest ( ) {
266
+ String sourceFile = SOURCE_FOLDER + "lzwCompression8BitPalette.tif" ;
267
+ CreateTiff ( sourceFile , 8 , 1024D , 768D ) ;
268
+ }
269
+
270
+ [ NUnit . Framework . Test ]
271
+ public virtual void PackbitsCompression8BitMinIsBlackTest ( ) {
272
+ String sourceFile = SOURCE_FOLDER + "packbitsCompression8BitMinIsBlack.tif" ;
273
+ CreateTiff ( sourceFile , 8 , 1024D , 768D ) ;
274
+ }
275
+
276
+ [ NUnit . Framework . Test ]
277
+ public virtual void PackbitsCompression8BitMinIsWhiteTest ( ) {
278
+ String sourceFile = SOURCE_FOLDER + "packbitsCompression8BitMinIsWhite.tif" ;
279
+ CreateTiff ( sourceFile , 8 , 1024D , 768D ) ;
280
+ }
281
+
282
+ private static void CreateTiff ( String sourceFile , int bpc , double width , double height ) {
283
+ ImageData img = ImageDataFactory . CreateTiff ( UrlUtil . ToURL ( sourceFile ) , false , 1 , false ) ;
284
+ NUnit . Framework . Assert . AreEqual ( bpc , img . GetBpc ( ) , DELTA ) ;
285
+ NUnit . Framework . Assert . AreEqual ( width , img . GetWidth ( ) , DELTA ) ;
286
+ NUnit . Framework . Assert . AreEqual ( height , img . GetHeight ( ) , DELTA ) ;
287
+ }
117
288
}
118
289
}
0 commit comments