Changeset 36508 in webkit


Ignore:
Timestamp:
Sep 16, 2008 9:59:18 AM (16 years ago)
Author:
alp@webkit.org
Message:

2008-09-16 Dirk Schulze <vbs85@gmx.de>

Reviewed by Oliver Hunt and Alp Toker.

Implemented toDataURL in Cairo. Only PNG support
at the moment.

Qt, Cairo and wx require toDataURL implementations
https://bugs.webkit.org/show_bug.cgi?id=17719

  • platform/MIMETypeRegistry.cpp: (WebCore::initializeSupportedImageMIMETypesForEncoding):
  • platform/graphics/cairo/ImageBufferCairo.cpp: (WebCore::ImageBuffer::ImageBuffer): (WebCore::writeFunction): (WebCore::ImageBuffer::toDataURL):
Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r36506 r36508  
     12008-09-16  Dirk Schulze  <vbs85@gmx.de>
     2
     3        Reviewed by Oliver Hunt and Alp Toker.
     4
     5        Implemented toDataURL in Cairo. Only PNG support
     6        at the moment.
     7
     8        Qt, Cairo and wx require toDataURL implementations
     9        https://bugs.webkit.org/show_bug.cgi?id=17719
     10
     11        * platform/MIMETypeRegistry.cpp:
     12        (WebCore::initializeSupportedImageMIMETypesForEncoding):
     13        * platform/graphics/cairo/ImageBufferCairo.cpp:
     14        (WebCore::ImageBuffer::ImageBuffer):
     15        (WebCore::writeFunction):
     16        (WebCore::ImageBuffer::toDataURL):
     17
    1182008-09-16  Tor Arne Vestbø  <tavestbo@trolltech.com>
    219
  • trunk/WebCore/platform/MIMETypeRegistry.cpp

    r36269 r36508  
    148148        supportedImageMIMETypesForEncoding->add(mimeType);
    149149    }
     150#elif PLATFORM(CAIRO)
     151    supportedImageMIMETypesForEncoding->add("image/png");
    150152#endif
    151153}
  • trunk/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp

    r35747 r36508  
    2828#include "ImageBuffer.h"
    2929
     30#include "Base64.h"
    3031#include "BitmapImage.h"
    3132#include "GraphicsContext.h"
    3233#include "ImageData.h"
     34#include "MIMETypeRegistry.h"
    3335#include "NotImplemented.h"
    3436#include "Pattern.h"
     37#include "PlatformString.h"
    3538
    3639#include <cairo.h>
     40#include <wtf/Vector.h>
    3741
    3842using namespace std;
     
    5054}
    5155
    52 ImageBuffer::ImageBuffer(_cairo_surface* surface)
     56ImageBuffer::ImageBuffer(cairo_surface_t* surface)
    5357    : m_surface(surface)
    5458{
     
    9599}
    96100
    97 String ImageBuffer::toDataURL(const String&) const
     101static cairo_status_t writeFunction(void* closure, const unsigned char* data, unsigned int length)
    98102{
    99     notImplemented();
    100     return String();
     103    Vector<char>* in = reinterpret_cast<Vector<char>*>(closure);
     104    in->append(data, length);
     105    return CAIRO_STATUS_SUCCESS;
     106}
     107
     108String ImageBuffer::toDataURL(const String& mimeType) const
     109{
     110    cairo_surface_t* image = cairo_get_target(context()->platformContext());
     111    if (!image)
     112        return "data:,";
     113
     114    String actualMimeType("image/png");
     115    if (MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType))
     116        actualMimeType = mimeType;
     117
     118    Vector<char> in;
     119    // Only PNG output is supported for now.
     120    cairo_surface_write_to_png_stream(image, writeFunction, &in);
     121
     122    Vector<char> out;
     123    base64Encode(in, out);
     124
     125    return "data:" + actualMimeType + ";base64," + String(out.data(), out.size());
    101126}
    102127
Note: See TracChangeset for help on using the changeset viewer.