1 /*
2 * Copyright 2020 The Chromium Authors. All Rights Reserved.
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 *
8 * Permission is granted to anyone to use this software for any purpose,
9 * including commercial applications, and to alter it and redistribute it
10 * freely, subject to the following restrictions:
11 *
12 * 1. The origin of this software must not be misrepresented; you must not
13 * claim that you wrote the original software. If you use this software
14 * in a product, an acknowledgment in the product documentation would be
15 * appreciated but is not required.
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 * 3. This notice may not be removed or altered from any source distribution.
19 */
20
21 #include "base/files/file.h"
22 #include "base/files/file_util.h"
23 #include "base/path_service.h"
24 #include "gtest-utils.h"
25
26 #include <gtest/gtest.h>
27 #include <string>
28
29 extern "C" int cjpeg(int argc, char *argv[]);
30
TEST(CJPEGTest,RGBISlow)31 TEST(CJPEGTest, RGBISlow) {
32
33 base::FilePath icc_path;
34 GetTestFilePath(&icc_path, "test1.icc");
35 base::FilePath input_image_path;
36 GetTestFilePath(&input_image_path, "testorig.ppm");
37 base::FilePath output_path(GetTargetDirectory());
38 output_path = output_path.AppendASCII("testout_rgb_islow.jpg");
39
40 std::string prog_name = "cjpeg";
41 std::string arg1 = "-rgb";
42 std::string arg2 = "-dct";
43 std::string arg3 = "int";
44 std::string arg4 = "-icc";
45 std::string arg5 = icc_path.MaybeAsASCII();
46 std::string arg6 = "-outfile";
47 std::string arg7 = output_path.MaybeAsASCII();
48 std::string arg8 = input_image_path.MaybeAsASCII();
49
50 char *command_line[] = { &prog_name[0],
51 &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
52 &arg6[0], &arg7[0], &arg8[0],
53 };
54 // Generate test image file.
55 EXPECT_EQ(cjpeg(9, command_line), 0);
56
57 // Compare expected MD5 sum against that of test image.
58 const std::string EXPECTED_MD5 = "1d44a406f61da743b5fd31c0a9abdca3";
59 EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
60 }
61
TEST(CJPEGTest,IFastOpt422)62 TEST(CJPEGTest, IFastOpt422) {
63
64 base::FilePath input_image_path;
65 GetTestFilePath(&input_image_path, "testorig.ppm");
66 base::FilePath output_path(GetTargetDirectory());
67 output_path = output_path.AppendASCII("testout_422_ifast_opt.jpg");
68
69 std::string prog_name = "cjpeg";
70 std::string arg1 = "-sample";
71 std::string arg2 = "2x1";
72 std::string arg3 = "-dct";
73 std::string arg4 = "fast";
74 std::string arg5 = "-opt";
75 std::string arg6 = "-outfile";
76 std::string arg7 = output_path.MaybeAsASCII();
77 std::string arg8 = input_image_path.MaybeAsASCII();
78
79 char *command_line[] = { &prog_name[0],
80 &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
81 &arg6[0], &arg7[0], &arg8[0],
82 };
83 // Generate test image file.
84 EXPECT_EQ(cjpeg(9, command_line), 0);
85
86 // Compare expected MD5 sum against that of test image.
87 const std::string EXPECTED_MD5 = "2540287b79d913f91665e660303ab2c8";
88 EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
89 }
90
TEST(CJPEGTest,IFastProg420Q100)91 TEST(CJPEGTest, IFastProg420Q100) {
92
93 base::FilePath scans_path;
94 GetTestFilePath(&scans_path, "test.scan");
95 base::FilePath input_image_path;
96 GetTestFilePath(&input_image_path, "testorig.ppm");
97 base::FilePath output_path(GetTargetDirectory());
98 output_path = output_path.AppendASCII("testout_420_q100_ifast_prog.jpg");
99
100 std::string prog_name = "cjpeg";
101 std::string arg1 = "-sample";
102 std::string arg2 = "2x2";
103 std::string arg3 = "-quality";
104 std::string arg4 = "100";
105 std::string arg5 = "-dct";
106 std::string arg6 = "fast";
107 std::string arg7 = "-scans";
108 std::string arg8 = scans_path.MaybeAsASCII();
109 std::string arg9 = "-outfile";
110 std::string arg10 = output_path.MaybeAsASCII();
111 std::string arg11 = input_image_path.MaybeAsASCII();
112
113 char *command_line[] = { &prog_name[0],
114 &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
115 &arg6[0], &arg7[0], &arg8[0], &arg9[0], &arg10[0],
116 &arg11[0]
117 };
118 // Generate test image file.
119 EXPECT_EQ(cjpeg(12, command_line), 0);
120
121 // Compare expected MD5 sum against that of test image.
122 const std::string EXPECTED_MD5 = "0ba15f9dab81a703505f835f9dbbac6d";
123 EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
124 }
125
TEST(CJPEGTest,GrayISlow)126 TEST(CJPEGTest, GrayISlow) {
127
128 base::FilePath input_image_path;
129 GetTestFilePath(&input_image_path, "testorig.ppm");
130 base::FilePath output_path(GetTargetDirectory());
131 output_path = output_path.AppendASCII("testout_gray_islow.jpg");
132
133 std::string prog_name = "cjpeg";
134 std::string arg1 = "-gray";
135 std::string arg2 = "-dct";
136 std::string arg3 = "int";
137 std::string arg4 = "-outfile";
138 std::string arg5 = output_path.MaybeAsASCII();
139 std::string arg6 = input_image_path.MaybeAsASCII();
140
141 char *command_line[] = { &prog_name[0],
142 &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
143 &arg6[0],
144 };
145 // Generate test image file.
146 EXPECT_EQ(cjpeg(7, command_line), 0);
147
148 // Compare expected MD5 sum against that of test image.
149 const std::string EXPECTED_MD5 = "72b51f894b8f4a10b3ee3066770aa38d";
150 EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
151 }
152
TEST(CJPEGTest,IFastOpt420S)153 TEST(CJPEGTest, IFastOpt420S) {
154
155 base::FilePath input_image_path;
156 GetTestFilePath(&input_image_path, "testorig.ppm");
157 base::FilePath output_path(GetTargetDirectory());
158 output_path = output_path.AppendASCII("testout_420s_ifast_opt.jpg");
159
160 std::string prog_name = "cjpeg";
161 std::string arg1 = "-sample";
162 std::string arg2 = "2x2";
163 std::string arg3 = "-smooth";
164 std::string arg4 = "1";
165 std::string arg5 = "-dct";
166 std::string arg6 = "int";
167 std::string arg7 = "-opt";
168 std::string arg8 = "-outfile";
169 std::string arg9 = output_path.MaybeAsASCII();
170 std::string arg10 = input_image_path.MaybeAsASCII();
171
172 char *command_line[] = { &prog_name[0],
173 &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
174 &arg6[0], &arg7[0], &arg8[0], &arg9[0], &arg10[0]
175 };
176 // Generate test image file.
177 EXPECT_EQ(cjpeg(11, command_line), 0);
178
179 // Compare expected MD5 sum against that of test image.
180 const std::string EXPECTED_MD5 = "388708217ac46273ca33086b22827ed8";
181 EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
182 }
183
TEST(CJPEGTest,FloatProg3x2)184 TEST(CJPEGTest, FloatProg3x2) {
185
186 base::FilePath input_image_path;
187 GetTestFilePath(&input_image_path, "testorig.ppm");
188 base::FilePath output_path(GetTargetDirectory());
189 output_path = output_path.AppendASCII("testout_3x2_float_prog.jpg");
190
191 std::string prog_name = "cjpeg";
192 std::string arg1 = "-sample";
193 std::string arg2 = "3x2";
194 std::string arg3 = "-dct";
195 std::string arg4 = "float";
196 std::string arg5 = "-prog";
197 std::string arg6 = "-outfile";
198 std::string arg7 = output_path.MaybeAsASCII();
199 std::string arg8 = input_image_path.MaybeAsASCII();
200
201 char *command_line[] = { &prog_name[0],
202 &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
203 &arg6[0], &arg7[0], &arg8[0]
204 };
205 // Generate test image file.
206 EXPECT_EQ(cjpeg(9, command_line), 0);
207
208 // Compare expected MD5 sum against that of test image.
209 #if defined(WITH_SIMD) && (defined(__i386__) || defined(__x86_64__))
210 const std::string EXPECTED_MD5 = "343e3f8caf8af5986ebaf0bdc13b5c71";
211 #else
212 const std::string EXPECTED_MD5 = "9bca803d2042bd1eb03819e2bf92b3e5";
213 #endif
214 EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
215 }
216
TEST(CJPEGTest,IFastProg3x2)217 TEST(CJPEGTest, IFastProg3x2) {
218
219 base::FilePath input_image_path;
220 GetTestFilePath(&input_image_path, "testorig.ppm");
221 base::FilePath output_path(GetTargetDirectory());
222 output_path = output_path.AppendASCII("testout_3x2_ifast_prog.jpg");
223
224 std::string prog_name = "cjpeg";
225 std::string arg1 = "-sample";
226 std::string arg2 = "3x2";
227 std::string arg3 = "-dct";
228 std::string arg4 = "fast";
229 std::string arg5 = "-prog";
230 std::string arg6 = "-outfile";
231 std::string arg7 = output_path.MaybeAsASCII();
232 std::string arg8 = input_image_path.MaybeAsASCII();
233
234 char *command_line[] = { &prog_name[0],
235 &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
236 &arg6[0], &arg7[0], &arg8[0]
237 };
238 // Generate test image file.
239 EXPECT_EQ(cjpeg(9, command_line), 0);
240
241 // Compare expected MD5 sum against that of test image.
242 const std::string EXPECTED_MD5 = "1ee5d2c1a77f2da495f993c8c7cceca5";
243 EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
244 }
245
246 #ifdef C_ARITH_CODING_SUPPORTED
TEST(CJPEGTest,ISlowAri420)247 TEST(CJPEGTest, ISlowAri420) {
248
249 base::FilePath input_image_path;
250 GetTestFilePath(&input_image_path, "testorig.ppm");
251 base::FilePath output_path(GetTargetDirectory());
252 output_path = output_path.AppendASCII("testout_420_islow_ari.jpg");
253
254 std::string prog_name = "cjpeg";
255 std::string arg1 = "-dct";
256 std::string arg2 = "int";
257 std::string arg3 = "-arithmetic";
258 std::string arg4 = "-outfile";
259 std::string arg5 = output_path.MaybeAsASCII();
260 std::string arg6 = input_image_path.MaybeAsASCII();
261
262 char *command_line[] = { &prog_name[0],
263 &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
264 &arg6[0]
265 };
266 // Generate test image file.
267 EXPECT_EQ(cjpeg(7, command_line), 0);
268
269 // Compare expected MD5 sum against that of test image.
270 const std::string EXPECTED_MD5 = "e986fb0a637a8d833d96e8a6d6d84ea1";
271 EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
272 }
273
TEST(CJPEGTest,ISlowProgAri444)274 TEST(CJPEGTest, ISlowProgAri444) {
275
276 base::FilePath input_image_path;
277 GetTestFilePath(&input_image_path, "testorig.ppm");
278 base::FilePath output_path(GetTargetDirectory());
279 output_path = output_path.AppendASCII("testout_444_islow_progari.jpg");
280
281 std::string prog_name = "cjpeg";
282 std::string arg1 = "-sample";
283 std::string arg2 = "1x1";
284 std::string arg3 = "-dct";
285 std::string arg4 = "int";
286 std::string arg5 = "-prog";
287 std::string arg6 = "-arithmetic";
288 std::string arg7 = "-outfile";
289 std::string arg8 = output_path.MaybeAsASCII();
290 std::string arg9 = input_image_path.MaybeAsASCII();
291
292 char *command_line[] = { &prog_name[0],
293 &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
294 &arg6[0], &arg7[0], &arg8[0], &arg9[0]
295 };
296 // Generate test image file.
297 EXPECT_EQ(cjpeg(10, command_line), 0);
298
299 // Compare expected MD5 sum against that of test image.
300 const std::string EXPECTED_MD5 = "0a8f1c8f66e113c3cf635df0a475a617";
301 EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
302 }
303
TEST(CJPEGTest,ISlowAri444)304 TEST(CJPEGTest, ISlowAri444) {
305
306 base::FilePath input_image_path;
307 GetTestFilePath(&input_image_path, "testorig.ppm");
308 base::FilePath output_path(GetTargetDirectory());
309 output_path = output_path.AppendASCII("testout_444_islow_ari.jpg");
310
311 std::string prog_name = "cjpeg";
312 std::string arg1 = "-dct";
313 std::string arg2 = "int";
314 std::string arg3 = "-arithmetic";
315 std::string arg4 = "-sample";
316 std::string arg5 = "1x1";
317 std::string arg6 = "-outfile";
318 std::string arg7 = output_path.MaybeAsASCII();
319 std::string arg8 = input_image_path.MaybeAsASCII();
320
321 char *command_line[] = { &prog_name[0],
322 &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
323 &arg6[0], &arg7[0], &arg8[0]
324 };
325 // Generate test image file.
326 EXPECT_EQ(cjpeg(9, command_line), 0);
327
328 // Compare expected MD5 sum against that of test image.
329 const std::string EXPECTED_MD5 = "dd1b827fc504feb0259894e7132585b4";
330 EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
331 }
332 #endif
333
TEST(CJPEGTest,ISlowProg420)334 TEST(CJPEGTest, ISlowProg420) {
335
336 base::FilePath input_image_path;
337 GetTestFilePath(&input_image_path, "testorig.ppm");
338 base::FilePath output_path(GetTargetDirectory());
339 output_path = output_path.AppendASCII("testout_420_islow_prog.jpg");
340
341 std::string prog_name = "cjpeg";
342 std::string arg1 = "-dct";
343 std::string arg2 = "int";
344 std::string arg3 = "-prog";
345 std::string arg4 = "-outfile";
346 std::string arg5 = output_path.MaybeAsASCII();
347 std::string arg6 = input_image_path.MaybeAsASCII();
348
349 char *command_line[] = { &prog_name[0],
350 &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
351 &arg6[0]
352 };
353 // Generate test image file.
354 EXPECT_EQ(cjpeg(7, command_line), 0);
355
356 // Compare expected MD5 sum against that of test image.
357 const std::string EXPECTED_MD5 = "1c4afddc05c0a43489ee54438a482d92";
358 EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
359 }
360
TEST(CJPEGTest,ISlow444)361 TEST(CJPEGTest, ISlow444) {
362
363 base::FilePath input_image_path;
364 GetTestFilePath(&input_image_path, "testorig.ppm");
365 base::FilePath output_path(GetTargetDirectory());
366 output_path = output_path.AppendASCII("testout_444_islow.jpg");
367
368 std::string prog_name = "cjpeg";
369 std::string arg1 = "-dct";
370 std::string arg2 = "int";
371 std::string arg3 = "-sample";
372 std::string arg4 = "1x1";
373 std::string arg5 = "-outfile";
374 std::string arg6 = output_path.MaybeAsASCII();
375 std::string arg7 = input_image_path.MaybeAsASCII();
376
377 char *command_line[] = { &prog_name[0],
378 &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
379 &arg6[0], &arg7[0]
380 };
381 // Generate test image file.
382 EXPECT_EQ(cjpeg(8, command_line), 0);
383
384 // Compare expected MD5 sum against that of test image.
385 const std::string EXPECTED_MD5 = "62a8665a2e08e90c6fffa3a94b894ce2";
386 EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
387 }
388
TEST(CJPEGTest,ISlowProg444)389 TEST(CJPEGTest, ISlowProg444) {
390
391 base::FilePath input_image_path;
392 GetTestFilePath(&input_image_path, "testorig.ppm");
393 base::FilePath output_path(GetTargetDirectory());
394 output_path = output_path.AppendASCII("testout_444_islow_prog.jpg");
395
396 std::string prog_name = "cjpeg";
397 std::string arg1 = "-dct";
398 std::string arg2 = "int";
399 std::string arg3 = "-prog";
400 std::string arg4 = "-sample";
401 std::string arg5 = "1x1";
402 std::string arg6 = "-outfile";
403 std::string arg7 = output_path.MaybeAsASCII();
404 std::string arg8 = input_image_path.MaybeAsASCII();
405
406 char *command_line[] = { &prog_name[0],
407 &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
408 &arg6[0], &arg7[0], &arg8[0]
409 };
410 // Generate test image file.
411 EXPECT_EQ(cjpeg(9, command_line), 0);
412
413 // Compare expected MD5 sum against that of test image.
414 const std::string EXPECTED_MD5 = "666ef192fff72570e332db7610e1a7d1";
415 EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
416 }
417