Changeset 446
- Timestamp:
- Jan 10, 2005, 2:21:50 PM (18 years ago)
- Location:
- pwntcha/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pwntcha/trunk/extras/makefont.c
r443 r446 18 18 #include <stdlib.h> 19 19 #include <stdio.h> 20 #include <string.h> 20 21 21 22 #include "SDL.h" … … 24 25 int main(int argc, char *argv[]) 25 26 { 27 unsigned char *text; 26 28 SDL_Color bg = { 0xff, 0xff, 0xff, 0 }; 27 29 SDL_Color fg = { 0x00, 0x00, 0x00, 0 }; 28 SDL_Surface * text;30 SDL_Surface *surface; 29 31 TTF_Font *font; 32 int i; 30 33 31 34 if(argc != 5) … … 36 39 } 37 40 41 /* Load font */ 38 42 TTF_Init(); 39 43 font = TTF_OpenFont(argv[1], atoi(argv[2])); … … 46 50 } 47 51 52 /* Add spaces to string */ 53 text = malloc(2 * strlen(argv[3]) * sizeof(char)); 54 for(i = 0; argv[3][i]; i++) 55 { 56 text[i * 2] = argv[3][i]; 57 text[i * 2 + 1] = ' '; 58 } 59 text[i * 2 - 1] = '\0'; 60 61 /* Render text to surface */ 48 62 TTF_SetFontStyle(font, TTF_STYLE_NORMAL); 49 text= TTF_RenderUTF8_Shaded(font, argv[3], fg, bg);50 if(! text)63 surface = TTF_RenderUTF8_Shaded(font, argv[3], fg, bg); 64 if(!surface) 51 65 { 52 fprintf(stderr, " textrendering failed: %s\n", SDL_GetError());66 fprintf(stderr, "surface rendering failed: %s\n", SDL_GetError()); 53 67 TTF_CloseFont(font); 54 68 TTF_Quit(); … … 56 70 } 57 71 58 SDL_SaveBMP(text, argv[4]); 59 SDL_FreeSurface(text); 72 /* Clean up surface */ 73 74 /* Save surface and free everything */ 75 SDL_SaveBMP(surface, argv[4]); 76 SDL_FreeSurface(surface); 60 77 TTF_CloseFont(font); 61 78 TTF_Quit(); -
pwntcha/trunk/src/common.h
r445 r446 18 18 }; 19 19 20 /* font structure */ 21 struct font 22 { 23 struct image *img; 24 struct glyph 25 { 26 int xmin, xmax, ymin, ymax; 27 int count; /* Black pixel count */ 28 } *glyphs; 29 }; 30 20 31 /* global variables */ 21 32 extern char *argv0; … … 33 44 char *decode_slashdot(struct image *img); 34 45 char *decode_vbulletin(struct image *img); 46 char *decode_xanga(struct image *img); 35 47 char *decode_test(struct image *img); 36 48 -
pwntcha/trunk/src/slashdot.c
r445 r446 25 25 26 26 /* Our macros */ 27 #define FACTOR 1 28 #define FONTNAME "font_slashdot.png" // use with FACTOR = 1 29 //#define FONTNAME "font.png" // use with FACTOR = 2 30 //#define FONTNAME "font_dilated.png" // use with FACTOR = 2 31 static struct image *font = NULL; 27 #define FONTNAME "font_slashdot.png" 28 29 struct font font; 30 struct glyph glyphs[22]; 32 31 33 32 /* Global stuff */ … … 169 168 } 170 169 171 tmp = image_new(img->width * FACTOR, img->height * FACTOR);172 173 for(y = 0; y < img->height * FACTOR; y++)174 for(x = 0; x < img->width * FACTOR; x++)175 { 176 xtmp = 1.0 * (x - img->width * FACTOR / 2) / FACTOR;177 ytmp = 1.0 * (y - img->height * FACTOR / 2) / FACTOR;170 tmp = image_new(img->width, img->height); 171 172 for(y = 0; y < img->height; y++) 173 for(x = 0; x < img->width; x++) 174 { 175 xtmp = 1.0 * (x - img->width / 2); 176 ytmp = 1.0 * (y - img->height / 2); 178 177 xdest = xtmp * cosa - ytmp * sina + 0.5 * img->width; 179 178 ydest = ytmp * cosa + xtmp * sina + 0.5 * img->height; … … 232 231 { 233 232 char all[] = "abcdefgijkmnpqrstvwxyz"; 234 struct235 {236 int xmin, xmax, ymin, ymax;237 int count;238 }239 glyphs[22];240 233 struct image *tmp; 241 234 int x, y, i = 0; … … 244 237 int distmin, distx, disty, distch; 245 238 246 if(!font )239 if(!font.img) 247 240 { 248 241 char fontname[BUFSIZ]; 249 242 sprintf(fontname, "%s/%s", share, FONTNAME); 250 font = image_load(fontname);251 if(!font )243 font.img = image_load(fontname); 244 if(!font.img) 252 245 { 253 246 fprintf(stderr, "cannot load font %s\n", fontname); 254 247 exit(-1); 255 248 } 249 font.glyphs = glyphs; 256 250 } 257 251 … … 265 259 } 266 260 267 for(x = 0; x < font ->width; x++)261 for(x = 0; x < font.img->width; x++) 268 262 { 269 263 int found = 0; 270 for(y = 0; y < font ->height; y++)271 { 272 getpixel(font , x, y, &r, &g, &b);264 for(y = 0; y < font.img->height; y++) 265 { 266 getpixel(font.img, x, y, &r, &g, &b); 273 267 if(r < 128) 274 268 { … … 287 281 xmax = x; 288 282 #if 0 289 ymin = font ->height;283 ymin = font.img->height; 290 284 ymax = 0; 291 for(y = 0; y < font ->height; y++)285 for(y = 0; y < font.img->height; y++) 292 286 { 293 287 int newx; … … 295 289 for(newx = xmin; newx < xmax; newx++) 296 290 { 297 getpixel(font , newx, y, &r, &g, &b);291 getpixel(font.img, newx, y, &r, &g, &b); 298 292 if(r < 128) 299 293 { … … 310 304 #else 311 305 ymin = 0; 312 ymax = font ->height;306 ymax = font.img->height; 313 307 #endif 314 glyphs[i].xmin = xmin;315 glyphs[i].xmax = xmax;316 glyphs[i].ymin = ymin;317 glyphs[i].ymax = ymax;318 glyphs[i].count = count;308 font.glyphs[i].xmin = xmin; 309 font.glyphs[i].xmax = xmax; 310 font.glyphs[i].ymin = ymin; 311 font.glyphs[i].ymax = ymax; 312 font.glyphs[i].count = count; 319 313 count = 0; 320 314 i++; … … 336 330 int localmin = INT_MAX, localx, localy; 337 331 //if(all[i] == 'i') continue; 338 xmin = glyphs[i].xmin;339 ymin = glyphs[i].ymin;340 xmax = glyphs[i].xmax;341 ymax = glyphs[i].ymax;332 xmin = font.glyphs[i].xmin; 333 ymin = font.glyphs[i].ymin; 334 xmax = font.glyphs[i].xmax; 335 ymax = font.glyphs[i].ymax; 342 336 //printf("trying to find %c (%i×%i) - ", all[i], xmax - xmin, ymax - ymin); 343 for(y = -5 * FACTOR; y < 5 * FACTOR; y++)344 for(x = startx - 5 * FACTOR; x < startx + 5 * FACTOR; x++)337 for(y = -5; y < 5; y++) 338 for(x = startx - 5; x < startx + 5; x++) 345 339 { 346 340 int z, t, dist; … … 350 344 { 351 345 int r2; 352 getgray(font , xmin + z, ymin + t, &r);346 getgray(font.img, xmin + z, ymin + t, &r); 353 347 getgray(img, x + z, y + t, &r2); 354 348 dist += abs(r - r2); … … 356 350 // printf("%i %i -> %i\n", x, y, dist); 357 351 //dist /= sqrt(xmax - xmin); 358 dist = dist * 128 / glyphs[i].count;352 dist = dist * 128 / font.glyphs[i].count; 359 353 if(dist < localmin) 360 354 { … … 378 372 379 373 /* Print min glyph */ 380 xmin = glyphs[distch].xmin;381 ymin = glyphs[distch].ymin;382 xmax = glyphs[distch].xmax;383 ymax = glyphs[distch].ymax;374 xmin = font.glyphs[distch].xmin; 375 ymin = font.glyphs[distch].ymin; 376 xmax = font.glyphs[distch].xmax; 377 ymax = font.glyphs[distch].ymax; 384 378 for(y = 0; y < ymax - ymin; y++) 385 379 for(x = 0; x < xmax - xmin; x++) 386 380 { 387 getpixel(font , xmin + x, ymin + y, &r, &g, &b);381 getpixel(font.img, xmin + x, ymin + y, &r, &g, &b); 388 382 if(r > 128) continue; 389 383 setpixel(tmp, distx + x, disty + y, r, g, b);
Note: See TracChangeset
for help on using the changeset viewer.