-
Notifications
You must be signed in to change notification settings - Fork 0
/
GfxState.h
1760 lines (1453 loc) · 63.9 KB
/
GfxState.h
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//========================================================================
//
// GfxState.h
//
// Copyright 1996-2003 Glyph & Cog, LLC
//
//========================================================================
//========================================================================
//
// Modified under the Poppler project - http://poppler.freedesktop.org
//
// All changes made under the Poppler project to this file are licensed
// under GPL version 2 or later
//
// Copyright (C) 2005 Kristian Høgsberg <krh@redhat.com>
// Copyright (C) 2006, 2007 Jeff Muizelaar <jeff@infidigm.net>
// Copyright (C) 2006 Carlos Garcia Campos <carlosgc@gnome.org>
// Copyright (C) 2009 Koji Otani <sho@bbr.jp>
// Copyright (C) 2009-2011, 2013, 2016-2022 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2010 Christian Feuersänger <cfeuersaenger@googlemail.com>
// Copyright (C) 2011 Andrea Canciani <ranma42@gmail.com>
// Copyright (C) 2011-2014, 2016, 2020 Thomas Freitag <Thomas.Freitag@alfa.de>
// Copyright (C) 2013 Lu Wang <coolwanglu@gmail.com>
// Copyright (C) 2015, 2017, 2020, 2022 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2017, 2019, 2022 Oliver Sander <oliver.sander@tu-dresden.de>
// Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
// Copyright (C) 2020, 2021 Philipp Knechtges <philipp-dev@knechtges.com>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
//
//========================================================================
#ifndef GFXSTATE_H
#define GFXSTATE_H
#include "poppler-config.h"
#include "poppler_private_export.h"
#include "Object.h"
#include "Function.h"
#include <cassert>
#include <map>
#include <memory>
#include <vector>
class Array;
class Gfx;
class GfxFont;
class PDFRectangle;
class GfxShading;
class OutputDev;
class GfxState;
class GfxResources;
class GfxSeparationColorSpace;
class Matrix
{
public:
double m[6];
void init(double xx, double yx, double xy, double yy, double x0, double y0)
{
m[0] = xx;
m[1] = yx;
m[2] = xy;
m[3] = yy;
m[4] = x0;
m[5] = y0;
}
bool invertTo(Matrix *other) const;
void translate(double tx, double ty);
void scale(double sx, double sy);
void transform(double x, double y, double *tx, double *ty) const;
double determinant() const { return m[0] * m[3] - m[1] * m[2]; }
double norm() const;
};
//------------------------------------------------------------------------
// GfxBlendMode
//------------------------------------------------------------------------
enum GfxBlendMode
{
gfxBlendNormal,
gfxBlendMultiply,
gfxBlendScreen,
gfxBlendOverlay,
gfxBlendDarken,
gfxBlendLighten,
gfxBlendColorDodge,
gfxBlendColorBurn,
gfxBlendHardLight,
gfxBlendSoftLight,
gfxBlendDifference,
gfxBlendExclusion,
gfxBlendHue,
gfxBlendSaturation,
gfxBlendColor,
gfxBlendLuminosity
};
//------------------------------------------------------------------------
// GfxColorComp
//------------------------------------------------------------------------
// 16.16 fixed point color component
typedef int GfxColorComp;
#define gfxColorComp1 0x10000
static inline GfxColorComp dblToCol(double x)
{
return (GfxColorComp)(x * gfxColorComp1);
}
static inline double colToDbl(GfxColorComp x)
{
return (double)x / (double)gfxColorComp1;
}
static inline unsigned char dblToByte(double x)
{
return static_cast<unsigned char>(x * 255.0);
}
static inline double byteToDbl(unsigned char x)
{
return (double)x / (double)255.0;
}
static inline GfxColorComp byteToCol(unsigned char x)
{
// (x / 255) << 16 = (0.0000000100000001... * x) << 16
// = ((x << 8) + (x) + (x >> 8) + ...) << 16
// = (x << 8) + (x) + (x >> 7)
// [for rounding]
return (GfxColorComp)((x << 8) + x + (x >> 7));
}
static inline unsigned char colToByte(GfxColorComp x)
{
// 255 * x + 0.5 = 256 * x - x + 0x8000
return (unsigned char)(((x << 8) - x + 0x8000) >> 16);
}
static inline unsigned short colToShort(GfxColorComp x)
{
return (unsigned short)(x);
}
//------------------------------------------------------------------------
// GfxColor
//------------------------------------------------------------------------
#define gfxColorMaxComps funcMaxOutputs
struct GfxColor
{
GfxColorComp c[gfxColorMaxComps];
};
static inline void clearGfxColor(GfxColor *gfxColor)
{
memset(gfxColor->c, 0, sizeof(GfxColorComp) * gfxColorMaxComps);
}
//------------------------------------------------------------------------
// GfxGray
//------------------------------------------------------------------------
typedef GfxColorComp GfxGray;
//------------------------------------------------------------------------
// GfxRGB
//------------------------------------------------------------------------
struct GfxRGB
{
GfxColorComp r, g, b;
bool operator==(GfxRGB other) const { return r == other.r && g == other.g && b == other.b; }
};
//------------------------------------------------------------------------
// GfxCMYK
//------------------------------------------------------------------------
struct GfxCMYK
{
GfxColorComp c, m, y, k;
};
//------------------------------------------------------------------------
// GfxColorSpace
//------------------------------------------------------------------------
// NB: The nGfxColorSpaceModes constant and the gfxColorSpaceModeNames
// array defined in GfxState.cc must match this enum.
enum GfxColorSpaceMode
{
csDeviceGray,
csCalGray,
csDeviceRGB,
csCalRGB,
csDeviceCMYK,
csLab,
csICCBased,
csIndexed,
csSeparation,
csDeviceN,
csPattern
};
// This shall hold a cmsHPROFILE handle.
// Only use the make_GfxLCMSProfilePtr function to construct this pointer,
// to ensure that the resources are properly released after usage.
typedef std::shared_ptr<void> GfxLCMSProfilePtr;
#ifdef USE_CMS
GfxLCMSProfilePtr POPPLER_PRIVATE_EXPORT make_GfxLCMSProfilePtr(void *profile);
#endif
// wrapper of cmsHTRANSFORM to copy
class GfxColorTransform
{
public:
void doTransform(void *in, void *out, unsigned int size);
// transformA should be a cmsHTRANSFORM
GfxColorTransform(void *transformA, int cmsIntent, unsigned int inputPixelType, unsigned int transformPixelType);
~GfxColorTransform();
GfxColorTransform(const GfxColorTransform &) = delete;
GfxColorTransform &operator=(const GfxColorTransform &) = delete;
int getIntent() const { return cmsIntent; }
int getInputPixelType() const { return inputPixelType; }
int getTransformPixelType() const { return transformPixelType; }
private:
GfxColorTransform() { }
void *transform;
int cmsIntent;
unsigned int inputPixelType;
unsigned int transformPixelType;
};
class POPPLER_PRIVATE_EXPORT GfxColorSpace
{
public:
GfxColorSpace();
virtual ~GfxColorSpace();
GfxColorSpace(const GfxColorSpace &) = delete;
GfxColorSpace &operator=(const GfxColorSpace &other) = delete;
virtual GfxColorSpace *copy() const = 0;
virtual GfxColorSpaceMode getMode() const = 0;
// Construct a color space. Returns nullptr if unsuccessful.
static GfxColorSpace *parse(GfxResources *res, Object *csObj, OutputDev *out, GfxState *state, int recursion = 0);
// Convert to gray, RGB, or CMYK.
virtual void getGray(const GfxColor *color, GfxGray *gray) const = 0;
virtual void getRGB(const GfxColor *color, GfxRGB *rgb) const = 0;
virtual void getCMYK(const GfxColor *color, GfxCMYK *cmyk) const = 0;
virtual void getDeviceN(const GfxColor *color, GfxColor *deviceN) const = 0;
virtual void getGrayLine(unsigned char * /*in*/, unsigned char * /*out*/, int /*length*/) { error(errInternal, -1, "GfxColorSpace::getGrayLine this should not happen"); }
virtual void getRGBLine(unsigned char * /*in*/, unsigned int * /*out*/, int /*length*/) { error(errInternal, -1, "GfxColorSpace::getRGBLine (first variant) this should not happen"); }
virtual void getRGBLine(unsigned char * /*in*/, unsigned char * /*out*/, int /*length*/) { error(errInternal, -1, "GfxColorSpace::getRGBLine (second variant) this should not happen"); }
virtual void getRGBXLine(unsigned char * /*in*/, unsigned char * /*out*/, int /*length*/) { error(errInternal, -1, "GfxColorSpace::getRGBXLine this should not happen"); }
virtual void getCMYKLine(unsigned char * /*in*/, unsigned char * /*out*/, int /*length*/) { error(errInternal, -1, "GfxColorSpace::getCMYKLine this should not happen"); }
virtual void getDeviceNLine(unsigned char * /*in*/, unsigned char * /*out*/, int /*length*/) { error(errInternal, -1, "GfxColorSpace::getDeviceNLine this should not happen"); }
// create mapping for spot colorants
virtual void createMapping(std::vector<GfxSeparationColorSpace *> *separationList, int maxSepComps);
int *getMapping() const { return mapping; }
// Does this ColorSpace support getRGBLine?
virtual bool useGetRGBLine() const { return false; }
// Does this ColorSpace support getGrayLine?
virtual bool useGetGrayLine() const { return false; }
// Does this ColorSpace support getCMYKLine?
virtual bool useGetCMYKLine() const { return false; }
// Does this ColorSpace support getDeviceNLine?
virtual bool useGetDeviceNLine() const { return false; }
// Return the number of color components.
virtual int getNComps() const = 0;
// Get this color space's default color.
virtual void getDefaultColor(GfxColor *color) const = 0;
// Return the default ranges for each component, assuming an image
// with a max pixel value of <maxImgPixel>.
virtual void getDefaultRanges(double *decodeLow, double *decodeRange, int maxImgPixel) const;
// Returns true if painting operations in this color space never
// mark the page (e.g., the "None" colorant).
virtual bool isNonMarking() const { return false; }
// Return the color space's overprint mask.
unsigned int getOverprintMask() const { return overprintMask; }
// Return the number of color space modes
static int getNumColorSpaceModes();
// Return the name of the <idx>th color space mode.
static const char *getColorSpaceModeName(int idx);
protected:
unsigned int overprintMask;
int *mapping;
};
//------------------------------------------------------------------------
// GfxDeviceGrayColorSpace
//------------------------------------------------------------------------
class POPPLER_PRIVATE_EXPORT GfxDeviceGrayColorSpace : public GfxColorSpace
{
public:
GfxDeviceGrayColorSpace();
~GfxDeviceGrayColorSpace() override;
GfxColorSpace *copy() const override;
GfxColorSpaceMode getMode() const override { return csDeviceGray; }
void getGray(const GfxColor *color, GfxGray *gray) const override;
void getRGB(const GfxColor *color, GfxRGB *rgb) const override;
void getCMYK(const GfxColor *color, GfxCMYK *cmyk) const override;
void getDeviceN(const GfxColor *color, GfxColor *deviceN) const override;
void getGrayLine(unsigned char *in, unsigned char *out, int length) override;
void getRGBLine(unsigned char *in, unsigned int *out, int length) override;
void getRGBLine(unsigned char *in, unsigned char *out, int length) override;
void getRGBXLine(unsigned char *in, unsigned char *out, int length) override;
void getCMYKLine(unsigned char *in, unsigned char *out, int length) override;
void getDeviceNLine(unsigned char *in, unsigned char *out, int length) override;
bool useGetRGBLine() const override { return true; }
bool useGetGrayLine() const override { return true; }
bool useGetCMYKLine() const override { return true; }
bool useGetDeviceNLine() const override { return true; }
int getNComps() const override { return 1; }
void getDefaultColor(GfxColor *color) const override;
private:
};
//------------------------------------------------------------------------
// GfxCalGrayColorSpace
//------------------------------------------------------------------------
class GfxCalGrayColorSpace : public GfxColorSpace
{
public:
GfxCalGrayColorSpace();
~GfxCalGrayColorSpace() override;
GfxColorSpace *copy() const override;
GfxColorSpaceMode getMode() const override { return csCalGray; }
// Construct a CalGray color space. Returns nullptr if unsuccessful.
static GfxColorSpace *parse(Array *arr, GfxState *state);
void getGray(const GfxColor *color, GfxGray *gray) const override;
void getRGB(const GfxColor *color, GfxRGB *rgb) const override;
void getCMYK(const GfxColor *color, GfxCMYK *cmyk) const override;
void getDeviceN(const GfxColor *color, GfxColor *deviceN) const override;
int getNComps() const override { return 1; }
void getDefaultColor(GfxColor *color) const override;
// CalGray-specific access.
double getWhiteX() const { return whiteX; }
double getWhiteY() const { return whiteY; }
double getWhiteZ() const { return whiteZ; }
double getBlackX() const { return blackX; }
double getBlackY() const { return blackY; }
double getBlackZ() const { return blackZ; }
double getGamma() const { return gamma; }
private:
double whiteX, whiteY, whiteZ; // white point
double blackX, blackY, blackZ; // black point
double gamma; // gamma value
void getXYZ(const GfxColor *color, double *pX, double *pY, double *pZ) const;
#ifdef USE_CMS
std::shared_ptr<GfxColorTransform> transform;
#endif
};
//------------------------------------------------------------------------
// GfxDeviceRGBColorSpace
//------------------------------------------------------------------------
class POPPLER_PRIVATE_EXPORT GfxDeviceRGBColorSpace : public GfxColorSpace
{
public:
GfxDeviceRGBColorSpace();
~GfxDeviceRGBColorSpace() override;
GfxColorSpace *copy() const override;
GfxColorSpaceMode getMode() const override { return csDeviceRGB; }
void getGray(const GfxColor *color, GfxGray *gray) const override;
void getRGB(const GfxColor *color, GfxRGB *rgb) const override;
void getCMYK(const GfxColor *color, GfxCMYK *cmyk) const override;
void getDeviceN(const GfxColor *color, GfxColor *deviceN) const override;
void getGrayLine(unsigned char *in, unsigned char *out, int length) override;
void getRGBLine(unsigned char *in, unsigned int *out, int length) override;
void getRGBLine(unsigned char *in, unsigned char *out, int length) override;
void getRGBXLine(unsigned char *in, unsigned char *out, int length) override;
void getCMYKLine(unsigned char *in, unsigned char *out, int length) override;
void getDeviceNLine(unsigned char *in, unsigned char *out, int length) override;
bool useGetRGBLine() const override { return true; }
bool useGetGrayLine() const override { return true; }
bool useGetCMYKLine() const override { return true; }
bool useGetDeviceNLine() const override { return true; }
int getNComps() const override { return 3; }
void getDefaultColor(GfxColor *color) const override;
private:
};
//------------------------------------------------------------------------
// GfxCalRGBColorSpace
//------------------------------------------------------------------------
class GfxCalRGBColorSpace : public GfxColorSpace
{
public:
GfxCalRGBColorSpace();
~GfxCalRGBColorSpace() override;
GfxColorSpace *copy() const override;
GfxColorSpaceMode getMode() const override { return csCalRGB; }
// Construct a CalRGB color space. Returns nullptr if unsuccessful.
static GfxColorSpace *parse(Array *arr, GfxState *state);
void getGray(const GfxColor *color, GfxGray *gray) const override;
void getRGB(const GfxColor *color, GfxRGB *rgb) const override;
void getCMYK(const GfxColor *color, GfxCMYK *cmyk) const override;
void getDeviceN(const GfxColor *color, GfxColor *deviceN) const override;
int getNComps() const override { return 3; }
void getDefaultColor(GfxColor *color) const override;
// CalRGB-specific access.
double getWhiteX() const { return whiteX; }
double getWhiteY() const { return whiteY; }
double getWhiteZ() const { return whiteZ; }
double getBlackX() const { return blackX; }
double getBlackY() const { return blackY; }
double getBlackZ() const { return blackZ; }
double getGammaR() const { return gammaR; }
double getGammaG() const { return gammaG; }
double getGammaB() const { return gammaB; }
const double *getMatrix() const { return mat; }
private:
double whiteX, whiteY, whiteZ; // white point
double blackX, blackY, blackZ; // black point
double gammaR, gammaG, gammaB; // gamma values
double mat[9]; // ABC -> XYZ transform matrix
void getXYZ(const GfxColor *color, double *pX, double *pY, double *pZ) const;
#ifdef USE_CMS
std::shared_ptr<GfxColorTransform> transform;
#endif
};
//------------------------------------------------------------------------
// GfxDeviceCMYKColorSpace
//------------------------------------------------------------------------
class POPPLER_PRIVATE_EXPORT GfxDeviceCMYKColorSpace : public GfxColorSpace
{
public:
GfxDeviceCMYKColorSpace();
~GfxDeviceCMYKColorSpace() override;
GfxColorSpace *copy() const override;
GfxColorSpaceMode getMode() const override { return csDeviceCMYK; }
void getGray(const GfxColor *color, GfxGray *gray) const override;
void getRGB(const GfxColor *color, GfxRGB *rgb) const override;
void getCMYK(const GfxColor *color, GfxCMYK *cmyk) const override;
void getDeviceN(const GfxColor *color, GfxColor *deviceN) const override;
void getRGBLine(unsigned char *in, unsigned int *out, int length) override;
void getRGBLine(unsigned char *, unsigned char *out, int length) override;
void getRGBXLine(unsigned char *in, unsigned char *out, int length) override;
void getCMYKLine(unsigned char *in, unsigned char *out, int length) override;
void getDeviceNLine(unsigned char *in, unsigned char *out, int length) override;
bool useGetRGBLine() const override { return true; }
bool useGetCMYKLine() const override { return true; }
bool useGetDeviceNLine() const override { return true; }
int getNComps() const override { return 4; }
void getDefaultColor(GfxColor *color) const override;
private:
};
//------------------------------------------------------------------------
// GfxLabColorSpace
//------------------------------------------------------------------------
class GfxLabColorSpace : public GfxColorSpace
{
public:
GfxLabColorSpace();
~GfxLabColorSpace() override;
GfxColorSpace *copy() const override;
GfxColorSpaceMode getMode() const override { return csLab; }
// Construct a Lab color space. Returns nullptr if unsuccessful.
static GfxColorSpace *parse(Array *arr, GfxState *state);
void getGray(const GfxColor *color, GfxGray *gray) const override;
void getRGB(const GfxColor *color, GfxRGB *rgb) const override;
void getCMYK(const GfxColor *color, GfxCMYK *cmyk) const override;
void getDeviceN(const GfxColor *color, GfxColor *deviceN) const override;
int getNComps() const override { return 3; }
void getDefaultColor(GfxColor *color) const override;
void getDefaultRanges(double *decodeLow, double *decodeRange, int maxImgPixel) const override;
// Lab-specific access.
double getWhiteX() const { return whiteX; }
double getWhiteY() const { return whiteY; }
double getWhiteZ() const { return whiteZ; }
double getBlackX() const { return blackX; }
double getBlackY() const { return blackY; }
double getBlackZ() const { return blackZ; }
double getAMin() const { return aMin; }
double getAMax() const { return aMax; }
double getBMin() const { return bMin; }
double getBMax() const { return bMax; }
private:
double whiteX, whiteY, whiteZ; // white point
double blackX, blackY, blackZ; // black point
double aMin, aMax, bMin, bMax; // range for the a and b components
void getXYZ(const GfxColor *color, double *pX, double *pY, double *pZ) const;
#ifdef USE_CMS
std::shared_ptr<GfxColorTransform> transform;
#endif
};
//------------------------------------------------------------------------
// GfxICCBasedColorSpace
//------------------------------------------------------------------------
class POPPLER_PRIVATE_EXPORT GfxICCBasedColorSpace : public GfxColorSpace
{
public:
GfxICCBasedColorSpace(int nCompsA, GfxColorSpace *altA, const Ref *iccProfileStreamA);
~GfxICCBasedColorSpace() override;
GfxColorSpace *copy() const override;
GfxColorSpaceMode getMode() const override { return csICCBased; }
// Construct an ICCBased color space. Returns nullptr if unsuccessful.
static GfxColorSpace *parse(Array *arr, OutputDev *out, GfxState *state, int recursion);
void getGray(const GfxColor *color, GfxGray *gray) const override;
void getRGB(const GfxColor *color, GfxRGB *rgb) const override;
void getCMYK(const GfxColor *color, GfxCMYK *cmyk) const override;
void getDeviceN(const GfxColor *color, GfxColor *deviceN) const override;
void getRGBLine(unsigned char *in, unsigned int *out, int length) override;
void getRGBLine(unsigned char *in, unsigned char *out, int length) override;
void getRGBXLine(unsigned char *in, unsigned char *out, int length) override;
void getCMYKLine(unsigned char *in, unsigned char *out, int length) override;
void getDeviceNLine(unsigned char *in, unsigned char *out, int length) override;
bool useGetRGBLine() const override;
bool useGetCMYKLine() const override;
bool useGetDeviceNLine() const override;
int getNComps() const override { return nComps; }
void getDefaultColor(GfxColor *color) const override;
void getDefaultRanges(double *decodeLow, double *decodeRange, int maxImgPixel) const override;
// ICCBased-specific access.
GfxColorSpace *getAlt() { return alt; }
Ref getRef() { return iccProfileStream; }
#ifdef USE_CMS
char *getPostScriptCSA();
void buildTransforms(GfxState *state);
void setProfile(GfxLCMSProfilePtr &profileA) { profile = profileA; }
GfxLCMSProfilePtr getProfile() { return profile; }
#endif
private:
int nComps; // number of color components (1, 3, or 4)
GfxColorSpace *alt; // alternate color space
double rangeMin[4]; // min values for each component
double rangeMax[4]; // max values for each component
Ref iccProfileStream; // the ICC profile
#ifdef USE_CMS
GfxLCMSProfilePtr profile;
char *psCSA;
int getIntent() { return (transform != nullptr) ? transform->getIntent() : 0; }
std::shared_ptr<GfxColorTransform> transform;
std::shared_ptr<GfxColorTransform> lineTransform; // color transform for line
mutable std::map<unsigned int, unsigned int> cmsCache;
#endif
};
//------------------------------------------------------------------------
// GfxIndexedColorSpace
//------------------------------------------------------------------------
class GfxIndexedColorSpace : public GfxColorSpace
{
public:
GfxIndexedColorSpace(GfxColorSpace *baseA, int indexHighA);
~GfxIndexedColorSpace() override;
GfxColorSpace *copy() const override;
GfxColorSpaceMode getMode() const override { return csIndexed; }
// Construct an Indexed color space. Returns nullptr if unsuccessful.
static GfxColorSpace *parse(GfxResources *res, Array *arr, OutputDev *out, GfxState *state, int recursion);
void getGray(const GfxColor *color, GfxGray *gray) const override;
void getRGB(const GfxColor *color, GfxRGB *rgb) const override;
void getCMYK(const GfxColor *color, GfxCMYK *cmyk) const override;
void getDeviceN(const GfxColor *color, GfxColor *deviceN) const override;
void getRGBLine(unsigned char *in, unsigned int *out, int length) override;
void getRGBLine(unsigned char *in, unsigned char *out, int length) override;
void getRGBXLine(unsigned char *in, unsigned char *out, int length) override;
void getCMYKLine(unsigned char *in, unsigned char *out, int length) override;
void getDeviceNLine(unsigned char *in, unsigned char *out, int length) override;
bool useGetRGBLine() const override { return true; }
bool useGetCMYKLine() const override { return true; }
bool useGetDeviceNLine() const override { return true; }
int getNComps() const override { return 1; }
void getDefaultColor(GfxColor *color) const override;
void getDefaultRanges(double *decodeLow, double *decodeRange, int maxImgPixel) const override;
// Indexed-specific access.
GfxColorSpace *getBase() { return base; }
int getIndexHigh() const { return indexHigh; }
unsigned char *getLookup() { return lookup; }
GfxColor *mapColorToBase(const GfxColor *color, GfxColor *baseColor) const;
unsigned int getOverprintMask() const { return base->getOverprintMask(); }
void createMapping(std::vector<GfxSeparationColorSpace *> *separationList, int maxSepComps) override { base->createMapping(separationList, maxSepComps); }
private:
GfxColorSpace *base; // base color space
int indexHigh; // max pixel value
unsigned char *lookup; // lookup table
};
//------------------------------------------------------------------------
// GfxSeparationColorSpace
//------------------------------------------------------------------------
class GfxSeparationColorSpace : public GfxColorSpace
{
public:
GfxSeparationColorSpace(GooString *nameA, GfxColorSpace *altA, Function *funcA);
~GfxSeparationColorSpace() override;
GfxColorSpace *copy() const override;
GfxColorSpaceMode getMode() const override { return csSeparation; }
// Construct a Separation color space. Returns nullptr if unsuccessful.
static GfxColorSpace *parse(GfxResources *res, Array *arr, OutputDev *out, GfxState *state, int recursion);
void getGray(const GfxColor *color, GfxGray *gray) const override;
void getRGB(const GfxColor *color, GfxRGB *rgb) const override;
void getCMYK(const GfxColor *color, GfxCMYK *cmyk) const override;
void getDeviceN(const GfxColor *color, GfxColor *deviceN) const override;
void createMapping(std::vector<GfxSeparationColorSpace *> *separationList, int maxSepComps) override;
int getNComps() const override { return 1; }
void getDefaultColor(GfxColor *color) const override;
bool isNonMarking() const override { return nonMarking; }
// Separation-specific access.
const GooString *getName() const { return name; }
GfxColorSpace *getAlt() { return alt; }
const Function *getFunc() const { return func; }
private:
GfxSeparationColorSpace(GooString *nameA, GfxColorSpace *altA, Function *funcA, bool nonMarkingA, unsigned int overprintMaskA, int *mappingA);
GooString *name; // colorant name
GfxColorSpace *alt; // alternate color space
Function *func; // tint transform (into alternate color space)
bool nonMarking;
};
//------------------------------------------------------------------------
// GfxDeviceNColorSpace
//------------------------------------------------------------------------
class GfxDeviceNColorSpace : public GfxColorSpace
{
public:
GfxDeviceNColorSpace(int nCompsA, std::vector<std::string> &&namesA, GfxColorSpace *alt, Function *func, std::vector<GfxSeparationColorSpace *> *sepsCS);
~GfxDeviceNColorSpace() override;
GfxColorSpace *copy() const override;
GfxColorSpaceMode getMode() const override { return csDeviceN; }
// Construct a DeviceN color space. Returns nullptr if unsuccessful.
static GfxColorSpace *parse(GfxResources *res, Array *arr, OutputDev *out, GfxState *state, int recursion);
void getGray(const GfxColor *color, GfxGray *gray) const override;
void getRGB(const GfxColor *color, GfxRGB *rgb) const override;
void getCMYK(const GfxColor *color, GfxCMYK *cmyk) const override;
void getDeviceN(const GfxColor *color, GfxColor *deviceN) const override;
void createMapping(std::vector<GfxSeparationColorSpace *> *separationList, int maxSepComps) override;
int getNComps() const override { return nComps; }
void getDefaultColor(GfxColor *color) const override;
bool isNonMarking() const override { return nonMarking; }
// DeviceN-specific access.
const std::string &getColorantName(int i) const { return names[i]; }
GfxColorSpace *getAlt() { return alt; }
const Function *getTintTransformFunc() const { return func; }
private:
GfxDeviceNColorSpace(int nCompsA, const std::vector<std::string> &namesA, GfxColorSpace *alt, Function *func, std::vector<GfxSeparationColorSpace *> *sepsCSA, int *mappingA, bool nonMarkingA, unsigned int overprintMaskA);
const int nComps; // number of components
const std::vector<std::string> names; // colorant names
GfxColorSpace *alt; // alternate color space
Function *func; // tint transform (into alternate color space)
bool nonMarking;
std::vector<GfxSeparationColorSpace *> *sepsCS; // list of separation cs for spot colorants;
};
//------------------------------------------------------------------------
// GfxPatternColorSpace
//------------------------------------------------------------------------
class GfxPatternColorSpace : public GfxColorSpace
{
public:
explicit GfxPatternColorSpace(GfxColorSpace *underA);
~GfxPatternColorSpace() override;
GfxColorSpace *copy() const override;
GfxColorSpaceMode getMode() const override { return csPattern; }
// Construct a Pattern color space. Returns nullptr if unsuccessful.
static GfxColorSpace *parse(GfxResources *res, Array *arr, OutputDev *out, GfxState *state, int recursion);
void getGray(const GfxColor *color, GfxGray *gray) const override;
void getRGB(const GfxColor *color, GfxRGB *rgb) const override;
void getCMYK(const GfxColor *color, GfxCMYK *cmyk) const override;
void getDeviceN(const GfxColor *color, GfxColor *deviceN) const override;
int getNComps() const override { return 0; }
void getDefaultColor(GfxColor *color) const override;
// Pattern-specific access.
GfxColorSpace *getUnder() { return under; }
private:
GfxColorSpace *under; // underlying color space (for uncolored
// patterns)
};
//------------------------------------------------------------------------
// GfxPattern
//------------------------------------------------------------------------
class GfxPattern
{
public:
GfxPattern(int typeA, int patternRefNumA);
virtual ~GfxPattern();
GfxPattern(const GfxPattern &) = delete;
GfxPattern &operator=(const GfxPattern &other) = delete;
static GfxPattern *parse(GfxResources *res, Object *obj, OutputDev *out, GfxState *state, int patternRefNum);
virtual GfxPattern *copy() const = 0;
int getType() const { return type; }
int getPatternRefNum() const { return patternRefNum; }
private:
int type;
int patternRefNum;
};
//------------------------------------------------------------------------
// GfxTilingPattern
//------------------------------------------------------------------------
class GfxTilingPattern : public GfxPattern
{
public:
static GfxTilingPattern *parse(Object *patObj, int patternRefNum);
~GfxTilingPattern() override;
GfxPattern *copy() const override;
int getPaintType() const { return paintType; }
int getTilingType() const { return tilingType; }
const double *getBBox() const { return bbox; }
double getXStep() const { return xStep; }
double getYStep() const { return yStep; }
Dict *getResDict() { return resDict.isDict() ? resDict.getDict() : (Dict *)nullptr; }
const double *getMatrix() const { return matrix; }
Object *getContentStream() { return &contentStream; }
private:
GfxTilingPattern(int paintTypeA, int tilingTypeA, const double *bboxA, double xStepA, double yStepA, const Object *resDictA, const double *matrixA, const Object *contentStreamA, int patternRefNumA);
int paintType;
int tilingType;
double bbox[4];
double xStep, yStep;
Object resDict;
double matrix[6];
Object contentStream;
};
//------------------------------------------------------------------------
// GfxShadingPattern
//------------------------------------------------------------------------
class GfxShadingPattern : public GfxPattern
{
public:
static GfxShadingPattern *parse(GfxResources *res, Object *patObj, OutputDev *out, GfxState *state, int patternRefNum);
~GfxShadingPattern() override;
GfxPattern *copy() const override;
GfxShading *getShading() { return shading; }
const double *getMatrix() const { return matrix; }
private:
GfxShadingPattern(GfxShading *shadingA, const double *matrixA, int patternRefNumA);
GfxShading *shading;
double matrix[6];
};
//------------------------------------------------------------------------
// GfxShading
//------------------------------------------------------------------------
class POPPLER_PRIVATE_EXPORT GfxShading
{
public:
explicit GfxShading(int typeA);
explicit GfxShading(const GfxShading *shading);
virtual ~GfxShading();
GfxShading(const GfxShading &) = delete;
GfxShading &operator=(const GfxShading &other) = delete;
static GfxShading *parse(GfxResources *res, Object *obj, OutputDev *out, GfxState *state);
virtual GfxShading *copy() const = 0;
int getType() const { return type; }
GfxColorSpace *getColorSpace() { return colorSpace; }
const GfxColor *getBackground() const { return &background; }
bool getHasBackground() const { return hasBackground; }
void getBBox(double *xMinA, double *yMinA, double *xMaxA, double *yMaxA) const
{
*xMinA = bbox_xMin;
*yMinA = bbox_yMin;
*xMaxA = bbox_xMax;
*yMaxA = bbox_yMax;
}
bool getHasBBox() const { return hasBBox; }
protected:
virtual bool init(GfxResources *res, Dict *dict, OutputDev *out, GfxState *state);
// 1: Function-based shading
// 2: Axial shading
// 3: Radial shading
// 4: Free-form Gouraud-shaded triangle mesh
// 5: Lattice-form Gouraud-shaded triangle mesh
// 6: Coons patch mesh
// 7: Tensor-product patch mesh
int type;
bool hasBackground;
bool hasBBox;
GfxColorSpace *colorSpace;
GfxColor background;
double bbox_xMin, bbox_yMin, bbox_xMax, bbox_yMax;
};
//------------------------------------------------------------------------
// GfxUnivariateShading
//------------------------------------------------------------------------
class POPPLER_PRIVATE_EXPORT GfxUnivariateShading : public GfxShading
{
public:
GfxUnivariateShading(int typeA, double t0A, double t1A, std::vector<std::unique_ptr<Function>> &&funcsA, bool extend0A, bool extend1A);
explicit GfxUnivariateShading(const GfxUnivariateShading *shading);
~GfxUnivariateShading() override;
double getDomain0() const { return t0; }
double getDomain1() const { return t1; }
bool getExtend0() const { return extend0; }
bool getExtend1() const { return extend1; }
int getNFuncs() const { return funcs.size(); }
const Function *getFunc(int i) const { return funcs[i].get(); }
// returns the nComps of the shading
// i.e. how many positions of color have been set
int getColor(double t, GfxColor *color);
void setupCache(const Matrix *ctm, double xMin, double yMin, double xMax, double yMax);
virtual void getParameterRange(double *lower, double *upper, double xMin, double yMin, double xMax, double yMax) = 0;
virtual double getDistance(double sMin, double sMax) const = 0;
protected:
bool init(GfxResources *res, Dict *dict, OutputDev *out, GfxState *state) override;
private:
double t0, t1;
std::vector<std::unique_ptr<Function>> funcs;
bool extend0, extend1;
int cacheSize, lastMatch;
double *cacheBounds;
double *cacheCoeff;
double *cacheValues;
};
//------------------------------------------------------------------------
// GfxFunctionShading
//------------------------------------------------------------------------
class POPPLER_PRIVATE_EXPORT GfxFunctionShading : public GfxShading
{
public:
GfxFunctionShading(double x0A, double y0A, double x1A, double y1A, const double *matrixA, std::vector<std::unique_ptr<Function>> &&funcsA);
explicit GfxFunctionShading(const GfxFunctionShading *shading);
~GfxFunctionShading() override;
static GfxFunctionShading *parse(GfxResources *res, Dict *dict, OutputDev *out, GfxState *state);
GfxShading *copy() const override;
void getDomain(double *x0A, double *y0A, double *x1A, double *y1A) const
{
*x0A = x0;
*y0A = y0;
*x1A = x1;
*y1A = y1;
}
const double *getMatrix() const { return matrix; }
int getNFuncs() const { return funcs.size(); }
const Function *getFunc(int i) const { return funcs[i].get(); }
void getColor(double x, double y, GfxColor *color) const;
protected:
bool init(GfxResources *res, Dict *dict, OutputDev *out, GfxState *state) override;
private:
double x0, y0, x1, y1;
double matrix[6];
std::vector<std::unique_ptr<Function>> funcs;
};
//------------------------------------------------------------------------
// GfxAxialShading
//------------------------------------------------------------------------
class GfxAxialShading : public GfxUnivariateShading
{
public:
GfxAxialShading(double x0A, double y0A, double x1A, double y1A, double t0A, double t1A, std::vector<std::unique_ptr<Function>> &&funcsA, bool extend0A, bool extend1A);
explicit GfxAxialShading(const GfxAxialShading *shading);
~GfxAxialShading() override;
static GfxAxialShading *parse(GfxResources *res, Dict *dict, OutputDev *out, GfxState *state);
GfxShading *copy() const override;
void getCoords(double *x0A, double *y0A, double *x1A, double *y1A) const
{
*x0A = x0;
*y0A = y0;
*x1A = x1;
*y1A = y1;
}