Commit aebb4b15 authored by Tor Lillqvist's avatar Tor Lillqvist Committed by Tor Lillqvist
Browse files

Use GLib's memory functions instead of malloc and free.

2000-03-11  Tor Lillqvist  <tml@iki.fi>

* plug-ins/twain/*.c: Use GLib's memory functions instead of
malloc and free.

* plug-ins/winsnap/winsnap.c: Add delay functionality.
parent 94ff1382
2000-03-11 Tor Lillqvist <tml@iki.fi>
* plug-ins/twain/*.c: Use GLib's memory functions instead of
malloc and free.
* plug-ins/winsnap/winsnap.c: Add delay functionality.
Sat Mar 11 14:44:19 CET 2000 Sven Neumann <sven@gimp.org>
* app/menus.c: translate branches in the gimp domain too and a
......
......@@ -235,7 +235,7 @@ void readDumpedImage(pTW_SESSION twSession)
while (moreData) {
/* Read the memory information */
fread((void *) &imageMemXfer, sizeof(TW_IMAGEMEMXFER), 1, inputFile);
imageMemXfer.Memory.TheMem = (TW_MEMREF) malloc (imageMemXfer.BytesWritten);
imageMemXfer.Memory.TheMem = (TW_MEMREF) g_malloc (imageMemXfer.BytesWritten);
fread((void *) imageMemXfer.Memory.TheMem,
1, imageMemXfer.BytesWritten, inputFile);
......@@ -247,7 +247,7 @@ void readDumpedImage(pTW_SESSION twSession)
return;
/* Clean up the memory */
free((void *) imageMemXfer.Memory.TheMem);
g_free (imageMemXfer.Memory.TheMem);
/* Check for continuation */
fread((void *) &moreData, sizeof(int), 1, inputFile);
......
......@@ -59,7 +59,6 @@
#include <glib.h> /* Needed when compiling with gcc */
#include <malloc.h>
#include <windows.h>
#include "twain.h"
#include "tw_func.h"
......@@ -682,7 +681,7 @@ transferImage(pTW_SESSION twSession, pTW_IMAGEINFO imageInfo)
(TW_MEMREF) &setupMemXfer);
/* Allocate the buffer for the transfer */
buffer = (char *) malloc (setupMemXfer.Preferred);
buffer = g_new (char, setupMemXfer.Preferred);
imageMemXfer.Memory.Flags = TWMF_APPOWNS | TWMF_POINTER;
imageMemXfer.Memory.Length = setupMemXfer.Preferred;
imageMemXfer.Memory.TheMem = (TW_MEMREF) buffer;
......@@ -718,7 +717,7 @@ transferImage(pTW_SESSION twSession, pTW_IMAGEINFO imageInfo)
} while (twSession->twRC == TWRC_SUCCESS);
/* Free the memory buffer */
free((void *) imageMemXfer.Memory.TheMem);
g_free (imageMemXfer.Memory.TheMem);
}
/*
......@@ -940,13 +939,13 @@ twainMessageLoop(pTW_SESSION twSession)
pTW_SESSION
newSession(pTW_IDENTITY appIdentity) {
/* Create the structure */
pTW_SESSION session = (pTW_SESSION) malloc (sizeof(TW_SESSION));
pTW_SESSION session = g_new (TW_SESSION, 1);
/* Set the structure fields */
session->hwnd = 0;
session->twRC = TWRC_SUCCESS;
session->appIdentity = appIdentity;
session->dsIdentity = (pTW_IDENTITY) malloc (sizeof(TW_IDENTITY));
session->dsIdentity = g_new (TW_IDENTITY, 1);
session->dsIdentity->Id = 0;
session->dsIdentity->ProductName[0] = '\0';
session->transferFunctions = NULL;
......
......@@ -69,13 +69,13 @@
pTW_SESSION
newSession(pTW_IDENTITY appIdentity) {
/* Create the structure */
pTW_SESSION session = (pTW_SESSION) malloc (sizeof(TW_SESSION));
pTW_SESSION session = g_new (TW_SESSION, 1);
/* Set the structure fields */
session->hwnd = 0;
session->twRC = TWRC_SUCCESS;
session->appIdentity = appIdentity;
session->dsIdentity = (pTW_IDENTITY) malloc (sizeof(TW_IDENTITY));
session->dsIdentity = g_new (TW_IDENTITY, 1);
session->dsIdentity->Id = 0;
session->dsIdentity->ProductName[0] = '\0';
session->transferFunctions = NULL;
......
......@@ -260,7 +260,7 @@ WinMain(HINSTANCE hInstance,
static pTW_IDENTITY
getAppIdentity(void)
{
pTW_IDENTITY appIdentity = (pTW_IDENTITY) malloc (sizeof(TW_IDENTITY));
pTW_IDENTITY appIdentity = g_new (TW_IDENTITY, 1);
/* Set up the application identity */
appIdentity->Id = 0;
......@@ -562,7 +562,7 @@ run(gchar *name, /* name of plugin */
values[1].type = PARAM_INT32;
values[1].data.d_int32 = 0;
values[2].type = PARAM_INT32ARRAY;
values[2].data.d_int32array = (gint32 *) malloc (sizeof(gint32) * MAX_IMAGES);
values[2].data.d_int32array = g_new (gint32, MAX_IMAGES);
/* How are we running today? */
switch (run_mode) {
......@@ -657,8 +657,7 @@ beginTransferCallback(pTW_IMAGEINFO imageInfo, void *clientData)
int done = 0;
int imageType, layerType;
pClientDataStruct theClientData =
(pClientDataStruct) malloc (sizeof(ClientDataStruct));
pClientDataStruct theClientData = g_new (ClientDataStruct, 1);
#ifdef _DEBUG
logBegin(imageInfo, clientData);
......@@ -681,7 +680,7 @@ beginTransferCallback(pTW_IMAGEINFO imageInfo, void *clientData)
case TWPT_PALETTE:
/* Get the palette data */
theClientData->paletteData = (pTW_PALETTE8) malloc (sizeof(TW_PALETTE8));
theClientData->paletteData = g_new (TW_PALETTE8, 1);
twSession->twRC = callDSM(APP_IDENTITY(twSession), DS_IDENTITY(twSession),
DG_IMAGE, DAT_PALETTE8, MSG_GET,
(TW_MEMREF) theClientData->paletteData);
......@@ -744,7 +743,7 @@ beginTransferCallback(pTW_IMAGEINFO imageInfo, void *clientData)
/* Store our client data for the data transfer callbacks */
if (clientData)
free(clientData);
g_free (clientData);
setClientData(twSession, (void *) theClientData);
/* Make sure to return TRUE to continue the image
......@@ -778,7 +777,7 @@ bitTransferCallback(pTW_IMAGEINFO imageInfo,
/* Allocate a buffer as necessary */
if (!destBuf)
destBuf = (char *) malloc (rows * cols);
destBuf = g_new (char, rows * cols);
/* Unpack the image data from bits into bytes */
srcBuf = (char *) imageMemXfer->Memory.TheMem;
......@@ -828,7 +827,7 @@ oneBytePerSampleTransferCallback(pTW_IMAGEINFO imageInfo,
/* Allocate a buffer as necessary */
if (!destBuf)
destBuf = (char *) malloc (rows * cols * bytesPerPixel);
destBuf = g_new (char, rows * cols * bytesPerPixel);
/* The bytes coming from the source may not be padded in
* a way that The GIMP is terribly happy with. It is
......@@ -886,7 +885,7 @@ twoBytesPerSampleTransferCallback(pTW_IMAGEINFO imageInfo,
/* Allocate a buffer as necessary */
if (!destBuf)
destBuf = (char *) malloc (rows * cols * imageInfo->SamplesPerPixel);
destBuf = g_new (char, rows * cols * imageInfo->SamplesPerPixel);
/* The bytes coming from the source may not be padded in
* a way that The GIMP is terribly happy with. It is
......@@ -970,7 +969,7 @@ palettedTransferCallback(pTW_IMAGEINFO imageInfo,
/* Allocate a buffer as necessary */
if (!destBuf)
destBuf = (char *) malloc (rows * cols * channelsPerEntry);
destBuf = g_new (char, rows * cols * channelsPerEntry);
/* Work through the rows */
destPtr = destBuf;
......@@ -1082,7 +1081,7 @@ endTransferCallback(int completionState, int pendingCount, void *clientData)
/* Clean up and detach from the drawable */
if (destBuf) {
free(destBuf);
g_free (destBuf);
destBuf = NULL;
}
gimp_drawable_flush(theClientData->drawable);
......
......@@ -96,6 +96,7 @@ LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
/* Data structure holding data between runs */
typedef struct {
gint root;
guint delay;
gint decor;
} WinSnapValues;
......@@ -103,20 +104,27 @@ typedef struct {
static WinSnapValues winsnapvals =
{
FALSE,
TRUE
0,
TRUE,
};
/* The dialog information */
typedef struct {
#ifdef CAN_SET_DECOR
GtkWidget *decor_button;
#endif
GtkWidget *single_button;
GtkWidget *root_button;
GtkWidget *delay_spinner;
gint run;
} WinSnapInterface;
/* The dialog data */
static WinSnapInterface winsnapintf =
{
#ifdef CAN_SET_DECOR
NULL,
#endif
NULL,
NULL,
NULL,
......@@ -268,7 +276,7 @@ doCapture(HWND selectedHwnd)
/* Try and get everything out of the way before the
* capture.
*/
Sleep(500);
Sleep(500 + winsnapvals.delay * 1000);
/* Are we capturing a window or the whole screen */
if (selectedHwnd) {
......@@ -819,9 +827,11 @@ snap_close_callback(GtkWidget *widget,
*/
static void
snap_grab_callback(GtkWidget *widget,
gpointer data)
gpointer data)
{
winsnapintf.run = TRUE;
winsnapvals.delay =
gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON (winsnapintf.delay_spinner));
gtk_widget_destroy(GTK_WIDGET (data));
}
......@@ -832,7 +842,7 @@ snap_grab_callback(GtkWidget *widget,
*/
static void
snap_toggle_update (GtkWidget *widget,
gpointer radio_button)
gpointer radio_button)
{
gint *toggle_val;
......@@ -864,11 +874,14 @@ snap_dialog(void)
GtkWidget *button;
GtkWidget *hbox;
GtkWidget *radio_label;
GtkWidget *label;
GtkAdjustment *adj;
GSList *radio_group = NULL;
gint radio_pressed[2];
gint decorations;
gint argc = 1;
gchar **argv = g_new (gchar *, 1);
guint delay;
/* Set the name */
argv[0] = g_strdup("winsnap");
......@@ -877,6 +890,7 @@ snap_dialog(void)
radio_pressed[0] = (winsnapvals.root == FALSE);
radio_pressed[1] = (winsnapvals.root == TRUE);
decorations = winsnapvals.decor;
delay = winsnapvals.delay;
/* Init GTK */
gtk_init(&argc, &argv);
......@@ -942,8 +956,8 @@ snap_dialog(void)
gtk_widget_show (radio_label);
gtk_widget_show (hbox);
/* With decorations */
#ifdef CAN_SET_DECOR
/* With decorations */
hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_end (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
winsnapintf.decor_button =
......@@ -990,6 +1004,33 @@ snap_dialog(void)
gtk_widget_show (hbox);
gtk_widget_show (frame);
/* with delay */
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
gtk_container_border_width (GTK_CONTAINER (frame), 4);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
frame, TRUE, TRUE, 0);
hbox = gtk_hbox_new (FALSE, 4);
gtk_container_border_width (GTK_CONTAINER (hbox), 4);
gtk_container_add (GTK_CONTAINER (frame), hbox);
label = gtk_label_new (_("after"));
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
adj = (GtkAdjustment *) gtk_adjustment_new ((gfloat)delay, 0.0, 100.0, 1.0, 5.0, 0.0);
winsnapintf.delay_spinner = gtk_spin_button_new (adj, 0, 0);
gtk_box_pack_start (GTK_BOX(hbox), winsnapintf.delay_spinner, FALSE, FALSE, 0);
gtk_widget_show (winsnapintf.delay_spinner);
label = gtk_label_new (_("Seconds Delay"));
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
gtk_widget_show (hbox);
gtk_widget_show (frame);
gtk_widget_show (dialog);
gtk_main ();
......@@ -1186,7 +1227,7 @@ sendBMPToGimp(HBITMAP hBMP, HDC hDC, RECT rect)
/* Check that we got the memory */
if (!capBytes) {
g_warning(_("No data captured"));
return 0;
return;
}
/* Flip the red and blue bytes */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment