summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/graphics/cg/ImageSourceCG.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/platform/graphics/cg/ImageSourceCG.cpp')
-rw-r--r--WebCore/platform/graphics/cg/ImageSourceCG.cpp48
1 files changed, 37 insertions, 11 deletions
diff --git a/WebCore/platform/graphics/cg/ImageSourceCG.cpp b/WebCore/platform/graphics/cg/ImageSourceCG.cpp
index 2bfc204..73907c9 100644
--- a/WebCore/platform/graphics/cg/ImageSourceCG.cpp
+++ b/WebCore/platform/graphics/cg/ImageSourceCG.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -25,15 +25,17 @@
#include "config.h"
#include "ImageSource.h"
-#include "SharedBuffer.h"
#if PLATFORM(CG)
#include "IntSize.h"
+#include "SharedBuffer.h"
#include <ApplicationServices/ApplicationServices.h>
namespace WebCore {
+static const CFStringRef kCGImageSourceShouldPreferRGB32 = CFSTR("kCGImageSourceShouldPreferRGB32");
+
ImageSource::ImageSource()
: m_decoder(0)
{
@@ -52,15 +54,13 @@ void ImageSource::clear()
}
}
-const CFStringRef kCGImageSourceShouldPreferRGB32 = CFSTR("kCGImageSourceShouldPreferRGB32");
-
CFDictionaryRef imageSourceOptions()
{
static CFDictionaryRef options;
if (!options) {
- const void *keys[2] = { kCGImageSourceShouldCache, kCGImageSourceShouldPreferRGB32 };
- const void *values[2] = { kCFBooleanTrue, kCFBooleanTrue };
+ const void* keys[2] = { kCGImageSourceShouldCache, kCGImageSourceShouldPreferRGB32 };
+ const void* values[2] = { kCFBooleanTrue, kCFBooleanTrue };
options = CFDictionaryCreate(NULL, keys, values, 2,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
}
@@ -108,10 +108,10 @@ bool ImageSource::isSizeAvailable()
return result;
}
-IntSize ImageSource::size() const
+IntSize ImageSource::frameSizeAtIndex(size_t index) const
{
IntSize result;
- CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(m_decoder, 0, imageSourceOptions());
+ CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(m_decoder, index, imageSourceOptions());
if (properties) {
int w = 0, h = 0;
CFNumberRef num = (CFNumberRef)CFDictionaryGetValue(properties, kCGImagePropertyPixelWidth);
@@ -120,16 +120,23 @@ IntSize ImageSource::size() const
num = (CFNumberRef)CFDictionaryGetValue(properties, kCGImagePropertyPixelHeight);
if (num)
CFNumberGetValue(num, kCFNumberIntType, &h);
- result = IntSize(w, h);
+ result = IntSize(w, h);
CFRelease(properties);
}
return result;
}
+IntSize ImageSource::size() const
+{
+ return frameSizeAtIndex(0);
+}
+
int ImageSource::repetitionCount()
{
int result = cAnimationLoopOnce; // No property means loop once.
-
+ if (!initialized())
+ return result;
+
// A property with value 0 means loop forever.
CFDictionaryRef properties = CGImageSourceCopyProperties(m_decoder, imageSourceOptions());
if (properties) {
@@ -154,7 +161,23 @@ size_t ImageSource::frameCount() const
CGImageRef ImageSource::createFrameAtIndex(size_t index)
{
- return CGImageSourceCreateImageAtIndex(m_decoder, index, imageSourceOptions());
+ if (!initialized())
+ return 0;
+
+ CGImageRef image = CGImageSourceCreateImageAtIndex(m_decoder, index, imageSourceOptions());
+ CFStringRef imageUTI = CGImageSourceGetType(m_decoder);
+ static const CFStringRef xbmUTI = CFSTR("public.xbitmap-image");
+ if (!imageUTI || !CFEqual(imageUTI, xbmUTI))
+ return image;
+
+ // If it is an xbm image, mask out all the white areas to render them transparent.
+ const CGFloat maskingColors[6] = {255, 255, 255, 255, 255, 255};
+ CGImageRef maskedImage = CGImageCreateWithMaskingColors(image, maskingColors);
+ if (!maskedImage)
+ return image;
+
+ CGImageRelease(image);
+ return maskedImage;
}
bool ImageSource::frameIsCompleteAtIndex(size_t index)
@@ -164,6 +187,9 @@ bool ImageSource::frameIsCompleteAtIndex(size_t index)
float ImageSource::frameDurationAtIndex(size_t index)
{
+ if (!initialized())
+ return 0;
+
float duration = 0;
CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(m_decoder, index, imageSourceOptions());
if (properties) {