| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#include <stdio.h> |
| 25 |
#include <libgimp/gimp.h> |
| 26 |
|
| 27 |
static void query (void); |
| 28 |
static void run (const gchar *name, |
| 29 |
gint nparams, |
| 30 |
const GimpParam *param, |
| 31 |
gint *nreturn_vals, |
| 32 |
GimpParam **return_vals); |
| 33 |
|
| 34 |
GimpPlugInInfo PLUG_IN_INFO = |
| 35 |
{ |
| 36 |
NULL, |
| 37 |
NULL, |
| 38 |
query, |
| 39 |
run |
| 40 |
}; |
| 41 |
|
| 42 |
MAIN() |
| 43 |
|
| 44 |
static void |
| 45 |
query (void) |
| 46 |
{ |
| 47 |
static GimpParamDef args[] = |
| 48 |
{ |
| 49 |
{ |
| 50 |
GIMP_PDB_INT32, |
| 51 |
"run-mode", |
| 52 |
"Run mode" |
| 53 |
}, |
| 54 |
{ |
| 55 |
GIMP_PDB_IMAGE, |
| 56 |
"image", |
| 57 |
"Input image" |
| 58 |
}, |
| 59 |
{ |
| 60 |
GIMP_PDB_DRAWABLE, |
| 61 |
"drawable", |
| 62 |
"Input drawable" |
| 63 |
} |
| 64 |
}; |
| 65 |
|
| 66 |
gimp_install_procedure ( |
| 67 |
"plug-in-SDLB", |
| 68 |
"Output level to console", |
| 69 |
"Create SDL-Ball level from pixels and output to console", |
| 70 |
"Jimmy Christensen", |
| 71 |
"SDL-Ball", |
| 72 |
"2008", |
| 73 |
"_Make Level", |
| 74 |
"RGB*, GRAY*", |
| 75 |
GIMP_PLUGIN, |
| 76 |
G_N_ELEMENTS (args), 0, |
| 77 |
args, NULL); |
| 78 |
|
| 79 |
gimp_plugin_menu_register ("plug-in-SDLB", |
| 80 |
"<Image>/sdlb"); |
| 81 |
printf("SDL-Ball Gimp Leveleditor plugin Registered\n"); |
| 82 |
} |
| 83 |
|
| 84 |
static int samergb(guchar a[], guchar b[]) |
| 85 |
{ |
| 86 |
if(a[0] == b[0] && a[1] == b[1] && a[2] == b[2]) |
| 87 |
{ |
| 88 |
return(1); |
| 89 |
} |
| 90 |
return(0); |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
static void |
| 95 |
run (const gchar *name, |
| 96 |
gint nparams, |
| 97 |
const GimpParam *param, |
| 98 |
gint *nreturn_vals, |
| 99 |
GimpParam **return_vals) |
| 100 |
{ |
| 101 |
static GimpParam values[1]; |
| 102 |
GimpPDBStatusType status = GIMP_PDB_SUCCESS; |
| 103 |
GimpRunMode run_mode; |
| 104 |
|
| 105 |
|
| 106 |
*nreturn_vals = 1; |
| 107 |
*return_vals = values; |
| 108 |
|
| 109 |
values[0].type = GIMP_PDB_STATUS; |
| 110 |
values[0].data.d_status = status; |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
run_mode = param[0].data.d_int32; |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
GimpDrawable *drawable; |
| 120 |
|
| 121 |
|
| 122 |
drawable = gimp_drawable_get (param[2].data.d_drawable); |
| 123 |
|
| 124 |
|
| 125 |
GimpPixelRgn rgn; |
| 126 |
|
| 127 |
guchar pix[4]; |
| 128 |
|
| 129 |
gimp_pixel_rgn_init(&rgn, drawable, 0,0, 26,23,FALSE,FALSE); |
| 130 |
|
| 131 |
int row,bri; |
| 132 |
|
| 133 |
#define R 0 |
| 134 |
#define G 1 |
| 135 |
#define B 2 |
| 136 |
#define A 3 |
| 137 |
|
| 138 |
#define BLU 0 |
| 139 |
#define YEL 1 |
| 140 |
#define CEM 2 |
| 141 |
#define GLA 3 |
| 142 |
#define GRE 4 |
| 143 |
#define STE 5 |
| 144 |
#define PUR 6 |
| 145 |
#define WHI 7 |
| 146 |
#define INV 8 |
| 147 |
#define RED 9 |
| 148 |
#define EXP 10 |
| 149 |
#define DOO 11 |
| 150 |
#define NON 12 |
| 151 |
|
| 152 |
guchar type[12][4]; |
| 153 |
|
| 154 |
type[BLU][R] = 0; |
| 155 |
type[BLU][G] = 0; |
| 156 |
type[BLU][B] = 255; |
| 157 |
|
| 158 |
type[YEL][R] = 255; |
| 159 |
type[YEL][G] = 255 ; |
| 160 |
type[YEL][B] = 0; |
| 161 |
|
| 162 |
type[CEM][R] = 0xC9; |
| 163 |
type[CEM][G] = 0xC9; |
| 164 |
type[CEM][B] = 0xC9; |
| 165 |
|
| 166 |
type[CEM][R] = 0xC9; |
| 167 |
type[CEM][G] = 0xC9; |
| 168 |
type[CEM][B] = 0xC9; |
| 169 |
|
| 170 |
type[GLA][R] = 0xFF; |
| 171 |
type[GLA][G] = 0xC5; |
| 172 |
type[GLA][B] = 0xC5; |
| 173 |
|
| 174 |
type[GRE][R] = 0x00; |
| 175 |
type[GRE][G] = 0xFF; |
| 176 |
type[GRE][B] = 0x00; |
| 177 |
|
| 178 |
type[STE][R] = 0xDB; |
| 179 |
type[STE][G] = 0xCF; |
| 180 |
type[STE][B] = 0xFF; |
| 181 |
|
| 182 |
type[PUR][R] = 0xFF; |
| 183 |
type[PUR][G] = 0x00; |
| 184 |
type[PUR][B] = 0xFF; |
| 185 |
|
| 186 |
type[WHI][R] = 0xFF; |
| 187 |
type[WHI][G] = 0xFF; |
| 188 |
type[WHI][B] = 0xFF; |
| 189 |
|
| 190 |
type[INV][R] = 0x00; |
| 191 |
type[INV][G] = 0xff; |
| 192 |
type[INV][B] = 0xd8; |
| 193 |
|
| 194 |
type[RED][R] = 0xFF; |
| 195 |
type[RED][G] = 0x00; |
| 196 |
type[RED][B] = 0x00; |
| 197 |
|
| 198 |
type[EXP][R] = 0xFF; |
| 199 |
type[EXP][G] = 0xB9; |
| 200 |
type[EXP][B] = 0x00; |
| 201 |
|
| 202 |
type[DOO][R] = 0x72; |
| 203 |
type[DOO][G] = 0x00; |
| 204 |
type[DOO][B] = 0xFF; |
| 205 |
|
| 206 |
type[NON][R] = 0x00; |
| 207 |
type[NON][G] = 0x00; |
| 208 |
type[NON][B] = 0x00; |
| 209 |
|
| 210 |
char level[23][26]; |
| 211 |
|
| 212 |
char brickColor[23][26][7]; |
| 213 |
|
| 214 |
char powerups[23][26]; |
| 215 |
|
| 216 |
for(row=0; row < 23; row++) |
| 217 |
{ |
| 218 |
for(bri=0; bri < 26; bri++) |
| 219 |
{ |
| 220 |
|
| 221 |
gimp_pixel_rgn_get_pixel(&rgn, pix,bri,row); |
| 222 |
|
| 223 |
|
| 224 |
if(samergb(pix, type[BLU])) |
| 225 |
{ |
| 226 |
level[row][bri]='1'; |
| 227 |
} else if(samergb(pix, type[YEL])) |
| 228 |
{ |
| 229 |
level[row][bri]='2'; |
| 230 |
} else if(samergb(pix,type[CEM])) |
| 231 |
{ |
| 232 |
level[row][bri]='3'; |
| 233 |
} else if(samergb(pix,type[GLA])) |
| 234 |
{ |
| 235 |
level[row][bri]='4'; |
| 236 |
} else if(samergb(pix,type[GRE])) |
| 237 |
{ |
| 238 |
level[row][bri]='5'; |
| 239 |
} else if(samergb(pix,type[STE])) |
| 240 |
{ |
| 241 |
level[row][bri]='6'; |
| 242 |
} else if(samergb(pix,type[PUR])) |
| 243 |
{ |
| 244 |
level[row][bri]='7'; |
| 245 |
} else if(samergb(pix,type[WHI])) |
| 246 |
{ |
| 247 |
level[row][bri]='8'; |
| 248 |
} else if(samergb(pix,type[INV])) |
| 249 |
{ |
| 250 |
level[row][bri]='9'; |
| 251 |
} else if(samergb(pix,type[RED])) |
| 252 |
{ |
| 253 |
level[row][bri]='A'; |
| 254 |
} else if(samergb(pix,type[EXP])) |
| 255 |
{ |
| 256 |
level[row][bri]='B'; |
| 257 |
} else if(samergb(pix,type[DOO])) |
| 258 |
{ |
| 259 |
level[row][bri]='C'; |
| 260 |
} else if(samergb(pix, type[NON])) |
| 261 |
{ |
| 262 |
|
| 263 |
level[row][bri]='0'; |
| 264 |
} else |
| 265 |
{ |
| 266 |
|
| 267 |
sprintf(brickColor[row][bri], "%02X%02X%02X",pix[0],pix[1],pix[2]); |
| 268 |
level[row][bri]='D'; |
| 269 |
} |
| 270 |
|
| 271 |
if(level[row][bri] != '0' && level[row][bri] != '3') |
| 272 |
{ |
| 273 |
|
| 274 |
powerups[row][bri]='L'; |
| 275 |
|
| 276 |
} else { |
| 277 |
powerups[row][bri]='0'; |
| 278 |
} |
| 279 |
} |
| 280 |
} |
| 281 |
|
| 282 |
printf("\n\n** Start **"); |
| 283 |
for(row=0; row < 23; row++) |
| 284 |
{ |
| 285 |
printf("\n"); |
| 286 |
for(bri=0; bri < 26; bri++) |
| 287 |
{ |
| 288 |
printf("%c%c",powerups[row][bri],level[row][bri]); |
| 289 |
if(level[row][bri] == 'D') |
| 290 |
{ |
| 291 |
printf("%s", brickColor[row][bri]); |
| 292 |
} |
| 293 |
} |
| 294 |
} |
| 295 |
printf("** Stop **"); |
| 296 |
|
| 297 |
|
| 298 |
printf("\n"); |
| 299 |
|
| 300 |
gimp_drawable_flush (drawable); |
| 301 |
|
| 302 |
gimp_displays_flush (); |
| 303 |
gimp_drawable_detach (drawable); |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
} |