Commit 261e3c68 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

added g_strcompress from glib-1.3

2000-08-01  Sven Neumann  <sven@gimp.org>

* libgimp/gimputils.[ch]: added g_strcompress from glib-1.3

* plug-ins/gdyntext/gdyntextutil.[ch]: removed since it duplicated
gimp_strescape and the newly added gimp_strcompress.

* plug-ins/gdyntext/Makefile.am
* plug-ins/gdyntext/gdyntext.[ch]
* plug-ins/gdyntext/gdyntext_ui.c
* plug-ins/gdyntext/gdyntextcompat.c: use the new functions and
got rid of some gimp_run_procedure calls since we now have proper
wrappers in libgimp.

* plug-ins/common/autocrop.c
* plug-ins/common/gif.c
* plug-ins/common/gifload.c
* plug-ins/common/guillotine.c
* plug-ins/common/mail.c
* plug-ins/common/screenshot.c
* plug-ins/common/tile.c
* plug-ins/common/zealouscrop.c
* plug-ins/gflare/gflare.c
* plug-ins/gimpressionist/gimpressionist.c
* plug-ins/pagecurl/pagecurl.c
* plug-ins/script-fu/script-fu-scripts.c
* plug-ins/script-fu/script-fu.c: replaced gimp_run_procedure
calls with functions from libgimp that wrap the PDB calls.

Sorry, all this is untested but I will leave tomorrow and hope to
get some hacking done at Mitch's place. So I wanted that stuff to
be in CVS. There are good chances that it works...
parent 7e304e73
2000-08-01 Sven Neumann <sven@gimp.org>
* libgimp/gimputils.[ch]: added g_strcompress from glib-1.3
* plug-ins/gdyntext/gdyntextutil.[ch]: removed since it duplicated
gimp_strescape and the newly added gimp_strcompress.
* plug-ins/gdyntext/Makefile.am
* plug-ins/gdyntext/gdyntext.[ch]
* plug-ins/gdyntext/gdyntext_ui.c
* plug-ins/gdyntext/gdyntextcompat.c: use the new functions and
got rid of some gimp_run_procedure calls since we now have proper
wrappers in libgimp.
* plug-ins/common/autocrop.c
* plug-ins/common/gif.c
* plug-ins/common/gifload.c
* plug-ins/common/guillotine.c
* plug-ins/common/mail.c
* plug-ins/common/screenshot.c
* plug-ins/common/tile.c
* plug-ins/common/zealouscrop.c
* plug-ins/gflare/gflare.c
* plug-ins/gimpressionist/gimpressionist.c
* plug-ins/pagecurl/pagecurl.c
* plug-ins/script-fu/script-fu-scripts.c
* plug-ins/script-fu/script-fu.c: replaced gimp_run_procedure
calls with functions from libgimp that wrap the PDB calls.
Sorry, all this is untested but I will leave tomorrow and hope to
get some hacking done at Mitch's place. So I wanted that stuff to
be in CVS. There are good chances that it works...
2000-07-31 Tor Lillqvist <tml@iki.fi>
 
