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 VIPS_BUFFER_H
31 #define VIPS_BUFFER_H
32 
33 #include <string.h>
34 #include <string>
35 
36 #include "../base/operation.hh"
37 
38 namespace PF
39 {
40 
41   class BufferPar: public OpParBase
42   {
43   public:
BufferPar()44     BufferPar(): OpParBase()
45     {
46       set_type( "buffer" );
47     }
48 
has_intensity()49     bool has_intensity() { return false; }
50     //bool has_opacity() { return false; }
51 
is_noop(VipsImage * full_res,unsigned int id,unsigned int level)52     bool is_noop( VipsImage* full_res, unsigned int id, unsigned int level ) { return true; }
53 
54     VipsImage* build(std::vector<VipsImage*>& in, int first,
55 		     VipsImage* imap, VipsImage* omap,
56 		     unsigned int& level);
57   };
58 
59 
60   template < OP_TEMPLATE_DEF >
61   class BufferProc
62   {
63   public:
render(VipsRegion ** ireg,int n,int in_first,VipsRegion * imap,VipsRegion * omap,VipsRegion * oreg,OpParBase * par)64     void render(VipsRegion** ireg, int n, int in_first,
65         VipsRegion* imap, VipsRegion* omap,
66         VipsRegion* oreg, OpParBase* par)
67     {
68       VipsRect *r = &oreg->valid;
69       int width = r->width;
70       int height = r->height;
71       int line_size = sizeof(T) * width * oreg->im->Bands; //layer->in_all[0]->Bands;
72       T* p;
73       T* pout;
74       int y;
75 
76       std::cout<<"BufferProc::render(): region: "<<r->width<<","<<r->height<<"+"<<r->left<<"+"<<r->top<<std::endl;
77 
78       for( y = 0; y < height; y++ ) {
79         p = (T*)VIPS_REGION_ADDR( ireg[0], r->left, r->top + y );
80         pout = (T*)VIPS_REGION_ADDR( oreg, r->left, r->top + y );
81         memcpy( pout, p, line_size );
82       }
83     }
84   };
85 
86 
87   ProcessorBase* new_buffer();
88 }
89 
90 
91 #endif
92