[gimp] plug-ins: a lot of coding style cleanup in file-dds.



commit ff2d22d915b9a94c491bde33fa2fa14f8cb740e2
Author: Jehan <jehan girinstud io>
Date:   Wed Jan 2 21:32:17 2019 +0100

    plug-ins: a lot of coding style cleanup in file-dds.
    
    Still a lot more to do but pushing WIP to not have it wasted if more
    commits come in from others.
    Also got rid of some global variables.

 plug-ins/file-dds/dds.c       |  450 +++---
 plug-ins/file-dds/dds.h       |   40 +-
 plug-ins/file-dds/ddsplugin.h |   93 +-
 plug-ins/file-dds/ddsread.c   | 2171 +++++++++++++-------------
 plug-ins/file-dds/ddswrite.c  | 3374 +++++++++++++++++++++--------------------
 5 files changed, 3143 insertions(+), 2985 deletions(-)
---
diff --git a/plug-ins/file-dds/dds.c b/plug-ins/file-dds/dds.c
index b4cc217364..ea8a943fe9 100644
--- a/plug-ins/file-dds/dds.c
+++ b/plug-ins/file-dds/dds.c
@@ -1,24 +1,24 @@
 /*
-       DDS GIMP plugin
-
-       Copyright (C) 2004-2012 Shawn Kirst <skirst gmail com>,
-   with parts (C) 2003 Arne Reuter <homepage arnereuter de> where specified.
-
-       This program is free software; you can redistribute it and/or
-       modify it under the terms of the GNU General Public
-       License as published by the Free Software Foundation; either
-       version 2 of the License, or (at your option) any later version.
-
-       This program is distributed in the hope that it will be useful,
-       but WITHOUT ANY WARRANTY; without even the implied warranty of
-       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-       General Public License for more details.
-
-       You should have received a copy of the GNU General Public License
-       along with this program; see the file COPYING.  If not, write to
-       the Free Software Foundation, 51 Franklin Street, Fifth Floor
-       Boston, MA 02110-1301, USA.
-*/
+ * DDS GIMP plugin
+ *
+ * Copyright (C) 2004-2012 Shawn Kirst <skirst gmail com>,
+ * with parts (C) 2003 Arne Reuter <homepage arnereuter de> where specified.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301, USA.
+ */
 
 #include "config.h"
 
@@ -37,32 +37,44 @@
 #include "dds.h"
 #include "misc.h"
 
-FILE *errFile;
-gchar *prog_name = "dds";
-gchar *filename;
-gint interactive_dds;
-
-static void query(void);
-static void run(const gchar *name, gint nparams, const GimpParam *param,
-                                        gint *nreturn_vals, GimpParam **return_vals);
+static void query (void);
+static void run   (const gchar     *name,
+                   gint             nparams,
+                   const GimpParam *param,
+                   gint            *nreturn_vals,
+                   GimpParam      **return_vals);
 
 GimpPlugInInfo PLUG_IN_INFO =
 {
-       0, 0, query, run
+  0,
+  0,
+  query,
+  run
 };
 
 
 DDSWriteVals dds_write_vals =
 {
-       DDS_COMPRESS_NONE, DDS_MIPMAP_NONE, DDS_SAVE_SELECTED_LAYER,
-   DDS_FORMAT_DEFAULT, -1, DDS_MIPMAP_FILTER_DEFAULT, DDS_MIPMAP_WRAP_DEFAULT,
-   0, 0, 0.0, 0, 0,
-   0, 0.5
+  DDS_COMPRESS_NONE,
+  DDS_MIPMAP_NONE,
+  DDS_SAVE_SELECTED_LAYER,
+  DDS_FORMAT_DEFAULT,
+  -1,
+  DDS_MIPMAP_FILTER_DEFAULT,
+  DDS_MIPMAP_WRAP_DEFAULT,
+  0,
+  0,
+  0.0,
+  0,
+  0,
+  0,
+  0.5
 };
 
 DDSReadVals dds_read_vals =
 {
-   1, 1
+   1,
+   1
 };
 
 static GimpParamDef load_args[] =
@@ -73,6 +85,7 @@ static GimpParamDef load_args[] =
    {GIMP_PDB_INT32, "load_mipmaps", "Load mipmaps if present"},
    {GIMP_PDB_INT32, "decode_images", "Decode YCoCg/AExp images when detected"}
 };
+
 static GimpParamDef load_return_vals[] =
 {
    {GIMP_PDB_IMAGE, "image", "Output image"}
@@ -107,9 +120,10 @@ static GimpParamDef decode_args[] =
    {GIMP_PDB_DRAWABLE, "drawable", "Drawable to save"}
 };
 
-MAIN()
+MAIN ()
 
-static void query(void)
+static void
+query (void)
 {
   gimp_install_procedure (LOAD_PROC,
                           "Loads files in DDS image format",
@@ -120,8 +134,8 @@ static void query(void)
                           N_("DDS image"),
                           0,
                           GIMP_PLUGIN,
-                          G_N_ELEMENTS(load_args),
-                          G_N_ELEMENTS(load_return_vals),
+                          G_N_ELEMENTS (load_args),
+                          G_N_ELEMENTS (load_return_vals),
                           load_args, load_return_vals);
 
   gimp_register_file_handler_mime (LOAD_PROC, "image/dds");
@@ -139,7 +153,7 @@ static void query(void)
                           N_("DDS image"),
                           "INDEXED, GRAY, RGB",
                           GIMP_PLUGIN,
-                          G_N_ELEMENTS(save_args), 0,
+                          G_N_ELEMENTS (save_args), 0,
                           save_args, 0);
 
   gimp_register_file_handler_mime (SAVE_PROC, "image/dds");
@@ -156,7 +170,7 @@ static void query(void)
                           N_("Decode YCoCg"),
                           "RGBA",
                           GIMP_PLUGIN,
-                          G_N_ELEMENTS(decode_args), 0,
+                          G_N_ELEMENTS (decode_args), 0,
                           decode_args, 0);
   /*gimp_plugin_menu_register (DECODE_YCOCG_PROC, "<Image>/Filters/Colors");*/
 
@@ -169,7 +183,7 @@ static void query(void)
                           N_("Decode YCoCg (scaled)"),
                           "RGBA",
                           GIMP_PLUGIN,
-                          G_N_ELEMENTS(decode_args), 0,
+                          G_N_ELEMENTS (decode_args), 0,
                           decode_args, 0);
   /*gimp_plugin_menu_register (DECODE_YCOCG_SCALED_PROC, "<Image>/Filters/Colors");*/
 
@@ -182,201 +196,201 @@ static void query(void)
                           N_("Decode Alpha exponent"),
                           "RGBA",
                           GIMP_PLUGIN,
-                          G_N_ELEMENTS(decode_args), 0,
+                          G_N_ELEMENTS (decode_args), 0,
                           decode_args, 0);
   /*gimp_plugin_menu_register (DECODE_ALPHA_EXP_PROC, "<Image>/Filters/Colors");*/
 }
 
-static void run(const gchar *name, gint nparams, const GimpParam *param,
-                                        gint *nreturn_vals, GimpParam **return_vals)
+static void
+run (const gchar      *name,
+     gint              nparams,
+     const GimpParam  *param,
+     gint             *nreturn_vals,
+     GimpParam       **return_vals)
 {
-       static GimpParam values[2];
-       GimpRunMode run_mode;
-       GimpPDBStatusType status = GIMP_PDB_SUCCESS;
-       gint32 imageID;
-       gint32 drawableID;
-       GimpExportReturn export = GIMP_EXPORT_CANCEL;
-   
-   gegl_init(NULL, 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;
-
-       if(!strcmp(name, LOAD_PROC))
-       {
-               switch(run_mode)
-               {
-                       case GIMP_RUN_INTERACTIVE:
-                          gimp_ui_init("dds", 0);
-                          interactive_dds = 1;
-            gimp_get_data(LOAD_PROC, &dds_read_vals);
-                          break;
-                       case GIMP_RUN_NONINTERACTIVE:
-                          interactive_dds = 0;
-            dds_read_vals.mipmaps = param[3].data.d_int32;
-            dds_read_vals.decode_images = param[4].data.d_int32;
-                          if(nparams != G_N_ELEMENTS(load_args))
-                                  status = GIMP_PDB_CALLING_ERROR;
-                          break;
-                       default:
-                          break;
-               }
-
-               if(status == GIMP_PDB_SUCCESS)
-               {
-                       status = read_dds(param[1].data.d_string, &imageID);
-                       if(status == GIMP_PDB_SUCCESS && imageID != -1)
-                       {
-                               *nreturn_vals = 2;
-                               values[1].type = GIMP_PDB_IMAGE;
-                               values[1].data.d_image = imageID;
-            if(interactive_dds)
-               gimp_set_data(LOAD_PROC, &dds_read_vals, sizeof(dds_read_vals));
-                       }
-                       else if(status != GIMP_PDB_CANCEL)
-                               status = GIMP_PDB_EXECUTION_ERROR;
-               }
-       }
-       else if(!strcmp(name, SAVE_PROC))
-       {
-               imageID = param[1].data.d_int32;
-               drawableID = param[2].data.d_int32;
-
-               switch(run_mode)
-               {
-                       case GIMP_RUN_INTERACTIVE:
-                       case GIMP_RUN_WITH_LAST_VALS:
-                          gimp_ui_init("dds", 0);
-                          export = gimp_export_image(&imageID, &drawableID, "DDS",
-                                       (GIMP_EXPORT_CAN_HANDLE_RGB |
-                                        GIMP_EXPORT_CAN_HANDLE_GRAY |
-                                        GIMP_EXPORT_CAN_HANDLE_INDEXED |
-                                        GIMP_EXPORT_CAN_HANDLE_ALPHA |
-                                        GIMP_EXPORT_CAN_HANDLE_LAYERS));
-                          if(export == GIMP_EXPORT_CANCEL)
-                          {
-                                       values[0].data.d_status = GIMP_PDB_CANCEL;
-                                       return;
-                               }
-                       default:
-                          break;
-               }
-
-               switch(run_mode)
-               {
-                       case GIMP_RUN_INTERACTIVE:
-                          gimp_get_data(SAVE_PROC, &dds_write_vals);
-                          interactive_dds = 1;
-                          break;
-                       case GIMP_RUN_NONINTERACTIVE:
-                          interactive_dds = 0;
-                          if(nparams != G_N_ELEMENTS(save_args))
-                                  status = GIMP_PDB_CALLING_ERROR;
-                          else
-                          {
-                                       dds_write_vals.compression = param[5].data.d_int32;
-                                       dds_write_vals.mipmaps = param[6].data.d_int32;
-               dds_write_vals.savetype = param[7].data.d_int32;
-               dds_write_vals.format = param[8].data.d_int32;
-               dds_write_vals.transindex = param[9].data.d_int32;
-               dds_write_vals.mipmap_filter = param[10].data.d_int32;
-               dds_write_vals.mipmap_wrap = param[11].data.d_int32;
-               dds_write_vals.gamma_correct = param[12].data.d_int32;
-               dds_write_vals.srgb = param[13].data.d_int32;
-               dds_write_vals.gamma = param[14].data.d_float;
-               dds_write_vals.perceptual_metric = param[15].data.d_int32;
-               dds_write_vals.preserve_alpha_coverage = param[16].data.d_int32;
-               dds_write_vals.alpha_test_threshold = param[17].data.d_float;
-
-                                       if((dds_write_vals.compression <  DDS_COMPRESS_NONE) ||
-                                               (dds_write_vals.compression >= DDS_COMPRESS_MAX))
-                                               status = GIMP_PDB_CALLING_ERROR;
-               if((dds_write_vals.mipmaps <  DDS_MIPMAP_NONE) ||
-                  (dds_write_vals.mipmaps >= DDS_MIPMAP_MAX))
-                  status = GIMP_PDB_CALLING_ERROR;
-               if((dds_write_vals.savetype <  DDS_SAVE_SELECTED_LAYER) ||
-                  (dds_write_vals.savetype >= DDS_SAVE_MAX))
-                  status = GIMP_PDB_CALLING_ERROR;
-               if((dds_write_vals.format <  DDS_FORMAT_DEFAULT) ||
-                  (dds_write_vals.format >= DDS_FORMAT_MAX))
-                  status = GIMP_PDB_CALLING_ERROR;
-               if((dds_write_vals.mipmap_filter <  DDS_MIPMAP_FILTER_DEFAULT) ||
-                  (dds_write_vals.mipmap_filter >= DDS_MIPMAP_FILTER_MAX))
-                  status = GIMP_PDB_CALLING_ERROR;
-               if((dds_write_vals.mipmap_wrap <  DDS_MIPMAP_WRAP_DEFAULT) ||
-                  (dds_write_vals.mipmap_wrap >= DDS_MIPMAP_WRAP_MAX))
-                  status = GIMP_PDB_CALLING_ERROR;
-                               }
-                          break;
-                       case GIMP_RUN_WITH_LAST_VALS:
-                          gimp_get_data(SAVE_PROC, &dds_write_vals);
-                          interactive_dds = 0;
-                          break;
-                       default:
-                          break;
-               }
-
-      if(dds_write_vals.gamma < 1e-04f)
-        /* gimp_gamma() got removed and was always returning 2.2 anyway.
+  static GimpParam  values[2];
+  GimpRunMode       run_mode;
+  GimpPDBStatusType status = GIMP_PDB_SUCCESS;
+  gint32            imageID;
+  gint32            drawableID;
+  GimpExportReturn  export = GIMP_EXPORT_CANCEL;
+
+  gegl_init (NULL, 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;
+
+  if (!strcmp (name, LOAD_PROC))
+    {
+      switch (run_mode)
+        {
+        case GIMP_RUN_INTERACTIVE:
+          gimp_ui_init ("dds", 0);
+          gimp_get_data (LOAD_PROC, &dds_read_vals);
+          break;
+        case GIMP_RUN_NONINTERACTIVE:
+          dds_read_vals.mipmaps = param[3].data.d_int32;
+          dds_read_vals.decode_images = param[4].data.d_int32;
+          if (nparams != G_N_ELEMENTS (load_args))
+            status = GIMP_PDB_CALLING_ERROR;
+          break;
+        default:
+          break;
+        }
+
+      if (status == GIMP_PDB_SUCCESS)
+        {
+          status = read_dds (param[1].data.d_string, &imageID,
+                             run_mode == GIMP_RUN_INTERACTIVE);
+          if (status == GIMP_PDB_SUCCESS && imageID != -1)
+            {
+              *nreturn_vals = 2;
+              values[1].type = GIMP_PDB_IMAGE;
+              values[1].data.d_image = imageID;
+              if (run_mode == GIMP_RUN_INTERACTIVE)
+                gimp_set_data (LOAD_PROC, &dds_read_vals, sizeof (dds_read_vals));
+            }
+          else if (status != GIMP_PDB_CANCEL)
+            status = GIMP_PDB_EXECUTION_ERROR;
+        }
+    }
+  else if (!strcmp (name, SAVE_PROC))
+    {
+      imageID = param[1].data.d_int32;
+      drawableID = param[2].data.d_int32;
+
+      switch (run_mode)
+        {
+        case GIMP_RUN_INTERACTIVE:
+        case GIMP_RUN_WITH_LAST_VALS:
+          gimp_ui_init ("dds", 0);
+          export = gimp_export_image (&imageID, &drawableID, "DDS",
+                                     (GIMP_EXPORT_CAN_HANDLE_RGB |
+                                      GIMP_EXPORT_CAN_HANDLE_GRAY |
+                                      GIMP_EXPORT_CAN_HANDLE_INDEXED |
+                                      GIMP_EXPORT_CAN_HANDLE_ALPHA |
+                                      GIMP_EXPORT_CAN_HANDLE_LAYERS));
+          if (export == GIMP_EXPORT_CANCEL)
+            {
+              values[0].data.d_status = GIMP_PDB_CANCEL;
+              return;
+            }
+        default:
+          break;
+        }
+
+      switch (run_mode)
+        {
+        case GIMP_RUN_INTERACTIVE:
+          gimp_get_data (SAVE_PROC, &dds_write_vals);
+          break;
+        case GIMP_RUN_NONINTERACTIVE:
+          if (nparams != G_N_ELEMENTS (save_args))
+            status = GIMP_PDB_CALLING_ERROR;
+          else
+            {
+              dds_write_vals.compression = param[5].data.d_int32;
+              dds_write_vals.mipmaps = param[6].data.d_int32;
+              dds_write_vals.savetype = param[7].data.d_int32;
+              dds_write_vals.format = param[8].data.d_int32;
+              dds_write_vals.transindex = param[9].data.d_int32;
+              dds_write_vals.mipmap_filter = param[10].data.d_int32;
+              dds_write_vals.mipmap_wrap = param[11].data.d_int32;
+              dds_write_vals.gamma_correct = param[12].data.d_int32;
+              dds_write_vals.srgb = param[13].data.d_int32;
+              dds_write_vals.gamma = param[14].data.d_float;
+              dds_write_vals.perceptual_metric = param[15].data.d_int32;
+              dds_write_vals.preserve_alpha_coverage = param[16].data.d_int32;
+              dds_write_vals.alpha_test_threshold = param[17].data.d_float;
+
+              if ((dds_write_vals.compression <  DDS_COMPRESS_NONE) ||
+                 (dds_write_vals.compression >= DDS_COMPRESS_MAX))
+                status = GIMP_PDB_CALLING_ERROR;
+              if ((dds_write_vals.mipmaps <  DDS_MIPMAP_NONE) ||
+                 (dds_write_vals.mipmaps >= DDS_MIPMAP_MAX))
+                status = GIMP_PDB_CALLING_ERROR;
+              if ((dds_write_vals.savetype <  DDS_SAVE_SELECTED_LAYER) ||
+                 (dds_write_vals.savetype >= DDS_SAVE_MAX))
+                status = GIMP_PDB_CALLING_ERROR;
+              if ((dds_write_vals.format <  DDS_FORMAT_DEFAULT) ||
+                 (dds_write_vals.format >= DDS_FORMAT_MAX))
+                status = GIMP_PDB_CALLING_ERROR;
+              if ((dds_write_vals.mipmap_filter <  DDS_MIPMAP_FILTER_DEFAULT) ||
+                 (dds_write_vals.mipmap_filter >= DDS_MIPMAP_FILTER_MAX))
+                status = GIMP_PDB_CALLING_ERROR;
+              if ((dds_write_vals.mipmap_wrap <  DDS_MIPMAP_WRAP_DEFAULT) ||
+                 (dds_write_vals.mipmap_wrap >= DDS_MIPMAP_WRAP_MAX))
+                status = GIMP_PDB_CALLING_ERROR;
+            }
+          break;
+        case GIMP_RUN_WITH_LAST_VALS:
+          gimp_get_data (SAVE_PROC, &dds_write_vals);
+          break;
+        default:
+          break;
+        }
+
+      if (dds_write_vals.gamma < 1e-04f)
+        /* gimp_gamma () got removed and was always returning 2.2 anyway.
          * XXX Review this piece of code if we expect gamma value could
          * be parameterized.
          */
-         dds_write_vals.gamma = 2.2;
-
-               if(status == GIMP_PDB_SUCCESS)
-               {
-                       status = write_dds(param[3].data.d_string, imageID, drawableID);
-                       if(status == GIMP_PDB_SUCCESS)
-                               gimp_set_data(SAVE_PROC, &dds_write_vals, sizeof(dds_write_vals));
-               }
-
-               if(export == GIMP_EXPORT_EXPORT)
-                       gimp_image_delete(imageID);
-   }
-   else if(!strcmp(name, DECODE_YCOCG_PROC))
-   {
-               imageID = param[1].data.d_int32;
-               drawableID = param[2].data.d_int32;
-
-      decode_ycocg_image(drawableID, TRUE);
+        dds_write_vals.gamma = 2.2;
+
+      if (status == GIMP_PDB_SUCCESS)
+        {
+          status = write_dds (param[3].data.d_string, imageID, drawableID,
+                              run_mode == GIMP_RUN_INTERACTIVE);
+          if (status == GIMP_PDB_SUCCESS)
+            gimp_set_data (SAVE_PROC, &dds_write_vals, sizeof (dds_write_vals));
+        }
+
+      if (export == GIMP_EXPORT_EXPORT)
+        gimp_image_delete (imageID);
+    }
+  else if (!strcmp (name, DECODE_YCOCG_PROC))
+    {
+      imageID = param[1].data.d_int32;
+      drawableID = param[2].data.d_int32;
+
+      decode_ycocg_image (drawableID, TRUE);
 
       status = GIMP_PDB_SUCCESS;
 
-      if(run_mode != GIMP_RUN_NONINTERACTIVE)
-         gimp_displays_flush();
-   }
-   else if(!strcmp(name, DECODE_YCOCG_SCALED_PROC))
-   {
-               imageID = param[1].data.d_int32;
-               drawableID = param[2].data.d_int32;
+      if (run_mode != GIMP_RUN_NONINTERACTIVE)
+        gimp_displays_flush ();
+    }
+  else if (!strcmp (name, DECODE_YCOCG_SCALED_PROC))
+    {
+      imageID = param[1].data.d_int32;
+      drawableID = param[2].data.d_int32;
 
-      decode_ycocg_scaled_image(drawableID, TRUE);
+      decode_ycocg_scaled_image (drawableID, TRUE);
 
       status = GIMP_PDB_SUCCESS;
 
-      if(run_mode != GIMP_RUN_NONINTERACTIVE)
-         gimp_displays_flush();
-   }
-   else if(!strcmp(name, DECODE_ALPHA_EXP_PROC))
-   {
-               imageID = param[1].data.d_int32;
-               drawableID = param[2].data.d_int32;
+      if (run_mode != GIMP_RUN_NONINTERACTIVE)
+        gimp_displays_flush ();
+    }
+  else if (!strcmp (name, DECODE_ALPHA_EXP_PROC))
+    {
+      imageID = param[1].data.d_int32;
+      drawableID = param[2].data.d_int32;
 
-      decode_alpha_exp_image(drawableID, TRUE);
+      decode_alpha_exp_image (drawableID, TRUE);
 
       status = GIMP_PDB_SUCCESS;
 
-      if(run_mode != GIMP_RUN_NONINTERACTIVE)
-         gimp_displays_flush();
-   }
-       else
-               status = GIMP_PDB_CALLING_ERROR;
+      if (run_mode != GIMP_RUN_NONINTERACTIVE)
+        gimp_displays_flush ();
+    }
+  else
+    status = GIMP_PDB_CALLING_ERROR;
 
-       values[0].data.d_status = status;
+  values[0].data.d_status = status;
 }
-
diff --git a/plug-ins/file-dds/dds.h b/plug-ins/file-dds/dds.h
index 6affc41a5c..5e2086aeed 100644
--- a/plug-ins/file-dds/dds.h
+++ b/plug-ins/file-dds/dds.h
@@ -1,24 +1,24 @@
 /*
-       DDS GIMP plugin
-
-       Copyright (C) 2004-2012 Shawn Kirst <skirst gmail com>,
-   with parts (C) 2003 Arne Reuter <homepage arnereuter de> where specified.
-
-       This program is free software; you can redistribute it and/or
-       modify it under the terms of the GNU General Public
-       License as published by the Free Software Foundation; either
-       version 2 of the License, or (at your option) any later version.
-
-       This program is distributed in the hope that it will be useful,
-       but WITHOUT ANY WARRANTY; without even the implied warranty of
-       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-       General Public License for more details.
-
-       You should have received a copy of the GNU General Public License
-       along with this program; see the file COPYING.  If not, write to
-       the Free Software Foundation, 51 Franklin Street, Fifth Floor
-       Boston, MA 02110-1301, USA.
-*/
+ * DDS GIMP plugin
+ *
+ * Copyright (C) 2004-2012 Shawn Kirst <skirst gmail com>,
+ * with parts (C) 2003 Arne Reuter <homepage arnereuter de> where specified.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301, USA.
+ */
 
 #ifndef DDS_H
 #define DDS_H
diff --git a/plug-ins/file-dds/ddsplugin.h b/plug-ins/file-dds/ddsplugin.h
index 6306ec6922..ecb250b4b9 100644
--- a/plug-ins/file-dds/ddsplugin.h
+++ b/plug-ins/file-dds/ddsplugin.h
@@ -1,24 +1,24 @@
 /*
-       DDS GIMP plugin
-
-       Copyright (C) 2004-2012 Shawn Kirst <skirst gmail com>,
-   with parts (C) 2003 Arne Reuter <homepage arnereuter de> where specified.
-
-       This program is free software; you can redistribute it and/or
-       modify it under the terms of the GNU General Public
-       License as published by the Free Software Foundation; either
-       version 2 of the License, or (at your option) any later version.
-
-       This program is distributed in the hope that it will be useful,
-       but WITHOUT ANY WARRANTY; without even the implied warranty of
-       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-       General Public License for more details.
-
-       You should have received a copy of the GNU General Public License
-       along with this program; see the file COPYING.  If not, write to
-       the Free Software Foundation, 51 Franklin Street, Fifth Floor
-       Boston, MA 02110-1301, USA.
-*/
+ * DDS GIMP plugin
+ *
+ * Copyright (C) 2004-2012 Shawn Kirst <skirst gmail com>,
+ * with parts (C) 2003 Arne Reuter <homepage arnereuter de> where specified.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301, USA.
+ */
 
 #ifndef __DDSPLUGIN_H
 #define __DDSPLUGIN_H
@@ -34,44 +34,45 @@
 
 typedef struct
 {
-   int compression;
-   int mipmaps;
-   int savetype;
-   int format;
-   int transindex;
-   int mipmap_filter;
-   int mipmap_wrap;
-   int gamma_correct;
-   int srgb;
-   float gamma;
-   int perceptual_metric;
-   int show_adv_opt;
-   int preserve_alpha_coverage;
-   float alpha_test_threshold;
+  int compression;
+  int mipmaps;
+  int savetype;
+  int format;
+  int transindex;
+  int mipmap_filter;
+  int mipmap_wrap;
+  int gamma_correct;
+  int srgb;
+  float gamma;
+  int perceptual_metric;
+  int show_adv_opt;
+  int preserve_alpha_coverage;
+  float alpha_test_threshold;
 } DDSWriteVals;
 
 typedef struct
 {
-   int mipmaps;
-   int decode_images;
+  int mipmaps;
+  int decode_images;
 } DDSReadVals;
 
 extern DDSWriteVals dds_write_vals;
 extern DDSReadVals dds_read_vals;
 
-extern GimpPDBStatusType read_dds(gchar *filename, gint32 *imageID);
-extern GimpPDBStatusType write_dds(gchar *, gint32, gint32);
+extern GimpPDBStatusType read_dds  (gchar    *filename,
+                                    gint32   *imageID,
+                                    gboolean  interactive_dds);
+extern GimpPDBStatusType write_dds (gchar    *filename,
+                                    gint32    image_id,
+                                    gint32    drawable_id,
+                                    gboolean  interactive_dds);
 
-extern gint interactive_dds;
-extern gchar *prog_name;
-extern gchar *filename;
-extern FILE *errorFile;
 
-#define LOAD_PROC "file-dds-load"
-#define SAVE_PROC "file-dds-save"
+#define LOAD_PROC                "file-dds-load"
+#define SAVE_PROC                "file-dds-save"
 
-#define DECODE_YCOCG_PROC "color-decode-ycocg"
+#define DECODE_YCOCG_PROC        "color-decode-ycocg"
 #define DECODE_YCOCG_SCALED_PROC "color-decode-ycocg-scaled"
-#define DECODE_ALPHA_EXP_PROC "color-decode-alpha-exp"
+#define DECODE_ALPHA_EXP_PROC    "color-decode-alpha-exp"
 
 #endif
diff --git a/plug-ins/file-dds/ddsread.c b/plug-ins/file-dds/ddsread.c
index 0be3a5660e..d263897d9c 100644
--- a/plug-ins/file-dds/ddsread.c
+++ b/plug-ins/file-dds/ddsread.c
@@ -1,32 +1,32 @@
 /*
-       DDS GIMP plugin
-
-       Copyright (C) 2004-2012 Shawn Kirst <skirst gmail com>,
-   with parts (C) 2003 Arne Reuter <homepage arnereuter de> where specified.
-
-       This program is free software; you can redistribute it and/or
-       modify it under the terms of the GNU General Public
-       License as published by the Free Software Foundation; either
-       version 2 of the License, or (at your option) any later version.
-
-       This program is distributed in the hope that it will be useful,
-       but WITHOUT ANY WARRANTY; without even the implied warranty of
-       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-       General Public License for more details.
-
-       You should have received a copy of the GNU General Public License
-       along with this program; see the file COPYING.  If not, write to
-       the Free Software Foundation, 51 Franklin Street, Fifth Floor
-       Boston, MA 02110-1301, USA.
-*/
+ * DDS GIMP plugin
+ *
+ * Copyright (C) 2004-2012 Shawn Kirst <skirst gmail com>,
+ * with parts (C) 2003 Arne Reuter <homepage arnereuter de> where specified.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301, USA.
+ */
 
 /*
-** !!! COPYRIGHT NOTICE !!!
-**
-** The following is based on code (C) 2003 Arne Reuter <homepage arnereuter de>
-** URL: http://www.dr-reuter.de/arne/dds.html
-**
-*/
+ ** !!! COPYRIGHT NOTICE !!!
+ **
+ ** The following is based on code (C) 2003 Arne Reuter <homepage arnereuter de>
+ ** URL: http://www.dr-reuter.de/arne/dds.html
+ **
+ */
 
 #include "config.h"
 
@@ -51,758 +51,787 @@
 
 typedef struct
 {
-   unsigned char rshift, gshift, bshift, ashift;
-   unsigned char rbits, gbits, bbits, abits;
-   unsigned int rmask, gmask, bmask, amask;
-   unsigned int bpp, gimp_bpp;
-   int tile_height;
-   unsigned char *palette;
+  unsigned char  rshift, gshift, bshift, ashift;
+  unsigned char  rbits, gbits, bbits, abits;
+  unsigned int   rmask, gmask, bmask, amask;
+  unsigned int   bpp, gimp_bpp;
+  int            tile_height;
+  unsigned char *palette;
 } dds_load_info_t;
 
-static int read_header(dds_header_t *hdr, FILE *fp);
-static int read_header_dx10(dds_header_dx10_t *hdr, FILE *fp);
-static int validate_header(dds_header_t *hdr);
-static int setup_dxgi_format(dds_header_t *hdr, dds_header_dx10_t *dx10hdr);
-static int load_layer(FILE *fp, dds_header_t *hdr, dds_load_info_t *d,
-                      gint32 image, unsigned int level, char *prefix,
-                      unsigned int *l, guchar *pixels, unsigned char *buf);
-static int load_mipmaps(FILE *fp, dds_header_t *hdr, dds_load_info_t *d,
-                        gint32 image, char *prefix, unsigned int *l,
-                        guchar *pixels, unsigned char *buf);
-static int load_face(FILE *fp, dds_header_t *hdr, dds_load_info_t *d,
-                     gint32 image, char *prefix, unsigned int *l,
-                     guchar *pixels, unsigned char *buf);
-static unsigned char color_bits(unsigned int mask);
-static unsigned char color_shift(unsigned int mask);
-static int load_dialog(void);
+static int           read_header       (dds_header_t      *hdr,
+                                        FILE              *fp);
+static int           read_header_dx10  (dds_header_dx10_t *hdr,
+                                        FILE              *fp);
+static int           validate_header   (dds_header_t      *hdr);
+static int           setup_dxgi_format (dds_header_t      *hdr,
+                                        dds_header_dx10_t *dx10hdr);
+static int           load_layer        (FILE              *fp,
+                                        dds_header_t      *hdr,
+                                        dds_load_info_t   *d,
+                                        gint32             image,
+                                        unsigned int       level,
+                                        char              *prefix,
+                                        unsigned int      *l,
+                                        guchar            *pixels,
+                                        unsigned char     *buf);
+static int           load_mipmaps      (FILE              *fp,
+                                        dds_header_t      *hdr,
+                                        dds_load_info_t   *d,
+                                        gint32             image,
+                                        char              *prefix,
+                                        unsigned int      *l,
+                                        guchar            *pixels,
+                                        unsigned char     *buf);
+static int           load_face         (FILE              *fp,
+                                        dds_header_t      *hdr,
+                                        dds_load_info_t   *d,
+                                        gint32             image,
+                                        char              *prefix,
+                                        unsigned int      *l,
+                                        guchar            *pixels,
+                                        unsigned char     *buf);
+static unsigned char color_bits        (unsigned int       mask);
+static unsigned char color_shift       (unsigned int       mask);
+static int           load_dialog       (void);
 
 static int runme = 0;
 
