#include "config.h"
#include "Image.h"
#include "BitmapImage.h"
#include "BitmapInfo.h"
#include "GraphicsContext.h"
#include "ImageObserver.h"
#include "NotImplemented.h"
#include <d2d1.h>
#include <windows.h>
#include <wtf/RetainPtr.h>
#include <wtf/text/WTFString.h>
namespace WebCore {
RefPtr<BitmapImage> BitmapImage::create(HBITMAP hBitmap)
{
DIBSECTION dibSection;
if (!GetObject(hBitmap, sizeof(DIBSECTION), &dibSection))
return nullptr;
ASSERT(dibSection.dsBm.bmBitsPixel == 32);
if (dibSection.dsBm.bmBitsPixel != 32)
return nullptr;
ASSERT(dibSection.dsBm.bmBits);
if (!dibSection.dsBm.bmBits)
return nullptr;
notImplemented();
return nullptr;
}
bool BitmapImage::getHBITMAPOfSize(HBITMAP bmp, const IntSize* size)
{
ASSERT(bmp);
BITMAP bmpInfo;
GetObject(bmp, sizeof(BITMAP), &bmpInfo);
ASSERT(bmpInfo.bmBitsPixel == 32);
int bufferSize = bmpInfo.bmWidthBytes * bmpInfo.bmHeight;
notImplemented();
return true;
}
void BitmapImage::drawFrameMatchingSourceSize(GraphicsContext& ctxt, const FloatRect& dstRect, const IntSize& srcSize, CompositeOperator compositeOp)
{
size_t frames = frameCount();
for (size_t i = 0; i < frames; ++i) {
auto image = frameImageAtIndex(i).get();
auto imageSize = image->GetSize();
if (image && clampTo<size_t>(imageSize.height) == static_cast<size_t>(srcSize.height()) && clampTo<size_t>(imageSize.width) == static_cast<size_t>(srcSize.width())) {
size_t currentFrame = m_currentFrame;
m_currentFrame = i;
draw(ctxt, dstRect, FloatRect(0.0f, 0.0f, srcSize.width(), srcSize.height()), compositeOp, BlendModeNormal, ImageOrientationDescription());
m_currentFrame = currentFrame;
return;
}
}
FloatSize imageSize = BitmapImage::size();
draw(ctxt, dstRect, FloatRect(0.0f, 0.0f, imageSize.width(), imageSize.height()), compositeOp, BlendModeNormal, ImageOrientationDescription());
}
void Image::drawPattern(GraphicsContext& ctxt, const FloatRect& destRect, const FloatRect& tileRect, const AffineTransform& patternTransform,
const FloatPoint& phase, const FloatSize& spacing, CompositeOperator op, BlendMode blendMode)
{
if (!nativeImageForCurrentFrame())
return;
ctxt.drawPattern(*this, destRect, tileRect, patternTransform, phase, spacing, op, blendMode);
if (imageObserver())
imageObserver()->didDraw(*this);
}
}