1*dfc6aa5cSAndroid Build Coastguard Worker /*
2*dfc6aa5cSAndroid Build Coastguard Worker * Copyright 2020 The Chromium Authors. All Rights Reserved.
3*dfc6aa5cSAndroid Build Coastguard Worker *
4*dfc6aa5cSAndroid Build Coastguard Worker * This software is provided 'as-is', without any express or implied
5*dfc6aa5cSAndroid Build Coastguard Worker * warranty. In no event will the authors be held liable for any damages
6*dfc6aa5cSAndroid Build Coastguard Worker * arising from the use of this software.
7*dfc6aa5cSAndroid Build Coastguard Worker *
8*dfc6aa5cSAndroid Build Coastguard Worker * Permission is granted to anyone to use this software for any purpose,
9*dfc6aa5cSAndroid Build Coastguard Worker * including commercial applications, and to alter it and redistribute it
10*dfc6aa5cSAndroid Build Coastguard Worker * freely, subject to the following restrictions:
11*dfc6aa5cSAndroid Build Coastguard Worker *
12*dfc6aa5cSAndroid Build Coastguard Worker * 1. The origin of this software must not be misrepresented; you must not
13*dfc6aa5cSAndroid Build Coastguard Worker * claim that you wrote the original software. If you use this software
14*dfc6aa5cSAndroid Build Coastguard Worker * in a product, an acknowledgment in the product documentation would be
15*dfc6aa5cSAndroid Build Coastguard Worker * appreciated but is not required.
16*dfc6aa5cSAndroid Build Coastguard Worker * 2. Altered source versions must be plainly marked as such, and must not be
17*dfc6aa5cSAndroid Build Coastguard Worker * misrepresented as being the original software.
18*dfc6aa5cSAndroid Build Coastguard Worker * 3. This notice may not be removed or altered from any source distribution.
19*dfc6aa5cSAndroid Build Coastguard Worker */
20*dfc6aa5cSAndroid Build Coastguard Worker
21*dfc6aa5cSAndroid Build Coastguard Worker #include "base/files/file.h"
22*dfc6aa5cSAndroid Build Coastguard Worker #include "base/files/file_util.h"
23*dfc6aa5cSAndroid Build Coastguard Worker #include "base/path_service.h"
24*dfc6aa5cSAndroid Build Coastguard Worker #include "gtest-utils.h"
25*dfc6aa5cSAndroid Build Coastguard Worker
26*dfc6aa5cSAndroid Build Coastguard Worker #include <gtest/gtest.h>
27*dfc6aa5cSAndroid Build Coastguard Worker #include <string>
28*dfc6aa5cSAndroid Build Coastguard Worker
29*dfc6aa5cSAndroid Build Coastguard Worker extern "C" int jpegtran(int argc, char *argv[]);
30*dfc6aa5cSAndroid Build Coastguard Worker
TEST(JPEGTranTest,ICC)31*dfc6aa5cSAndroid Build Coastguard Worker TEST(JPEGTranTest, ICC) {
32*dfc6aa5cSAndroid Build Coastguard Worker
33*dfc6aa5cSAndroid Build Coastguard Worker base::FilePath input_image_path;
34*dfc6aa5cSAndroid Build Coastguard Worker GetTestFilePath(&input_image_path, "testout_rgb_islow.jpg");
35*dfc6aa5cSAndroid Build Coastguard Worker base::FilePath icc_path;
36*dfc6aa5cSAndroid Build Coastguard Worker GetTestFilePath(&icc_path, "test2.icc");
37*dfc6aa5cSAndroid Build Coastguard Worker base::FilePath output_path(GetTargetDirectory());
38*dfc6aa5cSAndroid Build Coastguard Worker output_path = output_path.AppendASCII("testout_rgb_islow2.jpg");
39*dfc6aa5cSAndroid Build Coastguard Worker
40*dfc6aa5cSAndroid Build Coastguard Worker std::string prog_name = "jpegtran";
41*dfc6aa5cSAndroid Build Coastguard Worker std::string arg1 = "-copy";
42*dfc6aa5cSAndroid Build Coastguard Worker std::string arg2 = "all";
43*dfc6aa5cSAndroid Build Coastguard Worker std::string arg3 = "-icc";
44*dfc6aa5cSAndroid Build Coastguard Worker std::string arg4 = icc_path.MaybeAsASCII();
45*dfc6aa5cSAndroid Build Coastguard Worker std::string arg5 = "-outfile";
46*dfc6aa5cSAndroid Build Coastguard Worker std::string arg6 = output_path.MaybeAsASCII();
47*dfc6aa5cSAndroid Build Coastguard Worker std::string arg7 = input_image_path.MaybeAsASCII();
48*dfc6aa5cSAndroid Build Coastguard Worker
49*dfc6aa5cSAndroid Build Coastguard Worker char *command_line[] = { &prog_name[0],
50*dfc6aa5cSAndroid Build Coastguard Worker &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
51*dfc6aa5cSAndroid Build Coastguard Worker &arg6[0], &arg7[0]
52*dfc6aa5cSAndroid Build Coastguard Worker };
53*dfc6aa5cSAndroid Build Coastguard Worker // Generate test image file.
54*dfc6aa5cSAndroid Build Coastguard Worker EXPECT_EQ(jpegtran(8, command_line), 0);
55*dfc6aa5cSAndroid Build Coastguard Worker
56*dfc6aa5cSAndroid Build Coastguard Worker // Compare expected MD5 sum against that of test image.
57*dfc6aa5cSAndroid Build Coastguard Worker const std::string EXPECTED_MD5 = "31d121e57b6c2934c890a7fc7763bcd4";
58*dfc6aa5cSAndroid Build Coastguard Worker EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
59*dfc6aa5cSAndroid Build Coastguard Worker }
60*dfc6aa5cSAndroid Build Coastguard Worker
TEST(JPEGTranTest,Crop)61*dfc6aa5cSAndroid Build Coastguard Worker TEST(JPEGTranTest, Crop) {
62*dfc6aa5cSAndroid Build Coastguard Worker
63*dfc6aa5cSAndroid Build Coastguard Worker base::FilePath input_image_path;
64*dfc6aa5cSAndroid Build Coastguard Worker GetTestFilePath(&input_image_path, "testorig.jpg");
65*dfc6aa5cSAndroid Build Coastguard Worker base::FilePath output_path(GetTargetDirectory());
66*dfc6aa5cSAndroid Build Coastguard Worker output_path = output_path.AppendASCII("testout_crop.jpg");
67*dfc6aa5cSAndroid Build Coastguard Worker
68*dfc6aa5cSAndroid Build Coastguard Worker std::string prog_name = "jpegtran";
69*dfc6aa5cSAndroid Build Coastguard Worker std::string arg1 = "-crop";
70*dfc6aa5cSAndroid Build Coastguard Worker std::string arg2 = "120x90+20+50";
71*dfc6aa5cSAndroid Build Coastguard Worker std::string arg3 = "-transpose";
72*dfc6aa5cSAndroid Build Coastguard Worker std::string arg4 = "-perfect";
73*dfc6aa5cSAndroid Build Coastguard Worker std::string arg5 = "-outfile";
74*dfc6aa5cSAndroid Build Coastguard Worker std::string arg6 = output_path.MaybeAsASCII();
75*dfc6aa5cSAndroid Build Coastguard Worker std::string arg7 = input_image_path.MaybeAsASCII();
76*dfc6aa5cSAndroid Build Coastguard Worker
77*dfc6aa5cSAndroid Build Coastguard Worker char *command_line[] = { &prog_name[0],
78*dfc6aa5cSAndroid Build Coastguard Worker &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0],
79*dfc6aa5cSAndroid Build Coastguard Worker &arg6[0], &arg7[0]
80*dfc6aa5cSAndroid Build Coastguard Worker };
81*dfc6aa5cSAndroid Build Coastguard Worker // Generate test image file.
82*dfc6aa5cSAndroid Build Coastguard Worker EXPECT_EQ(jpegtran(8, command_line), 0);
83*dfc6aa5cSAndroid Build Coastguard Worker
84*dfc6aa5cSAndroid Build Coastguard Worker // Compare expected MD5 sum against that of test image.
85*dfc6aa5cSAndroid Build Coastguard Worker const std::string EXPECTED_MD5 = "b4197f377e621c4e9b1d20471432610d";
86*dfc6aa5cSAndroid Build Coastguard Worker EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
87*dfc6aa5cSAndroid Build Coastguard Worker }
88*dfc6aa5cSAndroid Build Coastguard Worker
89*dfc6aa5cSAndroid Build Coastguard Worker #ifdef C_ARITH_CODING_SUPPORTED
TEST(JPEGTranTest,ISlow420Ari)90*dfc6aa5cSAndroid Build Coastguard Worker TEST(JPEGTranTest, ISlow420Ari) {
91*dfc6aa5cSAndroid Build Coastguard Worker
92*dfc6aa5cSAndroid Build Coastguard Worker base::FilePath input_image_path;
93*dfc6aa5cSAndroid Build Coastguard Worker GetTestFilePath(&input_image_path, "testimgint.jpg");
94*dfc6aa5cSAndroid Build Coastguard Worker base::FilePath output_path(GetTargetDirectory());
95*dfc6aa5cSAndroid Build Coastguard Worker output_path = output_path.AppendASCII("testout_420_islow_ari2.jpg");
96*dfc6aa5cSAndroid Build Coastguard Worker
97*dfc6aa5cSAndroid Build Coastguard Worker std::string prog_name = "jpegtran";
98*dfc6aa5cSAndroid Build Coastguard Worker std::string arg1 = "-arithmetic";
99*dfc6aa5cSAndroid Build Coastguard Worker std::string arg2 = "-outfile";
100*dfc6aa5cSAndroid Build Coastguard Worker std::string arg3 = output_path.MaybeAsASCII();
101*dfc6aa5cSAndroid Build Coastguard Worker std::string arg4 = input_image_path.MaybeAsASCII();
102*dfc6aa5cSAndroid Build Coastguard Worker
103*dfc6aa5cSAndroid Build Coastguard Worker char *command_line[] = { &prog_name[0],
104*dfc6aa5cSAndroid Build Coastguard Worker &arg1[0], &arg2[0], &arg3[0], &arg4[0]
105*dfc6aa5cSAndroid Build Coastguard Worker };
106*dfc6aa5cSAndroid Build Coastguard Worker // Generate test image file.
107*dfc6aa5cSAndroid Build Coastguard Worker EXPECT_EQ(jpegtran(5, command_line), 0);
108*dfc6aa5cSAndroid Build Coastguard Worker
109*dfc6aa5cSAndroid Build Coastguard Worker // Compare expected MD5 sum against that of test image.
110*dfc6aa5cSAndroid Build Coastguard Worker const std::string EXPECTED_MD5 = "e986fb0a637a8d833d96e8a6d6d84ea1";
111*dfc6aa5cSAndroid Build Coastguard Worker EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
112*dfc6aa5cSAndroid Build Coastguard Worker }
113*dfc6aa5cSAndroid Build Coastguard Worker
TEST(JPEGTranTest,ISlow420)114*dfc6aa5cSAndroid Build Coastguard Worker TEST(JPEGTranTest, ISlow420) {
115*dfc6aa5cSAndroid Build Coastguard Worker
116*dfc6aa5cSAndroid Build Coastguard Worker base::FilePath input_image_path;
117*dfc6aa5cSAndroid Build Coastguard Worker GetTestFilePath(&input_image_path, "testimgari.jpg");
118*dfc6aa5cSAndroid Build Coastguard Worker base::FilePath output_path(GetTargetDirectory());
119*dfc6aa5cSAndroid Build Coastguard Worker output_path = output_path.AppendASCII("testout_420_islow.jpg");
120*dfc6aa5cSAndroid Build Coastguard Worker
121*dfc6aa5cSAndroid Build Coastguard Worker std::string prog_name = "jpegtran";
122*dfc6aa5cSAndroid Build Coastguard Worker std::string arg1 = "-outfile";
123*dfc6aa5cSAndroid Build Coastguard Worker std::string arg2 = output_path.MaybeAsASCII();
124*dfc6aa5cSAndroid Build Coastguard Worker std::string arg3 = input_image_path.MaybeAsASCII();
125*dfc6aa5cSAndroid Build Coastguard Worker
126*dfc6aa5cSAndroid Build Coastguard Worker char *command_line[] = { &prog_name[0],
127*dfc6aa5cSAndroid Build Coastguard Worker &arg1[0], &arg2[0], &arg3[0]
128*dfc6aa5cSAndroid Build Coastguard Worker };
129*dfc6aa5cSAndroid Build Coastguard Worker // Generate test image file.
130*dfc6aa5cSAndroid Build Coastguard Worker EXPECT_EQ(jpegtran(4, command_line), 0);
131*dfc6aa5cSAndroid Build Coastguard Worker
132*dfc6aa5cSAndroid Build Coastguard Worker // Compare expected MD5 sum against that of test image.
133*dfc6aa5cSAndroid Build Coastguard Worker const std::string EXPECTED_MD5 = "9a68f56bc76e466aa7e52f415d0f4a5f";
134*dfc6aa5cSAndroid Build Coastguard Worker EXPECT_TRUE(CompareFileAndMD5(output_path, EXPECTED_MD5));
135*dfc6aa5cSAndroid Build Coastguard Worker }
136*dfc6aa5cSAndroid Build Coastguard Worker #endif
137