-GimpPDBStatusType read_dds(gchar *filename, gint32 *imageID)
+GimpPDBStatusType
+read_dds (gchar    *filename,
+          gint32   *imageID,
+          gboolean  interactive_dds)
 {
-   gint32 image = 0;
-   unsigned char *buf;
-   unsigned int l = 0;
-   guchar *pixels;
-   gchar *tmp;
-   FILE *fp;
-   dds_header_t hdr;
-   dds_header_dx10_t dx10hdr;
-   dds_load_info_t d;
-   gint *layers, layer_count;
-   GimpImageBaseType type;
-   int i, j;
-
-   if (interactive_dds)
-   {
-      if(!load_dialog())
-         return(GIMP_PDB_CANCEL);
-   }
-
-   fp = g_fopen(filename, "rb");
-   if(fp == 0)
-   {
-      g_message("Error opening file.\n");
-      return(GIMP_PDB_EXECUTION_ERROR);
-   }
-
-   if(strrchr(filename, '/'))
-      tmp = g_strdup_printf("Loading %s:", strrchr(filename, '/') + 1);
-   else
-      tmp = g_strdup_printf("Loading %s:", filename);
-   gimp_progress_init(tmp);
-   g_free(tmp);
-
-   /* read header */
-   read_header(&hdr, fp);
-
-   memset(&dx10hdr, 0, sizeof(dds_header_dx10_t));
-
-   /* read DX10 header if necessary */
-   if(GETL32(hdr.pixelfmt.fourcc) == FOURCC('D','X','1','0'))
-   {
+  gint32 image = 0;
+  unsigned char *buf;
+  unsigned int l = 0;
+  guchar *pixels;
+  gchar *tmp;
+  FILE *fp;
+  dds_header_t hdr;
+  dds_header_dx10_t dx10hdr;
+  dds_load_info_t d;
+  gint *layers, layer_count;
+  GimpImageBaseType type;
+  int i, j;
+
+  if (interactive_dds)
+    {
+      if (!load_dialog ())
+        return (GIMP_PDB_CANCEL);
+    }
+
+  fp = g_fopen (filename, "rb");
+  if (fp == 0)
+    {
+      g_message ("Error opening file.\n");
+      return (GIMP_PDB_EXECUTION_ERROR);
+    }
+
+  if (strrchr (filename, '/'))
+    tmp = g_strdup_printf ("Loading %s:", strrchr (filename, '/') + 1);
+  else
+    tmp = g_strdup_printf ("Loading %s:", filename);
+  gimp_progress_init (tmp);
+  g_free (tmp);
+
+  /* read header */
+  read_header (&hdr, fp);
+
+  memset (&dx10hdr, 0, sizeof (dds_header_dx10_t));
+
+  /* read DX10 header if necessary */
+  if (GETL32(hdr.pixelfmt.fourcc) == FOURCC ('D','X','1','0'))
+    {
       read_header_dx10(&dx10hdr, fp);
 
-      if(!setup_dxgi_format(&hdr, &dx10hdr))
-      {
-         fclose(fp);
-         return(GIMP_PDB_EXECUTION_ERROR);
-      }
-   }
-
-   if(!validate_header(&hdr))
-   {
-      fclose(fp);
-      g_message("Invalid DDS header!\n");
-      return(GIMP_PDB_EXECUTION_ERROR);
-   }
-
-   /* a lot of DDS images out there don't have this for some reason -_- */
-   if(hdr.pitch_or_linsize == 0)
-   {
-      if(hdr.pixelfmt.flags & DDPF_FOURCC) /* assume linear size */
-      {
-         hdr.pitch_or_linsize = ((hdr.width + 3) >> 2) * ((hdr.height + 3) >> 2);
-         switch(GETL32(hdr.pixelfmt.fourcc))
-         {
-            case FOURCC('D','X','T','1'):
-            case FOURCC('A','T','I','1'):
-            case FOURCC('B','C','4','U'):
-            case FOURCC('B','C','4','S'):
-               hdr.pitch_or_linsize *= 8;
-               break;
+      if (!setup_dxgi_format (&hdr, &dx10hdr))
+        {
+          fclose (fp);
+          return (GIMP_PDB_EXECUTION_ERROR);
+        }
+    }
+
+  if (!validate_header (&hdr))
+    {
+      fclose (fp);
+      g_message ("Invalid DDS header!\n");
+      return (GIMP_PDB_EXECUTION_ERROR);
+    }
+
+  /* a lot of DDS images out there don't have this for some reason -_- */
+  if (hdr.pitch_or_linsize == 0)
+    {
+      if (hdr.pixelfmt.flags & DDPF_FOURCC) /* assume linear size */
+        {
+          hdr.pitch_or_linsize = ((hdr.width + 3) >> 2) * ((hdr.height + 3) >> 2);
+          switch (GETL32(hdr.pixelfmt.fourcc))
+            {
+            case FOURCC ('D','X','T','1'):
+            case FOURCC ('A','T','I','1'):
+            case FOURCC ('B','C','4','U'):
+            case FOURCC ('B','C','4','S'):
+              hdr.pitch_or_linsize *= 8;
+              break;
             default:
-               hdr.pitch_or_linsize *= 16;
-               break;
-         }
-      }
+              hdr.pitch_or_linsize *= 16;
+              break;
+            }
+        }
       else /* assume pitch */
-      {
-         hdr.pitch_or_linsize = hdr.height * hdr.width * (hdr.pixelfmt.bpp >> 3);
-      }
-   }
+        {
+          hdr.pitch_or_linsize = hdr.height * hdr.width * (hdr.pixelfmt.bpp >> 3);
+        }
+    }
 
-   if(hdr.pixelfmt.flags & DDPF_FOURCC)
-   {
+  if (hdr.pixelfmt.flags & DDPF_FOURCC)
+    {
       /* fourcc is dXt* or rXgb */
-      if(hdr.pixelfmt.fourcc[1] == 'X')
-         hdr.pixelfmt.flags |= DDPF_ALPHAPIXELS;
-   }
-
-   if(hdr.pixelfmt.flags & DDPF_FOURCC)
-   {
-      switch(GETL32(hdr.pixelfmt.fourcc))
-      {
-         case FOURCC('A','T','I','1'):
-         case FOURCC('B','C','4','U'):
-         case FOURCC('B','C','4','S'):
-            d.bpp = d.gimp_bpp = 1;
-            type = GIMP_GRAY;
-            break;
-         case FOURCC('A','T','I','2'):
-         case FOURCC('B','C','5','U'):
-         case FOURCC('B','C','5','S'):
-            d.bpp = d.gimp_bpp = 3;
-            type = GIMP_RGB;
-            break;
-         default:
-            d.bpp = d.gimp_bpp = 4;
-            type = GIMP_RGB;
-            break;
-      }
-   }
-   else
-   {
+      if (hdr.pixelfmt.fourcc[1] == 'X')
+        hdr.pixelfmt.flags |= DDPF_ALPHAPIXELS;
+    }
+
+  if (hdr.pixelfmt.flags & DDPF_FOURCC)
+    {
+      switch (GETL32(hdr.pixelfmt.fourcc))
+        {
+        case FOURCC ('A','T','I','1'):
+        case FOURCC ('B','C','4','U'):
+        case FOURCC ('B','C','4','S'):
+          d.bpp = d.gimp_bpp = 1;
+          type = GIMP_GRAY;
+          break;
+        case FOURCC ('A','T','I','2'):
+        case FOURCC ('B','C','5','U'):
+        case FOURCC ('B','C','5','S'):
+          d.bpp = d.gimp_bpp = 3;
+          type = GIMP_RGB;
+          break;
+        default:
+          d.bpp = d.gimp_bpp = 4;
+          type = GIMP_RGB;
+          break;
+        }
+    }
+  else
+    {
       d.bpp = hdr.pixelfmt.bpp >> 3;
 
-      if(d.bpp == 2)
-      {
-         if(hdr.pixelfmt.amask == 0xf000) // RGBA4
-         {
-            d.gimp_bpp = 4;
-            type = GIMP_RGB;
-         }
-         else if(hdr.pixelfmt.amask == 0xff00) //L8A8
-         {
-            d.gimp_bpp = 2;
-            type = GIMP_GRAY;
-         }
-         else if(hdr.pixelfmt.bmask == 0x1f) //R5G6B5 or RGB5A1
-         {
-            if(hdr.pixelfmt.amask == 0x8000) // RGB5A1
-               d.gimp_bpp = 4;
-            else
-               d.gimp_bpp = 3;
-
-            type = GIMP_RGB;
-         }
-         else //L16
-         {
-            d.gimp_bpp = 1;
-            type = GIMP_GRAY;
-         }
-      }
+      if (d.bpp == 2)
+        {
+          if (hdr.pixelfmt.amask == 0xf000) // RGBA4
+            {
+              d.gimp_bpp = 4;
+              type = GIMP_RGB;
+            }
+          else if (hdr.pixelfmt.amask == 0xff00) //L8A8
+            {
+              d.gimp_bpp = 2;
+              type = GIMP_GRAY;
+            }
+          else if (hdr.pixelfmt.bmask == 0x1f) //R5G6B5 or RGB5A1
+            {
+              if (hdr.pixelfmt.amask == 0x8000) // RGB5A1
+                d.gimp_bpp = 4;
+              else
+                d.gimp_bpp = 3;
+
+              type = GIMP_RGB;
+            }
+          else //L16
+            {
+              d.gimp_bpp = 1;
+              type = GIMP_GRAY;
+            }
+        }
       else
-      {
-         if(hdr.pixelfmt.flags & DDPF_PALETTEINDEXED8)
-         {
-            type = GIMP_INDEXED;
-            d.gimp_bpp = 1;
-         }
-         else if(hdr.pixelfmt.rmask == 0xe0) // R3G3B2
-         {
-            type = GIMP_RGB;
-            d.gimp_bpp = 3;
-         }
-         else
-         {
-            /* test alpha only image */
-            if(d.bpp == 1 && (hdr.pixelfmt.flags & DDPF_ALPHA))
+        {
+          if (hdr.pixelfmt.flags & DDPF_PALETTEINDEXED8)
+            {
+              type = GIMP_INDEXED;
+              d.gimp_bpp = 1;
+            }
+          else if (hdr.pixelfmt.rmask == 0xe0) // R3G3B2
             {
-               d.gimp_bpp = 2;
-               type = GIMP_GRAY;
+              type = GIMP_RGB;
+              d.gimp_bpp = 3;
             }
-            else
+          else
             {
-               d.gimp_bpp = d.bpp;
-               type = (d.bpp == 1) ? GIMP_GRAY : GIMP_RGB;
+              /* test alpha only image */
+              if (d.bpp == 1 && (hdr.pixelfmt.flags & DDPF_ALPHA))
+                {
+                  d.gimp_bpp = 2;
+                  type = GIMP_GRAY;
+                }
+              else
+                {
+                  d.gimp_bpp = d.bpp;
+                  type = (d.bpp == 1) ? GIMP_GRAY : GIMP_RGB;
+                }
             }
-         }
-      }
-   }
-
-   image = gimp_image_new(hdr.width, hdr.height, type);
-
-   if(image == -1)
-   {
-      g_message("Can't allocate new image.\n");
-      fclose(fp);
-      return(GIMP_PDB_EXECUTION_ERROR);
-   }
-
-   gimp_image_set_filename(image, filename);
-
-   if(hdr.pixelfmt.flags & DDPF_PALETTEINDEXED8)
-   {
-      d.palette = g_malloc(256 * 4);
-      if(fread(d.palette, 1, 1024, fp) != 1024)
-      {
-         g_message("Error reading palette.\n");
-         fclose(fp);
-         gimp_image_delete(image);
-         return(GIMP_PDB_EXECUTION_ERROR);
-      }
-      for(i = j = 0; i < 768; i += 3, j += 4)
-      {
-         d.palette[i + 0] = d.palette[j + 0];
-         d.palette[i + 1] = d.palette[j + 1];
-         d.palette[i + 2] = d.palette[j + 2];
-      }
-      gimp_image_set_colormap(image, d.palette, 256);
-   }
-
-   d.tile_height = gimp_tile_height();
-
-   pixels = g_new(guchar, d.tile_height * hdr.width * d.gimp_bpp);
-   buf = g_malloc(hdr.pitch_or_linsize);
-
-   d.rshift = color_shift(hdr.pixelfmt.rmask);
-   d.gshift = color_shift(hdr.pixelfmt.gmask);
-   d.bshift = color_shift(hdr.pixelfmt.bmask);
-   d.ashift = color_shift(hdr.pixelfmt.amask);
-   d.rbits = color_bits(hdr.pixelfmt.rmask);
-   d.gbits = color_bits(hdr.pixelfmt.gmask);
-   d.bbits = color_bits(hdr.pixelfmt.bmask);
-   d.abits = color_bits(hdr.pixelfmt.amask);
-   d.rmask = (hdr.pixelfmt.rmask >> d.rshift) << (8 - d.rbits);
-   d.gmask = (hdr.pixelfmt.gmask >> d.gshift) << (8 - d.gbits);
-   d.bmask = (hdr.pixelfmt.bmask >> d.bshift) << (8 - d.bbits);
-   d.amask = (hdr.pixelfmt.amask >> d.ashift) << (8 - d.abits);
-
-   if(!(hdr.caps.caps2 & DDSCAPS2_CUBEMAP) &&
+        }
+    }
+
+  image = gimp_image_new (hdr.width, hdr.height, type);
+
+  if (image == -1)
+    {
+      g_message ("Can't allocate new image.\n");
+      fclose (fp);
+      return (GIMP_PDB_EXECUTION_ERROR);
+    }
+
+  gimp_image_set_filename (image, filename);
+
+  if (hdr.pixelfmt.flags & DDPF_PALETTEINDEXED8)
+    {
+      d.palette = g_malloc (256 * 4);
+      if (fread (d.palette, 1, 1024, fp) != 1024)
+        {
+          g_message ("Error reading palette.\n");
+          fclose (fp);
+          gimp_image_delete (image);
+          return (GIMP_PDB_EXECUTION_ERROR);
+        }
+      for (i = j = 0; i < 768; i += 3, j += 4)
+        {
+          d.palette[i + 0] = d.palette[j + 0];
+          d.palette[i + 1] = d.palette[j + 1];
+          d.palette[i + 2] = d.palette[j + 2];
+        }
+      gimp_image_set_colormap (image, d.palette, 256);
+    }
+
+  d.tile_height = gimp_tile_height ();
+
+  pixels = g_new (guchar, d.tile_height * hdr.width * d.gimp_bpp);
+  buf = g_malloc (hdr.pitch_or_linsize);
+
+  d.rshift = color_shift (hdr.pixelfmt.rmask);
+  d.gshift = color_shift (hdr.pixelfmt.gmask);
+  d.bshift = color_shift (hdr.pixelfmt.bmask);
+  d.ashift = color_shift (hdr.pixelfmt.amask);
+  d.rbits = color_bits (hdr.pixelfmt.rmask);
+  d.gbits = color_bits (hdr.pixelfmt.gmask);
+  d.bbits = color_bits (hdr.pixelfmt.bmask);
+  d.abits = color_bits (hdr.pixelfmt.amask);
+  d.rmask = (hdr.pixelfmt.rmask >> d.rshift) << (8 - d.rbits);
+  d.gmask = (hdr.pixelfmt.gmask >> d.gshift) << (8 - d.gbits);
+  d.bmask = (hdr.pixelfmt.bmask >> d.bshift) << (8 - d.bbits);
+  d.amask = (hdr.pixelfmt.amask >> d.ashift) << (8 - d.abits);
+
+  if (!(hdr.caps.caps2 & DDSCAPS2_CUBEMAP) &&
       !(hdr.caps.caps2 & DDSCAPS2_VOLUME) &&
       dx10hdr.arraySize == 0)
-   {
-      if(!load_layer(fp, &hdr, &d, image, 0, "", &l, pixels, buf))
-      {
-         fclose(fp);
-         gimp_image_delete(image);
-         return(GIMP_PDB_EXECUTION_ERROR);
-      }
-      if(!load_mipmaps(fp, &hdr, &d, image, "", &l, pixels, buf))
-      {
-         fclose(fp);
-         gimp_image_delete(image);
-         return(GIMP_PDB_EXECUTION_ERROR);
-      }
-   }
-   else if(hdr.caps.caps2 & DDSCAPS2_CUBEMAP)
-   {
-      if((hdr.caps.caps2 & DDSCAPS2_CUBEMAP_POSITIVEX) &&
-         !load_face(fp, &hdr, &d, image, "(positive x)", &l, pixels, buf))
-      {
-         fclose(fp);
-         gimp_image_delete(image);
-         return(GIMP_PDB_EXECUTION_ERROR);
-      }
-      if((hdr.caps.caps2 & DDSCAPS2_CUBEMAP_NEGATIVEX) &&
-         !load_face(fp, &hdr, &d, image, "(negative x)", &l, pixels, buf))
-      {
-         fclose(fp);
-         gimp_image_delete(image);
-         return(GIMP_PDB_EXECUTION_ERROR);
-      }
-      if((hdr.caps.caps2 & DDSCAPS2_CUBEMAP_POSITIVEY) &&
-         !load_face(fp, &hdr, &d, image, "(positive y)", &l, pixels, buf))
-      {
-         fclose(fp);
-         gimp_image_delete(image);
-         return(GIMP_PDB_EXECUTION_ERROR);
-      }
-      if((hdr.caps.caps2 & DDSCAPS2_CUBEMAP_NEGATIVEY) &&
-         !load_face(fp, &hdr, &d, image, "(negative y)", &l, pixels, buf))
-      {
-         fclose(fp);
-         gimp_image_delete(image);
-         return(GIMP_PDB_EXECUTION_ERROR);
-      }
-      if((hdr.caps.caps2 & DDSCAPS2_CUBEMAP_POSITIVEZ) &&
-         !load_face(fp, &hdr, &d, image, "(positive z)", &l, pixels, buf))
-      {
-         fclose(fp);
-         gimp_image_delete(image);
-         return(GIMP_PDB_EXECUTION_ERROR);
-      }
-      if((hdr.caps.caps2 & DDSCAPS2_CUBEMAP_NEGATIVEZ) &&
-         !load_face(fp, &hdr, &d, image, "(negative z)", &l, pixels, buf))
-      {
-         fclose(fp);
-         gimp_image_delete(image);
-         return(GIMP_PDB_EXECUTION_ERROR);
-      }
-   }
-   else if((hdr.caps.caps2 & DDSCAPS2_VOLUME) &&
-            (hdr.flags & DDSD_DEPTH))
-   {
+    {
+      if (!load_layer (fp, &hdr, &d, image, 0, "", &l, pixels, buf))
+        {
+          fclose (fp);
+          gimp_image_delete (image);
+          return (GIMP_PDB_EXECUTION_ERROR);
+        }
+      if (!load_mipmaps (fp, &hdr, &d, image, "", &l, pixels, buf))
+        {
+          fclose (fp);
+          gimp_image_delete (image);
+          return (GIMP_PDB_EXECUTION_ERROR);
+        }
+    }
+  else if (hdr.caps.caps2 & DDSCAPS2_CUBEMAP)
+    {
+      if ((hdr.caps.caps2 & DDSCAPS2_CUBEMAP_POSITIVEX) &&
+          !load_face (fp, &hdr, &d, image, "(positive x)", &l, pixels, buf))
+        {
+          fclose (fp);
+          gimp_image_delete (image);
+          return (GIMP_PDB_EXECUTION_ERROR);
+        }
+      if ((hdr.caps.caps2 & DDSCAPS2_CUBEMAP_NEGATIVEX) &&
+          !load_face (fp, &hdr, &d, image, "(negative x)", &l, pixels, buf))
+        {
+          fclose (fp);
+          gimp_image_delete (image);
+          return (GIMP_PDB_EXECUTION_ERROR);
+        }
+      if ((hdr.caps.caps2 & DDSCAPS2_CUBEMAP_POSITIVEY) &&
+          !load_face (fp, &hdr, &d, image, "(positive y)", &l, pixels, buf))
+        {
+          fclose (fp);
+          gimp_image_delete (image);
+          return (GIMP_PDB_EXECUTION_ERROR);
+        }
+      if ((hdr.caps.caps2 & DDSCAPS2_CUBEMAP_NEGATIVEY) &&
+          !load_face (fp, &hdr, &d, image, "(negative y)", &l, pixels, buf))
+        {
+          fclose (fp);
+          gimp_image_delete (image);
+          return (GIMP_PDB_EXECUTION_ERROR);
+        }
+      if ((hdr.caps.caps2 & DDSCAPS2_CUBEMAP_POSITIVEZ) &&
+          !load_face (fp, &hdr, &d, image, "(positive z)", &l, pixels, buf))
+        {
+          fclose (fp);
+          gimp_image_delete (image);
+          return (GIMP_PDB_EXECUTION_ERROR);
+        }
+      if ((hdr.caps.caps2 & DDSCAPS2_CUBEMAP_NEGATIVEZ) &&
+          !load_face (fp, &hdr, &d, image, "(negative z)", &l, pixels, buf))
+        {
+          fclose (fp);
+          gimp_image_delete (image);
+          return (GIMP_PDB_EXECUTION_ERROR);
+        }
+    }
+  else if ((hdr.caps.caps2 & DDSCAPS2_VOLUME) &&
+           (hdr.flags & DDSD_DEPTH))
+    {
       unsigned int i, level;
       char *plane;
-      for(i = 0; i < hdr.depth; ++i)
-      {
-         plane = g_strdup_printf("(z = %d)", i);
-         if(!load_layer(fp, &hdr, &d, image, 0, plane, &l, pixels, buf))
-         {
-            g_free(plane);
-            fclose(fp);
-            gimp_image_delete(image);
-            return(GIMP_PDB_EXECUTION_ERROR);
-         }
-         g_free(plane);
-      }
-
-      if((hdr.flags & DDSD_MIPMAPCOUNT) &&
-         (hdr.caps.caps1 & DDSCAPS_MIPMAP) &&
-         (dds_read_vals.mipmaps != 0))
-      {
-         for(level = 1; level < hdr.num_mipmaps; ++level)
-         {
-            int n = hdr.depth >> level;
-            if(n < 1) n = 1;
-            for(i = 0; i < n; ++i)
+      for (i = 0; i < hdr.depth; ++i)
+        {
+          plane = g_strdup_printf ("(z = %d)", i);
+          if (!load_layer (fp, &hdr, &d, image, 0, plane, &l, pixels, buf))
             {
-               plane = g_strdup_printf("(z = %d)", i);
-               if(!load_layer(fp, &hdr, &d, image, level, plane, &l, pixels, buf))
-               {
-                  g_free(plane);
-                  fclose(fp);
-                  gimp_image_delete(image);
-                  return(GIMP_PDB_EXECUTION_ERROR);
-               }
-               g_free(plane);
+              g_free (plane);
+              fclose (fp);
+              gimp_image_delete (image);
+              return (GIMP_PDB_EXECUTION_ERROR);
             }
-         }
-      }
-   }
-   else if(dx10hdr.arraySize > 0)
-   {
+          g_free (plane);
+        }
+
+      if ((hdr.flags & DDSD_MIPMAPCOUNT) &&
+          (hdr.caps.caps1 & DDSCAPS_MIPMAP) &&
+          (dds_read_vals.mipmaps != 0))
+        {
+          for (level = 1; level < hdr.num_mipmaps; ++level)
+            {
+              int n = hdr.depth >> level;
+              if (n < 1) n = 1;
+              for (i = 0; i < n; ++i)
+                {
+                  plane = g_strdup_printf ("(z = %d)", i);
+                  if (!load_layer (fp, &hdr, &d, image, level, plane, &l, pixels, buf))
+                    {
+                      g_free (plane);
+                      fclose (fp);
+                      gimp_image_delete (image);
+                      return (GIMP_PDB_EXECUTION_ERROR);
+                    }
+                  g_free (plane);
+                }
+            }
+        }
+    }
+  else if (dx10hdr.arraySize > 0)
+    {
       unsigned int i;
       char *elem;
 
-      for(i = 0; i < dx10hdr.arraySize; ++i)
-      {
-         elem = g_strdup_printf("(array element %d)", i);
-         if(!load_layer(fp, &hdr, &d, image, 0, elem, &l, pixels, buf))
-         {
-            fclose(fp);
-            gimp_image_delete(image);
-            return(GIMP_PDB_EXECUTION_ERROR);
-         }
-         if(!load_mipmaps(fp, &hdr, &d, image, elem, &l, pixels, buf))
-         {
-            fclose(fp);
-            gimp_image_delete(image);
-            return(GIMP_PDB_EXECUTION_ERROR);
-         }
-         g_free(elem);
-      }
-   }
-
-   gimp_progress_update(1.0);
-
-   if(hdr.pixelfmt.flags & DDPF_PALETTEINDEXED8)
-      g_free(d.palette);
-
-   g_free(buf);
-   g_free(pixels);
-   fclose(fp);
-
-   layers = gimp_image_get_layers(image, &layer_count);
-
-   if(layers == NULL || layer_count == 0)
-   {
-      g_message("Oops!  NULL image read!  Please report this!");
-      return(GIMP_PDB_EXECUTION_ERROR);
-   }
-
-   gimp_image_set_active_layer(image, layers[0]);
-   g_free (layers);
-
-   *imageID = image;
-
-   return(GIMP_PDB_SUCCESS);
+      for (i = 0; i < dx10hdr.arraySize; ++i)
+        {
+          elem = g_strdup_printf ("(array element %d)", i);
+          if (!load_layer (fp, &hdr, &d, image, 0, elem, &l, pixels, buf))
+            {
+              fclose (fp);
+              gimp_image_delete (image);
+              return (GIMP_PDB_EXECUTION_ERROR);
+            }
+          if (!load_mipmaps (fp, &hdr, &d, image, elem, &l, pixels, buf))
+            {
+              fclose (fp);
+              gimp_image_delete (image);
+              return (GIMP_PDB_EXECUTION_ERROR);
+            }
+          g_free (elem);
+        }
+    }
+
+  gimp_progress_update (1.0);
+
+  if (hdr.pixelfmt.flags & DDPF_PALETTEINDEXED8)
+    g_free (d.palette);
+
+  g_free (buf);
+  g_free (pixels);
+  fclose (fp);
+
+  layers = gimp_image_get_layers (image, &layer_count);
+
+  if (layers == NULL || layer_count == 0)
+    {
+      g_message ("Oops!  NULL image read!  Please report this!");
+      return (GIMP_PDB_EXECUTION_ERROR);
+    }
+
+  gimp_image_set_active_layer (image, layers[0]);
+  g_free (layers);
+
+  *imageID = image;
+
+  return (GIMP_PDB_SUCCESS);
 }
 
-static int read_header(dds_header_t *hdr, FILE *fp)
+static int
+read_header (dds_header_t *hdr,
+             FILE         *fp)
 {
-   unsigned char buf[DDS_HEADERSIZE];
-
-   memset(hdr, 0, sizeof(dds_header_t));
-
-   if(fread(buf, 1, DDS_HEADERSIZE, fp) != DDS_HEADERSIZE)
-      return(0);
-
-   hdr->magic = GETL32(buf);
-
-   hdr->size = GETL32(buf + 4);
-   hdr->flags = GETL32(buf + 8);
-   hdr->height = GETL32(buf + 12);
-   hdr->width = GETL32(buf + 16);
-   hdr->pitch_or_linsize = GETL32(buf + 20);
-   hdr->depth = GETL32(buf + 24);
-   hdr->num_mipmaps = GETL32(buf + 28);
-
-   hdr->pixelfmt.size = GETL32(buf + 76);
-   hdr->pixelfmt.flags = GETL32(buf + 80);
-   hdr->pixelfmt.fourcc[0] = buf[84];
-   hdr->pixelfmt.fourcc[1] = buf[85];
-   hdr->pixelfmt.fourcc[2] = buf[86];
-   hdr->pixelfmt.fourcc[3] = buf[87];
-   hdr->pixelfmt.bpp = GETL32(buf + 88);
-   hdr->pixelfmt.rmask = GETL32(buf + 92);
-   hdr->pixelfmt.gmask = GETL32(buf + 96);
-   hdr->pixelfmt.bmask = GETL32(buf + 100);
-   hdr->pixelfmt.amask = GETL32(buf + 104);
-
-   hdr->caps.caps1 = GETL32(buf + 108);
-   hdr->caps.caps2 = GETL32(buf + 112);
-
-   /* GIMP-DDS special info */
-   if(GETL32(buf + 32) == FOURCC('G','I','M','P') &&
-      GETL32(buf + 36) == FOURCC('-','D','D','S'))
-   {
+  unsigned char buf[DDS_HEADERSIZE];
+
+  memset (hdr, 0, sizeof (dds_header_t));
+
+  if (fread (buf, 1, DDS_HEADERSIZE, fp) != DDS_HEADERSIZE)
+    return (0);
+
+  hdr->magic = GETL32(buf);
+
+  hdr->size = GETL32(buf + 4);
+  hdr->flags = GETL32(buf + 8);
+  hdr->height = GETL32(buf + 12);
+  hdr->width = GETL32(buf + 16);
+  hdr->pitch_or_linsize = GETL32(buf + 20);
+  hdr->depth = GETL32(buf + 24);
+  hdr->num_mipmaps = GETL32(buf + 28);
+
+  hdr->pixelfmt.size = GETL32(buf + 76);
+  hdr->pixelfmt.flags = GETL32(buf + 80);
+  hdr->pixelfmt.fourcc[0] = buf[84];
+  hdr->pixelfmt.fourcc[1] = buf[85];
+  hdr->pixelfmt.fourcc[2] = buf[86];
+  hdr->pixelfmt.fourcc[3] = buf[87];
+  hdr->pixelfmt.bpp = GETL32(buf + 88);
+  hdr->pixelfmt.rmask = GETL32(buf + 92);
+  hdr->pixelfmt.gmask = GETL32(buf + 96);
+  hdr->pixelfmt.bmask = GETL32(buf + 100);
+  hdr->pixelfmt.amask = GETL32(buf + 104);
+
+  hdr->caps.caps1 = GETL32(buf + 108);
+  hdr->caps.caps2 = GETL32(buf + 112);
+
+  /* GIMP-DDS special info */
+  if (GETL32(buf + 32) == FOURCC ('G','I','M','P') &&
+      GETL32(buf + 36) == FOURCC ('-','D','D','S'))
+    {
       hdr->reserved.gimp_dds_special.magic1 = GETL32(buf + 32);
       hdr->reserved.gimp_dds_special.magic2 = GETL32(buf + 36);
       hdr->reserved.gimp_dds_special.version = GETL32(buf + 40);
       hdr->reserved.gimp_dds_special.extra_fourcc = GETL32(buf + 44);
-   }
+    }
 
-   return(1);
+  return (1);
 }
 
-static int read_header_dx10(dds_header_dx10_t *hdr, FILE *fp)
+static int
+read_header_dx10(dds_header_dx10_t *hdr,
+                 FILE              *fp)
 {
-   char buf[DDS_HEADERSIZE_DX10];
+  char buf[DDS_HEADERSIZE_DX10];
 
-   memset(hdr, 0, sizeof(dds_header_dx10_t));
+  memset (hdr, 0, sizeof (dds_header_dx10_t));
 
-   if(fread(buf, 1, DDS_HEADERSIZE_DX10, fp) != DDS_HEADERSIZE_DX10)
-      return(0);
+  if (fread (buf, 1, DDS_HEADERSIZE_DX10, fp) != DDS_HEADERSIZE_DX10)
+    return (0);
 
-   hdr->dxgiFormat = GETL32(buf);
-   hdr->resourceDimension = GETL32(buf + 4);
-   hdr->miscFlag = GETL32(buf + 8);
-   hdr->arraySize = GETL32(buf + 12);
-   hdr->reserved = GETL32(buf + 16);
+  hdr->dxgiFormat = GETL32(buf);
+  hdr->resourceDimension = GETL32(buf + 4);
+  hdr->miscFlag = GETL32(buf + 8);
+  hdr->arraySize = GETL32(buf + 12);
+  hdr->reserved = GETL32(buf + 16);
 
-   return(1);
+  return (1);
 }
 
-static int validate_header(dds_header_t *hdr)
+static int
+validate_header (dds_header_t *hdr)
 {
-   unsigned int fourcc;
-
-   if(hdr->magic != FOURCC('D','D','S',' '))
-   {
-      g_message("Invalid DDS file.\n");
-      return(0);
-   }
-
-   if((hdr->flags & DDSD_PITCH) == (hdr->flags & DDSD_LINEARSIZE))
-   {
-      //g_message("Warning: DDSD_PITCH or DDSD_LINEARSIZE is not set.\n");
-      if(hdr->pixelfmt.flags & DDPF_FOURCC)
-         hdr->flags |= DDSD_LINEARSIZE;
+  unsigned int fourcc;
+
+  if (hdr->magic != FOURCC ('D','D','S',' '))
+    {
+      g_message ("Invalid DDS file.\n");
+      return (0);
+    }
+
+  if ((hdr->flags & DDSD_PITCH) == (hdr->flags & DDSD_LINEARSIZE))
+    {
+      //g_message ("Warning: DDSD_PITCH or DDSD_LINEARSIZE is not set.\n");
+      if (hdr->pixelfmt.flags & DDPF_FOURCC)
+        hdr->flags |= DDSD_LINEARSIZE;
       else
-         hdr->flags |= DDSD_PITCH;
-   }
-/*
-   if((hdr->pixelfmt.flags & DDPF_FOURCC) ==
-      (hdr->pixelfmt.flags & DDPF_RGB))
-   {
-      g_message("Invalid pixel format.\n");
-      return(0);
-   }
-*/
-   fourcc = GETL32(hdr->pixelfmt.fourcc);
-
-   if((hdr->pixelfmt.flags & DDPF_FOURCC) &&
-      fourcc != FOURCC('D','X','T','1') &&
-      fourcc != FOURCC('D','X','T','2') &&
-      fourcc != FOURCC('D','X','T','3') &&
-      fourcc != FOURCC('D','X','T','4') &&
-      fourcc != FOURCC('D','X','T','5') &&
-      fourcc != FOURCC('R','X','G','B') &&
-      fourcc != FOURCC('A','T','I','1') &&
-      fourcc != FOURCC('B','C','4','U') &&
-      fourcc != FOURCC('B','C','4','S') &&
-      fourcc != FOURCC('A','T','I','2') &&
-      fourcc != FOURCC('B','C','5','U') &&
-      fourcc != FOURCC('B','C','5','S') &&
-      fourcc != FOURCC('D','X','1','0'))
-   {
-      g_message("Unsupported format (FOURCC: %c%c%c%c, hex: %08x).\n",
-                hdr->pixelfmt.fourcc[0],
-                hdr->pixelfmt.fourcc[1],
-                hdr->pixelfmt.fourcc[2],
-                hdr->pixelfmt.fourcc[3],
-                GETL32(hdr->pixelfmt.fourcc));
-      return(0);
-   }
-
-   if(hdr->pixelfmt.flags & DDPF_RGB)
-   {
-      if((hdr->pixelfmt.bpp !=  8) &&
-         (hdr->pixelfmt.bpp != 16) &&
-         (hdr->pixelfmt.bpp != 24) &&
-         (hdr->pixelfmt.bpp != 32))
-      {
-         g_message("Invalid BPP.\n");
-         return(0);
-      }
-   }
-   else if(hdr->pixelfmt.flags & DDPF_LUMINANCE)
-   {
-      if((hdr->pixelfmt.bpp !=  8) &&
-         (hdr->pixelfmt.bpp != 16))
-      {
-         g_message("Invalid BPP.\n");
-         return(0);
-      }
+        hdr->flags |= DDSD_PITCH;
+    }
+  /*
+     if ((hdr->pixelfmt.flags & DDPF_FOURCC) ==
+     (hdr->pixelfmt.flags & DDPF_RGB))
+     {
+     g_message ("Invalid pixel format.\n");
+     return (0);
+     }
+     */
+  fourcc = GETL32(hdr->pixelfmt.fourcc);
+
+  if ((hdr->pixelfmt.flags & DDPF_FOURCC) &&
+      fourcc != FOURCC ('D','X','T','1') &&
+      fourcc != FOURCC ('D','X','T','2') &&
+      fourcc != FOURCC ('D','X','T','3') &&
+      fourcc != FOURCC ('D','X','T','4') &&
+      fourcc != FOURCC ('D','X','T','5') &&
+      fourcc != FOURCC ('R','X','G','B') &&
+      fourcc != FOURCC ('A','T','I','1') &&
+      fourcc != FOURCC ('B','C','4','U') &&
+      fourcc != FOURCC ('B','C','4','S') &&
+      fourcc != FOURCC ('A','T','I','2') &&
+      fourcc != FOURCC ('B','C','5','U') &&
+      fourcc != FOURCC ('B','C','5','S') &&
+      fourcc != FOURCC ('D','X','1','0'))
+    {
+      g_message ("Unsupported format (FOURCC: %c%c%c%c, hex: %08x).\n",
+                 hdr->pixelfmt.fourcc[0],
+                 hdr->pixelfmt.fourcc[1],
+                 hdr->pixelfmt.fourcc[2],
+                 hdr->pixelfmt.fourcc[3],
+                 GETL32(hdr->pixelfmt.fourcc));
+      return (0);
+    }
+
+  if (hdr->pixelfmt.flags & DDPF_RGB)
+    {
+      if ((hdr->pixelfmt.bpp !=  8) &&
+          (hdr->pixelfmt.bpp != 16) &&
+          (hdr->pixelfmt.bpp != 24) &&
+          (hdr->pixelfmt.bpp != 32))
+        {
+          g_message ("Invalid BPP.\n");
+          return (0);
+        }
+    }
+  else if (hdr->pixelfmt.flags & DDPF_LUMINANCE)
+    {
+      if ((hdr->pixelfmt.bpp !=  8) &&
+          (hdr->pixelfmt.bpp != 16))
+        {
+          g_message ("Invalid BPP.\n");
+          return (0);
+        }
 
       hdr->pixelfmt.flags |= DDPF_RGB;
-   }
-   else if(hdr->pixelfmt.flags & DDPF_PALETTEINDEXED8)
-   {
+    }
+  else if (hdr->pixelfmt.flags & DDPF_PALETTEINDEXED8)
+    {
       hdr->pixelfmt.flags |= DDPF_RGB;
-   }
+    }
 
-   if(!(hdr->pixelfmt.flags & DDPF_RGB) &&
+  if (!(hdr->pixelfmt.flags & DDPF_RGB) &&
       !(hdr->pixelfmt.flags & DDPF_ALPHA) &&
       !(hdr->pixelfmt.flags & DDPF_FOURCC) &&
       !(hdr->pixelfmt.flags & DDPF_LUMINANCE))
-   {
-      g_message("Unknown pixel format!  Taking a guess, expect trouble!");
-      switch(fourcc)
-      {
-         case FOURCC('D','X','T','1'):
-         case FOURCC('D','X','T','2'):
-         case FOURCC('D','X','T','3'):
-         case FOURCC('D','X','T','4'):
-         case FOURCC('D','X','T','5'):
-         case FOURCC('R','X','G','B'):
-         case FOURCC('A','T','I','1'):
-         case FOURCC('B','C','4','U'):
-         case FOURCC('B','C','4','S'):
-         case FOURCC('A','T','I','2'):
-         case FOURCC('B','C','5','U'):
-         case FOURCC('B','C','5','S'):
-            hdr->pixelfmt.flags |= DDPF_FOURCC;
-            break;
-         default:
-            switch(hdr->pixelfmt.bpp)
+    {
+      g_message ("Unknown pixel format!  Taking a guess, expect trouble!");
+      switch (fourcc)
+        {
+        case FOURCC ('D','X','T','1'):
+        case FOURCC ('D','X','T','2'):
+        case FOURCC ('D','X','T','3'):
+        case FOURCC ('D','X','T','4'):
+        case FOURCC ('D','X','T','5'):
+        case FOURCC ('R','X','G','B'):
+        case FOURCC ('A','T','I','1'):
+        case FOURCC ('B','C','4','U'):
+        case FOURCC ('B','C','4','S'):
+        case FOURCC ('A','T','I','2'):
+        case FOURCC ('B','C','5','U'):
+        case FOURCC ('B','C','5','S'):
+          hdr->pixelfmt.flags |= DDPF_FOURCC;
+          break;
+        default:
+          switch (hdr->pixelfmt.bpp)
             {
-               case 8:
-                  if(hdr->pixelfmt.flags & DDPF_ALPHAPIXELS)
-                     hdr->pixelfmt.flags |= DDPF_ALPHA;
-                  else
-                     hdr->pixelfmt.flags |= DDPF_LUMINANCE;
-                  break;
-               case 16:
-               case 24:
-               case 32:
-                  hdr->pixelfmt.flags |= DDPF_RGB;
-                  break;
-               default:
-                  g_message("Invalid pixel format.");
-                  return(0);
+            case 8:
+              if (hdr->pixelfmt.flags & DDPF_ALPHAPIXELS)
+                hdr->pixelfmt.flags |= DDPF_ALPHA;
+              else
+                hdr->pixelfmt.flags |= DDPF_LUMINANCE;
+              break;
+            case 16:
+            case 24:
+            case 32:
+              hdr->pixelfmt.flags |= DDPF_RGB;
+              break;
+            default:
+              g_message ("Invalid pixel format.");
+              return (0);
             }
-            break;
-      }
-   }
+          break;
+        }
+    }
 
-   return(1);
+  return (1);
 }
 
 /*
  * This function will set the necessary flags and attributes in the standard
  * dds header using the information found in the DX10 header.
  */
-static int setup_dxgi_format(dds_header_t *hdr, dds_header_dx10_t *dx10hdr)
+static int
+setup_dxgi_format (dds_header_t      *hdr,
+                   dds_header_dx10_t *dx10hdr)
 {
-   if((dx10hdr->resourceDimension == D3D10_RESOURCE_DIMENSION_TEXTURE2D) &&
+  if ((dx10hdr->resourceDimension == D3D10_RESOURCE_DIMENSION_TEXTURE2D) &&
       (dx10hdr->miscFlag & D3D10_RESOURCE_MISC_TEXTURECUBE))
-   {
+    {
       hdr->caps.caps2 |= DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALL_FACES;
-   }
-   else if(dx10hdr->resourceDimension == D3D10_RESOURCE_DIMENSION_TEXTURE3D)
-   {
+    }
+  else if (dx10hdr->resourceDimension == D3D10_RESOURCE_DIMENSION_TEXTURE3D)
+    {
       hdr->flags |= DDSD_DEPTH;
       hdr->caps.caps2 |= DDSCAPS2_VOLUME;
-   }
+    }
 
-   if((dx10hdr->resourceDimension != D3D10_RESOURCE_DIMENSION_TEXTURE1D) &&
+  if ((dx10hdr->resourceDimension != D3D10_RESOURCE_DIMENSION_TEXTURE1D) &&
       (dx10hdr->resourceDimension != D3D10_RESOURCE_DIMENSION_TEXTURE2D) &&
       (dx10hdr->resourceDimension != D3D10_RESOURCE_DIMENSION_TEXTURE3D))
-      return(0);
+    return (0);
 
-   // check for a compressed DXGI format
-   if((dx10hdr->dxgiFormat >= DXGI_FORMAT_BC1_TYPELESS) &&
+  // check for a compressed DXGI format
+  if ((dx10hdr->dxgiFormat >= DXGI_FORMAT_BC1_TYPELESS) &&
       (dx10hdr->dxgiFormat <= DXGI_FORMAT_BC5_SNORM))
-   {
+    {
       // set flag and replace FOURCC
       hdr->pixelfmt.flags |= DDPF_FOURCC;
 
-      switch(dx10hdr->dxgiFormat)
-      {
-         case DXGI_FORMAT_BC1_TYPELESS:
-         case DXGI_FORMAT_BC1_UNORM:
-         case DXGI_FORMAT_BC1_UNORM_SRGB:
-            PUTL32(hdr->pixelfmt.fourcc, FOURCC('D','X','T','1'));
-            break;
-         case DXGI_FORMAT_BC2_TYPELESS:
-         case DXGI_FORMAT_BC2_UNORM:
-         case DXGI_FORMAT_BC2_UNORM_SRGB:
-            PUTL32(hdr->pixelfmt.fourcc, FOURCC('D','X','T','3'));
-            break;
-         case DXGI_FORMAT_BC3_TYPELESS:
-         case DXGI_FORMAT_BC3_UNORM:
-         case DXGI_FORMAT_BC3_UNORM_SRGB:
-            PUTL32(hdr->pixelfmt.fourcc, FOURCC('D','X','T','5'));
-            break;
-         case DXGI_FORMAT_BC4_TYPELESS:
-         case DXGI_FORMAT_BC4_UNORM:
-            PUTL32(hdr->pixelfmt.fourcc, FOURCC('A','T','I','1'));
-            break;
-         case DXGI_FORMAT_BC4_SNORM:
-            PUTL32(hdr->pixelfmt.fourcc, FOURCC('B','C','4','S'));
-            break;
-         case DXGI_FORMAT_BC5_TYPELESS:
-         case DXGI_FORMAT_BC5_UNORM:
-            PUTL32(hdr->pixelfmt.fourcc, FOURCC('A','T','I','2'));
-            break;
-         case DXGI_FORMAT_BC5_SNORM:
-            PUTL32(hdr->pixelfmt.fourcc, FOURCC('B','C','5','S'));
-            break;
-         default:
-            break;
-      }
-   }
-   else
-   {
+      switch (dx10hdr->dxgiFormat)
+        {
+        case DXGI_FORMAT_BC1_TYPELESS:
+        case DXGI_FORMAT_BC1_UNORM:
+        case DXGI_FORMAT_BC1_UNORM_SRGB:
+          PUTL32(hdr->pixelfmt.fourcc, FOURCC ('D','X','T','1'));
+          break;
+        case DXGI_FORMAT_BC2_TYPELESS:
+        case DXGI_FORMAT_BC2_UNORM:
+        case DXGI_FORMAT_BC2_UNORM_SRGB:
+          PUTL32(hdr->pixelfmt.fourcc, FOURCC ('D','X','T','3'));
+          break;
+        case DXGI_FORMAT_BC3_TYPELESS:
+        case DXGI_FORMAT_BC3_UNORM:
+        case DXGI_FORMAT_BC3_UNORM_SRGB:
+          PUTL32(hdr->pixelfmt.fourcc, FOURCC ('D','X','T','5'));
+          break;
+        case DXGI_FORMAT_BC4_TYPELESS:
+        case DXGI_FORMAT_BC4_UNORM:
+          PUTL32(hdr->pixelfmt.fourcc, FOURCC ('A','T','I','1'));
+          break;
+        case DXGI_FORMAT_BC4_SNORM:
+          PUTL32(hdr->pixelfmt.fourcc, FOURCC ('B','C','4','S'));
+          break;
+        case DXGI_FORMAT_BC5_TYPELESS:
+        case DXGI_FORMAT_BC5_UNORM:
+          PUTL32(hdr->pixelfmt.fourcc, FOURCC ('A','T','I','2'));
+          break;
+        case DXGI_FORMAT_BC5_SNORM:
+          PUTL32(hdr->pixelfmt.fourcc, FOURCC ('B','C','5','S'));
+          break;
+        default:
+          break;
+        }
+    }
+  else
+    {
       /* unset the FOURCC flag */
       hdr->pixelfmt.flags &= ~DDPF_FOURCC;
 
-      switch(dx10hdr->dxgiFormat)
-      {
-         case DXGI_FORMAT_B8G8R8A8_TYPELESS:
-         case DXGI_FORMAT_B8G8R8A8_UNORM:
-         case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
-            hdr->pixelfmt.bpp = 32;
-            hdr->pixelfmt.flags |= DDPF_ALPHAPIXELS;
-            hdr->pixelfmt.rmask = 0x00ff0000;
-            hdr->pixelfmt.gmask = 0x0000ff00;
-            hdr->pixelfmt.bmask = 0x000000ff;
-            hdr->pixelfmt.amask = 0xff000000;
-            break;
-         case DXGI_FORMAT_B8G8R8X8_TYPELESS:
-         case DXGI_FORMAT_B8G8R8X8_UNORM:
-         case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
-            hdr->pixelfmt.bpp = 32;
-            hdr->pixelfmt.flags |= DDPF_ALPHAPIXELS;
-            hdr->pixelfmt.rmask = 0x00ff0000;
-            hdr->pixelfmt.gmask = 0x0000ff00;
-            hdr->pixelfmt.bmask = 0x000000ff;
-            hdr->pixelfmt.amask = 0x00000000;
-            break;
-         case DXGI_FORMAT_R8G8B8A8_TYPELESS:
-         case DXGI_FORMAT_R8G8B8A8_UNORM:
-         case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
-         case DXGI_FORMAT_R8G8B8A8_UINT:
-         case DXGI_FORMAT_R8G8B8A8_SNORM:
-         case DXGI_FORMAT_R8G8B8A8_SINT:
-            hdr->pixelfmt.bpp = 32;
-            hdr->pixelfmt.flags |= DDPF_ALPHAPIXELS;
-            hdr->pixelfmt.rmask = 0x000000ff;
-            hdr->pixelfmt.gmask = 0x0000ff00;
-            hdr->pixelfmt.bmask = 0x00ff0000;
-            hdr->pixelfmt.amask = 0xff000000;
-            break;
-         case DXGI_FORMAT_B5G6R5_UNORM:
-            hdr->pixelfmt.bpp = 16;
-            hdr->pixelfmt.rmask = 0x0000f800;
-            hdr->pixelfmt.gmask = 0x000007e0;
-            hdr->pixelfmt.bmask = 0x0000001f;
-            hdr->pixelfmt.amask = 0x00000000;
-            break;
-         case DXGI_FORMAT_B5G5R5A1_UNORM:
-            hdr->pixelfmt.bpp = 16;
-            hdr->pixelfmt.rmask = 0x00007c00;
-            hdr->pixelfmt.gmask = 0x000003e0;
-            hdr->pixelfmt.bmask = 0x0000001f;
-            hdr->pixelfmt.amask = 0x00008000;
-            break;
-         case DXGI_FORMAT_R10G10B10A2_TYPELESS:
-         case DXGI_FORMAT_R10G10B10A2_UNORM:
-         case DXGI_FORMAT_R10G10B10A2_UINT:
-            hdr->pixelfmt.bpp = 32;
-            hdr->pixelfmt.flags |= DDPF_ALPHAPIXELS;
-            hdr->pixelfmt.rmask = 0x000003ff;
-            hdr->pixelfmt.gmask = 0x000ffc00;
-            hdr->pixelfmt.bmask = 0x3ff00000;
-            hdr->pixelfmt.amask = 0xc0000000;
-            break;
-         case DXGI_FORMAT_A8_UNORM:
-            hdr->pixelfmt.bpp = 8;
-            hdr->pixelfmt.flags |= DDPF_ALPHA | DDPF_ALPHAPIXELS;
-            hdr->pixelfmt.rmask = hdr->pixelfmt.gmask = hdr->pixelfmt.bmask = 0;
-            hdr->pixelfmt.amask = 0x000000ff;
-            break;
-         case DXGI_FORMAT_R8_TYPELESS:
-         case DXGI_FORMAT_R8_UNORM:
-         case DXGI_FORMAT_R8_UINT:
-         case DXGI_FORMAT_R8_SNORM:
-         case DXGI_FORMAT_R8_SINT:
-            hdr->pixelfmt.bpp = 8;
-            hdr->pixelfmt.rmask = 0x000000ff;
-            hdr->pixelfmt.gmask = hdr->pixelfmt.bmask = hdr->pixelfmt.amask = 0;
-            break;
-         case DXGI_FORMAT_B4G4R4A4_UNORM:
-            hdr->pixelfmt.bpp = 16;
-            hdr->pixelfmt.flags |= DDPF_ALPHAPIXELS;
-            hdr->pixelfmt.rmask = 0x00000f00;
-            hdr->pixelfmt.gmask = 0x000000f0;
-            hdr->pixelfmt.bmask = 0x0000000f;
-            hdr->pixelfmt.amask = 0x0000f000;
-            break;
-         case DXGI_FORMAT_UNKNOWN:
-            g_message("Unknown DXGI format.  Expect problems...");
-            break;
-         default:  /* unsupported DXGI format */
-            g_message("Unsupported DXGI format (%d)", dx10hdr->dxgiFormat);
-            return(0);
-      }
-   }
-
-   return(1);
+      switch (dx10hdr->dxgiFormat)
+        {
+        case DXGI_FORMAT_B8G8R8A8_TYPELESS:
+        case DXGI_FORMAT_B8G8R8A8_UNORM:
+        case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
+          hdr->pixelfmt.bpp = 32;
+          hdr->pixelfmt.flags |= DDPF_ALPHAPIXELS;
+          hdr->pixelfmt.rmask = 0x00ff0000;
+          hdr->pixelfmt.gmask = 0x0000ff00;
+          hdr->pixelfmt.bmask = 0x000000ff;
+          hdr->pixelfmt.amask = 0xff000000;
+          break;
+        case DXGI_FORMAT_B8G8R8X8_TYPELESS:
+        case DXGI_FORMAT_B8G8R8X8_UNORM:
+        case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
+          hdr->pixelfmt.bpp = 32;
+          hdr->pixelfmt.flags |= DDPF_ALPHAPIXELS;
+          hdr->pixelfmt.rmask = 0x00ff0000;
+          hdr->pixelfmt.gmask = 0x0000ff00;
+          hdr->pixelfmt.bmask = 0x000000ff;
+          hdr->pixelfmt.amask = 0x00000000;
+          break;
+        case DXGI_FORMAT_R8G8B8A8_TYPELESS:
+        case DXGI_FORMAT_R8G8B8A8_UNORM:
+        case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
+        case DXGI_FORMAT_R8G8B8A8_UINT:
+        case DXGI_FORMAT_R8G8B8A8_SNORM:
+        case DXGI_FORMAT_R8G8B8A8_SINT:
+          hdr->pixelfmt.bpp = 32;
+          hdr->pixelfmt.flags |= DDPF_ALPHAPIXELS;
+          hdr->pixelfmt.rmask = 0x000000ff;
+          hdr->pixelfmt.gmask = 0x0000ff00;
+          hdr->pixelfmt.bmask = 0x00ff0000;
+          hdr->pixelfmt.amask = 0xff000000;
+          break;
+        case DXGI_FORMAT_B5G6R5_UNORM:
+          hdr->pixelfmt.bpp = 16;
+          hdr->pixelfmt.rmask = 0x0000f800;
+          hdr->pixelfmt.gmask = 0x000007e0;
+          hdr->pixelfmt.bmask = 0x0000001f;
+          hdr->pixelfmt.amask = 0x00000000;
+          break;
+        case DXGI_FORMAT_B5G5R5A1_UNORM:
+          hdr->pixelfmt.bpp = 16;
+          hdr->pixelfmt.rmask = 0x00007c00;
+          hdr->pixelfmt.gmask = 0x000003e0;
+          hdr->pixelfmt.bmask = 0x0000001f;
+          hdr->pixelfmt.amask = 0x00008000;
+          break;
+        case DXGI_FORMAT_R10G10B10A2_TYPELESS:
+        case DXGI_FORMAT_R10G10B10A2_UNORM:
+        case DXGI_FORMAT_R10G10B10A2_UINT:
+          hdr->pixelfmt.bpp = 32;
+          hdr->pixelfmt.flags |= DDPF_ALPHAPIXELS;
+          hdr->pixelfmt.rmask = 0x000003ff;
+          hdr->pixelfmt.gmask = 0x000ffc00;
+          hdr->pixelfmt.bmask = 0x3ff00000;
+          hdr->pixelfmt.amask = 0xc0000000;
+          break;
+        case DXGI_FORMAT_A8_UNORM:
+          hdr->pixelfmt.bpp = 8;
+          hdr->pixelfmt.flags |= DDPF_ALPHA | DDPF_ALPHAPIXELS;
+          hdr->pixelfmt.rmask = hdr->pixelfmt.gmask = hdr->pixelfmt.bmask = 0;
+          hdr->pixelfmt.amask = 0x000000ff;
+          break;
+        case DXGI_FORMAT_R8_TYPELESS:
+        case DXGI_FORMAT_R8_UNORM:
+        case DXGI_FORMAT_R8_UINT:
+        case DXGI_FORMAT_R8_SNORM:
+        case DXGI_FORMAT_R8_SINT:
+          hdr->pixelfmt.bpp = 8;
+          hdr->pixelfmt.rmask = 0x000000ff;
+          hdr->pixelfmt.gmask = hdr->pixelfmt.bmask = hdr->pixelfmt.amask = 0;
+          break;
+        case DXGI_FORMAT_B4G4R4A4_UNORM:
+          hdr->pixelfmt.bpp = 16;
+          hdr->pixelfmt.flags |= DDPF_ALPHAPIXELS;
+          hdr->pixelfmt.rmask = 0x00000f00;
+          hdr->pixelfmt.gmask = 0x000000f0;
+          hdr->pixelfmt.bmask = 0x0000000f;
+          hdr->pixelfmt.amask = 0x0000f000;
+          break;
+        case DXGI_FORMAT_UNKNOWN:
+          g_message ("Unknown DXGI format.  Expect problems...");
+          break;
+        default:  /* unsupported DXGI format */
+          g_message ("Unsupported DXGI format (%d)", dx10hdr->dxgiFormat);
+          return (0);
+        }
+    }
+
+  return (1);
 }
 
 
@@ -812,440 +841,466 @@ premultiplied_variant (const Babl* format)
   if (format == babl_format ("R'G'B'A u8"))
     return babl_format ("R'aG'aB'aA u8");
   else
-    g_printerr ("Add format %s to premultiplied_variant() %s: %d\n", babl_get_name (format), __FILE__, 
__LINE__);
+    g_printerr ("Add format %s to premultiplied_variant () %s: %d\n", babl_get_name (format), __FILE__, 
__LINE__);
   return format;
 }
 
-static int load_layer(FILE *fp, dds_header_t *hdr, dds_load_info_t *d,
-                      gint32 image, unsigned int level, char *prefix,
-                      unsigned int *l, guchar *pixels, unsigned char *buf)
+static int
+load_layer (FILE            *fp,
+            dds_header_t    *hdr,
+            dds_load_info_t *d,
+            gint32           image,
+            unsigned int     level,
+            char            *prefix,
+            unsigned int    *l,
+            guchar          *pixels,
+            unsigned char   *buf)
 {
-   GeglBuffer *buffer;
-   const Babl *bablfmt = NULL;
-   GimpImageType type = GIMP_RGBA_IMAGE;
-   gchar *layer_name;
-   gint x, y, z, n;
-   gint32 layer;
-   unsigned int width = hdr->width >> level;
-   unsigned int height = hdr->height >> level;
-   unsigned int size = hdr->pitch_or_linsize >> (2 * level);
-   unsigned int layerw;
-   int format = DDS_COMPRESS_NONE;
-
-   if(width < 1) width = 1;
-   if(height < 1) height = 1;
-
-   switch(d->bpp)
-   {
-      case 1:
-         if(hdr->pixelfmt.flags & DDPF_PALETTEINDEXED8)
-         {
-            type = GIMP_INDEXED_IMAGE;
-            bablfmt = babl_format("R'G'B' u8");
-         }
-         else if(hdr->pixelfmt.rmask == 0xe0)
-         {
-            type = GIMP_RGB_IMAGE;
-            bablfmt = babl_format("R'G'B' u8");
-         }
-         else if(hdr->pixelfmt.flags & DDPF_ALPHA)
-         {
-            type = GIMP_GRAYA_IMAGE;
-            bablfmt = babl_format("Y'A u8");
-         }
-         else
-         {
-            type = GIMP_GRAY_IMAGE;
-            bablfmt = babl_format("Y' u8");
-         }
-         break;
-      case 2:
-         if(hdr->pixelfmt.amask == 0xf000) //RGBA4
-         {
-            type = GIMP_RGBA_IMAGE;
-            bablfmt = babl_format("R'G'B'A u8");
-         }
-         else if(hdr->pixelfmt.amask == 0xff00) //L8A8
-         {
-            type = GIMP_GRAYA_IMAGE;
-            bablfmt = babl_format("Y'A u8");
-         }
-         else if(hdr->pixelfmt.bmask == 0x1f) //R5G6B5 or RGB5A1
-         {
-            type = (hdr->pixelfmt.amask == 0x8000) ? GIMP_RGBA_IMAGE : GIMP_RGB_IMAGE;
-            bablfmt = (hdr->pixelfmt.amask == 0x8000) ? babl_format("R'G'B'A u8") : babl_format("R'G'B' u8");
-         }
-         else //L16
-         {
-            type = GIMP_GRAY_IMAGE;
-            bablfmt = babl_format("Y' u8");
-         }
-         break;
-      case 3: type = GIMP_RGB_IMAGE;  bablfmt = babl_format("R'G'B' u8");  break;
-      case 4: type = GIMP_RGBA_IMAGE; bablfmt = babl_format("R'G'B'A u8"); break;
-   }
-
-   layer_name = (level) ? g_strdup_printf("mipmap %d %s", level, prefix) :
-                          g_strdup_printf("main surface %s", prefix);
-
-   layer = gimp_layer_new(image, layer_name, width, height, type, 100,
+  GeglBuffer    *buffer;
+  const Babl    *bablfmt = NULL;
+  GimpImageType  type = GIMP_RGBA_IMAGE;
+  gchar         *layer_name;
+  gint           x, y, z, n;
+  gint32         layer;
+  unsigned int   width = hdr->width >> level;
+  unsigned int   height = hdr->height >> level;
+  unsigned int   size = hdr->pitch_or_linsize >> (2 * level);
+  unsigned int   layerw;
+  int            format = DDS_COMPRESS_NONE;
+
+  if (width < 1) width = 1;
+  if (height < 1) height = 1;
+
+  switch (d->bpp)
+    {
+    case 1:
+      if (hdr->pixelfmt.flags & DDPF_PALETTEINDEXED8)
+        {
+          type = GIMP_INDEXED_IMAGE;
+          bablfmt = babl_format ("R'G'B' u8");
+        }
+      else if (hdr->pixelfmt.rmask == 0xe0)
+        {
+          type = GIMP_RGB_IMAGE;
+          bablfmt = babl_format ("R'G'B' u8");
+        }
+      else if (hdr->pixelfmt.flags & DDPF_ALPHA)
+        {
+          type = GIMP_GRAYA_IMAGE;
+          bablfmt = babl_format ("Y'A u8");
+        }
+      else
+        {
+          type = GIMP_GRAY_IMAGE;
+          bablfmt = babl_format ("Y' u8");
+        }
+      break;
+    case 2:
+      if (hdr->pixelfmt.amask == 0xf000) /* RGBA4 */
+        {
+          type = GIMP_RGBA_IMAGE;
+          bablfmt = babl_format ("R'G'B'A u8");
+        }
+      else if (hdr->pixelfmt.amask == 0xff00) /* L8A8 */
+        {
+          type = GIMP_GRAYA_IMAGE;
+          bablfmt = babl_format ("Y'A u8");
+        }
+      else if (hdr->pixelfmt.bmask == 0x1f) /* R5G6B5 or RGB5A1 */
+        {
+          type = (hdr->pixelfmt.amask == 0x8000) ? GIMP_RGBA_IMAGE : GIMP_RGB_IMAGE;
+          bablfmt = (hdr->pixelfmt.amask == 0x8000) ? babl_format ("R'G'B'A u8") : babl_format ("R'G'B' u8");
+        }
+      else /* L16 */
+        {
+          type = GIMP_GRAY_IMAGE;
+          bablfmt = babl_format ("Y' u8");
+        }
+      break;
+    case 3: type = GIMP_RGB_IMAGE;  bablfmt = babl_format ("R'G'B' u8");  break;
+    case 4: type = GIMP_RGBA_IMAGE; bablfmt = babl_format ("R'G'B'A u8"); break;
+    }
+
+  layer_name = (level) ? g_strdup_printf ("mipmap %d %s", level, prefix) :
+    g_strdup_printf ("main surface %s", prefix);
+
+  layer = gimp_layer_new (image, layer_name, width, height, type, 100,
                           GIMP_LAYER_MODE_NORMAL);
-   g_free(layer_name);
+  g_free (layer_name);
+
+  gimp_image_insert_layer (image, layer, 0, *l);
 
-   gimp_image_insert_layer(image, layer, 0, *l);
+  if ((*l)++) gimp_item_set_visible (layer, FALSE);
 
-   if((*l)++) gimp_item_set_visible(layer, FALSE);
+  buffer = gimp_drawable_get_buffer (layer);
 
-   buffer = gimp_drawable_get_buffer(layer);
-   
-   layerw = gegl_buffer_get_width(buffer);
+  layerw = gegl_buffer_get_width (buffer);
 
-   if(hdr->pixelfmt.flags & DDPF_FOURCC)
-   {
+  if (hdr->pixelfmt.flags & DDPF_FOURCC)
+    {
       unsigned int w = (width  + 3) >> 2;
       unsigned int h = (height + 3) >> 2;
 
-      switch(GETL32(hdr->pixelfmt.fourcc))
-      {
-         case FOURCC('D','X','T','1'): format = DDS_COMPRESS_BC1; break;
-         case FOURCC('D','X','T','2'): bablfmt = premultiplied_variant (bablfmt);
-         case FOURCC('D','X','T','3'): format = DDS_COMPRESS_BC2; break;
-         case FOURCC('D','X','T','4'): bablfmt = premultiplied_variant (bablfmt);
-         case FOURCC('D','X','T','5'): format = DDS_COMPRESS_BC3; break;
-         case FOURCC('R','X','G','B'): format = DDS_COMPRESS_BC3; break;
-         case FOURCC('A','T','I','1'):
-         case FOURCC('B','C','4','U'):
-         case FOURCC('B','C','4','S'): format = DDS_COMPRESS_BC4; break;
-         case FOURCC('A','T','I','2'):
-         case FOURCC('B','C','5','U'):
-         case FOURCC('B','C','5','S'): format = DDS_COMPRESS_BC5; break;
-      }
+      switch (GETL32(hdr->pixelfmt.fourcc))
+        {
+        case FOURCC ('D','X','T','1'): format = DDS_COMPRESS_BC1; break;
+        case FOURCC ('D','X','T','2'): bablfmt = premultiplied_variant (bablfmt);
+        case FOURCC ('D','X','T','3'): format = DDS_COMPRESS_BC2; break;
+        case FOURCC ('D','X','T','4'): bablfmt = premultiplied_variant (bablfmt);
+        case FOURCC ('D','X','T','5'): format = DDS_COMPRESS_BC3; break;
+        case FOURCC ('R','X','G','B'): format = DDS_COMPRESS_BC3; break;
+        case FOURCC ('A','T','I','1'):
+        case FOURCC ('B','C','4','U'):
+        case FOURCC ('B','C','4','S'): format = DDS_COMPRESS_BC4; break;
+        case FOURCC ('A','T','I','2'):
+        case FOURCC ('B','C','5','U'):
+        case FOURCC ('B','C','5','S'): format = DDS_COMPRESS_BC5; break;
+        }
 
       size = w * h;
-      if((format == DDS_COMPRESS_BC1) || (format == DDS_COMPRESS_BC4))
-         size *= 8;
+      if ((format == DDS_COMPRESS_BC1) || (format == DDS_COMPRESS_BC4))
+        size *= 8;
       else
-         size *= 16;
-   }
-
-   if((hdr->flags & DDSD_LINEARSIZE) &&
-      !fread(buf, size, 1, fp))
-   {
-      g_message("Unexpected EOF.\n");
-      return(0);
-   }
-
-   if((hdr->pixelfmt.flags & DDPF_RGB) || (hdr->pixelfmt.flags & DDPF_ALPHA))
-   {
+        size *= 16;
+    }
+
+  if ((hdr->flags & DDSD_LINEARSIZE) &&
+      !fread (buf, size, 1, fp))
+    {
+      g_message ("Unexpected EOF.\n");
+      return (0);
+    }
+
+  if ((hdr->pixelfmt.flags & DDPF_RGB) || (hdr->pixelfmt.flags & DDPF_ALPHA))
+    {
       z = 0;
-      for(y = 0, n = 0; y < height; ++y, ++n)
-      {
-         if(n >= d->tile_height)
-         {
-            gegl_buffer_set(buffer, GEGL_RECTANGLE(0, y - n, layerw, n), 0,
-                            bablfmt, pixels, GEGL_AUTO_ROWSTRIDE);
-            n = 0;
-            gimp_progress_update((double)y / (double)hdr->height);
-         }
-
-         if((hdr->flags & DDSD_PITCH) &&
-            !fread(buf, width * d->bpp, 1, fp))
-         {
-            g_message("Unexpected EOF.\n");
-            return(0);
-         }
-
-         if(!(hdr->flags & DDSD_LINEARSIZE)) z = 0;
-
-         for(x = 0; x < layerw; ++x)
-         {
-            unsigned int pixel = buf[z];
-            unsigned int pos = (n * layerw + x) * d->gimp_bpp;
-
-            if(d->bpp > 1) pixel += ((unsigned int)buf[z + 1] <<  8);
-            if(d->bpp > 2) pixel += ((unsigned int)buf[z + 2] << 16);
-            if(d->bpp > 3) pixel += ((unsigned int)buf[z + 3] << 24);
-
-            if(d->bpp >= 3)
+      for (y = 0, n = 0; y < height; ++y, ++n)
+        {
+          if (n >= d->tile_height)
             {
-               if(hdr->pixelfmt.amask == 0xc0000000) // handle RGB10A2
-               {
-                  pixels[pos + 0] = (pixel >> d->bshift) >> 2;
-                  pixels[pos + 1] = (pixel >> d->gshift) >> 2;
-                  pixels[pos + 2] = (pixel >> d->rshift) >> 2;
-                  if(hdr->pixelfmt.flags & DDPF_ALPHAPIXELS)
-                     pixels[pos + 3] = (pixel >> d->ashift << (8 - d->abits) & d->amask) * 255 / d->amask;
-               }
-               else
-               {
-                  pixels[pos] =
-                     (pixel >> d->rshift << (8 - d->rbits) & d->rmask) * 255 / d->rmask;
-                  pixels[pos + 1] =
-                     (pixel >> d->gshift << (8 - d->gbits) & d->gmask) * 255 / d->gmask;
-                  pixels[pos + 2] =
-                     (pixel >> d->bshift << (8 - d->bbits) & d->bmask) * 255 / d->bmask;
-                  if(hdr->pixelfmt.flags & DDPF_ALPHAPIXELS)
-                  {
-                     pixels[pos + 3] =
-                        (pixel >> d->ashift << (8 - d->abits) & d->amask) * 255 / d->amask;
-                  }
-               }
+              gegl_buffer_set (buffer, GEGL_RECTANGLE (0, y - n, layerw, n), 0,
+                               bablfmt, pixels, GEGL_AUTO_ROWSTRIDE);
+              n = 0;
+              gimp_progress_update ((double)y / (double)hdr->height);
             }
-            else if(d->bpp == 2)
+
+          if ((hdr->flags & DDSD_PITCH) &&
+              !fread (buf, width * d->bpp, 1, fp))
             {
-               if(hdr->pixelfmt.amask == 0xf000) //RGBA4
-               {
-                  pixels[pos] =
-                     (pixel >> d->rshift << (8 - d->rbits) & d->rmask) * 255 / d->rmask;
-                  pixels[pos + 1] =
-                     (pixel >> d->gshift << (8 - d->gbits) & d->gmask) * 255 / d->gmask;
-                  pixels[pos + 2] =
-                     (pixel >> d->bshift << (8 - d->bbits) & d->bmask) * 255 / d->bmask;
-                  pixels[pos + 3] =
-                     (pixel >> d->ashift << (8 - d->abits) & d->amask) * 255 / d->amask;
-               }
-               else if(hdr->pixelfmt.amask == 0xff00) //L8A8
-               {
-                  pixels[pos] =
-                     (pixel >> d->rshift << (8 - d->rbits) & d->rmask) * 255 / d->rmask;
-                  pixels[pos + 1] =
-                     (pixel >> d->ashift << (8 - d->abits) & d->amask) * 255 / d->amask;
-               }
-               else if(hdr->pixelfmt.bmask == 0x1f) //R5G6B5 or RGB5A1
-               {
-                  pixels[pos] =
-                     (pixel >> d->rshift << (8 - d->rbits) & d->rmask) * 255 / d->rmask;
-                  pixels[pos + 1] =
-                     (pixel >> d->gshift << (8 - d->gbits) & d->gmask) * 255 / d->gmask;
-                  pixels[pos + 2] =
-                     (pixel >> d->bshift << (8 - d->bbits) & d->bmask) * 255 / d->bmask;
-                  if(hdr->pixelfmt.amask == 0x8000)
-                  {
-                     pixels[pos + 3] =
-                         (pixel >> d->ashift << (8 - d->abits) & d->amask) * 255 / d->amask;
-                  }
-               }
-               else //L16
-                  pixels[pos] = (unsigned char)(255 * ((float)(pixel & 0xffff) / 65535.0f));
+              g_message ("Unexpected EOF.\n");
+              return (0);
             }
-            else
+
+          if (!(hdr->flags & DDSD_LINEARSIZE)) z = 0;
+
+          for (x = 0; x < layerw; ++x)
             {
-               if(hdr->pixelfmt.flags & DDPF_PALETTEINDEXED8)
-               {
-                  pixels[pos] = pixel & 0xff;
-               }
-               else if(hdr->pixelfmt.rmask == 0xe0) // R3G3B2
-               {
-                  pixels[pos] =
-                     (pixel >> d->rshift << (8 - d->rbits) & d->rmask) * 255 / d->rmask;
-                  pixels[pos + 1] =
-                     (pixel >> d->gshift << (8 - d->gbits) & d->gmask) * 255 / d->gmask;
-                  pixels[pos + 2] =
-                     (pixel >> d->bshift << (8 - d->bbits) & d->bmask) * 255 / d->bmask;
-               }
-               else if(hdr->pixelfmt.flags & DDPF_ALPHA)
-               {
-                  pixels[pos + 0] = 255;
-                  pixels[pos + 1] = pixel & 0xff;
-               }
-               else // LUMINANCE
-               {
-                  pixels[pos] = pixel & 0xff;
-               }
+              unsigned int pixel = buf[z];
+              unsigned int pos = (n * layerw + x) * d->gimp_bpp;
+
+              if (d->bpp > 1) pixel += ((unsigned int)buf[z + 1] <<  8);
+              if (d->bpp > 2) pixel += ((unsigned int)buf[z + 2] << 16);
+              if (d->bpp > 3) pixel += ((unsigned int)buf[z + 3] << 24);
+
+              if (d->bpp >= 3)
+                {
+                  if (hdr->pixelfmt.amask == 0xc0000000) // handle RGB10A2
+                    {
+                      pixels[pos + 0] = (pixel >> d->bshift) >> 2;
+                      pixels[pos + 1] = (pixel >> d->gshift) >> 2;
+                      pixels[pos + 2] = (pixel >> d->rshift) >> 2;
+                      if (hdr->pixelfmt.flags & DDPF_ALPHAPIXELS)
+                        pixels[pos + 3] = (pixel >> d->ashift << (8 - d->abits) & d->amask) * 255 / d->amask;
+                    }
+                  else
+                    {
+                      pixels[pos] =
+                        (pixel >> d->rshift << (8 - d->rbits) & d->rmask) * 255 / d->rmask;
+                      pixels[pos + 1] =
+                        (pixel >> d->gshift << (8 - d->gbits) & d->gmask) * 255 / d->gmask;
+                      pixels[pos + 2] =
+                        (pixel >> d->bshift << (8 - d->bbits) & d->bmask) * 255 / d->bmask;
+                      if (hdr->pixelfmt.flags & DDPF_ALPHAPIXELS)
+                        {
+                          pixels[pos + 3] =
+                            (pixel >> d->ashift << (8 - d->abits) & d->amask) * 255 / d->amask;
+                        }
+                    }
+                }
+              else if (d->bpp == 2)
+                {
+                  if (hdr->pixelfmt.amask == 0xf000) //RGBA4
+                    {
+                      pixels[pos] =
+                        (pixel >> d->rshift << (8 - d->rbits) & d->rmask) * 255 / d->rmask;
+                      pixels[pos + 1] =
+                        (pixel >> d->gshift << (8 - d->gbits) & d->gmask) * 255 / d->gmask;
+                      pixels[pos + 2] =
+                        (pixel >> d->bshift << (8 - d->bbits) & d->bmask) * 255 / d->bmask;
+                      pixels[pos + 3] =
+                        (pixel >> d->ashift << (8 - d->abits) & d->amask) * 255 / d->amask;
+                    }
+                  else if (hdr->pixelfmt.amask == 0xff00) //L8A8
+                    {
+                      pixels[pos] =
+                        (pixel >> d->rshift << (8 - d->rbits) & d->rmask) * 255 / d->rmask;
+                      pixels[pos + 1] =
+                        (pixel >> d->ashift << (8 - d->abits) & d->amask) * 255 / d->amask;
+                    }
+                  else if (hdr->pixelfmt.bmask == 0x1f) //R5G6B5 or RGB5A1
+                    {
+                      pixels[pos] =
+                        (pixel >> d->rshift << (8 - d->rbits) & d->rmask) * 255 / d->rmask;
+                      pixels[pos + 1] =
+                        (pixel >> d->gshift << (8 - d->gbits) & d->gmask) * 255 / d->gmask;
+                      pixels[pos + 2] =
+                        (pixel >> d->bshift << (8 - d->bbits) & d->bmask) * 255 / d->bmask;
+                      if (hdr->pixelfmt.amask == 0x8000)
+                        {
+                          pixels[pos + 3] =
+                            (pixel >> d->ashift << (8 - d->abits) & d->amask) * 255 / d->amask;
+                        }
+                    }
+                  else //L16
+                    pixels[pos] = (unsigned char)(255 * ((float)(pixel & 0xffff) / 65535.0f));
+                }
+              else
+                {
+                  if (hdr->pixelfmt.flags & DDPF_PALETTEINDEXED8)
+                    {
+                      pixels[pos] = pixel & 0xff;
+                    }
+                  else if (hdr->pixelfmt.rmask == 0xe0) // R3G3B2
+                    {
+                      pixels[pos] =
+                        (pixel >> d->rshift << (8 - d->rbits) & d->rmask) * 255 / d->rmask;
+                      pixels[pos + 1] =
+                        (pixel >> d->gshift << (8 - d->gbits) & d->gmask) * 255 / d->gmask;
+                      pixels[pos + 2] =
+                        (pixel >> d->bshift << (8 - d->bbits) & d->bmask) * 255 / d->bmask;
+                    }
+                  else if (hdr->pixelfmt.flags & DDPF_ALPHA)
+                    {
+                      pixels[pos + 0] = 255;
+                      pixels[pos + 1] = pixel & 0xff;
+                    }
+                  else // LUMINANCE
+                    {
+                      pixels[pos] = pixel & 0xff;
+                    }
+                }
+
+              z += d->bpp;
             }
+        }
 
-            z += d->bpp;
-         }
-      }
-
-      gegl_buffer_set(buffer, GEGL_RECTANGLE(0, y - n, layerw, n), 0,
-                      bablfmt, pixels, GEGL_AUTO_ROWSTRIDE);
-   }
-   else if(hdr->pixelfmt.flags & DDPF_FOURCC)
-   {
+      gegl_buffer_set (buffer, GEGL_RECTANGLE (0, y - n, layerw, n), 0,
+                       bablfmt, pixels, GEGL_AUTO_ROWSTRIDE);
+    }
+  else if (hdr->pixelfmt.flags & DDPF_FOURCC)
+    {
       unsigned char *dst;
 
-      if(!(hdr->flags & DDSD_LINEARSIZE))
-      {
-         g_message("Image marked as compressed, but DDSD_LINEARSIZE is not set.\n");
-         return(0);
-      }
+      if (!(hdr->flags & DDSD_LINEARSIZE))
+        {
+          g_message ("Image marked as compressed, but DDSD_LINEARSIZE is not set.\n");
+          return (0);
+        }
 
-      dst = g_malloc(width * height * d->gimp_bpp);
-      memset(dst, 0, width * height * d->gimp_bpp);
+      dst = g_malloc (width * height * d->gimp_bpp);
+      memset (dst, 0, width * height * d->gimp_bpp);
 
-      if(d->gimp_bpp == 4)
-      {
-         for(y = 0; y < height; ++y)
-            for(x = 0; x < width; ++x)
-               dst[y * (width * 4) + (x * 4) + 3] = 255;
-      }
+      if (d->gimp_bpp == 4)
+        {
+          for (y = 0; y < height; ++y)
+            for (x = 0; x < width; ++x)
+              dst[y * (width * 4) + (x * 4) + 3] = 255;
+        }
 
-      dxt_decompress(dst, buf, format, size, width, height, d->gimp_bpp,
-                     hdr->pixelfmt.flags & DDPF_NORMAL);
+      dxt_decompress (dst, buf, format, size, width, height, d->gimp_bpp,
+                      hdr->pixelfmt.flags & DDPF_NORMAL);
 
       z = 0;
-      for(y = 0, n = 0; y < height; ++y, ++n)
-      {
-         if(n >= d->tile_height)
-         {
-            gegl_buffer_set(buffer, GEGL_RECTANGLE(0, y - n, layerw, n), 0,
-                            bablfmt, pixels, GEGL_AUTO_ROWSTRIDE);
-            n = 0;
-            gimp_progress_update((double)y / (double)hdr->height);
-         }
-
-         memcpy(pixels + n * layerw * d->gimp_bpp,
-                dst + y * layerw * d->gimp_bpp,
-                width * d->gimp_bpp);
-      }
-
-      gegl_buffer_set(buffer, GEGL_RECTANGLE(0, y - n, layerw, n), 0,
-                      bablfmt, pixels, GEGL_AUTO_ROWSTRIDE);
-      
-      g_free(dst);
-   }
-
-   gegl_buffer_flush(buffer);
-   
-   g_object_unref(buffer);
-   
-   /* gimp dds specific.  decode encoded images */
-   if(dds_read_vals.decode_images &&
-      hdr->reserved.gimp_dds_special.magic1 == FOURCC('G','I','M','P') &&
-      hdr->reserved.gimp_dds_special.magic2 == FOURCC('-','D','D','S'))
-   {
-      switch(hdr->reserved.gimp_dds_special.extra_fourcc)
-      {
-         case FOURCC('A','E','X','P'):
-            decode_alpha_exp_image(layer, FALSE);
-            break;
-         case FOURCC('Y','C','G','1'):
-            decode_ycocg_image(layer, FALSE);
-            break;
-         case FOURCC('Y','C','G','2'):
-            decode_ycocg_scaled_image(layer, FALSE);
-            break;
-         default:
-            break;
-      }
-   }
-
-   return(1);
+      for (y = 0, n = 0; y < height; ++y, ++n)
+        {
+          if (n >= d->tile_height)
+            {
+              gegl_buffer_set (buffer, GEGL_RECTANGLE (0, y - n, layerw, n), 0,
+                               bablfmt, pixels, GEGL_AUTO_ROWSTRIDE);
+              n = 0;
+              gimp_progress_update ((double)y / (double)hdr->height);
+            }
+
+          memcpy (pixels + n * layerw * d->gimp_bpp,
+                  dst + y * layerw * d->gimp_bpp,
+                  width * d->gimp_bpp);
+        }
+
+      gegl_buffer_set (buffer, GEGL_RECTANGLE (0, y - n, layerw, n), 0,
+                       bablfmt, pixels, GEGL_AUTO_ROWSTRIDE);
+
+      g_free (dst);
+    }
+
+  gegl_buffer_flush (buffer);
+
+  g_object_unref (buffer);
+
+  /* gimp dds specific.  decode encoded images */
+  if (dds_read_vals.decode_images &&
+      hdr->reserved.gimp_dds_special.magic1 == FOURCC ('G','I','M','P') &&
+      hdr->reserved.gimp_dds_special.magic2 == FOURCC ('-','D','D','S'))
+    {
+      switch (hdr->reserved.gimp_dds_special.extra_fourcc)
+        {
+        case FOURCC ('A','E','X','P'):
+          decode_alpha_exp_image (layer, FALSE);
+          break;
+        case FOURCC ('Y','C','G','1'):
+          decode_ycocg_image (layer, FALSE);
+          break;
+        case FOURCC ('Y','C','G','2'):
+          decode_ycocg_scaled_image (layer, FALSE);
+          break;
+        default:
+          break;
+        }
+    }
+
+  return (1);
 }
 
-static int load_mipmaps(FILE *fp, dds_header_t *hdr, dds_load_info_t *d,
-                        gint32 image, char *prefix, unsigned int *l,
-                        guchar *pixels, unsigned char *buf)
+static int
+load_mipmaps (FILE *fp,
+              dds_header_t    *hdr,
+              dds_load_info_t *d,
+              gint32           image,
+              char            *prefix,
+              unsigned int    *l,
+              guchar          *pixels,
+              unsigned char   *buf)
 {
-   unsigned int level;
+  unsigned int level;
 
-   if((hdr->flags & DDSD_MIPMAPCOUNT) &&
+  if ((hdr->flags & DDSD_MIPMAPCOUNT) &&
       (hdr->caps.caps1 & DDSCAPS_MIPMAP) &&
       (dds_read_vals.mipmaps != 0))
-   {
-      for(level = 1; level < hdr->num_mipmaps; ++level)
-      {
-         if(!load_layer(fp, hdr, d, image, level, prefix, l, pixels, buf))
-            return(0);
-      }
-   }
-   return(1);
+    {
+      for (level = 1; level < hdr->num_mipmaps; ++level)
+        {
+          if (!load_layer (fp, hdr, d, image, level, prefix, l, pixels, buf))
+            return (0);
+        }
+    }
+  return (1);
 }
 
-static int load_face(FILE *fp, dds_header_t *hdr, dds_load_info_t *d,
-                     gint32 image, char *prefix, unsigned int *l,
-                     guchar *pixels, unsigned char *buf)
+static int
+load_face (FILE            *fp,
+           dds_header_t    *hdr,
+           dds_load_info_t *d,
+           gint32           image,
+           char            *prefix,
+           unsigned int    *l,
+           guchar          *pixels,
+           unsigned char   *buf)
 {
-   if(!load_layer(fp, hdr, d, image, 0, prefix, l, pixels, buf))
-      return(0);
-   return(load_mipmaps(fp, hdr, d, image, prefix, l, pixels, buf));
+  if (!load_layer (fp, hdr, d, image, 0, prefix, l, pixels, buf))
+    return (0);
+  return (load_mipmaps (fp, hdr, d, image, prefix, l, pixels, buf));
 }
 
-static unsigned char color_bits(unsigned int mask)
+static unsigned char
+color_bits (unsigned int mask)
 {
-   unsigned char i = 0;
+  unsigned char i = 0;
 
-   while(mask)
-   {
-      if(mask & 1) ++i;
+  while (mask)
+    {
+      if (mask & 1) ++i;
       mask >>= 1;
-   }
-   return(i);
+    }
+  return (i);
 }
 
-static unsigned char color_shift(unsigned int mask)
+static unsigned char
+color_shift (unsigned int mask)
 {
-   unsigned char i = 0;
+  unsigned char i = 0;
 
-   if(!mask) return(0);
-   while(!((mask >> i) & 1)) ++i;
-   return(i);
+  if (!mask) return (0);
+  while (!((mask >> i) & 1)) ++i;
+  return (i);
 }
 
-static void load_dialog_response(GtkWidget *widget, gint response_id,
-                                 gpointer data)
+static void
+load_dialog_response (GtkWidget *widget,
+                      gint       response_id,
+                      gpointer   data)
 {
-   switch(response_id)
-   {
-      case GTK_RESPONSE_OK:
-         runme = 1;
-      default:
-         gtk_widget_destroy(widget);
-         break;
-   }
+  switch (response_id)
+    {
+    case GTK_RESPONSE_OK:
+      runme = 1;
+    default:
+      gtk_widget_destroy (widget);
+      break;
+    }
 }
 
-static void toggle_clicked(GtkWidget *widget, gpointer data)
+static void
+toggle_clicked (GtkWidget *widget,
+                gpointer   data)
 {
-   int *flag = (int*)data;
-   (*flag) = !(*flag);
+  int *flag = (int*) data;
+  (*flag) = !(*flag);
 }
 
-static int load_dialog(void)
+static int
+load_dialog (void)
 {
-   GtkWidget *dlg;
-   GtkWidget *vbox;
-   GtkWidget *check;
+  GtkWidget *dlg;
+  GtkWidget *vbox;
+  GtkWidget *check;
 
-   dlg = gimp_dialog_new(_("Load DDS"), "dds", NULL, GTK_WIN_POS_MOUSE,
+  dlg = gimp_dialog_new (_("Load DDS"), "dds", NULL, GTK_WIN_POS_MOUSE,
                          gimp_standard_help_func, LOAD_PROC,
                          _("Cancel"), GTK_RESPONSE_CANCEL,
                          _("OK"),     GTK_RESPONSE_OK,
                          NULL);
 
-   g_signal_connect(dlg, "response",
+  g_signal_connect (dlg, "response",
                     G_CALLBACK (load_dialog_response),
                     0);
-   g_signal_connect(dlg, "destroy",
+  g_signal_connect (dlg, "destroy",
                     G_CALLBACK (gtk_main_quit),
                     0);
 
-   vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8);
-   gtk_container_set_border_width(GTK_CONTAINER(vbox), 8);
-   gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area (GTK_DIALOG(dlg))),
+  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
+  gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
+  gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
                       vbox, 1, 1, 0);
-   gtk_widget_show(vbox);
+  gtk_widget_show (vbox);
 
-   check = gtk_check_button_new_with_label(_("Load mipmaps"));
-   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), dds_read_vals.mipmaps);
-   g_signal_connect(check, "clicked",
+  check = gtk_check_button_new_with_label (_("Load mipmaps"));
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), dds_read_vals.mipmaps);
+  g_signal_connect (check, "clicked",
                     G_CALLBACK (toggle_clicked), &dds_read_vals.mipmaps);
-   gtk_box_pack_start(GTK_BOX(vbox), check, 1, 1, 0);
-   gtk_widget_show(check);
+  gtk_box_pack_start (GTK_BOX (vbox), check, 1, 1, 0);
+  gtk_widget_show (check);
 
-   check = gtk_check_button_new_with_label(_("Automatically decode YCoCg/AExp images when detected"));
-   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), dds_read_vals.decode_images);
-   g_signal_connect(check, "clicked",
+  check = gtk_check_button_new_with_label (_("Automatically decode YCoCg/AExp images when detected"));
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), dds_read_vals.decode_images);
+  g_signal_connect (check, "clicked",
                     G_CALLBACK (toggle_clicked), &dds_read_vals.decode_images);
-   gtk_box_pack_start(GTK_BOX(vbox), check, 1, 1, 0);
-   gtk_widget_show(check);
+  gtk_box_pack_start (GTK_BOX (vbox), check, 1, 1, 0);
+  gtk_widget_show (check);
 
-   gtk_widget_show(dlg);
+  gtk_widget_show (dlg);
 
-   runme = 0;
+  runme = 0;
 
-   gtk_main();
+  gtk_main ();
 
-   return(runme);
+  return (runme);
 }
