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

Unified Diff: components/user_manager/user_image/user_image.h

Issue 2537713002: Add support for transparent/translucent pixels in the user image (Closed)
Patch Set: Add support for transparent/translucent pixels in the user image Created 4 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
Index: components/user_manager/user_image/user_image.h
diff --git a/components/user_manager/user_image/user_image.h b/components/user_manager/user_image/user_image.h
index 4604163df218e66c9028d2329e2719e4323dc794..55e4978d1432a70277fe9547f71b4051b4a45fab 100644
--- a/components/user_manager/user_image/user_image.h
+++ b/components/user_manager/user_image/user_image.h
@@ -22,15 +22,31 @@ namespace user_manager {
// profile images and user wallpapers.
class USER_MANAGER_EXPORT UserImage {
public:
- // Encodes the given bitmap to bytes representation for WebUI. Returns null
- // on failure.
- static scoped_refptr<base::RefCountedBytes> Encode(const SkBitmap& bitmap);
+ // The format of the user image's bytes representation. PNG can support
+ // transparent background that's not supported with JPEG.
+ enum ImageFormat {
+ FORMAT_JPEG,
+ FORMAT_PNG,
+ FORMAT_UNKNOWN,
+ };
+
+ // Encodes the given bitmap to bytes representation in |image_format| for
+ // WebUI. Returns nullptr on failure.
+ static scoped_refptr<base::RefCountedBytes> Encode(const SkBitmap& bitmap,
+ ImageFormat image_format);
// Creates a new instance from a given still frame and tries to encode it
- // to bytes representation for WebUI. Always returns a non-null result.
+ // to bytes representation in |image_format| for WebUI. Always returns a
+ // non-null result.
// TODO(ivankr): remove eventually.
static std::unique_ptr<UserImage> CreateAndEncode(
- const gfx::ImageSkia& image);
+ const gfx::ImageSkia& image,
+ ImageFormat image_format);
+
+ // Choose the image format suitable for the given bitmap. Returns
+ // FORMAT_PNG if the bitmap contains transparent/translucent
+ // pixels. Otherwise, returns FORMAT_JPEG.
+ static ImageFormat ChooseImageFormat(const SkBitmap& bitmap);
// Create instance with an empty still frame and no bytes
// representation for WebUI.
@@ -43,7 +59,8 @@ class USER_MANAGER_EXPORT UserImage {
// Creates a new instance from a given still frame and bytes
// representation for WebUI.
UserImage(const gfx::ImageSkia& image,
- scoped_refptr<base::RefCountedBytes> image_bytes);
+ scoped_refptr<base::RefCountedBytes> image_bytes,
+ ImageFormat image_format);
virtual ~UserImage();
@@ -54,6 +71,8 @@ class USER_MANAGER_EXPORT UserImage {
scoped_refptr<base::RefCountedBytes> image_bytes() const {
return image_bytes_;
}
+ // Format of the bytes representation.
+ ImageFormat image_format() const { return image_format_; }
// URL from which this image was originally downloaded, if any.
void set_url(const GURL& url) { url_ = url; }
@@ -77,6 +96,7 @@ class USER_MANAGER_EXPORT UserImage {
// If image was loaded from the local file, file path is stored here.
base::FilePath file_path_;
bool is_safe_format_ = false;
+ ImageFormat image_format_ = FORMAT_UNKNOWN;
DISALLOW_COPY_AND_ASSIGN(UserImage);
};

Powered by Google App Engine
This is Rietveld 408576698