1 #pragma once 2 3 #ifndef CONVERT2FILLED_INCLUDED 4 #define CONVERT2FILLED_INCLUDED 5 6 #include "tfilepath.h" 7 #include "tlevel_io.h" 8 #include "tpalette.h" 9 #include "trasterimage.h" 10 #include "ttoonzimage.h" 11 12 #undef DVAPI 13 #undef DVVAR 14 #ifdef TOONZLIB_EXPORTS 15 #define DVAPI DV_EXPORT_API 16 #define DVVAR DV_EXPORT_VAR 17 #else 18 #define DVAPI DV_IMPORT_API 19 #define DVVAR DV_IMPORT_VAR 20 #endif 21 22 class DVAPI Convert2Tlv { 23 private: 24 TLevelP m_level1; 25 TLevel::Iterator m_it; 26 TLevelReaderP m_lr1; 27 TLevelReaderP m_lr2; 28 TLevelWriterP m_lw; 29 std::map<TPixel, int> m_colorMap; 30 TDimension m_size; 31 int m_count; 32 int m_from, m_to; 33 TPalette *m_palette; 34 int m_colorTolerance; 35 int m_lastIndex, m_maxPaletteIndex; 36 int m_antialiasType; 37 int m_antialiasValue; 38 39 bool m_isUnpaintedFromNAA; 40 bool m_appendDefaultPalette; 41 42 double m_dpi; 43 44 void buildToonzRaster(TRasterCM32P &rout, const TRasterP &rin1, 45 const TRasterP &rin2); 46 void doFill(TRasterCM32P &rout, const TRaster32P &rin); 47 void buildInksFromGrayTones(TRasterCM32P &rout, const TRasterP &rin); 48 std::map<TPixel, int>::const_iterator findNearestColor(const TPixel &color); 49 void buildInks(TRasterCM32P &rout, const TRaster32P &rin); 50 TPalette *buildPalette(); 51 void removeAntialias(TRasterCM32P &r); 52 53 void buildInksForNAAImage(TRasterCM32P &rout, const TRaster32P &rin); 54 55 public: 56 TFilePath m_levelIn1, m_levelIn2, m_levelOut, m_palettePath; 57 bool m_autoclose, m_premultiply; 58 59 // i livelli passati devono essere tif o png. 60 // se filepath2=TFilePath(), viene creata una tlv unpainted, altrimenti 61 // painted. 62 // nel secondo caso, i due livelli specificati (in qualsiasi ordine, la classe 63 // capisce da sola qual'e' l'unpainted e la painted) 64 // devono contenere la versione painted e quella unpainted della stessa 65 // sequenza di immagini 66 // la tlv e la tpl vengono salvate con il nome e il folder di filepath1. 67 Convert2Tlv(const TFilePath &filepath1, const TFilePath &filepath2, 68 const TFilePath &outFolder, const QString &outName, int from, 69 int to, bool doAutoclose, const TFilePath &palettePath, 70 int colorTolerance, int antialiasType, int antialiasValue, 71 bool isUnpaintedFromNAA, bool appendDefaultPalette, double dpi); 72 73 bool init(std::string &errorMessage); 74 int getFramesToConvertCount(); 75 bool abort(); 76 bool convertNext(std::string &errorMessage); 77 }; 78 79 // gmt, 3/1/2013; making raster>toonzraster conversion available to scripts 80 // it seems too complex to modify Convert2Tlv, that refer to file levels instead 81 // of memory levels. 82 // RasterToToonzRasterConverter uses the same algorithms (more or less) 83 // TODO: refactor the two classes 84 // NOTE: you don't need to specify a palette (with 85 // RasterToToonzRasterConverter::setPalette()): in that case a suitable palette 86 // is generated 87 class DVAPI RasterToToonzRasterConverter { 88 TPaletteP m_palette; 89 90 public: 91 RasterToToonzRasterConverter(); 92 ~RasterToToonzRasterConverter(); 93 94 void setPalette(const TPaletteP &palette); getPalette()95 const TPaletteP &getPalette() const { return m_palette; } 96 97 TRasterCM32P convert(const TRasterP &inputRaster); 98 TRasterCM32P convert(const TRasterP &inksInputRaster, 99 const TRasterP &paintInputRaster); 100 101 TToonzImageP convert(const TRasterImageP &ri); 102 }; 103 104 #endif 105