Chromium Code Reviews| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 if (frameArea < (desiredSize.width * desiredSize.height)) | 71 if (frameArea < (desiredSize.width * desiredSize.height)) |
| 72 break; // No more frames that are large enough. | 72 break; // No more frames that are large enough. |
| 73 | 73 |
| 74 if (!i || (frameArea < frameAreaAtIndex)) { | 74 if (!i || (frameArea < frameAreaAtIndex)) { |
| 75 index = i; // Closer to desired area than previous best match. | 75 index = i; // Closer to desired area than previous best match. |
| 76 frameAreaAtIndex = frameArea; | 76 frameAreaAtIndex = frameArea; |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 ImageFrame* frame = decoder->frameBufferAtIndex(index); | 80 ImageFrame* frame = decoder->frameBufferAtIndex(index); |
| 81 if (!frame) | 81 if (!frame || decoder->failed()) |
| 82 return WebImage(); | 82 return WebImage(); |
| 83 | 83 |
| 84 return WebImage(frame->bitmap()); | 84 return WebImage(frame->bitmap()); |
|
Peter Kasting
2016/09/22 21:44:08
Nit: Shorter:
return (frame && !decoder->failed
aleksandar.stojiljkovic
2016/09/27 18:08:28
Done.
| |
| 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(ImageDecoder::det ermineImageType(*buffer.get()), ImageDecoder::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) |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 107 for (size_t i = 0; i < std::min(frameCount, maxFrameCount); ++i) { | 107 for (size_t i = 0; i < std::min(frameCount, maxFrameCount); ++i) { |
| 108 const IntSize frameSize = decoder->frameSizeAtIndex(i); | 108 const IntSize frameSize = decoder->frameSizeAtIndex(i); |
| 109 if (frameSize == lastSize) | 109 if (frameSize == lastSize) |
| 110 continue; | 110 continue; |
| 111 lastSize = frameSize; | 111 lastSize = frameSize; |
| 112 | 112 |
| 113 ImageFrame* frame = decoder->frameBufferAtIndex(i); | 113 ImageFrame* frame = decoder->frameBufferAtIndex(i); |
| 114 if (!frame) | 114 if (!frame) |
| 115 continue; | 115 continue; |
| 116 | 116 |
| 117 const SkBitmap& bitmap = frame->bitmap(); | 117 SkBitmap bitmap = frame->bitmap(); |
| 118 if (!bitmap.isNull() && bitmap.isImmutable()) | 118 if (!bitmap.isNull() && frame->getStatus() == ImageFrame::FrameComplete) { |
|
Peter Kasting
2016/09/22 21:44:08
Nit: No {}
aleksandar.stojiljkovic
2016/09/27 18:08:28
Done.
| |
| 119 frames.append(WebImage(bitmap)); | 119 frames.append(WebImage(bitmap)); |
| 120 } | |
| 120 } | 121 } |
| 121 | 122 |
| 122 return frames; | 123 return frames; |
| 123 } | 124 } |
| 124 | 125 |
| 125 void WebImage::reset() | 126 void WebImage::reset() |
| 126 { | 127 { |
| 127 m_bitmap.reset(); | 128 m_bitmap.reset(); |
| 128 } | 129 } |
| 129 | 130 |
| (...skipping 15 matching lines...) Expand all 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 |