Parent Directory
|
Revision Log
Release 2.0.6 tag
1 /* 2 DDS GIMP plugin 3 4 Copyright (C) 2004-2008 Shawn Kirst <skirst@insightbb.com>, 5 with parts (C) 2003 Arne Reuter <homepage@arnereuter.de> where specified. 6 7 This program is free software; you can redistribute it and/or 8 modify it under the terms of the GNU General Public 9 License as published by the Free Software Foundation; either 10 version 2 of the License, or (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program; see the file COPYING. If not, write to 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 Boston, MA 02111-1307, USA. 21 */ 22 23 #include <stdio.h> 24 #include <stdlib.h> 25 #include <string.h> 26 27 #include <gtk/gtk.h> 28 29 #include <libgimp/gimp.h> 30 #include <libgimp/gimpui.h> 31 32 #include "ddsplugin.h" 33 #include "dds.h" 34 35 FILE *errFile; 36 gchar *prog_name = "dds"; 37 gchar *filename; 38 gint interactive_dds; 39 40 static void query(void); 41 static void run(const gchar *name, gint nparams, const GimpParam *param, 42 gint *nreturn_vals, GimpParam **return_vals); 43 44 GimpPlugInInfo PLUG_IN_INFO = 45 { 46 0, 0, query, run 47 }; 48 49 50 DDSWriteVals dds_write_vals = 51 { 52 DDS_COMPRESS_NONE, 0, DDS_SAVE_SELECTED_LAYER, DDS_FORMAT_DEFAULT, -1, 53 DDS_COLOR_DEFAULT, 0, DDS_MIPMAP_DEFAULT, 0 54 }; 55 56 DDSReadVals dds_read_vals = 57 { 58 1, 1 59 }; 60 61 static GimpParamDef load_args[] = 62 { 63 {GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive"}, 64 {GIMP_PDB_STRING, "filename", "The name of the file to load"}, 65 {GIMP_PDB_STRING, "raw_filename", "The name entered"}, 66 {GIMP_PDB_INT32, "load_mipmaps", "Load mipmaps if present"} 67 }; 68 static GimpParamDef load_return_vals[] = 69 { 70 {GIMP_PDB_IMAGE, "image", "Output image"} 71 }; 72 73 static GimpParamDef save_args[] = 74 { 75 {GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive"}, 76 {GIMP_PDB_IMAGE, "image", "Input image"}, 77 {GIMP_PDB_DRAWABLE, "drawable", "Drawable to save"}, 78 {GIMP_PDB_STRING, "filename", "The name of the file to save the image as"}, 79 {GIMP_PDB_STRING, "raw_filename", "The name entered"}, 80 {GIMP_PDB_INT32, "compression_format", "Compression format (0 = None, 1 = BC1/DXT1, 2 = BC2/DXT3, 3 = BC3/DXT5, 4 = BC3n/DXT5n, 5 = BC4/ATI1N, 6 = BC5/ATI2N, 7 = Alpha Exponent (DXT5), 8 = YCoCg (DXT5), 9 = YCoCg scaled (DXT5))"}, 81 {GIMP_PDB_INT32, "generate_mipmaps", "Generate mipmaps"}, 82 {GIMP_PDB_INT32, "savetype", "How to save the image (0 = selected layer, 1 = cube map, 2 = volume map"}, 83 {GIMP_PDB_INT32, "format", "Custom pixel format (0 = default, 1 = R5G6B5, 2 = RGBA4, 3 = RGB5A1, 4 = RGB10A2)"}, 84 {GIMP_PDB_INT32, "transparent_index", "Index of transparent color or -1 to disable (for indexed images only)."}, 85 {GIMP_PDB_INT32, "color_type", "Color selection algorithm used in DXT compression (0 = default, 1 = distance, 2 = luminance, 3 = inset bounding box)"}, 86 {GIMP_PDB_INT32, "dither", "Work on dithered color blocks when doing color selection for DXT compression"}, 87 {GIMP_PDB_INT32, "mipmap_filter", "Filtering to use when generating mipmaps (0 = default, 1 = nearest, 2 = box, 3 = bilinear, 4 = bicubic, 5 = lanczos)"} 88 }; 89 90 MAIN() 91 92 static void query(void) 93 { 94 gimp_install_procedure(LOAD_PROC, 95 "Loads files in DDS image format", 96 "Loads files in DDS image format", 97 "Shawn Kirst", 98 "Shawn Kirst", 99 "2004", 100 "<Load>/DDS image", 101 0, 102 GIMP_PLUGIN, 103 G_N_ELEMENTS(load_args), 104 G_N_ELEMENTS(load_return_vals), 105 load_args, load_return_vals); 106 107 gimp_register_file_handler_mime(LOAD_PROC, "image/dds"); 108 gimp_register_magic_load_handler(LOAD_PROC, 109 "dds", 110 "", 111 "0,string,DDS"); 112 113 gimp_install_procedure(SAVE_PROC, 114 "Saves files in DDS image format", 115 "Saves files in DDS image format", 116 "Shawn Kirst", 117 "Shawn Kirst", 118 "2004", 119 "<Save>/DDS image", 120 "INDEXED, GRAY, RGB", 121 GIMP_PLUGIN, 122 G_N_ELEMENTS(save_args), 0, 123 save_args, 0); 124 125 gimp_register_file_handler_mime(SAVE_PROC, "image/dds"); 126 gimp_register_save_handler(SAVE_PROC, 127 "dds", 128 ""); 129 } 130 131 static void run(const gchar *name, gint nparams, const GimpParam *param, 132 gint *nreturn_vals, GimpParam **return_vals) 133 { 134 static GimpParam values[2]; 135 GimpRunMode run_mode; 136 GimpPDBStatusType status = GIMP_PDB_SUCCESS; 137 gint32 imageID; 138 gint32 drawableID; 139 GimpExportReturn export = GIMP_EXPORT_CANCEL; 140 141 run_mode = param[0].data.d_int32; 142 143 *nreturn_vals = 1; 144 *return_vals = values; 145 146 values[0].type = GIMP_PDB_STATUS; 147 values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR; 148 149 if(!strcmp(name, LOAD_PROC)) 150 { 151 switch(run_mode) 152 { 153 case GIMP_RUN_INTERACTIVE: 154 gimp_ui_init("dds", 0); 155 interactive_dds = 1; 156 gimp_get_data(LOAD_PROC, &dds_read_vals); 157 break; 158 case GIMP_RUN_NONINTERACTIVE: 159 interactive_dds = 0; 160 dds_read_vals.show_dialog = 0; 161 dds_read_vals.mipmaps = param[3].data.d_int32; 162 if(nparams != G_N_ELEMENTS(load_args)) 163 status = GIMP_PDB_CALLING_ERROR; 164 break; 165 default: 166 break; 167 } 168 169 if(status == GIMP_PDB_SUCCESS) 170 { 171 status = read_dds(param[1].data.d_string, &imageID); 172 if(status == GIMP_PDB_SUCCESS && imageID != -1) 173 { 174 *nreturn_vals = 2; 175 values[1].type = GIMP_PDB_IMAGE; 176 values[1].data.d_image = imageID; 177 if(interactive_dds) 178 gimp_set_data(LOAD_PROC, &dds_read_vals, sizeof(dds_read_vals)); 179 } 180 else if(status != GIMP_PDB_CANCEL) 181 status = GIMP_PDB_EXECUTION_ERROR; 182 } 183 } 184 else if(!strcmp(name, SAVE_PROC)) 185 { 186 imageID = param[1].data.d_int32; 187 drawableID = param[2].data.d_int32; 188 189 switch(run_mode) 190 { 191 case GIMP_RUN_INTERACTIVE: 192 case GIMP_RUN_WITH_LAST_VALS: 193 gimp_ui_init("dds", 0); 194 export = gimp_export_image(&imageID, &drawableID, "DDS", 195 (GIMP_EXPORT_CAN_HANDLE_RGB | 196 GIMP_EXPORT_CAN_HANDLE_GRAY | 197 GIMP_EXPORT_CAN_HANDLE_INDEXED | 198 GIMP_EXPORT_CAN_HANDLE_ALPHA | 199 GIMP_EXPORT_CAN_HANDLE_LAYERS)); 200 if(export == GIMP_EXPORT_CANCEL) 201 { 202 values[0].data.d_status = GIMP_PDB_CANCEL; 203 return; 204 } 205 default: 206 break; 207 } 208 209 switch(run_mode) 210 { 211 case GIMP_RUN_INTERACTIVE: 212 gimp_get_data(SAVE_PROC, &dds_write_vals); 213 interactive_dds = 1; 214 break; 215 case GIMP_RUN_NONINTERACTIVE: 216 interactive_dds = 0; 217 if(nparams != G_N_ELEMENTS(save_args)) 218 status = GIMP_PDB_CALLING_ERROR; 219 else 220 { 221 dds_write_vals.compression = param[5].data.d_int32; 222 dds_write_vals.mipmaps = param[6].data.d_int32; 223 dds_write_vals.savetype = param[7].data.d_int32; 224 dds_write_vals.format = param[8].data.d_int32; 225 dds_write_vals.transindex = param[9].data.d_int32; 226 dds_write_vals.color_type = param[10].data.d_int32; 227 dds_write_vals.dither = param[11].data.d_int32; 228 dds_write_vals.mipmap_filter = param[12].data.d_int32; 229 230 if(dds_write_vals.compression < DDS_COMPRESS_NONE || 231 dds_write_vals.compression >= DDS_COMPRESS_MAX) 232 status = GIMP_PDB_CALLING_ERROR; 233 if(dds_write_vals.savetype < DDS_SAVE_SELECTED_LAYER || 234 dds_write_vals.savetype >= DDS_SAVE_MAX) 235 status = GIMP_PDB_CALLING_ERROR; 236 if(dds_write_vals.format < DDS_FORMAT_DEFAULT || 237 dds_write_vals.format >= DDS_FORMAT_MAX) 238 status = GIMP_PDB_CALLING_ERROR; 239 if(dds_write_vals.color_type < DDS_COLOR_DEFAULT || 240 dds_write_vals.color_type >= DDS_COLOR_MAX) 241 status = GIMP_PDB_CALLING_ERROR; 242 if(dds_write_vals.mipmap_filter < DDS_MIPMAP_DEFAULT || 243 dds_write_vals.mipmap_filter >= DDS_MIPMAP_MAX) 244 status = GIMP_PDB_CALLING_ERROR; 245 } 246 break; 247 case GIMP_RUN_WITH_LAST_VALS: 248 gimp_get_data(SAVE_PROC, &dds_write_vals); 249 interactive_dds = 0; 250 break; 251 default: 252 break; 253 } 254 255 if(status == GIMP_PDB_SUCCESS) 256 { 257 status = write_dds(param[3].data.d_string, imageID, drawableID); 258 if(status == GIMP_PDB_SUCCESS) 259 gimp_set_data(SAVE_PROC, &dds_write_vals, sizeof(dds_write_vals)); 260 } 261 262 if(export == GIMP_EXPORT_EXPORT) 263 gimp_image_delete(imageID); 264 } 265 else 266 status = GIMP_PDB_CALLING_ERROR; 267 268 values[0].data.d_status = status; 269 } 270
| ViewVC Help | |
| Powered by ViewVC 1.0.4 |