Changeset 73173 in webkit


Ignore:
Timestamp:
Dec 2, 2010 11:42:52 AM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2010-12-02 Noel Gordon <noel.gordon@gmail.com>

Reviewed by David Levin.

[chromium] Add canvas.toDataURL("image/jpeg", quality) support
https://bugs.webkit.org/show_bug.cgi?id=49365

Chromium window/linux layout try results now match the default test result, so
remove this platform-specific test exception file.

  • platform/chromium-win/fast/canvas/canvas-toDataURL-case-insensitive-mimetype-expected.txt: Removed.

2010-12-02 Noel Gordon <noel.gordon@gmail.com>

Reviewed by David Levin.

[chromium] Add canvas.toDataURL("image/jpeg", quality) support
https://bugs.webkit.org/show_bug.cgi?id=49365

Adds a libjpeg-based image encoder for Skia bitmaps. Default encoding quality
is 92 to match Mozilla, also Safari, though the actual value used by Safari is
undocumented, and it appears to pre-blur images prior to compression.

The preMultipliedBGRAtoRGB() routine restores the un-premultiplied RGB colors
where there is non-zero alpha. Again, this matches Firefox and Safari, but no
browser conforms to the HTML5 canvas standard here, I believe, considering the
result of canvas/philip/tests/toDataURL.jpeg.alpha.html; that test ignores the
alpha channel when extracting an "image/jpeg".toDataURL(). The correct answer
needs more investigation, bug http://webkit.org/b/40147.

