Commit 2024d501 authored by Morten Welinder's avatar Morten Welinder

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.
parent b33ef012
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.
......
......@@ -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,
......
......@@ -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);
}
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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
......
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