Title: [185417] trunk/Source/WebCore
Revision
185417
Author
[email protected]
Date
2015-06-10 08:58:13 -0700 (Wed, 10 Jun 2015)

Log Message

[EFL] Jpeg image export implementation for Canvas.
https://bugs.webkit.org/show_bug.cgi?id=145457

Reviewed by Gyuyoung Kim.

Add implementation of jpeg image export on Webkit EFL by using JPEGImageEncoder.

No new tests, fast/canvas/toDataURL-supportedTypes.html can be reused.

* PlatformEfl.cmake:
* platform/MIMETypeRegistry.cpp:
(WebCore::initializeSupportedImageMIMETypesForEncoding):
* platform/graphics/cairo/ImageBufferCairo.cpp:
* platform/graphics/efl/ImageBufferEfl.cpp: Added.
(WebCore::writeFunction):
(WebCore::encodeImage):
(WebCore::ImageBuffer::toDataURL):
* platform/image-encoders/JPEGImageEncoder.cpp:
(WebCore::compressRGBABigEndianToJPEG):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (185416 => 185417)


--- trunk/Source/WebCore/ChangeLog	2015-06-10 15:17:53 UTC (rev 185416)
+++ trunk/Source/WebCore/ChangeLog	2015-06-10 15:58:13 UTC (rev 185417)
@@ -1,3 +1,25 @@
+2015-06-10  KwangHyuk Kim  <[email protected]>
+
+        [EFL] Jpeg image export implementation for Canvas.
+        https://bugs.webkit.org/show_bug.cgi?id=145457
+
+        Reviewed by Gyuyoung Kim.
+
+        Add implementation of jpeg image export on Webkit EFL by using JPEGImageEncoder.
+
+        No new tests, fast/canvas/toDataURL-supportedTypes.html can be reused.
+
+        * PlatformEfl.cmake:
+        * platform/MIMETypeRegistry.cpp:
+        (WebCore::initializeSupportedImageMIMETypesForEncoding):
+        * platform/graphics/cairo/ImageBufferCairo.cpp:
+        * platform/graphics/efl/ImageBufferEfl.cpp: Added.
+        (WebCore::writeFunction):
+        (WebCore::encodeImage):
+        (WebCore::ImageBuffer::toDataURL):
+        * platform/image-encoders/JPEGImageEncoder.cpp:
+        (WebCore::compressRGBABigEndianToJPEG):
+
 2015-06-10  Carlos Garcia Campos  <[email protected]>
 
         [GTK] Move KeyBindingTranslator from platform to WebKit2 layer

Modified: trunk/Source/WebCore/PlatformEfl.cmake (185416 => 185417)


--- trunk/Source/WebCore/PlatformEfl.cmake	2015-06-10 15:17:53 UTC (rev 185416)
+++ trunk/Source/WebCore/PlatformEfl.cmake	2015-06-10 15:58:13 UTC (rev 185417)
@@ -134,6 +134,7 @@
     platform/graphics/efl/GraphicsContext3DEfl.cpp
     platform/graphics/efl/GraphicsContext3DPrivate.cpp
     platform/graphics/efl/IconEfl.cpp
+    platform/graphics/efl/ImageBufferEfl.cpp
     platform/graphics/efl/ImageEfl.cpp
     platform/graphics/efl/IntPointEfl.cpp
     platform/graphics/efl/IntRectEfl.cpp
@@ -199,6 +200,8 @@
     platform/graphics/x11/PlatformDisplayX11.cpp
     platform/graphics/x11/XUniqueResource.cpp
 
+    platform/image-encoders/JPEGImageEncoder.cpp
+
     platform/image-decoders/ImageDecoder.cpp
 
     platform/image-decoders/bmp/BMPImageDecoder.cpp

Modified: trunk/Source/WebCore/platform/MIMETypeRegistry.cpp (185416 => 185417)


--- trunk/Source/WebCore/platform/MIMETypeRegistry.cpp	2015-06-10 15:17:53 UTC (rev 185416)
+++ trunk/Source/WebCore/platform/MIMETypeRegistry.cpp	2015-06-10 15:58:13 UTC (rev 185417)
@@ -267,6 +267,9 @@
     supportedImageMIMETypesForEncoding->add("image/tiff");
     supportedImageMIMETypesForEncoding->add("image/bmp");
     supportedImageMIMETypesForEncoding->add("image/ico");
+#elif PLATFORM(EFL)
+    supportedImageMIMETypesForEncoding->add("image/png");
+    supportedImageMIMETypesForEncoding->add("image/jpeg");
 #elif USE(CAIRO)
     supportedImageMIMETypesForEncoding->add("image/png");
 #endif

Modified: trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp (185416 => 185417)


--- trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp	2015-06-10 15:17:53 UTC (rev 185416)
+++ trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp	2015-06-10 15:58:13 UTC (rev 185417)
@@ -361,7 +361,7 @@
         copyRectFromOneSurfaceToAnother(imageSurface.get(), m_data.m_surface.get(), IntSize(), IntRect(0, 0, numColumns, numRows), IntSize(destPoint.x() + sourceRect.x(), destPoint.y() + sourceRect.y()), CAIRO_OPERATOR_SOURCE);
 }
 
-#if !PLATFORM(GTK)
+#if !PLATFORM(GTK) && !PLATFORM(EFL)
 static cairo_status_t writeFunction(void* output, const unsigned char* data, unsigned int length)
 {
     if (!reinterpret_cast<Vector<unsigned char>*>(output)->tryAppend(data, length))

Added: trunk/Source/WebCore/platform/graphics/efl/ImageBufferEfl.cpp (0 => 185417)


--- trunk/Source/WebCore/platform/graphics/efl/ImageBufferEfl.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/efl/ImageBufferEfl.cpp	2015-06-10 15:58:13 UTC (rev 185417)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2015 Samsung Electronics. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ImageBuffer.h"
+
+#include "image-encoders/JPEGImageEncoder.h"
+
+#include <cairo.h>
+#include <wtf/text/Base64.h>
+
+
+namespace WebCore {
+
+static cairo_status_t writeFunction(void* output, const unsigned char* data, unsigned length)
+{
+    if (!reinterpret_cast<Vector<unsigned char>*>(output)->tryAppend(data, length))
+        return CAIRO_STATUS_WRITE_ERROR;
+    return CAIRO_STATUS_SUCCESS;
+}
+
+static bool encodeImage(cairo_surface_t* image, const String& mimeType, Vector<char>* output, const double* quality)
+{
+    ASSERT_UNUSED(mimeType, mimeType == "image/png" || mimeType == "image/jpeg"); // Only PNG  and JPEG output are supported for now.
+    bool result = false;    
+
+    if (mimeType == "image/png")
+        result = cairo_surface_write_to_png_stream(image, writeFunction, output) == CAIRO_STATUS_SUCCESS;
+
+    if (mimeType == "image/jpeg") {
+        unsigned char* imageData = cairo_image_surface_get_data(image);
+        int width = cairo_image_surface_get_width(image);
+        int height = cairo_image_surface_get_height(image);
+        result = compressRGBABigEndianToJPEG(imageData, IntSize(width, height), *output, quality);
+    }
+
+    return result;
+}
+
+String ImageBuffer::toDataURL(const String& mimeType, const double* quality, CoordinateSystem) const
+{
+    ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
+
+    cairo_surface_t* image = cairo_get_target(context()->platformContext()->cr());
+
+    Vector<char> encodedImage;
+    if (!image || !encodeImage(image, mimeType, &encodedImage, quality))
+        return "data:,";
+
+    Vector<char> base64Data;
+    base64Encode(encodedImage, base64Data);
+
+    return "data:" + mimeType + ";base64," + base64Data;
+}
+
+}

Modified: trunk/Source/WebCore/platform/image-encoders/JPEGImageEncoder.cpp (185416 => 185417)


--- trunk/Source/WebCore/platform/image-encoders/JPEGImageEncoder.cpp	2015-06-10 15:17:53 UTC (rev 185416)
+++ trunk/Source/WebCore/platform/image-encoders/JPEGImageEncoder.cpp	2015-06-10 15:58:13 UTC (rev 185417)
@@ -119,15 +119,17 @@
     jpeg_start_compress(&compressData, TRUE);
     rowBuffer.resize(compressData.image_width * 3);
 
+    // add offset to prevent clobbered error caused by setjmp and longjmp.
+    unsigned offset = 0;
     const unsigned char* pixel = rgbaBigEndianData;
     const unsigned char* pixelEnd = pixel + compressData.image_width * compressData.image_height * 4;
-    while (pixel < pixelEnd) {
+    while (pixel + offset < pixelEnd) {
         JSAMPLE* output = rowBuffer.data();
-        for (const unsigned char* rowEnd = pixel + compressData.image_width * 4; pixel < rowEnd;) {
-            *output++ = static_cast<JSAMPLE>(*pixel++ & 0xFF); // red
-            *output++ = static_cast<JSAMPLE>(*pixel++ & 0xFF); // green
-            *output++ = static_cast<JSAMPLE>(*pixel++ & 0xFF); // blue
-            ++pixel; // skip alpha
+        for (const unsigned char* rowEnd = pixel + offset + compressData.image_width * 4; pixel + offset < rowEnd;) {
+            *output++ = static_cast<JSAMPLE>(*(pixel + offset++) & 0xFF); // red
+            *output++ = static_cast<JSAMPLE>(*(pixel + offset++) & 0xFF); // green
+            *output++ = static_cast<JSAMPLE>(*(pixel + offset++) & 0xFF); // blue
+            ++offset; // skip alpha
         }
         output = rowBuffer.data();
         jpeg_write_scanlines(&compressData, &output, 1);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to