summaryrefslogtreecommitdiff
path: root/image
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2010-04-03 11:55:28 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2010-04-03 11:55:28 +0000
commit49810d8191e9a806ceb8a92c68369d8dac261f0d (patch)
treed57d82c882eb92f0d0bcf409b43a54beadc91e04 /image
parent6835a312b7df68c23fec9930b8e0aec94b537e5f (diff)
downloadnetsurf-49810d8191e9a806ceb8a92c68369d8dac261f0d.tar.gz
netsurf-49810d8191e9a806ceb8a92c68369d8dac261f0d.tar.bz2
Use mutator to modify content's title field.
svn path=/trunk/netsurf/; revision=10231
Diffstat (limited to 'image')
-rw-r--r--image/bmp.c11
-rw-r--r--image/gif.c12
-rw-r--r--image/ico.c11
-rw-r--r--image/jpeg.c11
-rw-r--r--image/mng.c21
-rw-r--r--image/png.c14
6 files changed, 30 insertions, 50 deletions
diff --git a/image/bmp.c b/image/bmp.c
index d4584f85d..23ea740e9 100644
--- a/image/bmp.c
+++ b/image/bmp.c
@@ -72,6 +72,7 @@ bool nsbmp_convert(struct content *c)
uint32_t swidth;
const char *data;
unsigned long size;
+ char title[100];
/* set the bmp data */
bmp = c->data.bmp.bmp;
@@ -98,12 +99,11 @@ bool nsbmp_convert(struct content *c)
c->width = bmp->width;
c->height = bmp->height;
LOG(("BMP width %u height %u", c->width, c->height));
- c->title = malloc(100);
- if (c->title)
- snprintf(c->title, 100, messages_get("BMPTitle"), c->width,
- c->height, size);
+ snprintf(title, sizeof(title), messages_get("BMPTitle"),
+ c->width, c->height, size);
+ content__set_title(c, title);
swidth = bmp->bitmap_callbacks.bitmap_get_bpp(bmp->bitmap) * bmp->width;
- c->size += (swidth * bmp->height) + 16 + 44 + 100;
+ c->size += (swidth * bmp->height) + 16 + 44;
/* exit as a success */
c->bitmap = bmp->bitmap;
@@ -159,7 +159,6 @@ void nsbmp_destroy(struct content *c)
{
bmp_finalise(c->data.bmp.bmp);
free(c->data.bmp.bmp);
- free(c->title);
}
diff --git a/image/gif.c b/image/gif.c
index 8c5025af6..01ea57420 100644
--- a/image/gif.c
+++ b/image/gif.c
@@ -86,6 +86,7 @@ bool nsgif_convert(struct content *c)
union content_msg_data msg_data;
const char *data;
unsigned long size;
+ char title[100];
/* Get the animation */
gif = c->data.gif.gif;
@@ -123,12 +124,10 @@ bool nsgif_convert(struct content *c)
/* Store our content width and description */
c->width = gif->width;
c->height = gif->height;
- c->title = malloc(100);
- if (c->title) {
- snprintf(c->title, 100, messages_get("GIFTitle"), c->width,
- c->height, size);
- }
- c->size += (gif->width * gif->height * 4) + 16 + 44 + 100;
+ snprintf(title, sizeof(title), messages_get("GIFTitle"),
+ c->width, c->height, size);
+ content__set_title(c, title);
+ c->size += (gif->width * gif->height * 4) + 16 + 44;
/* Schedule the animation if we have one */
c->data.gif.current_frame = 0;
@@ -195,7 +194,6 @@ void nsgif_destroy(struct content *c)
schedule_remove(nsgif_animate, c);
gif_finalise(c->data.gif.gif);
free(c->data.gif.gif);
- free(c->title);
}
diff --git a/image/ico.c b/image/ico.c
index 233018cea..3335a6a58 100644
--- a/image/ico.c
+++ b/image/ico.c
@@ -60,6 +60,7 @@ bool nsico_convert(struct content *c)
union content_msg_data msg_data;
const char *data;
unsigned long size;
+ char title[100];
/* set the ico data */
ico = c->data.ico.ico;
@@ -86,11 +87,10 @@ bool nsico_convert(struct content *c)
/* Store our content width and description */
c->width = ico->width;
c->height = ico->height;
- c->title = malloc(100);
- if (c->title)
- snprintf(c->title, 100, messages_get("ICOTitle"), c->width,
- c->height, size);
- c->size += (ico->width * ico->height * 4) + 16 + 44 + 100;
+ snprintf(title, sizeof(title), messages_get("ICOTitle"),
+ c->width, c->height, size);
+ content__set_title(c, title);
+ c->size += (ico->width * ico->height * 4) + 16 + 44;
/* exit as a success */
bmp = ico_find(c->data.ico.ico, 255, 255);
@@ -167,7 +167,6 @@ void nsico_destroy(struct content *c)
{
ico_finalise(c->data.ico.ico);
free(c->data.ico.ico);
- free(c->title);
}
#endif
diff --git a/image/jpeg.c b/image/jpeg.c
index dd86d6ac9..af28fe6fa 100644
--- a/image/jpeg.c
+++ b/image/jpeg.c
@@ -91,6 +91,7 @@ bool nsjpeg_convert(struct content *c)
union content_msg_data msg_data;
const char *data;
unsigned long size;
+ char title[100];
data = content__get_source_data(c, &size);
@@ -162,11 +163,10 @@ bool nsjpeg_convert(struct content *c)
c->width = width;
c->height = height;
c->bitmap = bitmap;
- c->title = malloc(100);
- if (c->title)
- snprintf(c->title, 100, messages_get("JPEGTitle"),
- width, height, size);
- c->size += height * rowstride + 100;
+ snprintf(title, sizeof(title), messages_get("JPEGTitle"),
+ width, height, size);
+ content__set_title(c, title);
+ c->size += height * rowstride;
c->status = CONTENT_STATUS_DONE;
/* Done: update status bar */
content_set_status(c, "");
@@ -284,7 +284,6 @@ void nsjpeg_destroy(struct content *c)
{
if (c->bitmap)
bitmap_destroy(c->bitmap);
- free(c->title);
}
#endif /* WITH_JPEG */
diff --git a/image/mng.c b/image/mng.c
index 2c9d6fd8a..012301d98 100644
--- a/image/mng.c
+++ b/image/mng.c
@@ -302,10 +302,9 @@ bool nsmng_process_data(struct content *c, char *data, unsigned int size)
bool nsmng_convert(struct content *c)
{
mng_retcode status;
-
- union content_msg_data msg_data;
const char *data;
unsigned long size;
+ char title[100];
assert(c != NULL);
@@ -319,25 +318,19 @@ bool nsmng_convert(struct content *c)
/* Set the title
*/
- c->title = malloc(100);
- if (!c->title) {
- msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
- return false;
- }
-
if (c->type == CONTENT_MNG) {
- snprintf(c->title, 100, messages_get("MNGTitle"),
+ snprintf(title, sizeof(title), messages_get("MNGTitle"),
c->width, c->height, size);
} else if (c->type == CONTENT_PNG) {
- snprintf(c->title, 100, messages_get("PNGTitle"),
+ snprintf(title, sizeof(title), messages_get("PNGTitle"),
c->width, c->height, size);
} else {
- snprintf(c->title, 100, messages_get("JNGTitle"),
+ snprintf(title, sizeof(title), messages_get("JNGTitle"),
c->width, c->height, size);
}
+ content__set_title(c, title);
- c->size += c->width * c->height * 4 + 100;
+ c->size += c->width * c->height * 4;
c->status = CONTENT_STATUS_DONE;
/* Done: update status bar */
content_set_status(c, "");
@@ -528,8 +521,6 @@ void nsmng_destroy(struct content *c)
if (c->bitmap)
bitmap_destroy(c->bitmap);
-
- free(c->title);
}
diff --git a/image/png.c b/image/png.c
index 3e9b21a9e..0cef6ec6a 100644
--- a/image/png.c
+++ b/image/png.c
@@ -51,9 +51,6 @@
#define png_set_expand_gray_1_2_4_to_8(png) png_set_gray_1_2_4_to_8(png)
#endif
-/* I hate doing this, but without g_strdup_printf or similar, we're a tad stuck. */
-#define NSPNG_TITLE_LEN (100)
-
/* libpng uses names starting png_, so use nspng_ here to avoid clashes */
static void info_callback(png_structp png, png_infop info);
@@ -265,6 +262,7 @@ bool nspng_convert(struct content *c)
{
const char *data;
unsigned long size;
+ char title[100];
assert(c->data.png.png != NULL);
assert(c->data.png.info != NULL);
@@ -273,14 +271,11 @@ bool nspng_convert(struct content *c)
png_destroy_read_struct(&c->data.png.png, &c->data.png.info, 0);
- c->title = malloc(NSPNG_TITLE_LEN);
-
- if (c->title != NULL) {
- snprintf(c->title, NSPNG_TITLE_LEN, messages_get("PNGTitle"),
+ snprintf(title, sizeof(title), messages_get("PNGTitle"),
c->width, c->height, size);
- }
+ content__set_title(c, title);
- c->size += (c->width * c->height * 4) + NSPNG_TITLE_LEN;
+ c->size += (c->width * c->height * 4);
assert(c->data.png.bitmap != NULL);
@@ -296,7 +291,6 @@ bool nspng_convert(struct content *c)
void nspng_destroy(struct content *c)
{
- free(c->title);
if (c->data.png.bitmap != NULL) {
bitmap_destroy(c->data.png.bitmap);
}