summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2009-12-04 16:58:54 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2009-12-04 16:58:54 +0000
commit455f03d06b3860a5551ba4ea4a8690ebac982867 (patch)
tree1aa6a771ccd726d088617971d774fb5a732a6ba7
parent43cf0065f7dbfb13d78e9372acadebf9f5b55eae (diff)
downloadalphagen-455f03d06b3860a5551ba4ea4a8690ebac982867.tar.gz
alphagen-455f03d06b3860a5551ba4ea4a8690ebac982867.tar.bz2
Don't allocate rows individually.
svn path=/trunk/tools/alphagen/; revision=9716
-rw-r--r--alphagen.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/alphagen.c b/alphagen.c
index e6247fc..940cab8 100644
--- a/alphagen.c
+++ b/alphagen.c
@@ -12,7 +12,7 @@
* Input:
* blackbg.png - The image exported on a black background
* whitebg.png - The image exported on a white background
- * Output
+ * Output:
* alpha.png - The resultant image with alpha channel
*
* Note that black.png and white.png must be the same size.
@@ -117,28 +117,27 @@ bool image_init(struct image *img, int width, int height, int channels)
img->height = height;
img->channels = channels;
+ row_data_width = width * channels;
// Allocate memory for row pointers
img->d = (uint8_t**)malloc(height * size);
if (img->d == NULL)
return false;
- row_data_width = width * channels;
- for (int i = 0; i < height; i++) {
- // Allocate memory for row data
- img->d[i] = (uint8_t*)malloc(row_data_width);
- if (img->d[i] == NULL)
- return false;
+ // Allocate memory for image data
+ img->d[0] = (uint8_t*)malloc(height * row_data_width * size);
+ if (img->d[0] == NULL)
+ return false;
+
+ for (int i = 1; i < height; i++) {
+ // Set pointers to each row
+ img->d[i] = img->d[i - 1] + row_data_width;
}
return true;
}
void image_free(struct image *img)
{
- for (int i = 0; i < img->height; i++) {
- // Free row data
- free(img->d[i]);
- }
- // Free row pointers
+ free(img->d[0]);
free(img->d);
}