int main(int argc, char **argv) { GError *tmp_err = NULL; // Parse arguments GOptionContext *ctx = g_option_context_new("SLIDE - retrieve information about a slide file"); g_option_context_add_main_entries(ctx, options, NULL); if (!common_parse_options(ctx, &argc, &argv, &tmp_err)) { fprintf(stderr, "%s\n", tmp_err->message); g_clear_error(&tmp_err); g_option_context_free(ctx); return 2; } g_option_context_free(ctx); if (argc != 2) { fprintf(stderr, "No slide specified\n"); return 2; } const char *filename = argv[1]; // Query vendor if (query_vendor) { const char *vendor = openslide_detect_vendor(filename); printf("%s\n", vendor ? vendor : ""); } return 0; }
int vips__openslide_isslide( const char *filename ) { #ifdef HAVE_OPENSLIDE_3_4 const char *vendor; int ok; vendor = openslide_detect_vendor( filename ); /* Generic tiled tiff images can be opened by openslide as well. * Only offer to load this file if it's not a generic tiff since * we want vips_tiffload() to handle these. */ ok = ( vendor && strcmp( vendor, "generic-tiff" ) != 0 ); VIPS_DEBUG_MSG( "vips__openslide_isslide: %s - %d\n", filename, ok ); return( ok ); #else openslide_t *osr; int ok; ok = 0; osr = openslide_open( filename ); if( osr ) { const char *vendor; /* Generic tiled tiff images can be opened by openslide as * well. Only offer to load this file if it's not a generic * tiff since we want vips_tiffload() to handle these. */ vendor = openslide_get_property_value( osr, OPENSLIDE_PROPERTY_NAME_VENDOR ); /* vendor will be NULL if osr is in error state. */ if( vendor && strcmp( vendor, "generic-tiff" ) != 0 ) ok = 1; openslide_close( osr ); } VIPS_DEBUG_MSG( "vips__openslide_isslide: %s - %d\n", filename, ok ); return( ok ); #endif }
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; }