[gnumeric] SheetObjectImage: simplify code
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] SheetObjectImage: simplify code
- Date: Thu, 5 Mar 2015 21:12:26 +0000 (UTC)
commit 2024d50189bc748473e57708b2e862d5c3799408
Author: Morten Welinder <terra gnome org>
Date: Thu Mar 5 16:11:16 2015 -0500
SheetObjectImage: simplify code
The illusion that we can take over image data without copying is just
an illusion. Make it clear we are copying and get rid of a bunch of
casts at the same time.
ChangeLog | 5 +++++
plugins/excel/ms-excel-read.c | 11 ++++++-----
plugins/excel/xlsx-read-drawing.c | 6 +++---
plugins/openoffice/openoffice-read.c | 2 +-
src/sheet-control-gui.c | 2 +-
src/sheet-object-image.c | 9 ++-------
src/sheet-object-image.h | 5 ++---
src/wbc-gtk-actions.c | 2 +-
8 files changed, 21 insertions(+), 21 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 07ee805..ded24cc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-03-05 Morten Welinder <terra gnome org>
+
+ * src/sheet-object-image.c (sheet_object_image_set_image): Drop
+ copy_data argument and simply assume it.
+
2015-03-04 Morten Welinder <terra gnome org>
* configure.ac: Post-release bump.
diff --git a/plugins/excel/ms-excel-read.c b/plugins/excel/ms-excel-read.c
index ca278f3..4b54323 100644
--- a/plugins/excel/ms-excel-read.c
+++ b/plugins/excel/ms-excel-read.c
@@ -644,12 +644,12 @@ ms_sheet_realize_obj (MSContainer *container, MSObj *obj)
excel_fill_bmp_header(data, blip->data, blip->data_len);
memcpy(data + BMP_HDR_SIZE, blip->data, blip->data_len);
sheet_object_image_set_image (GNM_SO_IMAGE (so),
- blip->type, data,
blip->data_len + BMP_HDR_SIZE, FALSE);
+ blip->type, data,
blip->data_len + BMP_HDR_SIZE);
+ g_free (data);
}
} else {
sheet_object_image_set_image (GNM_SO_IMAGE (so),
- blip->type, blip->data, blip->data_len,
- TRUE);
+ blip->type, blip->data, blip->data_len);
}
}
} else if ((attr = ms_obj_attr_bag_lookup (obj->attrs,
@@ -657,7 +657,7 @@ ms_sheet_realize_obj (MSContainer *container, MSObj *obj)
GdkPixbuf *pixbuf = GDK_PIXBUF (attr->v.v_object);
if (pixbuf) {
- gchar *buf;
+ gchar *buf = NULL;
gsize buf_size;
gdk_pixbuf_save_to_buffer
@@ -666,8 +666,9 @@ ms_sheet_realize_obj (MSContainer *container, MSObj *obj)
if (buf_size > 0) {
sheet_object_image_set_image
(GNM_SO_IMAGE (so),
- "png", buf, buf_size, FALSE);
+ "png", buf, buf_size);
}
+ g_free (buf);
}
}
if ((attr = ms_obj_attr_bag_lookup (obj->attrs,
diff --git a/plugins/excel/xlsx-read-drawing.c b/plugins/excel/xlsx-read-drawing.c
index 9749eb8..8f32a42 100644
--- a/plugins/excel/xlsx-read-drawing.c
+++ b/plugins/excel/xlsx-read-drawing.c
@@ -3056,13 +3056,13 @@ xlsx_blip_start (GsfXMLIn *xin, xmlChar const **attrs)
GsfInput *input = gsf_open_pkg_open_rel (
gsf_xml_in_get_input (xin), rel, NULL);
size_t size;
- gpointer data;
+ gconstpointer data;
g_return_if_fail (input != NULL);
size = gsf_input_size (input);
- data = (gpointer)gsf_input_read (input, size, NULL);
+ data = gsf_input_read (input, size, NULL);
sheet_object_image_set_image (GNM_SO_IMAGE (state->so),
- NULL, data, size, TRUE);
+ NULL, data, size);
g_object_unref (input);
}
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 96621ea..36e4b75 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -8343,7 +8343,7 @@ od_draw_image (GsfXMLIn *xin, xmlChar const **attrs)
gsf_off_t len = gsf_input_size (input);
guint8 const *data = gsf_input_read (input, len, NULL);
soi = g_object_new (GNM_SO_IMAGE_TYPE, NULL);
- sheet_object_image_set_image (soi, "", (void *)data, len, TRUE);
+ sheet_object_image_set_image (soi, "", data, len);
state->chart.so = GNM_SO (soi);
g_object_unref (input);
diff --git a/src/sheet-control-gui.c b/src/sheet-control-gui.c
index dd83c88..08aa88f 100644
--- a/src/sheet-control-gui.c
+++ b/src/sheet-control-gui.c
@@ -3939,7 +3939,7 @@ scg_image_create (SheetControlGUI *scg, SheetObjectAnchor *anchor,
scg_mode_edit (scg);
soi = g_object_new (GNM_SO_IMAGE_TYPE, NULL);
- sheet_object_image_set_image (soi, "", (guint8 *)data, len, TRUE);
+ sheet_object_image_set_image (soi, "", data, len);
so = GNM_SO (soi);
sheet_object_set_anchor (so, anchor);
diff --git a/src/sheet-object-image.c b/src/sheet-object-image.c
index 0789344..bf4c681 100644
--- a/src/sheet-object-image.c
+++ b/src/sheet-object-image.c
@@ -127,7 +127,6 @@ enum {
* @type:
* @data:
* @data_len
- * @copy_data:
*
* Assign raw data and type to @soi.
* yet.
@@ -135,9 +134,8 @@ enum {
void
sheet_object_image_set_image (SheetObjectImage *soi,
char const *type,
- guint8 *data,
- unsigned data_len,
- gboolean copy_data)
+ gconstpointer data,
+ unsigned data_len)
{
g_return_if_fail (GNM_IS_SO_IMAGE (soi));
@@ -148,9 +146,6 @@ sheet_object_image_set_image (SheetObjectImage *soi,
soi->image = go_image_new_from_data (soi->type, data, data_len,
((soi->type == NULL)? &soi->type: NULL), NULL);
- if (!copy_data)
- g_free (data);
-
if (soi->sheet_object.sheet != NULL) {
/* Share within document. */
GOImage *image = go_doc_add_image (GO_DOC (soi->sheet_object.sheet->workbook), NULL,
soi->image);
diff --git a/src/sheet-object-image.h b/src/sheet-object-image.h
index 41f4134..8455945 100644
--- a/src/sheet-object-image.h
+++ b/src/sheet-object-image.h
@@ -15,9 +15,8 @@ typedef struct _SheetObjectImage SheetObjectImage;
GType sheet_object_image_get_type (void);
void sheet_object_image_set_image (SheetObjectImage *soi,
char const *type,
- guint8 *data,
- unsigned data_len,
- gboolean copy_data);
+ gconstpointer data,
+ unsigned data_len);
void sheet_object_image_set_crop (SheetObjectImage *soi,
double crop_left, double crop_top,
double crop_right, double crop_bottom);
diff --git a/src/wbc-gtk-actions.c b/src/wbc-gtk-actions.c
index 199bf52..9f59bcb 100644
--- a/src/wbc-gtk-actions.c
+++ b/src/wbc-gtk-actions.c
@@ -1160,7 +1160,7 @@ static GNM_ACTION_DEF (cb_insert_image)
unsigned len = gsf_input_size (input);
guint8 const *data = gsf_input_read (input, len, NULL);
SheetObjectImage *soi = g_object_new (GNM_SO_IMAGE_TYPE, NULL);
- sheet_object_image_set_image (soi, "", (guint8 *)data, len, TRUE);
+ sheet_object_image_set_image (soi, "", data, len);
wbcg_insert_object (wbcg, GNM_SO (soi));
g_object_unref (input);
} else
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]