diff options
Diffstat (limited to 'Source/WebCore/platform/image-decoders/ico')
-rw-r--r-- | Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp | 65 | ||||
-rw-r--r-- | Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.h | 38 |
2 files changed, 47 insertions, 56 deletions
diff --git a/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp b/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp index 33869f8c8..64c2c358a 100644 --- a/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp +++ b/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp @@ -35,7 +35,6 @@ #include "BMPImageReader.h" #include "PNGImageDecoder.h" -#include <wtf/PassOwnPtr.h> namespace WebCore { @@ -45,8 +44,7 @@ namespace WebCore { static const size_t sizeOfDirectory = 6; static const size_t sizeOfDirEntry = 16; -ICOImageDecoder::ICOImageDecoder(ImageSource::AlphaOption alphaOption, - ImageSource::GammaAndColorProfileOption gammaAndColorProfileOption) +ICOImageDecoder::ICOImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption) : ImageDecoder(alphaOption, gammaAndColorProfileOption) , m_decodedOffset(0) { @@ -56,7 +54,7 @@ ICOImageDecoder::~ICOImageDecoder() { } -void ICOImageDecoder::setData(SharedBuffer* data, bool allDataReceived) +void ICOImageDecoder::setData(SharedBuffer& data, bool allDataReceived) { if (failed()) return; @@ -65,7 +63,7 @@ void ICOImageDecoder::setData(SharedBuffer* data, bool allDataReceived) for (BMPReaders::iterator i(m_bmpReaders.begin()); i != m_bmpReaders.end(); ++i) { if (*i) - (*i)->setData(data); + (*i)->setData(&data); } for (size_t i = 0; i < m_pngDecoders.size(); ++i) setDataForPNGDecoderAtIndex(i); @@ -79,34 +77,26 @@ bool ICOImageDecoder::isSizeAvailable() return ImageDecoder::isSizeAvailable(); } -IntSize ICOImageDecoder::size() const +IntSize ICOImageDecoder::size() { return m_frameSize.isEmpty() ? ImageDecoder::size() : m_frameSize; } -IntSize ICOImageDecoder::frameSizeAtIndex(size_t index) const +IntSize ICOImageDecoder::frameSizeAtIndex(size_t index, SubsamplingLevel) { return (index && (index < m_dirEntries.size())) ? m_dirEntries[index].m_size : size(); } -bool ICOImageDecoder::setSize(unsigned width, unsigned height) +bool ICOImageDecoder::setSize(const IntSize& size) { // The size calculated inside the BMPImageReader had better match the one in // the icon directory. - return m_frameSize.isEmpty() ? ImageDecoder::setSize(width, height) : ((IntSize(width, height) == m_frameSize) || setFailed()); + return m_frameSize.isEmpty() ? ImageDecoder::setSize(size) : ((size == m_frameSize) || setFailed()); } -size_t ICOImageDecoder::frameCount() +size_t ICOImageDecoder::frameCount() const { - decode(0, true); - if (m_frameBufferCache.isEmpty()) { - m_frameBufferCache.resize(m_dirEntries.size()); - for (size_t i = 0; i < m_dirEntries.size(); ++i) - m_frameBufferCache[i].setPremultiplyAlpha(m_premultiplyAlpha); - } - // CAUTION: We must not resize m_frameBufferCache again after this, as - // decodeAtIndex() may give a BMPImageReader a pointer to one of the - // entries. + const_cast<ICOImageDecoder*>(this)->decode(0, true); return m_frameBufferCache.size(); } @@ -117,7 +107,7 @@ ImageFrame* ICOImageDecoder::frameBufferAtIndex(size_t index) return 0; ImageFrame* buffer = &m_frameBufferCache[index]; - if (buffer->status() != ImageFrame::FrameComplete) + if (!buffer->isComplete()) decode(index, false); return buffer; } @@ -129,21 +119,20 @@ bool ICOImageDecoder::setFailed() return ImageDecoder::setFailed(); } -bool ICOImageDecoder::hotSpot(IntPoint& hotSpot) const +std::optional<IntPoint> ICOImageDecoder::hotSpot() const { // When unspecified, the default frame is always frame 0. This is consistent with // BitmapImage where currentFrame() starts at 0 and only increases when animation is // requested. - return hotSpotAtIndex(0, hotSpot); + return hotSpotAtIndex(0); } -bool ICOImageDecoder::hotSpotAtIndex(size_t index, IntPoint& hotSpot) const +std::optional<IntPoint> ICOImageDecoder::hotSpotAtIndex(size_t index) const { if (index >= m_dirEntries.size() || m_fileType != CURSOR) - return false; + return std::nullopt; - hotSpot = m_dirEntries[index].m_hotSpot; - return true; + return m_dirEntries[index].m_hotSpot; } @@ -166,7 +155,7 @@ void ICOImageDecoder::setDataForPNGDecoderAtIndex(size_t index) // FIXME: Save this copy by making the PNG decoder able to take an // optional offset. RefPtr<SharedBuffer> pngData(SharedBuffer::create(&m_data->data()[dirEntry.m_imageOffset], m_data->size() - dirEntry.m_imageOffset)); - m_pngDecoders[index]->setData(pngData.get(), isAllDataReceived()); + m_pngDecoders[index]->setData(*pngData, isAllDataReceived()); } void ICOImageDecoder::decode(size_t index, bool onlySize) @@ -181,10 +170,16 @@ void ICOImageDecoder::decode(size_t index, bool onlySize) // If we're done decoding this frame, we don't need the BMPImageReader or // PNGImageDecoder anymore. (If we failed, these have already been // cleared.) - else if ((m_frameBufferCache.size() > index) && (m_frameBufferCache[index].status() == ImageFrame::FrameComplete)) { - m_bmpReaders[index].clear(); - m_pngDecoders[index].clear(); + else if ((m_frameBufferCache.size() > index) && m_frameBufferCache[index].isComplete()) { + m_bmpReaders[index] = nullptr; + m_pngDecoders[index] = nullptr; } + + if (m_frameBufferCache.isEmpty()) + m_frameBufferCache.resize(m_dirEntries.size()); + // CAUTION: We must not resize m_frameBufferCache again after this, as + // decodeAtIndex() may give a BMPImageReader a pointer to one of the + // entries. } bool ICOImageDecoder::decodeDirectory() @@ -210,7 +205,7 @@ bool ICOImageDecoder::decodeAtIndex(size_t index) // We need to have already sized m_frameBufferCache before this, and // we must not resize it again later (see caution in frameCount()). ASSERT(m_frameBufferCache.size() == m_dirEntries.size()); - m_bmpReaders[index] = adoptPtr(new BMPImageReader(this, dirEntry.m_imageOffset, 0, true)); + m_bmpReaders[index] = std::make_unique<BMPImageReader>(this, dirEntry.m_imageOffset, 0, true); m_bmpReaders[index]->setData(m_data.get()); m_bmpReaders[index]->setBuffer(&m_frameBufferCache[index]); } @@ -221,9 +216,9 @@ bool ICOImageDecoder::decodeAtIndex(size_t index) } if (!m_pngDecoders[index]) { - m_pngDecoders[index] = adoptPtr( - new PNGImageDecoder(m_premultiplyAlpha ? ImageSource::AlphaPremultiplied : ImageSource::AlphaNotPremultiplied, - m_ignoreGammaAndColorProfile ? ImageSource::GammaAndColorProfileIgnored : ImageSource::GammaAndColorProfileApplied)); + m_pngDecoders[index] = std::make_unique< + PNGImageDecoder>(m_premultiplyAlpha ? AlphaOption::Premultiplied : AlphaOption::NotPremultiplied, + m_ignoreGammaAndColorProfile ? GammaAndColorProfileOption::Ignored : GammaAndColorProfileOption::Applied); setDataForPNGDecoderAtIndex(index); } // Fail if the size the PNGImageDecoder calculated does not match the size @@ -281,7 +276,7 @@ bool ICOImageDecoder::processDirectoryEntries() const IconDirectoryEntry& dirEntry = m_dirEntries.first(); // Technically, this next call shouldn't be able to fail, since the width // and height here are each <= 256, and |m_frameSize| is empty. - return setSize(dirEntry.m_size.width(), dirEntry.m_size.height()); + return setSize(dirEntry.m_size); } ICOImageDecoder::IconDirectoryEntry ICOImageDecoder::readDirectoryEntry() diff --git a/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.h b/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.h index a909deb80..b1bc5ade6 100644 --- a/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.h +++ b/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.h @@ -28,8 +28,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef ICOImageDecoder_h -#define ICOImageDecoder_h +#pragma once #include "BMPImageReader.h" @@ -38,25 +37,25 @@ namespace WebCore { class PNGImageDecoder; // This class decodes the ICO and CUR image formats. - class ICOImageDecoder : public ImageDecoder { + class ICOImageDecoder final : public ImageDecoder { public: - ICOImageDecoder(ImageSource::AlphaOption, ImageSource::GammaAndColorProfileOption); + ICOImageDecoder(AlphaOption, GammaAndColorProfileOption); virtual ~ICOImageDecoder(); // ImageDecoder - virtual String filenameExtension() const { return "ico"; } - virtual void setData(SharedBuffer*, bool allDataReceived); - virtual bool isSizeAvailable(); - virtual IntSize size() const; - virtual IntSize frameSizeAtIndex(size_t) const; - virtual bool setSize(unsigned width, unsigned height); - virtual size_t frameCount(); - virtual ImageFrame* frameBufferAtIndex(size_t); + String filenameExtension() const override { return "ico"; } + void setData(SharedBuffer&, bool allDataReceived) override; + bool isSizeAvailable() override; + IntSize size() override; + IntSize frameSizeAtIndex(size_t, SubsamplingLevel) override; + bool setSize(const IntSize&) override; + size_t frameCount() const override; + ImageFrame* frameBufferAtIndex(size_t) override; // CAUTION: setFailed() deletes all readers and decoders. Be careful to // avoid accessing deleted memory, especially when calling this from // inside BMPImageReader! - virtual bool setFailed(); - virtual bool hotSpot(IntPoint&) const; + bool setFailed() override; + std::optional<IntPoint> hotSpot() const override; private: enum ImageType { @@ -116,9 +115,8 @@ namespace WebCore { // could be decoded. bool processDirectoryEntries(); - // Stores the hot-spot for |index| in |hotSpot| and returns true, - // or returns false if there is none. - bool hotSpotAtIndex(size_t index, IntPoint& hotSpot) const; + // Returns the hot-spot for |index|, returns std::nullopt if there is none. + std::optional<IntPoint> hotSpotAtIndex(size_t) const; // Reads and returns a directory entry from the current offset into // |data|. @@ -141,9 +139,9 @@ namespace WebCore { IconDirectoryEntries m_dirEntries; // The image decoders for the various frames. - typedef Vector<OwnPtr<BMPImageReader> > BMPReaders; + typedef Vector<std::unique_ptr<BMPImageReader>> BMPReaders; BMPReaders m_bmpReaders; - typedef Vector<OwnPtr<PNGImageDecoder> > PNGDecoders; + typedef Vector<std::unique_ptr<PNGImageDecoder>> PNGDecoders; PNGDecoders m_pngDecoders; // Valid only while a BMPImageReader is decoding, this holds the size @@ -152,5 +150,3 @@ namespace WebCore { }; } // namespace WebCore - -#endif |