Esempio n. 1
0
// returns list of hashtables of (int -> struct _openslide_tiffdump_item)
GSList *_openslide_tiffdump_create(FILE *f) {
  // read and check magic
  uint16_t magic;
  fseeko(f, 0, SEEK_SET);
  if (fread(&magic, sizeof magic, 1, f) != 1) {
    return NULL;
  }
  if (magic != TIFF_BIGENDIAN && magic != TIFF_LITTLEENDIAN) {
    return NULL;
  }

  //  g_debug("magic: %d", magic);

  int32_t version = read_uint16(f, magic);
  int64_t diroff = read_uint32(f, magic);

  //  g_debug("version: %d", version);

  if (version != TIFF_VERSION) {
    return NULL;
  }

  // initialize loop detector
  GHashTable *loop_detector = g_hash_table_new_full(_openslide_int64_hash,
						    _openslide_int64_equal,
						    _openslide_int64_free,
						    NULL);
  // read all the directories
  GSList *result = NULL;
  while (diroff != 0) {
    // read a directory
    GHashTable *ht = read_directory(f, &diroff, loop_detector, magic);

    // was the directory successfully read?
    if (ht == NULL) {
      // no, so destroy everything
      _openslide_tiffdump_destroy(result);
      result = NULL;
      break;
    }

    // add result to list
    result = g_slist_prepend(result, ht);
  }

  g_hash_table_unref(loop_detector);
  return g_slist_reverse(result);
}
bool _openslide_try_hamamatsu_ndpi(openslide_t *osr, const char *filename,
				   struct _openslide_hash *quickhash1,
				   GError **err) {
  bool success = false;

  char *image_filenames = NULL;
  char *dirname = g_path_get_dirname(filename);
  image_filenames = g_new0(char, 1);
  image_filenames = g_build_filename(dirname, filename, NULL);

  FILE *f = _openslide_fopen(image_filenames, "rb", NULL);
  if (!f) {
    g_set_error(err, OPENSLIDE_ERROR, OPENSLIDE_ERROR_FORMAT_NOT_SUPPORTED,
                "Can't open file");
    return false;
  }

  //dump data from NDPI file. from this function, we get all information about
  //NDPI file (number of image, size of image, offset, etc)
  GSList *dump = _openslide_tiffdump_create(f, err);
  if (!dump) {
    fclose(f);
    return false;
  }
  fclose(f);

  const char *groupname = GROUP_VMS;
  GKeyFile *key_file = g_key_file_new();

  //NDPI file dont have key file. So, I am create the key using this method
  //but, the problem is I can not show the property using :
  //openslide_get_property_names(osr)
  //are you know why?
  g_key_file_set_string(key_file, groupname, "ImageFile", image_filenames);

  //I dont get information about number of layers from NDPI file.
  //So, I set this num_layers to 1
  int num_layers = 1;
  g_key_file_set_integer(key_file, groupname, "NoLayers", num_layers);

  //create NDPI key from from dump variable
  //create key_file from this GSList.
  //We will get some of image from NDPI file with jpeg format
  //I save the count number of all jpeg image in "num_images" variable
  //some of the jpeg file dont have complete header (dont have restart marker offset)
  //"num_jpegs" is total number of jpeg with complete header
  int num_images; //the total number of jpegs images
  int num_jpegs;  //the total number of jpegs with complete header

  //I am still confused how to create index name from extracted
  //NDPI file. So, I am create a file with symbols [%].
  //please check this function
  ndpi_create_key_file(dump, key_file,
                       groupname, &num_images, &num_jpegs);

  //I dont get information about num_cols and num_rows
  //So, I set this "num_cols" variable like this
  int num_cols;
  if(num_jpegs>1)
    num_cols = 2;
  else
    num_cols = 1;

  // add properties
  if (osr) {
    add_properties(osr->properties, key_file, groupname);
  }

  //I am not yet add the macros file
  //we can get the macros file from key_file

  success = hamamatsu_ndpi_part2(osr,
            num_jpegs, image_filenames,
            num_cols, key_file,
            err);

  _openslide_tiffdump_destroy(dump);
  g_key_file_free(key_file);
  return success;
}