Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: content/common/gpu/media/jpeg_codec_unittest.cc

Issue 825863002: WIP: Add hardware jpeg decode on tegra platform Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Created 5 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <string>
6
7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/files/file_util.h"
10 #include "base/logging.h"
11 #include "content/common/gpu/media/jpeg_codec.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 // This program is run like this:
15 // build/android/test_runner.py gtest -s content_unittests --debug -vvv
16 // --gtest-filter JpegDecoderTest.* --test-arguments="--input_file=
17 // /sdcard/flowers.jpg"
18 //
19 // The input is read from jpeg file. The output is written to output.rgb if it
20 // is given.
21
22 namespace content {
23
24 // These default values are used if nothing is specified in the command line.
25 const base::FilePath::CharType* kDefaultInputFile =
26 FILE_PATH_LITERAL("/sdcard/red.jpg");
27
28 // This class encapsulates the use of JpegDecoderTest to a simpler interface.
29 // It reads an jpg bytestream from a file and outputs the decoded
30 // frames (in RGBA format) to another file.
31 class JpegDecoderTest : public testing::Test {
32 public:
33 JpegDecoderTest();
34 ~JpegDecoderTest();
35
36 // Initialize the decoder. Return true if successful.
37 bool Decode();
38 protected:
39 virtual void SetUp() override;
40
41 private:
42 scoped_ptr<JPEGCodec> decoder_;
43 std::string data_; // data read from input_file
44 // These are the command line parameters
45 base::FilePath input_file_;
46 base::FilePath output_file_;
47 };
48
49 JpegDecoderTest::JpegDecoderTest() {
50 }
51
52 JpegDecoderTest::~JpegDecoderTest() {
53 decoder_.reset();
54 }
55
56 bool JpegDecoderTest::Decode() {
57 bool ret = false;
58
59 decoder_ = JPEGCodec::Create(JPEGCodec::kDecoder);
60
61 if (!base::ReadFileToString(input_file_, &data_)) {
62 LOG(ERROR) << "failed to read input data from " << input_file_.value();
63 return false;
64 }
65 unsigned w, h, row_bytes;
66 unsigned char* out_data;
67
68 ret = decoder_->Decode(reinterpret_cast<const uint8*>(data_.c_str()),
69 data_.size(), &out_data, &w,
70 &h, &row_bytes);
71
72 LOG(INFO) << "JPEG Decoder w: " <<w;
73 LOG(INFO) << "JPEG Decoder h: " <<h;
74 LOG(INFO) << "JPEG Decoder row bytes: " <<row_bytes;
75
76 // This creates or truncates output_file.
77 // Without it, AppendToFile() will not work.
78 if (!output_file_.empty()) {
79 if (base::WriteFile(output_file_,reinterpret_cast<const char*>(out_data),
80 row_bytes * h) != 0) {
81 return false;
82 }
83 }
84
85 return ret;
86 }
87
88 void JpegDecoderTest::SetUp() {
89 // Process command line.
90 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
91 CHECK(cmd_line);
92
93 base::CommandLine::SwitchMap switches = cmd_line->GetSwitches();
94 for (base::CommandLine::SwitchMap::const_iterator it = switches.begin();
95 it != switches.end();
96 ++it) {
97 if (it->first == "input_file") {
98 input_file_ = base::FilePath(it->second);
99 continue;
100 }
101 if (it->first == "output_file") {
102 output_file_ = base::FilePath(it->second);
103 continue;
104 }
105 }
106 // If nothing specified, use the default file in the source tree.
107 if (input_file_.empty()) {
108 input_file_ = base::FilePath(kDefaultInputFile);
109 }
110 LOG(INFO) << "Input File: " << input_file_.value();
111 LOG(INFO) << "Output File: " << output_file_.value();
112 }
113
114
115 TEST_F(JpegDecoderTest, TestDecode) {
116 EXPECT_TRUE(Decode());
117 }
118
119 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/media/jpeg_codec.cc ('k') | content/common/gpu/media/tegra_jpeg_codec_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698