1 // ---------------------------------------------------------------------------- 2 // wefax_map.h 3 // 4 // Copyright (C) 2006-2017 5 // Dave Freese, W1HKJ 6 // Copyright (C) 2008 7 // Stelios Bounanos, M0GLD 8 // 9 // This file is part of fldigi. 10 // 11 // Fldigi is free software: you can redistribute it and/or modify 12 // it under the terms of the GNU General Public License as published by 13 // the Free Software Foundation, either version 3 of the License, or 14 // (at your option) any later version. 15 // 16 // Fldigi is distributed in the hope that it will be useful, 17 // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 // GNU General Public License for more details. 20 // 21 // You should have received a copy of the GNU General Public License 22 // along with fldigi. If not, see <http://www.gnu.org/licenses/>. 23 // ---------------------------------------------------------------------------- 24 25 #ifndef wefax_map_H 26 #define wefax_map_H 27 28 #include <FL/Fl_Widget.H> 29 #include <FL/Fl_Box.H> 30 #include <FL/Fl_Image.H> 31 32 class wefax_map : public Fl_Widget { 33 private: 34 unsigned char *vidbuf; 35 int bufsize; 36 int width; 37 int height; 38 int numcol; 39 int slantdir; 40 void slant_corr(int x, int y); 41 void slant_undo(); 42 int zoom ; 43 int background ; 44 bool binary ; 45 unsigned char binary_threshold ; 46 pix2bin(unsigned char x)47 inline unsigned char pix2bin( unsigned char x ) const { 48 return x < binary_threshold ? 0 : 255 ; 49 } 50 51 static void draw_cb(void *data, int x, int y, int w, uchar *buf); 52 void resize_zoom(int, int, int, int); 53 public: 54 wefax_map(int, int, int, int, int bg_col = 0); 55 ~wefax_map(); 56 void video(unsigned char const *, int); pixel(unsigned char data,int pos)57 void pixel(unsigned char data, int pos) { 58 if (pos < 0 || pos >= bufsize) { 59 return ; 60 } 61 vidbuf[pos] = data; 62 if (pos % (width * depth) == 0) 63 redraw(); 64 } 65 unsigned char pixel(int); 66 int handle(int); 67 void draw(); 68 void clear(); image(Fl_Image * img)69 void image(Fl_Image *img) {Fl_Widget::image(img);} 70 void resize(int, int, int, int); 71 void resize_height(int new_height, bool clear_img); 72 void shift_horizontal_center(int hShift); 73 void stretch(double the_ratio); 74 int save_png(const char * filename, const char * extra_comments = NULL); 75 void set_zoom(int the_zoom); set_binary(bool bin_mode)76 void set_binary(bool bin_mode) { binary = bin_mode ;} pix_width(void)77 int pix_width(void) const { 78 return width ; 79 } pix_height(void)80 int pix_height(void) const { 81 return height ; 82 } buffer(void)83 const unsigned char * buffer(void) const { 84 return vidbuf; 85 } 86 /// Sometimes the row number goes back of one due to rounding error. 87 /// If this happens, noise removal does not work. 88 static const int noise_height_margin = 5 ; 89 void remove_noise( int row, int half_len, int noise_margin ); 90 static const int depth = 3; 91 92 private: 93 bool restore( int row, int margin ); 94 public: 95 void erosion( int row ); set_binary_threshold(unsigned char thres)96 void set_binary_threshold(unsigned char thres) { 97 binary_threshold = thres ; 98 } get_binary_threshold()99 unsigned char get_binary_threshold() const { 100 return binary_threshold ; 101 } 102 }; 103 104 class wefax_picbox : public Fl_Box 105 { 106 public: 107 wefax_picbox(int x, int y, int w, int h, const char* l = 0) Fl_Box(x,y,w,h,l)108 : Fl_Box(x, y, w, h, l) { } 109 int handle(int event); 110 }; 111 112 #endif 113