<commit_before>/* Swfdec
 * Copyright (C) 2007 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 
 * Boston, MA  02110-1301  USA
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "swfdec_test_image.h"
#include "swfdec_test_function.h"
#include "swfdec_test_utils.h"

#define SWFDEC_TEST_IMAGE_IS_VALID(image) ((image)->surface && \
    cairo_surface_status ((image)->surface) == CAIRO_STATUS_SUCCESS)

SwfdecAsObject *
swfdec_test_image_new (SwfdecAsContext *context, guint width, guint height)
{
  SwfdecAsValue val;
  SwfdecAsObject *ret;

  ret = g_object_new (SWFDEC_TYPE_TEST_IMAGE, "context", context, NULL);
  swfdec_as_object_get_variable (context->global, 
      swfdec_as_context_get_string (context, "Image"), &val);
  if (SWFDEC_AS_VALUE_IS_OBJECT (&val))
    swfdec_as_object_set_constructor (ret, SWFDEC_AS_VALUE_GET_OBJECT (&val));

  SWFDEC_TEST_IMAGE (ret)->surface = 
    cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
  return ret;
}

/*** SWFDEC_TEST_IMAGE ***/

G_DEFINE_TYPE (SwfdecTestImage, swfdec_test_image, SWFDEC_TYPE_AS_OBJECT)

static void
swfdec_test_image_dispose (GObject *object)
{
  SwfdecTestImage *image = SWFDEC_TEST_IMAGE (object);

  if (image->surface) {
    cairo_surface_destroy (image->surface);
    image->surface = NULL;
  }

  G_OBJECT_CLASS (swfdec_test_image_parent_class)->dispose (object);
}

static void
swfdec_test_image_class_init (SwfdecTestImageClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->dispose = swfdec_test_image_dispose;
}

static void
swfdec_test_image_init (SwfdecTestImage *this)
{
}

/*** AS CODE ***/

/* Compare two buffers, returning the number of pixels that are
 * different and the maximum difference of any single color channel in
 * result_ret.
 *
 * This function should be rewritten to compare all formats supported by
 * cairo_format_t instead of taking a mask as a parameter.
 */
static gboolean
buffer_diff_core (unsigned char *buf_a,
		  unsigned char *buf_b,
		  unsigned char *buf_diff,
		  int		width,
		  int		height,
		  int		stride_a,
		  int		stride_b,
		  int		stride_diff)
{
    int x, y;
    gboolean result = TRUE;
    guint32 *row_a, *row_b, *row;

    for (y = 0; y < height; y++) {
	row_a = (guint32 *) (buf_a + y * stride_a);
	row_b = (guint32 *) (buf_b + y * stride_b);
	row = (guint32 *) (buf_diff + y * stride_diff);
	for (x = 0; x < width; x++) {
	    /* check if the pixels are the same */
	    if (row_a[x] != row_b[x]) {
		int channel;<commit_msg>fix cast alignment warning in testing code<commit_after>/* Swfdec
 * Copyright (C) 2007 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 
 * Boston, MA  02110-1301  USA
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "swfdec_test_image.h"
#include "swfdec_test_function.h"
#include "swfdec_test_utils.h"

#define SWFDEC_TEST_IMAGE_IS_VALID(image) ((image)->surface && \
    cairo_surface_status ((image)->surface) == CAIRO_STATUS_SUCCESS)

SwfdecAsObject *
swfdec_test_image_new (SwfdecAsContext *context, guint width, guint height)
{
  SwfdecAsValue val;
  SwfdecAsObject *ret;

  ret = g_object_new (SWFDEC_TYPE_TEST_IMAGE, "context", context, NULL);
  swfdec_as_object_get_variable (context->global, 
      swfdec_as_context_get_string (context, "Image"), &val);
  if (SWFDEC_AS_VALUE_IS_OBJECT (&val))
    swfdec_as_object_set_constructor (ret, SWFDEC_AS_VALUE_GET_OBJECT (&val));

  SWFDEC_TEST_IMAGE (ret)->surface = 
    cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
  return ret;
}

/*** SWFDEC_TEST_IMAGE ***/

G_DEFINE_TYPE (SwfdecTestImage, swfdec_test_image, SWFDEC_TYPE_AS_OBJECT)

static void
swfdec_test_image_dispose (GObject *object)
{
  SwfdecTestImage *image = SWFDEC_TEST_IMAGE (object);

  if (image->surface) {
    cairo_surface_destroy (image->surface);
    image->surface = NULL;
  }

  G_OBJECT_CLASS (swfdec_test_image_parent_class)->dispose (object);
}

static void
swfdec_test_image_class_init (SwfdecTestImageClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->dispose = swfdec_test_image_dispose;
}

static void
swfdec_test_image_init (SwfdecTestImage *this)
{
}

/*** AS CODE ***/

/* Compare two buffers, returning the number of pixels that are
 * different and the maximum difference of any single color channel in
 * result_ret.
 *
 * This function should be rewritten to compare all formats supported by
 * cairo_format_t instead of taking a mask as a parameter.
 */
static gboolean
buffer_diff_core (unsigned char *buf_a,
		  unsigned char *buf_b,
		  unsigned char *buf_diff,
		  int		width,
		  int		height,
		  int		stride_a,
		  int		stride_b,
		  int		stride_diff)
{
    int x, y;
    gboolean result = TRUE;
    guint32 *row_a, *row_b, *row;

    for (y = 0; y < height; y++) {
	row_a = (guint32 *) (gpointer) (buf_a + y * stride_a);
	row_b = (guint32 *) (gpointer) (buf_b + y * stride_b);
	row = (guint32 *) (gpointer) (buf_diff + y * stride_diff);
	for (x = 0; x < width; x++) {
	    /* check if the pixels are the same */
	    if (row_a[x] != row_b[x]) {
		int channel;
{'fraction_non_alphanumeric': 0.09694350108058043, 'fraction_numerical': 0.008953380673047236, 'mean_word_length': 4.3369028006589785, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7626268', 'n_tokens_mistral': 2293, 'n_tokens_neox': 2191, 'n_words': 674}