1 /**************************************************************************/
2 /* Copyright 2012 Tim Day */
3 /* */
4 /* This file is part of Evolvotron */
5 /* */
6 /* Evolvotron is free software: you can redistribute it and/or modify */
7 /* it under the terms of the GNU General Public License as published by */
8 /* the Free Software Foundation, either version 3 of the License, or */
9 /* (at your option) any later version. */
10 /* */
11 /* Evolvotron is distributed in the hope that it will be useful, */
12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
14 /* GNU General Public License for more details. */
15 /* */
16 /* You should have received a copy of the GNU General Public License */
17 /* along with Evolvotron. If not, see <http://www.gnu.org/licenses/>. */
18 /**************************************************************************/
19
20 /*! \file
21 \brief Implementation of class MutatableImageComputerTask
22 */
23
24
25
26 #include "mutatable_image_computer_task.h"
27
MutatableImageComputerTask(MutatableImageDisplay * const disp,const boost::shared_ptr<const MutatableImage> & fn,uint pri,const QSize & fo,const QSize & fs,const QSize & wis,uint f,uint lev,uint frag,uint nfrag,bool j,uint ms,unsigned long long int n)28 MutatableImageComputerTask::MutatableImageComputerTask
29 (
30 MutatableImageDisplay*const disp,
31 const boost::shared_ptr<const MutatableImage>& fn,
32 uint pri,
33 const QSize& fo,
34 const QSize& fs,
35 const QSize& wis,
36 uint f,
37 uint lev,
38 uint frag,
39 uint nfrag,
40 bool j,
41 uint ms,
42 unsigned long long int n
43 )
44 :_aborted(false)
45 ,_display(disp)
46 ,_image_function(fn)
47 ,_priority(pri)
48 ,_fragment_origin(fo)
49 ,_fragment_size(fs)
50 ,_whole_image_size(wis)
51 ,_frames(f)
52 ,_level(lev)
53 ,_fragment(frag)
54 ,_number_of_fragments(nfrag)
55 ,_jittered_samples(j)
56 ,_multisample_grid(ms)
57 ,_current_pixel(0)
58 ,_current_col(0)
59 ,_current_row(0)
60 ,_current_frame(0)
61 ,_completed(false)
62 ,_serial(n)
63 {
64 /*
65 std::cerr
66 << "["
67 << _number_of_fragments
68 << ":"
69 << _fragment_size.width() << "x" << _fragment_size.height()
70 << " in "
71 << _whole_image_size.width() << "x" << _whole_image_size.height()
72 << "]";
73 */
74 assert(_image_function->ok());
75 assert(_fragment<_number_of_fragments);
76 assert(_number_of_fragments>1 || _whole_image_size==_fragment_size);
77 assert(1<=_multisample_grid);
78 }
79
allocate_images() const80 void MutatableImageComputerTask::allocate_images() const
81 {
82 for (uint f=0;f<frames();f++)
83 {
84 _images.push_back(QImage(fragment_size(),QImage::Format_RGB32));
85 }
86 }
87
~MutatableImageComputerTask()88 MutatableImageComputerTask::~MutatableImageComputerTask()
89 {
90 assert(_image_function->ok());
91 }
92
pixel_advance()93 void MutatableImageComputerTask::pixel_advance()
94 {
95 _current_pixel++;
96 _current_col++;
97 if (_current_col==fragment_size().width())
98 {
99 _current_col=0;
100 _current_row++;
101 if (_current_row==fragment_size().height())
102 {
103 _current_row=0;
104 _current_frame++;
105 if (_current_frame==frames())
106 {
107 _completed=true;
108 }
109 }
110 }
111 }
112