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

Unified Diff: ui/gfx/image/image.cc

Issue 16370006: Make the favicons look visually the same after refreshing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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
« no previous file with comments | « ui/gfx/image/image.h ('k') | ui/gfx/image/image_mac.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/image/image.cc
diff --git a/ui/gfx/image/image.cc b/ui/gfx/image/image.cc
index 875ca2044245326315d6d0e07ef322efff736ba3..b0733b7ccda5dc877e56c3d0656b2e89acfa23cd 100644
--- a/ui/gfx/image/image.cc
+++ b/ui/gfx/image/image.cc
@@ -124,7 +124,8 @@ gfx::Size UIImageSize(UIImage* image);
scoped_refptr<base::RefCountedMemory> Get1xPNGBytesFromNSImage(
NSImage* nsimage);
// Caller takes ownership of the returned NSImage.
-NSImage* NSImageFromPNG(const std::vector<gfx::ImagePNGRep>& image_png_reps);
+NSImage* NSImageFromPNG(const std::vector<gfx::ImagePNGRep>& image_png_reps,
+ CGColorSpaceRef color_space);
gfx::Size NSImageSize(NSImage* image);
#endif // defined(OS_MACOSX)
@@ -472,6 +473,10 @@ class ImageStorage : public base::RefCounted<ImageStorage> {
public:
ImageStorage(gfx::Image::RepresentationType default_type)
: default_representation_type_(default_type),
+#if defined(OS_MACOSX) && !defined(OS_IOS)
+ default_representation_color_space_(
+ base::mac::GetGenericRGBColorSpace()),
+#endif // defined(OS_MACOSX) && !defined(OS_IOS)
representations_deleter_(&representations_) {
}
@@ -480,6 +485,15 @@ class ImageStorage : public base::RefCounted<ImageStorage> {
}
gfx::Image::RepresentationMap& representations() { return representations_; }
+#if defined(OS_MACOSX) && !defined(OS_IOS)
+ void set_default_representation_color_space(CGColorSpaceRef color_space) {
+ default_representation_color_space_ = color_space;
+ }
+ CGColorSpaceRef default_representation_color_space() {
+ return default_representation_color_space_;
+ }
+#endif // defined(OS_MACOSX) && !defined(OS_IOS)
+
private:
friend class base::RefCounted<ImageStorage>;
@@ -489,6 +503,14 @@ class ImageStorage : public base::RefCounted<ImageStorage> {
// exist in the |representations_| map.
gfx::Image::RepresentationType default_representation_type_;
+#if defined(OS_MACOSX) && !defined(OS_IOS)
+ // The default representation's colorspace. This is used for converting to
+ // NSImage. This field exists to compensate for PNGCodec not writing or
+ // reading colorspace ancillary chunks. (sRGB, iCCP).
+ // Not owned.
+ CGColorSpaceRef default_representation_color_space_;
+#endif // defined(OS_MACOSX) && !defined(OS_IOS)
+
// All the representations of an Image. Size will always be at least one, with
// more for any converted representations.
gfx::Image::RepresentationMap representations_;
@@ -710,18 +732,22 @@ UIImage* Image::ToUIImage() const {
NSImage* Image::ToNSImage() const {
internal::ImageRep* rep = GetRepresentation(kImageRepCocoa, false);
if (!rep) {
+ CGColorSpaceRef default_representation_color_space =
+ storage_->default_representation_color_space();
+
switch (DefaultRepresentationType()) {
case kImageRepPNG: {
internal::ImageRepPNG* png_rep =
GetRepresentation(kImageRepPNG, true)->AsImageRepPNG();
rep = new internal::ImageRepCocoa(internal::NSImageFromPNG(
- png_rep->image_reps()));
+ png_rep->image_reps(), default_representation_color_space));
break;
}
case kImageRepSkia: {
internal::ImageRepSkia* skia_rep =
GetRepresentation(kImageRepSkia, true)->AsImageRepSkia();
- NSImage* image = NSImageFromImageSkia(*skia_rep->image());
+ NSImage* image = NSImageFromImageSkiaWithColorSpace(*skia_rep->image(),
+ default_representation_color_space);
base::mac::NSObjectRetain(image);
rep = new internal::ImageRepCocoa(image);
break;
@@ -896,6 +922,13 @@ void Image::SwapRepresentations(gfx::Image* other) {
storage_.swap(other->storage_);
}
+#if defined(OS_MACOSX) && !defined(OS_IOS)
+void Image::SetSourceColorSpace(CGColorSpaceRef color_space) {
+ if (storage_.get())
+ storage_->set_default_representation_color_space(color_space);
+}
+#endif // defined(OS_MACOSX) && !defined(OS_IOS)
+
Image::RepresentationType Image::DefaultRepresentationType() const {
CHECK(storage_.get());
RepresentationType default_type = storage_->default_representation_type();
« no previous file with comments | « ui/gfx/image/image.h ('k') | ui/gfx/image/image_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698