rendered paste body/*
RS.com CA(P)TCHA Pre-Processor
20.04.2008 von Kugelfisch
BSD-artige Lizenz
*/
#include <stdio.h>
#include <stdlib.h>
#include <jpeglib.h>
#include <math.h>
#define CATCHA_W 456
#define CATCHA_H 71
typedef struct {
unsigned char image[CATCHA_W][CATCHA_H];
} catcha;
void load_catcha(catcha* cat, char* filename) {
JSAMPARRAY buffer;
struct jpeg_error_mgr jerr;
struct jpeg_decompress_struct cinfo;
int x,y;
FILE* f = fopen(filename,"rb");
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
jpeg_stdio_src(&cinfo, f);
jpeg_read_header(&cinfo, TRUE);
jpeg_start_decompress(&cinfo);
if(cinfo.output_width != CATCHA_W || cinfo.output_height != CATCHA_H) {
fprintf(stderr,"Invalid CAPTCHA size!");
exit(-1);
}
buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr) &cinfo, JPOOL_IMAGE, cinfo.output_width * cinfo.output_components, 1);
while ((y = cinf e) {
JSAMPARRAY buffer;
struct jpeg_error_mgr jerr;
struct jpeg_compress_struct cinfo;
int x,y;
FILE* f = fope
cinfo.image_width = CATCHA_W;
cinfo.image_height = CATCHA_H;
cinfo.input_components = 1;
cinfo.in_color_space = JCS_GRAYSCALE;
jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo,100,TRUE);
jpeg_stdio_dest(&cinfo, f);
jpeg_start_compress(&cinfo, FALSE);
buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr) &cinfo, JPOOL_IMAGE, CATCHA_W, 1);
for(y=0; y<CATCHA_H; y++) {
for(x=0; x<CATCHA_W; x++)
if(cat->image[x][y] < 200)
buffer[0][x] = cat->image[x][y];
else
buffer[0][x] = 0xFF;
jpeg_write_scanlines(&cinfo, buffer, 1);
}
jpeg_finish_compress(&cinfo);
fclose(f);
jpeg_destroy_compress(&cinfo);
#define SINE_PHI_Y (0)
void catcha_reverse_sine_transform(catcha* cat) {
int x,y,shift;
// transform in x-direction
for(y=0; y<CATCHA_H; y++) {
shift = -(int)round(SINE_MAX_X*sin(SINE_OMEGA_X*y+SINE_PHI_X));
if(shift > 0) {
for(x=0; x<CATCHA_W; x++)
cat->image[x][y] = (x+shift<CATCHA_W)?cat->image[x+shift][y]:0xFF;
} else {
for(x=CATCHA_W-1; x>=0; x--)
cat->image[x][y] = (x+shift>=0)?cat->image[x+shift][y]:0xFF;
}
}
// transform in y-direction
for(x=0; x<CATCHA_W; x++) {
shift = -(int)round(SINE_MAX_Y*sin(SINE_OMEGA_Y*x+SINE_PHI_Y));
if(shift > 0) {
for(y=0; y<CATCHA_H; y++)
}
int main(int argc, char** argv) {
catcha cat;
if(argc < 3)
return -1;
load_catcha(&cat,argv[1]);
catcha_reverse_sine_transform(&cat);
save_catcha(&cat,argv[2]);
return 0;
}