/* LIBPIKA - The PIKA Library
 * Copyright (C) 1995-2003 Peter Mattis and Spencer Kimball
 *
 * pikapattern_pdb.c
 *
 * 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 3 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, see
 * <https://www.gnu.org/licenses/>.
 */

/* NOTE: This file is auto-generated by pdbgen.pl */

#include "config.h"

#include "stamp-pdbgen.h"

#include "pika.h"


/**
 * SECTION: pikapattern
 * @title: pikapattern
 * @short_description: Installable object used by fill and clone tools.
 *
 * Installable object used by fill and clone tools.
 **/


/**
 * pika_pattern_get_by_name:
 * @name: The name of the pattern.
 *
 * Returns the pattern with the given name.
 *
 * Returns the pattern with the given name.
 *
 * Returns: (transfer none): The pattern.
 *
 * Since: 3.0
 **/
PikaPattern *
pika_pattern_get_by_name (const gchar *name)
{
  PikaValueArray *args;
  PikaValueArray *return_vals;
  PikaPattern *pattern = NULL;

  args = pika_value_array_new_from_types (NULL,
                                          G_TYPE_STRING, name,
                                          G_TYPE_NONE);

  return_vals = _pika_pdb_run_procedure_array (pika_get_pdb (),
                                               "pika-pattern-get-by-name",
                                               args);
  pika_value_array_unref (args);

  if (PIKA_VALUES_GET_ENUM (return_vals, 0) == PIKA_PDB_SUCCESS)
    pattern = PIKA_VALUES_GET_PATTERN (return_vals, 1);

  pika_value_array_unref (return_vals);

  return pattern;
}

/**
 * pika_pattern_get_info:
 * @pattern: The pattern.
 * @width: (out): The pattern width.
 * @height: (out): The pattern height.
 * @bpp: (out): The pattern bpp.
 *
 * Gets information about the pattern.
 *
 * Gets information about the pattern: the pattern extents (width and
 * height) and bytes per pixel.
 *
 * Returns: TRUE on success.
 *
 * Since: 2.2
 **/
gboolean
pika_pattern_get_info (PikaPattern *pattern,
                       gint        *width,
                       gint        *height,
                       gint        *bpp)
{
  PikaValueArray *args;
  PikaValueArray *return_vals;
  gboolean success = TRUE;

  args = pika_value_array_new_from_types (NULL,
                                          PIKA_TYPE_PATTERN, pattern,
                                          G_TYPE_NONE);

  return_vals = _pika_pdb_run_procedure_array (pika_get_pdb (),
                                               "pika-pattern-get-info",
                                               args);
  pika_value_array_unref (args);

  *width = 0;
  *height = 0;
  *bpp = 0;

  success = PIKA_VALUES_GET_ENUM (return_vals, 0) == PIKA_PDB_SUCCESS;

  if (success)
    {
      *width = PIKA_VALUES_GET_INT (return_vals, 1);
      *height = PIKA_VALUES_GET_INT (return_vals, 2);
      *bpp = PIKA_VALUES_GET_INT (return_vals, 3);
    }

  pika_value_array_unref (return_vals);

  return success;
}

/**
 * _pika_pattern_get_pixels:
 * @pattern: The pattern.
 * @width: (out): The pattern width.
 * @height: (out): The pattern height.
 * @bpp: (out): The pattern bpp.
 * @color_bytes: (out) (transfer full): The pattern data.
 *
 * Gets information about the pattern (including pixels).
 *
 * Gets information about the pattern: the pattern extents (width and
 * height), its bpp, and its pixel data.
 *
 * Returns: TRUE on success.
 *
 * Since: 2.2
 **/
gboolean
_pika_pattern_get_pixels (PikaPattern  *pattern,
                          gint         *width,
                          gint         *height,
                          gint         *bpp,
                          GBytes      **color_bytes)
{
  PikaValueArray *args;
  PikaValueArray *return_vals;
  gboolean success = TRUE;

  args = pika_value_array_new_from_types (NULL,
                                          PIKA_TYPE_PATTERN, pattern,
                                          G_TYPE_NONE);

  return_vals = _pika_pdb_run_procedure_array (pika_get_pdb (),
                                               "pika-pattern-get-pixels",
                                               args);
  pika_value_array_unref (args);

  *width = 0;
  *height = 0;
  *bpp = 0;
  *color_bytes = NULL;

  success = PIKA_VALUES_GET_ENUM (return_vals, 0) == PIKA_PDB_SUCCESS;

  if (success)
    {
      *width = PIKA_VALUES_GET_INT (return_vals, 1);
      *height = PIKA_VALUES_GET_INT (return_vals, 2);
      *bpp = PIKA_VALUES_GET_INT (return_vals, 3);
      *color_bytes = PIKA_VALUES_DUP_BYTES (return_vals, 4);
    }

  pika_value_array_unref (return_vals);

  return success;
}
