예제 #1
0
	void ImageUtils::convertBumpToNormal(fipImage &toConvert, float strength)
	{
		if (toConvert.getBitsPerPixel() < 24)
			toConvert.convertTo24Bits();
		const int w = toConvert.getWidth();
		const int h = toConvert.getHeight();

		for (int y = 0; y < h; ++y)
		{
			for (int x = 0; x < w; ++x)
			{
				RGBQUAD topLeft, top, topRight, left, right, bottomLeft, bottom, bottomRight;
				RGBQUAD current;

				toConvert.getPixelColor(glm::clamp(x - 1, 0, w - 1), glm::clamp(y - 1, 0, h - 1), &topLeft);
				toConvert.getPixelColor(x, glm::clamp(y - 1, 0, h - 1), &top);
				toConvert.getPixelColor(glm::clamp(x + 1, 0, w - 1), glm::clamp(y - 1, 0, h - 1), &topRight);
				toConvert.getPixelColor(glm::clamp(x - 1, 0, w - 1), y, &left);
				toConvert.getPixelColor(glm::clamp(x + 1, 0, w - 1), y, &right);
				toConvert.getPixelColor(glm::clamp(x - 1, 0, w - 1), glm::clamp(y + 1, 0, h - 1), &bottomLeft);
				toConvert.getPixelColor(x, glm::clamp(y + 1, 0, h - 1), &bottom);
				toConvert.getPixelColor(glm::clamp(x + 1, 0, w - 1), glm::clamp(y + 1, 0, h - 1), &bottomRight);

				toConvert.getPixelColor(x, y, &current);

				const float tl = intensity(topLeft);
				const float t = intensity(top);
				const float tr = intensity(topRight);
				const float l = intensity(left);
				const float r = intensity(right);
				const float bl = intensity(bottomLeft);
				const float b = intensity(bottom);
				const float br = intensity(bottomRight);

				glm::vec3 normal((tr + 2.0f * r + br) - (tl + 2.0f * l + bl),
					(bl + 2.0f * b + br) - (tl + 2.0f * t + tr),
					1.0f / strength);

				normal = (glm::normalize(normal) + 1.0f) * 0.5f * 255.0f;

				current.rgbRed = BYTE(normal.r);
				current.rgbGreen = BYTE(normal.g);
				current.rgbBlue = BYTE(normal.b);

				toConvert.setPixelColor(x, y, &current);
			}
		}
	}
예제 #2
0
	void ImageUtils::switchRedBlue(fipImage &image)
	{
		for (unsigned int y = 0; y < image.getHeight(); ++y)
		{
			for (unsigned int x = 0; x < image.getWidth(); ++x)
			{
				RGBQUAD color;

				image.getPixelColor(x, y, &color);
				BYTE r = color.rgbRed;
				color.rgbRed = color.rgbBlue;
				color.rgbBlue = r;
				image.setPixelColor(x, y, &color);
			}
		}

	}