Canvas toDataURL is covered by existing tests canvas/philip/tests/toDataURL.*,
and fast/canvas/*toDataURL* tests.

  • WebCore.gypi:
  • bindings/v8/custom/V8HTMLCanvasElementCustom.cpp: (WebCore::V8HTMLCanvasElement::toDataURLCallback): don't set encoding quality here, just pass the toDataURL parameters through to the canvas layer.
  • platform/chromium/MIMETypeRegistryChromium.cpp: (WebCore::MIMETypeRegistry::isSupportedImageMIMETypeForEncoding): implement the supported mimeTypes for encoding in-place.
  • platform/graphics/skia/ImageBufferSkia.cpp: (WebCore::ImageBuffer::toDataURL): add jpeg encoding and quality support.
  • platform/image-encoders/skia/JPEGImageEncoder.cpp: Added. (WebCore::prepareOutput): (WebCore::writeOutput): (WebCore::finishOutput): (WebCore::handleError): (WebCore::preMultipliedBGRAtoRGB): FIXME: bug 40147. (WebCore::JPEGImageEncoder::encode):
  • platform/image-encoders/skia/JPEGImageEncoder.h: Added.
Location:
trunk
Files:
2 added
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r73171 r73173  
     12010-12-02  Noel Gordon  <noel.gordon@gmail.com>
     2
     3        Reviewed by David Levin.
     4
     5        [chromium] Add canvas.toDataURL("image/jpeg", quality) support
     6        https://bugs.webkit.org/show_bug.cgi?id=49365
     7
     8        Chromium window/linux layout try results now match the default test result, so
     9        remove this platform-specific test exception file.
     10
     11        * platform/chromium-win/fast/canvas/canvas-toDataURL-case-insensitive-mimetype-expected.txt: Removed.
     12
    1132010-12-02  Sheriff Bot  <webkit.review.bot@gmail.com>
    214
  • trunk/WebCore/ChangeLog

    r73171 r73173  
     12010-12-02  Noel Gordon  <noel.gordon@gmail.com>
     2
     3        Reviewed by David Levin.
     4
     5        [chromium] Add canvas.toDataURL("image/jpeg", quality) support
     6        https://bugs.webkit.org/show_bug.cgi?id=49365
     7
     8        Adds a libjpeg-based image encoder for Skia bitmaps.  Default encoding quality
     9        is 92 to match Mozilla, also Safari, though the actual value used by Safari is
     10        undocumented, and it appears to pre-blur images prior to compression.
     11
     12        The preMultipliedBGRAtoRGB() routine restores the un-premultiplied RGB colors
     13        where there is non-zero alpha.  Again, this matches Firefox and Safari, but no
     14        browser conforms to the HTML5 canvas standard here, I believe, considering the
     15        result of canvas/philip/tests/toDataURL.jpeg.alpha.html; that test ignores the
     16        alpha channel when extracting an "image/jpeg".toDataURL().  The correct answer
     17        needs more investigation, bug http://webkit.org/b/40147.
     18
     19        Canvas toDataURL is covered by existing tests canvas/philip/tests/toDataURL.*,
     20        and fast/canvas/*toDataURL* tests.
     21
     22        * WebCore.gypi:
     23        * bindings/v8/custom/V8HTMLCanvasElementCustom.cpp:
     24        (WebCore::V8HTMLCanvasElement::toDataURLCallback): don't set encoding quality
     25        here, just pass the toDataURL parameters through to the canvas layer.
     26        * platform/chromium/MIMETypeRegistryChromium.cpp:
     27        (WebCore::MIMETypeRegistry::isSupportedImageMIMETypeForEncoding): implement
     28        the supported mimeTypes for encoding in-place.
     29        * platform/graphics/skia/ImageBufferSkia.cpp:
     30        (WebCore::ImageBuffer::toDataURL): add jpeg encoding and quality support.
     31        * platform/image-encoders/skia/JPEGImageEncoder.cpp: Added.
     32        (WebCore::prepareOutput):
     33        (WebCore::writeOutput):
     34        (WebCore::finishOutput):
     35        (WebCore::handleError):
     36        (WebCore::preMultipliedBGRAtoRGB): FIXME: bug 40147.
     37        (WebCore::JPEGImageEncoder::encode):
     38        * platform/image-encoders/skia/JPEGImageEncoder.h: Added.
     39
    1402010-12-02  Sheriff Bot  <webkit.review.bot@gmail.com>
    241
  • trunk/WebCore/WebCore.gypi

    r73121 r73173  
    29382938            'platform/image-decoders/zlib/zlib.h',
    29392939            'platform/image-decoders/zlib/zutil.h',
     2940            'platform/image-encoders/skia/JPEGImageEncoder.cpp',
     2941            'platform/image-encoders/skia/JPEGImageEncoder.h',
    29402942            'platform/image-encoders/skia/PNGImageEncoder.cpp',
    29412943            'platform/image-encoders/skia/PNGImageEncoder.h',
  • trunk/WebCore/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp

    r60675 r73173  
    9595v8::Handle<v8::Value> V8HTMLCanvasElement::toDataURLCallback(const v8::Arguments& args)
    9696{
    97     double quality = 1.0;
    98     if (args.Length() > 1) {
    99         if (args[1]->IsNumber())
    100             quality = args[1]->NumberValue();
    101         if (!(0.0 <= quality && quality <= 1.0))
    102             quality = 1.0;
    103     }
    10497    v8::Handle<v8::Object> holder = args.Holder();
    10598    HTMLCanvasElement* canvas = V8HTMLCanvasElement::toNative(holder);
     99    ExceptionCode ec = 0;
     100
    106101    String type = toWebCoreString(args[0]);
    107     ExceptionCode ec = 0;
    108     String result = canvas->toDataURL(type, &quality, ec);
     102    double quality;
     103    double* qualityPtr = 0;
     104    if (args.Length() > 1 && args[1]->IsNumber()) {
     105        quality = args[1]->NumberValue();
     106        qualityPtr = &quality;
     107    }
     108
     109    String result = canvas->toDataURL(type, qualityPtr, ec);
    109110    V8Proxy::setDOMException(ec);
    110111    return v8StringOrUndefined(result);
  • trunk/WebCore/platform/chromium/MIMETypeRegistryChromium.cpp

    r56825 r73173  
    9292bool MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(const String& mimeType)
    9393{
    94     // FIXME: Fill this out. See: http://trac.webkit.org/changeset/30888
    95     return isSupportedImageMIMEType(mimeType);
     94    return mimeType == "image/jpeg" || mimeType == "image/png";
    9695}
    9796
  • trunk/WebCore/platform/graphics/skia/ImageBufferSkia.cpp

    r72374 r73173  
    4141#include "GraphicsContext.h"
    4242#include "ImageData.h"
     43#include "JPEGImageEncoder.h"
     44#include "MIMETypeRegistry.h"
    4345#include "PNGImageEncoder.h"
    4446#include "PlatformContextSkia.h"
     
    319321}
    320322
    321 String ImageBuffer::toDataURL(const String&, const double*) const
    322 {
    323     // Encode the image into a vector.
    324     Vector<unsigned char> pngEncodedData;
    325     PNGImageEncoder::encode(*context()->platformContext()->bitmap(), &pngEncodedData);
    326 
    327     // Convert it into base64.
    328     Vector<char> base64EncodedData;
    329     base64Encode(*reinterpret_cast<Vector<char>*>(&pngEncodedData), base64EncodedData);
    330     // Append with a \0 so that it's a valid string.
    331     base64EncodedData.append('\0');
    332 
    333     // And the resulting string.
    334     return makeString("data:image/png;base64,", base64EncodedData.data());
     323String ImageBuffer::toDataURL(const String& mimeType, const double* quality) const
     324{
     325    ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
     326
     327    Vector<unsigned char> encodedImage;
     328    if (mimeType == "image/jpeg") {
     329        int compressionQuality = JPEGImageEncoder::DefaultCompressionQuality;
     330        if (quality && *quality >= 0.0 && *quality <= 1.0)
     331            compressionQuality = static_cast<int>(*quality * 100 + 0.5);
     332        if (!JPEGImageEncoder::encode(*context()->platformContext()->bitmap(), compressionQuality, &encodedImage))
     333            return "data:,";
     334    } else {
     335        if (!PNGImageEncoder::encode(*context()->platformContext()->bitmap(), &encodedImage))
     336            return "data:,";
     337        ASSERT(mimeType == "image/png");
     338    }
     339
     340    Vector<char> base64Data;
     341    base64Encode(*reinterpret_cast<Vector<char>*>(&encodedImage), base64Data);
     342    base64Data.append('\0');
     343
     344    return makeString("data:", mimeType, ";base64,", base64Data.data());
    335345}
    336346
Note: See TracChangeset for help on using the changeset viewer.