1 /* This code is directly derived from the gtkdisp2.cc program included in the 2 * VIPS distribution; credits go therefore to the VIPS authors. 3 * 4 * 8-bit RGB images only, though it would be easy to fix this. 5 * 6 */ 7 8 /* 9 10 Copyright (C) 2014 Ferrero Andrea 11 12 This program is free software: you can redistribute it and/or modify 13 it under the terms of the GNU General Public License as published by 14 the Free Software Foundation, either version 3 of the License, or 15 (at your option) any later version. 16 17 This program is distributed in the hope that it will be useful, 18 but WITHOUT ANY WARRANTY; without even the implied warranty of 19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 GNU General Public License for more details. 21 22 You should have received a copy of the GNU General Public License 23 along with this program. If not, see <http://www.gnu.org/licenses/>. 24 25 26 */ 27 28 /* 29 30 These files are distributed with PhotoFlow - http://aferrero2707.github.io/PhotoFlow/ 31 32 */ 33 34 #ifndef PF_COLOR_SAMPLER_HH 35 #define PF_COLOR_SAMPLER_HH 36 37 #include <stdio.h> 38 #include <iostream> 39 40 #include <queue> 41 42 #include <gtkmm.h> 43 44 //#include <vips/vips> 45 46 #include "../base/photoflow.hh" 47 #include "../base/pipeline.hh" 48 #include "../base/image.hh" 49 50 #include "doublebuffer.hh" 51 52 53 54 namespace PF 55 { 56 57 class Sampler : public PipelineSink, public Gtk::Frame 58 { 59 60 /* The derived image we paint to the screen. 61 */ 62 VipsImage* display_image; 63 VipsImage* outimg; 64 65 int sampler_x, sampler_y, sampler_size; 66 67 bool display_merged; 68 int active_layer; 69 int edited_layer; 70 71 Gtk::HBox hbox; 72 Gtk::Label label_value1; 73 Gtk::Label label_value2; 74 Gtk::Label label_value3; 75 Gtk::Label label_value4; 76 Gtk::VBox labels_box; 77 Gtk::Label LCH_label_value1; 78 Gtk::Label LCH_label_value2; 79 Gtk::Label LCH_label_value3; 80 Gtk::VBox LCH_labels_box; 81 82 Gtk::CheckButton check; 83 bool enabled; 84 bool grabbed; 85 int id; 86 87 ICCTransform transform; 88 89 public: 90 91 /* We send this packet of data from the bg worker thread to the main GUI 92 * thread when a tile has been calculated. 93 */ 94 typedef struct { 95 Sampler * sampler; 96 float val[4]; 97 float lch[3]; 98 VipsInterpretation type; 99 } Update; 100 101 static gboolean queue_draw_cb (Update * update); 102 103 Sampler( Pipeline* v, Glib::ustring title, int id ); 104 virtual ~Sampler(); 105 get_display_image()106 VipsImage* get_display_image() { return display_image; } 107 108 void set_values(float val[4], float lch[3], VipsInterpretation type); 109 110 void update( VipsRect* area ); 111 112 void enable_changed(); 113 114 //void sink( const VipsRect& area ); 115 set_sticky_layer(int id)116 void set_sticky_layer( int id ) { 117 int old_id = active_layer; 118 active_layer = id; 119 std::cout<<"Sampler::set_sticky_layer(): id="<<id<<" old_id="<<old_id<<" display_merged="<<display_merged<<std::endl; 120 if( !display_merged && (old_id != active_layer) ) { 121 //update( NULL ); 122 if( get_pipeline() && get_pipeline()->get_image() ) { 123 //std::cout<<"Sampler::set_sticky_layer(): get_pipeline()->get_image()->update() called."<<std::endl; 124 get_pipeline()->set_output_layer_id( active_layer ); 125 //get_pipeline()->get_image()->update(); 126 } 127 } 128 } get_active_layer()129 int get_active_layer() { return active_layer; } 130 set_display_merged(bool val)131 void set_display_merged( bool val ) 132 { 133 bool old_val = display_merged; 134 display_merged = val; 135 std::cout<<"Sampler::set_displayed_merged(): val="<<val<<" old_val="<<old_val<<std::endl; 136 if( display_merged ) 137 get_pipeline()->set_output_layer_id( -1 ); 138 if( display_merged != old_val ) { 139 //update( NULL ); 140 if( get_pipeline() && get_pipeline()->get_image() ) { 141 //std::cout<<"Sampler::set_displayed_merged(): get_pipeline()->get_image()->update() called."<<std::endl; 142 //get_pipeline()->get_image()->update(); 143 } 144 } 145 } get_display_merged()146 bool get_display_merged() { return display_merged; } 147 148 149 150 virtual bool pointer_press_event( int button, double x, double y, double D, int mod_key ); 151 virtual bool pointer_release_event( int button, double x, double y, int mod_key ); 152 virtual bool pointer_motion_event( int button, double x, double y, int mod_key ); 153 154 virtual bool modify_preview( PixelBuffer& buf_out, float scale, int xoffset, int yoffset ); 155 156 157 }; 158 159 160 class SamplerGroup: public Gtk::Frame//ScrolledWindow 161 { 162 Gtk::HBox row1, row2, row3, row4; 163 Gtk::VBox box; 164 Sampler s1, s2, s3, s4, s5, s6, s7, s8; 165 166 public: 167 SamplerGroup( Pipeline* v ); 168 get_sampler_num()169 int get_sampler_num() { return 8; } 170 Sampler& get_sampler(int i); 171 }; 172 173 } 174 175 #endif 176