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