#ifndef BitmapImage_h
#define BitmapImage_h
#include "Image.h"
#include "Color.h"
#include "IntSize.h"
#if PLATFORM(MAC)
#include <wtf/RetainPtr.h>
#endif
#if PLATFORM(WIN)
typedef struct HBITMAP__ *HBITMAP;
#endif
#if PLATFORM(HAIKU)
class BBitmap;
#endif
namespace WebCore {
struct FrameData;
}
namespace WTF {
template<> class VectorTraits<WebCore::FrameData> : public SimpleClassVectorTraits {};
}
namespace WebCore {
template <typename T> class Timer;
struct FrameData : Noncopyable {
FrameData()
: m_frame(0)
, m_haveMetadata(false)
, m_isComplete(false)
#if ENABLE(RESPECT_EXIF_ORIENTATION)
, m_orientation(0)
#endif
, m_bytes(0)
, m_scale(0.0f)
, m_haveInfo(false)
, m_duration(0)
, m_hasAlpha(true)
{
}
~FrameData()
{
clear(true);
}
bool clear(bool clearMetadata);
NativeImagePtr m_frame;
bool m_haveMetadata;
bool m_isComplete;
#if ENABLE(RESPECT_EXIF_ORIENTATION)
int m_orientation;
#endif
ssize_t m_bytes;
float m_scale;
bool m_haveInfo;
float m_duration;
bool m_hasAlpha;
};
class BitmapImage : public Image {
friend class GeneratedImage;
friend class GraphicsContext;
public:
static PassRefPtr<BitmapImage> create(NativeImagePtr nativeImage, ImageObserver* observer = 0)
{
return adoptRef(new BitmapImage(nativeImage, observer));
}
static PassRefPtr<BitmapImage> create(ImageObserver* observer = 0)
{
return adoptRef(new BitmapImage(observer));
}
~BitmapImage();
virtual bool isBitmapImage() const { return true; }
virtual bool hasSingleSecurityOrigin() const { return true; }
virtual IntSize size() const;
IntSize currentFrameSize() const;
virtual bool dataChanged(bool allDataReceived);
virtual String filenameExtension() const;
virtual void stopAnimation();
virtual void resetAnimation();
virtual unsigned decodedSize() const { return m_decodedSize; }
#if PLATFORM(MAC)
virtual CFDataRef getTIFFRepresentation();
#endif
#if PLATFORM(CG)
virtual CGImageRef getCGImageRef();
#endif
#if PLATFORM(WIN) || (PLATFORM(QT) && OS(WINDOWS))
static PassRefPtr<BitmapImage> create(HBITMAP);
#endif
#if PLATFORM(WIN)
virtual bool getHBITMAP(HBITMAP);
virtual bool getHBITMAPOfSize(HBITMAP, LPSIZE);
#endif
#if PLATFORM(GTK)
virtual GdkPixbuf* getGdkPixbuf();
#endif
virtual NativeImagePtr nativeImageForCurrentFrame() { return frameAtIndex(currentFrame()); }
#if ENABLE(RESPECT_EXIF_ORIENTATION)
static const int ImageEXIFOrientationTopLeft = 1;
static const int ImageEXIFOrientationTopRight = 2;
static const int ImageEXIFOrientationBottomRight = 3;
static const int ImageEXIFOrientationBottomLeft = 4;
static const int ImageEXIFOrientationLeftTop = 5;
static const int ImageEXIFOrientationRightTop = 6;
static const int ImageEXIFOrientationRightBottom = 7;
static const int ImageEXIFOrientationLeftBottom = 8;
#endif
protected:
enum RepetitionCountStatus {
Unknown, Uncertain, Certain, };
BitmapImage(NativeImagePtr, ImageObserver* = 0);
BitmapImage(ImageObserver* = 0);
#if PLATFORM(WIN)
virtual void drawFrameMatchingSourceSize(GraphicsContext*, const FloatRect& dstRect, const IntSize& srcSize, ColorSpace styleColorSpace, CompositeOperator);
#endif
virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, ColorSpace styleColorSpace, CompositeOperator);
#if (OS(WINCE) && !PLATFORM(QT))
virtual void drawPattern(GraphicsContext*, const FloatRect& srcRect, const TransformationMatrix& patternTransform,
const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator, const FloatRect& destRect);
#endif
#if PLATFORM(HAIKU)
virtual BBitmap* getBBitmap() const;
#endif
size_t currentFrame() const { return m_currentFrame; }
size_t frameCount();
NativeImagePtr frameAtIndex(size_t, float scaleHint);
NativeImagePtr copyUnscaledFrameAtIndex(size_t);
NativeImagePtr frameAtIndex(size_t);
bool frameIsCompleteAtIndex(size_t);
float frameDurationAtIndex(size_t);
bool frameHasAlphaAtIndex(size_t);
#if ENABLE(RESPECT_EXIF_ORIENTATION)
int frameOrientationAtIndex(size_t);
#endif
double m_progressiveLoadChunkTime;
unsigned m_progressiveLoadChunkCount;
void cacheFrame(size_t index, float scaleHint);
void cacheFrameInfo(size_t index);
virtual void destroyDecodedData(bool destroyAll = true);
void destroyDecodedDataIfNecessary(bool destroyAll);
void destroyMetadataAndNotify(int framesCleared);
bool isSizeAvailable();
int repetitionCount(bool imageKnownToBeComplete); bool shouldAnimate();
virtual void startAnimation(bool catchUpIfNecessary = true);
void advanceAnimation(Timer<BitmapImage>*);
bool internalAdvanceAnimation(bool skippingFrames);
void initPlatformData();
void invalidatePlatformData();
void checkForSolidColor();
virtual bool mayFillWithSolidColor()
{
if (!m_checkedForSolidColor && frameCount() > 0) {
checkForSolidColor();
#if !OS(WINCE)
ASSERT(m_checkedForSolidColor);
#endif
}
return m_isSolidColor && m_currentFrame == 0;
}
virtual Color solidColor() const { return m_solidColor; }
ImageSource m_source;
mutable IntSize m_size;
size_t m_currentFrame; Vector<FrameData> m_frames;
Timer<BitmapImage>* m_frameTimer;
int m_repetitionCount; RepetitionCountStatus m_repetitionCountStatus;
int m_repetitionsComplete; double m_desiredFrameStartTime;
#if PLATFORM(MAC)
mutable RetainPtr<CFDataRef> m_tiffRep; #endif
Color m_solidColor; bool m_isSolidColor; bool m_checkedForSolidColor;
bool m_animationFinished;
bool m_allDataReceived;
mutable bool m_haveSize; bool m_sizeAvailable; mutable bool m_hasUniformFrameSize;
unsigned m_decodedSize;
mutable bool m_haveFrameCount;
size_t m_frameCount;
};
}
#endif