1 // ---------------------------------------------------------------------------- 2 // picture.h 3 // 4 // Copyright (C) 2006-2008 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 picture_H 26 #define picture_H 27 28 #include <FL/Fl_Widget.H> 29 #include <FL/Fl_Box.H> 30 #include <FL/Fl_Image.H> 31 32 class picture : 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 54 void (*cbFunc)(Fl_Widget *, void *); 55 56 public: 57 picture(int, int, int, int, int bg_col = 0); 58 ~picture(); 59 void video(unsigned char const *, int); pixel(unsigned char data,int pos)60 void pixel(unsigned char data, int pos) { 61 if (pos < 0 || pos >= bufsize) { 62 return ; 63 } 64 vidbuf[pos] = data; 65 if (pos % (width * depth) == 0) 66 redraw(); 67 } 68 unsigned char pixel(int); 69 int handle(int); 70 void draw(); 71 void clear(); image(Fl_Image * img)72 void image(Fl_Image *img) {Fl_Widget::image(img);} 73 void resize(int, int, int, int); 74 void resize_height(int new_height, bool clear_img); 75 void shift_horizontal_center(int hShift); 76 void stretch(double the_ratio); 77 int save_png(const char * filename, bool monochrome = false, const char * extra_comments = NULL); 78 void set_zoom(int the_zoom); set_binary(bool bin_mode)79 void set_binary(bool bin_mode) { binary = bin_mode ;} pix_width(void)80 int pix_width(void) const { 81 return width ; 82 } pix_height(void)83 int pix_height(void) const { 84 return height ; 85 } buffer(void)86 const unsigned char * buffer(void) const { 87 return vidbuf; 88 } 89 /// Sometimes the row number goes back of one due to rounding error. 90 /// If this happens, noise removal does not work. 91 static const int noise_height_margin = 5 ; 92 void remove_noise( int row, int half_len, int noise_margin ); 93 static const int depth = 3; 94 callback(void (* cbf)(Fl_Widget *,void *))95 void callback (void (*cbf)(Fl_Widget *, void *) ){ cbFunc = cbf;} do_callback()96 void do_callback() { 97 if (cbFunc) cbFunc(this, (void*)0); 98 } 99 100 private: 101 bool restore( int row, int margin ); 102 bool slantcorr; 103 public: 104 void dilatation( int row ); 105 void erosion( int row ); set_binary_threshold(unsigned char thres)106 void set_binary_threshold(unsigned char thres) { 107 binary_threshold = thres ; 108 } get_binary_threshold()109 unsigned char get_binary_threshold() const { 110 return binary_threshold ; 111 } 112 void slant(int dir); 113 void rotate(); 114 void shift_center(int dir); noslant()115 void noslant() {slantcorr = false;} 116 }; 117 118 class picbox : public Fl_Box 119 { 120 public: 121 picbox(int x, int y, int w, int h, const char* l = 0) Fl_Box(x,y,w,h,l)122 : Fl_Box(x, y, w, h, l) { } 123 int handle(int event); 124 }; 125 126 #endif 127