xref: /aosp_15_r20/external/libjpeg-turbo/gtest/djpeg-gtest-wrapper.cpp (revision dfc6aa5c1cfd4bc4e2018dc74aa96e29ee49c6da)
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 djpeg(int argc, char *argv[]);
30 
31 const static std::vector<std::tuple<const std::string,
32                                     const std::string,
33                                     const std::string>> SCALE_IMAGE_MD5 = {
34   std::make_tuple("2/1", "testout_420m_islow_2_1.ppm",
35                   "9f9de8c0612f8d06869b960b05abf9c9"),
36   std::make_tuple("15/8", "testout_420m_islow_15_8.ppm",
37                   "b6875bc070720b899566cc06459b63b7"),
38   std::make_tuple("13/8", "testout_420m_islow_13_8.ppm",
39                   "bc3452573c8152f6ae552939ee19f82f"),
40   std::make_tuple("11/8", "testout_420m_islow_11_8.ppm",
41                   "d8cc73c0aaacd4556569b59437ba00a5"),
42   std::make_tuple("9/8", "testout_420m_islow_9_8.ppm",
43                   "d25e61bc7eac0002f5b393aa223747b6"),
44   std::make_tuple("7/8", "testout_420m_islow_7_8.ppm",
45                   "ddb564b7c74a09494016d6cd7502a946"),
46   std::make_tuple("3/4", "testout_420m_islow_3_4.ppm",
47                   "8ed8e68808c3fbc4ea764fc9d2968646"),
48   std::make_tuple("5/8", "testout_420m_islow_5_8.ppm",
49                   "a3363274999da2366a024efae6d16c9b"),
50   std::make_tuple("1/2", "testout_420m_islow_1_2.ppm",
51                   "e692a315cea26b988c8e8b29a5dbcd81"),
52   std::make_tuple("3/8", "testout_420m_islow_3_8.ppm",
53                   "79eca9175652ced755155c90e785a996"),
54   std::make_tuple("1/4", "testout_420m_islow_1_4.ppm",
55                   "79cd778f8bf1a117690052cacdd54eca"),
56   std::make_tuple("1/8", "testout_420m_islow_1_8.ppm",
57                   "391b3d4aca640c8567d6f8745eb2142f")
58 };
59 
60 class DJPEGTestScalingDCT : public
61   ::testing::TestWithParam<std::tuple<const std::string,
62                                       const std::string,
63                                       const std::string>> {};
64 
TEST_P(DJPEGTestScalingDCT,Test)65 TEST_P(DJPEGTestScalingDCT, Test) {
66 
67   base::FilePath input_image_path;
68   GetTestFilePath(&input_image_path, "testorig.jpg");
69   base::FilePath output_path(GetTargetDirectory());
70   output_path = output_path.AppendASCII(std::get<1>(GetParam()));
71 
72   std::string prog_name = "djpeg";
73   std::string arg1 = "-dct";
74   std::string arg2 = "int";
75   std::string arg3 = "-scale";
76   std::string arg4 = std::get<0>(GetParam());
77   std::string arg5 = "-nosmooth";
78   std::string arg6 = "-ppm";
79   std::string arg7 = "-outfile";
80   std::string arg8 = output_path.MaybeAsASCII();
81   std::string arg9 = input_image_path.MaybeAsASCII();
82 
83   char *command_line[] = { &prog_name[0],
84                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
85                            &arg6[0], &arg7[0], &arg8[0], &arg9[0]
86                          };
87   // Generate test image file.
88   EXPECT_EQ(djpeg(10, command_line), 0);
89 
90   // Compare expected MD5 sum against that of test image.
91   EXPECT_TRUE(CompareFileAndMD5(output_path, std::get<2>(GetParam())));
92 }
93 
94 INSTANTIATE_TEST_SUITE_P(TestScalingDCT,
95                          DJPEGTestScalingDCT,
96                          ::testing::ValuesIn(SCALE_IMAGE_MD5));
97 
TEST(DJPEGTest,ISlow420256)98 TEST(DJPEGTest, ISlow420256) {
99 
100   base::FilePath input_image_path;
101   GetTestFilePath(&input_image_path, "testorig.jpg");
102   base::FilePath output_path(GetTargetDirectory());
103   output_path = output_path.AppendASCII("testout_420_islow_256.bmp");
104 
105   std::string prog_name = "djpeg";
106   std::string arg1 = "-dct";
107   std::string arg2 = "int";
108   std::string arg3 = "-colors";
109   std::string arg4 = "256";
110   std::string arg5 = "-bmp";
111   std::string arg6 = "-outfile";
112   std::string arg7 = output_path.MaybeAsASCII();
113   std::string arg8 = input_image_path.MaybeAsASCII();
114 
115   char *command_line[] = { &prog_name[0],
116                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
117                            &arg6[0], &arg7[0], &arg8[0]
118                          };
119   // Generate test image file.
120   EXPECT_EQ(djpeg(9, command_line), 0);
121 
122   // Compare expected MD5 sum against that of test image.
123   const std::string EXPECTED_MD5 = "4980185e3776e89bd931736e1cddeee6";
124   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
125 }
126 
TEST(DJPEGTest,ISlow420565)127 TEST(DJPEGTest, ISlow420565) {
128 
129   base::FilePath input_image_path;
130   GetTestFilePath(&input_image_path, "testorig.jpg");
131   base::FilePath output_path(GetTargetDirectory());
132   output_path = output_path.AppendASCII("testout_420_islow_565.bmp");
133 
134   std::string prog_name = "djpeg";
135   std::string arg1 = "-dct";
136   std::string arg2 = "int";
137   std::string arg3 = "-rgb565";
138   std::string arg4 = "-dither";
139   std::string arg5 = "none";
140   std::string arg6 = "-bmp";
141   std::string arg7 = "-outfile";
142   std::string arg8 = output_path.MaybeAsASCII();
143   std::string arg9 = input_image_path.MaybeAsASCII();
144 
145   char *command_line[] = { &prog_name[0],
146                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
147                            &arg6[0], &arg7[0], &arg8[0], &arg9[0]
148                          };
149   // Generate test image file.
150   EXPECT_EQ(djpeg(10, command_line), 0);
151 
152   // Compare expected MD5 sum against that of test image.
153   const std::string EXPECTED_MD5 = "bf9d13e16c4923b92e1faa604d7922cb";
154   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
155 }
156 
TEST(DJPEGTest,ISlow420565D)157 TEST(DJPEGTest, ISlow420565D) {
158 
159   base::FilePath input_image_path;
160   GetTestFilePath(&input_image_path, "testorig.jpg");
161   base::FilePath output_path(GetTargetDirectory());
162   output_path = output_path.AppendASCII("testout_420_islow_565D.bmp");
163 
164   std::string prog_name = "djpeg";
165   std::string arg1 = "-dct";
166   std::string arg2 = "int";
167   std::string arg3 = "-rgb565";
168   std::string arg4 = "-bmp";
169   std::string arg5 = "-outfile";
170   std::string arg6 = output_path.MaybeAsASCII();
171   std::string arg7 = input_image_path.MaybeAsASCII();
172 
173   char *command_line[] = { &prog_name[0],
174                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
175                            &arg6[0], &arg7[0]
176                          };
177   // Generate test image file.
178   EXPECT_EQ(djpeg(8, command_line), 0);
179 
180   // Compare expected MD5 sum against that of test image.
181   const std::string EXPECTED_MD5 = "6bde71526acc44bcff76f696df8638d2";
182   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
183 }
184 
TEST(DJPEGTest,ISlow420M565)185 TEST(DJPEGTest, ISlow420M565) {
186 
187   base::FilePath input_image_path;
188   GetTestFilePath(&input_image_path, "testorig.jpg");
189   base::FilePath output_path(GetTargetDirectory());
190   output_path = output_path.AppendASCII("testout_420m_islow_565.bmp");
191 
192   std::string prog_name = "djpeg";
193   std::string arg1 = "-dct";
194   std::string arg2 = "int";
195   std::string arg3 = "-nosmooth";
196   std::string arg4 = "-rgb565";
197   std::string arg5 = "-dither";
198   std::string arg6 = "none";
199   std::string arg7 = "-bmp";
200   std::string arg8 = "-outfile";
201   std::string arg9 = output_path.MaybeAsASCII();
202   std::string arg10 = input_image_path.MaybeAsASCII();
203 
204   char *command_line[] = { &prog_name[0],
205                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
206                            &arg6[0], &arg7[0], &arg8[0], &arg9[0], &arg10[0]
207                          };
208   // Generate test image file.
209   EXPECT_EQ(djpeg(11, command_line), 0);
210 
211   // Compare expected MD5 sum against that of test image.
212   const std::string EXPECTED_MD5 = "8dc0185245353cfa32ad97027342216f";
213   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
214 }
215 
TEST(DJPEGTest,ISlow420M565D)216 TEST(DJPEGTest, ISlow420M565D) {
217 
218   base::FilePath input_image_path;
219   GetTestFilePath(&input_image_path, "testorig.jpg");
220   base::FilePath output_path(GetTargetDirectory());
221   output_path = output_path.AppendASCII("testout_420m_islow_565D.bmp");
222 
223   std::string prog_name = "djpeg";
224   std::string arg1 = "-dct";
225   std::string arg2 = "int";
226   std::string arg3 = "-nosmooth";
227   std::string arg4 = "-rgb565";
228   std::string arg5 = "-bmp";
229   std::string arg6 = "-outfile";
230   std::string arg7 = output_path.MaybeAsASCII();
231   std::string arg8 = input_image_path.MaybeAsASCII();
232 
233   char *command_line[] = { &prog_name[0],
234                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
235                            &arg6[0], &arg7[0], &arg8[0]
236                          };
237   // Generate test image file.
238   EXPECT_EQ(djpeg(9, command_line), 0);
239 
240   // Compare expected MD5 sum against that of test image.
241   const std::string EXPECTED_MD5 = "ce034037d212bc403330df6f915c161b";
242   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
243 }
244 
TEST(DJPEGTest,ISlow420Skip1531)245 TEST(DJPEGTest, ISlow420Skip1531) {
246 
247   base::FilePath input_image_path;
248   GetTestFilePath(&input_image_path, "testorig.jpg");
249   base::FilePath output_path(GetTargetDirectory());
250   output_path = output_path.AppendASCII("testout_420_islow_skip15_31.ppm");
251 
252   std::string prog_name = "djpeg";
253   std::string arg1 = "-dct";
254   std::string arg2 = "int";
255   std::string arg3 = "-skip";
256   std::string arg4 = "15,31";
257   std::string arg5 = "-ppm";
258   std::string arg6 = "-outfile";
259   std::string arg7 = output_path.MaybeAsASCII();
260   std::string arg8 = 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], &arg7[0], &arg8[0]
265                          };
266   // Generate test image file.
267   EXPECT_EQ(djpeg(9, command_line), 0);
268 
269   // Compare expected MD5 sum against that of test image.
270   const std::string EXPECTED_MD5 = "c4c65c1e43d7275cd50328a61e6534f0";
271   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
272 }
273 
274 #ifdef C_ARITH_CODING_SUPPORTED
TEST(DJPEGTest,ISlow420AriSkip16139)275 TEST(DJPEGTest, ISlow420AriSkip16139) {
276 
277   base::FilePath input_image_path;
278   GetTestFilePath(&input_image_path, "testimgari.jpg");
279   base::FilePath output_path(GetTargetDirectory());
280   output_path = output_path.AppendASCII(
281                               "testout_420_islow_ari_skip16_139.ppm");
282 
283   std::string prog_name = "djpeg";
284   std::string arg1 = "-dct";
285   std::string arg2 = "int";
286   std::string arg3 = "-skip";
287   std::string arg4 = "16,139";
288   std::string arg5 = "-ppm";
289   std::string arg6 = "-outfile";
290   std::string arg7 = output_path.MaybeAsASCII();
291   std::string arg8 = input_image_path.MaybeAsASCII();
292 
293   char *command_line[] = { &prog_name[0],
294                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
295                            &arg6[0], &arg7[0], &arg8[0]
296                          };
297   // Generate test image file.
298   EXPECT_EQ(djpeg(9, command_line), 0);
299 
300   // Compare expected MD5 sum against that of test image.
301   const std::string EXPECTED_MD5 = "087c6b123db16ac00cb88c5b590bb74a";
302   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
303 }
304 
TEST(DJPEGTest,ISlow420AriCrop53x5344)305 TEST(DJPEGTest, ISlow420AriCrop53x5344) {
306 
307   base::FilePath input_image_path;
308   GetTestFilePath(&input_image_path, "testimgari.jpg");
309   base::FilePath output_path(GetTargetDirectory());
310   output_path = output_path.AppendASCII(
311                               "testout_420_islow_ari_crop53x53_4_4.ppm");
312 
313   std::string prog_name = "djpeg";
314   std::string arg1 = "-dct";
315   std::string arg2 = "int";
316   std::string arg3 = "-crop";
317   std::string arg4 = "53x53+4+4";
318   std::string arg5 = "-ppm";
319   std::string arg6 = "-outfile";
320   std::string arg7 = output_path.MaybeAsASCII();
321   std::string arg8 = input_image_path.MaybeAsASCII();
322 
323   char *command_line[] = { &prog_name[0],
324                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
325                            &arg6[0], &arg7[0], &arg8[0]
326                          };
327   // Generate test image file.
328   EXPECT_EQ(djpeg(9, command_line), 0);
329 
330   // Compare expected MD5 sum against that of test image.
331   const std::string EXPECTED_MD5 = "886c6775af22370257122f8b16207e6d";
332   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
333 }
334 
TEST(DJPEGTest,IFast420MAri)335 TEST(DJPEGTest, IFast420MAri) {
336 
337   base::FilePath input_image_path;
338   GetTestFilePath(&input_image_path, "testimgari.jpg");
339   base::FilePath output_path(GetTargetDirectory());
340   output_path = output_path.AppendASCII("testout_420m_ifast_ari.ppm");
341 
342   std::string prog_name = "djpeg";
343   std::string arg1 = "-fast";
344   std::string arg2 = "-ppm";
345   std::string arg3 = "-outfile";
346   std::string arg4 = output_path.MaybeAsASCII();
347   std::string arg5 = input_image_path.MaybeAsASCII();
348 
349   char *command_line[] = { &prog_name[0],
350                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0]
351                          };
352   // Generate test image file.
353   EXPECT_EQ(djpeg(6, command_line), 0);
354 
355   // Compare expected MD5 sum against that of test image.
356   const std::string EXPECTED_MD5 = "72b59a99bcf1de24c5b27d151bde2437";
357   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
358 }
359 
TEST(DJPEGTest,ISlow444AriCrop37x3700)360 TEST(DJPEGTest, ISlow444AriCrop37x3700) {
361 
362   base::FilePath input_image_path;
363   GetTestFilePath(&input_image_path, "testout_444_islow_ari.jpg");
364   base::FilePath output_path(GetTargetDirectory());
365   output_path = output_path.AppendASCII(
366                               "testout_444_islow_ari_crop37x37_0_0.ppm");
367 
368   std::string prog_name = "djpeg";
369   std::string arg1 = "-dct";
370   std::string arg2 = "int";
371   std::string arg3 = "-crop";
372   std::string arg4 = "37x37+0+0";
373   std::string arg5 = "-ppm";
374   std::string arg6 = "-outfile";
375   std::string arg7 = output_path.MaybeAsASCII();
376   std::string arg8 = input_image_path.MaybeAsASCII();
377 
378   char *command_line[] = { &prog_name[0],
379                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
380                            &arg6[0], &arg7[0], &arg8[0]
381                          };
382   // Generate test image file.
383   EXPECT_EQ(djpeg(9, command_line), 0);
384 
385   // Compare expected MD5 sum against that of test image.
386   const std::string EXPECTED_MD5 = "cb57b32bd6d03e35432362f7bf184b6d";
387   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
388 }
389 #endif
390 
TEST(DJPEGTest,RGBISlow)391 TEST(DJPEGTest, RGBISlow) {
392 
393   base::FilePath input_image_path;
394   GetTestFilePath(&input_image_path, "testout_rgb_islow.jpg");
395   base::FilePath output_path(GetTargetDirectory());
396   output_path = output_path.AppendASCII("testout_rgb_islow.ppm");
397   base::FilePath output_icc_path(GetTargetDirectory());
398   output_icc_path = output_icc_path.AppendASCII("testout_rgb_islow.icc");
399 
400   std::string prog_name = "djpeg";
401   std::string arg1 = "-dct";
402   std::string arg2 = "int";
403   std::string arg3 = "-ppm";
404   std::string arg4 = "-icc";
405   std::string arg5 = output_icc_path.MaybeAsASCII();
406   std::string arg6 = "-outfile";
407   std::string arg7 = output_path.MaybeAsASCII();
408   std::string arg8 = input_image_path.MaybeAsASCII();
409 
410   char *command_line[] = { &prog_name[0],
411                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
412                            &arg6[0], &arg7[0], &arg8[0]
413                          };
414   // Generate test image file.
415   EXPECT_EQ(djpeg(9, command_line), 0);
416 
417   // Compare expected MD5 sum against that of test image.
418   const std::string EXPECTED_MD5 = "00a257f5393fef8821f2b88ac7421291";
419   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
420   const std::string ICC_EXPECTED_MD5 = "b06a39d730129122e85c1363ed1bbc9e";
421   EXPECT_TRUE(CompareFileAndMD5(output_icc_path, ICC_EXPECTED_MD5));
422 }
423 
TEST(DJPEGTest,RGBISlow565)424 TEST(DJPEGTest, RGBISlow565) {
425 
426   base::FilePath input_image_path;
427   GetTestFilePath(&input_image_path, "testout_rgb_islow.jpg");
428   base::FilePath output_path(GetTargetDirectory());
429   output_path = output_path.AppendASCII("testout_rgb_islow_565.bmp");
430 
431   std::string prog_name = "djpeg";
432   std::string arg1 = "-dct";
433   std::string arg2 = "int";
434   std::string arg3 = "-rgb565";
435   std::string arg4 = "-dither";
436   std::string arg5 = "none";
437   std::string arg6 = "-bmp";
438   std::string arg7 = "-outfile";
439   std::string arg8 = output_path.MaybeAsASCII();
440   std::string arg9 = input_image_path.MaybeAsASCII();
441 
442   char *command_line[] = { &prog_name[0],
443                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
444                            &arg6[0], &arg7[0], &arg8[0], &arg9[0]
445                          };
446   // Generate test image file.
447   EXPECT_EQ(djpeg(10, command_line), 0);
448 
449   // Compare expected MD5 sum against that of test image.
450   const std::string EXPECTED_MD5 = "f07d2e75073e4bb10f6c6f4d36e2e3be";
451   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
452 }
453 
TEST(DJPEGTest,RGBISlow565D)454 TEST(DJPEGTest, RGBISlow565D) {
455 
456   base::FilePath input_image_path;
457   GetTestFilePath(&input_image_path, "testout_rgb_islow.jpg");
458   base::FilePath output_path(GetTargetDirectory());
459   output_path = output_path.AppendASCII("testout_rgb_islow_565D.bmp");
460 
461   std::string prog_name = "djpeg";
462   std::string arg1 = "-dct";
463   std::string arg2 = "int";
464   std::string arg3 = "-rgb565";
465   std::string arg4 = "-bmp";
466   std::string arg5 = "-outfile";
467   std::string arg6 = output_path.MaybeAsASCII();
468   std::string arg7 = input_image_path.MaybeAsASCII();
469 
470   char *command_line[] = { &prog_name[0],
471                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
472                            &arg6[0], &arg7[0]
473                          };
474   // Generate test image file.
475   EXPECT_EQ(djpeg(8, command_line), 0);
476 
477   // Compare expected MD5 sum against that of test image.
478   const std::string EXPECTED_MD5 = "4cfa0928ef3e6bb626d7728c924cfda4";
479   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
480 }
481 
TEST(DJPEGTest,IFast422)482 TEST(DJPEGTest, IFast422) {
483 
484   base::FilePath input_image_path;
485   GetTestFilePath(&input_image_path, "testout_422_ifast_opt.jpg");
486   base::FilePath output_path(GetTargetDirectory());
487   output_path = output_path.AppendASCII("testout_422_ifast.ppm");
488 
489   std::string prog_name = "djpeg";
490   std::string arg1 = "-dct";
491   std::string arg2 = "fast";
492   std::string arg3 = "-outfile";
493   std::string arg4 = output_path.MaybeAsASCII();
494   std::string arg5 = input_image_path.MaybeAsASCII();
495 
496   char *command_line[] = { &prog_name[0],
497                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0]
498                          };
499   // Generate test image file.
500   EXPECT_EQ(djpeg(6, command_line), 0);
501 
502   // Compare expected MD5 sum against that of test image.
503   const std::string EXPECTED_MD5 = "35bd6b3f833bad23de82acea847129fa";
504   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
505 }
506 
TEST(DJPEGTest,IFast422M)507 TEST(DJPEGTest, IFast422M) {
508 
509   base::FilePath input_image_path;
510   GetTestFilePath(&input_image_path, "testout_422_ifast_opt.jpg");
511   base::FilePath output_path(GetTargetDirectory());
512   output_path = output_path.AppendASCII("testout_422m_ifast.ppm");
513 
514   std::string prog_name = "djpeg";
515   std::string arg1 = "-dct";
516   std::string arg2 = "fast";
517   std::string arg3 = "-nosmooth";
518   std::string arg4 = "-outfile";
519   std::string arg5 = output_path.MaybeAsASCII();
520   std::string arg6 = input_image_path.MaybeAsASCII();
521 
522   char *command_line[] = { &prog_name[0],
523                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
524                            &arg6[0]
525                          };
526   // Generate test image file.
527   EXPECT_EQ(djpeg(7, command_line), 0);
528 
529   // Compare expected MD5 sum against that of test image.
530   const std::string EXPECTED_MD5 = "8dbc65323d62cca7c91ba02dd1cfa81d";
531   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
532 }
533 
TEST(DJPEGTest,IFast422M565)534 TEST(DJPEGTest, IFast422M565) {
535 
536   base::FilePath input_image_path;
537   GetTestFilePath(&input_image_path, "testout_422_ifast_opt.jpg");
538   base::FilePath output_path(GetTargetDirectory());
539   output_path = output_path.AppendASCII("testout_422m_ifast_565.bmp");
540 
541   std::string prog_name = "djpeg";
542   std::string arg1 = "-dct";
543   std::string arg2 = "int";
544   std::string arg3 = "-nosmooth";
545   std::string arg4 = "-rgb565";
546   std::string arg5 = "-dither";
547   std::string arg6 = "none";
548   std::string arg7 = "-bmp";
549   std::string arg8 = "-outfile";
550   std::string arg9 = output_path.MaybeAsASCII();
551   std::string arg10 = input_image_path.MaybeAsASCII();
552 
553   char *command_line[] = { &prog_name[0],
554                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
555                            &arg6[0], &arg7[0], &arg8[0], &arg9[0], &arg10[0]
556                          };
557   // Generate test image file.
558   EXPECT_EQ(djpeg(11, command_line), 0);
559 
560   // Compare expected MD5 sum against that of test image.
561   const std::string EXPECTED_MD5 = "3294bd4d9a1f2b3d08ea6020d0db7065";
562   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
563 }
564 
TEST(DJPEGTest,IFast422M565D)565 TEST(DJPEGTest, IFast422M565D) {
566 
567   base::FilePath input_image_path;
568   GetTestFilePath(&input_image_path, "testout_422_ifast_opt.jpg");
569   base::FilePath output_path(GetTargetDirectory());
570   output_path = output_path.AppendASCII("testout_422m_ifast_565D.bmp");
571 
572   std::string prog_name = "djpeg";
573   std::string arg1 = "-dct";
574   std::string arg2 = "int";
575   std::string arg3 = "-nosmooth";
576   std::string arg4 = "-rgb565";
577   std::string arg5 = "-bmp";
578   std::string arg6 = "-outfile";
579   std::string arg7 = output_path.MaybeAsASCII();
580   std::string arg8 = input_image_path.MaybeAsASCII();
581 
582   char *command_line[] = { &prog_name[0],
583                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
584                            &arg6[0], &arg7[0], &arg8[0]
585                          };
586   // Generate test image file.
587   EXPECT_EQ(djpeg(9, command_line), 0);
588 
589   // Compare expected MD5 sum against that of test image.
590   const std::string EXPECTED_MD5 = "da98c9c7b6039511be4a79a878a9abc1";
591   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
592 }
593 
TEST(DJPEGTest,IFastProg420Q100)594 TEST(DJPEGTest, IFastProg420Q100) {
595 
596   base::FilePath input_image_path;
597   GetTestFilePath(&input_image_path, "testout_420_q100_ifast_prog.jpg");
598   base::FilePath output_path(GetTargetDirectory());
599   output_path = output_path.AppendASCII("testout_420_q100_ifast.ppm");
600 
601   std::string prog_name = "djpeg";
602   std::string arg1 = "-dct";
603   std::string arg2 = "fast";
604   std::string arg3 = "-outfile";
605   std::string arg4 = output_path.MaybeAsASCII();
606   std::string arg5 = input_image_path.MaybeAsASCII();
607 
608   char *command_line[] = { &prog_name[0],
609                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0]
610                          };
611   // Generate test image file.
612   EXPECT_EQ(djpeg(6, command_line), 0);
613 
614   // Compare expected MD5 sum against that of test image.
615   const std::string EXPECTED_MD5 = "5a732542015c278ff43635e473a8a294";
616   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
617 }
618 
TEST(DJPEGTest,IFastProg420MQ100)619 TEST(DJPEGTest, IFastProg420MQ100) {
620 
621   base::FilePath input_image_path;
622   GetTestFilePath(&input_image_path, "testout_420_q100_ifast_prog.jpg");
623   base::FilePath output_path(GetTargetDirectory());
624   output_path = output_path.AppendASCII("testout_420m_q100_ifast.ppm");
625 
626   std::string prog_name = "djpeg";
627   std::string arg1 = "-dct";
628   std::string arg2 = "fast";
629   std::string arg3 = "-nosmooth";
630   std::string arg4 = "-outfile";
631   std::string arg5 = output_path.MaybeAsASCII();
632   std::string arg6 = input_image_path.MaybeAsASCII();
633 
634   char *command_line[] = { &prog_name[0],
635                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
636                            &arg6[0]
637                          };
638   // Generate test image file.
639   EXPECT_EQ(djpeg(7, command_line), 0);
640 
641   // Compare expected MD5 sum against that of test image.
642   const std::string EXPECTED_MD5 = "ff692ee9323a3b424894862557c092f1";
643   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
644 }
645 
TEST(DJPEGTest,GrayISlow)646 TEST(DJPEGTest, GrayISlow) {
647 
648   base::FilePath input_image_path;
649   GetTestFilePath(&input_image_path, "testout_gray_islow.jpg");
650   base::FilePath output_path(GetTargetDirectory());
651   output_path = output_path.AppendASCII("testout_gray_islow.ppm");
652 
653   std::string prog_name = "djpeg";
654   std::string arg1 = "-dct";
655   std::string arg2 = "int";
656   std::string arg3 = "-outfile";
657   std::string arg4 = output_path.MaybeAsASCII();
658   std::string arg5 = input_image_path.MaybeAsASCII();
659 
660   char *command_line[] = { &prog_name[0],
661                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0]
662                          };
663   // Generate test image file.
664   EXPECT_EQ(djpeg(6, command_line), 0);
665 
666   // Compare expected MD5 sum against that of test image.
667   const std::string EXPECTED_MD5 = "8d3596c56eace32f205deccc229aa5ed";
668   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
669 }
670 
TEST(DJPEGTest,GrayISlowRGB)671 TEST(DJPEGTest, GrayISlowRGB) {
672 
673   base::FilePath input_image_path;
674   GetTestFilePath(&input_image_path, "testout_gray_islow.jpg");
675   base::FilePath output_path(GetTargetDirectory());
676   output_path = output_path.AppendASCII("testout_gray_islow_rgb.ppm");
677 
678   std::string prog_name = "djpeg";
679   std::string arg1 = "-dct";
680   std::string arg2 = "int";
681   std::string arg3 = "-rgb";
682   std::string arg4 = "-outfile";
683   std::string arg5 = output_path.MaybeAsASCII();
684   std::string arg6 = input_image_path.MaybeAsASCII();
685 
686   char *command_line[] = { &prog_name[0],
687                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
688                            &arg6[0]
689                          };
690   // Generate test image file.
691   EXPECT_EQ(djpeg(7, command_line), 0);
692 
693   // Compare expected MD5 sum against that of test image.
694   const std::string EXPECTED_MD5 = "116424ac07b79e5e801f00508eab48ec";
695   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
696 }
697 
TEST(DJPEGTest,GrayISlow565)698 TEST(DJPEGTest, GrayISlow565) {
699 
700   base::FilePath input_image_path;
701   GetTestFilePath(&input_image_path, "testout_gray_islow.jpg");
702   base::FilePath output_path(GetTargetDirectory());
703   output_path = output_path.AppendASCII("testout_gray_islow_565.bmp");
704 
705   std::string prog_name = "djpeg";
706   std::string arg1 = "-dct";
707   std::string arg2 = "int";
708   std::string arg3 = "-rgb565";
709   std::string arg4 = "-dither";
710   std::string arg5 = "none";
711   std::string arg6 = "-bmp";
712   std::string arg7 = "-outfile";
713   std::string arg8 = output_path.MaybeAsASCII();
714   std::string arg9 = input_image_path.MaybeAsASCII();
715 
716   char *command_line[] = { &prog_name[0],
717                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
718                            &arg6[0], &arg7[0], &arg8[0], &arg9[0]
719                          };
720   // Generate test image file.
721   EXPECT_EQ(djpeg(10, command_line), 0);
722 
723   // Compare expected MD5 sum against that of test image.
724   const std::string EXPECTED_MD5 = "12f78118e56a2f48b966f792fedf23cc";
725   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
726 }
727 
TEST(DJPEGTest,GrayISlow565D)728 TEST(DJPEGTest, GrayISlow565D) {
729 
730   base::FilePath input_image_path;
731   GetTestFilePath(&input_image_path, "testout_gray_islow.jpg");
732   base::FilePath output_path(GetTargetDirectory());
733   output_path = output_path.AppendASCII("testout_gray_islow_565D.bmp");
734 
735   std::string prog_name = "djpeg";
736   std::string arg1 = "-dct";
737   std::string arg2 = "int";
738   std::string arg3 = "-rgb565";
739   std::string arg4 = "-bmp";
740   std::string arg5 = "-outfile";
741   std::string arg6 = output_path.MaybeAsASCII();
742   std::string arg7 = input_image_path.MaybeAsASCII();
743 
744   char *command_line[] = { &prog_name[0],
745                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
746                            &arg6[0], &arg7[0]
747                          };
748   // Generate test image file.
749   EXPECT_EQ(djpeg(8, command_line), 0);
750 
751   // Compare expected MD5 sum against that of test image.
752   const std::string EXPECTED_MD5 = "bdbbd616441a24354c98553df5dc82db";
753   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
754 }
755 
TEST(DJPEGTest,FloatProg3x2)756 TEST(DJPEGTest, FloatProg3x2) {
757 
758   base::FilePath input_image_path;
759 #if defined(WITH_SIMD) && (defined(__i386__) || defined(__x86_64__))
760   GetTestFilePath(&input_image_path, "testout_3x2_float_prog_sse.jpg");
761 #else
762   GetTestFilePath(&input_image_path, "testout_3x2_float_prog.jpg");
763 #endif
764   base::FilePath output_path(GetTargetDirectory());
765   output_path = output_path.AppendASCII("testout_3x2_float.ppm");
766 
767   std::string prog_name = "djpeg";
768   std::string arg1 = "-dct";
769   std::string arg2 = "float";
770   std::string arg3 = "-outfile";
771   std::string arg4 = output_path.MaybeAsASCII();
772   std::string arg5 = input_image_path.MaybeAsASCII();
773 
774   char *command_line[] = { &prog_name[0],
775                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0]
776                          };
777   // Generate test image file.
778   EXPECT_EQ(djpeg(6, command_line), 0);
779 
780   // Compare expected MD5 sum against that of test image.
781 #if defined(WITH_SIMD) && (defined(__i386__) || defined(__x86_64__))
782   const std::string EXPECTED_MD5 = "1a75f36e5904d6fc3a85a43da9ad89bb";
783 #else
784   const std::string EXPECTED_MD5 = "f6bfab038438ed8f5522fbd33595dcdc";
785 #endif
786   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
787 }
788 
TEST(DJPEGTest,IFastProg3x2)789 TEST(DJPEGTest, IFastProg3x2) {
790 
791   base::FilePath input_image_path;
792   GetTestFilePath(&input_image_path, "testout_3x2_ifast_prog.jpg");
793   base::FilePath output_path(GetTargetDirectory());
794   output_path = output_path.AppendASCII("testout_3x2_ifast.ppm");
795 
796   std::string prog_name = "djpeg";
797   std::string arg1 = "-dct";
798   std::string arg2 = "fast";
799   std::string arg3 = "-outfile";
800   std::string arg4 = output_path.MaybeAsASCII();
801   std::string arg5 = input_image_path.MaybeAsASCII();
802 
803   char *command_line[] = { &prog_name[0],
804                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0]
805                          };
806   // Generate test image file.
807   EXPECT_EQ(djpeg(6, command_line), 0);
808 
809   // Compare expected MD5 sum against that of test image.
810   const std::string EXPECTED_MD5 = "fd283664b3b49127984af0a7f118fccd";
811   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
812 }
813 
TEST(DJPEGTest,ISlowProgCrop62x627171)814 TEST(DJPEGTest, ISlowProgCrop62x627171) {
815 
816   base::FilePath input_image_path;
817   GetTestFilePath(&input_image_path, "testout_420_islow_prog.jpg");
818   base::FilePath output_path(GetTargetDirectory());
819   output_path = output_path.AppendASCII(
820                               "testout_420_islow_prog_crop62x62_71_71.ppm");
821 
822   std::string prog_name = "djpeg";
823   std::string arg1 = "-dct";
824   std::string arg2 = "int";
825   std::string arg3 = "-crop";
826   std::string arg4 = "62x62+71+71";
827   std::string arg5 = "-ppm";
828   std::string arg6 = "-outfile";
829   std::string arg7 = output_path.MaybeAsASCII();
830   std::string arg8 = input_image_path.MaybeAsASCII();
831 
832   char *command_line[] = { &prog_name[0],
833                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
834                            &arg6[0], &arg7[0], &arg8[0]
835                          };
836   // Generate test image file.
837   EXPECT_EQ(djpeg(9, command_line), 0);
838 
839   // Compare expected MD5 sum against that of test image.
840   const std::string EXPECTED_MD5 = "26eb36ccc7d1f0cb80cdabb0ac8b5d99";
841   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
842 }
843 
TEST(DJPEGTest,ISlow444Skip16)844 TEST(DJPEGTest, ISlow444Skip16) {
845 
846   base::FilePath input_image_path;
847   GetTestFilePath(&input_image_path, "testout_444_islow.jpg");
848   base::FilePath output_path(GetTargetDirectory());
849   output_path = output_path.AppendASCII("testout_444_islow_skip1_6.ppm");
850 
851   std::string prog_name = "djpeg";
852   std::string arg1 = "-dct";
853   std::string arg2 = "int";
854   std::string arg3 = "-skip";
855   std::string arg4 = "1,6";
856   std::string arg5 = "-ppm";
857   std::string arg6 = "-outfile";
858   std::string arg7 = output_path.MaybeAsASCII();
859   std::string arg8 = input_image_path.MaybeAsASCII();
860 
861   char *command_line[] = { &prog_name[0],
862                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
863                            &arg6[0], &arg7[0], &arg8[0]
864                          };
865   // Generate test image file.
866   EXPECT_EQ(djpeg(9, command_line), 0);
867 
868   // Compare expected MD5 sum against that of test image.
869   const std::string EXPECTED_MD5 = "5606f86874cf26b8fcee1117a0a436a6";
870   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
871 }
872 
TEST(DJPEGTest,ISlowProg444Crop98x981313)873 TEST(DJPEGTest, ISlowProg444Crop98x981313) {
874 
875   base::FilePath input_image_path;
876   GetTestFilePath(&input_image_path, "testout_444_islow_prog.jpg");
877   base::FilePath output_path(GetTargetDirectory());
878   output_path = output_path.AppendASCII(
879                               "testout_444_islow_prog_crop98x98_13_13.ppm");
880 
881   std::string prog_name = "djpeg";
882   std::string arg1 = "-dct";
883   std::string arg2 = "int";
884   std::string arg3 = "-crop";
885   std::string arg4 = "98x98+13+13";
886   std::string arg5 = "-ppm";
887   std::string arg6 = "-outfile";
888   std::string arg7 = output_path.MaybeAsASCII();
889   std::string arg8 = input_image_path.MaybeAsASCII();
890 
891   char *command_line[] = { &prog_name[0],
892                            &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
893                            &arg6[0], &arg7[0], &arg8[0]
894                          };
895   // Generate test image file.
896   EXPECT_EQ(djpeg(9, command_line), 0);
897 
898   // Compare expected MD5 sum against that of test image.
899   const std::string EXPECTED_MD5 = "db87dc7ce26bcdc7a6b56239ce2b9d6c";
900   EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
901 }
902