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 29 matching lines...) Expand all Loading... |
40 #include "wtf/Vector.h" | 40 #include "wtf/Vector.h" |
41 #include <algorithm> | 41 #include <algorithm> |
42 #include <memory> | 42 #include <memory> |
43 | 43 |
44 namespace blink { | 44 namespace blink { |
45 | 45 |
46 WebImage WebImage::fromData(const WebData& data, const WebSize& desiredSize) { | 46 WebImage WebImage::fromData(const WebData& data, const WebSize& desiredSize) { |
47 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); | 47 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); |
48 std::unique_ptr<ImageDecoder> decoder( | 48 std::unique_ptr<ImageDecoder> decoder( |
49 ImageDecoder::create(buffer, true, ImageDecoder::AlphaPremultiplied, | 49 ImageDecoder::create(buffer, true, ImageDecoder::AlphaPremultiplied, |
50 ImageDecoder::GammaAndColorProfileIgnored)); | 50 ImageDecoder::ColorSpaceIgnored)); |
51 if (!decoder || !decoder->isSizeAvailable()) | 51 if (!decoder || !decoder->isSizeAvailable()) |
52 return WebImage(); | 52 return WebImage(); |
53 | 53 |
54 // Frames are arranged by decreasing size, then decreasing bit depth. | 54 // Frames are arranged by decreasing size, then decreasing bit depth. |
55 // Pick the frame closest to |desiredSize|'s area without being smaller, | 55 // Pick the frame closest to |desiredSize|'s area without being smaller, |
56 // which has the highest bit depth. | 56 // which has the highest bit depth. |
57 const size_t frameCount = decoder->frameCount(); | 57 const size_t frameCount = decoder->frameCount(); |
58 size_t index = 0; // Default to first frame if none are large enough. | 58 size_t index = 0; // Default to first frame if none are large enough. |
59 int frameAreaAtIndex = 0; | 59 int frameAreaAtIndex = 0; |
60 for (size_t i = 0; i < frameCount; ++i) { | 60 for (size_t i = 0; i < frameCount; ++i) { |
(...skipping 18 matching lines...) Expand all Loading... |
79 } | 79 } |
80 | 80 |
81 WebVector<WebImage> WebImage::framesFromData(const WebData& data) { | 81 WebVector<WebImage> WebImage::framesFromData(const WebData& data) { |
82 // This is to protect from malicious images. It should be big enough that it's | 82 // This is to protect from malicious images. It should be big enough that it's |
83 // never hit in practice. | 83 // never hit in practice. |
84 const size_t maxFrameCount = 8; | 84 const size_t maxFrameCount = 8; |
85 | 85 |
86 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); | 86 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); |
87 std::unique_ptr<ImageDecoder> decoder( | 87 std::unique_ptr<ImageDecoder> decoder( |
88 ImageDecoder::create(buffer, true, ImageDecoder::AlphaPremultiplied, | 88 ImageDecoder::create(buffer, true, ImageDecoder::AlphaPremultiplied, |
89 ImageDecoder::GammaAndColorProfileIgnored)); | 89 ImageDecoder::ColorSpaceIgnored)); |
90 if (!decoder || !decoder->isSizeAvailable()) | 90 if (!decoder || !decoder->isSizeAvailable()) |
91 return WebVector<WebImage>(); | 91 return WebVector<WebImage>(); |
92 | 92 |
93 // Frames are arranged by decreasing size, then decreasing bit depth. | 93 // Frames are arranged by decreasing size, then decreasing bit depth. |
94 // Keep the first frame at every size, has the highest bit depth. | 94 // Keep the first frame at every size, has the highest bit depth. |
95 const size_t frameCount = decoder->frameCount(); | 95 const size_t frameCount = decoder->frameCount(); |
96 IntSize lastSize; | 96 IntSize lastSize; |
97 | 97 |
98 Vector<WebImage> frames; | 98 Vector<WebImage> frames; |
99 for (size_t i = 0; i < std::min(frameCount, maxFrameCount); ++i) { | 99 for (size_t i = 0; i < std::min(frameCount, maxFrameCount); ++i) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 132 |
133 WebImage::WebImage(PassRefPtr<Image> image) { | 133 WebImage::WebImage(PassRefPtr<Image> image) { |
134 if (!image) | 134 if (!image) |
135 return; | 135 return; |
136 | 136 |
137 if (sk_sp<SkImage> skImage = image->imageForCurrentFrame()) | 137 if (sk_sp<SkImage> skImage = image->imageForCurrentFrame()) |
138 skImage->asLegacyBitmap(&m_bitmap, SkImage::kRO_LegacyBitmapMode); | 138 skImage->asLegacyBitmap(&m_bitmap, SkImage::kRO_LegacyBitmapMode); |
139 } | 139 } |
140 | 140 |
141 } // namespace blink | 141 } // namespace blink |
OLD | NEW |