49 } |
61 } |
50 |
62 |
51 Sample* DefaultSampler::nextSample(Sample *prev) |
63 Sample* DefaultSampler::nextSample(Sample *prev) |
52 { |
64 { |
53 DefaultSample *s = new DefaultSample; |
65 DefaultSample *s = new DefaultSample; |
54 if (prev) |
66 |
|
67 /* grid oversampling */ |
|
68 static const int gridsamples[] = {1,5,9,16}; |
|
69 static const Float osa5x[] = {0.0, -0.4, +0.4, +0.4, -0.4}; |
|
70 static const Float osa5y[] = {0.0, -0.4, -0.4, +0.4, +0.4}; |
|
71 static const Float osa9x[] = {-0.34, 0.00, +0.34, |
|
72 -0.34, 0.00, +0.34, -0.34, 0.00, +0.34}; |
|
73 static const Float osa9y[] = {-0.34, -0.34, -0.34, |
|
74 0.00, 0.00, 0.00, +0.34, +0.34, +0.34}; |
|
75 static const Float osa16x[] = {-0.375, -0.125, +0.125, +0.375, |
|
76 -0.375, -0.125, +0.125, +0.375, -0.375, -0.125, +0.125, +0.375, |
|
77 -0.375, -0.125, +0.125, +0.375}; |
|
78 static const Float osa16y[] = {-0.375, -0.375, -0.375, -0.375, |
|
79 -0.125, -0.125, -0.125, -0.125, +0.125, +0.125, +0.125, +0.125, |
|
80 +0.375, +0.375, +0.375, +0.375}; |
|
81 static const Float *osaSx[] = {NULL, osa5x, osa9x, osa16x}; |
|
82 static const Float *osaSy[] = {NULL, osa5y, osa9y, osa16y}; |
|
83 const int samples = gridsamples[oversample]; |
|
84 const Float *osax = osaSx[oversample]; |
|
85 const Float *osay = osaSy[oversample]; |
|
86 |
|
87 if (!prev) |
55 { |
88 { |
56 DefaultSample *sp = static_cast<DefaultSample*>(prev); |
89 // first sample |
57 s->sx = sp->sx + 1; |
|
58 s->sy = sp->sy; |
|
59 if (s->sx >= w) |
|
60 { |
|
61 s->sx = 0; |
|
62 s->sy++; |
|
63 } |
|
64 if (s->sy >= h) |
|
65 { |
|
66 delete s; |
|
67 return NULL; |
|
68 } |
|
69 s->x = (Float)s->sx/h - (Float)w/h/2.0; |
|
70 s->y = (Float)s->sy/h - 0.5; |
|
71 } |
|
72 else |
|
73 { |
|
74 s->x = -(Float)w/h/2.0; |
90 s->x = -(Float)w/h/2.0; |
75 s->y = -0.5; |
91 s->y = -0.5; |
76 s->sx = 0; |
92 s->sx = 0; |
77 s->sy = 0; |
93 s->sy = 0; |
|
94 s->osa_samp = 0; |
78 } |
95 } |
|
96 else |
|
97 { |
|
98 DefaultSample *sp = static_cast<DefaultSample*>(prev); |
|
99 |
|
100 s->osa_samp = sp->osa_samp + 1; |
|
101 |
|
102 if (oversample && oversample <= 3 && s->osa_samp < samples) |
|
103 { |
|
104 s->sx = sp->sx; |
|
105 s->sy = sp->sy; |
|
106 s->x = osax[s->osa_samp]/h + (Float)s->sx/h - (Float)w/h/2.0; |
|
107 s->y = osay[s->osa_samp]/h + (Float)s->sy/h - 0.5; |
|
108 } |
|
109 else |
|
110 { |
|
111 s->sx = sp->sx + 1; |
|
112 s->sy = sp->sy; |
|
113 if (s->sx >= w) |
|
114 { |
|
115 s->sx = 0; |
|
116 s->sy++; |
|
117 } |
|
118 if (s->sy >= h) |
|
119 { |
|
120 delete s; |
|
121 return NULL; |
|
122 } |
|
123 s->x = (Float)s->sx/h - (Float)w/h/2.0; |
|
124 s->y = (Float)s->sy/h - 0.5; |
|
125 s->osa_samp = 0; |
|
126 } |
|
127 } |
|
128 |
|
129 if (s->osa_samp == 0 && oversample && oversample <= 3) |
|
130 { |
|
131 s->x += osax[0]/h; |
|
132 s->y += osay[0]/h; |
|
133 Float *buf = buffer + 3*(s->sy*w + s->sx); |
|
134 *(buf++) = 0; |
|
135 *(buf++) = 0; |
|
136 *(buf++) = 0; |
|
137 } |
|
138 |
79 return s; |
139 return s; |
80 } |
140 } |
81 |
141 |
82 void DefaultSampler::saveSample(Sample *samp, Colour &col) |
142 void DefaultSampler::saveSample(Sample *samp, Colour &col) |
83 { |
143 { |
84 DefaultSample *sp = static_cast<DefaultSample*>(samp); |
144 DefaultSample *sp = static_cast<DefaultSample*>(samp); |
85 Float *buf = buffer + 3*(sp->sy*w + sp->sx); |
145 Float *buf = buffer + 3*(sp->sy*w + sp->sx); |
86 *(buf++) = col.r; |
146 if (oversample) |
87 *(buf++) = col.g; |
147 { |
88 *(buf++) = col.b; |
148 *(buf+0) += col.r; |
|
149 *(buf+1) += col.g; |
|
150 *(buf+2) += col.b; |
|
151 } |
|
152 else |
|
153 { |
|
154 *(buf++) = col.r; |
|
155 *(buf++) = col.g; |
|
156 *(buf++) = col.b; |
|
157 } |
89 } |
158 } |
90 |
159 |