Exemplo n.º 1
0
	// Minimal mock of VW imageio routines
	void ReadImage(const std::string& file, ImageRGB<byte>& image) {
		CHECK_PRED1(fs::exists, file);
		bool jpeg = IsJpegFilename(file);

		// Get size
		point2<ptrdiff_t> size;
		if (jpeg) {
			size = jpeg_read_dimensions(file);
		} else {
			size = png_read_dimensions(file);
		}

		// Allocate image data
		image.AllocImageData(size.x, size.y);
		rgba8_view_t v = interleaved_view(image.GetWidth(),
																			image.GetHeight(),
																			(rgba8_pixel_t*)image.GetImageBuffer(),
																			image.GetWidth()*sizeof(PixelRGB<byte>));

		// Load the image
		if (jpeg) {
			jpeg_read_and_convert_view(file, v);
		} else {
			png_read_and_convert_view(file, v);
		}

		// GIL uses 255=opaque but we use 0=opaque
		InvertAlpha(image);
	}
Exemplo n.º 2
0
	void GlutWindow::CaptureFrameBuffer(ImageRGB<byte>& out) const {
		CHECK(InGlutThread())
			<< "Frame buffer can only be captured inside the GLUT thread.";
		Flush();
		ResizeImage(out, size_);
		glReadPixels(0, 0, size_.x, size_.y,
								 GL_BGRA, GL_UNSIGNED_BYTE, out.GetImageBuffer());
		ResetAlpha(out);  // the GL convention for alpha is different to ours
		FlipVertical(out);  // the GL convention for top and bottom is different to ours
	}
Exemplo n.º 3
0
	void WriteImage(const std::string& file, const ImageRGB<byte>& image) {
		rgba8c_view_t v = interleaved_view(image.GetWidth(),
																			 image.GetHeight(),
																			 (const rgba8_pixel_t*)image.GetImageBuffer(),
																			 image.GetWidth()*sizeof(PixelRGB<byte>));
		// Here we use a hack to work around the fact that GIL uses
		// 255=opaque but we use 0=opaque
		InvertAlpha(const_cast<ImageRGB<byte>&>(image));
		if (IsJpegFilename(file)) {
			CHECK(false) << "jpeg output not supported";
			//jpeg_write_view(file, v);
		} else {
			png_write_view(file, v);
		}
		InvertAlpha(const_cast<ImageRGB<byte>&>(image));
	}