1 /*
2 */
3
4 /*
5
6 Copyright (C) 2014 Ferrero Andrea
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20
21
22 */
23
24 /*
25
26 These files are distributed with PhotoFlow - http://aferrero2707.github.io/PhotoFlow/
27
28 */
29
30 #include "../base/processor.hh"
31 #include "uniform.hh"
32
UniformPar()33 PF::UniformPar::UniformPar():
34 PixelProcessorPar(),
35 grey( "grey", this, 0 ),
36 R( "R", this, 0 ),
37 G( "G", this, 0 ),
38 B( "B", this, 0 ),
39 L( "L", this, 0 ),
40 a( "a", this, 0 ),
41 b( "b", this, 0 ),
42 C( "C", this, 0 ),
43 M( "M", this, 0 ),
44 Y( "Y", this, 0 ),
45 K( "K", this, 0 )
46 {
47 set_type( "uniform" );
48
49 set_default_name( _("uniform fill") );
50 }
51
52
53
build(std::vector<VipsImage * > & in,int first,VipsImage * imap,VipsImage * omap,unsigned int & level)54 VipsImage* PF::UniformPar::build(std::vector<VipsImage*>& in, int first,
55 VipsImage* imap, VipsImage* omap,
56 unsigned int& level)
57 {
58 #ifndef NDEBUG
59 std::cout<<"UniformPar::build(): colorspace="<<get_colorspace()<<std::endl;
60 #endif
61 grey.set( R.get() );
62
63 if( get_colorspace() == PF::PF_COLORSPACE_RGB ) {
64 Rconv = R.get();
65 Gconv = G.get();
66 Bconv = B.get();
67
68 void *data;
69 size_t data_length;
70 if( !PF_VIPS_IMAGE_GET_BLOB( in[0], VIPS_META_ICC_NAME, &data, &data_length ) ) {
71 cmsHPROFILE wprofile = cmsOpenProfileFromMem( data, data_length );
72 if( wprofile ) {
73 cmsHTRANSFORM transform = cmsCreateTransform( PF::ICCStore::Instance().get_srgb_profile(PF::PF_TRC_STANDARD),
74 TYPE_RGB_FLT, wprofile, TYPE_RGB_FLT,
75 INTENT_PERCEPTUAL, cmsFLAGS_NOCACHE );
76 if( transform ) {
77 float rgb_in[3], rgb_out[3];
78 rgb_in[0] = R.get(); rgb_in[1] = G.get(); rgb_in[2] = B.get();
79 cmsDoTransform( transform, rgb_in, rgb_out, 1 );
80 cmsDeleteTransform( transform );
81
82 Rconv = rgb_out[0];
83 Bconv = rgb_out[1];
84 Bconv = rgb_out[2];
85 }
86 cmsCloseProfile( wprofile );
87 }
88 }
89 }
90
91 return PF::OpParBase::build( in, first, imap, omap, level );
92 }
93