Beispiel #1
0
void DiffuseGain::applyPtmRGB(const PyramidCoeff& redCoeff, const PyramidCoeff& greenCoeff, const PyramidCoeff& blueCoeff, const QSize* mipMapSize, const PyramidNormals& normals, const RenderingInfo& info, unsigned char* buffer)
{
	int offsetBuf = 0;
	const PTMCoefficient* redPtr = redCoeff.getLevel(info.level);
	const PTMCoefficient* greenPtr = greenCoeff.getLevel(info.level);
	const PTMCoefficient* bluePtr = blueCoeff.getLevel(info.level);
	const vcg::Point3f* normalsPtr = normals.getLevel(info.level);
	// Creates the output texture.
	
    #pragma omp parallel for schedule(static,CHUNK)
	for (int y = info.offy; y < info.offy + info.height; y++)
	{
        int offsetBuf = ((y-info.offy)*info.width)<<2;
		int offset = y * mipMapSize[info.level].width() + info.offx;
		for (int x = info.offx; x < info.offx + info.width; x++)
		{
			buffer[offsetBuf + 0] = tobyte(applyModel(&(redPtr[offset][0]), normalsPtr[offset].X(), normalsPtr[offset].Y(), info.light.X(), info.light.Y()));
			buffer[offsetBuf + 1] = tobyte(applyModel(&(greenPtr[offset][0]), normalsPtr[offset].X(), normalsPtr[offset].Y(), info.light.X(), info.light.Y()));
			buffer[offsetBuf + 2] = tobyte(applyModel(&(bluePtr[offset][0]), normalsPtr[offset].X(), normalsPtr[offset].Y(), info.light.X(), info.light.Y()));
            buffer[offsetBuf + 3] = 255;
			offset++;
			offsetBuf += 4;
		}
	}
	//qDebug() << "gain = " << DiffuseGain::gain;
}
Beispiel #2
0
void CoeffEnhancement::applyPtmRGB(const PyramidCoeff& redCoeff, const PyramidCoeff& greenCoeff, const PyramidCoeff& blueCoeff, const QSize* mipMapSize, const PyramidNormals& normals, const RenderingInfo& info, unsigned char* buffer)
{
	//int offsetBuf = 0;
	const PTMCoefficient* redPtr = redCoeff.getLevel(info.level);
	const PTMCoefficient* greenPtr = greenCoeff.getLevel(info.level);
	const PTMCoefficient* bluePtr = blueCoeff.getLevel(info.level);
	int lenght = info.width * info.height;
	PTMCoefficient* redC = new PTMCoefficient[lenght];
	PTMCoefficient* greenC = new PTMCoefficient[lenght];
	PTMCoefficient* blueC = new PTMCoefficient[lenght];
	int width = mipMapSize[info.level].width();
	// Creates the map of the coefficients of the sub-image in the current view of the browser
	#pragma omp parallel for schedule(static,CHUNK)
	for (int y = info.offy; y < info.offy + info.height; y++)
	{
		int offset = y * width + info.offx;
		int offset2 = (y - info.offy)*info.width;
		for (int x = info.offx; x < info.offx + info.width; x++)
		{
			memcpy(&redC[offset2], &redPtr[offset], sizeof(PTMCoefficient));
			memcpy(&greenC[offset2], &greenPtr[offset], sizeof(PTMCoefficient));
			memcpy(&blueC[offset2], &bluePtr[offset], sizeof(PTMCoefficient));
			offset++;
			offset2++;
		}
	}
	// Computes the enhanced coefficients
	enhancedCoeff(redC, info.width, info.height, 6);
	enhancedCoeff(greenC, info.width, info.height, 6);
	enhancedCoeff(blueC, info.width, info.height, 6);
	// Creates the output texture.	
	LightMemoized lVec(info.light.X(), info.light.Y());
	
	#pragma omp parallel for schedule(static,CHUNK)
	for (int y = info.offy; y < info.offy + info.height; y++)
	{
		int offsetBuf = (y-info.offy)*info.width*4;
		int offset2 = (y - info.offy)*info.width;
		for (int x = info.offx; x < info.offx + info.width; x++)
		{
			buffer[offsetBuf] = tobyte(redC[offset2].evalPoly(lVec)); 
			buffer[offsetBuf + 1] = tobyte(greenC[offset2].evalPoly(lVec));
			buffer[offsetBuf + 2] = tobyte(blueC[offset2].evalPoly(lVec));
			buffer[offsetBuf + 3] = 255;
			offsetBuf += 4;
			offset2++;
		}
	}
	delete[] redC;
	delete[] greenC;
	delete[] blueC;
}
Beispiel #3
0
void DiffuseGain::applyPtmLRGB(const PyramidCoeff& coeff, const PyramidRGB& rgb, const QSize* mipMapSize, const PyramidNormals& normals, const RenderingInfo& info, unsigned char* buffer)
{
	int offsetBuf = 0;
	const unsigned char* rgbPtr = rgb.getLevel(info.level);
	const PTMCoefficient* coeffPtr = coeff.getLevel(info.level);
	const vcg::Point3f* normalsPtr = normals.getLevel(info.level);
	// Creates the output texture.

    #pragma omp parallel for schedule(static,CHUNK)
	for (int y = info.offy; y < info.offy + info.height; y++)
	{
        int offsetBuf = ((y-info.offy)*info.width)<<2;
		int offset = y * mipMapSize[info.level].width() + info.offx;
		for (int x = info.offx; x < info.offx + info.width; x++)
		{
			//int offset = y * mipMapSize[info.level].width() + x;
            float lum = applyModel(&(coeffPtr[offset][0]), normalsPtr[offset].X(), normalsPtr[offset].Y(), info.light.X(), info.light.Y()) / 256.0f;
			int offset3 = offset*3;
			for (int i = 0; i < 3; i++)
				buffer[offsetBuf + i] = tobyte(rgbPtr[offset3 + i] * lum);
            buffer[offsetBuf + 3] = 255;
			offsetBuf += 4;
			offset++;
		}
	}
	//qDebug() << "gain = " << DiffuseGain::gain;
}
Beispiel #4
0
void SpecularEnhancement::applyPtmRGB(const PyramidCoeff& redCoeff, const PyramidCoeff& greenCoeff, const PyramidCoeff& blueCoeff, const QSize* mipMapSize, const PyramidNormals& normals, const RenderingInfo& info, unsigned char* buffer)
{
	// Creates the output texture.
	const PTMCoefficient* redPtr = redCoeff.getLevel(info.level);
	const PTMCoefficient* greenPtr = greenCoeff.getLevel(info.level);
	const PTMCoefficient* bluePtr = blueCoeff.getLevel(info.level);
	const vcg::Point3f* normalsPtr = normals.getLevel(info.level);
	LightMemoized lVec(info.light.X(), info.light.Y());
	
	#pragma omp parallel for schedule(static,CHUNK)
	for (int y = info.offy; y < info.offy + info.height; y++)
	{
		int offsetBuf = (y-info.offy)*info.width<<2;
		int offset = y * mipMapSize[info.level].width() + info.offx;
		for (int x = info.offx; x < info.offx + info.width; x++)
		{
			vcg::Point3f h(0, 0, 1);
			h += info.light;
			h /= 2;
			h.Normalize();
            float nDotH = h * normalsPtr[offset];
			if (nDotH < 0) 
				nDotH = 0.0;
			else if (nDotH > 1)
				nDotH = 1.0;
			nDotH = pow(nDotH, exp);
			float r = redPtr[offset].evalPoly(lVec);
			float g = greenPtr[offset].evalPoly(lVec);
            float b = bluePtr[offset].evalPoly(lVec);
			float temp = (r + g + b)/3;
            float lum =  temp * ks * 2 * nDotH;
			buffer[offsetBuf + 0] = tobyte( r * kd + lum);
			buffer[offsetBuf + 1] = tobyte( g * kd + lum );
			buffer[offsetBuf + 2] = tobyte( b * kd + lum );
			buffer[offsetBuf + 3] = 255;
			offsetBuf += 4;
			offset++;
		}
	}
}
Beispiel #5
0
void CoeffEnhancement::applyPtmLRGB(const PyramidCoeff& coeff, const PyramidRGB& rgb, const QSize* mipMapSize, const PyramidNormals& normals, const RenderingInfo& info, unsigned char* buffer)
{
	//int offsetBuf = 0;
	const PTMCoefficient* coeffPtr = coeff.getLevel(info.level);
	const unsigned char* rgbPtr = rgb.getLevel(info.level);
	PTMCoefficient* coeffMap = new PTMCoefficient[info.width*info.height];
	int width = mipMapSize[info.level].width();
	// Creates the map of the coefficients of the sub-image in the current view of the browser
	#pragma omp parallel for schedule(static,CHUNK)
	for (int y = info.offy; y < info.offy + info.height; y++)
	{
		int offset = y * width + info.offx;
		int offset2 = (y - info.offy)*info.width;
		for (int x = info.offx; x < info.offx + info.width; x++)
		{
			memcpy(coeffMap[offset2], coeffPtr[offset], sizeof(PTMCoefficient));
			offset++;
			offset2++;
		}
	}
	// Computes the enhanced coefficients.
	enhancedCoeff(coeffMap, info.width, info.height, 6);
	// Creates the output texture.
	LightMemoized lVec(info.light.X(), info.light.Y());
	
	#pragma omp parallel for schedule(static,CHUNK)
	for (int y = info.offy; y < info.offy + info.height; y++)
	{
                int offsetLoc = (y-info.offy)*info.width;
                int offsetBuf = offsetLoc << 2;
		int offset = y * width + info.offx;
		for (int x = info.offx; x < info.offx + info.width; x++)
		{
                        float lum = coeffMap[offsetLoc].evalPoly(lVec) / 255.0f;
			int offset3 = offset * 3;
			for (int i = 0; i < 3; i++)
				buffer[offsetBuf + i] = tobyte(rgbPtr[offset3 + i] * lum);
			buffer[offsetBuf + 3] = 255;
			offsetBuf +=4;
                        offset++;
                        offsetLoc++;
		}
	}
	delete[] coeffMap;
}
Beispiel #6
0
void SpecularEnhancement::applyPtmLRGB(const PyramidCoeff& coeff, const PyramidRGB& rgb, const QSize* mipMapSize, const PyramidNormals& normals, const RenderingInfo& info, unsigned char* buffer)
{
	// Creates the output texture.
	//int offsetBuf = 0;
	const PTMCoefficient* coeffPtr = coeff.getLevel(info.level);
	const unsigned char* rgbPtr = rgb.getLevel(info.level);
	const vcg::Point3f* normalsPtr = normals.getLevel(info.level);
	LightMemoized lVec(info.light.X(), info.light.Y());
	
	#pragma omp parallel for schedule(static,CHUNK) 
	for (int y = info.offy; y < info.offy + info.height; y++)
	{
		int offsetBuf = (y-info.offy)*info.width*4;
		int offset = y * mipMapSize[info.level].width() + info.offx;
		for (int x = info.offx; x < info.offx + info.width; x++)
		{
			float lum = coeffPtr[offset].evalPoly(lVec) / 255.0f;
            vcg::Point3f h(0, 0, 1);
			h += info.light;
			h /= 2;
			h.Normalize();
			float nDotH = h * normalsPtr[offset];
			if (nDotH < 0) 
				nDotH = 0.0;
			else if (nDotH > 1)
				nDotH = 1.0;
			nDotH = pow(nDotH, exp);
			nDotH *= ks*255;
			int offset3 = offset*3;
			for (int i = 0; i < 3; i++)
				buffer[offsetBuf + i]  = tobyte((rgbPtr[offset3 + i]*kd + nDotH)*lum);
			buffer[offsetBuf + 3] = 255;
			offsetBuf += 4;
			offset++;
		}
	}

}
Beispiel #7
0
void UnsharpMasking::applyPtmRGB(const PyramidCoeff& redCoeff, const PyramidCoeff& greenCoeff, const PyramidCoeff& blueCoeff, const QSize* mipMapSize, const PyramidNormals& normals, const RenderingInfo& info, unsigned char* buffer)
{
	int offsetBuf = 0;
	const PTMCoefficient* redPtr = redCoeff.getLevel(info.level);
	const PTMCoefficient* greenPtr = greenCoeff.getLevel(info.level);
	const PTMCoefficient* bluePtr = blueCoeff.getLevel(info.level);
	const vcg::Point3f* normalsPtr = normals.getLevel(info.level);
    float* lumMap = new float[info.width*info.height];
	int width = mipMapSize[info.level].width();
	if (type == 0) //classic unsharp masking
	{
        float* uvMap = new float[info.width*info.height*2];
		LightMemoized lVec(info.light.X(), info.light.Y());
        
		#pragma omp parallel for schedule(static,CHUNK)
		for (int y = info.offy; y < info.offy + info.height; y++)
		{
            int offsetBuf = (y-info.offy)*info.width<<2;
			int offset = y * width + info.offx;
			int offset2 = (y - info.offy)*info.width;
			for (int x = info.offx; x < info.offx + info.width; x++)
			{
				float r = redPtr[offset].evalPoly(lVec) / 255.0;//evalPoly((int*)&(redPtr[offset][0]), info.light.X(), info.light.Y()) / 255.0;
                float g = greenPtr[offset].evalPoly(lVec) / 255.0;//evalPoly((int*)&(greenPtr[offset][0]), info.light.X(), info.light.Y()) / 255.0;
                float b = bluePtr[offset].evalPoly(lVec) / 255.0;//evalPoly((int*)&(bluePtr[offset][0]), info.light.X(), info.light.Y()) / 255.0;
				getYUV(r, g, b, lumMap[offset2], uvMap[offset2*2], uvMap[offset2*2 + 1]);
				offset++;
				offset2++;
			}
		}
		enhancedLuminance(lumMap, info.width, info.height, info.mode);
		bool flag = (info.mode == LUM_UNSHARP_MODE || info.mode == SMOOTH_MODE || info.mode == CONTRAST_MODE || info.mode == ENHANCED_MODE);
		if (flag)
		{
			#pragma omp parallel for schedule(static,CHUNK)
			for (int y = info.offy; y < info.offy + info.height; y++)
			{
				int offsetBuf = (y-info.offy)*info.width<<2;
				int offset2 =(y - info.offy)*info.width; 
				for (int x = info.offx; x < info.offx + info.width; x++)
				{
					for (int i = 0; i < 3; i++)
						buffer[offsetBuf + i] = tobyte(lumMap[offset2] * 255.0);
					buffer[offsetBuf + 3] = 255;
					offsetBuf += 4;
					offset2++;
				}
			}
		}
		else
		{
			#pragma omp parallel for schedule(static,CHUNK)
			for (int y = info.offy; y < info.offy + info.height; y++)
			{
				int offsetBuf = (y-info.offy)*info.width<<2;
				int offset2 =(y - info.offy)*info.width; 
				for (int x = info.offx; x < info.offx + info.width; x++)
				{
					float r, g, b;
					getRGB(lumMap[offset2], uvMap[offset2*2], uvMap[offset2*2 +1], r, g, b);
					buffer[offsetBuf] = tobyte(r*255);
					buffer[offsetBuf + 1] = tobyte(g*255);
					buffer[offsetBuf + 2] = tobyte(b*255);
					buffer[offsetBuf + 3] = 255;
					offsetBuf += 4;
					offset2++;
				}
			}
		}
		delete[] uvMap;
	}
	else //luminance unsharp masking
	{
        #pragma omp parallel for schedule(static,CHUNK)
		for (int y = info.offy; y < info.offy + info.height; y++)
		{
			int offset= y * width + info.offx;
			int offset2 = (y - info.offy)*info.width;
			for (int x = info.offx; x < info.offx + info.width; x++)
			{
				lumMap[offset2] = getLum(normalsPtr[offset], info.light);
				offset++;
				offset2++;
			}
		}
		enhancedLuminance(lumMap, info.width, info.height, info.mode);
		bool flag = (info.mode == LUM_UNSHARP_MODE || info.mode == SMOOTH_MODE || info.mode == CONTRAST_MODE || info.mode == ENHANCED_MODE);
		LightMemoized lVec(info.light.X(), info.light.Y());
		if (flag)
		{
			#pragma omp parallel for schedule(static,CHUNK)
			for (int y = info.offy; y < info.offy + info.height; y++)
			{
				int offsetBuf = (y-info.offy)*info.width<<2;
				int offset = y * width + info.offx;
				int offset2 = (y - info.offy)*info.width;
				for (int x = info.offx; x < info.offx + info.width; x++)
				{
					float lum = lumMap[offset2];
					for (int i = 0; i < 3; i++)
						buffer[offsetBuf + i] = tobyte(lum / 2.0 * 255.0);
					buffer[offsetBuf + 3] = 255;
					offsetBuf += 4;
					offset++;
					offset2++;
				}
			}
		}
		else
		{
			#pragma omp parallel for schedule(static,CHUNK)
			for (int y = info.offy; y < info.offy + info.height; y++)
			{
				int offsetBuf = (y-info.offy)*info.width<<2;
				int offset = y * width + info.offx;
				int offset2 = (y - info.offy)*info.width;
				for (int x = info.offx; x < info.offx + info.width; x++)
				{
					float lum = lumMap[offset2];
					buffer[offsetBuf] = tobyte(redPtr[offset].evalPoly(lVec)*lum);//evalPoly((int*)&(redPtr[offset][0]), info.light.X(), info.light.Y()) * lum);
					buffer[offsetBuf + 1] = tobyte(greenPtr[offset].evalPoly(lVec)*lum);//evalPoly((int*)&(greenPtr[offset][0]), info.light.X(), info.light.Y()) * lum);
					buffer[offsetBuf + 2] = tobyte(bluePtr[offset].evalPoly(lVec)*lum);//evalPoly((int*)&(bluePtr[offset][0]), info.light.X(), info.light.Y()) * lum);
					buffer[offsetBuf + 3] = 255;
					offsetBuf += 4;
					offset++;
					offset2++;
				}
			}
		}
	}
	delete[] lumMap;
}
Beispiel #8
0
void UnsharpMasking::applyPtmLRGB(const PyramidCoeff& coeff, const PyramidRGB& rgb, const QSize* mipMapSize, const PyramidNormals& normals, const RenderingInfo& info, unsigned char* buffer)
{
	int offsetBuf = 0;
	const PTMCoefficient* coeffPtr = coeff.getLevel(info.level);
	const unsigned char* rgbPtr = rgb.getLevel(info.level);
    float* lumMap = new float[info.width*info.height];
	int width = mipMapSize[info.level].width();
	if (type == 0) //image unsharp masking
	{
		// Creates a map for Y component and a map for UV component. 
        float* uvMap = new float[info.width*info.height*2];
		LightMemoized lVec(info.light.X(), info.light.Y());
        
		#pragma omp parallel for schedule(static,CHUNK)
		for (int y = info.offy; y < info.offy + info.height; y++)
		{
            int offsetBuf = (y-info.offy)*info.width<<2;
			int offset = (y * width + info.offx)*3;
			int offset2 = ((y - info.offy)*info.width)*2;
			for (int x = info.offx; x < info.offx + info.width; x++)
			{
			    float lum =  coeffPtr[offset / 3].evalPoly(lVec) / 255.0;
                float r = rgbPtr[offset]*lum / 255.0;
                float g = rgbPtr[offset + 1]*lum / 255.0;
                float b = rgbPtr[offset + 2]*lum / 255.0;
				getYUV(r, g, b, lumMap[offset2 / 2], uvMap[offset2], uvMap[offset2 + 1]);
				offset += 3;
				offset2 += 2;
			}
		}
		// Computes the enhanced luminance.
		enhancedLuminance(lumMap, info.width, info.height, info.mode);
		// Creates the output texture.
		bool flag = (info.mode == LUM_UNSHARP_MODE || info.mode == SMOOTH_MODE || info.mode == CONTRAST_MODE ||info.mode == ENHANCED_MODE);
		if (flag)
		{
			#pragma omp parallel for schedule(static,CHUNK)
			for (int y = info.offy; y < info.offy + info.height; y++)
			{
				int offsetBuf = (y - info.offy) * info.width << 2;
				int offset2 =(y - info.offy) * info.width;
				for (int x = info.offx; x < info.offx + info.width; x++)
				{
					for (int i = 0; i < 3; i++)
						buffer[offsetBuf + i] = tobyte(lumMap[offset2] * 255.0);
					buffer[offsetBuf + 3] = 255;
					offsetBuf += 4;
					offset2++;
				}
			}
		}
		else
		{
			#pragma omp parallel for schedule(static,CHUNK)
			for (int y = info.offy; y < info.offy + info.height; y++)
			{
				int offsetBuf = (y - info.offy) * info.width << 2;
				int offset2 =(y - info.offy)*info.width * 2;
				for (int x = info.offx; x < info.offx + info.width; x++)
				{
					float r, g, b;
					getRGB(lumMap[offset2 / 2], uvMap[offset2], uvMap[offset2 + 1], r, g, b);
					buffer[offsetBuf ] = tobyte(r*255);
					buffer[offsetBuf + 1] = tobyte(g*255);
					buffer[offsetBuf + 2] = tobyte(b*255);
					buffer[offsetBuf + 3] = 255;
					offsetBuf += 4;
					offset2 += 2;
				}
			}
		}
		delete[] uvMap;
	}
	else //unsharp masking luminance
	{
		// Creates a map for the polynomial luminance.
		LightMemoized lVec(info.light.X(), info.light.Y());
		
		#pragma omp parallel for schedule(static,CHUNK)
		for (int y = info.offy; y < info.offy + info.height; y++)
		{
			int offset = y * width + info.offx;
			int offset2 = (y - info.offy)*info.width;
			for (int x = info.offx; x < info.offx + info.width; x++)
			{
				lumMap[offset2] = coeffPtr[offset].evalPoly(lVec) / 255.0;
				offset++;
				offset2++;
			}
		}
		// Computes the enhanced luminance
		enhancedLuminance(lumMap, info.width, info.height, info.mode);
		// Creates the output texture.
		bool flag = (info.mode == LUM_UNSHARP_MODE || info.mode == SMOOTH_MODE || info.mode == CONTRAST_MODE || info.mode == ENHANCED_MODE);
        if (flag)
		{
			#pragma omp parallel for schedule(static,CHUNK)
			for (int y = info.offy; y < info.offy + info.height; y++)
			{
				int offsetBuf = (y - info.offy) * info.width <<2;
				int offset2 = (y - info.offy) * info.width;
				for (int x = info.offx; x < info.offx + info.width; x++)
				{
					for (int i = 0; i < 3; i++)
						buffer[offsetBuf + i] = tobyte(lumMap[offset2] / 2.0 * 255.0);
					buffer[offsetBuf + 3] = 255;
					offsetBuf += 4;
					offset2++;
				}
			}
		}
		else
		{
			#pragma omp parallel for schedule(static,CHUNK)
			for (int y = info.offy; y < info.offy + info.height; y++)
			{
				int offsetBuf = (y - info.offy) * info.width << 2;
				int offset = (y * width + info.offx)*3;
				int offset2 = (y - info.offy) * info.width; 
				for (int x = info.offx; x < info.offx + info.width; x++)
				{
					for (int i = 0; i < 3; i++)
						buffer[offsetBuf + i] = tobyte(rgbPtr[offset + i] * lumMap[offset2]);
					buffer[offsetBuf + 3] = 255;
					offsetBuf += 4;
					offset += 3;
					offset2++;
				}
			}

		}
		
	}
	delete[] lumMap;
}