-
Notifications
You must be signed in to change notification settings - Fork 122
/
Copy pathRgbaImage.cs
213 lines (191 loc) · 7.02 KB
/
RgbaImage.cs
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
using System.Collections.Generic;
using System.IO;
using BitMiracle.LibTiff.Classic;
using NUnit.Framework;
namespace UnitTests
{
[TestFixture]
class RgbaImage
{
private static string[] Files
{
get
{
return new string[]
{
"CCITT_1.TIF",
"CCITT_2.TIF",
"CCITT_3.TIF",
"CCITT_4.TIF",
"CCITT_5.TIF",
"CCITT_6.TIF",
"CCITT_7.TIF",
"CCITT_8.TIF",
"FLAG_T24.TIF",
"G31D.TIF",
"G31DS.TIF",
"G32D.TIF",
"G32DS.TIF",
"G4.TIF",
"G4S.TIF",
"GMARBLES.TIF",
"MARBIBM.TIF",
"MARBLES.TIF",
"XING_T24.TIF",
"cramps-tile.tif",
"cramps.tif",
"flower-minisblack-02.tif",
"flower-minisblack-04.tif",
"flower-minisblack-08.tif",
"flower-minisblack-16.tif",
"flower-palette-02.tif",
"flower-palette-04.tif",
"flower-palette-08.tif",
"flower-rgb-contig-08.tif",
"flower-rgb-contig-16.tif",
"flower-rgb-planar-08.tif",
"flower-rgb-planar-16.tif",
"flower-separated-contig-08.tif",
"dscf0013.tif",
"fax2d.tif",
"g3test.tif",
"jello.tif",
"jim___ah.tif",
"jim___cg.tif",
"jim___dg.tif",
"jim___gg.tif",
"ladoga.tif",
"oxford.tif",
"pc260001.tif",
"quad-jpeg.tif",
"quad-lzw.tif",
"quad-tile.tif",
"strike.tif",
"ycbcr-cat.tif",
};
}
}
private static string[] ToPlainRgbaFiles
{
get
{
return new string[]
{
"lab8-lzw.tif",
"gray16-lzw-pc.tif",
"tiger-palette-strip-01.tif",
"chevron.tif",
"chevron-separate.tif",
"flower-rgb-contig-16-unassoc-alpha.tif",
"flower-rgb-contig-16-assoc-alpha.tif",
"flower-rgb-planar-16-unassoc-alpha.tif",
"flower-rgb-planar-16-assoc-alpha.tif",
"strike-separate.tif",
"flower-ycbcr-contig-08.tif",
"flower-ycbcr-separate-08.tif",
"flower-ycbcr12-contig-08.tif",
"flower-ycbcr41-contig-08.tif",
"flower-ycbcr42-contig-08.tif",
"flower-ycbcr44-contig-08.tif",
"palette1bpp.tif",
"cmyka-tile.tif",
"gray8a-tile.tif"
};
}
}
private static string[] ToRgbaFiles
{
get
{
return new string[]
{
"gray16-lzw-pc.tif",
"smallliz.tif",
"zackthecat.tif",
};
}
}
private static string[] ToRgbaZipFiles
{
get
{
return new string[]
{
"gray16-lzw-pc.tif",
"127.tif",
};
}
}
private static bool tryReadRGBAImage(string file)
{
Tiff tiff = Tiff.Open(file, "r");
int w = tiff.GetField(TiffTag.IMAGEWIDTH)[0].ToInt();
int h = tiff.GetField(TiffTag.IMAGELENGTH)[0].ToInt();
int[] raster = new int[w * h];
return tiff.ReadRGBAImage(w, h, raster);
}
private static void testTiff2Rgba(string file, string[] args, string suffix)
{
string inputFile = Path.Combine(TestCase.Folder, Path.GetFileName(file));
string outputFile = TestCase.Folder + @"Output.Tiff\" + Path.GetFileName(file) + suffix + ".tif";
List<string> completeArgs = new List<string>(args.Length + 2);
for (int i = 0; i < args.Length; ++i)
completeArgs.Add(args[i]);
completeArgs.Add(inputFile);
completeArgs.Add(outputFile);
File.Delete(outputFile);
BitMiracle.Tiff2Rgba.Program.g_testFriendly = true;
BitMiracle.Tiff2Rgba.Program.Main(completeArgs.ToArray());
string sampleFile = outputFile.Replace(@"\Output.Tiff\", @"\Expected.Tiff\");
Assert.IsTrue(File.Exists(outputFile));
FileAssert.AreEqual(sampleFile, outputFile);
}
[Test, TestCaseSource("Files")]
public void TestReadRGBAImage(string file)
{
string fullPath = Path.Combine(TestCase.Folder, file);
bool ok = tryReadRGBAImage(fullPath);
Assert.True(ok);
}
[Test, TestCaseSource("ToPlainRgbaFiles")]
public void TestTiff2Rgba(string file)
{
testTiff2Rgba(file, new string[] { }, "_rgba");
}
[Test, TestCaseSource("ToRgbaFiles")]
public void TestTiff2RgbaBlocks(string file)
{
testTiff2Rgba(file, new string[] { "-b" }, "_rgba_b");
}
[Test, TestCaseSource("ToRgbaFiles")]
public void TestTiff2RgbaRows(string file)
{
testTiff2Rgba(file, new string[] { "-r", "3" }, "_rgba_r3");
}
[Test, TestCaseSource("ToRgbaFiles")]
public void TestTiff2RgbaNoAlpha(string file)
{
testTiff2Rgba(file, new string[] { "-n" }, "_rgba_noalpha");
}
[Test, TestCaseSource("ToRgbaFiles")]
public void TestTiff2RgbaJpeg(string file)
{
testTiff2Rgba(file, new string[] { "-c", "jpeg" }, "_rgba_jpeg");
}
[Test, TestCaseSource("ToRgbaZipFiles")]
public void TestTiff2RgbaZip(string file)
{
testTiff2Rgba(file, new string[] { "-c", "zip" }, "_rgba_zip");
}
[Test, TestCaseSource("ToRgbaFiles")]
public void TestTiff2RgbaLzw(string file)
{
testTiff2Rgba(file, new string[] { "-c", "lzw" }, "_rgba_lzw");
}
[Test, TestCaseSource("ToRgbaFiles")]
public void TestTiff2RgbaNone(string file)
{
testTiff2Rgba(file, new string[] { "-c", "none" }, "_rgba_none");
}
}
}