| 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(*buffer.get(), Im
ageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgnored)); | 49 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(ImageDecoder::det
ermineImageType(*buffer.get()), ImageDecoder::AlphaPremultiplied, ImageDecoder::
GammaAndColorProfileIgnored)); |
| 50 if (!decoder) | 50 if (!decoder) |
| 51 return WebImage(); | 51 return WebImage(); |
| 52 | 52 |
| 53 decoder->setData(buffer.get(), true); | 53 decoder->setData(buffer.get(), true); |
| 54 if (!decoder->isSizeAvailable()) | 54 if (!decoder->isSizeAvailable()) |
| 55 return WebImage(); | 55 return WebImage(); |
| 56 | 56 |
| 57 // Frames are arranged by decreasing size, then decreasing bit depth. | 57 // Frames are arranged by decreasing size, then decreasing bit depth. |
| 58 // Pick the frame closest to |desiredSize|'s area without being smaller, | 58 // Pick the frame closest to |desiredSize|'s area without being smaller, |
| 59 // which has the highest bit depth. | 59 // which has the highest bit depth. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 83 | 83 |
| 84 return WebImage(frame->bitmap()); | 84 return WebImage(frame->bitmap()); |
| 85 } | 85 } |
| 86 | 86 |
| 87 WebVector<WebImage> WebImage::framesFromData(const WebData& data) | 87 WebVector<WebImage> WebImage::framesFromData(const WebData& data) |
| 88 { | 88 { |
| 89 // 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. |
| 90 const size_t maxFrameCount = 8; | 90 const size_t maxFrameCount = 8; |
| 91 | 91 |
| 92 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); | 92 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); |
| 93 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(*buffer.get(), Im
ageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgnored)); | 93 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(ImageDecoder::det
ermineImageType(*buffer.get()), ImageDecoder::AlphaPremultiplied, ImageDecoder::
GammaAndColorProfileIgnored)); |
| 94 if (!decoder) | 94 if (!decoder) |
| 95 return WebVector<WebImage>(); | 95 return WebVector<WebImage>(); |
| 96 | 96 |
| 97 decoder->setData(buffer.get(), true); | 97 decoder->setData(buffer.get(), true); |
| 98 if (!decoder->isSizeAvailable()) | 98 if (!decoder->isSizeAvailable()) |
| 99 return WebVector<WebImage>(); | 99 return WebVector<WebImage>(); |
| 100 | 100 |
| 101 // Frames are arranged by decreasing size, then decreasing bit depth. | 101 // Frames are arranged by decreasing size, then decreasing bit depth. |
| 102 // 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. |
| 103 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... |
| 145 WebImage::WebImage(const PassRefPtr<Image>& image) | 145 WebImage::WebImage(const PassRefPtr<Image>& image) |
| 146 { | 146 { |
| 147 if (!image) | 147 if (!image) |
| 148 return; | 148 return; |
| 149 | 149 |
| 150 if (RefPtr<SkImage> skImage = image->imageForCurrentFrame()) | 150 if (RefPtr<SkImage> skImage = image->imageForCurrentFrame()) |
| 151 skImage->asLegacyBitmap(&m_bitmap, SkImage::kRO_LegacyBitmapMode); | 151 skImage->asLegacyBitmap(&m_bitmap, SkImage::kRO_LegacyBitmapMode); |
| 152 } | 152 } |
| 153 | 153 |
| 154 } // namespace blink | 154 } // namespace blink |
| OLD | NEW |