|
Packit |
a4058c |
/* -*- Mode: C; c-basic-offset: 2; -*- */
|
|
Packit |
a4058c |
/* GdkPixbuf library - test loaders
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Copyright (C) 2013 Red Hat, Inc.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* This program is free software; you can redistribute it and/or modify
|
|
Packit |
a4058c |
* it under the terms of the GNU General Public License as published by
|
|
Packit |
a4058c |
* the Free Software Foundation; either version 2 of the License, or
|
|
Packit |
a4058c |
* (at your option) any later version.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* This program is distributed in the hope that it will be useful,
|
|
Packit |
a4058c |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
a4058c |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
a4058c |
* GNU General Public License for more details.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* You should have received a copy of the GNU General Public License
|
|
Packit |
a4058c |
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Author: Matthias Clasen
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
#include "config.h"
|
|
Packit |
a4058c |
#include "gdk-pixbuf/gdk-pixbuf.h"
|
|
Packit |
a4058c |
#include "test-common.h"
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
test_scale (gconstpointer data)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
const gchar *filename = data;
|
|
Packit |
a4058c |
const gchar *path;
|
|
Packit |
a4058c |
GError *error = NULL;
|
|
Packit |
a4058c |
GdkPixbuf *ref;
|
|
Packit |
a4058c |
GdkPixbuf *pixbuf;
|
|
Packit |
a4058c |
gint width, height;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (!format_supported (filename))
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
g_test_skip ("format not supported");
|
|
Packit |
a4058c |
return;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
path = g_test_get_filename (G_TEST_DIST, filename, NULL);
|
|
Packit |
a4058c |
ref = gdk_pixbuf_new_from_file (path, &error);
|
|
Packit |
a4058c |
g_assert_no_error (error);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
width = gdk_pixbuf_get_width (ref);
|
|
Packit |
a4058c |
height = gdk_pixbuf_get_height (ref);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
pixbuf = gdk_pixbuf_new_from_file_at_scale (path, 2 * width, 3 * height, FALSE, &error);
|
|
Packit |
a4058c |
g_assert_no_error (error);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_assert_cmpint (gdk_pixbuf_get_width (pixbuf), ==, 2 * width);
|
|
Packit |
a4058c |
g_assert_cmpint (gdk_pixbuf_get_height (pixbuf), ==, 3 * height);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_object_unref (pixbuf);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
pixbuf = gdk_pixbuf_new_from_file_at_scale (path, 4 * width, 2 * height, TRUE, &error);
|
|
Packit |
a4058c |
g_assert_no_error (error);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_assert_cmpint (gdk_pixbuf_get_width (pixbuf), ==, 2 * width);
|
|
Packit |
a4058c |
g_assert_cmpint (gdk_pixbuf_get_height (pixbuf), ==, 2 * height);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_object_unref (pixbuf);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_object_unref (ref);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
test_scale_down (gconstpointer data)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
const gchar *filename = data;
|
|
Packit |
a4058c |
const gchar *path;
|
|
Packit |
a4058c |
GError *error = NULL;
|
|
Packit |
a4058c |
GdkPixbuf *ref;
|
|
Packit |
a4058c |
GdkPixbuf *pixbuf;
|
|
Packit |
a4058c |
gint width, height;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (!format_supported (filename))
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
g_test_skip ("format not supported");
|
|
Packit |
a4058c |
return;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
path = g_test_get_filename (G_TEST_DIST, filename, NULL);
|
|
Packit |
a4058c |
ref = gdk_pixbuf_new_from_file (path, &error);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (skip_if_insufficient_memory (&error))
|
|
Packit |
a4058c |
return;
|
|
Packit |
a4058c |
g_assert_no_error (error);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
width = gdk_pixbuf_get_width (ref);
|
|
Packit |
a4058c |
height = gdk_pixbuf_get_height (ref);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
pixbuf = gdk_pixbuf_scale_simple (ref, width / 10, height / 10, GDK_INTERP_BILINEAR);
|
|
Packit |
a4058c |
g_assert (pixbuf != NULL);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_object_unref (ref);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
test_add_alpha (gconstpointer data)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
const gchar *filename = data;
|
|
Packit |
a4058c |
const gchar *path;
|
|
Packit |
a4058c |
GError *error = NULL;
|
|
Packit |
a4058c |
GdkPixbuf *ref;
|
|
Packit |
a4058c |
GdkPixbuf *pixbuf;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (!format_supported (filename))
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
g_test_skip ("format not supported");
|
|
Packit |
a4058c |
return;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
path = g_test_get_filename (G_TEST_DIST, filename, NULL);
|
|
Packit |
a4058c |
ref = gdk_pixbuf_new_from_file (path, &error);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (skip_if_insufficient_memory (&error))
|
|
Packit |
a4058c |
return;
|
|
Packit |
a4058c |
g_assert_no_error (error);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
pixbuf = gdk_pixbuf_add_alpha (ref, FALSE, 0, 0, 0);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (pixbuf == NULL)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
g_test_skip ("Couldn't add alpha to the image - your system probably lacks sufficient memory.");
|
|
Packit |
a4058c |
g_object_unref (ref);
|
|
Packit |
a4058c |
return;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_object_unref (pixbuf);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
pixbuf = gdk_pixbuf_add_alpha (ref, TRUE, 0, 0, 255);
|
|
Packit |
a4058c |
g_assert (pixbuf != NULL);
|
|
Packit |
a4058c |
g_object_unref (pixbuf);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_object_unref (ref);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
test_rotate (gconstpointer data)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
const gchar *filename = data;
|
|
Packit |
a4058c |
const gchar *path;
|
|
Packit |
a4058c |
GError *error = NULL;
|
|
Packit |
a4058c |
GdkPixbuf *ref;
|
|
Packit |
a4058c |
GdkPixbuf *pixbuf;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (!format_supported (filename))
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
g_test_skip ("format not supported");
|
|
Packit |
a4058c |
return;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
path = g_test_get_filename (G_TEST_DIST, filename, NULL);
|
|
Packit |
a4058c |
ref = gdk_pixbuf_new_from_file (path, &error);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (skip_if_insufficient_memory (&error))
|
|
Packit |
a4058c |
return;
|
|
Packit |
a4058c |
g_assert_no_error (error);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
pixbuf = gdk_pixbuf_rotate_simple (ref, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (pixbuf == NULL)
|
|
Packit |
a4058c |
g_test_skip ("Couldn't rotate the image - your system probably lacks sufficient memory.");
|
|
Packit |
a4058c |
else
|
|
Packit |
a4058c |
g_object_unref (pixbuf);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_object_unref (ref);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* Test images creation functions */
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* Create a 256x256 checkerboard of (1,1,1) and (255,255,255) pixels,
|
|
Packit |
a4058c |
* scale it to exactly half size and check that all pixels are (128,128,128). */
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
test_halve_checkerboard (gconstpointer data)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
GdkInterpType interp_type = *(GdkInterpType *) data;
|
|
Packit |
a4058c |
const GdkPixbuf *source; /* Source image */
|
|
Packit |
a4058c |
gint width = 256, height = 256; /* Size of source image */
|
|
Packit |
a4058c |
gint scaled_width, scaled_height; /* Size of scaled image */
|
|
Packit |
a4058c |
GdkPixbuf *scaled; /* Scaled version */
|
|
Packit |
a4058c |
guchar *row; /* Pointer to start of row of pixels within the image */
|
|
Packit |
a4058c |
guchar *pixel; /* Pointer to current pixel data in row */
|
|
Packit |
a4058c |
guint x, y;
|
|
Packit |
a4058c |
guchar expected; /* Expected color of all pixels */
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
expected = (interp_type == GDK_INTERP_NEAREST) ? 255 : 128;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
source = make_checkerboard (width, height);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
scaled = gdk_pixbuf_scale_simple (source, width / 2, height / 2, interp_type);
|
|
Packit |
a4058c |
scaled_width = gdk_pixbuf_get_width (scaled);
|
|
Packit |
a4058c |
scaled_height = gdk_pixbuf_get_height (scaled);
|
|
Packit |
a4058c |
g_assert_cmpint (scaled_width, >, 0);
|
|
Packit |
a4058c |
g_assert_cmpint (scaled_height, >, 0);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* Check that the result is all gray (or all white in the case of NEAREST) */
|
|
Packit |
a4058c |
for (y = 0, row = gdk_pixbuf_get_pixels (scaled);
|
|
Packit |
a4058c |
y < (guint) scaled_height;
|
|
Packit |
a4058c |
y++, row += gdk_pixbuf_get_rowstride (scaled))
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
for (x = 0, pixel = row;
|
|
Packit |
a4058c |
x < (guint) scaled_width;
|
|
Packit |
a4058c |
x++, pixel += gdk_pixbuf_get_n_channels (scaled))
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
if (!(pixel[0] == expected && pixel[1] == expected && pixel[2] == expected))
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
/* Expected failure: HYPER has a different opinion about the color
|
|
Packit |
a4058c |
* of the corner pixels: (126,126,126) and (130,130,130) */
|
|
Packit |
a4058c |
if (interp_type == GDK_INTERP_HYPER &&
|
|
Packit |
a4058c |
(x == 0 || x == scaled_width - 1) &&
|
|
Packit |
a4058c |
(y == 0 || y == scaled_height - 1))
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
continue;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
g_test_fail ();
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_object_unref (G_OBJECT (scaled));
|
|
Packit |
a4058c |
g_object_unref (G_OBJECT (source));
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* Crop a region out of a source image using subpixbuf() and using the scaler,
|
|
Packit |
a4058c |
* and check that the results are the same */
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
crop_n_compare (const GdkPixbuf *source,
|
|
Packit |
a4058c |
gint offset_x,
|
|
Packit |
a4058c |
gint offset_y,
|
|
Packit |
a4058c |
guint width,
|
|
Packit |
a4058c |
guint height,
|
|
Packit |
a4058c |
GdkInterpType interp_type)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
GdkPixbuf *cropped, *scaled;
|
|
Packit |
a4058c |
guchar *crow, *srow; /* Pointer to current row in image data */
|
|
Packit |
a4058c |
guchar *cpixel, *spixel; /* Pointer to current pixel in row */
|
|
Packit |
a4058c |
guint x, y;
|
|
Packit |
a4058c |
gint scaled_width, scaled_height; /* Size of scaled image */
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
cropped = gdk_pixbuf_new_subpixbuf ((GdkPixbuf *)source, offset_x, offset_y, width, height);
|
|
Packit |
a4058c |
g_assert_nonnull (cropped);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
scaled = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, width, height);
|
|
Packit |
a4058c |
g_assert_nonnull (scaled);
|
|
Packit |
a4058c |
gdk_pixbuf_scale (source, scaled,
|
|
Packit |
a4058c |
0, 0, /* dest_[xy] */
|
|
Packit |
a4058c |
width, height, /* dest_width/height */
|
|
Packit |
a4058c |
-1.0 * offset_x, -1.0 * offset_y, /* offset_[xy] */
|
|
Packit |
a4058c |
1.0, 1.0, /* scale_[xy] */
|
|
Packit |
a4058c |
interp_type);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
scaled_width = gdk_pixbuf_get_width (scaled);
|
|
Packit |
a4058c |
scaled_height = gdk_pixbuf_get_height (scaled);
|
|
Packit |
a4058c |
g_assert_cmpint (scaled_width, >, 0);
|
|
Packit |
a4058c |
g_assert_cmpint (scaled_height, >, 0);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
for (y = 0, crow = gdk_pixbuf_get_pixels (cropped),
|
|
Packit |
a4058c |
srow = gdk_pixbuf_get_pixels (scaled);
|
|
Packit |
a4058c |
y < scaled_height;
|
|
Packit |
a4058c |
y++, crow += gdk_pixbuf_get_rowstride (cropped),
|
|
Packit |
a4058c |
srow += gdk_pixbuf_get_rowstride (scaled))
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
for (x = 0, cpixel = crow, spixel = srow;
|
|
Packit |
a4058c |
x < scaled_width;
|
|
Packit |
a4058c |
x++, cpixel += gdk_pixbuf_get_n_channels (cropped),
|
|
Packit |
a4058c |
spixel += gdk_pixbuf_get_n_channels (scaled))
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
if (!(spixel[0] == cpixel[0] &&
|
|
Packit |
a4058c |
spixel[1] == cpixel[1] &&
|
|
Packit |
a4058c |
spixel[2] == cpixel[2]))
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
/* Expected failure: HYPER has a different opinion about the
|
|
Packit |
a4058c |
* colors of the edge pixels */
|
|
Packit |
a4058c |
if (interp_type == GDK_INTERP_HYPER &&
|
|
Packit |
a4058c |
((x == 0 || x == scaled_width - 1) ||
|
|
Packit |
a4058c |
(y == 0 || y == scaled_height - 1)))
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
continue;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
g_test_fail();
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_object_unref (G_OBJECT (cropped));
|
|
Packit |
a4058c |
g_object_unref (G_OBJECT (scaled));
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* Check that offsets work.
|
|
Packit |
a4058c |
* We should be able to copy a region of an image using the scaler using
|
|
Packit |
a4058c |
* negative offsets. */
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
test_offset (gconstpointer data)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
GdkInterpType interp_type = *(GdkInterpType *) data;
|
|
Packit |
a4058c |
gint width = 256, height = 256;
|
|
Packit |
a4058c |
const GdkPixbuf *source; /* Source image */
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
source = make_rg (width, height);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* Check that the scaler correctly crops out an image half the size of the
|
|
Packit |
a4058c |
* original from each corner and from the middle */
|
|
Packit |
a4058c |
crop_n_compare (source, 0, 0, width / 2, height / 2, interp_type);
|
|
Packit |
a4058c |
crop_n_compare (source, width / 2, 0, width / 2, height / 2, interp_type);
|
|
Packit |
a4058c |
crop_n_compare (source, 0, height / 2, width / 2, height / 2, interp_type);
|
|
Packit |
a4058c |
crop_n_compare (source, width / 2, height / 2, width / 2, height / 2, interp_type);
|
|
Packit |
a4058c |
crop_n_compare (source, width / 4, height / 4, width / 2, height / 2, interp_type);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_object_unref (G_OBJECT (source));
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* Test the dest_x and dest_y fields by making a copy of an image by
|
|
Packit |
a4058c |
* scaling 1:1 and using dest to copy the four quadrants separately.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* When scaled, images are:
|
|
Packit |
a4058c |
* 1) scaled by the scale factors with respect to the top-left corner
|
|
Packit |
a4058c |
* 2) translated by the offsets (negative to shift the image left/up in its
|
|
Packit |
a4058c |
* frame)
|
|
Packit |
a4058c |
* 3) a region of size dest_width x dest-height starting at (dest_x,dest_y)
|
|
Packit |
a4058c |
* in the scaled-and-offset image is copied to (dest_x,dest_y) in the
|
|
Packit |
a4058c |
* destination image. See the illustration at
|
|
Packit |
a4058c |
* https://developer.gnome.org/gdk-pixbuf/2.22/gdk-pixbuf-scaling.html#gdk-pixbuf-composite */
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
test_dest (gconstpointer data)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
GdkInterpType interp_type = *(GdkInterpType *) data;
|
|
Packit |
a4058c |
gint width = 256, height = 256;
|
|
Packit |
a4058c |
const GdkPixbuf *source; /* Source image */
|
|
Packit |
a4058c |
GdkPixbuf *copy; /* Destination image */
|
|
Packit |
a4058c |
gint x, y;
|
|
Packit |
a4058c |
guchar *srow, *crow; /* Pointer to current row in source and copy data */
|
|
Packit |
a4058c |
guchar *spixel, *cpixel; /* Pointer to current pixel in row */
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
source = make_rg (width, height);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
copy = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, width, height);
|
|
Packit |
a4058c |
g_assert_nonnull (copy);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* Copy the four quadrants with a no-op scale */
|
|
Packit |
a4058c |
gdk_pixbuf_scale ((const GdkPixbuf *)source, copy,
|
|
Packit |
a4058c |
0, 0, /* dest_[xy] */
|
|
Packit |
a4058c |
width / 2, height / 2, /* dest_width/height */
|
|
Packit |
a4058c |
0.0, 0.0, /* offset_[xy] */
|
|
Packit |
a4058c |
1.0, 1.0, /* scale_[xy] */
|
|
Packit |
a4058c |
interp_type);
|
|
Packit |
a4058c |
gdk_pixbuf_scale ((const GdkPixbuf *)source, copy,
|
|
Packit |
a4058c |
width / 2, 0, /* dest_[xy] */
|
|
Packit |
a4058c |
width / 2, height / 2, /* dest_width/height */
|
|
Packit |
a4058c |
0.0, 0.0, /* offset_[xy] */
|
|
Packit |
a4058c |
1.0, 1.0, /* scale_[xy] */
|
|
Packit |
a4058c |
interp_type);
|
|
Packit |
a4058c |
gdk_pixbuf_scale ((const GdkPixbuf *)source, copy,
|
|
Packit |
a4058c |
0, height / 2, /* dest_[xy] */
|
|
Packit |
a4058c |
width / 2, height / 2, /* dest_width/height */
|
|
Packit |
a4058c |
0.0, 0.0, /* offset_[xy] */
|
|
Packit |
a4058c |
1.0, 1.0, /* scale_[xy] */
|
|
Packit |
a4058c |
interp_type);
|
|
Packit |
a4058c |
gdk_pixbuf_scale ((const GdkPixbuf *)source, copy,
|
|
Packit |
a4058c |
width / 2, height / 2, /* dest_[xy] */
|
|
Packit |
a4058c |
width / 2, height / 2, /* dest_width/height */
|
|
Packit |
a4058c |
0.0, 0.0, /* offset_[xy] */
|
|
Packit |
a4058c |
1.0, 1.0, /* scale_[xy] */
|
|
Packit |
a4058c |
interp_type);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* Compare the original and the copy */
|
|
Packit |
a4058c |
for (y = 0, srow = gdk_pixbuf_get_pixels (source),
|
|
Packit |
a4058c |
crow = gdk_pixbuf_get_pixels (copy);
|
|
Packit |
a4058c |
y < gdk_pixbuf_get_height (source);
|
|
Packit |
a4058c |
y++, srow += gdk_pixbuf_get_rowstride (source),
|
|
Packit |
a4058c |
crow += gdk_pixbuf_get_rowstride (copy))
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
for (x = 0, spixel = srow, cpixel = crow;
|
|
Packit |
a4058c |
x < gdk_pixbuf_get_width (source);
|
|
Packit |
a4058c |
x++, spixel += gdk_pixbuf_get_n_channels (source),
|
|
Packit |
a4058c |
cpixel += gdk_pixbuf_get_n_channels (copy))
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
if (!(spixel[0] == cpixel[0] &&
|
|
Packit |
a4058c |
spixel[1] == cpixel[1] &&
|
|
Packit |
a4058c |
spixel[2] == cpixel[2]))
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
g_test_fail();
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_object_unref (G_OBJECT (source));
|
|
Packit |
a4058c |
g_object_unref (G_OBJECT (copy));
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
int
|
|
Packit |
a4058c |
main (int argc, char **argv)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
GdkInterpType nearest = GDK_INTERP_NEAREST;
|
|
Packit |
a4058c |
GdkInterpType tiles = GDK_INTERP_TILES;
|
|
Packit |
a4058c |
GdkInterpType bilinear = GDK_INTERP_BILINEAR;
|
|
Packit |
a4058c |
GdkInterpType hyper = GDK_INTERP_HYPER;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_test_init (&argc, &argv, NULL);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_test_add_data_func ("/pixbuf/scale/png", "test-images/randomly-modified/valid.1.png", test_scale);
|
|
Packit |
a4058c |
g_test_add_data_func ("/pixbuf/scale/bmp", "test-images/randomly-modified/valid.1.bmp", test_scale);
|
|
Packit |
a4058c |
g_test_add_data_func ("/pixbuf/scale/gif", "test-images/randomly-modified/valid.1.gif", test_scale);
|
|
Packit |
a4058c |
g_test_add_data_func ("/pixbuf/scale/jpeg", "test-images/randomly-modified/valid.1.jpeg", test_scale);
|
|
Packit |
a4058c |
g_test_add_data_func ("/pixbuf/scale/tga", "test-images/randomly-modified/valid.1.tga", test_scale);
|
|
Packit |
a4058c |
g_test_add_data_func ("/pixbuf/scale/xpm", "test-images/randomly-modified/valid.1.xpm", test_scale);
|
|
Packit |
a4058c |
g_test_add_data_func ("/pixbuf/scale/xbm", "test-images/randomly-modified/valid.1.xbm", test_scale);
|
|
Packit |
a4058c |
if (g_test_slow ())
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
g_test_add_data_func ("/pixbuf/scale/png/large", "large.png", test_scale_down);
|
|
Packit |
a4058c |
g_test_add_data_func ("/pixbuf/scale/jpeg/large", "large.jpg", test_scale_down);
|
|
Packit |
a4058c |
g_test_add_data_func ("/pixbuf/add-alpha/large", "large.png", test_add_alpha);
|
|
Packit |
a4058c |
g_test_add_data_func ("/pixbuf/rotate/large", "large.png", test_rotate);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_test_add_data_func ("/pixbuf/scale/halve-checkerboard/nearest", &nearest, test_halve_checkerboard);
|
|
Packit |
a4058c |
g_test_add_data_func ("/pixbuf/scale/halve-checkerboard/tiles", &tiles, test_halve_checkerboard);
|
|
Packit |
a4058c |
g_test_add_data_func ("/pixbuf/scale/halve-checkerboard/bilinear", &bilinear, test_halve_checkerboard);
|
|
Packit |
a4058c |
g_test_add_data_func ("/pixbuf/scale/halve-checkerboard/hyper", &hyper, test_halve_checkerboard);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_test_add_data_func ("/pixbuf/scale/offset/nearest", &nearest, test_offset);
|
|
Packit |
a4058c |
g_test_add_data_func ("/pixbuf/scale/offset/tiles", &tiles, test_offset);
|
|
Packit |
a4058c |
g_test_add_data_func ("/pixbuf/scale/offset/bilinear", &bilinear, test_offset);
|
|
Packit |
a4058c |
g_test_add_data_func ("/pixbuf/scale/offset/hyper", &hyper, test_offset);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_test_add_data_func ("/pixbuf/scale/dest/nearest", &nearest, test_dest);
|
|
Packit |
a4058c |
g_test_add_data_func ("/pixbuf/scale/dest/tiles", &tiles, test_dest);
|
|
Packit |
a4058c |
g_test_add_data_func ("/pixbuf/scale/dest/bilinear", &bilinear, test_dest);
|
|
Packit |
a4058c |
/* Don't bother with hyper as it changes the edge pixels */
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
return g_test_run ();
|
|
Packit |
a4058c |
}
|