Changeset 60675 in webkit
- Timestamp:
- Jun 4, 2010, 4:52:42 AM (15 years ago)
- Location:
- trunk
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r60672 r60675 1 2010-06-04 Matthew Delaney <mdelaney@apple.com> 2 3 Reviewed by Darin Adler. 4 5 CG implementation needed for compression quality in canvas.toDataURL 6 https://bugs.webkit.org/show_bug.cgi?id=38492 7 8 * platform/mac/Skipped: 9 1 10 2010-06-04 Steve Block <steveblock@google.com> 2 11 -
trunk/LayoutTests/platform/mac/Skipped
r60624 r60675 290 290 canvas/philip/tests/size.attributes.setAttribute.minus.html 291 291 canvas/philip/tests/toDataURL.jpeg.alpha.html 292 canvas/philip/tests/toDataURL.jpeg.quality.basic.html293 292 canvas/philip/tests/type.prototype.html 294 293 -
trunk/WebCore/ChangeLog
r60673 r60675 1 2010-06-04 Matthew Delaney <mdelaney@apple.com> 2 3 Reviewed by Darin Adler. 4 5 CG implementation needed for compression quality in canvas.toDataURL 6 https://bugs.webkit.org/show_bug.cgi?id=38492 7 8 Took toDataURL.jpeg.quality.basic.html test off of Skipped list. Passes. 9 10 Went the route of avoiding in-band signaling to flag the use of a quality 11 parameter or not. So, instead of simply passing the quality down as a 12 double, instead I pass a reference to the quality parameter from where 13 it comes in just after the JS bindings. Thus, no need for any global 14 constants to signify when the quality is not specified. Updated the other 15 platforms to support this (qt was on the only one currently with any 16 implementation). 17 18 * bindings/js/JSHTMLCanvasElementCustom.cpp: Moved range check logic for quality parameter down lower. Updated 19 call to toDataURL to use double* instead of just passing the quality directly. 20 (WebCore::JSHTMLCanvasElement::toDataURL): 21 * bindings/v8/custom/V8HTMLCanvasElementCustom.cpp: Updated toDataURL call to pass double* 22 (WebCore::V8HTMLCanvasElement::toDataURLCallback): 23 * dom/CanvasSurface.cpp: Updated method prototype. 24 (WebCore::CanvasSurface::toDataURL): 25 * dom/CanvasSurface.h: Updated method prototype. 26 (WebCore::CanvasSurface::toDataURL): 27 * platform/graphics/ImageBuffer.h: Updated method signature to use double* for quality param. 28 * platform/graphics/cairo/ImageBufferCairo.cpp: Updated prototype for consistency. 29 (WebCore::ImageBuffer::toDataURL): 30 * platform/graphics/cg/ImageBufferCG.cpp: Implemented support for quality parametejr when jpeg MIME type used. 31 (WebCore::jpegUTI): 32 (WebCore::utiFromMIMEType): 33 (WebCore::ImageBuffer::toDataURL): 34 * platform/graphics/haiku/ImageBufferHaiku.cpp: Updated prototype for consistency. 35 (WebCore::ImageBuffer::toDataURL): 36 * platform/graphics/qt/ImageBufferQt.cpp: Updated prototype for consistency. 37 (WebCore::ImageBuffer::toDataURL): 38 * platform/graphics/skia/ImageBufferSkia.cpp: Updated prototype for consistency. 39 (WebCore::ImageBuffer::toDataURL): 40 * platform/graphics/wince/ImageBufferWince.cpp: Updated prototype for consistency. 41 (WebCore::ImageBuffer::toDataURL): 42 * platform/graphics/wx/ImageBufferWx.cpp: Updated prototype for consistency. 43 (WebCore::ImageBuffer::toDataURL): 44 1 45 2010-06-04 Alejandro G. Castro <alex@igalia.com> 2 46 -
trunk/WebCore/bindings/js/JSHTMLCanvasElementCustom.cpp
r60458 r60675 89 89 { 90 90 const String& type = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(0)); 91 double quality = 1.0; 91 HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(impl()); 92 ExceptionCode ec = 0; 93 94 JSC::JSValue result; 95 double quality; 96 double* qualityPtr = 0; 92 97 if (exec->argumentCount() > 1) { 93 98 JSValue v = exec->argument(1); 94 if (v.isNumber()) 99 if (v.isNumber()) { 95 100 quality = v.toNumber(exec); 96 if (!(0.0 <= quality && quality <= 1.0))97 quality = 1.0;101 qualityPtr = &quality; 102 } 98 103 } 99 HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(impl()); 100 ExceptionCode ec = 0; 101 JSC::JSValue result = jsString(exec, canvas->toDataURL(type, quality, ec)); 104 105 result = jsString(exec, canvas->toDataURL(type, qualityPtr, ec)); 102 106 setDOMException(exec, ec); 103 107 return result; -
trunk/WebCore/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp
r60458 r60675 106 106 String type = toWebCoreString(args[0]); 107 107 ExceptionCode ec = 0; 108 String result = canvas->toDataURL(type, quality, ec);108 String result = canvas->toDataURL(type, &quality, ec); 109 109 V8Proxy::setDOMException(ec); 110 110 return v8StringOrUndefined(result); -
trunk/WebCore/dom/CanvasSurface.cpp
r60458 r60675 66 66 } 67 67 68 String CanvasSurface::toDataURL(const String& mimeType, doublequality, ExceptionCode& ec)68 String CanvasSurface::toDataURL(const String& mimeType, const double* quality, ExceptionCode& ec) 69 69 { 70 70 if (!m_originClean) { -
trunk/WebCore/dom/CanvasSurface.h
r60458 r60675 60 60 int height() const { return m_size.height(); } 61 61 62 String toDataURL(const String& mimeType, double quality, ExceptionCode&); 63 64 String toDataURL(const String& mimeType, ExceptionCode& ec) { return toDataURL(mimeType, 1.0, ec); } 62 String toDataURL(const String& mimeType, const double* quality, ExceptionCode&); 63 String toDataURL(const String& mimeType, ExceptionCode& ec) { return toDataURL(mimeType, 0, ec); } 65 64 66 65 const IntSize& size() const { return m_size; } -
trunk/WebCore/platform/graphics/ImageBuffer.h
r60458 r60675 44 44 class IntRect; 45 45 class String; 46 46 47 47 enum ImageColorSpace { 48 48 Unknown, … … 83 83 void putUnmultipliedImageData(ImageData*, const IntRect& sourceRect, const IntPoint& destPoint); 84 84 void putPremultipliedImageData(ImageData*, const IntRect& sourceRect, const IntPoint& destPoint); 85 86 String toDataURL(const String& mimeType, double quality = 1.0) const;85 86 String toDataURL(const String& mimeType, const double* quality = 0) const; 87 87 #if !PLATFORM(CG) 88 88 AffineTransform baseTransform() const { return AffineTransform(); } -
trunk/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
r60458 r60675 285 285 } 286 286 287 String ImageBuffer::toDataURL(const String& mimeType, double) const287 String ImageBuffer::toDataURL(const String& mimeType, const double*) const 288 288 { 289 289 cairo_surface_t* image = cairo_get_target(context()->platformContext()); -
trunk/WebCore/platform/graphics/cg/ImageBufferCG.cpp
r60458 r60675 251 251 } 252 252 253 static inline CFStringRef jpegUTI() 254 { 255 #if PLATFORM(WIN) 256 static const CFStringRef kUTTypeJPEG = CFSTR("public.jpeg"); 257 #endif 258 return kUTTypeJPEG; 259 } 260 253 261 static RetainPtr<CFStringRef> utiFromMIMEType(const String& mimeType) 254 262 { … … 262 270 // For now, only support PNG, JPEG, and GIF. See <rdar://problem/6095286>. 263 271 static const CFStringRef kUTTypePNG = CFSTR("public.png"); 264 static const CFStringRef kUTTypeJPEG = CFSTR("public.jpeg");265 272 static const CFStringRef kUTTypeGIF = CFSTR("com.compuserve.gif"); 266 273 … … 268 275 return kUTTypePNG; 269 276 if (equalIgnoringCase(mimeType, "image/jpeg")) 270 return kUTTypeJPEG;277 return jpegUTI(); 271 278 if (equalIgnoringCase(mimeType, "image/gif")) 272 279 return kUTTypeGIF; … … 277 284 } 278 285 279 String ImageBuffer::toDataURL(const String& mimeType, double) const286 String ImageBuffer::toDataURL(const String& mimeType, const double* quality) const 280 287 { 281 288 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); … … 289 296 return "data:,"; 290 297 291 RetainPtr<CGImageDestinationRef> destination(AdoptCF, CGImageDestinationCreateWithData(data.get(), utiFromMIMEType(mimeType).get(), 1, 0)); 298 RetainPtr<CFStringRef> uti = utiFromMIMEType(mimeType); 299 ASSERT(uti); 300 301 RetainPtr<CGImageDestinationRef> destination(AdoptCF, CGImageDestinationCreateWithData(data.get(), uti.get(), 1, 0)); 292 302 if (!destination) 293 303 return "data:,"; 294 304 295 CGImageDestinationAddImage(destination.get(), image.get(), 0); 305 RetainPtr<CFDictionaryRef> imageProperties = 0; 306 if (CFEqual(uti.get(), jpegUTI()) && quality && *quality >= 0.0 && *quality <= 1.0) { 307 // Apply the compression quality to the image destination. 308 RetainPtr<CFNumberRef> compressionQuality(AdoptCF, CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, quality)); 309 const void* key = kCGImageDestinationLossyCompressionQuality; 310 const void* value = compressionQuality.get(); 311 imageProperties.adoptCF(CFDictionaryCreate(0, &key, &value, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); 312 } 313 314 CGImageDestinationAddImage(destination.get(), image.get(), imageProperties.get()); 296 315 CGImageDestinationFinalize(destination.get()); 297 316 -
trunk/WebCore/platform/graphics/haiku/ImageBufferHaiku.cpp
r60458 r60675 311 311 } 312 312 313 String ImageBuffer::toDataURL(const String& mimeType, double) const313 String ImageBuffer::toDataURL(const String& mimeType, const double*) const 314 314 { 315 315 if (!MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)) -
trunk/WebCore/platform/graphics/qt/ImageBufferQt.cpp
r60458 r60675 277 277 // only formats (png, gif, jpeg..., xpm). So assume we get image/ as image 278 278 // mimetypes and then remove the image/ to get the Qt format. 279 String ImageBuffer::toDataURL(const String& mimeType, doublequality) const279 String ImageBuffer::toDataURL(const String& mimeType, const double* quality) const 280 280 { 281 281 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); 282 ASSERT(0.0 <= quality && quality <= 1.0);283 282 284 283 if (!mimeType.startsWith("image/")) … … 290 289 buffer.open(QBuffer::WriteOnly); 291 290 292 if (!m_data.m_pixmap.save(&buffer, mimeType.substring(sizeof "image").utf8().data(), quality * 100 + 0.5)) { 293 buffer.close(); 294 return "data:,"; 291 if (quality && *quality >= 0.0 && *quality <= 1.0) { 292 if (!m_data.m_pixmap.save(&buffer, mimeType.substring(sizeof "image").utf8().data(), *quality * 100 + 0.5)) { 293 buffer.close(); 294 return "data:,"; 295 } 296 } else { 297 if (!m_data.m_pixmap.save(&buffer, mimeType.substring(sizeof "image").utf8().data(), 100)) { 298 buffer.close(); 299 return "data:,"; 300 } 295 301 } 296 302 -
trunk/WebCore/platform/graphics/skia/ImageBufferSkia.cpp
r60458 r60675 262 262 } 263 263 264 String ImageBuffer::toDataURL(const String&, double) const264 String ImageBuffer::toDataURL(const String&, const double*) const 265 265 { 266 266 // Encode the image into a vector. -
trunk/WebCore/platform/graphics/wince/ImageBufferWince.cpp
r60458 r60675 217 217 } 218 218 219 String ImageBuffer::toDataURL(const String& mimeType, double) const219 String ImageBuffer::toDataURL(const String& mimeType, const double*) const 220 220 { 221 221 if (!m_data.m_bitmap->bytes()) -
trunk/WebCore/platform/graphics/wx/ImageBufferWx.cpp
r60458 r60675 77 77 } 78 78 79 String ImageBuffer::toDataURL(const String&, double) const79 String ImageBuffer::toDataURL(const String&, const double*) const 80 80 { 81 81 notImplemented();
Note:
See TracChangeset
for help on using the changeset viewer.