Example #1
0
ImageDecoder* ImageDecoder::create(const SharedBuffer& data, ImageSource::AlphaOption alphaOption, ImageSource::GammaAndColorProfileOption gammaAndColorProfileOption)
{
    static const unsigned lengthOfLongestSignature = 14; // To wit: "RIFF????WEBPVP"
    char contents[lengthOfLongestSignature];
    unsigned length = copyFromSharedBuffer(contents, lengthOfLongestSignature, data, 0);
    if (length < lengthOfLongestSignature)
        return 0;

    if (matchesGIFSignature(contents))
        return new GIFImageDecoder(alphaOption, gammaAndColorProfileOption);

    if (matchesPNGSignature(contents))
        return new PNGImageDecoder(alphaOption, gammaAndColorProfileOption);

    if (matchesJPEGSignature(contents))
        return new JPEGImageDecoder(alphaOption, gammaAndColorProfileOption);

#if USE(WEBP)
    if (matchesWebPSignature(contents))
        return new WEBPImageDecoder(alphaOption, gammaAndColorProfileOption);
#endif

    if (matchesBMPSignature(contents))
        return new BMPImageDecoder(alphaOption, gammaAndColorProfileOption);

    if (matchesICOSignature(contents) || matchesCURSignature(contents))
        return new ICOImageDecoder(alphaOption, gammaAndColorProfileOption);

    return 0;
}
Example #2
0
PassOwnPtr<ImageDecoder> ImageDecoder::create(const SharedBuffer& data, ImageSource::AlphaOption alphaOption, ImageSource::GammaAndColorProfileOption gammaAndColorProfileOption)
{
    static const unsigned longestSignatureLength = sizeof("RIFF????WEBPVP") - 1;
    ASSERT(longestSignatureLength == 14);

    size_t maxDecodedBytes = Platform::current()->maxDecodedImageBytes();

    char contents[longestSignatureLength];
    if (copyFromSharedBuffer(contents, longestSignatureLength, data, 0) < longestSignatureLength)
        return nullptr;

    if (matchesJPEGSignature(contents))
        return adoptPtr(new JPEGImageDecoder(alphaOption, gammaAndColorProfileOption, maxDecodedBytes));

    if (matchesPNGSignature(contents))
        return adoptPtr(new PNGImageDecoder(alphaOption, gammaAndColorProfileOption, maxDecodedBytes));

    if (matchesGIFSignature(contents))
        return adoptPtr(new GIFImageDecoder(alphaOption, gammaAndColorProfileOption, maxDecodedBytes));

    if (matchesICOSignature(contents) || matchesCURSignature(contents))
        return adoptPtr(new ICOImageDecoder(alphaOption, gammaAndColorProfileOption, maxDecodedBytes));

    if (matchesWebPSignature(contents))
        return adoptPtr(new WEBPImageDecoder(alphaOption, gammaAndColorProfileOption, maxDecodedBytes));

    if (matchesBMPSignature(contents))
        return adoptPtr(new BMPImageDecoder(alphaOption, gammaAndColorProfileOption, maxDecodedBytes));

    return nullptr;
}
Example #3
0
ImageDecoder::SniffResult ImageDecoder::determineImageType(const char* contents,
                                                           size_t length) {
  DCHECK_GE(length, kLongestSignatureLength);

  if (matchesJPEGSignature(contents))
    return SniffResult::JPEG;
  if (matchesPNGSignature(contents))
    return SniffResult::PNG;
  if (matchesGIFSignature(contents))
    return SniffResult::GIF;
  if (matchesWebPSignature(contents))
    return SniffResult::WEBP;
  if (matchesICOSignature(contents) || matchesCURSignature(contents))
    return SniffResult::ICO;
  if (matchesBMPSignature(contents))
    return SniffResult::BMP;
  return SniffResult::Invalid;
}