コード例 #1
0
ファイル: diffusegain.cpp プロジェクト: WeiqiJust/CHER-Ob
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;
}
コード例 #2
0
ファイル: coeffenhanc.cpp プロジェクト: WeiqiJust/CHER-Ob
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;
}
コード例 #3
0
ファイル: specularenhanc.cpp プロジェクト: WeiqiJust/CHER-Ob
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++;
		}
	}

}
コード例 #4
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;
}