Mercurial > hg > orthanc-wsi
annotate Framework/Inputs/PlainTiff.cpp @ 298:fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 18 Jul 2023 08:19:16 +0200 |
parents | |
children | 7020852a8fa9 |
rev | line source |
---|---|
298
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * modify it under the terms of the GNU Affero General Public License |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * the License, or (at your option) any later version. |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, but |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * Affero General Public License for more details. |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * You should have received a copy of the GNU Affero General Public License |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 **/ |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 #include "PlainTiff.h" |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 #include "../TiffReader.h" |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 #include <Images/Image.h> |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 #include <Images/ImageProcessing.h> |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 #include <Logging.h> |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 #include <OrthancException.h> |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 #include <cassert> |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 #include <string.h> |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 namespace OrthancWSI |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 { |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 PlainTiff::PlainTiff(const std::string& path, |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 unsigned int tileWidth, |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 unsigned int tileHeight, |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 unsigned int paddingAlignement, |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 uint8_t paddingRed, |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 uint8_t paddingGreen, |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 uint8_t paddingBlue) : |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 SingleLevelDecodedPyramid(tileWidth, tileHeight) |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 { |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 TiffReader reader(path); |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 // Look for the largest sub-image |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 bool first = true; |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 unsigned int width = 0; |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 unsigned int height = 0; |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 tdir_t largest = 0; |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 tdir_t pos = 0; |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 do |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 { |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 uint32_t w, h, tw, th; |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 if (TIFFSetDirectory(reader.GetTiff(), pos) && |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 !TIFFGetField(reader.GetTiff(), TIFFTAG_TILEWIDTH, &tw) && // Must not be a tiled image |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 !TIFFGetField(reader.GetTiff(), TIFFTAG_TILELENGTH, &th) && // Must not be a tiled image |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 TIFFGetField(reader.GetTiff(), TIFFTAG_IMAGEWIDTH, &w) && |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 TIFFGetField(reader.GetTiff(), TIFFTAG_IMAGELENGTH, &h) && |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 w > 0 && |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 h > 0) |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 { |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 if (first) |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 { |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 first = false; |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 width = w; |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 height = h; |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 largest = pos; |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 } |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 else if (w > width && |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 h > height) |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 { |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 width = w; |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 height = h; |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 largest = pos; |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 } |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 } |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 pos++; |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 } |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 while (TIFFReadDirectory(reader.GetTiff())); |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 if (first) |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 { |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "This is an empty TIFF image"); |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 } |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 // Back to the largest directory |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 if (!TIFFSetDirectory(reader.GetTiff(), largest)) |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 { |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 throw Orthanc::OrthancException(Orthanc::ErrorCode_CorruptedFile); |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 } |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 ImageCompression compression; |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 Orthanc::PixelFormat pixelFormat; |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 Orthanc::PhotometricInterpretation photometric; |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 if (!reader.GetCurrentDirectoryInformation(compression, pixelFormat, photometric)) |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 { |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 } |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 if (pixelFormat != Orthanc::PixelFormat_RGB24) |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 { |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 } |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 LOG(WARNING) << "Size of the source TIFF image: " << width << "x" << height; |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 const unsigned int paddedWidth = paddingAlignement * CeilingDivision(width, paddingAlignement); |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 const unsigned int paddedHeight = paddingAlignement * CeilingDivision(height, paddingAlignement); |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 assert(paddedWidth >= width && |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 paddedHeight >= height); |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 LOG(WARNING) << "Size of the padded TIFF image: " << paddedWidth << "x" << paddedHeight; |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 decoded_.reset(new Orthanc::Image(pixelFormat, paddedWidth, paddedHeight, false)); |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 Orthanc::ImageProcessing::Set(*decoded_, paddingRed, paddingGreen, paddingBlue, 255); |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 std::string strip; |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 strip.resize(TIFFStripSize(reader.GetTiff())); |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 const size_t stripPitch = width * Orthanc::GetBytesPerPixel(pixelFormat); |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 if (strip.empty() || |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 stripPitch == 0 || |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 strip.size() < stripPitch || |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 strip.size() % stripPitch != 0) |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 { |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 } |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 const size_t stripHeight = (strip.size() / stripPitch); |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 const size_t stripCount = CeilingDivision(height, stripHeight); |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 if (TIFFNumberOfStrips(reader.GetTiff()) != stripCount) |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 { |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 } |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 for (unsigned int i = 0; i < stripCount; i++) |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 { |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 TIFFReadEncodedStrip(reader.GetTiff(), i, &strip[0], static_cast<tsize_t>(-1)); |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 const unsigned int y = i * stripHeight; |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 const uint8_t* p = reinterpret_cast<const uint8_t*>(&strip[0]); |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 uint8_t* q = reinterpret_cast<uint8_t*>(decoded_->GetRow(y)); |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 for (unsigned j = 0; j < stripHeight && y + j < height; j++) |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 { |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 memcpy(q, p, stripPitch); |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 p += stripPitch; |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 q += decoded_->GetPitch(); |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 } |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 } |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 SetImage(*decoded_); |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 } |
fa734a851551
New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 } |