The cool thing about meetings is that they can get postponed, in
which case one has time to improve XCF loaders :) * fixed a few memleaks (I never actually cleaned up :) * fixed a colormap problem with layer masks, I hope this works * cleanups SVN revision: 4292
This commit is contained in:
parent
99490677bd
commit
a5b3f1e4f0
|
@ -5,7 +5,7 @@ AUTOMAKE_OPTIONS = 1.4 foreign
|
||||||
# A list of all the files in the current directory which can be regenerated
|
# A list of all the files in the current directory which can be regenerated
|
||||||
MAINTAINERCLEANFILES = Makefile.in
|
MAINTAINERCLEANFILES = Makefile.in
|
||||||
|
|
||||||
INCLUDES = $(X_CFLAGS)
|
INCLUDES = -DXCF_DBG $(X_CFLAGS)
|
||||||
|
|
||||||
pkgdir = $(libdir)/loaders/image
|
pkgdir = $(libdir)/loaders/image
|
||||||
pkg_LTLIBRARIES = xcf.la
|
pkg_LTLIBRARIES = xcf.la
|
||||||
|
|
|
@ -49,6 +49,8 @@
|
||||||
|
|
||||||
/* #define XCF_DBG */
|
/* #define XCF_DBG */
|
||||||
|
|
||||||
|
#define FREE(X) { free(X); X = NULL; }
|
||||||
|
|
||||||
#ifdef XCF_DBG
|
#ifdef XCF_DBG
|
||||||
#define D(s) \
|
#define D(s) \
|
||||||
{ \
|
{ \
|
||||||
|
@ -288,7 +290,7 @@ static void init_tile(Tile* tile, int width, int height, int bpp);
|
||||||
static Layer* new_layer(int width, int height, GimpImageType type, int opacity, LayerModeEffects mode);
|
static Layer* new_layer(int width, int height, GimpImageType type, int opacity, LayerModeEffects mode);
|
||||||
static void free_layer(Layer* layer);
|
static void free_layer(Layer* layer);
|
||||||
static void add_layer_to_image(Layer* layer);
|
static void add_layer_to_image(Layer* layer);
|
||||||
static void read_tiles_into_data(Tile* tiles, int num_cols, int width, int height, int bpp, DATA8** data);
|
static void read_tiles_into_data(Tile* tiles, int num_cols, int width, int height, int bpp, DATA8** data, int use_cmap);
|
||||||
static void apply_layer_mask(Layer* layer);
|
static void apply_layer_mask(Layer* layer);
|
||||||
static void set_layer_opacity(Layer* layer);
|
static void set_layer_opacity(Layer* layer);
|
||||||
static void flatten_image(void);
|
static void flatten_image(void);
|
||||||
|
@ -447,7 +449,8 @@ xcf_load_image_props (void)
|
||||||
if (image->file_version == 0)
|
if (image->file_version == 0)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
fprintf (stderr, "XCF warning: version 0 of XCF file format\n"
|
fprintf (stderr,
|
||||||
|
"XCF warning: version 0 of XCF file format\n"
|
||||||
"did not save indexed colormaps correctly.\n"
|
"did not save indexed colormaps correctly.\n"
|
||||||
"Substituting grayscale map.\n");
|
"Substituting grayscale map.\n");
|
||||||
image->cp += xcf_read_int32 (image->fp, &image->num_cols, 1);
|
image->cp += xcf_read_int32 (image->fp, &image->num_cols, 1);
|
||||||
|
@ -462,6 +465,7 @@ xcf_load_image_props (void)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
D(("Loading colormap.\n"));
|
||||||
image->cp += xcf_read_int32 (image->fp, &image->num_cols, 1);
|
image->cp += xcf_read_int32 (image->fp, &image->num_cols, 1);
|
||||||
image->cmap = malloc (sizeof(DATA8) * image->num_cols * 3);
|
image->cmap = malloc (sizeof(DATA8) * image->num_cols * 3);
|
||||||
image->cp += xcf_read_int8 (image->fp, (DATA8*) image->cmap, image->num_cols*3);
|
image->cp += xcf_read_int8 (image->fp, (DATA8*) image->cmap, image->num_cols*3);
|
||||||
|
@ -696,7 +700,7 @@ xcf_load_layer(void)
|
||||||
image->cp += xcf_read_string (image->fp, &name, 1);
|
image->cp += xcf_read_string (image->fp, &name, 1);
|
||||||
|
|
||||||
/* ugly, I know */
|
/* ugly, I know */
|
||||||
free(name);
|
FREE(name);
|
||||||
|
|
||||||
/* create a new layer */
|
/* create a new layer */
|
||||||
layer = new_layer (width, height, type, 255, NORMAL_MODE);
|
layer = new_layer (width, height, type, 255, NORMAL_MODE);
|
||||||
|
@ -738,7 +742,9 @@ xcf_load_layer(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
read_tiles_into_data(layer->tiles, layer->num_cols,
|
read_tiles_into_data(layer->tiles, layer->num_cols,
|
||||||
layer->width, layer->height, layer->bpp, &(layer->data));
|
layer->width, layer->height,
|
||||||
|
layer->bpp, &(layer->data),
|
||||||
|
1);
|
||||||
free_tiles(layer->tiles, layer->num_rows * layer->num_cols);
|
free_tiles(layer->tiles, layer->num_rows * layer->num_cols);
|
||||||
layer->tiles = NULL;
|
layer->tiles = NULL;
|
||||||
|
|
||||||
|
@ -756,8 +762,8 @@ error:
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
read_tiles_into_data(Tile* tiles, int num_cols,
|
read_tiles_into_data(Tile* tiles, int num_cols, int width,
|
||||||
int width, int height, int bpp, DATA8** data_p)
|
int height, int bpp, DATA8** data_p, int use_cmap)
|
||||||
{
|
{
|
||||||
int tile_x, tile_y, x, y, offset_x, offset_y;
|
int tile_x, tile_y, x, y, offset_x, offset_y;
|
||||||
DATA8* data;
|
DATA8* data;
|
||||||
|
@ -765,10 +771,11 @@ read_tiles_into_data(Tile* tiles, int num_cols,
|
||||||
DATA8* ptr2;
|
DATA8* ptr2;
|
||||||
Tile* t;
|
Tile* t;
|
||||||
|
|
||||||
|
|
||||||
if (tiles)
|
if (tiles)
|
||||||
{
|
{
|
||||||
if (*data_p)
|
if (*data_p)
|
||||||
free(*data_p);
|
FREE(*data_p);
|
||||||
|
|
||||||
/* Always allocate the data as 4 bytes per pixel */
|
/* Always allocate the data as 4 bytes per pixel */
|
||||||
data = (*data_p) = (DATA8*) malloc (sizeof(DATA32) * width * height);
|
data = (*data_p) = (DATA8*) malloc (sizeof(DATA32) * width * height);
|
||||||
|
@ -792,11 +799,12 @@ read_tiles_into_data(Tile* tiles, int num_cols,
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
/* use colormap if the image has one */
|
/* use colormap if the image has one */
|
||||||
if (image->cmap)
|
if (image->cmap && use_cmap)
|
||||||
{
|
{
|
||||||
R_VAL(ptr) = image->cmap[*(ptr2) * 3];
|
R_VAL(ptr) = image->cmap[*(ptr2) * 3];
|
||||||
G_VAL(ptr) = image->cmap[*(ptr2) * 3 + 1];
|
G_VAL(ptr) = image->cmap[*(ptr2) * 3 + 1];
|
||||||
B_VAL(ptr) = image->cmap[*(ptr2) * 3 + 2];
|
B_VAL(ptr) = image->cmap[*(ptr2) * 3 + 2];
|
||||||
|
printf("%i %i %i\n", R_VAL(ptr), G_VAL(ptr), B_VAL(ptr));
|
||||||
A_VAL(ptr) = 255;
|
A_VAL(ptr) = 255;
|
||||||
}
|
}
|
||||||
/* else use colors themselves */
|
/* else use colors themselves */
|
||||||
|
@ -812,7 +820,7 @@ read_tiles_into_data(Tile* tiles, int num_cols,
|
||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
/* use colormap if the image has one */
|
/* use colormap if the image has one */
|
||||||
if (image->cmap)
|
if (image->cmap && use_cmap)
|
||||||
{
|
{
|
||||||
R_VAL(ptr) = image->cmap[*(ptr2) * 3];
|
R_VAL(ptr) = image->cmap[*(ptr2) * 3];
|
||||||
G_VAL(ptr) = image->cmap[*(ptr2) * 3 + 1];
|
G_VAL(ptr) = image->cmap[*(ptr2) * 3 + 1];
|
||||||
|
@ -874,7 +882,7 @@ xcf_load_channel (void)
|
||||||
image->cp += xcf_read_string (image->fp, &name, 1);
|
image->cp += xcf_read_string (image->fp, &name, 1);
|
||||||
|
|
||||||
/* Yeah, still ugly :) */
|
/* Yeah, still ugly :) */
|
||||||
free(name);
|
FREE(name);
|
||||||
|
|
||||||
/* create a new channel */
|
/* create a new channel */
|
||||||
layer = new_layer (width, height, GRAY, 255, NORMAL_MODE);
|
layer = new_layer (width, height, GRAY, 255, NORMAL_MODE);
|
||||||
|
@ -893,8 +901,8 @@ xcf_load_channel (void)
|
||||||
if (!xcf_load_hierarchy(&(layer->tiles), &(layer->num_rows), &(layer->num_cols), &(layer->bpp)))
|
if (!xcf_load_hierarchy(&(layer->tiles), &(layer->num_rows), &(layer->num_cols), &(layer->bpp)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
read_tiles_into_data(layer->tiles, layer->num_cols,
|
read_tiles_into_data(layer->tiles, layer->num_cols, layer->width,
|
||||||
layer->width, layer->height, layer->bpp, &(layer->data));
|
layer->height, layer->bpp, &(layer->data), 0);
|
||||||
free_tiles(layer->tiles, layer->num_rows * layer->num_cols);
|
free_tiles(layer->tiles, layer->num_rows * layer->num_cols);
|
||||||
layer->tiles = NULL;
|
layer->tiles = NULL;
|
||||||
|
|
||||||
|
@ -1237,13 +1245,13 @@ xcf_load_tile_rle (Tile *tile,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free (xcfodata);
|
FREE(xcfodata);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
bogus_rle:
|
bogus_rle:
|
||||||
fprintf(stderr, "WHOOOOOP -- bogus rle? Highly unlikely, blame cK for this one :) \n");
|
fprintf(stderr, "WHOOOOOP -- bogus rle? Highly unlikely, blame cK for this one :) \n");
|
||||||
if (xcfodata)
|
if (xcfodata)
|
||||||
free (xcfodata);
|
FREE(xcfodata);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1287,7 +1295,10 @@ free_layer(Layer* layer)
|
||||||
if (layer->mask)
|
if (layer->mask)
|
||||||
free_layer(layer->mask);
|
free_layer(layer->mask);
|
||||||
|
|
||||||
free(layer);
|
if (layer->data)
|
||||||
|
FREE(layer->data);
|
||||||
|
|
||||||
|
FREE(layer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1353,9 +1364,9 @@ free_tiles(Tile* tiles, int num_tiles)
|
||||||
for (i=0; i<num_tiles; i++)
|
for (i=0; i<num_tiles; i++)
|
||||||
{
|
{
|
||||||
if (tiles[i].data)
|
if (tiles[i].data)
|
||||||
free (tiles[i].data);
|
FREE(tiles[i].data);
|
||||||
}
|
}
|
||||||
free (tiles);
|
FREE(tiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1403,7 +1414,7 @@ apply_layer_mask(Layer* layer)
|
||||||
{
|
{
|
||||||
DATA8* ptr1;
|
DATA8* ptr1;
|
||||||
DATA8* ptr2;
|
DATA8* ptr2;
|
||||||
int i;
|
int i, tmp;
|
||||||
|
|
||||||
D(("Applying layer mask.\n"));
|
D(("Applying layer mask.\n"));
|
||||||
|
|
||||||
|
@ -1416,7 +1427,11 @@ apply_layer_mask(Layer* layer)
|
||||||
|
|
||||||
for (i = 0; i < layer->width*layer->height; i++)
|
for (i = 0; i < layer->width*layer->height; i++)
|
||||||
{
|
{
|
||||||
*(ptr1+3) = (*(ptr1+3) * *(ptr2)) >> 8;
|
tmp = (*(ptr1+3) * *(ptr2)) / 256;
|
||||||
|
if (tmp > 255)
|
||||||
|
tmp = 255;
|
||||||
|
|
||||||
|
*(ptr1+3) = (DATA8)tmp;
|
||||||
ptr1 += 4;
|
ptr1 += 4;
|
||||||
ptr2 += 4;
|
ptr2 += 4;
|
||||||
}
|
}
|
||||||
|
@ -1546,7 +1561,7 @@ flatten_image(void)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
D(("Unknown layer mode: %i. Skipping.\n", lp->mode));
|
D(("Unknown layer mode: %i. Skipping.\n", l->mode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1569,7 +1584,6 @@ xcf_file_init(char* filename)
|
||||||
{
|
{
|
||||||
char success = 1;
|
char success = 1;
|
||||||
char id[14];
|
char id[14];
|
||||||
char* suffix = NULL;
|
|
||||||
|
|
||||||
image->single_layer_index = -1;
|
image->single_layer_index = -1;
|
||||||
/*
|
/*
|
||||||
|
@ -1632,6 +1646,9 @@ xcf_cleanup(void)
|
||||||
free_layer(l);
|
free_layer(l);
|
||||||
l = lp;
|
l = lp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (image->cmap)
|
||||||
|
FREE(image->cmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in New Issue