diff --git a/plug-ins/file-dds/ddswrite.c b/plug-ins/file-dds/ddswrite.c
index b5a297c7e5..b19b3c6cc5 100644
--- a/plug-ins/file-dds/ddswrite.c
+++ b/plug-ins/file-dds/ddswrite.c
@@ -1,24 +1,24 @@
 /*
-       DDS GIMP plugin
-
-       Copyright (C) 2004-2012 Shawn Kirst <skirst gmail com>,
-   with parts (C) 2003 Arne Reuter <homepage arnereuter de> where specified.
-
-       This program is free software; you can redistribute it and/or
-       modify it under the terms of the GNU General Public
-       License as published by the Free Software Foundation; either
-       version 2 of the License, or (at your option) any later version.
-
-       This program is distributed in the hope that it will be useful,
-       but WITHOUT ANY WARRANTY; without even the implied warranty of
-       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-       General Public License for more details.
-
-       You should have received a copy of the GNU General Public License
-       along with this program; see the file COPYING.  If not, write to
-       the Free Software Foundation, 51 Franklin Street, Fifth Floor
-       Boston, MA 02110-1301, USA.
-*/
+ * DDS GIMP plugin
+ *
+ * Copyright (C) 2004-2012 Shawn Kirst <skirst gmail com>,
+ * with parts (C) 2003 Arne Reuter <homepage arnereuter de> where specified.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301, USA.
+ */
 
 #include "config.h"
 
