Changeset 445 for pwntcha/trunk
- Timestamp:
- Jan 10, 2005, 12:23:38 PM (17 years ago)
- Location:
- pwntcha/trunk/src
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
pwntcha/trunk/src/Makefile.am
r444 r445 20 20 pwntcha_LDADD = $(ADDITIONAL_LDADD) 21 21 22 #if USE_DEVIL23 #ADDITIONAL_CFLAGS =24 #ADDITIONAL_LDFLAGS =25 #ADDITIONAL_LDADD = -lDevIL26 #else27 #if USE_OLE28 #ADDITIONAL_CFLAGS =29 #ADDITIONAL_LDFLAGS =30 #ADDITIONAL_LDADD = -luuid -loleaut32 -lole32 -lgdi3231 #else32 22 if USE_SDL 33 23 ADDITIONAL_CFLAGS = `sdl-config --cflags` … … 51 41 endif 52 42 endif 53 #endif54 #endif55 43 -
pwntcha/trunk/src/authimage.c
r430 r445 27 27 char *all = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 28 28 char *result; 29 struct image *tmp 1, *tmp2, *tmp3;29 struct image *tmp; 30 30 int x, y, r, g, b, i; 31 31 … … 47 47 48 48 /* half the captchas are inverse video; we set them back to normal */ 49 tmp1 = filter_scale(img, 2.0); 50 getpixel(img, 0, 0, &r, &g, &b); 51 tmp2 = filter_equalize(tmp1, r * 3 / 4); 52 tmp3 = filter_smooth(tmp2); 49 tmp = image_dup(img); 50 filter_scale(tmp, 2.0); 51 getpixel(tmp, 0, 0, &r, &g, &b); 52 filter_equalize(tmp, r * 3 / 4); 53 filter_smooth(tmp); 53 54 54 55 for(i = 0; i < 6; i++) … … 65 66 newx = 35.0 + (x + 6 * i) * 218.0 / 34.0 + y * 5.0 / 6.0 + 0.5; 66 67 newy = 33.0 - (x + 6 * i) * 18.0 / 34.0 + y * 42.0 / 6.0 + 0.5; 67 getpixel(tmp 3, newx, newy, &r, &g, &b);68 getpixel(tmp, newx, newy, &r, &g, &b); 68 69 getpixel(font, x + 6 * ch, y, &r2, &g, &b); 69 70 r = (r < 220) ? 0 : 255; … … 80 81 } 81 82 82 image_free(tmp3); 83 image_free(tmp2); 84 image_free(tmp1); 83 image_free(tmp); 85 84 86 85 return result; -
pwntcha/trunk/src/clubic.c
r430 r445 18 18 #include "common.h" 19 19 20 static struct image *find_glyphs(struct image *img);20 static void find_glyphs(struct image *img); 21 21 22 22 /* Our macros */ … … 28 28 char *decode_clubic(struct image *img) 29 29 { 30 struct image *tmp 1, *tmp2;30 struct image *tmp; 31 31 32 32 if(!font) … … 46 46 strcpy(result, " "); 47 47 48 tmp1 = filter_equalize(img, 200); 49 tmp2 = find_glyphs(tmp1); 48 tmp = image_dup(img); 49 filter_equalize(tmp, 200); 50 find_glyphs(tmp); 50 51 51 image_free(tmp1); 52 image_free(tmp2); 52 image_free(tmp); 53 53 54 54 return result; 55 55 } 56 56 57 static struct image *find_glyphs(struct image *img)57 static void find_glyphs(struct image *img) 58 58 { 59 59 char all[] = "0123456789"; … … 64 64 } 65 65 glyphs[10]; 66 struct image * dst;66 struct image *tmp; 67 67 int x, y, i = 0; 68 68 int r, g, b; … … 70 70 int distmin, distx, disty, distch; 71 71 72 dst= image_new(img->width, img->height);72 tmp = image_new(img->width, img->height); 73 73 74 74 for(y = 0; y < img->height; y++) … … 76 76 { 77 77 getpixel(img, x, y, &r, &g, &b); 78 setpixel( dst, x, y, 255, g, 255);78 setpixel(tmp, x, y, 255, g, 255); 79 79 } 80 80 … … 169 169 getpixel(font, xmin + x, ymin + y, &r, &g, &b); 170 170 if(r > 128) continue; 171 setpixel( dst, distx + x, disty + y, r, g, b);171 setpixel(tmp, distx + x, disty + y, r, g, b); 172 172 } 173 173 … … 176 176 } 177 177 178 return dst;178 image_free(tmp); 179 179 } 180 180 -
pwntcha/trunk/src/common.h
r438 r445 38 38 struct image *image_load(const char *name); 39 39 struct image *image_new(int width, int height); 40 struct image *image_dup(struct image *img); 40 41 void image_free(struct image *img); 41 42 void image_save(struct image *img, const char *name); 43 void image_swap(struct image *img1, struct image *img2); 42 44 int getgray(struct image *img, int x, int y, int *g); 43 45 int getpixel(struct image *img, int x, int y, int *r, int *g, int *b); … … 46 48 /* image filters */ 47 49 void filter_flood_fill(struct image *img, int x, int y, int r, int g, int b); 48 struct image *filter_fill_holes(struct image *img); 49 struct image *filter_dup(struct image *img); 50 struct image *filter_scale(struct image *img, float ratio); 51 struct image *filter_black_stuff(struct image *img); 52 struct image *filter_detect_lines(struct image *img); 53 struct image *filter_equalize(struct image *img, int threshold); 54 struct image *filter_trick(struct image *img); 55 struct image *filter_smooth(struct image *img); 56 struct image *filter_median(struct image *img); 57 struct image *filter_contrast(struct image *img); 58 struct image *filter_crop(struct image *img, 59 int xmin, int ymin, int xmax, int ymax); 50 void filter_fill_holes(struct image *img); 51 void filter_scale(struct image *img, float ratio); 52 void filter_black_stuff(struct image *img); 53 void filter_detect_lines(struct image *img); 54 void filter_equalize(struct image *img, int threshold); 55 void filter_trick(struct image *img); 56 void filter_smooth(struct image *img); 57 void filter_median(struct image *img); 58 void filter_contrast(struct image *img); 59 void filter_crop(struct image *img, int xmin, int ymin, int xmax, int ymax); 60 60 int filter_count(struct image *img); 61 61 -
pwntcha/trunk/src/filters.c
r441 r445 47 47 } 48 48 49 struct image *filter_dup(struct image *img) 50 { 51 struct image *dst; 52 int x, y; 53 int r, g, b; 54 55 dst = image_new(img->width, img->height); 56 57 for(y = 0; y < img->height; y++) 58 for(x = 0; x < img->width; x++) 59 { 60 getpixel(img, x, y, &r, &g, &b); 61 setpixel(dst, x, y, r, g, b); 62 } 63 64 return dst; 65 } 66 67 struct image *filter_scale(struct image *img, float ratio) 49 void filter_scale(struct image *img, float ratio) 68 50 { 69 51 struct image *dst; … … 83 65 } 84 66 85 return dst; 86 } 87 88 struct image *filter_fill_holes(struct image *img) 67 image_swap(img, dst); 68 image_free(dst); 69 } 70 71 void filter_fill_holes(struct image *img) 89 72 { 90 73 struct image *dst; … … 133 116 } 134 117 135 return dst; 136 } 137 138 struct image *filter_black_stuff(struct image *img) 118 image_swap(img, dst); 119 image_free(dst); 120 } 121 122 void filter_black_stuff(struct image *img) 139 123 { 140 124 struct image *dst; … … 173 157 } 174 158 175 return dst; 176 } 177 178 struct image *filter_detect_lines(struct image *img) 159 image_swap(img, dst); 160 image_free(dst); 161 } 162 163 void filter_detect_lines(struct image *img) 179 164 { 180 165 struct image *dst; … … 213 198 } 214 199 215 return dst; 216 } 217 218 struct image *filter_equalize(struct image *img, int threshold) 200 image_swap(img, dst); 201 image_free(dst); 202 } 203 204 void filter_equalize(struct image *img, int threshold) 219 205 { 220 206 struct image *dst; … … 244 230 } 245 231 246 return dst; 247 } 248 249 struct image *filter_trick(struct image *img) 232 image_swap(img, dst); 233 image_free(dst); 234 } 235 236 void filter_trick(struct image *img) 250 237 { 251 238 #define TSIZE 3 … … 290 277 } 291 278 292 return dst; 293 } 294 295 struct image *filter_smooth(struct image *img) 279 image_swap(img, dst); 280 image_free(dst); 281 } 282 283 void filter_smooth(struct image *img) 296 284 { 297 285 #define SSIZE 3 … … 321 309 } 322 310 323 return dst; 324 } 325 326 struct image *filter_median(struct image *img) 311 image_swap(img, dst); 312 image_free(dst); 313 } 314 315 void filter_median(struct image *img) 327 316 { 328 317 #define MSIZE 3 … … 361 350 } 362 351 363 return dst; 364 } 365 366 struct image *filter_contrast(struct image *img) 352 image_swap(img, dst); 353 image_free(dst); 354 } 355 356 void filter_contrast(struct image *img) 367 357 { 368 358 struct image *dst; … … 394 384 } 395 385 396 return dst;397 } 398 399 struct image *filter_crop(struct image *img, 400 386 image_swap(img, dst); 387 image_free(dst); 388 } 389 390 void filter_crop(struct image *img, int xmin, int ymin, int xmax, int ymax) 401 391 { 402 392 struct image *dst; … … 414 404 415 405 if(xmin >= xmax || ymin >= ymax) 416 return NULL;406 return; 417 407 418 408 dst = image_new(xmax - xmin, ymax - ymin); … … 425 415 } 426 416 427 return dst; 417 image_swap(img, dst); 418 image_free(dst); 428 419 } 429 420 -
pwntcha/trunk/src/image.c
r442 r445 12 12 #include <stdio.h> 13 13 #include <stdlib.h> 14 #include <string.h> 14 15 15 16 #include "config.h" 16 17 #include "common.h" 17 18 18 #if defined(HAVE_IL_H) 19 # error "DevIL routines not implemented yet" 20 #elif defined(HAVE_OLECTL_H) 21 # include <windows.h> 22 # include <ocidl.h> 23 # include <olectl.h> 24 static BOOL oleload(LPCTSTR name, LPPICTURE* pic); 25 struct priv 26 { 27 HBITMAP bitmap; 28 BITMAPINFO info; 29 }; 30 #elif defined(HAVE_SDL_IMAGE_H) 19 #if defined(HAVE_SDL_IMAGE_H) 31 20 # include <SDL_image.h> 32 21 #elif defined(HAVE_IMLIB2_H) … … 42 31 { 43 32 struct image *img; 44 #if defined(HAVE_IL_H) 45 #elif defined(HAVE_OLECTL_H) 46 struct priv *priv = malloc(sizeof(struct priv)); 47 LPPICTURE pic = NULL; 48 HDC dc; 49 long scrwidth = 0, scrheight = 0; 50 int width, height; 51 void *data = NULL; 52 #elif defined(HAVE_SDL_IMAGE_H) 33 #if defined(HAVE_SDL_IMAGE_H) 53 34 SDL_Surface *priv = IMG_Load(name); 54 35 #elif defined(HAVE_IMLIB2_H) … … 61 42 return NULL; 62 43 63 #if defined(HAVE_OLECTL_H) 64 if(!oleload((LPCTSTR)name, &pic)) 65 { 66 free(priv); 67 return NULL; 68 } 69 70 #if 0 71 for(i = 0; ; i++) 72 { 73 DEVMODE devMode; 74 devMode.dmSize = sizeof(DEVMODE); 75 76 if(EnumDisplaySettings(NULL, i, &devMode) != 1) 77 break; 78 79 printf("mode %i x %i - %i\n", (int)devMode.dmPelsWidth, 80 (int)devMode.dmPelsHeight, (int)devMode.dmBitsPerPel); 81 } 82 #endif 83 84 dc = CreateCompatibleDC(NULL); 85 86 if(GetDeviceCaps(dc, BITSPIXEL) < 24) 87 { 88 fprintf(stderr, "%s: 24bpp screen depth or better required\n", argv0); 89 DeleteDC(dc); 90 free(priv); 91 return NULL; 92 } 93 94 pic->lpVtbl->get_Width(pic, &scrwidth); 95 pic->lpVtbl->get_Height(pic, &scrheight); 96 width = (scrwidth * GetDeviceCaps(dc, LOGPIXELSX) + 2540 / 2) / 2540; 97 height = (scrheight * GetDeviceCaps(dc, LOGPIXELSY) + 2540 / 2) / 2540; 98 99 memset(&priv->info, 0, sizeof(BITMAPINFO)); 100 priv->info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 101 priv->info.bmiHeader.biBitCount = 24; 102 priv->info.bmiHeader.biWidth = width; 103 priv->info.bmiHeader.biHeight = -height; 104 priv->info.bmiHeader.biCompression = BI_RGB; 105 priv->info.bmiHeader.biPlanes = 1; 106 107 priv->bitmap = CreateDIBSection(dc, &priv->info, DIB_RGB_COLORS, &data, 0, 0); 108 SelectObject(dc, priv->bitmap); 109 pic->lpVtbl->Render(pic, dc, 0, 0, width, height, 110 0, scrheight, scrwidth, -scrheight, NULL); 111 pic->lpVtbl->Release(pic); 112 DeleteDC(dc); 113 #elif defined(HAVE_SDL_IMAGE_H) 44 #if defined(HAVE_SDL_IMAGE_H) 114 45 if(priv->format->BytesPerPixel == 1) 115 46 { … … 122 53 123 54 img = (struct image *)malloc(sizeof(struct image)); 124 #if defined(HAVE_IL_H) 125 #elif defined(HAVE_OLECTL_H) 126 img->width = width; 127 img->height = height; 128 img->pitch = 3 * width; 129 img->channels = 3; 130 img->pixels = data; 131 #elif defined(HAVE_SDL_IMAGE_H) 55 #if defined(HAVE_SDL_IMAGE_H) 132 56 img->width = priv->w; 133 57 img->height = priv->h; … … 157 81 { 158 82 struct image *img; 159 #if defined(HAVE_IL_H) 160 #elif defined(HAVE_OLECTL_H) 161 struct priv *priv = malloc(sizeof(struct priv)); 162 HDC dc; 163 void *data = NULL; 164 #elif defined(HAVE_SDL_IMAGE_H) 83 #if defined(HAVE_SDL_IMAGE_H) 165 84 SDL_Surface *priv; 166 85 Uint32 rmask, gmask, bmask, amask; … … 188 107 189 108 img = (struct image *)malloc(sizeof(struct image)); 190 #if defined(HAVE_IL_H) 191 #elif defined(HAVE_OLECTL_H) 192 dc = CreateCompatibleDC(NULL); 193 if(GetDeviceCaps(dc, BITSPIXEL) < 24) 194 { 195 fprintf(stderr, "a screen depth of at least 24bpp is required\n"); 196 DeleteDC(dc); 197 free(priv); 198 return NULL; 199 } 200 priv->info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 201 priv->info.bmiHeader.biWidth = width; 202 priv->info.bmiHeader.biHeight = -height; 203 priv->info.bmiHeader.biCompression = BI_RGB; 204 priv->info.bmiHeader.biBitCount = 24; 205 priv->info.bmiHeader.biPlanes = 1; 206 priv->bitmap = CreateDIBSection(dc, &priv->info, 207 DIB_RGB_COLORS, &data, 0, 0); 208 DeleteDC(dc); 209 img->width = width; 210 img->height = height; 211 img->pitch = 3 * width; 212 img->channels = 3; 213 img->pixels = data; 214 #elif defined(HAVE_SDL_IMAGE_H) 109 #if defined(HAVE_SDL_IMAGE_H) 215 110 img->width = priv->w; 216 111 img->height = priv->h; … … 237 132 } 238 133 134 struct image *image_dup(struct image *img) 135 { 136 struct image *dst; 137 int x, y; 138 dst = image_new(img->width, img->height); 139 for(y = 0; y < img->height; y++) 140 { 141 for(x = 0; x < img->width; x++) 142 { 143 int r, g, b; 144 getpixel(img, x, y, &r, &g, &b); 145 setpixel(dst, x, y, r, g, b); 146 } 147 } 148 return dst; 149 } 150 239 151 void image_free(struct image *img) 240 152 { 241 #if defined(HAVE_IL_H) 242 #elif defined(HAVE_OLECTL_H) 243 struct priv *priv = img->priv; 244 DeleteObject(priv->bitmap); 245 free(img->priv); 246 #elif defined(HAVE_SDL_IMAGE_H) 153 #if defined(HAVE_SDL_IMAGE_H) 247 154 SDL_FreeSurface(img->priv); 248 155 #elif defined(HAVE_IMLIB2_H) … … 260 167 void image_save(struct image *img, const char *name) 261 168 { 262 #if defined(HAVE_IL_H) 263 #elif defined(HAVE_OLECTL_H) 264 265 #elif defined(HAVE_SDL_IMAGE_H) 169 #if defined(HAVE_SDL_IMAGE_H) 266 170 SDL_SaveBMP(img->priv, name); 267 171 #elif defined(HAVE_IMLIB2_H) … … 271 175 cvSaveImage(name, img->priv); 272 176 #endif 177 } 178 179 void image_swap(struct image *img1, struct image *img2) 180 { 181 struct image tmp; 182 memcpy(&tmp, img1, sizeof(tmp)); 183 memcpy(img1, img2, sizeof(tmp)); 184 memcpy(img2, &tmp, sizeof(tmp)); 273 185 } 274 186 … … 315 227 } 316 228 317 #if defined(HAVE_OLECTL_H)318 static BOOL oleload(LPCTSTR name, LPPICTURE* pic)319 {320 HRESULT ret;321 HANDLE h;322 DWORD size, read = 0;323 LPVOID data;324 HGLOBAL buffer;325 LPSTREAM stream = NULL;326 327 h = CreateFile(name, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);328 if (h == INVALID_HANDLE_VALUE)329 return FALSE;330 331 size = GetFileSize(h, NULL);332 if(size == (DWORD)-1)333 {334 CloseHandle(h);335 return FALSE;336 }337 338 buffer = GlobalAlloc(GMEM_MOVEABLE, size);339 if(!buffer)340 {341 CloseHandle(h);342 return FALSE;343 }344 345 data = GlobalLock(buffer);346 if(!data)347 {348 GlobalUnlock(buffer);349 CloseHandle(h);350 return FALSE;351 }352 353 ret = ReadFile(h, data, size, &read, NULL);354 GlobalUnlock(buffer);355 CloseHandle(h);356 357 if(!ret)358 return FALSE;359 360 ret = CreateStreamOnHGlobal(buffer, TRUE, &stream);361 if(!SUCCEEDED(ret))362 {363 if(stream)364 stream->lpVtbl->Release(stream);365 return FALSE;366 }367 368 if(!stream)369 return FALSE;370 371 if(*pic)372 (*pic)->lpVtbl->Release(*pic);373 374 ret = OleLoadPicture(stream, size, FALSE, &IID_IPicture, (PVOID *)pic);375 stream->lpVtbl->Release(stream);376 377 if(!SUCCEEDED(ret))378 return FALSE;379 380 if(!*pic)381 return FALSE;382 383 return TRUE;384 }385 #endif386 -
pwntcha/trunk/src/linuxfr.c
r430 r445 48 48 memset(result, '\0', 8); 49 49 50 tmp = filter_equalize(img, 150); 50 tmp = image_dup(img); 51 filter_equalize(tmp, 150); 51 52 52 for(y = 0; y < img->height; y++)53 for(y = 0; y < tmp->height; y++) 53 54 { 54 55 int count = 0; 55 for(x = 0; x < img->width; x++)56 for(x = 0; x < tmp->width; x++) 56 57 { 57 58 getpixel(tmp, x, y, &r, &g, &b); … … 64 65 /* Find 7 consecutive lines that have at least 14 pixels; they're 65 66 * baseline candidates */ 66 for(y = 0; y < img->height - 11; y++)67 for(y = 0; y < tmp->height - 11; y++) 67 68 { 68 69 int ycan = 1; … … 81 82 /* Find 7 consecutive cells that have at least 2 pixels on 82 83 * each line; they're base column candidates */ 83 for(x = 0; x < img->width - 9 * 7 + 1; x++)84 for(x = 0; x < tmp->width - 9 * 7 + 1; x++) 84 85 { 85 86 int goodx = 1; -
pwntcha/trunk/src/phpbb.c
r430 r445 27 27 char all[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"; 28 28 char *result; 29 struct image *tmp1, *tmp2 , *tmp3;29 struct image *tmp1, *tmp2; 30 30 int x, y, i = 0; 31 31 int r, g, b; … … 49 49 strcpy(result, " "); 50 50 51 tmp1 = filter_smooth(img); 52 tmp2 = filter_equalize(tmp1, 128); 53 tmp3 = image_new(img->width, img->height); 51 tmp1 = image_dup(img); 52 tmp2 = image_new(img->width, img->height); 53 54 filter_smooth(tmp1); 55 filter_equalize(tmp1, 128); 54 56 55 57 for(x = 0; x < img->width; x++) 56 58 for(y = 0; y < img->height; y++) 57 59 { 58 getpixel(tmp 2, x, y, &r, &g, &b);60 getpixel(tmp1, x, y, &r, &g, &b); 59 61 if(r == 0 && offset == -1) 60 62 offset = x; 61 63 getpixel(img, x, y, &r, &g, &b); 62 setpixel(tmp 3, x, y, 255, g, 255);64 setpixel(tmp2, x, y, 255, g, 255); 63 65 } 64 66 … … 90 92 int r2; 91 93 getgray(font, xmin + z, ymin + t, &r); 92 getgray(tmp 2, x + z, y + t, &r2);94 getgray(tmp1, x + z, y + t, &r2); 93 95 if(r > r2) 94 96 dist += r - r2; … … 124 126 getpixel(font, xmin + x, ymin + y, &r2, &g, &b); 125 127 if(r2 > 128) continue; 126 getpixel(tmp 3, distx + x, disty + y, &r, &g, &b);127 setpixel(tmp 3, distx + x, disty + y, r2, g, b);128 getpixel(tmp2, distx + x, disty + y, &r, &g, &b); 129 setpixel(tmp2, distx + x, disty + y, r2, g, b); 128 130 } 129 131 … … 134 136 image_free(tmp1); 135 137 image_free(tmp2); 136 image_free(tmp3);137 138 138 139 return result; -
pwntcha/trunk/src/scode.c
r425 r445 31 31 result = malloc(1024 * sizeof(char)); 32 32 33 tmp1 = filter_dup(img);33 tmp1 = image_dup(img); 34 34 35 35 /* Remove border */ -
pwntcha/trunk/src/slashdot.c
r430 r445 19 19 #include "common.h" 20 20 21 static struct image *count_objects(struct image *img);22 static struct image *rotate(struct image *img);23 static struct image *cut_cells(struct image *img);24 static struct image *find_glyphs(struct image *img);21 static void count_objects(struct image *img); 22 static void rotate(struct image *img); 23 static void cut_cells(struct image *img); 24 static void find_glyphs(struct image *img); 25 25 26 26 /* Our macros */ … … 39 39 char *decode_slashdot(struct image *img) 40 40 { 41 struct image *tmp1, *tmp2 , *tmp3, *tmp4, *tmp5, *tmp6, *tmp7;41 struct image *tmp1, *tmp2; 42 42 43 43 /* Initialise local data */ … … 51 51 52 52 /* Clean image a bit */ 53 tmp1 = filter_detect_lines(img); 54 tmp2 = filter_fill_holes(tmp1); 53 tmp1 = image_dup(img); 54 filter_detect_lines(tmp1); 55 filter_fill_holes(tmp1); 55 56 56 57 /* Detect small objects to guess image orientation */ 57 tmp3 = filter_median(tmp2); 58 tmp4 = filter_equalize(tmp3, 200); 59 count_objects(tmp4); 58 tmp2 = image_dup(tmp1); 59 filter_median(tmp2); 60 filter_equalize(tmp2, 200); 61 count_objects(tmp2); 60 62 61 63 /* Invert rotation and find glyphs */ 62 tmp5 = rotate(tmp2);63 tmp6 = filter_median(tmp5);64 tmp7 = find_glyphs(tmp6);64 rotate(tmp1); 65 filter_median(tmp1); 66 find_glyphs(tmp1); 65 67 66 68 /* Clean up our mess */ 67 69 image_free(tmp1); 68 70 image_free(tmp2); 69 image_free(tmp3);70 image_free(tmp4);71 image_free(tmp5);72 image_free(tmp6);73 image_free(tmp7);74 71 75 72 /* aaaaaaa means decoding failed */ … … 82 79 /* The following functions are local */ 83 80 84 static struct image *count_objects(struct image *img)85 { 86 struct image * dst;81 static void count_objects(struct image *img) 82 { 83 struct image *tmp; 87 84 int gotblack = 1; 88 85 int x, y, i; 89 86 int r, g, b; 90 87 91 dst= image_new(img->width, img->height);88 tmp = image_new(img->width, img->height); 92 89 93 90 for(y = 0; y < img->height; y++) … … 95 92 { 96 93 getpixel(img, x, y, &r, &g, &b); 97 setpixel( dst, x, y, r, g, b);94 setpixel(tmp, x, y, r, g, b); 98 95 } 99 96 … … 101 98 { 102 99 gotblack = 0; 103 for(y = 0; y < dst->height; y++)104 for(x = 0; x < dst->width; x++)105 { 106 getpixel( dst, x, y, &r, &g, &b);100 for(y = 0; y < tmp->height; y++) 101 for(x = 0; x < tmp->width; x++) 102 { 103 getpixel(tmp, x, y, &r, &g, &b); 107 104 if(r == 0 && g == 0 && b == 0) 108 105 { 109 106 gotblack = 1; 110 filter_flood_fill( dst, x, y, 254 - objects, 0, 0);107 filter_flood_fill(tmp, x, y, 254 - objects, 0, 0); 111 108 objects++; 112 109 } … … 118 115 for(i = 0; i < objects; i++) 119 116 { 120 objlist[i].ymin = dst->height;117 objlist[i].ymin = tmp->height; 121 118 objlist[i].ymax = 0; 122 119 123 for(y = 0; y < dst->height; y++)124 for(x = 0; x < dst->width; x++)125 { 126 getpixel( dst, x, y, &r, &g, &b);120 for(y = 0; y < tmp->height; y++) 121 for(x = 0; x < tmp->width; x++) 122 { 123 getpixel(tmp, x, y, &r, &g, &b); 127 124 if(r == 255 - i && g == 0 && b == 0) 128 125 { … … 137 134 first = i; 138 135 last = i; 139 filter_flood_fill( dst, objlist[i].xmin, objlist[i].ymin, 0, 0, 255);136 filter_flood_fill(tmp, objlist[i].xmin, objlist[i].ymin, 0, 0, 255); 140 137 } 141 138 } … … 147 144 B.x = (objlist[last].xmin + objlist[last].xmax) / 2; 148 145 B.y = (objlist[last].ymin + objlist[last].ymax) / 2; 149 cvLine( dst, A, B, 0, 2.0, 0);146 cvLine(tmp, A, B, 0, 2.0, 0); 150 147 } 151 148 #endif 152 149 153 return dst; 154 } 155 156 static struct image *rotate(struct image *img) 157 { 158 struct image *dst; 150 image_swap(img, tmp); 151 image_free(tmp); 152 } 153 154 static void rotate(struct image *img) 155 { 156 struct image *tmp; 159 157 int x, y, xdest, ydest; 160 158 int r, g, b; … … 171 169 } 172 170 173 dst= image_new(img->width * FACTOR, img->height * FACTOR);171 tmp = image_new(img->width * FACTOR, img->height * FACTOR); 174 172 175 173 for(y = 0; y < img->height * FACTOR; y++) … … 192 190 if(r == 255 && g == 0 && b == 255) 193 191 g = 255; 194 setpixel(dst, x, y, r, g, b); 195 } 196 197 return dst; 198 } 199 200 static struct image *cut_cells(struct image *img) 201 { 202 struct image *dst; 192 setpixel(tmp, x, y, r, g, b); 193 } 194 195 image_swap(img, tmp); 196 image_free(tmp); 197 } 198 199 static void cut_cells(struct image *img) 200 { 201 struct image *tmp; 203 202 int x, y; 204 203 int r, g, b; 205 204 206 dst= image_new(img->width, img->height);205 tmp = image_new(img->width, img->height); 207 206 208 207 for(y = 0; y < img->height; y++) … … 210 209 { 211 210 getpixel(img, x, y, &r, &g, &b); 212 setpixel( dst, x, y, r, g, b);211 setpixel(tmp, x, y, r, g, b); 213 212 } 214 213 215 214 for(x = 0; x < img->width; x++) 216 215 { 217 setpixel( dst, x, 0, 255, 255, 255);218 setpixel( dst, x, img->height - 1, 255, 255, 255);216 setpixel(tmp, x, 0, 255, 255, 255); 217 setpixel(tmp, x, img->height - 1, 255, 255, 255); 219 218 } 220 219 … … 222 221 for(x = 0; x < 7; x++) 223 222 { 224 setpixel(dst, x * img->width / 7, y, 255, 255, 255); 225 setpixel(dst, (x + 1) * img->width / 7 - 1, y, 255, 255, 255); 226 } 227 228 return dst; 229 } 230 231 static struct image *find_glyphs(struct image *img) 223 setpixel(tmp, x * img->width / 7, y, 255, 255, 255); 224 setpixel(tmp, (x + 1) * img->width / 7 - 1, y, 255, 255, 255); 225 } 226 227 image_swap(img, tmp); 228 image_free(tmp); 229 } 230 231 static void find_glyphs(struct image *img) 232 232 { 233 233 char all[] = "abcdefgijkmnpqrstvwxyz"; … … 238 238 } 239 239 glyphs[22]; 240 struct image * dst;240 struct image *tmp; 241 241 int x, y, i = 0; 242 242 int r, g, b; … … 256 256 } 257 257 258 dst= image_new(img->width, img->height);258 tmp = image_new(img->width, img->height); 259 259 260 260 for(y = 0; y < img->height; y++) … … 262 262 { 263 263 getpixel(img, x, y, &r, &g, &b); 264 setpixel( dst, x, y, 255, g, 255);264 setpixel(tmp, x, y, 255, g, 255); 265 265 } 266 266 … … 387 387 getpixel(font, xmin + x, ymin + y, &r, &g, &b); 388 388 if(r > 128) continue; 389 setpixel( dst, distx + x, disty + y, r, g, b);389 setpixel(tmp, distx + x, disty + y, r, g, b); 390 390 } 391 391 … … 394 394 } 395 395 396 return dst; 397 } 398 396 image_swap(img, tmp); 397 image_free(tmp); 398 } 399 -
pwntcha/trunk/src/test.c
r430 r445 22 22 #define FONTNAME "font_phpbb.png" 23 23 24 static struct image *find_glyphs(struct image *img);24 static void find_glyphs(struct image *img); 25 25 26 26 /* Global stuff */ … … 32 32 char *decode_test(struct image *img) 33 33 { 34 struct image *tmp 1, *tmp2, *tmp3, *tmp4, *tmp5, *tmp6, *tmp7;34 struct image *tmp; 35 35 36 36 /* Initialise local data */ … … 42 42 result = malloc(7 * sizeof(char)); 43 43 44 tmp1 = filter_smooth(img); 45 tmp2 = filter_median(tmp1); 46 tmp3 = filter_equalize(tmp2, 130); 47 tmp4 = filter_median(tmp3); 48 tmp5 = find_glyphs(tmp3); 44 tmp = image_dup(img); 45 filter_smooth(tmp); 46 filter_median(tmp); 47 filter_equalize(tmp, 130); 48 filter_median(tmp); 49 find_glyphs(tmp); 49 50 50 image_free(tmp1); 51 image_free(tmp2); 52 image_free(tmp3); 53 image_free(tmp4); 54 image_free(tmp5); 51 image_free(tmp); 55 52 56 53 return result; … … 59 56 /* The following functions are local */ 60 57 61 static struct image *find_glyphs(struct image *img)58 static void find_glyphs(struct image *img) 62 59 { 63 60 char all[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"; 64 struct image * dst, *font;61 struct image *tmp, *font; 65 62 int x, y, i = 0; 66 63 int r, g, b; 67 int xmin, xmax, ymin, ymax, incell = 0, count = 0,cur = 0, offset = -1;64 int xmin, xmax, ymin, ymax, cur = 0, offset = -1; 68 65 int distmin, distx, disty, distch; 69 66 … … 80 77 } 81 78 82 dst= image_new(img->width, img->height);79 tmp = image_new(img->width, img->height); 83 80 84 81 for(x = 0; x < img->width; x++) … … 86 83 { 87 84 getpixel(img, x, y, &r, &g, &b); 88 setpixel( dst, x, y, 255, g, 255);85 setpixel(tmp, x, y, 255, g, 255); 89 86 if(r == 0 && offset == -1) 90 87 offset = x; … … 150 147 getpixel(font, xmin + x, ymin + y, &r, &g, &b); 151 148 if(r > 128) continue; 152 setpixel( dst, distx + x, disty + y, r, g, b);149 setpixel(tmp, distx + x, disty + y, r, g, b); 153 150 } 154 151 … … 157 154 } 158 155 159 return dst; 156 image_swap(img, tmp); 157 image_free(tmp); 160 158 } 161 159 -
pwntcha/trunk/src/vbulletin.c
r430 r445 26 26 char all[] = "2346789ABCDEFGHJKLMNPRTWXYZ"; 27 27 char *result; 28 struct image *tmp 1, *tmp2, *tmp3;28 struct image *tmp; 29 29 int limits[6] = { 26, 53, 80, 107, 134, 160 }; 30 30 int x, y, r, g, b, i, j; … … 47 47 48 48 /* half the captchas are inverse video; we set them back to normal */ 49 getpixel(img, 0, 0, &r, &g, &b); 49 tmp = image_dup(img); 50 getpixel(tmp, 0, 0, &r, &g, &b); 50 51 if(r < 50) 51 tmp1 = filter_equalize(img, 128);52 filter_equalize(tmp, 128); 52 53 else 53 tmp1 = filter_equalize(img, -128);54 filter_equalize(tmp, -128); 54 55 55 56 /* Remove garbage around the cells */ 56 for(x = 0; x < img->width; x++)57 for(x = 0; x < tmp->width; x++) 57 58 { 58 59 for(y = 0; y < 15; y++) 59 setpixel(tmp 1, x, y, 255, 255, 255);60 for(y = 45; y < img->height; y++)61 setpixel(tmp 1, x, y, 255, 255, 255);60 setpixel(tmp, x, y, 255, 255, 255); 61 for(y = 45; y < tmp->height; y++) 62 setpixel(tmp, x, y, 255, 255, 255); 62 63 } 63 64 64 for(x = 0; x < img->width; x++)65 for(x = 0; x < tmp->width; x++) 65 66 { 66 67 for(i = 0; i < 6; i++) … … 69 70 if(i == 6) 70 71 for(y = 15; y < 45; y++) 71 setpixel(tmp 1, x, y, 255, 255, 255);72 setpixel(tmp, x, y, 255, 255, 255); 72 73 else 73 74 x += 11; 74 75 } 75 76 76 tmp2 = filter_black_stuff(tmp1);77 tmp3 = filter_black_stuff(tmp2);77 filter_black_stuff(tmp); 78 filter_black_stuff(tmp); 78 79 79 80 /* Fill letters in gray */ 80 81 for(x = 26; x < 172; x++) 81 82 { 82 getpixel(tmp 3, x, 15, &r, &g, &b);83 getpixel(tmp, x, 15, &r, &g, &b); 83 84 if(r == 0) 84 filter_flood_fill(tmp 3, x, 15, 127, 0, 255);85 filter_flood_fill(tmp, x, 15, 127, 0, 255); 85 86 } 86 87 … … 89 90 for(y = 15; y < 45; y++) 90 91 { 91 getpixel(tmp 3, x, y, &r, &g, &b);92 getpixel(tmp, x, y, &r, &g, &b); 92 93 if(r == 0) 93 filter_flood_fill(tmp 3, x, y, 255, 255, 255);94 filter_flood_fill(tmp, x, y, 255, 255, 255); 94 95 } 95 96 … … 97 98 for(x = 26; x < 172; x++) 98 99 { 99 getpixel(tmp 3, x, 44, &r, &g, &b);100 getpixel(tmp, x, 44, &r, &g, &b); 100 101 if(r == 127) 101 filter_flood_fill(tmp 3, x, 44, 0, 0, 0);102 filter_flood_fill(tmp, x, 44, 0, 0, 0); 102 103 } 103 104 … … 106 107 for(y = 15; y < 45; y++) 107 108 { 108 getpixel(tmp 3, x, y, &r, &g, &b);109 getpixel(tmp, x, y, &r, &g, &b); 109 110 if(r == 127) 110 filter_flood_fill(tmp 3, x, y, 255, 255, 255);111 filter_flood_fill(tmp, x, y, 255, 255, 255); 111 112 } 112 113 … … 114 115 for(i = 0; i < 6; i++) 115 116 { 116 struct image *new ;117 struct image *new = image_dup(tmp); 117 118 int mindist = INT_MAX, min = -1; 118 new = filter_crop(tmp3, limits[i], 15, limits[i] + 11, 45);119 filter_crop(new, limits[i], 15, limits[i] + 11, 45); 119 120 for(j = 0; j < 27; j++) 120 121 { … … 138 139 } 139 140 140 image_free(tmp1); 141 image_free(tmp2); 142 image_free(tmp3); 141 image_free(tmp); 143 142 144 143 return result; -
pwntcha/trunk/src/xanga.c
r444 r445 19 19 #include "common.h" 20 20 21 static struct image *fill_white_holes(struct image *img); 22 static struct image *rotate(struct image *img); 23 static struct image *cut_cells(struct image *img); 24 static struct image *find_glyphs(struct image *img); 21 static void fill_white_holes(struct image *img); 25 22 26 23 /* Our macros */ … … 39 36 char *decode_xanga(struct image *img) 40 37 { 41 struct image *tmp 1, *tmp2, *tmp3, *tmp4, *tmp5, *tmp6, *tmp7;38 struct image *tmp; 42 39 43 40 /* Initialise local data */ … … 50 47 strcpy(result, " "); 51 48 52 image_save(img, "xanga1.bmp"); 49 tmp = image_dup(img); 50 image_save(tmp, "xanga1.bmp"); 53 51 /* Clean image a bit */ 54 // tmp1 = filter_equalize(img, 200);55 tmp1 = filter_contrast(img);56 // tmp1 = filter_detect_lines(img);57 image_save(tmp 1, "xanga2.bmp");58 tmp2 = fill_white_holes(tmp1);59 // tmp2 = filter_fill_holes(tmp1);60 image_save(tmp 2, "xanga3.bmp");61 // tmp3 = filter_detect_lines(tmp2);62 // tmp3 = filter_median(tmp2);63 //image_save(tmp 3, "xanga4.bmp");64 tmp3 = filter_equalize(tmp2, 128);65 image_save(tmp 3, "xanga4.bmp");52 // filter_equalize(tmp, 200); 53 filter_contrast(tmp); 54 //filter_detect_lines(tmp); 55 image_save(tmp, "xanga2.bmp"); 56 fill_white_holes(tmp); 57 // filter_fill_holes(tmp); 58 image_save(tmp, "xanga3.bmp"); 59 //filter_detect_lines(tmp); 60 // filter_median(tmp); 61 //image_save(tmp, "xanga4.bmp"); 62 filter_equalize(tmp, 128); 63 image_save(tmp, "xanga4.bmp"); 66 64 return NULL; 67 65 68 66 /* Detect small objects to guess image orientation */ 69 tmp3 = filter_median(tmp2);70 tmp4 = filter_equalize(tmp3, 200);67 filter_median(tmp); 68 filter_equalize(tmp, 200); 71 69 72 70 /* Invert rotation and find glyphs */ 73 tmp5 = rotate(tmp2);74 tmp6 = filter_median(tmp5);71 rotate(tmp); 72 filter_median(tmp); 75 73 76 74 /* Clean up our mess */ 77 image_free(tmp1); 78 image_free(tmp2); 79 image_free(tmp3); 80 image_free(tmp4); 81 image_free(tmp5); 82 image_free(tmp6); 83 image_free(tmp7); 75 image_free(tmp); 84 76 85 77 /* aaaaaaa means decoding failed */ … … 92 84 /* The following functions are local */ 93 85 94 static struct image *fill_white_holes(struct image *img)86 static void fill_white_holes(struct image *img) 95 87 { 96 struct image * dst;88 struct image *tmp; 97 89 int x, y, i; 98 90 int r, g, b; 99 91 100 dst= image_new(img->width, img->height);92 tmp = image_new(img->width, img->height); 101 93 102 94 for(y = 0; y < img->height; y++) … … 104 96 { 105 97 getpixel(img, x, y, &r, &g, &b); 106 setpixel( dst, x, y, r, g, b);98 setpixel(tmp, x, y, r, g, b); 107 99 } 108 100 … … 124 116 if(count > 600) 125 117 continue; 126 setpixel( dst, x, y, count / 5, count / 5, count / 5);118 setpixel(tmp, x, y, count / 5, count / 5, count / 5); 127 119 } 128 120 129 return dst; 121 image_swap(tmp, img); 122 image_free(tmp); 130 123 } 131 124
Note: See TracChangeset
for help on using the changeset viewer.