Commit 644a0060 authored by Manish Singh's avatar Manish Singh

updated CEL plugin added psd plugin and autoconfed for byte order

updated CEL plugin
added psd plugin and autoconfed for byte order

-Yosh
parent 8137f724
Sun Apr 26 02:34:21 PDT 1998 Manish Singh <yosh@gimp.org>
* updated CEL plugin
* added PSD plugin and autoconf for byte order
Thu Apr 23 19:08:16 PDT 1998 Manish Singh <yosh@gimp.org>
* Added sharpen to stable dist
......
......@@ -46,6 +46,10 @@
/* Define if you can safely include both <sys/time.h> and <time.h>. */
#undef TIME_WITH_SYS_TIME
/* Define if your processor stores words with the most significant
byte first (like Motorola and SPARC, unlike Intel and VAX). */
#undef WORDS_BIGENDIAN
#undef HAVE_DIRENT_H
#undef HAVE_DOPRNT
#undef HAVE_IPC_H
......
......@@ -42,7 +42,7 @@ fi)
AC_DEFUN(AC_GIMP_CHECK,
[
AM_PATH_GTK(0.99.7,,
AM_PATH_GTK(1.0.0,,
AC_MSG_ERROR(Test for GTK failed. See the file 'INSTALL' for help.))
X_LIBS=$GTK_LIBS
X_CFLAGS=$GTK_CFLAGS
......@@ -262,13 +262,16 @@ AC_HEADER_TIME
AC_CHECK_HEADER(sys/time.h, AC_DEFINE(HAVE_SYS_TIME_H))
AC_CHECK_HEADER(unistd.h, AC_DEFINE(HAVE_UNISTD_H))
dnl for the psd plugin
AC_C_BIGENDIAN
AC_TYPE_PID_T
AC_TYPE_SIGNAL
AC_FUNC_VPRINTF
AC_FUNC_ALLOCA
# Check for sys/select.h
dnl Check for sys/select.h
AC_MSG_CHECKING([fd_set and sys/select])
AC_TRY_COMPILE([#include <sys/types.h>],
......@@ -546,6 +549,7 @@ plug-ins/gfig/Makefile
plug-ins/gfig/gfig-examples/Makefile
plug-ins/screenshot/Makefile
plug-ins/sharpen/Makefile
plug-ins/psd/Makefile
app/Makefile
docs/Makefile
data/Makefile
......
......@@ -10,8 +10,12 @@
* 0.2 Default palette (nice yellows) is automatically used
* 0.3 Support for the older (pre KISS/GS) cell format
* 0.4 First support for saving images
* Future additions:
* + Automagically or via dialog box choose a KCF palette
* 0.5 Show copyright date, not version number, thanks to DbBrowser
* 0.6 File dialogs, palette handling, better magic behaviour
* 0.7 Handle interactivity settings, tidy up
* 1.0 Fixed for GIMP 0.99.27 running on GTK+ 1.0.0, and released
*
* Possible future additions:
* + Save (perhaps optionally?) the palette in a KCF
* + Support offsets -- like GIF?
*/
......@@ -23,14 +27,14 @@
#include <gtk/gtk.h>
#include <libgimp/gimp.h>
#define VERSION "0.4"
static void query(void);
static void run(char *name, int nparams, GParam *param,
int *nreturn_vals, GParam **return_vals);
static gint load_palette(FILE *fp, guchar palette[]);
static gint32 load_image(char *file, char *brief);
static gint save_image(char *file, char *brief,
gint32 image, gint32 layer);
static gint palette_dialog(char *title);
/* Globals... */
......@@ -42,10 +46,13 @@ GPlugInInfo PLUG_IN_INFO =
run, /* run_proc */
};
char *palette_file= NULL;
size_t data_length= 0;
/* Let GIMP library handle initialisation (and inquisitive users) */
int main(int argc, char *argv[]) {
return (gimp_main(argc, argv));
return gimp_main(argc, argv);
}
/* GIMP queries plug-in for parameters etc. */
......@@ -54,8 +61,9 @@ static void query(void) {
static GParamDef load_args[] =
{
{ PARAM_INT32, "run_mode", "Interactive, non-interactive" },
{ PARAM_STRING, "filename", "The name of the file to load" },
{ PARAM_STRING, "raw_filename", "The name of the file to load" },
{ PARAM_STRING, "filename", "Filename to load image from" },
{ PARAM_STRING, "raw_filename", "Name entered" },
{ PARAM_STRING, "palette_filename", "Filename to load palette from" },
};
static GParamDef load_return_vals[] =
......@@ -66,11 +74,12 @@ static void query(void) {
static int nload_return_vals = sizeof (load_return_vals) / sizeof (load_return_vals[0]);
static GParamDef save_args[] =
{
{ PARAM_INT32, "run_mode", "Interactive, non-interactive" },
{ PARAM_IMAGE, "image", "Input image" },
{ PARAM_DRAWABLE, "drawable", "Drawable to save" },
{ PARAM_STRING, "filename", "The name of the file to save the image in" },
{ PARAM_STRING, "raw_filename", "The name of the file to save the image in" },
{ PARAM_INT32, "run_mode", "Interactive, non-interactive" },
{ PARAM_IMAGE, "image", "Input image" },
{ PARAM_DRAWABLE, "drawable", "Drawable to save" },
{ PARAM_STRING, "filename", "Filename to save image to" },
{ PARAM_STRING, "raw_filename", "Name entered" },
{ PARAM_STRING, "palette_filename", "Filename to save palette to" },
};
static int nsave_args = sizeof (save_args) / sizeof (save_args[0]);
......@@ -78,17 +87,16 @@ static void query(void) {
gimp_install_procedure("file_cel_load",
"Loads files in KISS CEL file format",
"This plug-in loads individual KISS cell files.",
"Nick Lamb", "Nick Lamb", VERSION,
"<Load>/CEL", NULL, PROC_PLUG_IN,
"Nick Lamb", "Nick Lamb", "April 1998", "<Load>/CEL", NULL, PROC_PLUG_IN,
nload_args, nload_return_vals, load_args, load_return_vals);
gimp_register_magic_load_handler("file_cel_load", "cel",
"", "0,string,KiSS");
"", "0,string,KiSS\040");
gimp_install_procedure("file_cel_save",
"Saves files in KISS CEL file format",
"This plug-in saves individual KISS cell files.",
"Nick Lamb", "Nick Lamb", VERSION, "<Save>/CEL", "INDEXED*",
"Nick Lamb", "Nick Lamb", "April 1998", "<Save>/CEL", "INDEXED*",
PROC_PLUG_IN, nsave_args, 0, save_args, NULL);
gimp_register_save_handler("file_cel_save", "cel", "");
......@@ -98,17 +106,42 @@ static void run(char *name, int nparams, GParam *param,
int *nreturn_vals, GParam **return_vals) {
gint32 image; /* image ID after load */
gint status; /* status after save */
static GParam values[2]; /* Return values */
GRunModeType run_mode;
run_mode = param[0].data.d_int32;
/* Set up default return values */
*nreturn_vals = 1;
values[0].type = PARAM_STATUS;
values[0].data.d_status = STATUS_SUCCESS;
*nreturn_vals = 1;
*return_vals = values;
if (strcmp(name, "file_cel_load") == 0) {
if (run_mode != RUN_NONINTERACTIVE) {
gimp_get_data ("file_cel_save:length", &data_length);
if (data_length > 0) {
palette_file= (char *) g_malloc(data_length);
gimp_get_data ("file_cel_save:data", palette_file);
} else {
palette_file= g_strdup("*.kcf");
data_length= strlen(palette_file) + 1;
}
}
if (run_mode == RUN_NONINTERACTIVE) {
palette_file= param[3].data.d_string;
data_length= strlen(palette_file) + 1;
} else if (run_mode == RUN_INTERACTIVE) {
/* Let user choose KCF palette (cancel ignores) */
palette_dialog("Load KISS Palette");
gimp_set_data ("file_cel_save:length", &data_length, sizeof (size_t));
gimp_set_data ("file_cel_save:data", palette_file, data_length);
}
image = load_image(param[1].data.d_string, param[2].data.d_string);
if (image != -1) {
......@@ -120,8 +153,15 @@ static void run(char *name, int nparams, GParam *param,
}
} else if (strcmp (name, "file_cel_save") == 0) {
save_image(param[3].data.d_string, param[4].data.d_string,
param[1].data.d_int32, param[2].data.d_int32);
status = save_image(param[3].data.d_string, param[4].data.d_string,
param[1].data.d_int32, param[2].data.d_int32);
if (status != TRUE) {
values[0].data.d_status = STATUS_EXECUTION_ERROR;
} else {
gimp_set_data ("file_cel_save:length", &data_length, sizeof (size_t));
gimp_set_data ("file_cel_save:data", palette_file, data_length);
}
} else {
values[0].data.d_status = STATUS_EXECUTION_ERROR;
}
......@@ -131,7 +171,7 @@ static void run(char *name, int nparams, GParam *param,
static gint32 load_image(char *file, char *brief) {
FILE* fp; /* Read file pointer */
char progress[255]; /* Title for progress display */
char *progress; /* Title for progress display */
guchar header[32]; /* File header */
int height, width, /* Dimensions of image */
colours; /* Number of colours */
......@@ -150,6 +190,12 @@ static gint32 load_image(char *file, char *brief) {
/* Open the file for reading */
fp = fopen(file, "r");
if (fp == NULL) {
g_print("Can't open file\n");
gimp_quit();
}
progress= g_malloc(strlen(brief) + 10);
sprintf(progress, "Loading %s:", brief);
gimp_progress_init(progress);
......@@ -157,11 +203,11 @@ static gint32 load_image(char *file, char *brief) {
fread(header, 4, 1, fp);
if (strncmp((char *)header, "KiSS", 4)) {
if (strncmp(header, "KiSS", 4)) {
colours= 16;
width= header[0] + (256 * header[1]);
height= header[2] + (256 * header[3]);
} else {
} else { /* New-style image file, read full header */
fread(header, 28, 1, fp);
colours= (1 << header[1]);
width= header[4] + (256 * header[5]);
......@@ -177,14 +223,6 @@ static gint32 load_image(char *file, char *brief) {
gimp_image_set_filename(image, file);
palette = g_new(guchar, colours*3);
/* FIXME Default palette -- hopefully nasty enough to encourage a fix */
for (i= 1; i < colours; ++i)
palette[i*3+1]= palette[i*3]= i * 256 / colours;
gimp_image_set_cmap(image, palette, colours);
/* Create an indexed-alpha layer to hold the image... */
layer = gimp_layer_new(image, "Background", width, height,
......@@ -203,7 +241,7 @@ static gint32 load_image(char *file, char *brief) {
buffer = g_new(guchar, width);
line = g_new(guchar, (width+1) * 2);
for (i = 0; i < height; ++i) {
for (i = 0; i < height && !feof(fp); ++i) {
switch (colours) {
case 16:
......@@ -228,11 +266,35 @@ static gint32 load_image(char *file, char *brief) {
gimp_progress_update((float) i / (float) height);
}
/* Close files, give back allocated memory */
/* Close image files, give back allocated memory */
fclose(fp);
free(buffer);
free(line);
/* Use palette from file or otherwise default grey palette */
palette = g_new(guchar, colours*3);
/* Open the file for reading if user picked one */
if (palette_file == NULL) {
fp= NULL;
} else {
fp = fopen(palette_file, "r");
}
if (fp != NULL) {
colours= load_palette(fp, palette);
} else {
for (i= 0; i < colours; ++i) {
palette[i*3]= palette[i*3+1]= palette[i*3+2]= i * 256 / colours;
}
}
gimp_image_set_cmap(image, palette, colours);
/* Close palette file, give back allocated memory */
fclose(fp);
free(palette);
/* Now get everything redrawn and hand back the finished image */
......@@ -243,9 +305,43 @@ static gint32 load_image(char *file, char *brief) {
return (image);
}
static gint load_palette(FILE *fp, guchar palette[]) {
guchar header[32]; /* File header */
guchar buffer[2];
int i, bpp, colours= 0;
fread(header, 4, 1, fp);
if (!strncmp(header, "KiSS", 4)) {
fread(header+4, 28, 1, fp);
bpp= header[5];
colours= header[8] + header[9] * 256;
if (bpp == 12) {
for (i= 0; i < colours; ++i) {
fread(buffer, 1, 2, fp);
palette[i*3]= buffer[0] & 0xf0;
palette[i*3+1]= (buffer[1] & 0x0f) * 16;
palette[i*3+2]= (buffer[0] & 0x0f) * 16;
}
} else {
fread(palette, colours, 3, fp);
}
} else {
colours= 16; bpp= 12;
fseek(fp, 0, SEEK_SET);
for (i= 0; i < colours; ++i) {
fread(buffer, 1, 2, fp);
palette[i*3]= buffer[0] & 0xf0;
palette[i*3+1]= (buffer[1] & 0x0f) * 16;
palette[i*3+2]= (buffer[0] & 0x0f) * 16;
}
}
return colours;
}
static gint save_image(char *file, char *brief, gint32 image, gint32 layer) {
FILE* fp; /* Write file pointer */
char progress[255]; /* Title for progress display */
char *progress; /* Title for progress display */
guchar header[32]; /* File header */
gint colours, type; /* Number of colours, type of layer */
......@@ -268,12 +364,13 @@ static gint save_image(char *file, char *brief, gint32 image, gint32 layer) {
/* Open the file for writing */
fp = fopen(file, "w");
progress= g_malloc(strlen(brief) + 9);
sprintf(progress, "Saving %s:", brief);
gimp_progress_init(progress);
/* Headers */
memset(header,(int)0,(size_t)32);
strcpy((char *)header, "KiSS");
memset(header, 0, 32);
strcpy(header, "KiSS");
header[4]= 0x20;
/* Work out whether to save as 8bit or 4bit */
......@@ -327,3 +424,43 @@ static gint save_image(char *file, char *brief, gint32 image, gint32 layer) {
return TRUE;
}
static void palette_ok (GtkWidget *widget, GtkWidget **fs) {
g_free(palette_file);
palette_file= g_strdup(gtk_file_selection_get_filename
(GTK_FILE_SELECTION(fs)));
data_length= strlen(palette_file) + 1;
gtk_widget_destroy (GTK_WIDGET (fs));
}
static void palette_cancel (GtkWidget *widget, GtkWidget **window) {
gtk_main_quit ();
}
static gint palette_dialog(char *title) {
gchar **argv;
gint argc = 1;
GtkWidget *dialog;
argv= g_malloc(sizeof(gchar *));
argv[0]= strdup("CEL file-filter");
gtk_init (&argc, &argv);
gtk_rc_parse (gimp_gtkrc ());
dialog= gtk_file_selection_new(title);
gtk_window_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
gtk_file_selection_set_filename(GTK_FILE_SELECTION(dialog), palette_file);
gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (dialog)->ok_button),
"clicked", (GtkSignalFunc) palette_ok, dialog);
gtk_signal_connect (GTK_OBJECT (dialog),
"destroy", (GtkSignalFunc) palette_cancel, NULL);
gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (dialog)->cancel_button), "clicked", (GtkSignalFunc) palette_cancel, GTK_OBJECT (dialog));
gtk_widget_show(dialog);
gtk_main ();
gdk_flush ();
return 0;
}
......@@ -95,6 +95,7 @@ SUBDIRS = \
polar \
print \
ps \
psd \
randomize \
ripple \
rotate \
......
......@@ -10,8 +10,12 @@
* 0.2 Default palette (nice yellows) is automatically used
* 0.3 Support for the older (pre KISS/GS) cell format
* 0.4 First support for saving images
* Future additions:
* + Automagically or via dialog box choose a KCF palette
* 0.5 Show copyright date, not version number, thanks to DbBrowser
* 0.6 File dialogs, palette handling, better magic behaviour
* 0.7 Handle interactivity settings, tidy up
* 1.0 Fixed for GIMP 0.99.27 running on GTK+ 1.0.0, and released
*
* Possible future additions:
* + Save (perhaps optionally?) the palette in a KCF
* + Support offsets -- like GIF?
*/
......@@ -23,14 +27,14 @@
#include <gtk/gtk.h>
#include <libgimp/gimp.h>
#define VERSION "0.4"
static void query(void);
static void run(char *name, int nparams, GParam *param,
int *nreturn_vals, GParam **return_vals);
static gint load_palette(FILE *fp, guchar palette[]);
static gint32 load_image(char *file, char *brief);
static gint save_image(char *file, char *brief,
gint32 image, gint32 layer);
static gint palette_dialog(char *title);
/* Globals... */
......@@ -42,10 +46,13 @@ GPlugInInfo PLUG_IN_INFO =
run, /* run_proc */
};
char *palette_file= NULL;
size_t data_length= 0;
/* Let GIMP library handle initialisation (and inquisitive users) */
int main(int argc, char *argv[]) {
return (gimp_main(argc, argv));
return gimp_main(argc, argv);
}
/* GIMP queries plug-in for parameters etc. */
......@@ -54,8 +61,9 @@ static void query(void) {
static GParamDef load_args[] =
{
{ PARAM_INT32, "run_mode", "Interactive, non-interactive" },
{ PARAM_STRING, "filename", "The name of the file to load" },
{ PARAM_STRING, "raw_filename", "The name of the file to load" },
{ PARAM_STRING, "filename", "Filename to load image from" },
{ PARAM_STRING, "raw_filename", "Name entered" },
{ PARAM_STRING, "palette_filename", "Filename to load palette from" },
};
static GParamDef load_return_vals[] =
......@@ -66,11 +74,12 @@ static void query(void) {
static int nload_return_vals = sizeof (load_return_vals) / sizeof (load_return_vals[0]);
static GParamDef save_args[] =
{
{ PARAM_INT32, "run_mode", "Interactive, non-interactive" },
{ PARAM_IMAGE, "image", "Input image" },
{ PARAM_DRAWABLE, "drawable", "Drawable to save" },
{ PARAM_STRING, "filename", "The name of the file to save the image in" },
{ PARAM_STRING, "raw_filename", "The name of the file to save the image in" },
{ PARAM_INT32, "run_mode", "Interactive, non-interactive" },
{ PARAM_IMAGE, "image", "Input image" },
{ PARAM_DRAWABLE, "drawable", "Drawable to save" },
{ PARAM_STRING, "filename", "Filename to save image to" },
{ PARAM_STRING, "raw_filename", "Name entered" },
{ PARAM_STRING, "palette_filename", "Filename to save palette to" },
};
static int nsave_args = sizeof (save_args) / sizeof (save_args[0]);
......@@ -78,17 +87,16 @@ static void query(void) {
gimp_install_procedure("file_cel_load",
"Loads files in KISS CEL file format",
"This plug-in loads individual KISS cell files.",
"Nick Lamb", "Nick Lamb", VERSION,
"<Load>/CEL", NULL, PROC_PLUG_IN,
"Nick Lamb", "Nick Lamb", "April 1998", "<Load>/CEL", NULL, PROC_PLUG_IN,
nload_args, nload_return_vals, load_args, load_return_vals);
gimp_register_magic_load_handler("file_cel_load", "cel",
"", "0,string,KiSS");
"", "0,string,KiSS\040");
gimp_install_procedure("file_cel_save",
"Saves files in KISS CEL file format",
"This plug-in saves individual KISS cell files.",
"Nick Lamb", "Nick Lamb", VERSION, "<Save>/CEL", "INDEXED*",
"Nick Lamb", "Nick Lamb", "April 1998", "<Save>/CEL", "INDEXED*",
PROC_PLUG_IN, nsave_args, 0, save_args, NULL);
gimp_register_save_handler("file_cel_save", "cel", "");
......@@ -98,17 +106,42 @@ static void run(char *name, int nparams, GParam *param,
int *nreturn_vals, GParam **return_vals) {
gint32 image; /* image ID after load */
gint status; /* status after save */
static GParam values[2]; /* Return values */
GRunModeType run_mode;
run_mode = param[0].data.d_int32;
/* Set up default return values */
*nreturn_vals = 1;
values[0].type = PARAM_STATUS;
values[0].data.d_status = STATUS_SUCCESS;
*nreturn_vals = 1;
*return_vals = values;
if (strcmp(name, "file_cel_load") == 0) {
if (run_mode != RUN_NONINTERACTIVE) {
gimp_get_data ("file_cel_save:length", &data_length);
if (data_length > 0) {
palette_file= (char *) g_malloc(data_length);
gimp_get_data ("file_cel_save:data", palette_file);
} else {
palette_file= g_strdup("*.kcf");
data_length= strlen(palette_file) + 1;
}
}
if (run_mode == RUN_NONINTERACTIVE) {
palette_file= param[3].data.d_string;
data_length= strlen(palette_file) + 1;
} else if (run_mode == RUN_INTERACTIVE) {
/* Let user choose KCF palette (cancel ignores) */
palette_dialog("Load KISS Palette");
gimp_set_data ("file_cel_save:length", &data_length, sizeof (size_t));
gimp_set_data ("file_cel_save:data", palette_file, data_length);
}
image = load_image(param[1].data.d_string, param[2].data.d_string);
if (image != -1) {
......@@ -120,8 +153,15 @@ static void run(char *name, int nparams, GParam *param,
}
} else if (strcmp (name, "file_cel_save") == 0) {
save_image(param[3].data.d_string, param[4].data.d_string,
param[1].data.d_int32, param[2].data.d_int32);
status = save_image(param[3].data.d_string, param[4].data.d_string,
param[1].data.d_int32, param[2].data.d_int32);
if (status != TRUE) {
values[0].data.d_status = STATUS_EXECUTION_ERROR;
} else {
gimp_set_data ("file_cel_save:length", &data_length, sizeof (size_t));
gimp_set_data ("file_cel_save:data", palette_file, data_length);
}
} else {
values[0].data.d_status = STATUS_EXECUTION_ERROR;
}
......@@ -131,7 +171,7 @@ static void run(char *name, int nparams, GParam *param,
static gint32 load_image(char *file, char *brief) {
FILE* fp; /* Read file pointer */
char progress[255]; /* Title for progress display */
char *progress; /* Title for progress display */
guchar header[32]; /* File header */
int height, width, /* Dimensions of image */
colours; /* Number of colours */
......@@ -150,6 +190,12 @@ static gint32 load_image(char *file, char *brief) {
/* Open the file for reading */
fp = fopen(file, "r");
if (fp == NULL) {
g_print("Can't open file\n");
gimp_quit();
}
progress= g_malloc(strlen(brief) + 10);
sprintf(progress, "Loading %s:", brief);
gimp_progress_init(progress);
......@@ -157,11 +203,11 @@ static gint32 load_image(char *file, char *brief) {
fread(header, 4, 1, fp);
if (strncmp((char *)header, "KiSS", 4)) {
if (strncmp(header, "KiSS", 4)) {
colours= 16;
width= header[0] + (256 * header[1]);
height= header[2] + (256 * header[3]);
} else {
} else { /* New-style image file, read full header */
fread(header, 28, 1, fp);
colours= (1 << header[1]);
width= header[4] + (256 * header[5]);
......@@ -177,14 +223,6 @@ static gint32 load_image(char *file, char *brief) {
gimp_image_set_filename(image, file);
palette = g_new(guchar, colours*3);
/* FIXME Default palette -- hopefully nasty enough to encourage a fix */
for (i= 1; i < colours; ++i)
palette[i*3+1]= palette[i*3]= i * 256 / colours;
gimp_image_set_cmap(image, palette, colours);
/* Create an indexed-alpha layer to hold the image... */
layer = gimp_layer_new(image, "Background", width, height,
......@@ -203,7 +241,7 @@ static gint32 load_image(char *file, char *brief) {
buffer = g_new(guchar, width);
line = g_new(guchar, (width+1) * 2);
for (i = 0; i < height; ++i) {
for (i = 0; i < height && !feof(fp); ++i) {
switch (colours) {
case 16:
......@@ -228,11 +266,35 @@ static gint32 load_image(char *file, char *brief) {
gimp_progress_update((float) i / (float) height);
}
/* Close files, give back allocated memory */
/* Close image files, give back allocated memory */
fclose(fp);
free(buffer);
free(line);
/* Use palette from file or otherwise default grey palette */
palette = g_new(guchar, colours*3);
/* Open the file for reading if user picked one */
if (palette_file == NULL) {
fp= NULL;
} else {
fp = fopen(palette_file, "r");
}
if (fp != NULL) {
colours= load_palette(fp, palette);
} else {
for (i= 0; i < colours; ++i) {
palette[i*3]= palette[i*3+1]= palette[i*3+2]= i * 256 / colours;
}
}
gimp_image_set_cmap(image, palette, colours);
/* Close palette file, give back allocated memory */
fclose(fp);
free(palette);
/* Now get everything redrawn and hand back the finished image */
......@@ -243,9 +305,43 @@ static gint32 load_image(char *file, char *brief) {
return (image);
}
static gint load_palette(FILE *fp, guchar palette[]) {
guchar header[32]; /* File header */
guchar buffer[2];
int i, bpp, colours= 0;
fread(header, 4, 1, fp);
if (!strncmp(header, "KiSS", 4)) {
fread(header+4, 28, 1, fp);
bpp= header[5];
colours= header[8] + header[9] * 256;
if (bpp == 12) {
for (i= 0; i < colours; ++i) {
fread(buffer, 1, 2, fp);
palette[i*3]= buffer[0] & 0xf0;
palette[i*3+1]= (buffer[1] & 0x0f) * 16;
palette[i*3+2]= (buffer[0] & 0x0f) * 16;
}
} else {
fread(palette, colours, 3, fp);
}
} else {
colours= 16; bpp= 12;
fseek(fp, 0, SEEK_SET);
for (i= 0; i < colours; ++i) {
fread(buffer, 1, 2, fp);
palette[i*3]= buffer[0] & 0xf0;
palette[i*3+1]= (buffer[1] & 0x0f) * 16;
palette[i*3+2]= (buffer[0] & 0x0f) * 16;
}
}
return colours;
}
static gint save_image(char *file, char *brief, gint32 image, gint32 layer) {
FILE* fp; /* Write file pointer */
char progress[255]; /* Title for progress display */
char *progress; /* Title for progress display */
guchar header[32]; /* File header */
gint colours, type; /* Number of colours, type of layer */
......@@ -268,12 +364,13 @@ static gint save_image(char *file, char *brief, gint32 image, gint32 layer) {
/* Open the file for writing */
fp = fopen(file, "w");
progress= g_malloc(strlen(brief) + 9);
sprintf(progress, "Saving %s:", brief);
gimp_progress_init(progress);
/* Headers */
memset(header,(int)0,(size_t)