void whitening(enum mode m, FILE *fp_in, FILE *fp_out, FILE *hdr) { char *puf; int head_len = 3; int width, height, c_range, retval, i; puf = malloc(255); /* copy header */ for(i=0; i < HEADER_LEN; i++) { fgets (puf, 255, fp_in); fputs (puf, hdr); } free(puf); /* parsing image data */ for(i=0; i< 3*HEIGHT*WIDTH ; i+=3) { if ((WIDTH*HEIGHT*3)/2 < i) { write_img(fp_in, fp_out, m == TOP); } else { write_img(fp_in, fp_out, m == BOTTOM); } } }
static int img_write_magic(struct cr_img *img, int oflags, int type) { if (img_common_magic && (type != CR_FD_INVENTORY)) { u32 cmagic; cmagic = head_magic(oflags); if (write_img(img, &cmagic)) return -1; } return write_img(img, &imgset_template[type].magic); }
/*** query user for file name and write char image file ***/ void write_user_specified_img_file (char *prog_name, img *im) { char file_name[IMG_FILE_NAME_LENGTH]; printf ("Enter output file: "); scanf ("%s", file_name); write_img(prog_name, im, file_name); } /* end write_user_specified_img_file */
static void write_image_or_node(lua_State * L, wrtype_e writetype) { image *a, **aa; image_dict *ad; halfword n; if (lua_gettop(L) != 1) luaL_error(L, "%s expects an argument", wrtype_s[writetype]); if (lua_istable(L, 1)) (void) l_new_image(L); aa = (image **) luaL_checkudata(L, 1, TYPE_IMG); a = *aa; ad = img_dict(a); setup_image(static_pdf, a, writetype); switch (writetype) { case WR_WRITE: n = img_to_node(L, a); tail_append(n); break; case WR_IMMEDIATEWRITE: write_img(static_pdf, ad); break; case WR_NODE: lua_pop(L, 1); /* - */ n = img_to_node(L, a); lua_nodelib_push_fast(L, n); break; default: luaL_error(L, "%s expects an valid image", wrtype_s[writetype]); } if (img_state(ad) < DICT_REFERED) img_state(ad) = DICT_REFERED; }
static void write_image_or_node(lua_State * L, wrtype_e writetype) { image *a, **aa; image_dict *ad; halfword n; if (lua_gettop(L) != 1) luaL_error(L, "%s needs exactly 1 argument", wrtype_s[writetype]); if (lua_istable(L, 1)) (void) l_new_image(L); /* image --- if everything worked well */ aa = (image **) luaL_checkudata(L, 1, TYPE_IMG); /* image */ a = *aa; ad = img_dict(a); setup_image(static_pdf, a, writetype); switch (writetype) { case WR_WRITE: n = img_to_node(a); tail_append(n); break; /* image */ case WR_IMMEDIATEWRITE: write_img(static_pdf, ad); break; /* image */ case WR_NODE: /* image */ lua_pop(L, 1); /* - */ n = img_to_node(a); lua_nodelib_push_fast(L, n); break; /* node */ default: assert(0); } if (img_state(ad) < DICT_REFERED) img_state(ad) = DICT_REFERED; }
void write_stack(img** volume, const char* outprefix) { char fpath[512]; for (ushort n=0; n < num_imgs; ++n) { sprintf(fpath, "%s%.3u.pgm", outprefix, n+1); if (!write_img(volume[n], fpath)) { error("could not write image to disk!"); } } }
// argv[1] = img_src_path; argv[2] = img_dst_path; argv[3] = transformation int main( int argc, char *argv[] ) { // Input img *src_img = read_img( "hw8", argv[1] ) ; write_img( "yo", bilinear( "yo", src_img, 3 ), "test.img" ); return 0 ; }
static int lsbX_crypt_embed(FILE* image, FILE* in, const char* extension, FILE* out, size_calculator_crypt_type *max_size_calc, lsbX_writing_bytes_function_type *writer_delegate, const char* passwd, enum encrypt_type enc, enum encrypt_block_type blk) { struct bmp_type img; unsigned int offset = 0; uint32_t in_file_size, in_file_size_big_endian; uint32_t out_length, out_length_big_endian; unsigned int block_size, crypt_expected_packet_size, packet_size; char* in_buf; char* out_buf; /* header loading */ load_img_header(image, &img); /* sizes computation */ in_file_size = get_file_size(in); block_size = get_block_size_for_cipher(enc, blk); crypt_expected_packet_size = lsbX_crypt_packet_size(in_file_size, block_size, extension); /* checking and image loading */ if (bmp_checking(&img, crypt_expected_packet_size, (*max_size_calc)(image, block_size, extension)) != 0) return -1; img.matrix = malloc(sizeof(uint8_t)*img.usable_size); load_img_matrix(image, &img); /* packet allocation */ packet_size = lsbX_packet_size(in_file_size, extension); in_buf = malloc(sizeof(char)*packet_size); in_file_size_big_endian = htonl(in_file_size); /* packet building */ memcpy(in_buf, &in_file_size_big_endian, SIZE_MARKER_LENGTH); fread(in_buf+SIZE_MARKER_LENGTH, sizeof(char), in_file_size, in); memcpy(in_buf+SIZE_MARKER_LENGTH+in_file_size, extension, strlen(extension)+1); /* encryption of packet */ out_buf = malloc(sizeof(char)*crypt_expected_packet_size); crypt((unsigned char*) in_buf, packet_size, (unsigned char*) passwd, enc, blk, (unsigned char*) out_buf, &out_length); out_length_big_endian = htonl(out_length); /* bit manipulation on image content */ (*writer_delegate)(&out_length_big_endian, sizeof(uint32_t), &img, &offset); (*writer_delegate)(out_buf, sizeof(char)*out_length, &img, &offset); /* write to FILE* out */ write_img(out, &img); free(img.matrix); free(in_buf); free(out_buf); return 0; }
int main(int argc, char *argv[]) { int err = 0; char *img_name; char bin[32][128]; int bin_nr = 0; int offset = 0; int total_w = 0; char *buffer; if(argc == 1) exit(0); img_name = DEFAULT_FILENAME; for(int i = 1; i < argc; i++) { if(strcmp(argv[i], "-o") == 0) { if(!argv[i + 1]) { err = -ERR_ARGW; break; } img_name = argv[i + 1]; i++; } else if(strcmp(argv[i], "-f") == 0) { if(!argv[i + 1]) { err = -ERR_ARGW; break; } offset = atoi(argv[i + 1]); i++; } else { strcpy(bin[bin_nr], argv[i]); bin_nr++; } } if(err) err_exit(err); buffer = (char*)calloc(IMG_SIZE, 1); if((err = read_img(img_name, buffer)) < 0) err_exit(err); for(int i = 0; i < bin_nr; i++) { int res; res = write_buffer(bin[i], buffer, offset); if(res < 0) err_exit(res); offset += res; total_w += res; } if(err = write_img(img_name, buffer)) err_exit(err); free(buffer); printf("%d bytes written.\n", total_w); }
void process_file(const char *fname) { FILE *in; int32_t num_img; int i; in = fopen(fname, "rb"); if (in == NULL) { perror(fname); exit(1); } fseek(in, 12, SEEK_SET); num_img = read_LEint32(in); for (i = 0; i < num_img; i++) write_img(in, fname, i, num_img); fclose(in); }
void process_file(const char *fname) { FILE *in; int codec, num_images, format; int i; int width, height, size, maxval; unsigned char *data; pixel **img; in = fopen(fname, "rb"); if (in == NULL) { perror(fname); exit(1); } read_header(in, &codec, &num_images, &format); for (i = 0; i < num_images; i++) { width = read_LEint32(in); height = read_LEint32(in); data = malloc(width * height * 2); if (codec == 0) read_data_codec0(in, width, height, data); else if (codec == 3) { size = read_LEint32(in); read_data_codec3(in, size, data); } else { fprintf(stderr, "%s: unsupported codec %d\n", fname, codec); exit(1); } if (format == 1) { img = toimg_fmt1(data, width, height); maxval = 255; } else if (format == 5) { img = toimg_fmt5(data, width, height); maxval = 255; } else { fprintf(stderr, "%s: unsupported format %d\n", fname, format); exit(1); } write_img(img, fname, i, width, height, maxval); free(data); ppm_freearray(img, height); } fclose(in); }
int open_image_at(int dfd, int type, unsigned long flags, ...) { char path[PATH_MAX]; va_list args; int ret; va_start(args, flags); vsnprintf(path, PATH_MAX, fdset_template[type].fmt, args); va_end(args); if (flags & O_EXCL) { ret = unlinkat(dfd, path, 0); if (ret && errno != ENOENT) { pr_perror("Unable to unlink %s", path); goto err; } } ret = openat(dfd, path, flags, CR_FD_PERM); if (ret < 0) { pr_perror("Unable to open %s", path); goto err; } if (fdset_template[type].magic == RAW_IMAGE_MAGIC) goto skip_magic; if (flags == O_RDONLY) { u32 magic; if (read_img(ret, &magic) < 0) goto err; if (magic != fdset_template[type].magic) { pr_err("Magic doesn't match for %s\n", path); goto err; } } else { if (write_img(ret, &fdset_template[type].magic)) goto err; } skip_magic: return ret; err: return -1; }
// 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 ) ; }
// Create copy of src_img with web safe colors void webify( img *src_img, char *dst_name ) { long pixel, color, old_pixel, new_pixel, error[3] = {0,0,0} ; img *dst_img = copy_img( "hw9", src_img ) ; // With dithering for( pixel = 0 ; pixel < dst_img->size / dst_img->colors ; pixel++ ) { for( color = 0 ; color < dst_img->colors ; color++ ) { old_pixel = CAP( dst_img->image[color * dst_img->rows * dst_img->cols + pixel] + error[color] ) ; new_pixel = CAP( recolor_for_web( old_pixel )) ; error[color] = old_pixel - new_pixel ; dst_img->image[color * dst_img->rows * dst_img->cols + pixel] = new_pixel ; } } write_img( "hw9", dst_img, dst_name ) ; return ; }
static int lsbX_embed(FILE* image, FILE* in, const char* extension, FILE* out, size_calculator_type *max_size_calc, lsbX_writing_bytes_function_type *writer_delegate) { struct bmp_type img; uint8_t buffer[BUFFER_SIZE]; unsigned int offset = 0; size_t read_size; uint32_t in_file_size; /* image header loading */ load_img_header(image, &img); /* size computation */ in_file_size = get_file_size(in); /* checking and image loading */ if (bmp_checking(&img, in_file_size, (*max_size_calc)(image,extension)) != 0) return -1; img.matrix = malloc(sizeof(uint8_t)*img.usable_size); load_img_matrix(image, &img); /* packet construction on-the-fly and bit manipulation on image content * size must be written in big endian order to the file */ in_file_size = htonl(in_file_size); (*writer_delegate)(&in_file_size, sizeof(uint32_t), &img, &offset); while ((read_size = fread(buffer, sizeof(uint8_t), BUFFER_SIZE, in)) > 0) (*writer_delegate)(buffer, read_size, &img, &offset); /* writing the extension, including the \0 at the end (so strlen(extension) + 1 byte for \0) */ (*writer_delegate)(extension, strlen(extension)+1, &img, &offset); /* write to FILE* out */ write_img(out, &img); free(img.matrix); return 0; }
// dft_type = 1 for DFT, dft_type = -1 for IDFT void dft_both( img *src_img, char *dst_name, int dft_type ) { long x, y, u, v, i, M, N ; double sum_r, sum_i ; cimg *cdft_img, *cintermediate_img ; dimg *ddft_img, *dph_img, *dmg_img ; img *dst_img ; // Initialize M and N to match book M = src_img->cols ; N = src_img->rows ; // Initialize cdft_img = create_cimg ( "dft", M, N ) ; cintermediate_img = create_cimg ( "dft", M, N ) ; if( dft_type == 1 ) { // Premultiply by ( -1 )^( x + y ) to center for( x = 0 ; x < M ; x++ ) { for( y = 0 ; y < N ; y++ ) src_img->image[y * M + x] *= pow( -1, x + y ) ; } } // Compute DFT/IDFT // Compute cintermediate_img = F(x,v) for( v = 0 ; v < N ; v++ ) { for( x = 0 ; x < M ; x++ ) { sum_r = 0 ; sum_i = 0 ; for( y = 0 ; y < N ; y++ ) { sum_r += src_img->image[y * M + x] * cos( dft_type * -2 * PI * v * y / (double)N ) ; sum_i += src_img->image[y * M + x] * sin( dft_type * -2 * PI * v * y / (double)N ) ; } cintermediate_img->image[v * M + x].r = sum_r ; cintermediate_img->image[v * M + x].i = sum_i ; } } // Compute cintermediate_img = F(u,v) for( u = 0 ; u < M ; u++ ) { for( v = 0 ; v < N ; v++ ) { sum_r = 0 ; sum_i = 0 ; for( x = 0 ; x < M ; x++ ) { sum_r += cintermediate_img->image[v * M + u].r * cos( dft_type * -2 * PI * u * x / (double)M ) ; sum_i += cintermediate_img->image[v * M + u].i * sin( dft_type * -2 * PI * u * x / (double)M ) ; } cdft_img->image[v * M + u].r = sum_r ; cdft_img->image[v * M + u].i = sum_i ; } } if( dft_type == -1 ) { // 1/MN constant for( u = 0 ; u < M ; u++ ) { for( v = 0 ; v < N ; v++ ) { cdft_img->image[v * M + u].r /= M * N ; cdft_img->image[v * M + u].i /= M * N ; } } } if( dft_type == 1 ) { // Calculate Fourier spectrum and phase angle of DFT dph_img = ph_part( "dft", cdft_img ) ; dmg_img = mg_part( "dft", cdft_img ) ; // Initialize ddft_img = create_dimg ( "dft", M, N ) ; // Restate DFT as product of Fourier spectrum and phase angle. Save in ddft_img for( i = 0 ; i < M * N ; i++ ) ddft_img->image[i] = dph_img->image[i] * dmg_img->image[i] ; } else ddft_img = re_part( "dft", cdft_img ) ; // Scale this result and save it as an img with name = dst_name write_img( "dft", dimg2img_scale( "dft", ddft_img ), dst_name ) ; return ; }
int segment(struct SigSet *S, /* class parameters */ struct parms *parms, struct files *files) { int block_size; /* size of subregion blocks */ int ml; /* max likelihood? */ DCELL ***img; /* multispectral image, img[band][i][j] */ int last_row; int wd, ht; /* image width and height */ struct Region region; /* specifies image subregion */ int nbands; /* number of bands */ int nclasses; /* number of classes */ LIKELIHOOD ****ll_pym; /* pyramid of log likelihoods */ unsigned char ***sf_pym; /* pyramid of segmentations */ int D; /* number of levels in pyramid */ double *alpha_dec; /* class transition probabilities */ int i; ml = parms->ml; /* use maxl? */ block_size = parms->blocksize; wd = Rast_window_cols(); /* get width from GRASS */ ht = Rast_window_rows(); /* get height from GRASS */ /* make blocksize a power of 2 */ if (block_size < 8) block_size = 8; for (i = 0; (block_size >> i) > 1; i++) { } block_size = 1 << i; /**** this code may stay the same ******/ nbands = S->nbands; nclasses = S->nclasses; /* Check for too many classes */ if (nclasses > 256) G_fatal_error(_("Number of classes must be < 256")); /* allocate alpha_dec parameters */ D = levels(block_size, block_size); alpha_dec = (double *)G_malloc(D * sizeof(double)); /* allocate image block */ img = (DCELL ***) multialloc(sizeof(DCELL), 3, nbands, block_size, block_size); /* allocate memory for log likelihood pyramid */ ll_pym = (LIKELIHOOD ****) get_cubic_pyramid(block_size, block_size, nclasses, sizeof(LIKELIHOOD)); /* allocate memory for segmentation pyramid */ sf_pym = (unsigned char ***)get_pyramid(wd, ht, sizeof(char)); /* tiled segmentation */ init_reg(®ion, wd, ht, block_size); extract_init(S); last_row = -1; do { if (last_row != region.ymin) G_message(_("Processing rows %d-%d (of %d)..."), region.ymin + 1, region.ymax, ht); last_row = region.ymin; shift_img(img, nbands, ®ion, block_size); /* this reads grass images into the block defined in region */ read_block(img, ®ion, files); shift_ll(ll_pym, ®ion, block_size); extract(img, ®ion, ll_pym[0], S); if (ml) MLE(sf_pym[0], ll_pym[0], ®ion, nclasses); else { for (i = 0; i < D; i++) alpha_dec[i] = 1.0; seq_MAP(sf_pym, ®ion, ll_pym, nclasses, alpha_dec); } } while (increment_reg(®ion, wd, ht, block_size)); write_img(sf_pym[0], wd, ht, S, parms, files); return 0; }
struct cr_img *open_image_at(int dfd, int type, unsigned long flags, ...) { struct cr_img *img; unsigned long oflags = flags; char path[PATH_MAX]; va_list args; int ret; img = xmalloc(sizeof(*img)); if (!img) goto errn; oflags |= imgset_template[type].oflags; flags &= ~(O_OPT | O_NOBUF); va_start(args, flags); vsnprintf(path, PATH_MAX, imgset_template[type].fmt, args); va_end(args); ret = openat(dfd, path, flags, CR_FD_PERM); if (ret < 0) { if ((oflags & O_OPT) && errno == ENOENT) { xfree(img); return NULL; } pr_perror("Unable to open %s", path); goto err; } img->_x.fd = ret; if (oflags & O_NOBUF) bfd_setraw(&img->_x); else if (bfdopen(&img->_x, flags)) goto err; if (imgset_template[type].magic == RAW_IMAGE_MAGIC) goto skip_magic; if (flags == O_RDONLY) { u32 magic; if (read_img(img, &magic) < 0) goto err; if (magic != imgset_template[type].magic) { pr_err("Magic doesn't match for %s\n", path); goto err; } } else { if (write_img(img, &imgset_template[type].magic)) goto err; } skip_magic: return img; err: xfree(img); errn: return NULL; }
static ngx_int_t ngx_http_image_handler(ngx_http_request_t *r) { u_char *last; size_t root; ngx_int_t rc; ngx_str_t path; char request_uri[255]; int request_uri_len; ngx_image_conf_t *conf; conf = ngx_http_get_module_loc_conf(r, ngx_http_image_module); if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD))) { return NGX_HTTP_NOT_ALLOWED; } if (r->headers_in.if_modified_since) { return NGX_HTTP_NOT_MODIFIED; } if (r->uri.data[r->uri.len - 1] == '/') { return NGX_DECLINED; } rc = ngx_http_discard_request_body(r); if (rc != NGX_OK) { return rc; } last = ngx_http_map_uri_to_path(r, &path, &root, 0); if (last == NULL) { return NGX_HTTP_INTERNAL_SERVER_ERROR; } if(file_exists((char*) path.data) == -1) { request_uri_len = strlen((char *)r->uri_start) - strlen((char *)r->uri_end); strncpy(request_uri, (char *)r->uri_start, request_uri_len); request_uri[request_uri_len] = '\0'; dirname(request_uri,conf->request_dir); conf->url = request_uri;//请求的URL地址 conf->dest_file = (char *)path.data; check_image_type(conf);//检查图片类型(根据后缀进行简单判断) if( conf->dest_type > 0 ) { if (parse_image_info(conf) == 0)//解析并处理请求的图片URL { make_thumb(conf);//生成图片缩略图 water_mark(conf);//图片打上水印 thumb_to_string(conf);//GD对象转换成二进制字符串 if(conf->image_output == 0) { write_img(conf);//保存图片缩略图到文件 } if(conf->image_output == 1) { return output(r,conf,ngx_http_image_types[conf->dest_type]); } } } } return NGX_DECLINED; }
int main(int argc, char *argv[]) { struct GModule *module; struct GParams *params; int i, ret; int red, grn, blu; float size; double vp_height, z_exag; /* calculated viewpoint height, z-exag */ int width, height; /* output image size */ char *output_name; nv_data data; struct render_window *offscreen; /* initialize GRASS */ G_gisinit(argv[0]); module = G_define_module(); G_add_keyword(_("visualization")); G_add_keyword(_("graphics")); G_add_keyword(_("raster")); G_add_keyword(_("vector")); G_add_keyword(_("raster3d")); module->label = _("Creates a 3D rendering of GIS data."); module->description = _("Renders surfaces (raster data), " "2D/3D vector data, and " "volumes (3D raster data) in 3D."); params = (struct GParams *)G_malloc(sizeof(struct GParams)); /* define options, call G_parser() */ parse_command(argc, argv, params); /* check parameters consistency */ check_parameters(params); width = atoi(params->size->answers[0]); height = atoi(params->size->answers[1]); G_asprintf(&output_name, "%s.%s", params->output->answer, params->format->answer); GS_libinit(); GVL_libinit(); GS_set_swap_func(swap_gl); /* define render window */ offscreen = Nviz_new_render_window(); Nviz_init_render_window(offscreen); if (Nviz_create_render_window(offscreen, NULL, width, height) == -1) G_fatal_error(_("Unable to render data")); Nviz_make_current_render_window(offscreen); /* initialize nviz data */ Nviz_init_data(&data); /* define default attributes for map objects */ Nviz_set_surface_attr_default(); /* set background color */ Nviz_set_bgcolor(&data, Nviz_color_from_str(params->bgcolor->answer)); /* init view, lights */ Nviz_init_view(&data); /* load raster maps (surface topography) & set attributes (map/constant) */ load_rasters(params, &data); /* set draw mode of loaded surfaces */ surface_set_draw_mode(params); /* load line vector maps */ if (params->vlines->answer) { load_vlines(params, &data); /* set attributes of 2d lines */ vlines_set_attrb(params); } /* load point vector maps */ if (params->vpoints->answer) { load_vpoints(params, &data); /* set attributes for points */ vpoints_set_attrb(params); } /* load volumes */ if (params->volume->answer) { load_rasters3d(params, &data); } /* define isosurfaces for displaying volumes */ if (params->isosurf_level->answer) { add_isosurfs(params, &data); } /* define slices for displaying volumes */ if (params->slice->answer) { add_slices(params, &data); } /* focus on loaded data */ Nviz_set_focus_map(MAP_OBJ_UNDEFINED, -1); /* define view point */ if (params->exag->answer) { z_exag = atof(params->exag->answer); } else { z_exag = Nviz_get_exag(); G_verbose_message(_("Vertical exaggeration not given, using calculated " "value %.0f"), z_exag); } Nviz_change_exag(&data, z_exag); if (params->height->answer) { vp_height = atof(params->height->answer); } else { double min, max; Nviz_get_exag_height(&vp_height, &min, &max); G_verbose_message(_("Viewpoint height not given, using calculated " "value %.0f"), vp_height); } Nviz_set_viewpoint_height(vp_height); Nviz_set_viewpoint_position(atof(params->pos->answers[0]), atof(params->pos->answers[1])); Nviz_set_viewpoint_twist(atoi(params->twist->answer)); Nviz_set_viewpoint_persp(atoi(params->persp->answer)); if (params->focus->answer) { Nviz_set_focus(&data, atof(params->focus->answers[0]), atof(params->focus->answers[1]), atof(params->focus->answers[2])); } /* set lights */ Nviz_set_light_position(&data, 1, atof(params->light_pos->answers[0]), atof(params->light_pos->answers[1]), atof(params->light_pos->answers[2]), 0.0); Nviz_set_light_bright(&data, 1, atoi(params->light_bright->answer) / 100.0); if (G_str_to_color(params->light_color->answer, &red, &grn, &blu) != 1) { red = grn = blu = 255; } Nviz_set_light_color(&data, 1, red, grn, blu); Nviz_set_light_ambient(&data, 1, atof(params->light_ambient->answer) / 100.0); /* define fringes */ if (params->fringe->answer) { int nw, ne, sw, se; i = 0; nw = ne = sw = se = 0; while (params->fringe->answers[i]) { const char *edge = params->fringe->answers[i++]; if (strcmp(edge, "nw") == 0) nw = 1; else if (strcmp(edge, "ne") == 0) ne = 1; else if (strcmp(edge, "sw") == 0) sw = 1; else if (strcmp(edge, "se") == 0) se = 1; } Nviz_new_fringe(&data, -1, Nviz_color_from_str(params->fringe_color->answer), atof(params->fringe_elev->answer), nw, ne, sw, se); } /* draw north arrow */ if (params->north_arrow->answer) { if (!params->north_arrow_size->answer) size = Nviz_get_longdim(&data) / 8.; else size = atof(params->north_arrow_size->answer); Nviz_set_arrow(&data, atoi(params->north_arrow->answers[0]), atoi(params->north_arrow->answers[1]), size, Nviz_color_from_str(params->north_arrow_color-> answer)); Nviz_draw_arrow(&data); } GS_clear(data.bgcolor); /* cutting planes */ if (params->cplane->answer) draw_cplane(params, &data); /* draw */ Nviz_draw_all(&data); /* write to image */ ret = 0; if (strcmp(params->format->answer, "ppm") == 0) ret = write_img(output_name, FORMAT_PPM); if (strcmp(params->format->answer, "tif") == 0) ret = write_img(output_name, FORMAT_TIF); if (!ret) G_fatal_error(_("Unsupported output format")); G_done_msg(_("File <%s> created."), output_name); Nviz_destroy_data(&data); Nviz_destroy_render_window(offscreen); G_free((void *)output_name); G_free((void *)params); exit(EXIT_SUCCESS); }
uchar * v4l_capture::capture () { if (!write_img(frame.data)) return NULL; return frame.data; }
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 ; }
void pdf_write_image(PDF pdf, int n) { if (pdf->draftmode == 0) write_img(pdf, idict_array[obj_data_ptr(pdf, n)]); }
void Image_Write(tImage *image, char *filename, char *comment) { void write_img(char*, unsigned char **, int, int, char *); write_img(filename,image->content,image->row,image->col, comment); }