SlideIO 2.0.0
Open-source library for reading of medical images
Loading...
Searching...
No Matches
zviutils.hpp
1// This file is part of slideio project.
2// It is subject to the license terms in the LICENSE file found in the top-level directory
3// of this distribution and at http://slideio.com/license.html.#pragma once
4#pragma once
5
6#include "slideio/drivers/zvi/zvi_api_def.hpp"
7#include "slideio/drivers/zvi/pole_lib.hpp"
8#include "slideio/base/slideio_enums.hpp"
9#include <codecvt>
10#include <cstdint>
11#include <string>
12#include <variant>
13#include <vector>
14
15#if defined(_MSC_VER)
16#pragma warning( push )
17#pragma warning(disable: 4251)
18#endif
19
20enum class ZVIPixelFormat;
21
22namespace slideio
23{
24 namespace ZVIUtils
25 {
26 typedef enum tagVARENUM
27 {
28 VT_EMPTY = 0x0000,
29 VT_NULL = 0x0001,
30 VT_I2 = 0x0002,
31 VT_I4 = 0x0003,
32 VT_R4 = 0x0004,
33 VT_R8 = 0x0005,
34 VT_CY = 0x0006,
35 VT_DATE = 0x0007,
36 VT_BSTR = 0x0008,
37 VT_DISPATCH = 0x0009,
38 VT_ERROR = 0x000A,
39 VT_BOOL = 0x000B,
40 VT_VARIANT = 0x000C,
41 VT_UNKNOWN = 0x000D,
42 VT_DECIMAL = 0x000E,
43 VT_I1 = 0x0010,
44 VT_UI1 = 0x0011,
45 VT_UI2 = 0x0012,
46 VT_UI4 = 0x0013,
47 VT_I8 = 0x0014,
48 VT_UI8 = 0x0015,
49 VT_INT = 0x0016,
50 VT_UINT = 0x0017,
51 VT_VOID = 0x0018,
52 VT_HRESULT = 0x0019,
53 VT_PTR = 0x001A,
54 VT_SAFEARRAY = 0x001B,
55 VT_CARRAY = 0x001C,
56 VT_USERDEFINED = 0x001D,
57 VT_LPSTR = 0x001E,
58 VT_LPWSTR = 0x001F,
59 VT_RECORD = 0x0024,
60 VT_INT_PTR = 0x0025,
61 VT_UINT_PTR = 0x0026,
62 VT_BLOB = 0x0041,
63 VT_STREAM = 0x0042,
64 VT_STORAGE = 0x0043,
65 VT_STREAMED_OBJECT = 0x0044,
66 VT_STORED_OBJECT = 0x0045,
67 VT_ARRAY = 0x2000,
68 VT_BYREF = 0x4000
69 } VARENUM;
70 typedef std::variant<std::monostate, bool, int32_t, uint32_t, uint64_t, int64_t, double, std::string> Variant;
71
72 struct ZviTagEntry {
73 int32_t id;
74 Variant value;
75 };
76
77 // Reads a ZVI Tags stream:
78 // - hasClsidHeader=true: 16 raw bytes (CLSID) precede {Version}{Count}.
79 // Use this for the root-level <Tags> stream.
80 // - hasClsidHeader=false: stream starts directly with {Version}{Count}.
81 // Use this for [Image]/[Tags]/<Contents> and
82 // [Item(n)]/[Tags]/<Contents>.
83 // Returns one ZviTagEntry per (Value, TagID, Attribute) triple. Entries
84 // whose Value variant is monostate (VT_EMPTY / unsupported types) are
85 // dropped. {Attribute} is consumed and discarded.
86 std::vector<ZviTagEntry> SLIDEIO_ZVI_EXPORTS readAllTags(
87 ole::basic_stream& stream, bool hasClsidHeader);
88
89 void SLIDEIO_ZVI_EXPORTS skipItem(ole::basic_stream& stream);
90 void SLIDEIO_ZVI_EXPORTS skipItems(ole::basic_stream& stream, int count);
91 int32_t SLIDEIO_ZVI_EXPORTS readIntItem(ole::basic_stream& stream);
92 double SLIDEIO_ZVI_EXPORTS readDoubleItem(ole::basic_stream& stream);
93 std::string SLIDEIO_ZVI_EXPORTS readStringItem(ole::basic_stream& stream);
94 Variant SLIDEIO_ZVI_EXPORTS readItem(ole::basic_stream& stream, bool skipUnusedTypes = true);
95 slideio::DataType dataTypeFromPixelFormat(const ZVIPixelFormat pixel_format);
96 int channelCountFromPixelFormat(ZVIPixelFormat pixelFormat);
97
98 class SLIDEIO_ZVI_EXPORTS StreamKeeper
99 {
100 public:
101 StreamKeeper(ole::compound_document& doc, const std::string& path);
102 operator ole::basic_stream& () {
103 return m_StreamPos->stream();
104 }
105 ole::basic_stream* operator ->() {
106 return &(m_StreamPos->stream());
107 }
108 private:
109 std::vector<ole::stream_path>::iterator m_StreamPos;
110 };
111 }
112}
113#if defined(_MSC_VER)
114#pragma warning( pop )
115#endif
Definition: exceptions.hpp:15