Skip to content

Add libisyntax_get_data_model_major_version#55

Merged
Falcury merged 1 commit into
amspath:mainfrom
rvause:rv/get-dmmv
Jun 12, 2026
Merged

Add libisyntax_get_data_model_major_version#55
Falcury merged 1 commit into
amspath:mainfrom
rvause:rv/get-dmmv

Conversation

@rvause

@rvause rvause commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

This value is useful for identifying the isyntax file format version. Use case for exposing this value in the API would be to validate and reject invalid/unexpected formats when reading the image.

@Falcury

Falcury commented Jun 12, 2026

Copy link
Copy Markdown
Member

Should we also expose the minor version? This could also be relevant because some files have "100.4" instead of "100.5" (also see this issue).

@rvause

rvause commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

Good idea, updated with a data_model_minor_version member on the isyntax struct.

Here is a test util that is helpful to verify this.

#include <libisyntax.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
Print a formatted error and exit.
*/
#define ERR_EXIT(...)                                                          \
    do {                                                                       \
        fprintf(stderr, __VA_ARGS__);                                          \
        fprintf(stderr, "\n");                                                 \
        goto cleanup;                                                          \
    } while (0)

int main(int argc, char **argv) {
    // Set line buffering mode on stdout/stderr.
    setvbuf(stdout, NULL, _IOLBF, 0);
    setvbuf(stderr, NULL, _IOLBF, 0);

    isyntax_t *isyntax = NULL;
    int exit_status = EXIT_FAILURE;

    if (argc != 2)
        ERR_EXIT("Incorrect number of arguments: got %d, want 1", argc - 1);

    if (libisyntax_init() != LIBISYNTAX_OK)
        ERR_EXIT("Failed to initialize libisyntax");

    if (libisyntax_open(argv[1], 0, &isyntax) != LIBISYNTAX_OK)
        ERR_EXIT("Failed to open file: %s", argv[1]);

    char *filename = strrchr(argv[1], '/');
    if (!filename)
        filename = argv[1];
    else
        filename++;

    isyntax_image_t const *image = libisyntax_get_wsi_image(isyntax);
    int32_t num_levels = libisyntax_image_get_level_count(image);
    isyntax_level_t const *level0 = NULL;

    level0 = libisyntax_image_get_level(image, 0);
    if (!level0)
        ERR_EXIT("Failed to get the first level in the image");

    int32_t width = libisyntax_level_get_width(level0);
    int32_t height = libisyntax_level_get_height(level0);
    int32_t tile_width = libisyntax_get_tile_width(isyntax);
    int32_t tile_height = libisyntax_get_tile_height(isyntax);

    const char *manufacturer = libisyntax_get_manufacturer(isyntax);
    const char *model = libisyntax_get_manufacturers_model_name(isyntax);
    const char *serial = libisyntax_get_device_serial_number(isyntax);

    bool mpp_is_known = libisyntax_get_is_mpp_known(isyntax);
    double mppx = 0.0;
    double mppy = 0.0;
    if (mpp_is_known) {
        mppx = libisyntax_level_get_mpp_x(level0);
        mppy = libisyntax_level_get_mpp_y(level0);
    }
    const char *software_version;
    if (libisyntax_get_software_versions_count(isyntax) > 0) {
        software_version = libisyntax_get_software_versions(isyntax, 0);
    } else {
        software_version = "unknown";
    }

    printf("%s\n| %dx%d\n| %d levels\n", filename, width, height, num_levels);
    printf("| %dx%d tiles\n", tile_width, tile_height);
    if (mpp_is_known)
        printf("| x %.3f mpp, y %.3f mpp\n", mppx, mppy);
    printf("| software version %s\n", software_version);
    printf("| data model version: %d.%d\n",
           libisyntax_get_data_model_major_version(isyntax),
           libisyntax_get_data_model_minor_version(isyntax));
    if (strlen(manufacturer) > 0)
        printf("| %s %s %s\n", manufacturer, model, serial);
    else
        printf("| Unknown Scanner\n");

    printf("| Levels:\n");
    for (int32_t i = 0; i < num_levels; i++) {
        const isyntax_level_t *_level = libisyntax_image_get_level(image, i);
        int32_t _lvlw = libisyntax_level_get_width(_level);
        int32_t _lvlh = libisyntax_level_get_height(_level);
        double _scale = libisyntax_level_get_downsample_factor(_level);
        printf("|_ Level %d: %dx%d (%f)\n", i, _lvlw, _lvlh, _scale);
    }

    exit_status = EXIT_SUCCESS;
cleanup:
    if (isyntax != NULL)
        libisyntax_close(isyntax);
    return exit_status;
}

@Falcury Falcury merged commit 9a072db into amspath:main Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants