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

Unified Diff: components/enhanced_bookmarks/image_store_util.cc

Issue 259863007: Local salient image storage for enhanced bookmark experiment. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: components/enhanced_bookmarks/image_store_util.cc
diff --git a/components/enhanced_bookmarks/image_store_util.cc b/components/enhanced_bookmarks/image_store_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..213b5950fe516290d094cc7b0a8f53b793027cf2
--- /dev/null
+++ b/components/enhanced_bookmarks/image_store_util.cc
@@ -0,0 +1,33 @@
+// 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 "components/enhanced_bookmarks/image_store_util.h"
+
+#include "ui/gfx/image/image_skia.h"
+#include "ui/gfx/image/image_util.h"
+
+namespace {
+const int kJpegEncodingQuality = 70;
+} // namespace
+
+namespace enhanced_bookmarks {
+
+scoped_refptr<base::RefCountedMemory> BytesForImage(const gfx::Image& image) {
+ DCHECK(image.AsImageSkia().image_reps().size() == 1);
+ DCHECK(image.AsImageSkia().image_reps().begin()->scale() == 1.0f);
+
+ std::vector<unsigned char> data;
+ bool succeeded =
+ gfx::JPEG1xEncodedDataFromImage(image, kJpegEncodingQuality, &data);
+
+ if (!succeeded)
+ return scoped_refptr<base::RefCountedMemory>();
+
+ return scoped_refptr<base::RefCountedMemory>(new base::RefCountedBytes(data));
+}
+
+gfx::Image ImageForBytes(const scoped_refptr<base::RefCountedMemory>& bytes) {
+ return gfx::ImageFrom1xJPEGEncodedData(bytes->front(), bytes->size());
+}
+}
« no previous file with comments | « components/enhanced_bookmarks/image_store_util.h ('k') | components/enhanced_bookmarks/persistent_image_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698