diff --git a/plug-ins/file-dds/color.c b/plug-ins/file-dds/color.c index 3ec0f17a01..0c1be4095d 100644 --- a/plug-ins/file-dds/color.c +++ b/plug-ins/file-dds/color.c @@ -1,56 +1,58 @@ /* - DDS GIMP plugin - - Copyright (C) 2004-2012 Shawn Kirst , - with parts (C) 2003 Arne Reuter 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 , + * with parts (C) 2003 Arne Reuter 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 #include "color.h" -int linear_to_sRGB(int c) +int +linear_to_sRGB(int c) { - float v = (float)c / 255.0f; - - if(v < 0) - v = 0; - else if(v > 1) - v = 1; - else if(v <= 0.0031308f) - v = 12.92f * v; - else - v = 1.055f * powf(v, 0.41666f) - 0.055f; - - return((int)floorf(255.0f * v + 0.5f)); + float v = (float)c / 255.0f; + + if(v < 0) + v = 0; + else if(v > 1) + v = 1; + else if(v <= 0.0031308f) + v = 12.92f * v; + else + v = 1.055f * powf(v, 0.41666f) - 0.055f; + + return (int)floorf(255.0f * v + 0.5f); } -int sRGB_to_linear(int c) +int +sRGB_to_linear(int c) { - float v = (float)c / 255.0f; - - if(v < 0) - v = 0; - else if(v > 1) - v = 1; - else if(v <= 0.04045f) - v /= 12.92f; - else - v = powf((v + 0.055f) / 1.055f, 2.4f); - - return((int)floorf(255.0f * v + 0.5f)); + float v = (float)c / 255.0f; + + if(v < 0) + v = 0; + else if(v > 1) + v = 1; + else if(v <= 0.04045f) + v /= 12.92f; + else + v = powf((v + 0.055f) / 1.055f, 2.4f); + + return (int)floorf(255.0f * v + 0.5f); } diff --git a/plug-ins/file-dds/color.h b/plug-ins/file-dds/color.h index 8cb1f544d9..b5afa144e0 100644 --- a/plug-ins/file-dds/color.h +++ b/plug-ins/file-dds/color.h @@ -1,27 +1,25 @@ /* - DDS GIMP plugin + * DDS GIMP plugin + * + * Copyright (C) 2004-2012 Shawn Kirst , + * with parts (C) 2003 Arne Reuter 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 3 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. If not, see . + */ - Copyright (C) 2004-2012 Shawn Kirst , - with parts (C) 2003 Arne Reuter 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 COLOR_H -#define COLOR_H +#ifndef __COLOR_H__ +#define __COLOR_H__ #include "imath.h" @@ -30,62 +28,69 @@ int linear_to_sRGB(int c); int sRGB_to_linear(int c); /* YCoCg encoding */ -static inline void RGB_to_YCoCg(unsigned char *dst, int r, int g, int b) +static inline void +RGB_to_YCoCg (unsigned char *dst, int r, int g, int b) { - int y = ((r + (g << 1) + b) + 2) >> 2; - int co = ((((r << 1) - (b << 1)) + 2) >> 2) + 128; - int cg = (((-r + (g << 1) - b) + 2) >> 2) + 128; + int y = ((r + (g << 1) + b) + 2) >> 2; + int co = ((((r << 1) - (b << 1)) + 2) >> 2) + 128; + int cg = (((-r + (g << 1) - b) + 2) >> 2) + 128; - dst[0] = 255; - dst[1] = (cg > 255 ? 255 : (cg < 0 ? 0 : cg)); - dst[2] = (co > 255 ? 255 : (co < 0 ? 0 : co)); - dst[3] = (y > 255 ? 255 : (y < 0 ? 0 : y)); + dst[0] = 255; + dst[1] = (cg > 255 ? 255 : (cg < 0 ? 0 : cg)); + dst[2] = (co > 255 ? 255 : (co < 0 ? 0 : co)); + dst[3] = (y > 255 ? 255 : (y < 0 ? 0 : y)); } /* other color conversions */ -static inline int rgb_to_luminance(int r, int g, int b) +static inline int +rgb_to_luminance (int r, int g, int b) { - /* ITU-R BT.709 luma coefficents, scaled by 256 */ - return(((r * 54 + g * 182 + b * 20) + 128) >> 8); + /* ITU-R BT.709 luma coefficents, scaled by 256 */ + return ((r * 54 + g * 182 + b * 20) + 128) >> 8; } -static inline unsigned short pack_r5g6b5(int r, int g, int b) +static inline unsigned short +pack_r5g6b5 (int r, int g, int b) { - return((mul8bit(r, 31) << 11) | - (mul8bit(g, 63) << 5) | - (mul8bit(b, 31) )); + return (mul8bit(r, 31) << 11) | + (mul8bit(g, 63) << 5) | + (mul8bit(b, 31) ); } -static inline unsigned short pack_rgba4(int r, int g, int b, int a) +static inline unsigned short +pack_rgba4 (int r, int g, int b, int a) { - return((mul8bit(a, 15) << 12) | - (mul8bit(r, 15) << 8) | - (mul8bit(g, 15) << 4) | - (mul8bit(b, 15) )); + return (mul8bit(a, 15) << 12) | + (mul8bit(r, 15) << 8) | + (mul8bit(g, 15) << 4) | + (mul8bit(b, 15) ); } -static inline unsigned short pack_rgb5a1(int r, int g, int b, int a) +static inline unsigned short +pack_rgb5a1 (int r, int g, int b, int a) { - return((((a >> 7) & 0x01) << 15) | - (mul8bit(r, 31) << 10) | - (mul8bit(g, 31) << 5) | - (mul8bit(b, 31) )); + return (((a >> 7) & 0x01) << 15) | + (mul8bit(r, 31) << 10) | + (mul8bit(g, 31) << 5) | + (mul8bit(b, 31) ); } -static inline unsigned char pack_r3g3b2(int r, int g, int b) +static inline unsigned char +pack_r3g3b2(int r, int g, int b) { - return((mul8bit(r, 7) << 5) | - (mul8bit(g, 7) << 2) | - (mul8bit(b, 3) )); + return (mul8bit(r, 7) << 5) | + (mul8bit(g, 7) << 2) | + (mul8bit(b, 3) ); } -static inline unsigned int pack_rgb10a2(int r, int g, int b, int a) +static inline unsigned int +pack_rgb10a2 (int r, int g, int b, int a) { - return(((unsigned int)((a >> 6) & 0x003) << 30) | - ((unsigned int)((r << 2) & 0x3ff) << 20) | - ((unsigned int)((g << 2) & 0x3ff) << 10) | - ((unsigned int)((b << 2) & 0x3ff) )); + return ((unsigned int)((a >> 6) & 0x003) << 30) | + ((unsigned int)((r << 2) & 0x3ff) << 20) | + ((unsigned int)((g << 2) & 0x3ff) << 10) | + ((unsigned int)((b << 2) & 0x3ff) ); } -#endif +#endif /* __COLOR_H__ */ diff --git a/plug-ins/file-dds/dds.c b/plug-ins/file-dds/dds.c index ea8a943fe9..477305627b 100644 --- a/plug-ins/file-dds/dds.c +++ b/plug-ins/file-dds/dds.c @@ -37,6 +37,7 @@ #include "dds.h" #include "misc.h" + static void query (void); static void run (const gchar *name, gint nparams, @@ -44,6 +45,7 @@ static void run (const gchar *name, gint *nreturn_vals, GimpParam **return_vals); + GimpPlugInInfo PLUG_IN_INFO = { 0, @@ -52,7 +54,6 @@ GimpPlugInInfo PLUG_IN_INFO = run }; - DDSWriteVals dds_write_vals = { DDS_COMPRESS_NONE, @@ -73,55 +74,57 @@ DDSWriteVals dds_write_vals = DDSReadVals dds_read_vals = { - 1, - 1 + 1, + 1 }; static GimpParamDef load_args[] = { - {GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive"}, - {GIMP_PDB_STRING, "filename", "The name of the file to load"}, - {GIMP_PDB_STRING, "raw_filename", "The name entered"}, - {GIMP_PDB_INT32, "load_mipmaps", "Load mipmaps if present"}, - {GIMP_PDB_INT32, "decode_images", "Decode YCoCg/AExp images when detected"} + { GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive"}, + { GIMP_PDB_STRING, "filename", "The name of the file to load"}, + { GIMP_PDB_STRING, "raw_filename", "The name entered"}, + { 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"} + { GIMP_PDB_IMAGE, "image", "Output image"} }; static GimpParamDef save_args[] = { - {GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive"}, - {GIMP_PDB_IMAGE, "image", "Input image"}, - {GIMP_PDB_DRAWABLE, "drawable", "Drawable to save"}, - {GIMP_PDB_STRING, "filename", "The name of the file to save the image as"}, - {GIMP_PDB_STRING, "raw_filename", "The name entered"}, - {GIMP_PDB_INT32, "compression_format", "Compression format (0 = None, 1 = BC1/DXT1, 2 = BC2/DXT3, 3 = BC3/DXT5, 4 = BC3n/DXT5nm, 5 = BC4/ATI1N, 6 = BC5/ATI2N, 7 = RXGB (DXT5), 8 = Alpha Exponent (DXT5), 9 = YCoCg (DXT5), 10 = YCoCg scaled (DXT5))"}, - {GIMP_PDB_INT32, "mipmaps", "How to handle mipmaps (0 = No mipmaps, 1 = Generate mipmaps, 2 = Use existing mipmaps (layers)"}, - {GIMP_PDB_INT32, "savetype", "How to save the image (0 = selected layer, 1 = cube map, 2 = volume map, 3 = texture array"}, - {GIMP_PDB_INT32, "format", "Custom pixel format (0 = default, 1 = R5G6B5, 2 = RGBA4, 3 = RGB5A1, 4 = RGB10A2)"}, - {GIMP_PDB_INT32, "transparent_index", "Index of transparent color or -1 to disable (for indexed images only)."}, - {GIMP_PDB_INT32, "mipmap_filter", "Filtering to use when generating mipmaps (0 = default, 1 = nearest, 2 = box, 3 = triangle, 4 = quadratic, 5 = bspline, 6 = mitchell, 7 = lanczos, 8 = kaiser)"}, - {GIMP_PDB_INT32, "mipmap_wrap", "Wrap mode to use when generating mipmaps (0 = default, 1 = mirror, 2 = repeat, 3 = clamp)"}, - {GIMP_PDB_INT32, "gamma_correct", "Use gamma correct mipmap filtering"}, - {GIMP_PDB_INT32, "srgb", "Use sRGB colorspace for gamma correction"}, - {GIMP_PDB_FLOAT, "gamma", "Gamma value to use for gamma correction (i.e. 2.2)"}, - {GIMP_PDB_INT32, "perceptual_metric", "Use a perceptual error metric during compression"}, - {GIMP_PDB_INT32, "preserve_alpha_coverage", "Preserve alpha test converage for alpha channel maps"}, - {GIMP_PDB_FLOAT, "alpha_test_threshold", "Alpha test threshold value for which alpha test converage should be preserved"} + { GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive"}, + { GIMP_PDB_IMAGE, "image", "Input image"}, + { GIMP_PDB_DRAWABLE, "drawable", "Drawable to save"}, + { GIMP_PDB_STRING, "filename", "The name of the file to save the image as"}, + { GIMP_PDB_STRING, "raw_filename", "The name entered"}, + { GIMP_PDB_INT32, "compression_format", "Compression format (0 = None, 1 = BC1/DXT1, 2 = BC2/DXT3, 3 = BC3/DXT5, 4 = BC3n/DXT5nm, 5 = BC4/ATI1N, 6 = BC5/ATI2N, 7 = RXGB (DXT5), 8 = Alpha Exponent (DXT5), 9 = YCoCg (DXT5), 10 = YCoCg scaled (DXT5))"}, + { GIMP_PDB_INT32, "mipmaps", "How to handle mipmaps (0 = No mipmaps, 1 = Generate mipmaps, 2 = Use existing mipmaps (layers)"}, + { GIMP_PDB_INT32, "savetype", "How to save the image (0 = selected layer, 1 = cube map, 2 = volume map, 3 = texture array"}, + { GIMP_PDB_INT32, "format", "Custom pixel format (0 = default, 1 = R5G6B5, 2 = RGBA4, 3 = RGB5A1, 4 = RGB10A2)"}, + { GIMP_PDB_INT32, "transparent_index", "Index of transparent color or -1 to disable (for indexed images only)."}, + { GIMP_PDB_INT32, "mipmap_filter", "Filtering to use when generating mipmaps (0 = default, 1 = nearest, 2 = box, 3 = triangle, 4 = quadratic, 5 = bspline, 6 = mitchell, 7 = lanczos, 8 = kaiser)"}, + { GIMP_PDB_INT32, "mipmap_wrap", "Wrap mode to use when generating mipmaps (0 = default, 1 = mirror, 2 = repeat, 3 = clamp)"}, + { GIMP_PDB_INT32, "gamma_correct", "Use gamma correct mipmap filtering"}, + { GIMP_PDB_INT32, "srgb", "Use sRGB colorspace for gamma correction"}, + { GIMP_PDB_FLOAT, "gamma", "Gamma value to use for gamma correction (i.e. 2.2)"}, + { GIMP_PDB_INT32, "perceptual_metric", "Use a perceptual error metric during compression"}, + { GIMP_PDB_INT32, "preserve_alpha_coverage", "Preserve alpha test converage for alpha channel maps"}, + { GIMP_PDB_FLOAT, "alpha_test_threshold", "Alpha test threshold value for which alpha test converage should be preserved"} }; static GimpParamDef decode_args[] = { - {GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive"}, - {GIMP_PDB_IMAGE, "image", "Input image"}, - {GIMP_PDB_DRAWABLE, "drawable", "Drawable to save"} + { GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive"}, + { GIMP_PDB_IMAGE, "image", "Input image"}, + { GIMP_PDB_DRAWABLE, "drawable", "Drawable to save"} }; + MAIN () + static void query (void) { @@ -225,7 +228,7 @@ run (const gchar *name, values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR; - if (!strcmp (name, LOAD_PROC)) + if (! strcmp (name, LOAD_PROC)) { switch (run_mode) { @@ -233,12 +236,14 @@ run (const gchar *name, 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; } @@ -256,12 +261,14 @@ run (const gchar *name, gimp_set_data (LOAD_PROC, &dds_read_vals, sizeof (dds_read_vals)); } else if (status != GIMP_PDB_CANCEL) - status = GIMP_PDB_EXECUTION_ERROR; + { + status = GIMP_PDB_EXECUTION_ERROR; + } } } - else if (!strcmp (name, SAVE_PROC)) + else if (! strcmp (name, SAVE_PROC)) { - imageID = param[1].data.d_int32; + imageID = param[1].data.d_int32; drawableID = param[2].data.d_int32; switch (run_mode) @@ -280,6 +287,7 @@ run (const gchar *name, values[0].data.d_status = GIMP_PDB_CANCEL; return; } + default: break; } @@ -289,48 +297,70 @@ run (const gchar *name, 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; + { + 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.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; + 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; + { + 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; + { + 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; + { + 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; + { + 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; + { + 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; + { + status = GIMP_PDB_CALLING_ERROR; + } } break; + case GIMP_RUN_WITH_LAST_VALS: gimp_get_data (SAVE_PROC, &dds_write_vals); break; + default: break; } @@ -353,7 +383,7 @@ run (const gchar *name, if (export == GIMP_EXPORT_EXPORT) gimp_image_delete (imageID); } - else if (!strcmp (name, DECODE_YCOCG_PROC)) + else if (! strcmp (name, DECODE_YCOCG_PROC)) { imageID = param[1].data.d_int32; drawableID = param[2].data.d_int32; @@ -365,7 +395,7 @@ run (const gchar *name, if (run_mode != GIMP_RUN_NONINTERACTIVE) gimp_displays_flush (); } - else if (!strcmp (name, DECODE_YCOCG_SCALED_PROC)) + else if (! strcmp (name, DECODE_YCOCG_SCALED_PROC)) { imageID = param[1].data.d_int32; drawableID = param[2].data.d_int32; @@ -377,7 +407,7 @@ run (const gchar *name, if (run_mode != GIMP_RUN_NONINTERACTIVE) gimp_displays_flush (); } - else if (!strcmp (name, DECODE_ALPHA_EXP_PROC)) + else if (! strcmp (name, DECODE_ALPHA_EXP_PROC)) { imageID = param[1].data.d_int32; drawableID = param[2].data.d_int32; @@ -390,7 +420,9 @@ run (const gchar *name, gimp_displays_flush (); } else - status = GIMP_PDB_CALLING_ERROR; + { + status = GIMP_PDB_CALLING_ERROR; + } values[0].data.d_status = status; } diff --git a/plug-ins/file-dds/dds.h b/plug-ins/file-dds/dds.h index 5e2086aeed..8442c53bec 100644 --- a/plug-ins/file-dds/dds.h +++ b/plug-ins/file-dds/dds.h @@ -4,24 +4,22 @@ * Copyright (C) 2004-2012 Shawn Kirst , * with parts (C) 2003 Arne Reuter 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 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 3 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. + * 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. + * along with this program. If not, see . */ -#ifndef DDS_H -#define DDS_H +#ifndef __DDS_H__ +#define __DDS_H__ #define FOURCC(a, b, c, d) \ ((unsigned int)((unsigned int)(a) ) | \ @@ -31,78 +29,78 @@ typedef enum { - DDS_COMPRESS_NONE = 0, - DDS_COMPRESS_BC1, /* DXT1 */ - DDS_COMPRESS_BC2, /* DXT3 */ - DDS_COMPRESS_BC3, /* DXT5 */ - DDS_COMPRESS_BC3N, /* DXT5n */ - DDS_COMPRESS_BC4, /* ATI1 */ - DDS_COMPRESS_BC5, /* ATI2 */ - DDS_COMPRESS_RXGB, /* DXT5 */ - DDS_COMPRESS_AEXP, /* DXT5 */ - DDS_COMPRESS_YCOCG, /* DXT5 */ - DDS_COMPRESS_YCOCGS, /* DXT5 */ - DDS_COMPRESS_MAX + DDS_COMPRESS_NONE = 0, + DDS_COMPRESS_BC1, /* DXT1 */ + DDS_COMPRESS_BC2, /* DXT3 */ + DDS_COMPRESS_BC3, /* DXT5 */ + DDS_COMPRESS_BC3N, /* DXT5n */ + DDS_COMPRESS_BC4, /* ATI1 */ + DDS_COMPRESS_BC5, /* ATI2 */ + DDS_COMPRESS_RXGB, /* DXT5 */ + DDS_COMPRESS_AEXP, /* DXT5 */ + DDS_COMPRESS_YCOCG, /* DXT5 */ + DDS_COMPRESS_YCOCGS, /* DXT5 */ + DDS_COMPRESS_MAX } DDS_COMPRESSION_TYPE; typedef enum { - DDS_SAVE_SELECTED_LAYER = 0, - DDS_SAVE_CUBEMAP, - DDS_SAVE_VOLUMEMAP, - DDS_SAVE_ARRAY, - DDS_SAVE_MAX + DDS_SAVE_SELECTED_LAYER = 0, + DDS_SAVE_CUBEMAP, + DDS_SAVE_VOLUMEMAP, + DDS_SAVE_ARRAY, + DDS_SAVE_MAX } DDS_SAVE_TYPE; typedef enum { - DDS_FORMAT_DEFAULT = 0, - DDS_FORMAT_RGB8, - DDS_FORMAT_RGBA8, - DDS_FORMAT_BGR8, - DDS_FORMAT_ABGR8, - DDS_FORMAT_R5G6B5, - DDS_FORMAT_RGBA4, - DDS_FORMAT_RGB5A1, - DDS_FORMAT_RGB10A2, - DDS_FORMAT_R3G3B2, - DDS_FORMAT_A8, - DDS_FORMAT_L8, - DDS_FORMAT_L8A8, - DDS_FORMAT_AEXP, - DDS_FORMAT_YCOCG, - DDS_FORMAT_MAX + DDS_FORMAT_DEFAULT = 0, + DDS_FORMAT_RGB8, + DDS_FORMAT_RGBA8, + DDS_FORMAT_BGR8, + DDS_FORMAT_ABGR8, + DDS_FORMAT_R5G6B5, + DDS_FORMAT_RGBA4, + DDS_FORMAT_RGB5A1, + DDS_FORMAT_RGB10A2, + DDS_FORMAT_R3G3B2, + DDS_FORMAT_A8, + DDS_FORMAT_L8, + DDS_FORMAT_L8A8, + DDS_FORMAT_AEXP, + DDS_FORMAT_YCOCG, + DDS_FORMAT_MAX } DDS_FORMAT_TYPE; typedef enum { - DDS_MIPMAP_NONE = 0, - DDS_MIPMAP_GENERATE, - DDS_MIPMAP_EXISTING, - DDS_MIPMAP_MAX + DDS_MIPMAP_NONE = 0, + DDS_MIPMAP_GENERATE, + DDS_MIPMAP_EXISTING, + DDS_MIPMAP_MAX } DDS_MIPMAP; typedef enum { - DDS_MIPMAP_FILTER_DEFAULT = 0, - DDS_MIPMAP_FILTER_NEAREST, - DDS_MIPMAP_FILTER_BOX, - DDS_MIPMAP_FILTER_TRIANGLE, - DDS_MIPMAP_FILTER_QUADRATIC, - DDS_MIPMAP_FILTER_BSPLINE, - DDS_MIPMAP_FILTER_MITCHELL, - DDS_MIPMAP_FILTER_LANCZOS, - DDS_MIPMAP_FILTER_KAISER, - DDS_MIPMAP_FILTER_MAX + DDS_MIPMAP_FILTER_DEFAULT = 0, + DDS_MIPMAP_FILTER_NEAREST, + DDS_MIPMAP_FILTER_BOX, + DDS_MIPMAP_FILTER_TRIANGLE, + DDS_MIPMAP_FILTER_QUADRATIC, + DDS_MIPMAP_FILTER_BSPLINE, + DDS_MIPMAP_FILTER_MITCHELL, + DDS_MIPMAP_FILTER_LANCZOS, + DDS_MIPMAP_FILTER_KAISER, + DDS_MIPMAP_FILTER_MAX } DDS_MIPMAP_FILTER; typedef enum { - DDS_MIPMAP_WRAP_DEFAULT = 0, - DDS_MIPMAP_WRAP_MIRROR, - DDS_MIPMAP_WRAP_REPEAT, - DDS_MIPMAP_WRAP_CLAMP, - DDS_MIPMAP_WRAP_MAX + DDS_MIPMAP_WRAP_DEFAULT = 0, + DDS_MIPMAP_WRAP_MIRROR, + DDS_MIPMAP_WRAP_REPEAT, + DDS_MIPMAP_WRAP_CLAMP, + DDS_MIPMAP_WRAP_MAX } DDS_MIPMAP_WRAP; #define DDS_HEADERSIZE 128 @@ -151,177 +149,177 @@ typedef enum typedef struct { - unsigned int size; - unsigned int flags; - char fourcc[4]; - unsigned int bpp; - unsigned int rmask; - unsigned int gmask; - unsigned int bmask; - unsigned int amask; + unsigned int size; + unsigned int flags; + char fourcc[4]; + unsigned int bpp; + unsigned int rmask; + unsigned int gmask; + unsigned int bmask; + unsigned int amask; } dds_pixel_format_t; typedef struct { - unsigned int caps1; - unsigned int caps2; - unsigned int reserved[2]; + unsigned int caps1; + unsigned int caps2; + unsigned int reserved[2]; } dds_caps_t; typedef struct { - unsigned int magic; - unsigned int size; - unsigned int flags; - unsigned int height; - unsigned int width; - unsigned int pitch_or_linsize; - unsigned int depth; - unsigned int num_mipmaps; - union - { - struct - { - unsigned int magic1; // FOURCC "GIMP" - unsigned int magic2; // FOURCC "-DDS" - unsigned int version; - unsigned int extra_fourcc; - } gimp_dds_special; - unsigned char pad[4 * 11]; - } reserved; - dds_pixel_format_t pixelfmt; - dds_caps_t caps; - unsigned int reserved2; + unsigned int magic; + unsigned int size; + unsigned int flags; + unsigned int height; + unsigned int width; + unsigned int pitch_or_linsize; + unsigned int depth; + unsigned int num_mipmaps; + union + { + struct + { + unsigned int magic1; // FOURCC "GIMP" + unsigned int magic2; // FOURCC "-DDS" + unsigned int version; + unsigned int extra_fourcc; + } gimp_dds_special; + unsigned char pad[4 * 11]; + } reserved; + dds_pixel_format_t pixelfmt; + dds_caps_t caps; + unsigned int reserved2; } dds_header_t; typedef enum { - DXGI_FORMAT_UNKNOWN = 0, - DXGI_FORMAT_R32G32B32A32_TYPELESS = 1, - DXGI_FORMAT_R32G32B32A32_FLOAT = 2, - DXGI_FORMAT_R32G32B32A32_UINT = 3, - DXGI_FORMAT_R32G32B32A32_SINT = 4, - DXGI_FORMAT_R32G32B32_TYPELESS = 5, - DXGI_FORMAT_R32G32B32_FLOAT = 6, - DXGI_FORMAT_R32G32B32_UINT = 7, - DXGI_FORMAT_R32G32B32_SINT = 8, - DXGI_FORMAT_R16G16B16A16_TYPELESS = 9, - DXGI_FORMAT_R16G16B16A16_FLOAT = 10, - DXGI_FORMAT_R16G16B16A16_UNORM = 11, - DXGI_FORMAT_R16G16B16A16_UINT = 12, - DXGI_FORMAT_R16G16B16A16_SNORM = 13, - DXGI_FORMAT_R16G16B16A16_SINT = 14, - DXGI_FORMAT_R32G32_TYPELESS = 15, - DXGI_FORMAT_R32G32_FLOAT = 16, - DXGI_FORMAT_R32G32_UINT = 17, - DXGI_FORMAT_R32G32_SINT = 18, - DXGI_FORMAT_R32G8X24_TYPELESS = 19, - DXGI_FORMAT_D32_FLOAT_S8X24_UINT = 20, - DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS = 21, - DXGI_FORMAT_X32_TYPELESS_G8X24_UINT = 22, - DXGI_FORMAT_R10G10B10A2_TYPELESS = 23, - DXGI_FORMAT_R10G10B10A2_UNORM = 24, - DXGI_FORMAT_R10G10B10A2_UINT = 25, - DXGI_FORMAT_R11G11B10_FLOAT = 26, - DXGI_FORMAT_R8G8B8A8_TYPELESS = 27, - DXGI_FORMAT_R8G8B8A8_UNORM = 28, - DXGI_FORMAT_R8G8B8A8_UNORM_SRGB = 29, - DXGI_FORMAT_R8G8B8A8_UINT = 30, - DXGI_FORMAT_R8G8B8A8_SNORM = 31, - DXGI_FORMAT_R8G8B8A8_SINT = 32, - DXGI_FORMAT_R16G16_TYPELESS = 33, - DXGI_FORMAT_R16G16_FLOAT = 34, - DXGI_FORMAT_R16G16_UNORM = 35, - DXGI_FORMAT_R16G16_UINT = 36, - DXGI_FORMAT_R16G16_SNORM = 37, - DXGI_FORMAT_R16G16_SINT = 38, - DXGI_FORMAT_R32_TYPELESS = 39, - DXGI_FORMAT_D32_FLOAT = 40, - DXGI_FORMAT_R32_FLOAT = 41, - DXGI_FORMAT_R32_UINT = 42, - DXGI_FORMAT_R32_SINT = 43, - DXGI_FORMAT_R24G8_TYPELESS = 44, - DXGI_FORMAT_D24_UNORM_S8_UINT = 45, - DXGI_FORMAT_R24_UNORM_X8_TYPELESS = 46, - DXGI_FORMAT_X24_TYPELESS_G8_UINT = 47, - DXGI_FORMAT_R8G8_TYPELESS = 48, - DXGI_FORMAT_R8G8_UNORM = 49, - DXGI_FORMAT_R8G8_UINT = 50, - DXGI_FORMAT_R8G8_SNORM = 51, - DXGI_FORMAT_R8G8_SINT = 52, - DXGI_FORMAT_R16_TYPELESS = 53, - DXGI_FORMAT_R16_FLOAT = 54, - DXGI_FORMAT_D16_UNORM = 55, - DXGI_FORMAT_R16_UNORM = 56, - DXGI_FORMAT_R16_UINT = 57, - DXGI_FORMAT_R16_SNORM = 58, - DXGI_FORMAT_R16_SINT = 59, - DXGI_FORMAT_R8_TYPELESS = 60, - DXGI_FORMAT_R8_UNORM = 61, - DXGI_FORMAT_R8_UINT = 62, - DXGI_FORMAT_R8_SNORM = 63, - DXGI_FORMAT_R8_SINT = 64, - DXGI_FORMAT_A8_UNORM = 65, - DXGI_FORMAT_R1_UNORM = 66, - DXGI_FORMAT_R9G9B9E5_SHAREDEXP = 67, - DXGI_FORMAT_R8G8_B8G8_UNORM = 68, - DXGI_FORMAT_G8R8_G8B8_UNORM = 69, - DXGI_FORMAT_BC1_TYPELESS = 70, - DXGI_FORMAT_BC1_UNORM = 71, - DXGI_FORMAT_BC1_UNORM_SRGB = 72, - DXGI_FORMAT_BC2_TYPELESS = 73, - DXGI_FORMAT_BC2_UNORM = 74, - DXGI_FORMAT_BC2_UNORM_SRGB = 75, - DXGI_FORMAT_BC3_TYPELESS = 76, - DXGI_FORMAT_BC3_UNORM = 77, - DXGI_FORMAT_BC3_UNORM_SRGB = 78, - DXGI_FORMAT_BC4_TYPELESS = 79, - DXGI_FORMAT_BC4_UNORM = 80, - DXGI_FORMAT_BC4_SNORM = 81, - DXGI_FORMAT_BC5_TYPELESS = 82, - DXGI_FORMAT_BC5_UNORM = 83, - DXGI_FORMAT_BC5_SNORM = 84, - DXGI_FORMAT_B5G6R5_UNORM = 85, - DXGI_FORMAT_B5G5R5A1_UNORM = 86, - DXGI_FORMAT_B8G8R8A8_UNORM = 87, - DXGI_FORMAT_B8G8R8X8_UNORM = 88, - DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM = 89, - DXGI_FORMAT_B8G8R8A8_TYPELESS = 90, - DXGI_FORMAT_B8G8R8A8_UNORM_SRGB = 91, - DXGI_FORMAT_B8G8R8X8_TYPELESS = 92, - DXGI_FORMAT_B8G8R8X8_UNORM_SRGB = 93, - DXGI_FORMAT_BC6H_TYPELESS = 94, - DXGI_FORMAT_BC6H_UF16 = 95, - DXGI_FORMAT_BC6H_SF16 = 96, - DXGI_FORMAT_BC7_TYPELESS = 97, - DXGI_FORMAT_BC7_UNORM = 98, - DXGI_FORMAT_BC7_UNORM_SRGB = 99, - DXGI_FORMAT_AYUV = 100, - DXGI_FORMAT_Y410 = 101, - DXGI_FORMAT_Y416 = 102, - DXGI_FORMAT_NV12 = 103, - DXGI_FORMAT_P010 = 104, - DXGI_FORMAT_P016 = 105, - DXGI_FORMAT_420_OPAQUE = 106, - DXGI_FORMAT_YUY2 = 107, - DXGI_FORMAT_Y210 = 108, - DXGI_FORMAT_Y216 = 109, - DXGI_FORMAT_NV11 = 110, - DXGI_FORMAT_AI44 = 111, - DXGI_FORMAT_IA44 = 112, - DXGI_FORMAT_P8 = 113, - DXGI_FORMAT_A8P8 = 114, - DXGI_FORMAT_B4G4R4A4_UNORM = 115, - DXGI_FORMAT_FORCE_UINT = 0xffffffffUL + DXGI_FORMAT_UNKNOWN = 0, + DXGI_FORMAT_R32G32B32A32_TYPELESS = 1, + DXGI_FORMAT_R32G32B32A32_FLOAT = 2, + DXGI_FORMAT_R32G32B32A32_UINT = 3, + DXGI_FORMAT_R32G32B32A32_SINT = 4, + DXGI_FORMAT_R32G32B32_TYPELESS = 5, + DXGI_FORMAT_R32G32B32_FLOAT = 6, + DXGI_FORMAT_R32G32B32_UINT = 7, + DXGI_FORMAT_R32G32B32_SINT = 8, + DXGI_FORMAT_R16G16B16A16_TYPELESS = 9, + DXGI_FORMAT_R16G16B16A16_FLOAT = 10, + DXGI_FORMAT_R16G16B16A16_UNORM = 11, + DXGI_FORMAT_R16G16B16A16_UINT = 12, + DXGI_FORMAT_R16G16B16A16_SNORM = 13, + DXGI_FORMAT_R16G16B16A16_SINT = 14, + DXGI_FORMAT_R32G32_TYPELESS = 15, + DXGI_FORMAT_R32G32_FLOAT = 16, + DXGI_FORMAT_R32G32_UINT = 17, + DXGI_FORMAT_R32G32_SINT = 18, + DXGI_FORMAT_R32G8X24_TYPELESS = 19, + DXGI_FORMAT_D32_FLOAT_S8X24_UINT = 20, + DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS = 21, + DXGI_FORMAT_X32_TYPELESS_G8X24_UINT = 22, + DXGI_FORMAT_R10G10B10A2_TYPELESS = 23, + DXGI_FORMAT_R10G10B10A2_UNORM = 24, + DXGI_FORMAT_R10G10B10A2_UINT = 25, + DXGI_FORMAT_R11G11B10_FLOAT = 26, + DXGI_FORMAT_R8G8B8A8_TYPELESS = 27, + DXGI_FORMAT_R8G8B8A8_UNORM = 28, + DXGI_FORMAT_R8G8B8A8_UNORM_SRGB = 29, + DXGI_FORMAT_R8G8B8A8_UINT = 30, + DXGI_FORMAT_R8G8B8A8_SNORM = 31, + DXGI_FORMAT_R8G8B8A8_SINT = 32, + DXGI_FORMAT_R16G16_TYPELESS = 33, + DXGI_FORMAT_R16G16_FLOAT = 34, + DXGI_FORMAT_R16G16_UNORM = 35, + DXGI_FORMAT_R16G16_UINT = 36, + DXGI_FORMAT_R16G16_SNORM = 37, + DXGI_FORMAT_R16G16_SINT = 38, + DXGI_FORMAT_R32_TYPELESS = 39, + DXGI_FORMAT_D32_FLOAT = 40, + DXGI_FORMAT_R32_FLOAT = 41, + DXGI_FORMAT_R32_UINT = 42, + DXGI_FORMAT_R32_SINT = 43, + DXGI_FORMAT_R24G8_TYPELESS = 44, + DXGI_FORMAT_D24_UNORM_S8_UINT = 45, + DXGI_FORMAT_R24_UNORM_X8_TYPELESS = 46, + DXGI_FORMAT_X24_TYPELESS_G8_UINT = 47, + DXGI_FORMAT_R8G8_TYPELESS = 48, + DXGI_FORMAT_R8G8_UNORM = 49, + DXGI_FORMAT_R8G8_UINT = 50, + DXGI_FORMAT_R8G8_SNORM = 51, + DXGI_FORMAT_R8G8_SINT = 52, + DXGI_FORMAT_R16_TYPELESS = 53, + DXGI_FORMAT_R16_FLOAT = 54, + DXGI_FORMAT_D16_UNORM = 55, + DXGI_FORMAT_R16_UNORM = 56, + DXGI_FORMAT_R16_UINT = 57, + DXGI_FORMAT_R16_SNORM = 58, + DXGI_FORMAT_R16_SINT = 59, + DXGI_FORMAT_R8_TYPELESS = 60, + DXGI_FORMAT_R8_UNORM = 61, + DXGI_FORMAT_R8_UINT = 62, + DXGI_FORMAT_R8_SNORM = 63, + DXGI_FORMAT_R8_SINT = 64, + DXGI_FORMAT_A8_UNORM = 65, + DXGI_FORMAT_R1_UNORM = 66, + DXGI_FORMAT_R9G9B9E5_SHAREDEXP = 67, + DXGI_FORMAT_R8G8_B8G8_UNORM = 68, + DXGI_FORMAT_G8R8_G8B8_UNORM = 69, + DXGI_FORMAT_BC1_TYPELESS = 70, + DXGI_FORMAT_BC1_UNORM = 71, + DXGI_FORMAT_BC1_UNORM_SRGB = 72, + DXGI_FORMAT_BC2_TYPELESS = 73, + DXGI_FORMAT_BC2_UNORM = 74, + DXGI_FORMAT_BC2_UNORM_SRGB = 75, + DXGI_FORMAT_BC3_TYPELESS = 76, + DXGI_FORMAT_BC3_UNORM = 77, + DXGI_FORMAT_BC3_UNORM_SRGB = 78, + DXGI_FORMAT_BC4_TYPELESS = 79, + DXGI_FORMAT_BC4_UNORM = 80, + DXGI_FORMAT_BC4_SNORM = 81, + DXGI_FORMAT_BC5_TYPELESS = 82, + DXGI_FORMAT_BC5_UNORM = 83, + DXGI_FORMAT_BC5_SNORM = 84, + DXGI_FORMAT_B5G6R5_UNORM = 85, + DXGI_FORMAT_B5G5R5A1_UNORM = 86, + DXGI_FORMAT_B8G8R8A8_UNORM = 87, + DXGI_FORMAT_B8G8R8X8_UNORM = 88, + DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM = 89, + DXGI_FORMAT_B8G8R8A8_TYPELESS = 90, + DXGI_FORMAT_B8G8R8A8_UNORM_SRGB = 91, + DXGI_FORMAT_B8G8R8X8_TYPELESS = 92, + DXGI_FORMAT_B8G8R8X8_UNORM_SRGB = 93, + DXGI_FORMAT_BC6H_TYPELESS = 94, + DXGI_FORMAT_BC6H_UF16 = 95, + DXGI_FORMAT_BC6H_SF16 = 96, + DXGI_FORMAT_BC7_TYPELESS = 97, + DXGI_FORMAT_BC7_UNORM = 98, + DXGI_FORMAT_BC7_UNORM_SRGB = 99, + DXGI_FORMAT_AYUV = 100, + DXGI_FORMAT_Y410 = 101, + DXGI_FORMAT_Y416 = 102, + DXGI_FORMAT_NV12 = 103, + DXGI_FORMAT_P010 = 104, + DXGI_FORMAT_P016 = 105, + DXGI_FORMAT_420_OPAQUE = 106, + DXGI_FORMAT_YUY2 = 107, + DXGI_FORMAT_Y210 = 108, + DXGI_FORMAT_Y216 = 109, + DXGI_FORMAT_NV11 = 110, + DXGI_FORMAT_AI44 = 111, + DXGI_FORMAT_IA44 = 112, + DXGI_FORMAT_P8 = 113, + DXGI_FORMAT_A8P8 = 114, + DXGI_FORMAT_B4G4R4A4_UNORM = 115, + DXGI_FORMAT_FORCE_UINT = 0xffffffffUL } DXGI_FORMAT; typedef struct { - DXGI_FORMAT dxgiFormat; - unsigned int resourceDimension; - unsigned int miscFlag; - unsigned int arraySize; - unsigned int reserved; + DXGI_FORMAT dxgiFormat; + unsigned int resourceDimension; + unsigned int miscFlag; + unsigned int arraySize; + unsigned int reserved; } dds_header_dx10_t; -#endif +#endif /* __DDS_H__ */ diff --git a/plug-ins/file-dds/ddsplugin.h b/plug-ins/file-dds/ddsplugin.h index ecb250b4b9..67478943b5 100644 --- a/plug-ins/file-dds/ddsplugin.h +++ b/plug-ins/file-dds/ddsplugin.h @@ -4,24 +4,22 @@ * Copyright (C) 2004-2012 Shawn Kirst , * with parts (C) 2003 Arne Reuter 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 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 3 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. + * 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. + * along with this program. If not, see . */ -#ifndef __DDSPLUGIN_H -#define __DDSPLUGIN_H +#ifndef __DDSPLUGIN_H__ +#define __DDSPLUGIN_H__ #define DDS_PLUGIN_VERSION_MAJOR 3 #define DDS_PLUGIN_VERSION_MINOR 9 @@ -75,4 +73,4 @@ extern GimpPDBStatusType write_dds (gchar *filename, #define DECODE_YCOCG_SCALED_PROC "color-decode-ycocg-scaled" #define DECODE_ALPHA_EXP_PROC "color-decode-alpha-exp" -#endif +#endif /* __DDSPLUGIN_H__ */ diff --git a/plug-ins/file-dds/ddsread.c b/plug-ins/file-dds/ddsread.c index d63640b18b..33e8041f97 100644 --- a/plug-ins/file-dds/ddsread.c +++ b/plug-ins/file-dds/ddsread.c @@ -95,7 +95,7 @@ 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; +static gboolean runme = FALSE; GimpPDBStatusType read_dds (gchar *filename, @@ -118,14 +118,14 @@ read_dds (gchar *filename, if (interactive_dds) { if (!load_dialog ()) - return (GIMP_PDB_CANCEL); + return GIMP_PDB_CANCEL; } fp = g_fopen (filename, "rb"); if (fp == 0) { g_message ("Error opening file.\n"); - return (GIMP_PDB_EXECUTION_ERROR); + return GIMP_PDB_EXECUTION_ERROR; } if (strrchr (filename, '/')) @@ -148,7 +148,7 @@ read_dds (gchar *filename, if (!setup_dxgi_format (&hdr, &dx10hdr)) { fclose (fp); - return (GIMP_PDB_EXECUTION_ERROR); + return GIMP_PDB_EXECUTION_ERROR; } } @@ -156,7 +156,7 @@ read_dds (gchar *filename, { fclose (fp); g_message ("Invalid DDS header!\n"); - return (GIMP_PDB_EXECUTION_ERROR); + return GIMP_PDB_EXECUTION_ERROR; } /* a lot of DDS images out there don't have this for some reason -_- */ @@ -279,7 +279,7 @@ read_dds (gchar *filename, { g_message ("Can't allocate new image.\n"); fclose (fp); - return (GIMP_PDB_EXECUTION_ERROR); + return GIMP_PDB_EXECUTION_ERROR; } gimp_image_set_filename (image, filename); @@ -292,7 +292,7 @@ read_dds (gchar *filename, g_message ("Error reading palette.\n"); fclose (fp); gimp_image_delete (image); - return (GIMP_PDB_EXECUTION_ERROR); + return GIMP_PDB_EXECUTION_ERROR; } for (i = j = 0; i < 768; i += 3, j += 4) { @@ -329,13 +329,13 @@ read_dds (gchar *filename, { fclose (fp); gimp_image_delete (image); - return (GIMP_PDB_EXECUTION_ERROR); + 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); + return GIMP_PDB_EXECUTION_ERROR; } } else if (hdr.caps.caps2 & DDSCAPS2_CUBEMAP) @@ -345,42 +345,42 @@ read_dds (gchar *filename, { fclose (fp); gimp_image_delete (image); - return (GIMP_PDB_EXECUTION_ERROR); + 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); + 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); + 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); + 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); + 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); + return GIMP_PDB_EXECUTION_ERROR; } } else if ((hdr.caps.caps2 & DDSCAPS2_VOLUME) && @@ -396,7 +396,7 @@ read_dds (gchar *filename, g_free (plane); fclose (fp); gimp_image_delete (image); - return (GIMP_PDB_EXECUTION_ERROR); + return GIMP_PDB_EXECUTION_ERROR; } g_free (plane); } @@ -417,7 +417,7 @@ read_dds (gchar *filename, g_free (plane); fclose (fp); gimp_image_delete (image); - return (GIMP_PDB_EXECUTION_ERROR); + return GIMP_PDB_EXECUTION_ERROR; } g_free (plane); } @@ -436,13 +436,13 @@ read_dds (gchar *filename, { fclose (fp); gimp_image_delete (image); - return (GIMP_PDB_EXECUTION_ERROR); + 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); + return GIMP_PDB_EXECUTION_ERROR; } g_free (elem); } @@ -462,7 +462,7 @@ read_dds (gchar *filename, if (layers == NULL || layer_count == 0) { g_message ("Oops! NULL image read! Please report this!"); - return (GIMP_PDB_EXECUTION_ERROR); + return GIMP_PDB_EXECUTION_ERROR; } gimp_image_set_active_layer (image, layers[0]); @@ -470,7 +470,7 @@ read_dds (gchar *filename, *imageID = image; - return (GIMP_PDB_SUCCESS); + return GIMP_PDB_SUCCESS; } static int @@ -482,7 +482,7 @@ read_header (dds_header_t *hdr, memset (hdr, 0, sizeof (dds_header_t)); if (fread (buf, 1, DDS_HEADERSIZE, fp) != DDS_HEADERSIZE) - return (0); + return 0; hdr->magic = GETL32(buf); @@ -519,19 +519,19 @@ read_header (dds_header_t *hdr, 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) +read_header_dx10 (dds_header_dx10_t *hdr, + FILE *fp) { char buf[DDS_HEADERSIZE_DX10]; memset (hdr, 0, sizeof (dds_header_dx10_t)); if (fread (buf, 1, DDS_HEADERSIZE_DX10, fp) != DDS_HEADERSIZE_DX10) - return (0); + return 0; hdr->dxgiFormat = GETL32(buf); hdr->resourceDimension = GETL32(buf + 4); @@ -539,7 +539,7 @@ read_header_dx10(dds_header_dx10_t *hdr, hdr->arraySize = GETL32(buf + 12); hdr->reserved = GETL32(buf + 16); - return (1); + return 1; } static int @@ -550,7 +550,7 @@ validate_header (dds_header_t *hdr) if (hdr->magic != FOURCC ('D','D','S',' ')) { g_message ("Invalid DDS file.\n"); - return (0); + return 0; } if ((hdr->flags & DDSD_PITCH) == (hdr->flags & DDSD_LINEARSIZE)) @@ -566,7 +566,7 @@ validate_header (dds_header_t *hdr) (hdr->pixelfmt.flags & DDPF_RGB)) { g_message ("Invalid pixel format.\n"); - return (0); + return 0; } */ fourcc = GETL32(hdr->pixelfmt.fourcc); @@ -592,7 +592,7 @@ validate_header (dds_header_t *hdr) hdr->pixelfmt.fourcc[2], hdr->pixelfmt.fourcc[3], GETL32(hdr->pixelfmt.fourcc)); - return (0); + return 0; } if (hdr->pixelfmt.flags & DDPF_RGB) @@ -603,7 +603,7 @@ validate_header (dds_header_t *hdr) (hdr->pixelfmt.bpp != 32)) { g_message ("Invalid BPP.\n"); - return (0); + return 0; } } else if (hdr->pixelfmt.flags & DDPF_LUMINANCE) @@ -612,7 +612,7 @@ validate_header (dds_header_t *hdr) (hdr->pixelfmt.bpp != 16)) { g_message ("Invalid BPP.\n"); - return (0); + return 0; } hdr->pixelfmt.flags |= DDPF_RGB; @@ -660,13 +660,13 @@ validate_header (dds_header_t *hdr) break; default: g_message ("Invalid pixel format."); - return (0); + return 0; } break; } } - return (1); + return 1; } /* @@ -691,7 +691,7 @@ setup_dxgi_format (dds_header_t *hdr, 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) && @@ -827,11 +827,11 @@ setup_dxgi_format (dds_header_t *hdr, break; default: /* unsupported DXGI format */ g_message ("Unsupported DXGI format (%d)", dx10hdr->dxgiFormat); - return (0); + return 0; } } - return (1); + return 1; } @@ -968,10 +968,11 @@ load_layer (FILE *fp, !fread (buf, size, 1, fp)) { g_message ("Unexpected EOF.\n"); - return (0); + return 0; } - if ((hdr->pixelfmt.flags & DDPF_RGB) || (hdr->pixelfmt.flags & DDPF_ALPHA)) + if ((hdr->pixelfmt.flags & DDPF_RGB) || + (hdr->pixelfmt.flags & DDPF_ALPHA)) { z = 0; for (y = 0, n = 0; y < height; ++y, ++n) @@ -988,7 +989,7 @@ load_layer (FILE *fp, !fread (buf, width * d->bpp, 1, fp)) { g_message ("Unexpected EOF.\n"); - return (0); + return 0; } if (!(hdr->flags & DDSD_LINEARSIZE)) z = 0; @@ -1104,7 +1105,7 @@ load_layer (FILE *fp, if (!(hdr->flags & DDSD_LINEARSIZE)) { g_message ("Image marked as compressed, but DDSD_LINEARSIZE is not set.\n"); - return (0); + return 0; } dst = g_malloc (width * height * d->gimp_bpp); @@ -1167,11 +1168,11 @@ load_layer (FILE *fp, } } - return (1); + return 1; } static int -load_mipmaps (FILE *fp, +load_mipmaps (FILE *fp, dds_header_t *hdr, dds_load_info_t *d, gint32 image, @@ -1189,10 +1190,11 @@ load_mipmaps (FILE *fp, for (level = 1; level < hdr->num_mipmaps; ++level) { if (!load_layer (fp, hdr, d, image, level, prefix, l, pixels, buf)) - return (0); + return 0; } } - return (1); + + return 1; } static int @@ -1206,8 +1208,9 @@ load_face (FILE *fp, 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)); + return 0; + + return load_mipmaps (fp, hdr, d, image, prefix, l, pixels, buf); } static unsigned char @@ -1220,17 +1223,22 @@ color_bits (unsigned int mask) if (mask & 1) ++i; mask >>= 1; } - return (i); + + return i; } static unsigned char color_shift (unsigned int mask) { - unsigned char i = 0; + guchar 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 @@ -1241,7 +1249,7 @@ load_dialog_response (GtkWidget *widget, switch (response_id) { case GTK_RESPONSE_OK: - runme = 1; + runme = TRUE; default: gtk_widget_destroy (widget); break; @@ -1298,9 +1306,9 @@ load_dialog (void) gtk_widget_show (dlg); - runme = 0; + runme = FALSE; gtk_main (); - return (runme); + return runme; } diff --git a/plug-ins/file-dds/ddswrite.c b/plug-ins/file-dds/ddswrite.c index 329690324b..a918a204ba 100644 --- a/plug-ins/file-dds/ddswrite.c +++ b/plug-ins/file-dds/ddswrite.c @@ -43,16 +43,6 @@ #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 int runme = 0; enum { @@ -61,35 +51,48 @@ enum COMBO_SENSITIVE }; + +static gint save_dialog (gint32 image_id, + gint32 drawable); +static void save_dialog_response (GtkWidget *widget, + gint response_id, + gpointer data); +static gboolean write_image (FILE *fp, + gint32 image_id, + gint32 drawable_id); + + +static gboolean runme = FALSE; + 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" - } + { + "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]; -static gint is_cubemap = 0; -static gint is_volume = 0; -static gint is_array = 0; -static gint is_mipmap_chain_valid = 0; +static gint cubemap_faces[6]; +static gboolean is_cubemap = FALSE; +static gboolean is_volume = FALSE; +static gboolean is_array = FALSE; +static gboolean is_mipmap_chain_valid = FALSE; static GtkWidget *compress_opt; static GtkWidget *format_opt; @@ -105,84 +108,84 @@ static GtkWidget *alpha_test_threshold_spin; typedef struct string_value_s { - int value; - char *string; + gint value; + gchar *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 @@ -197,35 +200,40 @@ static struct 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 + +static gboolean check_mipmaps (gint32 image_id, - int savetype) + gint 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; + gint *layers; + gint num_layers; + gint i, j, w, h, mipw, miph; + gint num_mipmaps; + gint num_surfaces = 0; + gint min_surfaces = 1; + gint max_surfaces = 1; + gboolean valid = TRUE; GimpImageType type; /* not handling volume maps for the moment... */ if (savetype == DDS_SAVE_VOLUMEMAP) - return (0); + return 0; if (savetype == DDS_SAVE_CUBEMAP) { @@ -250,7 +258,7 @@ check_mipmaps (gint32 image_id, for (i = 0; i < num_layers; ++i) { if (type != gimp_drawable_type (layers[i])) - return (0); + return 0; if ((gimp_drawable_width (layers[i]) == w) && (gimp_drawable_height (layers[i]) == h)) @@ -260,14 +268,14 @@ check_mipmaps (gint32 image_id, if ((num_surfaces < min_surfaces) || (num_surfaces > max_surfaces) || (num_layers != (num_surfaces * num_mipmaps))) - return (0); + 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; + valid = FALSE; break; } @@ -280,33 +288,36 @@ check_mipmaps (gint32 image_id, if ((gimp_drawable_width (layers[i + j]) != mipw) || (gimp_drawable_height (layers[i + j]) != miph)) { - valid = 0; + valid = FALSE; break; } } } - return (valid); + return valid; } -static int +static gboolean check_cubemap (gint32 image_id) { - gint *layers, num_layers; - int cubemap = 1, i, j, k, w, h; - char *layer_name; + gint *layers; + gint num_layers; + gboolean cubemap = TRUE; + gint i, j, k, w, h; + gchar *layer_name; GimpImageType type; layers = gimp_image_get_layers (image_id, &num_layers); - if (num_layers < 6) return (0); + if (num_layers < 6) + return FALSE; /* 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 FALSE; /* invalidate cubemap faces */ for (i = 0; i < 6; ++i) @@ -344,7 +355,7 @@ check_cubemap (gint32 image_id) { if (cubemap_faces[i] == -1) { - cubemap = 0; + cubemap = FALSE; break; } } @@ -356,7 +367,7 @@ check_cubemap (gint32 image_id) for (i = 1; i < 6 && cubemap; ++i) { if (gimp_drawable_type (cubemap_faces[i]) != type) - cubemap = 0; + cubemap = FALSE; } } } @@ -391,7 +402,7 @@ check_cubemap (gint32 image_id) { if (cubemap_faces[i] == -1) { - cubemap = 0; + cubemap = FALSE; break; } } @@ -406,7 +417,7 @@ check_cubemap (gint32 image_id) { if ((gimp_drawable_width (cubemap_faces[i]) != w) || (gimp_drawable_height (cubemap_faces[i]) != h)) - cubemap = 0; + cubemap = FALSE; } } @@ -417,26 +428,28 @@ check_cubemap (gint32 image_id) for (i = 1; i < 6 && cubemap; ++i) { if (gimp_drawable_type (cubemap_faces[i]) != type) - cubemap = 0; + cubemap = FALSE; } } } - return (cubemap); + return FALSE; } -static int +static gboolean check_volume (gint32 image_id) { - gint *layers, num_layers; - int volume = 0, i, w, h; + gint *layers; + gint num_layers; + gboolean volume = FALSE; + gint i, w, h; GimpImageType type; layers = gimp_image_get_layers (image_id, &num_layers); if (num_layers > 1) { - volume = 1; + volume = TRUE; /* make sure all layers are the same size */ w = gimp_drawable_width (layers[0]); @@ -446,7 +459,7 @@ check_volume (gint32 image_id) { if ((gimp_drawable_width (layers[i]) != w) || (gimp_drawable_height (layers[i]) != h)) - volume = 0; + volume = FALSE; } if (volume) @@ -456,29 +469,31 @@ check_volume (gint32 image_id) for (i = 1; i < num_layers && volume; ++i) { if (gimp_drawable_type (layers[i]) != type) - volume = 0; + volume = FALSE; } } } - return (volume); + return volume; } -static int +static gboolean check_array (gint32 image_id) { - gint *layers, num_layers; - int array = 0, i, w, h; + gint *layers; + gint num_layers; + gboolean array = FALSE; + gint i, w, h; GimpImageType type; if (check_mipmaps (image_id, DDS_SAVE_ARRAY)) - return (1); + return 1; layers = gimp_image_get_layers (image_id, &num_layers); if (num_layers > 1) { - array = 1; + array = TRUE; /* make sure all layers are the same size */ w = gimp_drawable_width (layers[0]); @@ -488,7 +503,7 @@ check_array (gint32 image_id) { if ((gimp_drawable_width (layers[i]) != w) || (gimp_drawable_height (layers[i]) != h)) - array = 0; + array = FALSE; } if (array) @@ -499,21 +514,23 @@ check_array (gint32 image_id) { if (gimp_drawable_type (layers[i]) != type) { - array = 0; + array = FALSE; break; } } } } - return (array); + return array; } static int get_array_size (gint32 image_id) { - gint *layers, num_layers; - int i, w, h, elements = 0; + gint *layers; + gint num_layers; + gint i, w, h; + gint elements = 0; layers = gimp_image_get_layers (image_id, &num_layers); @@ -522,11 +539,14 @@ get_array_size (gint32 image_id) for (i = 0; i < num_layers; ++i) { - if ((gimp_drawable_width (layers[i]) == w) && (gimp_drawable_height (layers[i]) == h)) - ++elements; + if ((gimp_drawable_width (layers[i]) == w) && + (gimp_drawable_height (layers[i]) == h)) + { + elements++; + } } - return (elements); + return elements; } GimpPDBStatusType @@ -535,51 +555,51 @@ write_dds (gchar *filename, gint32 drawable_id, gboolean interactive_dds) { - FILE *fp; + FILE *fp; gchar *tmp; - int rc = 0; + 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); + is_volume = check_volume (image_id); + is_array = check_array (image_id); if (interactive_dds) { - if (!is_mipmap_chain_valid && + 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); + if (! save_dialog (image_id, drawable_id)) + return GIMP_PDB_CANCEL; } else { - if (dds_write_vals.savetype == DDS_SAVE_CUBEMAP && !is_cubemap) + if (dds_write_vals.savetype == DDS_SAVE_CUBEMAP && ! is_cubemap) { g_message ("DDS: Cannot save image as cube map"); - return (GIMP_PDB_EXECUTION_ERROR); + return GIMP_PDB_EXECUTION_ERROR; } - if (dds_write_vals.savetype == DDS_SAVE_VOLUMEMAP && !is_volume) + if (dds_write_vals.savetype == DDS_SAVE_VOLUMEMAP && ! is_volume) { g_message ("DDS: Cannot save image as volume map"); - return (GIMP_PDB_EXECUTION_ERROR); + 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); + return GIMP_PDB_EXECUTION_ERROR; } if (dds_write_vals.mipmaps == DDS_MIPMAP_EXISTING && - !is_mipmap_chain_valid) + ! is_mipmap_chain_valid) { g_message ("DDS: Cannot save with existing mipmaps as the mipmap chain is incomplete"); - return (GIMP_PDB_EXECUTION_ERROR); + return GIMP_PDB_EXECUTION_ERROR; } } @@ -587,7 +607,7 @@ write_dds (gchar *filename, if (fp == 0) { g_message ("Error opening %s", filename); - return (GIMP_PDB_EXECUTION_ERROR); + return GIMP_PDB_EXECUTION_ERROR; } if (strrchr (filename, '/')) @@ -601,7 +621,7 @@ write_dds (gchar *filename, fclose (fp); - return (rc ? GIMP_PDB_SUCCESS : GIMP_PDB_EXECUTION_ERROR); + return rc ? GIMP_PDB_SUCCESS : GIMP_PDB_EXECUTION_ERROR; } static void @@ -1220,25 +1240,31 @@ write_volume_mipmaps (FILE *fp, g_free (dst); } -static int +static gboolean 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; + gint i, w, h; + gint bpp = 0; + gint fmtbpp = 0; + gint has_alpha = 0; + gint num_mipmaps; + guchar hdr[DDS_HEADERSIZE]; + guchar hdr10[DDS_HEADERSIZE_DX10]; + guint flags = 0, pflags = 0, caps = 0, caps2 = 0, size = 0; + guint rmask = 0, gmask = 0, bmask = 0, amask = 0; + guint fourcc = 0; DXGI_FORMAT dxgi_format = DXGI_FORMAT_UNKNOWN; - gint32 num_layers, *layers; + gint32 num_layers; + gint32 *layers; guchar *cmap; - gint colors; - unsigned char zero[4] = {0, 0, 0, 0}; - int is_dx10 = 0, array_size = 1; + gint colors; + guchar zero[4] = {0, 0, 0, 0}; + gint is_dx10 = 0; + gint array_size = 1; layers = gimp_image_get_layers (image_id, &num_layers); @@ -1377,7 +1403,9 @@ write_image (FILE *fp, num_mipmaps = get_num_mipmaps (w, h); } else - num_mipmaps = 1; + { + num_mipmaps = 1; + } if ((dds_write_vals.savetype == DDS_SAVE_CUBEMAP) && is_cubemap) { @@ -1423,29 +1451,34 @@ write_image (FILE *fp, pflags |= DDPF_LUMINANCE; } else if ((bpp == 2) && (basetype == GIMP_INDEXED)) - pflags |= DDPF_PALETTEINDEXED8; + { + pflags |= DDPF_PALETTEINDEXED8; + } else - pflags |= DDPF_RGB; + { + 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); + 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 - */ + * 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')); + 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')); + PUTL32 (hdr + 44, FOURCC ('Y','C','G','1')); } } else @@ -1459,10 +1492,12 @@ write_image (FILE *fp, 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: @@ -1471,15 +1506,18 @@ write_image (FILE *fp, 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; @@ -1489,11 +1527,13 @@ write_image (FILE *fp, if ((dds_write_vals.compression == DDS_COMPRESS_BC3N) || (dds_write_vals.compression == DDS_COMPRESS_RXGB)) - pflags |= DDPF_NORMAL; + { + pflags |= DDPF_NORMAL; + } - PUTL32(hdr + 8, flags); - PUTL32(hdr + 80, pflags); - PUTL32(hdr + 84, fourcc); + 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) || @@ -1502,24 +1542,24 @@ write_image (FILE *fp, else size *= 16; - PUTL32(hdr + 20, size); /* linear size */ + 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 - */ + * 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')); + 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')); + 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')); + PUTL32 (hdr + 44, FOURCC ('Y','C','G','2')); } } @@ -1531,15 +1571,15 @@ write_image (FILE *fp, { 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); - PUTL32(hdr10 + 8, 0); - PUTL32(hdr10 + 12, array_size); - PUTL32(hdr10 + 16, 0); + PUTL32 (hdr10 + 0, dxgi_format); + PUTL32 (hdr10 + 4, D3D10_RESOURCE_DIMENSION_TEXTURE2D); + PUTL32 (hdr10 + 8, 0); + PUTL32 (hdr10 + 12, array_size); + PUTL32 (hdr10 + 16, 0); /* update main header accordingly */ - PUTL32(hdr + 80, pflags | DDPF_FOURCC); - PUTL32(hdr + 84, FOURCC ('D','X','1','0')); + PUTL32 (hdr + 80, pflags | DDPF_FOURCC); + PUTL32 (hdr + 84, FOURCC ('D','X','1','0')); } fwrite (hdr, DDS_HEADERSIZE, 1, fp); @@ -1553,6 +1593,7 @@ write_image (FILE *fp, (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); @@ -1561,6 +1602,7 @@ write_image (FILE *fp, else fputc (255, fp); } + for (; i < 256; ++i) fwrite (zero, 1, 4, fp); } @@ -1590,8 +1632,12 @@ write_image (FILE *fp, { 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); + 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); } @@ -1603,7 +1649,7 @@ write_image (FILE *fp, gimp_progress_update (1.0); - return (1); + return TRUE; } static GtkWidget * @@ -1614,7 +1660,8 @@ string_value_combo_new (string_value_t *strings, GtkCellRenderer *renderer; GtkListStore *store; GtkTreeIter iter; - int i, active = 0; + gint i; + gint active = 0; store = gtk_list_store_new (3, G_TYPE_INT, G_TYPE_STRING, G_TYPE_BOOLEAN); for (i = 0; strings[i].string; ++i) @@ -1641,14 +1688,14 @@ string_value_combo_new (string_value_t *strings, g_object_unref (store); - return (opt); + return opt; } static void string_value_combo_selected (GtkWidget *widget, gpointer data) { - int value; + gint value; GtkTreeIter iter; GtkTreeModel *model; @@ -1661,12 +1708,12 @@ string_value_combo_selected (GtkWidget *widget, static void string_value_combo_set_item_sensitive (GtkWidget *widget, - int value, - int sensitive) + gint value, + gboolean sensitive) { GtkTreeIter iter; GtkTreeModel *model; - int val; + gint val; model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget)); gtk_tree_model_get_iter_first (model, &iter); @@ -1684,7 +1731,7 @@ string_value_combo_set_item_sensitive (GtkWidget *widget, static void string_value_combo_set_active (GtkWidget *widget, - int value) + gint value) { GtkTreeIter iter; GtkTreeModel *model; @@ -1711,7 +1758,8 @@ save_dialog_response (GtkWidget *widget, switch (response_id) { case GTK_RESPONSE_OK: - runme = 1; + runme = TRUE; + default: gtk_widget_destroy (widget); break; @@ -1724,13 +1772,17 @@ compression_selected (GtkWidget *widget, { 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); + &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 @@ -1748,6 +1800,7 @@ savetype_selected (GtkWidget *widget, 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), @@ -1764,21 +1817,31 @@ static void mipmaps_selected (GtkWidget *widget, gpointer data) { - GtkTreeIter iter; GtkTreeModel *model; + GtkTreeIter iter; + 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) && - 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 (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) && dds_write_vals.preserve_alpha_coverage); } @@ -1786,7 +1849,8 @@ static void toggle_clicked (GtkWidget *widget, gpointer data) { - int *flag = (int *)data; + gint *flag = (int *)data; + (*flag) = !(*flag); } @@ -1813,30 +1877,39 @@ 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) { - 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) { - 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) { - dds_write_vals.srgb = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); + dds_write_vals.srgb = + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); + gtk_widget_set_sensitive (gamma_spin, !dds_write_vals.srgb); } @@ -1844,22 +1917,27 @@ 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) { - 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) { - 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 @@ -1890,10 +1968,10 @@ save_dialog (gint32 image_id, g_signal_connect (dlg, "response", G_CALLBACK (save_dialog_response), - 0); + NULL); g_signal_connect (dlg, "destroy", G_CALLBACK (gtk_main_quit), - 0); + NULL); gtk_window_set_resizable (GTK_WINDOW (dlg), 0); @@ -1924,7 +2002,8 @@ save_dialog (gint32 image_id, (GtkAttachOptions)(GTK_EXPAND), 0, 0); g_signal_connect (opt, "changed", - G_CALLBACK (compression_selected), 0); + G_CALLBACK (compression_selected), + NULL); compress_opt = opt; @@ -1963,7 +2042,8 @@ save_dialog (gint32 image_id, (GtkAttachOptions)(GTK_EXPAND), 0, 0); g_signal_connect (opt, "changed", - G_CALLBACK (savetype_selected), &image_id); + 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); @@ -1984,7 +2064,8 @@ save_dialog (gint32 image_id, (GtkAttachOptions)(GTK_EXPAND), 0, 0); g_signal_connect (opt, "changed", - G_CALLBACK (mipmaps_selected), &image_id); + G_CALLBACK (mipmaps_selected), + &image_id); string_value_combo_set_item_sensitive (opt, DDS_MIPMAP_EXISTING, check_mipmaps (image_id, dds_write_vals.savetype)); @@ -1992,7 +2073,7 @@ save_dialog (gint32 image_id, mipmap_opt = opt; string_value_combo_set_item_sensitive (opt, DDS_MIPMAP_EXISTING, - !(is_volume || is_cubemap) && + ! (is_volume || is_cubemap) && is_mipmap_chain_valid); @@ -2002,18 +2083,22 @@ save_dialog (gint32 image_id, 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); + g_signal_connect (check, "clicked", + G_CALLBACK (transindex_clicked), + NULL); + spin = gimp_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_signal_connect (spin, "value_changed", + G_CALLBACK (transindex_changed), + NULL); + g_object_set_data (G_OBJECT (check), "spin", spin); if (basetype != GIMP_INDEXED) @@ -2028,7 +2113,8 @@ save_dialog (gint32 image_id, 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); + gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), + dds_write_vals.transindex); } if (is_volume && dds_write_vals.savetype == DDS_SAVE_VOLUMEMAP) @@ -2040,13 +2126,16 @@ save_dialog (gint32 image_id, expander = gtk_expander_new (_("Advanced Options")); 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_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); + g_signal_connect (expander, "activate", + G_CALLBACK (adv_opt_expanded), + NULL); + vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4); gtk_container_add (GTK_CONTAINER (expander), vbox2); @@ -2064,14 +2153,17 @@ save_dialog (gint32 image_id, 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_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); + g_signal_connect (check, "clicked", + G_CALLBACK (toggle_clicked), + &dds_write_vals.perceptual_metric); + pm_chk = check; frame = gtk_frame_new (_("Mipmaps")); @@ -2130,10 +2222,12 @@ save_dialog (gint32 image_id, 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); + gamma_chk = check; check = gtk_check_button_new_with_label (_("Use sRGB colorspace")); @@ -2141,10 +2235,12 @@ save_dialog (gint32 image_id, 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); + srgb_chk = check; label = gtk_label_new (_("Gamma:")); @@ -2159,10 +2255,12 @@ save_dialog (gint32 image_id, (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); + g_signal_connect (spin, "value_changed", + G_CALLBACK (gamma_changed), + NULL); + gamma_spin = spin; check = gtk_check_button_new_with_label (_("Preserve alpha test coverage")); @@ -2170,10 +2268,12 @@ save_dialog (gint32 image_id, 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); + alpha_coverage_chk = check; label = gtk_label_new (_("Alpha test threshold:")); @@ -2188,28 +2288,40 @@ save_dialog (gint32 image_id, (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); + g_signal_connect (spin, "value_changed", + G_CALLBACK (alpha_test_threshold_changed), + NULL); + 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 (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) && dds_write_vals.preserve_alpha_coverage); gtk_widget_show (dlg); - runme = 0; + runme = FALSE; gtk_main (); - return (runme); + return runme; } diff --git a/plug-ins/file-dds/dxt.c b/plug-ins/file-dds/dxt.c index cbd542685e..65bbc5bd31 100644 --- a/plug-ins/file-dds/dxt.c +++ b/plug-ins/file-dds/dxt.c @@ -1,24 +1,24 @@ /* - DDS GIMP plugin - - Copyright (C) 2004-2012 Shawn Kirst , - with parts (C) 2003 Arne Reuter 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 , + * with parts (C) 2003 Arne Reuter 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. + */ /* * Parts of this code have been generously released in the public domain @@ -57,161 +57,179 @@ static const vec4_t V4EPSILON = VEC4_CONST1(1e-04f); typedef struct { - unsigned int single; - unsigned int alphamask; - vec4_t points[16]; - vec4_t palette[4]; - vec4_t max; - vec4_t min; - vec4_t metric; + unsigned int single; + unsigned int alphamask; + vec4_t points[16]; + vec4_t palette[4]; + vec4_t max; + vec4_t min; + vec4_t metric; } dxtblock_t; /* extract 4x4 BGRA block */ -static void extract_block(const unsigned char *src, int x, int y, - int w, int h, unsigned char *block) +static void +extract_block (const unsigned char *src, + int x, + int y, + int w, + int h, + unsigned char *block) { - int i, j; - int bw = MIN(w - x, 4); - int bh = MIN(h - y, 4); - int bx, by; - const int rem[] = - { - 0, 0, 0, 0, - 0, 1, 0, 1, - 0, 1, 2, 0, - 0, 1, 2, 3 - }; + int i, j; + int bw = MIN(w - x, 4); + int bh = MIN(h - y, 4); + int bx, by; + const int rem[] = + { + 0, 0, 0, 0, + 0, 1, 0, 1, + 0, 1, 2, 0, + 0, 1, 2, 3 + }; - for(i = 0; i < 4; ++i) - { + for (i = 0; i < 4; ++i) + { by = rem[(bh - 1) * 4 + i] + y; - for(j = 0; j < 4; ++j) - { - bx = rem[(bw - 1) * 4 + j] + x; - block[(i * 4 * 4) + (j * 4) + 0] = + for (j = 0; j < 4; ++j) + { + bx = rem[(bw - 1) * 4 + j] + x; + block[(i * 4 * 4) + (j * 4) + 0] = src[(by * (w * 4)) + (bx * 4) + 0]; - block[(i * 4 * 4) + (j * 4) + 1] = + block[(i * 4 * 4) + (j * 4) + 1] = src[(by * (w * 4)) + (bx * 4) + 1]; - block[(i * 4 * 4) + (j * 4) + 2] = + block[(i * 4 * 4) + (j * 4) + 2] = src[(by * (w * 4)) + (bx * 4) + 2]; - block[(i * 4 * 4) + (j * 4) + 3] = + block[(i * 4 * 4) + (j * 4) + 3] = src[(by * (w * 4)) + (bx * 4) + 3]; - } - } + } + } } /* pack BGR8 to RGB565 */ -static inline unsigned short pack_rgb565(const unsigned char *c) +static inline unsigned short +pack_rgb565 (const unsigned char *c) { - return((mul8bit(c[2], 31) << 11) | - (mul8bit(c[1], 63) << 5) | - (mul8bit(c[0], 31) )); + return (mul8bit(c[2], 31) << 11) | + (mul8bit(c[1], 63) << 5) | + (mul8bit(c[0], 31) ); } /* unpack RGB565 to BGR */ -static void unpack_rgb565(unsigned char *dst, unsigned short v) +static void +unpack_rgb565 (unsigned char *dst, + unsigned short v) { - int r = (v >> 11) & 0x1f; - int g = (v >> 5) & 0x3f; - int b = (v ) & 0x1f; + int r = (v >> 11) & 0x1f; + int g = (v >> 5) & 0x3f; + int b = (v ) & 0x1f; - dst[0] = (b << 3) | (b >> 2); - dst[1] = (g << 2) | (g >> 4); - dst[2] = (r << 3) | (r >> 2); + dst[0] = (b << 3) | (b >> 2); + dst[1] = (g << 2) | (g >> 4); + dst[2] = (r << 3) | (r >> 2); } /* linear interpolation at 1/3 point between a and b */ -static void lerp_rgb13(unsigned char *dst, unsigned char *a, unsigned char *b) +static void +lerp_rgb13 (unsigned char *dst, + unsigned char *a, + unsigned char *b) { #if 0 - dst[0] = blerp(a[0], b[0], 0x55); - dst[1] = blerp(a[1], b[1], 0x55); - dst[2] = blerp(a[2], b[2], 0x55); + dst[0] = blerp(a[0], b[0], 0x55); + dst[1] = blerp(a[1], b[1], 0x55); + dst[2] = blerp(a[2], b[2], 0x55); #else - /* + /* * according to the S3TC/DX10 specs, this is the correct way to do the * interpolation (with no rounding bias) * * dst = (2 * a + b) / 3; */ - dst[0] = (2 * a[0] + b[0]) / 3; - dst[1] = (2 * a[1] + b[1]) / 3; - dst[2] = (2 * a[2] + b[2]) / 3; + dst[0] = (2 * a[0] + b[0]) / 3; + dst[1] = (2 * a[1] + b[1]) / 3; + dst[2] = (2 * a[2] + b[2]) / 3; #endif } -static void vec4_endpoints_to_565(int *start, int *end, const vec4_t a, const vec4_t b) +static void +vec4_endpoints_to_565 (int *start, + int *end, + const vec4_t a, + const vec4_t b) { - int c[8] __attribute__((aligned(16))); - vec4_t ta = a * V4GRID + V4HALF; - vec4_t tb = b * V4GRID + V4HALF; + int c[8] __attribute__((aligned(16))); + vec4_t ta = a * V4GRID + V4HALF; + vec4_t tb = b * V4GRID + V4HALF; #ifdef USE_SSE # ifdef __SSE2__ - const __m128i C565 = _mm_setr_epi16(31, 63, 31, 0, 31, 63, 31, 0); - __m128i ia = _mm_cvttps_epi32(ta); - __m128i ib = _mm_cvttps_epi32(tb); - __m128i zero = _mm_setzero_si128(); - __m128i words = _mm_packs_epi32(ia, ib); - words = _mm_min_epi16(C565, _mm_max_epi16(zero, words)); - *((__m128i *)&c[0]) = _mm_unpacklo_epi16(words, zero); - *((__m128i *)&c[4]) = _mm_unpackhi_epi16(words, zero); + const __m128i C565 = _mm_setr_epi16(31, 63, 31, 0, 31, 63, 31, 0); + __m128i ia = _mm_cvttps_epi32(ta); + __m128i ib = _mm_cvttps_epi32(tb); + __m128i zero = _mm_setzero_si128(); + __m128i words = _mm_packs_epi32(ia, ib); + words = _mm_min_epi16(C565, _mm_max_epi16(zero, words)); + *((__m128i *)&c[0]) = _mm_unpacklo_epi16(words, zero); + *((__m128i *)&c[4]) = _mm_unpackhi_epi16(words, zero); # else - const __m64 C565 = _mm_setr_pi16(31, 63, 31, 0); - __m64 lo, hi, c0, c1; - __m64 zero = _mm_setzero_si64(); - lo = _mm_cvttps_pi32(ta); - hi = _mm_cvttps_pi32(_mm_movehl_ps(ta, ta)); - c0 = _mm_packs_pi32(lo, hi); - lo = _mm_cvttps_pi32(tb); - hi = _mm_cvttps_pi32(_mm_movehl_ps(tb, tb)); - c1 = _mm_packs_pi32(lo, hi); - c0 = _mm_min_pi16(C565, _mm_max_pi16(zero, c0)); - c1 = _mm_min_pi16(C565, _mm_max_pi16(zero, c1)); - *((__m64 *)&c[0]) = _mm_unpacklo_pi16(c0, zero); - *((__m64 *)&c[2]) = _mm_unpackhi_pi16(c0, zero); - *((__m64 *)&c[4]) = _mm_unpacklo_pi16(c1, zero); - *((__m64 *)&c[6]) = _mm_unpackhi_pi16(c1, zero); - _mm_empty(); + const __m64 C565 = _mm_setr_pi16(31, 63, 31, 0); + __m64 lo, hi, c0, c1; + __m64 zero = _mm_setzero_si64(); + lo = _mm_cvttps_pi32(ta); + hi = _mm_cvttps_pi32(_mm_movehl_ps(ta, ta)); + c0 = _mm_packs_pi32(lo, hi); + lo = _mm_cvttps_pi32(tb); + hi = _mm_cvttps_pi32(_mm_movehl_ps(tb, tb)); + c1 = _mm_packs_pi32(lo, hi); + c0 = _mm_min_pi16(C565, _mm_max_pi16(zero, c0)); + c1 = _mm_min_pi16(C565, _mm_max_pi16(zero, c1)); + *((__m64 *)&c[0]) = _mm_unpacklo_pi16(c0, zero); + *((__m64 *)&c[2]) = _mm_unpackhi_pi16(c0, zero); + *((__m64 *)&c[4]) = _mm_unpacklo_pi16(c1, zero); + *((__m64 *)&c[6]) = _mm_unpackhi_pi16(c1, zero); + _mm_empty(); # endif #else - c[0] = (int)ta[0]; c[4] = (int)tb[0]; - c[1] = (int)ta[1]; c[5] = (int)tb[1]; - c[2] = (int)ta[2]; c[6] = (int)tb[2]; - c[0] = MIN(31, MAX(0, c[0])); - c[1] = MIN(63, MAX(0, c[1])); - c[2] = MIN(31, MAX(0, c[2])); - c[4] = MIN(31, MAX(0, c[4])); - c[5] = MIN(63, MAX(0, c[5])); - c[6] = MIN(31, MAX(0, c[6])); + c[0] = (int)ta[0]; c[4] = (int)tb[0]; + c[1] = (int)ta[1]; c[5] = (int)tb[1]; + c[2] = (int)ta[2]; c[6] = (int)tb[2]; + c[0] = MIN(31, MAX(0, c[0])); + c[1] = MIN(63, MAX(0, c[1])); + c[2] = MIN(31, MAX(0, c[2])); + c[4] = MIN(31, MAX(0, c[4])); + c[5] = MIN(63, MAX(0, c[5])); + c[6] = MIN(31, MAX(0, c[6])); #endif - *start = ((c[2] << 11) | (c[1] << 5) | c[0]); - *end = ((c[6] << 11) | (c[5] << 5) | c[4]); + *start = ((c[2] << 11) | (c[1] << 5) | c[0]); + *end = ((c[6] << 11) | (c[5] << 5) | c[4]); } -static void dxtblock_init(dxtblock_t *dxtb, const unsigned char *block, int flags) +static void +dxtblock_init (dxtblock_t *dxtb, + const unsigned char *block, + int flags) { - int i, c0, c; - int bc1 = (flags & DXT_BC1); - float x, y, z; - vec4_t min, max, center, t, cov, inset; + int i, c0, c; + int bc1 = (flags & DXT_BC1); + float x, y, z; + vec4_t min, max, center, t, cov, inset; - dxtb->single = 1; - dxtb->alphamask = 0; + dxtb->single = 1; + dxtb->alphamask = 0; - if(flags & DXT_PERCEPTUAL) - /* ITU-R BT.709 luma coefficents */ - dxtb->metric = vec4_set(0.2126f, 0.7152f, 0.0722f, 0.0f); - else - dxtb->metric = vec4_set(1.0f, 1.0f, 1.0f, 0.0f); + if(flags & DXT_PERCEPTUAL) + /* ITU-R BT.709 luma coefficents */ + dxtb->metric = vec4_set(0.2126f, 0.7152f, 0.0722f, 0.0f); + else + dxtb->metric = vec4_set(1.0f, 1.0f, 1.0f, 0.0f); - c0 = GETL24(block); + c0 = GETL24(block); - for(i = 0; i < 16; ++i) - { - if(bc1 && (block[4 * i + 3] < 128)) - dxtb->alphamask |= (3 << (2 * i)); + for (i = 0; i < 16; ++i) + { + if (bc1 && (block[4 * i + 3] < 128)) + dxtb->alphamask |= (3 << (2 * i)); x = (float)block[4 * i + 0] / 255.0f; y = (float)block[4 * i + 1] / 255.0f; @@ -221,111 +239,119 @@ static void dxtblock_init(dxtblock_t *dxtb, const unsigned char *block, int flag c = GETL24(&block[4 * i]); dxtb->single = dxtb->single && (c == c0); - } + } - // no need to continue if this is a single color block - if(dxtb->single) return; + // no need to continue if this is a single color block + if (dxtb->single) + return; - min = vec4_set1(1.0f); - max = vec4_zero(); + min = vec4_set1(1.0f); + max = vec4_zero(); - // get bounding box extents - for(i = 0; i < 16; ++i) - { + // get bounding box extents + for (i = 0; i < 16; ++i) + { min = vec4_min(min, dxtb->points[i]); max = vec4_max(max, dxtb->points[i]); - } + } - // select diagonal - center = (max + min) * V4HALF; - cov = vec4_zero(); - for(i = 0; i < 16; ++i) - { + // select diagonal + center = (max + min) * V4HALF; + cov = vec4_zero(); + for (i = 0; i < 16; ++i) + { t = dxtb->points[i] - center; cov += t * vec4_splatz(t); - } + } #ifdef USE_SSE - { - __m128 mask, tmp; - // get mask - mask = _mm_cmplt_ps(cov, _mm_setzero_ps()); - // clear high bits (z, w) - mask = _mm_movelh_ps(mask, _mm_setzero_ps()); - // mask and combine - tmp = _mm_or_ps(_mm_and_ps(mask, min), _mm_andnot_ps(mask, max)); - min = _mm_or_ps(_mm_and_ps(mask, max), _mm_andnot_ps(mask, min)); - max = tmp; - } + { + __m128 mask, tmp; + // get mask + mask = _mm_cmplt_ps(cov, _mm_setzero_ps()); + // clear high bits (z, w) + mask = _mm_movelh_ps(mask, _mm_setzero_ps()); + // mask and combine + tmp = _mm_or_ps(_mm_and_ps(mask, min), _mm_andnot_ps(mask, max)); + min = _mm_or_ps(_mm_and_ps(mask, max), _mm_andnot_ps(mask, min)); + max = tmp; + } #else - { - float x0, x1, y0, y1; - x0 = max[0]; - y0 = max[1]; - x1 = min[0]; - y1 = min[1]; + { + float x0, x1, y0, y1; + x0 = max[0]; + y0 = max[1]; + x1 = min[0]; + y1 = min[1]; - if(cov[0] < 0) SWAP(x0, x1); - if(cov[1] < 0) SWAP(y0, y1); + if (cov[0] < 0) SWAP(x0, x1); + if (cov[1] < 0) SWAP(y0, y1); - max[0] = x0; - max[1] = y0; - min[0] = x1; - min[1] = y1; - } + max[0] = x0; + max[1] = y0; + min[0] = x1; + min[1] = y1; + } #endif - // inset bounding box and clamp to [0,1] - inset = (max - min) * vec4_set1(1.0f / 16.0f) - vec4_set1((8.0f / 255.0f) / 16.0f); - max = vec4_min(V4ONE, vec4_max(V4ZERO, max - inset)); - min = vec4_min(V4ONE, vec4_max(V4ZERO, min + inset)); + // inset bounding box and clamp to [0,1] + inset = (max - min) * vec4_set1(1.0f / 16.0f) - vec4_set1((8.0f / 255.0f) / 16.0f); + max = vec4_min(V4ONE, vec4_max(V4ZERO, max - inset)); + min = vec4_min(V4ONE, vec4_max(V4ZERO, min + inset)); - // clamp to color space and save - dxtb->max = vec4_trunc(V4GRID * max + V4HALF) * V4GRIDRCP; - dxtb->min = vec4_trunc(V4GRID * min + V4HALF) * V4GRIDRCP; + // clamp to color space and save + dxtb->max = vec4_trunc(V4GRID * max + V4HALF) * V4GRIDRCP; + dxtb->min = vec4_trunc(V4GRID * min + V4HALF) * V4GRIDRCP; } -static void construct_palette3(dxtblock_t *dxtb) +static void +construct_palette3 (dxtblock_t *dxtb) { - dxtb->palette[0] = dxtb->max; - dxtb->palette[1] = dxtb->min; - dxtb->palette[2] = (dxtb->max * V4HALF) + (dxtb->min * V4HALF); - dxtb->palette[3] = vec4_zero(); + dxtb->palette[0] = dxtb->max; + dxtb->palette[1] = dxtb->min; + dxtb->palette[2] = (dxtb->max * V4HALF) + (dxtb->min * V4HALF); + dxtb->palette[3] = vec4_zero(); } -static void construct_palette4(dxtblock_t *dxtb) +static void +construct_palette4 (dxtblock_t *dxtb) { - dxtb->palette[0] = dxtb->max; - dxtb->palette[1] = dxtb->min; - dxtb->palette[2] = (dxtb->max * V4TWOTHIRDS) + (dxtb->min * V4ONETHIRD ); - dxtb->palette[3] = (dxtb->max * V4ONETHIRD ) + (dxtb->min * V4TWOTHIRDS); + dxtb->palette[0] = dxtb->max; + dxtb->palette[1] = dxtb->min; + dxtb->palette[2] = (dxtb->max * V4TWOTHIRDS) + (dxtb->min * V4ONETHIRD ); + dxtb->palette[3] = (dxtb->max * V4ONETHIRD ) + (dxtb->min * V4TWOTHIRDS); } /* * from nvidia-texture-tools; see LICENSE.nvtt for copyright information */ -static void optimize_endpoints3(dxtblock_t *dxtb, unsigned int indices, - vec4_t *max, vec4_t *min) +static void +optimize_endpoints3 (dxtblock_t *dxtb, + unsigned int indices, + vec4_t *max, + vec4_t *min) { - float alpha, beta; - vec4_t alpha2_sum, alphax_sum; - vec4_t beta2_sum, betax_sum; - vec4_t alphabeta_sum, a, b, factor; - int i, bits; + float alpha, beta; + vec4_t alpha2_sum, alphax_sum; + vec4_t beta2_sum, betax_sum; + vec4_t alphabeta_sum, a, b, factor; + int i, bits; - alpha2_sum = beta2_sum = alphabeta_sum = vec4_zero(); - alphax_sum = vec4_zero(); - betax_sum = vec4_zero(); + alpha2_sum = beta2_sum = alphabeta_sum = vec4_zero(); + alphax_sum = vec4_zero(); + betax_sum = vec4_zero(); - for(i = 0; i < 16; ++i) - { + for (i = 0; i < 16; ++i) + { bits = indices >> (2 * i); // skip alpha pixels - if((bits & 3) == 3) continue; + if ((bits & 3) == 3) + continue; beta = (float)(bits & 1); - if(bits & 2) beta = 0.5f; + if (bits & 2) + beta = 0.5f; alpha = 1.0f - beta; a = vec4_set1(alpha); @@ -335,47 +361,52 @@ static void optimize_endpoints3(dxtblock_t *dxtb, unsigned int indices, alphabeta_sum += a * b; alphax_sum += dxtb->points[i] * a; betax_sum += dxtb->points[i] * b; - } + } - factor = alpha2_sum * beta2_sum - alphabeta_sum * alphabeta_sum; - if(vec4_cmplt(factor, V4EPSILON)) return; - factor = vec4_rcp(factor); + factor = alpha2_sum * beta2_sum - alphabeta_sum * alphabeta_sum; + if (vec4_cmplt(factor, V4EPSILON)) + return; + factor = vec4_rcp(factor); - a = (alphax_sum * beta2_sum - betax_sum * alphabeta_sum) * factor; - b = (betax_sum * alpha2_sum - alphax_sum * alphabeta_sum) * factor; + a = (alphax_sum * beta2_sum - betax_sum * alphabeta_sum) * factor; + b = (betax_sum * alpha2_sum - alphax_sum * alphabeta_sum) * factor; - // clamp to the color space - a = vec4_min(V4ONE, vec4_max(V4ZERO, a)); - b = vec4_min(V4ONE, vec4_max(V4ZERO, b)); - a = vec4_trunc(V4GRID * a + V4HALF) * V4GRIDRCP; - b = vec4_trunc(V4GRID * b + V4HALF) * V4GRIDRCP; + // clamp to the color space + a = vec4_min(V4ONE, vec4_max(V4ZERO, a)); + b = vec4_min(V4ONE, vec4_max(V4ZERO, b)); + a = vec4_trunc(V4GRID * a + V4HALF) * V4GRIDRCP; + b = vec4_trunc(V4GRID * b + V4HALF) * V4GRIDRCP; - *max = a; - *min = b; + *max = a; + *min = b; } /* * from nvidia-texture-tools; see LICENSE.nvtt for copyright information */ -static void optimize_endpoints4(dxtblock_t *dxtb, unsigned int indices, - vec4_t *max, vec4_t *min) +static void +optimize_endpoints4 (dxtblock_t *dxtb, + unsigned int indices, + vec4_t *max, + vec4_t *min) { - float alpha, beta; - vec4_t alpha2_sum, alphax_sum; - vec4_t beta2_sum, betax_sum; - vec4_t alphabeta_sum, a, b, factor; - int i, bits; + float alpha, beta; + vec4_t alpha2_sum, alphax_sum; + vec4_t beta2_sum, betax_sum; + vec4_t alphabeta_sum, a, b, factor; + int i, bits; - alpha2_sum = beta2_sum = alphabeta_sum = vec4_zero(); - alphax_sum = vec4_zero(); - betax_sum = vec4_zero(); + alpha2_sum = beta2_sum = alphabeta_sum = vec4_zero(); + alphax_sum = vec4_zero(); + betax_sum = vec4_zero(); - for(i = 0; i < 16; ++i) - { + for (i = 0; i < 16; ++i) + { bits = indices >> (2 * i); beta = (float)(bits & 1); - if(bits & 2) beta = (1.0f + beta) / 3.0f; + if (bits & 2) + beta = (1.0f + beta) / 3.0f; alpha = 1.0f - beta; a = vec4_set1(alpha); @@ -385,46 +416,48 @@ static void optimize_endpoints4(dxtblock_t *dxtb, unsigned int indices, alphabeta_sum += a * b; alphax_sum += dxtb->points[i] * a; betax_sum += dxtb->points[i] * b; - } + } - factor = alpha2_sum * beta2_sum - alphabeta_sum * alphabeta_sum; - if(vec4_cmplt(factor, V4EPSILON)) return; - factor = vec4_rcp(factor); + factor = alpha2_sum * beta2_sum - alphabeta_sum * alphabeta_sum; + if (vec4_cmplt(factor, V4EPSILON)) + return; + factor = vec4_rcp(factor); - a = (alphax_sum * beta2_sum - betax_sum * alphabeta_sum) * factor; - b = (betax_sum * alpha2_sum - alphax_sum * alphabeta_sum) * factor; + a = (alphax_sum * beta2_sum - betax_sum * alphabeta_sum) * factor; + b = (betax_sum * alpha2_sum - alphax_sum * alphabeta_sum) * factor; - // clamp to the color space - a = vec4_min(V4ONE, vec4_max(V4ZERO, a)); - b = vec4_min(V4ONE, vec4_max(V4ZERO, b)); - a = vec4_trunc(V4GRID * a + V4HALF) * V4GRIDRCP; - b = vec4_trunc(V4GRID * b + V4HALF) * V4GRIDRCP; + // clamp to the color space + a = vec4_min(V4ONE, vec4_max(V4ZERO, a)); + b = vec4_min(V4ONE, vec4_max(V4ZERO, b)); + a = vec4_trunc(V4GRID * a + V4HALF) * V4GRIDRCP; + b = vec4_trunc(V4GRID * b + V4HALF) * V4GRIDRCP; - *max = a; - *min = b; + *max = a; + *min = b; } -static unsigned int match_colors3(dxtblock_t *dxtb) +static unsigned int +match_colors3 (dxtblock_t *dxtb) { - int i, idx; - unsigned int indices = 0; - vec4_t t0, t1, t2; + int i, idx; + unsigned int indices = 0; + vec4_t t0, t1, t2; #ifdef USE_SSE - vec4_t d, bits, zero = _mm_setzero_ps(); - int mask; + vec4_t d, bits, zero = _mm_setzero_ps(); + int mask; #else - float d0, d1, d2; + float d0, d1, d2; #endif - // match each point to the closest color - for(i = 0; i < 16; ++i) - { + // match each point to the closest color + for (i = 0; i < 16; ++i) + { // skip alpha pixels - if(((dxtb->alphamask >> (2 * i)) & 3) == 3) - { - indices |= (3 << (2 * i)); - continue; - } + if (((dxtb->alphamask >> (2 * i)) & 3) == 3) + { + indices |= (3 << (2 * i)); + continue; + } t0 = (dxtb->points[i] - dxtb->palette[0]) * dxtb->metric; t1 = (dxtb->points[i] - dxtb->palette[1]) * dxtb->metric; @@ -444,36 +477,37 @@ static unsigned int match_colors3(dxtblock_t *dxtb) d1 = vec4_dot(t1, t1); d2 = vec4_dot(t2, t2); - if((d0 < d1) && (d0 < d2)) - idx = 0; - else if(d1 < d2) - idx = 1; + if ((d0 < d1) && (d0 < d2)) + idx = 0; + else if (d1 < d2) + idx = 1; else - idx = 2; + idx = 2; #endif indices |= (idx << (2 * i)); - } + } - return(indices); + return indices; } -static unsigned int match_colors4(dxtblock_t *dxtb) +static unsigned int +match_colors4 (dxtblock_t *dxtb) { - int i; - unsigned int idx, indices = 0; - unsigned int b0, b1, b2, b3, b4; - unsigned int x0, x1, x2; - vec4_t t0, t1, t2, t3; + int i; + unsigned int idx, indices = 0; + unsigned int b0, b1, b2, b3, b4; + unsigned int x0, x1, x2; + vec4_t t0, t1, t2, t3; #ifdef USE_SSE - vec4_t d; + vec4_t d; #else - float d[4]; + float d[4]; #endif - // match each point to the closest color - for(i = 0; i < 16; ++i) - { + // match each point to the closest color + for (i = 0; i < 16; ++i) + { t0 = (dxtb->points[i] - dxtb->palette[0]) * dxtb->metric; t1 = (dxtb->points[i] - dxtb->palette[1]) * dxtb->metric; t2 = (dxtb->points[i] - dxtb->palette[2]) * dxtb->metric; @@ -502,42 +536,47 @@ static unsigned int match_colors4(dxtblock_t *dxtb) idx = x2 | ((x0 | x1) << 1); indices |= (idx << (2 * i)); - } + } - return(indices); + return indices; } -static float compute_error3(dxtblock_t *dxtb, unsigned int indices) +static float +compute_error3 (dxtblock_t *dxtb, + unsigned int indices) { - int i, idx; - float error = 0; - vec4_t t; + int i, idx; + float error = 0; + vec4_t t; - // compute error - for(i = 0; i < 16; ++i) - { + // compute error + for (i = 0; i < 16; ++i) + { idx = (indices >> (2 * i)) & 3; // skip alpha pixels - if(idx == 3) continue; + if(idx == 3) + continue; t = (dxtb->points[i] - dxtb->palette[idx]) * dxtb->metric; error += vec4_dot(t, t); - } + } - return(error); + return error; } -static float compute_error4(dxtblock_t *dxtb, unsigned int indices) +static float +compute_error4 (dxtblock_t *dxtb, + unsigned int indices) { - int i, idx; - float error = 0; + int i, idx; + float error = 0; #ifdef USE_SSE - vec4_t a0, a1, a2, a3; - vec4_t b0, b1, b2, b3; - vec4_t d; + vec4_t a0, a1, a2, a3; + vec4_t b0, b1, b2, b3; + vec4_t d; - for(i = 0; i < 4; ++i) - { + for (i = 0; i < 4; ++i) + { idx = indices >> (8 * i); a0 = dxtb->points[4 * i + 0]; a1 = dxtb->points[4 * i + 1]; @@ -554,36 +593,38 @@ static float compute_error4(dxtblock_t *dxtb, unsigned int indices) _MM_TRANSPOSE4_PS(a0, a1, a2, a3); d = a0 * a0 + a1 * a1 + a2 * a2; error += vec4_accum(d); - } + } #else - vec4_t t; + vec4_t t; - // compute error - for(i = 0; i < 16; ++i) - { + // compute error + for (i = 0; i < 16; ++i) + { idx = (indices >> (2 * i)) & 3; t = (dxtb->points[i] - dxtb->palette[idx]) * dxtb->metric; error += vec4_dot(t, t); - } + } #endif - return(error); + + return error; } -static unsigned int compress3(dxtblock_t *dxtb) +static unsigned int +compress3 (dxtblock_t *dxtb) { - const int MAX_ITERATIONS = 8; - int i; - unsigned int indices, bestindices; - float error, besterror = FLT_MAX; - vec4_t oldmax, oldmin; + const int MAX_ITERATIONS = 8; + int i; + unsigned int indices, bestindices; + float error, besterror = FLT_MAX; + vec4_t oldmax, oldmin; - construct_palette3(dxtb); + construct_palette3(dxtb); - indices = match_colors3(dxtb); - bestindices = indices; + indices = match_colors3(dxtb); + bestindices = indices; - for(i = 0; i < MAX_ITERATIONS; ++i) - { + for (i = 0; i < MAX_ITERATIONS; ++i) + { oldmax = dxtb->max; oldmin = dxtb->min; @@ -592,37 +633,38 @@ static unsigned int compress3(dxtblock_t *dxtb) indices = match_colors3(dxtb); error = compute_error3(dxtb, indices); - if(error < besterror) - { - besterror = error; - bestindices = indices; - } + if (error < besterror) + { + besterror = error; + bestindices = indices; + } else - { - dxtb->max = oldmax; - dxtb->min = oldmin; - break; - } - } + { + dxtb->max = oldmax; + dxtb->min = oldmin; + break; + } + } - return(bestindices); + return bestindices; } -static unsigned int compress4(dxtblock_t *dxtb) +static unsigned int +compress4 (dxtblock_t *dxtb) { - const int MAX_ITERATIONS = 8; - int i; - unsigned int indices, bestindices; - float error, besterror = FLT_MAX; - vec4_t oldmax, oldmin; + const int MAX_ITERATIONS = 8; + int i; + unsigned int indices, bestindices; + float error, besterror = FLT_MAX; + vec4_t oldmax, oldmin; - construct_palette4(dxtb); + construct_palette4(dxtb); - indices = match_colors4(dxtb); - bestindices = indices; + indices = match_colors4(dxtb); + bestindices = indices; - for(i = 0; i < MAX_ITERATIONS; ++i) - { + for (i = 0; i < MAX_ITERATIONS; ++i) + { oldmax = dxtb->max; oldmin = dxtb->min; @@ -631,32 +673,35 @@ static unsigned int compress4(dxtblock_t *dxtb) indices = match_colors4(dxtb); error = compute_error4(dxtb, indices); - if(error < besterror) - { - besterror = error; - bestindices = indices; - } + if (error < besterror) + { + besterror = error; + bestindices = indices; + } else - { - dxtb->max = oldmax; - dxtb->min = oldmin; - break; - } - } + { + dxtb->max = oldmax; + dxtb->min = oldmin; + break; + } + } - return(bestindices); + return bestindices; } -static void encode_color_block(unsigned char *dst, unsigned char *block, int flags) +static void +encode_color_block (unsigned char *dst, + unsigned char *block, + int flags) { - dxtblock_t dxtb; - int max16, min16; - unsigned int indices, mask; + dxtblock_t dxtb; + int max16, min16; + unsigned int indices, mask; - dxtblock_init(&dxtb, block, flags); + dxtblock_init(&dxtb, block, flags); - if(dxtb.single) // single color block - { + if (dxtb.single) // single color block + { max16 = (omatch5[block[2]][0] << 11) | (omatch6[block[1]][0] << 5) | (omatch5[block[0]][0] ); @@ -666,190 +711,199 @@ static void encode_color_block(unsigned char *dst, unsigned char *block, int fla indices = 0xaaaaaaaa; // 101010... - if((flags & DXT_BC1) && dxtb.alphamask) - { - // DXT1 compression, non-opaque block. Add alpha indices. - indices |= dxtb.alphamask; - if(max16 > min16) + if ((flags & DXT_BC1) && dxtb.alphamask) + { + // DXT1 compression, non-opaque block. Add alpha indices. + indices |= dxtb.alphamask; + if (max16 > min16) SWAP(max16, min16); - } - else if(max16 < min16) - { - SWAP(max16, min16); - indices ^= 0x55555555; // 010101... - } - } - else if((flags & DXT_BC1) && dxtb.alphamask) // DXT1 compression, non-opaque block - { + } + else if (max16 < min16) + { + SWAP(max16, min16); + indices ^= 0x55555555; // 010101... + } + } + else if ((flags & DXT_BC1) && dxtb.alphamask) // DXT1 compression, non-opaque block + { indices = compress3(&dxtb); vec4_endpoints_to_565(&max16, &min16, dxtb.max, dxtb.min); - if(max16 > min16) - { - SWAP(max16, min16); - // remap indices 0 -> 1, 1 -> 0 - mask = indices & 0xaaaaaaaa; - mask = mask | (mask >> 1); - indices = (indices & mask) | ((indices ^ 0x55555555) & ~mask); - } - } - else - { + if (max16 > min16) + { + SWAP(max16, min16); + // remap indices 0 -> 1, 1 -> 0 + mask = indices & 0xaaaaaaaa; + mask = mask | (mask >> 1); + indices = (indices & mask) | ((indices ^ 0x55555555) & ~mask); + } + } + else + { indices = compress4(&dxtb); vec4_endpoints_to_565(&max16, &min16, dxtb.max, dxtb.min); - if(max16 < min16) - { - SWAP(max16, min16); - indices ^= 0x55555555; // 010101... - } - } + if (max16 < min16) + { + SWAP(max16, min16); + indices ^= 0x55555555; // 010101... + } + } - PUTL16(dst + 0, max16); - PUTL16(dst + 2, min16); - PUTL32(dst + 4, indices); + PUTL16(dst + 0, max16); + PUTL16(dst + 2, min16); + PUTL32(dst + 4, indices); } -static void get_min_max_YCoCg(const unsigned char *block, - unsigned char *mincolor, unsigned char *maxcolor) +static void +get_min_max_YCoCg (const unsigned char *block, + unsigned char *mincolor, + unsigned char *maxcolor) { - int i; + int i; - mincolor[2] = mincolor[1] = 255; - maxcolor[2] = maxcolor[1] = 0; + mincolor[2] = mincolor[1] = 255; + maxcolor[2] = maxcolor[1] = 0; - for(i = 0; i < 16; ++i) - { - if(block[4 * i + 2] < mincolor[2]) mincolor[2] = block[4 * i + 2]; - if(block[4 * i + 1] < mincolor[1]) mincolor[1] = block[4 * i + 1]; - if(block[4 * i + 2] > maxcolor[2]) maxcolor[2] = block[4 * i + 2]; - if(block[4 * i + 1] > maxcolor[1]) maxcolor[1] = block[4 * i + 1]; - } + for (i = 0; i < 16; ++i) + { + if (block[4 * i + 2] < mincolor[2]) mincolor[2] = block[4 * i + 2]; + if (block[4 * i + 1] < mincolor[1]) mincolor[1] = block[4 * i + 1]; + if (block[4 * i + 2] > maxcolor[2]) maxcolor[2] = block[4 * i + 2]; + if (block[4 * i + 1] > maxcolor[1]) maxcolor[1] = block[4 * i + 1]; + } } -static void scale_YCoCg(unsigned char *block, - unsigned char *mincolor, unsigned char *maxcolor) +static void +scale_YCoCg (unsigned char *block, + unsigned char *mincolor, + unsigned char *maxcolor) { - const int s0 = 128 / 2 - 1; - const int s1 = 128 / 4 - 1; - int m0, m1, m2, m3; - int mask0, mask1, scale; - int i; + const int s0 = 128 / 2 - 1; + const int s1 = 128 / 4 - 1; + int m0, m1, m2, m3; + int mask0, mask1, scale; + int i; - m0 = abs(mincolor[2] - 128); - m1 = abs(mincolor[1] - 128); - m2 = abs(maxcolor[2] - 128); - m3 = abs(maxcolor[1] - 128); + m0 = abs(mincolor[2] - 128); + m1 = abs(mincolor[1] - 128); + m2 = abs(maxcolor[2] - 128); + m3 = abs(maxcolor[1] - 128); - if(m1 > m0) m0 = m1; - if(m3 > m2) m2 = m3; - if(m2 > m0) m0 = m2; + if (m1 > m0) m0 = m1; + if (m3 > m2) m2 = m3; + if (m2 > m0) m0 = m2; - mask0 = -(m0 <= s0); - mask1 = -(m0 <= s1); - scale = 1 + (1 & mask0) + (2 & mask1); + mask0 = -(m0 <= s0); + mask1 = -(m0 <= s1); + scale = 1 + (1 & mask0) + (2 & mask1); - mincolor[2] = (mincolor[2] - 128) * scale + 128; - mincolor[1] = (mincolor[1] - 128) * scale + 128; - mincolor[0] = (scale - 1) << 3; + mincolor[2] = (mincolor[2] - 128) * scale + 128; + mincolor[1] = (mincolor[1] - 128) * scale + 128; + mincolor[0] = (scale - 1) << 3; - maxcolor[2] = (maxcolor[2] - 128) * scale + 128; - maxcolor[1] = (maxcolor[1] - 128) * scale + 128; - maxcolor[0] = (scale - 1) << 3; + maxcolor[2] = (maxcolor[2] - 128) * scale + 128; + maxcolor[1] = (maxcolor[1] - 128) * scale + 128; + maxcolor[0] = (scale - 1) << 3; - for(i = 0; i < 16; ++i) - { + for (i = 0; i < 16; ++i) + { block[i * 4 + 2] = (block[i * 4 + 2] - 128) * scale + 128; block[i * 4 + 1] = (block[i * 4 + 1] - 128) * scale + 128; - } + } } #define INSET_SHIFT 4 -static void inset_bbox_YCoCg(unsigned char *mincolor, unsigned char *maxcolor) +static void +inset_bbox_YCoCg (unsigned char *mincolor, + unsigned char *maxcolor) { - int inset[4], mini[4], maxi[4]; + int inset[4], mini[4], maxi[4]; - inset[2] = (maxcolor[2] - mincolor[2]) - ((1 << (INSET_SHIFT - 1)) - 1); - inset[1] = (maxcolor[1] - mincolor[1]) - ((1 << (INSET_SHIFT - 1)) - 1); + inset[2] = (maxcolor[2] - mincolor[2]) - ((1 << (INSET_SHIFT - 1)) - 1); + inset[1] = (maxcolor[1] - mincolor[1]) - ((1 << (INSET_SHIFT - 1)) - 1); - mini[2] = ((mincolor[2] << INSET_SHIFT) + inset[2]) >> INSET_SHIFT; - mini[1] = ((mincolor[1] << INSET_SHIFT) + inset[1]) >> INSET_SHIFT; + mini[2] = ((mincolor[2] << INSET_SHIFT) + inset[2]) >> INSET_SHIFT; + mini[1] = ((mincolor[1] << INSET_SHIFT) + inset[1]) >> INSET_SHIFT; - maxi[2] = ((maxcolor[2] << INSET_SHIFT) - inset[2]) >> INSET_SHIFT; - maxi[1] = ((maxcolor[1] << INSET_SHIFT) - inset[1]) >> INSET_SHIFT; + maxi[2] = ((maxcolor[2] << INSET_SHIFT) - inset[2]) >> INSET_SHIFT; + maxi[1] = ((maxcolor[1] << INSET_SHIFT) - inset[1]) >> INSET_SHIFT; - mini[2] = (mini[2] >= 0) ? mini[2] : 0; - mini[1] = (mini[1] >= 0) ? mini[1] : 0; + mini[2] = (mini[2] >= 0) ? mini[2] : 0; + mini[1] = (mini[1] >= 0) ? mini[1] : 0; - maxi[2] = (maxi[2] <= 255) ? maxi[2] : 255; - maxi[1] = (maxi[1] <= 255) ? maxi[1] : 255; + maxi[2] = (maxi[2] <= 255) ? maxi[2] : 255; + maxi[1] = (maxi[1] <= 255) ? maxi[1] : 255; - mincolor[2] = (mini[2] & 0xf8) | (mini[2] >> 5); - mincolor[1] = (mini[1] & 0xfc) | (mini[1] >> 6); + mincolor[2] = (mini[2] & 0xf8) | (mini[2] >> 5); + mincolor[1] = (mini[1] & 0xfc) | (mini[1] >> 6); - maxcolor[2] = (maxi[2] & 0xf8) | (maxi[2] >> 5); - maxcolor[1] = (maxi[1] & 0xfc) | (maxi[1] >> 6); + maxcolor[2] = (maxi[2] & 0xf8) | (maxi[2] >> 5); + maxcolor[1] = (maxi[1] & 0xfc) | (maxi[1] >> 6); } -static void select_diagonal_YCoCg(const unsigned char *block, - unsigned char *mincolor, - unsigned char *maxcolor) +static void +select_diagonal_YCoCg (const unsigned char *block, + unsigned char *mincolor, + unsigned char *maxcolor) { - unsigned char mid0, mid1, side, mask, b0, b1, c0, c1; - int i; + unsigned char mid0, mid1, side, mask, b0, b1, c0, c1; + int i; - mid0 = ((int)mincolor[2] + maxcolor[2] + 1) >> 1; - mid1 = ((int)mincolor[1] + maxcolor[1] + 1) >> 1; + mid0 = ((int)mincolor[2] + maxcolor[2] + 1) >> 1; + mid1 = ((int)mincolor[1] + maxcolor[1] + 1) >> 1; - side = 0; - for(i = 0; i < 16; ++i) - { + side = 0; + for (i = 0; i < 16; ++i) + { b0 = block[i * 4 + 2] >= mid0; b1 = block[i * 4 + 1] >= mid1; side += (b0 ^ b1); - } + } - mask = -(side > 8); - mask &= -(mincolor[2] != maxcolor[2]); + mask = -(side > 8); + mask &= -(mincolor[2] != maxcolor[2]); - c0 = mincolor[1]; - c1 = maxcolor[1]; + c0 = mincolor[1]; + c1 = maxcolor[1]; - c0 ^= c1; - c1 ^= c0 & mask; - c0 ^= c1; + c0 ^= c1; + c1 ^= c0 & mask; + c0 ^= c1; - mincolor[1] = c0; - maxcolor[1] = c1; + mincolor[1] = c0; + maxcolor[1] = c1; } -static void encode_YCoCg_block(unsigned char *dst, unsigned char *block) +static void +encode_YCoCg_block (unsigned char *dst, + unsigned char *block) { - unsigned char colors[4][3], *maxcolor, *mincolor; - unsigned int mask; - int c0, c1, d0, d1, d2, d3; - int b0, b1, b2, b3, b4; - int x0, x1, x2; - int i, idx; + unsigned char colors[4][3], *maxcolor, *mincolor; + unsigned int mask; + int c0, c1, d0, d1, d2, d3; + int b0, b1, b2, b3, b4; + int x0, x1, x2; + int i, idx; - maxcolor = &colors[0][0]; - mincolor = &colors[1][0]; + maxcolor = &colors[0][0]; + mincolor = &colors[1][0]; - get_min_max_YCoCg(block, mincolor, maxcolor); - scale_YCoCg(block, mincolor, maxcolor); - inset_bbox_YCoCg(mincolor, maxcolor); - select_diagonal_YCoCg(block, mincolor, maxcolor); + get_min_max_YCoCg(block, mincolor, maxcolor); + scale_YCoCg(block, mincolor, maxcolor); + inset_bbox_YCoCg(mincolor, maxcolor); + select_diagonal_YCoCg(block, mincolor, maxcolor); - lerp_rgb13(&colors[2][0], maxcolor, mincolor); - lerp_rgb13(&colors[3][0], mincolor, maxcolor); + lerp_rgb13(&colors[2][0], maxcolor, mincolor); + lerp_rgb13(&colors[3][0], mincolor, maxcolor); - mask = 0; + mask = 0; - for(i = 0; i < 16; ++i) - { + for (i = 0; i < 16; ++i) + { c0 = block[4 * i + 2]; c1 = block[4 * i + 1]; @@ -871,72 +925,75 @@ static void encode_YCoCg_block(unsigned char *dst, unsigned char *block) idx = (x2 | ((x0 | x1) << 1)); mask |= idx << (2 * i); - } + } - PUTL16(dst + 0, pack_rgb565(maxcolor)); - PUTL16(dst + 2, pack_rgb565(mincolor)); - PUTL32(dst + 4, mask); + PUTL16(dst + 0, pack_rgb565(maxcolor)); + PUTL16(dst + 2, pack_rgb565(mincolor)); + PUTL32(dst + 4, mask); } /* write DXT3 alpha block */ -static void encode_alpha_block_BC2(unsigned char *dst, - const unsigned char *block) +static void +encode_alpha_block_BC2 (unsigned char *dst, + const unsigned char *block) { - int i, a1, a2; + int i, a1, a2; - block += 3; + block += 3; - for(i = 0; i < 8; ++i) - { + for (i = 0; i < 8; ++i) + { a1 = mul8bit(block[8 * i + 0], 0x0f); a2 = mul8bit(block[8 * i + 4], 0x0f); *dst++ = (a2 << 4) | a1; - } + } } /* Write DXT5 alpha block */ -static void encode_alpha_block_BC3(unsigned char *dst, - const unsigned char *block, - const int offset) +static void +encode_alpha_block_BC3 (unsigned char *dst, + const unsigned char *block, + const int offset) { - int i, v, mn, mx; - int dist, bias, dist2, dist4, bits, mask; - int a, idx, t; + int i, v, mn, mx; + int dist, bias, dist2, dist4, bits, mask; + int a, idx, t; - block += offset; - block += 3; + block += offset; + block += 3; - /* find min/max alpha pair */ - mn = mx = block[0]; - for(i = 0; i < 16; ++i) - { + /* find min/max alpha pair */ + mn = mx = block[0]; + for (i = 0; i < 16; ++i) + { v = block[4 * i]; if(v > mx) mx = v; if(v < mn) mn = v; - } + } - /* encode them */ - *dst++ = mx; - *dst++ = mn; + /* encode them */ + *dst++ = mx; + *dst++ = mn; - /* - * determine bias and emit indices - * given the choice of mx/mn, these indices are optimal: - * http://fgiesen.wordpress.com/2009/12/15/dxt5-alpha-block-index-determination/ - */ - dist = mx - mn; - dist4 = dist * 4; - dist2 = dist * 2; - bias = (dist < 8) ? (dist - 1) : (dist / 2 + 2); - bias -= mn * 7; - bits = 0; - mask = 0; + /* + * determine bias and emit indices + * given the choice of mx/mn, these indices are optimal: + * http://fgiesen.wordpress.com/2009/12/15/dxt5-alpha-block-index-determination/ + */ + dist = mx - mn; + dist4 = dist * 4; + dist2 = dist * 2; + bias = (dist < 8) ? (dist - 1) : (dist / 2 + 2); + bias -= mn * 7; + bits = 0; + mask = 0; - for(i = 0; i < 16; ++i) - { + for (i = 0; i < 16; ++i) + { a = block[4 * i] * 7 + bias; - /* select index. this is a "linear scale" lerp factor between 0 (val=min) and 7 (val=max). */ + /* select index. this is a "linear scale" lerp factor between 0 + (val=min) and 7 (val=max). */ t = (a >= dist4) ? -1 : 0; idx = t & 4; a -= dist4 & t; t = (a >= dist2) ? -1 : 0; idx += t & 2; a -= dist2 & t; idx += (a >= dist); @@ -947,466 +1004,519 @@ static void encode_alpha_block_BC3(unsigned char *dst, /* write index */ mask |= idx << bits; - if((bits += 3) >= 8) - { - *dst++ = mask; - mask >>= 8; - bits -= 8; - } - } + if ((bits += 3) >= 8) + { + *dst++ = mask; + mask >>= 8; + bits -= 8; + } + } } #define BLOCK_COUNT(w, h) ((((h) + 3) >> 2) * (((w) + 3) >> 2)) #define BLOCK_OFFSET(x, y, w, bs) (((y) >> 2) * ((bs) * (((w) + 3) >> 2)) + ((bs) * ((x) >> 2))) -static void compress_BC1(unsigned char *dst, const unsigned char *src, - int w, int h, int flags) +static void +compress_BC1 (unsigned char *dst, + const unsigned char *src, + int w, + int h, + int flags) { - const unsigned int block_count = BLOCK_COUNT(w, h); - unsigned int i; - unsigned char block[64], *p; - int x, y; + const unsigned int block_count = BLOCK_COUNT(w, h); + unsigned int i; + unsigned char block[64], *p; + int x, y; #ifdef _OPENMP - #pragma omp parallel for schedule(dynamic, 256) private(block, p, x, y) +#pragma omp parallel for schedule(dynamic, 256) private(block, p, x, y) #endif - for(i = 0; i < block_count; ++i) - { + for (i = 0; i < block_count; ++i) + { x = (i % ((w + 3) >> 2)) << 2; y = (i / ((w + 3) >> 2)) << 2; p = dst + BLOCK_OFFSET(x, y, w, 8); extract_block(src, x, y, w, h, block); encode_color_block(p, block, DXT_BC1 | flags); - } + } } -static void compress_BC2(unsigned char *dst, const unsigned char *src, - int w, int h, int flags) +static void +compress_BC2 (unsigned char *dst, + const unsigned char *src, + int w, + int h, + int flags) { - const unsigned int block_count = BLOCK_COUNT(w, h); - unsigned int i; - unsigned char block[64], *p; - int x, y; + const unsigned int block_count = BLOCK_COUNT(w, h); + unsigned int i; + unsigned char block[64], *p; + int x, y; #ifdef _OPENMP - #pragma omp parallel for schedule(dynamic, 256) private(block, p, x, y) +#pragma omp parallel for schedule(dynamic, 256) private(block, p, x, y) #endif - for(i = 0; i < block_count; ++i) - { + for (i = 0; i < block_count; ++i) + { x = (i % ((w + 3) >> 2)) << 2; y = (i / ((w + 3) >> 2)) << 2; p = dst + BLOCK_OFFSET(x, y, w, 16); extract_block(src, x, y, w, h, block); encode_alpha_block_BC2(p, block); encode_color_block(p + 8, block, DXT_BC2 | flags); - } + } } -static void compress_BC3(unsigned char *dst, const unsigned char *src, - int w, int h, int flags) +static void +compress_BC3 (unsigned char *dst, + const unsigned char *src, + int w, + int h, + int flags) { - const unsigned int block_count = BLOCK_COUNT(w, h); - unsigned int i; - unsigned char block[64], *p; - int x, y; + const unsigned int block_count = BLOCK_COUNT(w, h); + unsigned int i; + unsigned char block[64], *p; + int x, y; #ifdef _OPENMP - #pragma omp parallel for schedule(dynamic, 256) private(block, p, x, y) +#pragma omp parallel for schedule(dynamic, 256) private(block, p, x, y) #endif - for(i = 0; i < block_count; ++i) - { + for (i = 0; i < block_count; ++i) + { x = (i % ((w + 3) >> 2)) << 2; y = (i / ((w + 3) >> 2)) << 2; p = dst + BLOCK_OFFSET(x, y, w, 16); extract_block(src, x, y, w, h, block); encode_alpha_block_BC3(p, block, 0); encode_color_block(p + 8, block, DXT_BC3 | flags); - } + } } -static void compress_BC4(unsigned char *dst, const unsigned char *src, - int w, int h) +static void +compress_BC4 (unsigned char *dst, + const unsigned char *src, + int w, + int h) { - const unsigned int block_count = BLOCK_COUNT(w, h); - unsigned int i; - unsigned char block[64], *p; - int x, y; + const unsigned int block_count = BLOCK_COUNT(w, h); + unsigned int i; + unsigned char block[64], *p; + int x, y; #ifdef _OPENMP - #pragma omp parallel for schedule(dynamic, 256) private(block, p, x, y) +#pragma omp parallel for schedule(dynamic, 256) private(block, p, x, y) #endif - for(i = 0; i < block_count; ++i) - { + for (i = 0; i < block_count; ++i) + { x = (i % ((w + 3) >> 2)) << 2; y = (i / ((w + 3) >> 2)) << 2; p = dst + BLOCK_OFFSET(x, y, w, 8); extract_block(src, x, y, w, h, block); encode_alpha_block_BC3(p, block, -1); - } + } } -static void compress_BC5(unsigned char *dst, const unsigned char *src, - int w, int h) +static void +compress_BC5 (unsigned char *dst, + const unsigned char *src, + int w, + int h) { - const unsigned int block_count = BLOCK_COUNT(w, h); - unsigned int i; - unsigned char block[64], *p; - int x, y; + const unsigned int block_count = BLOCK_COUNT(w, h); + unsigned int i; + unsigned char block[64], *p; + int x, y; #ifdef _OPENMP - #pragma omp parallel for schedule(dynamic, 256) private(block, p, x, y) +#pragma omp parallel for schedule(dynamic, 256) private(block, p, x, y) #endif - for(i = 0; i < block_count; ++i) - { + for (i = 0; i < block_count; ++i) + { x = (i % ((w + 3) >> 2)) << 2; y = (i / ((w + 3) >> 2)) << 2; p = dst + BLOCK_OFFSET(x, y, w, 16); extract_block(src, x, y, w, h, block); encode_alpha_block_BC3(p, block, -2); encode_alpha_block_BC3(p + 8, block, -1); - } + } } -static void compress_YCoCg(unsigned char *dst, const unsigned char *src, - int w, int h) +static void +compress_YCoCg (unsigned char *dst, + const unsigned char *src, + int w, + int h) { - const unsigned int block_count = BLOCK_COUNT(w, h); - unsigned int i; - unsigned char block[64], *p; - int x, y; + const unsigned int block_count = BLOCK_COUNT(w, h); + unsigned int i; + unsigned char block[64], *p; + int x, y; #ifdef _OPENMP - #pragma omp parallel for schedule(dynamic, 256) private(block, p, x, y) +#pragma omp parallel for schedule(dynamic, 256) private(block, p, x, y) #endif - for(i = 0; i < block_count; ++i) - { + for (i = 0; i < block_count; ++i) + { x = (i % ((w + 3) >> 2)) << 2; y = (i / ((w + 3) >> 2)) << 2; p = dst + BLOCK_OFFSET(x, y, w, 16); extract_block(src, x, y, w, h, block); encode_alpha_block_BC3(p, block, 0); encode_YCoCg_block(p + 8, block); - } + } } -int dxt_compress(unsigned char *dst, unsigned char *src, int format, - unsigned int width, unsigned int height, int bpp, - int mipmaps, int flags) +int +dxt_compress (unsigned char *dst, + unsigned char *src, + int format, + unsigned int width, + unsigned int height, + int bpp, + int mipmaps, + int flags) { - int i, size, w, h; - unsigned int offset; - unsigned char *tmp = NULL; - int j; - unsigned char *s; + int i, size, w, h; + unsigned int offset; + unsigned char *tmp = NULL; + int j; + unsigned char *s; - if(bpp == 1) - { + if (bpp == 1) + { /* grayscale promoted to BGRA */ size = get_mipmapped_size(width, height, 4, 0, mipmaps, DDS_COMPRESS_NONE); tmp = g_malloc(size); - for(i = j = 0; j < size; ++i, j += 4) - { - tmp[j + 0] = src[i]; - tmp[j + 1] = src[i]; - tmp[j + 2] = src[i]; - tmp[j + 3] = 255; - } + for (i = j = 0; j < size; ++i, j += 4) + { + tmp[j + 0] = src[i]; + tmp[j + 1] = src[i]; + tmp[j + 2] = src[i]; + tmp[j + 3] = 255; + } bpp = 4; - } - else if(bpp == 2) - { + } + else if (bpp == 2) + { /* gray-alpha promoted to BGRA */ size = get_mipmapped_size(width, height, 4, 0, mipmaps, DDS_COMPRESS_NONE); tmp = g_malloc(size); - for(i = j = 0; j < size; i += 2, j += 4) - { - tmp[j + 0] = src[i]; - tmp[j + 1] = src[i]; - tmp[j + 2] = src[i]; - tmp[j + 3] = src[i + 1]; - } + for (i = j = 0; j < size; i += 2, j += 4) + { + tmp[j + 0] = src[i]; + tmp[j + 1] = src[i]; + tmp[j + 2] = src[i]; + tmp[j + 3] = src[i + 1]; + } bpp = 4; - } - else if(bpp == 3) - { + } + else if (bpp == 3) + { size = get_mipmapped_size(width, height, 4, 0, mipmaps, DDS_COMPRESS_NONE); tmp = g_malloc(size); - for(i = j = 0; j < size; i += 3, j += 4) - { - tmp[j + 0] = src[i + 0]; - tmp[j + 1] = src[i + 1]; - tmp[j + 2] = src[i + 2]; - tmp[j + 3] = 255; - } + for (i = j = 0; j < size; i += 3, j += 4) + { + tmp[j + 0] = src[i + 0]; + tmp[j + 1] = src[i + 1]; + tmp[j + 2] = src[i + 2]; + tmp[j + 3] = 255; + } bpp = 4; - } + } - offset = 0; - w = width; - h = height; - s = tmp ? tmp : src; + offset = 0; + w = width; + h = height; + s = tmp ? tmp : src; - for(i = 0; i < mipmaps; ++i) - { - switch(format) - { - case DDS_COMPRESS_BC1: - compress_BC1(dst + offset, s, w, h, flags); - break; - case DDS_COMPRESS_BC2: - compress_BC2(dst + offset, s, w, h, flags); - break; - case DDS_COMPRESS_BC3: - case DDS_COMPRESS_BC3N: - case DDS_COMPRESS_RXGB: - case DDS_COMPRESS_AEXP: - case DDS_COMPRESS_YCOCG: - compress_BC3(dst + offset, s, w, h, flags); - break; - case DDS_COMPRESS_BC4: - compress_BC4(dst + offset, s, w, h); - break; - case DDS_COMPRESS_BC5: - compress_BC5(dst + offset, s, w, h); - break; - case DDS_COMPRESS_YCOCGS: - compress_YCoCg(dst + offset, s, w, h); - break; - default: - compress_BC3(dst + offset, s, w, h, flags); - break; - } + for (i = 0; i < mipmaps; ++i) + { + switch (format) + { + case DDS_COMPRESS_BC1: + compress_BC1(dst + offset, s, w, h, flags); + break; + case DDS_COMPRESS_BC2: + compress_BC2(dst + offset, s, w, h, flags); + break; + case DDS_COMPRESS_BC3: + case DDS_COMPRESS_BC3N: + case DDS_COMPRESS_RXGB: + case DDS_COMPRESS_AEXP: + case DDS_COMPRESS_YCOCG: + compress_BC3(dst + offset, s, w, h, flags); + break; + case DDS_COMPRESS_BC4: + compress_BC4(dst + offset, s, w, h); + break; + case DDS_COMPRESS_BC5: + compress_BC5(dst + offset, s, w, h); + break; + case DDS_COMPRESS_YCOCGS: + compress_YCoCg(dst + offset, s, w, h); + break; + default: + compress_BC3(dst + offset, s, w, h, flags); + break; + } s += (w * h * bpp); offset += get_mipmapped_size(w, h, 0, 0, 1, format); w = MAX(1, w >> 1); h = MAX(1, h >> 1); - } + } - if(tmp) g_free(tmp); + if (tmp) + g_free(tmp); - return(1); + return 1; } -static void decode_color_block(unsigned char *block, unsigned char *src, - int format) +static void +decode_color_block (unsigned char *block, + unsigned char *src, + int format) { - int i, x, y; - unsigned char *d = block; - unsigned int indices, idx; - unsigned char colors[4][3]; - unsigned short c0, c1; + int i, x, y; + unsigned char *d = block; + unsigned int indices, idx; + unsigned char colors[4][3]; + unsigned short c0, c1; - c0 = GETL16(&src[0]); - c1 = GETL16(&src[2]); + c0 = GETL16(&src[0]); + c1 = GETL16(&src[2]); - unpack_rgb565(colors[0], c0); - unpack_rgb565(colors[1], c1); + unpack_rgb565(colors[0], c0); + unpack_rgb565(colors[1], c1); - if((c0 > c1) || (format == DDS_COMPRESS_BC3)) - { + if ((c0 > c1) || (format == DDS_COMPRESS_BC3)) + { lerp_rgb13(colors[2], colors[0], colors[1]); lerp_rgb13(colors[3], colors[1], colors[0]); - } - else - { - for(i = 0; i < 3; ++i) - { - colors[2][i] = (colors[0][i] + colors[1][i] + 1) >> 1; - colors[3][i] = 255; - } - } + } + else + { + for (i = 0; i < 3; ++i) + { + colors[2][i] = (colors[0][i] + colors[1][i] + 1) >> 1; + colors[3][i] = 255; + } + } - src += 4; - for(y = 0; y < 4; ++y) - { + src += 4; + for (y = 0; y < 4; ++y) + { indices = src[y]; - for(x = 0; x < 4; ++x) - { - idx = indices & 0x03; - d[0] = colors[idx][2]; - d[1] = colors[idx][1]; - d[2] = colors[idx][0]; - if(format == DDS_COMPRESS_BC1) + for (x = 0; x < 4; ++x) + { + idx = indices & 0x03; + d[0] = colors[idx][2]; + d[1] = colors[idx][1]; + d[2] = colors[idx][0]; + if (format == DDS_COMPRESS_BC1) d[3] = ((c0 <= c1) && idx == 3) ? 0 : 255; - indices >>= 2; - d += 4; - } - } + indices >>= 2; + d += 4; + } + } } -static void decode_alpha_block_BC2(unsigned char *block, unsigned char *src) +static void +decode_alpha_block_BC2 (unsigned char *block, + unsigned char *src) { - int x, y; - unsigned char *d = block; - unsigned int bits; + int x, y; + unsigned char *d = block; + unsigned int bits; - for(y = 0; y < 4; ++y) - { + for (y = 0; y < 4; ++y) + { bits = GETL16(&src[2 * y]); - for(x = 0; x < 4; ++x) - { - d[0] = (bits & 0x0f) * 17; - bits >>= 4; - d += 4; - } - } + for (x = 0; x < 4; ++x) + { + d[0] = (bits & 0x0f) * 17; + bits >>= 4; + d += 4; + } + } } -static void decode_alpha_block_BC3(unsigned char *block, unsigned char *src, int w) +static void +decode_alpha_block_BC3 (unsigned char *block, + unsigned char *src, + int w) { - int x, y, code; - unsigned char *d = block; - unsigned char a0 = src[0]; - unsigned char a1 = src[1]; - unsigned long long bits = GETL64(src) >> 16; + int x, y, code; + unsigned char *d = block; + unsigned char a0 = src[0]; + unsigned char a1 = src[1]; + unsigned long long bits = GETL64(src) >> 16; - for(y = 0; y < 4; ++y) - { - for(x = 0; x < 4; ++x) - { - code = ((unsigned int)bits) & 0x07; - if(code == 0) + for (y = 0; y < 4; ++y) + { + for (x = 0; x < 4; ++x) + { + code = ((unsigned int)bits) & 0x07; + if (code == 0) d[0] = a0; - else if(code == 1) + else if (code == 1) d[0] = a1; - else if(a0 > a1) + else if (a0 > a1) d[0] = ((8 - code) * a0 + (code - 1) * a1) / 7; - else if(code >= 6) + else if (code >= 6) d[0] = (code == 6) ? 0 : 255; - else + else d[0] = ((6 - code) * a0 + (code - 1) * a1) / 5; - bits >>= 3; - d += 4; - } - if(w < 4) bits >>= (3 * (4 - w)); - } + bits >>= 3; + d += 4; + } + + if (w < 4) + bits >>= (3 * (4 - w)); + } } -static void make_normal(unsigned char *dst, unsigned char x, unsigned char y) +static void +make_normal (unsigned char *dst, + unsigned char x, + unsigned char y) { - float nx = 2.0f * ((float)x / 255.0f) - 1.0f; - float ny = 2.0f * ((float)y / 255.0f) - 1.0f; - float nz = 0.0f; - float d = 1.0f - nx * nx + ny * ny; - int z; + float nx = 2.0f * ((float)x / 255.0f) - 1.0f; + float ny = 2.0f * ((float)y / 255.0f) - 1.0f; + float nz = 0.0f; + float d = 1.0f - nx * nx + ny * ny; + int z; - if(d > 0) nz = sqrtf(d); + if (d > 0) + nz = sqrtf(d); - z = (int)(255.0f * (nz + 1) / 2.0f); - z = MAX(0, MIN(255, z)); + z = (int)(255.0f * (nz + 1) / 2.0f); + z = MAX(0, MIN(255, z)); - dst[0] = x; - dst[1] = y; - dst[2] = z; + dst[0] = x; + dst[1] = y; + dst[2] = z; } -static void normalize_block(unsigned char *block, int format) +static void +normalize_block (unsigned char *block, + int format) { - int x, y, tmp; + int x, y, tmp; - for(y = 0; y < 4; ++y) - { - for(x = 0; x < 4; ++x) - { - if(format == DDS_COMPRESS_BC3) - { - tmp = block[y * 16 + (x * 4)]; - make_normal(&block[y * 16 + (x * 4)], - block[y * 16 + (x * 4) + 3], - block[y * 16 + (x * 4) + 1]); - block[y * 16 + (x * 4) + 3] = tmp; - } - else if(format == DDS_COMPRESS_BC5) - { - make_normal(&block[y * 16 + (x * 4)], - block[y * 16 + (x * 4)], - block[y * 16 + (x * 4) + 1]); - } - } - } + for (y = 0; y < 4; ++y) + { + for (x = 0; x < 4; ++x) + { + if (format == DDS_COMPRESS_BC3) + { + tmp = block[y * 16 + (x * 4)]; + make_normal(&block[y * 16 + (x * 4)], + block[y * 16 + (x * 4) + 3], + block[y * 16 + (x * 4) + 1]); + block[y * 16 + (x * 4) + 3] = tmp; + } + else if (format == DDS_COMPRESS_BC5) + { + make_normal(&block[y * 16 + (x * 4)], + block[y * 16 + (x * 4)], + block[y * 16 + (x * 4) + 1]); + } + } + } } -static void put_block(unsigned char *dst, unsigned char *block, - unsigned int bx, unsigned int by, - unsigned int width, unsigned height, - int bpp) +static void +put_block (unsigned char *dst, + unsigned char *block, + unsigned int bx, + unsigned int by, + unsigned int width, + unsigned height, + int bpp) { - int x, y, i; - unsigned char *d; + int x, y, i; + unsigned char *d; - for(y = 0; y < 4 && ((by + y) < height); ++y) - { + for (y = 0; y < 4 && ((by + y) < height); ++y) + { d = dst + ((y + by) * width + bx) * bpp; - for(x = 0; x < 4 && ((bx + x) < width); ++x) - { - for(i = 0; i < bpp; ++ i) + for (x = 0; x < 4 && ((bx + x) < width); ++x) + { + for (i = 0; i < bpp; ++ i) *d++ = block[y * 16 + (x * 4) + i]; - } - } + } + } } -int dxt_decompress(unsigned char *dst, unsigned char *src, int format, - unsigned int size, unsigned int width, unsigned int height, - int bpp, int normals) +int +dxt_decompress (unsigned char *dst, + unsigned char *src, + int format, + unsigned int size, + unsigned int width, + unsigned int height, + int bpp, + int normals) { - unsigned char *s; - unsigned int x, y; - unsigned char block[16 * 4]; + unsigned char *s; + unsigned int x, y; + unsigned char block[16 * 4]; - s = src; + s = src; - for(y = 0; y < height; y += 4) - { - for(x = 0; x < width; x += 4) - { - memset(block, 255, 16 * 4); + for (y = 0; y < height; y += 4) + { + for (x = 0; x < width; x += 4) + { + memset(block, 255, 16 * 4); - if(format == DDS_COMPRESS_BC1) - { - decode_color_block(block, s, format); - s += 8; - } - else if(format == DDS_COMPRESS_BC2) - { - decode_alpha_block_BC2(block + 3, s); - decode_color_block(block, s + 8, format); - s += 16; - } - else if(format == DDS_COMPRESS_BC3) - { - decode_alpha_block_BC3(block + 3, s, width); - decode_color_block(block, s + 8, format); - s += 16; - } - else if(format == DDS_COMPRESS_BC4) - { - decode_alpha_block_BC3(block, s, width); - s += 8; - } - else if(format == DDS_COMPRESS_BC5) - { - decode_alpha_block_BC3(block, s + 8, width); - decode_alpha_block_BC3(block + 1, s, width); - s += 16; - } + if (format == DDS_COMPRESS_BC1) + { + decode_color_block(block, s, format); + s += 8; + } + else if (format == DDS_COMPRESS_BC2) + { + decode_alpha_block_BC2(block + 3, s); + decode_color_block(block, s + 8, format); + s += 16; + } + else if (format == DDS_COMPRESS_BC3) + { + decode_alpha_block_BC3(block + 3, s, width); + decode_color_block(block, s + 8, format); + s += 16; + } + else if (format == DDS_COMPRESS_BC4) + { + decode_alpha_block_BC3(block, s, width); + s += 8; + } + else if (format == DDS_COMPRESS_BC5) + { + decode_alpha_block_BC3(block, s + 8, width); + decode_alpha_block_BC3(block + 1, s, width); + s += 16; + } - if(normals) + if (normals) normalize_block(block, format); - put_block(dst, block, x, y, width, height, bpp); - } - } + put_block(dst, block, x, y, width, height, bpp); + } + } - return(1); + return 1; } diff --git a/plug-ins/file-dds/dxt.h b/plug-ins/file-dds/dxt.h index a49c85a803..5364bbe615 100644 --- a/plug-ins/file-dds/dxt.h +++ b/plug-ins/file-dds/dxt.h @@ -1,41 +1,49 @@ /* - DDS GIMP plugin + * DDS GIMP plugin + * + * Copyright (C) 2004-2012 Shawn Kirst , + * with parts (C) 2003 Arne Reuter 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 3 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. If not, see . + */ - Copyright (C) 2004-2012 Shawn Kirst , - with parts (C) 2003 Arne Reuter 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 DXT_H -#define DXT_H +#ifndef __DXT_H__ +#define __DXT_H__ typedef enum dxt_flags_e { - DXT_BC1 = 1 << 0, - DXT_BC2 = 1 << 1, - DXT_BC3 = 1 << 2, - DXT_PERCEPTUAL = 1 << 3, + DXT_BC1 = 1 << 0, + DXT_BC2 = 1 << 1, + DXT_BC3 = 1 << 2, + DXT_PERCEPTUAL = 1 << 3, } dxt_flags_t; -int dxt_compress(unsigned char *dst, unsigned char *src, int format, - unsigned int width, unsigned int height, int bpp, - int mipmaps, int flags); -int dxt_decompress(unsigned char *dst, unsigned char *src, int format, - unsigned int size, unsigned int width, unsigned int height, - int bpp, int normals); +int dxt_compress (unsigned char *dst, + unsigned char *src, + int format, + unsigned int width, + unsigned int height, + int bpp, + int mipmaps, + int flags); +int dxt_decompress (unsigned char *dst, + unsigned char *src, + int format, + unsigned int size, + unsigned int width, + unsigned int height, + int bpp, + int normals); -#endif +#endif /* __DXT_H__ */ diff --git a/plug-ins/file-dds/dxt_tables.h b/plug-ins/file-dds/dxt_tables.h index 14aee2b52a..e30bb6aa6b 100644 --- a/plug-ins/file-dds/dxt_tables.h +++ b/plug-ins/file-dds/dxt_tables.h @@ -1,216 +1,216 @@ -#ifndef DXT_TABLES_H -#define DXT_TABLES_H +#ifndef __DXT_TABLES_H__ +#define __DXT_TABLES_H__ static const unsigned char quantRB[256 + 16] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, - 0x08, 0x08, 0x08, 0x08, 0x08, 0x10, 0x10, 0x10, - 0x10, 0x10, 0x10, 0x10, 0x10, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x21, 0x21, 0x21, - 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x29, 0x29, - 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x31, 0x31, - 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x39, 0x39, - 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x42, 0x42, - 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x4a, 0x4a, - 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x52, - 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x5a, - 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x63, - 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x6b, - 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, - 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, - 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, - 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, - 0x8c, 0x8c, 0x8c, 0x8c, 0x8c, 0x8c, 0x8c, 0x8c, - 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, - 0x94, 0x9c, 0x9c, 0x9c, 0x9c, 0x9c, 0x9c, 0x9c, - 0x9c, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, - 0xa5, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, - 0xad, 0xb5, 0xb5, 0xb5, 0xb5, 0xb5, 0xb5, 0xb5, - 0xb5, 0xb5, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, - 0xbd, 0xbd, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, - 0xc6, 0xc6, 0xce, 0xce, 0xce, 0xce, 0xce, 0xce, - 0xce, 0xce, 0xd6, 0xd6, 0xd6, 0xd6, 0xd6, 0xd6, - 0xd6, 0xd6, 0xde, 0xde, 0xde, 0xde, 0xde, 0xde, - 0xde, 0xde, 0xde, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, - 0xe7, 0xe7, 0xe7, 0xef, 0xef, 0xef, 0xef, 0xef, - 0xef, 0xef, 0xef, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, - 0xf7, 0xf7, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, + 0x08, 0x08, 0x08, 0x08, 0x08, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x18, 0x18, 0x18, 0x21, 0x21, 0x21, + 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x29, 0x29, + 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x31, 0x31, + 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x39, 0x39, + 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x42, 0x42, + 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x4a, 0x4a, + 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x4a, 0x52, + 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x52, 0x5a, + 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x63, + 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x6b, + 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, + 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, + 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, 0x7b, + 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, + 0x8c, 0x8c, 0x8c, 0x8c, 0x8c, 0x8c, 0x8c, 0x8c, + 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, + 0x94, 0x9c, 0x9c, 0x9c, 0x9c, 0x9c, 0x9c, 0x9c, + 0x9c, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, + 0xa5, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, 0xad, + 0xad, 0xb5, 0xb5, 0xb5, 0xb5, 0xb5, 0xb5, 0xb5, + 0xb5, 0xb5, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, + 0xbd, 0xbd, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, + 0xc6, 0xc6, 0xce, 0xce, 0xce, 0xce, 0xce, 0xce, + 0xce, 0xce, 0xd6, 0xd6, 0xd6, 0xd6, 0xd6, 0xd6, + 0xd6, 0xd6, 0xde, 0xde, 0xde, 0xde, 0xde, 0xde, + 0xde, 0xde, 0xde, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7, + 0xe7, 0xe7, 0xe7, 0xef, 0xef, 0xef, 0xef, 0xef, + 0xef, 0xef, 0xef, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, + 0xf7, 0xf7, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }; static const unsigned char quantG[256 + 16] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x08, - 0x08, 0x08, 0x08, 0x0c, 0x0c, 0x0c, 0x0c, 0x10, - 0x10, 0x10, 0x10, 0x14, 0x14, 0x14, 0x14, 0x18, - 0x18, 0x18, 0x18, 0x1c, 0x1c, 0x1c, 0x1c, 0x20, - 0x20, 0x20, 0x20, 0x24, 0x24, 0x24, 0x24, 0x28, - 0x28, 0x28, 0x28, 0x2c, 0x2c, 0x2c, 0x2c, 0x30, - 0x30, 0x30, 0x30, 0x34, 0x34, 0x34, 0x34, 0x38, - 0x38, 0x38, 0x38, 0x3c, 0x3c, 0x3c, 0x3c, 0x41, - 0x41, 0x41, 0x41, 0x45, 0x45, 0x45, 0x45, 0x49, - 0x49, 0x49, 0x49, 0x4d, 0x4d, 0x4d, 0x4d, 0x51, - 0x51, 0x51, 0x51, 0x55, 0x55, 0x55, 0x55, 0x55, - 0x59, 0x59, 0x59, 0x59, 0x5d, 0x5d, 0x5d, 0x5d, - 0x61, 0x61, 0x61, 0x61, 0x65, 0x65, 0x65, 0x65, - 0x69, 0x69, 0x69, 0x69, 0x6d, 0x6d, 0x6d, 0x6d, - 0x71, 0x71, 0x71, 0x71, 0x75, 0x75, 0x75, 0x75, - 0x79, 0x79, 0x79, 0x79, 0x7d, 0x7d, 0x7d, 0x7d, - 0x82, 0x82, 0x82, 0x82, 0x86, 0x86, 0x86, 0x86, - 0x8a, 0x8a, 0x8a, 0x8a, 0x8e, 0x8e, 0x8e, 0x8e, - 0x92, 0x92, 0x92, 0x92, 0x96, 0x96, 0x96, 0x96, - 0x9a, 0x9a, 0x9a, 0x9a, 0x9e, 0x9e, 0x9e, 0x9e, - 0xa2, 0xa2, 0xa2, 0xa2, 0xa6, 0xa6, 0xa6, 0xa6, - 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xae, 0xae, 0xae, - 0xae, 0xb2, 0xb2, 0xb2, 0xb2, 0xb6, 0xb6, 0xb6, - 0xb6, 0xba, 0xba, 0xba, 0xba, 0xbe, 0xbe, 0xbe, - 0xbe, 0xc3, 0xc3, 0xc3, 0xc3, 0xc7, 0xc7, 0xc7, - 0xc7, 0xcb, 0xcb, 0xcb, 0xcb, 0xcf, 0xcf, 0xcf, - 0xcf, 0xd3, 0xd3, 0xd3, 0xd3, 0xd7, 0xd7, 0xd7, - 0xd7, 0xdb, 0xdb, 0xdb, 0xdb, 0xdf, 0xdf, 0xdf, - 0xdf, 0xe3, 0xe3, 0xe3, 0xe3, 0xe7, 0xe7, 0xe7, - 0xe7, 0xeb, 0xeb, 0xeb, 0xeb, 0xef, 0xef, 0xef, - 0xef, 0xf3, 0xf3, 0xf3, 0xf3, 0xf7, 0xf7, 0xf7, - 0xf7, 0xfb, 0xfb, 0xfb, 0xfb, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x08, + 0x08, 0x08, 0x08, 0x0c, 0x0c, 0x0c, 0x0c, 0x10, + 0x10, 0x10, 0x10, 0x14, 0x14, 0x14, 0x14, 0x18, + 0x18, 0x18, 0x18, 0x1c, 0x1c, 0x1c, 0x1c, 0x20, + 0x20, 0x20, 0x20, 0x24, 0x24, 0x24, 0x24, 0x28, + 0x28, 0x28, 0x28, 0x2c, 0x2c, 0x2c, 0x2c, 0x30, + 0x30, 0x30, 0x30, 0x34, 0x34, 0x34, 0x34, 0x38, + 0x38, 0x38, 0x38, 0x3c, 0x3c, 0x3c, 0x3c, 0x41, + 0x41, 0x41, 0x41, 0x45, 0x45, 0x45, 0x45, 0x49, + 0x49, 0x49, 0x49, 0x4d, 0x4d, 0x4d, 0x4d, 0x51, + 0x51, 0x51, 0x51, 0x55, 0x55, 0x55, 0x55, 0x55, + 0x59, 0x59, 0x59, 0x59, 0x5d, 0x5d, 0x5d, 0x5d, + 0x61, 0x61, 0x61, 0x61, 0x65, 0x65, 0x65, 0x65, + 0x69, 0x69, 0x69, 0x69, 0x6d, 0x6d, 0x6d, 0x6d, + 0x71, 0x71, 0x71, 0x71, 0x75, 0x75, 0x75, 0x75, + 0x79, 0x79, 0x79, 0x79, 0x7d, 0x7d, 0x7d, 0x7d, + 0x82, 0x82, 0x82, 0x82, 0x86, 0x86, 0x86, 0x86, + 0x8a, 0x8a, 0x8a, 0x8a, 0x8e, 0x8e, 0x8e, 0x8e, + 0x92, 0x92, 0x92, 0x92, 0x96, 0x96, 0x96, 0x96, + 0x9a, 0x9a, 0x9a, 0x9a, 0x9e, 0x9e, 0x9e, 0x9e, + 0xa2, 0xa2, 0xa2, 0xa2, 0xa6, 0xa6, 0xa6, 0xa6, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xae, 0xae, 0xae, + 0xae, 0xb2, 0xb2, 0xb2, 0xb2, 0xb6, 0xb6, 0xb6, + 0xb6, 0xba, 0xba, 0xba, 0xba, 0xbe, 0xbe, 0xbe, + 0xbe, 0xc3, 0xc3, 0xc3, 0xc3, 0xc7, 0xc7, 0xc7, + 0xc7, 0xcb, 0xcb, 0xcb, 0xcb, 0xcf, 0xcf, 0xcf, + 0xcf, 0xd3, 0xd3, 0xd3, 0xd3, 0xd7, 0xd7, 0xd7, + 0xd7, 0xdb, 0xdb, 0xdb, 0xdb, 0xdf, 0xdf, 0xdf, + 0xdf, 0xe3, 0xe3, 0xe3, 0xe3, 0xe7, 0xe7, 0xe7, + 0xe7, 0xeb, 0xeb, 0xeb, 0xeb, 0xef, 0xef, 0xef, + 0xef, 0xf3, 0xf3, 0xf3, 0xf3, 0xf7, 0xf7, 0xf7, + 0xf7, 0xfb, 0xfb, 0xfb, 0xfb, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }; static const unsigned char omatch5[256][2] = { - {0x00, 0x00}, {0x00, 0x00}, {0x00, 0x01}, {0x00, 0x01}, - {0x01, 0x00}, {0x01, 0x00}, {0x01, 0x00}, {0x01, 0x01}, - {0x01, 0x01}, {0x01, 0x01}, {0x01, 0x02}, {0x00, 0x04}, - {0x02, 0x01}, {0x02, 0x01}, {0x02, 0x01}, {0x02, 0x02}, - {0x02, 0x02}, {0x02, 0x02}, {0x02, 0x03}, {0x01, 0x05}, - {0x03, 0x02}, {0x03, 0x02}, {0x04, 0x00}, {0x03, 0x03}, - {0x03, 0x03}, {0x03, 0x03}, {0x03, 0x04}, {0x03, 0x04}, - {0x03, 0x04}, {0x03, 0x05}, {0x04, 0x03}, {0x04, 0x03}, - {0x05, 0x02}, {0x04, 0x04}, {0x04, 0x04}, {0x04, 0x05}, - {0x04, 0x05}, {0x05, 0x04}, {0x05, 0x04}, {0x05, 0x04}, - {0x06, 0x03}, {0x05, 0x05}, {0x05, 0x05}, {0x05, 0x06}, - {0x04, 0x08}, {0x06, 0x05}, {0x06, 0x05}, {0x06, 0x05}, - {0x06, 0x06}, {0x06, 0x06}, {0x06, 0x06}, {0x06, 0x07}, - {0x05, 0x09}, {0x07, 0x06}, {0x07, 0x06}, {0x08, 0x04}, - {0x07, 0x07}, {0x07, 0x07}, {0x07, 0x07}, {0x07, 0x08}, - {0x07, 0x08}, {0x07, 0x08}, {0x07, 0x09}, {0x08, 0x07}, - {0x08, 0x07}, {0x09, 0x06}, {0x08, 0x08}, {0x08, 0x08}, - {0x08, 0x09}, {0x08, 0x09}, {0x09, 0x08}, {0x09, 0x08}, - {0x09, 0x08}, {0x0a, 0x07}, {0x09, 0x09}, {0x09, 0x09}, - {0x09, 0x0a}, {0x08, 0x0c}, {0x0a, 0x09}, {0x0a, 0x09}, - {0x0a, 0x09}, {0x0a, 0x0a}, {0x0a, 0x0a}, {0x0a, 0x0a}, - {0x0a, 0x0b}, {0x09, 0x0d}, {0x0b, 0x0a}, {0x0b, 0x0a}, - {0x0c, 0x08}, {0x0b, 0x0b}, {0x0b, 0x0b}, {0x0b, 0x0b}, - {0x0b, 0x0c}, {0x0b, 0x0c}, {0x0b, 0x0c}, {0x0b, 0x0d}, - {0x0c, 0x0b}, {0x0c, 0x0b}, {0x0d, 0x0a}, {0x0c, 0x0c}, - {0x0c, 0x0c}, {0x0c, 0x0d}, {0x0c, 0x0d}, {0x0d, 0x0c}, - {0x0d, 0x0c}, {0x0d, 0x0c}, {0x0e, 0x0b}, {0x0d, 0x0d}, - {0x0d, 0x0d}, {0x0d, 0x0e}, {0x0c, 0x10}, {0x0e, 0x0d}, - {0x0e, 0x0d}, {0x0e, 0x0d}, {0x0e, 0x0e}, {0x0e, 0x0e}, - {0x0e, 0x0e}, {0x0e, 0x0f}, {0x0d, 0x11}, {0x0f, 0x0e}, - {0x0f, 0x0e}, {0x10, 0x0c}, {0x0f, 0x0f}, {0x0f, 0x0f}, - {0x0f, 0x0f}, {0x0f, 0x10}, {0x0f, 0x10}, {0x0f, 0x10}, - {0x0f, 0x11}, {0x10, 0x0f}, {0x10, 0x0f}, {0x11, 0x0e}, - {0x10, 0x10}, {0x10, 0x10}, {0x10, 0x11}, {0x10, 0x11}, - {0x11, 0x10}, {0x11, 0x10}, {0x11, 0x10}, {0x12, 0x0f}, - {0x11, 0x11}, {0x11, 0x11}, {0x11, 0x12}, {0x10, 0x14}, - {0x12, 0x11}, {0x12, 0x11}, {0x12, 0x11}, {0x12, 0x12}, - {0x12, 0x12}, {0x12, 0x12}, {0x12, 0x13}, {0x11, 0x15}, - {0x13, 0x12}, {0x13, 0x12}, {0x14, 0x10}, {0x13, 0x13}, - {0x13, 0x13}, {0x13, 0x13}, {0x13, 0x14}, {0x13, 0x14}, - {0x13, 0x14}, {0x13, 0x15}, {0x14, 0x13}, {0x14, 0x13}, - {0x15, 0x12}, {0x14, 0x14}, {0x14, 0x14}, {0x14, 0x15}, - {0x14, 0x15}, {0x15, 0x14}, {0x15, 0x14}, {0x15, 0x14}, - {0x16, 0x13}, {0x15, 0x15}, {0x15, 0x15}, {0x15, 0x16}, - {0x14, 0x18}, {0x16, 0x15}, {0x16, 0x15}, {0x16, 0x15}, - {0x16, 0x16}, {0x16, 0x16}, {0x16, 0x16}, {0x16, 0x17}, - {0x15, 0x19}, {0x17, 0x16}, {0x17, 0x16}, {0x18, 0x14}, - {0x17, 0x17}, {0x17, 0x17}, {0x17, 0x17}, {0x17, 0x18}, - {0x17, 0x18}, {0x17, 0x18}, {0x17, 0x19}, {0x18, 0x17}, - {0x18, 0x17}, {0x19, 0x16}, {0x18, 0x18}, {0x18, 0x18}, - {0x18, 0x19}, {0x18, 0x19}, {0x19, 0x18}, {0x19, 0x18}, - {0x19, 0x18}, {0x1a, 0x17}, {0x19, 0x19}, {0x19, 0x19}, - {0x19, 0x1a}, {0x18, 0x1c}, {0x1a, 0x19}, {0x1a, 0x19}, - {0x1a, 0x19}, {0x1a, 0x1a}, {0x1a, 0x1a}, {0x1a, 0x1a}, - {0x1a, 0x1b}, {0x19, 0x1d}, {0x1b, 0x1a}, {0x1b, 0x1a}, - {0x1c, 0x18}, {0x1b, 0x1b}, {0x1b, 0x1b}, {0x1b, 0x1b}, - {0x1b, 0x1c}, {0x1b, 0x1c}, {0x1b, 0x1c}, {0x1b, 0x1d}, - {0x1c, 0x1b}, {0x1c, 0x1b}, {0x1d, 0x1a}, {0x1c, 0x1c}, - {0x1c, 0x1c}, {0x1c, 0x1d}, {0x1c, 0x1d}, {0x1d, 0x1c}, - {0x1d, 0x1c}, {0x1d, 0x1c}, {0x1e, 0x1b}, {0x1d, 0x1d}, - {0x1d, 0x1d}, {0x1d, 0x1e}, {0x1d, 0x1e}, {0x1e, 0x1d}, - {0x1e, 0x1d}, {0x1e, 0x1d}, {0x1e, 0x1e}, {0x1e, 0x1e}, - {0x1e, 0x1e}, {0x1e, 0x1f}, {0x1e, 0x1f}, {0x1f, 0x1e}, - {0x1f, 0x1e}, {0x1f, 0x1e}, {0x1f, 0x1f}, {0x1f, 0x1f}, + {0x00, 0x00}, {0x00, 0x00}, {0x00, 0x01}, {0x00, 0x01}, + {0x01, 0x00}, {0x01, 0x00}, {0x01, 0x00}, {0x01, 0x01}, + {0x01, 0x01}, {0x01, 0x01}, {0x01, 0x02}, {0x00, 0x04}, + {0x02, 0x01}, {0x02, 0x01}, {0x02, 0x01}, {0x02, 0x02}, + {0x02, 0x02}, {0x02, 0x02}, {0x02, 0x03}, {0x01, 0x05}, + {0x03, 0x02}, {0x03, 0x02}, {0x04, 0x00}, {0x03, 0x03}, + {0x03, 0x03}, {0x03, 0x03}, {0x03, 0x04}, {0x03, 0x04}, + {0x03, 0x04}, {0x03, 0x05}, {0x04, 0x03}, {0x04, 0x03}, + {0x05, 0x02}, {0x04, 0x04}, {0x04, 0x04}, {0x04, 0x05}, + {0x04, 0x05}, {0x05, 0x04}, {0x05, 0x04}, {0x05, 0x04}, + {0x06, 0x03}, {0x05, 0x05}, {0x05, 0x05}, {0x05, 0x06}, + {0x04, 0x08}, {0x06, 0x05}, {0x06, 0x05}, {0x06, 0x05}, + {0x06, 0x06}, {0x06, 0x06}, {0x06, 0x06}, {0x06, 0x07}, + {0x05, 0x09}, {0x07, 0x06}, {0x07, 0x06}, {0x08, 0x04}, + {0x07, 0x07}, {0x07, 0x07}, {0x07, 0x07}, {0x07, 0x08}, + {0x07, 0x08}, {0x07, 0x08}, {0x07, 0x09}, {0x08, 0x07}, + {0x08, 0x07}, {0x09, 0x06}, {0x08, 0x08}, {0x08, 0x08}, + {0x08, 0x09}, {0x08, 0x09}, {0x09, 0x08}, {0x09, 0x08}, + {0x09, 0x08}, {0x0a, 0x07}, {0x09, 0x09}, {0x09, 0x09}, + {0x09, 0x0a}, {0x08, 0x0c}, {0x0a, 0x09}, {0x0a, 0x09}, + {0x0a, 0x09}, {0x0a, 0x0a}, {0x0a, 0x0a}, {0x0a, 0x0a}, + {0x0a, 0x0b}, {0x09, 0x0d}, {0x0b, 0x0a}, {0x0b, 0x0a}, + {0x0c, 0x08}, {0x0b, 0x0b}, {0x0b, 0x0b}, {0x0b, 0x0b}, + {0x0b, 0x0c}, {0x0b, 0x0c}, {0x0b, 0x0c}, {0x0b, 0x0d}, + {0x0c, 0x0b}, {0x0c, 0x0b}, {0x0d, 0x0a}, {0x0c, 0x0c}, + {0x0c, 0x0c}, {0x0c, 0x0d}, {0x0c, 0x0d}, {0x0d, 0x0c}, + {0x0d, 0x0c}, {0x0d, 0x0c}, {0x0e, 0x0b}, {0x0d, 0x0d}, + {0x0d, 0x0d}, {0x0d, 0x0e}, {0x0c, 0x10}, {0x0e, 0x0d}, + {0x0e, 0x0d}, {0x0e, 0x0d}, {0x0e, 0x0e}, {0x0e, 0x0e}, + {0x0e, 0x0e}, {0x0e, 0x0f}, {0x0d, 0x11}, {0x0f, 0x0e}, + {0x0f, 0x0e}, {0x10, 0x0c}, {0x0f, 0x0f}, {0x0f, 0x0f}, + {0x0f, 0x0f}, {0x0f, 0x10}, {0x0f, 0x10}, {0x0f, 0x10}, + {0x0f, 0x11}, {0x10, 0x0f}, {0x10, 0x0f}, {0x11, 0x0e}, + {0x10, 0x10}, {0x10, 0x10}, {0x10, 0x11}, {0x10, 0x11}, + {0x11, 0x10}, {0x11, 0x10}, {0x11, 0x10}, {0x12, 0x0f}, + {0x11, 0x11}, {0x11, 0x11}, {0x11, 0x12}, {0x10, 0x14}, + {0x12, 0x11}, {0x12, 0x11}, {0x12, 0x11}, {0x12, 0x12}, + {0x12, 0x12}, {0x12, 0x12}, {0x12, 0x13}, {0x11, 0x15}, + {0x13, 0x12}, {0x13, 0x12}, {0x14, 0x10}, {0x13, 0x13}, + {0x13, 0x13}, {0x13, 0x13}, {0x13, 0x14}, {0x13, 0x14}, + {0x13, 0x14}, {0x13, 0x15}, {0x14, 0x13}, {0x14, 0x13}, + {0x15, 0x12}, {0x14, 0x14}, {0x14, 0x14}, {0x14, 0x15}, + {0x14, 0x15}, {0x15, 0x14}, {0x15, 0x14}, {0x15, 0x14}, + {0x16, 0x13}, {0x15, 0x15}, {0x15, 0x15}, {0x15, 0x16}, + {0x14, 0x18}, {0x16, 0x15}, {0x16, 0x15}, {0x16, 0x15}, + {0x16, 0x16}, {0x16, 0x16}, {0x16, 0x16}, {0x16, 0x17}, + {0x15, 0x19}, {0x17, 0x16}, {0x17, 0x16}, {0x18, 0x14}, + {0x17, 0x17}, {0x17, 0x17}, {0x17, 0x17}, {0x17, 0x18}, + {0x17, 0x18}, {0x17, 0x18}, {0x17, 0x19}, {0x18, 0x17}, + {0x18, 0x17}, {0x19, 0x16}, {0x18, 0x18}, {0x18, 0x18}, + {0x18, 0x19}, {0x18, 0x19}, {0x19, 0x18}, {0x19, 0x18}, + {0x19, 0x18}, {0x1a, 0x17}, {0x19, 0x19}, {0x19, 0x19}, + {0x19, 0x1a}, {0x18, 0x1c}, {0x1a, 0x19}, {0x1a, 0x19}, + {0x1a, 0x19}, {0x1a, 0x1a}, {0x1a, 0x1a}, {0x1a, 0x1a}, + {0x1a, 0x1b}, {0x19, 0x1d}, {0x1b, 0x1a}, {0x1b, 0x1a}, + {0x1c, 0x18}, {0x1b, 0x1b}, {0x1b, 0x1b}, {0x1b, 0x1b}, + {0x1b, 0x1c}, {0x1b, 0x1c}, {0x1b, 0x1c}, {0x1b, 0x1d}, + {0x1c, 0x1b}, {0x1c, 0x1b}, {0x1d, 0x1a}, {0x1c, 0x1c}, + {0x1c, 0x1c}, {0x1c, 0x1d}, {0x1c, 0x1d}, {0x1d, 0x1c}, + {0x1d, 0x1c}, {0x1d, 0x1c}, {0x1e, 0x1b}, {0x1d, 0x1d}, + {0x1d, 0x1d}, {0x1d, 0x1e}, {0x1d, 0x1e}, {0x1e, 0x1d}, + {0x1e, 0x1d}, {0x1e, 0x1d}, {0x1e, 0x1e}, {0x1e, 0x1e}, + {0x1e, 0x1e}, {0x1e, 0x1f}, {0x1e, 0x1f}, {0x1f, 0x1e}, + {0x1f, 0x1e}, {0x1f, 0x1e}, {0x1f, 0x1f}, {0x1f, 0x1f}, }; static const unsigned char omatch6[256][2] = { - {0x00, 0x00}, {0x00, 0x01}, {0x01, 0x00}, {0x01, 0x01}, - {0x01, 0x01}, {0x01, 0x02}, {0x02, 0x01}, {0x02, 0x02}, - {0x02, 0x02}, {0x02, 0x03}, {0x03, 0x02}, {0x03, 0x03}, - {0x03, 0x03}, {0x03, 0x04}, {0x04, 0x03}, {0x04, 0x04}, - {0x04, 0x04}, {0x04, 0x05}, {0x05, 0x04}, {0x05, 0x05}, - {0x05, 0x05}, {0x05, 0x06}, {0x06, 0x05}, {0x00, 0x11}, - {0x06, 0x06}, {0x06, 0x07}, {0x07, 0x06}, {0x02, 0x10}, - {0x07, 0x07}, {0x07, 0x08}, {0x08, 0x07}, {0x03, 0x11}, - {0x08, 0x08}, {0x08, 0x09}, {0x09, 0x08}, {0x05, 0x10}, - {0x09, 0x09}, {0x09, 0x0a}, {0x0a, 0x09}, {0x06, 0x11}, - {0x0a, 0x0a}, {0x0a, 0x0b}, {0x0b, 0x0a}, {0x08, 0x10}, - {0x0b, 0x0b}, {0x0b, 0x0c}, {0x0c, 0x0b}, {0x09, 0x11}, - {0x0c, 0x0c}, {0x0c, 0x0d}, {0x0d, 0x0c}, {0x0b, 0x10}, - {0x0d, 0x0d}, {0x0d, 0x0e}, {0x0e, 0x0d}, {0x0c, 0x11}, - {0x0e, 0x0e}, {0x0e, 0x0f}, {0x0f, 0x0e}, {0x0e, 0x10}, - {0x0f, 0x0f}, {0x0f, 0x10}, {0x10, 0x0e}, {0x10, 0x0f}, - {0x11, 0x0e}, {0x10, 0x10}, {0x10, 0x11}, {0x11, 0x10}, - {0x12, 0x0f}, {0x11, 0x11}, {0x11, 0x12}, {0x12, 0x11}, - {0x14, 0x0e}, {0x12, 0x12}, {0x12, 0x13}, {0x13, 0x12}, - {0x15, 0x0f}, {0x13, 0x13}, {0x13, 0x14}, {0x14, 0x13}, - {0x17, 0x0e}, {0x14, 0x14}, {0x14, 0x15}, {0x15, 0x14}, - {0x18, 0x0f}, {0x15, 0x15}, {0x15, 0x16}, {0x16, 0x15}, - {0x1a, 0x0e}, {0x16, 0x16}, {0x16, 0x17}, {0x17, 0x16}, - {0x1b, 0x0f}, {0x17, 0x17}, {0x17, 0x18}, {0x18, 0x17}, - {0x13, 0x21}, {0x18, 0x18}, {0x18, 0x19}, {0x19, 0x18}, - {0x15, 0x20}, {0x19, 0x19}, {0x19, 0x1a}, {0x1a, 0x19}, - {0x16, 0x21}, {0x1a, 0x1a}, {0x1a, 0x1b}, {0x1b, 0x1a}, - {0x18, 0x20}, {0x1b, 0x1b}, {0x1b, 0x1c}, {0x1c, 0x1b}, - {0x19, 0x21}, {0x1c, 0x1c}, {0x1c, 0x1d}, {0x1d, 0x1c}, - {0x1b, 0x20}, {0x1d, 0x1d}, {0x1d, 0x1e}, {0x1e, 0x1d}, - {0x1c, 0x21}, {0x1e, 0x1e}, {0x1e, 0x1f}, {0x1f, 0x1e}, - {0x1e, 0x20}, {0x1f, 0x1f}, {0x1f, 0x20}, {0x20, 0x1e}, - {0x20, 0x1f}, {0x21, 0x1e}, {0x20, 0x20}, {0x20, 0x21}, - {0x21, 0x20}, {0x22, 0x1f}, {0x21, 0x21}, {0x21, 0x22}, - {0x22, 0x21}, {0x24, 0x1e}, {0x22, 0x22}, {0x22, 0x23}, - {0x23, 0x22}, {0x25, 0x1f}, {0x23, 0x23}, {0x23, 0x24}, - {0x24, 0x23}, {0x27, 0x1e}, {0x24, 0x24}, {0x24, 0x25}, - {0x25, 0x24}, {0x28, 0x1f}, {0x25, 0x25}, {0x25, 0x26}, - {0x26, 0x25}, {0x2a, 0x1e}, {0x26, 0x26}, {0x26, 0x27}, - {0x27, 0x26}, {0x2b, 0x1f}, {0x27, 0x27}, {0x27, 0x28}, - {0x28, 0x27}, {0x23, 0x31}, {0x28, 0x28}, {0x28, 0x29}, - {0x29, 0x28}, {0x25, 0x30}, {0x29, 0x29}, {0x29, 0x2a}, - {0x2a, 0x29}, {0x26, 0x31}, {0x2a, 0x2a}, {0x2a, 0x2b}, - {0x2b, 0x2a}, {0x28, 0x30}, {0x2b, 0x2b}, {0x2b, 0x2c}, - {0x2c, 0x2b}, {0x29, 0x31}, {0x2c, 0x2c}, {0x2c, 0x2d}, - {0x2d, 0x2c}, {0x2b, 0x30}, {0x2d, 0x2d}, {0x2d, 0x2e}, - {0x2e, 0x2d}, {0x2c, 0x31}, {0x2e, 0x2e}, {0x2e, 0x2f}, - {0x2f, 0x2e}, {0x2e, 0x30}, {0x2f, 0x2f}, {0x2f, 0x30}, - {0x30, 0x2e}, {0x30, 0x2f}, {0x31, 0x2e}, {0x30, 0x30}, - {0x30, 0x31}, {0x31, 0x30}, {0x32, 0x2f}, {0x31, 0x31}, - {0x31, 0x32}, {0x32, 0x31}, {0x34, 0x2e}, {0x32, 0x32}, - {0x32, 0x33}, {0x33, 0x32}, {0x35, 0x2f}, {0x33, 0x33}, - {0x33, 0x34}, {0x34, 0x33}, {0x37, 0x2e}, {0x34, 0x34}, - {0x34, 0x35}, {0x35, 0x34}, {0x38, 0x2f}, {0x35, 0x35}, - {0x35, 0x36}, {0x36, 0x35}, {0x3a, 0x2e}, {0x36, 0x36}, - {0x36, 0x37}, {0x37, 0x36}, {0x3b, 0x2f}, {0x37, 0x37}, - {0x37, 0x38}, {0x38, 0x37}, {0x3d, 0x2e}, {0x38, 0x38}, - {0x38, 0x39}, {0x39, 0x38}, {0x3e, 0x2f}, {0x39, 0x39}, - {0x39, 0x3a}, {0x3a, 0x39}, {0x3a, 0x3a}, {0x3a, 0x3a}, - {0x3a, 0x3b}, {0x3b, 0x3a}, {0x3b, 0x3b}, {0x3b, 0x3b}, - {0x3b, 0x3c}, {0x3c, 0x3b}, {0x3c, 0x3c}, {0x3c, 0x3c}, - {0x3c, 0x3d}, {0x3d, 0x3c}, {0x3d, 0x3d}, {0x3d, 0x3d}, - {0x3d, 0x3e}, {0x3e, 0x3d}, {0x3e, 0x3e}, {0x3e, 0x3e}, - {0x3e, 0x3f}, {0x3f, 0x3e}, {0x3f, 0x3f}, {0x3f, 0x3f}, + {0x00, 0x00}, {0x00, 0x01}, {0x01, 0x00}, {0x01, 0x01}, + {0x01, 0x01}, {0x01, 0x02}, {0x02, 0x01}, {0x02, 0x02}, + {0x02, 0x02}, {0x02, 0x03}, {0x03, 0x02}, {0x03, 0x03}, + {0x03, 0x03}, {0x03, 0x04}, {0x04, 0x03}, {0x04, 0x04}, + {0x04, 0x04}, {0x04, 0x05}, {0x05, 0x04}, {0x05, 0x05}, + {0x05, 0x05}, {0x05, 0x06}, {0x06, 0x05}, {0x00, 0x11}, + {0x06, 0x06}, {0x06, 0x07}, {0x07, 0x06}, {0x02, 0x10}, + {0x07, 0x07}, {0x07, 0x08}, {0x08, 0x07}, {0x03, 0x11}, + {0x08, 0x08}, {0x08, 0x09}, {0x09, 0x08}, {0x05, 0x10}, + {0x09, 0x09}, {0x09, 0x0a}, {0x0a, 0x09}, {0x06, 0x11}, + {0x0a, 0x0a}, {0x0a, 0x0b}, {0x0b, 0x0a}, {0x08, 0x10}, + {0x0b, 0x0b}, {0x0b, 0x0c}, {0x0c, 0x0b}, {0x09, 0x11}, + {0x0c, 0x0c}, {0x0c, 0x0d}, {0x0d, 0x0c}, {0x0b, 0x10}, + {0x0d, 0x0d}, {0x0d, 0x0e}, {0x0e, 0x0d}, {0x0c, 0x11}, + {0x0e, 0x0e}, {0x0e, 0x0f}, {0x0f, 0x0e}, {0x0e, 0x10}, + {0x0f, 0x0f}, {0x0f, 0x10}, {0x10, 0x0e}, {0x10, 0x0f}, + {0x11, 0x0e}, {0x10, 0x10}, {0x10, 0x11}, {0x11, 0x10}, + {0x12, 0x0f}, {0x11, 0x11}, {0x11, 0x12}, {0x12, 0x11}, + {0x14, 0x0e}, {0x12, 0x12}, {0x12, 0x13}, {0x13, 0x12}, + {0x15, 0x0f}, {0x13, 0x13}, {0x13, 0x14}, {0x14, 0x13}, + {0x17, 0x0e}, {0x14, 0x14}, {0x14, 0x15}, {0x15, 0x14}, + {0x18, 0x0f}, {0x15, 0x15}, {0x15, 0x16}, {0x16, 0x15}, + {0x1a, 0x0e}, {0x16, 0x16}, {0x16, 0x17}, {0x17, 0x16}, + {0x1b, 0x0f}, {0x17, 0x17}, {0x17, 0x18}, {0x18, 0x17}, + {0x13, 0x21}, {0x18, 0x18}, {0x18, 0x19}, {0x19, 0x18}, + {0x15, 0x20}, {0x19, 0x19}, {0x19, 0x1a}, {0x1a, 0x19}, + {0x16, 0x21}, {0x1a, 0x1a}, {0x1a, 0x1b}, {0x1b, 0x1a}, + {0x18, 0x20}, {0x1b, 0x1b}, {0x1b, 0x1c}, {0x1c, 0x1b}, + {0x19, 0x21}, {0x1c, 0x1c}, {0x1c, 0x1d}, {0x1d, 0x1c}, + {0x1b, 0x20}, {0x1d, 0x1d}, {0x1d, 0x1e}, {0x1e, 0x1d}, + {0x1c, 0x21}, {0x1e, 0x1e}, {0x1e, 0x1f}, {0x1f, 0x1e}, + {0x1e, 0x20}, {0x1f, 0x1f}, {0x1f, 0x20}, {0x20, 0x1e}, + {0x20, 0x1f}, {0x21, 0x1e}, {0x20, 0x20}, {0x20, 0x21}, + {0x21, 0x20}, {0x22, 0x1f}, {0x21, 0x21}, {0x21, 0x22}, + {0x22, 0x21}, {0x24, 0x1e}, {0x22, 0x22}, {0x22, 0x23}, + {0x23, 0x22}, {0x25, 0x1f}, {0x23, 0x23}, {0x23, 0x24}, + {0x24, 0x23}, {0x27, 0x1e}, {0x24, 0x24}, {0x24, 0x25}, + {0x25, 0x24}, {0x28, 0x1f}, {0x25, 0x25}, {0x25, 0x26}, + {0x26, 0x25}, {0x2a, 0x1e}, {0x26, 0x26}, {0x26, 0x27}, + {0x27, 0x26}, {0x2b, 0x1f}, {0x27, 0x27}, {0x27, 0x28}, + {0x28, 0x27}, {0x23, 0x31}, {0x28, 0x28}, {0x28, 0x29}, + {0x29, 0x28}, {0x25, 0x30}, {0x29, 0x29}, {0x29, 0x2a}, + {0x2a, 0x29}, {0x26, 0x31}, {0x2a, 0x2a}, {0x2a, 0x2b}, + {0x2b, 0x2a}, {0x28, 0x30}, {0x2b, 0x2b}, {0x2b, 0x2c}, + {0x2c, 0x2b}, {0x29, 0x31}, {0x2c, 0x2c}, {0x2c, 0x2d}, + {0x2d, 0x2c}, {0x2b, 0x30}, {0x2d, 0x2d}, {0x2d, 0x2e}, + {0x2e, 0x2d}, {0x2c, 0x31}, {0x2e, 0x2e}, {0x2e, 0x2f}, + {0x2f, 0x2e}, {0x2e, 0x30}, {0x2f, 0x2f}, {0x2f, 0x30}, + {0x30, 0x2e}, {0x30, 0x2f}, {0x31, 0x2e}, {0x30, 0x30}, + {0x30, 0x31}, {0x31, 0x30}, {0x32, 0x2f}, {0x31, 0x31}, + {0x31, 0x32}, {0x32, 0x31}, {0x34, 0x2e}, {0x32, 0x32}, + {0x32, 0x33}, {0x33, 0x32}, {0x35, 0x2f}, {0x33, 0x33}, + {0x33, 0x34}, {0x34, 0x33}, {0x37, 0x2e}, {0x34, 0x34}, + {0x34, 0x35}, {0x35, 0x34}, {0x38, 0x2f}, {0x35, 0x35}, + {0x35, 0x36}, {0x36, 0x35}, {0x3a, 0x2e}, {0x36, 0x36}, + {0x36, 0x37}, {0x37, 0x36}, {0x3b, 0x2f}, {0x37, 0x37}, + {0x37, 0x38}, {0x38, 0x37}, {0x3d, 0x2e}, {0x38, 0x38}, + {0x38, 0x39}, {0x39, 0x38}, {0x3e, 0x2f}, {0x39, 0x39}, + {0x39, 0x3a}, {0x3a, 0x39}, {0x3a, 0x3a}, {0x3a, 0x3a}, + {0x3a, 0x3b}, {0x3b, 0x3a}, {0x3b, 0x3b}, {0x3b, 0x3b}, + {0x3b, 0x3c}, {0x3c, 0x3b}, {0x3c, 0x3c}, {0x3c, 0x3c}, + {0x3c, 0x3d}, {0x3d, 0x3c}, {0x3d, 0x3d}, {0x3d, 0x3d}, + {0x3d, 0x3e}, {0x3e, 0x3d}, {0x3e, 0x3e}, {0x3e, 0x3e}, + {0x3e, 0x3f}, {0x3f, 0x3e}, {0x3f, 0x3f}, {0x3f, 0x3f}, }; -#endif +#endif /* __DXT_TABLES_H__ */ diff --git a/plug-ins/file-dds/endian_rw.h b/plug-ins/file-dds/endian_rw.h index 97d1f60c81..1d0b5fcd35 100644 --- a/plug-ins/file-dds/endian_rw.h +++ b/plug-ins/file-dds/endian_rw.h @@ -1,71 +1,69 @@ -/* - DDS GIMP plugin - - Copyright (C) 2004-2012 Shawn Kirst , - with parts (C) 2003 Arne Reuter 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 ENDIAN_RW_H -#define ENDIAN_RW_H - -#define GETL64(buf) \ - (((unsigned long long)(buf)[0] ) | \ - ((unsigned long long)(buf)[1] << 8) | \ - ((unsigned long long)(buf)[2] << 16) | \ - ((unsigned long long)(buf)[3] << 24) | \ - ((unsigned long long)(buf)[4] << 32) | \ - ((unsigned long long)(buf)[5] << 40) | \ - ((unsigned long long)(buf)[6] << 48) | \ - ((unsigned long long)(buf)[7] << 56)) - -#define GETL32(buf) \ - (((unsigned int)(buf)[0] ) | \ - ((unsigned int)(buf)[1] << 8) | \ - ((unsigned int)(buf)[2] << 16) | \ - ((unsigned int)(buf)[3] << 24)) - -#define GETL24(buf) \ - (((unsigned int)(buf)[0] ) | \ - ((unsigned int)(buf)[1] << 8) | \ - ((unsigned int)(buf)[2] << 16)) - -#define GETL16(buf) \ - (((unsigned short)(buf)[0] ) | \ - ((unsigned short)(buf)[1] << 8)) - -#define PUTL16(buf, s) \ - (buf)[0] = ((s) ) & 0xff; \ - (buf)[1] = ((s) >> 8) & 0xff; - -#define PUTL32(buf, l) \ - (buf)[0] = ((l) ) & 0xff; \ - (buf)[1] = ((l) >> 8) & 0xff; \ - (buf)[2] = ((l) >> 16) & 0xff; \ - (buf)[3] = ((l) >> 24) & 0xff; - -#define PUTL64(buf, ll) \ - (buf)[0] = ((ll) ) & 0xff; \ - (buf)[1] = ((ll) >> 8) & 0xff; \ - (buf)[2] = ((ll) >> 16) & 0xff; \ - (buf)[3] = ((ll) >> 24) & 0xff; \ - (buf)[4] = ((ll) >> 32) & 0xff; \ - (buf)[5] = ((ll) >> 40) & 0xff; \ - (buf)[6] = ((ll) >> 48) & 0xff; \ - (buf)[7] = ((ll) >> 56) & 0xff; - -#endif +/* + * DDS GIMP plugin + * + * Copyright (C) 2004-2012 Shawn Kirst , + * with parts (C) 2003 Arne Reuter 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 3 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. If not, see . + */ + +#ifndef __ENDIAN_RW_H__ +#define __ENDIAN_RW_H__ + +#define GETL64(buf) \ + (((unsigned long long)(buf)[0] ) | \ + ((unsigned long long)(buf)[1] << 8) | \ + ((unsigned long long)(buf)[2] << 16) | \ + ((unsigned long long)(buf)[3] << 24) | \ + ((unsigned long long)(buf)[4] << 32) | \ + ((unsigned long long)(buf)[5] << 40) | \ + ((unsigned long long)(buf)[6] << 48) | \ + ((unsigned long long)(buf)[7] << 56)) + +#define GETL32(buf) \ + (((unsigned int)(buf)[0] ) | \ + ((unsigned int)(buf)[1] << 8) | \ + ((unsigned int)(buf)[2] << 16) | \ + ((unsigned int)(buf)[3] << 24)) + +#define GETL24(buf) \ + (((unsigned int)(buf)[0] ) | \ + ((unsigned int)(buf)[1] << 8) | \ + ((unsigned int)(buf)[2] << 16)) + +#define GETL16(buf) \ + (((unsigned short)(buf)[0] ) | \ + ((unsigned short)(buf)[1] << 8)) + +#define PUTL16(buf, s) \ + (buf)[0] = ((s) ) & 0xff; \ + (buf)[1] = ((s) >> 8) & 0xff; + +#define PUTL32(buf, l) \ + (buf)[0] = ((l) ) & 0xff; \ + (buf)[1] = ((l) >> 8) & 0xff; \ + (buf)[2] = ((l) >> 16) & 0xff; \ + (buf)[3] = ((l) >> 24) & 0xff; + +#define PUTL64(buf, ll) \ + (buf)[0] = ((ll) ) & 0xff; \ + (buf)[1] = ((ll) >> 8) & 0xff; \ + (buf)[2] = ((ll) >> 16) & 0xff; \ + (buf)[3] = ((ll) >> 24) & 0xff; \ + (buf)[4] = ((ll) >> 32) & 0xff; \ + (buf)[5] = ((ll) >> 40) & 0xff; \ + (buf)[6] = ((ll) >> 48) & 0xff; \ + (buf)[7] = ((ll) >> 56) & 0xff; + +#endif /* __ENDIAN_RW_H__ */ diff --git a/plug-ins/file-dds/imath.h b/plug-ins/file-dds/imath.h index 6f4dbc759f..785c16d44d 100644 --- a/plug-ins/file-dds/imath.h +++ b/plug-ins/file-dds/imath.h @@ -1,27 +1,25 @@ /* - DDS GIMP plugin + * DDS GIMP plugin + * + * Copyright (C) 2004-2012 Shawn Kirst , + * with parts (C) 2003 Arne Reuter 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 3 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. If not, see . + */ - Copyright (C) 2004-2012 Shawn Kirst , - with parts (C) 2003 Arne Reuter 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 IMATH_H -#define IMATH_H +#ifndef __IMATH_H__ +#define __IMATH_H__ #ifndef MIN # ifdef __GNUC__ @@ -45,23 +43,35 @@ /* round integer x up to next multiple of 4 */ #define RND_MUL4(x) ((x) + (4 - ((x) & 3))) -static inline int mul8bit(int a, int b) +static inline int +mul8bit (int a, + int b) { - int t = a * b + 128; - return((t + (t >> 8)) >> 8); + int t = a * b + 128; + + return (t + (t >> 8)) >> 8; } -static inline int blerp(int a, int b, int x) +static inline int +blerp (int a, + int b, + int x) { - return(a + mul8bit(b - a, x)); + return a + mul8bit(b - a, x); } -static inline int icerp(int a, int b, int c, int d, int x) +static inline int +icerp (int a, + int b, + int c, + int d, + int x) { - int p = (d - c) - (a - b); - int q = (a - b) - p; - int r = c - a; - return((x * (x * (x * p + (q << 7)) + (r << 14)) + (b << 21)) >> 21); + int p = (d - c) - (a - b); + int q = (a - b) - p; + int r = c - a; + + return (x * (x * (x * p + (q << 7)) + (r << 14)) + (b << 21)) >> 21; } -#endif +#endif /* __IMATH_H__ */ diff --git a/plug-ins/file-dds/mipmap.c b/plug-ins/file-dds/mipmap.c index fda90ff1ec..a1ad0c1359 100644 --- a/plug-ins/file-dds/mipmap.c +++ b/plug-ins/file-dds/mipmap.c @@ -1,24 +1,24 @@ /* - DDS GIMP plugin - - Copyright (C) 2004-2012 Shawn Kirst , - with parts (C) 2003 Arne Reuter 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 , + * with parts (C) 2003 Arne Reuter 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 #include @@ -45,377 +45,453 @@ typedef void (*volmipmapfunc_t)(unsigned char *, int, int, int, unsigned char * * size functions * ******************************************************************************/ -int get_num_mipmaps(int width, int height) +int +get_num_mipmaps (int width, + int height) { - int w = width << 1; - int h = height << 1; - int n = 0; + int w = width << 1; + int h = height << 1; + int n = 0; - while(w != 1 || h != 1) - { - if(w > 1) w >>= 1; - if(h > 1) h >>= 1; + while (w != 1 || h != 1) + { + if (w > 1) w >>= 1; + if (h > 1) h >>= 1; ++n; - } + } - return(n); + return n; } -unsigned int get_mipmapped_size(int width, int height, int bpp, - int level, int num, int format) +unsigned int +get_mipmapped_size (int width, + int height, + int bpp, + int level, + int num, + int format) { - int w, h, n = 0; - unsigned int size = 0; + int w, h, n = 0; + unsigned int size = 0; - w = width >> level; - h = height >> level; - w = MAX(1, w); - h = MAX(1, h); - w <<= 1; - h <<= 1; + w = width >> level; + h = height >> level; + w = MAX(1, w); + h = MAX(1, h); + w <<= 1; + h <<= 1; - while(n < num && (w != 1 || h != 1)) - { - if(w > 1) w >>= 1; - if(h > 1) h >>= 1; - if(format == DDS_COMPRESS_NONE) - size += (w * h); + while (n < num && (w != 1 || h != 1)) + { + if (w > 1) w >>= 1; + if (h > 1) h >>= 1; + if (format == DDS_COMPRESS_NONE) + size += (w * h); else - size += ((w + 3) >> 2) * ((h + 3) >> 2); + size += ((w + 3) >> 2) * ((h + 3) >> 2); ++n; - } + } - if(format == DDS_COMPRESS_NONE) + if (format == DDS_COMPRESS_NONE) + { size *= bpp; - else - { - if(format == DDS_COMPRESS_BC1 || format == DDS_COMPRESS_BC4) - size *= 8; + } + else + { + if (format == DDS_COMPRESS_BC1 || format == DDS_COMPRESS_BC4) + size *= 8; else - size *= 16; - } + size *= 16; + } - return(size); + return size; } -unsigned int get_volume_mipmapped_size(int width, int height, - int depth, int bpp, int level, - int num, int format) +unsigned int +get_volume_mipmapped_size (int width, + int height, + int depth, + int bpp, + int level, + int num, + int format) { - int w, h, d, n = 0; - unsigned int size = 0; + int w, h, d, n = 0; + unsigned int size = 0; - w = width >> level; - h = height >> level; - d = depth >> level; - w = MAX(1, w); - h = MAX(1, h); - d = MAX(1, d); - w <<= 1; - h <<= 1; - d <<= 1; + w = width >> level; + h = height >> level; + d = depth >> level; + w = MAX(1, w); + h = MAX(1, h); + d = MAX(1, d); + w <<= 1; + h <<= 1; + d <<= 1; - while(n < num && (w != 1 || h != 1)) - { - if(w > 1) w >>= 1; - if(h > 1) h >>= 1; - if(d > 1) d >>= 1; - if(format == DDS_COMPRESS_NONE) - size += (w * h * d); + while (n < num && (w != 1 || h != 1)) + { + if (w > 1) w >>= 1; + if (h > 1) h >>= 1; + if (d > 1) d >>= 1; + if (format == DDS_COMPRESS_NONE) + size += (w * h * d); else - size += (((w + 3) >> 2) * ((h + 3) >> 2) * d); + size += (((w + 3) >> 2) * ((h + 3) >> 2) * d); ++n; - } + } - if(format == DDS_COMPRESS_NONE) + if (format == DDS_COMPRESS_NONE) + { size *= bpp; - else - { - if(format == DDS_COMPRESS_BC1 || format == DDS_COMPRESS_BC4) - size *= 8; + } + else + { + if (format == DDS_COMPRESS_BC1 || format == DDS_COMPRESS_BC4) + size *= 8; else - size *= 16; - } + size *= 16; + } - return(size); + return size; } -int get_next_mipmap_dimensions(int *next_w, int *next_h, - int curr_w, int curr_h) +int +get_next_mipmap_dimensions (int *next_w, + int *next_h, + int curr_w, + int curr_h) { - if(curr_w == 1 || curr_h == 1) - return(0); + if (curr_w == 1 || curr_h == 1) + return 0; - if(next_w) *next_w = curr_w >> 1; - if(next_h) *next_h = curr_h >> 1; + if (next_w) *next_w = curr_w >> 1; + if (next_h) *next_h = curr_h >> 1; - return(1); + return 1; } /****************************************************************************** * wrap modes * ******************************************************************************/ -static int wrap_mirror(int x, int max) +static int +wrap_mirror (int x, + int max) { - if(max == 1) x = 0; - x = abs(x); - while(x >= max) - x = abs(max + max - x - 2); - return(x); + if (max == 1) x = 0; + x = abs(x); + while (x >= max) + x = abs(max + max - x - 2); + + return x; } -static int wrap_repeat(int x, int max) +static int +wrap_repeat (int x, + int max) { - if(x >= 0) return(x % max); - return((x + 1) % max + max - 1); + if (x >= 0) + return x % max; + + return (x + 1) % max + max - 1; } -static int wrap_clamp(int x, int max) +static int +wrap_clamp (int x, + int max) { - return(MAX(0, MIN(max - 1, x))); + return MAX(0, MIN(max - 1, x)); } /****************************************************************************** * gamma-correction * ******************************************************************************/ -static int linear_to_gamma(int gc, int v, float gamma) +static int +linear_to_gamma (int gc, + int v, + float gamma) { - if(gc == 1) - { + if (gc == 1) + { v = (int)(powf((float)v / 255.0f, gamma) * 255); - if(v > 255) v = 255; - } - else if(gc == 2) + if (v > 255) v = 255; + } + else if (gc == 2) + { v = linear_to_sRGB(v); + } - return(v); + return v; } -static int gamma_to_linear(int gc, int v, float gamma) +static int +gamma_to_linear (int gc, + int v, + float gamma) { - if(gc == 1) - { + if (gc == 1) + { v = (int)(powf((float)v / 255.0f, 1.0f / gamma) * 255); if(v > 255) v = 255; - } - else if(gc == 2) + } + else if (gc == 2) + { v = sRGB_to_linear(v); + } - return(v); + return v; } /****************************************************************************** * filters * ******************************************************************************/ -static float box_filter(float t) +static float +box_filter (float t) { - if((t >= -0.5f) && (t < 0.5f)) - return(1.0f); + if ((t >= -0.5f) && (t < 0.5f)) + return 1.0f; - return(0.0f); + return 0.0f; } -static float triangle_filter(float t) +static float +triangle_filter (float t) { - if(t < 0.0f) t = -t; - if(t < 1.0f) return(1.0f - t); - return(0.0f); + if (t < 0.0f) t = -t; + if (t < 1.0f) return 1.0f - t; + + return 0.0f; } -static float quadratic_filter(float t) +static float +quadratic_filter (float t) { - if(t < 0.0f) t = -t; - if(t < 0.5f) return(0.75f - t * t); - if(t < 1.5f) - { + if (t < 0.0f) t = -t; + if (t < 0.5f) return 0.75f - t * t; + if (t < 1.5f) + { t -= 1.5f; - return(0.5f * t * t); - } - return(0.0f); + return 0.5f * t * t; + } + + return 0.0f; } -static float bspline_filter(float t) +static float +bspline_filter (float t) { - float tt; + float tt; - if(t < 0.0f) t = -t; + if (t < 0.0f) + t = -t; - if(t < 1.0f) - { + if (t < 1.0f) + { tt = t * t; - return(((0.5f * tt * t) - tt + (2.0f / 3.0f))); - } - else if(t < 2.0f) - { + return ((0.5f * tt * t) - tt + (2.0f / 3.0f)); + } + else if (t < 2.0f) + { t = 2.0f - t; - return((1.0f / 6.0f) * (t * t * t)); - } + return (1.0f / 6.0f) * (t * t * t); + } - return(0.0f); + return 0.0f; } -static float mitchell(float t, const float B, const float C) +static float +mitchell (float t, + const float B, + const float C) { - float tt; + float tt; - tt = t * t; - if(t < 0.0f) t = -t; + tt = t * t; + if (t < 0.0f) + t = -t; - if(t < 1.0f) - { + if (t < 1.0f) + { t = (((12.0f - 9.0f * B - 6.0f * C) * (t * tt)) + - ((-18.0f + 12.0f * B + 6.0f * C) * tt) + - (6.0f - 2.0f * B)); - return(t / 6.0f); - } - else if(t < 2.0f) - { + ((-18.0f + 12.0f * B + 6.0f * C) * tt) + + (6.0f - 2.0f * B)); + + return t / 6.0f; + } + else if (t < 2.0f) + { t = (((-1.0f * B - 6.0f * C) * (t * tt)) + - ((6.0f * B + 30.0f * C) * tt) + - ((-12.0f * B - 48.0f * C) * t) + - (8.0f * B + 24.0f * C)); - return(t / 6.0f); - } + ((6.0f * B + 30.0f * C) * tt) + + ((-12.0f * B - 48.0f * C) * t) + + (8.0f * B + 24.0f * C)); - return(0.0f); + return t / 6.0f; + } + + return 0.0f; } -static float mitchell_filter(float t) +static float +mitchell_filter (float t) { - return(mitchell(t, 1.0f / 3.0f, 1.0f / 3.0f)); + return mitchell(t, 1.0f / 3.0f, 1.0f / 3.0f); } -static float sinc(float x) +static float +sinc (float x) { - x = (x * M_PI); - if(fabsf(x) < 1e-04f) - return(1.0f + x * x * (-1.0f / 6.0f + x * x * 1.0f / 120.0f)); + x = (x * M_PI); + if (fabsf(x) < 1e-04f) + return 1.0f + x * x * (-1.0f / 6.0f + x * x * 1.0f / 120.0f); - return(sinf(x) / x); + return sinf(x) / x; } -static float lanczos_filter(float t) +static float +lanczos_filter (float t) { - if(t < 0.0f) t = -t; - if(t < 3.0f) return(sinc(t) * sinc(t / 3.0f)); - return(0.0f); + if (t < 0.0f) t = -t; + if (t < 3.0f) return sinc(t) * sinc(t / 3.0f); + + return 0.0f; } -static float bessel0(float x) +static float +bessel0 (float x) { - const float EPSILON = 1e-6f; - float xh, sum, pow, ds; - int k; + const float EPSILON = 1e-6f; + float xh, sum, pow, ds; + int k; - xh = 0.5f * x; - sum = 1.0f; - pow = 1.0f; - k = 0; - ds = 1.0f; - while(ds > sum * EPSILON) - { + xh = 0.5f * x; + sum = 1.0f; + pow = 1.0f; + k = 0; + ds = 1.0f; + + while (ds > sum * EPSILON) + { ++k; pow = pow * (xh / k); ds = pow * pow; sum += ds; - } + } - return(sum); + return sum; } -static float kaiser_filter(float t) +static float +kaiser_filter (float t) { - if(t < 0.0f) t = -t; + if (t < 0.0f) t = -t; - if(t < 3.0f) - { + if (t < 3.0f) + { const float alpha = 4.0f; const float rb04 = 0.0884805322f; // 1.0f / bessel0(4.0f); const float ratio = t / 3.0f; - if((1.0f - ratio * ratio) >= 0) - return(sinc(t) * bessel0(alpha * sqrtf(1.0f - ratio * ratio)) * rb04); - } - return(0.0f); + if ((1.0f - ratio * ratio) >= 0) + return sinc(t) * bessel0(alpha * sqrtf(1.0f - ratio * ratio)) * rb04; + } + + return 0.0f; } /****************************************************************************** * 2D image scaling * ******************************************************************************/ -static void scale_image_nearest(unsigned char *dst, int dw, int dh, - unsigned char *src, int sw, int sh, - int bpp, filterfunc_t filter, float support, - wrapfunc_t wrap, - int gc, float gamma) +static void +scale_image_nearest (unsigned char *dst, + int dw, + int dh, + unsigned char *src, + int sw, + int sh, + int bpp, + filterfunc_t filter, + float support, + wrapfunc_t wrap, + int gc, + float gamma) { - int n, x, y; - int ix, iy; - int srowbytes = sw * bpp; - int drowbytes = dw * bpp; + int n, x, y; + int ix, iy; + int srowbytes = sw * bpp; + int drowbytes = dw * bpp; - for(y = 0; y < dh; ++y) - { + for (y = 0; y < dh; ++y) + { iy = (y * sh + sh / 2) / dh; - for(x = 0; x < dw; ++x) - { - ix = (x * sw + sw / 2) / dw; - for(n = 0; n < bpp; ++n) - { - dst[y * drowbytes + (x * bpp) + n] = - src[iy * srowbytes + (ix * bpp) + n]; - } - } - } + for (x = 0; x < dw; ++x) + { + ix = (x * sw + sw / 2) / dw; + for (n = 0; n < bpp; ++n) + { + dst[y * drowbytes + (x * bpp) + n] = + src[iy * srowbytes + (ix * bpp) + n]; + } + } + } } -static void scale_image(unsigned char *dst, int dw, int dh, - unsigned char *src, int sw, int sh, - int bpp, filterfunc_t filter, float support, - wrapfunc_t wrap, - int gc, float gamma) +static void +scale_image (unsigned char *dst, + int dw, + int dh, + unsigned char *src, + int sw, + int sh, + int bpp, + filterfunc_t filter, + float support, + wrapfunc_t wrap, + int gc, + float gamma) { - const float blur = 1.0f; - const float xfactor = (float)dw / (float)sw; - const float yfactor = (float)dh / (float)sh; + const float blur = 1.0f; + const float xfactor = (float)dw / (float)sw; + const float yfactor = (float)dh / (float)sh; - int x, y, start, stop, nmax, n, i; - int sstride = sw * bpp; - float center, contrib, density, s, r, t; + int x, y, start, stop, nmax, n, i; + int sstride = sw * bpp; + float center, contrib, density, s, r, t; - unsigned char *d, *row, *col; + unsigned char *d, *row, *col; - float xscale = MIN(xfactor, 1.0f) / blur; - float yscale = MIN(yfactor, 1.0f) / blur; - float xsupport = support / xscale; - float ysupport = support / yscale; - unsigned char *tmp; + float xscale = MIN(xfactor, 1.0f) / blur; + float yscale = MIN(yfactor, 1.0f) / blur; + float xsupport = support / xscale; + float ysupport = support / yscale; + unsigned char *tmp; - if(xsupport <= 0.5f) - { + if (xsupport <= 0.5f) + { xsupport = 0.5f + 1e-10f; xscale = 1.0f; - } - if(ysupport <= 0.5f) - { + } + + if (ysupport <= 0.5f) + { ysupport = 0.5f + 1e-10f; yscale = 1.0f; - } + } #ifdef _OPENMP - tmp = g_malloc(sw * bpp * omp_get_max_threads()); + tmp = g_malloc(sw * bpp * omp_get_max_threads()); #else - tmp = g_malloc(sw * bpp); + tmp = g_malloc(sw * bpp); #endif #ifdef _OPENMP - #pragma omp parallel for schedule(dynamic) \ - private(x, y, d, row, col, center, start, stop, nmax, s, i, n, density, r, t, contrib) +#pragma omp parallel for schedule(dynamic) \ + private(x, y, d, row, col, center, start, stop, nmax, s, i, n, density, r, t, contrib) #endif - for(y = 0; y < dh; ++y) - { + for (y = 0; y < dh; ++y) + { /* resample in Y direction to temp buffer */ d = tmp; #ifdef _OPENMP @@ -428,168 +504,190 @@ static void scale_image(unsigned char *dst, int dw, int dh, nmax = stop - start; s = (float)start - center + 0.5f; - for(x = 0; x < sw; ++x) - { - col = src + (x * bpp); + for (x = 0; x < sw; ++x) + { + col = src + (x * bpp); - for(i = 0; i < bpp; ++i) - { - density = 0.0f; - r = 0.0f; - - for(n = 0; n < nmax; ++n) + for (i = 0; i < bpp; ++i) { - contrib = filter((s + n) * yscale); - density += contrib; - if(i == 3) - t = col[(wrap(start + n, sh) * sstride) + i]; - else - t = linear_to_gamma(gc, col[(wrap(start + n, sh) * sstride) + i], gamma); - r += t * contrib; + density = 0.0f; + r = 0.0f; + + for (n = 0; n < nmax; ++n) + { + contrib = filter((s + n) * yscale); + density += contrib; + if (i == 3) + t = col[(wrap(start + n, sh) * sstride) + i]; + else + t = linear_to_gamma(gc, col[(wrap(start + n, sh) * sstride) + i], gamma); + r += t * contrib; + } + + if (density != 0.0f && density != 1.0f) + r /= density; + + r = MIN(255, MAX(0, r)); + + if (i != 3) + r = gamma_to_linear(gc, r, gamma); + + d[(x * bpp) + i] = (unsigned char)r; } - - if(density != 0.0f && density != 1.0f) - r /= density; - - r = MIN(255, MAX(0, r)); - - if(i != 3) - r = gamma_to_linear(gc, r, gamma); - - d[(x * bpp) + i] = (unsigned char)r; - } - } + } /* resample in X direction using temp buffer */ row = d; d = dst; - for(x = 0; x < dw; ++x) - { - center = ((float)x + 0.5f) / xfactor; - start = (int)(center - xsupport + 0.5f); - stop = (int)(center + xsupport + 0.5f); - nmax = stop - start; - s = (float)start - center + 0.5f; + for (x = 0; x < dw; ++x) + { + center = ((float)x + 0.5f) / xfactor; + start = (int)(center - xsupport + 0.5f); + stop = (int)(center + xsupport + 0.5f); + nmax = stop - start; + s = (float)start - center + 0.5f; - for(i = 0; i < bpp; ++i) - { - density = 0.0f; - r = 0.0f; - - for(n = 0; n < nmax; ++n) + for (i = 0; i < bpp; ++i) { - contrib = filter((s + n) * xscale); - density += contrib; - if(i == 3) - t = row[(wrap(start + n, sw) * bpp) + i]; - else - t = linear_to_gamma(gc, row[(wrap(start + n, sw) * bpp) + i], gamma); - r += t * contrib; + density = 0.0f; + r = 0.0f; + + for (n = 0; n < nmax; ++n) + { + contrib = filter((s + n) * xscale); + density += contrib; + if (i == 3) + t = row[(wrap(start + n, sw) * bpp) + i]; + else + t = linear_to_gamma(gc, row[(wrap(start + n, sw) * bpp) + i], gamma); + r += t * contrib; + } + + if (density != 0.0f && density != 1.0f) + r /= density; + + r = MIN(255, MAX(0, r)); + + if (i != 3) + r = gamma_to_linear(gc, r, gamma); + + d[(y * (dw * bpp)) + (x * bpp) + i] = (unsigned char)r; } + } + } - if(density != 0.0f && density != 1.0f) - r /= density; - - r = MIN(255, MAX(0, r)); - - if(i != 3) - r = gamma_to_linear(gc, r, gamma); - - d[(y * (dw * bpp)) + (x * bpp) + i] = (unsigned char)r; - } - } - } - - g_free(tmp); + g_free (tmp); } /****************************************************************************** * 3D image scaling * ******************************************************************************/ -static void scale_volume_image_nearest(unsigned char *dst, int dw, int dh, int dd, - unsigned char *src, int sw, int sh, int sd, - int bpp, filterfunc_t filter, float support, - wrapfunc_t wrap, - int gc, float gamma) +static void +scale_volume_image_nearest (unsigned char *dst, + int dw, + int dh, + int dd, + unsigned char *src, + int sw, + int sh, + int sd, + int bpp, + filterfunc_t filter, + float support, + wrapfunc_t wrap, + int gc, + float gamma) { - int n, x, y, z; - int ix, iy, iz; + int n, x, y, z; + int ix, iy, iz; - for(z = 0; z < dd; ++z) - { + for (z = 0; z < dd; ++z) + { iz = (z * sd + sd / 2) / dd; - for(y = 0; y < dh; ++y) - { - iy = (y * sh + sh / 2) / dh; - for(x = 0; x < dw; ++x) - { - ix = (x * sw + sw / 2) / dw; - for(n = 0; n < bpp; ++n) + for (y = 0; y < dh; ++y) + { + iy = (y * sh + sh / 2) / dh; + for (x = 0; x < dw; ++x) { - dst[(z * (dw * dh)) + (y * dw) + (x * bpp) + n] = - src[(iz * (sw * sh)) + (iy * sw) + (ix * bpp) + n]; + ix = (x * sw + sw / 2) / dw; + for (n = 0; n < bpp; ++n) + { + dst[(z * (dw * dh)) + (y * dw) + (x * bpp) + n] = + src[(iz * (sw * sh)) + (iy * sw) + (ix * bpp) + n]; + } } - } - } - } + } + } } -static void scale_volume_image(unsigned char *dst, int dw, int dh, int dd, - unsigned char *src, int sw, int sh, int sd, - int bpp, filterfunc_t filter, float support, - wrapfunc_t wrap, - int gc, float gamma) +static void +scale_volume_image (unsigned char *dst, + int dw, + int dh, + int dd, + unsigned char *src, + int sw, + int sh, + int sd, + int bpp, + filterfunc_t filter, + float support, + wrapfunc_t wrap, + int gc, + float gamma) { - const float blur = 1.0f; - const float xfactor = (float)dw / (float)sw; - const float yfactor = (float)dh / (float)sh; - const float zfactor = (float)dd / (float)sd; + const float blur = 1.0f; + const float xfactor = (float)dw / (float)sw; + const float yfactor = (float)dh / (float)sh; + const float zfactor = (float)dd / (float)sd; - int x, y, z, start, stop, nmax, n, i; - int sstride = sw * bpp; - int zstride = sh * sw * bpp; - float center, contrib, density, s, r, t; + int x, y, z, start, stop, nmax, n, i; + int sstride = sw * bpp; + int zstride = sh * sw * bpp; + float center, contrib, density, s, r, t; - unsigned char *d, *row, *col, *slice; + unsigned char *d, *row, *col, *slice; - float xscale = MIN(xfactor, 1.0f) / blur; - float yscale = MIN(yfactor, 1.0f) / blur; - float zscale = MIN(zfactor, 1.0f) / blur; - float xsupport = support / xscale; - float ysupport = support / yscale; - float zsupport = support / zscale; - unsigned char *tmp1, *tmp2; + float xscale = MIN(xfactor, 1.0f) / blur; + float yscale = MIN(yfactor, 1.0f) / blur; + float zscale = MIN(zfactor, 1.0f) / blur; + float xsupport = support / xscale; + float ysupport = support / yscale; + float zsupport = support / zscale; + unsigned char *tmp1, *tmp2; - /* down to a 2D image, use the faster 2D image resampler */ - if(dd == 1 && sd == 1) - { + /* down to a 2D image, use the faster 2D image resampler */ + if (dd == 1 && sd == 1) + { scale_image(dst, dw, dh, src, sw, sh, bpp, filter, support, wrap, gc, gamma); return; - } + } - if(xsupport <= 0.5f) - { + if (xsupport <= 0.5f) + { xsupport = 0.5f + 1e-10f; xscale = 1.0f; - } - if(ysupport <= 0.5f) - { + } + + if (ysupport <= 0.5f) + { ysupport = 0.5f + 1e-10f; yscale = 1.0f; - } - if(zsupport <= 0.5f) - { + } + + if (zsupport <= 0.5f) + { zsupport = 0.5f + 1e-10f; zscale = 1.0f; - } + } - tmp1 = g_malloc(sh * sw * bpp); - tmp2 = g_malloc(dh * sw * bpp); + tmp1 = g_malloc(sh * sw * bpp); + tmp2 = g_malloc(dh * sw * bpp); - for(z = 0; z < dd; ++z) - { + for (z = 0; z < dd; ++z) + { /* resample in Z direction */ d = tmp1; @@ -599,142 +697,142 @@ static void scale_volume_image(unsigned char *dst, int dw, int dh, int dd, nmax = stop - start; s = (float)start - center + 0.5f; - #ifdef _OPENMP - #pragma omp parallel for schedule(dynamic) \ - private(x, y, slice, i, n, density, r, t, contrib) - #endif - for(y = 0; y < sh; ++y) - { - for(x = 0; x < sw; ++x) - { - slice = src + (y * (sw * bpp)) + (x * bpp); - - for(i = 0; i < bpp; ++i) +#ifdef _OPENMP +#pragma omp parallel for schedule(dynamic) \ + private(x, y, slice, i, n, density, r, t, contrib) +#endif + for (y = 0; y < sh; ++y) + { + for (x = 0; x < sw; ++x) { - density = 0.0f; - r = 0.0f; + slice = src + (y * (sw * bpp)) + (x * bpp); - for(n = 0; n < nmax; ++n) - { - contrib = filter((s + n) * zscale); - density += contrib; - if(i == 3) - t = slice[(wrap(start + n, sd) * zstride) + i]; - else - t = linear_to_gamma(gc, slice[(wrap(start + n, sd) * zstride) + i], gamma); - r += t * contrib; - } + for (i = 0; i < bpp; ++i) + { + density = 0.0f; + r = 0.0f; - if(density != 0.0f && density != 1.0f) - r /= density; + for (n = 0; n < nmax; ++n) + { + contrib = filter((s + n) * zscale); + density += contrib; + if (i == 3) + t = slice[(wrap(start + n, sd) * zstride) + i]; + else + t = linear_to_gamma(gc, slice[(wrap(start + n, sd) * zstride) + i], gamma); + r += t * contrib; + } - r = MIN(255, MAX(0, r)); + if (density != 0.0f && density != 1.0f) + r /= density; - if(i != 3) - r = gamma_to_linear(gc, r, gamma); + r = MIN(255, MAX(0, r)); - d[((y * sw) + x) * bpp + i] = (unsigned char)r; + if (i != 3) + r = gamma_to_linear(gc, r, gamma); + + d[((y * sw) + x) * bpp + i] = (unsigned char)r; + } } - } - } + } /* resample in Y direction */ d = tmp2; - #ifdef _OPENMP - #pragma omp parallel for schedule(dynamic) \ - private(x, y, col, center, start, stop, nmax, s, i, n, density, r, t, contrib) - #endif - for(y = 0; y < dh; ++y) - { - center = ((float)y + 0.5f) / yfactor; - start = (int)(center - ysupport + 0.5f); - stop = (int)(center + ysupport + 0.5f); - nmax = stop - start; - s = (float)start - center + 0.5f; +#ifdef _OPENMP +#pragma omp parallel for schedule(dynamic) \ + private(x, y, col, center, start, stop, nmax, s, i, n, density, r, t, contrib) +#endif + for (y = 0; y < dh; ++y) + { + center = ((float)y + 0.5f) / yfactor; + start = (int)(center - ysupport + 0.5f); + stop = (int)(center + ysupport + 0.5f); + nmax = stop - start; + s = (float)start - center + 0.5f; - for(x = 0; x < sw; ++x) - { - col = tmp1 + (x * bpp); - - for(i = 0; i < bpp; ++i) + for (x = 0; x < sw; ++x) { - density = 0.0f; - r = 0.0f; + col = tmp1 + (x * bpp); - for(n = 0; n < nmax; ++n) - { - contrib = filter((s + n) * yscale); - density += contrib; - if(i == 3) - t = col[(wrap(start + n, sh) * sstride) + i]; - else - t = linear_to_gamma(gc, col[(wrap(start + n, sh) * sstride) + i], gamma); - r += t * contrib; - } + for (i = 0; i < bpp; ++i) + { + density = 0.0f; + r = 0.0f; - if(density != 0.0f && density != 1.0f) - r /= density; + for (n = 0; n < nmax; ++n) + { + contrib = filter((s + n) * yscale); + density += contrib; + if (i == 3) + t = col[(wrap(start + n, sh) * sstride) + i]; + else + t = linear_to_gamma(gc, col[(wrap(start + n, sh) * sstride) + i], gamma); + r += t * contrib; + } - r = MIN(255, MAX(0, r)); + if (density != 0.0f && density != 1.0f) + r /= density; - if(i != 3) - r = gamma_to_linear(gc, r, gamma); + r = MIN(255, MAX(0, r)); - d[((y * sw) + x) * bpp + i] = (unsigned char)r; + if (i != 3) + r = gamma_to_linear(gc, r, gamma); + + d[((y * sw) + x) * bpp + i] = (unsigned char)r; + } } - } - } + } /* resample in X direction */ d = dst; - #ifdef _OPENMP - #pragma omp parallel for schedule(dynamic) \ - private(x, y, row, center, start, stop, nmax, s, i, n, density, r, t, contrib) - #endif - for(y = 0; y < dh; ++y) - { - row = tmp2 + (y * sstride); +#ifdef _OPENMP +#pragma omp parallel for schedule(dynamic) \ + private(x, y, row, center, start, stop, nmax, s, i, n, density, r, t, contrib) +#endif + for (y = 0; y < dh; ++y) + { + row = tmp2 + (y * sstride); - for(x = 0; x < dw; ++x) - { - center = ((float)x + 0.5f) / xfactor; - start = (int)(center - xsupport + 0.5f); - stop = (int)(center + xsupport + 0.5f); - nmax = stop - start; - s = (float)start - center + 0.5f; - - for(i = 0; i < bpp; ++i) + for (x = 0; x < dw; ++x) { - density = 0.0f; - r = 0.0f; + center = ((float)x + 0.5f) / xfactor; + start = (int)(center - xsupport + 0.5f); + stop = (int)(center + xsupport + 0.5f); + nmax = stop - start; + s = (float)start - center + 0.5f; - for(n = 0; n < nmax; ++n) - { - contrib = filter((s + n) * xscale); - density += contrib; - if(i == 3) - t = row[(wrap(start + n, sw) * bpp) + i]; - else - t = linear_to_gamma(gc, row[(wrap(start + n, sw) * bpp) + i], gamma); - r += t * contrib; - } + for (i = 0; i < bpp; ++i) + { + density = 0.0f; + r = 0.0f; - if(density != 0.0f && density != 1.0f) - r /= density; + for (n = 0; n < nmax; ++n) + { + contrib = filter((s + n) * xscale); + density += contrib; + if (i == 3) + t = row[(wrap(start + n, sw) * bpp) + i]; + else + t = linear_to_gamma(gc, row[(wrap(start + n, sw) * bpp) + i], gamma); + r += t * contrib; + } - r = MIN(255, MAX(0, r)); + if (density != 0.0f && density != 1.0f) + r /= density; - if(i != 3) - r = gamma_to_linear(gc, r, gamma); + r = MIN(255, MAX(0, r)); - d[((z * dh * dw) + (y * dw) + x) * bpp + i] = (unsigned char)r; + if (i != 3) + r = gamma_to_linear(gc, r, gamma); + + d[((z * dh * dw) + (y * dw) + x) * bpp + i] = (unsigned char)r; + } } - } - } - } + } + } - g_free(tmp1); - g_free(tmp2); + g_free (tmp1); + g_free (tmp2); } /****************************************************************************** @@ -743,19 +841,19 @@ static void scale_volume_image(unsigned char *dst, int dw, int dh, int dd, static struct { - int filter; - filterfunc_t func; - float support; + int filter; + filterfunc_t func; + float support; } filters[] = { - {DDS_MIPMAP_FILTER_BOX, box_filter, 0.5f}, - {DDS_MIPMAP_FILTER_TRIANGLE, triangle_filter, 1.0f}, - {DDS_MIPMAP_FILTER_QUADRATIC, quadratic_filter, 1.5f}, - {DDS_MIPMAP_FILTER_BSPLINE, bspline_filter, 2.0f}, - {DDS_MIPMAP_FILTER_MITCHELL, mitchell_filter, 2.0f}, - {DDS_MIPMAP_FILTER_LANCZOS, lanczos_filter, 3.0f}, - {DDS_MIPMAP_FILTER_KAISER, kaiser_filter, 3.0f}, - {DDS_MIPMAP_FILTER_MAX, NULL, 0.0f} + { DDS_MIPMAP_FILTER_BOX, box_filter, 0.5f }, + { DDS_MIPMAP_FILTER_TRIANGLE, triangle_filter, 1.0f }, + { DDS_MIPMAP_FILTER_QUADRATIC, quadratic_filter, 1.5f }, + { DDS_MIPMAP_FILTER_BSPLINE, bspline_filter, 2.0f }, + { DDS_MIPMAP_FILTER_MITCHELL, mitchell_filter, 2.0f }, + { DDS_MIPMAP_FILTER_LANCZOS, lanczos_filter, 3.0f }, + { DDS_MIPMAP_FILTER_KAISER, kaiser_filter, 3.0f }, + { DDS_MIPMAP_FILTER_MAX, NULL, 0.0f } }; /* @@ -763,249 +861,272 @@ static struct * if (texel_alpha < alpha_test_threshold) * discard; */ -static float calc_alpha_test_coverage(unsigned char *src, - unsigned int width, unsigned int height, int bpp, - float alpha_test_threshold, - float alpha_scale) +static float +calc_alpha_test_coverage (unsigned char *src, + unsigned int width, + unsigned int height, + int bpp, + float alpha_test_threshold, + float alpha_scale) { - unsigned int x, y; - int rowbytes = width * bpp; - int coverage = 0; - const int alpha_channel_idx = 3; + unsigned int x, y; + int rowbytes = width * bpp; + int coverage = 0; + const int alpha_channel_idx = 3; - if(bpp <= alpha_channel_idx) - { + if (bpp <= alpha_channel_idx) + { /* No alpha channel */ return 1.f; - } + } - for(y = 0; y < height; ++y) - { - for(x = 0; x < width; ++x) - { - const float alpha = src[y * rowbytes + (x * bpp) + alpha_channel_idx]; - if((alpha * alpha_scale) >= (alpha_test_threshold * 255)) - { - ++coverage; - } - } - } + for (y = 0; y < height; ++y) + { + for (x = 0; x < width; ++x) + { + const float alpha = src[y * rowbytes + (x * bpp) + alpha_channel_idx]; + if ((alpha * alpha_scale) >= (alpha_test_threshold * 255)) + { + ++coverage; + } + } + } - return (float)coverage / (width * height); + return (float)coverage / (width * height); } -static void scale_alpha_to_coverage(unsigned char *img, - unsigned int width, unsigned int height, int bpp, - float desired_coverage, - float alpha_test_threshold) +static void +scale_alpha_to_coverage (unsigned char *img, + unsigned int width, + unsigned int height, + int bpp, + float desired_coverage, + float alpha_test_threshold) { - int i; - unsigned int x, y; - const int rowbytes = width * bpp; - const int alpha_channel_idx = 3; - float min_alpha_scale = 0.0f; - float max_alpha_scale = 4.0f; - float alpha_scale = 1.0f; + int i; + unsigned int x, y; + const int rowbytes = width * bpp; + const int alpha_channel_idx = 3; + float min_alpha_scale = 0.0f; + float max_alpha_scale = 4.0f; + float alpha_scale = 1.0f; - if(bpp <= alpha_channel_idx) - { + if (bpp <= alpha_channel_idx) + { /* No alpha channel */ return; - } + } - /* Binary search */ - for(i = 0; i < 10; i++) - { + /* Binary search */ + for (i = 0; i < 10; i++) + { float cur_coverage = calc_alpha_test_coverage(img, width, height, bpp, alpha_test_threshold, alpha_scale); - if(cur_coverage < desired_coverage) - { - min_alpha_scale = alpha_scale; - } + if (cur_coverage < desired_coverage) + { + min_alpha_scale = alpha_scale; + } else if (cur_coverage > desired_coverage) - { - max_alpha_scale = alpha_scale; - } + { + max_alpha_scale = alpha_scale; + } else - { - break; - } + { + break; + } alpha_scale = (min_alpha_scale + max_alpha_scale) / 2; - } + } - /* Scale alpha channel */ - for(y = 0; y < height; ++y) - { - for(x = 0; x < width; ++x) - { - float new_alpha = img[y * rowbytes + (x * bpp) + alpha_channel_idx] * alpha_scale; - if(new_alpha > 255.0f) - { - new_alpha = 255.0f; - } + /* Scale alpha channel */ + for (y = 0; y < height; ++y) + { + for (x = 0; x < width; ++x) + { + float new_alpha = img[y * rowbytes + (x * bpp) + alpha_channel_idx] * alpha_scale; + if (new_alpha > 255.0f) + { + new_alpha = 255.0f; + } - img[y * rowbytes + (x * bpp) + alpha_channel_idx] = (unsigned char)new_alpha; - } - } + img[y * rowbytes + (x * bpp) + alpha_channel_idx] = (unsigned char)new_alpha; + } + } } /****************************************************************************** * mipmap generation * ******************************************************************************/ -int generate_mipmaps(unsigned char *dst, unsigned char *src, - unsigned int width, unsigned int height, int bpp, - int indexed, int mipmaps, int filter, int wrap, - int gc, float gamma, - int preserve_alpha_coverage, float alpha_test_threshold) +int +generate_mipmaps (unsigned char *dst, + unsigned char *src, + unsigned int width, + unsigned int height, + int bpp, + int indexed, + int mipmaps, + int filter, + int wrap, + int gc, + float gamma, + int preserve_alpha_coverage, + float alpha_test_threshold) { - int i; - unsigned int sw, sh, dw, dh; - unsigned char *s, *d; - mipmapfunc_t mipmap_func = NULL; - filterfunc_t filter_func = NULL; - wrapfunc_t wrap_func = NULL; - float support = 0.0f; - const int has_alpha = (bpp >= 3); - float alpha_test_coverage = 1; + int i; + unsigned int sw, sh, dw, dh; + unsigned char *s, *d; + mipmapfunc_t mipmap_func = NULL; + filterfunc_t filter_func = NULL; + wrapfunc_t wrap_func = NULL; + float support = 0.0f; + const int has_alpha = (bpp >= 3); + float alpha_test_coverage = 1; - if(indexed || filter == DDS_MIPMAP_FILTER_NEAREST) - { + if (indexed || filter == DDS_MIPMAP_FILTER_NEAREST) + { mipmap_func = scale_image_nearest; - } - else - { - if((filter <= DDS_MIPMAP_FILTER_DEFAULT) || - (filter >= DDS_MIPMAP_FILTER_MAX)) - filter = DDS_MIPMAP_FILTER_BOX; + } + else + { + if ((filter <= DDS_MIPMAP_FILTER_DEFAULT) || + (filter >= DDS_MIPMAP_FILTER_MAX)) + filter = DDS_MIPMAP_FILTER_BOX; mipmap_func = scale_image; - for(i = 0; filters[i].filter != DDS_MIPMAP_FILTER_MAX; ++i) - { - if(filter == filters[i].filter) - { - filter_func = filters[i].func; - support = filters[i].support; - break; - } - } - } + for (i = 0; filters[i].filter != DDS_MIPMAP_FILTER_MAX; ++i) + { + if (filter == filters[i].filter) + { + filter_func = filters[i].func; + support = filters[i].support; + break; + } + } + } - switch(wrap) - { - case DDS_MIPMAP_WRAP_MIRROR: wrap_func = wrap_mirror; break; - case DDS_MIPMAP_WRAP_REPEAT: wrap_func = wrap_repeat; break; - case DDS_MIPMAP_WRAP_CLAMP: wrap_func = wrap_clamp; break; - default: wrap_func = wrap_clamp; break; - } + switch (wrap) + { + case DDS_MIPMAP_WRAP_MIRROR: wrap_func = wrap_mirror; break; + case DDS_MIPMAP_WRAP_REPEAT: wrap_func = wrap_repeat; break; + case DDS_MIPMAP_WRAP_CLAMP: wrap_func = wrap_clamp; break; + default: wrap_func = wrap_clamp; break; + } - if(has_alpha && preserve_alpha_coverage) - { + if (has_alpha && preserve_alpha_coverage) + { alpha_test_coverage = calc_alpha_test_coverage(src, width, height, bpp, alpha_test_threshold, 1.0f); - } + } - memcpy(dst, src, width * height * bpp); + memcpy (dst, src, width * height * bpp); - s = dst; - d = dst + (width * height * bpp); + s = dst; + d = dst + (width * height * bpp); - sw = width; - sh = height; + sw = width; + sh = height; - for(i = 1; i < mipmaps; ++i) - { + for (i = 1; i < mipmaps; ++i) + { dw = MAX(1, sw >> 1); dh = MAX(1, sh >> 1); mipmap_func(d, dw, dh, s, sw, sh, bpp, filter_func, support, wrap_func, gc, gamma); - if(has_alpha && preserve_alpha_coverage) - { - scale_alpha_to_coverage(d, dw, dh, bpp, alpha_test_coverage, alpha_test_threshold); - } + if (has_alpha && preserve_alpha_coverage) + { + scale_alpha_to_coverage(d, dw, dh, bpp, alpha_test_coverage, alpha_test_threshold); + } s = d; sw = dw; sh = dh; d += (dw * dh * bpp); - } + } - return(1); + return 1; } -int generate_volume_mipmaps(unsigned char *dst, unsigned char *src, - unsigned int width, unsigned int height, - unsigned int depth, int bpp, int indexed, - int mipmaps, int filter, int wrap, - int gc, float gamma) +int +generate_volume_mipmaps (unsigned char *dst, + unsigned char *src, + unsigned int width, + unsigned int height, + unsigned int depth, + int bpp, + int indexed, + int mipmaps, + int filter, + int wrap, + int gc, + float gamma) { - int i; - unsigned int sw, sh, sd; - unsigned int dw, dh, dd; - unsigned char *s, *d; - volmipmapfunc_t mipmap_func = NULL; - filterfunc_t filter_func = NULL; - wrapfunc_t wrap_func = NULL; - float support = 0.0f; + int i; + unsigned int sw, sh, sd; + unsigned int dw, dh, dd; + unsigned char *s, *d; + volmipmapfunc_t mipmap_func = NULL; + filterfunc_t filter_func = NULL; + wrapfunc_t wrap_func = NULL; + float support = 0.0f; - if(indexed || filter == DDS_MIPMAP_FILTER_NEAREST) - { + if (indexed || filter == DDS_MIPMAP_FILTER_NEAREST) + { mipmap_func = scale_volume_image_nearest; - } - else - { - if((filter <= DDS_MIPMAP_FILTER_DEFAULT) || - (filter >= DDS_MIPMAP_FILTER_MAX)) - filter = DDS_MIPMAP_FILTER_BOX; + } + else + { + if ((filter <= DDS_MIPMAP_FILTER_DEFAULT) || + (filter >= DDS_MIPMAP_FILTER_MAX)) + filter = DDS_MIPMAP_FILTER_BOX; mipmap_func = scale_volume_image; - for(i = 0; filters[i].filter != DDS_MIPMAP_FILTER_MAX; ++i) - { - if(filter == filters[i].filter) - { - filter_func = filters[i].func; - support = filters[i].support; - break; - } - } - } + for (i = 0; filters[i].filter != DDS_MIPMAP_FILTER_MAX; ++i) + { + if (filter == filters[i].filter) + { + filter_func = filters[i].func; + support = filters[i].support; + break; + } + } + } - switch(wrap) - { - case DDS_MIPMAP_WRAP_MIRROR: wrap_func = wrap_mirror; break; - case DDS_MIPMAP_WRAP_REPEAT: wrap_func = wrap_repeat; break; - case DDS_MIPMAP_WRAP_CLAMP: wrap_func = wrap_clamp; break; - default: wrap_func = wrap_clamp; break; - } + switch (wrap) + { + case DDS_MIPMAP_WRAP_MIRROR: wrap_func = wrap_mirror; break; + case DDS_MIPMAP_WRAP_REPEAT: wrap_func = wrap_repeat; break; + case DDS_MIPMAP_WRAP_CLAMP: wrap_func = wrap_clamp; break; + default: wrap_func = wrap_clamp; break; + } - memcpy(dst, src, width * height * depth * bpp); + memcpy (dst, src, width * height * depth * bpp); - s = dst; - d = dst + (width * height * depth * bpp); + s = dst; + d = dst + (width * height * depth * bpp); - sw = width; - sh = height; - sd = depth; + sw = width; + sh = height; + sd = depth; - for(i = 1; i < mipmaps; ++i) - { + for (i = 1; i < mipmaps; ++i) + { dw = MAX(1, sw >> 1); dh = MAX(1, sh >> 1); dd = MAX(1, sd >> 1); - mipmap_func(d, dw, dh, dd, s, sw, sh, sd, bpp, filter_func, support, wrap_func, gc, gamma); + mipmap_func (d, dw, dh, dd, s, sw, sh, sd, bpp, filter_func, support, wrap_func, gc, gamma); s = d; sw = dw; sh = dh; sd = dd; d += (dw * dh * dd * bpp); - } + } - return(1); + return 1; } diff --git a/plug-ins/file-dds/mipmap.h b/plug-ins/file-dds/mipmap.h index ff77eb3c46..166f326703 100644 --- a/plug-ins/file-dds/mipmap.h +++ b/plug-ins/file-dds/mipmap.h @@ -1,47 +1,75 @@ /* - DDS GIMP plugin + * DDS GIMP plugin + * + * Copyright (C) 2004-2012 Shawn Kirst , + * with parts (C) 2003 Arne Reuter 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 3 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. If not, see . + */ - Copyright (C) 2004-2012 Shawn Kirst , - with parts (C) 2003 Arne Reuter where specified. +#ifndef __MIPMAP_H__ +#define __MIPMAP_H__ - 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. +int get_num_mipmaps (int width, + int height); +unsigned int get_mipmapped_size (int width, + int height, + int bpp, + int level, + int num, + int format); +unsigned int get_volume_mipmapped_size (int width, + int height, + int depth, + int bpp, + int level, + int num, + int format); +int get_next_mipmap_dimensions (int *next_w, + int *next_h, + int curr_w, + int curr_h); - 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. +float cubic_interpolate (float a, + float b, + float c, + float d, + float x); +int generate_mipmaps (unsigned char *dst, + unsigned char *src, + unsigned int width, + unsigned int height, + int bpp, + int indexed, + int mipmaps, + int filter, + int wrap, + int gamma_correct, + float gamma, + int preserve_alpha_test_coverage, + float alpha_test_threshold); +int generate_volume_mipmaps (unsigned char *dst, + unsigned char *src, + unsigned int width, + unsigned int height, + unsigned int depth, + int bpp, + int indexed, + int mipmaps, + int filter, + int wrap, + int gamma_correct, + float gamma); - 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 MIPMAP_H -#define MIPMAP_H - -int get_num_mipmaps(int width, int height); -unsigned int get_mipmapped_size(int width, int height, int bpp, - int level, int num, int format); -unsigned int get_volume_mipmapped_size(int width, int height, - int depth, int bpp, int level, - int num, int format); -int get_next_mipmap_dimensions(int *next_w, int *next_h, - int curr_w, int curr_h); - -float cubic_interpolate(float a, float b, float c, float d, float x); -int generate_mipmaps(unsigned char *dst, unsigned char *src, - unsigned int width, unsigned int height, int bpp, - int indexed, int mipmaps, int filter, int wrap, - int gamma_correct, float gamma, - int preserve_alpha_test_coverage, float alpha_test_threshold); -int generate_volume_mipmaps(unsigned char *dst, unsigned char *src, - unsigned int width, unsigned int height, - unsigned int depth, int bpp, int indexed, - int mipmaps, int filter, int wrap, - int gamma_correct, float gamma); - -#endif +#endif /* __MIPMAP_H__ */ diff --git a/plug-ins/file-dds/misc.c b/plug-ins/file-dds/misc.c index 1a09031a32..c8c3593c20 100644 --- a/plug-ins/file-dds/misc.c +++ b/plug-ins/file-dds/misc.c @@ -1,70 +1,74 @@ /* - DDS GIMP plugin - - Copyright (C) 2004-2012 Shawn Kirst , - with parts (C) 2003 Arne Reuter 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 , + * with parts (C) 2003 Arne Reuter 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 #include "misc.h" -static inline float saturate(float a) +static inline float +saturate (float a) { - if(a < 0) a = 0; - if(a > 1) a = 1; - return(a); + if(a < 0) a = 0; + if(a > 1) a = 1; + + return a; } -void decode_ycocg_image(gint32 drawableID, gboolean shadow) +void +decode_ycocg_image (gint32 drawableID, + gboolean shadow) { - GeglBuffer *buffer, *sbuffer; - const Babl *format; - unsigned char *data; - unsigned int i, w, h, num_pixels; + GeglBuffer *buffer, *sbuffer; + const Babl *format; + unsigned char *data; + unsigned int i, w, h, num_pixels; - const float offset = 0.5f * 256.0f / 255.0f; - float Y, Co, Cg, R, G, B; + const float offset = 0.5f * 256.0f / 255.0f; + float Y, Co, Cg, R, G, B; - buffer = gimp_drawable_get_buffer(drawableID); + buffer = gimp_drawable_get_buffer (drawableID); - if(shadow) - { - sbuffer = gimp_drawable_get_shadow_buffer(drawableID); - gegl_buffer_copy(buffer, NULL, GEGL_ABYSS_NONE, sbuffer, NULL); - g_object_unref(buffer); + if (shadow) + { + sbuffer = gimp_drawable_get_shadow_buffer (drawableID); + gegl_buffer_copy (buffer, NULL, GEGL_ABYSS_NONE, sbuffer, NULL); + g_object_unref (buffer); buffer = sbuffer; - } - - format = babl_format("R'G'B'A u8"); + } - w = gegl_buffer_get_width(buffer); - h = gegl_buffer_get_height(buffer); - num_pixels = w * h; - - data = g_malloc(num_pixels * 4); - - gegl_buffer_get(buffer, GEGL_RECTANGLE(0, 0, w, h), 1.0, format, data, + format = babl_format ("R'G'B'A u8"); + + w = gegl_buffer_get_width (buffer); + h = gegl_buffer_get_height (buffer); + num_pixels = w * h; + + data = g_malloc (num_pixels * 4); + + gegl_buffer_get (buffer, GEGL_RECTANGLE(0, 0, w, h), 1.0, format, data, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE); - gimp_progress_init("Decoding YCoCg pixels..."); + gimp_progress_init ("Decoding YCoCg pixels..."); - for(i = 0; i < num_pixels; ++i) - { + for (i = 0; i < num_pixels; ++i) + { Y = (float)data[4 * i + 3] / 255.0f; Co = (float)data[4 * i + 0] / 255.0f; Cg = (float)data[4 * i + 1] / 255.0f; @@ -84,62 +88,64 @@ void decode_ycocg_image(gint32 drawableID, gboolean shadow) data[4 * i + 1] = (unsigned char)(G * 255.0f); data[4 * i + 2] = (unsigned char)(B * 255.0f); - if((i & 0x7fff) == 0) - gimp_progress_update((float)i / (float)num_pixels); - } + if ((i & 0x7fff) == 0) + gimp_progress_update ((float)i / (float)num_pixels); + } - gegl_buffer_set(buffer, GEGL_RECTANGLE(0, 0, w, h), 0, format, data, + gegl_buffer_set (buffer, GEGL_RECTANGLE(0, 0, w, h), 0, format, data, GEGL_AUTO_ROWSTRIDE); - gimp_progress_update(1.0); + gimp_progress_update (1.0); - gegl_buffer_flush(buffer); - - if(shadow) - gimp_drawable_merge_shadow(drawableID, TRUE); - - gimp_drawable_update(drawableID, 0, 0, w, h); + gegl_buffer_flush (buffer); - g_free(data); - - g_object_unref(buffer); + if (shadow) + gimp_drawable_merge_shadow (drawableID, TRUE); + + gimp_drawable_update (drawableID, 0, 0, w, h); + + g_free (data); + + g_object_unref (buffer); } -void decode_ycocg_scaled_image(gint32 drawableID, gboolean shadow) +void +decode_ycocg_scaled_image (gint32 drawableID, + gboolean shadow) { - GeglBuffer *buffer, *sbuffer; - const Babl *format; - unsigned char *data; - unsigned int i, w, h, num_pixels; + GeglBuffer *buffer, *sbuffer; + const Babl *format; + unsigned char *data; + unsigned int i, w, h, num_pixels; - const float offset = 0.5f * 256.0f / 255.0f; - float Y, Co, Cg, R, G, B, s; + const float offset = 0.5f * 256.0f / 255.0f; + float Y, Co, Cg, R, G, B, s; - buffer = gimp_drawable_get_buffer(drawableID); - - if(shadow) - { + buffer = gimp_drawable_get_buffer (drawableID); + + if (shadow) + { sbuffer = gimp_drawable_get_shadow_buffer(drawableID); gegl_buffer_copy(buffer, NULL, GEGL_ABYSS_NONE, sbuffer, NULL); g_object_unref(buffer); buffer = sbuffer; - } - - format = babl_format("R'G'B'A u8"); - - w = gegl_buffer_get_width(buffer); - h = gegl_buffer_get_height(buffer); - num_pixels = w * h; - - data = g_malloc(num_pixels * 4); - - gegl_buffer_get(buffer, GEGL_RECTANGLE(0, 0, w, h), 1.0, format, data, - GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE); - - gimp_progress_init("Decoding YCoCg (scaled) pixels..."); + } - for(i = 0; i < num_pixels; ++i) - { + format = babl_format ("R'G'B'A u8"); + + w = gegl_buffer_get_width (buffer); + h = gegl_buffer_get_height (buffer); + num_pixels = w * h; + + data = g_malloc (num_pixels * 4); + + gegl_buffer_get (buffer, GEGL_RECTANGLE(0, 0, w, h), 1.0, format, data, + GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE); + + gimp_progress_init ("Decoding YCoCg (scaled) pixels..."); + + for (i = 0; i < num_pixels; ++i) + { Y = (float)data[4 * i + 3] / 255.0f; Co = (float)data[4 * i + 0] / 255.0f; Cg = (float)data[4 * i + 1] / 255.0f; @@ -162,60 +168,62 @@ void decode_ycocg_scaled_image(gint32 drawableID, gboolean shadow) /* set alpha to 1 */ data[4 * i + 3] = 255; - if((i & 0x7fff) == 0) - gimp_progress_update((float)i / (float)num_pixels); - } + if ((i & 0x7fff) == 0) + gimp_progress_update ((float)i / (float)num_pixels); + } - gegl_buffer_set(buffer, GEGL_RECTANGLE(0, 0, w, h), 0, format, data, + gegl_buffer_set (buffer, GEGL_RECTANGLE(0, 0, w, h), 0, format, data, GEGL_AUTO_ROWSTRIDE); - - gimp_progress_update(1.0); - - gegl_buffer_flush(buffer); - if(shadow) - gimp_drawable_merge_shadow(drawableID, TRUE); + gimp_progress_update (1.0); - gimp_drawable_update(drawableID, 0, 0, w, h); - - g_free(data); - - g_object_unref(buffer); + gegl_buffer_flush (buffer); + + if (shadow) + gimp_drawable_merge_shadow (drawableID, TRUE); + + gimp_drawable_update (drawableID, 0, 0, w, h); + + g_free (data); + + g_object_unref (buffer); } -void decode_alpha_exp_image(gint32 drawableID, gboolean shadow) +void +decode_alpha_exp_image (gint32 drawableID, + gboolean shadow) { - GeglBuffer *buffer, *sbuffer; - const Babl *format; - unsigned char *data; - unsigned int i, w, h, num_pixels; - int R, G, B, A; + GeglBuffer *buffer, *sbuffer; + const Babl *format; + unsigned char *data; + unsigned int i, w, h, num_pixels; + int R, G, B, A; - buffer = gimp_drawable_get_buffer(drawableID); - - if(shadow) - { - sbuffer = gimp_drawable_get_shadow_buffer(drawableID); - gegl_buffer_copy(buffer, NULL, GEGL_ABYSS_NONE, sbuffer, NULL); - g_object_unref(buffer); + buffer = gimp_drawable_get_buffer (drawableID); + + if (shadow) + { + sbuffer = gimp_drawable_get_shadow_buffer (drawableID); + gegl_buffer_copy (buffer, NULL, GEGL_ABYSS_NONE, sbuffer, NULL); + g_object_unref (buffer); buffer = sbuffer; - } - - format = babl_format("R'G'B'A u8"); - - w = gegl_buffer_get_width(buffer); - h = gegl_buffer_get_height(buffer); - num_pixels = w * h; - - data = g_malloc(num_pixels * 4); - - gegl_buffer_get(buffer, GEGL_RECTANGLE(0, 0, w, h), 1.0, format, data, - GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE); - - gimp_progress_init("Decoding Alpha-exponent pixels..."); + } - for(i = 0; i < num_pixels; ++i) - { + format = babl_format ("R'G'B'A u8"); + + w = gegl_buffer_get_width (buffer); + h = gegl_buffer_get_height (buffer); + num_pixels = w * h; + + data = g_malloc (num_pixels * 4); + + gegl_buffer_get (buffer, GEGL_RECTANGLE(0, 0, w, h), 1.0, format, data, + GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE); + + gimp_progress_init ("Decoding Alpha-exponent pixels..."); + + for (i = 0; i < num_pixels; ++i) + { R = data[4 * i + 0]; G = data[4 * i + 1]; B = data[4 * i + 2]; @@ -231,23 +239,23 @@ void decode_alpha_exp_image(gint32 drawableID, gboolean shadow) data[4 * i + 2] = B; data[4 * i + 3] = A; - if((i & 0x7fff) == 0) - gimp_progress_update((float)i / (float)num_pixels); - } + if ((i & 0x7fff) == 0) + gimp_progress_update ((float)i / (float)num_pixels); + } - gegl_buffer_set(buffer, GEGL_RECTANGLE(0, 0, w, h), 0, format, data, + gegl_buffer_set (buffer, GEGL_RECTANGLE(0, 0, w, h), 0, format, data, GEGL_AUTO_ROWSTRIDE); - - gimp_progress_update(1.0); - - gegl_buffer_flush(buffer); - if(shadow) - gimp_drawable_merge_shadow(drawableID, TRUE); + gimp_progress_update (1.0); - gimp_drawable_update(drawableID, 0, 0, w, h); - - g_free(data); - - g_object_unref(buffer); + gegl_buffer_flush (buffer); + + if (shadow) + gimp_drawable_merge_shadow (drawableID, TRUE); + + gimp_drawable_update (drawableID, 0, 0, w, h); + + g_free (data); + + g_object_unref (buffer); } diff --git a/plug-ins/file-dds/misc.h b/plug-ins/file-dds/misc.h index d54482a9af..73656ee7ff 100644 --- a/plug-ins/file-dds/misc.h +++ b/plug-ins/file-dds/misc.h @@ -1,30 +1,31 @@ /* - DDS GIMP plugin + * DDS GIMP plugin + * + * Copyright (C) 2004-2012 Shawn Kirst , + * with parts (C) 2003 Arne Reuter 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 3 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. If not, see . + */ - Copyright (C) 2004-2012 Shawn Kirst , - with parts (C) 2003 Arne Reuter where specified. +#ifndef __MISC_H__ +#define __MISC_H__ - 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. +void decode_ycocg_image (gint32 drawableID, + gboolean shadow); +void decode_ycocg_scaled_image (gint32 drawableID, + gboolean shadow); +void decode_alpha_exp_image (gint32 drawableID, + gboolean shadow); - 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 MISC_H -#define MISC_H - -void decode_ycocg_image(gint32 drawableID, gboolean shadow); -void decode_ycocg_scaled_image(gint32 drawableID, gboolean shadow); -void decode_alpha_exp_image(gint32 drawableID, gboolean shadow); - -#endif +#endif /* __MISC_H__ */ diff --git a/plug-ins/file-dds/vec.h b/plug-ins/file-dds/vec.h index fd94de6651..cc3c344868 100644 --- a/plug-ins/file-dds/vec.h +++ b/plug-ins/file-dds/vec.h @@ -1,27 +1,25 @@ /* - DDS GIMP plugin + * DDS GIMP plugin + * + * Copyright (C) 2004-2012 Shawn Kirst , + * with parts (C) 2003 Arne Reuter 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 3 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. If not, see . + */ - Copyright (C) 2004-2012 Shawn Kirst , - with parts (C) 2003 Arne Reuter 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 VEC_H -#define VEC_H +#ifndef __VEC_H__ +#define __VEC_H__ #include @@ -42,185 +40,206 @@ typedef float sym3x3_t[6]; #define VEC4_CONST3(x, y, z) {x, y, z, 0.0f} #define VEC4_CONST1(x) {x, x, x, x} -static inline vec4_t vec4_set(float x, float y, float z, float w) +static inline vec4_t +vec4_set (float x, + float y, + float z, + float w) { #ifdef USE_SSE - return(_mm_setr_ps(x, y, z, w)); + return _mm_setr_ps(x, y, z, w); #else - vec4_t v = {x, y, z, w}; - return(v); + vec4_t v = { x, y, z, w }; + return v; #endif } -static inline vec4_t vec4_set1(float f) +static inline vec4_t +vec4_set1 (float f) { #ifdef USE_SSE - return(_mm_set1_ps(f)); + return _mm_set1_ps(f); #else - vec4_t v = {f, f, f, f}; - return(v); + vec4_t v = { f, f, f, f }; + return v; #endif } -static inline vec4_t vec4_zero() +static inline vec4_t +vec4_zero (void) { #ifdef USE_SSE - return(_mm_setzero_ps()); + return _mm_setzero_ps(); #else - vec4_t v = {0, 0, 0, 0}; - return(v); + vec4_t v = { 0, 0, 0, 0 }; + return v; #endif } -static inline void vec4_store(float *f, const vec4_t v) +static inline void +vec4_store (float *f, + const vec4_t v) { #ifdef USE_SSE - _mm_store_ps(f, v); + _mm_store_ps (f, v); #else - f[0] = v[0]; f[1] = v[1]; f[2] = v[2]; f[3] = v[3]; + f[0] = v[0]; f[1] = v[1]; f[2] = v[2]; f[3] = v[3]; #endif } -static inline vec4_t vec4_splatx(const vec4_t v) +static inline vec4_t +vec4_splatx (const vec4_t v) { #ifdef USE_SSE - return(_mm_shuffle_ps(v, v, 0x00)); + return _mm_shuffle_ps(v, v, 0x00); #else - vec4_t r = {v[0], v[0], v[0], v[0]}; - return(r); + vec4_t r = { v[0], v[0], v[0], v[0] }; + return r; #endif } -static inline vec4_t vec4_splaty(const vec4_t v) +static inline vec4_t +vec4_splaty (const vec4_t v) { #ifdef USE_SSE - return(_mm_shuffle_ps(v, v, 0x55)); + return _mm_shuffle_ps(v, v, 0x55); #else - vec4_t r = {v[1], v[1], v[1], v[1]}; - return(r); + vec4_t r = { v[1], v[1], v[1], v[1] }; + return r; #endif } -static inline vec4_t vec4_splatz(const vec4_t v) +static inline vec4_t +vec4_splatz (const vec4_t v) { #ifdef USE_SSE - return(_mm_shuffle_ps(v, v, 0xaa)); + return _mm_shuffle_ps(v, v, 0xaa); #else - vec4_t r = {v[2], v[2], v[2], v[2]}; - return(r); + vec4_t r = { v[2], v[2], v[2], v[2] }; + return r; #endif } -static inline vec4_t vec4_splatw(const vec4_t v) +static inline vec4_t +vec4_splatw (const vec4_t v) { #ifdef USE_SSE - return(_mm_shuffle_ps(v, v, 0xff)); + return _mm_shuffle_ps(v, v, 0xff); #else - vec4_t r = {v[3], v[3], v[3], v[3]}; - return(r); + vec4_t r = { v[3], v[3], v[3], v[3] }; + return r; #endif } -static inline vec4_t vec4_rcp(const vec4_t v) +static inline vec4_t +vec4_rcp (const vec4_t v) { #ifdef USE_SSE - __m128 est = _mm_rcp_ps(v); - __m128 diff = _mm_sub_ps(_mm_set1_ps(1.0f), _mm_mul_ps(est, v)); - return(_mm_add_ps(_mm_mul_ps(diff, est), est)); + __m128 est = _mm_rcp_ps (v); + __m128 diff = _mm_sub_ps (_mm_set1_ps(1.0f), _mm_mul_ps(est, v)); + return _mm_add_ps(_mm_mul_ps(diff, est), est); #else - vec4_t one = {1.0f, 1.0f, 1.0f, 1.0f}; - return(one / v); + vec4_t one = { 1.0f, 1.0f, 1.0f, 1.0f }; + return one / v; #endif } -static inline vec4_t vec4_min(const vec4_t a, const vec4_t b) +static inline vec4_t +vec4_min (const vec4_t a, + const vec4_t b) { #ifdef USE_SSE - return(_mm_min_ps(a, b)); + return _mm_min_ps(a, b); #else - return(vec4_set(MIN(a[0], b[0]), MIN(a[1], b[1]), MIN(a[2], b[2]), MIN(a[3], b[3]))); + return vec4_set (MIN(a[0], b[0]), MIN(a[1], b[1]), MIN(a[2], b[2]), MIN(a[3], b[3])); #endif } -static inline vec4_t vec4_max(const vec4_t a, const vec4_t b) +static inline vec4_t +vec4_max (const vec4_t a, + const vec4_t b) { #ifdef USE_SSE - return(_mm_max_ps(a, b)); + return _mm_max_ps (a, b); #else - return(vec4_set(MAX(a[0], b[0]), MAX(a[1], b[1]), MAX(a[2], b[2]), MAX(a[3], b[3]))); + return vec4_set (MAX(a[0], b[0]), MAX(a[1], b[1]), MAX(a[2], b[2]), MAX(a[3], b[3])); #endif } -static inline vec4_t vec4_trunc(const vec4_t v) +static inline vec4_t +vec4_trunc (const vec4_t v) { #ifdef USE_SSE # ifdef __SSE4_1__ - return(_mm_round_ps(v, _MM_FROUND_TRUNC)); + return _mm_round_ps(v, _MM_FROUND_TRUNC); # elif defined(__SSE2__) - return(_mm_cvtepi32_ps(_mm_cvttps_epi32(v))); + return _mm_cvtepi32_ps(_mm_cvttps_epi32(v)); # else - // convert to ints - __m128 in = v; - __m64 lo = _mm_cvttps_pi32(in); - __m64 hi = _mm_cvttps_pi32(_mm_movehl_ps(in, in)); - // convert to floats - __m128 part = _mm_movelh_ps(in, _mm_cvtpi32_ps(in, hi)); - __m128 trunc = _mm_cvtpi32_ps(part, lo); + // convert to ints + __m128 in = v; + __m64 lo = _mm_cvttps_pi32(in); + __m64 hi = _mm_cvttps_pi32(_mm_movehl_ps(in, in)); + // convert to floats + __m128 part = _mm_movelh_ps(in, _mm_cvtpi32_ps(in, hi)); + __m128 trunc = _mm_cvtpi32_ps(part, lo); // clear mmx state - _mm_empty(); - return(trunc); + _mm_empty (); + return trunc; # endif #else - vec4_t r = { - v[0] > 0.0f ? floorf(v[0]) : ceil(v[0]), - v[1] > 0.0f ? floorf(v[1]) : ceil(v[1]), - v[2] > 0.0f ? floorf(v[2]) : ceil(v[2]), - v[3] > 0.0f ? floorf(v[3]) : ceil(v[3]), - }; - return(r); + vec4_t r = { v[0] > 0.0f ? floorf(v[0]) : ceil(v[0]), + v[1] > 0.0f ? floorf(v[1]) : ceil(v[1]), + v[2] > 0.0f ? floorf(v[2]) : ceil(v[2]), + v[3] > 0.0f ? floorf(v[3]) : ceil(v[3]), }; + return r; #endif } -static inline float vec4_accum(const vec4_t v) +static inline float +vec4_accum (const vec4_t v) { #ifdef USE_SSE - float rv; - __m128 t; + float rv; + __m128 t; # ifdef __SSE3__ - t = _mm_hadd_ps(v, v); - t = _mm_hadd_ps(t, t); + t = _mm_hadd_ps(v, v); + t = _mm_hadd_ps(t, t); # else - t = _mm_add_ps(v, _mm_movehl_ps(v, v)); - t = _mm_add_ss(t, _mm_shuffle_ps(t, t, 0x01)); + t = _mm_add_ps(v, _mm_movehl_ps(v, v)); + t = _mm_add_ss(t, _mm_shuffle_ps(t, t, 0x01)); # endif - _mm_store_ss(&rv, t); - return(rv); + _mm_store_ss(&rv, t); + return rv; #else - return(v[0] + v[1] + v[2] + v[3]); + return v[0] + v[1] + v[2] + v[3]; #endif } -static inline float vec4_dot(const vec4_t a, const vec4_t b) +static inline float +vec4_dot (const vec4_t a, + const vec4_t b) { #if defined(USE_SSE) && defined(__SSE4_1__) - float rv; - __m128 t = _mm_dp_ps(a, b, 0xff); - _mm_store_ss(&rv, t); - return(rv); + float rv; + __m128 t = _mm_dp_ps(a, b, 0xff); + _mm_store_ss(&rv, t); + return rv; #else - return(vec4_accum(a * b)); + return vec4_accum(a * b); #endif } -static inline int vec4_cmplt(const vec4_t a, const vec4_t b) +static inline int +vec4_cmplt (const vec4_t a, + const vec4_t b) { #ifdef USE_SSE - __m128 bits = _mm_cmplt_ps(a, b); - int val = _mm_movemask_ps(bits); - return(val != 0); + __m128 bits = _mm_cmplt_ps(a, b); + int val = _mm_movemask_ps(bits); + return val != 0; #else - return((a[0] < b[0]) || (a[1] < b[1]) || (a[2] < b[2]) || (a[3] < b[3])); + return (a[0] < b[0]) || (a[1] < b[1]) || (a[2] < b[2]) || (a[3] < b[3]); #endif } -#endif +#endif /* __VEC_H__ */