void w_draw_form(t_env *e) { t_coord pos; t_coord dim; dim.x = 30; dim.y = 30; pos.x = 5; pos.y = 5; create_img(e, dim, "xpm/close.xpm", pos); dim.x = 36; dim.y = 12; pos.x = 200; pos.y = e->height / 6; if (e->set->color == 1) create_img(e, dim, "xpm/on.xpm", pos); else create_img(e, dim, "xpm/off.xpm", pos); pos.y = 5 * e->height / 6; mlx_string_put(e->mlx, e->win, 200, pos.y - 5, 0xff1212, "Beta !"); if (e->set->straff == 1) create_img(e, dim, "xpm/on.xpm", pos); else create_img(e, dim, "xpm/off.xpm", pos); dim.x = 200; pos.y = 3 * e->height / 6; draw_cursor(e, dim, pos, 0x8904B1); }
/*** copy char image struct ***/ img *copy_img (char *prog_name, img *in) { img *out; unsigned char *in_pixel, *out_pixel; long cols, rows, colors, size; /* if NULL in, then NULL out */ if (in == NULL) { return NULL; } /* get image size, etc */ cols = in->cols; rows = in->rows; colors = in->colors; size = in->size; /* create image struct with no data yet */ out = create_img (prog_name, cols, rows, colors); in_pixel = in->image; out_pixel = out->image; /* copy in to out */ while (size-- > 0) { *out_pixel++ = *in_pixel++; } /* copy pixels */ return out; } /* end copy_img */
void option_case(char *name, int opt) { t_data e; char **buf; if (opt != 2 && opt != 1) put_usage_error("./fdf"); open_check(name); buf = get_data(name); e.opt = opt; if (opt == 1) { e.para = 0; e.iso = 1; } if (opt == 2) { e.para = 1; e.iso = 0; } e.y_max = nb_lines(buf); e.x_max = nb_points(buf, e.y_max); e.data = read_map(buf, e.x_max, e.y_max); e.cal_data = NULL; init_t_m(&e); create_img(&e); free_tab(&e); }
void w_draw_label(t_env *e) { t_coord pos; t_coord dim; dim.x = 55; dim.y = 9; pos.x = 100; pos.y = e->height / 6; create_img(e, dim, "xpm/color.xpm", pos); pos.y = 3 * e->height / 6; create_img(e, dim, "xpm/light.xpm", pos); pos.y = 5 * e->height / 6; dim.x = 71; create_img(e, dim, "xpm/straff.xpm", pos); }
int main(int argc, char **argv) { static_check(); if (argc != 3) { bug("usage: <input *.img> <input dirname>\n"); } const char *imgname = argv[1], *home = argv[2]; if (create_img(open_img(imgname), home) != 0) { bug("create img failed.\n"); } printf("create %s (%s) successfully.\n", imgname, home); return 0; }
/* Scale to 0 - 255 */ img *dimg2img_scale (char *prog_name, dimg *in) { img *out; double *in_pixel; unsigned char *out_pixel; long cols, rows, size; long i; double min, max; double scale; /* if NULL in, then NULL out */ if (in == NULL) { return NULL; } /* get image size, etc */ cols = in->cols; rows = in->rows; size = in->size; /* find min, max, scale */ in_pixel = in->image; min = max = *in_pixel; for (i = 0; i < size; i++) { if (*in_pixel < min) { min = *in_pixel; } if (*in_pixel > max) { max = *in_pixel; } in_pixel++; } scale = (IMG_WHITE - IMG_BLACK) / (max - min); /* create image struct with no data yet */ out = create_img (prog_name, cols, rows, 1); in_pixel = in->image; out_pixel = out->image; /* copy in to out */ while (size-- > 0) { *out_pixel++ = (unsigned char) ( (*in_pixel++ - min) * scale); } /* copy pixels */ return out; } /* end dimg2img_scale */
int main(int ac, char **argv) { t_env env; if (ac < 2) return (0); if ((env.ptr = mlx_init()) == NULL) return (0); if ((env.win = mlx_new_window(env.ptr, SCREENWIDTH, SCREENHEIGHT , "Raycaster")) == NULL) return (0); create_img(&env); get_tex(&env); init(&env); get_map(&env.worldmap, argv[1]); mlx(&env); return (0); }
/** * Antud funktsioon kasutab genereeritud mapi ja tekitab sellest pildi * */ void generate_image_from_map(char *fname){ int x,y; int H=pixel_map.H; int W=pixel_map.W; create_img(W,H); for(y=0;y<H;y++){ for(x=0;x<W;x++){ point p=pixel_map.map[y][x]; set_pixel(x,y, get_pixel(p.x, p.y)); } } save_img(fname); return; }
// Nearest Neighbor void resize( img *src_img, char *dst_name, float resize_factor ) { img *new_img ; // I choose to get rid of any fractional pixels in new size. // This is accounted for by truncation via type casting long col_size = (long)( resize_factor * src_img->cols ) ; long row_size = (long)( resize_factor * src_img->rows ) ; long i, j, k, nn_j, nn_k ; // Create new image new_img = create_img( "resize", col_size, row_size, src_img->colors ) ; // Interpolate // Iterate through positions of new_img and copy intensity values // from appropriate src_img pixels for( i = 0 ; i < new_img->colors ; i++ ) { for( j = 0 ; j < new_img->rows ; j++ ) { // Find the nearest neighbor in src_img nn_j = (long)( j / resize_factor ) ; // Account for truncation errors if( j / resize_factor - nn_j >= 0.5 ) nn_j++ ; for( k = 0 ; k < new_img->cols ; k++ ) { // Find the nearest neighbor in src_img nn_k = (long)( k / resize_factor ) ; // Account for truncation errors if( k / resize_factor - nn_k >= 0.5 ) nn_k++ ; // Copy value from nearest neighbor in src_img into new_img new_img->image[i * new_img->rows * new_img->cols + j * new_img->cols + k] = src_img->image[i * src_img->rows * src_img->cols + nn_j * src_img->cols + nn_k] ; } } } // Save resized image write_img( "resize", new_img, dst_name ) ; }
img *bilinear (char *prog_name, img *in, int n) { img *out; long rows = in->rows; long cols = in->cols; long new_rows = rows*n; long new_cols = cols*n; out = create_img(prog_name, new_cols, new_rows, 1); float x; float y; int i, j; long x0, x1, y0, y1; double r00, r01, r10, r11, rx0, rx1; char rxy; for (i=0; i<new_rows; i++) { for (j=0; j<new_cols; j++) { x = i*rows/new_rows; y = j*cols/new_cols; x0 = x-0.5; x1 = x+0.5; y0 = y-0.5; y1 = y+0.5; r00 = in->image[x0*cols+y0]; r01 = in->image[x0*cols+y1]; r10 = in->image[x1*cols+y0]; r11 = in->image[x1*cols+y1]; rx0 = r00 + (x-x0)*(r10-r00); rx1 = r01 + (x-x0)*(r11-r01); rxy = rx0 + (y-y0)*(rx1-rx0); out->image[i*new_cols+j] = rxy; } } return out; }
/* Without scaling */ img *dimg2img (char *prog_name, dimg *in) { img *out; double *in_pixel; unsigned char *out_pixel; long cols, rows, size; /* if NULL in, then NULL out */ if (in == NULL) { return NULL; } /* get image size, etc */ cols = in->cols; rows = in->rows; size = in->size; /* create image struct with no data yet */ out = create_img (prog_name, cols, rows, 1); in_pixel = in->image; out_pixel = out->image; /* copy in to out */ while (size-- > 0) { if (*in_pixel < IMG_BLACK) { *out_pixel = IMG_BLACK; } else if (*in_pixel >= IMG_WHITE) { *out_pixel = IMG_WHITE; } else *out_pixel = (unsigned char) (*in_pixel + 0.5); in_pixel++; out_pixel++; } /* copy pixels */ return out; } /* end dimg2img */
int main(int argc, char *argv[]) { int port; char* file_img; int rfd; //Get the arguments get_args(&port, &file_img, argc, argv); int sd = UDP_Open(port); //Creates a new socket and binds to a port to it assert(sd > -1); //Open the file image, if not present call file_create routine disk_fd = open(file_img, O_RDWR); if(disk_fd == -1) { #ifdef DEBUG printf("----File image doesn't exist - Creating a new one\n"); #endif rfd = create_img(file_img); if(rfd == -1) { #ifdef DEBUG printf("----Error Creating the file - Exiting\n"); #endif return -1; } disk_fd = rfd; } #ifdef DEBUG printf("----File descriptor open: %d\n", disk_fd); #endif printf(" SERVER:: waiting in loop\n"); while (1) { struct sockaddr_in s; char buffer[MSG_BUFFER_SIZE]; //Redefined the size as, it may recieve more than 4096 bytes int rc = UDP_Read(sd, &s, buffer, MSG_BUFFER_SIZE); if (rc > 0) { printf(" SERVER:: Read %d bytes (message: '%s')\n", rc, buffer); int ret_func = parse_msg(buffer); //Parse the message //Common paramters across all routines int pinum, inum, type, block, entries; char name[NAME_SIZE]; char rw_buf[MFS_BLOCK_SIZE]; char buf[MSG_BUFFER_SIZE]; int res_t, ret; //res_t- return status of server side routines S_Stat_t m; switch(ret_func) { case 1: ret = Lookup_parse(buffer, &pinum, &name); if (!ret) res_t = S_Lookup(pinum, name); else res_t = -1; //MSG Format: Function_id, Success_state(-1 or inum) memset(buf, 0, MSG_BUFFER_SIZE); snprintf(buf, 2*sizeof(int) , "%d%d", ret_func, res_t); send_resp(sd, &s, buf); break; case 2: ret = Stat_parse(buffer, &inum); if(!ret) res_t = S_Stat(inum, &m); else res_t = -1; //MSG Format: Function_id, Success_State, File_type, File_size memset(buf, 0, MSG_BUFFER_SIZE); snprintf(buf, 4*sizeof(int) , "%d%d%d%04d", ret_func, res_t, m.type, m.size); send_resp(sd, &s, buf); break; case 3: ret = Write_parse(buffer, &inum, &rw_buf, &block); if(!ret) res_t = S_Write(inum, rw_buf, block); else res_t = -1; //MSG Format: Function_id, Success_state memset(buf, 0, MSG_BUFFER_SIZE); snprintf(buf, 2*sizeof(int) , "%d%d", ret_func, res_t); send_resp(sd, &s, buf); break; case 4: ret = Read_parse(buffer, &inum, &block); if(!ret) res_t = S_Read(inum, &rw_buf, block, &type, &entries); else res_t = -1; //MSG Format: Function_id, Success_state, File_type, Num_of_entries, 4K buffer bytes read memset(buf, 0, MSG_BUFFER_SIZE); snprintf(buf, 4*sizeof(int) , "%d%d%d%02d", ret_func, res_t, type, entries); strcat(buf, rw_buf); send_resp(sd, &s, buf); break; case 5: ret = Creat_parse(buffer, &pinum, &type, &name); if(!ret) res_t = S_Creat(pinum, type, name); else res_t = -1; //MSG Format: Function_id, Success_state memset(buf, 0, MSG_BUFFER_SIZE); snprintf(buf, 2*sizeof(int) , "%d%d", ret_func, res_t); send_resp(sd, &s, buf); break; case 6: ret = Unlink_parse(buffer, &pinum, &name); break; case 7: #ifdef DEBUG printf("----MFS_Shutdown called\n"); #endif break; default: #ifdef DEBUG printf("Invalid Function Id\n"); #endif ret = -1; break; } } //rc > 0 loop } //while loop return 0; }
int main(int argc, char *argv[]) { int port; char* file_img; int rfd; //Get the arguments get_args(&port, &file_img, argc, argv); int sd = UDP_Open(port); //Creates a new socket and binds to a port to it assert(sd > -1); //Open the file image, if not present call file_create routine disk_fd = open(file_img, O_RDWR); if(disk_fd == -1) { #ifdef DEBUG printf("File image doesn't exist - Creating a new one\n"); #endif rfd = create_img(file_img); if(rfd == -1) { #ifdef DEBUG printf("Error Creating the file - Exiting\n"); #endif return -1; } //disk_fd = rfd; } #ifdef DEBUG printf("File descriptor open: %d\n", disk_fd); #endif //close(ofd); /* CR_t* cr; lseek(ofd, 0, SEEK_SET); int br = read(ofd, (void*)cr, 4); printf("BR: %d\n", br); printf("Log end: %d\n", cr->log_end); printf("Imap_0 addr: %d\n", cr->imap_p[0]); */ printf(" SERVER:: waiting in loop\n"); Stat_t* m =(Stat_t*) malloc(sizeof(Stat_t)); sstat(10, m); printf("file->size=%d\n File->type=%d\n", m->size, m->type); while (1) { struct sockaddr_in s; char buffer[BUFFER_SIZE]; int rc = UDP_Read(sd, &s, buffer, BUFFER_SIZE); if (rc > 0) { printf(" SERVER:: read %d bytes (message: '%s')\n", rc, buffer); char reply[BUFFER_SIZE]; sprintf(reply, "reply"); rc = UDP_Write(sd, &s, reply, BUFFER_SIZE); } } return 0; }
QImage create_img(const QImage image, QRgb (*transform)(PixelArgs&) ) { function<QRgb(PixelArgs&)> fn = transform; return create_img(image, fn); }
/*** read a char image into a specified file ***/ img *read_img (char *prog_name, char *input_file) { image_file_header header; img *im; long cols, rows, colors; size_t items_read; FILE *fp; /* open file and check for errors */ fp = fopen (input_file, "rb"); if (fp == NULL) { fprintf (stderr, "%s: read_img, file ", prog_name); perror (input_file); exit (-1); } /* read header and check for errors */ items_read = fread (&header, sizeof (header), 1, fp); if (ferror (fp)) { fprintf (stderr, "%s: read_img, file ", prog_name); perror (input_file); exit (-1); } if (items_read != 1) { fprintf (stderr, "%s: read_img, file %s", prog_name, input_file); fprintf (stderr, " expect to read 1 header item, actually read %d items\n", items_read); exit (-1); } /* put msl and lsb together to get true values */ cols = (header.cols_msb << 8) | header.cols_lsb; rows = (header.rows_msb << 8) | header.rows_lsb; colors = (header.colors_msb << 8) | header.colors_lsb; /* get an img struct to work with */ im = create_img (prog_name, cols, rows, colors); /* read image data and check for errors */ items_read = fread (im->image, 1, im->size, fp); if (ferror (fp)) { fprintf (stderr, "%s: read_img file ", prog_name); perror (input_file); exit (-1); } if (items_read != im->size) { fprintf (stderr, "%s: read_img, file %s", prog_name, input_file); fprintf (stderr, " expected %ld items, actually read %ld items\n", im->size, items_read); exit (-1); } /* close file and check for error */ if (fclose (fp) == EOF) { fprintf (stderr, "%s: read_wpi_or_non_wpi_img, file ", prog_name); perror (input_file); exit (-1); } /* success */ return im; } /* end read_img */
void main( int argc, char *argv[] ) { // img_array stores old images, new_img_array stores new ones img *old_img, *tmp_img ; limg *projection_limg ; long i, x, y ; FILE *fp ; /***********************************************************/ /* PROJECTION / /***********************************************************/ // Slightly modified from part one // Simplified variant of projection generation. // Since we are only concerned with theta = 0, pi/2 // we can just sum up the rows/cols of the image // Read image old_img = create_img( "hw7", 64, 64, 1 ) ; for( x = 0 ; x < old_img->size ; x++ ) old_img->image[x] = 0 ; old_img->image[2080] = 255 ; // I assume the input image is square, so I pad images that aren't square if( old_img->cols != old_img->rows ) { tmp_img = create_img( "hw7", MAX( old_img->cols, old_img->rows ), MAX( old_img->cols, old_img->rows ), 1 ) ; // Initialize tmp_img to zeroes for( x = 0 ; x < tmp_img->size ; x++ ) tmp_img->image[x] = 0 ; // Copy old image into temp image for( y = 0 ; y < old_img->rows ; y++ ) { for( x = 0 ; x < old_img->cols ; x++ ) { tmp_img->image[y * tmp_img->cols + x] = old_img->image[y * old_img->cols + x] ; } } // Replace old image with padded image old_img = tmp_img ; } // Note: projections will be stored in the format: // The first half of the image array will store the first // phi_max - phi_min numbers corresponding to theta = 0. // The second half will store the numbers corresponding to // theta = pi/2. We assume phi to increment one pixel at a time, // so phi_min = 0 and phi_max = old_img->cols - 1 projection_limg = create_limg( "hw7", old_img->cols, 2 ) ; // Initialize new_img_array[i] for( x = 0 ; x < projection_limg->size ; x++ ) projection_limg->image[x] = 0 ; // Get values for theta = 0 // We can simply iterate the columns of the image since the impulse // function forces all other columns in the sum to zero (p370) for( x = 0 ; x < old_img->cols ; x++ ) { for( y = 0 ; y < old_img->rows ; y++ ) { projection_limg->image[0 * projection_limg->cols + x] += old_img->image[y * old_img->cols + x] ; } } // Get values for theta = pi/2 for( y = 0 ; y < old_img->rows ; y++ ) { for( x = 0 ; x < old_img->cols ; x++ ) { projection_limg->image[1 * projection_limg->cols + y] += old_img->image[y * old_img->cols + x] ; } } /***********************************************************/ /* BACKPROJECTION / /***********************************************************/ // Initialize new images to store backprojection // Doesn't matter how we initialize; this is quickest for me img *back_img = create_img( "hw7", 64, 64, 1 ) ; limg *back_limg = create_limg( "hw7", back_img->cols, back_img->rows ) ; // Calculate backprojection for( x = 0 ; x < back_limg->cols ; x++ ) { for( y = 0 ; y < back_limg->rows ; y++ ) { // b(x,y) = p(x,0) + p(y/(pi/2)) back_limg->image[x * back_limg->rows + y] = (projection_limg->image[x] + projection_limg->image[projection_limg->cols + y]) ; } } // Scale back_limg to [0,255] long max = -1, min = 2147483645 ; // Find max/min intensities for( x = 0 ; x < back_limg->size ; x++ ) { max = MAX( back_limg->image[x], max ) ; min = MIN( back_limg->image[x], min ) ; } // Scale for( x = 0 ; x < back_limg->size ; x++ ) { back_limg->image[x] = ( 255 * ( back_limg->image[x] - min )) / max ; } // Copy from limg into img for( x = 0 ; x < back_img->size ; x++ ) { back_img->image[x] = (int)back_limg->image[x] ; } // Write write_img( "hw7", back_img, "bp.img" ) ; return ; }