コード例 #1
0
ファイル: alice4view.cpp プロジェクト: bartgrantham/alice
void put_image(fipImage &img, int offsetx, int offsety, unsigned char *fb, int bytes_per_pixel, unsigned int bytes_per_row)
{
    RGBQUAD rgb;
    for (unsigned int j = 0; j < std::min(FRAMEBUFFER_HEIGHT, img.getHeight()); j++) {
        unsigned char* row = fb + bytes_per_row * (j + offsety);
	memset(row, 0, bytes_per_row);

        for (unsigned int i = 0; i < std::min(FRAMEBUFFER_WIDTH, img.getWidth()); i++) {
            img.getPixelColor(i, img.getHeight() - 1 - j, &rgb);
            unsigned char *pixel = row + (i + offsetx) * bytes_per_pixel;
            pixel[0] = rgb.rgbRed;
            pixel[1] = rgb.rgbGreen;
            pixel[2] = rgb.rgbBlue;
        }
    }
}
コード例 #2
0
void printImg(const char* file_out, const vector<pixel>& pixels, const vector<centroid>& centroids, const fipImage& input, const FREE_IMAGE_TYPE& originalType){
	//write image
	//allocate output image
	fipImage output(FIT_BITMAP, input.getWidth(), input.getHeight(), 24);

	for(unsigned int i = 0; i < output.getWidth(); ++i) {
		for(unsigned int j = 0; j < output.getHeight(); ++j) {
			byte colors[4];
			int cluster = pixels[j * output.getWidth() + i].cluster;
			if(cluster==-1)cluster=0;
			colors[0] = static_cast<byte>(centroids[cluster].b * 255);
			colors[1] = static_cast<byte>(centroids[cluster].g * 255);
			colors[2] = static_cast<byte>(centroids[cluster].r * 255);

			output.setPixelColor(i, j, reinterpret_cast<RGBQUAD*>(colors));
		}
	}

	if(!output.convertToType(originalType)) {
		cout << "Could not convert back to 24 bits for image saving." << endl;
	}

	if(!output.save(file_out)) {
		cout << "Something went wrong with filesaving" << endl;
	}
}
コード例 #3
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);
			}
		}
	}
コード例 #4
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);
			}
		}

	}
コード例 #5
0
ファイル: fipImage.cpp プロジェクト: MrMasterplan/PIC-stuff
BOOL fipImage::combineChannels(fipImage& red, fipImage& green, fipImage& blue) {
	if(!_dib) {
		int width = red.getWidth();
		int height = red.getHeight();
		_dib = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
	}

	if(_dib) {
		BOOL bResult = TRUE;
		bResult &= FreeImage_SetChannel(_dib, red._dib, FICC_RED);
		bResult &= FreeImage_SetChannel(_dib, green._dib, FICC_GREEN);
		bResult &= FreeImage_SetChannel(_dib, blue._dib, FICC_BLUE);

		_bHasChanged = TRUE;

		return bResult;
	}
	return FALSE;
}