@@ -43,39 +43,46 @@
 #include "imath.h"
 #include "color.h"
 
-static gint save_dialog(gint32 image_id, gint32 drawable);
-static void save_dialog_response(GtkWidget *widget, gint response_id, gpointer data);
-static int write_image(FILE *fp, gint32 image_id, gint32 drawable_id);
+static gint save_dialog          (gint32     image_id,
+                                  gint32     drawable);
+static void save_dialog_response (GtkWidget *widget,
+                                  gint       response_id,
+                                  gpointer   data);
+static int  write_image          (FILE      *fp,
+                                  gint32     image_id,
+                                  gint32     drawable_id);
 
 static int runme = 0;
 
 enum
 {
-   COMBO_VALUE, COMBO_STRING, COMBO_SENSITIVE
+  COMBO_VALUE,
+  COMBO_STRING,
+  COMBO_SENSITIVE
 };
 
 static const char *cubemap_face_names[4][6] =
 {
-   {
+    {
       "positive x", "negative x",
       "positive y", "negative y",
       "positive z", "negative z"
-   },
-   {
+    },
+    {
       "pos x", "neg x",
       "pos y", "neg y",
       "pos z", "neg z",
-   },
-   {
+    },
+    {
       "+x", "-x",
       "+y", "-y",
       "+z", "-z"
-   },
-   {
+    },
+    {
       "right", "left",
       "top", "bottom",
       "back", "front"
-   }
+    }
 };
 
 static gint cubemap_faces[6];
@@ -98,1187 +105,1234 @@ static GtkWidget *alpha_test_threshold_spin;
 
 typedef struct string_value_s
 {
-   int value;
-   char *string;
+  int value;
+  char *string;
 } string_value_t;
 
 static string_value_t compression_strings[] =
 {
-   {DDS_COMPRESS_NONE,   "None"},
-   {DDS_COMPRESS_BC1,    "BC1 / DXT1"},
-   {DDS_COMPRESS_BC2,    "BC2 / DXT3"},
-   {DDS_COMPRESS_BC3,    "BC3 / DXT5"},
-   {DDS_COMPRESS_BC3N,   "BC3nm / DXT5nm"},
-   {DDS_COMPRESS_BC4,    "BC4 / ATI1 (3Dc+)"},
-   {DDS_COMPRESS_BC5,    "BC5 / ATI2 (3Dc)"},
-   {DDS_COMPRESS_RXGB,   "RXGB (DXT5)"},
-   {DDS_COMPRESS_AEXP,   "Alpha Exponent (DXT5)"},
-   {DDS_COMPRESS_YCOCG,  "YCoCg (DXT5)"},
-   {DDS_COMPRESS_YCOCGS, "YCoCg scaled (DXT5)"},
-   {-1, 0}
+    {DDS_COMPRESS_NONE,   "None"},
+    {DDS_COMPRESS_BC1,    "BC1 / DXT1"},
+    {DDS_COMPRESS_BC2,    "BC2 / DXT3"},
+    {DDS_COMPRESS_BC3,    "BC3 / DXT5"},
+    {DDS_COMPRESS_BC3N,   "BC3nm / DXT5nm"},
+    {DDS_COMPRESS_BC4,    "BC4 / ATI1 (3Dc+)"},
+    {DDS_COMPRESS_BC5,    "BC5 / ATI2 (3Dc)"},
+    {DDS_COMPRESS_RXGB,   "RXGB (DXT5)"},
+    {DDS_COMPRESS_AEXP,   "Alpha Exponent (DXT5)"},
+    {DDS_COMPRESS_YCOCG,  "YCoCg (DXT5)"},
+    {DDS_COMPRESS_YCOCGS, "YCoCg scaled (DXT5)"},
+    {-1, 0}
 };
 
 static string_value_t format_strings[] =
 {
-   {DDS_FORMAT_DEFAULT, "Default"},
-   {DDS_FORMAT_RGB8,    "RGB8"},
-   {DDS_FORMAT_RGBA8,   "RGBA8"},
-   {DDS_FORMAT_BGR8,    "BGR8"},
-   {DDS_FORMAT_ABGR8,   "ABGR8"},
-   {DDS_FORMAT_R5G6B5,  "R5G6B5"},
-   {DDS_FORMAT_RGBA4,   "RGBA4"},
-   {DDS_FORMAT_RGB5A1,  "RGB5A1"},
-   {DDS_FORMAT_RGB10A2, "RGB10A2"},
-   {DDS_FORMAT_R3G3B2,  "R3G3B2"},
-   {DDS_FORMAT_A8,      "A8"},
-   {DDS_FORMAT_L8,      "L8"},
-   {DDS_FORMAT_L8A8,    "L8A8"},
-   {DDS_FORMAT_AEXP,    "AExp"},
-   {DDS_FORMAT_YCOCG,   "YCoCg"},
-   {-1, 0}
+    {DDS_FORMAT_DEFAULT, "Default"},
+    {DDS_FORMAT_RGB8,    "RGB8"},
+    {DDS_FORMAT_RGBA8,   "RGBA8"},
+    {DDS_FORMAT_BGR8,    "BGR8"},
+    {DDS_FORMAT_ABGR8,   "ABGR8"},
+    {DDS_FORMAT_R5G6B5,  "R5G6B5"},
+    {DDS_FORMAT_RGBA4,   "RGBA4"},
+    {DDS_FORMAT_RGB5A1,  "RGB5A1"},
+    {DDS_FORMAT_RGB10A2, "RGB10A2"},
+    {DDS_FORMAT_R3G3B2,  "R3G3B2"},
+    {DDS_FORMAT_A8,      "A8"},
+    {DDS_FORMAT_L8,      "L8"},
+    {DDS_FORMAT_L8A8,    "L8A8"},
+    {DDS_FORMAT_AEXP,    "AExp"},
+    {DDS_FORMAT_YCOCG,   "YCoCg"},
+    {-1, 0}
 };
 
 static string_value_t mipmap_strings[] =
 {
-   {DDS_MIPMAP_NONE,     "No mipmaps"},
-   {DDS_MIPMAP_GENERATE, "Generate mipmaps"},
-   {DDS_MIPMAP_EXISTING, "Use existing mipmaps"},
-   {-1, 0}
+    {DDS_MIPMAP_NONE,     "No mipmaps"},
+    {DDS_MIPMAP_GENERATE, "Generate mipmaps"},
+    {DDS_MIPMAP_EXISTING, "Use existing mipmaps"},
+    {-1, 0}
 };
 
 static string_value_t mipmap_filter_strings[] =
 {
-   {DDS_MIPMAP_FILTER_DEFAULT,   "Default"},
-   {DDS_MIPMAP_FILTER_NEAREST,   "Nearest"},
-   {DDS_MIPMAP_FILTER_BOX,       "Box"},
-   {DDS_MIPMAP_FILTER_TRIANGLE,  "Triangle"},
-   {DDS_MIPMAP_FILTER_QUADRATIC, "Quadratic"},
-   {DDS_MIPMAP_FILTER_BSPLINE,   "B-Spline"},
-   {DDS_MIPMAP_FILTER_MITCHELL,  "Mitchell"},
-   {DDS_MIPMAP_FILTER_LANCZOS,   "Lanczos"},
-   {DDS_MIPMAP_FILTER_KAISER,    "Kaiser"},
-   {-1, 0}
+    {DDS_MIPMAP_FILTER_DEFAULT,   "Default"},
+    {DDS_MIPMAP_FILTER_NEAREST,   "Nearest"},
+    {DDS_MIPMAP_FILTER_BOX,       "Box"},
+    {DDS_MIPMAP_FILTER_TRIANGLE,  "Triangle"},
+    {DDS_MIPMAP_FILTER_QUADRATIC, "Quadratic"},
+    {DDS_MIPMAP_FILTER_BSPLINE,   "B-Spline"},
+    {DDS_MIPMAP_FILTER_MITCHELL,  "Mitchell"},
+    {DDS_MIPMAP_FILTER_LANCZOS,   "Lanczos"},
+    {DDS_MIPMAP_FILTER_KAISER,    "Kaiser"},
+    {-1, 0}
 };
 
 static string_value_t mipmap_wrap_strings[] =
 {
-   {DDS_MIPMAP_WRAP_DEFAULT, "Default"},
-   {DDS_MIPMAP_WRAP_MIRROR,  "Mirror"},
-   {DDS_MIPMAP_WRAP_REPEAT,  "Repeat"},
-   {DDS_MIPMAP_WRAP_CLAMP,   "Clamp"},
-   {-1, 0}
+    {DDS_MIPMAP_WRAP_DEFAULT, "Default"},
+    {DDS_MIPMAP_WRAP_MIRROR,  "Mirror"},
+    {DDS_MIPMAP_WRAP_REPEAT,  "Repeat"},
+    {DDS_MIPMAP_WRAP_CLAMP,   "Clamp"},
+    {-1, 0}
 };
 
 static string_value_t save_type_strings[] =
 {
-   {DDS_SAVE_SELECTED_LAYER, "Image / Selected layer"},
-   {DDS_SAVE_CUBEMAP,        "As cube map"},
-   {DDS_SAVE_VOLUMEMAP,      "As volume map"},
-   {DDS_SAVE_ARRAY,          "As texture array"},
-   {-1, 0}
+    {DDS_SAVE_SELECTED_LAYER, "Image / Selected layer"},
+    {DDS_SAVE_CUBEMAP,        "As cube map"},
+    {DDS_SAVE_VOLUMEMAP,      "As volume map"},
+    {DDS_SAVE_ARRAY,          "As texture array"},
+    {-1, 0}
 };
 
 static struct
 {
-   int format;
-   DXGI_FORMAT dxgi_format;
-   int bpp;
-   int alpha;
-   unsigned int rmask;
-   unsigned int gmask;
-   unsigned int bmask;
-   unsigned int amask;
+  int          format;
+  DXGI_FORMAT  dxgi_format;
+  int          bpp;
+  int          alpha;
+  unsigned int rmask;
+  unsigned int gmask;
+  unsigned int bmask;
+  unsigned int amask;
 } format_info[] =
 {
-   {DDS_FORMAT_RGB8,    DXGI_FORMAT_UNKNOWN,           3, 0, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000},
-   {DDS_FORMAT_RGBA8,   DXGI_FORMAT_B8G8R8A8_UNORM,    4, 1, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000},
-   {DDS_FORMAT_BGR8,    DXGI_FORMAT_UNKNOWN,           3, 0, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000},
-   {DDS_FORMAT_ABGR8,   DXGI_FORMAT_R8G8B8A8_UNORM,    4, 1, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000},
-   {DDS_FORMAT_R5G6B5,  DXGI_FORMAT_B5G6R5_UNORM,      2, 0, 0x0000f800, 0x000007e0, 0x0000001f, 0x00000000},
-   {DDS_FORMAT_RGBA4,   DXGI_FORMAT_B4G4R4A4_UNORM,    2, 1, 0x00000f00, 0x000000f0, 0x0000000f, 0x0000f000},
-   {DDS_FORMAT_RGB5A1,  DXGI_FORMAT_B5G5R5A1_UNORM,    2, 1, 0x00007c00, 0x000003e0, 0x0000001f, 0x00008000},
-   {DDS_FORMAT_RGB10A2, DXGI_FORMAT_R10G10B10A2_UNORM, 4, 1, 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000},
-   {DDS_FORMAT_R3G3B2,  DXGI_FORMAT_UNKNOWN,           1, 0, 0x000000e0, 0x0000001c, 0x00000003, 0x00000000},
-   {DDS_FORMAT_A8,      DXGI_FORMAT_A8_UNORM,          1, 0, 0x00000000, 0x00000000, 0x00000000, 0x000000ff},
-   {DDS_FORMAT_L8,      DXGI_FORMAT_R8_UNORM,          1, 0, 0x000000ff, 0x000000ff, 0x000000ff, 0x00000000},
-   {DDS_FORMAT_L8A8,    DXGI_FORMAT_UNKNOWN,           2, 1, 0x000000ff, 0x000000ff, 0x000000ff, 0x0000ff00},
-   {DDS_FORMAT_AEXP,    DXGI_FORMAT_B8G8R8A8_UNORM,    4, 1, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000},
-   {DDS_FORMAT_YCOCG,   DXGI_FORMAT_B8G8R8A8_UNORM,    4, 1, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000}
+    {DDS_FORMAT_RGB8,    DXGI_FORMAT_UNKNOWN,           3, 0, 0x00ff0000, 0x0000ff00, 0x000000ff, 
0x00000000},
+    {DDS_FORMAT_RGBA8,   DXGI_FORMAT_B8G8R8A8_UNORM,    4, 1, 0x00ff0000, 0x0000ff00, 0x000000ff, 
0xff000000},
+    {DDS_FORMAT_BGR8,    DXGI_FORMAT_UNKNOWN,           3, 0, 0x000000ff, 0x0000ff00, 0x00ff0000, 
0x00000000},
+    {DDS_FORMAT_ABGR8,   DXGI_FORMAT_R8G8B8A8_UNORM,    4, 1, 0x000000ff, 0x0000ff00, 0x00ff0000, 
0xff000000},
+    {DDS_FORMAT_R5G6B5,  DXGI_FORMAT_B5G6R5_UNORM,      2, 0, 0x0000f800, 0x000007e0, 0x0000001f, 
0x00000000},
+    {DDS_FORMAT_RGBA4,   DXGI_FORMAT_B4G4R4A4_UNORM,    2, 1, 0x00000f00, 0x000000f0, 0x0000000f, 
0x0000f000},
+    {DDS_FORMAT_RGB5A1,  DXGI_FORMAT_B5G5R5A1_UNORM,    2, 1, 0x00007c00, 0x000003e0, 0x0000001f, 
0x00008000},
+    {DDS_FORMAT_RGB10A2, DXGI_FORMAT_R10G10B10A2_UNORM, 4, 1, 0x000003ff, 0x000ffc00, 0x3ff00000, 
0xc0000000},
+    {DDS_FORMAT_R3G3B2,  DXGI_FORMAT_UNKNOWN,           1, 0, 0x000000e0, 0x0000001c, 0x00000003, 
0x00000000},
+    {DDS_FORMAT_A8,      DXGI_FORMAT_A8_UNORM,          1, 0, 0x00000000, 0x00000000, 0x00000000, 
0x000000ff},
+    {DDS_FORMAT_L8,      DXGI_FORMAT_R8_UNORM,          1, 0, 0x000000ff, 0x000000ff, 0x000000ff, 
0x00000000},
+    {DDS_FORMAT_L8A8,    DXGI_FORMAT_UNKNOWN,           2, 1, 0x000000ff, 0x000000ff, 0x000000ff, 
0x0000ff00},
+    {DDS_FORMAT_AEXP,    DXGI_FORMAT_B8G8R8A8_UNORM,    4, 1, 0x00ff0000, 0x0000ff00, 0x000000ff, 
0xff000000},
+    {DDS_FORMAT_YCOCG,   DXGI_FORMAT_B8G8R8A8_UNORM,    4, 1, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000}
 };
 
