Parent Directory
|
Revision Log
Replacing 2.0.1 release tag, phase 2 of 2
1 /* 2 DDS GIMP plugin 3 4 Copyright (C) 2004 Shawn Kirst <skirst@fuse.net>, 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 DDSSaveVals ddsvals = 51 { 52 DDS_COMPRESS_NONE, 0, DDS_SAVE_SELECTED_LAYER, DDS_FORMAT_DEFAULT, -1, 53 DDS_COLOR_DEFAULT, 0, 0 54 }; 55 56 static GimpParamDef load_args[] = 57 { 58 {GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive"}, 59 {GIMP_PDB_STRING, "filename", "The name of the file to load"}, 60 {GIMP_PDB_STRING, "raw_filename", "The name entered"} 61 }; 62 static GimpParamDef load_return_vals[] = 63 { 64 {GIMP_PDB_IMAGE, "image", "Output image"} 65 }; 66 67 static GimpParamDef save_args[] = 68 { 69 {GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive"}, 70 {GIMP_PDB_IMAGE, "image", "Input image"}, 71 {GIMP_PDB_DRAWABLE, "drawable", "Drawable to save"}, 72 {GIMP_PDB_STRING, "filename", "The name of the file to save the image as"}, 73 {GIMP_PDB_STRING, "raw_filename", "The name entered"}, 74 {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))"}, 75 {GIMP_PDB_INT32, "generate_mipmaps", "Generate mipmaps"}, 76 {GIMP_PDB_INT32, "savetype", "How to save the image (0 = selected layer, 1 = cube map, 2 = volume map"}, 77 {GIMP_PDB_INT32, "format", "Custom pixel format (0 = default, 1 = R5G6B5, 2 = RGBA4, 3 = RGB5A1, 4 = RGB10A2)"}, 78 {GIMP_PDB_INT32, "transparent_index", "Index of transparent color or -1 to disable (for indexed images only)."}, 79 {GIMP_PDB_INT32, "color_type", "Color selection algorithm used in DXT compression (0 = default, 1 = distance, 2 = luminance, 3 = inset bounding box)"}, 80 {GIMP_PDB_INT32, "dither", "Work on dithered color blocks when doing color selection for DXT compression"} 81 }; 82 83 MAIN() 84 85 static void query(void) 86 { 87 gimp_install_procedure(LOAD_PROC, 88 "Loads files in DDS image format", 89 "Loads files in DDS image format", 90 "Shawn Kirst", 91 "Shawn Kirst", 92 "2004", 93 "<Load>/DDS image", 94 0, 95 GIMP_PLUGIN, 96 G_N_ELEMENTS(load_args), 97 G_N_ELEMENTS(load_return_vals), 98 load_args, load_return_vals); 99 100 gimp_register_file_handler_mime(LOAD_PROC, "image/dds"); 101 gimp_register_magic_load_handler(LOAD_PROC, 102 "dds", 103 "", 104 "0,string,DDS"); 105 106 gimp_install_procedure(SAVE_PROC, 107 "Saves files in DDS image format", 108 "Saves files in DDS image format", 109 "Shawn Kirst", 110 "Shawn Kirst", 111 "2004", 112 "<Save>/DDS image", 113 "INDEXED, GRAY, RGB", 114 GIMP_PLUGIN, 115 G_N_ELEMENTS(save_args), 0, 116 save_args, 0); 117 118 gimp_register_file_handler_mime(SAVE_PROC, "image/dds"); 119 gimp_register_save_handler(SAVE_PROC, 120 "dds", 121 ""); 122 } 123 124 static void run(const gchar *name, gint nparams, const GimpParam *param, 125 gint *nreturn_vals, GimpParam **return_vals) 126 { 127 static GimpParam values[2]; 128 GimpRunMode run_mode; 129 GimpPDBStatusType status = GIMP_PDB_SUCCESS; 130 gint32 imageID; 131 gint32 drawableID; 132 GimpExportReturn export = GIMP_EXPORT_CANCEL; 133 134 run_mode = param[0].data.d_int32; 135 136 *nreturn_vals = 1; 137 *return_vals = values; 138 139 values[0].type = GIMP_PDB_STATUS; 140 values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR; 141 142 if(!strcmp(name, LOAD_PROC)) 143 { 144 switch(run_mode) 145 { 146 case GIMP_RUN_INTERACTIVE: 147 interactive_dds = 1; 148 break; 149 case GIMP_RUN_NONINTERACTIVE: 150 interactive_dds = 0; 151 if(nparams != G_N_ELEMENTS(load_args)) 152 status = GIMP_PDB_CALLING_ERROR; 153 break; 154 default: 155 break; 156 } 157 158 if(status == GIMP_PDB_SUCCESS) 159 { 160 imageID = read_dds(param[1].data.d_string); 161 if(imageID != -1) 162 { 163 *nreturn_vals = 2; 164 values[1].type = GIMP_PDB_IMAGE; 165 values[1].data.d_image = imageID; 166 } 167 else 168 status = GIMP_PDB_EXECUTION_ERROR; 169 } 170 } 171 else if(!strcmp(name, SAVE_PROC)) 172 { 173 imageID = param[1].data.d_int32; 174 drawableID = param[2].data.d_int32; 175 176 switch(run_mode) 177 { 178 case GIMP_RUN_INTERACTIVE: 179 case GIMP_RUN_WITH_LAST_VALS: 180 gimp_ui_init("dds", 0); 181 export = gimp_export_image(&imageID, &drawableID, "DDS", 182 (GIMP_EXPORT_CAN_HANDLE_RGB | 183 GIMP_EXPORT_CAN_HANDLE_GRAY | 184 GIMP_EXPORT_CAN_HANDLE_INDEXED | 185 GIMP_EXPORT_CAN_HANDLE_ALPHA | 186 GIMP_EXPORT_CAN_HANDLE_LAYERS)); 187 if(export == GIMP_EXPORT_CANCEL) 188 { 189 values[0].data.d_status = GIMP_PDB_CANCEL; 190 return; 191 } 192 default: 193 break; 194 } 195 196 switch(run_mode) 197 { 198 case GIMP_RUN_INTERACTIVE: 199 gimp_get_data(SAVE_PROC, &ddsvals); 200 interactive_dds = 1; 201 break; 202 case GIMP_RUN_NONINTERACTIVE: 203 interactive_dds = 0; 204 if(nparams != G_N_ELEMENTS(save_args)) 205 status = GIMP_PDB_CALLING_ERROR; 206 else 207 { 208 ddsvals.compression = param[5].data.d_int32; 209 ddsvals.mipmaps = param[6].data.d_int32; 210 ddsvals.savetype = param[7].data.d_int32; 211 ddsvals.format = param[8].data.d_int32; 212 ddsvals.transindex = param[9].data.d_int32; 213 ddsvals.color_type = param[10].data.d_int32; 214 ddsvals.dither = param[11].data.d_int32; 215 216 if(ddsvals.compression < DDS_COMPRESS_NONE || 217 ddsvals.compression >= DDS_COMPRESS_MAX) 218 status = GIMP_PDB_CALLING_ERROR; 219 if(ddsvals.savetype < DDS_SAVE_SELECTED_LAYER || 220 ddsvals.savetype >= DDS_SAVE_MAX) 221 status = GIMP_PDB_CALLING_ERROR; 222 if(ddsvals.format < DDS_FORMAT_DEFAULT || 223 ddsvals.format >= DDS_FORMAT_MAX) 224 status = GIMP_PDB_CALLING_ERROR; 225 if(ddsvals.color_type < DDS_COLOR_DEFAULT || 226 ddsvals.color_type >= DDS_COLOR_MAX) 227 status = GIMP_PDB_CALLING_ERROR; 228 } 229 break; 230 case GIMP_RUN_WITH_LAST_VALS: 231 gimp_get_data(SAVE_PROC, &ddsvals); 232 interactive_dds = 0; 233 break; 234 default: 235 break; 236 } 237 238 if(status == GIMP_PDB_SUCCESS) 239 { 240 status = write_dds(param[3].data.d_string, imageID, drawableID); 241 if(status == GIMP_PDB_SUCCESS) 242 gimp_set_data(SAVE_PROC, &ddsvals, sizeof(ddsvals)); 243 } 244 245 if(export == GIMP_EXPORT_EXPORT) 246 gimp_image_delete(imageID); 247 } 248 else 249 status = GIMP_PDB_CALLING_ERROR; 250 251 values[0].data.d_status = status; 252 } 253
| ViewVC Help | |
| Powered by ViewVC 1.0.4 |