- Timestamp:
- Jan 4, 2005, 6:06:04 PM (16 years ago)
- Location:
- pwntcha/trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pwntcha/trunk/src/common.h
r402 r413 28 28 29 29 /* image operations */ 30 struct image *image_load(c har *name);30 struct image *image_load(const char *name); 31 31 struct image *image_new(int width, int height); 32 32 void image_free(struct image *img); 33 void image_save(struct image *img, const char *name); 33 34 void image_display(struct image *img); 34 35 int getgray(struct image *img, int x, int y, int *g); … … 40 41 struct image *filter_fill_holes(struct image *img); 41 42 struct image *filter_dup(struct image *img); 43 struct image *filter_black_stuff(struct image *img); 42 44 struct image *filter_detect_lines(struct image *img); 43 45 struct image *filter_equalize(struct image *img, int threshold); … … 46 48 struct image *filter_median(struct image *img); 47 49 struct image *filter_contrast(struct image *img); 50 struct image *filter_crop(struct image *img, 51 int xmin, int ymin, int xmax, int ymax); 48 52 int filter_count(struct image *img); 49 53 -
pwntcha/trunk/src/filters.c
r402 r413 121 121 } 122 122 123 struct image *filter_black_stuff(struct image *img) 124 { 125 struct image *dst; 126 int x, y; 127 int r, ra, rb, g, b; 128 129 dst = image_new(img->width, img->height); 130 131 /* Remove vertical stuff */ 132 for(y = 0; y < img->height; y++) 133 for(x = 0; x < img->width; x++) 134 { 135 getpixel(img, x, y, &r, &g, &b); 136 setpixel(dst, x, y, r, g, b); 137 if(y > 0 && y < img->height - 1) 138 { 139 getpixel(img, x, y - 1, &ra, &g, &b); 140 getpixel(img, x, y + 1, &rb, &g, &b); 141 if(r < ra && (r - ra) * (r - rb) > 5000) 142 setpixel(dst, x, y, ra, ra, ra); 143 } 144 } 145 146 /* Remove horizontal stuff */ 147 for(y = 0; y < img->height; y++) 148 for(x = 0; x < img->width; x++) 149 { 150 getpixel(img, x, y, &r, &g, &b); 151 if(x > 0 && x < img->width - 1) 152 { 153 getpixel(dst, x - 1, y, &ra, &g, &b); 154 getpixel(dst, x + 1, y, &rb, &g, &b); 155 if(r < ra && (r - ra) * (r - rb) > 5000) 156 setpixel(dst, x, y, ra, ra, ra); 157 } 158 } 159 160 return dst; 161 } 162 123 163 struct image *filter_detect_lines(struct image *img) 124 164 { … … 166 206 int x, y; 167 207 int r, g, b; 168 169 dst = image_new(img->width, img->height); 170 171 for(y = 0; y < img->height; y++) 172 for(x = 0; x < img->width; x++) 173 { 174 getpixel(img, x, y, &r, &g, &b); 175 if(r < threshold) r = 0; else r = 255; 176 setpixel(dst, x, y, r, r, r); 208 int min = 0, max = 255; 209 210 dst = image_new(img->width, img->height); 211 212 if(threshold < 0) 213 { 214 min = 255; 215 max = 0; 216 threshold = -threshold; 217 } 218 219 for(y = 0; y < img->height; y++) 220 for(x = 0; x < img->width; x++) 221 { 222 getpixel(img, x, y, &r, &g, &b); 223 if(r < threshold) 224 setpixel(dst, x, y, min, min, min); 225 else 226 setpixel(dst, x, y, max, max, max); 177 227 } 178 228 … … 330 380 } 331 381 382 struct image *filter_crop(struct image *img, 383 int xmin, int ymin, int xmax, int ymax) 384 { 385 struct image *dst; 386 int x, y; 387 int r, g, b; 388 389 if(xmin < 0) 390 xmin = 0; 391 if(ymin < 0) 392 ymin = 0; 393 if(xmax >= img->width) 394 xmax = img->width - 1; 395 if(ymax >= img->height) 396 ymax = img->height - 1; 397 398 if(xmin >= xmax || ymin >= ymax) 399 return NULL; 400 401 dst = image_new(xmax - xmin, ymax - ymin); 402 403 for(y = 0; y < dst->height; y++) 404 for(x = 0; x < dst->width; x++) 405 { 406 getpixel(img, xmin + x, ymin + y, &r, &g, &b); 407 setpixel(dst, x, y, r, g, b); 408 } 409 410 return dst; 411 } 412 332 413 int filter_count(struct image *img) 333 414 { -
pwntcha/trunk/src/image.c
r407 r413 27 27 #endif 28 28 29 struct image *image_load(c har *name)29 struct image *image_load(const char *name) 30 30 { 31 31 struct image *img; … … 77 77 gmask = 0x00ff0000; 78 78 bmask = 0x0000ff00; 79 amask = 0x000000 ff;79 amask = 0x00000000; 80 80 # else 81 81 rmask = 0x000000ff; 82 82 gmask = 0x0000ff00; 83 83 bmask = 0x00ff0000; 84 amask = 0x ff000000;84 amask = 0x00000000; 85 85 # endif 86 86 priv = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, … … 135 135 136 136 free(img); 137 } 138 139 void image_save(struct image *img, const char *name) 140 { 141 #if defined(HAVE_SDL_IMAGE_H) 142 SDL_SaveBMP(img->priv, name); 143 #elif defined(HAVE_IMLIB2_H) 144 imlib_context_set_image(img->priv); 145 imlib_save_image(name); 146 #elif defined(HAVE_CV_H) 147 cvSaveImage(name, img->priv); 148 #endif 137 149 } 138 150
Note: See TracChangeset
for help on using the changeset viewer.