| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "public/platform/WebImage.h" | 31 #include "public/platform/WebImage.h" |
| 32 | 32 |
| 33 #include "platform/SharedBuffer.h" | 33 #include "platform/SharedBuffer.h" |
| 34 #include "platform/graphics/Image.h" | 34 #include "platform/graphics/Image.h" |
| 35 #include "platform/image-decoders/ImageDecoder.h" | 35 #include "platform/image-decoders/ImageDecoder.h" |
| 36 #include "public/platform/WebData.h" | 36 #include "public/platform/WebData.h" |
| 37 #include "public/platform/WebSize.h" | 37 #include "public/platform/WebSize.h" |
| 38 #include "third_party/skia/include/core/SkImage.h" | 38 #include "third_party/skia/include/core/SkImage.h" |
| 39 #include "wtf/OwnPtr.h" |
| 40 #include "wtf/PassOwnPtr.h" |
| 39 #include "wtf/PassRefPtr.h" | 41 #include "wtf/PassRefPtr.h" |
| 40 #include "wtf/Vector.h" | 42 #include "wtf/Vector.h" |
| 41 #include <algorithm> | 43 #include <algorithm> |
| 42 #include <memory> | |
| 43 | 44 |
| 44 namespace blink { | 45 namespace blink { |
| 45 | 46 |
| 46 WebImage WebImage::fromData(const WebData& data, const WebSize& desiredSize) | 47 WebImage WebImage::fromData(const WebData& data, const WebSize& desiredSize) |
| 47 { | 48 { |
| 48 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); | 49 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); |
| 49 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(*buffer.get(), Im
ageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgnored)); | 50 OwnPtr<ImageDecoder> decoder(ImageDecoder::create(*buffer.get(), ImageDecode
r::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgnored)); |
| 50 if (!decoder) | 51 if (!decoder) |
| 51 return WebImage(); | 52 return WebImage(); |
| 52 | 53 |
| 53 decoder->setData(buffer.get(), true); | 54 decoder->setData(buffer.get(), true); |
| 54 if (!decoder->isSizeAvailable()) | 55 if (!decoder->isSizeAvailable()) |
| 55 return WebImage(); | 56 return WebImage(); |
| 56 | 57 |
| 57 // Frames are arranged by decreasing size, then decreasing bit depth. | 58 // Frames are arranged by decreasing size, then decreasing bit depth. |
| 58 // Pick the frame closest to |desiredSize|'s area without being smaller, | 59 // Pick the frame closest to |desiredSize|'s area without being smaller, |
| 59 // which has the highest bit depth. | 60 // which has the highest bit depth. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 83 | 84 |
| 84 return WebImage(frame->bitmap()); | 85 return WebImage(frame->bitmap()); |
| 85 } | 86 } |
| 86 | 87 |
| 87 WebVector<WebImage> WebImage::framesFromData(const WebData& data) | 88 WebVector<WebImage> WebImage::framesFromData(const WebData& data) |
| 88 { | 89 { |
| 89 // This is to protect from malicious images. It should be big enough that it
's never hit in pracice. | 90 // This is to protect from malicious images. It should be big enough that it
's never hit in pracice. |
| 90 const size_t maxFrameCount = 8; | 91 const size_t maxFrameCount = 8; |
| 91 | 92 |
| 92 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); | 93 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); |
| 93 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(*buffer.get(), Im
ageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgnored)); | 94 OwnPtr<ImageDecoder> decoder(ImageDecoder::create(*buffer.get(), ImageDecode
r::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgnored)); |
| 94 if (!decoder) | 95 if (!decoder) |
| 95 return WebVector<WebImage>(); | 96 return WebVector<WebImage>(); |
| 96 | 97 |
| 97 decoder->setData(buffer.get(), true); | 98 decoder->setData(buffer.get(), true); |
| 98 if (!decoder->isSizeAvailable()) | 99 if (!decoder->isSizeAvailable()) |
| 99 return WebVector<WebImage>(); | 100 return WebVector<WebImage>(); |
| 100 | 101 |
| 101 // Frames are arranged by decreasing size, then decreasing bit depth. | 102 // Frames are arranged by decreasing size, then decreasing bit depth. |
| 102 // Keep the first frame at every size, has the highest bit depth. | 103 // Keep the first frame at every size, has the highest bit depth. |
| 103 const size_t frameCount = decoder->frameCount(); | 104 const size_t frameCount = decoder->frameCount(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 WebImage::WebImage(const PassRefPtr<Image>& image) | 146 WebImage::WebImage(const PassRefPtr<Image>& image) |
| 146 { | 147 { |
| 147 if (!image) | 148 if (!image) |
| 148 return; | 149 return; |
| 149 | 150 |
| 150 if (RefPtr<SkImage> skImage = image->imageForCurrentFrame()) | 151 if (RefPtr<SkImage> skImage = image->imageForCurrentFrame()) |
| 151 skImage->asLegacyBitmap(&m_bitmap, SkImage::kRO_LegacyBitmapMode); | 152 skImage->asLegacyBitmap(&m_bitmap, SkImage::kRO_LegacyBitmapMode); |
| 152 } | 153 } |
| 153 | 154 |
| 154 } // namespace blink | 155 } // namespace blink |
| OLD | NEW |