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" | |
41 #include "wtf/PassRefPtr.h" | 39 #include "wtf/PassRefPtr.h" |
42 #include "wtf/Vector.h" | 40 #include "wtf/Vector.h" |
43 #include <algorithm> | 41 #include <algorithm> |
| 42 #include <memory> |
44 | 43 |
45 namespace blink { | 44 namespace blink { |
46 | 45 |
47 WebImage WebImage::fromData(const WebData& data, const WebSize& desiredSize) | 46 WebImage WebImage::fromData(const WebData& data, const WebSize& desiredSize) |
48 { | 47 { |
49 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); | 48 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); |
50 OwnPtr<ImageDecoder> decoder(ImageDecoder::create(*buffer.get(), ImageDecode
r::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgnored)); | 49 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(*buffer.get(), Im
ageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgnored)); |
51 if (!decoder) | 50 if (!decoder) |
52 return WebImage(); | 51 return WebImage(); |
53 | 52 |
54 decoder->setData(buffer.get(), true); | 53 decoder->setData(buffer.get(), true); |
55 if (!decoder->isSizeAvailable()) | 54 if (!decoder->isSizeAvailable()) |
56 return WebImage(); | 55 return WebImage(); |
57 | 56 |
58 // Frames are arranged by decreasing size, then decreasing bit depth. | 57 // Frames are arranged by decreasing size, then decreasing bit depth. |
59 // Pick the frame closest to |desiredSize|'s area without being smaller, | 58 // Pick the frame closest to |desiredSize|'s area without being smaller, |
60 // which has the highest bit depth. | 59 // which has the highest bit depth. |
(...skipping 23 matching lines...) Expand all Loading... |
84 | 83 |
85 return WebImage(frame->bitmap()); | 84 return WebImage(frame->bitmap()); |
86 } | 85 } |
87 | 86 |
88 WebVector<WebImage> WebImage::framesFromData(const WebData& data) | 87 WebVector<WebImage> WebImage::framesFromData(const WebData& data) |
89 { | 88 { |
90 // This is to protect from malicious images. It should be big enough that it
's never hit in pracice. | 89 // This is to protect from malicious images. It should be big enough that it
's never hit in pracice. |
91 const size_t maxFrameCount = 8; | 90 const size_t maxFrameCount = 8; |
92 | 91 |
93 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); | 92 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); |
94 OwnPtr<ImageDecoder> decoder(ImageDecoder::create(*buffer.get(), ImageDecode
r::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgnored)); | 93 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(*buffer.get(), Im
ageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgnored)); |
95 if (!decoder) | 94 if (!decoder) |
96 return WebVector<WebImage>(); | 95 return WebVector<WebImage>(); |
97 | 96 |
98 decoder->setData(buffer.get(), true); | 97 decoder->setData(buffer.get(), true); |
99 if (!decoder->isSizeAvailable()) | 98 if (!decoder->isSizeAvailable()) |
100 return WebVector<WebImage>(); | 99 return WebVector<WebImage>(); |
101 | 100 |
102 // Frames are arranged by decreasing size, then decreasing bit depth. | 101 // Frames are arranged by decreasing size, then decreasing bit depth. |
103 // Keep the first frame at every size, has the highest bit depth. | 102 // Keep the first frame at every size, has the highest bit depth. |
104 const size_t frameCount = decoder->frameCount(); | 103 const size_t frameCount = decoder->frameCount(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 WebImage::WebImage(const PassRefPtr<Image>& image) | 145 WebImage::WebImage(const PassRefPtr<Image>& image) |
147 { | 146 { |
148 if (!image) | 147 if (!image) |
149 return; | 148 return; |
150 | 149 |
151 if (RefPtr<SkImage> skImage = image->imageForCurrentFrame()) | 150 if (RefPtr<SkImage> skImage = image->imageForCurrentFrame()) |
152 skImage->asLegacyBitmap(&m_bitmap, SkImage::kRO_LegacyBitmapMode); | 151 skImage->asLegacyBitmap(&m_bitmap, SkImage::kRO_LegacyBitmapMode); |
153 } | 152 } |
154 | 153 |
155 } // namespace blink | 154 } // namespace blink |
OLD | NEW |