* plug-ins/common/gz.c (load_image,save_image): Change Win32
......
......@@ -23,6 +23,8 @@
#include <string.h>
#include <glib.h>
#include "gimputils.h"
/**
* gimp_strescape:
* @source: A string to escape special characters in.
......@@ -121,3 +123,77 @@ gimp_strescape (const gchar *source,
return dest;
}
#endif /* GLIB <= 1.3 */
/**
* gimp_strcompress:
* @source: A string to that has special characters escaped.
*
* Does the opposite of g_strescape(), that is it converts escaped
* characters back to their unescaped form.
*
* Escaped characters are either one of the sequences \b, \f, \n, \r,
* \t, \\, \", or a three-digit octal escape sequence \nnn.
*
* If glib > 1.3 is installed this function is identical to
* g_strcompress(). For systems using glib-1.2 this function provides
* the functionality from glib-1.3.
*
* Returns: A newly allocated copy of the string, with all escaped
* special characters converted to their unescaped form.
*/
#if !(defined (GLIB_CHECK_VERSION) && GLIB_CHECK_VERSION (1,3,1))
gchar*
gimp_strcompress (const gchar *source)
{
const gchar *p = source, *octal;
gchar *dest = g_malloc (strlen (source) + 1);
gchar *q = dest;
while (*p)
{
if (*p == '\\')
{
p++;
switch (*p)
{
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7':
*q = 0;
octal = p;
while ((p < octal + 3) && (*p >= '0') && (*p <= '7'))
{
*q = (*q * 8) + (*p - '0');
p++;
}
q++;
p--;
break;
case 'b':
*q++ = '\b';
break;
case 'f':
*q++ = '\f';
break;
case 'n':
*q++ = '\n';
break;
case 'r':
*q++ = '\r';
break;
case 't':
*q++ = '\t';
break;
default: /* Also handles \" and \\ */
*q++ = *p;
break;
}
}
else
*q++ = *p;
p++;
}
*q = 0;
return dest;
}
#endif /* GLIB <= 1.3 */
......@@ -32,16 +32,18 @@ extern "C" {
/*
* Right now all you find here is the g_strescape function out of
* glib-1.3. We need its functionality, but don't want to rely on
* that version being installed
* Right now all you find here are the g_strescape and g_strcompress
* function out of glib-1.3. We need their functionality, but don't
* want to rely on that version being installed
*/
#if (defined (GLIB_CHECK_VERSION) && GLIB_CHECK_VERSION (1,3,1))
#define gimp_strescape(string, exceptions) g_strescape (string, exceptions)
#define gimp_strcompress(string) g_strcompress (string)
#else
gchar* gimp_strescape (const gchar *source,
const gchar *exceptions);
gchar * gimp_strescape (const gchar *source,
const gchar *exceptions);
gchar * gimp_strcompress (const gchar *source);
#endif /* GLIB <= 1.3 */
......@@ -50,3 +52,6 @@ gchar* gimp_strescape (const gchar *source,
#endif /* __cplusplus */
#endif /* __GIMPUTILS_H__ */
......@@ -23,6 +23,8 @@
#include <string.h>
#include <glib.h>
#include "gimputils.h"
/**
* gimp_strescape:
* @source: A string to escape special characters in.
......@@ -121,3 +123,77 @@ gimp_strescape (const gchar *source,
return dest;
}
#endif /* GLIB <= 1.3 */
/**
* gimp_strcompress:
* @source: A string to that has special characters escaped.
*
* Does the opposite of g_strescape(), that is it converts escaped
* characters back to their unescaped form.
*
* Escaped characters are either one of the sequences \b, \f, \n, \r,
* \t, \\, \", or a three-digit octal escape sequence \nnn.
*
* If glib > 1.3 is installed this function is identical to
* g_strcompress(). For systems using glib-1.2 this function provides
* the functionality from glib-1.3.
*
* Returns: A newly allocated copy of the string, with all escaped
* special characters converted to their unescaped form.
*/
#if !(defined (GLIB_CHECK_VERSION) && GLIB_CHECK_VERSION (1,3,1))
gchar*
gimp_strcompress (const gchar *source)
{
const gchar *p = source, *octal;
gchar *dest = g_malloc (strlen (source) + 1);
gchar *q = dest;
while (*p)
{
if (*p == '\\')
{
p++;
switch (*p)
{
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7':
*q = 0;
octal = p;
while ((p < octal + 3) && (*p >= '0') && (*p <= '7'))
{
*q = (*q * 8) + (*p - '0');
p++;
}
q++;
p--;
break;
case 'b':
*q++ = '\b';
break;
case 'f':
*q++ = '\f';
break;
case 'n':
*q++ = '\n';
break;
case 'r':
*q++ = '\r';
break;
case 't':
*q++ = '\t';
break;
default: /* Also handles \" and \\ */
*q++ = *p;
break;
}
}
else
*q++ = *p;
p++;
}
*q = 0;
return dest;
}
#endif /* GLIB <= 1.3 */
......@@ -32,16 +32,18 @@ extern "C" {
/*
* Right now all you find here is the g_strescape function out of
* glib-1.3. We need its functionality, but don't want to rely on
* that version being installed
* Right now all you find here are the g_strescape and g_strcompress
* function out of glib-1.3. We need their functionality, but don't
* want to rely on that version being installed
*/
#if (defined (GLIB_CHECK_VERSION) && GLIB_CHECK_VERSION (1,3,1))
#define gimp_strescape(string, exceptions) g_strescape (string, exceptions)
#define gimp_strcompress(string) g_strcompress (string)
#else
gchar* gimp_strescape (const gchar *source,
const gchar *exceptions);
gchar * gimp_strescape (const gchar *source,
const gchar *exceptions);
gchar * gimp_strcompress (const gchar *source);
#endif /* GLIB <= 1.3 */
......@@ -50,3 +52,6 @@ gchar* gimp_strescape (const gchar *source,
#endif /* __cplusplus */
#endif /* __GIMPUTILS_H__ */
......@@ -141,7 +141,6 @@ doit (GDrawable *drawable,
gint32 nx, ny, nw, nh;
guchar *buffer;
guchar color[4] = {0, 0, 0, 0};
gint nreturn_vals;
width = drawable->width;
height = drawable->height;
......@@ -227,16 +226,9 @@ doit (GDrawable *drawable,
g_free (buffer);
gimp_drawable_detach (drawable);
if (nw != width || nh != height)
{
gimp_run_procedure ("gimp_crop", &nreturn_vals,
PARAM_IMAGE, image_id,
PARAM_INT32, nw,
PARAM_INT32, nh,
PARAM_INT32, nx,
PARAM_INT32, ny,
PARAM_END);
}
gimp_crop (image_id, nw, nh, nx, ny);
}
static gint
......
......@@ -779,7 +779,6 @@ boundscheck (gint32 image_ID)
GDrawable *drawable;
gint32 *layers;
gint nlayers;
gint nreturn_vals;
gint i;
gint offset_x, offset_y;
......@@ -809,13 +808,9 @@ boundscheck (gint32 image_ID)
* the user and they said yes. */
if ((run_mode == RUN_NONINTERACTIVE) || badbounds_dialog ())
{
gimp_run_procedure("gimp_crop", &nreturn_vals,
PARAM_IMAGE, image_ID,
PARAM_INT32, gimp_image_width(image_ID),
PARAM_INT32, gimp_image_height(image_ID),
PARAM_INT32, 0,
PARAM_INT32, 0,
PARAM_END);
gimp_crop (image_ID,
gimp_image_width (image_ID), gimp_image_height (image_ID),
0, 0);
return TRUE;
}
else
......
......@@ -812,7 +812,6 @@ ReadImage (FILE *fd,
gchar *framename;
gchar *framename_ptr;
gboolean alpha_frame = FALSE;
int nreturn_vals;
static int previous_disposal;
......@@ -889,9 +888,8 @@ ReadImage (FILE *fd,
#ifdef GIFDEBUG
g_print ("GIF: Promoting image to RGB...\n");
#endif
gimp_run_procedure("gimp_convert_rgb", &nreturn_vals,
PARAM_IMAGE, image_ID,
PARAM_END);
gimp_convert_rgb (image_ID);
break;
}
}
......
......@@ -28,7 +28,6 @@
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <libgimp/gimp.h>
......@@ -137,8 +136,6 @@ guillotine (gint32 image_ID)
gint* vguides;
gchar filename[1024];
gint i,x,y;
GParam *return_vals;
gint nreturn_vals;
num_vguides = 0;
num_hguides = 0;
......@@ -166,12 +163,12 @@ guillotine (gint32 image_ID)
if (num_vguides+num_hguides)
{
printf("Yay... found %d horizontal guides and %d vertical guides.\n",
num_hguides, num_vguides);
g_print ("Yay... found %d horizontal guides and %d vertical guides.\n",
num_hguides, num_vguides);
}
else
{
printf("Poopy, no guides.\n");
g_print ("Poopy, no guides.\n");
return;
}
......@@ -197,7 +194,7 @@ guillotine (gint32 image_ID)
hguides[num_hguides++] =
gimp_image_get_guide_position(image_ID, guide_num); break;
default:
printf("Aie! Aie! Aie! Too!\n");
g_print ("Aie! Aie! Aie! Too!\n");
gimp_quit();
}
guide_num = gimp_image_find_next_guide(image_ID, guide_num);
......@@ -211,11 +208,11 @@ guillotine (gint32 image_ID)
qsort(vguides, num_vguides, sizeof(gint), &unexciting);
for (i=0;i<num_vguides;i++)
printf("%d,",vguides[i]);
printf("\n");
g_print ("%d,",vguides[i]);
g_print ("\n");
for (i=0;i<num_hguides;i++)
printf("%d,",hguides[i]);
printf("\n");
g_print ("%d,",hguides[i]);
g_print ("\n");
/* Do the actual dup'ing and cropping... this isn't a too naive a
......@@ -226,16 +223,11 @@ guillotine (gint32 image_ID)
{
gint32 new_image;
return_vals =
gimp_run_procedure("gimp_channel_ops_duplicate", &nreturn_vals,
PARAM_IMAGE, image_ID,
PARAM_END);
new_image = gimp_channel_ops_duplicate (image_ID);
if (return_vals[0].data.d_status == STATUS_SUCCESS)
new_image = return_vals[1].data.d_int32;
else
if (new_image == -1)
{
printf("Aie3!\n");
g_print ("Aie3!\n");
return;
}
......@@ -249,21 +241,17 @@ guillotine (gint32 image_ID)
/* vguides[x], hguides[y],x, y); */
gimp_run_procedure("gimp_crop", &nreturn_vals,
PARAM_IMAGE, new_image,
PARAM_INT32, (vguides[x+1]-vguides[x]),
PARAM_INT32, (hguides[y+1]-hguides[y]),
PARAM_INT32, vguides[x],
PARAM_INT32, hguides[y],
PARAM_END);
gimp_crop (new_image,
vguides[x+1] - vguides[x], hguides[y+1] - hguides[y],
vguides[x], hguides[y]);
/* gimp_undo_push_group_end (new_image); */
gimp_image_undo_enable (new_image);
/* show the rough coordinates of the image in the title */
sprintf(filename, "%s-(%i,%i)", gimp_image_get_filename (image_ID),
x, y);
g_snprintf (filename, sizeof (filename), "%s-(%i,%i)", gimp_image_get_filename (image_ID),
x, y);
gimp_image_set_filename(new_image, filename);
gimp_display_new (new_image);
......
......@@ -292,9 +292,7 @@ run (gchar *name,
run_mode);
if (status == STATUS_SUCCESS)
{
gimp_set_data ("plug_in_mail_image", &mail_info, sizeof(m_info));
}
gimp_set_data ("plug_in_mail_image", &mail_info, sizeof(m_info));
}
}
else
......@@ -467,24 +465,19 @@ save_dialog (void)
GtkWidget *text;
GtkWidget *vscrollbar;
gchar buffer[BUFFER_SIZE];
gint nreturn_vals;
GParam *return_vals;
gchar buffer[BUFFER_SIZE];
gchar *gump_from;
gimp_ui_init ("mail", FALSE);
/* check gimprc for a preffered "From:" address */
return_vals = gimp_run_procedure ("gimp_gimprc_query",
&nreturn_vals,
PARAM_STRING, "gump-from",
PARAM_END);
/* check to see if we actually got a value */
if (return_vals[0].data.d_status == STATUS_SUCCESS &&
return_vals[1].data.d_string != NULL)
strncpy (mail_info.from, return_vals[1].data.d_string , BUFFER_SIZE);
gump_from = gimp_gimprc_query ("gump-from");
gimp_destroy_params (return_vals, nreturn_vals);
if (gump_from)
{
strncpy (mail_info.from, gump_from, BUFFER_SIZE);
g_free (gump_from);
}
dlg = gimp_dialog_new (_("Send to Mail"), "mail",
gimp_standard_help_func, "filters/mail.html",
......
......@@ -97,7 +97,6 @@ static void shoot_ok_callback (GtkWidget *widget,
gpointer data);
static void shoot_toggle_update (GtkWidget *widget,
gpointer radio_button);
static void shoot_display_image (gint32 image);
static void shoot_delay (gint32 delay);
static gint shoot_delay_callback (gpointer data);
......@@ -231,7 +230,7 @@ run (gchar *name,
/* Store variable states for next run */
gimp_set_data (PLUG_IN_NAME, &shootvals, sizeof (ScreenShotValues));
/* display the image */
shoot_display_image (image_ID);
gimp_display_new (image_ID);
}
/* set return values */
*nreturn_vals = 2;
......@@ -334,21 +333,7 @@ shoot (void)
if (image_ID != -1)
{
/* figure out the monitor resolution and set the image to it */
params = gimp_run_procedure ("gimp_get_monitor_resolution",
&retvals,
PARAM_END);
if (params[0].data.d_status == STATUS_SUCCESS)
{
xres = params[1].data.d_float;
yres = params[2].data.d_float;
}
else
{
xres = 72.0;
yres = 72.0;
}
gimp_destroy_params (params, retvals);
gimp_get_monitor_resolution (&xres, &yres);
gimp_image_set_resolution (image_ID, xres, yres);
/* unset the image filename */
......@@ -557,17 +542,3 @@ shoot_delay_callback (gpointer data)
return (*seconds_left);
}
/* Display function */
void
shoot_display_image (gint32 image)
{
GParam *params;
gint retvals;
params = gimp_run_procedure ("gimp_display_new",
&retvals,
PARAM_IMAGE, image,
PARAM_END);
gimp_destroy_params (params, retvals);
}
......@@ -237,7 +237,6 @@ tile (gint32 image_id,
gint width, height;
gint i, j, k;
gint progress, max_progress;
gint nreturn_vals;
gpointer pr;
/* initialize */
......@@ -280,22 +279,10 @@ tile (gint32 image_id,
{
gimp_undo_push_group_start (image_id);
gimp_run_procedure ("gimp_image_resize", &nreturn_vals,
PARAM_IMAGE, image_id,
PARAM_INT32, tvals.new_width,
PARAM_INT32, tvals.new_height,
PARAM_INT32, 0,
PARAM_INT32, 0,
PARAM_END);
gimp_image_resize (image_id, tvals.new_width, tvals.new_height, 0, 0);
if (gimp_drawable_is_layer (drawable_id))
gimp_run_procedure ("gimp_layer_resize", &nreturn_vals,
PARAM_LAYER, drawable_id,
PARAM_INT32, tvals.new_width,
PARAM_INT32, tvals.new_height,
PARAM_INT32, 0,
PARAM_INT32, 0,
PARAM_END);
gimp_layer_resize (drawable_id, tvals.new_width, tvals.new_height, 0, 0);
/* Get the specified drawable */
drawable = gimp_drawable_get (drawable_id);
......@@ -356,9 +343,7 @@ tile (gint32 image_id,
gimp_drawable_detach (new_layer);
}
else
gimp_run_procedure ("gimp_undo_push_group_end", &nreturn_vals,
PARAM_IMAGE, image_id,
PARAM_END);
gimp_undo_push_group_end (image_id);
gimp_drawable_flush (drawable);
gimp_drawable_detach (drawable);
......
......@@ -146,7 +146,6 @@ do_zcrop (GDrawable *drawable,
GPixelRgn srcPR, destPR;
gint width, height, x, y;
guchar *buffer;
gint nreturn_vals;
gint8 *killrows;
gint8 *killcols;
gint32 livingrows, livingcols, destrow, destcol;
......@@ -263,25 +262,11 @@ do_zcrop (GDrawable *drawable,
g_free(killcols);
gimp_progress_update(1.00);
gimp_run_procedure ("gimp_undo_push_group_start", &nreturn_vals,
PARAM_IMAGE, image_id,
PARAM_END);
gimp_undo_push_group_start (image_id);
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->id, TRUE);
gimp_run_procedure("gimp_crop", &nreturn_vals,
PARAM_IMAGE, image_id,
PARAM_INT32, (gint32)livingcols,
PARAM_INT32, (gint32)livingrows,
PARAM_INT32, 0,
PARAM_INT32, 0,
PARAM_END);
gimp_run_procedure ("gimp_undo_push_group_end", &nreturn_vals,
PARAM_IMAGE, image_id,
PARAM_END);
gimp_crop (image_id, livingcols, livingrows, 0, 0);
gimp_undo_push_group_end (image_id);
}