-static int check_mipmaps(gint32 image_id, int savetype)
+static int
+check_mipmaps (gint32 image_id,
+               int    savetype)
 {
-   gint *layers, num_layers;
-   int i, j, w, h, mipw, miph, num_mipmaps, num_surfaces = 0;
-   int min_surfaces = 1, max_surfaces = 1;
-   int valid = 1;
-   GimpImageType type;
-   
-   /* not handling volume maps for the moment... */
-   if(savetype == DDS_SAVE_VOLUMEMAP)
-      return(0);
-   
-   if(savetype == DDS_SAVE_CUBEMAP)
-   {
+  gint *layers, num_layers;
+  int i, j, w, h, mipw, miph, num_mipmaps, num_surfaces = 0;
+  int min_surfaces = 1, max_surfaces = 1;
+  int valid = 1;
+  GimpImageType type;
+
+  /* not handling volume maps for the moment... */
+  if (savetype == DDS_SAVE_VOLUMEMAP)
+    return (0);
+
+  if (savetype == DDS_SAVE_CUBEMAP)
+    {
       min_surfaces = 6;
       max_surfaces = 6;
-   }
-   else if(savetype == DDS_SAVE_ARRAY)
-   {
+    }
+  else if (savetype == DDS_SAVE_ARRAY)
+    {
       min_surfaces = 2;
       max_surfaces = INT_MAX;
-   }
-   
-   layers = gimp_image_get_layers(image_id, &num_layers);
-   
-   w = gimp_image_width(image_id);
-   h = gimp_image_height(image_id);
-   
-   num_mipmaps = get_num_mipmaps(w, h);
-   
-   type = gimp_drawable_type(layers[0]);
-   
-   for(i = 0; i < num_layers; ++i)
-   {
-      if(type != gimp_drawable_type(layers[i]))
-         return(0);
-      
-      if((gimp_drawable_width(layers[i])  == w) &&
-         (gimp_drawable_height(layers[i]) == h))
-         ++num_surfaces;
-   }
-   
-   if((num_surfaces < min_surfaces) ||
+    }
+
+  layers = gimp_image_get_layers (image_id, &num_layers);
+
+  w = gimp_image_width (image_id);
+  h = gimp_image_height (image_id);
+
+  num_mipmaps = get_num_mipmaps (w, h);
+
+  type = gimp_drawable_type (layers[0]);
+
+  for (i = 0; i < num_layers; ++i)
+    {
+      if (type != gimp_drawable_type (layers[i]))
+        return (0);
+
+      if ((gimp_drawable_width (layers[i])  == w) &&
+          (gimp_drawable_height (layers[i]) == h))
+        ++num_surfaces;
+    }
+
+  if ((num_surfaces < min_surfaces) ||
       (num_surfaces > max_surfaces) ||
       (num_layers != (num_surfaces * num_mipmaps)))
-      return(0);
-   
-   for(i = 0; valid && i < num_layers; i += num_mipmaps)
-   {
-      if((gimp_drawable_width(layers[i])  != w) ||
-         (gimp_drawable_height(layers[i]) != h))
-      {
-         valid = 0;
-         break;
-      }
-      
-      for(j = 1; j < num_mipmaps; ++j)
-      {
-         mipw = w >> j;
-         miph = h >> j;
-         if(mipw < 1) mipw = 1;
-         if(miph < 1) miph = 1;
-         if((gimp_drawable_width(layers[i + j])  != mipw) ||
-            (gimp_drawable_height(layers[i + j]) != miph))
-         {
-            valid = 0;
-            break;
-         }
-      }
-   }
-   
-   return(valid);
+    return (0);
+
+  for (i = 0; valid && i < num_layers; i += num_mipmaps)
+    {
+      if ((gimp_drawable_width (layers[i])  != w) ||
+          (gimp_drawable_height (layers[i]) != h))
+        {
+          valid = 0;
+          break;
+        }
+
+      for (j = 1; j < num_mipmaps; ++j)
+        {
+          mipw = w >> j;
+          miph = h >> j;
+          if (mipw < 1) mipw = 1;
+          if (miph < 1) miph = 1;
+          if ((gimp_drawable_width (layers[i + j])  != mipw) ||
+              (gimp_drawable_height (layers[i + j]) != miph))
+            {
+              valid = 0;
+              break;
+            }
+        }
+    }
+
+  return (valid);
 }
 
-static int check_cubemap(gint32 image_id)
+static int
+check_cubemap (gint32 image_id)
 {
-   gint *layers, num_layers;
-   int cubemap = 1, i, j, k, w, h;
-   char *layer_name;
-   GimpImageType type;
-   
-   layers = gimp_image_get_layers(image_id, &num_layers);
-   
-   if(num_layers < 6) return(0);
-   
-   /* check for a valid cubemap with mipmap layers */
-   if(num_layers > 6)
-   {
+  gint *layers, num_layers;
+  int cubemap = 1, i, j, k, w, h;
+  char *layer_name;
+  GimpImageType type;
+
+  layers = gimp_image_get_layers (image_id, &num_layers);
+
+  if (num_layers < 6) return (0);
+
+  /* check for a valid cubemap with mipmap layers */
+  if (num_layers > 6)
+    {
       /* check that mipmap layers are in order for a cubemap */
-      if(!check_mipmaps(image_id, DDS_SAVE_CUBEMAP))
-         return(0);
-      
+      if (!check_mipmaps (image_id, DDS_SAVE_CUBEMAP))
+        return (0);
+
       /* invalidate cubemap faces */
-      for(i = 0; i < 6; ++i)
-         cubemap_faces[i] = -1;
-      
+      for (i = 0; i < 6; ++i)
+        cubemap_faces[i] = -1;
+
       /* find the mipmap level 0 layers */
-      w = gimp_image_width(image_id);
-      h = gimp_image_height(image_id);
-      
-      for(i = 0; i < num_layers; ++i)
-      {
-         if((gimp_drawable_width(layers[i])  != w) ||
-            (gimp_drawable_height(layers[i]) != h))
+      w = gimp_image_width (image_id);
+      h = gimp_image_height (image_id);
+
+      for (i = 0; i < num_layers; ++i)
+        {
+          if ((gimp_drawable_width (layers[i])  != w) ||
+              (gimp_drawable_height (layers[i]) != h))
             continue;
-         
-         layer_name = (char*)gimp_item_get_name(layers[i]);
-         for(j = 0; j < 6; ++j)
-         {
-            for(k = 0; k < 4; ++k)
+
+          layer_name = (char*)gimp_item_get_name (layers[i]);
+          for (j = 0; j < 6; ++j)
             {
-               if(strstr(layer_name, cubemap_face_names[k][j]))
-               {
-                  if(cubemap_faces[j] == -1)
-                  {
-                     cubemap_faces[j] = layers[i];
-                     break;
-                  }
-               }
+              for (k = 0; k < 4; ++k)
+                {
+                  if (strstr (layer_name, cubemap_face_names[k][j]))
+                    {
+                      if (cubemap_faces[j] == -1)
+                        {
+                          cubemap_faces[j] = layers[i];
+                          break;
+                        }
+                    }
+                }
             }
-         }
-      }
-      
+        }
+
       /* check for 6 valid faces */
-      for(i = 0; i < 6; ++i)
-      {
-         if(cubemap_faces[i] == -1)
-         {
-            cubemap = 0;
-            break;
-         }
-      }
-      
+      for (i = 0; i < 6; ++i)
+        {
+          if (cubemap_faces[i] == -1)
+            {
+              cubemap = 0;
+              break;
+            }
+        }
+
       /* make sure they are all the same type */
-      if(cubemap)
-      {
-         type = gimp_drawable_type(cubemap_faces[0]);
-         for(i = 1; i < 6 && cubemap; ++i)
-         {
-            if(gimp_drawable_type(cubemap_faces[i]) != type)
-               cubemap = 0;
-         }
-      }
-   }   
-   
-   if(num_layers == 6)
-   {
+      if (cubemap)
+        {
+          type = gimp_drawable_type (cubemap_faces[0]);
+          for (i = 1; i < 6 && cubemap; ++i)
+            {
+              if (gimp_drawable_type (cubemap_faces[i]) != type)
+                cubemap = 0;
+            }
+        }
+    }
+
+  if (num_layers == 6)
+    {
       /* invalidate cubemap faces */
-      for(i = 0; i < 6; ++i)
-         cubemap_faces[i] = -1;
-      
-      for(i = 0; i < 6; ++i)
-      {
-         layer_name = (char*)gimp_item_get_name(layers[i]);
-         for(j = 0; j < 6; ++j)
-         {
-            for(k = 0; k < 4; ++k)
+      for (i = 0; i < 6; ++i)
+        cubemap_faces[i] = -1;
+
+      for (i = 0; i < 6; ++i)
+        {
+          layer_name = (char*)gimp_item_get_name (layers[i]);
+          for (j = 0; j < 6; ++j)
             {
-               if(strstr(layer_name, cubemap_face_names[k][j]))
-               {
-                  if(cubemap_faces[j] == -1)
-                  {
-                     cubemap_faces[j] = layers[i];
-                     break;
-                  }
-               }
+              for (k = 0; k < 4; ++k)
+                {
+                  if (strstr (layer_name, cubemap_face_names[k][j]))
+                    {
+                      if (cubemap_faces[j] == -1)
+                        {
+                          cubemap_faces[j] = layers[i];
+                          break;
+                        }
+                    }
+                }
             }
-         }
-      }
-      
+        }
+
       /* check for 6 valid faces */
-      for(i = 0; i < 6; ++i)
-      {
-         if(cubemap_faces[i] == -1)
-         {
-            cubemap = 0;
-            break;
-         }
-      }
-      
+      for (i = 0; i < 6; ++i)
+        {
+          if (cubemap_faces[i] == -1)
+            {
+              cubemap = 0;
+              break;
+            }
+        }
+
       /* make sure they are all the same size */
-      if(cubemap)
-      {
-         w = gimp_drawable_width(cubemap_faces[0]);
-         h = gimp_drawable_height(cubemap_faces[0]);
-         
-         for(i = 1; i < 6 && cubemap; ++i)
-         {
-            if((gimp_drawable_width(cubemap_faces[i])  != w) ||
-               (gimp_drawable_height(cubemap_faces[i]) != h))
-               cubemap = 0;
-         }
-      }
-      
+      if (cubemap)
+        {
+          w = gimp_drawable_width (cubemap_faces[0]);
+          h = gimp_drawable_height (cubemap_faces[0]);
+
+          for (i = 1; i < 6 && cubemap; ++i)
+            {
+              if ((gimp_drawable_width (cubemap_faces[i])  != w) ||
+                  (gimp_drawable_height (cubemap_faces[i]) != h))
+                cubemap = 0;
+            }
+        }
+
       /* make sure they are all the same type */
-      if(cubemap)
-      {
-         type = gimp_drawable_type(cubemap_faces[0]);
-         for(i = 1; i < 6 && cubemap; ++i)
-         {
-            if(gimp_drawable_type(cubemap_faces[i]) != type)
-               cubemap = 0;
-         }
-      }
-   }
-   
-   return(cubemap);
+      if (cubemap)
+        {
+          type = gimp_drawable_type (cubemap_faces[0]);
+          for (i = 1; i < 6 && cubemap; ++i)
+            {
+              if (gimp_drawable_type (cubemap_faces[i]) != type)
+                cubemap = 0;
+            }
+        }
+    }
+
+  return (cubemap);
 }
 
-static int check_volume(gint32 image_id)
+static int
+check_volume (gint32 image_id)
 {
-   gint *layers, num_layers;
-   int volume = 0, i, w, h;
-   GimpImageType type;
-   
-   layers = gimp_image_get_layers(image_id, &num_layers);
-   
-   if(num_layers > 1)
-   {
+  gint *layers, num_layers;
+  int volume = 0, i, w, h;
+  GimpImageType type;
+
+  layers = gimp_image_get_layers (image_id, &num_layers);
+
+  if (num_layers > 1)
+    {
       volume = 1;
-      
+
       /* make sure all layers are the same size */
-      w = gimp_drawable_width(layers[0]);
-      h = gimp_drawable_height(layers[0]);
-      
-      for(i = 1; i < num_layers && volume; ++i)
-      {
-         if((gimp_drawable_width(layers[i])  != w) ||
-            (gimp_drawable_height(layers[i]) != h))
+      w = gimp_drawable_width (layers[0]);
+      h = gimp_drawable_height (layers[0]);
+
+      for (i = 1; i < num_layers && volume; ++i)
+        {
+          if ((gimp_drawable_width (layers[i])  != w) ||
+              (gimp_drawable_height (layers[i]) != h))
             volume = 0;
-      }
-      
-      if(volume)
-      {
-         /* make sure all layers are the same type */
-         type = gimp_drawable_type(layers[0]);
-         for(i = 1; i < num_layers && volume; ++i)
-         {
-            if(gimp_drawable_type(layers[i]) != type)
-               volume = 0;
-         }
-      }
-   }
-   
-   return(volume);
+        }
+
+      if (volume)
+        {
+          /* make sure all layers are the same type */
+          type = gimp_drawable_type (layers[0]);
+          for (i = 1; i < num_layers && volume; ++i)
+            {
+              if (gimp_drawable_type (layers[i]) != type)
+                volume = 0;
+            }
+        }
+    }
+
+  return (volume);
 }
 
-static int check_array(gint32 image_id)
+static int
+check_array (gint32 image_id)
 {
-   gint *layers, num_layers;
-   int array = 0, i, w, h;
-   GimpImageType type;
-   
-   if(check_mipmaps(image_id, DDS_SAVE_ARRAY))
-      return(1);
-   
-   layers = gimp_image_get_layers(image_id, &num_layers);
-   
-   if(num_layers > 1)
-   {
+  gint *layers, num_layers;
+  int array = 0, i, w, h;
+  GimpImageType type;
+
+  if (check_mipmaps (image_id, DDS_SAVE_ARRAY))
+    return (1);
+
+  layers = gimp_image_get_layers (image_id, &num_layers);
+
+  if (num_layers > 1)
+    {
       array = 1;
-      
+
       /* make sure all layers are the same size */
-      w = gimp_drawable_width(layers[0]);
-      h = gimp_drawable_height(layers[0]);
-      
-      for(i = 1; i < num_layers && array; ++i)
-      {
-         if((gimp_drawable_width(layers[i])  != w) ||
-            (gimp_drawable_height(layers[i]) != h))
+      w = gimp_drawable_width (layers[0]);
+      h = gimp_drawable_height (layers[0]);
+
+      for (i = 1; i < num_layers && array; ++i)
+        {
+          if ((gimp_drawable_width (layers[i])  != w) ||
+              (gimp_drawable_height (layers[i]) != h))
             array = 0;
-      }
-      
-      if(array)
-      {
-         /* make sure all layers are the same type */
-         type = gimp_drawable_type(layers[0]);
-         for(i = 1; i < num_layers; ++i)
-         {
-            if(gimp_drawable_type(layers[i]) != type)
+        }
+
+      if (array)
+        {
+          /* make sure all layers are the same type */
+          type = gimp_drawable_type (layers[0]);
+          for (i = 1; i < num_layers; ++i)
             {
-               array = 0;
-               break;
+              if (gimp_drawable_type (layers[i]) != type)
+                {
+                  array = 0;
+                  break;
+                }
             }
-         }
-      }
-   }
-   
-   return(array);
+        }
+    }
+
+  return (array);
 }
 
-static int get_array_size(gint32 image_id)
+static int
+get_array_size (gint32 image_id)
 {
-   gint *layers, num_layers;
-   int i, w, h, elements = 0;
-   
-   layers = gimp_image_get_layers(image_id, &num_layers);
-   
-   w = gimp_image_width(image_id);
-   h = gimp_image_height(image_id);
-   
-   for(i = 0; i < num_layers; ++i)
-   {
-      if((gimp_drawable_width(layers[i]) == w) && (gimp_drawable_height(layers[i]) == h))
-         ++elements;
-   }
-   
-   return(elements);
+  gint *layers, num_layers;
+  int i, w, h, elements = 0;
+
+  layers = gimp_image_get_layers (image_id, &num_layers);
+
+  w = gimp_image_width (image_id);
+  h = gimp_image_height (image_id);
+
+  for (i = 0; i < num_layers; ++i)
+    {
+      if ((gimp_drawable_width (layers[i]) == w) && (gimp_drawable_height (layers[i]) == h))
+        ++elements;
+    }
+
+  return (elements);
 }
 
-GimpPDBStatusType write_dds(gchar *filename, gint32 image_id, gint32 drawable_id)
+GimpPDBStatusType
+write_dds (gchar    *filename,
+           gint32    image_id,
+           gint32    drawable_id,
+           gboolean  interactive_dds)
 {
-   FILE *fp;
-   gchar *tmp;
-   int rc = 0;
-
-   is_mipmap_chain_valid = check_mipmaps(image_id, dds_write_vals.savetype);
-   
-   is_cubemap = check_cubemap(image_id);
-   is_volume = check_volume(image_id);
-   is_array = check_array(image_id);
-   
-   if(interactive_dds)
-   {
-      if(!is_mipmap_chain_valid &&
-         dds_write_vals.mipmaps == DDS_MIPMAP_EXISTING)
-         dds_write_vals.mipmaps = DDS_MIPMAP_NONE;
-
-      if(!save_dialog(image_id, drawable_id))
-         return(GIMP_PDB_CANCEL);
-   }
-   else
-   {
-      if(dds_write_vals.savetype == DDS_SAVE_CUBEMAP && !is_cubemap)
-      {
-         g_message("DDS: Cannot save image as cube map");
-         return(GIMP_PDB_EXECUTION_ERROR);
-      }
-
-      if(dds_write_vals.savetype == DDS_SAVE_VOLUMEMAP && !is_volume)
-      {
-         g_message("DDS: Cannot save image as volume map");
-         return(GIMP_PDB_EXECUTION_ERROR);
-      }
-
-      if(dds_write_vals.savetype == DDS_SAVE_VOLUMEMAP &&
-         dds_write_vals.compression != DDS_COMPRESS_NONE)
-      {
-         g_message("DDS: Cannot save volume map with compression");
-         return(GIMP_PDB_EXECUTION_ERROR);
-      }
-
-      if(dds_write_vals.mipmaps == DDS_MIPMAP_EXISTING &&
-         !is_mipmap_chain_valid)
-      {
-         g_message("DDS: Cannot save with existing mipmaps as the mipmap chain is incomplete");
-         return(GIMP_PDB_EXECUTION_ERROR);
-      }
-   }
-
-   fp = g_fopen(filename, "wb");
-   if(fp == 0)
-   {
-      g_message("Error opening %s", filename);
-      return(GIMP_PDB_EXECUTION_ERROR);
-   }
-
-   if(strrchr(filename, '/'))
-      tmp = g_strdup_printf("Saving %s:", strrchr(filename, '/') + 1);
-   else
-      tmp = g_strdup_printf("Saving %s:", filename);
-   gimp_progress_init(tmp);
-   g_free(tmp);
-
-   rc = write_image(fp, image_id, drawable_id);
-
-   fclose(fp);
-
-   return(rc ? GIMP_PDB_SUCCESS : GIMP_PDB_EXECUTION_ERROR);
+  FILE *fp;
+  gchar *tmp;
+  int rc = 0;
+
+  is_mipmap_chain_valid = check_mipmaps (image_id, dds_write_vals.savetype);
+
+  is_cubemap = check_cubemap (image_id);
+  is_volume = check_volume (image_id);
+  is_array = check_array (image_id);
+
+  if (interactive_dds)
+    {
+      if (!is_mipmap_chain_valid &&
+          dds_write_vals.mipmaps == DDS_MIPMAP_EXISTING)
+        dds_write_vals.mipmaps = DDS_MIPMAP_NONE;
+
+      if (!save_dialog (image_id, drawable_id))
+        return (GIMP_PDB_CANCEL);
+    }
+  else
+    {
+      if (dds_write_vals.savetype == DDS_SAVE_CUBEMAP && !is_cubemap)
+        {
+          g_message ("DDS: Cannot save image as cube map");
+          return (GIMP_PDB_EXECUTION_ERROR);
+        }
+
+      if (dds_write_vals.savetype == DDS_SAVE_VOLUMEMAP && !is_volume)
+        {
+          g_message ("DDS: Cannot save image as volume map");
+          return (GIMP_PDB_EXECUTION_ERROR);
+        }
+
+      if (dds_write_vals.savetype == DDS_SAVE_VOLUMEMAP &&
+          dds_write_vals.compression != DDS_COMPRESS_NONE)
+        {
+          g_message ("DDS: Cannot save volume map with compression");
+          return (GIMP_PDB_EXECUTION_ERROR);
+        }
+
+      if (dds_write_vals.mipmaps == DDS_MIPMAP_EXISTING &&
+          !is_mipmap_chain_valid)
+        {
+          g_message ("DDS: Cannot save with existing mipmaps as the mipmap chain is incomplete");
+          return (GIMP_PDB_EXECUTION_ERROR);
+        }
+    }
+
+  fp = g_fopen (filename, "wb");
+  if (fp == 0)
+    {
+      g_message ("Error opening %s", filename);
+      return (GIMP_PDB_EXECUTION_ERROR);
+    }
+
+  if (strrchr (filename, '/'))
+    tmp = g_strdup_printf ("Saving %s:", strrchr (filename, '/') + 1);
+  else
+    tmp = g_strdup_printf ("Saving %s:", filename);
+  gimp_progress_init (tmp);
+  g_free (tmp);
+
+  rc = write_image (fp, image_id, drawable_id);
+
+  fclose (fp);
+
+  return (rc ? GIMP_PDB_SUCCESS : GIMP_PDB_EXECUTION_ERROR);
 }
 
-static void swap_rb(unsigned char *pixels, unsigned int n, int bpp)
+static void
+swap_rb (unsigned char *pixels,
+         unsigned int   n,
+         int            bpp)
 {
-   unsigned int i;
-   unsigned char t;
+  unsigned int i;
+  unsigned char t;
 
-   for(i = 0; i < n; ++i)
-   {
+  for (i = 0; i < n; ++i)
+    {
       t = pixels[bpp * i + 0];
       pixels[bpp * i + 0] = pixels[bpp * i + 2];
       pixels[bpp * i + 2] = t;
-   }
+    }
 }
 
-static void alpha_exp(unsigned char *dst, int r, int g, int b, int a)
+static void
+alpha_exp (unsigned char *dst,
+           int            r,
+           int            g,
+           int            b,
+           int            a)
 {
-   float ar, ag, ab, aa;
+  float ar, ag, ab, aa;
 
-   ar = (float)r / 255.0f;
-   ag = (float)g / 255.0f;
-   ab = (float)b / 255.0f;
+  ar = (float)r / 255.0f;
+  ag = (float)g / 255.0f;
+  ab = (float)b / 255.0f;
 
-   aa = MAX(ar, MAX(ag, ab));
+  aa = MAX (ar, MAX (ag, ab));
 
-   if(aa < 1e-04f)
-   {
+  if (aa < 1e-04f)
+    {
       dst[0] = b;
       dst[1] = g;
       dst[2] = r;
       dst[3] = 255;
       return;
-   }
+    }
 
-   ar /= aa;
-   ag /= aa;
-   ab /= aa;
+  ar /= aa;
+  ag /= aa;
+  ab /= aa;
 
-   r = (int)floorf(255.0f * ar + 0.5f);
-   g = (int)floorf(255.0f * ag + 0.5f);
-   b = (int)floorf(255.0f * ab + 0.5f);
-   a = (int)floorf(255.0f * aa + 0.5f);
+  r = (int)floorf (255.0f * ar + 0.5f);
+  g = (int)floorf (255.0f * ag + 0.5f);
+  b = (int)floorf (255.0f * ab + 0.5f);
+  a = (int)floorf (255.0f * aa + 0.5f);
 
-   dst[0] = MAX(0, MIN(255, b));
-   dst[1] = MAX(0, MIN(255, g));
-   dst[2] = MAX(0, MIN(255, r));
-   dst[3] = MAX(0, MIN(255, a));
+  dst[0] = MAX (0, MIN (255, b));
+  dst[1] = MAX (0, MIN (255, g));
+  dst[2] = MAX (0, MIN (255, r));
+  dst[3] = MAX (0, MIN (255, a));
 }
 
-static void convert_pixels(unsigned char *dst, unsigned char *src,
-                           int format, int w, int h, int d, int bpp,
-                           unsigned char *palette, int mipmaps)
+static void
+convert_pixels (unsigned char *dst,
+                unsigned char *src,
+                int            format,
+                int            w,
+                int            h,
+                int            d,
+                int            bpp,
+                unsigned char *palette,
+                int            mipmaps)
 {
-   unsigned int i, num_pixels;
-   unsigned char r, g, b, a;
-
-   if(d > 0)
-      num_pixels = get_volume_mipmapped_size(w, h, d, 1, 0, mipmaps, DDS_COMPRESS_NONE);
-   else
-      num_pixels = get_mipmapped_size(w, h, 1, 0, mipmaps, DDS_COMPRESS_NONE);
-
-   for(i = 0; i < num_pixels; ++i)
-   {
-      if(bpp == 1)
-      {
-         if(palette)
-         {
-            r = palette[3 * src[i] + 0];
-            g = palette[3 * src[i] + 1];
-            b = palette[3 * src[i] + 2];
-         }
-         else
+  unsigned int i, num_pixels;
+  unsigned char r, g, b, a;
+
+  if (d > 0)
+    num_pixels = get_volume_mipmapped_size (w, h, d, 1, 0, mipmaps, DDS_COMPRESS_NONE);
+  else
+    num_pixels = get_mipmapped_size (w, h, 1, 0, mipmaps, DDS_COMPRESS_NONE);
+
+  for (i = 0; i < num_pixels; ++i)
+    {
+      if (bpp == 1)
+        {
+          if (palette)
+            {
+              r = palette[3 * src[i] + 0];
+              g = palette[3 * src[i] + 1];
+              b = palette[3 * src[i] + 2];
+            }
+          else
             r = g = b = src[i];
 
-         if(format == DDS_FORMAT_A8)
+          if (format == DDS_FORMAT_A8)
             a = src[i];
-         else
+          else
             a = 255;
-      }
-      else if(bpp == 2)
-      {
-         r = g = b = src[2 * i];
-         a = src[2 * i + 1];
-      }
-      else if(bpp == 3)
-      {
-         b = src[3 * i + 0];
-         g = src[3 * i + 1];
-         r = src[3 * i + 2];
-         a = 255;
-      }
+        }
+      else if (bpp == 2)
+        {
+          r = g = b = src[2 * i];
+          a = src[2 * i + 1];
+        }
+      else if (bpp == 3)
+        {
+          b = src[3 * i + 0];
+          g = src[3 * i + 1];
+          r = src[3 * i + 2];
+          a = 255;
+        }
       else
-      {
-         b = src[4 * i + 0];
-         g = src[4 * i + 1];
-         r = src[4 * i + 2];
-         a = src[4 * i + 3];
-      }
-
-      switch(format)
-      {
-         case DDS_FORMAT_RGB8:
-            dst[3 * i + 0] = b;
-            dst[3 * i + 1] = g;
-            dst[3 * i + 2] = r;
-            break;
-         case DDS_FORMAT_RGBA8:
-            dst[4 * i + 0] = b;
-            dst[4 * i + 1] = g;
-            dst[4 * i + 2] = r;
-            dst[4 * i + 3] = a;
-            break;
-         case DDS_FORMAT_BGR8:
-            dst[3 * i + 0] = r;
-            dst[3 * i + 1] = g;
-            dst[3 * i + 2] = b;
-            break;
-         case DDS_FORMAT_ABGR8:
-            dst[4 * i + 0] = r;
-            dst[4 * i + 1] = g;
-            dst[4 * i + 2] = b;
-            dst[4 * i + 3] = a;
-            break;
-         case DDS_FORMAT_R5G6B5:
-            PUTL16(&dst[2 * i], pack_r5g6b5(r, g, b));
-            break;
-         case DDS_FORMAT_RGBA4:
-            PUTL16(&dst[2 * i], pack_rgba4(r, g, b, a));
-            break;
-         case DDS_FORMAT_RGB5A1:
-            PUTL16(&dst[2 * i], pack_rgb5a1(r, g, b, a));
-            break;
-         case DDS_FORMAT_RGB10A2:
-            PUTL32(&dst[4 * i], pack_rgb10a2(r, g, b, a));
-            break;
-         case DDS_FORMAT_R3G3B2:
-            dst[i] = pack_r3g3b2(r, g, b);
-            break;
-         case DDS_FORMAT_A8:
-            dst[i] = a;
-            break;
-         case DDS_FORMAT_L8:
-            dst[i] = rgb_to_luminance(r, g, b);
-            break;
-         case DDS_FORMAT_L8A8:
-            dst[2 * i + 0] = rgb_to_luminance(r, g, b);
-            dst[2 * i + 1] = a;
-            break;
-         case DDS_FORMAT_YCOCG:
-            dst[4 * i] = a;
-            RGB_to_YCoCg(&dst[4 * i], r, g, b);
-            break;
-         case DDS_FORMAT_AEXP:
-            alpha_exp(&dst[4 * i], r, g, b, a);
-            break;
-         default:
-            break;
-      }
-   }
+        {
+          b = src[4 * i + 0];
+          g = src[4 * i + 1];
+          r = src[4 * i + 2];
+          a = src[4 * i + 3];
+        }
+
+      switch (format)
+        {
+        case DDS_FORMAT_RGB8:
+          dst[3 * i + 0] = b;
+          dst[3 * i + 1] = g;
+          dst[3 * i + 2] = r;
+          break;
+        case DDS_FORMAT_RGBA8:
+          dst[4 * i + 0] = b;
+          dst[4 * i + 1] = g;
+          dst[4 * i + 2] = r;
+          dst[4 * i + 3] = a;
+          break;
+        case DDS_FORMAT_BGR8:
+          dst[3 * i + 0] = r;
+          dst[3 * i + 1] = g;
+          dst[3 * i + 2] = b;
+          break;
+        case DDS_FORMAT_ABGR8:
+          dst[4 * i + 0] = r;
+          dst[4 * i + 1] = g;
+          dst[4 * i + 2] = b;
+          dst[4 * i + 3] = a;
+          break;
+        case DDS_FORMAT_R5G6B5:
+          PUTL16(&dst[2 * i], pack_r5g6b5(r, g, b));
+          break;
+        case DDS_FORMAT_RGBA4:
+          PUTL16(&dst[2 * i], pack_rgba4(r, g, b, a));
+          break;
+        case DDS_FORMAT_RGB5A1:
+          PUTL16(&dst[2 * i], pack_rgb5a1(r, g, b, a));
+          break;
+        case DDS_FORMAT_RGB10A2:
+          PUTL32(&dst[4 * i], pack_rgb10a2(r, g, b, a));
+          break;
+        case DDS_FORMAT_R3G3B2:
+          dst[i] = pack_r3g3b2(r, g, b);
+          break;
+        case DDS_FORMAT_A8:
+          dst[i] = a;
+          break;
+        case DDS_FORMAT_L8:
+          dst[i] = rgb_to_luminance (r, g, b);
+          break;
+        case DDS_FORMAT_L8A8:
+          dst[2 * i + 0] = rgb_to_luminance (r, g, b);
+          dst[2 * i + 1] = a;
+          break;
+        case DDS_FORMAT_YCOCG:
+          dst[4 * i] = a;
+          RGB_to_YCoCg (&dst[4 * i], r, g, b);
+          break;
+        case DDS_FORMAT_AEXP:
+          alpha_exp (&dst[4 * i], r, g, b, a);
+          break;
+        default:
+          break;
+        }
+    }
 }
 
-static void get_mipmap_chain(unsigned char *dst, int w, int h, int bpp,
-                             gint32 image_id, gint drawable_id)
+static void
+get_mipmap_chain (unsigned char *dst,
+                  int            w,
+                  int            h,
+                  int            bpp,
+                  gint32         image_id,
+                  gint           drawable_id)
 {
-   gint *layers, num_layers;
-   GeglBuffer *buffer;
-   const Babl *format = 0;
-   int i, idx = 0, offset, mipw, miph;
-
-   if(bpp == 1)
-      format = babl_format("Y' u8");
-   else if(bpp == 2)
-      format = babl_format("Y'A u8");
-   else if(bpp == 3)
-      format = babl_format("R'G'B' u8");
-   else
-      format = babl_format("R'G'B'A u8");
-               
-   layers = gimp_image_get_layers(image_id, &num_layers);
-   
-   for(i = 0; i < num_layers; ++i)
-   {
-      if(layers[i] == drawable_id)
-      {
-         idx = i;
-         break;
-      }
-   }
-   
-   if(i == num_layers) return;
-   
-   offset = 0;
-
-   while(get_next_mipmap_dimensions(&mipw, &miph, w, h))
-   {
-      buffer = gimp_drawable_get_buffer(layers[++idx]);
-      
-      if((gegl_buffer_get_width(buffer)  != mipw) ||
-         (gegl_buffer_get_height(buffer) != miph))
-      {
-         g_object_unref(buffer);
-         return;
-      }
-      
-      gegl_buffer_get(buffer, GEGL_RECTANGLE(0, 0, mipw, miph), 1.0, format,
-                      dst + offset, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
-      g_object_unref(buffer);
+  gint *layers, num_layers;
+  GeglBuffer *buffer;
+  const Babl *format = 0;
+  int i, idx = 0, offset, mipw, miph;
+
+  if (bpp == 1)
+    format = babl_format ("Y' u8");
+  else if (bpp == 2)
+    format = babl_format ("Y'A u8");
+  else if (bpp == 3)
+    format = babl_format ("R'G'B' u8");
+  else
+    format = babl_format ("R'G'B'A u8");
+
+  layers = gimp_image_get_layers (image_id, &num_layers);
+
+  for (i = 0; i < num_layers; ++i)
+    {
+      if (layers[i] == drawable_id)
+        {
+          idx = i;
+          break;
+        }
+    }
+
+  if (i == num_layers) return;
+
+  offset = 0;
+
+  while (get_next_mipmap_dimensions (&mipw, &miph, w, h))
+    {
+      buffer = gimp_drawable_get_buffer (layers[++idx]);
+
+      if ((gegl_buffer_get_width (buffer)  != mipw) ||
+          (gegl_buffer_get_height (buffer) != miph))
+        {
+          g_object_unref (buffer);
+          return;
+        }
+
+      gegl_buffer_get (buffer, GEGL_RECTANGLE (0, 0, mipw, miph), 1.0, format,
+                       dst + offset, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
+      g_object_unref (buffer);
 
       /* we need BGRX or BGRA */
-      if(bpp >= 3)
-         swap_rb(dst + offset, mipw * miph, bpp);
+      if (bpp >= 3)
+        swap_rb (dst + offset, mipw * miph, bpp);
 
       offset += (mipw * miph * bpp);
       w = mipw;
       h = miph;
-   }
+    }
 }
 
-static void write_layer(FILE *fp, gint32 image_id, gint32 drawable_id,
-                        int w, int h, int bpp, int fmtbpp, int mipmaps)
+static void
+write_layer (FILE   *fp,
+             gint32  image_id,
+             gint32  drawable_id,
+             int     w,
+             int     h,
+             int     bpp,
+             int     fmtbpp,
+             int     mipmaps)
 {
-   GeglBuffer *buffer;
-   const Babl *format = 0;
-   GimpImageBaseType basetype;
-   GimpImageType type;
-   unsigned char *src, *dst, *fmtdst, *tmp;
-   unsigned char *palette = NULL;
-   int i, c, x, y, size, fmtsize, offset, colors;
-   int compression = dds_write_vals.compression;
-   int flags = 0;
-
-   basetype = gimp_image_base_type(image_id);
-   type = gimp_drawable_type(drawable_id);
-
-   buffer = gimp_drawable_get_buffer(drawable_id);
-   
-   src = g_malloc(w * h * bpp);
-   
-   if(bpp == 1)
-      format = babl_format("Y' u8");
-   else if(bpp == 2)
-      format = babl_format("Y'A u8");
-   else if(bpp == 3)
-      format = babl_format("R'G'B' u8");
-   else
-      format = babl_format("R'G'B'A u8");
-               
-   gegl_buffer_get(buffer, GEGL_RECTANGLE(0, 0, w, h), 1.0, format, src,
+  GeglBuffer *buffer;
+  const Babl *format = 0;
+  GimpImageBaseType basetype;
+  GimpImageType type;
+  unsigned char *src, *dst, *fmtdst, *tmp;
+  unsigned char *palette = NULL;
+  int i, c, x, y, size, fmtsize, offset, colors;
+  int compression = dds_write_vals.compression;
+  int flags = 0;
+
+  basetype = gimp_image_base_type (image_id);
+  type = gimp_drawable_type (drawable_id);
+
+  buffer = gimp_drawable_get_buffer (drawable_id);
+
+  src = g_malloc (w * h * bpp);
+
+  if (bpp == 1)
+    format = babl_format ("Y' u8");
+  else if (bpp == 2)
+    format = babl_format ("Y'A u8");
+  else if (bpp == 3)
+    format = babl_format ("R'G'B' u8");
+  else
+    format = babl_format ("R'G'B'A u8");
+
+  gegl_buffer_get (buffer, GEGL_RECTANGLE (0, 0, w, h), 1.0, format, src,
                    GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
 
-   if(basetype == GIMP_INDEXED)
-   {
-      palette = gimp_image_get_colormap(image_id, &colors);
+  if (basetype == GIMP_INDEXED)
+    {
+      palette = gimp_image_get_colormap (image_id, &colors);
 
-      if(type == GIMP_INDEXEDA_IMAGE)
-      {
-         tmp = g_malloc(w * h);
-         for(i = 0; i < w * h; ++i)
+      if (type == GIMP_INDEXEDA_IMAGE)
+        {
+          tmp = g_malloc (w * h);
+          for (i = 0; i < w * h; ++i)
             tmp[i] = src[2 * i];
-         g_free(src);
-         src = tmp;
-         bpp = 1;
-      }
-   }
-
-   /* we want and assume BGRA ordered pixels for bpp >= 3 from here and
-      onwards */
-   if(bpp >= 3)
-      swap_rb(src, w * h, bpp);
-
-   if(compression == DDS_COMPRESS_BC3N)
-   {
-      if(bpp != 4)
-      {
-         fmtsize = w * h * 4;
-         fmtdst = g_malloc(fmtsize);
-         convert_pixels(fmtdst, src, DDS_FORMAT_RGBA8, w, h, 0, bpp,
-                        palette, 1);
-         g_free(src);
-         src = fmtdst;
-         bpp = 4;
-      }
-
-      for(y = 0; y < h; ++y)
-      {
-         for(x = 0; x < w; ++x)
-         {
-            /* set alpha to red (x) */
-            src[y * (w * 4) + (x * 4) + 3] =
-               src[y * (w * 4) + (x * 4) + 2];
-            /* set red to 1 */
-            src[y * (w * 4) + (x * 4) + 2] = 255;
-         }
-      }
-   }
-
-   /* RXGB (Doom3) */
-   if(compression == DDS_COMPRESS_RXGB)
-   {
-      if(bpp != 4)
-      {
-         fmtsize = w * h * 4;
-         fmtdst = g_malloc(fmtsize);
-         convert_pixels(fmtdst, src, DDS_FORMAT_RGBA8, w, h, 0, bpp,
-                        palette, 1);
-         g_free(src);
-         src = fmtdst;
-         bpp = 4;
-      }
-
-      for(y = 0; y < h; ++y)
-      {
-         for(x = 0; x < w; ++x)
-         {
-            /* swap red and alpha */
-            c = src[y * (w * 4) + (x * 4) + 3];
-            src[y * (w * 4) + (x * 4) + 3] =
-               src[y * (w * 4) + (x * 4) + 2];
-            src[y * (w * 4) + (x * 4) + 2] = c;
-         }
-      }
-   }
-
-   if(compression == DDS_COMPRESS_YCOCG ||
+          g_free (src);
+          src = tmp;
+          bpp = 1;
+        }
+    }
+
+  /* we want and assume BGRA ordered pixels for bpp >= 3 from here and
+     onwards */
+  if (bpp >= 3)
+    swap_rb (src, w * h, bpp);
+
+  if (compression == DDS_COMPRESS_BC3N)
+    {
+      if (bpp != 4)
+        {
+          fmtsize = w * h * 4;
+          fmtdst = g_malloc (fmtsize);
+          convert_pixels (fmtdst, src, DDS_FORMAT_RGBA8, w, h, 0, bpp,
+                          palette, 1);
+          g_free (src);
+          src = fmtdst;
+          bpp = 4;
+        }
+
+      for (y = 0; y < h; ++y)
+        {
+          for (x = 0; x < w; ++x)
+            {
+              /* set alpha to red (x) */
+              src[y * (w * 4) + (x * 4) + 3] =
+                src[y * (w * 4) + (x * 4) + 2];
+              /* set red to 1 */
+              src[y * (w * 4) + (x * 4) + 2] = 255;
+            }
+        }
+    }
+
+  /* RXGB (Doom3) */
+  if (compression == DDS_COMPRESS_RXGB)
+    {
+      if (bpp != 4)
+        {
+          fmtsize = w * h * 4;
+          fmtdst = g_malloc (fmtsize);
+          convert_pixels (fmtdst, src, DDS_FORMAT_RGBA8, w, h, 0, bpp,
+                          palette, 1);
+          g_free (src);
+          src = fmtdst;
+          bpp = 4;
+        }
+
+      for (y = 0; y < h; ++y)
+        {
+          for (x = 0; x < w; ++x)
+            {
+              /* swap red and alpha */
+              c = src[y * (w * 4) + (x * 4) + 3];
+              src[y * (w * 4) + (x * 4) + 3] =
+                src[y * (w * 4) + (x * 4) + 2];
+              src[y * (w * 4) + (x * 4) + 2] = c;
+            }
+        }
+    }
+
+  if (compression == DDS_COMPRESS_YCOCG ||
       compression == DDS_COMPRESS_YCOCGS) /* convert to YCoCG */
-   {
+    {
       fmtsize = w * h * 4;
-      fmtdst = g_malloc(fmtsize);
-      convert_pixels(fmtdst, src, DDS_FORMAT_YCOCG, w, h, 0, bpp,
-                     palette, 1);
-      g_free(src);
+      fmtdst = g_malloc (fmtsize);
+      convert_pixels (fmtdst, src, DDS_FORMAT_YCOCG, w, h, 0, bpp,
+                      palette, 1);
+      g_free (src);
       src = fmtdst;
       bpp = 4;
-   }
+    }
 
-   if(compression == DDS_COMPRESS_AEXP)
-   {
+  if (compression == DDS_COMPRESS_AEXP)
+    {
       fmtsize = w * h * 4;
-      fmtdst = g_malloc(fmtsize);
-      convert_pixels(fmtdst, src, DDS_FORMAT_AEXP, w, h, 0, bpp,
-                     palette, 1);
-      g_free(src);
+      fmtdst = g_malloc (fmtsize);
+      convert_pixels (fmtdst, src, DDS_FORMAT_AEXP, w, h, 0, bpp,
+                      palette, 1);
+      g_free (src);
       src = fmtdst;
       bpp = 4;
-   }
-
-   if(compression == DDS_COMPRESS_NONE)
-   {
-      if(mipmaps > 1)
-      {
-         /* pre-convert indexed images to RGB for better quality mipmaps
-            if a pixel format conversion is requested */
-         if(dds_write_vals.format > DDS_FORMAT_DEFAULT && basetype == GIMP_INDEXED)
-         {
-            fmtsize = get_mipmapped_size(w, h, 3, 0, mipmaps, DDS_COMPRESS_NONE);
-            fmtdst = g_malloc(fmtsize);
-            convert_pixels(fmtdst, src, DDS_FORMAT_RGB8, w, h, 0, bpp,
-                           palette, 1);
-            g_free(src);
-            src = fmtdst;
-            bpp = 3;
-            palette = NULL;
-         }
-
-         size = get_mipmapped_size(w, h, bpp, 0, mipmaps, DDS_COMPRESS_NONE);
-         dst = g_malloc(size);
-         if(dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE)
-         {
-            generate_mipmaps(dst, src, w, h, bpp, palette != NULL,
-                             mipmaps,
-                             dds_write_vals.mipmap_filter,
-                             dds_write_vals.mipmap_wrap,
-                             dds_write_vals.gamma_correct + dds_write_vals.srgb,
-                             dds_write_vals.gamma,
-                             dds_write_vals.preserve_alpha_coverage,
-                             dds_write_vals.alpha_test_threshold);
-         }
-         else
-         {
-            memcpy(dst, src, w * h * bpp);
-            get_mipmap_chain(dst + (w * h * bpp), w, h, bpp, image_id, drawable_id);
-         }
-
-         if(dds_write_vals.format > DDS_FORMAT_DEFAULT)
-         {
-            fmtsize = get_mipmapped_size(w, h, fmtbpp, 0, mipmaps,
-                                         DDS_COMPRESS_NONE);
-            fmtdst = g_malloc(fmtsize);
-
-            convert_pixels(fmtdst, dst, dds_write_vals.format, w, h, 0, bpp,
-                           palette, mipmaps);
-
-            g_free(dst);
-            dst = fmtdst;
-            bpp = fmtbpp;
-         }
-
-         offset = 0;
-
-         for(i = 0; i < mipmaps; ++i)
-         {
-            size = get_mipmapped_size(w, h, bpp, i, 1, DDS_COMPRESS_NONE);
-            fwrite(dst + offset, 1, size, fp);
-            offset += size;
-         }
-
-         g_free(dst);
-      }
+    }
+
+  if (compression == DDS_COMPRESS_NONE)
+    {
+      if (mipmaps > 1)
+        {
+          /* pre-convert indexed images to RGB for better quality mipmaps
+             if a pixel format conversion is requested */
+          if (dds_write_vals.format > DDS_FORMAT_DEFAULT && basetype == GIMP_INDEXED)
+            {
+              fmtsize = get_mipmapped_size (w, h, 3, 0, mipmaps, DDS_COMPRESS_NONE);
+              fmtdst = g_malloc (fmtsize);
+              convert_pixels (fmtdst, src, DDS_FORMAT_RGB8, w, h, 0, bpp,
+                              palette, 1);
+              g_free (src);
+              src = fmtdst;
+              bpp = 3;
+              palette = NULL;
+            }
+
+          size = get_mipmapped_size (w, h, bpp, 0, mipmaps, DDS_COMPRESS_NONE);
+          dst = g_malloc (size);
+          if (dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE)
+            {
+              generate_mipmaps (dst, src, w, h, bpp, palette != NULL,
+                                mipmaps,
+                                dds_write_vals.mipmap_filter,
+                                dds_write_vals.mipmap_wrap,
+                                dds_write_vals.gamma_correct + dds_write_vals.srgb,
+                                dds_write_vals.gamma,
+                                dds_write_vals.preserve_alpha_coverage,
+                                dds_write_vals.alpha_test_threshold);
+            }
+          else
+            {
+              memcpy (dst, src, w * h * bpp);
+              get_mipmap_chain (dst + (w * h * bpp), w, h, bpp, image_id, drawable_id);
+            }
+
+          if (dds_write_vals.format > DDS_FORMAT_DEFAULT)
+            {
+              fmtsize = get_mipmapped_size (w, h, fmtbpp, 0, mipmaps,
+                                            DDS_COMPRESS_NONE);
+              fmtdst = g_malloc (fmtsize);
+
+              convert_pixels (fmtdst, dst, dds_write_vals.format, w, h, 0, bpp,
+                              palette, mipmaps);
+
+              g_free (dst);
+              dst = fmtdst;
+              bpp = fmtbpp;
+            }
+
+          offset = 0;
+
+          for (i = 0; i < mipmaps; ++i)
+            {
+              size = get_mipmapped_size (w, h, bpp, i, 1, DDS_COMPRESS_NONE);
+              fwrite (dst + offset, 1, size, fp);
+              offset += size;
+            }
+
+          g_free (dst);
+        }
       else
-      {
-         if(dds_write_vals.format > DDS_FORMAT_DEFAULT)
-         {
-            fmtdst = g_malloc(h * w * fmtbpp);
-            convert_pixels(fmtdst, src, dds_write_vals.format, w, h, 0, bpp,
-                           palette, 1);
-            g_free(src);
-            src = fmtdst;
-            bpp = fmtbpp;
-         }
-
-         fwrite(src, 1, h * w * bpp, fp);
-      }
-   }
-   else
-   {
-      size = get_mipmapped_size(w, h, bpp, 0, mipmaps, compression);
-
-      dst = g_malloc(size);
-
-      if(basetype == GIMP_INDEXED)
-      {
-         fmtsize = get_mipmapped_size(w, h, 3, 0, mipmaps,
-                                      DDS_COMPRESS_NONE);
-         fmtdst = g_malloc(fmtsize);
-         convert_pixels(fmtdst, src, DDS_FORMAT_RGB8, w, h, 0, bpp,
-                        palette, mipmaps);
-         g_free(src);
-         src = fmtdst;
-         bpp = 3;
-      }
-
-      if(mipmaps > 1)
-      {
-         fmtsize = get_mipmapped_size(w, h, bpp, 0, mipmaps,
-                                      DDS_COMPRESS_NONE);
-         fmtdst = g_malloc(fmtsize);
-         if(dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE)
-         {
-            generate_mipmaps(fmtdst, src, w, h, bpp, 0, mipmaps,
-                             dds_write_vals.mipmap_filter,
-                             dds_write_vals.mipmap_wrap,
-                             dds_write_vals.gamma_correct + dds_write_vals.srgb,
-                             dds_write_vals.gamma,
-                             dds_write_vals.preserve_alpha_coverage,
-                             dds_write_vals.alpha_test_threshold);
-         }
-         else
-         {
-            memcpy(fmtdst, src, w * h * bpp);
-            get_mipmap_chain(fmtdst + (w * h * bpp), w, h, bpp, image_id, drawable_id);
-         }
-
-         g_free(src);
-         src = fmtdst;
-      }
+        {
+          if (dds_write_vals.format > DDS_FORMAT_DEFAULT)
+            {
+              fmtdst = g_malloc (h * w * fmtbpp);
+              convert_pixels (fmtdst, src, dds_write_vals.format, w, h, 0, bpp,
+                              palette, 1);
+              g_free (src);
+              src = fmtdst;
+              bpp = fmtbpp;
+            }
+
+          fwrite (src, 1, h * w * bpp, fp);
+        }
+    }
+  else
+    {
+      size = get_mipmapped_size (w, h, bpp, 0, mipmaps, compression);
+
+      dst = g_malloc (size);
+
+      if (basetype == GIMP_INDEXED)
+        {
+          fmtsize = get_mipmapped_size (w, h, 3, 0, mipmaps,
+                                        DDS_COMPRESS_NONE);
+          fmtdst = g_malloc (fmtsize);
+          convert_pixels (fmtdst, src, DDS_FORMAT_RGB8, w, h, 0, bpp,
+                          palette, mipmaps);
+          g_free (src);
+          src = fmtdst;
+          bpp = 3;
+        }
+
+      if (mipmaps > 1)
+        {
+          fmtsize = get_mipmapped_size (w, h, bpp, 0, mipmaps,
+                                        DDS_COMPRESS_NONE);
+          fmtdst = g_malloc (fmtsize);
+          if (dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE)
+            {
+              generate_mipmaps (fmtdst, src, w, h, bpp, 0, mipmaps,
+                                dds_write_vals.mipmap_filter,
+                                dds_write_vals.mipmap_wrap,
+                                dds_write_vals.gamma_correct + dds_write_vals.srgb,
+                                dds_write_vals.gamma,
+                                dds_write_vals.preserve_alpha_coverage,
+                                dds_write_vals.alpha_test_threshold);
+            }
+          else
+            {
+              memcpy (fmtdst, src, w * h * bpp);
+              get_mipmap_chain (fmtdst + (w * h * bpp), w, h, bpp, image_id, drawable_id);
+            }
+
+          g_free (src);
+          src = fmtdst;
+        }
 
       flags = 0;
-      if(dds_write_vals.perceptual_metric) flags |= DXT_PERCEPTUAL;
+      if (dds_write_vals.perceptual_metric) flags |= DXT_PERCEPTUAL;
 
-      dxt_compress(dst, src, compression, w, h, bpp, mipmaps, flags);
+      dxt_compress (dst, src, compression, w, h, bpp, mipmaps, flags);
 
-      fwrite(dst, 1, size, fp);
+      fwrite (dst, 1, size, fp);
 
-      g_free(dst);
-   }
+      g_free (dst);
+    }
 
-   g_free(src);
+  g_free (src);
 
-   g_object_unref(buffer);
+  g_object_unref (buffer);
 }
 
-static void write_volume_mipmaps(FILE *fp, gint32 image_id, gint32 *layers,
-                                 int w, int h, int d, int bpp, int fmtbpp,
-                                 int mipmaps)
+static void
+write_volume_mipmaps (FILE   *fp,
+                      gint32  image_id,
+                      gint32 *layers,
+                      int     w,
+                      int     h,
+                      int     d,
+                      int     bpp,
+                      int     fmtbpp,
+                      int     mipmaps)
 {
-   int i, size, offset, colors;
-   unsigned char *src, *dst, *tmp, *fmtdst;
-   unsigned char *palette = 0;
-   GeglBuffer *buffer;
-   const Babl *format;
-   GimpImageBaseType type;
-
-   type = gimp_image_base_type(image_id);
-
-   if(dds_write_vals.compression != DDS_COMPRESS_NONE) return;
-
-   src = g_malloc(w * h * bpp * d);
-
-   if(bpp == 1)
-      format = babl_format("Y' u8");
-   else if(bpp == 2)
-      format = babl_format("Y'A u8");
-   else if(bpp == 3)
-      format = babl_format("R'G'B' u8");
-   else
-      format = babl_format("R'G'B'A u8");
-               
-   if(gimp_image_base_type(image_id) == GIMP_INDEXED)
-      palette = gimp_image_get_colormap(image_id, &colors);
-
-   offset = 0;
-   for(i = 0; i < d; ++i)
-   {
-      buffer = gimp_drawable_get_buffer(layers[i]);
-      gegl_buffer_get(buffer, GEGL_RECTANGLE(0, 0, w, h), 1.0, format,
-                      src + offset, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
+  int i, size, offset, colors;
+  unsigned char *src, *dst, *tmp, *fmtdst;
+  unsigned char *palette = 0;
+  GeglBuffer *buffer;
+  const Babl *format;
+  GimpImageBaseType type;
+
+  type = gimp_image_base_type (image_id);
+
+  if (dds_write_vals.compression != DDS_COMPRESS_NONE) return;
+
+  src = g_malloc (w * h * bpp * d);
+
+  if (bpp == 1)
+    format = babl_format ("Y' u8");
+  else if (bpp == 2)
+    format = babl_format ("Y'A u8");
+  else if (bpp == 3)
+    format = babl_format ("R'G'B' u8");
+  else
+    format = babl_format ("R'G'B'A u8");
+
+  if (gimp_image_base_type (image_id) == GIMP_INDEXED)
+    palette = gimp_image_get_colormap (image_id, &colors);
+
+  offset = 0;
+  for (i = 0; i < d; ++i)
+    {
+      buffer = gimp_drawable_get_buffer (layers[i]);
+      gegl_buffer_get (buffer, GEGL_RECTANGLE (0, 0, w, h), 1.0, format,
+                       src + offset, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
       offset += (w * h * bpp);
-      g_object_unref(buffer);
-   }
-
-   if(gimp_drawable_type(layers[0]) == GIMP_INDEXEDA_IMAGE)
-   {
-      tmp = g_malloc(w * h * d);
-      for(i = 0; i < w * h * d; ++i)
-         tmp[i] = src[2 * i];
-      g_free(src);
+      g_object_unref (buffer);
+    }
+
+  if (gimp_drawable_type (layers[0]) == GIMP_INDEXEDA_IMAGE)
+    {
+      tmp = g_malloc (w * h * d);
+      for (i = 0; i < w * h * d; ++i)
+        tmp[i] = src[2 * i];
+      g_free (src);
       src = tmp;
       bpp = 1;
-   }
-
-   /* we want and assume BGRA ordered pixels for bpp >= 3 from here and
-      onwards */
-   if(bpp >= 3)
-      swap_rb(src, w * h * d, bpp);
-
-   /* pre-convert indexed images to RGB for better mipmaps if a
-      pixel format conversion is requested */
-   if(dds_write_vals.format > DDS_FORMAT_DEFAULT && type == GIMP_INDEXED)
-   {
-      size = get_volume_mipmapped_size(w, h, d, 3, 0, mipmaps,
-                                       DDS_COMPRESS_NONE);
-      dst = g_malloc(size);
-      convert_pixels(dst, src, DDS_FORMAT_RGB8, w, h, d, bpp, palette, 1);
-      g_free(src);
+    }
+
+  /* we want and assume BGRA ordered pixels for bpp >= 3 from here and
+     onwards */
+  if (bpp >= 3)
+    swap_rb (src, w * h * d, bpp);
+
+  /* pre-convert indexed images to RGB for better mipmaps if a
+     pixel format conversion is requested */
+  if (dds_write_vals.format > DDS_FORMAT_DEFAULT && type == GIMP_INDEXED)
+    {
+      size = get_volume_mipmapped_size (w, h, d, 3, 0, mipmaps,
+                                        DDS_COMPRESS_NONE);
+      dst = g_malloc (size);
+      convert_pixels (dst, src, DDS_FORMAT_RGB8, w, h, d, bpp, palette, 1);
+      g_free (src);
       src = dst;
       bpp = 3;
       palette = NULL;
-   }
+    }
 
-   size = get_volume_mipmapped_size(w, h, d, bpp, 0, mipmaps,
+  size = get_volume_mipmapped_size (w, h, d, bpp, 0, mipmaps,
                                     dds_write_vals.compression);
 
-   dst = g_malloc(size);
+  dst = g_malloc (size);
 
-   offset = get_volume_mipmapped_size(w, h, d, bpp, 0, 1,
+  offset = get_volume_mipmapped_size (w, h, d, bpp, 0, 1,
                                       dds_write_vals.compression);
 
-   generate_volume_mipmaps(dst, src, w, h, d, bpp,
+  generate_volume_mipmaps (dst, src, w, h, d, bpp,
                            palette != NULL, mipmaps,
                            dds_write_vals.mipmap_filter,
                            dds_write_vals.mipmap_wrap,
                            dds_write_vals.gamma_correct + dds_write_vals.srgb,
                            dds_write_vals.gamma);
 
-   if(dds_write_vals.format > DDS_FORMAT_DEFAULT)
-   {
-      size = get_volume_mipmapped_size(w, h, d, fmtbpp, 0, mipmaps,
-                                       dds_write_vals.compression);
-      offset = get_volume_mipmapped_size(w, h, d, fmtbpp, 0, 1,
-                                         dds_write_vals.compression);
-      fmtdst = g_malloc(size);
-
-      convert_pixels(fmtdst, dst, dds_write_vals.format, w, h, d, bpp,
-                     palette, mipmaps);
-      g_free(dst);
+  if (dds_write_vals.format > DDS_FORMAT_DEFAULT)
+    {
+      size = get_volume_mipmapped_size (w, h, d, fmtbpp, 0, mipmaps,
+                                        dds_write_vals.compression);
+      offset = get_volume_mipmapped_size (w, h, d, fmtbpp, 0, 1,
+                                          dds_write_vals.compression);
+      fmtdst = g_malloc (size);
+
+      convert_pixels (fmtdst, dst, dds_write_vals.format, w, h, d, bpp,
+                      palette, mipmaps);
+      g_free (dst);
       dst = fmtdst;
-   }
+    }
 
-   fwrite(dst + offset, 1, size, fp);
+  fwrite (dst + offset, 1, size, fp);
 
-   g_free(src);
-   g_free(dst);
+  g_free (src);
+  g_free (dst);
 }
 
-static int write_image(FILE *fp, gint32 image_id, gint32 drawable_id)
+static int
+write_image (FILE   *fp,
+             gint32  image_id,
+             gint32  drawable_id)
 {
-   GimpImageType drawable_type;
-   GimpImageBaseType basetype;
-   int i, w, h, bpp = 0, fmtbpp = 0, has_alpha = 0;
-   int num_mipmaps;
-   unsigned char hdr[DDS_HEADERSIZE], hdr10[DDS_HEADERSIZE_DX10];
-   unsigned int flags = 0, pflags = 0, caps = 0, caps2 = 0, size = 0;
-   unsigned int rmask = 0, gmask = 0, bmask = 0, amask = 0;
-   unsigned int fourcc = 0;
-   DXGI_FORMAT dxgi_format = DXGI_FORMAT_UNKNOWN;
-   gint32 num_layers, *layers;
-   guchar *cmap;
-   gint colors;
-   unsigned char zero[4] = {0, 0, 0, 0};
-   int is_dx10 = 0, array_size = 1;
-
-   layers = gimp_image_get_layers(image_id, &num_layers);
-   
-   if(dds_write_vals.mipmaps == DDS_MIPMAP_EXISTING)
-      drawable_id = layers[0];
-
-   if(dds_write_vals.savetype == DDS_SAVE_SELECTED_LAYER)
-   {
-      w = gimp_drawable_width(drawable_id);
-      h = gimp_drawable_height(drawable_id);
-   }
-   else
-   {
-      w = gimp_image_width(image_id);
-      h = gimp_image_height(image_id);
-   }
-
-   basetype = gimp_image_base_type(image_id);
-   drawable_type = gimp_drawable_type(drawable_id);
-
-   switch(drawable_type)
-   {
-      case GIMP_RGB_IMAGE:      bpp = 3; break;
-      case GIMP_RGBA_IMAGE:     bpp = 4; break;
-      case GIMP_GRAY_IMAGE:     bpp = 1; break;
-      case GIMP_GRAYA_IMAGE:    bpp = 2; break;
-      case GIMP_INDEXED_IMAGE:  bpp = 1; break;
-      case GIMP_INDEXEDA_IMAGE: bpp = 2; break;
-      default:
-         break;
-   }
-
-   if(dds_write_vals.format > DDS_FORMAT_DEFAULT)
-   {
-      for(i = 0; ; ++i)
-      {
-         if(format_info[i].format == dds_write_vals.format)
-         {
-            fmtbpp = format_info[i].bpp;
-            has_alpha = format_info[i].alpha;
-            rmask = format_info[i].rmask;
-            gmask = format_info[i].gmask;
-            bmask = format_info[i].bmask;
-            amask = format_info[i].amask;
-            dxgi_format = format_info[i].dxgi_format;
-            break;
-         }
-      }
-   }
-   else if(bpp == 1)
-   {
-      if(basetype == GIMP_INDEXED)
-      {
-         fmtbpp = 1;
-         has_alpha = 0;
-         rmask = bmask = gmask = amask = 0;
-      }
+  GimpImageType drawable_type;
+  GimpImageBaseType basetype;
+  int i, w, h, bpp = 0, fmtbpp = 0, has_alpha = 0;
+  int num_mipmaps;
+  unsigned char hdr[DDS_HEADERSIZE], hdr10[DDS_HEADERSIZE_DX10];
+  unsigned int flags = 0, pflags = 0, caps = 0, caps2 = 0, size = 0;
+  unsigned int rmask = 0, gmask = 0, bmask = 0, amask = 0;
+  unsigned int fourcc = 0;
+  DXGI_FORMAT dxgi_format = DXGI_FORMAT_UNKNOWN;
+  gint32 num_layers, *layers;
+  guchar *cmap;
+  gint colors;
+  unsigned char zero[4] = {0, 0, 0, 0};
+  int is_dx10 = 0, array_size = 1;
+
+  layers = gimp_image_get_layers (image_id, &num_layers);
+
+  if (dds_write_vals.mipmaps == DDS_MIPMAP_EXISTING)
+    drawable_id = layers[0];
+
+  if (dds_write_vals.savetype == DDS_SAVE_SELECTED_LAYER)
+    {
+      w = gimp_drawable_width (drawable_id);
+      h = gimp_drawable_height (drawable_id);
+    }
+  else
+    {
+      w = gimp_image_width (image_id);
+      h = gimp_image_height (image_id);
+    }
+
+  basetype = gimp_image_base_type (image_id);
+  drawable_type = gimp_drawable_type (drawable_id);
+
+  switch (drawable_type)
+    {
+    case GIMP_RGB_IMAGE:      bpp = 3; break;
+    case GIMP_RGBA_IMAGE:     bpp = 4; break;
+    case GIMP_GRAY_IMAGE:     bpp = 1; break;
+    case GIMP_GRAYA_IMAGE:    bpp = 2; break;
+    case GIMP_INDEXED_IMAGE:  bpp = 1; break;
+    case GIMP_INDEXEDA_IMAGE: bpp = 2; break;
+    default:
+                              break;
+    }
+
+  if (dds_write_vals.format > DDS_FORMAT_DEFAULT)
+    {
+      for (i = 0; ; ++i)
+        {
+          if (format_info[i].format == dds_write_vals.format)
+            {
+              fmtbpp = format_info[i].bpp;
+              has_alpha = format_info[i].alpha;
+              rmask = format_info[i].rmask;
+              gmask = format_info[i].gmask;
+              bmask = format_info[i].bmask;
+              amask = format_info[i].amask;
+              dxgi_format = format_info[i].dxgi_format;
+              break;
+            }
+        }
+    }
+  else if (bpp == 1)
+    {
+      if (basetype == GIMP_INDEXED)
+        {
+          fmtbpp = 1;
+          has_alpha = 0;
+          rmask = bmask = gmask = amask = 0;
+        }
       else
-      {
-         fmtbpp = 1;
-         has_alpha = 0;
-         rmask = 0x000000ff;
-         gmask = bmask = amask = 0;
-         dxgi_format = DXGI_FORMAT_R8_UNORM;
-      }
-   }
-   else if(bpp == 2)
-   {
-      if(basetype == GIMP_INDEXED)
-      {
-         fmtbpp = 1;
-         has_alpha = 0;
-         rmask = gmask = bmask = amask = 0;
-      }
+        {
+          fmtbpp = 1;
+          has_alpha = 0;
+          rmask = 0x000000ff;
+          gmask = bmask = amask = 0;
+          dxgi_format = DXGI_FORMAT_R8_UNORM;
+        }
+    }
+  else if (bpp == 2)
+    {
+      if (basetype == GIMP_INDEXED)
+        {
+          fmtbpp = 1;
+          has_alpha = 0;
+          rmask = gmask = bmask = amask = 0;
+        }
       else
-      {
-         fmtbpp = 2;
-         has_alpha = 1;
-         rmask = 0x000000ff;
-         gmask = 0x000000ff;
-         bmask = 0x000000ff;
-         amask = 0x0000ff00;
-      }
-   }
-   else if(bpp == 3)
-   {
+        {
+          fmtbpp = 2;
+          has_alpha = 1;
+          rmask = 0x000000ff;
+          gmask = 0x000000ff;
+          bmask = 0x000000ff;
+          amask = 0x0000ff00;
+        }
+    }
+  else if (bpp == 3)
+    {
       fmtbpp = 3;
       rmask = 0x00ff0000;
       gmask = 0x0000ff00;
       bmask = 0x000000ff;
       amask = 0x00000000;
-   }
-   else
-   {
+    }
+  else
+    {
       fmtbpp = 4;
       has_alpha = 1;
       rmask = 0x00ff0000;
@@ -1286,196 +1340,196 @@ static int write_image(FILE *fp, gint32 image_id, gint32 drawable_id)
       bmask = 0x000000ff;
       amask = 0xff000000;
       dxgi_format = DXGI_FORMAT_B8G8R8A8_UNORM;
-   }
+    }
 
-   memset(hdr, 0, DDS_HEADERSIZE);
+  memset (hdr, 0, DDS_HEADERSIZE);
 
-   PUTL32(hdr,       FOURCC('D','D','S',' '));
-   PUTL32(hdr + 4,   124);
-   PUTL32(hdr + 12,  h);
-   PUTL32(hdr + 16,  w);
-   PUTL32(hdr + 76,  32);
+  PUTL32(hdr,       FOURCC ('D','D','S',' '));
+  PUTL32(hdr + 4,   124);
+  PUTL32(hdr + 12,  h);
+  PUTL32(hdr + 16,  w);
+  PUTL32(hdr + 76,  32);
 
-   if(dds_write_vals.compression == DDS_COMPRESS_NONE)
-   {
+  if (dds_write_vals.compression == DDS_COMPRESS_NONE)
+    {
       PUTL32(hdr + 88,  fmtbpp << 3);
       PUTL32(hdr + 92,  rmask);
       PUTL32(hdr + 96,  gmask);
       PUTL32(hdr + 100, bmask);
       PUTL32(hdr + 104, amask);
-   }
+    }
 
-   /*
-    put some information in the reserved area to identify the origin
-    of the image
-   */
-   PUTL32(hdr + 32, FOURCC('G','I','M','P'));
-   PUTL32(hdr + 36, FOURCC('-','D','D','S'));
-   PUTL32(hdr + 40, DDS_PLUGIN_VERSION);
+  /*
+     put some information in the reserved area to identify the origin
+     of the image
+     */
+  PUTL32(hdr + 32, FOURCC ('G','I','M','P'));
+  PUTL32(hdr + 36, FOURCC ('-','D','D','S'));
+  PUTL32(hdr + 40, DDS_PLUGIN_VERSION);
 
-   flags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
+  flags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
 
-   caps = DDSCAPS_TEXTURE;
-   if(dds_write_vals.mipmaps)
-   {
+  caps = DDSCAPS_TEXTURE;
+  if (dds_write_vals.mipmaps)
+    {
       flags |= DDSD_MIPMAPCOUNT;
       caps |= (DDSCAPS_COMPLEX | DDSCAPS_MIPMAP);
-      num_mipmaps = get_num_mipmaps(w, h);
-   }
-   else
-      num_mipmaps = 1;
+      num_mipmaps = get_num_mipmaps (w, h);
+    }
+  else
+    num_mipmaps = 1;
 
-   if((dds_write_vals.savetype == DDS_SAVE_CUBEMAP) && is_cubemap)
-   {
+  if ((dds_write_vals.savetype == DDS_SAVE_CUBEMAP) && is_cubemap)
+    {
       caps |= DDSCAPS_COMPLEX;
       caps2 |= (DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_ALL_FACES);
-   }
-   else if((dds_write_vals.savetype == DDS_SAVE_VOLUMEMAP) && is_volume)
-   {
+    }
+  else if ((dds_write_vals.savetype == DDS_SAVE_VOLUMEMAP) && is_volume)
+    {
       PUTL32(hdr + 24, num_layers); /* depth */
       flags |= DDSD_DEPTH;
       caps |= DDSCAPS_COMPLEX;
       caps2 |= DDSCAPS2_VOLUME;
-   }
+    }
 
-   PUTL32(hdr + 28,  num_mipmaps);
-   PUTL32(hdr + 108, caps);
-   PUTL32(hdr + 112, caps2);
+  PUTL32(hdr + 28,  num_mipmaps);
+  PUTL32(hdr + 108, caps);
+  PUTL32(hdr + 112, caps2);
 
-   if(dds_write_vals.compression == DDS_COMPRESS_NONE)
-   {
+  if (dds_write_vals.compression == DDS_COMPRESS_NONE)
+    {
       flags |= DDSD_PITCH;
 
-      if(dds_write_vals.format > DDS_FORMAT_DEFAULT)
-      {
-         if(dds_write_vals.format == DDS_FORMAT_A8)
+      if (dds_write_vals.format > DDS_FORMAT_DEFAULT)
+        {
+          if (dds_write_vals.format == DDS_FORMAT_A8)
             pflags |= DDPF_ALPHA;
-         else
-         {
-            if(((fmtbpp == 1) || (dds_write_vals.format == DDS_FORMAT_L8A8)) &&
-               (dds_write_vals.format != DDS_FORMAT_R3G3B2))
-               pflags |= DDPF_LUMINANCE;
-            else
-               pflags |= DDPF_RGB;
-         }
-      }
+          else
+            {
+              if (((fmtbpp == 1) || (dds_write_vals.format == DDS_FORMAT_L8A8)) &&
+                  (dds_write_vals.format != DDS_FORMAT_R3G3B2))
+                pflags |= DDPF_LUMINANCE;
+              else
+                pflags |= DDPF_RGB;
+            }
+        }
       else
-      {
-         if(bpp == 1)
-         {
-            if(basetype == GIMP_INDEXED)
-               pflags |= DDPF_PALETTEINDEXED8;
-            else
-               pflags |= DDPF_LUMINANCE;
-         }
-         else if((bpp == 2) && (basetype == GIMP_INDEXED))
+        {
+          if (bpp == 1)
+            {
+              if (basetype == GIMP_INDEXED)
+                pflags |= DDPF_PALETTEINDEXED8;
+              else
+                pflags |= DDPF_LUMINANCE;
+            }
+          else if ((bpp == 2) && (basetype == GIMP_INDEXED))
             pflags |= DDPF_PALETTEINDEXED8;
-         else
+          else
             pflags |= DDPF_RGB;
-      }
+        }
 
-      if(has_alpha) pflags |= DDPF_ALPHAPIXELS;
+      if (has_alpha) pflags |= DDPF_ALPHAPIXELS;
 
       PUTL32(hdr + 8,  flags);
       PUTL32(hdr + 20, w * fmtbpp); /* pitch */
       PUTL32(hdr + 80, pflags);
 
       /*
-       write extra fourcc info - this is special to GIMP DDS. When the image
-       is read by the plugin, we can detect the added information to decode
-       the pixels
-      */
-      if(dds_write_vals.format == DDS_FORMAT_AEXP)
-      {
-         PUTL32(hdr + 44, FOURCC('A','E','X','P'));
-      }
-      else if(dds_write_vals.format == DDS_FORMAT_YCOCG)
-      {
-         PUTL32(hdr + 44, FOURCC('Y','C','G','1'));
-      }
-   }
-   else
-   {
+         write extra fourcc info - this is special to GIMP DDS. When the image
+         is read by the plugin, we can detect the added information to decode
+         the pixels
+         */
+      if (dds_write_vals.format == DDS_FORMAT_AEXP)
+        {
+          PUTL32(hdr + 44, FOURCC ('A','E','X','P'));
+        }
+      else if (dds_write_vals.format == DDS_FORMAT_YCOCG)
+        {
+          PUTL32(hdr + 44, FOURCC ('Y','C','G','1'));
+        }
+    }
+  else
+    {
       flags |= DDSD_LINEARSIZE;
       pflags = DDPF_FOURCC;
 
-      switch(dds_write_vals.compression)
-      {
-         case DDS_COMPRESS_BC1:
-            fourcc = FOURCC('D','X','T','1');
-            dxgi_format = DXGI_FORMAT_BC1_UNORM;
-            break;
-         case DDS_COMPRESS_BC2:
-            fourcc = FOURCC('D','X','T','3');
-            dxgi_format = DXGI_FORMAT_BC2_UNORM;
-            break;
-         case DDS_COMPRESS_BC3:
-         case DDS_COMPRESS_BC3N:
-         case DDS_COMPRESS_YCOCG:
-         case DDS_COMPRESS_YCOCGS:
-         case DDS_COMPRESS_AEXP:
-            fourcc = FOURCC('D','X','T','5');
-            dxgi_format = DXGI_FORMAT_BC3_UNORM;
-            break;
-         case DDS_COMPRESS_RXGB:
-            fourcc = FOURCC('R','X','G','B');
-            dxgi_format = DXGI_FORMAT_BC3_UNORM;
-            break;
-         case DDS_COMPRESS_BC4:
-            fourcc = FOURCC('A','T','I','1');
-            dxgi_format = DXGI_FORMAT_BC4_UNORM;
-            //is_dx10 = 1;
-            break;
-         case DDS_COMPRESS_BC5:
-            fourcc = FOURCC('A','T','I','2');
-            dxgi_format = DXGI_FORMAT_BC5_UNORM;
-            //is_dx10 = 1;
-            break;
-      }
-
-      if((dds_write_vals.compression == DDS_COMPRESS_BC3N) ||
-         (dds_write_vals.compression == DDS_COMPRESS_RXGB))
-         pflags |= DDPF_NORMAL;
+      switch (dds_write_vals.compression)
+        {
+        case DDS_COMPRESS_BC1:
+          fourcc = FOURCC ('D','X','T','1');
+          dxgi_format = DXGI_FORMAT_BC1_UNORM;
+          break;
+        case DDS_COMPRESS_BC2:
+          fourcc = FOURCC ('D','X','T','3');
+          dxgi_format = DXGI_FORMAT_BC2_UNORM;
+          break;
+        case DDS_COMPRESS_BC3:
+        case DDS_COMPRESS_BC3N:
+        case DDS_COMPRESS_YCOCG:
+        case DDS_COMPRESS_YCOCGS:
+        case DDS_COMPRESS_AEXP:
+          fourcc = FOURCC ('D','X','T','5');
+          dxgi_format = DXGI_FORMAT_BC3_UNORM;
+          break;
+        case DDS_COMPRESS_RXGB:
+          fourcc = FOURCC ('R','X','G','B');
+          dxgi_format = DXGI_FORMAT_BC3_UNORM;
+          break;
+        case DDS_COMPRESS_BC4:
+          fourcc = FOURCC ('A','T','I','1');
+          dxgi_format = DXGI_FORMAT_BC4_UNORM;
+          //is_dx10 = 1;
+          break;
+        case DDS_COMPRESS_BC5:
+          fourcc = FOURCC ('A','T','I','2');
+          dxgi_format = DXGI_FORMAT_BC5_UNORM;
+          //is_dx10 = 1;
+          break;
+        }
+
+      if ((dds_write_vals.compression == DDS_COMPRESS_BC3N) ||
+          (dds_write_vals.compression == DDS_COMPRESS_RXGB))
+        pflags |= DDPF_NORMAL;
 
       PUTL32(hdr + 8,  flags);
       PUTL32(hdr + 80, pflags);
       PUTL32(hdr + 84, fourcc);
 
       size = ((w + 3) >> 2) * ((h + 3) >> 2);
-      if((dds_write_vals.compression == DDS_COMPRESS_BC1) ||
-         (dds_write_vals.compression == DDS_COMPRESS_BC4))
-         size *= 8;
+      if ((dds_write_vals.compression == DDS_COMPRESS_BC1) ||
+          (dds_write_vals.compression == DDS_COMPRESS_BC4))
+        size *= 8;
       else
-         size *= 16;
+        size *= 16;
 
       PUTL32(hdr + 20, size); /* linear size */
 
       /*
-       write extra fourcc info - this is special to GIMP DDS. When the image
-       is read by the plugin, we can detect the added information to decode
-       the pixels
-      */
-      if(dds_write_vals.compression == DDS_COMPRESS_AEXP)
-      {
-         PUTL32(hdr + 44, FOURCC('A','E','X','P'));
-      }
-      else if(dds_write_vals.compression == DDS_COMPRESS_YCOCG)
-      {
-         PUTL32(hdr + 44, FOURCC('Y','C','G','1'));
-      }
-      else if(dds_write_vals.compression == DDS_COMPRESS_YCOCGS)
-      {
-         PUTL32(hdr + 44, FOURCC('Y','C','G','2'));
-      }
-   }
-
-   /* texture arrays require a DX10 header */
-   if(dds_write_vals.savetype == DDS_SAVE_ARRAY)
-      is_dx10 = 1;
-
-   if(is_dx10)
-   {
-      array_size = (dds_write_vals.savetype == DDS_SAVE_SELECTED_LAYER) ? 1 : get_array_size(image_id);
+         write extra fourcc info - this is special to GIMP DDS. When the image
+         is read by the plugin, we can detect the added information to decode
+         the pixels
+         */
+      if (dds_write_vals.compression == DDS_COMPRESS_AEXP)
+        {
+          PUTL32(hdr + 44, FOURCC ('A','E','X','P'));
+        }
+      else if (dds_write_vals.compression == DDS_COMPRESS_YCOCG)
+        {
+          PUTL32(hdr + 44, FOURCC ('Y','C','G','1'));
+        }
+      else if (dds_write_vals.compression == DDS_COMPRESS_YCOCGS)
+        {
+          PUTL32(hdr + 44, FOURCC ('Y','C','G','2'));
+        }
+    }
+
+  /* texture arrays require a DX10 header */
+  if (dds_write_vals.savetype == DDS_SAVE_ARRAY)
+    is_dx10 = 1;
+
+  if (is_dx10)
+    {
+      array_size = (dds_write_vals.savetype == DDS_SAVE_SELECTED_LAYER) ? 1 : get_array_size (image_id);
 
       PUTL32(hdr10 +  0, dxgi_format);
       PUTL32(hdr10 +  4, D3D10_RESOURCE_DIMENSION_TEXTURE2D);
@@ -1485,643 +1539,677 @@ static int write_image(FILE *fp, gint32 image_id, gint32 drawable_id)
 
       /* update main header accordingly */
       PUTL32(hdr + 80, pflags | DDPF_FOURCC);
-      PUTL32(hdr + 84, FOURCC('D','X','1','0'));
-   }
+      PUTL32(hdr + 84, FOURCC ('D','X','1','0'));
+    }
 
-   fwrite(hdr, DDS_HEADERSIZE, 1, fp);
+  fwrite (hdr, DDS_HEADERSIZE, 1, fp);
 
-   if(is_dx10)
-      fwrite(hdr10, DDS_HEADERSIZE_DX10, 1, fp);
+  if (is_dx10)
+    fwrite (hdr10, DDS_HEADERSIZE_DX10, 1, fp);
 
-   /* write palette for indexed images */
-   if((basetype == GIMP_INDEXED) &&
+  /* write palette for indexed images */
+  if ((basetype == GIMP_INDEXED) &&
       (dds_write_vals.format == DDS_FORMAT_DEFAULT) &&
       (dds_write_vals.compression == DDS_COMPRESS_NONE))
-   {
-      cmap = gimp_image_get_colormap(image_id, &colors);
-      for(i = 0; i < colors; ++i)
-      {
-         fwrite(&cmap[3 * i], 1, 3, fp);
-         if(i == dds_write_vals.transindex)
-            fputc(0, fp);
-         else
-            fputc(255, fp);
-      }
-      for(; i < 256; ++i)
-         fwrite(zero, 1, 4, fp);
-   }
-
-   if(dds_write_vals.savetype == DDS_SAVE_CUBEMAP)
-   {
-      for(i = 0; i < 6; ++i)
-      {
-         write_layer(fp, image_id, cubemap_faces[i], w, h, bpp, fmtbpp,
-                     num_mipmaps);
-         gimp_progress_update((float)(i + 1) / 6.0);
-      }
-   }
-   else if(dds_write_vals.savetype == DDS_SAVE_VOLUMEMAP)
-   {
-      for(i = 0; i < num_layers; ++i)
-      {
-         write_layer(fp, image_id, layers[i], w, h, bpp, fmtbpp, 1);
-         gimp_progress_update((float)i / (float)num_layers);
-      }
-
-      if(num_mipmaps > 1)
-         write_volume_mipmaps(fp, image_id, layers, w, h, num_layers,
+    {
+      cmap = gimp_image_get_colormap (image_id, &colors);
+      for (i = 0; i < colors; ++i)
+        {
+          fwrite (&cmap[3 * i], 1, 3, fp);
+          if (i == dds_write_vals.transindex)
+            fputc (0, fp);
+          else
+            fputc (255, fp);
+        }
+      for (; i < 256; ++i)
+        fwrite (zero, 1, 4, fp);
+    }
+
+  if (dds_write_vals.savetype == DDS_SAVE_CUBEMAP)
+    {
+      for (i = 0; i < 6; ++i)
+        {
+          write_layer (fp, image_id, cubemap_faces[i], w, h, bpp, fmtbpp,
+                       num_mipmaps);
+          gimp_progress_update ((float)(i + 1) / 6.0);
+        }
+    }
+  else if (dds_write_vals.savetype == DDS_SAVE_VOLUMEMAP)
+    {
+      for (i = 0; i < num_layers; ++i)
+        {
+          write_layer (fp, image_id, layers[i], w, h, bpp, fmtbpp, 1);
+          gimp_progress_update ((float)i / (float)num_layers);
+        }
+
+      if (num_mipmaps > 1)
+        write_volume_mipmaps (fp, image_id, layers, w, h, num_layers,
                               bpp, fmtbpp, num_mipmaps);
-   }
-   else if(dds_write_vals.savetype == DDS_SAVE_ARRAY)
-   {
-      for(i = 0; i < num_layers; ++i)
-      {
-         if((gimp_drawable_width(layers[i]) == w) && (gimp_drawable_height(layers[i]) == h))
-            write_layer(fp, image_id, layers[i], w, h, bpp, fmtbpp, num_mipmaps);
-
-         gimp_progress_update((float)i / (float)num_layers);
-      }
-   }
-   else
-   {
-      write_layer(fp, image_id, drawable_id, w, h, bpp, fmtbpp, num_mipmaps);
-   }
-
-   gimp_progress_update(1.0);
-
-   return(1);
+    }
+  else if (dds_write_vals.savetype == DDS_SAVE_ARRAY)
+    {
+      for (i = 0; i < num_layers; ++i)
+        {
+          if ((gimp_drawable_width (layers[i]) == w) && (gimp_drawable_height (layers[i]) == h))
+            write_layer (fp, image_id, layers[i], w, h, bpp, fmtbpp, num_mipmaps);
+
+          gimp_progress_update ((float)i / (float)num_layers);
+        }
+    }
+  else
+    {
+      write_layer (fp, image_id, drawable_id, w, h, bpp, fmtbpp, num_mipmaps);
+    }
+
+  gimp_progress_update (1.0);
+
+  return (1);
 }
 
-static GtkWidget *string_value_combo_new(string_value_t *strings,
-                                         int active_value)
+static GtkWidget *
+string_value_combo_new (string_value_t *strings,
+                        int             active_value)
 {
-   GtkWidget *opt;
-   GtkCellRenderer *renderer;
-   GtkListStore *store;
-   GtkTreeIter iter;
-   int i, active = 0;
-
-   store = gtk_list_store_new(3, G_TYPE_INT, G_TYPE_STRING, G_TYPE_BOOLEAN);
-   for(i = 0; strings[i].string; ++i)
-   {
-      if(strings[i].value == active_value) active = i;
-      gtk_list_store_append(store, &iter);
-      gtk_list_store_set(store, &iter,
-                         0, strings[i].value,
-                         1, strings[i].string,
-                         2, 1,
-                         -1);
-   }
-
-   renderer = gtk_cell_renderer_text_new();
-
-   opt = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
-   gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(opt), renderer, 1);
-   gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(opt), renderer,
+  GtkWidget *opt;
+  GtkCellRenderer *renderer;
+  GtkListStore *store;
+  GtkTreeIter iter;
+  int i, active = 0;
+
+  store = gtk_list_store_new (3, G_TYPE_INT, G_TYPE_STRING, G_TYPE_BOOLEAN);
+  for (i = 0; strings[i].string; ++i)
+    {
+      if (strings[i].value == active_value) active = i;
+      gtk_list_store_append (store, &iter);
+      gtk_list_store_set (store, &iter,
+                          0, strings[i].value,
+                          1, strings[i].string,
+                          2, 1,
+                          -1);
+    }
+
+  renderer = gtk_cell_renderer_text_new ();
+
+  opt = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
+  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (opt), renderer, 1);
+  gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (opt), renderer,
                                   "text", COMBO_STRING,
                                   "sensitive", COMBO_SENSITIVE,
                                   NULL);
 
-   gtk_combo_box_set_active(GTK_COMBO_BOX(opt), active);
+  gtk_combo_box_set_active (GTK_COMBO_BOX (opt), active);
 
-   g_object_unref(store);
+  g_object_unref (store);
 
-   return(opt);
+  return (opt);
 }
 
-static void string_value_combo_selected(GtkWidget *widget, gpointer data)
+static void
+string_value_combo_selected (GtkWidget *widget,
+                             gpointer   data)
 {
-   int value;
-   GtkTreeIter iter;
-   GtkTreeModel *model;
+  int value;
+  GtkTreeIter iter;
+  GtkTreeModel *model;
 
-   model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
-   gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &iter);
-   gtk_tree_model_get(model, &iter, COMBO_VALUE, &value, -1);
+  model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
+  gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter);
+  gtk_tree_model_get (model, &iter, COMBO_VALUE, &value, -1);
 
-   *((int *)data) = value;
+  *((int *)data) = value;
 }
 
-static void string_value_combo_set_item_sensitive(GtkWidget *widget,
-                                                  int value, int sensitive)
+static void
+string_value_combo_set_item_sensitive (GtkWidget *widget,
+                                       int        value,
+                                       int        sensitive)
 {
-   GtkTreeIter iter;
-   GtkTreeModel *model;
-   int val;
-
-   model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
-   gtk_tree_model_get_iter_first(model, &iter);
-   do
-   {
-      gtk_tree_model_get(model, &iter, COMBO_VALUE, &val, -1);
-      if(val == value)
-      {
-         gtk_list_store_set(GTK_LIST_STORE(model), &iter,
-                            COMBO_SENSITIVE, sensitive, -1);
-         break;
-      }
-   } while(gtk_tree_model_iter_next(model, &iter));
+  GtkTreeIter iter;
+  GtkTreeModel *model;
+  int val;
+
+  model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
+  gtk_tree_model_get_iter_first (model, &iter);
+  do
+    {
+      gtk_tree_model_get (model, &iter, COMBO_VALUE, &val, -1);
+      if (val == value)
+        {
+          gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+                              COMBO_SENSITIVE, sensitive, -1);
+          break;
+        }
+    } while (gtk_tree_model_iter_next (model, &iter));
 }
 
-static void string_value_combo_set_active(GtkWidget *widget,
-                                          int value)
+static void
+string_value_combo_set_active (GtkWidget *widget,
+                               int        value)
 {
-   GtkTreeIter iter;
-   GtkTreeModel *model;
-   int val;
-
-   model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
-   gtk_tree_model_get_iter_first(model, &iter);
-   do
-   {
-      gtk_tree_model_get(model, &iter, COMBO_VALUE, &val, -1);
-      if(val == value)
-      {
-         gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widget), &iter);
-         break;
-      }
-   } while(gtk_tree_model_iter_next(model, &iter));
+  GtkTreeIter iter;
+  GtkTreeModel *model;
+  int val;
+
+  model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
+  gtk_tree_model_get_iter_first (model, &iter);
+  do
+    {
+      gtk_tree_model_get (model, &iter, COMBO_VALUE, &val, -1);
+      if (val == value)
+        {
+          gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget), &iter);
+          break;
+        }
+    } while (gtk_tree_model_iter_next (model, &iter));
 }
 
-static void save_dialog_response(GtkWidget *widget, gint response_id,
-                                 gpointer data)
+static void
+save_dialog_response (GtkWidget *widget,
+                      gint       response_id,
+                      gpointer   data)
 {
-   switch(response_id)
-   {
-      case GTK_RESPONSE_OK:
-         runme = 1;
-      default:
-         gtk_widget_destroy(widget);
-         break;
-   }
+  switch (response_id)
+    {
+    case GTK_RESPONSE_OK:
+      runme = 1;
+    default:
+      gtk_widget_destroy (widget);
+      break;
+    }
 }
 
-static void compression_selected(GtkWidget *widget, gpointer data)
+static void
+compression_selected (GtkWidget *widget,
+                      gpointer   data)
 {
-   GtkTreeIter iter;
-   GtkTreeModel *model;
-   model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
-   gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &iter);
-   gtk_tree_model_get(model, &iter, COMBO_VALUE,
+  GtkTreeIter iter;
+  GtkTreeModel *model;
+  model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
+  gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter);
+  gtk_tree_model_get (model, &iter, COMBO_VALUE,
                       &dds_write_vals.compression, -1);
 
-   gtk_widget_set_sensitive(format_opt, dds_write_vals.compression == DDS_COMPRESS_NONE);
-   gtk_widget_set_sensitive(pm_chk, dds_write_vals.compression != DDS_COMPRESS_NONE);
+  gtk_widget_set_sensitive (format_opt, dds_write_vals.compression == DDS_COMPRESS_NONE);
+  gtk_widget_set_sensitive (pm_chk, dds_write_vals.compression != DDS_COMPRESS_NONE);
 }
 
-static void savetype_selected(GtkWidget *widget, gpointer data)
+static void
+savetype_selected (GtkWidget *widget,
+                   gpointer   data)
 {
-   gint32 image_id = *((gint32 *)data);
-
-   dds_write_vals.savetype = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
-
-   switch(dds_write_vals.savetype)
-   {
-      case DDS_SAVE_SELECTED_LAYER:
-      case DDS_SAVE_CUBEMAP:
-      case DDS_SAVE_ARRAY:
-         gtk_widget_set_sensitive(compress_opt, 1);
-         break;
-      case DDS_SAVE_VOLUMEMAP:
-         dds_write_vals.compression = DDS_COMPRESS_NONE;
-         gtk_combo_box_set_active(GTK_COMBO_BOX(compress_opt),
-                                  DDS_COMPRESS_NONE);
-         gtk_widget_set_sensitive(compress_opt, 0);
-         break;
-   }
-
-   string_value_combo_set_item_sensitive(mipmap_opt, DDS_MIPMAP_EXISTING,
-                                         check_mipmaps(image_id, dds_write_vals.savetype));   
+  gint32 image_id = *((gint32 *)data);
+
+  dds_write_vals.savetype = gtk_combo_box_get_active (GTK_COMBO_BOX (widget));
+
+  switch (dds_write_vals.savetype)
+    {
+    case DDS_SAVE_SELECTED_LAYER:
+    case DDS_SAVE_CUBEMAP:
+    case DDS_SAVE_ARRAY:
+      gtk_widget_set_sensitive (compress_opt, 1);
+      break;
+    case DDS_SAVE_VOLUMEMAP:
+      dds_write_vals.compression = DDS_COMPRESS_NONE;
+      gtk_combo_box_set_active (GTK_COMBO_BOX (compress_opt),
+                                DDS_COMPRESS_NONE);
+      gtk_widget_set_sensitive (compress_opt, 0);
+      break;
+    }
+
+  string_value_combo_set_item_sensitive (mipmap_opt, DDS_MIPMAP_EXISTING,
+                                         check_mipmaps (image_id, dds_write_vals.savetype));
 }
 
-static void mipmaps_selected(GtkWidget *widget, gpointer data)
+static void
+mipmaps_selected (GtkWidget *widget,
+                  gpointer   data)
 {
-   GtkTreeIter iter;
-   GtkTreeModel *model;
-   model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
-   gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &iter);
-   gtk_tree_model_get(model, &iter, COMBO_VALUE,
+  GtkTreeIter iter;
+  GtkTreeModel *model;
+  model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
+  gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter);
+  gtk_tree_model_get (model, &iter, COMBO_VALUE,
                       &dds_write_vals.mipmaps, -1);
 
-   gtk_widget_set_sensitive(mipmap_filter_opt, dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE);
-   gtk_widget_set_sensitive(mipmap_wrap_opt, dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE);
-   gtk_widget_set_sensitive(gamma_chk, dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE);
-   gtk_widget_set_sensitive(srgb_chk, (dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE) && 
dds_write_vals.gamma_correct);
-   gtk_widget_set_sensitive(gamma_spin, (dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE) &&
+  gtk_widget_set_sensitive (mipmap_filter_opt, dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE);
+  gtk_widget_set_sensitive (mipmap_wrap_opt, dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE);
+  gtk_widget_set_sensitive (gamma_chk, dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE);
+  gtk_widget_set_sensitive (srgb_chk, (dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE) && 
dds_write_vals.gamma_correct);
+  gtk_widget_set_sensitive (gamma_spin, (dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE) &&
                             dds_write_vals.gamma_correct && !dds_write_vals.srgb);
-   gtk_widget_set_sensitive(alpha_coverage_chk, dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE);
-   gtk_widget_set_sensitive(alpha_test_threshold_spin, (dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE) &&
+  gtk_widget_set_sensitive (alpha_coverage_chk, dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE);
+  gtk_widget_set_sensitive (alpha_test_threshold_spin, (dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE) &&
                             dds_write_vals.preserve_alpha_coverage);
 }
 
-static void toggle_clicked(GtkWidget *widget, gpointer data)
+static void
+toggle_clicked (GtkWidget *widget,
+                gpointer   data)
 {
-   int *flag = (int *)data;
-   (*flag) = !(*flag);
+  int *flag = (int *)data;
+  (*flag) = !(*flag);
 }
 
-static void transindex_clicked(GtkWidget *widget, gpointer data)
+static void
+transindex_clicked (GtkWidget *widget,
+                    gpointer   data)
 {
-   GtkWidget *spin = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), "spin"));
+  GtkWidget *spin = GTK_WIDGET (g_object_get_data (G_OBJECT (widget), "spin"));
 
-   if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
-   {
+  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
+    {
       dds_write_vals.transindex = 0;
-      gtk_widget_set_sensitive(spin, 1);
-      gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), 0);
-   }
-   else
-   {
-      gtk_widget_set_sensitive(spin, 0);
+      gtk_widget_set_sensitive (spin, 1);
+      gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), 0);
+    }
+  else
+    {
+      gtk_widget_set_sensitive (spin, 0);
       dds_write_vals.transindex = -1;
-   }
+    }
 }
 
