Parent Directory
|
Revision Log
1.2.1 release
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 #include "dxt.h" 35 36 FILE *errFile; 37 gchar *prog_name = "dds"; 38 gchar *filename; 39 gint interactive_dds; 40 41 static void query(void); 42 static void run(const gchar *name, gint nparams, const GimpParam *param, 43 gint *nreturn_vals, GimpParam **return_vals); 44 45 GimpPlugInInfo PLUG_IN_INFO = 46 { 47 0, 0, query, run 48 }; 49 50 51 DDSSaveVals ddsvals = 52 { 53 DDS_COMPRESS_NONE, 0, 0, DDS_SAVE_SELECTED_LAYER, DDS_FORMAT_DEFAULT, -1 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 = DXT1, 2 = DXT3, 3 = DXT5, 4 = ATI1N, 5 = ATI2N)"}, 75 {GIMP_PDB_INT32, "generate_mipmaps", "Generate mipmaps"}, 76 {GIMP_PDB_INT32, "swap_ra", "Swap red and alpha channels (RGBA images only)"}, 77 {GIMP_PDB_INT32, "savetype", "How to save the image (0 = selected layer, 1 = cube map, 2 = volume map"}, 78 {GIMP_PDB_INT32, "format", "Custom pixel format (0 = default, 1 = R5G6B5, 2 = RGBA4, 3 = RGB5A1, 4 = RGB10A2)"}, 79 {GIMP_PDB_INT32, "transparent_index", "Index of transparent color or -1 to disable (for indexed images only)."} 80 }; 81 82 MAIN() 83 84 static void query(void) 85 { 86 gimp_install_procedure(LOAD_PROC, 87 "Loads files in DDS image format", 88 "Loads files in DDS image format", 89 "Shawn Kirst", 90 "Shawn Kirst", 91 "2004", 92 "<Load>/DDS image", 93 0, 94 GIMP_PLUGIN, 95 G_N_ELEMENTS(load_args), 96 G_N_ELEMENTS(load_return_vals), 97 load_args, load_return_vals); 98 99 gimp_register_file_handler_mime(LOAD_PROC, "image/dds"); 100 gimp_register_magic_load_handler(LOAD_PROC, 101 "dds", 102 "", 103 "0,string,DDS"); 104 105 gimp_install_procedure(SAVE_PROC, 106 "Saves files in DDS image format", 107 "Saves files in DDS image format", 108 "Shawn Kirst", 109 "Shawn Kirst", 110 "2004", 111 "<Save>/DDS image", 112 "INDEXED, GRAY, RGB", 113 GIMP_PLUGIN, 114 G_N_ELEMENTS(save_args), 0, 115 save_args, 0); 116 117 gimp_register_file_handler_mime(SAVE_PROC, "image/dds"); 118 gimp_register_save_handler(SAVE_PROC, 119 "dds", 120 ""); 121 } 122 123 static void run(const gchar *name, gint nparams, const GimpParam *param, 124 gint *nreturn_vals, GimpParam **return_vals) 125 { 126 static GimpParam values[2]; 127 GimpRunMode run_mode; 128 GimpPDBStatusType status = GIMP_PDB_SUCCESS; 129 gint32 imageID; 130 gint32 drawableID; 131 GimpExportReturn export = GIMP_EXPORT_CANCEL; 132 char *error; 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 error = initialize_opengl(); 143 if(error) 144 { 145 g_message(error); 146 return; 147 } 148 149 if(!strcmp(name, LOAD_PROC)) 150 { 151 switch(run_mode) 152 { 153 case GIMP_RUN_INTERACTIVE: 154 interactive_dds = 1; 155 break; 156 case GIMP_RUN_NONINTERACTIVE: 157 interactive_dds = 0; 158 if(nparams != G_N_ELEMENTS(load_args)) 159 status = GIMP_PDB_CALLING_ERROR; 160 break; 161 default: 162 break; 163 } 164 165 if(status == GIMP_PDB_SUCCESS) 166 { 167 imageID = read_dds(param[1].data.d_string); 168 if(imageID != -1) 169 { 170 *nreturn_vals = 2; 171 values[1].type = GIMP_PDB_IMAGE; 172 values[1].data.d_image = imageID; 173 } 174 else 175 status = GIMP_PDB_EXECUTION_ERROR; 176 } 177 } 178 else if(!strcmp(name, SAVE_PROC)) 179 { 180 imageID = param[1].data.d_int32; 181 drawableID = param[2].data.d_int32; 182 183 switch(run_mode) 184 { 185 case GIMP_RUN_INTERACTIVE: 186 case GIMP_RUN_WITH_LAST_VALS: 187 gimp_ui_init("dds", 0); 188 export = gimp_export_image(&imageID, &drawableID, "DDS", 189 (GIMP_EXPORT_CAN_HANDLE_RGB | 190 GIMP_EXPORT_CAN_HANDLE_GRAY | 191 GIMP_EXPORT_CAN_HANDLE_INDEXED | 192 GIMP_EXPORT_CAN_HANDLE_ALPHA | 193 GIMP_EXPORT_CAN_HANDLE_LAYERS)); 194 if(export == GIMP_EXPORT_CANCEL) 195 { 196 values[0].data.d_status = GIMP_PDB_CANCEL; 197 return; 198 } 199 default: 200 break; 201 } 202 203 switch(run_mode) 204 { 205 case GIMP_RUN_INTERACTIVE: 206 gimp_get_data(SAVE_PROC, &ddsvals); 207 interactive_dds = 1; 208 break; 209 case GIMP_RUN_NONINTERACTIVE: 210 interactive_dds = 0; 211 if(nparams != G_N_ELEMENTS(save_args)) 212 status = GIMP_PDB_CALLING_ERROR; 213 else 214 { 215 ddsvals.compression = param[5].data.d_int32; 216 ddsvals.mipmaps = param[6].data.d_int32; 217 ddsvals.swapRA = param[7].data.d_int32; 218 ddsvals.savetype = param[8].data.d_int32; 219 ddsvals.format = param[9].data.d_int32; 220 ddsvals.transindex = param[10].data.d_int32; 221 222 if(ddsvals.compression < DDS_COMPRESS_NONE || 223 ddsvals.compression >= DDS_COMPRESS_MAX) 224 status = GIMP_PDB_CALLING_ERROR; 225 if(ddsvals.savetype < DDS_SAVE_SELECTED_LAYER || 226 ddsvals.savetype >= DDS_SAVE_MAX) 227 status = GIMP_PDB_CALLING_ERROR; 228 if(ddsvals.format < DDS_FORMAT_DEFAULT || 229 ddsvals.format >= DDS_FORMAT_MAX) 230 status = GIMP_PDB_CALLING_ERROR; 231 } 232 break; 233 case GIMP_RUN_WITH_LAST_VALS: 234 gimp_get_data(SAVE_PROC, &ddsvals); 235 interactive_dds = 0; 236 break; 237 default: 238 break; 239 } 240 241 if(status == GIMP_PDB_SUCCESS) 242 { 243 status = write_dds(param[3].data.d_string, imageID, drawableID); 244 if(status == GIMP_PDB_SUCCESS) 245 gimp_set_data(SAVE_PROC, &ddsvals, sizeof(ddsvals)); 246 } 247 248 if(export == GIMP_EXPORT_EXPORT) 249 gimp_image_delete(imageID); 250 } 251 else 252 status = GIMP_PDB_CALLING_ERROR; 253 254 values[0].data.d_status = status; 255 } 256
| ViewVC Help | |
| Powered by ViewVC 1.0.4 |