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 jpegtran(int argc, char *argv[]);
30
TEST(JPEGTranTest,ICC)31 TEST(JPEGTranTest, ICC) {
32
33 base::FilePath input_image_path;
34 GetTestFilePath(&input_image_path, "testout_rgb_islow.jpg");
35 base::FilePath icc_path;
36 GetTestFilePath(&icc_path, "test2.icc");
37 base::FilePath output_path(GetTargetDirectory());
38 output_path = output_path.AppendASCII("testout_rgb_islow2.jpg");
39
40 std::string prog_name = "jpegtran";
41 std::string arg1 = "-copy";
42 std::string arg2 = "all";
43 std::string arg3 = "-icc";
44 std::string arg4 = icc_path.MaybeAsASCII();
45 std::string arg5 = "-outfile";
46 std::string arg6 = output_path.MaybeAsASCII();
47 std::string arg7 = input_image_path.MaybeAsASCII();
48
49 char *command_line[] = { &prog_name[0],
50 &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
51 &arg6[0], &arg7[0]
52 };
53 // Generate test image file.
54 EXPECT_EQ(jpegtran(8, command_line), 0);
55
56 // Compare expected MD5 sum against that of test image.
57 const std::string EXPECTED_MD5 = "31d121e57b6c2934c890a7fc7763bcd4";
58 EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
59 }
60
TEST(JPEGTranTest,Crop)61 TEST(JPEGTranTest, Crop) {
62
63 base::FilePath input_image_path;
64 GetTestFilePath(&input_image_path, "testorig.jpg");
65 base::FilePath output_path(GetTargetDirectory());
66 output_path = output_path.AppendASCII("testout_crop.jpg");
67
68 std::string prog_name = "jpegtran";
69 std::string arg1 = "-crop";
70 std::string arg2 = "120x90+20+50";
71 std::string arg3 = "-transpose";
72 std::string arg4 = "-perfect";
73 std::string arg5 = "-outfile";
74 std::string arg6 = output_path.MaybeAsASCII();
75 std::string arg7 = input_image_path.MaybeAsASCII();
76
77 char *command_line[] = { &prog_name[0],
78 &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
79 &arg6[0], &arg7[0]
80 };
81 // Generate test image file.
82 EXPECT_EQ(jpegtran(8, command_line), 0);
83
84 // Compare expected MD5 sum against that of test image.
85 const std::string EXPECTED_MD5 = "b4197f377e621c4e9b1d20471432610d";
86 EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
87 }
88
89 #ifdef C_ARITH_CODING_SUPPORTED
TEST(JPEGTranTest,ISlow420Ari)90 TEST(JPEGTranTest, ISlow420Ari) {
91
92 base::FilePath input_image_path;
93 GetTestFilePath(&input_image_path, "testimgint.jpg");
94 base::FilePath output_path(GetTargetDirectory());
95 output_path = output_path.AppendASCII("testout_420_islow_ari2.jpg");
96
97 std::string prog_name = "jpegtran";
98 std::string arg1 = "-arithmetic";
99 std::string arg2 = "-outfile";
100 std::string arg3 = output_path.MaybeAsASCII();
101 std::string arg4 = input_image_path.MaybeAsASCII();
102
103 char *command_line[] = { &prog_name[0],
104 &arg1[0], &arg2[0], &arg3[0], &arg4[0]
105 };
106 // Generate test image file.
107 EXPECT_EQ(jpegtran(5, command_line), 0);
108
109 // Compare expected MD5 sum against that of test image.
110 const std::string EXPECTED_MD5 = "e986fb0a637a8d833d96e8a6d6d84ea1";
111 EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
112 }
113
TEST(JPEGTranTest,ISlow420)114 TEST(JPEGTranTest, ISlow420) {
115
116 base::FilePath input_image_path;
117 GetTestFilePath(&input_image_path, "testimgari.jpg");
118 base::FilePath output_path(GetTargetDirectory());
119 output_path = output_path.AppendASCII("testout_420_islow.jpg");
120
121 std::string prog_name = "jpegtran";
122 std::string arg1 = "-outfile";
123 std::string arg2 = output_path.MaybeAsASCII();
124 std::string arg3 = input_image_path.MaybeAsASCII();
125
126 char *command_line[] = { &prog_name[0],
127 &arg1[0], &arg2[0], &arg3[0]
128 };
129 // Generate test image file.
130 EXPECT_EQ(jpegtran(4, command_line), 0);
131
132 // Compare expected MD5 sum against that of test image.
133 const std::string EXPECTED_MD5 = "9a68f56bc76e466aa7e52f415d0f4a5f";
134 EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
135 }
136 #endif
137