From a4e969f4965059196ca948db781e52f7cfebf19e Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 24 May 2016 08:28:08 +0000 Subject: webkitgtk-2.12.3 --- Tools/ImageDiff/CMakeLists.txt | 20 ++++++++++++++++++++ Tools/ImageDiff/PlatformGTK.cmake | 11 +++++++++++ Tools/ImageDiff/gtk/ImageDiff.cpp | 17 +++++++++++------ 3 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 Tools/ImageDiff/CMakeLists.txt create mode 100644 Tools/ImageDiff/PlatformGTK.cmake (limited to 'Tools/ImageDiff') diff --git a/Tools/ImageDiff/CMakeLists.txt b/Tools/ImageDiff/CMakeLists.txt new file mode 100644 index 000000000..6ce4ed522 --- /dev/null +++ b/Tools/ImageDiff/CMakeLists.txt @@ -0,0 +1,20 @@ +set(IMAGE_DIFF_DIR "${TOOLS_DIR}/ImageDiff") + +set(IMAGE_DIFF_INCLUDE_DIRECTORIES + ${CMAKE_BINARY_DIR} + ${WTF_DIR} +) + +set(IMAGE_DIFF_SYSTEM_INCLUDE_DIRECTORIES "") + +set(IMAGE_DIFF_LIBRARIES + WTF +) + +WEBKIT_INCLUDE_CONFIG_FILES_IF_EXISTS() + +include_directories(${IMAGE_DIFF_INCLUDE_DIRECTORIES}) +include_directories(SYSTEM ${IMAGE_DIFF_SYSTEM_INCLUDE_DIRECTORIES}) +add_executable(ImageDiff ${IMAGE_DIFF_SOURCES}) +target_link_libraries(ImageDiff ${IMAGE_DIFF_LIBRARIES}) +set_target_properties(ImageDiff PROPERTIES FOLDER "Tools") diff --git a/Tools/ImageDiff/PlatformGTK.cmake b/Tools/ImageDiff/PlatformGTK.cmake new file mode 100644 index 000000000..8b37ca08b --- /dev/null +++ b/Tools/ImageDiff/PlatformGTK.cmake @@ -0,0 +1,11 @@ +set(IMAGE_DIFF_SOURCES + ${IMAGE_DIFF_DIR}/gtk/ImageDiff.cpp +) + +list(APPEND IMAGE_DIFF_SYSTEM_INCLUDE_DIRECTORIES + ${GTK_INCLUDE_DIRS} +) + +list(APPEND IMAGE_DIFF_LIBRARIES + ${GTK_LIBRARIES} +) diff --git a/Tools/ImageDiff/gtk/ImageDiff.cpp b/Tools/ImageDiff/gtk/ImageDiff.cpp index 2cb9f3bce..5a128d1e3 100644 --- a/Tools/ImageDiff/gtk/ImageDiff.cpp +++ b/Tools/ImageDiff/gtk/ImageDiff.cpp @@ -11,7 +11,7 @@ * 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. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * 3. Neither the name of Apple Inc. ("Apple") nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -63,23 +64,27 @@ GdkPixbuf* readPixbufFromStdin(long imageSize) } gdk_pixbuf_loader_close(loader, 0); - GdkPixbuf* decodedImage = gdk_pixbuf_loader_get_pixbuf(loader); - g_object_ref(decodedImage); + GdkPixbuf* decodedImage = GDK_PIXBUF(g_object_ref(gdk_pixbuf_loader_get_pixbuf(loader))); + g_object_unref(loader); return decodedImage; } -GdkPixbuf* differenceImageFromDifferenceBuffer(unsigned char* buffer, int width, int height) +GdkPixbuf* differenceImageFromDifferenceBuffer(unsigned char* buffer, int width, int height, float maxDistance) { GdkPixbuf* image = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, width, height); if (!image) return image; + bool shouldNormalize = maxDistance > 0 && maxDistance < 1; int rowStride = gdk_pixbuf_get_rowstride(image); unsigned char* diffPixels = gdk_pixbuf_get_pixels(image); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { unsigned char* diffPixel = diffPixels + (y * rowStride) + (x * 3); - diffPixel[0] = diffPixel[1] = diffPixel[2] = *buffer++; + unsigned char bufferPixel = *buffer++; + if (shouldNormalize) + bufferPixel /= maxDistance; + diffPixel[0] = diffPixel[1] = diffPixel[2] = bufferPixel; } } @@ -140,7 +145,7 @@ float calculateDifference(GdkPixbuf* baselineImage, GdkPixbuf* actualImage, GdkP else { difference = roundf(difference * 100.0f) / 100.0f; difference = max(difference, 0.01f); // round to 2 decimal places - *differenceImage = differenceImageFromDifferenceBuffer(diffBuffer, width, height); + *differenceImage = differenceImageFromDifferenceBuffer(diffBuffer, width, height, maxDistance); } free(diffBuffer); -- cgit v1.2.1