-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathimage_8cpp-source.html
254 lines (254 loc) · 38 KB
/
image_8cpp-source.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>pbrt: image.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main Page</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li class="current"><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<h1>image.cpp</h1><a href="image_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001
<a name="l00002"></a>00002 <span class="comment">/*</span>
<a name="l00003"></a>00003 <span class="comment"> pbrt source code Copyright(c) 1998-2007 Matt Pharr and Greg Humphreys.</span>
<a name="l00004"></a>00004 <span class="comment"></span>
<a name="l00005"></a>00005 <span class="comment"> This file is part of pbrt.</span>
<a name="l00006"></a>00006 <span class="comment"></span>
<a name="l00007"></a>00007 <span class="comment"> pbrt is free software; you can redistribute it and/or modify</span>
<a name="l00008"></a>00008 <span class="comment"> it under the terms of the GNU General Public License as published by</span>
<a name="l00009"></a>00009 <span class="comment"> the Free Software Foundation; either version 2 of the License, or</span>
<a name="l00010"></a>00010 <span class="comment"> (at your option) any later version. Note that the text contents of</span>
<a name="l00011"></a>00011 <span class="comment"> the book "Physically Based Rendering" are *not* licensed under the</span>
<a name="l00012"></a>00012 <span class="comment"> GNU GPL.</span>
<a name="l00013"></a>00013 <span class="comment"></span>
<a name="l00014"></a>00014 <span class="comment"> pbrt is distributed in the hope that it will be useful,</span>
<a name="l00015"></a>00015 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00016"></a>00016 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<a name="l00017"></a>00017 <span class="comment"> GNU General Public License for more details.</span>
<a name="l00018"></a>00018 <span class="comment"></span>
<a name="l00019"></a>00019 <span class="comment"> You should have received a copy of the GNU General Public License</span>
<a name="l00020"></a>00020 <span class="comment"> along with this program. If not, see <http://www.gnu.org/licenses/>.</span>
<a name="l00021"></a>00021 <span class="comment"></span>
<a name="l00022"></a>00022 <span class="comment"> */</span>
<a name="l00023"></a>00023
<a name="l00024"></a>00024 <span class="comment">// image.cpp*</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include "<a class="code" href="pbrt_8h.html">pbrt.h</a>"</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include "<a class="code" href="film_8h.html">film.h</a>"</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include "<a class="code" href="color_8h.html">color.h</a>"</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include "<a class="code" href="paramset_8h.html">paramset.h</a>"</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include "<a class="code" href="tonemap_8h.html">tonemap.h</a>"</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include "<a class="code" href="sampling_8h.html">sampling.h</a>"</span>
<a name="l00031"></a>00031 <span class="comment">// ImageFilm Declarations</span>
<a name="l00032"></a><a class="code" href="classImageFilm.html">00032</a> <span class="keyword">class </span><a class="code" href="classImageFilm.html">ImageFilm</a> : <span class="keyword">public</span> <a class="code" href="classFilm.html">Film</a> {
<a name="l00033"></a>00033 <span class="keyword">public</span>:
<a name="l00034"></a>00034 <span class="comment">// ImageFilm Public Methods</span>
<a name="l00035"></a>00035 <a class="code" href="classImageFilm.html#686df06d99c042780f381230f5191056">ImageFilm</a>(<span class="keywordtype">int</span> xres, <span class="keywordtype">int</span> yres,
<a name="l00036"></a>00036 <a class="code" href="classFilter.html">Filter</a> *filt, <span class="keyword">const</span> <span class="keywordtype">float</span> crop[4],
<a name="l00037"></a>00037 <span class="keyword">const</span> <span class="keywordtype">string</span> &<a class="code" href="classImageFilm.html#aaa61b7b3cb22b520fcb1c62f57584cc">filename</a>, <span class="keywordtype">bool</span> premult,
<a name="l00038"></a>00038 <span class="keywordtype">int</span> wf);
<a name="l00039"></a><a class="code" href="classImageFilm.html#9ef6090f68212631abe30aa78804c30a">00039</a> <a class="code" href="classImageFilm.html#9ef6090f68212631abe30aa78804c30a">~ImageFilm</a>() {
<a name="l00040"></a>00040 <span class="keyword">delete</span> <a class="code" href="classImageFilm.html#9eb261044726deff2aea076f9c973013">pixels</a>;
<a name="l00041"></a>00041 <span class="keyword">delete</span> <a class="code" href="classImageFilm.html#d91aad5afa6ef1f088cf5b474059b3af">filter</a>;
<a name="l00042"></a>00042 <span class="keyword">delete</span>[] <a class="code" href="classImageFilm.html#71819b70759ab933aa59b5a16f084381">filterTable</a>;
<a name="l00043"></a>00043 }
<a name="l00044"></a>00044 <span class="keywordtype">void</span> <a class="code" href="classImageFilm.html#e85b27fe21f6d3799d97a836f4a48703">AddSample</a>(<span class="keyword">const</span> <a class="code" href="structSample.html">Sample</a> &sample, <span class="keyword">const</span> <a class="code" href="classRay.html">Ray</a> &ray,
<a name="l00045"></a>00045 <span class="keyword">const</span> <a class="code" href="classSpectrum.html">Spectrum</a> &L, <span class="keywordtype">float</span> alpha);
<a name="l00046"></a>00046 <span class="keywordtype">void</span> <a class="code" href="classImageFilm.html#2adf1f50c18104f1de5161def2ff3658">GetSampleExtent</a>(<span class="keywordtype">int</span> *xstart, <span class="keywordtype">int</span> *xend,
<a name="l00047"></a>00047 <span class="keywordtype">int</span> *ystart, <span class="keywordtype">int</span> *yend) <span class="keyword">const</span>;
<a name="l00048"></a>00048 <span class="keywordtype">void</span> <a class="code" href="classImageFilm.html#fdd385a53cb205ef3fe6a75fefa7348e">WriteImage</a>();
<a name="l00049"></a>00049 <span class="keyword">private</span>:
<a name="l00050"></a>00050 <span class="comment">// ImageFilm Private Data</span>
<a name="l00051"></a><a class="code" href="classImageFilm.html#d91aad5afa6ef1f088cf5b474059b3af">00051</a> <a class="code" href="classFilter.html">Filter</a> *<a class="code" href="classImageFilm.html#d91aad5afa6ef1f088cf5b474059b3af">filter</a>;
<a name="l00052"></a><a class="code" href="classImageFilm.html#0be5e7b9be41b6f79c55b287206a8080">00052</a> <span class="keywordtype">int</span> <a class="code" href="classImageFilm.html#0be5e7b9be41b6f79c55b287206a8080">writeFrequency</a>, <a class="code" href="classImageFilm.html#03fc8ded049b3630e6ea55808aafb888">sampleCount</a>;
<a name="l00053"></a><a class="code" href="classImageFilm.html#aaa61b7b3cb22b520fcb1c62f57584cc">00053</a> <span class="keywordtype">string</span> filename;
<a name="l00054"></a><a class="code" href="classImageFilm.html#45c9e69dbd23f400f22b57ac1bee22d0">00054</a> <span class="keywordtype">bool</span> <a class="code" href="classImageFilm.html#45c9e69dbd23f400f22b57ac1bee22d0">premultiplyAlpha</a>;
<a name="l00055"></a><a class="code" href="classImageFilm.html#4ad2139383951904828e213f03daad62">00055</a> <span class="keywordtype">float</span> <a class="code" href="classImageFilm.html#4ad2139383951904828e213f03daad62">cropWindow</a>[4];
<a name="l00056"></a><a class="code" href="classImageFilm.html#f7e6476d3b84110c2d88fca7d7f68b22">00056</a> <span class="keywordtype">int</span> <a class="code" href="classImageFilm.html#c7a8ad086d28a1e31e05bb7596950f33">xPixelStart</a>, <a class="code" href="classImageFilm.html#f7e6476d3b84110c2d88fca7d7f68b22">yPixelStart</a>, <a class="code" href="classImageFilm.html#0517c240230acc2b75e6444e8c880efa">xPixelCount</a>, <a class="code" href="classImageFilm.html#337519591bdb4dfe063cdcf184bd3992">yPixelCount</a>;
<a name="l00057"></a><a class="code" href="structImageFilm_1_1Pixel.html">00057</a> <span class="keyword">struct </span><a class="code" href="structImageFilm_1_1Pixel.html">Pixel</a> {
<a name="l00058"></a><a class="code" href="structImageFilm_1_1Pixel.html#4f9072bdc373461e66db3d3a44496ce8">00058</a> <a class="code" href="structImageFilm_1_1Pixel.html#4f9072bdc373461e66db3d3a44496ce8">Pixel</a>() : <a class="code" href="structImageFilm_1_1Pixel.html#449b3440e94e9a446dec9068927697f6">L</a>(0.f) {
<a name="l00059"></a>00059 <a class="code" href="structImageFilm_1_1Pixel.html#b313ce7a5011f5e21d72c54d0309ba52">alpha</a> = 0.f;
<a name="l00060"></a>00060 <a class="code" href="structImageFilm_1_1Pixel.html#6fad989e28b1af3d7c326ed3cf0ebce1">weightSum</a> = 0.f;
<a name="l00061"></a>00061 }
<a name="l00062"></a><a class="code" href="structImageFilm_1_1Pixel.html#449b3440e94e9a446dec9068927697f6">00062</a> <a class="code" href="classSpectrum.html">Spectrum</a> <a class="code" href="structImageFilm_1_1Pixel.html#449b3440e94e9a446dec9068927697f6">L</a>;
<a name="l00063"></a><a class="code" href="structImageFilm_1_1Pixel.html#6fad989e28b1af3d7c326ed3cf0ebce1">00063</a> <span class="keywordtype">float</span> <a class="code" href="structImageFilm_1_1Pixel.html#b313ce7a5011f5e21d72c54d0309ba52">alpha</a>, <a class="code" href="structImageFilm_1_1Pixel.html#6fad989e28b1af3d7c326ed3cf0ebce1">weightSum</a>;
<a name="l00064"></a>00064 };
<a name="l00065"></a><a class="code" href="classImageFilm.html#9eb261044726deff2aea076f9c973013">00065</a> <a class="code" href="classBlockedArray.html">BlockedArray<Pixel></a> *<a class="code" href="classImageFilm.html#9eb261044726deff2aea076f9c973013">pixels</a>;
<a name="l00066"></a><a class="code" href="classImageFilm.html#71819b70759ab933aa59b5a16f084381">00066</a> <span class="keywordtype">float</span> *<a class="code" href="classImageFilm.html#71819b70759ab933aa59b5a16f084381">filterTable</a>;
<a name="l00067"></a>00067 };
<a name="l00068"></a>00068 <span class="comment">// ImageFilm Method Definitions</span>
<a name="l00069"></a><a class="code" href="classImageFilm.html#686df06d99c042780f381230f5191056">00069</a> <a class="code" href="classImageFilm.html#686df06d99c042780f381230f5191056">ImageFilm::ImageFilm</a>(<span class="keywordtype">int</span> xres, <span class="keywordtype">int</span> yres,
<a name="l00070"></a>00070 <a class="code" href="classFilter.html">Filter</a> *filt, <span class="keyword">const</span> <span class="keywordtype">float</span> crop[4],
<a name="l00071"></a>00071 <span class="keyword">const</span> <span class="keywordtype">string</span> &fn, <span class="keywordtype">bool</span> premult, <span class="keywordtype">int</span> wf)
<a name="l00072"></a>00072 : <a class="code" href="classFilm.html">Film</a>(xres, yres) {
<a name="l00073"></a>00073 <a class="code" href="classImageFilm.html#d91aad5afa6ef1f088cf5b474059b3af">filter</a> = filt;
<a name="l00074"></a>00074 <a class="code" href="pbrtparse_8y.html#2ac249754cc680184bc1b7825aacb876">memcpy</a>(<a class="code" href="classImageFilm.html#4ad2139383951904828e213f03daad62">cropWindow</a>, crop, 4 * <span class="keyword">sizeof</span>(<span class="keywordtype">float</span>));
<a name="l00075"></a>00075 <a class="code" href="classImageFilm.html#aaa61b7b3cb22b520fcb1c62f57584cc">filename</a> = fn;
<a name="l00076"></a>00076 <a class="code" href="classImageFilm.html#45c9e69dbd23f400f22b57ac1bee22d0">premultiplyAlpha</a> = premult;
<a name="l00077"></a>00077 <a class="code" href="classImageFilm.html#0be5e7b9be41b6f79c55b287206a8080">writeFrequency</a> = <a class="code" href="classImageFilm.html#03fc8ded049b3630e6ea55808aafb888">sampleCount</a> = wf;
<a name="l00078"></a>00078 <span class="comment">// Compute film image extent</span>
<a name="l00079"></a>00079 <a class="code" href="classImageFilm.html#c7a8ad086d28a1e31e05bb7596950f33">xPixelStart</a> = <a class="code" href="pbrt_8h.html#1a941973fe233e9e8179a48dff4115c8">Ceil2Int</a>(<a class="code" href="classFilm.html#2a6768612de9b5c940ce90edf74e51e4">xResolution</a> * <a class="code" href="classImageFilm.html#4ad2139383951904828e213f03daad62">cropWindow</a>[0]);
<a name="l00080"></a>00080 <a class="code" href="classImageFilm.html#0517c240230acc2b75e6444e8c880efa">xPixelCount</a> =
<a name="l00081"></a>00081 max(1, <a class="code" href="pbrt_8h.html#1a941973fe233e9e8179a48dff4115c8">Ceil2Int</a>(<a class="code" href="classFilm.html#2a6768612de9b5c940ce90edf74e51e4">xResolution</a> * cropWindow[1]) - <a class="code" href="classImageFilm.html#c7a8ad086d28a1e31e05bb7596950f33">xPixelStart</a>);
<a name="l00082"></a>00082 <a class="code" href="classImageFilm.html#f7e6476d3b84110c2d88fca7d7f68b22">yPixelStart</a> =
<a name="l00083"></a>00083 <a class="code" href="pbrt_8h.html#1a941973fe233e9e8179a48dff4115c8">Ceil2Int</a>(<a class="code" href="classFilm.html#063949abe489b632809617887e32a87c">yResolution</a> * cropWindow[2]);
<a name="l00084"></a>00084 <a class="code" href="classImageFilm.html#337519591bdb4dfe063cdcf184bd3992">yPixelCount</a> =
<a name="l00085"></a>00085 max(1, <a class="code" href="pbrt_8h.html#1a941973fe233e9e8179a48dff4115c8">Ceil2Int</a>(<a class="code" href="classFilm.html#063949abe489b632809617887e32a87c">yResolution</a> * cropWindow[3]) - <a class="code" href="classImageFilm.html#f7e6476d3b84110c2d88fca7d7f68b22">yPixelStart</a>);
<a name="l00086"></a>00086 <span class="comment">// Allocate film image storage</span>
<a name="l00087"></a>00087 <a class="code" href="classImageFilm.html#9eb261044726deff2aea076f9c973013">pixels</a> = <span class="keyword">new</span> <a class="code" href="classBlockedArray.html">BlockedArray<Pixel></a>(<a class="code" href="classImageFilm.html#0517c240230acc2b75e6444e8c880efa">xPixelCount</a>, <a class="code" href="classImageFilm.html#337519591bdb4dfe063cdcf184bd3992">yPixelCount</a>);
<a name="l00088"></a>00088 <span class="comment">// Precompute filter weight table</span>
<a name="l00089"></a>00089 <span class="preprocessor"> #define FILTER_TABLE_SIZE 16</span>
<a name="l00090"></a>00090 <span class="preprocessor"></span> <a class="code" href="classImageFilm.html#71819b70759ab933aa59b5a16f084381">filterTable</a> =
<a name="l00091"></a>00091 <span class="keyword">new</span> <span class="keywordtype">float</span>[<a class="code" href="image_8cpp.html#426c0b0b52199b3c6682f7d8db1a234d">FILTER_TABLE_SIZE</a> * <a class="code" href="image_8cpp.html#426c0b0b52199b3c6682f7d8db1a234d">FILTER_TABLE_SIZE</a>];
<a name="l00092"></a>00092 <span class="keywordtype">float</span> *ftp = filterTable;
<a name="l00093"></a>00093 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> y = 0; y < <a class="code" href="image_8cpp.html#426c0b0b52199b3c6682f7d8db1a234d">FILTER_TABLE_SIZE</a>; ++y) {
<a name="l00094"></a>00094 <span class="keywordtype">float</span> fy = ((float)y + .5f) * <a class="code" href="classImageFilm.html#d91aad5afa6ef1f088cf5b474059b3af">filter</a>-><a class="code" href="classFilter.html#87ab09bba9cc78544b71efc54d1ff6e9">yWidth</a> /
<a name="l00095"></a>00095 FILTER_TABLE_SIZE;
<a name="l00096"></a>00096 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> x = 0; x < FILTER_TABLE_SIZE; ++x) {
<a name="l00097"></a>00097 <span class="keywordtype">float</span> fx = ((float)x + .5f) * <a class="code" href="classImageFilm.html#d91aad5afa6ef1f088cf5b474059b3af">filter</a>-><a class="code" href="classFilter.html#209958b23de5933f8ce2eb5ae79117ed">xWidth</a> /
<a name="l00098"></a>00098 FILTER_TABLE_SIZE;
<a name="l00099"></a>00099 *ftp++ = <a class="code" href="classImageFilm.html#d91aad5afa6ef1f088cf5b474059b3af">filter</a>-><a class="code" href="classFilter.html#f079c261f8d3b4dd2b2aa0ee90bd947d">Evaluate</a>(fx, fy);
<a name="l00100"></a>00100 }
<a name="l00101"></a>00101 }
<a name="l00102"></a>00102 }
<a name="l00103"></a><a class="code" href="classImageFilm.html#e85b27fe21f6d3799d97a836f4a48703">00103</a> <span class="keywordtype">void</span> <a class="code" href="classImageFilm.html#e85b27fe21f6d3799d97a836f4a48703">ImageFilm::AddSample</a>(<span class="keyword">const</span> <a class="code" href="structSample.html">Sample</a> &sample,
<a name="l00104"></a>00104 <span class="keyword">const</span> <a class="code" href="classRay.html">Ray</a> &ray, <span class="keyword">const</span> <a class="code" href="classSpectrum.html">Spectrum</a> &L, <span class="keywordtype">float</span> alpha) {
<a name="l00105"></a>00105 <span class="comment">// Compute sample's raster extent</span>
<a name="l00106"></a>00106 <span class="keywordtype">float</span> dImageX = sample.<a class="code" href="structSample.html#0ef393f48bbf914ec9556d88be3968a6">imageX</a> - 0.5f;
<a name="l00107"></a>00107 <span class="keywordtype">float</span> dImageY = sample.<a class="code" href="structSample.html#67fa8bb74cf175f601ebab630655fcf4">imageY</a> - 0.5f;
<a name="l00108"></a>00108 <span class="keywordtype">int</span> x0 = <a class="code" href="pbrt_8h.html#1a941973fe233e9e8179a48dff4115c8">Ceil2Int</a> (dImageX - <a class="code" href="classImageFilm.html#d91aad5afa6ef1f088cf5b474059b3af">filter</a>-><a class="code" href="classFilter.html#209958b23de5933f8ce2eb5ae79117ed">xWidth</a>);
<a name="l00109"></a>00109 <span class="keywordtype">int</span> x1 = <a class="code" href="pbrt_8h.html#02648670ea7bf29f5782902cd9aa87c1">Floor2Int</a>(dImageX + <a class="code" href="classImageFilm.html#d91aad5afa6ef1f088cf5b474059b3af">filter</a>-><a class="code" href="classFilter.html#209958b23de5933f8ce2eb5ae79117ed">xWidth</a>);
<a name="l00110"></a>00110 <span class="keywordtype">int</span> y0 = <a class="code" href="pbrt_8h.html#1a941973fe233e9e8179a48dff4115c8">Ceil2Int</a> (dImageY - <a class="code" href="classImageFilm.html#d91aad5afa6ef1f088cf5b474059b3af">filter</a>-><a class="code" href="classFilter.html#87ab09bba9cc78544b71efc54d1ff6e9">yWidth</a>);
<a name="l00111"></a>00111 <span class="keywordtype">int</span> y1 = <a class="code" href="pbrt_8h.html#02648670ea7bf29f5782902cd9aa87c1">Floor2Int</a>(dImageY + <a class="code" href="classImageFilm.html#d91aad5afa6ef1f088cf5b474059b3af">filter</a>-><a class="code" href="classFilter.html#87ab09bba9cc78544b71efc54d1ff6e9">yWidth</a>);
<a name="l00112"></a>00112 x0 = max(x0, <a class="code" href="classImageFilm.html#c7a8ad086d28a1e31e05bb7596950f33">xPixelStart</a>);
<a name="l00113"></a>00113 x1 = min(x1, <a class="code" href="classImageFilm.html#c7a8ad086d28a1e31e05bb7596950f33">xPixelStart</a> + <a class="code" href="classImageFilm.html#0517c240230acc2b75e6444e8c880efa">xPixelCount</a> - 1);
<a name="l00114"></a>00114 y0 = max(y0, <a class="code" href="classImageFilm.html#f7e6476d3b84110c2d88fca7d7f68b22">yPixelStart</a>);
<a name="l00115"></a>00115 y1 = min(y1, <a class="code" href="classImageFilm.html#f7e6476d3b84110c2d88fca7d7f68b22">yPixelStart</a> + <a class="code" href="classImageFilm.html#337519591bdb4dfe063cdcf184bd3992">yPixelCount</a> - 1);
<a name="l00116"></a>00116 <span class="keywordflow">if</span> ((x1-x0) < 0 || (y1-y0) < 0) <span class="keywordflow">return</span>;
<a name="l00117"></a>00117 <span class="comment">// Loop over filter support and add sample to pixel arrays</span>
<a name="l00118"></a>00118 <span class="comment">// Precompute $x$ and $y$ filter table offsets</span>
<a name="l00119"></a>00119 <span class="keywordtype">int</span> *ifx = (<span class="keywordtype">int</span> *)alloca((x1-x0+1) * <span class="keyword">sizeof</span>(int));
<a name="l00120"></a>00120 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> x = x0; x <= x1; ++x) {
<a name="l00121"></a>00121 <span class="keywordtype">float</span> fx = fabsf((x - dImageX) *
<a name="l00122"></a>00122 <a class="code" href="classImageFilm.html#d91aad5afa6ef1f088cf5b474059b3af">filter</a>-><a class="code" href="classFilter.html#0c91d7d036b2f9f6a4625654a9381303">invXWidth</a> * <a class="code" href="image_8cpp.html#426c0b0b52199b3c6682f7d8db1a234d">FILTER_TABLE_SIZE</a>);
<a name="l00123"></a>00123 ifx[x-x0] = min(<a class="code" href="pbrt_8h.html#02648670ea7bf29f5782902cd9aa87c1">Floor2Int</a>(fx), FILTER_TABLE_SIZE-1);
<a name="l00124"></a>00124 }
<a name="l00125"></a>00125 <span class="keywordtype">int</span> *ify = (<span class="keywordtype">int</span> *)alloca((y1-y0+1) * <span class="keyword">sizeof</span>(int));
<a name="l00126"></a>00126 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> y = y0; y <= y1; ++y) {
<a name="l00127"></a>00127 <span class="keywordtype">float</span> fy = fabsf((y - dImageY) *
<a name="l00128"></a>00128 <a class="code" href="classImageFilm.html#d91aad5afa6ef1f088cf5b474059b3af">filter</a>-><a class="code" href="classFilter.html#1ed7f6b9bbf7f7e4a66ecc9621ead920">invYWidth</a> * <a class="code" href="image_8cpp.html#426c0b0b52199b3c6682f7d8db1a234d">FILTER_TABLE_SIZE</a>);
<a name="l00129"></a>00129 ify[y-y0] = min(<a class="code" href="pbrt_8h.html#02648670ea7bf29f5782902cd9aa87c1">Floor2Int</a>(fy), FILTER_TABLE_SIZE-1);
<a name="l00130"></a>00130 }
<a name="l00131"></a>00131 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> y = y0; y <= y1; ++y)
<a name="l00132"></a>00132 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> x = x0; x <= x1; ++x) {
<a name="l00133"></a>00133 <span class="comment">// Evaluate filter value at $(x,y)$ pixel</span>
<a name="l00134"></a>00134 <span class="keywordtype">int</span> offset = ify[y-y0]*<a class="code" href="image_8cpp.html#426c0b0b52199b3c6682f7d8db1a234d">FILTER_TABLE_SIZE</a> + ifx[x-x0];
<a name="l00135"></a>00135 <span class="keywordtype">float</span> filterWt = <a class="code" href="classImageFilm.html#71819b70759ab933aa59b5a16f084381">filterTable</a>[offset];
<a name="l00136"></a>00136 <span class="comment">// Update pixel values with filtered sample contribution</span>
<a name="l00137"></a>00137 <a class="code" href="structImageFilm_1_1Pixel.html">Pixel</a> &pixel = (*pixels)(x - <a class="code" href="classImageFilm.html#c7a8ad086d28a1e31e05bb7596950f33">xPixelStart</a>, y - <a class="code" href="classImageFilm.html#f7e6476d3b84110c2d88fca7d7f68b22">yPixelStart</a>);
<a name="l00138"></a>00138 pixel.<a class="code" href="structImageFilm_1_1Pixel.html#449b3440e94e9a446dec9068927697f6">L</a>.<a class="code" href="classSpectrum.html#05c9229316ac9df94335b6a376cc2a1c">AddWeighted</a>(filterWt, L);
<a name="l00139"></a>00139 pixel.<a class="code" href="structImageFilm_1_1Pixel.html#b313ce7a5011f5e21d72c54d0309ba52">alpha</a> += alpha * filterWt;
<a name="l00140"></a>00140 pixel.<a class="code" href="structImageFilm_1_1Pixel.html#6fad989e28b1af3d7c326ed3cf0ebce1">weightSum</a> += filterWt;
<a name="l00141"></a>00141 }
<a name="l00142"></a>00142 <span class="comment">// Possibly write out in-progress image</span>
<a name="l00143"></a>00143 <span class="keywordflow">if</span> (--<a class="code" href="classImageFilm.html#03fc8ded049b3630e6ea55808aafb888">sampleCount</a> == 0) {
<a name="l00144"></a>00144 <a class="code" href="classImageFilm.html#fdd385a53cb205ef3fe6a75fefa7348e">WriteImage</a>();
<a name="l00145"></a>00145 <a class="code" href="classImageFilm.html#03fc8ded049b3630e6ea55808aafb888">sampleCount</a> = <a class="code" href="classImageFilm.html#0be5e7b9be41b6f79c55b287206a8080">writeFrequency</a>;
<a name="l00146"></a>00146 }
<a name="l00147"></a>00147 }
<a name="l00148"></a><a class="code" href="classImageFilm.html#2adf1f50c18104f1de5161def2ff3658">00148</a> <span class="keywordtype">void</span> <a class="code" href="classImageFilm.html#2adf1f50c18104f1de5161def2ff3658">ImageFilm::GetSampleExtent</a>(<span class="keywordtype">int</span> *xstart,
<a name="l00149"></a>00149 <span class="keywordtype">int</span> *xend, <span class="keywordtype">int</span> *ystart, <span class="keywordtype">int</span> *yend)<span class="keyword"> const </span>{
<a name="l00150"></a>00150 *xstart = <a class="code" href="pbrt_8h.html#02648670ea7bf29f5782902cd9aa87c1">Floor2Int</a>(<a class="code" href="classImageFilm.html#c7a8ad086d28a1e31e05bb7596950f33">xPixelStart</a> + .5f - <a class="code" href="classImageFilm.html#d91aad5afa6ef1f088cf5b474059b3af">filter</a>-><a class="code" href="classFilter.html#209958b23de5933f8ce2eb5ae79117ed">xWidth</a>);
<a name="l00151"></a>00151 *xend = <a class="code" href="pbrt_8h.html#02648670ea7bf29f5782902cd9aa87c1">Floor2Int</a>(<a class="code" href="classImageFilm.html#c7a8ad086d28a1e31e05bb7596950f33">xPixelStart</a> + .5f + <a class="code" href="classImageFilm.html#0517c240230acc2b75e6444e8c880efa">xPixelCount</a> +
<a name="l00152"></a>00152 <a class="code" href="classImageFilm.html#d91aad5afa6ef1f088cf5b474059b3af">filter</a>-><a class="code" href="classFilter.html#209958b23de5933f8ce2eb5ae79117ed">xWidth</a>);
<a name="l00153"></a>00153 *ystart = <a class="code" href="pbrt_8h.html#02648670ea7bf29f5782902cd9aa87c1">Floor2Int</a>(<a class="code" href="classImageFilm.html#f7e6476d3b84110c2d88fca7d7f68b22">yPixelStart</a> + .5f - <a class="code" href="classImageFilm.html#d91aad5afa6ef1f088cf5b474059b3af">filter</a>-><a class="code" href="classFilter.html#87ab09bba9cc78544b71efc54d1ff6e9">yWidth</a>);
<a name="l00154"></a>00154 *yend = <a class="code" href="pbrt_8h.html#02648670ea7bf29f5782902cd9aa87c1">Floor2Int</a>(<a class="code" href="classImageFilm.html#f7e6476d3b84110c2d88fca7d7f68b22">yPixelStart</a> + .5f + <a class="code" href="classImageFilm.html#337519591bdb4dfe063cdcf184bd3992">yPixelCount</a> +
<a name="l00155"></a>00155 <a class="code" href="classImageFilm.html#d91aad5afa6ef1f088cf5b474059b3af">filter</a>-><a class="code" href="classFilter.html#87ab09bba9cc78544b71efc54d1ff6e9">yWidth</a>);
<a name="l00156"></a>00156 }
<a name="l00157"></a><a class="code" href="classImageFilm.html#fdd385a53cb205ef3fe6a75fefa7348e">00157</a> <span class="keywordtype">void</span> <a class="code" href="classImageFilm.html#fdd385a53cb205ef3fe6a75fefa7348e">ImageFilm::WriteImage</a>() {
<a name="l00158"></a>00158 <span class="comment">// Convert image to RGB and compute final pixel values</span>
<a name="l00159"></a>00159 <span class="keywordtype">int</span> nPix = <a class="code" href="classImageFilm.html#0517c240230acc2b75e6444e8c880efa">xPixelCount</a> * <a class="code" href="classImageFilm.html#337519591bdb4dfe063cdcf184bd3992">yPixelCount</a>;
<a name="l00160"></a>00160 <span class="keywordtype">float</span> *rgb = <span class="keyword">new</span> <span class="keywordtype">float</span>[3*nPix], *alpha = <span class="keyword">new</span> <span class="keywordtype">float</span>[nPix];
<a name="l00161"></a>00161 <span class="keywordtype">int</span> offset = 0;
<a name="l00162"></a>00162 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> y = 0; y < yPixelCount; ++y) {
<a name="l00163"></a>00163 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> x = 0; x < <a class="code" href="classImageFilm.html#0517c240230acc2b75e6444e8c880efa">xPixelCount</a>; ++x) {
<a name="l00164"></a>00164 <span class="comment">// Convert pixel spectral radiance to RGB</span>
<a name="l00165"></a>00165 <span class="keywordtype">float</span> xyz[3];
<a name="l00166"></a>00166 (*pixels)(x, y).L.XYZ(xyz);
<a name="l00167"></a>00167 <span class="keyword">const</span> <span class="keywordtype">float</span>
<a name="l00168"></a>00168 rWeight[3] = { 3.240479f, -1.537150f, -0.498535f };
<a name="l00169"></a>00169 <span class="keyword">const</span> <span class="keywordtype">float</span>
<a name="l00170"></a>00170 gWeight[3] = {-0.969256f, 1.875991f, 0.041556f };
<a name="l00171"></a>00171 <span class="keyword">const</span> <span class="keywordtype">float</span>
<a name="l00172"></a>00172 bWeight[3] = { 0.055648f, -0.204043f, 1.057311f };
<a name="l00173"></a>00173 rgb[3*offset ] = rWeight[0]*xyz[0] +
<a name="l00174"></a>00174 rWeight[1]*xyz[1] +
<a name="l00175"></a>00175 rWeight[2]*xyz[2];
<a name="l00176"></a>00176 rgb[3*offset+1] = gWeight[0]*xyz[0] +
<a name="l00177"></a>00177 gWeight[1]*xyz[1] +
<a name="l00178"></a>00178 gWeight[2]*xyz[2];
<a name="l00179"></a>00179 rgb[3*offset+2] = bWeight[0]*xyz[0] +
<a name="l00180"></a>00180 bWeight[1]*xyz[1] +
<a name="l00181"></a>00181 bWeight[2]*xyz[2];
<a name="l00182"></a>00182 alpha[offset] = (*pixels)(x, y).alpha;
<a name="l00183"></a>00183 <span class="comment">// Normalize pixel with weight sum</span>
<a name="l00184"></a>00184 <span class="keywordtype">float</span> weightSum = (*pixels)(x, y).weightSum;
<a name="l00185"></a>00185 <span class="keywordflow">if</span> (weightSum != 0.f) {
<a name="l00186"></a>00186 <span class="keywordtype">float</span> invWt = 1.f / weightSum;
<a name="l00187"></a>00187 rgb[3*offset ] =
<a name="l00188"></a>00188 <a class="code" href="pbrt_8h.html#036098e5cec04b73d8720de12e8e5cd1">Clamp</a>(rgb[3*offset ] * invWt, 0.f, <a class="code" href="pbrt_8h.html#956e2723d559858d08644ac99146e910">INFINITY</a>);
<a name="l00189"></a>00189 rgb[3*offset+1] =
<a name="l00190"></a>00190 <a class="code" href="pbrt_8h.html#036098e5cec04b73d8720de12e8e5cd1">Clamp</a>(rgb[3*offset+1] * invWt, 0.f, <a class="code" href="pbrt_8h.html#956e2723d559858d08644ac99146e910">INFINITY</a>);
<a name="l00191"></a>00191 rgb[3*offset+2] =
<a name="l00192"></a>00192 <a class="code" href="pbrt_8h.html#036098e5cec04b73d8720de12e8e5cd1">Clamp</a>(rgb[3*offset+2] * invWt, 0.f, <a class="code" href="pbrt_8h.html#956e2723d559858d08644ac99146e910">INFINITY</a>);
<a name="l00193"></a>00193 alpha[offset] = <a class="code" href="pbrt_8h.html#036098e5cec04b73d8720de12e8e5cd1">Clamp</a>(alpha[offset] * invWt, 0.f, 1.f);
<a name="l00194"></a>00194 }
<a name="l00195"></a>00195 <span class="comment">// Compute premultiplied alpha color</span>
<a name="l00196"></a>00196 <span class="keywordflow">if</span> (<a class="code" href="classImageFilm.html#45c9e69dbd23f400f22b57ac1bee22d0">premultiplyAlpha</a>) {
<a name="l00197"></a>00197 rgb[3*offset ] *= alpha[offset];
<a name="l00198"></a>00198 rgb[3*offset+1] *= alpha[offset];
<a name="l00199"></a>00199 rgb[3*offset+2] *= alpha[offset];
<a name="l00200"></a>00200 }
<a name="l00201"></a>00201 ++offset;
<a name="l00202"></a>00202 }
<a name="l00203"></a>00203 }
<a name="l00204"></a>00204 <span class="comment">// Write RGBA image</span>
<a name="l00205"></a>00205 <a class="code" href="exrio_8cpp.html#adf7c9452dc5e5ece32ade3d2dde96ba">WriteRGBAImage</a>(<a class="code" href="classImageFilm.html#aaa61b7b3cb22b520fcb1c62f57584cc">filename</a>, rgb, alpha,
<a name="l00206"></a>00206 <a class="code" href="classImageFilm.html#0517c240230acc2b75e6444e8c880efa">xPixelCount</a>, yPixelCount,
<a name="l00207"></a>00207 <a class="code" href="classFilm.html#2a6768612de9b5c940ce90edf74e51e4">xResolution</a>, <a class="code" href="classFilm.html#063949abe489b632809617887e32a87c">yResolution</a>,
<a name="l00208"></a>00208 <a class="code" href="classImageFilm.html#c7a8ad086d28a1e31e05bb7596950f33">xPixelStart</a>, <a class="code" href="classImageFilm.html#f7e6476d3b84110c2d88fca7d7f68b22">yPixelStart</a>);
<a name="l00209"></a>00209 <span class="comment">// Release temporary image memory</span>
<a name="l00210"></a>00210 <span class="keyword">delete</span>[] alpha;
<a name="l00211"></a>00211 <span class="keyword">delete</span>[] rgb;
<a name="l00212"></a>00212 }
<a name="l00213"></a><a class="code" href="image_8cpp.html#a197aa9e905fb399414ef8e7b1dd5853">00213</a> <span class="keyword">extern</span> <span class="stringliteral">"C"</span> <a class="code" href="pbrt_8h.html#808e08638be3cba36e36759e5b150de0">DLLEXPORT</a> <a class="code" href="classFilm.html">Film</a> *<a class="code" href="image_8cpp.html#a197aa9e905fb399414ef8e7b1dd5853">CreateFilm</a>(<span class="keyword">const</span> <a class="code" href="classParamSet.html">ParamSet</a> &params, <a class="code" href="classFilter.html">Filter</a> *<a class="code" href="classImageFilm.html#d91aad5afa6ef1f088cf5b474059b3af">filter</a>)
<a name="l00214"></a>00214 {
<a name="l00215"></a>00215 <span class="keywordtype">string</span> <a class="code" href="classImageFilm.html#aaa61b7b3cb22b520fcb1c62f57584cc">filename</a> = params.<a class="code" href="classParamSet.html#a3f26c4aa7282d1a548bc14cc4409598">FindOneString</a>(<span class="stringliteral">"filename"</span>, <span class="stringliteral">"pbrt.exr"</span>);
<a name="l00216"></a>00216 <span class="keywordtype">bool</span> <a class="code" href="classImageFilm.html#45c9e69dbd23f400f22b57ac1bee22d0">premultiplyAlpha</a> = params.<a class="code" href="classParamSet.html#3a0bf8f2142200ec23078cde92bd41b4">FindOneBool</a>(<span class="stringliteral">"premultiplyalpha"</span>, <span class="keyword">true</span>);
<a name="l00217"></a>00217
<a name="l00218"></a>00218 <span class="keywordtype">int</span> xres = params.<a class="code" href="classParamSet.html#23f24db9c46375e33764910c4fa999d5">FindOneInt</a>(<span class="stringliteral">"xresolution"</span>, 640);
<a name="l00219"></a>00219 <span class="keywordtype">int</span> yres = params.<a class="code" href="classParamSet.html#23f24db9c46375e33764910c4fa999d5">FindOneInt</a>(<span class="stringliteral">"yresolution"</span>, 480);
<a name="l00220"></a>00220 <span class="keywordtype">float</span> crop[4] = { 0, 1, 0, 1 };
<a name="l00221"></a>00221 <span class="keywordtype">int</span> cwi;
<a name="l00222"></a>00222 <span class="keyword">const</span> <span class="keywordtype">float</span> *cr = params.<a class="code" href="classParamSet.html#16ef98ac9d59f839f08c13fb80eeeefe">FindFloat</a>(<span class="stringliteral">"cropwindow"</span>, &cwi);
<a name="l00223"></a>00223 <span class="keywordflow">if</span> (cr && cwi == 4) {
<a name="l00224"></a>00224 crop[0] = <a class="code" href="pbrt_8h.html#036098e5cec04b73d8720de12e8e5cd1">Clamp</a>(min(cr[0], cr[1]), 0., 1.);
<a name="l00225"></a>00225 crop[1] = <a class="code" href="pbrt_8h.html#036098e5cec04b73d8720de12e8e5cd1">Clamp</a>(max(cr[0], cr[1]), 0., 1.);
<a name="l00226"></a>00226 crop[2] = <a class="code" href="pbrt_8h.html#036098e5cec04b73d8720de12e8e5cd1">Clamp</a>(min(cr[2], cr[3]), 0., 1.);
<a name="l00227"></a>00227 crop[3] = <a class="code" href="pbrt_8h.html#036098e5cec04b73d8720de12e8e5cd1">Clamp</a>(max(cr[2], cr[3]), 0., 1.);
<a name="l00228"></a>00228 }
<a name="l00229"></a>00229 <span class="keywordtype">int</span> <a class="code" href="classImageFilm.html#0be5e7b9be41b6f79c55b287206a8080">writeFrequency</a> = params.<a class="code" href="classParamSet.html#23f24db9c46375e33764910c4fa999d5">FindOneInt</a>(<span class="stringliteral">"writefrequency"</span>, -1);
<a name="l00230"></a>00230
<a name="l00231"></a>00231 <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="classImageFilm.html#686df06d99c042780f381230f5191056">ImageFilm</a>(xres, yres, filter, crop,
<a name="l00232"></a>00232 filename, premultiplyAlpha, writeFrequency);
<a name="l00233"></a>00233 }
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Mon Jul 20 17:31:53 2009 for pbrt by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>