├── src ├── makefile ├── ocrsubtitles ├── tesseract_wrapper ├── common │ ├── pgm.hpp │ ├── rectangle.hpp │ ├── color.hpp │ ├── rectangle.cpp │ ├── subtitle.hpp │ ├── filler.hpp │ ├── ycbcr_img.hpp │ ├── color.cpp │ ├── subtitle.cpp │ ├── pgm.cpp │ ├── y4m.hpp │ ├── ycbcr_img.cpp │ ├── y4m.cpp │ └── filler.cpp ├── getsubtitles.cpp ├── remsubtitles.cpp └── locsubtitles.cpp ├── README.md └── COPYING /src/makefile: -------------------------------------------------------------------------------- 1 | 2 | all : locsubtitles getsubtitles remsubtitles 3 | 4 | locsubtitles : locsubtitles.cpp common/y4m.cpp common/subtitle.cpp common/rectangle.cpp common/color.cpp common/ycbcr_img.cpp common/pgm.cpp 5 | g++ -O2 -lboost_program_options -o locsubtitles locsubtitles.cpp common/y4m.cpp common/subtitle.cpp common/rectangle.cpp common/color.cpp common/ycbcr_img.cpp common/pgm.cpp 6 | 7 | getsubtitles : getsubtitles.cpp common/y4m.cpp common/subtitle.cpp common/rectangle.cpp common/color.cpp common/ycbcr_img.cpp common/pgm.cpp 8 | g++ -O2 -lboost_program_options -o getsubtitles getsubtitles.cpp common/y4m.cpp common/subtitle.cpp common/rectangle.cpp common/color.cpp common/ycbcr_img.cpp common/pgm.cpp 9 | 10 | remsubtitles : remsubtitles.cpp common/y4m.cpp common/subtitle.cpp common/filler.cpp common/color.cpp common/ycbcr_img.cpp common/pgm.cpp 11 | g++ -O2 -lboost_program_options -o remsubtitles remsubtitles.cpp common/y4m.cpp common/subtitle.cpp common/filler.cpp common/color.cpp common/ycbcr_img.cpp common/pgm.cpp 12 | -------------------------------------------------------------------------------- /src/ocrsubtitles: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This file is part of the burnt-in subtitle extractor. 4 | # Copyright (C) 2018 Benedikt Freisen 5 | # 6 | # This program is free software; you can redistribute it and/or 7 | # modify it under the terms of the GNU General Public License 8 | # as published by the Free Software Foundation; either version 2 9 | # of the License, or (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program; if not, write to the Free Software 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | 20 | while read line 21 | do text=$($1 ${line##*\}}); 22 | text2=$(echo -n "$text" | tr "\n" "|"); 23 | echo "${line%\}*}}$text2" 24 | done 25 | -------------------------------------------------------------------------------- /src/tesseract_wrapper: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This file is part of the burnt-in subtitle extractor. 4 | # Copyright (C) 2018 Benedikt Freisen 5 | # 6 | # This program is free software; you can redistribute it and/or 7 | # modify it under the terms of the GNU General Public License 8 | # as published by the Free Software Foundation; either version 2 9 | # of the License, or (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program; if not, write to the Free Software 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | 20 | convert "$1" "temp.tiff" 21 | tesseract "temp.tiff" "temp" "-l" "nld" > /dev/null 22 | cat "temp.txt" 23 | rm "temp.txt" 24 | rm "temp.tiff" 25 | -------------------------------------------------------------------------------- /src/common/pgm.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the burnt-in subtitle extractor. 3 | * Copyright (C) 2018 Benedikt Freisen 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef PGM_HPP 21 | #define PGM_HPP 22 | 23 | #include 24 | 25 | void read_pgm(const char* name, uint8_t*& img, int& width, int& height); 26 | 27 | void write_pgm(uint8_t* img, int width, int height, const char* name); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /src/common/rectangle.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the burnt-in subtitle extractor. 3 | * Copyright (C) 2018 Benedikt Freisen 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef RECTANGLE_HPP 21 | #define RECTANGLE_HPP 22 | 23 | #include 24 | 25 | class rectangle 26 | { 27 | public: 28 | int x; 29 | int y; 30 | int w; 31 | int h; 32 | rectangle(); 33 | rectangle(int x, int y, int w, int h); 34 | }; 35 | 36 | std::istream& operator>>(std::istream& istr, rectangle& r); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/common/color.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the burnt-in subtitle extractor. 3 | * Copyright (C) 2018 Benedikt Freisen 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef COLOR_HPP 21 | #define COLOR_HPP 22 | 23 | #include 24 | #include 25 | 26 | class color 27 | { 28 | public: 29 | uint8_t y; 30 | uint8_t cb; 31 | uint8_t cr; 32 | color(); 33 | color(uint8_t y, uint8_t cb, uint8_t cr); 34 | bool similar_to(color c, color d); 35 | }; 36 | 37 | std::istream& operator>>(std::istream& istr, color& c); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/common/rectangle.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the burnt-in subtitle extractor. 3 | * Copyright (C) 2018 Benedikt Freisen 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "rectangle.hpp" 21 | 22 | rectangle::rectangle() 23 | { 24 | 25 | } 26 | 27 | rectangle::rectangle(int x, int y, int w, int h) 28 | { 29 | this->x = x; 30 | this->y = y; 31 | this->w = w; 32 | this->h = h; 33 | } 34 | 35 | std::istream& operator>>(std::istream& istr, rectangle& r) 36 | { 37 | char c; 38 | istr >> r.x >> c >> r.y >> c >> r.w >> c >> r.h; 39 | return istr; 40 | } 41 | -------------------------------------------------------------------------------- /src/common/subtitle.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the burnt-in subtitle extractor. 3 | * Copyright (C) 2018 Benedikt Freisen 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef SUBTITLE_HPP 21 | #define SUBTITLE_HPP 22 | 23 | #include 24 | #include 25 | 26 | class subtitle 27 | { 28 | public: 29 | int start; 30 | int end; 31 | std::string text; 32 | subtitle(); 33 | subtitle(int start, int end, std::string text); 34 | friend std::istream& operator>>(std::istream& istr, subtitle& s); 35 | friend std::ostream& operator<<(std::ostream& ostr, subtitle s); 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/common/filler.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the burnt-in subtitle extractor. 3 | * Copyright (C) 2018 Benedikt Freisen 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | class filler 23 | { 24 | uint8_t* data[32]; 25 | uint8_t* alpha[32]; 26 | //uint8_t* data_blurred[32]; 27 | //uint8_t* alpha_blurred[32]; 28 | int steps; 29 | int width[32]; 30 | int height[32]; 31 | public: 32 | filler(int w, int h, uint8_t* img, uint8_t* mask); 33 | ~filler(); 34 | void set_data0(uint8_t* data0); 35 | void fill(); 36 | void shrink(int n); 37 | /*void blur(int n);*/ 38 | void restore(int n); 39 | }; 40 | -------------------------------------------------------------------------------- /src/common/ycbcr_img.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the burnt-in subtitle extractor. 3 | * Copyright (C) 2018 Benedikt Freisen 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef YCBCR_IMG_HPP 21 | #define YCBCR_IMG_HPP 22 | 23 | #include 24 | #include 25 | #include "color.hpp" 26 | 27 | class ycbcr_img 28 | { 29 | public: 30 | int width; 31 | int height; 32 | int width_chroma; 33 | int height_chroma; 34 | uint8_t* y; 35 | uint8_t* cb; 36 | uint8_t* cr; 37 | ycbcr_img(int width, int height); 38 | ~ycbcr_img(); 39 | color pixel(int xpos, int ypos); 40 | }; 41 | 42 | std::istream& operator>>(std::istream& istr, ycbcr_img& img); 43 | 44 | std::ostream& operator<<(std::ostream& ostr, ycbcr_img& img); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/common/color.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the burnt-in subtitle extractor. 3 | * Copyright (C) 2018 Benedikt Freisen 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "color.hpp" 21 | 22 | color::color() 23 | { 24 | 25 | } 26 | 27 | color::color(uint8_t y, uint8_t cb, uint8_t cr) 28 | { 29 | this->y = y; 30 | this->cb = cb; 31 | this->cr = cr; 32 | } 33 | 34 | bool color::similar_to(color c, color d) 35 | { 36 | return ((y >= c.y - d.y) && (y <= c.y + d.y) && (cb >= c.cb - d.cb) && (cb <= c.cb + d.cb) && (cr >= c.cr - d.cr) && (cr <= c.cr + d.cr)); 37 | } 38 | 39 | std::istream& operator>>(std::istream& istr, color& c) 40 | { 41 | char ch; 42 | int y, cb, cr; 43 | istr >> y >> ch >> cb >> ch >> cr; 44 | c.y = y; 45 | c.cb = cb; 46 | c.cr = cr; 47 | return istr; 48 | } 49 | -------------------------------------------------------------------------------- /src/common/subtitle.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the burnt-in subtitle extractor. 3 | * Copyright (C) 2018 Benedikt Freisen 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "subtitle.hpp" 21 | 22 | subtitle::subtitle() 23 | { 24 | 25 | } 26 | 27 | subtitle::subtitle(int start, int end, std::string text) 28 | { 29 | this->start = start; 30 | this->end = end; 31 | this->text = text; 32 | } 33 | 34 | std::istream& operator>>(std::istream& istr, subtitle& s) 35 | { 36 | istr.flags(std::ios::dec); 37 | char c; 38 | istr >> c; 39 | if (c != '{') 40 | istr.setstate(std::istream::failbit); 41 | istr >> s.start; 42 | istr >> c >> c; 43 | istr >> s.end; 44 | istr >> c; 45 | std::getline(istr, s.text); 46 | return istr; 47 | } 48 | 49 | std::ostream& operator<<(std::ostream& ostr, subtitle s) 50 | { 51 | ostr << "{" << s.start << "}{" << s.end << "}" << s.text << "\n"; 52 | return ostr; 53 | } 54 | -------------------------------------------------------------------------------- /src/common/pgm.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the burnt-in subtitle extractor. 3 | * Copyright (C) 2018 Benedikt Freisen 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #include "pgm.hpp" 24 | 25 | using namespace std; 26 | 27 | void read_pgm(const char* name, uint8_t*& img, int& width, int& height) 28 | { 29 | ifstream f; 30 | f.open(name); 31 | char sig[10]; 32 | int maxval; 33 | f.getline(sig, 9); 34 | if (strcmp(sig, "P5") != 0) 35 | { 36 | width = 0; 37 | height = 0; 38 | return; 39 | } 40 | f >> width >> height >> maxval; 41 | f.ignore(1); 42 | img = new uint8_t[width * height]; 43 | f.read((char*)img, width * height); 44 | f.close(); 45 | } 46 | 47 | void write_pgm(uint8_t* img, int width, int height, const char* name) 48 | { 49 | ofstream f; 50 | f.open(name); 51 | f << "P5\n" << width << " " << height << "\n255\n"; 52 | f.write((char*)img, width * height); 53 | f.close(); 54 | } 55 | -------------------------------------------------------------------------------- /src/common/y4m.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the burnt-in subtitle extractor. 3 | * Copyright (C) 2018 Benedikt Freisen 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef Y4M_HPP 21 | #define Y4M_HPP 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | class ratio 29 | { 30 | public: 31 | uint16_t num; 32 | uint16_t den; 33 | /*ratio(uint16_t num, uint16_t den);*/ 34 | double to_double(); 35 | friend std::istream& operator>>(std::istream& istr, ratio& r); 36 | friend std::ostream& operator<<(std::ostream& istr, ratio& r); 37 | }; 38 | 39 | class y4m_stream_header 40 | { 41 | public: 42 | uint16_t w; 43 | uint16_t h; 44 | std::string c; 45 | char i; 46 | ratio f; 47 | ratio a; 48 | std::vector x; 49 | public: 50 | y4m_stream_header(); 51 | friend std::istream& operator>>(std::istream& istr, y4m_stream_header& h); 52 | friend std::ostream& operator<<(std::ostream& ostr, y4m_stream_header& h); 53 | 54 | }; 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /src/common/ycbcr_img.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the burnt-in subtitle extractor. 3 | * Copyright (C) 2018 Benedikt Freisen 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "ycbcr_img.hpp" 21 | 22 | ycbcr_img::ycbcr_img(int width, int height) 23 | { 24 | this->width = width; 25 | this->height = height; 26 | this->width_chroma = this->width / 2; 27 | this->height_chroma = this->height / 2; 28 | this->y = new uint8_t[this->width * this->height]; 29 | this->cb = new uint8_t[this->width_chroma * this->height_chroma]; 30 | this->cr = new uint8_t[this->width_chroma * this->height_chroma]; 31 | } 32 | 33 | ycbcr_img::~ycbcr_img() 34 | { 35 | delete [] y; 36 | delete [] cb; 37 | delete [] cr; 38 | } 39 | 40 | std::istream& operator>>(std::istream& istr, ycbcr_img& img) 41 | { 42 | istr.read((char*)img.y, img.width * img.height); 43 | istr.read((char*)img.cb, img.width_chroma * img.height_chroma); 44 | istr.read((char*)img.cr, img.width_chroma * img.height_chroma); 45 | return istr; 46 | } 47 | 48 | std::ostream& operator<<(std::ostream& ostr, ycbcr_img& img) 49 | { 50 | ostr.write((char*)img.y, img.width * img.height); 51 | ostr.write((char*)img.cb, img.width_chroma * img.height_chroma); 52 | ostr.write((char*)img.cr, img.width_chroma * img.height_chroma); 53 | return ostr; 54 | } 55 | 56 | color ycbcr_img::pixel(int xpos, int ypos) 57 | { 58 | return color(y[ypos * width + xpos], cb[(ypos / 2) * width_chroma + (xpos / 2)], cr[(ypos / 2) * width_chroma + (xpos / 2)]); 59 | } 60 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Burnt-in subtitle extractor 2 | 3 | This project provides a set of basic extraction tools for burnt-in subtitles, i.e. subtitles that are part of the picture itself. 4 | 5 | ## Tools 6 | 7 | The burnt-in subtitle extractor consists of four different tools: 8 | 9 | - `locsubtitles` locates subtitles within the picture, creates mask files and writes their names to an initial textual subtitle file along with timing information 10 | - `getsubtitles` applies those masks to the picture and writes the averaged out graphical subtitles to a new set of image files 11 | - `remsubtitles` deletes the masked out areas from the input frames and blends in the surrounding colors 12 | - `ocrsubtitles` runs the extracted graphical subtitles through an external OCR and outputs the final textual subtitle file 13 | 14 | ## Examples 15 | 16 | The following examples will in part rely on default parameters. 17 | You will typically have to provide parameters tuned to your input file. 18 | Type e.g. `getsubtitles --help` for details. 19 | 20 | ``` 21 | > ffmpeg -i test.flv -f yuv4mpegpipe - | ./locsubtitles > test.sub 22 | > ffmpeg -i test.flv -f yuv4mpegpipe - | ./remsubtitles -s test.sub | ffplay - 23 | ``` 24 | 25 | ## How it works 26 | 27 | This program relies on several patterns in how subtitles are typically added to videos: 28 | 29 | - Subtitles typically have borders and a defined text and border color 30 | - Subtitles are usually located in the same part of the picture and do not move 31 | - Analysis can be limited to a specified region 32 | - This program further relies on the presence of a frame without subtitles between frames with different subtitles 33 | 34 | The algorithm then does the following: 35 | 36 | - For every frame 37 | - Create a text mask that includes all pixels that have the text color 38 | - Expand that text mask in all four directions by the stroke width of the text border 39 | - Create a border mask that includes all pixels that have the border color 40 | - Expand that border mask in all four directions by the stroke width of the text 41 | - Calculate the intersection of both masks 42 | - If the number of pixels in the resulting mask is above a specified threshold 43 | - (A subtitle has been found) 44 | - If the previous frame did not have subtitles 45 | - Mark the start position 46 | - Otherwise: Set the subtitle mask to the intersection of both frames' subtitle masks 47 | - Otherwise (no subtitle) 48 | - If the previous frame had subtitles 49 | - Write the previous (i.e. the non-empty) subtitle mask to an image file 50 | - Write start and end time information and the name of the mask file to the subtitle file 51 | - When the end of the video has been reached, output any pending information and exit 52 | 53 | The OCR component uses the Tesseract engine, which has to be installed on the system. 54 | The target language is currently hard-coded to Dutch. This can be changed in the wrapper script. 55 | 56 | ## Prerequisites 57 | 58 | The program has been tested with the following setup, only: 59 | 60 | - GNU/Linux operating system 61 | - GNU C++ compiler + Boost libraries 62 | - Bash shell + Tesseract OCR 63 | - Y4M video streams produced by ffmpeg 64 | 65 | Other setups might work. 66 | -------------------------------------------------------------------------------- /src/common/y4m.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the burnt-in subtitle extractor. 3 | * Copyright (C) 2018 Benedikt Freisen 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "y4m.hpp" 21 | 22 | /*ratio::ratio(uint16_t num, uint16_t den) 23 | { 24 | this->num = num; 25 | this->den = den; 26 | }*/ 27 | 28 | std::istream& operator>>(std::istream& istr, ratio& r) 29 | { 30 | istr >> r.num; 31 | char c; 32 | istr >> c; 33 | istr >> r.den; 34 | return istr; 35 | } 36 | 37 | std::ostream& operator<<(std::ostream& ostr, ratio& r) 38 | { 39 | ostr << r.num << ':' << r.den; 40 | return ostr; 41 | } 42 | 43 | double ratio::to_double() 44 | { 45 | if (this->den == 0) 46 | return 1; 47 | return ((double) this->num) / this->den; 48 | } 49 | 50 | y4m_stream_header::y4m_stream_header() 51 | { 52 | w = 0; 53 | h = 0; 54 | c = "420jpeg"; 55 | i = '?'; 56 | /*f = ratio(0, 0); 57 | i = ratio(0, 0);*/ 58 | } 59 | 60 | std::istream& operator>>(std::istream& istr, y4m_stream_header& h) 61 | { 62 | std::ios_base::fmtflags flags = istr.flags(std::ios_base::dec); 63 | std::string s; 64 | char c; 65 | istr >> s; 66 | if (s != "YUV4MPEG2") 67 | { 68 | istr.setstate(std::istream::failbit); 69 | istr.flags(flags); 70 | return istr; 71 | } 72 | istr >> c; 73 | while (c != '\n') 74 | { 75 | if (c != ' ') 76 | { 77 | istr.setstate(std::istream::failbit); 78 | istr.flags(flags); 79 | return istr; 80 | } 81 | istr >> c; 82 | switch (c) 83 | { 84 | case 'W': 85 | istr >> h.w; 86 | break; 87 | case 'H': 88 | istr >> h.h; 89 | break; 90 | case 'C': 91 | istr >> h.c; 92 | break; 93 | case 'I': 94 | istr >> h.i; 95 | break; 96 | case 'F': 97 | istr >> h.f; 98 | break; 99 | case 'A': 100 | istr >> h.a; 101 | break; 102 | case 'X': 103 | istr >> s; 104 | h.x.push_back(std::string(s)); 105 | break; 106 | default: 107 | istr.setstate(std::istream::failbit); 108 | istr.flags(flags); 109 | return istr; 110 | break; 111 | } 112 | istr >> c; 113 | } 114 | return istr; 115 | } 116 | 117 | std::ostream& operator<<(std::ostream& ostr, y4m_stream_header& h) 118 | { 119 | ostr << "YUV4MPEG2" << " W" << h.w << " H" << h.h << " C" << h.c << " I" << h.i << " F" << h.f << " A" << h.a; 120 | int i; 121 | for (i = 0; i < h.x.size(); i++) 122 | ostr << " X" << h.x[i]; 123 | ostr << '\n'; 124 | return ostr; 125 | } 126 | -------------------------------------------------------------------------------- /src/getsubtitles.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the burnt-in subtitle extractor. 3 | * Copyright (C) 2018 Benedikt Freisen 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | namespace po = boost::program_options; 28 | 29 | #include "common/y4m.hpp" 30 | #include "common/subtitle.hpp" 31 | #include "common/rectangle.hpp" 32 | #include "common/color.hpp" 33 | #include "common/ycbcr_img.hpp" 34 | #include "common/pgm.hpp" 35 | 36 | using namespace std; 37 | 38 | int bounds(int a, int b, int c) 39 | { 40 | if (a < b) 41 | return b; 42 | if (a > c) 43 | return c; 44 | return a; 45 | } 46 | 47 | int main(int argc, char **argv) 48 | { 49 | rectangle area(50, 350, 550, 100); 50 | 51 | color text_color(205, 128, 128); 52 | color text_color_diff(45, 20, 20); 53 | color border_color(50, 128, 128); 54 | color border_color_diff(50, 40, 40); 55 | 56 | string prefix; 57 | string subname; 58 | 59 | po::options_description desc("Allowed options"); 60 | desc.add_options() 61 | ("help,h", "print help message") 62 | ("area,a", po::value(&area), "area containing subtitles (x,y,w,h)") 63 | ("text-color,t", po::value(&text_color), "text color (y,cb,cr)") 64 | ("text-cdiff,T", po::value(&text_color_diff), "text color max. difference (y,cb,cr)") 65 | ("border-color,b", po::value(&border_color), "border color (y,cb,cr)") 66 | ("border-cdiff,B", po::value(&border_color_diff), "border color max. difference (y,cb,cr)") 67 | ("prefix,p", po::value(&prefix)->default_value("text_"), "name prefix for numbered .pgm files showing text") 68 | ("sub,s", po::value(&subname)->default_value("test.sub"), "name of input .sub file") 69 | ; 70 | 71 | po::variables_map vm; 72 | po::store(po::parse_command_line(argc, argv, desc), vm); 73 | po::notify(vm); 74 | 75 | if (vm.count("help")) 76 | { 77 | clog << desc << "\n"; 78 | exit(EXIT_FAILURE); 79 | } 80 | 81 | int dark = (text_color.y + border_color.y) / 2; 82 | int bright = text_color.y; 83 | 84 | y4m_stream_header stream_header; 85 | cin >> stream_header; 86 | 87 | ycbcr_img img(stream_header.w, stream_header.h); 88 | 89 | int img_no = 0; 90 | int mask_no = 0; 91 | 92 | int start = 0; 93 | int end = 0; 94 | 95 | uint8_t* mask = NULL; 96 | 97 | uint32_t* img_area_luma = NULL; 98 | 99 | int count = 0; 100 | 101 | ifstream f; 102 | f.open(subname.c_str()); 103 | 104 | char buffer[10000]; 105 | 106 | while (!cin.eof()) 107 | { 108 | cin.getline(buffer, 9999); 109 | cin >> img; 110 | 111 | if (img_no == end) 112 | { 113 | subtitle sub; 114 | f >> sub; 115 | start = sub.start; 116 | end = sub.end; 117 | stringstream ss; 118 | char c; 119 | ss << sub.text; 120 | ss >> noskipws >> area.x >> c >> area.y >> c; 121 | string name; 122 | getline(ss, name); 123 | 124 | read_pgm(name.c_str(), mask, area.w, area.h); 125 | 126 | img_area_luma = new uint32_t[area.w * area.h]; 127 | memset(img_area_luma, 0, area.w * area.h * sizeof(uint32_t)); 128 | count = 0; 129 | } 130 | 131 | int x, y; 132 | if ((img_no >= start) && (img_no < end)) 133 | { 134 | for (y = 0; y < area.h; y++) 135 | { 136 | for (x = 0; x < area.w; x++) 137 | { 138 | img_area_luma[y * area.w + x] += img.y[(y + area.y) * img.width + x + area.x]; 139 | } 140 | } 141 | count++; 142 | } 143 | 144 | img_no++; 145 | 146 | if (img_no == end) 147 | { 148 | for (y = 0; y < area.h; y++) 149 | { 150 | for (x = 0; x < area.w; x++) 151 | { 152 | if (mask[y * area.w + x]) 153 | mask[y * area.w + x] = bounds(((int)(img_area_luma[y * area.w + x] / count) - dark) * 255 / (bright - dark), 0, 255); 154 | } 155 | } 156 | 157 | ostringstream oss; 158 | oss << prefix << mask_no << ".pgm"; 159 | write_pgm(mask, area.w, area.h, oss.str().c_str()); 160 | oss.clear(); 161 | oss << area.x << " " << area.y << " " << prefix << mask_no << ".pgm"; 162 | cout << subtitle(start, end, oss.str()); 163 | mask_no++; 164 | 165 | delete [] img_area_luma; 166 | img_area_luma = NULL; 167 | delete [] mask; 168 | mask = NULL; 169 | } 170 | 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /src/remsubtitles.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the burnt-in subtitle extractor. 3 | * Copyright (C) 2018 Benedikt Freisen 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | namespace po = boost::program_options; 27 | 28 | #include "common/y4m.hpp" 29 | #include "common/subtitle.hpp" 30 | #include "common/filler.hpp" 31 | #include "common/ycbcr_img.hpp" 32 | #include "common/pgm.hpp" 33 | 34 | using namespace std; 35 | 36 | 37 | int main(int argc, char **argv) 38 | { 39 | int area_x; 40 | int area_y; 41 | string subname; 42 | 43 | po::options_description desc("Allowed options"); 44 | desc.add_options() 45 | ("help,h", "print help message") 46 | ("area-x,x", po::value(&area_x)->default_value(50), " x-coordinate of area containing subtitles") 47 | ("area-y,y", po::value(&area_y)->default_value(350), " y-coordinate of area containing subtitles") 48 | ("sub,s", po::value(&subname)->default_value("test.sub"), "name of input .sub file") 49 | ; 50 | 51 | po::variables_map vm; 52 | po::store(po::parse_command_line(argc, argv, desc), vm); 53 | po::notify(vm); 54 | 55 | if (vm.count("help")) 56 | { 57 | clog << desc << "\n"; 58 | exit(EXIT_FAILURE); 59 | } 60 | 61 | y4m_stream_header stream_header; 62 | cin >> stream_header; 63 | cout << stream_header; 64 | 65 | int mask_width; 66 | int mask_height; 67 | int mask_width_chroma; 68 | int mask_height_chroma; 69 | 70 | int img_no = 0; 71 | int mask_no = 0; 72 | 73 | int start = 0; 74 | int end = 0; 75 | 76 | ycbcr_img img(stream_header.w, stream_header.h); 77 | uint8_t* mask = NULL; 78 | 79 | filler* filler_luma = NULL; 80 | uint8_t* img_area_luma = NULL; 81 | filler* filler_chroma = NULL; 82 | uint8_t* img_area_chroma = NULL; 83 | uint8_t* mask_chroma = NULL; 84 | 85 | ifstream f; 86 | f.open(subname.c_str()); 87 | 88 | char buffer[10000]; 89 | 90 | while (!cin.eof()) 91 | { 92 | cin.getline(buffer, 9999); 93 | cout << buffer << "\n"; 94 | cin >> img; 95 | 96 | if (img_no == end) 97 | { 98 | subtitle sub; 99 | f >> sub; 100 | start = sub.start; 101 | end = sub.end; 102 | stringstream ss; 103 | char c; 104 | ss << sub.text; 105 | ss >> noskipws >> area_x >> c >> area_y >> c; 106 | string name; 107 | getline(ss, name); 108 | 109 | read_pgm(name.c_str(), mask, mask_width, mask_height); 110 | mask_no++; 111 | 112 | mask_width_chroma = (mask_width + 1) / 2; 113 | mask_height_chroma = (mask_height + 1) / 2; 114 | int i, x, y; 115 | for (i = 0; i < mask_width * mask_height; i++) 116 | mask[i] = 255 - mask[i]; 117 | img_area_luma = new uint8_t[mask_width * mask_height]; 118 | filler_luma = new filler(mask_width, mask_height, img_area_luma, mask); 119 | img_area_chroma = new uint8_t[mask_width_chroma * mask_height_chroma]; 120 | mask_chroma = new uint8_t[mask_width_chroma * mask_height_chroma]; 121 | for (y = 0; y < (mask_height + 0) / 2; y++) 122 | { 123 | for (x = 0; x < (mask_width + 0) / 2; x++) 124 | { 125 | mask_chroma[y * mask_width_chroma + x] = 126 | mask[(y * 2) * mask_width + x * 2] & 127 | mask[(y * 2) * mask_width + x * 2 + 1] & 128 | mask[(y * 2 + 1) * mask_width + x * 2] & 129 | mask[(y * 2 + 1) * mask_width + x * 2 + 1]; 130 | } 131 | } 132 | filler_chroma = new filler(mask_width_chroma, mask_height_chroma, img_area_chroma, mask_chroma); 133 | } 134 | 135 | int x, y; 136 | if ((img_no >= start) && (img_no < end)) 137 | { 138 | for (y = 0; y < mask_height; y++) 139 | { 140 | for (x = 0; x < mask_width; x++) 141 | { 142 | img_area_luma[y * mask_width + x] = img.y[(y + area_y) * img.width + x + area_x]; 143 | } 144 | } 145 | filler_luma->fill(); 146 | for (y = 0; y < mask_height; y++) 147 | { 148 | for (x = 0; x < mask_width; x++) 149 | { 150 | img.y[(y + area_y) * img.width + x + area_x] = img_area_luma[y * mask_width + x]; 151 | } 152 | } 153 | 154 | for (y = 0; y < mask_height_chroma; y++) 155 | { 156 | for (x = 0; x < mask_width_chroma; x++) 157 | { 158 | img_area_chroma[y * mask_width_chroma + x] = img.cb[(y + area_y / 2) * img.width_chroma + x + area_x / 2]; 159 | } 160 | } 161 | filler_chroma->fill(); 162 | for (y = 0; y < mask_height_chroma; y++) 163 | { 164 | for (x = 0; x < mask_width_chroma; x++) 165 | { 166 | img.cb[(y + area_y / 2) * img.width_chroma + x + area_x / 2] = img_area_chroma[y * mask_width_chroma + x]; 167 | } 168 | } 169 | 170 | for (y = 0; y < mask_height_chroma; y++) 171 | { 172 | for (x = 0; x < mask_width_chroma; x++) 173 | { 174 | img_area_chroma[y * mask_width_chroma + x] = img.cr[(y + area_y / 2) * img.width_chroma + x + area_x / 2]; 175 | } 176 | } 177 | filler_chroma->fill(); 178 | for (y = 0; y < mask_height_chroma; y++) 179 | { 180 | for (x = 0; x < mask_width_chroma; x++) 181 | { 182 | img.cr[(y + area_y / 2) * img.width_chroma + x + area_x / 2] = img_area_chroma[y * mask_width_chroma + x]; 183 | } 184 | } 185 | 186 | } 187 | 188 | cout << img; 189 | 190 | img_no++; 191 | 192 | if (img_no == end) 193 | { 194 | delete [] img_area_luma; 195 | img_area_luma = NULL; 196 | delete [] img_area_chroma; 197 | img_area_chroma = NULL; 198 | delete [] mask_chroma; 199 | mask_chroma = NULL; 200 | delete filler_chroma; 201 | filler_chroma = NULL; 202 | delete filler_luma; 203 | filler_luma = NULL; 204 | delete [] mask; 205 | mask = NULL; 206 | } 207 | 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /src/locsubtitles.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the burnt-in subtitle extractor. 3 | * Copyright (C) 2018 Benedikt Freisen 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | namespace po = boost::program_options; 29 | 30 | #include "common/y4m.hpp" 31 | #include "common/subtitle.hpp" 32 | #include "common/rectangle.hpp" 33 | #include "common/color.hpp" 34 | #include "common/ycbcr_img.hpp" 35 | #include "common/pgm.hpp" 36 | 37 | using namespace std; 38 | 39 | void expand(uint8_t* img, int width, int height, int left, int right, int top, int bottom) 40 | { 41 | int x, y; 42 | for (y = 0; y < height; y++) 43 | { 44 | int distance = 1000; 45 | for (x = left; x < width; x++) 46 | { 47 | if (img[y * width + x]) 48 | { 49 | if (distance > right) 50 | { 51 | int x2; 52 | for (x2 = x - left; x2 < x; x2++) 53 | img[y * width + x2] = 255; 54 | } 55 | distance = 0; 56 | } 57 | else if (distance < right) 58 | img[y * width + x] = 255; 59 | distance++; 60 | } 61 | } 62 | for (x = 0; x < width; x++) 63 | { 64 | int distance = 1000; 65 | for (y = top; y < height; y++) 66 | { 67 | if (img[y * width + x]) 68 | { 69 | if (distance > bottom) 70 | { 71 | int y2; 72 | for (y2 = y - top; y2 < y; y2++) 73 | img[y2 * width + x] = 255; 74 | } 75 | distance = 0; 76 | } 77 | else if (distance < bottom) 78 | img[y * width + x] = 255; 79 | distance++; 80 | } 81 | } 82 | } 83 | 84 | int count_nonzero(uint8_t* img, int size) 85 | { 86 | int n = 0; 87 | int i; 88 | for (i = 0; i < size; i++) 89 | { 90 | if (img[i]) 91 | n++; 92 | } 93 | return n; 94 | } 95 | 96 | void swap(uint8_t*& a, uint8_t*& b) 97 | { 98 | uint8_t* temp = a; 99 | a = b; 100 | b = temp; 101 | } 102 | 103 | 104 | int main(int argc, char** argv) 105 | { 106 | rectangle area(50, 350, 550, 100); 107 | rectangle radius1(4, 6, 4, 6); 108 | rectangle radius2(4, 4, 4, 4); 109 | 110 | color text_color(205, 128, 128); 111 | color text_color_diff(45, 20, 20); 112 | color border_color(50, 128, 128); 113 | color border_color_diff(50, 40, 40); 114 | 115 | string prefix; 116 | 117 | int threshold; 118 | 119 | po::options_description desc("Allowed options"); 120 | desc.add_options() 121 | ("help,h", "print help message") 122 | ("area,a", po::value(&area), "area containing subtitles (x,y,w,h)") 123 | ("text-color,t", po::value(&text_color), "text color (y,cb,cr)") 124 | ("text-cdiff,T", po::value(&text_color_diff), "text color max. difference (y,cb,cr)") 125 | ("border-color,b", po::value(&border_color), "border color (y,cb,cr)") 126 | ("border-cdiff,B", po::value(&border_color_diff), "border color max. difference (y,cb,cr)") 127 | ("prefix,p", po::value(&prefix)->default_value("mask_"), "name prefix for numbered .pgm masks") 128 | ("radius1,r", po::value(&radius1), "radius 1 (left,right,top,bottom)") 129 | ("radius2,R", po::value(&radius2), "radius 2 (left,right,top,bottom)") 130 | ("threshold,s", po::value(&threshold)->default_value(5000), "threshold") 131 | ; 132 | 133 | po::variables_map vm; 134 | po::store(po::parse_command_line(argc, argv, desc), vm); 135 | po::notify(vm); 136 | 137 | if (vm.count("help")) 138 | { 139 | clog << desc << "\n"; 140 | exit(EXIT_FAILURE); 141 | } 142 | 143 | y4m_stream_header stream_header; 144 | cin >> stream_header; 145 | 146 | bool subtitles_visible = false; 147 | 148 | int img_no = 0; 149 | int mask_no = 0; 150 | int start = 0; 151 | int end = 0; 152 | 153 | ycbcr_img img(stream_header.w, stream_header.h); 154 | 155 | uint8_t* mask1 = new uint8_t[area.w * area.h]; // text 156 | uint8_t* mask2 = new uint8_t[area.w * area.h]; // border 157 | uint8_t* mask3 = new uint8_t[area.w * area.h]; // text & border (intersection) 158 | uint8_t* mask3_old = new uint8_t[area.w * area.h]; 159 | 160 | char buffer[10000]; 161 | 162 | while (!cin.eof()) 163 | { 164 | cin.getline(buffer, 9999); 165 | cin >> img; 166 | memset(mask1, 0, area.w * area.h); 167 | memset(mask2, 0, area.w * area.h); 168 | int x, y, i; 169 | for (y = 0; y < area.h; y++) 170 | { 171 | for (x = 0; x < area.w; x++) 172 | { 173 | color pix(img.pixel(x + area.x, y + area.y)); 174 | if (pix.similar_to(text_color, text_color_diff)) 175 | mask1[y * area.w + x] = 255; 176 | else if (pix.similar_to(border_color, border_color_diff)) 177 | mask2[y * area.w + x] = 255; 178 | } 179 | } 180 | expand(mask1, area.w, area.h, radius1.x, radius1.y, radius1.w, radius1.h); 181 | expand(mask2, area.w, area.h, radius2.x, radius2.y, radius2.w, radius2.h); 182 | for (i = 0; i < area.w * area.h; i++) 183 | { 184 | mask3[i] = mask1[i] & mask2[i]; 185 | } 186 | if (count_nonzero(mask3, area.w * area.h) > threshold) 187 | { 188 | if (!subtitles_visible) 189 | { 190 | start = img_no; 191 | subtitles_visible = true; 192 | } 193 | else 194 | { 195 | for (i = 0; i < area.w * area.h; i++) 196 | { 197 | mask3[i] &= mask3_old[i]; 198 | } 199 | } 200 | } 201 | else 202 | { 203 | if (subtitles_visible) 204 | { 205 | end = img_no; 206 | ostringstream oss; 207 | oss << prefix << mask_no << ".pgm"; 208 | write_pgm(mask3_old, area.w, area.h, oss.str().c_str()); 209 | ostringstream oss2; 210 | oss2 << area.x << " " << area.y << " " << prefix << mask_no << ".pgm"; 211 | cout << subtitle(start, end, oss2.str()); 212 | mask_no++; 213 | subtitles_visible = false; 214 | } 215 | } 216 | 217 | img_no++; 218 | swap(mask3, mask3_old); 219 | } 220 | } 221 | -------------------------------------------------------------------------------- /src/common/filler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the burnt-in subtitle extractor. 3 | * Copyright (C) 2018 Benedikt Freisen 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "filler.hpp" 21 | 22 | filler::filler(int w, int h, uint8_t* img, uint8_t* mask) 23 | { 24 | int i; 25 | width[0] = w; 26 | height[0] = h; 27 | data[0] = img; 28 | alpha[0] = mask; 29 | //data_blurred[0] = new uint8_t[width[0] * height[0]]; 30 | //alpha_blurred[0] = new uint8_t[width[0] * height[0]]; 31 | for (i = 1; i < 32; i++) 32 | { 33 | width[i] = (width[i - 1] + 1) / 2; 34 | height[i] = (height[i - 1] + 1) / 2; 35 | data[i] = new uint8_t[width[i] * height[i]]; 36 | alpha[i] = new uint8_t[width[i] * height[i]]; 37 | //data_blurred[i] = new uint8_t[width[i] * height[i]]; 38 | //alpha_blurred[i] = new uint8_t[width[i] * height[i]]; 39 | } 40 | } 41 | 42 | filler::~filler() 43 | { 44 | //delete [] data_blurred[0]; 45 | //delete [] alpha_blurred[0]; 46 | int i; 47 | for (i = 1; i < 32; i++) 48 | { 49 | delete [] data[i]; 50 | delete [] alpha[i]; 51 | //delete [] data_blurred[i]; 52 | //delete [] alpha_blurred[i]; 53 | } 54 | } 55 | 56 | void filler::set_data0(uint8_t* data0) 57 | { 58 | data[0] = data0; 59 | } 60 | 61 | 62 | int min(int a, int b) 63 | { 64 | return (a < b) ? a : b; 65 | } 66 | 67 | int bounds(int a, int b, int c) 68 | { 69 | if (a < b) 70 | return b; 71 | if (a > c) 72 | return c; 73 | return a; 74 | } 75 | 76 | int index(int x, int y, int width, int height) 77 | { 78 | return width * bounds(y, 0, height - 1) + bounds(x, 0, width - 1); 79 | } 80 | 81 | /*void filler::blur(int n) 82 | { 83 | int x, y; 84 | for (y = 0; y < height[n]; y++) 85 | { 86 | for (x = 0; x < width[n]; x++) 87 | { 88 | int alphasumme = 89 | alpha[n][index(x - 1, y - 1, width[n], height[n])] + 90 | alpha[n][index(x, y - 1, width[n], height[n])] + 91 | alpha[n][index(x + 1, y - 1, width[n], height[n])] + 92 | alpha[n][index(x - 1, y, width[n], height[n])] + 93 | alpha[n][index(x, y, width[n], height[n])] + 94 | alpha[n][index(x + 1, y, width[n], height[n])] + 95 | alpha[n][index(x - 1, y + 1, width[n], height[n])] + 96 | alpha[n][index(x, y + 1, width[n], height[n])] + 97 | alpha[n][index(x + 1, y + 1, width[n], height[n])]; 98 | if (alphasumme == 0) 99 | { 100 | alpha_blurred[n][index(x, y, width[n], height[n])] = 0; 101 | data_blurred[n][index(x, y, width[n], height[n])] = 0; 102 | } 103 | else 104 | { 105 | int summe = 106 | data[n][index(x - 1, y - 1, width[n], height[n])] * alpha[n][index(x - 1, y - 1, width[n], height[n])] + 107 | data[n][index(x, y - 1, width[n], height[n])] * alpha[n][index(x, y - 1, width[n], height[n])] + 108 | data[n][index(x + 1, y - 1, width[n], height[n])] * alpha[n][index(x + 1, y - 1, width[n], height[n])] + 109 | data[n][index(x - 1, y, width[n], height[n])] * alpha[n][index(x - 1, y, width[n], height[n])] + 110 | data[n][index(x, y, width[n], height[n])] * alpha[n][index(x, y, width[n], height[n])] + 111 | data[n][index(x + 1, y, width[n], height[n])] * alpha[n][index(x + 1, y, width[n], height[n])] + 112 | data[n][index(x - 1, y + 1, width[n], height[n])] * alpha[n][index(x - 1, y + 1, width[n], height[n])] + 113 | data[n][index(x, y + 1, width[n], height[n])] * alpha[n][index(x, y + 1, width[n], height[n])] + 114 | data[n][index(x + 1, y + 1, width[n], height[n])] * alpha[n][index(x + 1, y + 1, width[n], height[n])]; 115 | alpha_blurred[n][index(x, y, width[n], height[n])] = min(255, alphasumme / 9); 116 | data_blurred[n][index(x, y, width[n], height[n])] = summe / alphasumme; 117 | } 118 | } 119 | } 120 | }*/ 121 | 122 | 123 | void filler::shrink(int n) 124 | { 125 | int x, y; 126 | for (y = 0; y < height[n + 1]; y++) 127 | { 128 | for (x = 0; x < width[n + 1]; x++) 129 | { 130 | int summe = 131 | data[n][index(x * 2, y * 2, width[n], height[n])] * alpha[n][index(x * 2, y * 2, width[n], height[n])] + 132 | data[n][index(x * 2 + 1, y * 2, width[n], height[n])] * alpha[n][index(x * 2 + 1, y * 2, width[n], height[n])] + 133 | data[n][index(x * 2, y * 2 + 1, width[n], height[n])] * alpha[n][index(x * 2, y * 2 + 1, width[n], height[n])] + 134 | data[n][index(x * 2 + 1, y * 2 + 1, width[n], height[n])] * alpha[n][index(x * 2 + 1, y * 2 + 1, width[n], height[n])]; 135 | int alphasumme = 136 | alpha[n][index(x * 2, y * 2, width[n], height[n])] + 137 | alpha[n][index(x * 2 + 1, y * 2, width[n], height[n])] + 138 | alpha[n][index(x * 2, y * 2 + 1, width[n], height[n])] + 139 | alpha[n][index(x * 2 + 1, y * 2 + 1, width[n], height[n])]; 140 | alpha[n + 1][y * width[n + 1] + x] = min(255, alphasumme / 2); /* Alpha value * 2 */ 141 | data[n + 1][y * width[n + 1] + x] = (alphasumme == 0) ? 0 : (summe / alphasumme); 142 | } 143 | } 144 | } 145 | 146 | uint8_t alphablend(uint8_t a, uint8_t b, uint8_t alpha) 147 | { 148 | return (a * alpha + b * (255 - alpha)) / 255; 149 | } 150 | 151 | uint8_t subpix(uint8_t* data, int x, int y, int width, int height) 152 | { 153 | if (y % 2 == 0) 154 | { 155 | if (x % 2 == 0) 156 | return ( 157 | (int)data[index(x / 2, y / 2, width, height)] * 9 + 158 | (int)data[index(x / 2 - 1, y / 2, width, height)] * 3 + 159 | (int)data[index(x / 2, y / 2 - 1, width, height)] * 3 + 160 | (int)data[index(x / 2 - 1, y / 2 - 1, width, height)] * 1 161 | ) / 16; 162 | else 163 | return ( 164 | (int)data[index(x / 2, y / 2, width, height)] * 9 + 165 | (int)data[index(x / 2 + 1, y / 2, width, height)] * 3 + 166 | (int)data[index(x / 2, y / 2 - 1, width, height)] * 3 + 167 | (int)data[index(x / 2 + 1, y / 2 - 1, width, height)] * 1 168 | ) / 16; 169 | } 170 | else 171 | { 172 | if (x % 2 == 0) 173 | return ( 174 | (int)data[index(x / 2, y / 2, width, height)] * 9 + 175 | (int)data[index(x / 2 - 1, y / 2, width, height)] * 3 + 176 | (int)data[index(x / 2, y / 2 + 1, width, height)] * 3 + 177 | (int)data[index(x / 2 - 1, y / 2 + 1, width, height)] * 1 178 | ) / 16; 179 | else 180 | return ( 181 | (int)data[index(x / 2, y / 2, width, height)] * 9 + 182 | (int)data[index(x / 2 + 1, y / 2, width, height)] * 3 + 183 | (int)data[index(x / 2, y / 2 + 1, width, height)] * 3 + 184 | (int)data[index(x / 2 + 1, y / 2 + 1, width, height)] * 1 185 | ) / 16; 186 | } 187 | } 188 | 189 | void filler::restore(int n) 190 | { 191 | int x, y; 192 | for (y = 0; y < height[n]; y++) 193 | { 194 | for (x = 0; x < width[n]; x++) 195 | { 196 | data[n][y * width[n] + x] = alphablend(data[n][y * width[n] + x], subpix(data[n + 1], x, y, width[n + 1], height[n + 1]), alpha[n][y * width[n] + x]); 197 | if (n) 198 | alpha[n][y * width[n] + x] = alphablend(alpha[n][y * width[n] + x], 255, subpix(alpha[n + 1], x, y, width[n + 1], height[n + 1])); 199 | } 200 | } 201 | } 202 | 203 | void filler::fill() 204 | { 205 | int i; 206 | for (i = 0; i < 31; i++) 207 | { 208 | //blur(i); 209 | shrink(i); 210 | } 211 | alpha[31][0] = 255; 212 | for (i = 30; i >= 0; i--) 213 | { 214 | restore(i); 215 | } 216 | } 217 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | --------------------------------------------------------------------------------