├── .gitignore ├── 3rdparty ├── 3rdparty_src │ └── tlg2png │ │ ├── AbstractTlgReader.cc │ │ ├── AbstractTlgReader.h │ │ ├── BadMagicException.h │ │ ├── LzssCompressionState.cc │ │ ├── LzssCompressionState.h │ │ ├── LzssCompressor.cc │ │ ├── LzssCompressor.h │ │ ├── Tlg0Reader.cc │ │ ├── Tlg0Reader.h │ │ ├── Tlg5Reader.cc │ │ ├── Tlg5Reader.h │ │ ├── Tlg6Reader.cc │ │ ├── Tlg6Reader.h │ │ └── TlgConverter.cc ├── include │ ├── json.hpp │ ├── opencv2 │ │ ├── core.hpp │ │ ├── core │ │ │ ├── base.hpp │ │ │ ├── bufferpool.hpp │ │ │ ├── check.hpp │ │ │ ├── cv_cpu_dispatch.h │ │ │ ├── cvdef.h │ │ │ ├── cvstd.hpp │ │ │ ├── cvstd.inl.hpp │ │ │ ├── cvstd_wrapper.hpp │ │ │ ├── fast_math.hpp │ │ │ ├── hal │ │ │ │ └── interface.h │ │ │ ├── mat.hpp │ │ │ ├── mat.inl.hpp │ │ │ ├── matx.hpp │ │ │ ├── neon_utils.hpp │ │ │ ├── operations.hpp │ │ │ ├── optim.hpp │ │ │ ├── ovx.hpp │ │ │ ├── persistence.hpp │ │ │ ├── saturate.hpp │ │ │ ├── traits.hpp │ │ │ ├── types.hpp │ │ │ ├── utility.hpp │ │ │ ├── version.hpp │ │ │ └── vsx_utils.hpp │ │ ├── imgcodecs.hpp │ │ ├── imgproc.hpp │ │ ├── opencv.hpp │ │ └── opencv_modules.hpp │ └── tlg2png │ │ ├── Image.h │ │ └── TlgConverter.h └── lib │ ├── libopencv_core430.dll │ ├── libopencv_imgcodecs430.dll │ ├── libopencv_imgproc430.dll │ ├── libpng16.dll │ ├── libtlg2png.dll │ └── libzlib.dll ├── LICENSE ├── Makefile ├── README.md ├── doc ├── README_zh-CN.md └── full_flow.md └── src ├── cglayer.cpp ├── cglayer.h ├── cglayerindex.cpp ├── cglayerindex.h ├── cgmerge.cpp ├── cgpic.cpp ├── cgpic.h ├── cgpicindex.cpp ├── cgpicindex.h ├── csvsplitter.cpp └── csvsplitter.h /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | build 3 | -------------------------------------------------------------------------------- /3rdparty/3rdparty_src/tlg2png/AbstractTlgReader.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "AbstractTlgReader.h" 7 | #include "BadMagicException.h" 8 | #include "Tlg0Reader.h" 9 | #include "Tlg5Reader.h" 10 | #include "Tlg6Reader.h" 11 | 12 | std::unique_ptr 13 | AbstractTlgReader::choose_reader(std::ifstream &ifs) 14 | { 15 | std::vector readers 16 | { 17 | new Tlg0Reader(), 18 | new Tlg5Reader(), 19 | new Tlg6Reader(), 20 | }; 21 | 22 | auto pos = ifs.tellg(); 23 | for (auto reader : readers) 24 | { 25 | try 26 | { 27 | ifs.seekg(pos, ifs.beg); 28 | if (reader->is_magic_valid(ifs)) 29 | { 30 | return std::unique_ptr(reader); 31 | } 32 | } 33 | catch (BadMagicException const &e) 34 | { 35 | continue; 36 | } 37 | } 38 | 39 | throw std::runtime_error("Not a TLG image"); 40 | } 41 | 42 | const Image AbstractTlgReader::read(std::string path) const 43 | { 44 | std::ifstream ifs(path, std::ifstream::in | std::ifstream::binary); 45 | if (!ifs) 46 | throw std::runtime_error("Can\'t open " + path + " for reading"); 47 | 48 | try 49 | { 50 | ifs.seekg(0, ifs.beg); 51 | if (!is_magic_valid(ifs)) 52 | throw BadMagicException(); 53 | auto ret = read_raw_data(ifs); 54 | ifs.close(); 55 | return ret; 56 | } 57 | catch (std::exception const &e) 58 | { 59 | ifs.close(); 60 | throw; 61 | } 62 | } 63 | 64 | const bool AbstractTlgReader::is_magic_valid(std::ifstream &ifs) const 65 | { 66 | bool result = false; 67 | auto magic_size = get_magic().size(); 68 | char *actual = new char[magic_size]; 69 | try 70 | { 71 | ifs.read(actual, magic_size); 72 | if (std::strncmp(actual, get_magic().data(), magic_size) == 0) 73 | { 74 | result = true; 75 | } 76 | } 77 | catch (std::exception const &e) 78 | { 79 | } 80 | delete[] actual; 81 | return result; 82 | } 83 | -------------------------------------------------------------------------------- /3rdparty/3rdparty_src/tlg2png/AbstractTlgReader.h: -------------------------------------------------------------------------------- 1 | #ifndef ABSTRACT_TLG_READER_H_ 2 | #define ABSTRACT_TLG_READER_H_ 3 | #include 4 | #include 5 | #include 6 | #include "Image.h" 7 | 8 | class AbstractTlgReader 9 | { 10 | friend class Tlg0Reader; 11 | 12 | public: 13 | static std::unique_ptr 14 | choose_reader(std::ifstream &ifs); 15 | 16 | const Image read(std::string path) const; 17 | 18 | private: 19 | virtual const Image read_raw_data(std::ifstream &stream) const = 0; 20 | 21 | virtual const std::string get_magic() const = 0; 22 | 23 | const bool is_magic_valid(std::ifstream &ifs) const; 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /3rdparty/3rdparty_src/tlg2png/BadMagicException.h: -------------------------------------------------------------------------------- 1 | #ifndef BAD_MAGIC_EXCEPTION_H_ 2 | #define BAD_MAGIC_EXCEPTION_H_ 3 | 4 | class BadMagicException : public std::exception 5 | { 6 | const char *what() const noexcept 7 | { 8 | return "Not a TLG image"; 9 | } 10 | }; 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /3rdparty/3rdparty_src/tlg2png/LzssCompressionState.cc: -------------------------------------------------------------------------------- 1 | #include "LzssCompressionState.h" 2 | 3 | LzssCompressionState::LzssCompressionState() 4 | { 5 | for (int i = 0; i < 4096; i ++) 6 | text[i] = 0; 7 | } 8 | -------------------------------------------------------------------------------- /3rdparty/3rdparty_src/tlg2png/LzssCompressionState.h: -------------------------------------------------------------------------------- 1 | #ifndef LZSS_COMPRESSION_STATE_H_ 2 | #define LZSS_COMPRESSION_STATE_H_ 3 | #include 4 | 5 | struct LzssCompressionState 6 | { 7 | uint8_t text[4096]; 8 | uint16_t offset = 0; 9 | 10 | LzssCompressionState(); 11 | }; 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /3rdparty/3rdparty_src/tlg2png/LzssCompressor.cc: -------------------------------------------------------------------------------- 1 | #include "LzssCompressor.h" 2 | 3 | void LzssCompressor::decompress( 4 | LzssCompressionState &compression_state, 5 | uint8_t *input, 6 | size_t input_size, 7 | uint8_t *output) 8 | { 9 | uint8_t *end = input + input_size; 10 | 11 | for (uint32_t i = 0; i < input_size; i ++) 12 | output[i] = 0; 13 | 14 | int flags = 0; 15 | while (input < end) 16 | { 17 | flags >>= 1; 18 | if ((flags & 0x100) != 0x100) 19 | flags = *input++ | 0xff00; 20 | 21 | if ((flags & 1) == 1) 22 | { 23 | uint8_t x0 = *input++; 24 | uint8_t x1 = *input++; 25 | int position = x0 | ((x1 & 0xf) << 8); 26 | int length = 3 + ((x1 & 0xf0) >> 4); 27 | if (length == 18) 28 | length += *input++; 29 | for (int j = 0; j < length; j ++) 30 | { 31 | uint8_t c = compression_state.text[position]; 32 | *output ++ = c; 33 | compression_state.text[compression_state.offset] = c; 34 | compression_state.offset ++; 35 | compression_state.offset &= 0xfff; 36 | position ++; 37 | position &= 0xfff; 38 | } 39 | } 40 | else 41 | { 42 | uint8_t c = *input ++; 43 | *output ++ = c; 44 | compression_state.text[compression_state.offset] = c; 45 | compression_state.offset ++; 46 | compression_state.offset &= 0xfff; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /3rdparty/3rdparty_src/tlg2png/LzssCompressor.h: -------------------------------------------------------------------------------- 1 | #ifndef LZSS_COMPRESSOR_H_ 2 | #define LZSS_COMPRESSOR_H_ 3 | #include 4 | #include 5 | #include "LzssCompressionState.h" 6 | 7 | class LzssCompressor 8 | { 9 | public: 10 | static void decompress( 11 | LzssCompressionState &compression_state, 12 | uint8_t *input, 13 | size_t input_size, 14 | uint8_t *output); 15 | }; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /3rdparty/3rdparty_src/tlg2png/Tlg0Reader.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "Tlg0Reader.h" 7 | #include "Tlg5Reader.h" 8 | #include "Tlg6Reader.h" 9 | 10 | namespace 11 | { 12 | std::string extract_string(char *&ptr) 13 | { 14 | int length = 0; 15 | while (*ptr >= '0' && *ptr <= '9') 16 | { 17 | length *= 10; 18 | length += *ptr++ - '0'; 19 | } 20 | 21 | if (*ptr != ':') 22 | return ""; 23 | ptr ++; 24 | 25 | std::string value; 26 | for (int i = 0; i < length; i ++) 27 | value += *ptr ++; 28 | 29 | return value; 30 | } 31 | 32 | void process_tag_chunk(std::unique_ptr chunk_data, size_t chunk_size) 33 | { 34 | char *start = chunk_data.get(); 35 | char *ptr = start; 36 | while (ptr < start + chunk_size) 37 | { 38 | auto key = extract_string(ptr); 39 | ptr ++; 40 | auto value = extract_string(ptr); 41 | ptr ++; 42 | std::cout << "Tag found: " << key << " = " << value << std::endl; 43 | } 44 | } 45 | 46 | void process_chunks(std::ifstream &ifs) 47 | { 48 | char chunk_name[4]; 49 | while (ifs.read(chunk_name, 4)) 50 | { 51 | uint32_t chunk_size; 52 | ifs.read((char*) &chunk_size, 4); 53 | 54 | auto chunk_data = std::unique_ptr(new char[chunk_size]); 55 | ifs.read(chunk_data.get(), chunk_size); 56 | if (std::strncmp(chunk_name, "tags", 4) == 0) 57 | { 58 | process_tag_chunk(std::move(chunk_data), chunk_size); 59 | } 60 | } 61 | } 62 | } 63 | 64 | const std::string Tlg0Reader::get_magic() const 65 | { 66 | return std::string("\x54\x4c\x47\x30\x2e\x30\x00\x73\x64\x73\x1a", 11); 67 | } 68 | 69 | const Image Tlg0Reader::read_raw_data(std::ifstream &ifs) const 70 | { 71 | uint32_t raw_data_size; 72 | ifs.read((char*) &raw_data_size, 4); 73 | 74 | auto reader = AbstractTlgReader::choose_reader(ifs); 75 | auto ret = reader->read_raw_data(ifs); 76 | 77 | process_chunks(ifs); 78 | 79 | return ret; 80 | } 81 | -------------------------------------------------------------------------------- /3rdparty/3rdparty_src/tlg2png/Tlg0Reader.h: -------------------------------------------------------------------------------- 1 | #ifndef TLG0_READER_H_ 2 | #define TLG0_READER_H_ 3 | #include "AbstractTlgReader.h" 4 | 5 | class Tlg0Reader : public AbstractTlgReader 6 | { 7 | public: 8 | virtual const std::string get_magic() const; 9 | 10 | private: 11 | virtual const Image read_raw_data(std::ifstream &stream) const; 12 | }; 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /3rdparty/3rdparty_src/tlg2png/Tlg5Reader.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "LzssCompressionState.h" 6 | #include "LzssCompressor.h" 7 | #include "Tlg5Reader.h" 8 | 9 | namespace 10 | { 11 | struct Tlg5Header 12 | { 13 | uint8_t channel_count; 14 | uint32_t image_width; 15 | uint32_t image_height; 16 | uint32_t block_height; 17 | 18 | void read(std::ifstream &ifs); 19 | }; 20 | 21 | void Tlg5Header::read(std::ifstream &ifs) 22 | { 23 | ifs.read((char*) &channel_count, 1); 24 | ifs.read((char*) &image_width, 4); 25 | ifs.read((char*) &image_height, 4); 26 | ifs.read((char*) &block_height, 4); 27 | } 28 | 29 | struct Tlg5BlockInfo 30 | { 31 | uint8_t mark; 32 | uint32_t block_size; 33 | std::unique_ptr block_data = nullptr; 34 | 35 | void read(std::ifstream &ifs); 36 | void decompress( 37 | const Tlg5Header &header, 38 | LzssCompressionState &compression_state); 39 | }; 40 | 41 | void Tlg5BlockInfo::read(std::ifstream &ifs) 42 | { 43 | ifs.read((char*) &mark, 1); 44 | ifs.read((char*) &block_size, 4); 45 | block_data = std::unique_ptr(new uint8_t[block_size]); 46 | ifs.read((char*) block_data.get(), block_size); 47 | } 48 | 49 | void Tlg5BlockInfo::decompress( 50 | const Tlg5Header &header, 51 | LzssCompressionState &compression_state) 52 | { 53 | auto new_data = new uint8_t[header.image_width * header.block_height]; 54 | 55 | LzssCompressor::decompress( 56 | compression_state, 57 | block_data.get(), 58 | block_size, 59 | new_data); 60 | 61 | block_data = std::unique_ptr(new_data); 62 | } 63 | 64 | std::map read_channel_data( 65 | const Tlg5Header &header, 66 | LzssCompressionState &compression_state, 67 | std::ifstream &ifs) 68 | { 69 | std::map map; 70 | for (int channel = 0; channel < header.channel_count; channel ++) 71 | { 72 | Tlg5BlockInfo block_info; 73 | block_info.read(ifs); 74 | if (!block_info.mark) 75 | { 76 | block_info.decompress(header, compression_state); 77 | } 78 | map[channel] = std::move(block_info); 79 | } 80 | return map; 81 | } 82 | 83 | void load_pixel_block_row( 84 | const Tlg5Header &header, 85 | std::map channel_data, 86 | int block_y, 87 | uint32_t *pixels) 88 | { 89 | uint32_t max_y = block_y + header.block_height; 90 | if (max_y > header.image_height) 91 | max_y = header.image_height; 92 | bool use_alpha = header.channel_count == 4; 93 | 94 | for (uint32_t y = block_y; y < max_y; y ++) 95 | { 96 | uint8_t prev_red = 0; 97 | uint8_t prev_green = 0; 98 | uint8_t prev_blue = 0; 99 | uint8_t prev_alpha = 0; 100 | 101 | int block_y_shift = (y - block_y) * header.image_width; 102 | int prev_y_shift = (y - 1) * header.image_width; 103 | int y_shift = y * header.image_width; 104 | for (uint32_t x = 0; x < header.image_width; x ++) 105 | { 106 | uint8_t red = channel_data[2].block_data.get()[block_y_shift + x]; 107 | uint8_t green = channel_data[1].block_data.get()[block_y_shift + x]; 108 | uint8_t blue = channel_data[0].block_data.get()[block_y_shift + x]; 109 | uint8_t alpha = use_alpha ? channel_data[3].block_data.get()[block_y_shift + x] : 0; 110 | 111 | red += green; 112 | blue += green; 113 | 114 | prev_red += red; 115 | prev_green += green; 116 | prev_blue += blue; 117 | prev_alpha += alpha; 118 | 119 | uint8_t output_red = prev_red; 120 | uint8_t output_green = prev_green; 121 | uint8_t output_blue = prev_blue; 122 | uint8_t output_alpha = prev_alpha; 123 | 124 | if (y > 0) 125 | { 126 | uint32_t above = pixels[prev_y_shift + x]; 127 | uint8_t above_red = above & 0xff; 128 | uint8_t above_green = above >> 8; 129 | uint8_t above_blue = above >> 16; 130 | uint8_t above_alpha = above >> 24; 131 | output_red += above_red; 132 | output_green += above_green; 133 | output_blue += above_blue; 134 | output_alpha += above_alpha; 135 | } 136 | 137 | if (!use_alpha) 138 | output_alpha = 0xff; 139 | 140 | uint32_t output = 141 | output_red | 142 | (output_green << 8) | 143 | (output_blue << 16) | 144 | (output_alpha << 24); 145 | 146 | pixels[y_shift + x] = output; 147 | } 148 | } 149 | } 150 | 151 | void read_pixels(const Tlg5Header &header, std::ifstream &ifs, uint32_t *pixels) 152 | { 153 | LzssCompressionState state; 154 | for (uint32_t y = 0; y < header.image_height; y += header.block_height) 155 | { 156 | auto channel_data = read_channel_data(header, state, ifs); 157 | load_pixel_block_row(header, std::move(channel_data), y, pixels); 158 | } 159 | } 160 | } 161 | 162 | const std::string Tlg5Reader::get_magic() const 163 | { 164 | return std::string("\x54\x4c\x47\x35\x2e\x30\x00\x72\x61\x77\x1a", 11); 165 | } 166 | 167 | const Image Tlg5Reader::read_raw_data(std::ifstream &ifs) const 168 | { 169 | Tlg5Header header; 170 | header.read(ifs); 171 | if (header.channel_count != 3 && header.channel_count != 4) 172 | { 173 | throw std::runtime_error("Unsupported channel count"); 174 | } 175 | 176 | auto block_count = (header.image_height - 1) / header.block_height + 1; 177 | ifs.seekg(4 * block_count, ifs.cur); 178 | 179 | Image image; 180 | image.width = header.image_width; 181 | image.height = header.image_height; 182 | image.pixels = new uint32_t[image.width * image.height]; 183 | read_pixels(header, ifs, image.pixels); 184 | return image; 185 | } 186 | -------------------------------------------------------------------------------- /3rdparty/3rdparty_src/tlg2png/Tlg5Reader.h: -------------------------------------------------------------------------------- 1 | #ifndef TLG5_READER_H_ 2 | #define TLG5_READER_H_ 3 | #include "AbstractTlgReader.h" 4 | 5 | class Tlg5Reader : public AbstractTlgReader 6 | { 7 | public: 8 | virtual const std::string get_magic() const; 9 | 10 | private: 11 | virtual const Image read_raw_data(std::ifstream &stream) const; 12 | }; 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /3rdparty/3rdparty_src/tlg2png/Tlg6Reader.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "LzssCompressionState.h" 5 | #include "LzssCompressor.h" 6 | #include "Tlg6Reader.h" 7 | 8 | namespace 9 | { 10 | const int w_block_size = 8; 11 | const int h_block_size = 8; 12 | const int golomb_n_count = 4; 13 | const int leading_zero_table_bits = 12; 14 | const int leading_zero_table_size = 1 << leading_zero_table_bits; 15 | 16 | uint8_t leading_zero_table[leading_zero_table_size]; 17 | uint8_t golomb_bit_length_table[golomb_n_count * 2 * 128][golomb_n_count]; 18 | 19 | std::array transformers 20 | { 21 | [](uint8_t &r, uint8_t &g, uint8_t &b) 22 | { 23 | }, 24 | 25 | [](uint8_t &r, uint8_t &g, uint8_t &b) 26 | { 27 | r += g; 28 | b += g; 29 | }, 30 | 31 | [](uint8_t &r, uint8_t &g, uint8_t &b) 32 | { 33 | g += b; 34 | r += g; 35 | }, 36 | 37 | [](uint8_t &r, uint8_t &g, uint8_t &b) 38 | { 39 | g += r; 40 | b += g; 41 | }, 42 | 43 | [](uint8_t &r, uint8_t &g, uint8_t &b) 44 | { 45 | b += r; 46 | g += b; 47 | r += g; 48 | }, 49 | 50 | [](uint8_t &r, uint8_t &g, uint8_t &b) 51 | { 52 | b += r; 53 | g += b; 54 | }, 55 | 56 | [](uint8_t &r, uint8_t &g, uint8_t &b) 57 | { 58 | b += g; 59 | }, 60 | 61 | [](uint8_t &r, uint8_t &g, uint8_t &b) 62 | { 63 | g += b; 64 | }, 65 | 66 | [](uint8_t &r, uint8_t &g, uint8_t &b) 67 | { 68 | r += g; 69 | }, 70 | 71 | [](uint8_t &r, uint8_t &g, uint8_t &b) 72 | { 73 | r += b; 74 | g += r; 75 | b += g; 76 | }, 77 | 78 | [](uint8_t &r, uint8_t &g, uint8_t &b) 79 | { 80 | b += r; 81 | g += r; 82 | }, 83 | 84 | [](uint8_t &r, uint8_t &g, uint8_t &b) 85 | { 86 | r += b; 87 | g += b; 88 | }, 89 | 90 | [](uint8_t &r, uint8_t &g, uint8_t &b) 91 | { 92 | r += b; 93 | g += r; 94 | }, 95 | 96 | [](uint8_t &r, uint8_t &g, uint8_t &b) 97 | { 98 | b += g; 99 | r += b; 100 | g += r; 101 | }, 102 | 103 | [](uint8_t &r, uint8_t &g, uint8_t &b) 104 | { 105 | g += r; 106 | b += g; 107 | r += b; 108 | }, 109 | 110 | [](uint8_t &r, uint8_t &g, uint8_t &b) 111 | { 112 | g += (b << 1); 113 | r += (b << 1); 114 | }, 115 | }; 116 | 117 | struct Tlg6Header 118 | { 119 | uint8_t channel_count; 120 | uint8_t data_flags; 121 | uint8_t color_type; 122 | uint8_t external_golomb_table; 123 | uint32_t image_width; 124 | uint32_t image_height; 125 | uint32_t max_bit_length; 126 | uint32_t x_block_count; 127 | uint32_t y_block_count; 128 | 129 | void read(std::ifstream &ifs); 130 | }; 131 | 132 | void Tlg6Header::read(std::ifstream &ifs) 133 | { 134 | ifs.read((char*) &channel_count, 1); 135 | ifs.read((char*) &data_flags, 1); 136 | ifs.read((char*) &color_type, 1); 137 | ifs.read((char*) &external_golomb_table, 1); 138 | ifs.read((char*) &image_width, 4); 139 | ifs.read((char*) &image_height, 4); 140 | ifs.read((char*) &max_bit_length, 4); 141 | 142 | x_block_count = ((image_width - 1)/ w_block_size) + 1; 143 | y_block_count = ((image_height - 1)/ h_block_size) + 1; 144 | } 145 | 146 | struct Tlg6FilterTypes 147 | { 148 | uint32_t data_size; 149 | std::unique_ptr data = nullptr; 150 | 151 | void read(std::ifstream &ifs); 152 | void decompress(Tlg6Header const &header); 153 | }; 154 | 155 | void Tlg6FilterTypes::read(std::ifstream &ifs) 156 | { 157 | ifs.read((char*) &data_size, 4); 158 | data = std::unique_ptr(new uint8_t[data_size]); 159 | ifs.read((char*) data.get(), data_size); 160 | } 161 | 162 | void Tlg6FilterTypes::decompress(Tlg6Header const &header) 163 | { 164 | auto output_size = header.x_block_count * header.y_block_count; 165 | uint8_t *output = new uint8_t[output_size]; 166 | 167 | LzssCompressionState compression_state; 168 | uint8_t *ptr = compression_state.text; 169 | for (int i = 0; i < 32; i ++) 170 | { 171 | for (int j = 0; j < 16; j ++) 172 | { 173 | for (int k = 0; k < 4; k ++) 174 | *ptr ++ = i; 175 | 176 | for (int k = 0; k < 4; k ++) 177 | *ptr ++ = j; 178 | } 179 | } 180 | 181 | LzssCompressor::decompress( 182 | compression_state, 183 | data.get(), 184 | data_size, 185 | output); 186 | 187 | data = std::unique_ptr(output); 188 | } 189 | 190 | inline uint32_t make_gt_mask( 191 | uint32_t const &a, 192 | uint32_t const &b) 193 | { 194 | uint32_t tmp2 = ~b; 195 | uint32_t tmp = 196 | ((a & tmp2) + (((a ^ tmp2) >> 1) & 0x7f7f7f7f)) & 0x80808080; 197 | 198 | return ((tmp >> 7) + 0x7f7f7f7f) ^ 0x7f7f7f7f; 199 | } 200 | 201 | inline uint32_t packed_bytes_add( 202 | uint32_t const &a, 203 | uint32_t const &b) 204 | { 205 | return a + b - ((((a & b) << 1) + ((a ^ b) & 0xfefefefe)) & 0x01010100); 206 | } 207 | 208 | inline uint32_t med( 209 | uint32_t const &a, 210 | uint32_t const &b, 211 | uint32_t const &c, 212 | uint32_t const &v) 213 | { 214 | uint32_t aa_gt_bb = make_gt_mask(a, b); 215 | uint32_t a_xor_b_and_aa_gt_bb = ((a ^ b) & aa_gt_bb); 216 | uint32_t aa = a_xor_b_and_aa_gt_bb ^ a; 217 | uint32_t bb = a_xor_b_and_aa_gt_bb ^ b; 218 | uint32_t n = make_gt_mask(c, bb); 219 | uint32_t nn = make_gt_mask(aa, c); 220 | uint32_t m = ~(n | nn); 221 | return packed_bytes_add((n & aa) | (nn & bb) | ((bb & m) - (c & m) + (aa & m)), v); 222 | } 223 | 224 | inline uint32_t avg( 225 | uint32_t const &a, 226 | uint32_t const &b, 227 | uint32_t const &c, 228 | uint32_t const &v) 229 | { 230 | return packed_bytes_add((a & b) 231 | + (((a ^ b) & 0xfefefefe) >> 1) 232 | + ((a ^ b) & 0x01010101), v); 233 | } 234 | 235 | void init_table() 236 | { 237 | short golomb_compression_table[golomb_n_count][9] = 238 | { 239 | {3, 7, 15, 27, 63, 108, 223, 448, 130, }, 240 | {3, 5, 13, 24, 51, 95, 192, 384, 257, }, 241 | {2, 5, 12, 21, 39, 86, 155, 320, 384, }, 242 | {2, 3, 9, 18, 33, 61, 129, 258, 511, }, 243 | }; 244 | 245 | for (int i = 0; i < leading_zero_table_size; i ++) 246 | { 247 | int cnt = 0; 248 | int j = 1; 249 | 250 | while (j != leading_zero_table_size && !(i & j)) 251 | { 252 | j <<= 1; 253 | cnt ++; 254 | } 255 | 256 | cnt ++; 257 | 258 | if (j == leading_zero_table_size) 259 | cnt = 0; 260 | 261 | leading_zero_table[i] = cnt; 262 | } 263 | 264 | for (int n = 0; n < golomb_n_count; n ++) 265 | { 266 | int a = 0; 267 | for (int i = 0; i < 9; i ++) 268 | { 269 | for (int j = 0; j < golomb_compression_table[n][i]; j ++) 270 | { 271 | golomb_bit_length_table[a ++][n] = i; 272 | } 273 | } 274 | } 275 | } 276 | 277 | void decode_golomb_values(uint8_t *pixel_buf, int pixel_count, uint8_t *bit_pool) 278 | { 279 | int n = golomb_n_count - 1; 280 | int a = 0; 281 | 282 | int bit_pos = 1; 283 | uint8_t zero = (*bit_pool & 1) ? 0 : 1; 284 | uint8_t *limit = pixel_buf + pixel_count * 4; 285 | 286 | while (pixel_buf < limit) 287 | { 288 | int count; 289 | { 290 | uint32_t t = *(uint32_t*)(bit_pool) >> bit_pos; 291 | int b = leading_zero_table[t & (leading_zero_table_size - 1)]; 292 | int bit_count = b; 293 | while (!b) 294 | { 295 | bit_count += leading_zero_table_bits; 296 | bit_pos += leading_zero_table_bits; 297 | bit_pool += bit_pos >> 3; 298 | bit_pos &= 7; 299 | t = *(uint32_t*)(bit_pool) >> bit_pos; 300 | b = leading_zero_table[t & (leading_zero_table_size - 1)]; 301 | bit_count += b; 302 | } 303 | 304 | bit_pos += b; 305 | bit_pool += bit_pos >> 3; 306 | bit_pos &= 7; 307 | 308 | bit_count --; 309 | count = 1 << bit_count; 310 | t = *(uint32_t*)(bit_pool); 311 | count += ((t >> bit_pos) & (count - 1)); 312 | 313 | bit_pos += bit_count; 314 | bit_pool += bit_pos >> 3; 315 | bit_pos &= 7; 316 | } 317 | 318 | if (zero) 319 | { 320 | do 321 | { 322 | *pixel_buf = 0; 323 | pixel_buf += 4; 324 | } 325 | while (-- count); 326 | } 327 | else 328 | { 329 | do 330 | { 331 | int bit_count; 332 | int b; 333 | 334 | uint32_t t = *(uint32_t*)(bit_pool) >> bit_pos; 335 | if (t) 336 | { 337 | b = leading_zero_table[t & (leading_zero_table_size - 1)]; 338 | bit_count = b; 339 | while (!b) 340 | { 341 | bit_count += leading_zero_table_bits; 342 | bit_pos += leading_zero_table_bits; 343 | bit_pool += bit_pos >> 3; 344 | bit_pos &= 7; 345 | t = *(uint32_t*)(bit_pool) >> bit_pos; 346 | b = leading_zero_table[t & (leading_zero_table_size - 1)]; 347 | bit_count += b; 348 | } 349 | bit_count --; 350 | } 351 | else 352 | { 353 | bit_pool += 5; 354 | bit_count = bit_pool[-1]; 355 | bit_pos = 0; 356 | t = *(uint32_t*)(bit_pool); 357 | b = 0; 358 | } 359 | 360 | int k = golomb_bit_length_table[a][n]; 361 | int v = (bit_count << k) + ((t >> b) & ((1 << k) - 1)); 362 | int sign = (v & 1) - 1; 363 | v >>= 1; 364 | a += v; 365 | 366 | *(uint8_t*)pixel_buf = ((v ^ sign) + sign + 1); 367 | pixel_buf += 4; 368 | 369 | bit_pos += b; 370 | bit_pos += k; 371 | bit_pool += bit_pos >> 3; 372 | bit_pos &= 7; 373 | 374 | if (-- n < 0) 375 | { 376 | a >>= 1; 377 | n = golomb_n_count - 1; 378 | } 379 | } 380 | while (-- count); 381 | } 382 | 383 | zero ^= 1; 384 | } 385 | } 386 | 387 | void decode_line( 388 | uint32_t *prev_line, 389 | uint32_t *current_line, 390 | int width, 391 | int start_block, 392 | int block_limit, 393 | uint8_t *filter_types, 394 | int skip_block_bytes, 395 | uint32_t *in, 396 | uint32_t initialp, 397 | int odd_skip, 398 | int dir, 399 | int channel_count) 400 | { 401 | uint32_t p, up; 402 | int step, i; 403 | 404 | if (start_block) 405 | { 406 | prev_line += start_block * w_block_size; 407 | current_line += start_block * w_block_size; 408 | p = current_line[-1]; 409 | up = prev_line[-1]; 410 | } 411 | else 412 | { 413 | p = up = initialp; 414 | } 415 | 416 | in += skip_block_bytes * start_block; 417 | step = (dir & 1) ? 1 : -1; 418 | 419 | for (i = start_block; i < block_limit; i ++) 420 | { 421 | int w = width - i * w_block_size; 422 | if (w > w_block_size) 423 | w = w_block_size; 424 | 425 | int ww = w; 426 | if (step == -1) 427 | in += ww - 1; 428 | 429 | if (i & 1) 430 | in += odd_skip * ww; 431 | 432 | uint32_t (*filter)( 433 | uint32_t const &, 434 | uint32_t const &, 435 | uint32_t const &, 436 | uint32_t const &) 437 | = filter_types[i] & 1 ? &avg : &med; 438 | 439 | void (*transformer)(uint8_t &, uint8_t &, uint8_t &) 440 | = transformers[filter_types[i] >> 1]; 441 | 442 | do 443 | { 444 | uint8_t a = (*in >> 24) & 0xff; 445 | uint8_t r = (*in >> 16) & 0xff; 446 | uint8_t g = (*in >> 8) & 0xff; 447 | uint8_t b = (*in) & 0xff; 448 | 449 | transformer(r, g, b); 450 | 451 | uint32_t u = *prev_line; 452 | p = filter( 453 | p, 454 | u, 455 | up, 456 | (0xff0000 & (b << 16)) 457 | + (0xff00 & (g << 8)) 458 | + (0xff & r) + (a << 24)); 459 | 460 | if (channel_count == 3) 461 | p |= 0xff000000; 462 | 463 | up = u; 464 | *current_line = p; 465 | 466 | current_line ++; 467 | prev_line ++; 468 | in += step; 469 | } 470 | while (-- w); 471 | 472 | in += skip_block_bytes + (step == 1 ? - ww : 1); 473 | if (i & 1) 474 | in -= odd_skip * ww; 475 | } 476 | } 477 | } 478 | 479 | const std::string Tlg6Reader::get_magic() const 480 | { 481 | return std::string("\x54\x4c\x47\x36\x2e\x30\x00\x72\x61\x77\x1a", 11); 482 | } 483 | 484 | const Image Tlg6Reader::read_raw_data(std::ifstream &ifs) const 485 | { 486 | Tlg6Header header; 487 | header.read(ifs); 488 | if (header.channel_count != 1 489 | && header.channel_count != 3 490 | && header.channel_count != 4) 491 | { 492 | throw std::runtime_error("Unsupported channel count"); 493 | } 494 | 495 | Tlg6FilterTypes filter_types; 496 | filter_types.read(ifs); 497 | filter_types.decompress(header); 498 | 499 | Image image; 500 | image.width = header.image_width; 501 | image.height = header.image_height; 502 | image.pixels = new uint32_t[image.width * image.height]; 503 | 504 | uint32_t *pixel_buf = new uint32_t[4 * header.image_width * h_block_size]; 505 | uint32_t *zero_line = new uint32_t[header.image_width]; 506 | uint32_t *prev_line = zero_line; 507 | for (uint32_t i = 0; i < header.image_width; i ++) 508 | zero_line[i] = 0; 509 | 510 | init_table(); 511 | uint32_t main_count = header.image_width / w_block_size; 512 | int fraction = header.image_width - main_count * w_block_size; 513 | for (uint32_t y = 0; y < header.image_height; y += h_block_size) 514 | { 515 | uint32_t ylim = y + h_block_size; 516 | if (ylim >= header.image_height) 517 | ylim = header.image_height; 518 | 519 | int pixel_count = (ylim - y) * header.image_width; 520 | for (int c = 0; c < header.channel_count; c ++) 521 | { 522 | uint32_t bit_length; 523 | ifs.read((char*) &bit_length, 4); 524 | 525 | int method = (bit_length >> 30) & 3; 526 | bit_length &= 0x3fffffff; 527 | 528 | int byte_length = bit_length / 8; 529 | if (bit_length % 8) 530 | byte_length ++; 531 | 532 | uint8_t *bit_pool = new uint8_t[byte_length]; 533 | ifs.read((char*) bit_pool, byte_length); 534 | 535 | if (method == 0) 536 | { 537 | decode_golomb_values((uint8_t*)pixel_buf + c, pixel_count, bit_pool); 538 | } 539 | else 540 | { 541 | throw std::runtime_error("Unsupported encoding method"); 542 | } 543 | } 544 | 545 | uint8_t *ft = filter_types.data.get() + (y / h_block_size) * header.x_block_count; 546 | int skip_bytes = (ylim - y) * w_block_size; 547 | 548 | for (uint32_t yy = y; yy < ylim; yy ++) 549 | { 550 | uint32_t *current_line = &image.pixels[yy * image.width]; 551 | 552 | int dir = (yy & 1) ^ 1; 553 | int odd_skip = ((ylim - yy -1) - (yy - y)); 554 | 555 | if (main_count) 556 | { 557 | int start = ((header.image_width < w_block_size) 558 | ? header.image_width 559 | : w_block_size) * (yy - y); 560 | 561 | decode_line( 562 | prev_line, 563 | current_line, 564 | header.image_width, 565 | 0, 566 | main_count, 567 | ft, 568 | skip_bytes, 569 | pixel_buf + start, 570 | header.channel_count == 3 571 | ? 0xff000000 572 | : 0, 573 | odd_skip, 574 | dir, 575 | header.channel_count); 576 | } 577 | 578 | if (main_count != header.x_block_count) 579 | { 580 | int ww = fraction; 581 | if (ww > w_block_size) 582 | ww = w_block_size; 583 | 584 | int start = ww * (yy - y); 585 | decode_line( 586 | prev_line, 587 | current_line, 588 | header.image_width, 589 | main_count, 590 | header.x_block_count, 591 | ft, 592 | skip_bytes, 593 | pixel_buf + start, 594 | header.channel_count == 3 595 | ? 0xff000000 596 | : 0, 597 | odd_skip, 598 | dir, 599 | header.channel_count); 600 | } 601 | 602 | prev_line = current_line; 603 | } 604 | } 605 | 606 | return image; 607 | } 608 | -------------------------------------------------------------------------------- /3rdparty/3rdparty_src/tlg2png/Tlg6Reader.h: -------------------------------------------------------------------------------- 1 | #ifndef TLG6_READER_H_ 2 | #define TLG6_READER_H_ 3 | #include "AbstractTlgReader.h" 4 | 5 | class Tlg6Reader : public AbstractTlgReader 6 | { 7 | public: 8 | virtual const std::string get_magic() const; 9 | 10 | private: 11 | virtual const Image read_raw_data(std::ifstream &stream) const; 12 | }; 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /3rdparty/3rdparty_src/tlg2png/TlgConverter.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "BadMagicException.h" 6 | #include "TlgConverter.h" 7 | #include "AbstractTlgReader.h" 8 | #include "Tlg0Reader.h" 9 | #include "Tlg5Reader.h" 10 | #include "Tlg6Reader.h" 11 | 12 | const Image TlgConverter::read(std::string path) const 13 | { 14 | std::ifstream ifs(path, std::ifstream::in | std::ifstream::binary); 15 | if (!ifs) 16 | throw std::runtime_error("Can\'t open " + path + " for reading"); 17 | 18 | try 19 | { 20 | auto reader = AbstractTlgReader::choose_reader(ifs); 21 | auto ret = reader->read(path); 22 | ifs.close(); 23 | return ret; 24 | } 25 | catch (std::exception const &e) 26 | { 27 | ifs.close(); 28 | throw; 29 | } 30 | } 31 | 32 | void TlgConverter::save(const Image image, std::string path) const 33 | { 34 | FILE *fp = fopen(path.c_str(), "wb"); 35 | if (fp == nullptr) 36 | throw std::runtime_error("Could not open " + path + " for writing"); 37 | 38 | png_structp png_ptr = nullptr; 39 | png_infop info_ptr = nullptr; 40 | try 41 | { 42 | auto png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); 43 | if (png_ptr == nullptr) 44 | throw std::runtime_error("Could not allocate write struct\n"); 45 | 46 | auto info_ptr = png_create_info_struct(png_ptr); 47 | if (info_ptr == nullptr) 48 | throw std::runtime_error("Could not allocate info struct\n"); 49 | 50 | png_init_io(png_ptr, fp); 51 | 52 | if (setjmp(png_jmpbuf(png_ptr))) 53 | throw std::runtime_error("Error during PNG creation\n"); 54 | 55 | // Write header (8 bit colour depth) 56 | png_set_IHDR( 57 | png_ptr, 58 | info_ptr, 59 | image.width, 60 | image.height, 61 | 8, 62 | PNG_COLOR_TYPE_RGBA, 63 | PNG_INTERLACE_NONE, 64 | PNG_COMPRESSION_TYPE_BASE, 65 | PNG_FILTER_TYPE_BASE); 66 | 67 | // 0 = no compression, 9 = max compression 68 | // 1 produces good file size and is still fast. 69 | png_set_compression_level(png_ptr, 1); 70 | 71 | png_write_info(png_ptr, info_ptr); 72 | 73 | for (uint32_t y = 0; y < image.height; y ++) 74 | { 75 | png_write_row(png_ptr, (png_bytep) &image.pixels[y * image.width]); 76 | } 77 | 78 | png_write_end(png_ptr, nullptr); 79 | } 80 | catch (std::exception const &e) 81 | { 82 | if (info_ptr != nullptr) 83 | png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); 84 | if (png_ptr != nullptr) 85 | png_destroy_write_struct(&png_ptr, (png_infopp)NULL); 86 | 87 | fclose(fp); 88 | throw; 89 | } 90 | // *** zzyy21 added on 2020-07-06 91 | // *** close file after writing, avoid read 92 | // *** incomplete files during subsequent operations 93 | fclose(fp); 94 | // *** end of zzyy21's modify 95 | } 96 | -------------------------------------------------------------------------------- /3rdparty/include/opencv2/core/bufferpool.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | // 5 | // Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved. 6 | 7 | #ifndef OPENCV_CORE_BUFFER_POOL_HPP 8 | #define OPENCV_CORE_BUFFER_POOL_HPP 9 | 10 | #ifdef _MSC_VER 11 | #pragma warning(push) 12 | #pragma warning(disable: 4265) 13 | #endif 14 | 15 | namespace cv 16 | { 17 | 18 | //! @addtogroup core 19 | //! @{ 20 | 21 | class BufferPoolController 22 | { 23 | protected: 24 | ~BufferPoolController() { } 25 | public: 26 | virtual size_t getReservedSize() const = 0; 27 | virtual size_t getMaxReservedSize() const = 0; 28 | virtual void setMaxReservedSize(size_t size) = 0; 29 | virtual void freeAllReservedBuffers() = 0; 30 | }; 31 | 32 | //! @} 33 | 34 | } 35 | 36 | #ifdef _MSC_VER 37 | #pragma warning(pop) 38 | #endif 39 | 40 | #endif // OPENCV_CORE_BUFFER_POOL_HPP 41 | -------------------------------------------------------------------------------- /3rdparty/include/opencv2/core/check.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | 5 | #ifndef OPENCV_CORE_CHECK_HPP 6 | #define OPENCV_CORE_CHECK_HPP 7 | 8 | #include 9 | 10 | namespace cv { 11 | 12 | /** Returns string of cv::Mat depth value: CV_8U -> "CV_8U" or "" */ 13 | CV_EXPORTS const char* depthToString(int depth); 14 | 15 | /** Returns string of cv::Mat depth value: CV_8UC3 -> "CV_8UC3" or "" */ 16 | CV_EXPORTS const String typeToString(int type); 17 | 18 | 19 | //! @cond IGNORED 20 | namespace detail { 21 | 22 | /** Returns string of cv::Mat depth value: CV_8U -> "CV_8U" or NULL */ 23 | CV_EXPORTS const char* depthToString_(int depth); 24 | 25 | /** Returns string of cv::Mat depth value: CV_8UC3 -> "CV_8UC3" or cv::String() */ 26 | CV_EXPORTS const cv::String typeToString_(int type); 27 | 28 | enum TestOp { 29 | TEST_CUSTOM = 0, 30 | TEST_EQ = 1, 31 | TEST_NE = 2, 32 | TEST_LE = 3, 33 | TEST_LT = 4, 34 | TEST_GE = 5, 35 | TEST_GT = 6, 36 | CV__LAST_TEST_OP 37 | }; 38 | 39 | struct CheckContext { 40 | const char* func; 41 | const char* file; 42 | int line; 43 | enum TestOp testOp; 44 | const char* message; 45 | const char* p1_str; 46 | const char* p2_str; 47 | }; 48 | 49 | #ifndef CV__CHECK_FILENAME 50 | # define CV__CHECK_FILENAME __FILE__ 51 | #endif 52 | 53 | #ifndef CV__CHECK_FUNCTION 54 | # if defined _MSC_VER 55 | # define CV__CHECK_FUNCTION __FUNCSIG__ 56 | # elif defined __GNUC__ 57 | # define CV__CHECK_FUNCTION __PRETTY_FUNCTION__ 58 | # else 59 | # define CV__CHECK_FUNCTION "" 60 | # endif 61 | #endif 62 | 63 | #define CV__CHECK_LOCATION_VARNAME(id) CVAUX_CONCAT(CVAUX_CONCAT(__cv_check_, id), __LINE__) 64 | #define CV__DEFINE_CHECK_CONTEXT(id, message, testOp, p1_str, p2_str) \ 65 | static const cv::detail::CheckContext CV__CHECK_LOCATION_VARNAME(id) = \ 66 | { CV__CHECK_FUNCTION, CV__CHECK_FILENAME, __LINE__, testOp, message, p1_str, p2_str } 67 | 68 | CV_EXPORTS void CV_NORETURN check_failed_auto(const int v1, const int v2, const CheckContext& ctx); 69 | CV_EXPORTS void CV_NORETURN check_failed_auto(const size_t v1, const size_t v2, const CheckContext& ctx); 70 | CV_EXPORTS void CV_NORETURN check_failed_auto(const float v1, const float v2, const CheckContext& ctx); 71 | CV_EXPORTS void CV_NORETURN check_failed_auto(const double v1, const double v2, const CheckContext& ctx); 72 | CV_EXPORTS void CV_NORETURN check_failed_auto(const Size_ v1, const Size_ v2, const CheckContext& ctx); 73 | CV_EXPORTS void CV_NORETURN check_failed_MatDepth(const int v1, const int v2, const CheckContext& ctx); 74 | CV_EXPORTS void CV_NORETURN check_failed_MatType(const int v1, const int v2, const CheckContext& ctx); 75 | CV_EXPORTS void CV_NORETURN check_failed_MatChannels(const int v1, const int v2, const CheckContext& ctx); 76 | 77 | CV_EXPORTS void CV_NORETURN check_failed_auto(const int v, const CheckContext& ctx); 78 | CV_EXPORTS void CV_NORETURN check_failed_auto(const size_t v, const CheckContext& ctx); 79 | CV_EXPORTS void CV_NORETURN check_failed_auto(const float v, const CheckContext& ctx); 80 | CV_EXPORTS void CV_NORETURN check_failed_auto(const double v, const CheckContext& ctx); 81 | CV_EXPORTS void CV_NORETURN check_failed_auto(const Size_ v, const CheckContext& ctx); 82 | CV_EXPORTS void CV_NORETURN check_failed_auto(const std::string& v1, const CheckContext& ctx); 83 | CV_EXPORTS void CV_NORETURN check_failed_MatDepth(const int v, const CheckContext& ctx); 84 | CV_EXPORTS void CV_NORETURN check_failed_MatType(const int v, const CheckContext& ctx); 85 | CV_EXPORTS void CV_NORETURN check_failed_MatChannels(const int v, const CheckContext& ctx); 86 | 87 | 88 | #define CV__TEST_EQ(v1, v2) ((v1) == (v2)) 89 | #define CV__TEST_NE(v1, v2) ((v1) != (v2)) 90 | #define CV__TEST_LE(v1, v2) ((v1) <= (v2)) 91 | #define CV__TEST_LT(v1, v2) ((v1) < (v2)) 92 | #define CV__TEST_GE(v1, v2) ((v1) >= (v2)) 93 | #define CV__TEST_GT(v1, v2) ((v1) > (v2)) 94 | 95 | #define CV__CHECK(id, op, type, v1, v2, v1_str, v2_str, msg_str) do { \ 96 | if(CV__TEST_##op((v1), (v2))) ; else { \ 97 | CV__DEFINE_CHECK_CONTEXT(id, msg_str, cv::detail::TEST_ ## op, v1_str, v2_str); \ 98 | cv::detail::check_failed_ ## type((v1), (v2), CV__CHECK_LOCATION_VARNAME(id)); \ 99 | } \ 100 | } while (0) 101 | 102 | #define CV__CHECK_CUSTOM_TEST(id, type, v, test_expr, v_str, test_expr_str, msg_str) do { \ 103 | if(!!(test_expr)) ; else { \ 104 | CV__DEFINE_CHECK_CONTEXT(id, msg_str, cv::detail::TEST_CUSTOM, v_str, test_expr_str); \ 105 | cv::detail::check_failed_ ## type((v), CV__CHECK_LOCATION_VARNAME(id)); \ 106 | } \ 107 | } while (0) 108 | 109 | } // namespace 110 | //! @endcond 111 | 112 | 113 | /// Supported values of these types: int, float, double 114 | #define CV_CheckEQ(v1, v2, msg) CV__CHECK(_, EQ, auto, v1, v2, #v1, #v2, msg) 115 | #define CV_CheckNE(v1, v2, msg) CV__CHECK(_, NE, auto, v1, v2, #v1, #v2, msg) 116 | #define CV_CheckLE(v1, v2, msg) CV__CHECK(_, LE, auto, v1, v2, #v1, #v2, msg) 117 | #define CV_CheckLT(v1, v2, msg) CV__CHECK(_, LT, auto, v1, v2, #v1, #v2, msg) 118 | #define CV_CheckGE(v1, v2, msg) CV__CHECK(_, GE, auto, v1, v2, #v1, #v2, msg) 119 | #define CV_CheckGT(v1, v2, msg) CV__CHECK(_, GT, auto, v1, v2, #v1, #v2, msg) 120 | 121 | /// Check with additional "decoding" of type values in error message 122 | #define CV_CheckTypeEQ(t1, t2, msg) CV__CHECK(_, EQ, MatType, t1, t2, #t1, #t2, msg) 123 | /// Check with additional "decoding" of depth values in error message 124 | #define CV_CheckDepthEQ(d1, d2, msg) CV__CHECK(_, EQ, MatDepth, d1, d2, #d1, #d2, msg) 125 | 126 | #define CV_CheckChannelsEQ(c1, c2, msg) CV__CHECK(_, EQ, MatChannels, c1, c2, #c1, #c2, msg) 127 | 128 | /// Example: type == CV_8UC1 || type == CV_8UC3 129 | #define CV_CheckType(t, test_expr, msg) CV__CHECK_CUSTOM_TEST(_, MatType, t, (test_expr), #t, #test_expr, msg) 130 | 131 | /// Example: depth == CV_32F || depth == CV_64F 132 | #define CV_CheckDepth(t, test_expr, msg) CV__CHECK_CUSTOM_TEST(_, MatDepth, t, (test_expr), #t, #test_expr, msg) 133 | 134 | /// Example: v == A || v == B 135 | #define CV_Check(v, test_expr, msg) CV__CHECK_CUSTOM_TEST(_, auto, v, (test_expr), #v, #test_expr, msg) 136 | 137 | /// Some complex conditions: CV_Check(src2, src2.empty() || (src2.type() == src1.type() && src2.size() == src1.size()), "src2 should have same size/type as src1") 138 | // TODO define pretty-printers 139 | 140 | #ifndef NDEBUG 141 | #define CV_DbgCheck(v, test_expr, msg) CV__CHECK_CUSTOM_TEST(_, auto, v, (test_expr), #v, #test_expr, msg) 142 | #define CV_DbgCheckEQ(v1, v2, msg) CV__CHECK(_, EQ, auto, v1, v2, #v1, #v2, msg) 143 | #define CV_DbgCheckNE(v1, v2, msg) CV__CHECK(_, NE, auto, v1, v2, #v1, #v2, msg) 144 | #define CV_DbgCheckLE(v1, v2, msg) CV__CHECK(_, LE, auto, v1, v2, #v1, #v2, msg) 145 | #define CV_DbgCheckLT(v1, v2, msg) CV__CHECK(_, LT, auto, v1, v2, #v1, #v2, msg) 146 | #define CV_DbgCheckGE(v1, v2, msg) CV__CHECK(_, GE, auto, v1, v2, #v1, #v2, msg) 147 | #define CV_DbgCheckGT(v1, v2, msg) CV__CHECK(_, GT, auto, v1, v2, #v1, #v2, msg) 148 | #else 149 | #define CV_DbgCheck(v, test_expr, msg) do { } while (0) 150 | #define CV_DbgCheckEQ(v1, v2, msg) do { } while (0) 151 | #define CV_DbgCheckNE(v1, v2, msg) do { } while (0) 152 | #define CV_DbgCheckLE(v1, v2, msg) do { } while (0) 153 | #define CV_DbgCheckLT(v1, v2, msg) do { } while (0) 154 | #define CV_DbgCheckGE(v1, v2, msg) do { } while (0) 155 | #define CV_DbgCheckGT(v1, v2, msg) do { } while (0) 156 | #endif 157 | 158 | } // namespace 159 | 160 | #endif // OPENCV_CORE_CHECK_HPP 161 | -------------------------------------------------------------------------------- /3rdparty/include/opencv2/core/cv_cpu_dispatch.h: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | 5 | #if defined __OPENCV_BUILD \ 6 | 7 | #include "cv_cpu_config.h" 8 | #include "cv_cpu_helper.h" 9 | 10 | #ifdef CV_CPU_DISPATCH_MODE 11 | #define CV_CPU_OPTIMIZATION_NAMESPACE __CV_CAT(opt_, CV_CPU_DISPATCH_MODE) 12 | #define CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN namespace __CV_CAT(opt_, CV_CPU_DISPATCH_MODE) { 13 | #define CV_CPU_OPTIMIZATION_NAMESPACE_END } 14 | #else 15 | #define CV_CPU_OPTIMIZATION_NAMESPACE cpu_baseline 16 | #define CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN namespace cpu_baseline { 17 | #define CV_CPU_OPTIMIZATION_NAMESPACE_END } 18 | #define CV_CPU_BASELINE_MODE 1 19 | #endif 20 | 21 | 22 | #define __CV_CPU_DISPATCH_CHAIN_END(fn, args, mode, ...) /* done */ 23 | #define __CV_CPU_DISPATCH(fn, args, mode, ...) __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) 24 | #define __CV_CPU_DISPATCH_EXPAND(fn, args, ...) __CV_EXPAND(__CV_CPU_DISPATCH(fn, args, __VA_ARGS__)) 25 | #define CV_CPU_DISPATCH(fn, args, ...) __CV_CPU_DISPATCH_EXPAND(fn, args, __VA_ARGS__, END) // expand macros 26 | 27 | 28 | #if defined CV_ENABLE_INTRINSICS \ 29 | && !defined CV_DISABLE_OPTIMIZATION \ 30 | && !defined __CUDACC__ /* do not include SSE/AVX/NEON headers for NVCC compiler */ \ 31 | 32 | #ifdef CV_CPU_COMPILE_SSE2 33 | # include 34 | # define CV_MMX 1 35 | # define CV_SSE 1 36 | # define CV_SSE2 1 37 | #endif 38 | #ifdef CV_CPU_COMPILE_SSE3 39 | # include 40 | # define CV_SSE3 1 41 | #endif 42 | #ifdef CV_CPU_COMPILE_SSSE3 43 | # include 44 | # define CV_SSSE3 1 45 | #endif 46 | #ifdef CV_CPU_COMPILE_SSE4_1 47 | # include 48 | # define CV_SSE4_1 1 49 | #endif 50 | #ifdef CV_CPU_COMPILE_SSE4_2 51 | # include 52 | # define CV_SSE4_2 1 53 | #endif 54 | #ifdef CV_CPU_COMPILE_POPCNT 55 | # ifdef _MSC_VER 56 | # include 57 | # if defined(_M_X64) 58 | # define CV_POPCNT_U64 _mm_popcnt_u64 59 | # endif 60 | # define CV_POPCNT_U32 _mm_popcnt_u32 61 | # else 62 | # include 63 | # if defined(__x86_64__) 64 | # define CV_POPCNT_U64 __builtin_popcountll 65 | # endif 66 | # define CV_POPCNT_U32 __builtin_popcount 67 | # endif 68 | # define CV_POPCNT 1 69 | #endif 70 | #ifdef CV_CPU_COMPILE_AVX 71 | # include 72 | # define CV_AVX 1 73 | #endif 74 | #ifdef CV_CPU_COMPILE_FP16 75 | # if defined(__arm__) || defined(__aarch64__) || defined(_M_ARM) || defined(_M_ARM64) 76 | # include 77 | # else 78 | # include 79 | # endif 80 | # define CV_FP16 1 81 | #endif 82 | #ifdef CV_CPU_COMPILE_AVX2 83 | # include 84 | # define CV_AVX2 1 85 | #endif 86 | #ifdef CV_CPU_COMPILE_AVX_512F 87 | # include 88 | # define CV_AVX_512F 1 89 | #endif 90 | #ifdef CV_CPU_COMPILE_AVX512_COMMON 91 | # define CV_AVX512_COMMON 1 92 | # define CV_AVX_512CD 1 93 | #endif 94 | #ifdef CV_CPU_COMPILE_AVX512_KNL 95 | # define CV_AVX512_KNL 1 96 | # define CV_AVX_512ER 1 97 | # define CV_AVX_512PF 1 98 | #endif 99 | #ifdef CV_CPU_COMPILE_AVX512_KNM 100 | # define CV_AVX512_KNM 1 101 | # define CV_AVX_5124FMAPS 1 102 | # define CV_AVX_5124VNNIW 1 103 | # define CV_AVX_512VPOPCNTDQ 1 104 | #endif 105 | #ifdef CV_CPU_COMPILE_AVX512_SKX 106 | # define CV_AVX512_SKX 1 107 | # define CV_AVX_512VL 1 108 | # define CV_AVX_512BW 1 109 | # define CV_AVX_512DQ 1 110 | #endif 111 | #ifdef CV_CPU_COMPILE_AVX512_CNL 112 | # define CV_AVX512_CNL 1 113 | # define CV_AVX_512IFMA 1 114 | # define CV_AVX_512VBMI 1 115 | #endif 116 | #ifdef CV_CPU_COMPILE_AVX512_CLX 117 | # define CV_AVX512_CLX 1 118 | # define CV_AVX_512VNNI 1 119 | #endif 120 | #ifdef CV_CPU_COMPILE_AVX512_ICL 121 | # define CV_AVX512_ICL 1 122 | # undef CV_AVX_512IFMA 123 | # define CV_AVX_512IFMA 1 124 | # undef CV_AVX_512VBMI 125 | # define CV_AVX_512VBMI 1 126 | # undef CV_AVX_512VNNI 127 | # define CV_AVX_512VNNI 1 128 | # define CV_AVX_512VBMI2 1 129 | # define CV_AVX_512BITALG 1 130 | # define CV_AVX_512VPOPCNTDQ 1 131 | #endif 132 | #ifdef CV_CPU_COMPILE_FMA3 133 | # define CV_FMA3 1 134 | #endif 135 | 136 | #if defined _WIN32 && (defined(_M_ARM) || defined(_M_ARM64)) && (defined(CV_CPU_COMPILE_NEON) || !defined(_MSC_VER)) 137 | # include 138 | # include 139 | # define CV_NEON 1 140 | #elif defined(__ARM_NEON__) || (defined (__ARM_NEON) && defined(__aarch64__)) 141 | # include 142 | # define CV_NEON 1 143 | #endif 144 | 145 | #if defined(__ARM_NEON__) || defined(__aarch64__) 146 | # include 147 | #endif 148 | 149 | #ifdef CV_CPU_COMPILE_VSX 150 | # include 151 | # undef vector 152 | # undef pixel 153 | # undef bool 154 | # define CV_VSX 1 155 | #endif 156 | 157 | #ifdef CV_CPU_COMPILE_VSX3 158 | # define CV_VSX3 1 159 | #endif 160 | 161 | #ifdef CV_CPU_COMPILE_MSA 162 | # include "hal/msa_macros.h" 163 | # define CV_MSA 1 164 | #endif 165 | 166 | #ifdef __EMSCRIPTEN__ 167 | # define CV_WASM_SIMD 1 168 | # include 169 | #endif 170 | 171 | #endif // CV_ENABLE_INTRINSICS && !CV_DISABLE_OPTIMIZATION && !__CUDACC__ 172 | 173 | #if defined CV_CPU_COMPILE_AVX && !defined CV_CPU_BASELINE_COMPILE_AVX 174 | struct VZeroUpperGuard { 175 | #ifdef __GNUC__ 176 | __attribute__((always_inline)) 177 | #endif 178 | inline VZeroUpperGuard() { _mm256_zeroupper(); } 179 | #ifdef __GNUC__ 180 | __attribute__((always_inline)) 181 | #endif 182 | inline ~VZeroUpperGuard() { _mm256_zeroupper(); } 183 | }; 184 | #define __CV_AVX_GUARD VZeroUpperGuard __vzeroupper_guard; CV_UNUSED(__vzeroupper_guard); 185 | #endif 186 | 187 | #ifdef __CV_AVX_GUARD 188 | #define CV_AVX_GUARD __CV_AVX_GUARD 189 | #else 190 | #define CV_AVX_GUARD 191 | #endif 192 | 193 | #endif // __OPENCV_BUILD 194 | 195 | 196 | 197 | #if !defined __OPENCV_BUILD /* Compatibility code */ \ 198 | && !defined __CUDACC__ /* do not include SSE/AVX/NEON headers for NVCC compiler */ 199 | #if defined __SSE2__ || defined _M_X64 || (defined _M_IX86_FP && _M_IX86_FP >= 2) 200 | # include 201 | # define CV_MMX 1 202 | # define CV_SSE 1 203 | # define CV_SSE2 1 204 | #elif defined _WIN32 && (defined(_M_ARM) || defined(_M_ARM64)) && (defined(CV_CPU_COMPILE_NEON) || !defined(_MSC_VER)) 205 | # include 206 | # include 207 | # define CV_NEON 1 208 | #elif defined(__ARM_NEON__) || (defined (__ARM_NEON) && defined(__aarch64__)) 209 | # include 210 | # define CV_NEON 1 211 | #elif defined(__VSX__) && defined(__PPC64__) && defined(__LITTLE_ENDIAN__) 212 | # include 213 | # undef vector 214 | # undef pixel 215 | # undef bool 216 | # define CV_VSX 1 217 | #endif 218 | 219 | #endif // !__OPENCV_BUILD && !__CUDACC (Compatibility code) 220 | 221 | 222 | 223 | #ifndef CV_MMX 224 | # define CV_MMX 0 225 | #endif 226 | #ifndef CV_SSE 227 | # define CV_SSE 0 228 | #endif 229 | #ifndef CV_SSE2 230 | # define CV_SSE2 0 231 | #endif 232 | #ifndef CV_SSE3 233 | # define CV_SSE3 0 234 | #endif 235 | #ifndef CV_SSSE3 236 | # define CV_SSSE3 0 237 | #endif 238 | #ifndef CV_SSE4_1 239 | # define CV_SSE4_1 0 240 | #endif 241 | #ifndef CV_SSE4_2 242 | # define CV_SSE4_2 0 243 | #endif 244 | #ifndef CV_POPCNT 245 | # define CV_POPCNT 0 246 | #endif 247 | #ifndef CV_AVX 248 | # define CV_AVX 0 249 | #endif 250 | #ifndef CV_FP16 251 | # define CV_FP16 0 252 | #endif 253 | #ifndef CV_AVX2 254 | # define CV_AVX2 0 255 | #endif 256 | #ifndef CV_FMA3 257 | # define CV_FMA3 0 258 | #endif 259 | #ifndef CV_AVX_512F 260 | # define CV_AVX_512F 0 261 | #endif 262 | #ifndef CV_AVX_512BW 263 | # define CV_AVX_512BW 0 264 | #endif 265 | #ifndef CV_AVX_512CD 266 | # define CV_AVX_512CD 0 267 | #endif 268 | #ifndef CV_AVX_512DQ 269 | # define CV_AVX_512DQ 0 270 | #endif 271 | #ifndef CV_AVX_512ER 272 | # define CV_AVX_512ER 0 273 | #endif 274 | #ifndef CV_AVX_512IFMA 275 | # define CV_AVX_512IFMA 0 276 | #endif 277 | #define CV_AVX_512IFMA512 CV_AVX_512IFMA // deprecated 278 | #ifndef CV_AVX_512PF 279 | # define CV_AVX_512PF 0 280 | #endif 281 | #ifndef CV_AVX_512VBMI 282 | # define CV_AVX_512VBMI 0 283 | #endif 284 | #ifndef CV_AVX_512VL 285 | # define CV_AVX_512VL 0 286 | #endif 287 | #ifndef CV_AVX_5124FMAPS 288 | # define CV_AVX_5124FMAPS 0 289 | #endif 290 | #ifndef CV_AVX_5124VNNIW 291 | # define CV_AVX_5124VNNIW 0 292 | #endif 293 | #ifndef CV_AVX_512VPOPCNTDQ 294 | # define CV_AVX_512VPOPCNTDQ 0 295 | #endif 296 | #ifndef CV_AVX_512VNNI 297 | # define CV_AVX_512VNNI 0 298 | #endif 299 | #ifndef CV_AVX_512VBMI2 300 | # define CV_AVX_512VBMI2 0 301 | #endif 302 | #ifndef CV_AVX_512BITALG 303 | # define CV_AVX_512BITALG 0 304 | #endif 305 | #ifndef CV_AVX512_COMMON 306 | # define CV_AVX512_COMMON 0 307 | #endif 308 | #ifndef CV_AVX512_KNL 309 | # define CV_AVX512_KNL 0 310 | #endif 311 | #ifndef CV_AVX512_KNM 312 | # define CV_AVX512_KNM 0 313 | #endif 314 | #ifndef CV_AVX512_SKX 315 | # define CV_AVX512_SKX 0 316 | #endif 317 | #ifndef CV_AVX512_CNL 318 | # define CV_AVX512_CNL 0 319 | #endif 320 | #ifndef CV_AVX512_CLX 321 | # define CV_AVX512_CLX 0 322 | #endif 323 | #ifndef CV_AVX512_ICL 324 | # define CV_AVX512_ICL 0 325 | #endif 326 | 327 | #ifndef CV_NEON 328 | # define CV_NEON 0 329 | #endif 330 | 331 | #ifndef CV_VSX 332 | # define CV_VSX 0 333 | #endif 334 | 335 | #ifndef CV_VSX3 336 | # define CV_VSX3 0 337 | #endif 338 | 339 | #ifndef CV_MSA 340 | # define CV_MSA 0 341 | #endif 342 | 343 | #ifndef CV_WASM_SIMD 344 | # define CV_WASM_SIMD 0 345 | #endif 346 | -------------------------------------------------------------------------------- /3rdparty/include/opencv2/core/cvstd.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 | // Copyright (C) 2013, OpenCV Foundation, all rights reserved. 16 | // Third party copyrights are property of their respective owners. 17 | // 18 | // Redistribution and use in source and binary forms, with or without modification, 19 | // are permitted provided that the following conditions are met: 20 | // 21 | // * Redistribution's of source code must retain the above copyright notice, 22 | // this list of conditions and the following disclaimer. 23 | // 24 | // * Redistribution's in binary form must reproduce the above copyright notice, 25 | // this list of conditions and the following disclaimer in the documentation 26 | // and/or other materials provided with the distribution. 27 | // 28 | // * The name of the copyright holders may not be used to endorse or promote products 29 | // derived from this software without specific prior written permission. 30 | // 31 | // This software is provided by the copyright holders and contributors "as is" and 32 | // any express or implied warranties, including, but not limited to, the implied 33 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 34 | // In no event shall the Intel Corporation or contributors be liable for any direct, 35 | // indirect, incidental, special, exemplary, or consequential damages 36 | // (including, but not limited to, procurement of substitute goods or services; 37 | // loss of use, data, or profits; or business interruption) however caused 38 | // and on any theory of liability, whether in contract, strict liability, 39 | // or tort (including negligence or otherwise) arising in any way out of 40 | // the use of this software, even if advised of the possibility of such damage. 41 | // 42 | //M*/ 43 | 44 | #ifndef OPENCV_CORE_CVSTD_HPP 45 | #define OPENCV_CORE_CVSTD_HPP 46 | 47 | #ifndef __cplusplus 48 | # error cvstd.hpp header must be compiled as C++ 49 | #endif 50 | 51 | #include "opencv2/core/cvdef.h" 52 | #include 53 | #include 54 | #include 55 | 56 | #include 57 | 58 | // import useful primitives from stl 59 | # include 60 | # include 61 | # include //for abs(int) 62 | # include 63 | 64 | namespace cv 65 | { 66 | static inline uchar abs(uchar a) { return a; } 67 | static inline ushort abs(ushort a) { return a; } 68 | static inline unsigned abs(unsigned a) { return a; } 69 | static inline uint64 abs(uint64 a) { return a; } 70 | 71 | using std::min; 72 | using std::max; 73 | using std::abs; 74 | using std::swap; 75 | using std::sqrt; 76 | using std::exp; 77 | using std::pow; 78 | using std::log; 79 | } 80 | 81 | #include "cvstd_wrapper.hpp" 82 | 83 | namespace cv { 84 | 85 | //! @addtogroup core_utils 86 | //! @{ 87 | 88 | //////////////////////////// memory management functions //////////////////////////// 89 | 90 | /** @brief Allocates an aligned memory buffer. 91 | 92 | The function allocates the buffer of the specified size and returns it. When the buffer size is 16 93 | bytes or more, the returned buffer is aligned to 16 bytes. 94 | @param bufSize Allocated buffer size. 95 | */ 96 | CV_EXPORTS void* fastMalloc(size_t bufSize); 97 | 98 | /** @brief Deallocates a memory buffer. 99 | 100 | The function deallocates the buffer allocated with fastMalloc . If NULL pointer is passed, the 101 | function does nothing. C version of the function clears the pointer *pptr* to avoid problems with 102 | double memory deallocation. 103 | @param ptr Pointer to the allocated buffer. 104 | */ 105 | CV_EXPORTS void fastFree(void* ptr); 106 | 107 | /*! 108 | The STL-compliant memory Allocator based on cv::fastMalloc() and cv::fastFree() 109 | */ 110 | template class Allocator 111 | { 112 | public: 113 | typedef _Tp value_type; 114 | typedef value_type* pointer; 115 | typedef const value_type* const_pointer; 116 | typedef value_type& reference; 117 | typedef const value_type& const_reference; 118 | typedef size_t size_type; 119 | typedef ptrdiff_t difference_type; 120 | template class rebind { typedef Allocator other; }; 121 | 122 | explicit Allocator() {} 123 | ~Allocator() {} 124 | explicit Allocator(Allocator const&) {} 125 | template 126 | explicit Allocator(Allocator const&) {} 127 | 128 | // address 129 | pointer address(reference r) { return &r; } 130 | const_pointer address(const_reference r) { return &r; } 131 | 132 | pointer allocate(size_type count, const void* =0) { return reinterpret_cast(fastMalloc(count * sizeof (_Tp))); } 133 | void deallocate(pointer p, size_type) { fastFree(p); } 134 | 135 | void construct(pointer p, const _Tp& v) { new(static_cast(p)) _Tp(v); } 136 | void destroy(pointer p) { p->~_Tp(); } 137 | 138 | size_type max_size() const { return cv::max(static_cast<_Tp>(-1)/sizeof(_Tp), 1); } 139 | }; 140 | 141 | //! @} core_utils 142 | 143 | //! @endcond 144 | 145 | //! @addtogroup core_basic 146 | //! @{ 147 | 148 | //////////////////////////////// string class //////////////////////////////// 149 | 150 | class CV_EXPORTS FileNode; //for string constructor from FileNode 151 | 152 | typedef std::string String; 153 | 154 | #ifndef OPENCV_DISABLE_STRING_LOWER_UPPER_CONVERSIONS 155 | 156 | //! @cond IGNORED 157 | namespace details { 158 | // std::tolower is int->int 159 | static inline char char_tolower(char ch) 160 | { 161 | return (char)std::tolower((int)ch); 162 | } 163 | // std::toupper is int->int 164 | static inline char char_toupper(char ch) 165 | { 166 | return (char)std::toupper((int)ch); 167 | } 168 | } // namespace details 169 | //! @endcond 170 | 171 | static inline std::string toLowerCase(const std::string& str) 172 | { 173 | std::string result(str); 174 | std::transform(result.begin(), result.end(), result.begin(), details::char_tolower); 175 | return result; 176 | } 177 | 178 | static inline std::string toUpperCase(const std::string& str) 179 | { 180 | std::string result(str); 181 | std::transform(result.begin(), result.end(), result.begin(), details::char_toupper); 182 | return result; 183 | } 184 | 185 | #endif // OPENCV_DISABLE_STRING_LOWER_UPPER_CONVERSIONS 186 | 187 | //! @} core_basic 188 | } // cv 189 | 190 | #endif //OPENCV_CORE_CVSTD_HPP 191 | -------------------------------------------------------------------------------- /3rdparty/include/opencv2/core/cvstd.inl.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 | // Copyright (C) 2013, OpenCV Foundation, all rights reserved. 16 | // Third party copyrights are property of their respective owners. 17 | // 18 | // Redistribution and use in source and binary forms, with or without modification, 19 | // are permitted provided that the following conditions are met: 20 | // 21 | // * Redistribution's of source code must retain the above copyright notice, 22 | // this list of conditions and the following disclaimer. 23 | // 24 | // * Redistribution's in binary form must reproduce the above copyright notice, 25 | // this list of conditions and the following disclaimer in the documentation 26 | // and/or other materials provided with the distribution. 27 | // 28 | // * The name of the copyright holders may not be used to endorse or promote products 29 | // derived from this software without specific prior written permission. 30 | // 31 | // This software is provided by the copyright holders and contributors "as is" and 32 | // any express or implied warranties, including, but not limited to, the implied 33 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 34 | // In no event shall the Intel Corporation or contributors be liable for any direct, 35 | // indirect, incidental, special, exemplary, or consequential damages 36 | // (including, but not limited to, procurement of substitute goods or services; 37 | // loss of use, data, or profits; or business interruption) however caused 38 | // and on any theory of liability, whether in contract, strict liability, 39 | // or tort (including negligence or otherwise) arising in any way out of 40 | // the use of this software, even if advised of the possibility of such damage. 41 | // 42 | //M*/ 43 | 44 | #ifndef OPENCV_CORE_CVSTDINL_HPP 45 | #define OPENCV_CORE_CVSTDINL_HPP 46 | 47 | #include 48 | #include 49 | #include 50 | 51 | //! @cond IGNORED 52 | 53 | #ifdef _MSC_VER 54 | #pragma warning( push ) 55 | #pragma warning( disable: 4127 ) 56 | #endif 57 | 58 | namespace cv 59 | { 60 | 61 | template class DataType< std::complex<_Tp> > 62 | { 63 | public: 64 | typedef std::complex<_Tp> value_type; 65 | typedef value_type work_type; 66 | typedef _Tp channel_type; 67 | 68 | enum { generic_type = 0, 69 | depth = DataType::depth, 70 | channels = 2, 71 | fmt = DataType::fmt + ((channels - 1) << 8), 72 | type = CV_MAKETYPE(depth, channels) }; 73 | 74 | typedef Vec vec_type; 75 | }; 76 | 77 | static inline 78 | std::ostream& operator << (std::ostream& out, Ptr fmtd) 79 | { 80 | fmtd->reset(); 81 | for(const char* str = fmtd->next(); str; str = fmtd->next()) 82 | out << str; 83 | return out; 84 | } 85 | 86 | static inline 87 | std::ostream& operator << (std::ostream& out, const Mat& mtx) 88 | { 89 | return out << Formatter::get()->format(mtx); 90 | } 91 | 92 | static inline 93 | std::ostream& operator << (std::ostream& out, const UMat& m) 94 | { 95 | return out << m.getMat(ACCESS_READ); 96 | } 97 | 98 | template static inline 99 | std::ostream& operator << (std::ostream& out, const Complex<_Tp>& c) 100 | { 101 | return out << "(" << c.re << "," << c.im << ")"; 102 | } 103 | 104 | template static inline 105 | std::ostream& operator << (std::ostream& out, const std::vector >& vec) 106 | { 107 | return out << Formatter::get()->format(Mat(vec)); 108 | } 109 | 110 | 111 | template static inline 112 | std::ostream& operator << (std::ostream& out, const std::vector >& vec) 113 | { 114 | return out << Formatter::get()->format(Mat(vec)); 115 | } 116 | 117 | 118 | template static inline 119 | std::ostream& operator << (std::ostream& out, const Matx<_Tp, m, n>& matx) 120 | { 121 | return out << Formatter::get()->format(Mat(matx)); 122 | } 123 | 124 | template static inline 125 | std::ostream& operator << (std::ostream& out, const Point_<_Tp>& p) 126 | { 127 | out << "[" << p.x << ", " << p.y << "]"; 128 | return out; 129 | } 130 | 131 | template static inline 132 | std::ostream& operator << (std::ostream& out, const Point3_<_Tp>& p) 133 | { 134 | out << "[" << p.x << ", " << p.y << ", " << p.z << "]"; 135 | return out; 136 | } 137 | 138 | template static inline 139 | std::ostream& operator << (std::ostream& out, const Vec<_Tp, n>& vec) 140 | { 141 | out << "["; 142 | if (cv::traits::Depth<_Tp>::value <= CV_32S) 143 | { 144 | for (int i = 0; i < n - 1; ++i) { 145 | out << (int)vec[i] << ", "; 146 | } 147 | out << (int)vec[n-1] << "]"; 148 | } 149 | else 150 | { 151 | for (int i = 0; i < n - 1; ++i) { 152 | out << vec[i] << ", "; 153 | } 154 | out << vec[n-1] << "]"; 155 | } 156 | 157 | return out; 158 | } 159 | 160 | template static inline 161 | std::ostream& operator << (std::ostream& out, const Size_<_Tp>& size) 162 | { 163 | return out << "[" << size.width << " x " << size.height << "]"; 164 | } 165 | 166 | template static inline 167 | std::ostream& operator << (std::ostream& out, const Rect_<_Tp>& rect) 168 | { 169 | return out << "[" << rect.width << " x " << rect.height << " from (" << rect.x << ", " << rect.y << ")]"; 170 | } 171 | 172 | static inline std::ostream& operator << (std::ostream& out, const MatSize& msize) 173 | { 174 | int i, dims = msize.dims(); 175 | for( i = 0; i < dims; i++ ) 176 | { 177 | out << msize[i]; 178 | if( i < dims-1 ) 179 | out << " x "; 180 | } 181 | return out; 182 | } 183 | 184 | static inline std::ostream &operator<< (std::ostream &s, cv::Range &r) 185 | { 186 | return s << "[" << r.start << " : " << r.end << ")"; 187 | } 188 | 189 | } // cv 190 | 191 | #ifdef _MSC_VER 192 | #pragma warning( pop ) 193 | #endif 194 | 195 | //! @endcond 196 | 197 | #endif // OPENCV_CORE_CVSTDINL_HPP 198 | -------------------------------------------------------------------------------- /3rdparty/include/opencv2/core/cvstd_wrapper.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | 5 | #ifndef OPENCV_CORE_CVSTD_WRAPPER_HPP 6 | #define OPENCV_CORE_CVSTD_WRAPPER_HPP 7 | 8 | #include "opencv2/core/cvdef.h" 9 | 10 | #include 11 | #include // std::shared_ptr 12 | #include // std::enable_if 13 | 14 | namespace cv { 15 | 16 | using std::nullptr_t; 17 | 18 | //! @addtogroup core_basic 19 | //! @{ 20 | 21 | #ifdef CV_DOXYGEN 22 | 23 | template using Ptr = std::shared_ptr<_Tp>; // In ideal world it should look like this, but we need some compatibility workarounds below 24 | 25 | template static inline 26 | Ptr<_Tp> makePtr(const A1&... a1) { return std::make_shared<_Tp>(a1...); } 27 | 28 | #else // cv::Ptr with compatibility workarounds 29 | 30 | // It should be defined for C-API types only. 31 | // C++ types should use regular "delete" operator. 32 | template struct DefaultDeleter; 33 | #if 0 34 | { 35 | void operator()(Y* p) const; 36 | }; 37 | #endif 38 | 39 | namespace sfinae { 40 | template 41 | struct has_parenthesis_operator 42 | { 43 | private: 44 | template 45 | static CV_CONSTEXPR std::true_type check(typename std::is_same().operator()(std::declval()...))>::type, Ret>::type*); 46 | 47 | template static CV_CONSTEXPR std::false_type check(...); 48 | 49 | typedef decltype(check(0)) type; 50 | 51 | public: 52 | #if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900/*MSVS 2015*/) 53 | static CV_CONSTEXPR bool value = type::value; 54 | #else 55 | // support MSVS 2013 56 | static const int value = type::value; 57 | #endif 58 | }; 59 | } // namespace sfinae 60 | 61 | template 62 | struct has_custom_delete 63 | : public std::false_type {}; 64 | 65 | // Force has_custom_delete to std::false_type when NVCC is compiling CUDA source files 66 | #ifndef __CUDACC__ 67 | template 68 | struct has_custom_delete, void, T*>::value >::type > 69 | : public std::true_type {}; 70 | #endif 71 | 72 | template 73 | struct Ptr : public std::shared_ptr 74 | { 75 | #if 0 76 | using std::shared_ptr::shared_ptr; // GCC 5.x can't handle this 77 | #else 78 | inline Ptr() CV_NOEXCEPT : std::shared_ptr() {} 79 | inline Ptr(nullptr_t) CV_NOEXCEPT : std::shared_ptr(nullptr) {} 80 | template inline Ptr(Y* p, D d) : std::shared_ptr(p, d) {} 81 | template inline Ptr(nullptr_t, D d) : std::shared_ptr(nullptr, d) {} 82 | 83 | template inline Ptr(const Ptr& r, T* ptr) CV_NOEXCEPT : std::shared_ptr(r, ptr) {} 84 | 85 | inline Ptr(const Ptr& o) CV_NOEXCEPT : std::shared_ptr(o) {} 86 | inline Ptr(Ptr&& o) CV_NOEXCEPT : std::shared_ptr(std::move(o)) {} 87 | 88 | template inline Ptr(const Ptr& o) CV_NOEXCEPT : std::shared_ptr(o) {} 89 | template inline Ptr(Ptr&& o) CV_NOEXCEPT : std::shared_ptr(std::move(o)) {} 90 | #endif 91 | inline Ptr(const std::shared_ptr& o) CV_NOEXCEPT : std::shared_ptr(o) {} 92 | inline Ptr(std::shared_ptr&& o) CV_NOEXCEPT : std::shared_ptr(std::move(o)) {} 93 | 94 | // Overload with custom DefaultDeleter: Ptr(...) 95 | template 96 | inline Ptr(const std::true_type&, Y* ptr) : std::shared_ptr(ptr, DefaultDeleter()) {} 97 | 98 | // Overload without custom deleter: Ptr(...); 99 | template 100 | inline Ptr(const std::false_type&, Y* ptr) : std::shared_ptr(ptr) {} 101 | 102 | template 103 | inline Ptr(Y* ptr) : Ptr(has_custom_delete(), ptr) {} 104 | 105 | // Overload with custom DefaultDeleter: Ptr(...) 106 | template 107 | inline void reset(const std::true_type&, Y* ptr) { std::shared_ptr::reset(ptr, DefaultDeleter()); } 108 | 109 | // Overload without custom deleter: Ptr(...); 110 | template 111 | inline void reset(const std::false_type&, Y* ptr) { std::shared_ptr::reset(ptr); } 112 | 113 | template 114 | inline void reset(Y* ptr) { Ptr::reset(has_custom_delete(), ptr); } 115 | 116 | template 117 | void reset(Y* ptr, Deleter d) { std::shared_ptr::reset(ptr, d); } 118 | 119 | void reset() CV_NOEXCEPT { std::shared_ptr::reset(); } 120 | 121 | Ptr& operator=(const Ptr& o) { std::shared_ptr::operator =(o); return *this; } 122 | template inline Ptr& operator=(const Ptr& o) { std::shared_ptr::operator =(o); return *this; } 123 | 124 | T* operator->() const CV_NOEXCEPT { return std::shared_ptr::get();} 125 | typename std::add_lvalue_reference::type operator*() const CV_NOEXCEPT { return *std::shared_ptr::get(); } 126 | 127 | // OpenCV 3.x methods (not a part of standard C++ library) 128 | inline void release() { std::shared_ptr::reset(); } 129 | inline operator T* () const { return std::shared_ptr::get(); } 130 | inline bool empty() const { return std::shared_ptr::get() == nullptr; } 131 | 132 | template inline 133 | Ptr staticCast() const CV_NOEXCEPT { return std::static_pointer_cast(*this); } 134 | 135 | template inline 136 | Ptr constCast() const CV_NOEXCEPT { return std::const_pointer_cast(*this); } 137 | 138 | template inline 139 | Ptr dynamicCast() const CV_NOEXCEPT { return std::dynamic_pointer_cast(*this); } 140 | }; 141 | 142 | template static inline 143 | Ptr<_Tp> makePtr(const A1&... a1) 144 | { 145 | static_assert( !has_custom_delete<_Tp>::value, "Can't use this makePtr with custom DefaultDeleter"); 146 | return (Ptr<_Tp>)std::make_shared<_Tp>(a1...); 147 | } 148 | 149 | #endif // CV_DOXYGEN 150 | 151 | //! @} core_basic 152 | } // cv 153 | 154 | #endif //OPENCV_CORE_CVSTD_WRAPPER_HPP 155 | -------------------------------------------------------------------------------- /3rdparty/include/opencv2/core/fast_math.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 | // Copyright (C) 2013, OpenCV Foundation, all rights reserved. 16 | // Copyright (C) 2015, Itseez Inc., all rights reserved. 17 | // Third party copyrights are property of their respective owners. 18 | // 19 | // Redistribution and use in source and binary forms, with or without modification, 20 | // are permitted provided that the following conditions are met: 21 | // 22 | // * Redistribution's of source code must retain the above copyright notice, 23 | // this list of conditions and the following disclaimer. 24 | // 25 | // * Redistribution's in binary form must reproduce the above copyright notice, 26 | // this list of conditions and the following disclaimer in the documentation 27 | // and/or other materials provided with the distribution. 28 | // 29 | // * The name of the copyright holders may not be used to endorse or promote products 30 | // derived from this software without specific prior written permission. 31 | // 32 | // This software is provided by the copyright holders and contributors "as is" and 33 | // any express or implied warranties, including, but not limited to, the implied 34 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 35 | // In no event shall the Intel Corporation or contributors be liable for any direct, 36 | // indirect, incidental, special, exemplary, or consequential damages 37 | // (including, but not limited to, procurement of substitute goods or services; 38 | // loss of use, data, or profits; or business interruption) however caused 39 | // and on any theory of liability, whether in contract, strict liability, 40 | // or tort (including negligence or otherwise) arising in any way out of 41 | // the use of this software, even if advised of the possibility of such damage. 42 | // 43 | //M*/ 44 | 45 | #ifndef OPENCV_CORE_FAST_MATH_HPP 46 | #define OPENCV_CORE_FAST_MATH_HPP 47 | 48 | #include "opencv2/core/cvdef.h" 49 | 50 | //! @addtogroup core_utils 51 | //! @{ 52 | 53 | /****************************************************************************************\ 54 | * fast math * 55 | \****************************************************************************************/ 56 | 57 | #ifdef __cplusplus 58 | # include 59 | #else 60 | # ifdef __BORLANDC__ 61 | # include 62 | # else 63 | # include 64 | # endif 65 | #endif 66 | 67 | #if defined(__CUDACC__) 68 | // nothing, intrinsics/asm code is not supported 69 | #else 70 | #if ((defined _MSC_VER && defined _M_X64) \ 71 | || (defined __GNUC__ && defined __x86_64__ && defined __SSE2__)) \ 72 | && !defined(OPENCV_SKIP_INCLUDE_EMMINTRIN_H) 73 | #include 74 | #endif 75 | 76 | #if defined __PPC64__ && defined __GNUC__ && defined _ARCH_PWR8 \ 77 | && !defined(OPENCV_SKIP_INCLUDE_ALTIVEC_H) 78 | #include 79 | #endif 80 | 81 | #if defined(CV_INLINE_ROUND_FLT) 82 | // user-specified version 83 | // CV_INLINE_ROUND_DBL should be defined too 84 | #elif defined __GNUC__ && defined __arm__ && (defined __ARM_PCS_VFP || defined __ARM_VFPV3__ || defined __ARM_NEON__) && !defined __SOFTFP__ 85 | // 1. general scheme 86 | #define ARM_ROUND(_value, _asm_string) \ 87 | int res; \ 88 | float temp; \ 89 | CV_UNUSED(temp); \ 90 | __asm__(_asm_string : [res] "=r" (res), [temp] "=w" (temp) : [value] "w" (_value)); \ 91 | return res 92 | // 2. version for double 93 | #ifdef __clang__ 94 | #define CV_INLINE_ROUND_DBL(value) ARM_ROUND(value, "vcvtr.s32.f64 %[temp], %[value] \n vmov %[res], %[temp]") 95 | #else 96 | #define CV_INLINE_ROUND_DBL(value) ARM_ROUND(value, "vcvtr.s32.f64 %[temp], %P[value] \n vmov %[res], %[temp]") 97 | #endif 98 | // 3. version for float 99 | #define CV_INLINE_ROUND_FLT(value) ARM_ROUND(value, "vcvtr.s32.f32 %[temp], %[value]\n vmov %[res], %[temp]") 100 | #elif defined __PPC64__ && defined __GNUC__ && defined _ARCH_PWR8 101 | // P8 and newer machines can convert fp32/64 to int quickly. 102 | #define CV_INLINE_ROUND_DBL(value) \ 103 | int out; \ 104 | double temp; \ 105 | __asm__( "fctiw %[temp],%[in]\n\tmfvsrwz %[out],%[temp]\n\t" : [out] "=r" (out), [temp] "=d" (temp) : [in] "d" ((double)(value)) : ); \ 106 | return out; 107 | 108 | // FP32 also works with FP64 routine above 109 | #define CV_INLINE_ROUND_FLT(value) CV_INLINE_ROUND_DBL(value) 110 | #endif 111 | 112 | #ifdef CV_INLINE_ISINF_FLT 113 | // user-specified version 114 | // CV_INLINE_ISINF_DBL should be defined too 115 | #elif defined __PPC64__ && defined _ARCH_PWR9 && defined(scalar_test_data_class) 116 | #define CV_INLINE_ISINF_DBL(value) return scalar_test_data_class(value, 0x30); 117 | #define CV_INLINE_ISINF_FLT(value) CV_INLINE_ISINF_DBL(value) 118 | #endif 119 | 120 | #ifdef CV_INLINE_ISNAN_FLT 121 | // user-specified version 122 | // CV_INLINE_ISNAN_DBL should be defined too 123 | #elif defined __PPC64__ && defined _ARCH_PWR9 && defined(scalar_test_data_class) 124 | #define CV_INLINE_ISNAN_DBL(value) return scalar_test_data_class(value, 0x40); 125 | #define CV_INLINE_ISNAN_FLT(value) CV_INLINE_ISNAN_DBL(value) 126 | #endif 127 | 128 | #if !defined(OPENCV_USE_FASTMATH_BUILTINS) \ 129 | && ( \ 130 | defined(__x86_64__) || defined(__i686__) \ 131 | || defined(__arm__) \ 132 | || defined(__PPC64__) \ 133 | ) 134 | /* Let builtin C math functions when available. Dedicated hardware is available to 135 | round and convert FP values. */ 136 | #define OPENCV_USE_FASTMATH_BUILTINS 1 137 | #endif 138 | 139 | /* Enable builtin math functions if possible, desired, and available. 140 | Note, not all math functions inline equally. E.g lrint will not inline 141 | without the -fno-math-errno option. */ 142 | #if defined(CV_ICC) 143 | // nothing 144 | #elif defined(OPENCV_USE_FASTMATH_BUILTINS) && OPENCV_USE_FASTMATH_BUILTINS 145 | #if defined(__clang__) 146 | #define CV__FASTMATH_ENABLE_CLANG_MATH_BUILTINS 147 | #if !defined(CV_INLINE_ISNAN_DBL) && __has_builtin(__builtin_isnan) 148 | #define CV_INLINE_ISNAN_DBL(value) return __builtin_isnan(value); 149 | #endif 150 | #if !defined(CV_INLINE_ISNAN_FLT) && __has_builtin(__builtin_isnan) 151 | #define CV_INLINE_ISNAN_FLT(value) return __builtin_isnan(value); 152 | #endif 153 | #if !defined(CV_INLINE_ISINF_DBL) && __has_builtin(__builtin_isinf) 154 | #define CV_INLINE_ISINF_DBL(value) return __builtin_isinf(value); 155 | #endif 156 | #if !defined(CV_INLINE_ISINF_FLT) && __has_builtin(__builtin_isinf) 157 | #define CV_INLINE_ISINF_FLT(value) return __builtin_isinf(value); 158 | #endif 159 | #elif defined(__GNUC__) 160 | #define CV__FASTMATH_ENABLE_GCC_MATH_BUILTINS 161 | #if !defined(CV_INLINE_ISNAN_DBL) 162 | #define CV_INLINE_ISNAN_DBL(value) return __builtin_isnan(value); 163 | #endif 164 | #if !defined(CV_INLINE_ISNAN_FLT) 165 | #define CV_INLINE_ISNAN_FLT(value) return __builtin_isnanf(value); 166 | #endif 167 | #if !defined(CV_INLINE_ISINF_DBL) 168 | #define CV_INLINE_ISINF_DBL(value) return __builtin_isinf(value); 169 | #endif 170 | #if !defined(CV_INLINE_ISINF_FLT) 171 | #define CV_INLINE_ISINF_FLT(value) return __builtin_isinff(value); 172 | #endif 173 | #elif defined(_MSC_VER) 174 | #if !defined(CV_INLINE_ISNAN_DBL) 175 | #define CV_INLINE_ISNAN_DBL(value) return isnan(value); 176 | #endif 177 | #if !defined(CV_INLINE_ISNAN_FLT) 178 | #define CV_INLINE_ISNAN_FLT(value) return isnan(value); 179 | #endif 180 | #if !defined(CV_INLINE_ISINF_DBL) 181 | #define CV_INLINE_ISINF_DBL(value) return isinf(value); 182 | #endif 183 | #if !defined(CV_INLINE_ISINF_FLT) 184 | #define CV_INLINE_ISINF_FLT(value) return isinf(value); 185 | #endif 186 | #endif 187 | #endif 188 | 189 | #endif // defined(__CUDACC__) 190 | 191 | /** @brief Rounds floating-point number to the nearest integer 192 | 193 | @param value floating-point number. If the value is outside of INT_MIN ... INT_MAX range, the 194 | result is not defined. 195 | */ 196 | CV_INLINE int 197 | cvRound( double value ) 198 | { 199 | #if defined CV_INLINE_ROUND_DBL 200 | CV_INLINE_ROUND_DBL(value); 201 | #elif ((defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__ \ 202 | && defined __SSE2__ && !defined __APPLE__) || CV_SSE2) \ 203 | && !defined(__CUDACC__) 204 | __m128d t = _mm_set_sd( value ); 205 | return _mm_cvtsd_si32(t); 206 | #elif defined _MSC_VER && defined _M_IX86 207 | int t; 208 | __asm 209 | { 210 | fld value; 211 | fistp t; 212 | } 213 | return t; 214 | #elif defined CV_ICC || defined __GNUC__ 215 | return (int)(lrint(value)); 216 | #else 217 | /* it's ok if round does not comply with IEEE754 standard; 218 | the tests should allow +/-1 difference when the tested functions use round */ 219 | return (int)(value + (value >= 0 ? 0.5 : -0.5)); 220 | #endif 221 | } 222 | 223 | 224 | /** @brief Rounds floating-point number to the nearest integer not larger than the original. 225 | 226 | The function computes an integer i such that: 227 | \f[i \le \texttt{value} < i+1\f] 228 | @param value floating-point number. If the value is outside of INT_MIN ... INT_MAX range, the 229 | result is not defined. 230 | */ 231 | CV_INLINE int cvFloor( double value ) 232 | { 233 | #if (defined CV__FASTMATH_ENABLE_GCC_MATH_BUILTINS || defined CV__FASTMATH_ENABLE_CLANG_MATH_BUILTINS) \ 234 | && ( \ 235 | defined(__PPC64__) \ 236 | ) 237 | return __builtin_floor(value); 238 | #else 239 | int i = (int)value; 240 | return i - (i > value); 241 | #endif 242 | } 243 | 244 | /** @brief Rounds floating-point number to the nearest integer not smaller than the original. 245 | 246 | The function computes an integer i such that: 247 | \f[i \le \texttt{value} < i+1\f] 248 | @param value floating-point number. If the value is outside of INT_MIN ... INT_MAX range, the 249 | result is not defined. 250 | */ 251 | CV_INLINE int cvCeil( double value ) 252 | { 253 | #if (defined CV__FASTMATH_ENABLE_GCC_MATH_BUILTINS || defined CV__FASTMATH_ENABLE_CLANG_MATH_BUILTINS) \ 254 | && ( \ 255 | defined(__PPC64__) \ 256 | ) 257 | return __builtin_ceil(value); 258 | #else 259 | int i = (int)value; 260 | return i + (i < value); 261 | #endif 262 | } 263 | 264 | /** @brief Determines if the argument is Not A Number. 265 | 266 | @param value The input floating-point value 267 | 268 | The function returns 1 if the argument is Not A Number (as defined by IEEE754 standard), 0 269 | otherwise. */ 270 | CV_INLINE int cvIsNaN( double value ) 271 | { 272 | #if defined CV_INLINE_ISNAN_DBL 273 | CV_INLINE_ISNAN_DBL(value); 274 | #else 275 | Cv64suf ieee754; 276 | ieee754.f = value; 277 | return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) + 278 | ((unsigned)ieee754.u != 0) > 0x7ff00000; 279 | #endif 280 | } 281 | 282 | /** @brief Determines if the argument is Infinity. 283 | 284 | @param value The input floating-point value 285 | 286 | The function returns 1 if the argument is a plus or minus infinity (as defined by IEEE754 standard) 287 | and 0 otherwise. */ 288 | CV_INLINE int cvIsInf( double value ) 289 | { 290 | #if defined CV_INLINE_ISINF_DBL 291 | CV_INLINE_ISINF_DBL(value); 292 | #elif defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__) || defined(_M_ARM64) || defined(__PPC64__) 293 | Cv64suf ieee754; 294 | ieee754.f = value; 295 | return (ieee754.u & 0x7fffffff00000000) == 296 | 0x7ff0000000000000; 297 | #else 298 | Cv64suf ieee754; 299 | ieee754.f = value; 300 | return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) == 0x7ff00000 && 301 | (unsigned)ieee754.u == 0; 302 | #endif 303 | } 304 | 305 | #ifdef __cplusplus 306 | 307 | /** @overload */ 308 | CV_INLINE int cvRound(float value) 309 | { 310 | #if defined CV_INLINE_ROUND_FLT 311 | CV_INLINE_ROUND_FLT(value); 312 | #elif ((defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__ \ 313 | && defined __SSE2__ && !defined __APPLE__) || CV_SSE2) \ 314 | && !defined(__CUDACC__) 315 | __m128 t = _mm_set_ss( value ); 316 | return _mm_cvtss_si32(t); 317 | #elif defined _MSC_VER && defined _M_IX86 318 | int t; 319 | __asm 320 | { 321 | fld value; 322 | fistp t; 323 | } 324 | return t; 325 | #elif defined CV_ICC || defined __GNUC__ 326 | return (int)(lrintf(value)); 327 | #else 328 | /* it's ok if round does not comply with IEEE754 standard; 329 | the tests should allow +/-1 difference when the tested functions use round */ 330 | return (int)(value + (value >= 0 ? 0.5f : -0.5f)); 331 | #endif 332 | } 333 | 334 | /** @overload */ 335 | CV_INLINE int cvRound( int value ) 336 | { 337 | return value; 338 | } 339 | 340 | /** @overload */ 341 | CV_INLINE int cvFloor( float value ) 342 | { 343 | #if (defined CV__FASTMATH_ENABLE_GCC_MATH_BUILTINS || defined CV__FASTMATH_ENABLE_CLANG_MATH_BUILTINS) \ 344 | && ( \ 345 | defined(__PPC64__) \ 346 | ) 347 | return __builtin_floorf(value); 348 | #else 349 | int i = (int)value; 350 | return i - (i > value); 351 | #endif 352 | } 353 | 354 | /** @overload */ 355 | CV_INLINE int cvFloor( int value ) 356 | { 357 | return value; 358 | } 359 | 360 | /** @overload */ 361 | CV_INLINE int cvCeil( float value ) 362 | { 363 | #if (defined CV__FASTMATH_ENABLE_GCC_MATH_BUILTINS || defined CV__FASTMATH_ENABLE_CLANG_MATH_BUILTINS) \ 364 | && ( \ 365 | defined(__PPC64__) \ 366 | ) 367 | return __builtin_ceilf(value); 368 | #else 369 | int i = (int)value; 370 | return i + (i < value); 371 | #endif 372 | } 373 | 374 | /** @overload */ 375 | CV_INLINE int cvCeil( int value ) 376 | { 377 | return value; 378 | } 379 | 380 | /** @overload */ 381 | CV_INLINE int cvIsNaN( float value ) 382 | { 383 | #if defined CV_INLINE_ISNAN_FLT 384 | CV_INLINE_ISNAN_FLT(value); 385 | #else 386 | Cv32suf ieee754; 387 | ieee754.f = value; 388 | return (ieee754.u & 0x7fffffff) > 0x7f800000; 389 | #endif 390 | } 391 | 392 | /** @overload */ 393 | CV_INLINE int cvIsInf( float value ) 394 | { 395 | #if defined CV_INLINE_ISINF_FLT 396 | CV_INLINE_ISINF_FLT(value); 397 | #else 398 | Cv32suf ieee754; 399 | ieee754.f = value; 400 | return (ieee754.u & 0x7fffffff) == 0x7f800000; 401 | #endif 402 | } 403 | 404 | #endif // __cplusplus 405 | 406 | //! @} core_utils 407 | 408 | #endif 409 | -------------------------------------------------------------------------------- /3rdparty/include/opencv2/core/hal/interface.h: -------------------------------------------------------------------------------- 1 | #ifndef OPENCV_CORE_HAL_INTERFACE_H 2 | #define OPENCV_CORE_HAL_INTERFACE_H 3 | 4 | //! @addtogroup core_hal_interface 5 | //! @{ 6 | 7 | //! @name Return codes 8 | //! @{ 9 | #define CV_HAL_ERROR_OK 0 10 | #define CV_HAL_ERROR_NOT_IMPLEMENTED 1 11 | #define CV_HAL_ERROR_UNKNOWN -1 12 | //! @} 13 | 14 | #ifdef __cplusplus 15 | #include 16 | #else 17 | #include 18 | #include 19 | #endif 20 | 21 | //! @name Data types 22 | //! primitive types 23 | //! - schar - signed 1 byte integer 24 | //! - uchar - unsigned 1 byte integer 25 | //! - short - signed 2 byte integer 26 | //! - ushort - unsigned 2 byte integer 27 | //! - int - signed 4 byte integer 28 | //! - uint - unsigned 4 byte integer 29 | //! - int64 - signed 8 byte integer 30 | //! - uint64 - unsigned 8 byte integer 31 | //! @{ 32 | #if !defined _MSC_VER && !defined __BORLANDC__ 33 | # if defined __cplusplus && __cplusplus >= 201103L && !defined __APPLE__ 34 | # include 35 | # ifdef __NEWLIB__ 36 | typedef unsigned int uint; 37 | # else 38 | typedef std::uint32_t uint; 39 | # endif 40 | # else 41 | # include 42 | typedef uint32_t uint; 43 | # endif 44 | #else 45 | typedef unsigned uint; 46 | #endif 47 | 48 | typedef signed char schar; 49 | 50 | #ifndef __IPL_H__ 51 | typedef unsigned char uchar; 52 | typedef unsigned short ushort; 53 | #endif 54 | 55 | #if defined _MSC_VER || defined __BORLANDC__ 56 | typedef __int64 int64; 57 | typedef unsigned __int64 uint64; 58 | # define CV_BIG_INT(n) n##I64 59 | # define CV_BIG_UINT(n) n##UI64 60 | #else 61 | typedef int64_t int64; 62 | typedef uint64_t uint64; 63 | # define CV_BIG_INT(n) n##LL 64 | # define CV_BIG_UINT(n) n##ULL 65 | #endif 66 | 67 | #define CV_USRTYPE1 (void)"CV_USRTYPE1 support has been dropped in OpenCV 4.0" 68 | 69 | #define CV_CN_MAX 512 70 | #define CV_CN_SHIFT 3 71 | #define CV_DEPTH_MAX (1 << CV_CN_SHIFT) 72 | 73 | #define CV_8U 0 74 | #define CV_8S 1 75 | #define CV_16U 2 76 | #define CV_16S 3 77 | #define CV_32S 4 78 | #define CV_32F 5 79 | #define CV_64F 6 80 | #define CV_16F 7 81 | 82 | #define CV_MAT_DEPTH_MASK (CV_DEPTH_MAX - 1) 83 | #define CV_MAT_DEPTH(flags) ((flags) & CV_MAT_DEPTH_MASK) 84 | 85 | #define CV_MAKETYPE(depth,cn) (CV_MAT_DEPTH(depth) + (((cn)-1) << CV_CN_SHIFT)) 86 | #define CV_MAKE_TYPE CV_MAKETYPE 87 | 88 | #define CV_8UC1 CV_MAKETYPE(CV_8U,1) 89 | #define CV_8UC2 CV_MAKETYPE(CV_8U,2) 90 | #define CV_8UC3 CV_MAKETYPE(CV_8U,3) 91 | #define CV_8UC4 CV_MAKETYPE(CV_8U,4) 92 | #define CV_8UC(n) CV_MAKETYPE(CV_8U,(n)) 93 | 94 | #define CV_8SC1 CV_MAKETYPE(CV_8S,1) 95 | #define CV_8SC2 CV_MAKETYPE(CV_8S,2) 96 | #define CV_8SC3 CV_MAKETYPE(CV_8S,3) 97 | #define CV_8SC4 CV_MAKETYPE(CV_8S,4) 98 | #define CV_8SC(n) CV_MAKETYPE(CV_8S,(n)) 99 | 100 | #define CV_16UC1 CV_MAKETYPE(CV_16U,1) 101 | #define CV_16UC2 CV_MAKETYPE(CV_16U,2) 102 | #define CV_16UC3 CV_MAKETYPE(CV_16U,3) 103 | #define CV_16UC4 CV_MAKETYPE(CV_16U,4) 104 | #define CV_16UC(n) CV_MAKETYPE(CV_16U,(n)) 105 | 106 | #define CV_16SC1 CV_MAKETYPE(CV_16S,1) 107 | #define CV_16SC2 CV_MAKETYPE(CV_16S,2) 108 | #define CV_16SC3 CV_MAKETYPE(CV_16S,3) 109 | #define CV_16SC4 CV_MAKETYPE(CV_16S,4) 110 | #define CV_16SC(n) CV_MAKETYPE(CV_16S,(n)) 111 | 112 | #define CV_32SC1 CV_MAKETYPE(CV_32S,1) 113 | #define CV_32SC2 CV_MAKETYPE(CV_32S,2) 114 | #define CV_32SC3 CV_MAKETYPE(CV_32S,3) 115 | #define CV_32SC4 CV_MAKETYPE(CV_32S,4) 116 | #define CV_32SC(n) CV_MAKETYPE(CV_32S,(n)) 117 | 118 | #define CV_32FC1 CV_MAKETYPE(CV_32F,1) 119 | #define CV_32FC2 CV_MAKETYPE(CV_32F,2) 120 | #define CV_32FC3 CV_MAKETYPE(CV_32F,3) 121 | #define CV_32FC4 CV_MAKETYPE(CV_32F,4) 122 | #define CV_32FC(n) CV_MAKETYPE(CV_32F,(n)) 123 | 124 | #define CV_64FC1 CV_MAKETYPE(CV_64F,1) 125 | #define CV_64FC2 CV_MAKETYPE(CV_64F,2) 126 | #define CV_64FC3 CV_MAKETYPE(CV_64F,3) 127 | #define CV_64FC4 CV_MAKETYPE(CV_64F,4) 128 | #define CV_64FC(n) CV_MAKETYPE(CV_64F,(n)) 129 | 130 | #define CV_16FC1 CV_MAKETYPE(CV_16F,1) 131 | #define CV_16FC2 CV_MAKETYPE(CV_16F,2) 132 | #define CV_16FC3 CV_MAKETYPE(CV_16F,3) 133 | #define CV_16FC4 CV_MAKETYPE(CV_16F,4) 134 | #define CV_16FC(n) CV_MAKETYPE(CV_16F,(n)) 135 | //! @} 136 | 137 | //! @name Comparison operation 138 | //! @sa cv::CmpTypes 139 | //! @{ 140 | #define CV_HAL_CMP_EQ 0 141 | #define CV_HAL_CMP_GT 1 142 | #define CV_HAL_CMP_GE 2 143 | #define CV_HAL_CMP_LT 3 144 | #define CV_HAL_CMP_LE 4 145 | #define CV_HAL_CMP_NE 5 146 | //! @} 147 | 148 | //! @name Border processing modes 149 | //! @sa cv::BorderTypes 150 | //! @{ 151 | #define CV_HAL_BORDER_CONSTANT 0 152 | #define CV_HAL_BORDER_REPLICATE 1 153 | #define CV_HAL_BORDER_REFLECT 2 154 | #define CV_HAL_BORDER_WRAP 3 155 | #define CV_HAL_BORDER_REFLECT_101 4 156 | #define CV_HAL_BORDER_TRANSPARENT 5 157 | #define CV_HAL_BORDER_ISOLATED 16 158 | //! @} 159 | 160 | //! @name DFT flags 161 | //! @{ 162 | #define CV_HAL_DFT_INVERSE 1 163 | #define CV_HAL_DFT_SCALE 2 164 | #define CV_HAL_DFT_ROWS 4 165 | #define CV_HAL_DFT_COMPLEX_OUTPUT 16 166 | #define CV_HAL_DFT_REAL_OUTPUT 32 167 | #define CV_HAL_DFT_TWO_STAGE 64 168 | #define CV_HAL_DFT_STAGE_COLS 128 169 | #define CV_HAL_DFT_IS_CONTINUOUS 512 170 | #define CV_HAL_DFT_IS_INPLACE 1024 171 | //! @} 172 | 173 | //! @name SVD flags 174 | //! @{ 175 | #define CV_HAL_SVD_NO_UV 1 176 | #define CV_HAL_SVD_SHORT_UV 2 177 | #define CV_HAL_SVD_MODIFY_A 4 178 | #define CV_HAL_SVD_FULL_UV 8 179 | //! @} 180 | 181 | //! @name Gemm flags 182 | //! @{ 183 | #define CV_HAL_GEMM_1_T 1 184 | #define CV_HAL_GEMM_2_T 2 185 | #define CV_HAL_GEMM_3_T 4 186 | //! @} 187 | 188 | //! @} 189 | 190 | #endif 191 | -------------------------------------------------------------------------------- /3rdparty/include/opencv2/core/neon_utils.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2015, Itseez Inc., all rights reserved. 14 | // Third party copyrights are property of their respective owners. 15 | // 16 | // Redistribution and use in source and binary forms, with or without modification, 17 | // are permitted provided that the following conditions are met: 18 | // 19 | // * Redistribution's of source code must retain the above copyright notice, 20 | // this list of conditions and the following disclaimer. 21 | // 22 | // * Redistribution's in binary form must reproduce the above copyright notice, 23 | // this list of conditions and the following disclaimer in the documentation 24 | // and/or other materials provided with the distribution. 25 | // 26 | // * The name of the copyright holders may not be used to endorse or promote products 27 | // derived from this software without specific prior written permission. 28 | // 29 | // This software is provided by the copyright holders and contributors "as is" and 30 | // any express or implied warranties, including, but not limited to, the implied 31 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 32 | // In no event shall the Intel Corporation or contributors be liable for any direct, 33 | // indirect, incidental, special, exemplary, or consequential damages 34 | // (including, but not limited to, procurement of substitute goods or services; 35 | // loss of use, data, or profits; or business interruption) however caused 36 | // and on any theory of liability, whether in contract, strict liability, 37 | // or tort (including negligence or otherwise) arising in any way out of 38 | // the use of this software, even if advised of the possibility of such damage. 39 | // 40 | //M*/ 41 | 42 | #ifndef OPENCV_HAL_NEON_UTILS_HPP 43 | #define OPENCV_HAL_NEON_UTILS_HPP 44 | 45 | #include "opencv2/core/cvdef.h" 46 | 47 | //! @addtogroup core_utils_neon 48 | //! @{ 49 | 50 | #if CV_NEON 51 | 52 | inline int32x2_t cv_vrnd_s32_f32(float32x2_t v) 53 | { 54 | static int32x2_t v_sign = vdup_n_s32(1 << 31), 55 | v_05 = vreinterpret_s32_f32(vdup_n_f32(0.5f)); 56 | 57 | int32x2_t v_addition = vorr_s32(v_05, vand_s32(v_sign, vreinterpret_s32_f32(v))); 58 | return vcvt_s32_f32(vadd_f32(v, vreinterpret_f32_s32(v_addition))); 59 | } 60 | 61 | inline int32x4_t cv_vrndq_s32_f32(float32x4_t v) 62 | { 63 | static int32x4_t v_sign = vdupq_n_s32(1 << 31), 64 | v_05 = vreinterpretq_s32_f32(vdupq_n_f32(0.5f)); 65 | 66 | int32x4_t v_addition = vorrq_s32(v_05, vandq_s32(v_sign, vreinterpretq_s32_f32(v))); 67 | return vcvtq_s32_f32(vaddq_f32(v, vreinterpretq_f32_s32(v_addition))); 68 | } 69 | 70 | inline uint32x2_t cv_vrnd_u32_f32(float32x2_t v) 71 | { 72 | static float32x2_t v_05 = vdup_n_f32(0.5f); 73 | return vcvt_u32_f32(vadd_f32(v, v_05)); 74 | } 75 | 76 | inline uint32x4_t cv_vrndq_u32_f32(float32x4_t v) 77 | { 78 | static float32x4_t v_05 = vdupq_n_f32(0.5f); 79 | return vcvtq_u32_f32(vaddq_f32(v, v_05)); 80 | } 81 | 82 | inline float32x4_t cv_vrecpq_f32(float32x4_t val) 83 | { 84 | float32x4_t reciprocal = vrecpeq_f32(val); 85 | reciprocal = vmulq_f32(vrecpsq_f32(val, reciprocal), reciprocal); 86 | reciprocal = vmulq_f32(vrecpsq_f32(val, reciprocal), reciprocal); 87 | return reciprocal; 88 | } 89 | 90 | inline float32x2_t cv_vrecp_f32(float32x2_t val) 91 | { 92 | float32x2_t reciprocal = vrecpe_f32(val); 93 | reciprocal = vmul_f32(vrecps_f32(val, reciprocal), reciprocal); 94 | reciprocal = vmul_f32(vrecps_f32(val, reciprocal), reciprocal); 95 | return reciprocal; 96 | } 97 | 98 | inline float32x4_t cv_vrsqrtq_f32(float32x4_t val) 99 | { 100 | float32x4_t e = vrsqrteq_f32(val); 101 | e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(e, e), val), e); 102 | e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(e, e), val), e); 103 | return e; 104 | } 105 | 106 | inline float32x2_t cv_vrsqrt_f32(float32x2_t val) 107 | { 108 | float32x2_t e = vrsqrte_f32(val); 109 | e = vmul_f32(vrsqrts_f32(vmul_f32(e, e), val), e); 110 | e = vmul_f32(vrsqrts_f32(vmul_f32(e, e), val), e); 111 | return e; 112 | } 113 | 114 | inline float32x4_t cv_vsqrtq_f32(float32x4_t val) 115 | { 116 | return cv_vrecpq_f32(cv_vrsqrtq_f32(val)); 117 | } 118 | 119 | inline float32x2_t cv_vsqrt_f32(float32x2_t val) 120 | { 121 | return cv_vrecp_f32(cv_vrsqrt_f32(val)); 122 | } 123 | 124 | #endif 125 | 126 | //! @} 127 | 128 | #endif // OPENCV_HAL_NEON_UTILS_HPP 129 | -------------------------------------------------------------------------------- /3rdparty/include/opencv2/core/optim.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2013, OpenCV Foundation, all rights reserved. 14 | // Third party copyrights are property of their respective owners. 15 | // 16 | // Redistribution and use in source and binary forms, with or without modification, 17 | // are permitted provided that the following conditions are met: 18 | // 19 | // * Redistribution's of source code must retain the above copyright notice, 20 | // this list of conditions and the following disclaimer. 21 | // 22 | // * Redistribution's in binary form must reproduce the above copyright notice, 23 | // this list of conditions and the following disclaimer in the documentation 24 | // and/or other materials provided with the distribution. 25 | // 26 | // * The name of the copyright holders may not be used to endorse or promote products 27 | // derived from this software without specific prior written permission. 28 | // 29 | // This software is provided by the copyright holders and contributors "as is" and 30 | // any express or implied warranties, including, but not limited to, the implied 31 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 32 | // In no event shall the OpenCV Foundation or contributors be liable for any direct, 33 | // indirect, incidental, special, exemplary, or consequential damages 34 | // (including, but not limited to, procurement of substitute goods or services; 35 | // loss of use, data, or profits; or business interruption) however caused 36 | // and on any theory of liability, whether in contract, strict liability, 37 | // or tort (including negligence or otherwise) arising in any way out of 38 | // the use of this software, even if advised of the possibility of such damage. 39 | // 40 | //M*/ 41 | 42 | #ifndef OPENCV_OPTIM_HPP 43 | #define OPENCV_OPTIM_HPP 44 | 45 | #include "opencv2/core.hpp" 46 | 47 | namespace cv 48 | { 49 | 50 | /** @addtogroup core_optim 51 | The algorithms in this section minimize or maximize function value within specified constraints or 52 | without any constraints. 53 | @{ 54 | */ 55 | 56 | /** @brief Basic interface for all solvers 57 | */ 58 | class CV_EXPORTS MinProblemSolver : public Algorithm 59 | { 60 | public: 61 | /** @brief Represents function being optimized 62 | */ 63 | class CV_EXPORTS Function 64 | { 65 | public: 66 | virtual ~Function() {} 67 | virtual int getDims() const = 0; 68 | virtual double getGradientEps() const; 69 | virtual double calc(const double* x) const = 0; 70 | virtual void getGradient(const double* x,double* grad); 71 | }; 72 | 73 | /** @brief Getter for the optimized function. 74 | 75 | The optimized function is represented by Function interface, which requires derivatives to 76 | implement the calc(double*) and getDim() methods to evaluate the function. 77 | 78 | @return Smart-pointer to an object that implements Function interface - it represents the 79 | function that is being optimized. It can be empty, if no function was given so far. 80 | */ 81 | virtual Ptr getFunction() const = 0; 82 | 83 | /** @brief Setter for the optimized function. 84 | 85 | *It should be called at least once before the call to* minimize(), as default value is not usable. 86 | 87 | @param f The new function to optimize. 88 | */ 89 | virtual void setFunction(const Ptr& f) = 0; 90 | 91 | /** @brief Getter for the previously set terminal criteria for this algorithm. 92 | 93 | @return Deep copy of the terminal criteria used at the moment. 94 | */ 95 | virtual TermCriteria getTermCriteria() const = 0; 96 | 97 | /** @brief Set terminal criteria for solver. 98 | 99 | This method *is not necessary* to be called before the first call to minimize(), as the default 100 | value is sensible. 101 | 102 | Algorithm stops when the number of function evaluations done exceeds termcrit.maxCount, when 103 | the function values at the vertices of simplex are within termcrit.epsilon range or simplex 104 | becomes so small that it can enclosed in a box with termcrit.epsilon sides, whatever comes 105 | first. 106 | @param termcrit Terminal criteria to be used, represented as cv::TermCriteria structure. 107 | */ 108 | virtual void setTermCriteria(const TermCriteria& termcrit) = 0; 109 | 110 | /** @brief actually runs the algorithm and performs the minimization. 111 | 112 | The sole input parameter determines the centroid of the starting simplex (roughly, it tells 113 | where to start), all the others (terminal criteria, initial step, function to be minimized) are 114 | supposed to be set via the setters before the call to this method or the default values (not 115 | always sensible) will be used. 116 | 117 | @param x The initial point, that will become a centroid of an initial simplex. After the algorithm 118 | will terminate, it will be set to the point where the algorithm stops, the point of possible 119 | minimum. 120 | @return The value of a function at the point found. 121 | */ 122 | virtual double minimize(InputOutputArray x) = 0; 123 | }; 124 | 125 | /** @brief This class is used to perform the non-linear non-constrained minimization of a function, 126 | 127 | defined on an `n`-dimensional Euclidean space, using the **Nelder-Mead method**, also known as 128 | **downhill simplex method**. The basic idea about the method can be obtained from 129 | . 130 | 131 | It should be noted, that this method, although deterministic, is rather a heuristic and therefore 132 | may converge to a local minima, not necessary a global one. It is iterative optimization technique, 133 | which at each step uses an information about the values of a function evaluated only at `n+1` 134 | points, arranged as a *simplex* in `n`-dimensional space (hence the second name of the method). At 135 | each step new point is chosen to evaluate function at, obtained value is compared with previous 136 | ones and based on this information simplex changes it's shape , slowly moving to the local minimum. 137 | Thus this method is using *only* function values to make decision, on contrary to, say, Nonlinear 138 | Conjugate Gradient method (which is also implemented in optim). 139 | 140 | Algorithm stops when the number of function evaluations done exceeds termcrit.maxCount, when the 141 | function values at the vertices of simplex are within termcrit.epsilon range or simplex becomes so 142 | small that it can enclosed in a box with termcrit.epsilon sides, whatever comes first, for some 143 | defined by user positive integer termcrit.maxCount and positive non-integer termcrit.epsilon. 144 | 145 | @note DownhillSolver is a derivative of the abstract interface 146 | cv::MinProblemSolver, which in turn is derived from the Algorithm interface and is used to 147 | encapsulate the functionality, common to all non-linear optimization algorithms in the optim 148 | module. 149 | 150 | @note term criteria should meet following condition: 151 | @code 152 | termcrit.type == (TermCriteria::MAX_ITER + TermCriteria::EPS) && termcrit.epsilon > 0 && termcrit.maxCount > 0 153 | @endcode 154 | */ 155 | class CV_EXPORTS DownhillSolver : public MinProblemSolver 156 | { 157 | public: 158 | /** @brief Returns the initial step that will be used in downhill simplex algorithm. 159 | 160 | @param step Initial step that will be used in algorithm. Note, that although corresponding setter 161 | accepts column-vectors as well as row-vectors, this method will return a row-vector. 162 | @see DownhillSolver::setInitStep 163 | */ 164 | virtual void getInitStep(OutputArray step) const=0; 165 | 166 | /** @brief Sets the initial step that will be used in downhill simplex algorithm. 167 | 168 | Step, together with initial point (given in DownhillSolver::minimize) are two `n`-dimensional 169 | vectors that are used to determine the shape of initial simplex. Roughly said, initial point 170 | determines the position of a simplex (it will become simplex's centroid), while step determines the 171 | spread (size in each dimension) of a simplex. To be more precise, if \f$s,x_0\in\mathbb{R}^n\f$ are 172 | the initial step and initial point respectively, the vertices of a simplex will be: 173 | \f$v_0:=x_0-\frac{1}{2} s\f$ and \f$v_i:=x_0+s_i\f$ for \f$i=1,2,\dots,n\f$ where \f$s_i\f$ denotes 174 | projections of the initial step of *n*-th coordinate (the result of projection is treated to be 175 | vector given by \f$s_i:=e_i\cdot\left\f$, where \f$e_i\f$ form canonical basis) 176 | 177 | @param step Initial step that will be used in algorithm. Roughly said, it determines the spread 178 | (size in each dimension) of an initial simplex. 179 | */ 180 | virtual void setInitStep(InputArray step)=0; 181 | 182 | /** @brief This function returns the reference to the ready-to-use DownhillSolver object. 183 | 184 | All the parameters are optional, so this procedure can be called even without parameters at 185 | all. In this case, the default values will be used. As default value for terminal criteria are 186 | the only sensible ones, MinProblemSolver::setFunction() and DownhillSolver::setInitStep() 187 | should be called upon the obtained object, if the respective parameters were not given to 188 | create(). Otherwise, the two ways (give parameters to createDownhillSolver() or miss them out 189 | and call the MinProblemSolver::setFunction() and DownhillSolver::setInitStep()) are absolutely 190 | equivalent (and will drop the same errors in the same way, should invalid input be detected). 191 | @param f Pointer to the function that will be minimized, similarly to the one you submit via 192 | MinProblemSolver::setFunction. 193 | @param initStep Initial step, that will be used to construct the initial simplex, similarly to the one 194 | you submit via MinProblemSolver::setInitStep. 195 | @param termcrit Terminal criteria to the algorithm, similarly to the one you submit via 196 | MinProblemSolver::setTermCriteria. 197 | */ 198 | static Ptr create(const Ptr& f=Ptr(), 199 | InputArray initStep=Mat_(1,1,0.0), 200 | TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS,5000,0.000001)); 201 | }; 202 | 203 | /** @brief This class is used to perform the non-linear non-constrained minimization of a function 204 | with known gradient, 205 | 206 | defined on an *n*-dimensional Euclidean space, using the **Nonlinear Conjugate Gradient method**. 207 | The implementation was done based on the beautifully clear explanatory article [An Introduction to 208 | the Conjugate Gradient Method Without the Agonizing 209 | Pain](http://www.cs.cmu.edu/~quake-papers/painless-conjugate-gradient.pdf) by Jonathan Richard 210 | Shewchuk. The method can be seen as an adaptation of a standard Conjugate Gradient method (see, for 211 | example ) for numerically solving the 212 | systems of linear equations. 213 | 214 | It should be noted, that this method, although deterministic, is rather a heuristic method and 215 | therefore may converge to a local minima, not necessary a global one. What is even more disastrous, 216 | most of its behaviour is ruled by gradient, therefore it essentially cannot distinguish between 217 | local minima and maxima. Therefore, if it starts sufficiently near to the local maximum, it may 218 | converge to it. Another obvious restriction is that it should be possible to compute the gradient of 219 | a function at any point, thus it is preferable to have analytic expression for gradient and 220 | computational burden should be born by the user. 221 | 222 | The latter responsibility is accomplished via the getGradient method of a 223 | MinProblemSolver::Function interface (which represents function being optimized). This method takes 224 | point a point in *n*-dimensional space (first argument represents the array of coordinates of that 225 | point) and compute its gradient (it should be stored in the second argument as an array). 226 | 227 | @note class ConjGradSolver thus does not add any new methods to the basic MinProblemSolver interface. 228 | 229 | @note term criteria should meet following condition: 230 | @code 231 | termcrit.type == (TermCriteria::MAX_ITER + TermCriteria::EPS) && termcrit.epsilon > 0 && termcrit.maxCount > 0 232 | // or 233 | termcrit.type == TermCriteria::MAX_ITER) && termcrit.maxCount > 0 234 | @endcode 235 | */ 236 | class CV_EXPORTS ConjGradSolver : public MinProblemSolver 237 | { 238 | public: 239 | /** @brief This function returns the reference to the ready-to-use ConjGradSolver object. 240 | 241 | All the parameters are optional, so this procedure can be called even without parameters at 242 | all. In this case, the default values will be used. As default value for terminal criteria are 243 | the only sensible ones, MinProblemSolver::setFunction() should be called upon the obtained 244 | object, if the function was not given to create(). Otherwise, the two ways (submit it to 245 | create() or miss it out and call the MinProblemSolver::setFunction()) are absolutely equivalent 246 | (and will drop the same errors in the same way, should invalid input be detected). 247 | @param f Pointer to the function that will be minimized, similarly to the one you submit via 248 | MinProblemSolver::setFunction. 249 | @param termcrit Terminal criteria to the algorithm, similarly to the one you submit via 250 | MinProblemSolver::setTermCriteria. 251 | */ 252 | static Ptr create(const Ptr& f=Ptr(), 253 | TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS,5000,0.000001)); 254 | }; 255 | 256 | //! return codes for cv::solveLP() function 257 | enum SolveLPResult 258 | { 259 | SOLVELP_UNBOUNDED = -2, //!< problem is unbounded (target function can achieve arbitrary high values) 260 | SOLVELP_UNFEASIBLE = -1, //!< problem is unfeasible (there are no points that satisfy all the constraints imposed) 261 | SOLVELP_SINGLE = 0, //!< there is only one maximum for target function 262 | SOLVELP_MULTI = 1 //!< there are multiple maxima for target function - the arbitrary one is returned 263 | }; 264 | 265 | /** @brief Solve given (non-integer) linear programming problem using the Simplex Algorithm (Simplex Method). 266 | 267 | What we mean here by "linear programming problem" (or LP problem, for short) can be formulated as: 268 | 269 | \f[\mbox{Maximize } c\cdot x\\ 270 | \mbox{Subject to:}\\ 271 | Ax\leq b\\ 272 | x\geq 0\f] 273 | 274 | Where \f$c\f$ is fixed `1`-by-`n` row-vector, \f$A\f$ is fixed `m`-by-`n` matrix, \f$b\f$ is fixed `m`-by-`1` 275 | column vector and \f$x\f$ is an arbitrary `n`-by-`1` column vector, which satisfies the constraints. 276 | 277 | Simplex algorithm is one of many algorithms that are designed to handle this sort of problems 278 | efficiently. Although it is not optimal in theoretical sense (there exist algorithms that can solve 279 | any problem written as above in polynomial time, while simplex method degenerates to exponential 280 | time for some special cases), it is well-studied, easy to implement and is shown to work well for 281 | real-life purposes. 282 | 283 | The particular implementation is taken almost verbatim from **Introduction to Algorithms, third 284 | edition** by T. H. Cormen, C. E. Leiserson, R. L. Rivest and Clifford Stein. In particular, the 285 | Bland's rule is used to prevent cycling. 286 | 287 | @param Func This row-vector corresponds to \f$c\f$ in the LP problem formulation (see above). It should 288 | contain 32- or 64-bit floating point numbers. As a convenience, column-vector may be also submitted, 289 | in the latter case it is understood to correspond to \f$c^T\f$. 290 | @param Constr `m`-by-`n+1` matrix, whose rightmost column corresponds to \f$b\f$ in formulation above 291 | and the remaining to \f$A\f$. It should contain 32- or 64-bit floating point numbers. 292 | @param z The solution will be returned here as a column-vector - it corresponds to \f$c\f$ in the 293 | formulation above. It will contain 64-bit floating point numbers. 294 | @return One of cv::SolveLPResult 295 | */ 296 | CV_EXPORTS_W int solveLP(InputArray Func, InputArray Constr, OutputArray z); 297 | 298 | //! @} 299 | 300 | }// cv 301 | 302 | #endif 303 | -------------------------------------------------------------------------------- /3rdparty/include/opencv2/core/ovx.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | 5 | // Copyright (C) 2016, Intel Corporation, all rights reserved. 6 | // Third party copyrights are property of their respective owners. 7 | 8 | // OpenVX related definitions and declarations 9 | 10 | #pragma once 11 | #ifndef OPENCV_OVX_HPP 12 | #define OPENCV_OVX_HPP 13 | 14 | #include "cvdef.h" 15 | 16 | namespace cv 17 | { 18 | /// Check if use of OpenVX is possible 19 | CV_EXPORTS_W bool haveOpenVX(); 20 | 21 | /// Check if use of OpenVX is enabled 22 | CV_EXPORTS_W bool useOpenVX(); 23 | 24 | /// Enable/disable use of OpenVX 25 | CV_EXPORTS_W void setUseOpenVX(bool flag); 26 | } // namespace cv 27 | 28 | #endif // OPENCV_OVX_HPP 29 | -------------------------------------------------------------------------------- /3rdparty/include/opencv2/core/saturate.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 | // Copyright (C) 2013, OpenCV Foundation, all rights reserved. 16 | // Copyright (C) 2014, Itseez Inc., all rights reserved. 17 | // Third party copyrights are property of their respective owners. 18 | // 19 | // Redistribution and use in source and binary forms, with or without modification, 20 | // are permitted provided that the following conditions are met: 21 | // 22 | // * Redistribution's of source code must retain the above copyright notice, 23 | // this list of conditions and the following disclaimer. 24 | // 25 | // * Redistribution's in binary form must reproduce the above copyright notice, 26 | // this list of conditions and the following disclaimer in the documentation 27 | // and/or other materials provided with the distribution. 28 | // 29 | // * The name of the copyright holders may not be used to endorse or promote products 30 | // derived from this software without specific prior written permission. 31 | // 32 | // This software is provided by the copyright holders and contributors "as is" and 33 | // any express or implied warranties, including, but not limited to, the implied 34 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 35 | // In no event shall the Intel Corporation or contributors be liable for any direct, 36 | // indirect, incidental, special, exemplary, or consequential damages 37 | // (including, but not limited to, procurement of substitute goods or services; 38 | // loss of use, data, or profits; or business interruption) however caused 39 | // and on any theory of liability, whether in contract, strict liability, 40 | // or tort (including negligence or otherwise) arising in any way out of 41 | // the use of this software, even if advised of the possibility of such damage. 42 | // 43 | //M*/ 44 | 45 | #ifndef OPENCV_CORE_SATURATE_HPP 46 | #define OPENCV_CORE_SATURATE_HPP 47 | 48 | #include "opencv2/core/cvdef.h" 49 | #include "opencv2/core/fast_math.hpp" 50 | 51 | namespace cv 52 | { 53 | 54 | //! @addtogroup core_utils 55 | //! @{ 56 | 57 | /////////////// saturate_cast (used in image & signal processing) /////////////////// 58 | 59 | /** @brief Template function for accurate conversion from one primitive type to another. 60 | 61 | The function saturate_cast resembles the standard C++ cast operations, such as static_cast\() 62 | and others. It perform an efficient and accurate conversion from one primitive type to another 63 | (see the introduction chapter). saturate in the name means that when the input value v is out of the 64 | range of the target type, the result is not formed just by taking low bits of the input, but instead 65 | the value is clipped. For example: 66 | @code 67 | uchar a = saturate_cast(-100); // a = 0 (UCHAR_MIN) 68 | short b = saturate_cast(33333.33333); // b = 32767 (SHRT_MAX) 69 | @endcode 70 | Such clipping is done when the target type is unsigned char , signed char , unsigned short or 71 | signed short . For 32-bit integers, no clipping is done. 72 | 73 | When the parameter is a floating-point value and the target type is an integer (8-, 16- or 32-bit), 74 | the floating-point value is first rounded to the nearest integer and then clipped if needed (when 75 | the target type is 8- or 16-bit). 76 | 77 | @param v Function parameter. 78 | @sa add, subtract, multiply, divide, Mat::convertTo 79 | */ 80 | template static inline _Tp saturate_cast(uchar v) { return _Tp(v); } 81 | /** @overload */ 82 | template static inline _Tp saturate_cast(schar v) { return _Tp(v); } 83 | /** @overload */ 84 | template static inline _Tp saturate_cast(ushort v) { return _Tp(v); } 85 | /** @overload */ 86 | template static inline _Tp saturate_cast(short v) { return _Tp(v); } 87 | /** @overload */ 88 | template static inline _Tp saturate_cast(unsigned v) { return _Tp(v); } 89 | /** @overload */ 90 | template static inline _Tp saturate_cast(int v) { return _Tp(v); } 91 | /** @overload */ 92 | template static inline _Tp saturate_cast(float v) { return _Tp(v); } 93 | /** @overload */ 94 | template static inline _Tp saturate_cast(double v) { return _Tp(v); } 95 | /** @overload */ 96 | template static inline _Tp saturate_cast(int64 v) { return _Tp(v); } 97 | /** @overload */ 98 | template static inline _Tp saturate_cast(uint64 v) { return _Tp(v); } 99 | 100 | template<> inline uchar saturate_cast(schar v) { return (uchar)std::max((int)v, 0); } 101 | template<> inline uchar saturate_cast(ushort v) { return (uchar)std::min((unsigned)v, (unsigned)UCHAR_MAX); } 102 | template<> inline uchar saturate_cast(int v) { return (uchar)((unsigned)v <= UCHAR_MAX ? v : v > 0 ? UCHAR_MAX : 0); } 103 | template<> inline uchar saturate_cast(short v) { return saturate_cast((int)v); } 104 | template<> inline uchar saturate_cast(unsigned v) { return (uchar)std::min(v, (unsigned)UCHAR_MAX); } 105 | template<> inline uchar saturate_cast(float v) { int iv = cvRound(v); return saturate_cast(iv); } 106 | template<> inline uchar saturate_cast(double v) { int iv = cvRound(v); return saturate_cast(iv); } 107 | template<> inline uchar saturate_cast(int64 v) { return (uchar)((uint64)v <= (uint64)UCHAR_MAX ? v : v > 0 ? UCHAR_MAX : 0); } 108 | template<> inline uchar saturate_cast(uint64 v) { return (uchar)std::min(v, (uint64)UCHAR_MAX); } 109 | 110 | template<> inline schar saturate_cast(uchar v) { return (schar)std::min((int)v, SCHAR_MAX); } 111 | template<> inline schar saturate_cast(ushort v) { return (schar)std::min((unsigned)v, (unsigned)SCHAR_MAX); } 112 | template<> inline schar saturate_cast(int v) { return (schar)((unsigned)(v-SCHAR_MIN) <= (unsigned)UCHAR_MAX ? v : v > 0 ? SCHAR_MAX : SCHAR_MIN); } 113 | template<> inline schar saturate_cast(short v) { return saturate_cast((int)v); } 114 | template<> inline schar saturate_cast(unsigned v) { return (schar)std::min(v, (unsigned)SCHAR_MAX); } 115 | template<> inline schar saturate_cast(float v) { int iv = cvRound(v); return saturate_cast(iv); } 116 | template<> inline schar saturate_cast(double v) { int iv = cvRound(v); return saturate_cast(iv); } 117 | template<> inline schar saturate_cast(int64 v) { return (schar)((uint64)((int64)v-SCHAR_MIN) <= (uint64)UCHAR_MAX ? v : v > 0 ? SCHAR_MAX : SCHAR_MIN); } 118 | template<> inline schar saturate_cast(uint64 v) { return (schar)std::min(v, (uint64)SCHAR_MAX); } 119 | 120 | template<> inline ushort saturate_cast(schar v) { return (ushort)std::max((int)v, 0); } 121 | template<> inline ushort saturate_cast(short v) { return (ushort)std::max((int)v, 0); } 122 | template<> inline ushort saturate_cast(int v) { return (ushort)((unsigned)v <= (unsigned)USHRT_MAX ? v : v > 0 ? USHRT_MAX : 0); } 123 | template<> inline ushort saturate_cast(unsigned v) { return (ushort)std::min(v, (unsigned)USHRT_MAX); } 124 | template<> inline ushort saturate_cast(float v) { int iv = cvRound(v); return saturate_cast(iv); } 125 | template<> inline ushort saturate_cast(double v) { int iv = cvRound(v); return saturate_cast(iv); } 126 | template<> inline ushort saturate_cast(int64 v) { return (ushort)((uint64)v <= (uint64)USHRT_MAX ? v : v > 0 ? USHRT_MAX : 0); } 127 | template<> inline ushort saturate_cast(uint64 v) { return (ushort)std::min(v, (uint64)USHRT_MAX); } 128 | 129 | template<> inline short saturate_cast(ushort v) { return (short)std::min((int)v, SHRT_MAX); } 130 | template<> inline short saturate_cast(int v) { return (short)((unsigned)(v - SHRT_MIN) <= (unsigned)USHRT_MAX ? v : v > 0 ? SHRT_MAX : SHRT_MIN); } 131 | template<> inline short saturate_cast(unsigned v) { return (short)std::min(v, (unsigned)SHRT_MAX); } 132 | template<> inline short saturate_cast(float v) { int iv = cvRound(v); return saturate_cast(iv); } 133 | template<> inline short saturate_cast(double v) { int iv = cvRound(v); return saturate_cast(iv); } 134 | template<> inline short saturate_cast(int64 v) { return (short)((uint64)((int64)v - SHRT_MIN) <= (uint64)USHRT_MAX ? v : v > 0 ? SHRT_MAX : SHRT_MIN); } 135 | template<> inline short saturate_cast(uint64 v) { return (short)std::min(v, (uint64)SHRT_MAX); } 136 | 137 | template<> inline int saturate_cast(unsigned v) { return (int)std::min(v, (unsigned)INT_MAX); } 138 | template<> inline int saturate_cast(int64 v) { return (int)((uint64)(v - INT_MIN) <= (uint64)UINT_MAX ? v : v > 0 ? INT_MAX : INT_MIN); } 139 | template<> inline int saturate_cast(uint64 v) { return (int)std::min(v, (uint64)INT_MAX); } 140 | template<> inline int saturate_cast(float v) { return cvRound(v); } 141 | template<> inline int saturate_cast(double v) { return cvRound(v); } 142 | 143 | template<> inline unsigned saturate_cast(schar v) { return (unsigned)std::max(v, (schar)0); } 144 | template<> inline unsigned saturate_cast(short v) { return (unsigned)std::max(v, (short)0); } 145 | template<> inline unsigned saturate_cast(int v) { return (unsigned)std::max(v, (int)0); } 146 | template<> inline unsigned saturate_cast(int64 v) { return (unsigned)((uint64)v <= (uint64)UINT_MAX ? v : v > 0 ? UINT_MAX : 0); } 147 | template<> inline unsigned saturate_cast(uint64 v) { return (unsigned)std::min(v, (uint64)UINT_MAX); } 148 | // we intentionally do not clip negative numbers, to make -1 become 0xffffffff etc. 149 | template<> inline unsigned saturate_cast(float v) { return static_cast(cvRound(v)); } 150 | template<> inline unsigned saturate_cast(double v) { return static_cast(cvRound(v)); } 151 | 152 | template<> inline uint64 saturate_cast(schar v) { return (uint64)std::max(v, (schar)0); } 153 | template<> inline uint64 saturate_cast(short v) { return (uint64)std::max(v, (short)0); } 154 | template<> inline uint64 saturate_cast(int v) { return (uint64)std::max(v, (int)0); } 155 | template<> inline uint64 saturate_cast(int64 v) { return (uint64)std::max(v, (int64)0); } 156 | 157 | template<> inline int64 saturate_cast(uint64 v) { return (int64)std::min(v, (uint64)LLONG_MAX); } 158 | 159 | /** @overload */ 160 | template static inline _Tp saturate_cast(float16_t v) { return saturate_cast<_Tp>((float)v); } 161 | 162 | // in theory, we could use a LUT for 8u/8s->16f conversion, 163 | // but with hardware support for FP32->FP16 conversion the current approach is preferable 164 | template<> inline float16_t saturate_cast(uchar v) { return float16_t((float)v); } 165 | template<> inline float16_t saturate_cast(schar v) { return float16_t((float)v); } 166 | template<> inline float16_t saturate_cast(ushort v) { return float16_t((float)v); } 167 | template<> inline float16_t saturate_cast(short v) { return float16_t((float)v); } 168 | template<> inline float16_t saturate_cast(unsigned v){ return float16_t((float)v); } 169 | template<> inline float16_t saturate_cast(int v) { return float16_t((float)v); } 170 | template<> inline float16_t saturate_cast(uint64 v) { return float16_t((float)v); } 171 | template<> inline float16_t saturate_cast(int64 v) { return float16_t((float)v); } 172 | template<> inline float16_t saturate_cast(float v) { return float16_t(v); } 173 | template<> inline float16_t saturate_cast(double v) { return float16_t((float)v); } 174 | 175 | //! @} 176 | 177 | } // cv 178 | 179 | #endif // OPENCV_CORE_SATURATE_HPP 180 | -------------------------------------------------------------------------------- /3rdparty/include/opencv2/core/traits.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 | // Copyright (C) 2013, OpenCV Foundation, all rights reserved. 16 | // Third party copyrights are property of their respective owners. 17 | // 18 | // Redistribution and use in source and binary forms, with or without modification, 19 | // are permitted provided that the following conditions are met: 20 | // 21 | // * Redistribution's of source code must retain the above copyright notice, 22 | // this list of conditions and the following disclaimer. 23 | // 24 | // * Redistribution's in binary form must reproduce the above copyright notice, 25 | // this list of conditions and the following disclaimer in the documentation 26 | // and/or other materials provided with the distribution. 27 | // 28 | // * The name of the copyright holders may not be used to endorse or promote products 29 | // derived from this software without specific prior written permission. 30 | // 31 | // This software is provided by the copyright holders and contributors "as is" and 32 | // any express or implied warranties, including, but not limited to, the implied 33 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 34 | // In no event shall the Intel Corporation or contributors be liable for any direct, 35 | // indirect, incidental, special, exemplary, or consequential damages 36 | // (including, but not limited to, procurement of substitute goods or services; 37 | // loss of use, data, or profits; or business interruption) however caused 38 | // and on any theory of liability, whether in contract, strict liability, 39 | // or tort (including negligence or otherwise) arising in any way out of 40 | // the use of this software, even if advised of the possibility of such damage. 41 | // 42 | //M*/ 43 | 44 | #ifndef OPENCV_CORE_TRAITS_HPP 45 | #define OPENCV_CORE_TRAITS_HPP 46 | 47 | #include "opencv2/core/cvdef.h" 48 | 49 | namespace cv 50 | { 51 | 52 | //#define OPENCV_TRAITS_ENABLE_DEPRECATED 53 | 54 | //! @addtogroup core_basic 55 | //! @{ 56 | 57 | /** @brief Template "trait" class for OpenCV primitive data types. 58 | 59 | @note Deprecated. This is replaced by "single purpose" traits: traits::Type and traits::Depth 60 | 61 | A primitive OpenCV data type is one of unsigned char, bool, signed char, unsigned short, signed 62 | short, int, float, double, or a tuple of values of one of these types, where all the values in the 63 | tuple have the same type. Any primitive type from the list can be defined by an identifier in the 64 | form CV_\{U|S|F}C(\), for example: uchar \~ CV_8UC1, 3-element 65 | floating-point tuple \~ CV_32FC3, and so on. A universal OpenCV structure that is able to store a 66 | single instance of such a primitive data type is Vec. Multiple instances of such a type can be 67 | stored in a std::vector, Mat, Mat_, SparseMat, SparseMat_, or any other container that is able to 68 | store Vec instances. 69 | 70 | The DataType class is basically used to provide a description of such primitive data types without 71 | adding any fields or methods to the corresponding classes (and it is actually impossible to add 72 | anything to primitive C/C++ data types). This technique is known in C++ as class traits. It is not 73 | DataType itself that is used but its specialized versions, such as: 74 | @code 75 | template<> class DataType 76 | { 77 | typedef uchar value_type; 78 | typedef int work_type; 79 | typedef uchar channel_type; 80 | enum { channel_type = CV_8U, channels = 1, fmt='u', type = CV_8U }; 81 | }; 82 | ... 83 | template DataType > 84 | { 85 | typedef std::complex<_Tp> value_type; 86 | typedef std::complex<_Tp> work_type; 87 | typedef _Tp channel_type; 88 | // DataDepth is another helper trait class 89 | enum { depth = DataDepth<_Tp>::value, channels=2, 90 | fmt=(channels-1)*256+DataDepth<_Tp>::fmt, 91 | type=CV_MAKETYPE(depth, channels) }; 92 | }; 93 | ... 94 | @endcode 95 | The main purpose of this class is to convert compilation-time type information to an 96 | OpenCV-compatible data type identifier, for example: 97 | @code 98 | // allocates a 30x40 floating-point matrix 99 | Mat A(30, 40, DataType::type); 100 | 101 | Mat B = Mat_ >(3, 3); 102 | // the statement below will print 6, 2 , that is depth == CV_64F, channels == 2 103 | cout << B.depth() << ", " << B.channels() << endl; 104 | @endcode 105 | So, such traits are used to tell OpenCV which data type you are working with, even if such a type is 106 | not native to OpenCV. For example, the matrix B initialization above is compiled because OpenCV 107 | defines the proper specialized template class DataType\ \> . This mechanism is also 108 | useful (and used in OpenCV this way) for generic algorithms implementations. 109 | 110 | @note Default values were dropped to stop confusing developers about using of unsupported types (see #7599) 111 | */ 112 | template class DataType 113 | { 114 | public: 115 | #ifdef OPENCV_TRAITS_ENABLE_DEPRECATED 116 | typedef _Tp value_type; 117 | typedef value_type work_type; 118 | typedef value_type channel_type; 119 | typedef value_type vec_type; 120 | enum { generic_type = 1, 121 | depth = -1, 122 | channels = 1, 123 | fmt = 0, 124 | type = CV_MAKETYPE(depth, channels) 125 | }; 126 | #endif 127 | }; 128 | 129 | template<> class DataType 130 | { 131 | public: 132 | typedef bool value_type; 133 | typedef int work_type; 134 | typedef value_type channel_type; 135 | typedef value_type vec_type; 136 | enum { generic_type = 0, 137 | depth = CV_8U, 138 | channels = 1, 139 | fmt = (int)'u', 140 | type = CV_MAKETYPE(depth, channels) 141 | }; 142 | }; 143 | 144 | template<> class DataType 145 | { 146 | public: 147 | typedef uchar value_type; 148 | typedef int work_type; 149 | typedef value_type channel_type; 150 | typedef value_type vec_type; 151 | enum { generic_type = 0, 152 | depth = CV_8U, 153 | channels = 1, 154 | fmt = (int)'u', 155 | type = CV_MAKETYPE(depth, channels) 156 | }; 157 | }; 158 | 159 | template<> class DataType 160 | { 161 | public: 162 | typedef schar value_type; 163 | typedef int work_type; 164 | typedef value_type channel_type; 165 | typedef value_type vec_type; 166 | enum { generic_type = 0, 167 | depth = CV_8S, 168 | channels = 1, 169 | fmt = (int)'c', 170 | type = CV_MAKETYPE(depth, channels) 171 | }; 172 | }; 173 | 174 | template<> class DataType 175 | { 176 | public: 177 | typedef schar value_type; 178 | typedef int work_type; 179 | typedef value_type channel_type; 180 | typedef value_type vec_type; 181 | enum { generic_type = 0, 182 | depth = CV_8S, 183 | channels = 1, 184 | fmt = (int)'c', 185 | type = CV_MAKETYPE(depth, channels) 186 | }; 187 | }; 188 | 189 | template<> class DataType 190 | { 191 | public: 192 | typedef ushort value_type; 193 | typedef int work_type; 194 | typedef value_type channel_type; 195 | typedef value_type vec_type; 196 | enum { generic_type = 0, 197 | depth = CV_16U, 198 | channels = 1, 199 | fmt = (int)'w', 200 | type = CV_MAKETYPE(depth, channels) 201 | }; 202 | }; 203 | 204 | template<> class DataType 205 | { 206 | public: 207 | typedef short value_type; 208 | typedef int work_type; 209 | typedef value_type channel_type; 210 | typedef value_type vec_type; 211 | enum { generic_type = 0, 212 | depth = CV_16S, 213 | channels = 1, 214 | fmt = (int)'s', 215 | type = CV_MAKETYPE(depth, channels) 216 | }; 217 | }; 218 | 219 | template<> class DataType 220 | { 221 | public: 222 | typedef int value_type; 223 | typedef value_type work_type; 224 | typedef value_type channel_type; 225 | typedef value_type vec_type; 226 | enum { generic_type = 0, 227 | depth = CV_32S, 228 | channels = 1, 229 | fmt = (int)'i', 230 | type = CV_MAKETYPE(depth, channels) 231 | }; 232 | }; 233 | 234 | template<> class DataType 235 | { 236 | public: 237 | typedef float value_type; 238 | typedef value_type work_type; 239 | typedef value_type channel_type; 240 | typedef value_type vec_type; 241 | enum { generic_type = 0, 242 | depth = CV_32F, 243 | channels = 1, 244 | fmt = (int)'f', 245 | type = CV_MAKETYPE(depth, channels) 246 | }; 247 | }; 248 | 249 | template<> class DataType 250 | { 251 | public: 252 | typedef double value_type; 253 | typedef value_type work_type; 254 | typedef value_type channel_type; 255 | typedef value_type vec_type; 256 | enum { generic_type = 0, 257 | depth = CV_64F, 258 | channels = 1, 259 | fmt = (int)'d', 260 | type = CV_MAKETYPE(depth, channels) 261 | }; 262 | }; 263 | 264 | template<> class DataType 265 | { 266 | public: 267 | typedef float16_t value_type; 268 | typedef float work_type; 269 | typedef value_type channel_type; 270 | typedef value_type vec_type; 271 | enum { generic_type = 0, 272 | depth = CV_16F, 273 | channels = 1, 274 | fmt = (int)'h', 275 | type = CV_MAKETYPE(depth, channels) 276 | }; 277 | }; 278 | 279 | /** @brief A helper class for cv::DataType 280 | 281 | The class is specialized for each fundamental numerical data type supported by OpenCV. It provides 282 | DataDepth::value constant. 283 | */ 284 | template class DataDepth 285 | { 286 | public: 287 | enum 288 | { 289 | value = DataType<_Tp>::depth, 290 | fmt = DataType<_Tp>::fmt 291 | }; 292 | }; 293 | 294 | 295 | #ifdef OPENCV_TRAITS_ENABLE_DEPRECATED 296 | 297 | template class TypeDepth 298 | { 299 | #ifdef OPENCV_TRAITS_ENABLE_LEGACY_DEFAULTS 300 | enum { depth = CV_USRTYPE1 }; 301 | typedef void value_type; 302 | #endif 303 | }; 304 | 305 | template<> class TypeDepth 306 | { 307 | enum { depth = CV_8U }; 308 | typedef uchar value_type; 309 | }; 310 | 311 | template<> class TypeDepth 312 | { 313 | enum { depth = CV_8S }; 314 | typedef schar value_type; 315 | }; 316 | 317 | template<> class TypeDepth 318 | { 319 | enum { depth = CV_16U }; 320 | typedef ushort value_type; 321 | }; 322 | 323 | template<> class TypeDepth 324 | { 325 | enum { depth = CV_16S }; 326 | typedef short value_type; 327 | }; 328 | 329 | template<> class TypeDepth 330 | { 331 | enum { depth = CV_32S }; 332 | typedef int value_type; 333 | }; 334 | 335 | template<> class TypeDepth 336 | { 337 | enum { depth = CV_32F }; 338 | typedef float value_type; 339 | }; 340 | 341 | template<> class TypeDepth 342 | { 343 | enum { depth = CV_64F }; 344 | typedef double value_type; 345 | }; 346 | 347 | template<> class TypeDepth 348 | { 349 | enum { depth = CV_16F }; 350 | typedef float16_t value_type; 351 | }; 352 | 353 | #endif 354 | 355 | //! @} 356 | 357 | namespace traits { 358 | 359 | namespace internal { 360 | #define CV_CREATE_MEMBER_CHECK(X) \ 361 | template class CheckMember_##X { \ 362 | struct Fallback { int X; }; \ 363 | struct Derived : T, Fallback { }; \ 364 | template struct Check; \ 365 | typedef char CV_NO[1]; \ 366 | typedef char CV_YES[2]; \ 367 | template static CV_NO & func(Check *); \ 368 | template static CV_YES & func(...); \ 369 | public: \ 370 | typedef CheckMember_##X type; \ 371 | enum { value = sizeof(func(0)) == sizeof(CV_YES) }; \ 372 | }; 373 | 374 | CV_CREATE_MEMBER_CHECK(fmt) 375 | CV_CREATE_MEMBER_CHECK(type) 376 | 377 | } // namespace internal 378 | 379 | 380 | template 381 | struct Depth 382 | { enum { value = DataType::depth }; }; 383 | 384 | template 385 | struct Type 386 | { enum { value = DataType::type }; }; 387 | 388 | /** Similar to traits::Type but has value = -1 in case of unknown type (instead of compiler error) */ 389 | template >::value > 390 | struct SafeType {}; 391 | 392 | template 393 | struct SafeType 394 | { enum { value = -1 }; }; 395 | 396 | template 397 | struct SafeType 398 | { enum { value = Type::value }; }; 399 | 400 | 401 | template >::value > 402 | struct SafeFmt {}; 403 | 404 | template 405 | struct SafeFmt 406 | { enum { fmt = 0 }; }; 407 | 408 | template 409 | struct SafeFmt 410 | { enum { fmt = DataType::fmt }; }; 411 | 412 | 413 | } // namespace 414 | 415 | } // cv 416 | 417 | #endif // OPENCV_CORE_TRAITS_HPP 418 | -------------------------------------------------------------------------------- /3rdparty/include/opencv2/core/version.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | 5 | #ifndef OPENCV_VERSION_HPP 6 | #define OPENCV_VERSION_HPP 7 | 8 | #define CV_VERSION_MAJOR 4 9 | #define CV_VERSION_MINOR 3 10 | #define CV_VERSION_REVISION 0 11 | #define CV_VERSION_STATUS "" 12 | 13 | #define CVAUX_STR_EXP(__A) #__A 14 | #define CVAUX_STR(__A) CVAUX_STR_EXP(__A) 15 | 16 | #define CVAUX_STRW_EXP(__A) L ## #__A 17 | #define CVAUX_STRW(__A) CVAUX_STRW_EXP(__A) 18 | 19 | #define CV_VERSION CVAUX_STR(CV_VERSION_MAJOR) "." CVAUX_STR(CV_VERSION_MINOR) "." CVAUX_STR(CV_VERSION_REVISION) CV_VERSION_STATUS 20 | 21 | /* old style version constants*/ 22 | #define CV_MAJOR_VERSION CV_VERSION_MAJOR 23 | #define CV_MINOR_VERSION CV_VERSION_MINOR 24 | #define CV_SUBMINOR_VERSION CV_VERSION_REVISION 25 | 26 | #endif // OPENCV_VERSION_HPP 27 | -------------------------------------------------------------------------------- /3rdparty/include/opencv2/opencv.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009-2010, Willow Garage Inc., all rights reserved. 15 | // Third party copyrights are property of their respective owners. 16 | // 17 | // Redistribution and use in source and binary forms, with or without modification, 18 | // are permitted provided that the following conditions are met: 19 | // 20 | // * Redistribution's of source code must retain the above copyright notice, 21 | // this list of conditions and the following disclaimer. 22 | // 23 | // * Redistribution's in binary form must reproduce the above copyright notice, 24 | // this list of conditions and the following disclaimer in the documentation 25 | // and/or other materials provided with the distribution. 26 | // 27 | // * The name of the copyright holders may not be used to endorse or promote products 28 | // derived from this software without specific prior written permission. 29 | // 30 | // This software is provided by the copyright holders and contributors "as is" and 31 | // any express or implied warranties, including, but not limited to, the implied 32 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 33 | // In no event shall the Intel Corporation or contributors be liable for any direct, 34 | // indirect, incidental, special, exemplary, or consequential damages 35 | // (including, but not limited to, procurement of substitute goods or services; 36 | // loss of use, data, or profits; or business interruption) however caused 37 | // and on any theory of liability, whether in contract, strict liability, 38 | // or tort (including negligence or otherwise) arising in any way out of 39 | // the use of this software, even if advised of the possibility of such damage. 40 | // 41 | //M*/ 42 | 43 | #ifndef OPENCV_ALL_HPP 44 | #define OPENCV_ALL_HPP 45 | 46 | // File that defines what modules where included during the build of OpenCV 47 | // These are purely the defines of the correct HAVE_OPENCV_modulename values 48 | #include "opencv2/opencv_modules.hpp" 49 | 50 | // Then the list of defines is checked to include the correct headers 51 | // Core library is always included --> without no OpenCV functionality available 52 | #include "opencv2/core.hpp" 53 | 54 | // Then the optional modules are checked 55 | #ifdef HAVE_OPENCV_CALIB3D 56 | #include "opencv2/calib3d.hpp" 57 | #endif 58 | #ifdef HAVE_OPENCV_FEATURES2D 59 | #include "opencv2/features2d.hpp" 60 | #endif 61 | #ifdef HAVE_OPENCV_DNN 62 | #include "opencv2/dnn.hpp" 63 | #endif 64 | #ifdef HAVE_OPENCV_FLANN 65 | #include "opencv2/flann.hpp" 66 | #endif 67 | #ifdef HAVE_OPENCV_HIGHGUI 68 | #include "opencv2/highgui.hpp" 69 | #endif 70 | #ifdef HAVE_OPENCV_IMGCODECS 71 | #include "opencv2/imgcodecs.hpp" 72 | #endif 73 | #ifdef HAVE_OPENCV_IMGPROC 74 | #include "opencv2/imgproc.hpp" 75 | #endif 76 | #ifdef HAVE_OPENCV_ML 77 | #include "opencv2/ml.hpp" 78 | #endif 79 | #ifdef HAVE_OPENCV_OBJDETECT 80 | #include "opencv2/objdetect.hpp" 81 | #endif 82 | #ifdef HAVE_OPENCV_PHOTO 83 | #include "opencv2/photo.hpp" 84 | #endif 85 | #ifdef HAVE_OPENCV_STITCHING 86 | #include "opencv2/stitching.hpp" 87 | #endif 88 | #ifdef HAVE_OPENCV_VIDEO 89 | #include "opencv2/video.hpp" 90 | #endif 91 | #ifdef HAVE_OPENCV_VIDEOIO 92 | #include "opencv2/videoio.hpp" 93 | #endif 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /3rdparty/include/opencv2/opencv_modules.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ** File generated automatically, do not modify ** 3 | * 4 | * This file defines the list of modules available in current build configuration 5 | * 6 | * 7 | */ 8 | 9 | // This definition means that OpenCV is built with enabled non-free code. 10 | // For example, patented algorithms for non-profit/non-commercial use only. 11 | /* #undef OPENCV_ENABLE_NONFREE */ 12 | 13 | #define HAVE_OPENCV_CORE 14 | #define HAVE_OPENCV_IMGCODECS 15 | #define HAVE_OPENCV_IMGPROC 16 | 17 | 18 | -------------------------------------------------------------------------------- /3rdparty/include/tlg2png/Image.h: -------------------------------------------------------------------------------- 1 | #ifndef IMAGE_H_ 2 | #define IMAGE_H_ 3 | #include 4 | 5 | struct Image 6 | { 7 | uint32_t width; 8 | uint32_t height; 9 | uint32_t *pixels; 10 | }; 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /3rdparty/include/tlg2png/TlgConverter.h: -------------------------------------------------------------------------------- 1 | #ifndef TLG_CONVERTER_H_ 2 | #define TLG_CONVERTER_H_ 3 | #include 4 | #include "Image.h" 5 | 6 | class TlgConverter 7 | { 8 | public: 9 | const Image read(std::string path) const; 10 | void save(const Image image, std::string path) const; 11 | }; 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /3rdparty/lib/libopencv_core430.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzyy21/CGMerge/050b25da99122824c915a2a6b4be664f52ddd77b/3rdparty/lib/libopencv_core430.dll -------------------------------------------------------------------------------- /3rdparty/lib/libopencv_imgcodecs430.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzyy21/CGMerge/050b25da99122824c915a2a6b4be664f52ddd77b/3rdparty/lib/libopencv_imgcodecs430.dll -------------------------------------------------------------------------------- /3rdparty/lib/libopencv_imgproc430.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzyy21/CGMerge/050b25da99122824c915a2a6b4be664f52ddd77b/3rdparty/lib/libopencv_imgproc430.dll -------------------------------------------------------------------------------- /3rdparty/lib/libpng16.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzyy21/CGMerge/050b25da99122824c915a2a6b4be664f52ddd77b/3rdparty/lib/libpng16.dll -------------------------------------------------------------------------------- /3rdparty/lib/libtlg2png.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzyy21/CGMerge/050b25da99122824c915a2a6b4be664f52ddd77b/3rdparty/lib/libtlg2png.dll -------------------------------------------------------------------------------- /3rdparty/lib/libzlib.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzyy21/CGMerge/050b25da99122824c915a2a6b4be664f52ddd77b/3rdparty/lib/libzlib.dll -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # ################################################################ 2 | # FilePath : Makefile 3 | # Project Name : CGMerge 4 | # Author : zzyy21 5 | # Create Time : 2020-06-27 19:07:46 6 | # Modifed by : zzyy21 7 | # Last Modify : 2020-07-05 18:35:29 8 | # Description : Makefile for MinGW make on Windows 9 | # Revision : v1.0 - first release 10 | # v2.0 - Updated directory structure and Makefile 11 | # for integrating third-party libraries 12 | # v3.0 - change default target to exe instead of 13 | # exe-static due to the use of OpenCV. 14 | # delete exe-static target. 15 | # ################################################################ 16 | 17 | .PHONY : default_target 18 | default_target: exe 19 | 20 | # rules for build all 21 | # choose item for build all 22 | .PHONY :all 23 | all: exe 24 | 25 | # build target filename 26 | TARGET = CGMerge 27 | 28 | # compiler and cpp standard setting 29 | CC = g++ 30 | STD_FLAG = c++11 31 | 32 | # clean command, set according to shell 33 | CLEAN_CMD = del /q 34 | 35 | # file extension definition 36 | # source file 37 | SOURCE_FILEEXT = cpp 38 | # dynamic link library 39 | DLIB_FILEEXT = dll 40 | # static library 41 | SLIB_FILEEXT = a 42 | 43 | # set extra comple flags 44 | COMPILE_FLAGS = -Wall -Wextra -g 45 | 46 | # extra include directory 47 | # format: 48 | # example: EXTRA_INCLUDE_PATH = foo/include bar/include 49 | EXTRA_INCLUDE_PATH = 50 | 51 | # extra library directory 52 | # format: 53 | # example: EXTRA_LIBRARY_PATH = foo/lib bar/lib 54 | EXTRA_LIBRARY_PATH = 55 | 56 | # extra libraries 57 | # format: 58 | # example: EXTRA_LIBRARIES = foo bar 59 | EXTRA_LIBRARIES = tlg2png png16 zlib opencv_imgcodecs430 opencv_imgproc430 opencv_core430 60 | 61 | # project path definition 62 | BUILD_PATH = build 63 | OBJECT_PATH = $(BUILD_PATH)/obj 64 | PUBLIC_INCLUDE_PATH = include 65 | SOURCE_PATH = src 66 | 67 | 68 | ################################################### 69 | # Generally no need to change the lines below # 70 | ################################################### 71 | 72 | # file list 73 | SOURCES = $(wildcard $(SOURCE_PATH)/*.$(SOURCE_FILEEXT)) 74 | OBJECTS = $(patsubst %.$(SOURCE_FILEEXT),$(OBJECT_PATH)/%.o, $(notdir $(SOURCES))) 75 | 76 | # 3rdparty library auto import 77 | LIBRARY_PATH = 3rdparty/lib 78 | LIBRARY_INCLUDE_PATH = 3rdparty/include 79 | #LIBRARIES = $(wildcard $(LIBRARY_PATH)/*) 80 | 81 | 82 | ################ generate compile flags ################ 83 | # include path link flags -I 84 | INCLUDE_DIRS = $(EXTRA_INCLUDE_PATH) $(PUBLIC_INCLUDE_PATH) $(LIBRARY_INCLUDE_PATH) 85 | IFLAGS = ${foreach IFLAG,${INCLUDE_DIRS},-I${IFLAG}} 86 | 87 | # library path link flags -L 88 | LIB_DIRS = $(EXTRA_LIBRARY_PATH) $(LIBRARY_PATH) 89 | LDFLAGS = ${foreach LDFLAG,${LIB_DIRS},-L${LDFLAG}} 90 | 91 | LIBS = $(EXTRA_LIBRARIES) $(patsubst lib%,%, $(basename $(notdir $(LIBRARIES)))) 92 | LLFLAGS = ${foreach LLFLAG,${LIBS},-l${LLFLAG}} 93 | 94 | # general compile flags 95 | CFLAGS = -std=$(STD_FLAG) $(COMPILE_FLAGS) 96 | 97 | 98 | ################ build rules ################ 99 | 100 | # rules for build dynamic link executable file 101 | .PHONY :exe 102 | exe: $(BUILD_PATH)/$(TARGET).exe 103 | $(BUILD_PATH)/$(TARGET).exe: $(OBJECTS) 104 | $(CC) -o $(BUILD_PATH)/$(TARGET).exe $(OBJECTS) $(LDFLAGS) $(LLFLAGS) $(CFLAGS) 105 | 106 | # pull in dependency info for *existing* .o files 107 | -include $(OBJECTS:.o=.d) 108 | 109 | # rules for build objective 110 | $(OBJECT_PATH)/%.o: $(SOURCE_PATH)/%.$(SOURCE_FILEEXT) 111 | $(CC) -c -o $@ $< $(IFLAGS) $(CFLAGS) 112 | $(CC) -MM -MP -MT $@ -o $(@:.o=.d) $< $(IFLAGS) $(CFLAGS) 113 | 114 | 115 | # print all flags, sources, libs, etc. for check 116 | .PHONY :check 117 | check: 118 | @echo Source files: $(SOURCES) 119 | @echo Include flags: $(IFLAGS) 120 | @echo Lib dir flags: $(LDFLAGS) 121 | @echo Library flags: $(LLFLAGS) 122 | @echo Compile flags: $(CFLAGS) 123 | 124 | 125 | # delete all builded things 126 | .PHONY :clean 127 | clean: 128 | cd $(BUILD_PATH) && $(CLEAN_CMD) *.exe 129 | cd $(OBJECT_PATH) && $(CLEAN_CMD) *.o 130 | cd $(OBJECT_PATH) && $(CLEAN_CMD) *.d 131 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CGMerge 2 | 3 | CGMerge is a tool to merge CG of YuzuSoft galgame. 4 | This tool will read the CG list and merge rules from the csv file and merge resources into CGs. 5 | This tool does not have the function of extracting files from the game, and needs to be used with extracting tools. 6 | 7 | ## Ciallo~(∠・ω< )⌒★ 8 | 9 | CGMerge是一个合成柚子社galgame CG的工具。 10 | 将从csv文件中读取CG列表及合成规则并合成CG。 11 | 这个工具本身不具备解包的功能,需要搭配解包工具使用。 12 | [查看中文说明](/doc/README_zh-CN.md) 13 | 14 | ## How to use 15 | 16 | [Full instruction of extract resources and merge CG (zh-CN only)](/doc/full_flow.md) 17 | 18 | ### Input files needed (get from extracted resources) 19 | 20 | data.xp3 -> main/`cglist.csv` & `imagediffmap.csv`, These two files must `be converted into ANSI encoding format` 21 | evimage.xp3 -> `*.json` & `*/n.tlg` 22 | 23 | The input files need to be placed in the same directory as the tool's executable file. 24 | 25 | ### Merge CGs 26 | 27 | After all needed input files prepared 28 | Double click to run CGMerge.exe 29 | or 30 | run the program in command line 31 | 32 | ``` cmd 33 | CGMerge 34 | ``` 35 | 36 | ## Development setting 37 | 38 | The Makefile is only tested for cmd and MinGW-w64. 39 | 40 | Windows cmd + MinGW-w64: 41 | 42 | ``` cmd 43 | make 44 | ``` 45 | 46 | If the Makefile does not work in your enviroment, you may build the files manually. 47 | 48 | The `source files` are located in `src/` 49 | 50 | Thirdparty libraries used: 51 | 52 | 1. [tlg2png](https://github.com/vn-tools/tlg2png) for extracting images from tlg file. Source files for building this library is attached in 3rdparty/3rdparty_src/tlg2png/ 53 | 54 | 2. [libpng](http://www.libpng.org/pub/png/libpng.html), dependency of tlg2png 55 | 56 | 3. [zlib](https://www.zlib.net/), dependency of libpng 57 | 58 | 4. [OpenCV](https://opencv.org/), used in image processing functions 59 | 60 | Thirdparty library include path: `3rdparty/include/` 61 | 62 | Thirdparty library path: `3rdparty/lib/` 63 | The libraries provided in the project are `dll` file compiled with `MinGW-w64`, you may use your own build if this not work or you use a different enviroment. 64 | Version of library provided in `3rdparty/lib/`: 65 | 66 | ````txt 67 | tlg2png: v1.0 68 | libpng: 1.6.37 69 | zlib: 1.2.11 70 | OpenCV: 4.3.0 (required functions only) 71 | ```` 72 | 73 | ## License 74 | 75 | CGMerge is released under the [GPL License](http://www.gnu.org/licenses/gpl.html). 76 | 77 | Thirdparty libraries used are subject to their license. 78 | -------------------------------------------------------------------------------- /doc/README_zh-CN.md: -------------------------------------------------------------------------------- 1 | # CGMerge 2 | 3 | CGMerge是一个合成柚子社galgame CG的工具。 4 | 将从csv文件中读取CG列表及合成规则并合成CG。 5 | 这个工具本身不具备解包的功能,需要搭配解包工具使用。 6 | 7 | ## Ciallo~(∠・ω< )⌒★ 8 | 9 | [English Version of README](/README.md) 10 | 11 | ## 目录 12 | 13 | * [如何使用](##如何使用) 14 | * [开发配置](##开发配置) 15 | * [许可证](##许可证) 16 | 17 | ## 如何使用 18 | 19 | [完整的解包合成流程](/doc/full_flow.md) 20 | 21 | ### 需要的输入文件(解包获得) 22 | 23 | data.xp3 -> main/`cglist.csv` & `imagediffmap.csv`, 并将文件`转换为ANSI编码`格式 24 | evimage -> `*.json` & `*/n.tlg` 25 | 26 | 输入文件需要和工具放在同一目录下。 27 | 28 | ### 执行合成 29 | 30 | 将所有输入文件准备好后 31 | 直接双击打开CGMerge.exe 32 | 或 33 | 在命令行中执行 34 | 35 | ``` cmd 36 | CGMerge 37 | ``` 38 | 39 | ## 开发配置 40 | 41 | Makefile仅供在cmd+MinGW-w64下使用。 42 | 43 | Windows cmd + MinGW-w64: 44 | 45 | ``` cmd 46 | make 47 | ``` 48 | 49 | 如果使用别的环境,Makefile可能不起作用,你需要手动编译。 50 | 51 | 源文件目录:`src/` 52 | 53 | 使用的第三方库: 54 | 55 | 1. [tlg2png](https://github.com/vn-tools/tlg2png) 用于从tlg文件中提取图像。源文件附在 3rdparty/3rdparty_src/tlg2png/ 56 | 57 | 2. [libpng](http://www.libpng.org/pub/png/libpng.html),tlg2png的依赖库 58 | 59 | 3. [zlib](https://www.zlib.net/),libpng的依赖库 60 | 61 | 4. [OpenCV](https://opencv.org/), 用于图像处理 62 | 63 | 第三方库头文件目录:`3rdparty/include/` 64 | 65 | 第三方库目录:`3rdparty/lib/` 66 | 项目中提供的库是使用 `MinGW-w64` 编译的 `dll` 文件 ,如果它不能正常使用,或者你使用别的环境,可能需要使用你自己编译的库文件。 67 | 在 `3rdparty/lib/` 目录下提供的库的版本: 68 | 69 | ````txt 70 | tlg2png: v1.0 71 | libpng: 1.6.37 72 | zlib: 1.2.11 73 | OpenCV: 4.3.0 (仅包含所需的功能) 74 | ```` 75 | 76 | ## 许可 77 | 78 | 本项目采用[GPL3.0](http://www.gnu.org/licenses/gpl.html)许可 79 | 80 | 使用的第三方库遵照第三方库的许可 81 | -------------------------------------------------------------------------------- /doc/full_flow.md: -------------------------------------------------------------------------------- 1 | ## 完整的解包合成流程 2 | 3 | 这是一份使用相关工具进行解包和CG合成的教程。\ 4 | 解包方法有很多,这里只说明其中一种(我最开始用的一种)。\ 5 | 这个工具也是基于这种方法原本的不足而编写的。 6 | 7 | [返回中文说明](/doc/README_zh-CN.md) 8 | [Back to README](/README.md) 9 | 10 | ### 需要的工具 11 | 12 | * [KrKrExtract](https://github.com/xmoeproject/KrkrExtract/releases) : xmoe的KiriKiri解包工具 13 | 14 | ### 解包与合成过程 15 | 16 | 1. 将KrKrExtract放入游戏目录下,并将游戏程序拖到KrKrExtract.exe上运行。 17 | 18 | 2. `Text Decryption` 选择 `Text`。将`data.xp3`拖进KrKrExtract的窗口,进行解码。解码完成后找到`./KrkrExtract_Output/data/main/` 目录下的 `cglist.csv` 及 `imagediffmap.csv` 两个文件。文件中包含了CG列表,并且根据列表中的CG名我们可以得到每张CG的合成规则。打开文件,并使用`ANSI`(GB2312)编码重新保存。此后合成使用编码修改后的文件。 19 | 20 | 3. `PSB Package` 中勾选 `JSON` 和 `Unpack Animation` 两项。将`evimage.xp3`拖进KrKrExtract的窗口,进行解码。解码后在 `./KrkrExtract_Output/evimage/` 得到 `*.json` 文件和同名目录,目录中包括 `.tlg` 文件。json文件中包含了CG的相关信息,图层则在各个tlg文件中。 21 | 22 | 4. 将`*.json`、json同名目录及目录中`.tlg`、ANSI编码的`cglist.csv`及`imagediffmap.csv`放在本工具同一目录下,执行`CGMerge`。泡杯咖啡等待工具运行完成,合成的CG将放在`CGOutput`目录中。 23 | 24 | ### Reference 25 | 26 | 1. 27 | -------------------------------------------------------------------------------- /src/cglayer.cpp: -------------------------------------------------------------------------------- 1 | /* **************************************************************** 2 | * FilePath : /src/cglayer.cpp 3 | * Project Name : CGMerge 4 | * Author : zzyy21 5 | * Create Time : 2020-06-22 22:32:07 6 | * Modifed by : zzyy21 7 | * Last Modify : 2020-07-11 00:31:41 8 | * Description : layer information 9 | * Revision : v1.0 - first release 10 | * v2.0 - Add function to call tlg2png to deal with 11 | * tlg files extracted by KrkrExtract. 12 | * Modify the rule for generating fileName_ to 13 | * match files processed by tlg2png. 14 | * v3.0 - add fuctions using OpenCV, read image 15 | * files and pad to target size. 16 | * v3.2 - modify to optimize appending layer 17 | * v3.3 - add support for negative left/top 18 | * handle out of range situation 19 | * **************************************************************** */ 20 | 21 | #include "cglayer.h" 22 | 23 | #include 24 | //#include 25 | #include "opencv2/opencv.hpp" 26 | 27 | #include "tlg2png/Image.h" 28 | #include "tlg2png/TlgConverter.h" 29 | 30 | // CGLayer constructor, get layer infomation from parameters. 31 | // set info variables and call tlg2png to extract png image 32 | // get the image into Mat 33 | // @param 1 - seriesName: layer series name 34 | // @param 2 - layerid: layer id, to find tlg file 35 | // @param 3 - width: target width of the layer 36 | // @param 4 - height: target height of the layer 37 | // @param 5 - left: column position when append layer on background 38 | // @param 6 - top: row position when append layer on background 39 | CGLayer::CGLayer(const std::string &seriesName, int layerid, int width, 40 | int height, int left, int top) { 41 | seriesName_ = seriesName; 42 | layerid_ = layerid; 43 | width_ = width; 44 | height_ = height; 45 | left_ = left; 46 | top_ = top; 47 | 48 | // v1.0 49 | // fileName_ = seriesName_ + "+pimg+" + std::to_string(layerid_) + ".tlg.png"; 50 | 51 | // v2.0 52 | fileName_ = seriesName_ + "/" + std::to_string(layerid_) + ".png"; 53 | 54 | tlg2png(); 55 | 56 | readImg(); 57 | } 58 | 59 | // No longer used after v3.3 60 | /* 61 | // CGLayer constructor, get layer infomation from parameters. 62 | // set info variables and call tlg2png to extract png image 63 | // get the image into Mat 64 | // @param 1 - seriesName: layer series name 65 | // @param 2 - layerid: layer id, to find tlg file 66 | // @param 3 - left: column position when append layer on background 67 | // @param 4 - top: row position when append layer on background 68 | CGLayer::CGLayer(const std::string &seriesName, int layerid, int left, int top) { 69 | seriesName_ = seriesName; 70 | layerid_ = layerid; 71 | left_ = left; 72 | top_ = top; 73 | 74 | // v1.0 75 | // fileName_ = seriesName_ + "+pimg+" + std::to_string(layerid_) + ".tlg.png"; 76 | 77 | // v2.0 78 | fileName_ = seriesName_ + "/" + std::to_string(layerid_) + ".png"; 79 | 80 | tlg2png(); 81 | 82 | readImg(); 83 | } 84 | */ 85 | 86 | CGLayer::~CGLayer() { 87 | } 88 | 89 | // return column position when append layer on background 90 | int CGLayer::left() { 91 | return left_; 92 | }; 93 | 94 | // return row position when append layer on background 95 | int CGLayer::top() { 96 | return top_; 97 | }; 98 | 99 | // return png file path of the layer 100 | std::string CGLayer::fileName() { 101 | return fileName_; 102 | } 103 | 104 | // find tlg file and extract to png 105 | void CGLayer::tlg2png() { 106 | std::string tlgFilePath = seriesName_ + "/" + std::to_string(layerid_) + ".tlg"; 107 | TlgConverter converter; 108 | Image image = converter.read(tlgFilePath); 109 | converter.save(image, fileName_); 110 | } 111 | 112 | // get cv::Mat from image file 113 | void CGLayer::readImg() { 114 | img_ = cv::imread(fileName_, cv::IMREAD_UNCHANGED); 115 | 116 | // No longer used after v3.2 117 | /* 118 | cv::Scalar padPixel(0, 0, 0, 0); 119 | int padTop = top_; 120 | int padBottom = height_ - img_.rows - top_; 121 | int padLeft = left_; 122 | int padRight = width_ - img_.cols - left_; 123 | cv::copyMakeBorder(img_, img_, padTop, padBottom, padLeft, padRight, cv::BORDER_CONSTANT, padPixel); 124 | */ 125 | 126 | // negative left or top 127 | // appear in amairo isle, ev414a 128 | if ((left_ < 0) && (top_ < 0)) { 129 | cv::Mat partImg_(img_, cv::Rect(-left_, -top_, img_.cols + left_, img_.rows + top_)); 130 | cv::Mat tmpMat = partImg_.clone(); 131 | img_ = tmpMat; 132 | left_ = 0; 133 | top_ = 0; 134 | } 135 | else if ((left_ < 0) && (top_ >= 0)) { 136 | cv::Mat partImg_(img_, cv::Rect(-left_, 0, img_.cols + left_, img_.rows)); 137 | cv::Mat tmpMat = partImg_.clone(); 138 | img_ = tmpMat; 139 | left_ = 0; 140 | } 141 | else if ((left_ >= 0) && (top_ < 0)) { 142 | cv::Mat partImg_(img_, cv::Rect(0, -top_, img_.cols, img_.rows + top_)); 143 | cv::Mat tmpMat = partImg_.clone(); 144 | img_ = tmpMat; 145 | top_ = 0; 146 | } 147 | 148 | // out of range 149 | // appear in sabbat of witch ev316ea 150 | int right = left_ + img_.cols; 151 | int down = top_ + img_.rows; 152 | if ((right > width_) && (down > height_)) { 153 | cv::Mat partImg_(img_, cv::Rect(0, 0, width_ - left_, height_ - top_)); 154 | cv::Mat tmpMat = partImg_.clone(); 155 | img_ = tmpMat; 156 | } 157 | else if ((right > width_) && (down <= height_)) { 158 | cv::Mat partImg_(img_, cv::Rect(0, 0, width_ - left_, img_.rows)); 159 | cv::Mat tmpMat = partImg_.clone(); 160 | img_ = tmpMat; 161 | } 162 | else if ((right <= width_) && (down > height_)) { 163 | cv::Mat partImg_(img_, cv::Rect(0, 0, img_.cols, height_ - top_)); 164 | cv::Mat tmpMat = partImg_.clone(); 165 | img_ = tmpMat; 166 | } 167 | 168 | } 169 | 170 | // return the readed image in cv::Mat format 171 | cv::Mat CGLayer::img() { 172 | return img_; 173 | } 174 | -------------------------------------------------------------------------------- /src/cglayer.h: -------------------------------------------------------------------------------- 1 | /* **************************************************************** 2 | * FilePath : /src/cglayer.h 3 | * Project Name : CGMerge 4 | * Author : zzyy21 5 | * Create Time : 2020-06-22 22:32:10 6 | * Modifed by : zzyy21 7 | * Last Modify : 2020-07-11 00:31:55 8 | * Description : class for layer information 9 | * Revision : v1.0 - first release 10 | * v2.0 - Add function to call tlg2png to deal with 11 | * tlg files extracted by KrkrExtract. 12 | * Modify the rule for generating fileName_ to 13 | * match files processed by tlg2png. 14 | * v3.0 - add fuctions using OpenCV, read image 15 | * files and pad to target size. 16 | * v3.2 - modify to optimize appending layer 17 | * v3.3 - add support for negative left/top 18 | * handle out of range situation 19 | * **************************************************************** */ 20 | 21 | #ifndef CGLAYER_H_ 22 | #define CGLAYER_H_ 23 | 24 | #include 25 | #include "opencv2/opencv.hpp" 26 | 27 | class CGLayer { 28 | private: 29 | std::string seriesName_; 30 | int layerid_; 31 | int width_; 32 | int height_; 33 | int left_; 34 | int top_; 35 | std::string fileName_; 36 | 37 | cv::Mat img_; 38 | 39 | void tlg2png(); 40 | 41 | void readImg(); 42 | 43 | public: 44 | CGLayer(const std::string &seriesName, int layerid, int width, 45 | int height, int left, int top); 46 | // **No longer used after v3.3 47 | //CGLayer(const std::string &seriesName, int layerid, int left, int top); 48 | ~CGLayer(); 49 | 50 | int left(); 51 | int top(); 52 | std::string fileName(); 53 | 54 | cv::Mat img(); 55 | }; 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/cglayerindex.cpp: -------------------------------------------------------------------------------- 1 | /* **************************************************************** 2 | * FilePath : /src/cglayerindex.cpp 3 | * Project Name : CGMerge 4 | * Author : zzyy21 5 | * Create Time : 2020-06-23 20:26:07 6 | * Modifed by : zzyy21 7 | * Last Modify : 2020-07-11 11:01:26 8 | * Description : layer index operation 9 | * Revision : v1.0 - Get layer info from txt file by expimg 10 | * v2.0 - Get layer info from json file by KrkrExtract 11 | * v3.0 - Modify function call to fit the change of 12 | * using OpenCV 13 | * v3.2 - modify to optimize appending layer 14 | * v3.3 - use new layer identify rule 15 | * add default layer for "diff" rule 16 | * **************************************************************** */ 17 | 18 | #include "cglayerindex.h" 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "cglayer.h" 25 | #include "json.hpp" 26 | 27 | // No longer used after v2.0 due to the use of json layer info 28 | /* 29 | // return the value get from txt format lines 30 | // @param 1 - line: input line with format:"xxx: " 31 | int CGLayerIndex::getValue(const std::string &line) { 32 | std::string tmpString; 33 | tmpString = line.substr(line.find(':') + 1); 34 | return stoi(tmpString); 35 | } 36 | */ 37 | 38 | // No longer use after v3.3, use getLayerId istead 39 | /* 40 | // get pictrue background and upper layer identifier from input line 41 | // @param 1 - line: input line with format:"name :" 42 | // @param 2 - p_bgLayer: pointer to store background identifier 43 | // @param 3 - p_upLayer: pointer to upper layer identifier 44 | void CGLayerIndex::getPicId(const std::string &line, int* p_bgLayer, int* p_upLayer) { 45 | int infoStart = line.rfind(' '); 46 | char tmpChar; 47 | 48 | tmpChar = line.at(infoStart + 1); 49 | if ((tmpChar >= 'A') && (tmpChar <= 'Z')) { 50 | *p_bgLayer = tmpChar - 'A'; 51 | } 52 | else if ((tmpChar >= 'a') && (tmpChar <= 'z')) { 53 | *p_bgLayer = tmpChar - 'a'; 54 | } 55 | 56 | tmpChar = line.at(infoStart + 2); 57 | if ((tmpChar >= 'A') && (tmpChar <= 'Z')) { 58 | *p_upLayer = tmpChar - 'A'; 59 | } 60 | else if ((tmpChar >= 'a') && (tmpChar <= 'z')) { 61 | *p_upLayer = tmpChar - 'a'; 62 | } 63 | } 64 | */ 65 | 66 | // turn all upper case char to lower case in input string 67 | // @param 1 - inString: pointer to string to be handle 68 | void CGLayerIndex::stringToLowercase(std::string *inString) { 69 | for (size_t i = 0; i < (*inString).size(); i++) { 70 | char tmpChar = (*inString).at(i); 71 | if ((tmpChar >= 'A') && (tmpChar <= 'Z')) { 72 | (*inString)[i] = tmpChar - 'A' + 'a'; 73 | } 74 | } 75 | } 76 | 77 | // remove all ' ' at the end of input string 78 | // @param 1 - inString: pointer to string to be handle 79 | void CGLayerIndex::removeLineEndSpace(std::string *inString) { 80 | int size = (*inString).size(); 81 | char endChar = (*inString).at(size - 1); 82 | while (endChar == ' ') { 83 | (*inString).erase(size - 1, 1); 84 | size--; 85 | endChar = (*inString).at(size - 1); 86 | } 87 | } 88 | 89 | // get v3.3 layer identifier from input layer name 90 | // @param 1 - layerName: input string layer name (lower case only) 91 | // @param 2 - p_bgLayer: pointer to store background identifier 92 | // @param 3 - p_upLayer: pointer to upper layer identifier 93 | void CGLayerIndex::getLayerId(const std::string &layerName, int* p_bgLayer, int* p_upLayer) { 94 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 95 | // simple two char: "" 96 | // getLayerNum(), (0, 0) 97 | // single char layer: "" 98 | // appear in cafe stella 99 | // getLayerNum(a), (0, 0) (bg is always 0)) 100 | // three char start with M: "M" 101 | // appear in sanoba witch 102 | // getLayerNum(), (0, 0) 103 | // "M", bg += 26 104 | // (26, 0) 105 | // string end with " \u306e\u30b3\u30d4\u30fc": 106 | // " \u306e\u30b3\u30d4\u30fc" 107 | // appear in amairo isle 108 | // getLayerNum(), (0, 0) 109 | // " のコピー", bg += 26 110 | // (26, 0) 111 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 112 | 113 | int length = layerName.size(); 114 | if (length == 2) { 115 | *p_bgLayer = layerName.at(0) - 'a'; 116 | *p_upLayer = layerName.at(1) - 'a'; 117 | } 118 | else if (length == 1) { 119 | *p_bgLayer = 0; 120 | *p_upLayer = layerName.at(0) - 'a'; 121 | } 122 | else if (length == 3) { 123 | *p_bgLayer = layerName.at(1) - 'a' + 26; 124 | *p_upLayer = layerName.at(2) - 'a'; 125 | } 126 | else if (length == 15) { 127 | *p_bgLayer = layerName.at(0) - 'a' + 26; 128 | *p_upLayer = layerName.at(1) - 'a'; 129 | } 130 | } 131 | 132 | // No longer used due after v2.0 to the use of json layer info 133 | /* 134 | // get series layer infos from txt file extracted by expimg 135 | int CGLayerIndex::getInfoTxt() { 136 | std::string lineBuff; 137 | std::ifstream txtFile; 138 | std::string txtFileName = seriesName_ + "+pimg+layers.txt"; 139 | txtFile.open(txtFileName, std::ios::in|std::ios::binary); 140 | 141 | // width * height 142 | std::getline(txtFile, lineBuff); 143 | imageWidth_ = getValue(lineBuff); 144 | std::getline(txtFile, lineBuff); 145 | imageHeight_ = getValue(lineBuff); 146 | std::getline(txtFile, lineBuff); 147 | 148 | // get layers info 149 | int layerNum = 0; 150 | while (std::getline(txtFile, lineBuff)) { 151 | // name 152 | int bgLayer; 153 | int upLayer; 154 | getPicId(lineBuff, &bgLayer, &upLayer); 155 | 156 | // layer_id 157 | std::getline(txtFile, lineBuff); 158 | int layerid = getValue(lineBuff); 159 | 160 | // width 161 | std::getline(txtFile, lineBuff); 162 | 163 | // height 164 | std::getline(txtFile, lineBuff); 165 | 166 | // left 167 | std::getline(txtFile, lineBuff); 168 | int left = getValue(lineBuff); 169 | 170 | // top 171 | std::getline(txtFile, lineBuff); 172 | int top = getValue(lineBuff); 173 | 174 | // opacity 175 | std::getline(txtFile, lineBuff); 176 | 177 | // layer_type 178 | std::getline(txtFile, lineBuff); 179 | 180 | // type 181 | std::getline(txtFile, lineBuff); 182 | 183 | // visible 184 | std::getline(txtFile, lineBuff); 185 | 186 | // blank line 187 | std::getline(txtFile, lineBuff); 188 | 189 | CGLayer cglayer(seriesName_, layerid, left, top); 190 | layers_.push_back(cglayer); 191 | layerIndex_[bgLayer * 26 + upLayer] = layerNum; 192 | availableIndex_.push_back(bgLayer * 26 + upLayer); 193 | layerNum++; 194 | } 195 | 196 | txtFile.close(); 197 | 198 | return layerNum; 199 | } 200 | */ 201 | 202 | // get series layer infos from json file extracted by KrkrExtraxct 203 | int CGLayerIndex::getInfoJson() { 204 | std::string jsonFileName = seriesName_ + ".json"; 205 | std::ifstream jsonFile(jsonFileName, std::ios::in|std::ios::binary); 206 | 207 | nlohmann::json jsonLayerIndex; 208 | jsonFile >> jsonLayerIndex; 209 | 210 | imageWidth_ = jsonLayerIndex["width"]; 211 | imageHeight_ = jsonLayerIndex["height"]; 212 | 213 | int totalLayers = jsonLayerIndex["layers"].size(); 214 | std::string layerName; 215 | int bgLayer; 216 | int upLayer; 217 | int layerid; 218 | int left; 219 | int top; 220 | for (int layerNum = 0; layerNum < totalLayers; layerNum++) { 221 | layerName = jsonLayerIndex["layers"][layerNum]["name"]; 222 | // fixed name end with extra space 223 | // appear in dracu-riot ev117a "EH " 224 | removeLineEndSpace(&layerName); 225 | stringToLowercase(&layerName); 226 | getLayerId(layerName, &bgLayer, &upLayer); 227 | 228 | layerid = jsonLayerIndex["layers"][layerNum]["layer_id"]; 229 | 230 | left = jsonLayerIndex["layers"][layerNum]["left"]; 231 | top = jsonLayerIndex["layers"][layerNum]["top"]; 232 | 233 | CGLayer cglayer(seriesName_, layerid, imageWidth_, imageHeight_, left, top); 234 | //CGLayer cglayer(seriesName_, layerid, left, top); 235 | layers_.push_back(cglayer); 236 | layerIndex_[bgLayer * 26 + upLayer] = layerNum; 237 | availableIndex_.push_back(bgLayer * 26 + upLayer); 238 | } 239 | 240 | // **replaced by default layer 241 | // if no layer "aa", set the last layer as "aa" 242 | // appear in amairo isle, patch.xp3 ev214n 243 | //if (layerIndex_[0] == -1) { 244 | // CGLayer cglayer(seriesName_, layerid, left, top); 245 | // layers_.push_back(cglayer); 246 | // layerIndex_[0] = totalLayers; 247 | // availableIndex_.push_back(0); 248 | // totalLayers++; 249 | //} 250 | 251 | // set last layer as default background layer for "diff" rule 252 | //CGLayer cglayer(seriesName_, layerid, imageWidth_, imageHeight_, left, top); 253 | //layers_.push_back(cglayer); 254 | //layerIndex_[2 * 26 * 26] = totalLayers; 255 | //availableIndex_.push_back(2 * 26 * 26); 256 | //totalLayers++; 257 | 258 | defaultBGLayer_ = bgLayer * 26 + upLayer; 259 | 260 | jsonFile.close(); 261 | 262 | return totalLayers; 263 | } 264 | 265 | // default constructor of CGLayerIndex, 266 | // create object with seriesName_ = "dummy" 267 | CGLayerIndex::CGLayerIndex() { 268 | seriesName_ = "dummy"; 269 | } 270 | 271 | // CGLayerIndex constructor, 272 | // create index object with series name in parameter, 273 | // and read json file to get layer information 274 | // @param 1 - seriesName: series name of this index 275 | CGLayerIndex::CGLayerIndex(const std::string &seriesName) { 276 | for (int i = 0; i < 2 * 26 * 26; i++) { 277 | layerIndex_[i] = -1; 278 | } 279 | 280 | seriesName_ = seriesName; 281 | 282 | layerNum_ = getInfoJson(); 283 | } 284 | 285 | CGLayerIndex::~CGLayerIndex() { 286 | } 287 | 288 | // return series name of the index 289 | std::string CGLayerIndex::seriesName() { 290 | return seriesName_; 291 | }; 292 | 293 | // return total layer number in the index 294 | int CGLayerIndex::layerNum() { 295 | return(layerNum_); 296 | } 297 | 298 | // return image width of the cg series 299 | int CGLayerIndex::imageWidth() { 300 | return imageWidth_; 301 | }; 302 | 303 | // return image height of the cg series 304 | int CGLayerIndex::imageHeight() { 305 | return imageHeight_; 306 | }; 307 | 308 | // No longer use after v3.3 due to the new layer id 309 | /* 310 | // return CGLayer by background and upper layer identifier 311 | // @param 1 - bgLayer: background identifier 312 | // @param 2 - upLayer: upper layer identifier 313 | CGLayer CGLayerIndex::findLayer(int bgLayer, int upLayer) { 314 | // TODO: if layer exist? 315 | return layers_[layerIndex_[bgLayer * 26 + upLayer] ]; 316 | } 317 | 318 | // return CGLayer by position number in index. 319 | // @param 1 - availableIndexNo: index No 320 | CGLayer CGLayerIndex::findLayer(int availableIndexNo) { 321 | // TODO: if layer exist? 322 | return layers_[layerIndex_[availableIndex_[availableIndexNo] ] ]; 323 | } 324 | */ 325 | 326 | // return CGLayer by background and upper layer identifier 327 | // @param 1 - layerId: layer to get. 328 | CGLayer CGLayerIndex::findLayer(int layerId) { 329 | // TODO: if layer exist? 330 | return layers_[layerIndex_[layerId] ]; 331 | } 332 | 333 | // return the layerId of default background for diff rule 334 | int CGLayerIndex::defaultBGLayer() { 335 | return defaultBGLayer_; 336 | } 337 | -------------------------------------------------------------------------------- /src/cglayerindex.h: -------------------------------------------------------------------------------- 1 | /* **************************************************************** 2 | * FilePath : /src/cglayerindex.h 3 | * Project Name : CGMerge 4 | * Author : zzyy21 5 | * Create Time : 2020-06-23 20:26:21 6 | * Modifed by : zzyy21 7 | * Last Modify : 2020-07-11 10:59:35 8 | * Description : get layer index from file 9 | * Revision : v1.0 - Get layer info from txt file by expimg 10 | * v2.0 - Get layer info from json file by KrkrExtract 11 | * v3.3 - use new layer identify rule 12 | * **************************************************************** */ 13 | 14 | #ifndef CGLAYERINDEX_H_ 15 | #define CGLAYERINDEX_H_ 16 | 17 | #include "cglayer.h" 18 | 19 | #include 20 | #include 21 | 22 | // CGLayerIndex 23 | // use std::vector to store a set of layer information 24 | // use layerIndex_[2 * 26 * 26] to store the index of CGLayer 25 | // background layer identifier 'A'->0, 'B'->1, ..., 'Z'->25 26 | // "MA"/"A? \u306e\u30b3\u30d4\u30fc"-> 26 ... "MZ" -> 51 27 | // upper layer identifier 'a'->0, 'b'->1, ..., 'z'->25 28 | // layerIndex_[bg * 26 + up] is the position of this layer in vector 29 | 30 | class CGLayerIndex { 31 | private: 32 | std::string seriesName_; 33 | int imageWidth_; 34 | int imageHeight_; 35 | std::vector layers_; 36 | int layerIndex_[2 * 26 * 26 + 1]; 37 | std::vector availableIndex_; 38 | int layerNum_; 39 | int defaultBGLayer_ = -1; 40 | 41 | // **No longer used due after v2.0 to the use of json layer info 42 | //int getValue(const std::string &line); 43 | // **No longer used after v3.3 44 | //void getPicId(const std::string &line, int* p_bgLayer, int* p_upLayer); 45 | void stringToLowercase(std::string *inString); 46 | void removeLineEndSpace(std::string *inString); 47 | void getLayerId(const std::string &layerName, int* p_bgLayer, int* p_upLayer); 48 | // **No longer used due after v2.0 to the use of json layer info 49 | //int getInfoTxt(); 50 | int getInfoJson(); 51 | 52 | public: 53 | CGLayerIndex(); 54 | CGLayerIndex(const std::string &seriesName); 55 | ~CGLayerIndex(); 56 | 57 | std::string seriesName(); 58 | int layerNum(); 59 | int imageWidth(); 60 | int imageHeight(); 61 | // **No longer use after v3.3 due to the new layer id 62 | //CGLayer findLayer(int bgLayer, int upLayer); 63 | // **No longer use after v3.3 due to the new layer id 64 | //CGLayer findLayer(int indexNum); 65 | CGLayer findLayer(int layerId); 66 | int defaultBGLayer(); 67 | }; 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /src/cgmerge.cpp: -------------------------------------------------------------------------------- 1 | /* **************************************************************** 2 | * FilePath : /src/cgmerge.cpp 3 | * Project Name : CGMerge 4 | * Author : zzyy21 5 | * Create Time : 2020-06-24 19:42:04 6 | * Modifed by : zzyy21 7 | * Last Modify : 2020-07-08 23:29:56 8 | * Description : main entry of CGMerge 9 | * Revision : v1.0 - using Magick command-line tool batch file 10 | * v3.0 - using built-in merge fuction with OpenCV 11 | * v3.1 - add prompt text for user 12 | * **************************************************************** */ 13 | 14 | #include 15 | 16 | #include "csvsplitter.h" 17 | 18 | int main(void) { 19 | printf("\r\n\xA9\xB3\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xB7\r\n"); 20 | printf("\xA9\xA7 \xE8\xD6\xD7\xD3\xC9\xE7 CG \xBA\xCF\xB3\xC9\xB9\xA4\xBE\xDF by zzyy21 \xA9\xA7\r\n"); 21 | printf("\xA9\xBB\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xA5\xA9\xBF\r\n\r\n"); 22 | 23 | printf(" Ciallo\xA1\xAB\x28\xA1\xCF\x3F\xA6\xD8\x3C\x20\x29\xA1\xD0\xA1\xEF\r\n\r\n\r\n"); 24 | 25 | printf("\xC7\xEB\xC8\xB7\xC8\xCF\xA3\xBA\r\n"); 26 | printf("(1) cglist.csv \xBA\xCD imagediffmap.csv \xD2\xD1\xD7\xAA\xBB\xBB\xCE\xAA GB2312 \xB1\xE0\xC2\xEB\xB8\xF1\xCA\xBD\r\n"); 27 | printf("(2) cglist.csv\xA3\xACimagediffmap.csv\xA3\xAC*.json \xBC\xB0\xB0\xFC\xBA\xAC tlg \xCE\xC4\xBC\xFE\xB5\xC4\xCD\xAC\xC3\xFB\xC4\xBF\xC2\xBC"); 28 | printf("\xD2\xD1\xBA\xCD\xB1\xBE\xB3\xCC\xD0\xF2\xB7\xC5\xD4\xDA\xCD\xAC\xD2\xBB\xC4\xBF\xC2\xBC\xD6\xD0\r\n\r\n"); 29 | 30 | printf("\xB0\xB4\xBB\xD8\xB3\xB5\xBF\xAA\xCA\xBC\xBA\xCF\xB3\xC9\x7E\r\n"); 31 | getchar(); 32 | 33 | system("mkdir CGOutput"); 34 | CSVFileSplitter csvSplitter("cglist.csv"); 35 | 36 | printf("\r\n\r\nCG\xBA\xCF\xB3\xC9\xBD\xE1\xCA\xF8~~ \xB9\xB2\xBA\xCF\xB3\xC9 %d \xD7\xE9 %d \xD5\xC5\r\n", csvSplitter.totalGroup(), csvSplitter.totalPic()); 37 | getchar(); 38 | 39 | //csvSplitter.writeBatFile(); 40 | //system("merge.bat"); 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /src/cgpic.cpp: -------------------------------------------------------------------------------- 1 | /* **************************************************************** 2 | * FilePath : /src/cgpic.cpp 3 | * Project Name : CGMerge 4 | * Author : zzyy21 5 | * Create Time : 2020-06-24 15:06:55 6 | * Modifed by : zzyy21 7 | * Last Modify : 2020-07-10 22:56:30 8 | * Description : operation to single cg picture 9 | * Revision : v1.0 - first version for generate Magick convert 10 | * command-lines 11 | * v1.0(200705) - add png:include-chunk definition 12 | * v1.0(200706) - modify quality parameter setting 13 | * v3.0 - add fuctions using OpenCV, merge image 14 | * layers and save image file. 15 | * v3.2 - modify to optimize appending layer 16 | * v3.3 - add public func return cg file name 17 | * **************************************************************** */ 18 | 19 | #include "cglayer.h" 20 | #include "cgpic.h" 21 | 22 | #include 23 | 24 | CGPic::CGPic() { 25 | } 26 | 27 | CGPic::~CGPic() { 28 | } 29 | 30 | // No longer used after v3.2, use imgAppendLayerNew instead 31 | /* 32 | // append 4 channel upper layer on 3 channel background 33 | // layer in same size. using opencv library. 34 | // @param 1 - up: upper layer (4 channels) 35 | // @param 2 - p_bg: pointer to the background layer, also the result 36 | void CGPic::imgAppendLayer(const cv::Mat& up, cv::Mat* p_bg) { 37 | std::vector srcChannels; 38 | std::vector outChannels; 39 | split(up, srcChannels); 40 | split(*p_bg, outChannels); 41 | 42 | for (int i = 0; i < 3; i++) { 43 | // out_RGB <--- dst_RGB(1 - src_A) 44 | outChannels[i] = outChannels[i].mul(255.0 - srcChannels[3], 1 / 255.0); 45 | // out_RGB <--- src_RGBsrc_A + dst_RGB(1 - src_A) 46 | outChannels[i] += srcChannels[i].mul(srcChannels[3], 1 / 255.0); 47 | } 48 | 49 | cv::merge(outChannels, *p_bg); 50 | } 51 | */ 52 | 53 | // append 4 channel upper layer to a specific position 54 | // on 3 channel background layer. using opencv library. 55 | // @param 1 - up: upper layer (4 channels) 56 | // @param 2 - left: column position of the upper layer's upper left corner on background 57 | // @param 3 - top: row position of the upper layer's upper left corner on background 58 | // @param 4 - p_bg: pointer to the background layer, also the result 59 | void CGPic::imgAppendLayerNew(const cv::Mat& up, int left, int top, cv::Mat* p_bg) { 60 | cv::Mat bgPart(*p_bg, cv::Rect(left, top, up.cols, up.rows)); 61 | 62 | std::vector upChannels; 63 | std::vector bgPartChannels; 64 | split(up, upChannels); 65 | split(bgPart, bgPartChannels); 66 | 67 | for (int i = 0; i < 3; i++) { 68 | // out_RGB <--- dst_RGB(1 - src_A) 69 | bgPartChannels[i] = bgPartChannels[i].mul(255.0 - upChannels[3], 1 / 255.0); 70 | // out_RGB <--- src_RGBsrc_A + dst_RGB(1 - src_A) 71 | bgPartChannels[i] += upChannels[i].mul(upChannels[3], 1 / 255.0); 72 | } 73 | 74 | cv::merge(bgPartChannels, bgPart); 75 | } 76 | 77 | // set picture size 78 | // @param 1 - width: width of the pic 79 | // @param 2 - height: height of the pic 80 | void CGPic::setSize(int width, int height) { 81 | width_ = width; 82 | height_ = height; 83 | } 84 | 85 | // append a layer to the top of picture 86 | // @param 1 - layer: layer to be added 87 | void CGPic::addLayer(const CGLayer &layer) { 88 | layers_.push_back(layer); 89 | } 90 | 91 | // set the output file name of the picture 92 | // @param 1 - fileName: name to be set 93 | void CGPic::setFileName(const std::string &fileName) { 94 | fileName_ = fileName; 95 | } 96 | 97 | // return file name of this pic 98 | std::string CGPic::fileName() { 99 | return fileName_; 100 | } 101 | 102 | // No longer used after v3.0 due to the use of OpenCV 103 | /* 104 | // return the command-line script to merge the picture using Magick 105 | std::string CGPic::magickMergeScript() { 106 | std::string commandLine = "magick convert -size "; 107 | commandLine += std::to_string(width_) + "x" + std::to_string(height_) + " "; 108 | 109 | for (int i = layers_.size() - 1; i >= 0; i--) { 110 | commandLine += "-page "; 111 | commandLine += "+" + std::to_string(layers_[i].left()); 112 | commandLine += "+" + std::to_string(layers_[i].top()) + " "; 113 | commandLine += "\"" + layers_[i].fileName() + "\" "; 114 | } 115 | 116 | // Set Magick png compression level, maximum compression 117 | // * For the MNG and PNG image formats, the quality value sets the zlib 118 | // * compression level (quality / 10) and filter-type (quality % 10). 119 | // * The default PNG "quality" is 75, which means compression level 7 120 | // * with adaptive PNG filtering, unless the image has a color map, 121 | // * in which case it means compression level 7 with no PNG filtering. 122 | // * If filter-type is 5, adaptive filtering is used when quality is 123 | // * greater than 50 and the image does not have a color map, 124 | // * otherwise no filtering is used. 125 | // * For compression level 0 (quality value less than 10), 126 | // * the Huffman-only strategy is used, which is fastest 127 | // * but not necessarily the worst compression. 128 | // *** v1.0 use 95 for highest compression 129 | // *** v1.0 2020-07-06 use 05 for fastest processing, as the highest 130 | // *** compression is slow but does not obviously reduce the size 131 | commandLine += "-quality 05 "; 132 | // Define ancillary chunks in PNG. Avoid writing time information to cause 133 | // different verification of merged image files. 134 | // * Ancillary chunks to be excluded from or included in PNG output. 135 | // * The value can be the name of a PNG chunk-type such as bKGD, 136 | // * a comma-separated list of chunk-names (which can include the word date, 137 | // * the word all, or the word none). Although PNG chunk-names are 138 | // * case-dependent, you can use all lowercase names if you prefer. 139 | commandLine += "-define png:include-chunk=none "; 140 | 141 | commandLine += "-mosaic CGOutput\\" + fileName_; 142 | 143 | return commandLine; 144 | } 145 | */ 146 | 147 | void CGPic::saveImage() { 148 | int layerNum = layers_.size(); 149 | cv::Mat img; 150 | // background layer in 3 channels 151 | cv::cvtColor(layers_[layerNum - 1].img(), img, cv::COLOR_BGRA2BGR); 152 | 153 | for (int i = layerNum - 2; i >= 0; i--) { 154 | // v3.1 155 | //imgAppendLayer(layers_[i].img(), &img); 156 | // v3.2 157 | imgAppendLayerNew(layers_[i].img(), layers_[i].left(), layers_[i].top(), &img); 158 | } 159 | 160 | std::string outputPath = "CGOutput\\" + fileName_; 161 | // huffman only compression strategy 162 | // fastest, acceptable file size 163 | std::vector compressionParams = {cv::IMWRITE_PNG_STRATEGY, cv::IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY}; 164 | 165 | cv::imwrite(outputPath, img, compressionParams); 166 | } 167 | -------------------------------------------------------------------------------- /src/cgpic.h: -------------------------------------------------------------------------------- 1 | /* **************************************************************** 2 | * FilePath : /src/cgpic.h 3 | * Project Name : CGMerge 4 | * Author : zzyy21 5 | * Create Time : 2020-06-22 22:42:02 6 | * Modifed by : zzyy21 7 | * Last Modify : 2020-07-10 22:52:30 8 | * Description : class for single cg picture 9 | * Revision : v1.0 - first version for generate Magick convert 10 | * command-lines 11 | * v3.0 - add fuctions using OpenCV, merge image 12 | * layers and save image file. 13 | * v3.2 - modify to optimize appending layer 14 | * v3.3 - add public func return cg file name 15 | * **************************************************************** */ 16 | 17 | #ifndef CGPIC_H_ 18 | #define CGPIC_H_ 19 | 20 | #include "cglayer.h" 21 | 22 | #include 23 | #include 24 | 25 | class CGPic { 26 | private: 27 | std::string fileName_; 28 | int width_; 29 | int height_; 30 | std::vector layers_; 31 | 32 | // **No longer used after v3.2, use imgAppendLayerNew instead 33 | //void imgAppendLayer(const cv::Mat& up, cv::Mat* p_bg); 34 | void imgAppendLayerNew(const cv::Mat& up, int left, int top, cv::Mat* p_bg); 35 | 36 | public: 37 | CGPic(); 38 | ~CGPic(); 39 | 40 | void setSize(int width, int height); 41 | void addLayer(const CGLayer &layer); 42 | void setFileName(const std::string &fileName); 43 | std::string fileName(); 44 | 45 | // **No longer used after v3.0 due to the use of OpenCV 46 | //std::string magickMergeScript(); 47 | void saveImage(); 48 | }; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/cgpicindex.cpp: -------------------------------------------------------------------------------- 1 | /* **************************************************************** 2 | * FilePath : /src/cgpicindex.cpp 3 | * Project Name : CGMerge 4 | * Author : zzyy21 5 | * Create Time : 2020-07-10 19:31:33 6 | * Modifed by : zzyy21 7 | * Last Modify : 2020-07-10 23:51:53 8 | * Description : functions to handle imagediffmap.csv file 9 | * build a index for cgpic. 10 | * Revision : v3.3 - new file for class CSVimagediffmapSplitter 11 | * imagediffmap.csv file handling. 12 | * get layer identify id from imagediffmap.csv. 13 | * use new layer identify rule. 14 | * **************************************************************** */ 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #include "cgpicindex.h" 21 | 22 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23 | // pic id string, series name, seton, layer name (:background) 24 | // ev101aa, ev101a, seton, Aa 25 | // ev101ab, ev101a, seton, Ab :Aa 26 | // ev118_b, ev118_a, diff, B 27 | // EV215MAA, EV215A, diff, MAA 28 | // EV607JA, EV607A, diff, AA のコピー 29 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 30 | 31 | // CSVimagediffmapSplitter constructor. 32 | // open "imagediffmap.csv" and get the first line to lineBuff_ 33 | CSVimagediffmapSplitter::CSVimagediffmapSplitter() { 34 | imagediffmap_.open("imagediffmap.csv", std::ios::in|std::ios::binary); 35 | 36 | // get the first uncomment line 37 | while (std::getline(imagediffmap_, lineBuff_)) { 38 | char tmpChar = lineBuff_.at(0); 39 | if (tmpChar == '#') { 40 | continue; 41 | } 42 | else if ((tmpChar == '\r') || (tmpChar == '\n')) { 43 | continue; 44 | } 45 | else { 46 | break; 47 | } 48 | } 49 | 50 | while (getNewGroup()) {} 51 | 52 | imagediffmap_.close(); 53 | } 54 | 55 | CSVimagediffmapSplitter::~CSVimagediffmapSplitter() { 56 | } 57 | 58 | // get layer identifier from input line with two char 59 | // @param 1 - line: input line with format:"" 60 | // @param 2 - p_bgLayer: pointer to store background identifier 61 | // @param 3 - p_upLayer: pointer to upper layer identifier 62 | void CSVimagediffmapSplitter::getLayerNum(const std::string &layerNumString, int* p_bgLayer, int* p_upLayer) { 63 | char tmpChar; 64 | tmpChar = layerNumString.at(0); 65 | if ((tmpChar >= 'a') && (tmpChar <= 'z')) { 66 | *p_bgLayer = tmpChar - 'a'; 67 | } 68 | else if ((tmpChar >= 'A') && (tmpChar <= 'Z')) { 69 | *p_bgLayer = tmpChar - 'A'; 70 | } 71 | 72 | tmpChar = layerNumString.at(1); 73 | if ((tmpChar >= 'a') && (tmpChar <= 'z')) { 74 | *p_upLayer = tmpChar - 'a'; 75 | } 76 | else if ((tmpChar >= 'A') && (tmpChar <= 'Z')) { 77 | *p_upLayer = tmpChar - 'A'; 78 | } 79 | } 80 | 81 | // get v3.3 layer identifier from input layer name 82 | // @param 1 - layerName: input string layer name (lower case only) 83 | // @param 2 - p_bgLayer: pointer to store background identifier 84 | // @param 3 - p_upLayer: pointer to upper layer identifier 85 | void CSVimagediffmapSplitter::layerIdcode(const std::string &layerName, int* p_bgLayer, int* p_upLayer) { 86 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 87 | // simple two char: "" 88 | // getLayerNum(), (0, 0) 89 | // single char layer: "" 90 | // appear in cafe stella 91 | // getLayerNum(a), (0, 0) (bg is always 0)) 92 | // three char start with M: "M" 93 | // appear in sanoba witch 94 | // getLayerNum(), (0, 0) 95 | // "M", bg += 26 96 | // (26, 0) 97 | // string end with " のコピー": " のコピー" 98 | // appear in amairo isle 99 | // getLayerNum(), (0, 0) 100 | // " のコピー", bg += 26 101 | // (26, 0) 102 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 103 | 104 | int length = layerName.size(); 105 | if (length == 2) { 106 | *p_bgLayer = layerName.at(0) - 'a'; 107 | *p_upLayer = layerName.at(1) - 'a'; 108 | } 109 | else if (length == 1) { 110 | *p_bgLayer = 0; 111 | *p_upLayer = layerName.at(0) - 'a'; 112 | } 113 | else if (length == 3) { 114 | *p_bgLayer = layerName.at(1) - 'a' + 26; 115 | *p_upLayer = layerName.at(2) - 'a'; 116 | } 117 | else if (length == 11) { 118 | *p_bgLayer = layerName.at(0) - 'a' + 26; 119 | *p_upLayer = layerName.at(1) - 'a'; 120 | } 121 | } 122 | 123 | // get index id from input pic id string 124 | // @param 1 - idString: input pic id string 125 | // @param 2 - p_seriesId: pointer to series identifier 126 | // @param 3 - p_bgLayer: pointer to store background identifier 127 | // @param 4 - p_upLayer: pointer to store upper layer identifier 128 | void CSVimagediffmapSplitter::getIndexId(const std::string &idString, int* p_seriesId, int* p_bgLayer, int* p_upLayer) { 129 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 130 | // idString --> seriesId: 131 | // _ series --> seriesId += 2 132 | // m series --> seriesId += 1 133 | // example: 134 | // cgInfo groupName idString seriesId layerId 135 | // ev101bc ev101 aa 0 (1, 2) 136 | // ev202mad ev202 mad 1 (0, 3) 137 | // ev304_aa ev304 _aa 2 (0, 0) 138 | // ev404_mad ev404 _mad 3 (0, 3) 139 | // ev502_B ev502 _B 2 (0, 1) 140 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 141 | 142 | int isUnderlineSeries = 0; 143 | int isMSeries = 0; 144 | char tmpChar = idString.at(0); 145 | std::string tmpString; 146 | if (tmpChar == '_') { 147 | isUnderlineSeries = 1; 148 | tmpString = idString.substr(1); 149 | } 150 | else { 151 | tmpString = idString; 152 | } 153 | 154 | int length = tmpString.size(); 155 | // mAa 156 | if (length == 3) { 157 | isMSeries = 1; 158 | tmpString = tmpString.substr(1); 159 | } 160 | // A 161 | else if (length == 1) { 162 | tmpString = "a" + tmpString; 163 | } 164 | 165 | getLayerNum(tmpString, p_bgLayer, p_upLayer); 166 | 167 | *p_seriesId = isUnderlineSeries * 2 + isMSeries; 168 | } 169 | 170 | // split a line from imagediffmap.csv to get cg series info 171 | // @param 1 - line: line in imagediffmap.csv 172 | // example: "ev112mbc,ev112mm,seton,Bc:Ba" --> 173 | // series name of ("ev112m", 1, 2) is "ev112mm" 174 | // example: "ev701bb,ev701b,seton,Bb:Ba" --> 175 | // series name of ("ev701", 1, 1) is "ev701b" 176 | void CSVimagediffmapSplitter::lineSplitt(const std::string &line) { 177 | std::string tmpLine = line; 178 | size_t splitPosition; 179 | 180 | splitPosition = tmpLine.find(','); 181 | std::string idString = tmpLine.substr(5, splitPosition - 5); 182 | int seriesId; 183 | int bgLayer; 184 | int upLayer; 185 | getIndexId(idString, &seriesId, &bgLayer, &upLayer); 186 | 187 | tmpLine = tmpLine.substr(splitPosition + 1); 188 | splitPosition = tmpLine.find(','); 189 | std::string seriesName = tmpLine.substr(0, splitPosition); 190 | seriesNameIndexs_[seriesId][bgLayer * 26 + upLayer] = seriesName; 191 | 192 | tmpLine = tmpLine.substr(splitPosition + 1); 193 | splitPosition = tmpLine.find(','); 194 | std::string mergeTypeStr = tmpLine.substr(0, splitPosition); 195 | if (mergeTypeStr == "diff") { 196 | tmpLine = tmpLine.substr(splitPosition + 1); 197 | removeEOLChar(&tmpLine); 198 | int bgLayerId; 199 | int upLayerId; 200 | layerIdcode(tmpLine, &bgLayerId, &upLayerId); 201 | bgLayerIndexs_[seriesId][bgLayer * 26 + upLayer] = 2 * 26 * 26; 202 | upLayerId += bgLayerId * 26; 203 | upLayerIndexs_[seriesId][bgLayer * 26 + upLayer] = upLayerId; 204 | } 205 | else if (mergeTypeStr == "seton") { 206 | tmpLine = tmpLine.substr(splitPosition + 1); 207 | removeEOLChar(&tmpLine); 208 | int bgLayerId; 209 | int upLayerId; 210 | splitPosition = tmpLine.find(':'); 211 | if (splitPosition != std::string::npos) { 212 | std::string upLayerName = tmpLine.substr(0, splitPosition); 213 | layerIdcode(upLayerName, &bgLayerId, &upLayerId); 214 | upLayerIndexs_[seriesId][bgLayer * 26 + upLayer] = bgLayerId * 26 + upLayerId; 215 | tmpLine = tmpLine.substr(splitPosition + 1); 216 | } 217 | else { 218 | upLayerIndexs_[seriesId][bgLayer * 26 + upLayer] = -1; 219 | } 220 | 221 | layerIdcode(tmpLine, &bgLayerId, &upLayerId); 222 | bgLayerIndexs_[seriesId][bgLayer * 26 + upLayer] = bgLayerId * 26 + upLayerId; 223 | } 224 | } 225 | 226 | // turn all upper case char to lower case in input string 227 | // @param 1 - inString: pointer to string to be handle 228 | void CSVimagediffmapSplitter::stringToLowercase(std::string *inString) { 229 | for (size_t i = 0; i < (*inString).size(); i++) { 230 | char tmpChar = (*inString).at(i); 231 | if ((tmpChar >= 'A') && (tmpChar <= 'Z')) { 232 | (*inString)[i] = tmpChar - 'A' + 'a'; 233 | } 234 | } 235 | } 236 | 237 | // remove all '\r' and \n' at the end of input string 238 | // @param 1 - inString: pointer to string to be handle 239 | void CSVimagediffmapSplitter::removeEOLChar(std::string *inString) { 240 | int size = (*inString).size(); 241 | char endChar = (*inString).at(size - 1); 242 | while ((endChar == '\r') || (endChar == '\n')) { 243 | (*inString).erase(size - 1, 1); 244 | size--; 245 | endChar = (*inString).at(size - 1); 246 | } 247 | } 248 | 249 | // clear used info and get new for a new group 250 | // corresponding to a new line in cglist.csv 251 | // return a bool indicating whether there is a next group 252 | bool CSVimagediffmapSplitter::getNewGroup() { 253 | seriesNameIndexs_.clear(); 254 | seriesNameIndexs_.resize(4, newSeriesNameIndex_); 255 | bgLayerIndexs_.clear(); 256 | bgLayerIndexs_.resize(4, newLayerIdcodeIndex_); 257 | upLayerIndexs_.clear(); 258 | upLayerIndexs_.resize(4, newLayerIdcodeIndex_); 259 | 260 | std::string currentGroupName = lineBuff_.substr(0, 5); 261 | 262 | bool getlineSuccess = false; 263 | do { 264 | char tmpChar = lineBuff_.at(0); 265 | // comment line, appear in Riddle Joker 266 | if (tmpChar == '#') { 267 | continue; 268 | } 269 | // blank line 270 | if ((tmpChar == '\r') || (tmpChar == '\n')) { 271 | continue; 272 | } 273 | stringToLowercase(&lineBuff_); 274 | if (lineBuff_.substr(0, 5) != currentGroupName) { 275 | getlineSuccess = true; 276 | break; 277 | } 278 | lineSplitt(lineBuff_); 279 | } while (std::getline(imagediffmap_, lineBuff_)); 280 | 281 | int groupIdi = currentGroupName.at(2) - '1'; 282 | int groupIdj = (currentGroupName.at(3) - '0') * 10 + currentGroupName.at(4) - '1'; 283 | int groupId = groupIdi * 30 + groupIdj; 284 | groupSeriesNameIndexs_.push_back(seriesNameIndexs_); 285 | groupBgLayerIndexs_.push_back(bgLayerIndexs_); 286 | groupUpLayerIndexs_.push_back(upLayerIndexs_); 287 | groupIndex_[groupId] = groupsPushed; 288 | groupsPushed++; 289 | 290 | return getlineSuccess; 291 | } 292 | 293 | // find cg information from cg name string get from imagediffmap.csv 294 | // @param 1 - cgInfo: cg name string 295 | // @param 3 - p_cgSeriesName: pointer to store cg's series name 296 | // @param 3 - p_bgLayer: pointer to store background identifier 297 | // @param 4 - p_upLayer: pointer to upper layer identifier 298 | // example: "ev101aa" --> "ev101a", 0, 0; "ev113_mbc" --> "ev113_mm", 1, 2; 299 | void CSVimagediffmapSplitter::findInfo(const std::string &cgInfo, std::string* p_cgSeriesName, int* p_bgLayer, int* p_upLayer) { 300 | std::string tmpString; 301 | 302 | tmpString = cgInfo.substr(0, 5); 303 | int groupIdi = tmpString.at(2) - '1'; 304 | int groupIdj = (tmpString.at(3) - '0') * 10 + tmpString.at(4) - '1'; 305 | int groupId = groupIdi * 30 + groupIdj; 306 | int groupPos = groupIndex_[groupId]; 307 | 308 | tmpString = cgInfo.substr(5); 309 | int seriesId; 310 | int bgLayer; 311 | int upLayer; 312 | getIndexId(tmpString, &seriesId, &bgLayer, &upLayer); 313 | 314 | *p_cgSeriesName = groupSeriesNameIndexs_[groupPos][seriesId][bgLayer * 26 + upLayer]; 315 | *p_bgLayer = groupBgLayerIndexs_[groupPos][seriesId][bgLayer * 26 + upLayer]; 316 | *p_upLayer = groupUpLayerIndexs_[groupPos][seriesId][bgLayer * 26 + upLayer]; 317 | } 318 | 319 | // No longer used after v3.0 due to getting info from imagediffmap.csv 320 | // replaced by void CSVimagediffmapSplitter::findInfo(...) 321 | /* 322 | // get cg information from cg name string get from csv file 323 | // @param 1 - cgInfo: cg name string 324 | // @param 3 - p_cgSeriesName: pointer to store cg's series name 325 | // @param 3 - p_bgLayer: pointer to store background identifier 326 | // @param 4 - p_upLayer: pointer to upper layer identifier 327 | // example: "ev101aa" --> "ev101a", 0, 0; "ev113_mbc" --> "ev113_mm", 1, 2; 328 | void CSVFileSplitter::cgInfo(const std::string &cgInfo, std::string* p_cgSeriesName, int* p_bgLayer, int* p_upLayer) { 329 | int stringLen = cgInfo.length(); 330 | std::string tmpString = cgInfo.substr(0, stringLen - 2); 331 | char tmpChar; 332 | 333 | // Senren Banka Yoshino animal ear CG 334 | if (tmpString.at(stringLen - 3) == 'm') { 335 | tmpString = tmpString + "m"; 336 | } 337 | else { 338 | tmpString = tmpString + "a"; 339 | } 340 | *p_cgSeriesName = tmpString; 341 | 342 | tmpChar = cgInfo.at(stringLen - 2); 343 | if ((tmpChar >= 'a') && (tmpChar <= 'z')) { 344 | *p_bgLayer = tmpChar - 'a'; 345 | } 346 | else if ((tmpChar >= 'A') && (tmpChar <= 'Z')) { 347 | *p_bgLayer = tmpChar - 'A'; 348 | } 349 | 350 | tmpChar = cgInfo.at(stringLen - 1); 351 | if ((tmpChar >= 'a') && (tmpChar <= 'z')) { 352 | *p_upLayer = tmpChar - 'a'; 353 | } 354 | else if ((tmpChar >= 'A') && (tmpChar <= 'Z')) { 355 | *p_upLayer = tmpChar - 'A'; 356 | } 357 | } 358 | */ 359 | -------------------------------------------------------------------------------- /src/cgpicindex.h: -------------------------------------------------------------------------------- 1 | /* **************************************************************** 2 | * FilePath : /src/cgpicindex.h 3 | * Project Name : CGMerge 4 | * Author : zzyy21 5 | * Create Time : 2020-07-10 19:31:21 6 | * Modifed by : zzyy21 7 | * Last Modify : 2020-07-10 19:45:06 8 | * Description : CSVimagediffmapSplitter class for imagediffmap.csv 9 | * file handling. build a index for cgpic. 10 | * Revision : v3.3 - new file for class CSVimagediffmapSplitter 11 | * imagediffmap.csv file handling. 12 | * get layer identify id from imagediffmap.csv. 13 | * use new layer identify rule. 14 | * **************************************************************** */ 15 | 16 | #ifndef CGPICINDEX_H_ 17 | #define CGPICINDEX_H_ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | // class for splitting imagediffmap.csv 24 | class CSVimagediffmapSplitter { 25 | private: 26 | std::ifstream imagediffmap_; 27 | std::string lineBuff_; 28 | 29 | std::vector newSeriesNameIndex_ = std::vector(26 * 26); 30 | std::vector newLayerIdcodeIndex_ = std::vector(26 * 26); 31 | std::vector > seriesNameIndexs_; 32 | std::vector > bgLayerIndexs_; 33 | std::vector > upLayerIndexs_; 34 | 35 | std::vector > > groupSeriesNameIndexs_; 36 | std::vector > > groupBgLayerIndexs_; 37 | std::vector > > groupUpLayerIndexs_; 38 | std::vector > groupFindNameIndex_; 39 | int groupIndex_[8 * 30]; // max 8 character * 30 group/character 40 | int groupsPushed = 0; 41 | bool getNewGroup(); 42 | 43 | void getLayerNum(const std::string &layerNumString, int* p_bgLayer, int* p_upLayer); 44 | void layerIdcode(const std::string &layerName, int* p_bgLayer, int* p_upLayer); 45 | void getIndexId(const std::string &idString, int* seriesId, int* p_bgLayer, int* p_upLayer); 46 | void lineSplitt(const std::string &line); 47 | 48 | void stringToLowercase(std::string *inString); 49 | void removeEOLChar(std::string *inString); 50 | 51 | public: 52 | CSVimagediffmapSplitter(); 53 | ~CSVimagediffmapSplitter(); 54 | 55 | void findInfo(const std::string &cgInfo, std::string* p_cgSeriesName, int* p_bgLayer, int* p_upLayer); 56 | 57 | }; 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /src/csvsplitter.cpp: -------------------------------------------------------------------------------- 1 | /* **************************************************************** 2 | * FilePath : /src/csvsplitter.cpp 3 | * Project Name : CGMerge 4 | * Author : zzyy21 5 | * Create Time : 2020-06-24 19:43:38 6 | * Modifed by : zzyy21 7 | * Last Modify : 2020-07-11 01:34:52 8 | * Description : functions to handle cglist.csv file 9 | * Revision : v1.0 - process cglist.csv 10 | * v3.0 - process cglist.csv & imagediffmap.csv, 11 | * merge images using OpenCV instead of generate 12 | * Magick Command-line scripts 13 | * v3.1 - add prompt text for user 14 | * v3.2 - fix bug of commented line in cglist.csv 15 | * v3.3 - move class CSVimagediffmapSplitter for 16 | * imagediffmap.csv file handling to new file 17 | * cgpicindex.cpp. 18 | * use new layer identify rule 19 | * fixed bug caused by line end with extra 20 | * ",EV105A,diff,BC",etc. in sabbat of witch 21 | * **************************************************************** */ 22 | 23 | #include "csvsplitter.h" 24 | 25 | #include 26 | #include 27 | #include 28 | //#include 29 | 30 | #include "cgpic.h" 31 | #include "cglayer.h" 32 | #include "cglayerindex.h" 33 | #include "cgpicindex.h" 34 | 35 | // return a vector of CGPic get from csv line 36 | // @param 1 - csvLine: line from csv file. 37 | // example format: "thum_ev104,芳04,\tev104aa,ev104ab,ev104ac,ev104ad,ev104ae,ev104af" 38 | // example format: "thum_ev311,ム11,\tev311aa,ev311ab,ev311ab|*ev311_aa" 39 | std::vector CSVFileSplitter::csvLineSplit(const std::string &csvLine) { 40 | std::vector cgPics; 41 | std::string tmpLine = csvLine; 42 | size_t splitPosition; 43 | 44 | // useless thumbnail info 45 | splitPosition = tmpLine.find(','); 46 | tmpLine = tmpLine.substr(splitPosition + 1); 47 | 48 | // cg series name displayed in game, used in output file name 49 | std::string cgName; 50 | if (nameInLine_) { 51 | std::string charaNo = csvLine.substr(7, 1); 52 | splitPosition = tmpLine.find(','); 53 | cgName = charaNo + "_" + tmpLine.substr(0, splitPosition); 54 | tmpLine = tmpLine.substr(splitPosition + 1); 55 | } 56 | else { 57 | cgName = csvLine.substr(5, 5); 58 | } 59 | 60 | // remove '\t' before cgs if exist 61 | if (tmpLine.at(0) == '\t') { 62 | tmpLine = tmpLine.substr(1); 63 | } 64 | 65 | // process the end of line to make it easier to split 66 | removeEOLChar(&tmpLine); 67 | tmpLine = tmpLine + ","; 68 | 69 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 70 | // if the cg name is "ev418bc|*ev418_ab" 71 | // it has four layers in two series, in the order from background to uppest: 72 | // ("ev418a", 1, 0), main series background layer 73 | // ("ev418a", 1, 2), main series upper layer 74 | // ("ev418_a", 0, 0), add series background layer 75 | // ("ev418_a", 0, 1), add series upper layer 76 | //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 77 | 78 | std::string mainSeriesName; 79 | int mainBgLayer; 80 | int mainUpLayer; 81 | 82 | std::string addSeriesName; 83 | int addBgLayer; 84 | int addUpLayer; 85 | 86 | int cgPicNum = 0; 87 | 88 | while ((splitPosition = tmpLine.find(',')) != std::string::npos) { 89 | // line end with ",EV105A,diff,BC",etc. which should 90 | // not exist. should be in imagediffmap.csv. 91 | // appear in sabbat of witch 92 | if (splitPosition < 7) { 93 | tmpLine = tmpLine.substr(splitPosition + 1); 94 | continue; 95 | } 96 | 97 | cgPicNum++; 98 | CGPic tmpCGPic; 99 | std::string tmpCGpicInfo = tmpLine.substr(0, splitPosition); 100 | 101 | size_t addPosition = tmpCGpicInfo.find("|*"); 102 | if (addPosition != std::string::npos) { 103 | std::string addcgInfo = tmpCGpicInfo.substr(addPosition + 2); 104 | csvImageDiffmapSplitter_.findInfo(addcgInfo, &addSeriesName, &addBgLayer, &addUpLayer); 105 | 106 | // new add series, create a new layer index for the new series 107 | if (addSeriesName != (*currentAddSeries_).seriesName()) { 108 | delete currentAddSeries_; 109 | printf("\xD5\xFD\xD4\xDA\xCC\xE1\xC8\xA1 %s \xD6\xD0\xCD\xBC\xB2\xE3\xA1\xAD\r\n", addSeriesName.c_str()); 110 | currentAddSeries_ = new CGLayerIndex(addSeriesName); 111 | } 112 | 113 | if (addBgLayer == 2 * 26 * 26) { 114 | addBgLayer = (*currentAddSeries_).defaultBGLayer(); 115 | } 116 | 117 | // before v3.2 118 | //// addUpLayer != 0 -> append add series upper layer 119 | //if (addUpLayer != -1) { 120 | // tmpCGPic.addLayer((*currentAddSeries_).findLayer(addBgLayer, addUpLayer)); 121 | //} 122 | //// append add series background layer 123 | //tmpCGPic.addLayer((*currentAddSeries_).findLayer(addBgLayer, 0)); 124 | 125 | // after v3.3 126 | // addUpLayer != -1 -> up layer exist 127 | // addUpLayer != addBgLayer -> up layer isn't default bg 128 | if ((addUpLayer != -1) && (addUpLayer != addBgLayer)) { 129 | tmpCGPic.addLayer((*currentAddSeries_).findLayer(addUpLayer)); 130 | } 131 | // append add series background layer 132 | tmpCGPic.addLayer((*currentAddSeries_).findLayer(addBgLayer)); 133 | 134 | tmpCGpicInfo = tmpCGpicInfo.substr(0, addPosition); 135 | } 136 | 137 | csvImageDiffmapSplitter_.findInfo(tmpCGpicInfo, &mainSeriesName, &mainBgLayer, &mainUpLayer); 138 | 139 | // new main series, create a new layer index for the new series 140 | if (mainSeriesName != (*currentMainSeries_).seriesName()) { 141 | delete currentMainSeries_; 142 | printf("\xD5\xFD\xD4\xDA\xCC\xE1\xC8\xA1 %s \xD6\xD0\xCD\xBC\xB2\xE3\xA1\xAD\r\n", mainSeriesName.c_str()); 143 | currentMainSeries_ = new CGLayerIndex(mainSeriesName); 144 | } 145 | 146 | if (mainBgLayer == 2 * 26 * 26) { 147 | mainBgLayer = (*currentMainSeries_).defaultBGLayer(); 148 | } 149 | 150 | // before v3.2 151 | //// mainUpLayer != 0 -> append main series upper layer 152 | //if (mainUpLayer) { 153 | // tmpCGPic.addLayer((*currentMainSeries_).findLayer(mainBgLayer, mainUpLayer)); 154 | //} 155 | //// append main series background layer 156 | //tmpCGPic.addLayer((*currentMainSeries_).findLayer(mainBgLayer, 0)); 157 | 158 | // after v3.3 159 | // mainUpLayer != -1 -> up layer exist 160 | // mainUpLayer != mainBgLayer -> up layer isn't default bg 161 | if ((mainUpLayer != -1) && (mainUpLayer != mainBgLayer)) { 162 | tmpCGPic.addLayer((*currentMainSeries_).findLayer(mainUpLayer)); 163 | } 164 | // append main series background layer 165 | tmpCGPic.addLayer((*currentMainSeries_).findLayer(mainBgLayer)); 166 | 167 | tmpCGPic.setSize((*currentMainSeries_).imageWidth(), (*currentMainSeries_).imageHeight()); 168 | char cgNumChar[3]; 169 | sprintf(cgNumChar, "%03d", cgPicNum); 170 | std::string tmpCGFileName = cgName + "_" + cgNumChar + ".png"; 171 | tmpCGPic.setFileName(tmpCGFileName); 172 | cgPics.push_back(tmpCGPic); 173 | 174 | tmpLine = tmpLine.substr(splitPosition + 1); 175 | } 176 | 177 | return cgPics; 178 | } 179 | 180 | // remove all '\r' and \n' at the end of input string 181 | // @param 1 - inString: pointer to string to be handle 182 | void CSVFileSplitter::removeEOLChar(std::string *inString) { 183 | int size = (*inString).size(); 184 | char endChar = (*inString).at(size - 1); 185 | while ((endChar == '\r') || (endChar == '\n')) { 186 | (*inString).erase(size - 1, 1); 187 | size--; 188 | endChar = (*inString).at(size - 1); 189 | } 190 | } 191 | 192 | // turn all upper case char to lower case in input string 193 | // @param 1 - inString: pointer to string to be handle 194 | void CSVFileSplitter::stringToLowercase(std::string *inString) { 195 | for (size_t i = 0; i < (*inString).size(); i++) { 196 | char tmpChar = (*inString).at(i); 197 | if ((tmpChar >= 'A') && (tmpChar <= 'Z')) { 198 | (*inString)[i] = tmpChar - 'A' + 'a'; 199 | } 200 | } 201 | } 202 | 203 | // CSVFileSplitter constructor, handle the file with input name. 204 | // @param 1 - csvFileName: path to csv file 205 | CSVFileSplitter::CSVFileSplitter(const std::string &csvFileName) { 206 | csvFileName_ = csvFileName; 207 | csvCGPicSeriesNum_ = 0; 208 | totalPicNum_ = 0; 209 | std::ifstream csvFile; 210 | std::string lineBuff; 211 | csvFile.open(csvFileName_, std::ios::in|std::ios::binary); 212 | 213 | // line 1: always "#CGモード一覧\r\n" (ANSI) 214 | std::getline(csvFile, lineBuff); 215 | // line 2: title line 216 | std::getline(csvFile, lineBuff); 217 | titleLineSplit(lineBuff); 218 | 219 | // initial create dummy index name 220 | currentMainSeries_ = new CGLayerIndex; 221 | currentAddSeries_ = new CGLayerIndex; 222 | 223 | while (std::getline(csvFile, lineBuff)) { 224 | char tmpChar = lineBuff.at(0); 225 | // ":" divisse between character or between cg and sd 226 | if (tmpChar == ':') { 227 | continue; 228 | } 229 | // comment line, appear in Riddle Joker 230 | if (tmpChar == '#') { 231 | continue; 232 | } 233 | // blank line 234 | if ((tmpChar == '\r') || (tmpChar == '\n')) { 235 | continue; 236 | } 237 | 238 | stringToLowercase(&lineBuff); 239 | 240 | // cg line start with "thum_evxxx,..." or "thum_EVxxx,..." 241 | // sd line start with "thum_sdxxx,..." or "thum_SDxxx,..." 242 | tmpChar = lineBuff.at(5); 243 | if ((tmpChar == 's') || (tmpChar == 'S')) { 244 | break; 245 | } 246 | else { 247 | // before v3.0, store the info to generate Magick script 248 | //csvCGPicSeries_.push_back(csvLineSplit(lineBuff)); 249 | //csvCGPicSeriesNum_++; 250 | 251 | // v3.0 merge image using OpenCV 252 | csvCGPicSeriesNum_++; 253 | printf("\r\n\xA1\xAA\xA1\xAA\xA1\xAA\xA1\xAA\xA1\xAA \xB5\xDA %i \xD7\xE9 \xA1\xAA\xA1\xAA\xA1\xAA\xA1\xAA\xA1\xAA\r\n", csvCGPicSeriesNum_); 254 | std::vector cgGroup = csvLineSplit(lineBuff); 255 | int cgNum = cgGroup.size(); 256 | totalPicNum_ += cgNum; 257 | printf("\xB5\xDA %i \xD7\xE9\xA3\xAC\xB9\xB2 %i \xD5\xC5\xA3\xBA\r\n", csvCGPicSeriesNum_, cgNum); 258 | for (int i = 0; i < cgNum; i++) { 259 | printf("\xD5\xFD\xD4\xDA\xBA\xCF\xB3\xC9 %s ...\r\n", cgGroup[i].fileName().c_str()); 260 | cgGroup[i].saveImage(); 261 | } 262 | } 263 | } 264 | 265 | delete currentMainSeries_; 266 | delete currentAddSeries_; 267 | 268 | csvFile.close(); 269 | } 270 | 271 | CSVFileSplitter::~CSVFileSplitter() { 272 | } 273 | 274 | // return total number of CG group 275 | int CSVFileSplitter::totalGroup() { 276 | return csvCGPicSeriesNum_; 277 | } 278 | 279 | // return total number of CG Image 280 | int CSVFileSplitter::totalPic() { 281 | return totalPicNum_; 282 | } 283 | 284 | // No longer used after v3.0 due to the use of OpenCV 285 | /* 286 | // print stored cgs info for debug 287 | void CSVFileSplitter::debugPrint() { 288 | std::cout << "csvCGPicSeriesNum_ = " << csvCGPicSeriesNum_ << std::endl; 289 | for (int i = 0; i < csvCGPicSeriesNum_; i++) { 290 | std::vector tmpCGPics = csvCGPicSeries_[i]; 291 | int tmpCGPicNum = tmpCGPics.size(); 292 | std::cout << "tmpCGPics.size(): " << tmpCGPicNum << std::endl; 293 | 294 | for (int j = 0; j < tmpCGPicNum; j++) { 295 | CGPic tmpCGPic = tmpCGPics[j]; 296 | 297 | std::cout << tmpCGPic.magickMergeScript() << std::endl; 298 | } 299 | } 300 | } 301 | */ 302 | 303 | // No longer used after v3.0 due to the use of OpenCV 304 | /* 305 | // generate a batch script with merging command-line of all CGs stored 306 | void CSVFileSplitter::writeBatFile() { 307 | // Prompt text uses GB2312 encoding formatt 308 | std::ofstream outFile("merge.bat", std::ios::out | std::ios::binary); 309 | outFile << "@echo off\r\n"; 310 | 311 | outFile << "if not exist \"CGOutput\" (\r\n" 312 | << " mkdir \"CGOutput\"\r\n" 313 | << ")\r\n"; 314 | 315 | outFile << "echo \xB9\xB2\xD3\xD0 " << csvCGPicSeriesNum_ 316 | << " \xD7\xE9\xCD\xBC\xC6\xAC\r\n"; 317 | 318 | for (int i = 0; i < csvCGPicSeriesNum_; i++) { 319 | std::vector tmpCGPics = csvCGPicSeries_[i]; 320 | int tmpCGPicNum = tmpCGPics.size(); 321 | outFile << "echo \xB5\xDA " << i + 1 << "/" << csvCGPicSeriesNum_ << " \xD7\xE9\xA3" 322 | << "\xAC\xB9\xB2 " << tmpCGPicNum << " \xD5\xC5\xA3\xBA\r\n"; 323 | 324 | for (int j = 0; j < tmpCGPicNum; j++) { 325 | CGPic tmpCGPic = tmpCGPics[j]; 326 | outFile << "echo \xD5\xFD\xD4\xDA\xBA\xCF\xB3\xC9\xB5\xDA " 327 | << j + 1 << " \xD5\xC5\xA1\xAD\r\n"; 328 | outFile << tmpCGPic.magickMergeScript() << "\r\n"; 329 | } 330 | } 331 | 332 | outFile << "echo \x43\x47\xBA\xCF\xB3\xC9\xCD\xEA\xB3\xC9\r\n"; 333 | outFile << "pause > nul\r\n"; 334 | outFile << "del %0\r\n"; 335 | } 336 | */ 337 | 338 | // split the title line for number of item before cg info 339 | // set the variables (itemBeforeCG_, nameInLine_) 340 | // @param 1 - titleLine: title line in cglist.csv (ANSI) 341 | // example: "#サムネール, 画像1, 画像2, 画像3, ...\r\n" --> (1, false) 342 | // "#サムネール,CG名称,\t画像1, 画像2, 画像3, ...\r\n" --> (2, true) 343 | void CSVFileSplitter::titleLineSplit(const std::string &titleLine) { 344 | size_t splitPosition; 345 | splitPosition = titleLine.find('1'); 346 | std::string tmpLine = titleLine.substr(0, splitPosition - 4); 347 | 348 | itemBeforeCg_ = 0; 349 | size_t findStart = 0; 350 | while ((findStart = tmpLine.find(',', findStart + 1)) != std::string::npos) { 351 | itemBeforeCg_++; 352 | } 353 | 354 | if (itemBeforeCg_ > 1) { 355 | nameInLine_ = true; 356 | } 357 | else { 358 | nameInLine_ = false; 359 | } 360 | 361 | } 362 | -------------------------------------------------------------------------------- /src/csvsplitter.h: -------------------------------------------------------------------------------- 1 | /* **************************************************************** 2 | * FilePath : /src/csvsplitter.h 3 | * Project Name : CGMerge 4 | * Author : zzyy21 5 | * Create Time : 2020-06-24 11:53:59 6 | * Modifed by : zzyy21 7 | * Last Modify : 2020-07-10 19:37:40 8 | * Description : CSVSplitter class for cglist.csv file handling 9 | * Revision : v1.0 - process cglist.csv 10 | * v3.0 - process cglist.csv & imagediffmap.csv, 11 | * merge images using OpenCV instead of generate 12 | * Magick Command-line scripts 13 | * v3.3 - move class CSVimagediffmapSplitter for 14 | * imagediffmap.csv file handling to new file 15 | * cgpicindex.h. use new layer identify rule. 16 | * **************************************************************** */ 17 | 18 | #ifndef CSVSPLITTER_H_ 19 | #define CSVSPLITTER_H_ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include "cgpic.h" 26 | #include "cglayerindex.h" 27 | #include "cgpicindex.h" 28 | 29 | // class for splitting cglist.csv 30 | class CSVFileSplitter { 31 | private: 32 | std::string csvFileName_; 33 | std::vector > csvCGPicSeries_; 34 | int csvCGPicSeriesNum_; 35 | int totalPicNum_; 36 | 37 | CSVimagediffmapSplitter csvImageDiffmapSplitter_; 38 | 39 | CGLayerIndex* currentMainSeries_; 40 | CGLayerIndex* currentAddSeries_; 41 | // **No longer used after v3.0 due to getting info from imagediffmap.csv 42 | //void cgInfo(const std::string &cgInfo, std::string* p_cgSeriesName, int* p_bgLayer, int* p_upLayer); 43 | std::vector csvLineSplit(const std::string &csvLine); 44 | 45 | void titleLineSplit(const std::string &titleLine); 46 | bool nameInLine_; 47 | int itemBeforeCg_; 48 | 49 | void removeEOLChar(std::string *inString); 50 | void stringToLowercase(std::string *inString); 51 | 52 | public: 53 | CSVFileSplitter(const std::string &csvFileName = "cglist.csv"); 54 | ~CSVFileSplitter(); 55 | 56 | int totalGroup(); 57 | int totalPic(); 58 | 59 | // **No longer used after v3.0 due to the use of OpenCV 60 | //void debugPrint(); 61 | // **No longer used after v3.0 due to the use of OpenCV 62 | //void writeBatFile(); 63 | }; 64 | 65 | #endif 66 | --------------------------------------------------------------------------------