/* LIBGIMP - The GIMP Library
 * Copyright (C) 1995-2003 Peter Mattis and Spencer Kimball
 *
 * gimpbrush_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 2 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., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/* NOTE: This file is autogenerated by pdbgen.pl */

#include "config.h"

#include <string.h>

#include "gimp.h"

/**
 * gimp_brush_new:
 * @name: The requested name of the new brush.
 *
 * Creates a new brush
 *
 * This procedure creates a new, uninitialized brush
 *
 * Returns: The actual new brush name.
 *
 * Since: GIMP 2.2
 */
gchar *
gimp_brush_new (const gchar *name)
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gchar *ret_name = NULL;

  return_vals = gimp_run_procedure ("gimp_brush_new",
				    &nreturn_vals,
				    GIMP_PDB_STRING, name,
				    GIMP_PDB_END);

  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
    ret_name = g_strdup (return_vals[1].data.d_string);

  gimp_destroy_params (return_vals, nreturn_vals);

  return ret_name;
}

/**
 * gimp_brush_duplicate:
 * @name: The brush name.
 *
 * Duplicates a brush
 *
 * This procedure creates an identical brush by a different name
 *
 * Returns: The name of the brush's copy.
 *
 * Since: GIMP 2.2
 */
gchar *
gimp_brush_duplicate (const gchar *name)
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gchar *ret_name = NULL;

  return_vals = gimp_run_procedure ("gimp_brush_duplicate",
				    &nreturn_vals,
				    GIMP_PDB_STRING, name,
				    GIMP_PDB_END);

  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
    ret_name = g_strdup (return_vals[1].data.d_string);

  gimp_destroy_params (return_vals, nreturn_vals);

  return ret_name;
}

/**
 * gimp_brush_rename:
 * @name: The brush name.
 * @new_name: The new name of the brush.
 *
 * Rename a brush
 *
 * This procedure renames a brush
 *
 * Returns: The actual new name of the brush.
 *
 * Since: GIMP 2.2
 */
gchar *
gimp_brush_rename (const gchar *name,
		   const gchar *new_name)
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gchar *ret_name = NULL;

  return_vals = gimp_run_procedure ("gimp_brush_rename",
				    &nreturn_vals,
				    GIMP_PDB_STRING, name,
				    GIMP_PDB_STRING, new_name,
				    GIMP_PDB_END);

  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
    ret_name = g_strdup (return_vals[1].data.d_string);

  gimp_destroy_params (return_vals, nreturn_vals);

  return ret_name;
}

/**
 * gimp_brush_delete:
 * @name: The brush name.
 *
 * Deletes a brush
 *
 * This procedure deletes a brush
 *
 * Returns: TRUE on success.
 *
 * Since: GIMP 2.2
 */
gboolean
gimp_brush_delete (const gchar *name)
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gboolean success = TRUE;

  return_vals = gimp_run_procedure ("gimp_brush_delete",
				    &nreturn_vals,
				    GIMP_PDB_STRING, name,
				    GIMP_PDB_END);

  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  gimp_destroy_params (return_vals, nreturn_vals);

  return success;
}

/**
 * gimp_brush_get_info:
 * @name: The brush name.
 * @width: The brush width.
 * @height: The brush height.
 * @mask_bpp: The brush mask bpp.
 * @color_bpp: The brush color bpp.
 *
 * Retrieve information about the specified brush.
 *
 * This procedure retrieves information about the specified brush. This
 * includes the brush name, and the brush extents (width and height).
 *
 * Returns: TRUE on success.
 *
 * Since: GIMP 2.2
 */
gboolean
gimp_brush_get_info (const gchar *name,
		     gint        *width,
		     gint        *height,
		     gint        *mask_bpp,
		     gint        *color_bpp)
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gboolean success = TRUE;

  return_vals = gimp_run_procedure ("gimp_brush_get_info",
				    &nreturn_vals,
				    GIMP_PDB_STRING, name,
				    GIMP_PDB_END);

  *width = 0;
  *height = 0;
  *mask_bpp = 0;
  *color_bpp = 0;

  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  if (success)
    {
      *width = return_vals[1].data.d_int32;
      *height = return_vals[2].data.d_int32;
      *mask_bpp = return_vals[3].data.d_int32;
      *color_bpp = return_vals[4].data.d_int32;
    }

  gimp_destroy_params (return_vals, nreturn_vals);

  return success;
}

