15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* 25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. 35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2008-2009 Torch Mobile, Inc. 45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions 75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * are met: 85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 1. Redistributions of source code must retain the above copyright 95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer. 105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright 115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer in the 125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * documentation and/or other materials provided with the distribution. 135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2402772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */ 265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef JPEGImageDecoder_h 285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define JPEGImageDecoder_h 295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 30a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/image-decoders/ImageDecoder.h" 315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 32a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "wtf/Noncopyable.h" 3393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "wtf/OwnPtr.h" 34926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)namespace WebCore { 365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 37a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)class JPEGImageReader; 385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 39a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)// This class decodes the JPEG image format. 40a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)class PLATFORM_EXPORT JPEGImageDecoder : public ImageDecoder { 41a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) WTF_MAKE_NONCOPYABLE(JPEGImageDecoder); 42a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)public: 43a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) JPEGImageDecoder(ImageSource::AlphaOption, ImageSource::GammaAndColorProfileOption, size_t maxDecodedBytes); 44a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) virtual ~JPEGImageDecoder(); 455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 46a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // ImageDecoder 47a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) virtual String filenameExtension() const OVERRIDE { return "jpg"; } 48a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) virtual bool isSizeAvailable() OVERRIDE; 49323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) virtual bool hasColorProfile() const OVERRIDE { return m_hasColorProfile; } 50a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) virtual IntSize decodedSize() const OVERRIDE { return m_decodedSize; } 51a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) virtual bool setSize(unsigned width, unsigned height) OVERRIDE; 52a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) virtual ImageFrame* frameBufferAtIndex(size_t) OVERRIDE; 53a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // CAUTION: setFailed() deletes |m_reader|. Be careful to avoid 54a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // accessing deleted memory, especially when calling this from inside 55a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // JPEGImageReader! 56a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) virtual bool setFailed() OVERRIDE; 575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 58a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) bool outputScanlines(); 59d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) unsigned desiredScaleNumerator() const; 60a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void jpegComplete(); 615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 62a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void setOrientation(ImageOrientation orientation) { m_orientation = orientation; } 63323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) void setHasColorProfile(bool hasColorProfile) { m_hasColorProfile = hasColorProfile; } 64d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) void setDecodedSize(unsigned width, unsigned height); 655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 66a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)private: 67a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Decodes the image. If |onlySize| is true, stops decoding after 68a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // calculating the image size. If decoding fails but there is no more 69a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // data coming, sets the "decode failure" flag. 70a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void decode(bool onlySize); 715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 72a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) OwnPtr<JPEGImageReader> m_reader; 73a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) IntSize m_decodedSize; 74323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) bool m_hasColorProfile; 75a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)}; 765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} // namespace WebCore 785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif 80