UNPKG

9.15 kBtext/x-cView Raw
1// Copyright 2013 Lovell Fuller and others.
2// SPDX-License-Identifier: Apache-2.0
3
4#ifndef SRC_PIPELINE_H_
5#define SRC_PIPELINE_H_
6
7#include <memory>
8#include <string>
9#include <vector>
10#include <unordered_map>
11
12#include <napi.h>
13#include <vips/vips8>
14
15#include "./common.h"
16
17Napi::Value pipeline(const Napi::CallbackInfo& info);
18
19struct Composite {
20 sharp::InputDescriptor *input;
21 VipsBlendMode mode;
22 int gravity;
23 int left;
24 int top;
25 bool hasOffset;
26 bool tile;
27 bool premultiplied;
28
29 Composite():
30 input(nullptr),
31 mode(VIPS_BLEND_MODE_OVER),
32 gravity(0),
33 left(0),
34 top(0),
35 hasOffset(false),
36 tile(false),
37 premultiplied(false) {}
38};
39
40struct PipelineBaton {
41 sharp::InputDescriptor *input;
42 std::string formatOut;
43 std::string fileOut;
44 void *bufferOut;
45 size_t bufferOutLength;
46 std::vector<Composite *> composite;
47 std::vector<sharp::InputDescriptor *> joinChannelIn;
48 int topOffsetPre;
49 int leftOffsetPre;
50 int widthPre;
51 int heightPre;
52 int topOffsetPost;
53 int leftOffsetPost;
54 int widthPost;
55 int heightPost;
56 int width;
57 int height;
58 int channels;
59 VipsKernel kernel;
60 sharp::Canvas canvas;
61 int position;
62 std::vector<double> resizeBackground;
63 bool hasCropOffset;
64 int cropOffsetLeft;
65 int cropOffsetTop;
66 bool hasAttentionCenter;
67 int attentionX;
68 int attentionY;
69 bool premultiplied;
70 bool tileCentre;
71 bool fastShrinkOnLoad;
72 double tintA;
73 double tintB;
74 bool flatten;
75 std::vector<double> flattenBackground;
76 bool unflatten;
77 bool negate;
78 bool negateAlpha;
79 double blurSigma;
80 double brightness;
81 double saturation;
82 int hue;
83 double lightness;
84 int medianSize;
85 double sharpenSigma;
86 double sharpenM1;
87 double sharpenM2;
88 double sharpenX1;
89 double sharpenY2;
90 double sharpenY3;
91 int threshold;
92 bool thresholdGrayscale;
93 std::vector<double> trimBackground;
94 double trimThreshold;
95 int trimOffsetLeft;
96 int trimOffsetTop;
97 std::vector<double> linearA;
98 std::vector<double> linearB;
99 double gamma;
100 double gammaOut;
101 bool greyscale;
102 bool normalise;
103 int normaliseLower;
104 int normaliseUpper;
105 int claheWidth;
106 int claheHeight;
107 int claheMaxSlope;
108 bool useExifOrientation;
109 int angle;
110 double rotationAngle;
111 std::vector<double> rotationBackground;
112 bool rotateBeforePreExtract;
113 bool flip;
114 bool flop;
115 int extendTop;
116 int extendBottom;
117 int extendLeft;
118 int extendRight;
119 std::vector<double> extendBackground;
120 VipsExtend extendWith;
121 bool withoutEnlargement;
122 bool withoutReduction;
123 std::vector<double> affineMatrix;
124 std::vector<double> affineBackground;
125 double affineIdx;
126 double affineIdy;
127 double affineOdx;
128 double affineOdy;
129 std::string affineInterpolator;
130 int jpegQuality;
131 bool jpegProgressive;
132 std::string jpegChromaSubsampling;
133 bool jpegTrellisQuantisation;
134 int jpegQuantisationTable;
135 bool jpegOvershootDeringing;
136 bool jpegOptimiseScans;
137 bool jpegOptimiseCoding;
138 bool pngProgressive;
139 int pngCompressionLevel;
140 bool pngAdaptiveFiltering;
141 bool pngPalette;
142 int pngQuality;
143 int pngEffort;
144 int pngBitdepth;
145 double pngDither;
146 int jp2Quality;
147 bool jp2Lossless;
148 int jp2TileHeight;
149 int jp2TileWidth;
150 std::string jp2ChromaSubsampling;
151 int webpQuality;
152 int webpAlphaQuality;
153 bool webpNearLossless;
154 bool webpLossless;
155 bool webpSmartSubsample;
156 int webpEffort;
157 bool webpMinSize;
158 bool webpMixed;
159 int gifBitdepth;
160 int gifEffort;
161 double gifDither;
162 double gifInterFrameMaxError;
163 double gifInterPaletteMaxError;
164 bool gifReuse;
165 bool gifProgressive;
166 int tiffQuality;
167 VipsForeignTiffCompression tiffCompression;
168 VipsForeignTiffPredictor tiffPredictor;
169 bool tiffPyramid;
170 int tiffBitdepth;
171 bool tiffTile;
172 int tiffTileHeight;
173 int tiffTileWidth;
174 double tiffXres;
175 double tiffYres;
176 VipsForeignTiffResunit tiffResolutionUnit;
177 int heifQuality;
178 VipsForeignHeifCompression heifCompression;
179 int heifEffort;
180 std::string heifChromaSubsampling;
181 bool heifLossless;
182 double jxlDistance;
183 int jxlDecodingTier;
184 int jxlEffort;
185 bool jxlLossless;
186 VipsBandFormat rawDepth;
187 std::string err;
188 bool withMetadata;
189 int withMetadataOrientation;
190 double withMetadataDensity;
191 std::string withMetadataIcc;
192 std::unordered_map<std::string, std::string> withMetadataStrs;
193 int timeoutSeconds;
194 std::unique_ptr<double[]> convKernel;
195 int convKernelWidth;
196 int convKernelHeight;
197 double convKernelScale;
198 double convKernelOffset;
199 sharp::InputDescriptor *boolean;
200 VipsOperationBoolean booleanOp;
201 VipsOperationBoolean bandBoolOp;
202 int extractChannel;
203 bool removeAlpha;
204 double ensureAlpha;
205 VipsInterpretation colourspaceInput;
206 VipsInterpretation colourspace;
207 std::vector<int> delay;
208 int loop;
209 int tileSize;
210 int tileOverlap;
211 VipsForeignDzContainer tileContainer;
212 VipsForeignDzLayout tileLayout;
213 std::string tileFormat;
214 int tileAngle;
215 std::vector<double> tileBackground;
216 int tileSkipBlanks;
217 VipsForeignDzDepth tileDepth;
218 std::string tileId;
219 std::string tileBasename;
220 std::unique_ptr<double[]> recombMatrix;
221
222 PipelineBaton():
223 input(nullptr),
224 bufferOutLength(0),
225 topOffsetPre(-1),
226 topOffsetPost(-1),
227 channels(0),
228 kernel(VIPS_KERNEL_LANCZOS3),
229 canvas(sharp::Canvas::CROP),
230 position(0),
231 resizeBackground{ 0.0, 0.0, 0.0, 255.0 },
232 hasCropOffset(false),
233 cropOffsetLeft(0),
234 cropOffsetTop(0),
235 hasAttentionCenter(false),
236 attentionX(0),
237 attentionY(0),
238 premultiplied(false),
239 tintA(128.0),
240 tintB(128.0),
241 flatten(false),
242 flattenBackground{ 0.0, 0.0, 0.0 },
243 unflatten(false),
244 negate(false),
245 negateAlpha(true),
246 blurSigma(0.0),
247 brightness(1.0),
248 saturation(1.0),
249 hue(0),
250 lightness(0),
251 medianSize(0),
252 sharpenSigma(0.0),
253 sharpenM1(1.0),
254 sharpenM2(2.0),
255 sharpenX1(2.0),
256 sharpenY2(10.0),
257 sharpenY3(20.0),
258 threshold(0),
259 thresholdGrayscale(true),
260 trimBackground{},
261 trimThreshold(0.0),
262 trimOffsetLeft(0),
263 trimOffsetTop(0),
264 linearA{},
265 linearB{},
266 gamma(0.0),
267 greyscale(false),
268 normalise(false),
269 normaliseLower(1),
270 normaliseUpper(99),
271 claheWidth(0),
272 claheHeight(0),
273 claheMaxSlope(3),
274 useExifOrientation(false),
275 angle(0),
276 rotationAngle(0.0),
277 rotationBackground{ 0.0, 0.0, 0.0, 255.0 },
278 flip(false),
279 flop(false),
280 extendTop(0),
281 extendBottom(0),
282 extendLeft(0),
283 extendRight(0),
284 extendBackground{ 0.0, 0.0, 0.0, 255.0 },
285 extendWith(VIPS_EXTEND_BACKGROUND),
286 withoutEnlargement(false),
287 withoutReduction(false),
288 affineMatrix{ 1.0, 0.0, 0.0, 1.0 },
289 affineBackground{ 0.0, 0.0, 0.0, 255.0 },
290 affineIdx(0),
291 affineIdy(0),
292 affineOdx(0),
293 affineOdy(0),
294 affineInterpolator("bicubic"),
295 jpegQuality(80),
296 jpegProgressive(false),
297 jpegChromaSubsampling("4:2:0"),
298 jpegTrellisQuantisation(false),
299 jpegQuantisationTable(0),
300 jpegOvershootDeringing(false),
301 jpegOptimiseScans(false),
302 jpegOptimiseCoding(true),
303 pngProgressive(false),
304 pngCompressionLevel(6),
305 pngAdaptiveFiltering(false),
306 pngPalette(false),
307 pngQuality(100),
308 pngEffort(7),
309 pngBitdepth(8),
310 pngDither(1.0),
311 jp2Quality(80),
312 jp2Lossless(false),
313 jp2TileHeight(512),
314 jp2TileWidth(512),
315 jp2ChromaSubsampling("4:4:4"),
316 webpQuality(80),
317 webpAlphaQuality(100),
318 webpNearLossless(false),
319 webpLossless(false),
320 webpSmartSubsample(false),
321 webpEffort(4),
322 webpMinSize(false),
323 webpMixed(false),
324 gifBitdepth(8),
325 gifEffort(7),
326 gifDither(1.0),
327 gifInterFrameMaxError(0.0),
328 gifInterPaletteMaxError(3.0),
329 gifReuse(true),
330 gifProgressive(false),
331 tiffQuality(80),
332 tiffCompression(VIPS_FOREIGN_TIFF_COMPRESSION_JPEG),
333 tiffPredictor(VIPS_FOREIGN_TIFF_PREDICTOR_HORIZONTAL),
334 tiffPyramid(false),
335 tiffBitdepth(8),
336 tiffTile(false),
337 tiffTileHeight(256),
338 tiffTileWidth(256),
339 tiffXres(1.0),
340 tiffYres(1.0),
341 tiffResolutionUnit(VIPS_FOREIGN_TIFF_RESUNIT_INCH),
342 heifQuality(50),
343 heifCompression(VIPS_FOREIGN_HEIF_COMPRESSION_AV1),
344 heifEffort(4),
345 heifChromaSubsampling("4:4:4"),
346 heifLossless(false),
347 jxlDistance(1.0),
348 jxlDecodingTier(0),
349 jxlEffort(7),
350 jxlLossless(false),
351 rawDepth(VIPS_FORMAT_UCHAR),
352 withMetadata(false),
353 withMetadataOrientation(-1),
354 withMetadataDensity(0.0),
355 timeoutSeconds(0),
356 convKernelWidth(0),
357 convKernelHeight(0),
358 convKernelScale(0.0),
359 convKernelOffset(0.0),
360 boolean(nullptr),
361 booleanOp(VIPS_OPERATION_BOOLEAN_LAST),
362 bandBoolOp(VIPS_OPERATION_BOOLEAN_LAST),
363 extractChannel(-1),
364 removeAlpha(false),
365 ensureAlpha(-1.0),
366 colourspaceInput(VIPS_INTERPRETATION_LAST),
367 colourspace(VIPS_INTERPRETATION_LAST),
368 loop(-1),
369 tileSize(256),
370 tileOverlap(0),
371 tileContainer(VIPS_FOREIGN_DZ_CONTAINER_FS),
372 tileLayout(VIPS_FOREIGN_DZ_LAYOUT_DZ),
373 tileAngle(0),
374 tileBackground{ 255.0, 255.0, 255.0, 255.0 },
375 tileSkipBlanks(-1),
376 tileDepth(VIPS_FOREIGN_DZ_DEPTH_LAST) {}
377};
378
379#endif // SRC_PIPELINE_H_