| 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 28 matching lines...) Expand all Loading... |
| 39 #include "wtf/PassRefPtr.h" | 39 #include "wtf/PassRefPtr.h" |
| 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 { | 47 { |
| 48 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); | 48 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); |
| 49 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(ImageDecoder::det
ermineImageType(*buffer.get()), ImageDecoder::AlphaPremultiplied, ImageDecoder::
GammaAndColorProfileIgnored)); | 49 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(buffer, true, |
| 50 if (!decoder) | 50 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgno
red)); |
| 51 return WebImage(); | 51 if (!decoder || !decoder->isSizeAvailable()) |
| 52 | |
| 53 decoder->setData(buffer.get(), true); | |
| 54 if (!decoder->isSizeAvailable()) | |
| 55 return WebImage(); | 52 return WebImage(); |
| 56 | 53 |
| 57 // Frames are arranged by decreasing size, then decreasing bit depth. | 54 // Frames are arranged by decreasing size, then decreasing bit depth. |
| 58 // Pick the frame closest to |desiredSize|'s area without being smaller, | 55 // Pick the frame closest to |desiredSize|'s area without being smaller, |
| 59 // which has the highest bit depth. | 56 // which has the highest bit depth. |
| 60 const size_t frameCount = decoder->frameCount(); | 57 const size_t frameCount = decoder->frameCount(); |
| 61 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. |
| 62 int frameAreaAtIndex = 0; | 59 int frameAreaAtIndex = 0; |
| 63 for (size_t i = 0; i < frameCount; ++i) { | 60 for (size_t i = 0; i < frameCount; ++i) { |
| 64 const IntSize frameSize = decoder->frameSizeAtIndex(i); | 61 const IntSize frameSize = decoder->frameSizeAtIndex(i); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 83 | 80 |
| 84 return WebImage(frame->bitmap()); | 81 return WebImage(frame->bitmap()); |
| 85 } | 82 } |
| 86 | 83 |
| 87 WebVector<WebImage> WebImage::framesFromData(const WebData& data) | 84 WebVector<WebImage> WebImage::framesFromData(const WebData& data) |
| 88 { | 85 { |
| 89 // This is to protect from malicious images. It should be big enough that it
's never hit in pracice. | 86 // 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; | 87 const size_t maxFrameCount = 8; |
| 91 | 88 |
| 92 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); | 89 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); |
| 93 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(ImageDecoder::det
ermineImageType(*buffer.get()), ImageDecoder::AlphaPremultiplied, ImageDecoder::
GammaAndColorProfileIgnored)); | 90 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(buffer, true, |
| 94 if (!decoder) | 91 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgno
red)); |
| 95 return WebVector<WebImage>(); | 92 if (!decoder || !decoder->isSizeAvailable()) |
| 96 | |
| 97 decoder->setData(buffer.get(), true); | |
| 98 if (!decoder->isSizeAvailable()) | |
| 99 return WebVector<WebImage>(); | 93 return WebVector<WebImage>(); |
| 100 | 94 |
| 101 // Frames are arranged by decreasing size, then decreasing bit depth. | 95 // Frames are arranged by decreasing size, then decreasing bit depth. |
| 102 // Keep the first frame at every size, has the highest bit depth. | 96 // Keep the first frame at every size, has the highest bit depth. |
| 103 const size_t frameCount = decoder->frameCount(); | 97 const size_t frameCount = decoder->frameCount(); |
| 104 IntSize lastSize; | 98 IntSize lastSize; |
| 105 | 99 |
| 106 Vector<WebImage> frames; | 100 Vector<WebImage> frames; |
| 107 for (size_t i = 0; i < std::min(frameCount, maxFrameCount); ++i) { | 101 for (size_t i = 0; i < std::min(frameCount, maxFrameCount); ++i) { |
| 108 const IntSize frameSize = decoder->frameSizeAtIndex(i); | 102 const IntSize frameSize = decoder->frameSizeAtIndex(i); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 WebImage::WebImage(const PassRefPtr<Image>& image) | 139 WebImage::WebImage(const PassRefPtr<Image>& image) |
| 146 { | 140 { |
| 147 if (!image) | 141 if (!image) |
| 148 return; | 142 return; |
| 149 | 143 |
| 150 if (RefPtr<SkImage> skImage = image->imageForCurrentFrame()) | 144 if (RefPtr<SkImage> skImage = image->imageForCurrentFrame()) |
| 151 skImage->asLegacyBitmap(&m_bitmap, SkImage::kRO_LegacyBitmapMode); | 145 skImage->asLegacyBitmap(&m_bitmap, SkImage::kRO_LegacyBitmapMode); |
| 152 } | 146 } |
| 153 | 147 |
| 154 } // namespace blink | 148 } // namespace blink |
| OLD | NEW |