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

Unified 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 6 years 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/gpu/media/jpeg_codec_unittest.cc
diff --git a/content/common/gpu/media/jpeg_codec_unittest.cc b/content/common/gpu/media/jpeg_codec_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2b5815cdba8eaca59e9e1c94cd8f97b6ee057e2b
--- /dev/null
+++ b/content/common/gpu/media/jpeg_codec_unittest.cc
@@ -0,0 +1,119 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+
+#include "base/bind.h"
+#include "base/command_line.h"
+#include "base/files/file_util.h"
+#include "base/logging.h"
+#include "content/common/gpu/media/jpeg_codec.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+// This program is run like this:
+// build/android/test_runner.py gtest -s content_unittests --debug -vvv
+// --gtest-filter JpegDecoderTest.* --test-arguments="--input_file=
+// /sdcard/flowers.jpg"
+//
+// The input is read from jpeg file. The output is written to output.rgb if it
+// is given.
+
+namespace content {
+
+// These default values are used if nothing is specified in the command line.
+const base::FilePath::CharType* kDefaultInputFile =
+ FILE_PATH_LITERAL("/sdcard/red.jpg");
+
+// This class encapsulates the use of JpegDecoderTest to a simpler interface.
+// It reads an jpg bytestream from a file and outputs the decoded
+// frames (in RGBA format) to another file.
+class JpegDecoderTest : public testing::Test {
+ public:
+ JpegDecoderTest();
+ ~JpegDecoderTest();
+
+ // Initialize the decoder. Return true if successful.
+ bool Decode();
+ protected:
+ virtual void SetUp() override;
+
+ private:
+ scoped_ptr<JPEGCodec> decoder_;
+ std::string data_; // data read from input_file
+ // These are the command line parameters
+ base::FilePath input_file_;
+ base::FilePath output_file_;
+};
+
+JpegDecoderTest::JpegDecoderTest() {
+}
+
+JpegDecoderTest::~JpegDecoderTest() {
+ decoder_.reset();
+}
+
+bool JpegDecoderTest::Decode() {
+ bool ret = false;
+
+ decoder_ = JPEGCodec::Create(JPEGCodec::kDecoder);
+
+ if (!base::ReadFileToString(input_file_, &data_)) {
+ LOG(ERROR) << "failed to read input data from " << input_file_.value();
+ return false;
+ }
+ unsigned w, h, row_bytes;
+ unsigned char* out_data;
+
+ ret = decoder_->Decode(reinterpret_cast<const uint8*>(data_.c_str()),
+ data_.size(), &out_data, &w,
+ &h, &row_bytes);
+
+ LOG(INFO) << "JPEG Decoder w: " <<w;
+ LOG(INFO) << "JPEG Decoder h: " <<h;
+ LOG(INFO) << "JPEG Decoder row bytes: " <<row_bytes;
+
+ // This creates or truncates output_file.
+ // Without it, AppendToFile() will not work.
+ if (!output_file_.empty()) {
+ if (base::WriteFile(output_file_,reinterpret_cast<const char*>(out_data),
+ row_bytes * h) != 0) {
+ return false;
+ }
+ }
+
+ return ret;
+}
+
+void JpegDecoderTest::SetUp() {
+ // Process command line.
+ base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
+ CHECK(cmd_line);
+
+ base::CommandLine::SwitchMap switches = cmd_line->GetSwitches();
+ for (base::CommandLine::SwitchMap::const_iterator it = switches.begin();
+ it != switches.end();
+ ++it) {
+ if (it->first == "input_file") {
+ input_file_ = base::FilePath(it->second);
+ continue;
+ }
+ if (it->first == "output_file") {
+ output_file_ = base::FilePath(it->second);
+ continue;
+ }
+ }
+ // If nothing specified, use the default file in the source tree.
+ if (input_file_.empty()) {
+ input_file_ = base::FilePath(kDefaultInputFile);
+ }
+ LOG(INFO) << "Input File: " << input_file_.value();
+ LOG(INFO) << "Output File: " << output_file_.value();
+}
+
+
+TEST_F(JpegDecoderTest, TestDecode) {
+ EXPECT_TRUE(Decode());
+}
+
+} // namespace content
« 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