int main(int argc, char **argv) { if (argc!=6) { fprintf(stderr,"Usage: %s <image file> <cancer type> <subject id> <case id> <output file>\n",argv[0]); exit(1); } char *inp_file = argv[1]; char *c_type = argv[2]; char *s_id = argv[3]; char *c_id = argv[4]; char *h_name = "localhost"; FILE *fpo = fopen(argv[5],"w"); int check_ok = 1; struct stat attrib; stat(inp_file,&attrib); char file_date[20]; strftime(file_date, 20, "%m-%d-%y:%H.%M.%S", localtime(&(attrib.st_ctime))); openslide_t *osr = openslide_open(inp_file); if (osr==NULL) { fprintf(stderr,"Error: openslide cannot read file: %s\n",inp_file); exit(1); } int64_t w,h; openslide_get_level0_dimensions(osr,&w,&h); if (w<=0 || h<=0) { fprintf(stderr,"Error: openslide cannot get width (%ld) and height (%ld) from the image file: %s\n.",w,h,inp_file); exit(1); } fprintf(fpo,"hostname,filename,last_modified,cancer_type,case_id,subject_id,identifier,width,height,mpp_x,mpp_y,objective,vendor,status,level_count,imageid\n"); fprintf(fpo,"%s,",h_name); fprintf(fpo,"%s,",inp_file); fprintf(fpo,"%s,",file_date); fprintf(fpo,"%s,",c_type); fprintf(fpo,"%s,",c_id); fprintf(fpo,"%s,",s_id); fprintf(fpo,"%s,",c_id); fprintf(fpo,"%f,",(float)w); fprintf(fpo,"%f,",(float)h); /* get objective value */ char *o_val = (char*)openslide_get_property_value(osr,"openslide.objective-power"); if (o_val==NULL) o_val = (char*)openslide_get_property_value(osr,"aperio.AppMag"); char *mpp_x = (char*)openslide_get_property_value(osr,"openslide.mpp-x"); if (mpp_x!=NULL) fprintf(fpo,"%.8f,",atof(mpp_x)); else { if (o_val!=NULL) fprintf(fpo,"%f,",0.25*40.0/atof(o_val)); else { check_ok = 0; fprintf(fpo,"%f,",-1.0); } } char *mpp_y = (char*)openslide_get_property_value(osr,"openslide.mpp-y"); if (mpp_y!=NULL) fprintf(fpo,"%.8f,",atof(mpp_y)); else { if (o_val!=NULL) fprintf(fpo,"%f,",0.25*40.0/atof(o_val)); else { check_ok = 0; fprintf(fpo,"%f,",-1.0); } } /* print objective value */ if (o_val!=NULL) fprintf(fpo,"%f,",(float)atof(o_val)); else { fprintf(fpo,"%f,",-1.0); check_ok = 0; } char *vendor = (char*)openslide_get_property_value(osr,"openslide.vendor"); if (vendor!=NULL) fprintf(fpo,"%s,",vendor); else fprintf(fpo,"no_vendor,"); if (check_ok==0) { fprintf(fpo,"some_errors,"); fprintf(stderr,"SOME_ERRORS: %s\n",inp_file); } else { fprintf(fpo,"status_ok,"); fprintf(stdout,"OK: %s\n",inp_file); } char *level_count = (char*)openslide_get_property_value(osr,"openslide.level-count"); if (level_count!=NULL) fprintf(fpo,"%s,",level_count); else fprintf(fpo,"1,"); char *image_id = (char*)openslide_get_property_value(osr,"aperio.ImageID"); if (image_id!=NULL) fprintf(fpo,"%d\n",atoi(image_id)); else fprintf(fpo,"-1\n"); fflush(fpo); openslide_close(osr); fclose(fpo); exit(0); }
int main(int argc, char **argv) { if (!g_thread_supported()) { g_thread_init(NULL); } if (argc != 2) { fail("No file specified"); } const char *path = argv[1]; if (g_str_equal(path, "--leak-check--")) { child_check_open_fds(); return 0; } openslide_get_version(); if (!openslide_detect_vendor(path)) { fail("No vendor for %s", path); } openslide_t *osr = openslide_open(path); if (!osr) { fail("Couldn't open %s", path); } const char *err = openslide_get_error(osr); if (err) { fail("Open failed: %s", err); } openslide_close(osr); osr = openslide_open(path); if (!osr || openslide_get_error(osr)) { fail("Reopen failed"); } int64_t w, h; openslide_get_level0_dimensions(osr, &w, &h); int32_t levels = openslide_get_level_count(osr); for (int32_t i = -1; i < levels + 1; i++) { int64_t ww, hh; openslide_get_level_dimensions(osr, i, &ww, &hh); openslide_get_level_downsample(osr, i); } openslide_get_best_level_for_downsample(osr, 0.8); openslide_get_best_level_for_downsample(osr, 1.0); openslide_get_best_level_for_downsample(osr, 1.5); openslide_get_best_level_for_downsample(osr, 2.0); openslide_get_best_level_for_downsample(osr, 3.0); openslide_get_best_level_for_downsample(osr, 3.1); openslide_get_best_level_for_downsample(osr, 10); openslide_get_best_level_for_downsample(osr, 20); openslide_get_best_level_for_downsample(osr, 25); openslide_get_best_level_for_downsample(osr, 100); openslide_get_best_level_for_downsample(osr, 1000); openslide_get_best_level_for_downsample(osr, 10000); // NULL buffer openslide_read_region(osr, NULL, 0, 0, 0, 1000, 1000); // empty region openslide_read_region(osr, NULL, 0, 0, 0, 0, 0); // read properties const char * const *property_names = openslide_get_property_names(osr); while (*property_names) { const char *name = *property_names; openslide_get_property_value(osr, name); property_names++; } // read associated images const char * const *associated_image_names = openslide_get_associated_image_names(osr); while (*associated_image_names) { int64_t w, h; const char *name = *associated_image_names; openslide_get_associated_image_dimensions(osr, name, &w, &h); uint32_t *buf = g_new(uint32_t, w * h); openslide_read_associated_image(osr, name, buf); g_free(buf); associated_image_names++; } test_image_fetch(osr, -10, -10, 200, 200); test_image_fetch(osr, w/2, h/2, 500, 500); test_image_fetch(osr, w - 200, h - 100, 500, 400); test_image_fetch(osr, w*2, h*2, 400, 400); test_image_fetch(osr, w - 20, 0, 40, 100); test_image_fetch(osr, 0, h - 20, 100, 40); // active region const char *bounds_x = openslide_get_property_value(osr, OPENSLIDE_PROPERTY_NAME_BOUNDS_X); const char *bounds_y = openslide_get_property_value(osr, OPENSLIDE_PROPERTY_NAME_BOUNDS_Y); int64_t bounds_xx = 0; int64_t bounds_yy = 0; if (bounds_x && bounds_y) { bounds_xx = g_ascii_strtoll(bounds_x, NULL, 10); bounds_yy = g_ascii_strtoll(bounds_y, NULL, 10); test_image_fetch(osr, bounds_xx, bounds_yy, 200, 200); } openslide_close(osr); check_cloexec_leaks(path, argv[0], bounds_xx, bounds_yy); return 0; }