-static void transindex_changed(GtkWidget *widget, gpointer data)
+static void
+transindex_changed (GtkWidget *widget,
+                    gpointer   data)
 {
-   dds_write_vals.transindex = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
+  dds_write_vals.transindex = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
 }
 
-static void adv_opt_expanded(GtkWidget *widget, gpointer data)
+static void
+adv_opt_expanded (GtkWidget *widget,
+                  gpointer   data)
 {
-   dds_write_vals.show_adv_opt = !gtk_expander_get_expanded(GTK_EXPANDER(widget));
+  dds_write_vals.show_adv_opt = !gtk_expander_get_expanded (GTK_EXPANDER (widget));
 }
 
-static void gamma_correct_clicked(GtkWidget *widget, gpointer data)
+static void
+gamma_correct_clicked (GtkWidget *widget,
+                       gpointer   data)
 {
-   dds_write_vals.gamma_correct = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
-   gtk_widget_set_sensitive(srgb_chk, dds_write_vals.gamma_correct);
-   gtk_widget_set_sensitive(gamma_spin, dds_write_vals.gamma_correct && !dds_write_vals.srgb);
+  dds_write_vals.gamma_correct = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
+  gtk_widget_set_sensitive (srgb_chk, dds_write_vals.gamma_correct);
+  gtk_widget_set_sensitive (gamma_spin, dds_write_vals.gamma_correct && !dds_write_vals.srgb);
 }
 
