-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathopenslide-vendor-mirax.c.patch
133 lines (126 loc) · 5.26 KB
/
openslide-vendor-mirax.c.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
diff --git a/src/openslide-vendor-mirax.c b/src/openslide-vendor-mirax.c
index ffc03b3..b8f46e6 100644
--- a/src/openslide-vendor-mirax.c
+++ b/src/openslide-vendor-mirax.c
@@ -32,6 +32,7 @@
#include "openslide-decode-gdkpixbuf.h"
#include "openslide-decode-jpeg.h"
#include "openslide-decode-png.h"
+#include "openslide-decode-jp2k.h"
#include <glib.h>
#include <stdlib.h>
@@ -141,6 +142,7 @@ enum image_format {
FORMAT_JPEG,
FORMAT_PNG,
FORMAT_BMP,
+ FORMAT_JPEG2000,
};
struct slide_zoom_level_section {
@@ -245,6 +247,23 @@ static uint32_t *read_image(openslide_t *osr,
dest, w, h,
err);
break;
+ case FORMAT_JPEG2000: {
+ g_autofree void *buf = g_malloc(image->length);
+ int32_t buflen;
+ g_autoptr(_openslide_file) f = _openslide_fopen(data->datafile_paths[image->fileno], err);
+ if (!f) {
+ return false;
+ }
+ if (!_openslide_fseek(f, image->start_in_file, SEEK_SET, err)) {
+ g_prefix_error(err, "Couldn't fseek %s: ", data->datafile_paths[image->fileno]);
+ return false;
+ }
+ buflen = _openslide_fread_exact(f, buf, image->length, NULL);
+ result = _openslide_jp2k_decode_buffer(
+ dest, w, h,
+ buf, buflen, OPENSLIDE_JP2K_RGB, err);
+ }
+ break;
default:
g_assert_not_reached();
}
@@ -397,6 +416,17 @@ static bool mirax_detect(const char *filename, struct _openslide_tifflike *tl,
g_strndup(filename, strlen(filename) - strlen(MRXS_EXT));
g_autofree char *slidedat_path =
g_build_filename(dirname, SLIDEDAT_INI, NULL);
+ if (!_openslide_fexists(slidedat_path, &tmp_err)) {
+ g_autofree char *basename = g_path_get_dirname(filename);
+ if (basename) {
+ if (g_str_has_suffix(basename, MRXS_EXT)) {
+ g_free(slidedat_path);
+ g_free(dirname);
+ dirname = g_strndup(basename, strlen(basename) - strlen(MRXS_EXT));
+ slidedat_path = g_build_filename(dirname, SLIDEDAT_INI, SLIDEDAT_INI, NULL);
+ }
+ }
+ }
if (!_openslide_fexists(slidedat_path, &tmp_err)) {
if (tmp_err != NULL) {
g_propagate_prefixed_error(err, tmp_err, "Testing whether %s exists: ",
@@ -973,6 +1003,8 @@ static enum image_format parse_image_format(const char *name, GError **err) {
return FORMAT_PNG;
} else if (!strcmp(name, "BMP24")) {
return FORMAT_BMP;
+ } else if (!strcmp(name, "JPEG2000")) {
+ return FORMAT_JPEG2000;
} else {
g_set_error(err, OPENSLIDE_ERROR, OPENSLIDE_ERROR_FAILED,
"Unrecognized image format: %s", name);
@@ -1359,8 +1391,10 @@ static int get_associated_image_nonhier_offset(GKeyFile *keyfile,
// verify image format
// we have only ever seen JPEG
if (parse_image_format(format, NULL) != FORMAT_JPEG) {
+ /*
g_set_error(err, OPENSLIDE_ERROR, OPENSLIDE_ERROR_FAILED,
"Unsupported associated image format: %s", format);
+ */
return -1;
}
@@ -1373,10 +1407,22 @@ static bool mirax_open(openslide_t *osr, const char *filename,
// get directory from filename
g_autofree char *dirname =
g_strndup(filename, strlen(filename) - strlen(MRXS_EXT));
+ bool girder_paths = false;
+ GError *tmp_err = NULL;
+ g_autofree char *slidedat_path2 =
+ g_build_filename(dirname, SLIDEDAT_INI, NULL);
+ if (!_openslide_fexists(slidedat_path2, &tmp_err)) {
+ g_free(dirname);
+ g_autofree char *basename = g_path_get_dirname(filename);
+ dirname = g_strndup(basename, strlen(basename) - strlen(MRXS_EXT));
+ girder_paths = true;
+ }
// first, check slidedat
g_autofree char *slidedat_path =
- g_build_filename(dirname, SLIDEDAT_INI, NULL);
+ !girder_paths ?
+ g_build_filename(dirname, SLIDEDAT_INI, NULL) :
+ g_build_filename(dirname, SLIDEDAT_INI, SLIDEDAT_INI, NULL);
// hash the slidedat
if (!_openslide_hash_file(quickhash1, slidedat_path, err)) {
return false;
@@ -1409,7 +1455,7 @@ static bool mirax_open(openslide_t *osr, const char *filename,
READ_KEY_OR_FAIL(objective_magnification, slidedat, GROUP_GENERAL,
KEY_OBJECTIVE_MAGNIFICATION, integer);
- GError *tmp_err = NULL;
+ tmp_err = NULL;
int image_divisions =
g_key_file_get_integer(slidedat, GROUP_GENERAL,
KEY_CAMERA_IMAGE_DIVISIONS_PER_SIDE, &tmp_err);
@@ -1499,7 +1545,7 @@ static bool mirax_open(openslide_t *osr, const char *filename,
g_autofree char *key = g_strdup_printf(KEY_d_FILE, i);
g_autofree char *name = NULL;
READ_KEY_OR_FAIL(name, slidedat, GROUP_DATAFILE, key, value);
- datafile_paths[i] = g_build_filename(dirname, name, NULL);
+ datafile_paths[i] = !girder_paths ? g_build_filename(dirname, name, NULL) : g_build_filename(dirname, name, name, NULL);
}
// load data from all slide_zoom_level_section_names sections
@@ -1624,7 +1670,7 @@ static bool mirax_open(openslide_t *osr, const char *filename,
*/
// read indexfile
- g_autofree char *index_path = g_build_filename(dirname, index_filename, NULL);
+ g_autofree char *index_path = !girder_paths ? g_build_filename(dirname, index_filename, NULL) : g_build_filename(dirname, index_filename, index_filename, NULL);
g_autoptr(_openslide_file) indexfile = _openslide_fopen(index_path, err);
if (!indexfile) {
return false;