Changeset 60675 in webkit


Ignore:
Timestamp:
Jun 4, 2010 4:52:42 AM (14 years ago)
Author:
eric@webkit.org
Message:

2010-06-04 Matthew Delaney <mdelaney@apple.com>

Reviewed by Darin Adler.

CG implementation needed for compression quality in canvas.toDataURL
https://bugs.webkit.org/show_bug.cgi?id=38492

  • platform/mac/Skipped:

2010-06-04 Matthew Delaney <mdelaney@apple.com>

Reviewed by Darin Adler.

CG implementation needed for compression quality in canvas.toDataURL
https://bugs.webkit.org/show_bug.cgi?id=38492

Took toDataURL.jpeg.quality.basic.html test off of Skipped list. Passes.

Went the route of avoiding in-band signaling to flag the use of a quality
parameter or not. So, instead of simply passing the quality down as a
double, instead I pass a reference to the quality parameter from where
it comes in just after the JS bindings. Thus, no need for any global
constants to signify when the quality is not specified. Updated the other
platforms to support this (qt was on the only one currently with any
implementation).

  • bindings/js/JSHTMLCanvasElementCustom.cpp: Moved range check logic for quality parameter down lower. Updated call to toDataURL to use double* instead of just passing the quality directly. (WebCore::JSHTMLCanvasElement::toDataURL):
  • bindings/v8/custom/V8HTMLCanvasElementCustom.cpp: Updated toDataURL call to pass double* (WebCore::V8HTMLCanvasElement::toDataURLCallback):
  • dom/CanvasSurface.cpp: Updated method prototype. (WebCore::CanvasSurface::toDataURL):
  • dom/CanvasSurface.h: Updated method prototype. (WebCore::CanvasSurface::toDataURL):
  • platform/graphics/ImageBuffer.h: Updated method signature to use double* for quality param.
  • platform/graphics/cairo/ImageBufferCairo.cpp: Updated prototype for consistency. (WebCore::ImageBuffer::toDataURL):
  • platform/graphics/cg/ImageBufferCG.cpp: Implemented support for quality parametejr when jpeg MIME type used. (WebCore::jpegUTI): (WebCore::utiFromMIMEType): (WebCore::ImageBuffer::toDataURL):
  • platform/graphics/haiku/ImageBufferHaiku.cpp: Updated prototype for consistency. (WebCore::ImageBuffer::toDataURL):
  • platform/graphics/qt/ImageBufferQt.cpp: Updated prototype for consistency. (WebCore::ImageBuffer::toDataURL):
  • platform/graphics/skia/ImageBufferSkia.cpp: Updated prototype for consistency. (WebCore::ImageBuffer::toDataURL):
  • platform/graphics/wince/ImageBufferWince.cpp: Updated prototype for consistency. (WebCore::ImageBuffer::toDataURL):
  • platform/graphics/wx/ImageBufferWx.cpp: Updated prototype for consistency. (WebCore::ImageBuffer::toDataURL):