-static void srgb_clicked(GtkWidget *widget, gpointer data)
+static void
+srgb_clicked (GtkWidget *widget,
+              gpointer   data)
 {
-   dds_write_vals.srgb = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
-   gtk_widget_set_sensitive(gamma_spin, !dds_write_vals.srgb);
+  dds_write_vals.srgb = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
+  gtk_widget_set_sensitive (gamma_spin, !dds_write_vals.srgb);
 }
 
-static void gamma_changed(GtkWidget *widget, gpointer data)
+static void
+gamma_changed (GtkWidget *widget,
+               gpointer   data)
 {
-   dds_write_vals.gamma = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widget));
+  dds_write_vals.gamma = gtk_spin_button_get_value (GTK_SPIN_BUTTON (widget));
 }
 
-static void alpha_coverage_clicked(GtkWidget *widget, gpointer data)
+static void
+alpha_coverage_clicked (GtkWidget *widget,
+                        gpointer   data)
 {
-   dds_write_vals.preserve_alpha_coverage = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
-   gtk_widget_set_sensitive(alpha_test_threshold_spin, dds_write_vals.preserve_alpha_coverage);
+  dds_write_vals.preserve_alpha_coverage = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
+  gtk_widget_set_sensitive (alpha_test_threshold_spin, dds_write_vals.preserve_alpha_coverage);
 }
 
