OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/image/image.h" | 5 #include "ui/gfx/image/image.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | |
9 | 8 |
10 #include "base/logging.h" | 9 #include "base/logging.h" |
11 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
12 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
13 #include "third_party/skia/include/core/SkBitmap.h" | 12 #include "third_party/skia/include/core/SkBitmap.h" |
14 #include "ui/gfx/image/image_png_rep.h" | 13 #include "ui/gfx/image/image_png_rep.h" |
15 #include "ui/gfx/image/image_skia.h" | 14 #include "ui/gfx/image/image_skia.h" |
16 #include "ui/gfx/image/image_skia_source.h" | |
17 #include "ui/gfx/size.h" | 15 #include "ui/gfx/size.h" |
18 | 16 |
19 #if !defined(OS_IOS) | 17 #if !defined(OS_IOS) |
20 #include "ui/gfx/codec/png_codec.h" | 18 #include "ui/gfx/codec/png_codec.h" |
21 #endif | 19 #endif |
22 | 20 |
23 #if defined(OS_IOS) | 21 #if defined(OS_IOS) |
24 #include "base/mac/foundation_util.h" | 22 #include "base/mac/foundation_util.h" |
25 #include "ui/gfx/image/image_skia_util_ios.h" | 23 #include "ui/gfx/image/image_skia_util_ios.h" |
26 #elif defined(OS_MACOSX) | 24 #elif defined(OS_MACOSX) |
27 #include "base/mac/mac_util.h" | 25 #include "base/mac/mac_util.h" |
28 #include "ui/gfx/image/image_skia_util_mac.h" | 26 #include "ui/gfx/image/image_skia_util_mac.h" |
29 #endif | 27 #endif |
30 | 28 |
31 namespace gfx { | 29 namespace gfx { |
32 | 30 |
33 namespace internal { | 31 namespace internal { |
34 | 32 |
35 #if defined(OS_IOS) | 33 #if defined(OS_IOS) |
36 scoped_refptr<base::RefCountedMemory> Get1xPNGBytesFromUIImage( | 34 scoped_refptr<base::RefCountedMemory> Get1xPNGBytesFromUIImage( |
37 UIImage* uiimage); | 35 UIImage* uiimage); |
38 // Caller takes ownership of the returned UIImage. | 36 // Caller takes ownership of the returned UIImage. |
39 UIImage* CreateUIImageFromPNG( | 37 UIImage* CreateUIImageFromPNG( |
40 const std::vector<ImagePNGRep>& image_png_reps); | 38 const std::vector<gfx::ImagePNGRep>& image_png_reps); |
41 gfx::Size UIImageSize(UIImage* image); | 39 gfx::Size UIImageSize(UIImage* image); |
42 #elif defined(OS_MACOSX) | 40 #elif defined(OS_MACOSX) |
43 scoped_refptr<base::RefCountedMemory> Get1xPNGBytesFromNSImage( | 41 scoped_refptr<base::RefCountedMemory> Get1xPNGBytesFromNSImage( |
44 NSImage* nsimage); | 42 NSImage* nsimage); |
45 // Caller takes ownership of the returned NSImage. | 43 // Caller takes ownership of the returned NSImage. |
46 NSImage* NSImageFromPNG(const std::vector<ImagePNGRep>& image_png_reps, | 44 NSImage* NSImageFromPNG(const std::vector<gfx::ImagePNGRep>& image_png_reps, |
47 CGColorSpaceRef color_space); | 45 CGColorSpaceRef color_space); |
48 gfx::Size NSImageSize(NSImage* image); | 46 gfx::Size NSImageSize(NSImage* image); |
49 #endif // defined(OS_MACOSX) | 47 #endif // defined(OS_MACOSX) |
50 | 48 |
51 #if defined(OS_IOS) | 49 #if defined(OS_IOS) |
52 ImageSkia* ImageSkiaFromPNG( | 50 ImageSkia* ImageSkiaFromPNG( |
53 const std::vector<ImagePNGRep>& image_png_reps); | 51 const std::vector<gfx::ImagePNGRep>& image_png_reps); |
54 scoped_refptr<base::RefCountedMemory> Get1xPNGBytesFromImageSkia( | 52 scoped_refptr<base::RefCountedMemory> Get1xPNGBytesFromImageSkia( |
55 const ImageSkia* skia); | 53 const ImageSkia* skia); |
56 #else | 54 #else |
57 // Returns a 16x16 red image to visually show error in decoding PNG. | 55 // Returns a 16x16 red image to visually show error in decoding PNG. |
58 // Caller takes ownership of returned ImageSkia. | 56 // Caller takes ownership of returned ImageSkia. |
59 ImageSkia* GetErrorImageSkia() { | 57 ImageSkia* GetErrorImageSkia() { |
60 SkBitmap bitmap; | 58 SkBitmap bitmap; |
61 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); | 59 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); |
62 bitmap.allocPixels(); | 60 bitmap.allocPixels(); |
63 bitmap.eraseARGB(0xff, 0xff, 0, 0); | 61 bitmap.eraseARGB(0xff, 0xff, 0, 0); |
64 return new ImageSkia(ImageSkiaRep(bitmap, 1.0f)); | 62 return new gfx::ImageSkia(gfx::ImageSkiaRep(bitmap, 1.0f)); |
65 } | 63 } |
66 | 64 |
67 class PNGImageSource : public ImageSkiaSource { | 65 ImageSkia* ImageSkiaFromPNG( |
68 public: | 66 const std::vector<gfx::ImagePNGRep>& image_png_reps) { |
69 PNGImageSource() {} | 67 if (image_png_reps.empty()) |
70 virtual ~PNGImageSource() {} | 68 return GetErrorImageSkia(); |
71 | 69 |
72 virtual ImageSkiaRep GetImageForScale(float scale) OVERRIDE { | 70 scoped_ptr<gfx::ImageSkia> image_skia(new ImageSkia()); |
73 if (image_skia_reps_.empty()) | 71 for (size_t i = 0; i < image_png_reps.size(); ++i) { |
74 return ImageSkiaRep(); | 72 scoped_refptr<base::RefCountedMemory> raw_data = |
75 | 73 image_png_reps[i].raw_data; |
76 const ImageSkiaRep* rep = NULL; | |
77 // gfx::ImageSkia passes one of the resource scale factors. The source | |
78 // should return: | |
79 // 1) The ImageSkiaRep with the highest scale if all available | |
80 // scales are smaller than |scale|. | |
81 // 2) The ImageSkiaRep with the smallest one that is larger than |scale|. | |
82 for (ImageSkiaRepSet::const_iterator iter = image_skia_reps_.begin(); | |
83 iter != image_skia_reps_.end(); ++iter) { | |
84 if ((*iter).scale() == scale) | |
85 return (*iter); | |
86 if (!rep || rep->scale() < (*iter).scale()) | |
87 rep = &(*iter); | |
88 if (rep->scale() >= scale) | |
89 break; | |
90 } | |
91 return rep ? *rep : ImageSkiaRep(); | |
92 } | |
93 | |
94 const gfx::Size size() const { | |
95 return size_; | |
96 } | |
97 | |
98 bool AddPNGData(const ImagePNGRep& png_rep) { | |
99 const gfx::ImageSkiaRep rep = ToImageSkiaRep(png_rep); | |
100 if (rep.is_null()) | |
101 return false; | |
102 if (size_.IsEmpty()) | |
103 size_ = gfx::Size(rep.GetWidth(), rep.GetHeight()); | |
104 image_skia_reps_.insert(rep); | |
105 return true; | |
106 } | |
107 | |
108 static ImageSkiaRep ToImageSkiaRep(const ImagePNGRep& png_rep) { | |
109 scoped_refptr<base::RefCountedMemory> raw_data = png_rep.raw_data; | |
110 CHECK(raw_data.get()); | 74 CHECK(raw_data.get()); |
111 SkBitmap bitmap; | 75 SkBitmap bitmap; |
112 if (!PNGCodec::Decode(raw_data->front(), raw_data->size(), | 76 if (!gfx::PNGCodec::Decode(raw_data->front(), raw_data->size(), |
113 &bitmap)) { | 77 &bitmap)) { |
114 LOG(ERROR) << "Unable to decode PNG for " << png_rep.scale << "."; | 78 LOG(ERROR) << "Unable to decode PNG for " |
115 return ImageSkiaRep(); | 79 << image_png_reps[i].scale |
| 80 << "."; |
| 81 return GetErrorImageSkia(); |
116 } | 82 } |
117 return ImageSkiaRep(bitmap, png_rep.scale); | 83 image_skia->AddRepresentation(gfx::ImageSkiaRep( |
| 84 bitmap, image_png_reps[i].scale)); |
118 } | 85 } |
119 | 86 return image_skia.release(); |
120 private: | |
121 struct Compare { | |
122 bool operator()(const ImageSkiaRep& rep1, const ImageSkiaRep& rep2) { | |
123 return rep1.scale() < rep2.scale(); | |
124 } | |
125 }; | |
126 | |
127 typedef std::set<ImageSkiaRep, Compare> ImageSkiaRepSet; | |
128 ImageSkiaRepSet image_skia_reps_; | |
129 gfx::Size size_; | |
130 | |
131 DISALLOW_COPY_AND_ASSIGN(PNGImageSource); | |
132 }; | |
133 | |
134 ImageSkia* ImageSkiaFromPNG( | |
135 const std::vector<ImagePNGRep>& image_png_reps) { | |
136 if (image_png_reps.empty()) | |
137 return GetErrorImageSkia(); | |
138 scoped_ptr<PNGImageSource> image_source(new PNGImageSource); | |
139 | |
140 for (size_t i = 0; i < image_png_reps.size(); ++i) { | |
141 if (!image_source->AddPNGData(image_png_reps[i])) | |
142 return GetErrorImageSkia(); | |
143 } | |
144 const gfx::Size& size = image_source->size(); | |
145 DCHECK(!size.IsEmpty()); | |
146 if (size.IsEmpty()) | |
147 return GetErrorImageSkia(); | |
148 return new ImageSkia(image_source.release(), size); | |
149 } | 87 } |
150 | 88 |
151 scoped_refptr<base::RefCountedMemory> Get1xPNGBytesFromImageSkia( | 89 scoped_refptr<base::RefCountedMemory> Get1xPNGBytesFromImageSkia( |
152 const ImageSkia* image_skia) { | 90 const ImageSkia* image_skia) { |
153 ImageSkiaRep image_skia_rep = image_skia->GetRepresentation(1.0f); | 91 ImageSkiaRep image_skia_rep = image_skia->GetRepresentation(1.0f); |
154 | 92 |
155 scoped_refptr<base::RefCountedBytes> png_bytes(new base::RefCountedBytes()); | 93 scoped_refptr<base::RefCountedBytes> png_bytes(new base::RefCountedBytes()); |
156 if (image_skia_rep.scale() != 1.0f || | 94 if (image_skia_rep.scale() != 1.0f || |
157 !PNGCodec::EncodeBGRASkBitmap(image_skia_rep.sk_bitmap(), false, | 95 !gfx::PNGCodec::EncodeBGRASkBitmap(image_skia_rep.sk_bitmap(), false, |
158 &png_bytes->data())) { | 96 &png_bytes->data())) { |
159 return NULL; | 97 return NULL; |
160 } | 98 } |
161 return png_bytes; | 99 return png_bytes; |
162 } | 100 } |
163 #endif | 101 #endif |
164 | 102 |
165 class ImageRepPNG; | 103 class ImageRepPNG; |
166 class ImageRepSkia; | 104 class ImageRepSkia; |
167 class ImageRepCocoa; | 105 class ImageRepCocoa; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 | 295 |
358 DISALLOW_COPY_AND_ASSIGN(ImageRepCocoa); | 296 DISALLOW_COPY_AND_ASSIGN(ImageRepCocoa); |
359 }; | 297 }; |
360 #endif // defined(OS_MACOSX) | 298 #endif // defined(OS_MACOSX) |
361 | 299 |
362 // The Storage class acts similarly to the pixels in a SkBitmap: the Image | 300 // The Storage class acts similarly to the pixels in a SkBitmap: the Image |
363 // class holds a refptr instance of Storage, which in turn holds all the | 301 // class holds a refptr instance of Storage, which in turn holds all the |
364 // ImageReps. This way, the Image can be cheaply copied. | 302 // ImageReps. This way, the Image can be cheaply copied. |
365 class ImageStorage : public base::RefCounted<ImageStorage> { | 303 class ImageStorage : public base::RefCounted<ImageStorage> { |
366 public: | 304 public: |
367 ImageStorage(Image::RepresentationType default_type) | 305 ImageStorage(gfx::Image::RepresentationType default_type) |
368 : default_representation_type_(default_type), | 306 : default_representation_type_(default_type), |
369 #if defined(OS_MACOSX) && !defined(OS_IOS) | 307 #if defined(OS_MACOSX) && !defined(OS_IOS) |
370 default_representation_color_space_( | 308 default_representation_color_space_( |
371 base::mac::GetGenericRGBColorSpace()), | 309 base::mac::GetGenericRGBColorSpace()), |
372 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 310 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
373 representations_deleter_(&representations_) { | 311 representations_deleter_(&representations_) { |
374 } | 312 } |
375 | 313 |
376 Image::RepresentationType default_representation_type() { | 314 gfx::Image::RepresentationType default_representation_type() { |
377 return default_representation_type_; | 315 return default_representation_type_; |
378 } | 316 } |
379 Image::RepresentationMap& representations() { return representations_; } | 317 gfx::Image::RepresentationMap& representations() { return representations_; } |
380 | 318 |
381 #if defined(OS_MACOSX) && !defined(OS_IOS) | 319 #if defined(OS_MACOSX) && !defined(OS_IOS) |
382 void set_default_representation_color_space(CGColorSpaceRef color_space) { | 320 void set_default_representation_color_space(CGColorSpaceRef color_space) { |
383 default_representation_color_space_ = color_space; | 321 default_representation_color_space_ = color_space; |
384 } | 322 } |
385 CGColorSpaceRef default_representation_color_space() { | 323 CGColorSpaceRef default_representation_color_space() { |
386 return default_representation_color_space_; | 324 return default_representation_color_space_; |
387 } | 325 } |
388 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 326 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
389 | 327 |
390 private: | 328 private: |
391 friend class base::RefCounted<ImageStorage>; | 329 friend class base::RefCounted<ImageStorage>; |
392 | 330 |
393 ~ImageStorage() {} | 331 ~ImageStorage() {} |
394 | 332 |
395 // The type of image that was passed to the constructor. This key will always | 333 // The type of image that was passed to the constructor. This key will always |
396 // exist in the |representations_| map. | 334 // exist in the |representations_| map. |
397 Image::RepresentationType default_representation_type_; | 335 gfx::Image::RepresentationType default_representation_type_; |
398 | 336 |
399 #if defined(OS_MACOSX) && !defined(OS_IOS) | 337 #if defined(OS_MACOSX) && !defined(OS_IOS) |
400 // The default representation's colorspace. This is used for converting to | 338 // The default representation's colorspace. This is used for converting to |
401 // NSImage. This field exists to compensate for PNGCodec not writing or | 339 // NSImage. This field exists to compensate for PNGCodec not writing or |
402 // reading colorspace ancillary chunks. (sRGB, iCCP). | 340 // reading colorspace ancillary chunks. (sRGB, iCCP). |
403 // Not owned. | 341 // Not owned. |
404 CGColorSpaceRef default_representation_color_space_; | 342 CGColorSpaceRef default_representation_color_space_; |
405 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 343 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
406 | 344 |
407 // All the representations of an Image. Size will always be at least one, with | 345 // All the representations of an Image. Size will always be at least one, with |
408 // more for any converted representations. | 346 // more for any converted representations. |
409 Image::RepresentationMap representations_; | 347 gfx::Image::RepresentationMap representations_; |
410 | 348 |
411 STLValueDeleter<Image::RepresentationMap> representations_deleter_; | 349 STLValueDeleter<Image::RepresentationMap> representations_deleter_; |
412 | 350 |
413 DISALLOW_COPY_AND_ASSIGN(ImageStorage); | 351 DISALLOW_COPY_AND_ASSIGN(ImageStorage); |
414 }; | 352 }; |
415 | 353 |
416 } // namespace internal | 354 } // namespace internal |
417 | 355 |
418 Image::Image() { | 356 Image::Image() { |
419 // |storage_| is NULL for empty Images. | 357 // |storage_| is NULL for empty Images. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 Image& Image::operator=(const Image& other) { | 406 Image& Image::operator=(const Image& other) { |
469 storage_ = other.storage_; | 407 storage_ = other.storage_; |
470 return *this; | 408 return *this; |
471 } | 409 } |
472 | 410 |
473 Image::~Image() { | 411 Image::~Image() { |
474 } | 412 } |
475 | 413 |
476 // static | 414 // static |
477 Image Image::CreateFrom1xBitmap(const SkBitmap& bitmap) { | 415 Image Image::CreateFrom1xBitmap(const SkBitmap& bitmap) { |
478 return Image(ImageSkia::CreateFrom1xBitmap(bitmap)); | 416 return gfx::Image(ImageSkia::CreateFrom1xBitmap(bitmap)); |
479 } | 417 } |
480 | 418 |
481 // static | 419 // static |
482 Image Image::CreateFrom1xPNGBytes(const unsigned char* input, | 420 Image Image::CreateFrom1xPNGBytes(const unsigned char* input, |
483 size_t input_size) { | 421 size_t input_size) { |
484 if (input_size == 0u) | 422 if (input_size == 0u) |
485 return Image(); | 423 return gfx::Image(); |
486 | 424 |
487 scoped_refptr<base::RefCountedBytes> raw_data(new base::RefCountedBytes()); | 425 scoped_refptr<base::RefCountedBytes> raw_data(new base::RefCountedBytes()); |
488 raw_data->data().assign(input, input + input_size); | 426 raw_data->data().assign(input, input + input_size); |
489 | 427 |
490 return CreateFrom1xPNGBytes(raw_data); | 428 return CreateFrom1xPNGBytes(raw_data); |
491 } | 429 } |
492 | 430 |
493 Image Image::CreateFrom1xPNGBytes( | 431 Image Image::CreateFrom1xPNGBytes( |
494 const scoped_refptr<base::RefCountedMemory>& input) { | 432 const scoped_refptr<base::RefCountedMemory>& input) { |
495 if (!input.get() || input->size() == 0u) | 433 if (!input.get() || input->size() == 0u) |
496 return Image(); | 434 return gfx::Image(); |
497 | 435 |
498 std::vector<ImagePNGRep> image_reps; | 436 std::vector<gfx::ImagePNGRep> image_reps; |
499 image_reps.push_back(ImagePNGRep(input, 1.0f)); | 437 image_reps.push_back(ImagePNGRep(input, 1.0f)); |
500 return Image(image_reps); | 438 return gfx::Image(image_reps); |
501 } | 439 } |
502 | 440 |
503 const SkBitmap* Image::ToSkBitmap() const { | 441 const SkBitmap* Image::ToSkBitmap() const { |
504 // Possibly create and cache an intermediate ImageRepSkia. | 442 // Possibly create and cache an intermediate ImageRepSkia. |
505 return ToImageSkia()->bitmap(); | 443 return ToImageSkia()->bitmap(); |
506 } | 444 } |
507 | 445 |
508 const ImageSkia* Image::ToImageSkia() const { | 446 const ImageSkia* Image::ToImageSkia() const { |
509 internal::ImageRep* rep = GetRepresentation(kImageRepSkia, false); | 447 internal::ImageRep* rep = GetRepresentation(kImageRepSkia, false); |
510 if (!rep) { | 448 if (!rep) { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 } | 543 } |
606 #endif | 544 #endif |
607 | 545 |
608 scoped_refptr<base::RefCountedMemory> Image::As1xPNGBytes() const { | 546 scoped_refptr<base::RefCountedMemory> Image::As1xPNGBytes() const { |
609 if (IsEmpty()) | 547 if (IsEmpty()) |
610 return new base::RefCountedBytes(); | 548 return new base::RefCountedBytes(); |
611 | 549 |
612 internal::ImageRep* rep = GetRepresentation(kImageRepPNG, false); | 550 internal::ImageRep* rep = GetRepresentation(kImageRepPNG, false); |
613 | 551 |
614 if (rep) { | 552 if (rep) { |
615 const std::vector<ImagePNGRep>& image_png_reps = | 553 const std::vector<gfx::ImagePNGRep>& image_png_reps = |
616 rep->AsImageRepPNG()->image_reps(); | 554 rep->AsImageRepPNG()->image_reps(); |
617 for (size_t i = 0; i < image_png_reps.size(); ++i) { | 555 for (size_t i = 0; i < image_png_reps.size(); ++i) { |
618 if (image_png_reps[i].scale == 1.0f) | 556 if (image_png_reps[i].scale == 1.0f) |
619 return image_png_reps[i].raw_data; | 557 return image_png_reps[i].raw_data; |
620 } | 558 } |
621 return new base::RefCountedBytes(); | 559 return new base::RefCountedBytes(); |
622 } | 560 } |
623 | 561 |
624 scoped_refptr<base::RefCountedMemory> png_bytes(NULL); | 562 scoped_refptr<base::RefCountedMemory> png_bytes(NULL); |
625 switch (DefaultRepresentationType()) { | 563 switch (DefaultRepresentationType()) { |
(...skipping 30 matching lines...) Expand all Loading... |
656 return new base::RefCountedBytes(); | 594 return new base::RefCountedBytes(); |
657 } | 595 } |
658 | 596 |
659 // Do not insert representations for scale factors other than 1x even if | 597 // Do not insert representations for scale factors other than 1x even if |
660 // they are available because: | 598 // they are available because: |
661 // - Only the 1x PNG bytes can be accessed. | 599 // - Only the 1x PNG bytes can be accessed. |
662 // - ImageRepPNG is not used as an intermediate type in converting to a | 600 // - ImageRepPNG is not used as an intermediate type in converting to a |
663 // final type eg (converting from ImageRepSkia to ImageRepPNG to get an | 601 // final type eg (converting from ImageRepSkia to ImageRepPNG to get an |
664 // ImageRepCocoa). | 602 // ImageRepCocoa). |
665 std::vector<ImagePNGRep> image_png_reps; | 603 std::vector<ImagePNGRep> image_png_reps; |
666 image_png_reps.push_back(ImagePNGRep(png_bytes, 1.0f)); | 604 image_png_reps.push_back(gfx::ImagePNGRep(png_bytes, 1.0f)); |
667 rep = new internal::ImageRepPNG(image_png_reps); | 605 rep = new internal::ImageRepPNG(image_png_reps); |
668 AddRepresentation(rep); | 606 AddRepresentation(rep); |
669 return png_bytes; | 607 return png_bytes; |
670 } | 608 } |
671 | 609 |
672 SkBitmap Image::AsBitmap() const { | 610 SkBitmap Image::AsBitmap() const { |
673 return IsEmpty() ? SkBitmap() : *ToSkBitmap(); | 611 return IsEmpty() ? SkBitmap() : *ToSkBitmap(); |
674 } | 612 } |
675 | 613 |
676 ImageSkia Image::AsImageSkia() const { | 614 ImageSkia Image::AsImageSkia() const { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 return 0; | 676 return 0; |
739 return GetRepresentation(DefaultRepresentationType(), true)->Height(); | 677 return GetRepresentation(DefaultRepresentationType(), true)->Height(); |
740 } | 678 } |
741 | 679 |
742 gfx::Size Image::Size() const { | 680 gfx::Size Image::Size() const { |
743 if (IsEmpty()) | 681 if (IsEmpty()) |
744 return gfx::Size(); | 682 return gfx::Size(); |
745 return GetRepresentation(DefaultRepresentationType(), true)->Size(); | 683 return GetRepresentation(DefaultRepresentationType(), true)->Size(); |
746 } | 684 } |
747 | 685 |
748 void Image::SwapRepresentations(Image* other) { | 686 void Image::SwapRepresentations(gfx::Image* other) { |
749 storage_.swap(other->storage_); | 687 storage_.swap(other->storage_); |
750 } | 688 } |
751 | 689 |
752 #if defined(OS_MACOSX) && !defined(OS_IOS) | 690 #if defined(OS_MACOSX) && !defined(OS_IOS) |
753 void Image::SetSourceColorSpace(CGColorSpaceRef color_space) { | 691 void Image::SetSourceColorSpace(CGColorSpaceRef color_space) { |
754 if (storage_.get()) | 692 if (storage_.get()) |
755 storage_->set_default_representation_color_space(color_space); | 693 storage_->set_default_representation_color_space(color_space); |
756 } | 694 } |
757 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 695 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
758 | 696 |
(...skipping 12 matching lines...) Expand all Loading... |
771 } | 709 } |
772 return it->second; | 710 return it->second; |
773 } | 711 } |
774 | 712 |
775 void Image::AddRepresentation(internal::ImageRep* rep) const { | 713 void Image::AddRepresentation(internal::ImageRep* rep) const { |
776 CHECK(storage_.get()); | 714 CHECK(storage_.get()); |
777 storage_->representations().insert(std::make_pair(rep->type(), rep)); | 715 storage_->representations().insert(std::make_pair(rep->type(), rep)); |
778 } | 716 } |
779 | 717 |
780 } // namespace gfx | 718 } // namespace gfx |
OLD | NEW |