Location:
trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r60672 r60675  
     12010-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
    1102010-06-04  Steve Block  <steveblock@google.com>
    211
  • trunk/LayoutTests/platform/mac/Skipped

    r60624 r60675  
    290290canvas/philip/tests/size.attributes.setAttribute.minus.html
    291291canvas/philip/tests/toDataURL.jpeg.alpha.html
    292 canvas/philip/tests/toDataURL.jpeg.quality.basic.html
    293292canvas/philip/tests/type.prototype.html
    294293
  • trunk/WebCore/ChangeLog

    r60673 r60675  
     12010-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
    1452010-06-04  Alejandro G. Castro  <alex@igalia.com>
    246
  • trunk/WebCore/bindings/js/JSHTMLCanvasElementCustom.cpp

    r60458 r60675  
    8989{
    9090    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;
    9297    if (exec->argumentCount() > 1) {
    9398        JSValue v = exec->argument(1);
    94         if (v.isNumber())
     99        if (v.isNumber()) {
    95100            quality = v.toNumber(exec);
    96         if (!(0.0 <= quality && quality <= 1.0))
    97             quality = 1.0;
     101            qualityPtr = &quality;
     102        }
    98103    }
    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));
    102106    setDOMException(exec, ec);
    103107    return result;
  • trunk/WebCore/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp

    r60458 r60675  
    106106    String type = toWebCoreString(args[0]);
    107107    ExceptionCode ec = 0;
    108     String result = canvas->toDataURL(type, quality, ec);
     108    String result = canvas->toDataURL(type, &quality, ec);
    109109    V8Proxy::setDOMException(ec);
    110110    return v8StringOrUndefined(result);
  • trunk/WebCore/dom/CanvasSurface.cpp

    r60458 r60675  
    6666}
    6767
    68 String CanvasSurface::toDataURL(const String& mimeType, double quality, ExceptionCode& ec)
     68String CanvasSurface::toDataURL(const String& mimeType, const double* quality, ExceptionCode& ec)
    6969{
    7070    if (!m_originClean) {
  • trunk/WebCore/dom/CanvasSurface.h

    r60458 r60675  
    6060    int height() const { return m_size.height(); }
    6161
    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); }
    6564
    6665    const IntSize& size() const { return m_size; }
  • trunk/WebCore/platform/graphics/ImageBuffer.h

    r60458 r60675  
    4444    class IntRect;
    4545    class String;
    46 
     46   
    4747    enum ImageColorSpace {
    4848        Unknown,
     
    8383        void putUnmultipliedImageData(ImageData*, const IntRect& sourceRect, const IntPoint& destPoint);
    8484        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;
    8787#if !PLATFORM(CG)
    8888        AffineTransform baseTransform() const { return AffineTransform(); }
  • trunk/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp

    r60458 r60675  
    285285}
    286286
    287 String ImageBuffer::toDataURL(const String& mimeType, double) const
     287String ImageBuffer::toDataURL(const String& mimeType, const double*) const
    288288{
    289289    cairo_surface_t* image = cairo_get_target(context()->platformContext());
  • trunk/WebCore/platform/graphics/cg/ImageBufferCG.cpp

    r60458 r60675  
    251251}
    252252
     253static inline CFStringRef jpegUTI()
     254{
     255#if PLATFORM(WIN)
     256    static const CFStringRef kUTTypeJPEG = CFSTR("public.jpeg");
     257#endif
     258    return kUTTypeJPEG;
     259}
     260   
    253261static RetainPtr<CFStringRef> utiFromMIMEType(const String& mimeType)
    254262{
     
    262270    // For now, only support PNG, JPEG, and GIF. See <rdar://problem/6095286>.
    263271    static const CFStringRef kUTTypePNG = CFSTR("public.png");
    264     static const CFStringRef kUTTypeJPEG = CFSTR("public.jpeg");
    265272    static const CFStringRef kUTTypeGIF = CFSTR("com.compuserve.gif");
    266273
     
    268275        return kUTTypePNG;
    269276    if (equalIgnoringCase(mimeType, "image/jpeg"))
    270         return kUTTypeJPEG;
     277        return jpegUTI();
    271278    if (equalIgnoringCase(mimeType, "image/gif"))
    272279        return kUTTypeGIF;
     
    277284}
    278285
    279 String ImageBuffer::toDataURL(const String& mimeType, double) const
     286String ImageBuffer::toDataURL(const String& mimeType, const double* quality) const
    280287{
    281288    ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
     
    289296        return "data:,";
    290297
    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));
    292302    if (!destination)
    293303        return "data:,";
    294304
    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());
    296315    CGImageDestinationFinalize(destination.get());
    297316
  • trunk/WebCore/platform/graphics/haiku/ImageBufferHaiku.cpp

    r60458 r60675  
    311311}
    312312
    313 String ImageBuffer::toDataURL(const String& mimeType, double) const
     313String ImageBuffer::toDataURL(const String& mimeType, const double*) const
    314314{
    315315    if (!MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType))
  • trunk/WebCore/platform/graphics/qt/ImageBufferQt.cpp

    r60458 r60675  
    277277// only formats (png, gif, jpeg..., xpm). So assume we get image/ as image
    278278// mimetypes and then remove the image/ to get the Qt format.
    279 String ImageBuffer::toDataURL(const String& mimeType, double quality) const
     279String ImageBuffer::toDataURL(const String& mimeType, const double* quality) const
    280280{
    281281    ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
    282     ASSERT(0.0 <= quality && quality <= 1.0);
    283282
    284283    if (!mimeType.startsWith("image/"))
     
    290289    buffer.open(QBuffer::WriteOnly);
    291290
    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        }
    295301    }
    296302
  • trunk/WebCore/platform/graphics/skia/ImageBufferSkia.cpp

    r60458 r60675  
    262262}
    263263
    264 String ImageBuffer::toDataURL(const String&, double) const
     264String ImageBuffer::toDataURL(const String&, const double*) const
    265265{
    266266    // Encode the image into a vector.
  • trunk/WebCore/platform/graphics/wince/ImageBufferWince.cpp

    r60458 r60675  
    217217}
    218218
    219 String ImageBuffer::toDataURL(const String& mimeType, double) const
     219String ImageBuffer::toDataURL(const String& mimeType, const double*) const
    220220{
    221221    if (!m_data.m_bitmap->bytes())
  • trunk/WebCore/platform/graphics/wx/ImageBufferWx.cpp

    r60458 r60675  
    7777}
    7878
    79 String ImageBuffer::toDataURL(const String&, double) const
     79String ImageBuffer::toDataURL(const String&, const double*) const
    8080{
    8181    notImplemented();
Note: See TracChangeset for help on using the changeset viewer.