Commit 10e5b780 authored by pkasting@chromium.org's avatar pkasting@chromium.org

2009-06-12 Peter Kasting <pkasting@google.com>

        Reviewed by Eric Seidel.

        https://bugs.webkit.org/show_bug.cgi?id=25709 part eight
        Replace placeholder Cairo BMP, ICO, XBM decoders with real ones.  Remove
        all the decoders from skia/ since they are now just mirrors of the Cairo
        ones.

        * GNUmakefile.am:
        * WebCore.vcproj/WebCore.vcproj:
        * WebCoreSources.bkl:
        * platform/graphics/cairo/ImageSourceCairo.cpp:
        (WebCore::createDecoder): Pass IntSize() to ICOImageDecoder() so it will always decode the largest icon.  Enable XBM decoding on Windows.
        * platform/graphics/skia/ImageSourceSkia.cpp:
        * platform/graphics/wx/ImageSourceWx.cpp:
        (WebCore::createDecoder): Pass IntSize() to ICOImageDecoder() so it will always decode the largest icon.
        * platform/image-decoders/bmp/BMPImageDecoder.cpp: Replaced with WebCore/platform/image-decoders/skia/BMPImageDecoder.cpp.
        * platform/image-decoders/bmp/BMPImageDecoder.h: Replaced with WebCore/platform/image-decoders/skia/BMPImageDecoder.h.
        * platform/image-decoders/bmp/BMPImageReader.cpp: Copied from WebCore/platform/image-decoders/skia/BMPImageReader.cpp.
        * platform/image-decoders/bmp/BMPImageReader.h: Copied from WebCore/platform/image-decoders/skia/BMPImageReader.h.
        * platform/image-decoders/ico/ICOImageDecoder.cpp: Replaced with WebCore/platform/image-decoders/skia/ICOImageDecoder.cpp.
        * platform/image-decoders/ico/ICOImageDecoder.h: Replaced with WebCore/platform/image-decoders/skia/ICOImageDecoder.h.
        * platform/image-decoders/skia/BMPImageDecoder.cpp: Removed.
        * platform/image-decoders/skia/BMPImageDecoder.h: Removed.
        * platform/image-decoders/skia/BMPImageReader.cpp: Removed.
        * platform/image-decoders/skia/BMPImageReader.h: Removed.
        * platform/image-decoders/skia/GIFImageDecoder.cpp: Removed.
        * platform/image-decoders/skia/GIFImageDecoder.h: Removed.
        * platform/image-decoders/skia/GIFImageReader.cpp: Removed.
        * platform/image-decoders/skia/GIFImageReader.h: Removed.
        * platform/image-decoders/skia/ICOImageDecoder.cpp: Removed.
        * platform/image-decoders/skia/ICOImageDecoder.h: Removed.
        * platform/image-decoders/skia/JPEGImageDecoder.cpp: Removed.
        * platform/image-decoders/skia/JPEGImageDecoder.h: Removed.
        * platform/image-decoders/skia/PNGImageDecoder.cpp: Removed.
        * platform/image-decoders/skia/PNGImageDecoder.h: Removed.
        * platform/image-decoders/skia/XBMImageDecoder.cpp: Removed.
        * platform/image-decoders/skia/XBMImageDecoder.h: Removed.
        * platform/image-decoders/xbm/XBMImageDecoder.cpp: Replaced with WebCore/platform/image-decoders/skia/XBMImageDecoder.cpp.
        * platform/image-decoders/xbm/XBMImageDecoder.h: Replaced with WebCore/platform/image-decoders/skia/XBMImageDecoder.h.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@44634 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c2c22c62