-static void alpha_test_threshold_changed(GtkWidget *widget, gpointer data)
+static void
+alpha_test_threshold_changed (GtkWidget *widget,
+                              gpointer   data)
 {
-   dds_write_vals.alpha_test_threshold = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widget));
+  dds_write_vals.alpha_test_threshold = gtk_spin_button_get_value (GTK_SPIN_BUTTON (widget));
 }
 
-static gint save_dialog(gint32 image_id, gint32 drawable_id)
+static gint
+save_dialog (gint32 image_id,
+             gint32 drawable_id)
 {
-   GtkWidget *dlg;
-   GtkWidget *vbox, *vbox2, *hbox;
-   GtkWidget *table;
-   GtkWidget *label;
-   GtkWidget *opt;
-   GtkWidget *check;
-   GtkWidget *spin;
-   GtkWidget *expander;
-   GtkWidget *frame;
-   GimpImageBaseType basetype;
-
-   if(is_cubemap || is_volume || is_array)
-      dds_write_vals.savetype = DDS_SAVE_SELECTED_LAYER;
-
-   basetype = gimp_image_base_type(image_id);
-
-   dlg = gimp_dialog_new (_("Export as DDS"), "dds", NULL, GTK_WIN_POS_MOUSE,
-                          gimp_standard_help_func, SAVE_PROC,
+  GtkWidget *dlg;
+  GtkWidget *vbox, *vbox2, *hbox;
+  GtkWidget *table;
+  GtkWidget *label;
+  GtkWidget *opt;
+  GtkWidget *check;
+  GtkWidget *spin;
+  GtkWidget *expander;
+  GtkWidget *frame;
+  GimpImageBaseType basetype;
+
+  if (is_cubemap || is_volume || is_array)
+    dds_write_vals.savetype = DDS_SAVE_SELECTED_LAYER;
+
+  basetype = gimp_image_base_type (image_id);
+
+  dlg = gimp_dialog_new (_("Export as DDS"), "dds", NULL, GTK_WIN_POS_MOUSE,
+                         gimp_standard_help_func, SAVE_PROC,
                          _("Cancel"), GTK_RESPONSE_CANCEL,
                          _("OK"),     GTK_RESPONSE_OK,
-                          NULL);
+                         NULL);
 
-   g_signal_connect(dlg, "response",
-                      G_CALLBACK(save_dialog_response),
-                      0);
-   g_signal_connect(dlg, "destroy",
-                      G_CALLBACK(gtk_main_quit),
-                      0);
+  g_signal_connect (dlg, "response",
+                    G_CALLBACK (save_dialog_response),
+                    0);
+  g_signal_connect (dlg, "destroy",
+                    G_CALLBACK (gtk_main_quit),
+                    0);
 
-   gtk_window_set_resizable(GTK_WINDOW(dlg), 0);
+  gtk_window_set_resizable (GTK_WINDOW (dlg), 0);
 
-   vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4);
-   gtk_container_set_border_width(GTK_CONTAINER(vbox), 8);
-   gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area (GTK_DIALOG(dlg))),
+  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4);
+  gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
+  gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
                       vbox, 1, 1, 0);
-   gtk_widget_show(vbox);
+  gtk_widget_show (vbox);
 
-   table = gtk_table_new(4, 2, 0);
-   gtk_widget_show(table);
-   gtk_box_pack_start(GTK_BOX(vbox), table, 1, 1, 0);
-   gtk_table_set_row_spacings(GTK_TABLE(table), 4);
-   gtk_table_set_col_spacings(GTK_TABLE(table), 8);
+  table = gtk_table_new (4, 2, 0);
+  gtk_widget_show (table);
+  gtk_box_pack_start (GTK_BOX (vbox), table, 1, 1, 0);
+  gtk_table_set_row_spacings (GTK_TABLE (table), 4);
+  gtk_table_set_col_spacings (GTK_TABLE (table), 8);
 
-   label = gtk_label_new(_("Compression:"));
-   gtk_widget_show(label);
-   gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1,
+  label = gtk_label_new (_("Compression:"));
+  gtk_widget_show (label);
+  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
                     (GtkAttachOptions)(GTK_FILL),
                     (GtkAttachOptions)(0), 0, 0);
-   gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
+  gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
 
-   opt = string_value_combo_new(compression_strings,
+  opt = string_value_combo_new (compression_strings,
                                 dds_write_vals.compression);
-   gtk_widget_show(opt);
-   gtk_table_attach(GTK_TABLE(table), opt, 1, 2, 0, 1,
+  gtk_widget_show (opt);
+  gtk_table_attach (GTK_TABLE (table), opt, 1, 2, 0, 1,
                     (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
                     (GtkAttachOptions)(GTK_EXPAND), 0, 0);
 
-   g_signal_connect(opt, "changed",
-                      G_CALLBACK(compression_selected), 0);
+  g_signal_connect (opt, "changed",
+                    G_CALLBACK (compression_selected), 0);
 
-   compress_opt = opt;
+  compress_opt = opt;
 
-   label = gtk_label_new(_("Format:"));
-   gtk_widget_show(label);
-   gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
+  label = gtk_label_new (_("Format:"));
+  gtk_widget_show (label);
+  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
                     (GtkAttachOptions)(GTK_FILL),
                     (GtkAttachOptions)(0), 0, 0);
-   gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
+  gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
 
-   opt = string_value_combo_new(format_strings, dds_write_vals.format);
-   gtk_widget_show(opt);
-   gtk_table_attach(GTK_TABLE(table), opt, 1, 2, 1, 2,
+  opt = string_value_combo_new (format_strings, dds_write_vals.format);
+  gtk_widget_show (opt);
+  gtk_table_attach (GTK_TABLE (table), opt, 1, 2, 1, 2,
                     (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
                     (GtkAttachOptions)(GTK_EXPAND), 0, 0);
 
-   g_signal_connect(opt, "changed",
-                      G_CALLBACK(string_value_combo_selected),
-                      &dds_write_vals.format);
+  g_signal_connect (opt, "changed",
+                    G_CALLBACK (string_value_combo_selected),
+                    &dds_write_vals.format);
 
-   gtk_widget_set_sensitive(opt, dds_write_vals.compression == DDS_COMPRESS_NONE);
+  gtk_widget_set_sensitive (opt, dds_write_vals.compression == DDS_COMPRESS_NONE);
 
-   format_opt = opt;
+  format_opt = opt;
 
-   label = gtk_label_new(_("Save:"));
-   gtk_widget_show(label);
-   gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3,
+  label = gtk_label_new (_("Save:"));
+  gtk_widget_show (label);
+  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3,
                     (GtkAttachOptions)(GTK_FILL),
                     (GtkAttachOptions)(0), 0, 0);
-   gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
+  gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
 
-   opt = string_value_combo_new(save_type_strings, dds_write_vals.savetype);
-   gtk_widget_show(opt);
-   gtk_table_attach(GTK_TABLE(table), opt, 1, 2, 2, 3,
+  opt = string_value_combo_new (save_type_strings, dds_write_vals.savetype);
+  gtk_widget_show (opt);
+  gtk_table_attach (GTK_TABLE (table), opt, 1, 2, 2, 3,
                     (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
                     (GtkAttachOptions)(GTK_EXPAND), 0, 0);
 
-   g_signal_connect(opt, "changed",
-                      G_CALLBACK(savetype_selected), &image_id);
+  g_signal_connect (opt, "changed",
+                    G_CALLBACK (savetype_selected), &image_id);
 
-   string_value_combo_set_item_sensitive(opt, DDS_SAVE_CUBEMAP, is_cubemap);
-   string_value_combo_set_item_sensitive(opt, DDS_SAVE_VOLUMEMAP, is_volume);
-   string_value_combo_set_item_sensitive(opt, DDS_SAVE_ARRAY, is_array);
+  string_value_combo_set_item_sensitive (opt, DDS_SAVE_CUBEMAP, is_cubemap);
+  string_value_combo_set_item_sensitive (opt, DDS_SAVE_VOLUMEMAP, is_volume);
+  string_value_combo_set_item_sensitive (opt, DDS_SAVE_ARRAY, is_array);
 
-   label = gtk_label_new(_("Mipmaps:"));
-   gtk_widget_show(label);
-   gtk_table_attach(GTK_TABLE(table), label, 0, 1, 3, 4,
+  label = gtk_label_new (_("Mipmaps:"));
+  gtk_widget_show (label);
+  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 3, 4,
                     (GtkAttachOptions)(GTK_FILL),
                     (GtkAttachOptions)(0), 0, 0);
-   gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
+  gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
 
-   opt = string_value_combo_new(mipmap_strings,
+  opt = string_value_combo_new (mipmap_strings,
                                 dds_write_vals.mipmaps);
-   gtk_widget_show(opt);
-   gtk_table_attach(GTK_TABLE(table), opt, 1, 2, 3, 4,
+  gtk_widget_show (opt);
+  gtk_table_attach (GTK_TABLE (table), opt, 1, 2, 3, 4,
                     (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
                     (GtkAttachOptions)(GTK_EXPAND), 0, 0);
 
-   g_signal_connect(opt, "changed",
-                      G_CALLBACK(mipmaps_selected), &image_id);
+  g_signal_connect (opt, "changed",
+                    G_CALLBACK (mipmaps_selected), &image_id);
 
-   string_value_combo_set_item_sensitive(opt, DDS_MIPMAP_EXISTING,
-                                         check_mipmaps(image_id, dds_write_vals.savetype));
+  string_value_combo_set_item_sensitive (opt, DDS_MIPMAP_EXISTING,
+                                         check_mipmaps (image_id, dds_write_vals.savetype));
 
-   mipmap_opt = opt;
+  mipmap_opt = opt;
 
-   string_value_combo_set_item_sensitive(opt, DDS_MIPMAP_EXISTING,
+  string_value_combo_set_item_sensitive (opt, DDS_MIPMAP_EXISTING,
                                          !(is_volume || is_cubemap) &&
                                          is_mipmap_chain_valid);
 
 
-   hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8);
-   gtk_box_pack_start(GTK_BOX(vbox), hbox, 1, 1, 0);
-   gtk_widget_show(hbox);
+  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8);
+  gtk_box_pack_start (GTK_BOX (vbox), hbox, 1, 1, 0);
+  gtk_widget_show (hbox);
 
-   check = gtk_check_button_new_with_label(_("Transparent index:"));
-   gtk_box_pack_start(GTK_BOX(hbox), check, 0, 0, 0);
-   g_signal_connect(check, "clicked",
-                      G_CALLBACK(transindex_clicked), 0);
-   gtk_widget_show(check);
+  check = gtk_check_button_new_with_label (_("Transparent index:"));
+  gtk_box_pack_start (GTK_BOX (hbox), check, 0, 0, 0);
+  g_signal_connect (check, "clicked",
+                    G_CALLBACK (transindex_clicked), 0);
+  gtk_widget_show (check);
 
-   spin = gtk_spin_button_new(GTK_ADJUSTMENT(gtk_adjustment_new(0, 0, 255, 1, 1, 0)), 1, 0);
-   gtk_box_pack_start(GTK_BOX(hbox), spin, 1, 1, 0);
-   gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(spin),
+  spin = gtk_spin_button_new (GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, 255, 1, 1, 0)), 1, 0);
+  gtk_box_pack_start (GTK_BOX (hbox), spin, 1, 1, 0);
+  gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (spin),
                                      GTK_UPDATE_IF_VALID);
-   g_signal_connect(spin, "value_changed",
-                      G_CALLBACK(transindex_changed), 0);
-   gtk_widget_show(spin);
-
-   g_object_set_data(G_OBJECT(check), "spin", spin);
-
-   if(basetype != GIMP_INDEXED)
-   {
-      gtk_widget_set_sensitive(check, 0);
-      gtk_widget_set_sensitive(spin, 0);
-   }
-   else if(dds_write_vals.transindex < 0)
-   {
-      gtk_widget_set_sensitive(spin, 0);
-   }
-   else if(dds_write_vals.transindex >= 0)
-   {
-      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), 1);
-      gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), dds_write_vals.transindex);
-   }
-
-   if(is_volume && dds_write_vals.savetype == DDS_SAVE_VOLUMEMAP)
-   {
+  g_signal_connect (spin, "value_changed",
+                    G_CALLBACK (transindex_changed), 0);
+  gtk_widget_show (spin);
+
+  g_object_set_data (G_OBJECT (check), "spin", spin);
+
+  if (basetype != GIMP_INDEXED)
+    {
+      gtk_widget_set_sensitive (check, 0);
+      gtk_widget_set_sensitive (spin, 0);
+    }
+  else if (dds_write_vals.transindex < 0)
+    {
+      gtk_widget_set_sensitive (spin, 0);
+    }
+  else if (dds_write_vals.transindex >= 0)
+    {
+      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), 1);
+      gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), dds_write_vals.transindex);
+    }
+
+  if (is_volume && dds_write_vals.savetype == DDS_SAVE_VOLUMEMAP)
+    {
       dds_write_vals.compression = DDS_COMPRESS_NONE;
-      string_value_combo_set_active(compress_opt, DDS_COMPRESS_NONE);
-      gtk_widget_set_sensitive(compress_opt, 0);
-   }
-
-   expander = gtk_expander_new(_("<b>Advanced Options</b>"));
-   gtk_expander_set_use_markup(GTK_EXPANDER(expander), 1);
-   gtk_expander_set_expanded(GTK_EXPANDER(expander), dds_write_vals.show_adv_opt);
-   gtk_expander_set_spacing(GTK_EXPANDER(expander), 8);
-   g_signal_connect(expander, "activate",
-                      G_CALLBACK(adv_opt_expanded), 0);
-   gtk_box_pack_start(GTK_BOX(vbox), expander, 1, 1, 0);
-   gtk_widget_show(expander);
-
-
-   vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4);
-   gtk_container_add(GTK_CONTAINER(expander), vbox2);
-   gtk_widget_show(vbox2);
-
-   frame = gtk_frame_new(_("Compression"));
-   gtk_box_pack_start(GTK_BOX(vbox2), frame, 1, 1, 0);
-   gtk_widget_show(frame);
-
-   table = gtk_table_new(1, 2, 0);
-   gtk_table_set_row_spacings(GTK_TABLE(table), 4);
-   gtk_table_set_col_spacings(GTK_TABLE(table), 8);
-   gtk_container_set_border_width(GTK_CONTAINER(table), 8);
-   gtk_container_add(GTK_CONTAINER(frame), table);
-   gtk_widget_show(table);
-
-   check = gtk_check_button_new_with_label(_("Use perceptual error metric"));
-   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), dds_write_vals.perceptual_metric);
-   gtk_table_attach(GTK_TABLE(table), check, 0, 2, 0, 1,
+      string_value_combo_set_active (compress_opt, DDS_COMPRESS_NONE);
+      gtk_widget_set_sensitive (compress_opt, 0);
+    }
+
+  expander = gtk_expander_new (_("<b>Advanced Options</b>"));
+  gtk_expander_set_use_markup (GTK_EXPANDER (expander), 1);
+  gtk_expander_set_expanded (GTK_EXPANDER (expander), dds_write_vals.show_adv_opt);
+  gtk_expander_set_spacing (GTK_EXPANDER (expander), 8);
+  g_signal_connect (expander, "activate",
+                    G_CALLBACK (adv_opt_expanded), 0);
+  gtk_box_pack_start (GTK_BOX (vbox), expander, 1, 1, 0);
+  gtk_widget_show (expander);
+
+
+  vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4);
+  gtk_container_add (GTK_CONTAINER (expander), vbox2);
+  gtk_widget_show (vbox2);
+
+  frame = gtk_frame_new (_("Compression"));
+  gtk_box_pack_start (GTK_BOX (vbox2), frame, 1, 1, 0);
+  gtk_widget_show (frame);
+
+  table = gtk_table_new (1, 2, 0);
+  gtk_table_set_row_spacings (GTK_TABLE (table), 4);
+  gtk_table_set_col_spacings (GTK_TABLE (table), 8);
+  gtk_container_set_border_width (GTK_CONTAINER (table), 8);
+  gtk_container_add (GTK_CONTAINER (frame), table);
+  gtk_widget_show (table);
+
+  check = gtk_check_button_new_with_label (_("Use perceptual error metric"));
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), dds_write_vals.perceptual_metric);
+  gtk_table_attach (GTK_TABLE (table), check, 0, 2, 0, 1,
                     (GtkAttachOptions)(GTK_FILL),
                     (GtkAttachOptions)(0), 0, 0);
-   g_signal_connect(check, "clicked",
-                      G_CALLBACK(toggle_clicked), &dds_write_vals.perceptual_metric);
-   gtk_widget_show(check);
-
-   pm_chk = check;
-
-   frame = gtk_frame_new(_("Mipmaps"));
-   gtk_box_pack_start(GTK_BOX(vbox2), frame, 1, 1, 0);
-   gtk_widget_show(frame);
-
-   table = gtk_table_new(7, 2, 0);
-   gtk_table_set_row_spacings(GTK_TABLE(table), 4);
-   gtk_table_set_col_spacings(GTK_TABLE(table), 8);
-   gtk_container_set_border_width(GTK_CONTAINER(table), 8);
-   gtk_container_add(GTK_CONTAINER(frame), table);
-   gtk_widget_show(table);
-
-   label = gtk_label_new(_("Filter:"));
-   gtk_widget_show(label);
-   gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1,
+  g_signal_connect (check, "clicked",
+                    G_CALLBACK (toggle_clicked), &dds_write_vals.perceptual_metric);
+  gtk_widget_show (check);
+
+  pm_chk = check;
+
+  frame = gtk_frame_new (_("Mipmaps"));
+  gtk_box_pack_start (GTK_BOX (vbox2), frame, 1, 1, 0);
+  gtk_widget_show (frame);
+
+  table = gtk_table_new (7, 2, 0);
+  gtk_table_set_row_spacings (GTK_TABLE (table), 4);
+  gtk_table_set_col_spacings (GTK_TABLE (table), 8);
+  gtk_container_set_border_width (GTK_CONTAINER (table), 8);
+  gtk_container_add (GTK_CONTAINER (frame), table);
+  gtk_widget_show (table);
+
+  label = gtk_label_new (_("Filter:"));
+  gtk_widget_show (label);
+  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
                     (GtkAttachOptions)(GTK_FILL),
                     (GtkAttachOptions)(0), 0, 0);
-   gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
+  gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
 
-   opt = string_value_combo_new(mipmap_filter_strings,
+  opt = string_value_combo_new (mipmap_filter_strings,
                                 dds_write_vals.mipmap_filter);
-   gtk_widget_show(opt);
-   gtk_table_attach(GTK_TABLE(table), opt, 1, 2, 0, 1,
+  gtk_widget_show (opt);
+  gtk_table_attach (GTK_TABLE (table), opt, 1, 2, 0, 1,
                     (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
                     (GtkAttachOptions)(GTK_EXPAND), 0, 0);
 
-   g_signal_connect(opt, "changed",
-                      G_CALLBACK(string_value_combo_selected),
-                      &dds_write_vals.mipmap_filter);
+  g_signal_connect (opt, "changed",
+                    G_CALLBACK (string_value_combo_selected),
+                    &dds_write_vals.mipmap_filter);
 
-   mipmap_filter_opt = opt;
+  mipmap_filter_opt = opt;
 
-   label = gtk_label_new(_("Wrap mode:"));
-   gtk_widget_show(label);
-   gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
+  label = gtk_label_new (_("Wrap mode:"));
+  gtk_widget_show (label);
+  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
                     (GtkAttachOptions)(GTK_FILL),
                     (GtkAttachOptions)(0), 0, 0);
-   gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
+  gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
 
-   opt = string_value_combo_new(mipmap_wrap_strings,
+  opt = string_value_combo_new (mipmap_wrap_strings,
                                 dds_write_vals.mipmap_wrap);
-   gtk_widget_show(opt);
-   gtk_table_attach(GTK_TABLE(table), opt, 1, 2, 1, 2,
+  gtk_widget_show (opt);
+  gtk_table_attach (GTK_TABLE (table), opt, 1, 2, 1, 2,
                     (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
                     (GtkAttachOptions)(GTK_EXPAND), 0, 0);
 
-   g_signal_connect(opt, "changed",
-                      G_CALLBACK(string_value_combo_selected),
-                      &dds_write_vals.mipmap_wrap);
+  g_signal_connect (opt, "changed",
+                    G_CALLBACK (string_value_combo_selected),
+                    &dds_write_vals.mipmap_wrap);
 
-   mipmap_wrap_opt = opt;
+  mipmap_wrap_opt = opt;
 
-   check = gtk_check_button_new_with_label(_("Apply gamma correction"));
-   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), dds_write_vals.gamma_correct && 
dds_write_vals.mipmaps);
-   gtk_table_attach(GTK_TABLE(table), check, 1, 2, 2, 3,
+  check = gtk_check_button_new_with_label (_("Apply gamma correction"));
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), dds_write_vals.gamma_correct && 
dds_write_vals.mipmaps);
+  gtk_table_attach (GTK_TABLE (table), check, 1, 2, 2, 3,
                     (GtkAttachOptions)(GTK_FILL),
                     (GtkAttachOptions)(0), 0, 0);
-   g_signal_connect(check, "clicked",
-                      G_CALLBACK(gamma_correct_clicked), NULL);
-   gtk_widget_show(check);
+  g_signal_connect (check, "clicked",
+                    G_CALLBACK (gamma_correct_clicked), NULL);
+  gtk_widget_show (check);
 
-   gamma_chk = check;
+  gamma_chk = check;
 
-   check = gtk_check_button_new_with_label(_("Use sRGB colorspace"));
-   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), dds_write_vals.gamma_correct && 
dds_write_vals.srgb);
-   gtk_table_attach(GTK_TABLE(table), check, 1, 2, 3, 4,
+  check = gtk_check_button_new_with_label (_("Use sRGB colorspace"));
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), dds_write_vals.gamma_correct && 
dds_write_vals.srgb);
+  gtk_table_attach (GTK_TABLE (table), check, 1, 2, 3, 4,
                     (GtkAttachOptions)(GTK_FILL),
                     (GtkAttachOptions)(0), 0, 0);
-   g_signal_connect(check, "clicked",
-                      G_CALLBACK(srgb_clicked), NULL);
-   gtk_widget_show(check);
+  g_signal_connect (check, "clicked",
+                    G_CALLBACK (srgb_clicked), NULL);
+  gtk_widget_show (check);
 
-   srgb_chk = check;
+  srgb_chk = check;
 
-   label = gtk_label_new(_("Gamma:"));
-   gtk_widget_show(label);
-   gtk_table_attach(GTK_TABLE(table), label, 0, 1, 4, 5,
+  label = gtk_label_new (_("Gamma:"));
+  gtk_widget_show (label);
+  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 4, 5,
                     (GtkAttachOptions)(GTK_FILL),
                     (GtkAttachOptions)(0), 0, 0);
-   gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
+  gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
 
-   spin = gtk_spin_button_new(GTK_ADJUSTMENT(gtk_adjustment_new(dds_write_vals.gamma, 1e-05, 100, 0.1, 0.5, 
0)), 1, 1);
-   gtk_table_attach(GTK_TABLE(table), spin, 1, 2, 4, 5,
+  spin = gtk_spin_button_new (GTK_ADJUSTMENT (gtk_adjustment_new (dds_write_vals.gamma, 1e-05, 100, 0.1, 
0.5, 0)), 1, 1);
+  gtk_table_attach (GTK_TABLE (table), spin, 1, 2, 4, 5,
                     (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
                     (GtkAttachOptions)(GTK_EXPAND), 0, 0);
-   gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(spin), GTK_UPDATE_IF_VALID);
-   g_signal_connect(spin, "value_changed",
-                      G_CALLBACK(gamma_changed), 0);
-   gtk_widget_show(spin);
+  gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (spin), GTK_UPDATE_IF_VALID);
+  g_signal_connect (spin, "value_changed",
+                    G_CALLBACK (gamma_changed), 0);
+  gtk_widget_show (spin);
 
-   gamma_spin = spin;
+  gamma_spin = spin;
 
-   check = gtk_check_button_new_with_label(_("Preserve alpha test coverage"));
-   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), dds_write_vals.preserve_alpha_coverage && 
dds_write_vals.mipmaps);
-   gtk_table_attach(GTK_TABLE(table), check, 1, 2, 5, 6,
+  check = gtk_check_button_new_with_label (_("Preserve alpha test coverage"));
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), dds_write_vals.preserve_alpha_coverage && 
dds_write_vals.mipmaps);
+  gtk_table_attach (GTK_TABLE (table), check, 1, 2, 5, 6,
                     (GtkAttachOptions)(GTK_FILL),
                     (GtkAttachOptions)(0), 0, 0);
-   g_signal_connect(check, "clicked",
-                      G_CALLBACK(alpha_coverage_clicked), NULL);
-   gtk_widget_show(check);
+  g_signal_connect (check, "clicked",
+                    G_CALLBACK (alpha_coverage_clicked), NULL);
+  gtk_widget_show (check);
 
-   alpha_coverage_chk = check;
+  alpha_coverage_chk = check;
 
-   label = gtk_label_new(_("Alpha test threshold:"));
-   gtk_widget_show(label);
-   gtk_table_attach(GTK_TABLE(table), label, 0, 1, 6, 7,
+  label = gtk_label_new (_("Alpha test threshold:"));
+  gtk_widget_show (label);
+  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 6, 7,
                     (GtkAttachOptions)(GTK_FILL),
                     (GtkAttachOptions)(0), 0, 0);
-   gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
+  gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
 
-   spin = gtk_spin_button_new(GTK_ADJUSTMENT(gtk_adjustment_new(dds_write_vals.alpha_test_threshold, 0, 1, 
0.01, 0.1, 0)), 1, 2);
-   gtk_table_attach(GTK_TABLE(table), spin, 1, 2, 6, 7,
+  spin = gtk_spin_button_new (GTK_ADJUSTMENT (gtk_adjustment_new (dds_write_vals.alpha_test_threshold, 0, 1, 
0.01, 0.1, 0)), 1, 2);
+  gtk_table_attach (GTK_TABLE (table), spin, 1, 2, 6, 7,
                     (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
                     (GtkAttachOptions)(GTK_EXPAND), 0, 0);
-   gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(spin), GTK_UPDATE_IF_VALID);
-   g_signal_connect(spin, "value_changed",
-                      G_CALLBACK(alpha_test_threshold_changed), 0);
-   gtk_widget_show(spin);
-
-   alpha_test_threshold_spin = spin;
-
-   gtk_widget_set_sensitive(mipmap_filter_opt, dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE);
-   gtk_widget_set_sensitive(mipmap_wrap_opt, dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE);
-   gtk_widget_set_sensitive(gamma_chk, dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE);
-   gtk_widget_set_sensitive(srgb_chk, (dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE) && 
dds_write_vals.gamma_correct);
-   gtk_widget_set_sensitive(gamma_spin, (dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE) &&
+  gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (spin), GTK_UPDATE_IF_VALID);
+  g_signal_connect (spin, "value_changed",
+                    G_CALLBACK (alpha_test_threshold_changed), 0);
+  gtk_widget_show (spin);
+
+  alpha_test_threshold_spin = spin;
+
+  gtk_widget_set_sensitive (mipmap_filter_opt, dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE);
+  gtk_widget_set_sensitive (mipmap_wrap_opt, dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE);
+  gtk_widget_set_sensitive (gamma_chk, dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE);
+  gtk_widget_set_sensitive (srgb_chk, (dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE) && 
dds_write_vals.gamma_correct);
+  gtk_widget_set_sensitive (gamma_spin, (dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE) &&
                             dds_write_vals.gamma_correct && !dds_write_vals.srgb);
-   gtk_widget_set_sensitive(pm_chk, dds_write_vals.compression != DDS_COMPRESS_NONE);
-   gtk_widget_set_sensitive(alpha_coverage_chk, dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE);
-   gtk_widget_set_sensitive(alpha_test_threshold_spin, (dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE) &&
+  gtk_widget_set_sensitive (pm_chk, dds_write_vals.compression != DDS_COMPRESS_NONE);
+  gtk_widget_set_sensitive (alpha_coverage_chk, dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE);
+  gtk_widget_set_sensitive (alpha_test_threshold_spin, (dds_write_vals.mipmaps == DDS_MIPMAP_GENERATE) &&
                             dds_write_vals.preserve_alpha_coverage);
 
-   gtk_widget_show(dlg);
+  gtk_widget_show (dlg);
 
-   runme = 0;
+  runme = 0;
 
-   gtk_main();
+  gtk_main ();
 
-   return(runme);
+  return (runme);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]