#include "config.h"
#include "BitmapImage.h"
-#if PLATFORM(CG)
+#if USE(CG)
#include "AffineTransform.h"
#include "FloatConversion.h"
return frameAtIndex(0);
}
+CGImageRef BitmapImage::getFirstCGImageRefOfSize(const IntSize& size)
+{
+ size_t count = frameCount();
+ for (size_t i = 0; i < count; ++i) {
+ CGImageRef cgImage = frameAtIndex(i);
+ if (IntSize(CGImageGetWidth(cgImage), CGImageGetHeight(cgImage)) == size)
+ return cgImage;
+ }
+
+ // Fallback to the default CGImageRef if we can't find the right size
+ return getCGImageRef();
+}
+
void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& destRect, const FloatRect& srcRect, ColorSpace styleColorSpace, CompositeOperator compositeOp)
{
startAnimation();
// containing only the portion we want to display. We need to do this because high-quality
// interpolation smoothes sharp edges, causing pixels from outside the source rect to bleed
// into the destination rect. See <rdar://problem/6112909>.
- shouldUseSubimage = (interpolationQuality == kCGInterpolationHigh || interpolationQuality == kCGInterpolationDefault) && (srcRect.size() != destRect.size() || !ctxt->getCTM().isIdentityOrTranslationOrFlipped());
+ shouldUseSubimage = (interpolationQuality != kCGInterpolationNone) && (srcRect.size() != destRect.size() || !ctxt->getCTM().isIdentityOrTranslationOrFlipped());
float xScale = srcRect.width() / destRect.width();
float yScale = srcRect.height() / destRect.height();
if (shouldUseSubimage) {
adjustedDestRect.setHeight(subimageRect.height() / yScale);
image.adoptCF(CGImageCreateWithImageInRect(image.get(), subimageRect));
- if (currHeight < srcRect.bottom()) {
+ if (currHeight < srcRect.maxY()) {
ASSERT(CGImageGetHeight(image.get()) == currHeight - CGRectIntegral(srcRect).origin.y);
adjustedDestRect.setHeight(CGImageGetHeight(image.get()) / yScale);
}
// Flip the coords.
CGContextScaleCTM(context, 1, -1);
- adjustedDestRect.setY(-adjustedDestRect.bottom());
+ adjustedDestRect.setY(-adjustedDestRect.maxY());
// Adjust the color space.
image = imageWithColorSpace(image.get(), styleColorSpace);
// Avoid a hang under CGContextDrawTiledImage on release builds.
return;
+#if !ASSERT_DISABLED
+ if (this->isBitmapImage())
+ ASSERT(static_cast<BitmapImage*>(this)->notSolidColor());
+#endif
+
CGContextRef context = ctxt->platformContext();
ctxt->save();
CGContextClipToRect(context, destRect);
}
-#endif // PLATFORM(CG)
+#endif // USE(CG)