2009-06-12 Peter Kasting <pkasting@google.com>
Reviewed by Eric Seidel.
https://bugs.webkit.org/show_bug.cgi?id=25709 part eight
Replace placeholder Cairo BMP, ICO, XBM decoders with real ones. Remove
all the decoders from skia/ since they are now just mirrors of the Cairo
ones.
* GNUmakefile.am:
* WebCore.vcproj/WebCore.vcproj:
* WebCoreSources.bkl:
* platform/graphics/cairo/ImageSourceCairo.cpp:
(WebCore::createDecoder): Pass IntSize() to ICOImageDecoder() so it will always decode the largest icon. Enable XBM decoding on Windows.
* platform/graphics/skia/ImageSourceSkia.cpp:
* platform/graphics/wx/ImageSourceWx.cpp:
(WebCore::createDecoder): Pass IntSize() to ICOImageDecoder() so it will always decode the largest icon.
* platform/image-decoders/bmp/BMPImageDecoder.cpp: Replaced with WebCore/platform/image-decoders/skia/BMPImageDecoder.cpp.
* platform/image-decoders/bmp/BMPImageDecoder.h: Replaced with WebCore/platform/image-decoders/skia/BMPImageDecoder.h.
* platform/image-decoders/bmp/BMPImageReader.cpp: Copied from WebCore/platform/image-decoders/skia/BMPImageReader.cpp.
* platform/image-decoders/bmp/BMPImageReader.h: Copied from WebCore/platform/image-decoders/skia/BMPImageReader.h.
* platform/image-decoders/ico/ICOImageDecoder.cpp: Replaced with WebCore/platform/image-decoders/skia/ICOImageDecoder.cpp.
* platform/image-decoders/ico/ICOImageDecoder.h: Replaced with WebCore/platform/image-decoders/skia/ICOImageDecoder.h.
* platform/image-decoders/skia/BMPImageDecoder.cpp: Removed.
* platform/image-decoders/skia/BMPImageDecoder.h: Removed.
* platform/image-decoders/skia/BMPImageReader.cpp: Removed.
* platform/image-decoders/skia/BMPImageReader.h: Removed.
* platform/image-decoders/skia/GIFImageDecoder.cpp: Removed.
* platform/image-decoders/skia/GIFImageDecoder.h: Removed.
* platform/image-decoders/skia/GIFImageReader.cpp: Removed.
* platform/image-decoders/skia/GIFImageReader.h: Removed.
* platform/image-decoders/skia/ICOImageDecoder.cpp: Removed.
* platform/image-decoders/skia/ICOImageDecoder.h: Removed.
* platform/image-decoders/skia/JPEGImageDecoder.cpp: Removed.
* platform/image-decoders/skia/JPEGImageDecoder.h: Removed.
* platform/image-decoders/skia/PNGImageDecoder.cpp: Removed.
* platform/image-decoders/skia/PNGImageDecoder.h: Removed.
* platform/image-decoders/skia/XBMImageDecoder.cpp: Removed.
* platform/image-decoders/skia/XBMImageDecoder.h: Removed.
* platform/image-decoders/xbm/XBMImageDecoder.cpp: Replaced with WebCore/platform/image-decoders/skia/XBMImageDecoder.cpp.
* platform/image-decoders/xbm/XBMImageDecoder.h: Replaced with WebCore/platform/image-decoders/skia/XBMImageDecoder.h.
2009-06-11 Peter Kasting <pkasting@google.com>
Reviewed by Eric Seidel.
......@@ -1862,6 +1862,8 @@ webcoregtk_sources += \
WebCore/platform/image-decoders/ImageDecoder.h \
WebCore/platform/image-decoders/bmp/BMPImageDecoder.cpp \
WebCore/platform/image-decoders/bmp/BMPImageDecoder.h \
WebCore/platform/image-decoders/bmp/BMPImageReader.cpp \
WebCore/platform/image-decoders/bmp/BMPImageReader.h \
WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp \
WebCore/platform/image-decoders/gif/GIFImageDecoder.h \
WebCore/platform/image-decoders/gif/GIFImageReader.cpp \
......
......@@ -6578,6 +6578,62 @@
/>
</FileConfiguration>
</File>
<File
RelativePath="..\platform\image-decoders\bmp\BMPImageReader.cpp"
>
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug_Internal|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\platform\image-decoders\bmp\BMPImageReader.h"
>
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCustomBuildTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCustomBuildTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug_Internal|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCustomBuildTool"
/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="ico"
......
......@@ -891,7 +891,8 @@ This file contains the list of files needed to build WebCore.
</set>
<set append="1" var="WEBCORE_SOURCES_BMP">
platform/image-decoders/bmp/BMPImageDecoder.cpp
platform/image-decoders/bmp/BMPImageDecoder.cpp
platform/image-decoders/bmp/BMPImageReader.cpp
</set>
<set append="1" var="WEBCORE_SOURCES_ICO">
......
......@@ -34,13 +34,10 @@
#include "ICOImageDecoder.h"
#include "JPEGImageDecoder.h"
#include "PNGImageDecoder.h"
#include "XBMImageDecoder.h"
#include "SharedBuffer.h"
#include <cairo.h>
#if !PLATFORM(WIN)
#include "XBMImageDecoder.h"
#endif
namespace WebCore {
ImageDecoder* createDecoder(const Vector<char>& data)
......@@ -78,13 +75,11 @@ ImageDecoder* createDecoder(const Vector<char>& data)
// CURs begin with 2-byte 0 followed by 2-byte 2.
if (!memcmp(contents, "\000\000\001\000", 4) ||
!memcmp(contents, "\000\000\002\000", 4))
return new ICOImageDecoder();
return new ICOImageDecoder(IntSize());
#if !PLATFORM(WIN)
// XBMs require 8 bytes of info.
if (length >= 8 && strncmp(contents, "#define ", 8) == 0)
return new XBMImageDecoder();
#endif
// Give up. We don't know what the heck this is.
return 0;
......
......@@ -34,11 +34,11 @@
#include "SharedBuffer.h"
#include "GIFImageDecoder.h"
#include "ICOImageDecoder.h"
#include "JPEGImageDecoder.h"
#include "PNGImageDecoder.h"
#include "BMPImageDecoder.h"
#include "XBMImageDecoder.h"
#include "ICOImageDecoder.h"
#include "SkBitmap.h"
......
......@@ -80,7 +80,7 @@ ImageDecoder* createDecoder(const SharedBuffer& data)
// CURs begin with 2-byte 0 followed by 2-byte 2.
if (!memcmp(contents, "\000\000\001\000", 4) ||
!memcmp(contents, "\000\000\002\000", 4))
return new ICOImageDecoder();
return new ICOImageDecoder(IntSize());
// XBMs require 8 bytes of info.
if (length >= 8 && strncmp(contents, "#define ", 8) == 0)
......
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* Copyright (c) 2008, 2009, Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "BMPImageDecoder.h"
namespace WebCore
{
namespace WebCore {
bool BMPImageDecoder::isSizeAvailable() const
// Number of bits in .BMP used to store the file header (doesn't match
// "sizeof(BMPImageDecoder::BitmapFileHeader)" since we omit some fields and
// don't pack).
static const size_t sizeOfFileHeader = 14;
void BMPImageDecoder::decodeImage(SharedBuffer* data)
{
return false;
// Read and process file header.
if ((m_decodedOffset < sizeOfFileHeader) && !processFileHeader(data))
return;
// Decode BMP.
decodeBMP(data);
}
RGBA32Buffer* BMPImageDecoder::frameBufferAtIndex(size_t index)
bool BMPImageDecoder::processFileHeader(SharedBuffer* data)
{
return 0;
// Read file header.
ASSERT(!m_decodedOffset);
if (data->size() < sizeOfFileHeader)
return false;
const uint16_t fileType =
(data->data()[0] << 8) | static_cast<uint8_t>(data->data()[1]);
m_imgDataOffset = readUint32(data, 10);
m_decodedOffset = m_headerOffset = sizeOfFileHeader;
// See if this is a bitmap filetype we understand.
enum {
BMAP = 'BM',
// The following additional OS/2 2.x header values (see
// http://www.fileformat.info/format/os2bmp/egff.htm ) aren't widely
// decoded, and are unlikely to be in much use.
/*
ICON = 'IC',
POINTER = 'PT',
COLORICON = 'CI',
COLORPOINTER = 'CP',
BITMAPARRAY = 'BA',
*/
};
if (fileType != BMAP)
m_failed = true;
return !m_failed;
}
} // namespace WebCore
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* Copyright (c) 2008, 2009, Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef BMPImageDecoder_h
#define BMPImageDecoder_h
#include "ImageDecoder.h"
#include "BMPImageReader.h"
namespace WebCore {
class BMPImageReader;
// This class decodes the BMP image format.
class BMPImageDecoder : public ImageDecoder {
class BMPImageDecoder : public BMPImageReader {
public:
virtual String filenameExtension() const { return "bmp"; }
// Whether or not the size information has been decoded yet.
virtual bool isSizeAvailable() const;
// BMPImageReader
virtual void decodeImage(SharedBuffer*);
virtual RGBA32Buffer* frameBufferAtIndex(size_t index);
private:
// Processes the file header at the beginning of the data. Returns true if
// the file header could be decoded.
bool processFileHeader(SharedBuffer*);
};
} // namespace WebCore
......
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
* Copyright (c) 2008, 2009, Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "ICOImageDecoder.h"
namespace WebCore
namespace WebCore {
// Number of bits in .ICO/.CUR used to store the directory and its entries,
// respectively (doesn't match sizeof values for member structs since we omit
// some fields).
static const size_t sizeOfDirectory = 6;
static const size_t sizeOfDirEntry = 16;
void ICOImageDecoder::decodeImage(SharedBuffer* data)
{
// Read and process directory.
if ((m_decodedOffset < sizeOfDirectory) && !processDirectory(data))
return;
// Read and process directory entries.
if ((m_decodedOffset < (sizeOfDirectory + (m_directory.idCount * sizeOfDirEntry)))
&& !processDirectoryEntries(data))
return;
// Check if this entry is a PNG; we need 4 bytes to check the magic number.
if (m_imageType == Unknown) {
if (data->size() < (m_dirEntry.dwImageOffset + 4))
return;
m_imageType =
strncmp(&data->data()[m_dirEntry.dwImageOffset], "\x89PNG", 4) ?
BMP : PNG;
}
// Decode selected entry.
if (m_imageType == PNG)
decodePNG(data);
else {
// Note that we don't try to limit the bytes we give to the decoder to
// just the size specified in the icon directory. If the size given in
// the directory is insufficient to decode the whole image, the image is
// corrupt anyway, so whatever we do may be wrong. The easiest choice
// (which we do here) is to simply aggressively consume bytes until we
// run out of bytes, finish decoding, or hit a sequence that makes the
// decoder fail.
decodeBMP(data);
}
}
RGBA32Buffer* ICOImageDecoder::frameBufferAtIndex(size_t index)
{
return (m_imageType == PNG) ? m_pngDecoder.frameBufferAtIndex(0) :
BMPImageReader::frameBufferAtIndex(0);
}
bool ICOImageDecoder::isSizeAvailable() const
{
return false;
return (m_imageType == PNG) ? m_pngDecoder.isSizeAvailable() :
BMPImageReader::isSizeAvailable();
}
RGBA32Buffer* ICOImageDecoder::frameBufferAtIndex(size_t index)
IntSize ICOImageDecoder::size() const
{
return (m_imageType == PNG) ? m_pngDecoder.size() : BMPImageReader::size();
}
bool ICOImageDecoder::processDirectory(SharedBuffer* data)
{
return 0;
// Read directory.
ASSERT(!m_decodedOffset);
if (data->size() < sizeOfDirectory)
return false;
const uint16_t fileType = readUint16(data, 2);
m_directory.idCount = readUint16(data, 4);
m_decodedOffset = sizeOfDirectory;
// See if this is an icon filetype we understand, and make sure we have at
// least one entry in the directory.
enum {
ICON = 1,
CURSOR = 2,
};
if (((fileType != ICON) && (fileType != CURSOR)) ||
(m_directory.idCount == 0))
m_failed = true;
return !m_failed;
}
} // namespace WebCore
bool ICOImageDecoder::processDirectoryEntries(SharedBuffer* data)
{
// Read directory entries.
ASSERT(m_decodedOffset == sizeOfDirectory);
if ((m_decodedOffset > data->size()) || (data->size() - m_decodedOffset) <
(m_directory.idCount * sizeOfDirEntry))
return false;
for (int i = 0; i < m_directory.idCount; ++i) {
const IconDirectoryEntry dirEntry = readDirectoryEntry(data);
if ((i == 0) || isBetterEntry(dirEntry))
m_dirEntry = dirEntry;
}
// Make sure the specified image offset is past the end of the directory
// entries, and that the offset isn't so large that it overflows when we add
// 4 bytes to it (which we do in decodeImage() while ensuring it's safe to
// examine the first 4 bytes of the image data).
if ((m_dirEntry.dwImageOffset < m_decodedOffset) ||
((m_dirEntry.dwImageOffset + 4) < m_dirEntry.dwImageOffset)) {
m_failed = true;
return false;
}
// Ready to decode the image at the specified offset.
m_decodedOffset = m_headerOffset = m_dirEntry.dwImageOffset;
return true;
}
ICOImageDecoder::IconDirectoryEntry ICOImageDecoder::readDirectoryEntry(
SharedBuffer* data)
{
// Read icon data.
IconDirectoryEntry entry;
entry.bWidth = static_cast<uint8_t>(data->data()[m_decodedOffset]);
if (entry.bWidth == 0)
entry.bWidth = 256;
entry.bHeight = static_cast<uint8_t>(data->data()[m_decodedOffset + 1]);
if (entry.bHeight == 0)
entry.bHeight = 256;
entry.wBitCount = readUint16(data, 6);
entry.dwImageOffset = readUint32(data, 12);
// Some icons don't have a bit depth, only a color count. Convert the
// color count to the minimum necessary bit depth. It doesn't matter if
// this isn't quite what the bitmap info header says later, as we only use
// this value to determine which icon entry is best.
if (!entry.wBitCount) {
uint8_t colorCount = data->data()[m_decodedOffset + 2];
if (colorCount) {
for (--colorCount; colorCount; colorCount >>= 1)
++entry.wBitCount;
}
}
m_decodedOffset += sizeOfDirEntry;
return entry;
}
bool ICOImageDecoder::isBetterEntry(const IconDirectoryEntry& entry) const
{
const IntSize entrySize(entry.bWidth, entry.bHeight);
const IntSize dirEntrySize(m_dirEntry.bWidth, m_dirEntry.bHeight);
const int entryArea = entry.bWidth * entry.bHeight;
const int dirEntryArea = m_dirEntry.bWidth * m_dirEntry.bHeight;
if ((entrySize != dirEntrySize) && !m_preferredIconSize.isEmpty()) {
// An icon of exactly the preferred size is best.
if (entrySize == m_preferredIconSize)
return true;
if (dirEntrySize == m_preferredIconSize)
return false;
// The icon closest to the preferred area without being smaller is
// better.
if (entryArea != dirEntryArea) {
return (entryArea < dirEntryArea)
&& (entryArea >= (m_preferredIconSize.width() * m_preferredIconSize.height()));
}
}
// Larger icons are better.
if (entryArea != dirEntryArea)
return (entryArea > dirEntryArea);
// Higher bit-depth icons are better.
return (entry.wBitCount > m_dirEntry.wBitCount);
}
void ICOImageDecoder::decodePNG(SharedBuffer* data)
{
// Copy out PNG data to a separate vector and instantiate PNG decoder.
// It would be nice to save this copy, if I could figure out how to just
// offset the perceived start of |data| by |m_dirEntry.dwImageOffset| when
// passing it to setData()...
RefPtr<SharedBuffer> pngData(
SharedBuffer::create(&data->data()[m_dirEntry.dwImageOffset],
data->size() - m_dirEntry.dwImageOffset));
m_pngDecoder.setData(pngData.get(), true);