1 #pragma once
2 
3 #ifndef TCLEANUPPER_H
4 #define TCLEANUPPER_H
5 
6 #include "trasterimage.h"
7 #include "ttoonzimage.h"
8 #include "toonz/cleanupparameters.h"
9 
10 #undef DVAPI
11 #undef DVVAR
12 #ifdef TOONZLIB_EXPORTS
13 #define DVAPI DV_EXPORT_API
14 #define DVVAR DV_EXPORT_VAR
15 #else
16 #define DVAPI DV_IMPORT_API
17 #define DVVAR DV_IMPORT_VAR
18 #endif
19 
20 //-----------------------------------------------------------------------------
21 
22 //  Forward declarations
23 
24 class CleanupPreprocessedImage;
25 class TargetColors;
26 class TCamera;
27 
28 //-----------------------------------------------------------------------------
29 
30 //****************************************************************************************
31 //    CleanupProcessedImage declaration
32 //****************************************************************************************
33 
34 class DVAPI CleanupPreprocessedImage {
35   std::string m_imgId;
36   TDimension m_size;
37 
38 public:
39   bool m_wasFromGR8;
40   bool m_autocentered;
41   std::vector<TPixel32> m_pixelsLut;
42   TAffine m_appliedAff;
43 
44 public:
45   CleanupPreprocessedImage(CleanupParameters *parameters,
46                            TToonzImageP processed, bool fromGr8);
47   ~CleanupPreprocessedImage();
48 
getSize()49   TDimension getSize() const { return m_size; }
50   TToonzImageP getImg() const;
51   TRasterImageP getPreviewImage() const;
52 };
53 
54 //****************************************************************************************
55 //    TCleanupper singleton declaration
56 //****************************************************************************************
57 
58 class DVAPI TCleanupper {
59   CleanupParameters *m_parameters;
60   TPointD m_sourceDpi;
61 
62 private:
TCleanupper()63   TCleanupper()
64       : m_parameters(0) {
65   }  // singleton class - will not be externally constructed
66 
67 public:
68   static TCleanupper *instance();
69 
70   void setParameters(CleanupParameters *parameters);
getParameters()71   const CleanupParameters *getParameters() const { return m_parameters; }
72 
73   TPalette *createToonzPaletteFromCleanupPalette();
74 
75   /*---
76    * 拡大/縮小をしていない場合(DPIが変わらない場合)、NearestNeighborでリサンプリングする。
77    * ---*/
78   bool getResampleValues(const TRasterImageP &image, TAffine &aff, double &blur,
79                          TDimension &outDim, TPointD &outDpi, bool isCameraTest,
80                          bool &isSameDpi);
81 
82   TRasterP processColors(const TRasterP &r);
83 
84   /*!
85 The main cleanup method.
86 \warning The input image reference is internally released at the most
87 appropriate
88 time, to unlock a possibly useful memory block.
89 */
90   CleanupPreprocessedImage *process(TRasterImageP &image, bool first_image,
91                                     TRasterImageP &onlyResampledImage,
92                                     bool isCameraTest    = false,
93                                     bool returnResampled = false,
94                                     bool onlyForSwatch   = false,
95                                     TAffine *aff         = 0);
96 
97   void finalize(const TRaster32P &dst, CleanupPreprocessedImage *src);
98   TToonzImageP finalize(CleanupPreprocessedImage *src,
99                         bool isCleanupper = false);
100 
101   TRasterImageP autocenterOnly(const TRasterImageP &image, bool isCameraTest,
102                                bool &autocentered);
103 
getSourceDpi()104   TPointD getSourceDpi() const { return m_sourceDpi; }
setSourceDpi(const TPointD & dpi)105   void setSourceDpi(const TPointD &dpi) { m_sourceDpi = dpi; }
106 
107 private:
108   // process phase
109   bool doAutocenter(double &angle, double &skew, double &cxin, double &cyin,
110                     double &cqout, double &cpout, const double xdpi,
111                     const double ydpi, const int raster_is_savebox,
112                     const TRect saveBox, const TRasterImageP &image,
113                     const double scalex);
114   void preprocessColors(const TRasterCM32P &outRas, const TRaster32P &raster32,
115                         const TargetColors &colors);
116   void removeSinglePoint(const TRasterCM32P &outRas);
117 
118   // post-processing phase
119   TToonzImageP doPostProcessingGR8(const CleanupPreprocessedImage *img);
120   void doPostProcessingGR8(const TRaster32P &outRas,
121                            CleanupPreprocessedImage *srcImg);
122 
123   TToonzImageP doPostProcessingColor(const TToonzImageP &imgToProcess,
124                                      bool isCleanupper);
125   void doPostProcessingColor(const TRaster32P &outRas,
126                              CleanupPreprocessedImage *srcImg);
127 };
128 
129 #endif
130