summaryrefslogtreecommitdiff
path: root/Tools/ImageDiff
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2016-05-24 08:28:08 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2016-05-24 08:28:08 +0000
commita4e969f4965059196ca948db781e52f7cfebf19e (patch)
tree6ca352808c8fdc52006a0f33f6ae3c593b23867d /Tools/ImageDiff
parent41386e9cb918eed93b3f13648cbef387e371e451 (diff)
downloadWebKitGtk-tarball-a4e969f4965059196ca948db781e52f7cfebf19e.tar.gz
webkitgtk-2.12.3webkitgtk-2.12.3
Diffstat (limited to 'Tools/ImageDiff')
-rw-r--r--Tools/ImageDiff/CMakeLists.txt20
-rw-r--r--Tools/ImageDiff/PlatformGTK.cmake11
-rw-r--r--Tools/ImageDiff/gtk/ImageDiff.cpp17
3 files changed, 42 insertions, 6 deletions
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 <algorithm>
#include <cmath>
#include <cstdio>
+#include <cstdlib>
#include <cstring>
#include <gdk/gdk.h>
@@ -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);