src/sampler.cc
branchpyrit
changeset 93 96d65f841791
parent 92 9af5c039b678
child 94 4c8abb8977dc
equal deleted inserted replaced
92:9af5c039b678 93:96d65f841791
    58 		}
    58 		}
    59 	}
    59 	}
    60 	if ( phase == 1 )
    60 	if ( phase == 1 )
    61 	{
    61 	{
    62 		// finalize subsampling
    62 		// finalize subsampling
    63 		const Float subsample2 = 1.0/(subsample*subsample);
    63 		const Float subsample2 = 1.0f / (subsample*subsample);
    64 		int num_samples = 0;
    64 		int num_samples = 0;
    65 		Colour ic;
    65 		Colour ic;
    66 		phase = 2;
    66 		phase = 2;
    67 		sx = -1;
    67 		sx = -1;
    68 		for (int y = 0; y < h/subsample; y++)
    68 		for (int y = 0; y < h/subsample; y++)
    93 				{
    93 				{
    94 					// interpolate
    94 					// interpolate
    95 					for (int i = 0; i < subsample; i++)
    95 					for (int i = 0; i < subsample; i++)
    96 						for (int j = 0; j < subsample; j++)
    96 						for (int j = 0; j < subsample; j++)
    97 						{
    97 						{
    98 							ic = c1*(subsample-i)*(subsample-j)*subsample2
    98 							ic = c1*(Float)((subsample-i)*(subsample-j)*subsample2)
    99 								+ c2*(i)*(subsample-j)*subsample2
    99 								+ c2*(Float)((i)*(subsample-j)*subsample2)
   100 								+ c3*(subsample-i)*(j)*subsample2
   100 								+ c3*(Float)((subsample-i)*(j)*subsample2)
   101 								+ c4*(i)*(j)*subsample2;
   101 								+ c4*(Float)((i)*(j)*subsample2);
   102 							p = buffer + 3*((y1+j)*w + x1+i);
   102 							p = buffer + 3*((y1+j)*w + x1+i);
   103 							*(p + 0) = ic.r;
   103 							*(p + 0) = ic.r;
   104 							*(p + 1) = oversample ? -ic.g : ic.g;
   104 							*(p + 1) = oversample ? -ic.g : ic.g;
   105 							*(p + 2) = ic.b;
   105 							*(p + 2) = ic.b;
   106 						}
   106 						}
   128 					// interpolated
   128 					// interpolated
   129 					*(buf+1) = -*(buf+1);
   129 					*(buf+1) = -*(buf+1);
   130 				}
   130 				}
   131 				else
   131 				else
   132 				{
   132 				{
   133 					*buf = *buf * (1.0/samples);
   133 					*buf = *buf * (1.0f/samples);
   134 					*(buf+1) = *(buf+1) * (1.0/samples);
   134 					*(buf+1) = *(buf+1) * (1.0f/samples);
   135 					*(buf+2) = *(buf+2) * (1.0/samples);
   135 					*(buf+2) = *(buf+2) * (1.0f/samples);
   136 				}
   136 				}
   137 		else
   137 		else
   138 			for (buf = buffer; buf != buffer + w*h*3; buf++)
   138 			for (buf = buffer; buf != buffer + w*h*3; buf++)
   139 				*buf = *buf * (1.0/samples);
   139 				*buf = *buf * (1.0f/samples);
   140 	}
   140 	}
   141 	phase = -1;
   141 	phase = -1;
   142 	return 0;
   142 	return 0;
   143 }
   143 }
   144 
   144 
   151 	{
   151 	{
   152 		// subsampling
   152 		// subsampling
   153 		if (sx < 0)
   153 		if (sx < 0)
   154 		{
   154 		{
   155 			// first sample
   155 			// first sample
   156 			s->x = -(Float)w/h/2.0;
   156 			s->x = -(Float)w/h/2.0f;
   157 			s->y = -0.5;
   157 			s->y = -0.5f;
   158 			sx = 0;
   158 			sx = 0;
   159 			sy = 0;
   159 			sy = 0;
   160 			osa_samp = 0;
   160 			osa_samp = 0;
   161 		}
   161 		}
   162 		else
   162 		else
   175 				sx += subsample;
   175 				sx += subsample;
   176 				if (sx > w-1)
   176 				if (sx > w-1)
   177 					sx = w-1;
   177 					sx = w-1;
   178 			}
   178 			}
   179 
   179 
   180 			s->x = (Float)sx/h - (Float)w/h/2.0;
   180 			s->x = (Float)sx/h - (Float)w/h/2.0f;
   181 			s->y = (Float)sy/h - 0.5;
   181 			s->y = (Float)sy/h - 0.5f;
   182 		}
   182 		}
   183 	}
   183 	}
   184 	else if (phase == 2)
   184 	else if (phase == 2)
   185 	{
   185 	{
   186 		/* grid oversampling */
   186 		/* grid oversampling */
   187 		static const int gridsamples[] = {1,4,9,16};
   187 		static const int gridsamples[] = {1,4,9,16};
   188 		static const Float osa4x[] = {-0.25, +0.25, +0.25, -0.25};
   188 		static const Float osa4x[] = {-0.25f, +0.25f, +0.25f, -0.25f};
   189 		static const Float osa4y[] = {-0.25, -0.25, +0.25, +0.25};
   189 		static const Float osa4y[] = {-0.25f, -0.25f, +0.25f, +0.25f};
   190 		static const Float osa9x[] = {-0.34,  0.00, +0.34,
   190 		static const Float osa9x[] = {-0.34f,  0.00f, +0.34f,
   191 			-0.34,  0.00, +0.34, -0.34,  0.00, +0.34};
   191 			-0.34f,  0.00f, +0.34f, -0.34f,  0.00f, +0.34f};
   192 		static const Float osa9y[] = {-0.34, -0.34, -0.34,
   192 		static const Float osa9y[] = {-0.34f, -0.34f, -0.34f,
   193 				0.00,  0.00,  0.00, +0.34, +0.34, +0.34};
   193 				0.00f,  0.00f,  0.00f, +0.34f, +0.34f, +0.34f};
   194 		static const Float osa16x[] = {-0.375, -0.125, +0.125, +0.375,
   194 		static const Float osa16x[] = {-0.375f, -0.125f, +0.125f, +0.375f,
   195 			-0.375, -0.125, +0.125, +0.375, -0.375, -0.125, +0.125, +0.375,
   195 			-0.375f, -0.125f, +0.125f, +0.375f, -0.375f, -0.125f, +0.125f, +0.375f,
   196 			-0.375, -0.125, +0.125, +0.375};
   196 			-0.375f, -0.125f, +0.125f, +0.375f};
   197 		static const Float osa16y[] = {-0.375, -0.375, -0.375, -0.375,
   197 		static const Float osa16y[] = {-0.375f, -0.375f, -0.375f, -0.375f,
   198 			-0.125, -0.125, -0.125, -0.125, +0.125, +0.125, +0.125, +0.125,
   198 			-0.125f, -0.125f, -0.125f, -0.125f, +0.125f, +0.125f, +0.125f, +0.125f,
   199 			+0.375, +0.375, +0.375, +0.375};
   199 			+0.375f, +0.375f, +0.375f, +0.375f};
   200 		static const Float *osaSx[] = {NULL, osa4x, osa9x, osa16x};
   200 		static const Float *osaSx[] = {NULL, osa4x, osa9x, osa16x};
   201 		static const Float *osaSy[] = {NULL, osa4y, osa9y, osa16y};
   201 		static const Float *osaSy[] = {NULL, osa4y, osa9y, osa16y};
   202 		const int samples = gridsamples[oversample];
   202 		const int samples = gridsamples[oversample];
   203 		const Float *osax = osaSx[oversample];
   203 		const Float *osax = osaSx[oversample];
   204 		const Float *osay = osaSy[oversample];
   204 		const Float *osay = osaSy[oversample];
   205 
   205 
   206 		if (sx < 0)
   206 		if (sx < 0)
   207 		{
   207 		{
   208 			// first sample
   208 			// first sample
   209 			s->x = -(Float)w/h/2.0;
   209 			s->x = -(Float)w/h/2.0f;
   210 			s->y = -0.5;
   210 			s->y = -0.5f;
   211 			sx = 0;
   211 			sx = 0;
   212 			sy = 0;
   212 			sy = 0;
   213 			osa_samp = 0;
   213 			osa_samp = 0;
   214 		}
   214 		}
   215 		else
   215 		else
   216 		{
   216 		{
   217 			osa_samp++;
   217 			osa_samp++;
   218 
   218 
   219 			if (oversample && oversample <= 3 && osa_samp < samples)
   219 			if (oversample && oversample <= 3 && osa_samp < samples)
   220 			{
   220 			{
   221 				s->x = osax[osa_samp]/h + (Float)sx/h - (Float)w/h/2.0;
   221 				s->x = osax[osa_samp]/h + (Float)sx/h - (Float)w/h/2.0f;
   222 				s->y = osay[osa_samp]/h + (Float)sy/h - 0.5;
   222 				s->y = osay[osa_samp]/h + (Float)sy/h - 0.5f;
   223 			}
   223 			}
   224 			else
   224 			else
   225 			{
   225 			{
   226 				if (subsample > 1)
   226 				if (subsample > 1)
   227 				{
   227 				{
   277 					}
   277 					}
   278 					if (sy >= h)
   278 					if (sy >= h)
   279 						return false;
   279 						return false;
   280 				}
   280 				}
   281 
   281 
   282 				s->x = (Float)sx/h - (Float)w/h/2.0;
   282 				s->x = (Float)sx/h - (Float)w/h/2.0f;
   283 				s->y = (Float)sy/h - 0.5;
   283 				s->y = (Float)sy/h - 0.5f;
   284 				osa_samp = 0;
   284 				osa_samp = 0;
   285 			}
   285 			}
   286 		}
   286 		}
   287 
   287 
   288 		if (osa_samp == 0 && oversample && oversample <= 3)
   288 		if (osa_samp == 0 && oversample && oversample <= 3)