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 #ifndef PF_IMAGE_TO_MAP_H 31 #define PF_IMAGE_TO_MAP_H 32 33 namespace PF 34 { 35 class ImageToMapPar: public OpParBase 36 { 37 ICCProfile* profile; 38 ProcessorBase* proc_average; 39 ProcessorBase* convert2lab; 40 ProcessorBase* convert_cs; 41 42 public: 43 ImageToMapPar(); 44 has_intensity()45 bool has_intensity() { return false; } get_profile()46 ICCProfile* get_profile() { return profile; } 47 48 VipsImage* build(std::vector<VipsImage*>& in, int first, 49 VipsImage* imap, VipsImage* omap, 50 unsigned int& level); 51 }; 52 53 54 template < OP_TEMPLATE_DEF > 55 class ImageToMapProc 56 { 57 public: render(VipsRegion ** ireg,int n,int in_first,VipsRegion * imap,VipsRegion * omap,VipsRegion * oreg,ImageToMapPar * par)58 void render(VipsRegion** ireg, int n, int in_first, 59 VipsRegion* imap, VipsRegion* omap, 60 VipsRegion* oreg, ImageToMapPar* par) 61 { 62 std::cout<<"ImageToMapProc::render(): unsupported colorspace "<<CS<<std::endl; 63 } 64 }; 65 66 67 template < class BLENDER, int CHMIN, int CHMAX, bool has_imap, bool has_omap, bool PREVIEW > 68 class ImageToMapProc< float, BLENDER, PF_COLORSPACE_GRAYSCALE, CHMIN, CHMAX, has_imap, has_omap, PREVIEW > 69 { 70 public: render(VipsRegion ** ireg,int n,int in_first,VipsRegion * imap,VipsRegion * omap,VipsRegion * oreg,ImageToMapPar * par)71 void render(VipsRegion** ireg, int n, int in_first, 72 VipsRegion* imap, VipsRegion* omap, 73 VipsRegion* oreg, ImageToMapPar* par) 74 { 75 ICCProfile* profile = par->get_profile(); 76 if( !profile ) return; 77 78 VipsRect *r = &oreg->valid; 79 //int x, y, xomap, y0, dx1=CHMIN, dx2=PF::ColorspaceInfo<colorspace>::NCH-CHMIN, ch, CHMAXplus1=CHMAX+1; 80 int x, xin, y, y0; 81 int width = r->width; 82 int line_size = width * oreg->im->Bands; 83 float* pin; 84 float* pin2; 85 float* pout; 86 float* line = NULL; 87 float val; 88 //if( profile->get_trc_type()!=PF_TRC_LINEAR ) line = new float[line_size]; 89 if( true && r->left==0 && r->top==0 ) { 90 std::cout<<"ImageToMapProc::render(): profile="<<profile<<std::endl; 91 //std::cout<<"ImageToMapProc::render(): profile->has_colorants="<<profile->has_colorants<<std::endl; 92 std::cout<<"ImageToMapProc::render(): colorspace="<<convert_colorspace(ireg[in_first]->im->Type)<<std::endl; 93 } 94 for( y = 0; y < r->height; y++ ) { 95 y0 = r->top + y; 96 pin = (float*)VIPS_REGION_ADDR( ireg[in_first], r->left, y0 ); 97 pout = (float*)VIPS_REGION_ADDR( oreg, r->left, y0 ); 98 if(convert_colorspace(ireg[in_first]->im->Type) == PF_COLORSPACE_RGB) { 99 for( x = 0; x < line_size; x++ ) { 100 val = profile->get_lightness( pin[0], pin[1], pin[2] ); 101 if( profile->is_linear() ) 102 val = profile->linear2perceptual( val ); 103 *pout = val; 104 pout += 1; pin += 3; 105 } 106 } else if(convert_colorspace(ireg[in_first]->im->Type) == PF_COLORSPACE_LAB) { 107 for( x = 0; x < line_size; x++ ) { 108 *pout = pin[0]; 109 pout += 1; pin += 3; 110 } 111 } 112 } 113 //if( line ) delete line; 114 } 115 }; 116 117 118 ProcessorBase* new_image_to_map(); 119 } 120 121 #endif 122 123 124