1 | //======================================================================== |
2 | // |
3 | // SplashScreen.h |
4 | // |
5 | //======================================================================== |
6 | |
7 | //======================================================================== |
8 | // |
9 | // Modified under the Poppler project - http://poppler.freedesktop.org |
10 | // |
11 | // All changes made under the Poppler project to this file are licensed |
12 | // under GPL version 2 or later |
13 | // |
14 | // Copyright (C) 2009, 2018, 2020, 2021 Albert Astals Cid <aacid@kde.org> |
15 | // |
16 | // To see a description of the changes please see the Changelog file that |
17 | // came with your tarball or type make ChangeLog if you are building from git |
18 | // |
19 | //======================================================================== |
20 | |
21 | #ifndef SPLASHSCREEN_H |
22 | #define SPLASHSCREEN_H |
23 | |
24 | #include "SplashTypes.h" |
25 | |
26 | #include <cstdlib> |
27 | |
28 | //------------------------------------------------------------------------ |
29 | // SplashScreen |
30 | //------------------------------------------------------------------------ |
31 | |
32 | class SplashScreen |
33 | { |
34 | public: |
35 | explicit SplashScreen(const SplashScreenParams *params); |
36 | explicit SplashScreen(const SplashScreen *screen); |
37 | ~SplashScreen(); |
38 | |
39 | SplashScreen(const SplashScreen &) = delete; |
40 | SplashScreen &operator=(const SplashScreen &) = delete; |
41 | |
42 | SplashScreen *copy() const { return new SplashScreen(this); } |
43 | |
44 | // Return the computed pixel value (0=black, 1=white) for the gray |
45 | // level <value> at (<x>, <y>). |
46 | int test(int x, int y, unsigned char value) |
47 | { |
48 | int xx, yy; |
49 | if (mat == nullptr) { |
50 | createMatrix(); |
51 | } |
52 | xx = x & sizeM1; |
53 | yy = y & sizeM1; |
54 | return value < mat[(yy << log2Size) + xx] ? 0 : 1; |
55 | } |
56 | |
57 | // Returns true if value is above the white threshold or below the |
58 | // black threshold, i.e., if the corresponding halftone will be |
59 | // solid white or black. |
60 | bool isStatic(unsigned char value) |
61 | { |
62 | if (mat == nullptr) { |
63 | createMatrix(); |
64 | } |
65 | return value < minVal || value >= maxVal; |
66 | } |
67 | |
68 | private: |
69 | void createMatrix(); |
70 | |
71 | void buildDispersedMatrix(int i, int j, int val, int delta, int offset); |
72 | void buildClusteredMatrix(); |
73 | int distance(int x0, int y0, int x1, int y1); |
74 | void buildSCDMatrix(int r); |
75 | |
76 | const SplashScreenParams *screenParams; // params to create the other members |
77 | unsigned char *mat; // threshold matrix |
78 | int size; // size of the threshold matrix |
79 | int sizeM1; // size - 1 |
80 | int log2Size; // log2(size) |
81 | unsigned char minVal; // any pixel value below minVal generates |
82 | // solid black |
83 | unsigned char maxVal; // any pixel value above maxVal generates |
84 | // solid white |
85 | }; |
86 | |
87 | #endif |
88 | |