/**
 * gimp_brush_get_pixels:
 * @name: The brush name.
 * @width: The brush width.
 * @height: The brush height.
 * @mask_bpp: The brush mask bpp.
 * @num_mask_bytes: Length of brush mask data.
 * @mask_bytes: The brush mask data.
 * @color_bpp: The brush color bpp.
 * @num_color_bytes: Length of brush color data.
 * @color_bytes: The brush color data.
 *
 * Retrieve information about the specified brush.
 *
 * This procedure retrieves information about the specified brush. This
 * includes the brush extents (width and height) and its pixels data.
 *
 * Returns: TRUE on success.
 *
 * Since: GIMP 2.2
 */
gboolean
gimp_brush_get_pixels (const gchar  *name,
		       gint         *width,
		       gint         *height,
		       gint         *mask_bpp,
		       gint         *num_mask_bytes,
		       guint8      **mask_bytes,
		       gint         *color_bpp,
		       gint         *num_color_bytes,
		       guint8      **color_bytes)
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gboolean success = TRUE;

  return_vals = gimp_run_procedure ("gimp_brush_get_pixels",
				    &nreturn_vals,
				    GIMP_PDB_STRING, name,
				    GIMP_PDB_END);

  *width = 0;
  *height = 0;
  *mask_bpp = 0;
  *num_mask_bytes = 0;
  *mask_bytes = NULL;
  *color_bpp = 0;
  *num_color_bytes = 0;
  *color_bytes = NULL;

  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  if (success)
    {
      *width = return_vals[1].data.d_int32;
      *height = return_vals[2].data.d_int32;
      *mask_bpp = return_vals[3].data.d_int32;
      *num_mask_bytes = return_vals[4].data.d_int32;
      *mask_bytes = g_new (guint8, *num_mask_bytes);
      memcpy (*mask_bytes, return_vals[5].data.d_int8array,
	      *num_mask_bytes * sizeof (guint8));
      *color_bpp = return_vals[6].data.d_int32;
      *num_color_bytes = return_vals[7].data.d_int32;
      *color_bytes = g_new (guint8, *num_color_bytes);
      memcpy (*color_bytes, return_vals[8].data.d_int8array,
	      *num_color_bytes * sizeof (guint8));
    }

  gimp_destroy_params (return_vals, nreturn_vals);

  return success;
}

/**
 * gimp_brush_get_spacing:
 * @name: The brush name.
 * @spacing: The brush spacing.
 *
 * Get the brush spacing.
 *
 * This procedure returns the spacing setting for the specified brush.
 * The return value is an integer between 0 and 1000 which represents
 * percentage of the maximum of the width and height of the mask.
 *
 * Returns: TRUE on success.
 *
 * Since: GIMP 2.2
 */
gboolean
gimp_brush_get_spacing (const gchar *name,
			gint        *spacing)
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gboolean success = TRUE;

  return_vals = gimp_run_procedure ("gimp_brush_get_spacing",
				    &nreturn_vals,
				    GIMP_PDB_STRING, name,
				    GIMP_PDB_END);

  *spacing = 0;

  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  if (success)
    *spacing = return_vals[1].data.d_int32;

  gimp_destroy_params (return_vals, nreturn_vals);

  return success;
}

/**
 * gimp_brush_set_spacing:
 * @name: The brush name.
 * @spacing: The brush spacing.
 *
 * Set the brush spacing.
 *
 * This procedure modifies the spacing setting for the specified brush.
 * The value should be a integer between 0 and 1000.
 *
 * Returns: TRUE on success.
 *
 * Since: GIMP 2.2
 */
gboolean
gimp_brush_set_spacing (const gchar *name,
			gint         spacing)
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gboolean success = TRUE;

  return_vals = gimp_run_procedure ("gimp_brush_set_spacing",
				    &nreturn_vals,
				    GIMP_PDB_STRING, name,
				    GIMP_PDB_INT32, spacing,
				    GIMP_PDB_END);

  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  gimp_destroy_params (return_vals, nreturn_vals);

  return success;
}
