summaryrefslogtreecommitdiff
path: root/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp')
-rw-r--r--Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp65
1 files changed, 30 insertions, 35 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()