Line data Source code
1 : /******************************************************************************
2 : *
3 : * Project: GDAL
4 : * Purpose: Zarr driver
5 : * Author: Even Rouault <even dot rouault at spatialys.com>
6 : *
7 : ******************************************************************************
8 : * Copyright (c) 2021, Even Rouault <even dot rouault at spatialys.com>
9 : *
10 : * SPDX-License-Identifier: MIT
11 : ****************************************************************************/
12 :
13 : #ifndef ZARR_V3_CODEC_H
14 : #define ZARR_V3_CODEC_H
15 :
16 : #include "zarr.h"
17 :
18 : struct VSIVirtualHandle;
19 :
20 : /************************************************************************/
21 : /* ZarrArrayMetadata */
22 : /************************************************************************/
23 :
24 : /** Array-related metadata needed for the good working of Zarr V3 codecs */
25 : struct ZarrArrayMetadata
26 : {
27 : /** Data type of the array */
28 : DtypeElt oElt{};
29 :
30 : /** Shape of a block/chunk */
31 : std::vector<size_t> anBlockSizes{};
32 :
33 : /** No data value of the array. Empty or abyNoData.size() == oElt.nNativeSize */
34 : std::vector<GByte> abyNoData{};
35 : };
36 :
37 : /************************************************************************/
38 : /* ZarrV3Codec */
39 : /************************************************************************/
40 :
41 : /** Abstract class for a Zarr V3 codec */
42 4905 : class ZarrV3Codec CPL_NON_FINAL
43 : {
44 : protected:
45 : const std::string m_osName;
46 : CPLJSONObject m_oConfiguration{};
47 : ZarrArrayMetadata m_oInputArrayMetadata{};
48 :
49 : ZarrV3Codec(const std::string &osName);
50 :
51 : public:
52 : virtual ~ZarrV3Codec();
53 :
54 : enum class IOType
55 : {
56 : BYTES,
57 : ARRAY
58 : };
59 :
60 : virtual IOType GetInputType() const = 0;
61 : virtual IOType GetOutputType() const = 0;
62 :
63 : virtual bool InitFromConfiguration(
64 : const std::string &osArrayName, const CPLJSONObject &configuration,
65 : const ZarrArrayMetadata &oInputArrayMetadata,
66 : ZarrArrayMetadata &oOutputArrayMetadata, bool bEmitWarnings) = 0;
67 :
68 : virtual std::unique_ptr<ZarrV3Codec> Clone() const = 0;
69 :
70 2180 : virtual bool IsNoOp() const
71 : {
72 2180 : return false;
73 : }
74 :
75 : virtual bool Encode(const ZarrByteVectorQuickResize &abySrc,
76 : ZarrByteVectorQuickResize &abyDst) const = 0;
77 : virtual bool Decode(const ZarrByteVectorQuickResize &abySrc,
78 : ZarrByteVectorQuickResize &abyDst) const = 0;
79 :
80 : /** Partial decoding.
81 : * anStartIdx[i]: coordinate in pixel, within the array of an outer chunk,
82 : * that is < m_oInputArrayMetadata.anBlockSizes[i]
83 : * anCount[i]: number of pixels to extract <= m_oInputArrayMetadata.anBlockSizes[i]
84 : */
85 : virtual bool DecodePartial(VSIVirtualHandle *poFile,
86 : const ZarrByteVectorQuickResize &abySrc,
87 : ZarrByteVectorQuickResize &abyDst,
88 : std::vector<size_t> &anStartIdx,
89 : std::vector<size_t> &anCount);
90 :
91 12773 : const std::string &GetName() const
92 : {
93 12773 : return m_osName;
94 : }
95 :
96 : const CPLJSONObject &GetConfiguration() const
97 : {
98 : return m_oConfiguration;
99 : }
100 :
101 : virtual std::vector<size_t>
102 292 : GetInnerMostBlockSize(const std::vector<size_t> &input) const
103 : {
104 292 : return input;
105 : }
106 :
107 1028 : virtual void ChangeArrayShapeForward(std::vector<size_t> &anStartIdx,
108 : std::vector<size_t> &anCount)
109 : {
110 : (void)anStartIdx;
111 : (void)anCount;
112 1028 : }
113 : };
114 :
115 : /************************************************************************/
116 : /* ZarrV3CodecAbstractCompressor */
117 : /************************************************************************/
118 :
119 : class ZarrV3CodecAbstractCompressor CPL_NON_FINAL : public ZarrV3Codec
120 : {
121 : protected:
122 : CPLStringList m_aosCompressorOptions{};
123 : const CPLCompressor *m_pDecompressor = nullptr;
124 : const CPLCompressor *m_pCompressor = nullptr;
125 :
126 : explicit ZarrV3CodecAbstractCompressor(const std::string &osName);
127 :
128 : ZarrV3CodecAbstractCompressor(const ZarrV3CodecAbstractCompressor &) =
129 : delete;
130 : ZarrV3CodecAbstractCompressor &
131 : operator=(const ZarrV3CodecAbstractCompressor &) = delete;
132 :
133 : public:
134 636 : IOType GetInputType() const override
135 : {
136 636 : return IOType::BYTES;
137 : }
138 :
139 635 : IOType GetOutputType() const override
140 : {
141 635 : return IOType::BYTES;
142 : }
143 :
144 : bool Encode(const ZarrByteVectorQuickResize &abySrc,
145 : ZarrByteVectorQuickResize &abyDst) const override;
146 : bool Decode(const ZarrByteVectorQuickResize &abySrc,
147 : ZarrByteVectorQuickResize &abyDst) const override;
148 : };
149 :
150 : /************************************************************************/
151 : /* ZarrV3CodecGZip */
152 : /************************************************************************/
153 :
154 : // Implements https://zarr-specs.readthedocs.io/en/latest/v3/codecs/gzip/v1.0.html
155 : class ZarrV3CodecGZip final : public ZarrV3CodecAbstractCompressor
156 : {
157 : public:
158 : static constexpr const char *NAME = "gzip";
159 :
160 : ZarrV3CodecGZip();
161 :
162 : static CPLJSONObject GetConfiguration(int nLevel);
163 :
164 : bool InitFromConfiguration(const std::string &osArrayName,
165 : const CPLJSONObject &configuration,
166 : const ZarrArrayMetadata &oInputArrayMetadata,
167 : ZarrArrayMetadata &oOutputArrayMetadata,
168 : bool bEmitWarnings) override;
169 :
170 : std::unique_ptr<ZarrV3Codec> Clone() const override;
171 : };
172 :
173 : /************************************************************************/
174 : /* ZarrV3CodecNumcodecsZlib */
175 : /************************************************************************/
176 :
177 : // numcodecs zlib compressor, Zarr v3 name "numcodecs.zlib"
178 : class ZarrV3CodecNumcodecsZlib final : public ZarrV3CodecAbstractCompressor
179 : {
180 : public:
181 : static constexpr const char *NAME = "numcodecs.zlib";
182 :
183 : ZarrV3CodecNumcodecsZlib();
184 :
185 : bool InitFromConfiguration(const std::string &osArrayName,
186 : const CPLJSONObject &configuration,
187 : const ZarrArrayMetadata &oInputArrayMetadata,
188 : ZarrArrayMetadata &oOutputArrayMetadata,
189 : bool bEmitWarnings) override;
190 :
191 : std::unique_ptr<ZarrV3Codec> Clone() const override;
192 : };
193 :
194 : /************************************************************************/
195 : /* ZarrV3CodecNumcodecsShuffle */
196 : /************************************************************************/
197 :
198 : // numcodecs byte shuffle filter, Zarr v3 name "numcodecs.shuffle"
199 : class ZarrV3CodecNumcodecsShuffle final : public ZarrV3CodecAbstractCompressor
200 : {
201 : public:
202 : static constexpr const char *NAME = "numcodecs.shuffle";
203 :
204 : ZarrV3CodecNumcodecsShuffle();
205 :
206 : bool InitFromConfiguration(const std::string &osArrayName,
207 : const CPLJSONObject &configuration,
208 : const ZarrArrayMetadata &oInputArrayMetadata,
209 : ZarrArrayMetadata &oOutputArrayMetadata,
210 : bool bEmitWarnings) override;
211 :
212 : std::unique_ptr<ZarrV3Codec> Clone() const override;
213 : };
214 :
215 : /************************************************************************/
216 : /* ZarrV3CodecBlosc */
217 : /************************************************************************/
218 :
219 : // Implements https://zarr-specs.readthedocs.io/en/latest/v3/codecs/blosc/v1.0.html
220 : class ZarrV3CodecBlosc final : public ZarrV3CodecAbstractCompressor
221 : {
222 : public:
223 : static constexpr const char *NAME = "blosc";
224 :
225 : ZarrV3CodecBlosc();
226 :
227 : static CPLJSONObject GetConfiguration(const char *cname, int clevel,
228 : const char *shuffle, int typesize,
229 : int blocksize);
230 :
231 : bool InitFromConfiguration(const std::string &osArrayName,
232 : const CPLJSONObject &configuration,
233 : const ZarrArrayMetadata &oInputArrayMetadata,
234 : ZarrArrayMetadata &oOutputArrayMetadata,
235 : bool bEmitWarnings) override;
236 :
237 : std::unique_ptr<ZarrV3Codec> Clone() const override;
238 : };
239 :
240 : /************************************************************************/
241 : /* ZarrV3CodecZstd */
242 : /************************************************************************/
243 :
244 : // Implements https://github.com/zarr-developers/zarr-specs/pull/256
245 : class ZarrV3CodecZstd final : public ZarrV3CodecAbstractCompressor
246 : {
247 : public:
248 : static constexpr const char *NAME = "zstd";
249 :
250 : ZarrV3CodecZstd();
251 :
252 : static CPLJSONObject GetConfiguration(int level, bool checksum);
253 :
254 : bool InitFromConfiguration(const std::string &osArrayName,
255 : const CPLJSONObject &configuration,
256 : const ZarrArrayMetadata &oInputArrayMetadata,
257 : ZarrArrayMetadata &oOutputArrayMetadata,
258 : bool bEmitWarnings) override;
259 :
260 : std::unique_ptr<ZarrV3Codec> Clone() const override;
261 : };
262 :
263 : /************************************************************************/
264 : /* ZarrV3CodecBytes */
265 : /************************************************************************/
266 :
267 : // Implements https://zarr-specs.readthedocs.io/en/latest/v3/codecs/bytes/v1.0.html
268 : class ZarrV3CodecBytes final : public ZarrV3Codec
269 : {
270 : bool m_bLittle = true;
271 :
272 : public:
273 : static constexpr const char *NAME = "bytes";
274 :
275 : ZarrV3CodecBytes();
276 :
277 2554 : IOType GetInputType() const override
278 : {
279 2554 : return IOType::ARRAY;
280 : }
281 :
282 2555 : IOType GetOutputType() const override
283 : {
284 2555 : return IOType::BYTES;
285 : }
286 :
287 : static CPLJSONObject GetConfiguration(bool bLittle);
288 :
289 : bool InitFromConfiguration(const std::string &osArrayName,
290 : const CPLJSONObject &configuration,
291 : const ZarrArrayMetadata &oInputArrayMetadata,
292 : ZarrArrayMetadata &oOutputArrayMetadata,
293 : bool bEmitWarnings) override;
294 :
295 1 : bool IsLittle() const
296 : {
297 1 : return m_bLittle;
298 : }
299 :
300 2608 : bool IsNoOp() const override
301 : {
302 : // Byte-oriented string types have no endianness concept
303 2608 : if (m_oInputArrayMetadata.oElt.nativeType ==
304 : DtypeElt::NativeType::STRING_ASCII)
305 2 : return true;
306 : if constexpr (CPL_IS_LSB)
307 2606 : return m_oInputArrayMetadata.oElt.nativeSize == 1 || m_bLittle;
308 : else
309 : return m_oInputArrayMetadata.oElt.nativeSize == 1 || !m_bLittle;
310 : }
311 :
312 : std::unique_ptr<ZarrV3Codec> Clone() const override;
313 :
314 : bool Encode(const ZarrByteVectorQuickResize &abySrc,
315 : ZarrByteVectorQuickResize &abyDst) const override;
316 : bool Decode(const ZarrByteVectorQuickResize &abySrc,
317 : ZarrByteVectorQuickResize &abyDst) const override;
318 : };
319 :
320 : /************************************************************************/
321 : /* ZarrV3CodecVLenUTF8 */
322 : /************************************************************************/
323 :
324 : /** Implements the vlen-utf8 array-to-bytes codec for variable-length
325 : * UTF-8 strings (zarr-extensions).
326 : *
327 : * Binary format (little-endian):
328 : * [u32 item_count] [u32 len_0][bytes_0] [u32 len_1][bytes_1] ...
329 : *
330 : * Decode produces a flat buffer of nElements * nativeSize bytes where
331 : * each slot is a null-padded string. Read-only for now.
332 : */
333 : class ZarrV3CodecVLenUTF8 final : public ZarrV3Codec
334 : {
335 : public:
336 : static constexpr const char *NAME = "vlen-utf8";
337 :
338 : ZarrV3CodecVLenUTF8();
339 :
340 14 : IOType GetInputType() const override
341 : {
342 14 : return IOType::ARRAY;
343 : }
344 :
345 14 : IOType GetOutputType() const override
346 : {
347 14 : return IOType::BYTES;
348 : }
349 :
350 : bool InitFromConfiguration(const std::string &osArrayName,
351 : const CPLJSONObject &configuration,
352 : const ZarrArrayMetadata &oInputArrayMetadata,
353 : ZarrArrayMetadata &oOutputArrayMetadata,
354 : bool bEmitWarnings) override;
355 :
356 : std::unique_ptr<ZarrV3Codec> Clone() const override;
357 :
358 : bool Encode(const ZarrByteVectorQuickResize &abySrc,
359 : ZarrByteVectorQuickResize &abyDst) const override;
360 : bool Decode(const ZarrByteVectorQuickResize &abySrc,
361 : ZarrByteVectorQuickResize &abyDst) const override;
362 : };
363 :
364 : /************************************************************************/
365 : /* ZarrV3CodecTranspose */
366 : /************************************************************************/
367 :
368 : // Implements https://zarr-specs.readthedocs.io/en/latest/v3/codecs/transpose/v1.0.html
369 : class ZarrV3CodecTranspose final : public ZarrV3Codec
370 : {
371 : // m_anOrder is such that dest_shape[i] = source_shape[m_anOrder[i]]
372 : // where source_shape[] is the size of the array before the Encode() operation
373 : // and dest_shape[] its size after.
374 : // m_anOrder[] describes a bijection of [0,N-1] to [0,N-1]
375 : std::vector<int> m_anOrder{};
376 :
377 : // m_anReverseOrder is such that m_anReverseOrder[m_anOrder[i]] = i
378 : std::vector<int> m_anReverseOrder{};
379 :
380 : bool Transpose(const ZarrByteVectorQuickResize &abySrc,
381 : ZarrByteVectorQuickResize &abyDst, bool bEncodeDirection,
382 : const std::vector<size_t> &anForwardBlockSizes) const;
383 :
384 : public:
385 : static constexpr const char *NAME = "transpose";
386 :
387 : ZarrV3CodecTranspose();
388 :
389 83 : IOType GetInputType() const override
390 : {
391 83 : return IOType::ARRAY;
392 : }
393 :
394 83 : IOType GetOutputType() const override
395 : {
396 83 : return IOType::ARRAY;
397 : }
398 :
399 : static CPLJSONObject GetConfiguration(const std::vector<int> &anOrder);
400 :
401 : bool InitFromConfiguration(const std::string &osArrayName,
402 : const CPLJSONObject &configuration,
403 : const ZarrArrayMetadata &oInputArrayMetadata,
404 : ZarrArrayMetadata &oOutputArrayMetadata,
405 : bool bEmitWarnings) override;
406 :
407 1 : const std::vector<int> &GetOrder() const
408 : {
409 1 : return m_anOrder;
410 : }
411 :
412 : bool IsNoOp() const override;
413 :
414 : std::unique_ptr<ZarrV3Codec> Clone() const override;
415 :
416 : bool Encode(const ZarrByteVectorQuickResize &abySrc,
417 : ZarrByteVectorQuickResize &abyDst) const override;
418 : bool Decode(const ZarrByteVectorQuickResize &abySrc,
419 : ZarrByteVectorQuickResize &abyDst) const override;
420 :
421 : bool DecodePartial(VSIVirtualHandle *poFile,
422 : const ZarrByteVectorQuickResize &abySrc,
423 : ZarrByteVectorQuickResize &abyDst,
424 : std::vector<size_t> &anStartIdx,
425 : std::vector<size_t> &anCount) override;
426 :
427 : std::vector<size_t>
428 : GetInnerMostBlockSize(const std::vector<size_t> &input) const override;
429 :
430 : template <class T>
431 50 : inline void Reorder1DForward(std::vector<T> &vector) const
432 : {
433 100 : std::vector<T> res;
434 150 : for (int idx : m_anOrder)
435 100 : res.push_back(vector[idx]);
436 50 : vector = std::move(res);
437 50 : }
438 :
439 : template <class T>
440 50 : inline void Reorder1DInverse(std::vector<T> &vector) const
441 : {
442 100 : std::vector<T> res;
443 150 : for (int idx : m_anReverseOrder)
444 100 : res.push_back(vector[idx]);
445 50 : vector = std::move(res);
446 50 : }
447 :
448 25 : void ChangeArrayShapeForward(std::vector<size_t> &anStartIdx,
449 : std::vector<size_t> &anCount) override
450 : {
451 25 : Reorder1DForward(anStartIdx);
452 25 : Reorder1DForward(anCount);
453 25 : }
454 : };
455 :
456 : /************************************************************************/
457 : /* ZarrV3CodecCRC32C */
458 : /************************************************************************/
459 :
460 : // Implements https://zarr-specs.readthedocs.io/en/latest/v3/codecs/crc32c/index.html
461 : class ZarrV3CodecCRC32C final : public ZarrV3Codec
462 : {
463 : bool m_bCheckCRC = true;
464 :
465 : public:
466 : static constexpr const char *NAME = "crc32c";
467 :
468 : ZarrV3CodecCRC32C();
469 :
470 835 : IOType GetInputType() const override
471 : {
472 835 : return IOType::BYTES;
473 : }
474 :
475 835 : IOType GetOutputType() const override
476 : {
477 835 : return IOType::BYTES;
478 : }
479 :
480 : bool InitFromConfiguration(const std::string &osArrayName,
481 : const CPLJSONObject &configuration,
482 : const ZarrArrayMetadata &oInputArrayMetadata,
483 : ZarrArrayMetadata &oOutputArrayMetadata,
484 : bool bEmitWarnings) override;
485 :
486 : std::unique_ptr<ZarrV3Codec> Clone() const override;
487 :
488 : bool Encode(const ZarrByteVectorQuickResize &abySrc,
489 : ZarrByteVectorQuickResize &abyDst) const override;
490 : bool Decode(const ZarrByteVectorQuickResize &abySrc,
491 : ZarrByteVectorQuickResize &abyDst) const override;
492 : };
493 :
494 : /************************************************************************/
495 : /* ZarrV3CodecShardingIndexed */
496 : /************************************************************************/
497 :
498 : class ZarrV3CodecSequence;
499 :
500 : // https://zarr-specs.readthedocs.io/en/latest/v3/codecs/sharding-indexed/index.html
501 : class ZarrV3CodecShardingIndexed final : public ZarrV3Codec
502 : {
503 : std::unique_ptr<ZarrV3CodecSequence> m_poCodecSequence{};
504 : std::unique_ptr<ZarrV3CodecSequence> m_poIndexCodecSequence{};
505 : bool m_bIndexLocationAtEnd = true;
506 : bool m_bIndexHasCRC32 = false;
507 : std::vector<size_t> m_anInnerBlockSize{};
508 :
509 : struct Location
510 : {
511 : uint64_t nOffset;
512 : uint64_t nSize;
513 : };
514 :
515 : public:
516 : static constexpr const char *NAME = "sharding_indexed";
517 :
518 : ZarrV3CodecShardingIndexed();
519 :
520 714 : IOType GetInputType() const override
521 : {
522 714 : return IOType::ARRAY;
523 : }
524 :
525 696 : IOType GetOutputType() const override
526 : {
527 696 : return IOType::BYTES;
528 : }
529 :
530 : bool InitFromConfiguration(const std::string &osArrayName,
531 : const CPLJSONObject &configuration,
532 : const ZarrArrayMetadata &oInputArrayMetadata,
533 : ZarrArrayMetadata &oOutputArrayMetadata,
534 : bool bEmitWarnings) override;
535 :
536 : std::unique_ptr<ZarrV3Codec> Clone() const override;
537 :
538 : bool Encode(const ZarrByteVectorQuickResize &abySrc,
539 : ZarrByteVectorQuickResize &abyDst) const override;
540 : bool Decode(const ZarrByteVectorQuickResize &abySrc,
541 : ZarrByteVectorQuickResize &abyDst) const override;
542 :
543 : bool DecodePartial(VSIVirtualHandle *poFile,
544 : const ZarrByteVectorQuickResize &abySrc,
545 : ZarrByteVectorQuickResize &abyDst,
546 : std::vector<size_t> &anStartIdx,
547 : std::vector<size_t> &anCount) override;
548 :
549 : /** Batch-read multiple inner chunks from the same shard via two
550 : * ReadMultiRange() passes (index entries, then data), then decode.
551 : * pszFilename is used as a cache key for the shard index; pass nullptr
552 : * to bypass the cache.
553 : */
554 : bool BatchDecodePartial(
555 : VSIVirtualHandle *poFile, const char *pszFilename,
556 : const std::vector<std::pair<std::vector<size_t>, std::vector<size_t>>>
557 : &anRequests,
558 : std::vector<ZarrByteVectorQuickResize> &aResults);
559 :
560 : std::vector<size_t>
561 : GetInnerMostBlockSize(const std::vector<size_t> &input) const override;
562 : };
563 :
564 : /************************************************************************/
565 : /* ZarrV3CodecSequence */
566 : /************************************************************************/
567 :
568 : class ZarrV3CodecSequence
569 : {
570 : const ZarrArrayMetadata m_oInputArrayMetadata;
571 : std::vector<std::unique_ptr<ZarrV3Codec>> m_apoCodecs{};
572 : CPLJSONObject m_oCodecArray{};
573 : ZarrByteVectorQuickResize m_abyTmp{};
574 : bool m_bPartialDecodingPossible = false;
575 :
576 : bool AllocateBuffer(ZarrByteVectorQuickResize &abyBuffer, size_t nEltCount);
577 :
578 : public:
579 3385 : explicit ZarrV3CodecSequence(const ZarrArrayMetadata &oInputArrayMetadata)
580 3385 : : m_oInputArrayMetadata(oInputArrayMetadata)
581 : {
582 3385 : }
583 :
584 : // This method is not thread safe due to cloning a JSON object
585 : std::unique_ptr<ZarrV3CodecSequence> Clone() const;
586 :
587 : bool InitFromJson(const std::string &osArrayName,
588 : const CPLJSONObject &oCodecs,
589 : ZarrArrayMetadata &oOutputArrayMetadata);
590 :
591 487 : const CPLJSONObject &GetJSon() const
592 : {
593 487 : return m_oCodecArray;
594 : }
595 :
596 10809 : const std::vector<std::unique_ptr<ZarrV3Codec>> &GetCodecs() const
597 : {
598 10809 : return m_apoCodecs;
599 : }
600 :
601 64175 : bool SupportsPartialDecoding() const
602 : {
603 64175 : return m_bPartialDecodingPossible;
604 : }
605 :
606 : bool Encode(ZarrByteVectorQuickResize &abyBuffer);
607 : bool Decode(ZarrByteVectorQuickResize &abyBuffer);
608 :
609 : /** Partial decoding.
610 : * anStartIdx[i]: coordinate in pixel, within the array of an outer chunk,
611 : * that is < m_oInputArrayMetadata.anBlockSizes[i]
612 : * anCount[i]: number of pixels to extract <= m_oInputArrayMetadata.anBlockSizes[i]
613 : */
614 : bool DecodePartial(VSIVirtualHandle *poFile,
615 : ZarrByteVectorQuickResize &abyBuffer,
616 : const std::vector<size_t> &anStartIdx,
617 : const std::vector<size_t> &anCount);
618 :
619 : /** Batch-read multiple inner chunks via ReadMultiRange().
620 : * Delegates to the sharding codec if present, otherwise falls back
621 : * to sequential DecodePartial() calls.
622 : * pszFilename is forwarded to the sharding codec for index caching.
623 : */
624 : bool BatchDecodePartial(
625 : VSIVirtualHandle *poFile, const char *pszFilename,
626 : const std::vector<std::pair<std::vector<size_t>, std::vector<size_t>>>
627 : &anRequests,
628 : std::vector<ZarrByteVectorQuickResize> &aResults);
629 :
630 : std::vector<size_t>
631 : GetInnerMostBlockSize(const std::vector<size_t> &anOuterBlockSize) const;
632 : };
633 :
634 : /************************************************************************/
635 : /* ZarrV3CodecPcodec */
636 : /************************************************************************/
637 :
638 : /** Non-standard "pcodec" (a.k.a. "pco") from https://github.com/pcodec/pcodec
639 : *
640 : * Also see https://numcodecs.readthedocs.io/en/stable/compression/pcodec.html
641 : */
642 : class ZarrV3CodecPcodec /* final */ : public ZarrV3Codec
643 : {
644 : public:
645 : static constexpr const char *NAME = "numcodecs.pcodec";
646 :
647 : explicit ZarrV3CodecPcodec();
648 : ~ZarrV3CodecPcodec() override;
649 :
650 : IOType GetInputType() const override
651 : {
652 : return IOType::ARRAY;
653 : }
654 :
655 : IOType GetOutputType() const override
656 : {
657 : return IOType::BYTES;
658 : }
659 :
660 : bool InitFromConfiguration(const std::string &osArrayName,
661 : const CPLJSONObject &configuration,
662 : const ZarrArrayMetadata &oInputArrayMetadata,
663 : ZarrArrayMetadata &oOutputArrayMetadata,
664 : bool bEmitWarnings) override;
665 :
666 : std::unique_ptr<ZarrV3Codec> Clone() const override;
667 :
668 : bool Decode(const ZarrByteVectorQuickResize &abySrc,
669 : ZarrByteVectorQuickResize &abyDst) const override;
670 :
671 : bool Encode(const ZarrByteVectorQuickResize &abySrc,
672 : ZarrByteVectorQuickResize &abyDst) const override;
673 : };
674 :
675 : #endif
|