diff options
-rw-r--r-- | img-load.c | 352 | ||||
-rw-r--r-- | img-load.h | 4 | ||||
-rw-r--r-- | img-save-dialog.c | 356 | ||||
-rw-r--r-- | img-save-dialog.h | 4 | ||||
-rw-r--r-- | img-save.c | 689 | ||||
-rw-r--r-- | img-save.h | 14 | ||||
-rw-r--r-- | plugin-img.c | 375 | ||||
-rw-r--r-- | plugin-img.h | 72 |
8 files changed, 935 insertions, 931 deletions
@@ -1,219 +1,221 @@ #include "plugin-img.h" static inline void -rgb565_to_rgb(const guint16 * rgb565, guint8 * res) +rgb565_to_rgb (const guint16 * rgb565, guint8 * res) { - /* - * How to: - * | 16 bits | - * | high || low | - * 11111 111111 11111 - * | B | | G | | R | - * 111110001111110011111000 - * | B || G || R | - * | 24 bits | - * - */ - res[0] = (guint8) (((*rgb565) & 0x1F) << 3); /* Red */ - res[1] = (guint8) (((*rgb565) & 0x7E0) >> 3); /* Green */ - res[2] = (guint8) (((*rgb565) & 0xF800) >> 8); /* Blue */ + /* + * How to: + * | 16 bits | + * | high || low | + * 11111 111111 11111 + * | B | | G | | R | + * 111110001111110011111000 + * | B || G || R | + * | 24 bits | + * + */ + res[0] = (guint8) (((*rgb565) & 0x1F) << 3); /* Red */ + res[1] = (guint8) (((*rgb565) & 0x7E0) >> 3); /* Green */ + res[2] = (guint8) (((*rgb565) & 0xF800) >> 8); /* Blue */ } static void -img_map_rgb565_to_rgb(const guint8 * src, guint8 * dest, size_t src_size) +img_map_rgb565_to_rgb (const guint8 * src, guint8 * dest, size_t src_size) { - size_t s, d; + size_t s, d; - /* - * 5+6+5=16bits (2 bytes) per pixel - */ - for (s = 0, d = 0; s < src_size;) + /* + * 5+6+5=16bits (2 bytes) per pixel + */ + for (s = 0, d = 0; s < src_size;) { - rgb565_to_rgb((const guint16 *)&(src[s]), &(dest[d])); - s += 2; - d += 3; + rgb565_to_rgb ((const guint16 *) &(src[s]), &(dest[d])); + s += 2; + d += 3; } } gint32 -img_load_image(const gchar * filename, ImageParasite * meta, GError ** error) +img_load_image (const gchar * filename, ImageParasite * meta, GError ** error) { - FILE *fp; - size_t nread; - size_t src_size; - guint8 *src, *dest; - FileHeader hdr; - ColorKey ckey; - guint32 row, col, width, height; - gint32 frame, nframes, *frames; - gchar buf[20]; - gint32 image, layer; - GimpDrawable *drawable; - GimpPixelRgn pixel_rgn; - GimpImageType image_type; - - ckey.is = 0; - ckey.R = 0; - ckey.G = 0; - ckey.B = 0; - gimp_progress_init_printf("Opening '%s'", gimp_filename_to_utf8(filename)); - - D(("*** Loading \"%s\"\n", filename)); - fp = g_fopen(filename, "rb"); - if (!fp) + FILE *fp; + size_t nread; + size_t src_size; + guint8 *src, *dest; + FileHeader hdr; + ColorKey ckey; + guint32 row, col, width, height; + gint32 frame, nframes, *frames; + gchar buf[20]; + gint32 image, layer; + GimpDrawable *drawable; + GimpPixelRgn pixel_rgn; + GimpImageType image_type; + + ckey.is = 0; + ckey.R = 0; + ckey.G = 0; + ckey.B = 0; + gimp_progress_init_printf ("Opening '%s'", + gimp_filename_to_utf8 (filename)); + + D (("*** Loading \"%s\"\n", filename)); + fp = g_fopen (filename, "rb"); + if (!fp) { - g_set_error(error, G_FILE_ERROR, g_file_error_from_errno(errno), "%s", - g_strerror(errno)); - return -1; + g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno), "%s", + g_strerror (errno)); + return -1; } - /* - * Read common header - */ - nread = fread((void *)&hdr, sizeof(hdr), 1, fp); - if (nread != 1) + /* + * Read common header + */ + nread = fread ((void *) &hdr, sizeof (hdr), 1, fp); + if (nread != 1) { - D(("Error reading file header: %s\n", g_strerror(errno))); - g_set_error(error, G_FILE_ERROR, g_file_error_from_errno(errno), - "Error reading file header: %s\n", g_strerror(errno)); - fclose(fp); - return -1; + D (("Error reading file header: %s\n", g_strerror (errno))); + g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno), + "Error reading file header: %s\n", g_strerror (errno)); + fclose (fp); + return -1; } - hdr.nrows = GUINT32_FROM_LE(hdr.nrows); - hdr.ncols = GUINT32_FROM_LE(hdr.ncols); - hdr.width = GUINT32_FROM_LE(hdr.width); - hdr.height = GUINT32_FROM_LE(hdr.height); - - /* - * Width and height are TOTAL ones - */ - if ((0 == hdr.ncols) || (0 == hdr.nrows) || (hdr.width % hdr.ncols) || - (hdr.height % hdr.nrows)) + hdr.nrows = GUINT32_FROM_LE (hdr.nrows); + hdr.ncols = GUINT32_FROM_LE (hdr.ncols); + hdr.width = GUINT32_FROM_LE (hdr.width); + hdr.height = GUINT32_FROM_LE (hdr.height); + + /* + * Width and height are TOTAL ones + */ + if ((0 == hdr.ncols) || (0 == hdr.nrows) || (hdr.width % hdr.ncols) || + (hdr.height % hdr.nrows)) { - D(("Invalid file geometry: frames: %ux%u, size: %ux%u\n", hdr.ncols, - hdr.nrows, hdr.width, hdr.height)); - g_set_error(error, 0, 0, - "Invalid file geometry: frames: %ux%u, size: %ux%u\n", - hdr.ncols, hdr.nrows, hdr.width, hdr.height); - fclose(fp); - return -1; + D (("Invalid file geometry: frames: %ux%u, size: %ux%u\n", hdr.ncols, + hdr.nrows, hdr.width, hdr.height)); + g_set_error (error, 0, 0, + "Invalid file geometry: frames: %ux%u, size: %ux%u\n", + hdr.ncols, hdr.nrows, hdr.width, hdr.height); + fclose (fp); + return -1; } - width = hdr.width / hdr.ncols; - height = hdr.height / hdr.nrows; + width = hdr.width / hdr.ncols; + height = hdr.height / hdr.nrows; - src_size = width * height; - switch (hdr.fmt) + src_size = width * height; + switch (hdr.fmt) { - case FMT_RGB565: - src_size *= 2; - image_type = GIMP_RGB_IMAGE; - break; - case FMT_RGB: - src_size *= 3; - image_type = GIMP_RGB_IMAGE; - /* - * Read color key - */ - nread = fread((void *)&ckey, sizeof(ckey), 1, fp); - if (nread != 1) - { - D(("Error reading color key: %s\n", g_strerror(errno))); - g_set_error(error, G_FILE_ERROR, g_file_error_from_errno(errno), - "Error reading color key: %s\n", g_strerror(errno)); - fclose(fp); - return -1; - } - if (ckey.is != 0) - ckey.is = 1; /* Normalize */ - - break; - case FMT_RGBA: - src_size *= 4; /* Alpha only for RGBA */ - image_type = GIMP_RGBA_IMAGE; - break; - default: - D(("Invalid file format: %1u\n", hdr.fmt)); - g_set_error(error, 0, 0, "Invalid file format: %1u\n", hdr.fmt); - fclose(fp); + case FMT_RGB565: + src_size *= 2; + image_type = GIMP_RGB_IMAGE; + break; + case FMT_RGB: + src_size *= 3; + image_type = GIMP_RGB_IMAGE; + /* + * Read color key + */ + nread = fread ((void *) &ckey, sizeof (ckey), 1, fp); + if (nread != 1) + { + D (("Error reading color key: %s\n", g_strerror (errno))); + g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno), + "Error reading color key: %s\n", g_strerror (errno)); + fclose (fp); return -1; + } + if (ckey.is != 0) + ckey.is = 1; /* Normalize */ + + break; + case FMT_RGBA: + src_size *= 4; /* Alpha only for RGBA */ + image_type = GIMP_RGBA_IMAGE; + break; + default: + D (("Invalid file format: %1u\n", hdr.fmt)); + g_set_error (error, 0, 0, "Invalid file format: %1u\n", hdr.fmt); + fclose (fp); + return -1; } - D(("Format: %s (%u), frames: %ux%u, size: %ux%u\n", FMT[hdr.fmt], hdr.fmt, - hdr.ncols, hdr.nrows, hdr.width, hdr.height)); - __DEBUG(if (ckey.is) - D(("Has color key: (%1u, %1u, %1u)\n", ckey.R, ckey.G, ckey.B))); - - /* - * We are ready to make image with layers - */ - image = gimp_image_new(width, height, GIMP_RGB); - gimp_image_set_filename(image, filename); - - frame = 0; - nframes = hdr.nrows * hdr.ncols; - src = g_new(guint8, src_size); - dest = (hdr.fmt == FMT_RGB565) ? g_new(guint8, width * height * 3) : NULL; - for (row = 1; row <= hdr.nrows; row++) + D (("Format: %s (%u), frames: %ux%u, size: %ux%u\n", FMT[hdr.fmt], hdr.fmt, + hdr.ncols, hdr.nrows, hdr.width, hdr.height)); + __DEBUG (if (ckey.is) + D (("Has color key: (%1u, %1u, %1u)\n", ckey.R, ckey.G, ckey.B))); + + /* + * We are ready to make image with layers + */ + image = gimp_image_new (width, height, GIMP_RGB); + gimp_image_set_filename (image, filename); + + frame = 0; + nframes = hdr.nrows * hdr.ncols; + src = g_new (guint8, src_size); + dest = (hdr.fmt == FMT_RGB565) ? g_new (guint8, width * height * 3) : NULL; + for (row = 1; row <= hdr.nrows; row++) { - for (col = 1; col <= hdr.ncols; col++) + for (col = 1; col <= hdr.ncols; col++) { - frame++; - gimp_progress_update((gdouble) frame / (gdouble) nframes); - D(("Reading frame #%u of %u (%ux%u, %u bytes)\n", frame, nframes, - width, height, src_size)); - g_snprintf(buf, sizeof(buf), "#%i", frame); - layer = - gimp_layer_new(image, buf, width, height, image_type, 100, - GIMP_NORMAL_MODE); - gimp_image_add_layer(image, layer, frame - 1); - drawable = gimp_drawable_get(layer); - gimp_pixel_rgn_init(&pixel_rgn, drawable, 0, 0, width, height, TRUE, - FALSE); - - nread = fread((char *)src, src_size, 1, fp); - if (nread != 1) + frame++; + gimp_progress_update ((gdouble) frame / (gdouble) nframes); + D (("Reading frame #%u of %u (%ux%u, %u bytes)\n", frame, nframes, + width, height, src_size)); + g_snprintf (buf, sizeof (buf), "#%i", frame); + layer = + gimp_layer_new (image, buf, width, height, image_type, 100, + GIMP_NORMAL_MODE); + gimp_image_add_layer (image, layer, frame - 1); + drawable = gimp_drawable_get (layer); + gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0, width, height, + TRUE, FALSE); + + nread = fread ((char *) src, src_size, 1, fp); + if (nread != 1) { - D(("Invalid image data\n")); - g_set_error(error, G_FILE_ERROR, g_file_error_from_errno(errno), - "Invalid image data\n"); - - if (dest) - g_free(dest); - g_free(src); - fclose(fp); - return -1; + D (("Invalid image data\n")); + g_set_error (error, G_FILE_ERROR, + g_file_error_from_errno (errno), + "Invalid image data\n"); + + if (dest) + g_free (dest); + g_free (src); + fclose (fp); + return -1; } - if (hdr.fmt == FMT_RGB565) + if (hdr.fmt == FMT_RGB565) { - img_map_rgb565_to_rgb(src, dest, src_size); - gimp_pixel_rgn_set_rect(&pixel_rgn, (const guchar *)dest, 0, 0, - width, height); + img_map_rgb565_to_rgb (src, dest, src_size); + gimp_pixel_rgn_set_rect (&pixel_rgn, (const guchar *) dest, 0, + 0, width, height); } - else + else { - gimp_pixel_rgn_set_rect(&pixel_rgn, (const guchar *)src, 0, 0, - width, height); + gimp_pixel_rgn_set_rect (&pixel_rgn, (const guchar *) src, 0, 0, + width, height); } - gimp_drawable_detach(drawable); + gimp_drawable_detach (drawable); } } - frames = gimp_image_get_layers(image, (gint32 *) & nframes); - if (nframes > 0) + frames = gimp_image_get_layers (image, (gint32 *) & nframes); + if (nframes > 0) { - gimp_image_set_active_layer(image, frames[0]); - g_free(frames); + gimp_image_set_active_layer (image, frames[0]); + g_free (frames); } - if (dest) - g_free(dest); - g_free(src); - fclose(fp); + if (dest) + g_free (dest); + g_free (src); + fclose (fp); - meta->format = hdr.fmt; - meta->ckey = ckey; - gimp_progress_update(1.0); - D(("*** Loaded \"%s\"\n", filename)); + meta->format = hdr.fmt; + meta->ckey = ckey; + gimp_progress_update (1.0); + D (("*** Loaded \"%s\"\n", filename)); - return image; + return image; } @@ -1,5 +1,5 @@ #ifndef __IMG_LOAD_H__ -# define __IMG_LOAD_H__ +#define __IMG_LOAD_H__ -gint32 img_load_image(const gchar *, ImageParasite *, GError **); +gint32 img_load_image (const gchar *, ImageParasite *, GError **); #endif diff --git a/img-save-dialog.c b/img-save-dialog.c index ce7c3ef..f5335a2 100644 --- a/img-save-dialog.c +++ b/img-save-dialog.c @@ -2,215 +2,217 @@ #include <libgimp/gimpui.h> static GtkWidget *fmt_frame, *ckey_frame, *fmt_vbox, *ckey_vbox, *ckey_align, - *fmt_align, *hbox, *fmt_rgb565, *fmt_rgb, *fmt_rgba, *ckey_image, *ckey_use, - *gimp_color; + *fmt_align, *hbox, *fmt_rgb565, *fmt_rgb, *fmt_rgba, *ckey_image, *ckey_use, + *gimp_color; static GimpRGB color; static GdkPixbuf *pixbuf; static GtkWidget * -img_preview_new(gint32 image_ID) +img_preview_new (gint32 image_ID) { - GtkWidget *image, *event_box, *align; - guint32 width, height; - gint *frames, nframes, layer; + GtkWidget *image, *event_box, *align; + guint32 width, height; + gint *frames, nframes, layer; - frames = gimp_image_get_layers(image_ID, &nframes); - layer = frames[g_random_int() % nframes]; - g_free(frames); - width = gimp_drawable_width(layer); - height = gimp_drawable_height(layer); + frames = gimp_image_get_layers (image_ID, &nframes); + layer = frames[g_random_int () % nframes]; + g_free (frames); + width = gimp_drawable_width (layer); + height = gimp_drawable_height (layer); - pixbuf = - gimp_drawable_get_thumbnail(layer, MIN(width, 128), MIN(height, 128), - GIMP_PIXBUF_SMALL_CHECKS); + pixbuf = + gimp_drawable_get_thumbnail (layer, MIN (width, 128), MIN (height, 128), + GIMP_PIXBUF_SMALL_CHECKS); - image = gtk_image_new_from_pixbuf(pixbuf); - g_object_unref(pixbuf); + image = gtk_image_new_from_pixbuf (pixbuf); + g_object_unref (pixbuf); - event_box = gtk_event_box_new(); - gtk_widget_set_events(event_box, GDK_ALL_EVENTS_MASK); + event_box = gtk_event_box_new (); + gtk_widget_set_events (event_box, GDK_ALL_EVENTS_MASK); - align = gtk_alignment_new(0.5, 0.5, 0, 0); + align = gtk_alignment_new (0.5, 0.5, 0, 0); - gtk_widget_show(image); - gtk_widget_show(event_box); - gtk_container_add(GTK_CONTAINER(event_box), image); - gtk_container_add(GTK_CONTAINER(align), event_box); + gtk_widget_show (image); + gtk_widget_show (event_box); + gtk_container_add (GTK_CONTAINER (event_box), image); + gtk_container_add (GTK_CONTAINER (align), event_box); - return align; + return align; } static void -on_RGB(GtkWidget * widget, gpointer data) +on_RGB (GtkWidget * widget, gpointer data) { - gtk_widget_set_sensitive(ckey_vbox, - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON + gtk_widget_set_sensitive (ckey_vbox, + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fmt_rgb)) || - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fmt_rgba))); } static void -on_ckey_use(GtkWidget * widget, gpointer data) +on_ckey_use (GtkWidget * widget, gpointer data) { - gboolean active; + gboolean active; - active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); - gtk_widget_set_sensitive(ckey_image, active); - gtk_widget_set_sensitive(gimp_color, active); + active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); + gtk_widget_set_sensitive (ckey_image, active); + gtk_widget_set_sensitive (gimp_color, active); } static gboolean -on_image_click(GtkWidget * widget, GdkEventButton * event, gpointer data) +on_image_click (GtkWidget * widget, GdkEventButton * event, gpointer data) { - int width, height, rowstride, n_channels; - guchar *pixels, *p; - - n_channels = gdk_pixbuf_get_n_channels(pixbuf); - width = gdk_pixbuf_get_width(pixbuf); - height = gdk_pixbuf_get_height(pixbuf); - rowstride = gdk_pixbuf_get_rowstride(pixbuf); - pixels = gdk_pixbuf_get_pixels(pixbuf); - p = pixels + (int)(event->y * rowstride) + (int)(event->x * n_channels); - gimp_rgb_set_uchar(&color, p[0], p[1], p[2]); - gimp_color_button_set_color((GimpColorButton *) gimp_color, &color); - return TRUE; + int width, height, rowstride, n_channels; + guchar *pixels, *p; + + n_channels = gdk_pixbuf_get_n_channels (pixbuf); + width = gdk_pixbuf_get_width (pixbuf); + height = gdk_pixbuf_get_height (pixbuf); + rowstride = gdk_pixbuf_get_rowstride (pixbuf); + pixels = gdk_pixbuf_get_pixels (pixbuf); + p = pixels + (int) (event->y * rowstride) + (int) (event->x * n_channels); + gimp_rgb_set_uchar (&color, p[0], p[1], p[2]); + gimp_color_button_set_color ((GimpColorButton *) gimp_color, &color); + return TRUE; } gboolean -img_save_dialog(gint32 image, ImageParasite * plugin) +img_save_dialog (gint32 image, ImageParasite * plugin) { - GtkWidget *dialog; - gint response; - - gimp_ui_init(PLUG_IN_BINARY, TRUE); - dialog = - gimp_dialog_new("Save as IMG", PLUG_IN_BINARY, NULL, 0, - gimp_standard_help_func, "plug-in-img", - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, - GTK_RESPONSE_OK, NULL); - gimp_window_set_transient(GTK_WINDOW(dialog)); - gtk_widget_show(dialog); - - /* - * Radio buttons to select file format - */ - fmt_frame = gimp_frame_new("Image format"); - fmt_rgb565 = gtk_radio_button_new_with_label(NULL, FMT[FMT_RGB565]); - fmt_rgb = - gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON - (fmt_rgb565), FMT[FMT_RGB]); - fmt_rgba = - gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(fmt_rgb), - FMT[FMT_RGBA]); - gtk_widget_show(fmt_frame); - gtk_widget_show(fmt_rgb565); - gtk_widget_show(fmt_rgb); - gtk_widget_show(fmt_rgba); - - /* - * Horizontal main box - */ - hbox = gtk_hbox_new(TRUE, 2); - gtk_widget_show(hbox); - - /* - * Vertical box for radio buttons - */ - fmt_align = gtk_alignment_new(0.5, 0, 0, 0); - gtk_widget_show(fmt_align); - fmt_vbox = gtk_vbox_new(TRUE, 12); - gtk_container_add(GTK_CONTAINER(fmt_align), fmt_vbox); - gtk_container_set_border_width(GTK_CONTAINER(fmt_vbox), 12); - gtk_widget_show(fmt_vbox); - gtk_box_pack_start(GTK_BOX(fmt_vbox), fmt_frame, TRUE, TRUE, 0); - gtk_box_pack_start(GTK_BOX(fmt_vbox), fmt_rgb565, TRUE, TRUE, 0); - gtk_box_pack_start(GTK_BOX(fmt_vbox), fmt_rgb, TRUE, TRUE, 0); - gtk_box_pack_start(GTK_BOX(fmt_vbox), fmt_rgba, TRUE, TRUE, 0); - - /* - * Allow color key for RGB and RGBA - */ - g_signal_connect(G_OBJECT(fmt_rgb), "clicked", G_CALLBACK(on_RGB), NULL); - g_signal_connect(G_OBJECT(fmt_rgba), "clicked", G_CALLBACK(on_RGB), NULL); - - /* - * Vertical box for color key - */ - ckey_align = gtk_alignment_new(0.5, 0, 0, 0); - gtk_widget_show(ckey_align); - ckey_vbox = gtk_vbox_new(FALSE, 2); - gtk_container_add(GTK_CONTAINER(ckey_align), ckey_vbox); - gtk_container_set_border_width(GTK_CONTAINER(ckey_vbox), 12); - ckey_frame = gimp_frame_new("Transparent color"); - ckey_use = gtk_check_button_new_with_label("Set transparent color"); - ckey_image = img_preview_new(image); - gimp_rgb_set_uchar(&color, plugin->ckey.R, plugin->ckey.G, plugin->ckey.B); - gimp_color = - gimp_color_button_new("Choose color", 64, 64, &color, - GIMP_COLOR_AREA_FLAT); - gtk_box_pack_start(GTK_BOX(ckey_vbox), ckey_frame, TRUE, TRUE, 0); - gtk_box_pack_start(GTK_BOX(ckey_vbox), ckey_use, TRUE, TRUE, 0); - gtk_box_pack_start(GTK_BOX(ckey_vbox), ckey_image, TRUE, TRUE, 0); - gtk_box_pack_start(GTK_BOX(ckey_vbox), gimp_color, TRUE, TRUE, 0); - gtk_widget_show(gimp_color); - gtk_widget_show(ckey_vbox); - gtk_widget_show(ckey_frame); - gtk_widget_show(ckey_use); - gtk_widget_show(ckey_image); - g_signal_connect(G_OBJECT(ckey_use), "clicked", G_CALLBACK(on_ckey_use), - NULL); - g_signal_connect(G_OBJECT(ckey_image), "button-press-event", - G_CALLBACK(on_image_click), NULL); - /* - * Assemble all together - */ - gtk_box_pack_start(GTK_BOX(hbox), fmt_align, TRUE, TRUE, 0); - gtk_box_pack_start(GTK_BOX(hbox), ckey_align, TRUE, TRUE, 0); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, TRUE, TRUE, 0); - - /* - * Set initial parameters - */ - switch (plugin->format) + GtkWidget *dialog; + gint response; + + gimp_ui_init (PLUG_IN_BINARY, TRUE); + dialog = + gimp_dialog_new ("Save as IMG", PLUG_IN_BINARY, NULL, 0, + gimp_standard_help_func, "plug-in-img", + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, + GTK_RESPONSE_OK, NULL); + gimp_window_set_transient (GTK_WINDOW (dialog)); + gtk_widget_show (dialog); + + /* + * Radio buttons to select file format + */ + fmt_frame = gimp_frame_new ("Image format"); + fmt_rgb565 = gtk_radio_button_new_with_label (NULL, FMT[FMT_RGB565]); + fmt_rgb = + gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON + (fmt_rgb565), FMT[FMT_RGB]); + fmt_rgba = + gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (fmt_rgb), + FMT[FMT_RGBA]); + gtk_widget_show (fmt_frame); + gtk_widget_show (fmt_rgb565); + gtk_widget_show (fmt_rgb); + gtk_widget_show (fmt_rgba); + + /* + * Horizontal main box + */ + hbox = gtk_hbox_new (TRUE, 2); + gtk_widget_show (hbox); + + /* + * Vertical box for radio buttons + */ + fmt_align = gtk_alignment_new (0.5, 0, 0, 0); + gtk_widget_show (fmt_align); + fmt_vbox = gtk_vbox_new (TRUE, 12); + gtk_container_add (GTK_CONTAINER (fmt_align), fmt_vbox); + gtk_container_set_border_width (GTK_CONTAINER (fmt_vbox), 12); + gtk_widget_show (fmt_vbox); + gtk_box_pack_start (GTK_BOX (fmt_vbox), fmt_frame, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (fmt_vbox), fmt_rgb565, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (fmt_vbox), fmt_rgb, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (fmt_vbox), fmt_rgba, TRUE, TRUE, 0); + + /* + * Allow color key for RGB and RGBA + */ + g_signal_connect (G_OBJECT (fmt_rgb), "clicked", G_CALLBACK (on_RGB), NULL); + g_signal_connect (G_OBJECT (fmt_rgba), "clicked", G_CALLBACK (on_RGB), + NULL); + + /* + * Vertical box for color key + */ + ckey_align = gtk_alignment_new (0.5, 0, 0, 0); + gtk_widget_show (ckey_align); + ckey_vbox = gtk_vbox_new (FALSE, 2); + gtk_container_add (GTK_CONTAINER (ckey_align), ckey_vbox); + gtk_container_set_border_width (GTK_CONTAINER (ckey_vbox), 12); + ckey_frame = gimp_frame_new ("Transparent color"); + ckey_use = gtk_check_button_new_with_label ("Set transparent color"); + ckey_image = img_preview_new (image); + gimp_rgb_set_uchar (&color, plugin->ckey.R, plugin->ckey.G, plugin->ckey.B); + gimp_color = + gimp_color_button_new ("Choose color", 64, 64, &color, + GIMP_COLOR_AREA_FLAT); + gtk_box_pack_start (GTK_BOX (ckey_vbox), ckey_frame, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (ckey_vbox), ckey_use, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (ckey_vbox), ckey_image, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (ckey_vbox), gimp_color, TRUE, TRUE, 0); + gtk_widget_show (gimp_color); + gtk_widget_show (ckey_vbox); + gtk_widget_show (ckey_frame); + gtk_widget_show (ckey_use); + gtk_widget_show (ckey_image); + g_signal_connect (G_OBJECT (ckey_use), "clicked", G_CALLBACK (on_ckey_use), + NULL); + g_signal_connect (G_OBJECT (ckey_image), "button-press-event", + G_CALLBACK (on_image_click), NULL); + /* + * Assemble all together + */ + gtk_box_pack_start (GTK_BOX (hbox), fmt_align, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (hbox), ckey_align, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, TRUE, TRUE, + 0); + + /* + * Set initial parameters + */ + switch (plugin->format) { - case FMT_RGB565: - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fmt_rgb565), TRUE); - break; - case FMT_RGB: - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fmt_rgb), TRUE); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ckey_use), - plugin->ckey.is != 0); - break; - case FMT_RGBA: - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fmt_rgba), TRUE); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ckey_use), - plugin->ckey.is != 0); - break; + case FMT_RGB565: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fmt_rgb565), TRUE); + break; + case FMT_RGB: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fmt_rgb), TRUE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ckey_use), + plugin->ckey.is != 0); + break; + case FMT_RGBA: + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fmt_rgba), TRUE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ckey_use), + plugin->ckey.is != 0); + break; } - on_RGB(fmt_rgb, NULL); - on_ckey_use(ckey_use, NULL); - - /* - * Run the dialog - */ - response = gimp_dialog_run(GIMP_DIALOG(dialog)); - - /* - * Get new parameters - */ - if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(fmt_rgb565))) - plugin->format = FMT_RGB565; - else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(fmt_rgb))) - plugin->format = FMT_RGB; - else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(fmt_rgba))) - plugin->format = FMT_RGBA; - plugin->ckey.is = - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ckey_use)) ? 1 : 0; - gimp_color_button_get_color((GimpColorButton *) gimp_color, &color); - gimp_rgb_get_uchar(&color, &plugin->ckey.R, &plugin->ckey.G, - &plugin->ckey.B); - gtk_widget_destroy(dialog); - return (response == GTK_RESPONSE_OK); + on_RGB (fmt_rgb, NULL); + on_ckey_use (ckey_use, NULL); + + /* + * Run the dialog + */ + response = gimp_dialog_run (GIMP_DIALOG (dialog)); + + /* + * Get new parameters + */ + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fmt_rgb565))) + plugin->format = FMT_RGB565; + else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fmt_rgb))) + plugin->format = FMT_RGB; + else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fmt_rgba))) + plugin->format = FMT_RGBA; + plugin->ckey.is = + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ckey_use)) ? 1 : 0; + gimp_color_button_get_color ((GimpColorButton *) gimp_color, &color); + gimp_rgb_get_uchar (&color, &plugin->ckey.R, &plugin->ckey.G, + &plugin->ckey.B); + gtk_widget_destroy (dialog); + return (response == GTK_RESPONSE_OK); } diff --git a/img-save-dialog.h b/img-save-dialog.h index 8594943..1e0fcaa 100644 --- a/img-save-dialog.h +++ b/img-save-dialog.h @@ -1,6 +1,6 @@ #ifndef __IMG_SAVE_DIALOG_H -# define __IMG_SAVE_DIALOG_H +#define __IMG_SAVE_DIALOG_H -gboolean img_save_dialog(gint32 image, ImageParasite * plugin); +gboolean img_save_dialog (gint32 image, ImageParasite * plugin); #endif @@ -4,448 +4,447 @@ * Parse strings for format and color key **/ GimpPDBStatusType -img_read_options(ImageParasite * p, const gchar * fmt, const gchar * ckey, - GError ** error) +img_read_options (ImageParasite * p, const gchar * fmt, const gchar * ckey, + GError ** error) { - gdouble r, g, b; - guint32 R, G, B; - - if ((strcmp(fmt, FMT[0]) == 0) || (strcmp(fmt, "0") == 0)) - p->format = FMT_RGB565; - else if ((strcmp(fmt, FMT[1]) == 0) || (strcmp(fmt, "1") == 0)) - p->format = FMT_RGB; - else if ((strcmp(fmt, FMT[2]) == 0) || (strcmp(fmt, "2") == 0)) - p->format = FMT_RGBA; - else + gdouble r, g, b; + guint32 R, G, B; + + if ((strcmp (fmt, FMT[0]) == 0) || (strcmp (fmt, "0") == 0)) + p->format = FMT_RGB565; + else if ((strcmp (fmt, FMT[1]) == 0) || (strcmp (fmt, "1") == 0)) + p->format = FMT_RGB; + else if ((strcmp (fmt, FMT[2]) == 0) || (strcmp (fmt, "2") == 0)) + p->format = FMT_RGBA; + else { - g_set_error(error, 0, 0, "Invalid file format: %s", fmt); - return GIMP_PDB_CALLING_ERROR; + g_set_error (error, 0, 0, "Invalid file format: %s", fmt); + return GIMP_PDB_CALLING_ERROR; } - if (NULL == ckey) + if (NULL == ckey) { - p->ckey.is = 0; - p->ckey.R = 0; - p->ckey.G = 0; - p->ckey.B = 0; + p->ckey.is = 0; + p->ckey.R = 0; + p->ckey.G = 0; + p->ckey.B = 0; } - else + else { - if ((strcmp(ckey, "") == 0) || (strcmp(ckey, "0") == 0) || - (strcmp(ckey, "no") == 0)) + if ((strcmp (ckey, "") == 0) || (strcmp (ckey, "0") == 0) || + (strcmp (ckey, "no") == 0)) { - p->ckey.is = 0; + p->ckey.is = 0; } - else if (3 == sscanf(ckey, "(%u, %u, %u)", &R, &G, &B)) + else if (3 == sscanf (ckey, "(%u, %u, %u)", &R, &G, &B)) { - if ((R < 256) && (G < 256) && (B < 256)) + if ((R < 256) && (G < 256) && (B < 256)) { - p->ckey.is = 1; - p->ckey.R = R; - p->ckey.G = G; - p->ckey.B = B; + p->ckey.is = 1; + p->ckey.R = R; + p->ckey.G = G; + p->ckey.B = B; } - else + else { - g_set_error(error, 0, 0, - "Invalid color key: %s; all values must be < 256", - ckey); - return GIMP_PDB_CALLING_ERROR; + g_set_error (error, 0, 0, + "Invalid color key: %s; all values must be < 256", + ckey); + return GIMP_PDB_CALLING_ERROR; } } - else if (3 == sscanf(ckey, "(%lf; %lf; %lf)", &r, &g, &b)) + else if (3 == sscanf (ckey, "(%lf; %lf; %lf)", &r, &g, &b)) { - if ((r <= 1.0) && (g <= 1.0) && (b <= 1.0) && (r >= 0.0) && - (g >= 0.0) && (b >= 0.0)) + if ((r <= 1.0) && (g <= 1.0) && (b <= 1.0) && (r >= 0.0) && + (g >= 0.0) && (b >= 0.0)) { - p->ckey.is = 1; - p->ckey.R = (guint8) (r * 255); - p->ckey.G = (guint8) (g * 255); - p->ckey.B = (guint8) (b * 255); + p->ckey.is = 1; + p->ckey.R = (guint8) (r * 255); + p->ckey.G = (guint8) (g * 255); + p->ckey.B = (guint8) (b * 255); } - else + else { - g_set_error(error, 0, 0, - "Invalid color key: %s; example: (0.1; 0.7; 0.3), all values must be in [0; 1]", - ckey); - return GIMP_PDB_CALLING_ERROR; + g_set_error (error, 0, 0, + "Invalid color key: %s; example: (0.1; 0.7; 0.3), all values must be in [0; 1]", + ckey); + return GIMP_PDB_CALLING_ERROR; } } - else if (1 == sscanf(ckey, "0x%x", &R)) + else if (1 == sscanf (ckey, "0x%x", &R)) { - size_t l; + size_t l; - l = strlen(ckey); - if (5 == l) /* e. g. 0xAF9, but not 0xAAA6 */ + l = strlen (ckey); + if (5 == l) /* e. g. 0xAF9, but not 0xAAA6 */ { - p->ckey.is = 1; - G = R & 0x000F00; - p->ckey.R = (guint8) ((G >> 4) | (G >> 8)); /* Red */ - G = R & 0x0000F0; - p->ckey.G = (guint8) (G | (G >> 4)); /* Green */ - G = R & 0x00000F; - p->ckey.B = (guint8) ((G << 4) | G); /* Blue */ + p->ckey.is = 1; + G = R & 0x000F00; + p->ckey.R = (guint8) ((G >> 4) | (G >> 8)); /* Red */ + G = R & 0x0000F0; + p->ckey.G = (guint8) (G | (G >> 4)); /* Green */ + G = R & 0x00000F; + p->ckey.B = (guint8) ((G << 4) | G); /* Blue */ } - else if (8 == l) /* e. g. 0xFFAA99 */ + else if (8 == l) /* e. g. 0xFFAA99 */ { - p->ckey.is = 1; - p->ckey.R = (guint8) ((R & 0xFF0000) >> 16); /* Red */ - p->ckey.G = (guint8) ((R & 0x00FF00) >> 8); /* Green */ - p->ckey.B = (guint8) (R & 0x0000FF); /* Blue */ + p->ckey.is = 1; + p->ckey.R = (guint8) ((R & 0xFF0000) >> 16); /* Red */ + p->ckey.G = (guint8) ((R & 0x00FF00) >> 8); /* Green */ + p->ckey.B = (guint8) (R & 0x0000FF); /* Blue */ } - else + else { - g_set_error(error, 0, 0, - "Hex color key %s is invalid; examples are 0xFFF or 0xFF44GG", - ckey); - return GIMP_PDB_CALLING_ERROR; + g_set_error (error, 0, 0, + "Hex color key %s is invalid; examples are 0xFFF or 0xFF44GG", + ckey); + return GIMP_PDB_CALLING_ERROR; } } - else + else { - g_set_error(error, 0, 0, "Invalid color key: %s", ckey); - return GIMP_PDB_CALLING_ERROR; + g_set_error (error, 0, 0, "Invalid color key: %s", ckey); + return GIMP_PDB_CALLING_ERROR; } } - D(("Parsed format: %s (%1u)\n", FMT[p->format], p->format)); - D(("Parsed color key: %s (%1u, %1u, %1u)\n", (p->ckey.is) ? "yes" : "no", - p->ckey.R, p->ckey.G, p->ckey.B)); - return GIMP_PDB_SUCCESS; + D (("Parsed format: %s (%1u)\n", FMT[p->format], p->format)); + D (("Parsed color key: %s (%1u, %1u, %1u)\n", (p->ckey.is) ? "yes" : "no", + p->ckey.R, p->ckey.G, p->ckey.B)); + return GIMP_PDB_SUCCESS; } static inline void -rgb_to_rgb565(const guint8 * c, guint16 * res) +rgb_to_rgb565 (const guint8 * c, guint16 * res) { - /* - * How to: - * | 24 bits | - * | B || G || R | - * 11111xxx000000xx11111xxx - * | B | | G | | R | - * 11111 000000 11111 - * | high || low | - * | 16 bits | - * - */ - (*res) = 0; - (*res) |= ((guint16) (c[0]) >> 3); /* Red */ - (*res) |= ((guint16) (c[1]) >> 2) << 5; /* Green */ - (*res) |= ((guint16) (c[2]) >> 3) << 11; /* Blue */ + /* + * How to: + * | 24 bits | + * | B || G || R | + * 11111xxx000000xx11111xxx + * | B | | G | | R | + * 11111 000000 11111 + * | high || low | + * | 16 bits | + * + */ + (*res) = 0; + (*res) |= ((guint16) (c[0]) >> 3); /* Red */ + (*res) |= ((guint16) (c[1]) >> 2) << 5; /* Green */ + (*res) |= ((guint16) (c[2]) >> 3) << 11; /* Blue */ } static void -img_map_gimp_to_file(GimpImageType image_type, guint8 fmt, - const ColorKey * ckey, guint8 * src, guint8 * dest, - size_t npixels) +img_map_gimp_to_file (GimpImageType image_type, guint8 fmt, + const ColorKey * ckey, guint8 * src, guint8 * dest, + size_t npixels) { - size_t s, d; - guint8 r, g, b; + size_t s, d; + guint8 r, g, b; - switch (image_type) + switch (image_type) { - case GIMP_RGB_IMAGE: - npixels *= 3; - switch (fmt) - { - case FMT_RGB565: /* RGB -> RGB565 */ - for (s = 0, d = 0; s < npixels;) - { - rgb_to_rgb565(&(src[s]), (guint16 *) & (dest[d])); - d += 2; - s += 3; - } - break; - - case FMT_RGB: /* RGB -> RGB */ - memcpy(dest, src, npixels); - break; - - case FMT_RGBA: /* RGB -> RGBA */ - if (ckey->is == 0) - for (s = 0, d = 0; s < npixels;) - { - dest[d++] = src[s++]; /* Red */ - dest[d++] = src[s++]; /* Green */ - dest[d++] = src[s++]; /* Blue */ - dest[d++] = 255; /* Opaque */ - } - else /* Color key to Alpha */ - for (s = 0, d = 0; s < npixels;) - { - r = dest[d++] = src[s++]; /* Red */ - g = dest[d++] = src[s++]; /* Green */ - b = dest[d++] = src[s++]; /* Blue */ - if ((r == ckey->R) && (g == ckey->G) && (b == ckey->B)) - dest[d++] = 0; /* Transparent */ - else - dest[d++] = 255; /* Opaque */ - } - break; - - default: - break; - } + case GIMP_RGB_IMAGE: + npixels *= 3; + switch (fmt) + { + case FMT_RGB565: /* RGB -> RGB565 */ + for (s = 0, d = 0; s < npixels;) + { + rgb_to_rgb565 (&(src[s]), (guint16 *) & (dest[d])); + d += 2; + s += 3; + } + break; + + case FMT_RGB: /* RGB -> RGB */ + memcpy (dest, src, npixels); + break; + + case FMT_RGBA: /* RGB -> RGBA */ + if (ckey->is == 0) + for (s = 0, d = 0; s < npixels;) + { + dest[d++] = src[s++]; /* Red */ + dest[d++] = src[s++]; /* Green */ + dest[d++] = src[s++]; /* Blue */ + dest[d++] = 255; /* Opaque */ + } + else /* Color key to Alpha */ + for (s = 0, d = 0; s < npixels;) + { + r = dest[d++] = src[s++]; /* Red */ + g = dest[d++] = src[s++]; /* Green */ + b = dest[d++] = src[s++]; /* Blue */ + if ((r == ckey->R) && (g == ckey->G) && (b == ckey->B)) + dest[d++] = 0; /* Transparent */ + else + dest[d++] = 255; /* Opaque */ + } break; - case GIMP_RGBA_IMAGE: - npixels *= 4; - switch (fmt) - { - case FMT_RGB565: /* RGBA -> RGB565 */ - for (s = 0, d = 0; s < npixels;) - { - rgb_to_rgb565(&(src[s]), (guint16 *) & (dest[d])); - d += 2; - s += 4; /* Skip Alpha */ - } - break; - - case FMT_RGB: /* RGBA -> RGB */ - for (s = 0, d = 0; s < npixels;) - { - dest[d++] = src[s++]; /* Red */ - dest[d++] = src[s++]; /* Green */ - dest[d++] = src[s++]; /* Blue */ - s++; /* Skip Alpha */ - } - break; - - case FMT_RGBA: /* RGBA -> RGBA */ - memcpy(dest, src, npixels); - break; - - default: - break; - } + default: break; + } + break; - default: + case GIMP_RGBA_IMAGE: + npixels *= 4; + switch (fmt) + { + case FMT_RGB565: /* RGBA -> RGB565 */ + for (s = 0, d = 0; s < npixels;) + { + rgb_to_rgb565 (&(src[s]), (guint16 *) & (dest[d])); + d += 2; + s += 4; /* Skip Alpha */ + } + break; + + case FMT_RGB: /* RGBA -> RGB */ + for (s = 0, d = 0; s < npixels;) + { + dest[d++] = src[s++]; /* Red */ + dest[d++] = src[s++]; /* Green */ + dest[d++] = src[s++]; /* Blue */ + s++; /* Skip Alpha */ + } break; + + case FMT_RGBA: /* RGBA -> RGBA */ + memcpy (dest, src, npixels); + break; + + default: + break; + } + break; + + default: + break; } } GimpPDBStatusType -img_sanity_check(gint32 image_ID, GError ** error) +img_sanity_check (gint32 image_ID, GError ** error) { - gint32 *layers; - gint nlayers; - gint image_width; - gint image_height; - gint i; - GimpPDBStatusType status = GIMP_PDB_SUCCESS; - - if (gimp_image_base_type(image_ID) != GIMP_RGB) + gint32 *layers; + gint nlayers; + gint image_width; + gint image_height; + gint i; + GimpPDBStatusType status = GIMP_PDB_SUCCESS; + + if (gimp_image_base_type (image_ID) != GIMP_RGB) { - g_set_error(error, 0, 0, "Can save only RGB images."); - return GIMP_PDB_EXECUTION_ERROR; + g_set_error (error, 0, 0, "Can save only RGB images."); + return GIMP_PDB_EXECUTION_ERROR; } - layers = gimp_image_get_layers(image_ID, &nlayers); - if (nlayers == 0) + layers = gimp_image_get_layers (image_ID, &nlayers); + if (nlayers == 0) { - g_set_error(error, 0, 0, "Can't save empty images ;-)"); - return GIMP_PDB_EXECUTION_ERROR; + g_set_error (error, 0, 0, "Can't save empty images ;-)"); + return GIMP_PDB_EXECUTION_ERROR; } - image_width = gimp_image_width(image_ID); - image_height = gimp_image_height(image_ID); + image_width = gimp_image_width (image_ID); + image_height = gimp_image_height (image_ID); - for (i = 0; i < nlayers; i++) + for (i = 0; i < nlayers; i++) { - if ((gimp_drawable_width(layers[i]) != image_width) || - (gimp_drawable_height(layers[i]) != image_height)) + if ((gimp_drawable_width (layers[i]) != image_width) || + (gimp_drawable_height (layers[i]) != image_height)) { - g_set_error(error, 0, 0, - "All layers must exactly match width and height of image."); - status = GIMP_PDB_EXECUTION_ERROR; - break; + g_set_error (error, 0, 0, + "All layers must exactly match width and height of image."); + status = GIMP_PDB_EXECUTION_ERROR; + break; } } - g_free(layers); - return status; + g_free (layers); + return status; } GimpPDBStatusType -img_save_image(gint32 image, const ImageParasite * plugin, - const gchar * filename, GError ** error) +img_save_image (gint32 image, const ImageParasite * plugin, + const gchar * filename, GError ** error) { - FILE *fp; - GimpPixelRgn pixel_rgn; - GimpDrawable *drawable = NULL; - gint *layers = NULL, nlayers; - size_t nwritten; - guint8 *data = NULL, *pixels = NULL; - size_t data_size, npixels; - gint i, width, height; - FileHeader hdr; + FILE *fp; + GimpPixelRgn pixel_rgn; + GimpDrawable *drawable = NULL; + gint *layers = NULL, nlayers; + size_t nwritten; + guint8 *data = NULL, *pixels = NULL; + size_t data_size, npixels; + gint i, width, height; + FileHeader hdr; #if 0 - ImageParasite test; - GError *terr = NULL; + ImageParasite test; + GError *terr = NULL; - img_read_options(&test, "RGB", "(23,45,6)", &terr); - if (NULL != terr) + img_read_options (&test, "RGB", "(23,45,6)", &terr); + if (NULL != terr) { - printf("%s\n", terr->message); - g_error_free(terr); + printf ("%s\n", terr->message); + g_error_free (terr); } - img_read_options(&test, "RGBA", "0x999", &terr); - if (NULL != terr) + img_read_options (&test, "RGBA", "0x999", &terr); + if (NULL != terr) { - printf("%s\n", terr->message); - g_error_free(terr); + printf ("%s\n", terr->message); + g_error_free (terr); } - img_read_options(&test, "0", "0x321", &terr); - if (NULL != terr) + img_read_options (&test, "0", "0x321", &terr); + if (NULL != terr) { - printf("%s\n", terr->message); - g_error_free(terr); + printf ("%s\n", terr->message); + g_error_free (terr); } - img_read_options(&test, "2", "0xFFFFFF", &terr); - if (NULL != terr) + img_read_options (&test, "2", "0xFFFFFF", &terr); + if (NULL != terr) { - printf("%s\n", terr->message); - g_error_free(terr); + printf ("%s\n", terr->message); + g_error_free (terr); } - img_read_options(&test, "RGB", "(0,1;0,7;0,346)", &terr); - if (NULL != terr) + img_read_options (&test, "RGB", "(0,1;0,7;0,346)", &terr); + if (NULL != terr) { - printf("%s\n", terr->message); - g_error_free(terr); + printf ("%s\n", terr->message); + g_error_free (terr); } #endif - /* - * Should call sanity_check() for all secure checks - */ - - layers = gimp_image_get_layers(image, &nlayers); - width = gimp_image_width(image); - height = gimp_image_height(image); - npixels = width * height; - - /* - * Making file header - */ - hdr.fmt = plugin->format; - hdr.ncols = 1; /* Always one column */ - hdr.nrows = nlayers; - hdr.width = width * hdr.ncols; - hdr.height = height * hdr.nrows; - - hdr.nrows = GUINT32_TO_LE(hdr.nrows); - hdr.ncols = GUINT32_TO_LE(hdr.ncols); - hdr.width = GUINT32_TO_LE(hdr.width); - hdr.height = GUINT32_TO_LE(hdr.height); - - D(("*** Saving \"%s\"\n", filename)); - - gimp_progress_init_printf("Saving '%s'", gimp_filename_to_utf8(filename)); - - if (!(fp = g_fopen(filename, "wb"))) + /* + * Should call sanity_check() for all secure checks + */ + + layers = gimp_image_get_layers (image, &nlayers); + width = gimp_image_width (image); + height = gimp_image_height (image); + npixels = width * height; + + /* + * Making file header + */ + hdr.fmt = plugin->format; + hdr.ncols = 1; /* Always one column */ + hdr.nrows = nlayers; + hdr.width = width * hdr.ncols; + hdr.height = height * hdr.nrows; + + hdr.nrows = GUINT32_TO_LE (hdr.nrows); + hdr.ncols = GUINT32_TO_LE (hdr.ncols); + hdr.width = GUINT32_TO_LE (hdr.width); + hdr.height = GUINT32_TO_LE (hdr.height); + + D (("*** Saving \"%s\"\n", filename)); + + gimp_progress_init_printf ("Saving '%s'", gimp_filename_to_utf8 (filename)); + + if (!(fp = g_fopen (filename, "wb"))) { - g_set_error(error, G_FILE_ERROR, g_file_error_from_errno(errno), - "Could not open '%s' for writing: %s", - gimp_filename_to_utf8(filename), g_strerror(errno)); - g_free(layers); - return GIMP_PDB_EXECUTION_ERROR; + g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno), + "Could not open '%s' for writing: %s", + gimp_filename_to_utf8 (filename), g_strerror (errno)); + g_free (layers); + return GIMP_PDB_EXECUTION_ERROR; } - /* - * Write file - */ - D(("Writing header: format: %s (%1u), frames: %ux%u, size: %ux%u\n", - FMT[hdr.fmt], hdr.fmt, hdr.ncols, hdr.nrows, hdr.width, hdr.height)); - nwritten = fwrite((const void *)&hdr, sizeof(hdr), 1, fp); - if (nwritten != 1) + /* + * Write file + */ + D (("Writing header: format: %s (%1u), frames: %ux%u, size: %ux%u\n", + FMT[hdr.fmt], hdr.fmt, hdr.ncols, hdr.nrows, hdr.width, hdr.height)); + nwritten = fwrite ((const void *) &hdr, sizeof (hdr), 1, fp); + if (nwritten != 1) { - D(("Error: %s\n", g_strerror(errno))); - g_set_error(error, G_FILE_ERROR, g_file_error_from_errno(errno), - "Writing file header: %s\n", g_strerror(errno)); - fclose(fp); - g_free(layers); - return GIMP_PDB_EXECUTION_ERROR; + D (("Error: %s\n", g_strerror (errno))); + g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno), + "Writing file header: %s\n", g_strerror (errno)); + fclose (fp); + g_free (layers); + return GIMP_PDB_EXECUTION_ERROR; } - /* - * File format specific preparations - */ - data_size = width * height; - switch (hdr.fmt) + /* + * File format specific preparations + */ + data_size = width * height; + switch (hdr.fmt) { - case FMT_RGB565: - data_size *= 2; - break; - - case FMT_RGB: - D(("Writing color key: %s (%1u, %1u, %1u)\n", - (plugin->ckey.is) ? "yes" : "no", plugin->ckey.R, plugin->ckey.G, - plugin->ckey.B)); - nwritten = - fwrite((const void *)&(plugin->ckey), sizeof(plugin->ckey), 1, - fp); - if (nwritten != 1) - { - D(("Error: %s\n", g_strerror(errno))); - g_set_error(error, G_FILE_ERROR, g_file_error_from_errno(errno), - "Writing color key: %s\n", g_strerror(errno)); - fclose(fp); - g_free(layers); - return GIMP_PDB_EXECUTION_ERROR; - } - data_size *= 3; - break; - - case FMT_RGBA: - __DEBUG(if (plugin->ckey.is) - D(("Will convert color key " - "(%1u, %1u, %1u) to full transparent\n", plugin->ckey.R, - plugin->ckey.G, plugin->ckey.B));); - data_size *= 4; - break; + case FMT_RGB565: + data_size *= 2; + break; + + case FMT_RGB: + D (("Writing color key: %s (%1u, %1u, %1u)\n", + (plugin->ckey.is) ? "yes" : "no", plugin->ckey.R, plugin->ckey.G, + plugin->ckey.B)); + nwritten = + fwrite ((const void *) &(plugin->ckey), sizeof (plugin->ckey), 1, fp); + if (nwritten != 1) + { + D (("Error: %s\n", g_strerror (errno))); + g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno), + "Writing color key: %s\n", g_strerror (errno)); + fclose (fp); + g_free (layers); + return GIMP_PDB_EXECUTION_ERROR; + } + data_size *= 3; + break; + + case FMT_RGBA: + __DEBUG (if (plugin->ckey.is) + D (("Will convert color key " + "(%1u, %1u, %1u) to full transparent\n", plugin->ckey.R, + plugin->ckey.G, plugin->ckey.B));); + data_size *= 4; + break; } - /* - * Writing each layer (frame) - */ - data = g_new(guint8, data_size); - pixels = g_new(guint8, npixels * 4); /* Enough for RGB or RGBA */ - for (i = 0; i < nlayers; i++) + /* + * Writing each layer (frame) + */ + data = g_new (guint8, data_size); + pixels = g_new (guint8, npixels * 4); /* Enough for RGB or RGBA */ + for (i = 0; i < nlayers; i++) { - gimp_progress_update((gdouble) i / (gdouble) nlayers); - drawable = gimp_drawable_get(layers[i]); - gimp_pixel_rgn_init(&pixel_rgn, drawable, 0, 0, width, height, FALSE, - FALSE); - gimp_pixel_rgn_get_rect(&pixel_rgn, (guchar *) pixels, 0, 0, width, - height); - D(("Writing frame #%u of %u (%u bytes)\n", i + 1, nlayers, data_size)); - /* - * Allow different image type for different layers - */ - img_map_gimp_to_file(gimp_drawable_type(layers[i]), hdr.fmt, - &(plugin->ckey), pixels, data, npixels); - - nwritten = fwrite((const void *)data, data_size, 1, fp); - if (nwritten != 1) + gimp_progress_update ((gdouble) i / (gdouble) nlayers); + drawable = gimp_drawable_get (layers[i]); + gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0, width, height, FALSE, + FALSE); + gimp_pixel_rgn_get_rect (&pixel_rgn, (guchar *) pixels, 0, 0, width, + height); + D (("Writing frame #%u of %u (%u bytes)\n", i + 1, nlayers, data_size)); + /* + * Allow different image type for different layers + */ + img_map_gimp_to_file (gimp_drawable_type (layers[i]), hdr.fmt, + &(plugin->ckey), pixels, data, npixels); + + nwritten = fwrite ((const void *) data, data_size, 1, fp); + if (nwritten != 1) { - D(("Error: %s\n", g_strerror(errno))); - g_set_error(error, G_FILE_ERROR, g_file_error_from_errno(errno), - "Writing layer #%u: %s\n", i, g_strerror(errno)); - fclose(fp); - g_free(layers); - g_free(data); - g_free(pixels); - return GIMP_PDB_EXECUTION_ERROR; + D (("Error: %s\n", g_strerror (errno))); + g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno), + "Writing layer #%u: %s\n", i, g_strerror (errno)); + fclose (fp); + g_free (layers); + g_free (data); + g_free (pixels); + return GIMP_PDB_EXECUTION_ERROR; } } - fclose(fp); - g_free(layers); - g_free(data); - g_free(pixels); - gimp_progress_update(1.0); - D(("*** Written \"%s\"\n", filename)); + fclose (fp); + g_free (layers); + g_free (data); + g_free (pixels); + gimp_progress_update (1.0); + D (("*** Written \"%s\"\n", filename)); - return GIMP_PDB_SUCCESS; + return GIMP_PDB_SUCCESS; } @@ -1,12 +1,12 @@ #ifndef __IMG_SAVE_H__ -# define __IMG_SAVE_H__ +#define __IMG_SAVE_H__ -GimpPDBStatusType img_read_options(ImageParasite *, const gchar *, - const gchar *, GError **); +GimpPDBStatusType img_read_options (ImageParasite *, const gchar *, + const gchar *, GError **); -GimpPDBStatusType img_save_image(gint32, const ImageParasite *, const gchar *, - GError **); -gboolean img_save_dialog(gint32, ImageParasite *); +GimpPDBStatusType img_save_image (gint32, const ImageParasite *, + const gchar *, GError **); +gboolean img_save_dialog (gint32, ImageParasite *); -GimpPDBStatusType img_sanity_check(gint32, GError **); +GimpPDBStatusType img_sanity_check (gint32, GError **); #endif diff --git a/plugin-img.c b/plugin-img.c index 7c47d03..b4b19d7 100644 --- a/plugin-img.c +++ b/plugin-img.c @@ -6,245 +6,246 @@ const gchar *FMT[3] = { "RGB565", "RGB", "RGBA" }; static void -img_set_parasite(gint32 image, const ImageParasite * p) +img_set_parasite (gint32 image, const ImageParasite * p) { - D(("Setting parasite for %u: format: %s (%1u), " - "color key: %s (%1u, %1u, %1u)\n", image, FMT[p->format], p->format, - (p->ckey.is) ? "yes" : "no", p->ckey.R, p->ckey.G, p->ckey.B)); - gimp_image_parasite_detach(image, PARASITE_ORIG_FILE); - gimp_image_attach_new_parasite(image, PARASITE_ORIG_FILE, - GIMP_PARASITE_PERSISTENT, - sizeof(ImageParasite), p); + D (("Setting parasite for %u: format: %s (%1u), " + "color key: %s (%1u, %1u, %1u)\n", image, FMT[p->format], p->format, + (p->ckey.is) ? "yes" : "no", p->ckey.R, p->ckey.G, p->ckey.B)); + gimp_image_parasite_detach (image, PARASITE_ORIG_FILE); + gimp_image_attach_new_parasite (image, PARASITE_ORIG_FILE, + GIMP_PARASITE_PERSISTENT, + sizeof (ImageParasite), p); } static void -img_get_parasite(gint32 image, ImageParasite * p) +img_get_parasite (gint32 image, ImageParasite * p) { - GimpParasite *gp = NULL; + GimpParasite *gp = NULL; - gp = gimp_image_parasite_find(image, PARASITE_ORIG_FILE); - if (gp != NULL) + gp = gimp_image_parasite_find (image, PARASITE_ORIG_FILE); + if (gp != NULL) { - p->format = ((ImageParasite *) (gp->data))->format; - p->ckey = ((ImageParasite *) (gp->data))->ckey; - D(("Setting parasite for %u: format: %s (%1u), " - "color key: %s (%1u, %1u, %1u)\n", image, FMT[p->format], p->format, - (p->ckey.is) ? "yes" : "no", p->ckey.R, p->ckey.G, p->ckey.B)); + p->format = ((ImageParasite *) (gp->data))->format; + p->ckey = ((ImageParasite *) (gp->data))->ckey; + D (("Setting parasite for %u: format: %s (%1u), " + "color key: %s (%1u, %1u, %1u)\n", image, FMT[p->format], p->format, + (p->ckey.is) ? "yes" : "no", p->ckey.R, p->ckey.G, p->ckey.B)); - gimp_parasite_free(gp); + gimp_parasite_free (gp); } } static void -query(void) +query (void) { - static const GimpParamDef load_args[] = { - {GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive"}, - {GIMP_PDB_STRING, "filename", "The name of the file to load"}, - {GIMP_PDB_STRING, "raw-filename", "The name entered"} - }; - static const GimpParamDef load_return_vals[] = { - {GIMP_PDB_IMAGE, "image", "Output image"}, - }; - - static const GimpParamDef save_args[] = { - {GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive"}, - {GIMP_PDB_IMAGE, "image", "Input image"}, - {GIMP_PDB_DRAWABLE, "drawable", "Drawable to save"}, - {GIMP_PDB_STRING, "filename", - "The name of the file to save the image in"}, - {GIMP_PDB_STRING, "raw-filename", "The name entered"}, - {GIMP_PDB_STRING, "format", "File format: RGB565 (or 0), RGB (1) or RGBA (2)"}, - {GIMP_PDB_STRING, "ckey", - "Color key, ex.: 0, no, (23,55,56), (0.1;0.5;0.8), 0xFFF, 0xFEFEFE"} - }; - - gimp_install_procedure(LOAD_PROC, "Loads files of IMG file format", - "Loads files of IMG file format", - "Igor Pashev <pashev.igor@gmail.com>", - "Public Domain", "2009", "IMG", NULL, GIMP_PLUGIN, - G_N_ELEMENTS(load_args), - G_N_ELEMENTS(load_return_vals), load_args, - load_return_vals); - - gimp_register_file_handler_mime(LOAD_PROC, IMG_MIME); - gimp_register_magic_load_handler(LOAD_PROC, "img", "", ""); - - gimp_install_procedure(SAVE_PROC, "Saves files in IMG file format", - "Saves files in IMG file format", - "Igor Pashev <pashev.igor@gmail.com>", - "Public Domain", "2009", "IMG", "*", GIMP_PLUGIN, - G_N_ELEMENTS(save_args), 0, save_args, NULL); - - gimp_register_file_handler_mime(SAVE_PROC, IMG_MIME); - gimp_register_save_handler(SAVE_PROC, "img", ""); + static const GimpParamDef load_args[] = { + {GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive"}, + {GIMP_PDB_STRING, "filename", "The name of the file to load"}, + {GIMP_PDB_STRING, "raw-filename", "The name entered"} + }; + static const GimpParamDef load_return_vals[] = { + {GIMP_PDB_IMAGE, "image", "Output image"}, + }; + + static const GimpParamDef save_args[] = { + {GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive"}, + {GIMP_PDB_IMAGE, "image", "Input image"}, + {GIMP_PDB_DRAWABLE, "drawable", "Drawable to save"}, + {GIMP_PDB_STRING, "filename", + "The name of the file to save the image in"}, + {GIMP_PDB_STRING, "raw-filename", "The name entered"}, + {GIMP_PDB_STRING, "format", + "File format: RGB565 (or 0), RGB (1) or RGBA (2)"}, + {GIMP_PDB_STRING, "ckey", + "Color key, ex.: 0, no, (23,55,56), (0.1;0.5;0.8), 0xFFF, 0xFEFEFE"} + }; + + gimp_install_procedure (LOAD_PROC, "Loads files of IMG file format", + "Loads files of IMG file format", + "Igor Pashev <pashev.igor@gmail.com>", + "Public Domain", "2009", "IMG", NULL, GIMP_PLUGIN, + G_N_ELEMENTS (load_args), + G_N_ELEMENTS (load_return_vals), load_args, + load_return_vals); + + gimp_register_file_handler_mime (LOAD_PROC, IMG_MIME); + gimp_register_magic_load_handler (LOAD_PROC, "img", "", ""); + + gimp_install_procedure (SAVE_PROC, "Saves files in IMG file format", + "Saves files in IMG file format", + "Igor Pashev <pashev.igor@gmail.com>", + "Public Domain", "2009", "IMG", "*", GIMP_PLUGIN, + G_N_ELEMENTS (save_args), 0, save_args, NULL); + + gimp_register_file_handler_mime (SAVE_PROC, IMG_MIME); + gimp_register_save_handler (SAVE_PROC, "img", ""); } static void -run(const gchar * name, gint nparams, const GimpParam * param, - gint * nreturn_vals, GimpParam ** return_vals) +run (const gchar * name, gint nparams, const GimpParam * param, + gint * nreturn_vals, GimpParam ** return_vals) { - static GimpParam values[2]; - gint32 image_ID; - gint32 drawable_ID; - static ImageParasite plugin; - GimpRunMode run_mode; - GimpPDBStatusType status = GIMP_PDB_SUCCESS; - GimpExportReturn export = GIMP_EXPORT_CANCEL; - - GError *error = NULL; - - run_mode = param[0].data.d_int32; - - *nreturn_vals = 1; - *return_vals = values; - values[0].type = GIMP_PDB_STATUS; - values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR; - - /* - * Load image - */ - if (strcmp(name, LOAD_PROC) == 0) + static GimpParam values[2]; + gint32 image_ID; + gint32 drawable_ID; + static ImageParasite plugin; + GimpRunMode run_mode; + GimpPDBStatusType status = GIMP_PDB_SUCCESS; + GimpExportReturn export = GIMP_EXPORT_CANCEL; + + GError *error = NULL; + + run_mode = param[0].data.d_int32; + + *nreturn_vals = 1; + *return_vals = values; + values[0].type = GIMP_PDB_STATUS; + values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR; + + /* + * Load image + */ + if (strcmp (name, LOAD_PROC) == 0) { - switch (run_mode) + switch (run_mode) { - case GIMP_RUN_INTERACTIVE: - break; + case GIMP_RUN_INTERACTIVE: + break; - case GIMP_RUN_NONINTERACTIVE: - if (nparams != 3) - status = GIMP_PDB_CALLING_ERROR; - break; + case GIMP_RUN_NONINTERACTIVE: + if (nparams != 3) + status = GIMP_PDB_CALLING_ERROR; + break; - default: - break; + default: + break; } - if (status == GIMP_PDB_SUCCESS) + if (status == GIMP_PDB_SUCCESS) { - image_ID = img_load_image(param[1].data.d_string, &plugin, &error); + image_ID = img_load_image (param[1].data.d_string, &plugin, &error); - if (image_ID != -1) + if (image_ID != -1) { - *nreturn_vals = 2; - values[1].type = GIMP_PDB_IMAGE; - values[1].data.d_image = image_ID; - img_set_parasite(image_ID, &plugin); + *nreturn_vals = 2; + values[1].type = GIMP_PDB_IMAGE; + values[1].data.d_image = image_ID; + img_set_parasite (image_ID, &plugin); } - else + else { - status = GIMP_PDB_EXECUTION_ERROR; + status = GIMP_PDB_EXECUTION_ERROR; } } } - /* - * Save image - */ - else if (strcmp(name, SAVE_PROC) == 0) + /* + * Save image + */ + else if (strcmp (name, SAVE_PROC) == 0) { - gchar *filename; + gchar *filename; - image_ID = param[1].data.d_int32; - drawable_ID = param[2].data.d_int32; - filename = param[3].data.d_string; + image_ID = param[1].data.d_int32; + drawable_ID = param[2].data.d_int32; + filename = param[3].data.d_string; - switch (run_mode) + switch (run_mode) { - case GIMP_RUN_WITH_LAST_VALS: /* Save */ - case GIMP_RUN_INTERACTIVE: /* Save as... */ - gimp_get_data(SAVE_PROC, &plugin); /* Get plugin recent options */ - img_get_parasite(image_ID, &plugin); /* Maybe overwrite it by image specific */ - gimp_ui_init(PLUG_IN_BINARY, FALSE); - export = - gimp_export_image(&image_ID, &drawable_ID, "IMG", - (GIMP_EXPORT_CAN_HANDLE_RGB | - GIMP_EXPORT_CAN_HANDLE_ALPHA | - GIMP_EXPORT_CAN_HANDLE_LAYERS)); - if (export == GIMP_EXPORT_CANCEL) - { - status = GIMP_PDB_CANCEL; - } - - /* - * Sanity check: RGB, geometry, layers. - */ - if (status == GIMP_PDB_SUCCESS) - { - status = img_sanity_check(image_ID, &error); - } - - /* - * Allow user to override default values - */ - if ((run_mode == GIMP_RUN_INTERACTIVE) && - (status == GIMP_PDB_SUCCESS)) - { - if (!img_save_dialog(image_ID, &plugin)) - status = GIMP_PDB_CANCEL; - else - { - gimp_set_data(SAVE_PROC, &plugin, sizeof(ImageParasite)); /* Save plugin defaults */ - img_set_parasite(image_ID, &plugin); /* Save the same for the image */ - } - } - break; - - case GIMP_RUN_NONINTERACTIVE: /* TODO: non-interactive */ - if (nparams < 6) - status = GIMP_PDB_CALLING_ERROR; - if (status == GIMP_PDB_SUCCESS) - { - status = img_sanity_check(image_ID, &error); - } - if (status == GIMP_PDB_SUCCESS) - { - gchar *fmt, *key; - - fmt = param[5].data.d_string; - key = (nparams > 6) ? param[6].data.d_string : NULL; - status = img_read_options(&plugin, fmt, key, &error); - } - break; - - default: - status = GIMP_PDB_CALLING_ERROR; - break; + case GIMP_RUN_WITH_LAST_VALS: /* Save */ + case GIMP_RUN_INTERACTIVE: /* Save as... */ + gimp_get_data (SAVE_PROC, &plugin); /* Get plugin recent options */ + img_get_parasite (image_ID, &plugin); /* Maybe overwrite it by image specific */ + gimp_ui_init (PLUG_IN_BINARY, FALSE); + export = + gimp_export_image (&image_ID, &drawable_ID, "IMG", + (GIMP_EXPORT_CAN_HANDLE_RGB | + GIMP_EXPORT_CAN_HANDLE_ALPHA | + GIMP_EXPORT_CAN_HANDLE_LAYERS)); + if (export == GIMP_EXPORT_CANCEL) + { + status = GIMP_PDB_CANCEL; + } + + /* + * Sanity check: RGB, geometry, layers. + */ + if (status == GIMP_PDB_SUCCESS) + { + status = img_sanity_check (image_ID, &error); + } + + /* + * Allow user to override default values + */ + if ((run_mode == GIMP_RUN_INTERACTIVE) && + (status == GIMP_PDB_SUCCESS)) + { + if (!img_save_dialog (image_ID, &plugin)) + status = GIMP_PDB_CANCEL; + else + { + gimp_set_data (SAVE_PROC, &plugin, sizeof (ImageParasite)); /* Save plugin defaults */ + img_set_parasite (image_ID, &plugin); /* Save the same for the image */ + } + } + break; + + case GIMP_RUN_NONINTERACTIVE: /* TODO: non-interactive */ + if (nparams < 6) + status = GIMP_PDB_CALLING_ERROR; + if (status == GIMP_PDB_SUCCESS) + { + status = img_sanity_check (image_ID, &error); + } + if (status == GIMP_PDB_SUCCESS) + { + gchar *fmt, *key; + + fmt = param[5].data.d_string; + key = (nparams > 6) ? param[6].data.d_string : NULL; + status = img_read_options (&plugin, fmt, key, &error); + } + break; + + default: + status = GIMP_PDB_CALLING_ERROR; + break; } - if (status == GIMP_PDB_SUCCESS) + if (status == GIMP_PDB_SUCCESS) { - status = img_save_image(image_ID, &plugin, filename, &error); + status = img_save_image (image_ID, &plugin, filename, &error); } - /* - * Delete temporary image after export - */ - if (export == GIMP_EXPORT_EXPORT) + /* + * Delete temporary image after export + */ + if (export == GIMP_EXPORT_EXPORT) { - gimp_image_delete(image_ID); + gimp_image_delete (image_ID); } } - else + else { - status = GIMP_PDB_CALLING_ERROR; + status = GIMP_PDB_CALLING_ERROR; } - if (status != GIMP_PDB_SUCCESS && error) + if (status != GIMP_PDB_SUCCESS && error) { - *nreturn_vals = 2; - values[1].type = GIMP_PDB_STRING; - values[1].data.d_string = error->message; + *nreturn_vals = 2; + values[1].type = GIMP_PDB_STRING; + values[1].data.d_string = error->message; } - values[0].data.d_status = status; + values[0].data.d_status = status; } const GimpPlugInInfo PLUG_IN_INFO = { - NULL, /* init_proc */ - NULL, /* quit_proc */ - query, /* query_proc */ - run, /* run_proc */ + NULL, /* init_proc */ + NULL, /* quit_proc */ + query, /* query_proc */ + run, /* run_proc */ }; -MAIN() +MAIN () diff --git a/plugin-img.h b/plugin-img.h index 8523a79..fafccf6 100644 --- a/plugin-img.h +++ b/plugin-img.h @@ -1,37 +1,37 @@ #ifndef __IMG_H__ -# define __IMG_H__ +#define __IMG_H__ -# include <libgimp/gimp.h> -# include <libgimp/gimpui.h> -# include <errno.h> -# include <string.h> -# include <glib/gstdio.h> +#include <libgimp/gimp.h> +#include <libgimp/gimpui.h> +#include <errno.h> +#include <string.h> +#include <glib/gstdio.h> -# define LOAD_PROC "file-img-load" -# define SAVE_PROC "file-img-save" -# define PLUG_IN_BINARY "file-img" +#define LOAD_PROC "file-img-load" +#define SAVE_PROC "file-img-save" +#define PLUG_IN_BINARY "file-img" /* Comment out to disable debug */ -# define DEBUG +#define DEBUG -# ifdef DEBUG -# define __DEBUG(x) {x} -# define D(x) \ +#ifdef DEBUG +#define __DEBUG(x) {x} +#define D(x) \ { \ printf("IMG plugin: "); \ printf x; \ } -# else -# define __DEBUG(x) -# define D(x) -# endif +#else +#define __DEBUG(x) +#define D(x) +#endif /* FIXME: MIME type for these files */ -# define IMG_MIME "image/x-img" +#define IMG_MIME "image/x-img" -# define FMT_RGB565 0 -# define FMT_RGB 1 -# define FMT_RGBA 2 +#define FMT_RGB565 0 +#define FMT_RGB 1 +#define FMT_RGBA 2 extern const gchar *FMT[3]; @@ -49,25 +49,25 @@ extern const gchar *FMT[3]; /* ACHTUNG: byte order in the file is LITTLE-ENDIAN - lowest byte comes first */ typedef struct _FileHeader { - guint8 fmt; /* 0 - RGB565, 1 - RGB, 2 - RGBA) */ + guint8 fmt; /* 0 - RGB565, 1 - RGB, 2 - RGBA) */ - /* - * ACHTUNG: do not align, or else sizeof(ftm)==4: __attribute__ ((packed)) - */ - guint32 nrows __attribute__ ((packed)); /* Number of rows of frames */ - guint32 ncols __attribute__ ((packed)); /* Number of columns of frames */ + /* + * ACHTUNG: do not align, or else sizeof(ftm)==4: __attribute__ ((packed)) + */ + guint32 nrows __attribute__((packed)); /* Number of rows of frames */ + guint32 ncols __attribute__((packed)); /* Number of columns of frames */ - guint32 width __attribute__ ((packed)); /* Image width (total) */ - guint32 height __attribute__ ((packed)); /* Image height (total) */ + guint32 width __attribute__((packed)); /* Image width (total) */ + guint32 height __attribute__((packed)); /* Image height (total) */ } FileHeader; typedef struct _ColorKey { - guint8 is; /* 0 - no color key, otherwise is one */ - guint8 R __attribute__ ((packed)); - guint8 G __attribute__ ((packed)); - guint8 B __attribute__ ((packed)); + guint8 is; /* 0 - no color key, otherwise is one */ + guint8 R __attribute__((packed)); + guint8 G __attribute__((packed)); + guint8 B __attribute__((packed)); } ColorKey; @@ -75,11 +75,11 @@ typedef struct _ColorKey * for each image LOADED image or for plugin defaults * * */ -# define PARASITE_ORIG_FILE "orig-file-info" +#define PARASITE_ORIG_FILE "orig-file-info" typedef struct _ImageParasite { - guint32 format; - ColorKey ckey; + guint32 format; + ColorKey ckey; } ImageParasite; #endif |