Пример #1
0
/* Exports the left and right eye view as images */
void exportImage(void) {
	unsigned char *image;
	image = (unsigned char*)malloc((3*Settings::pixelWidth*Settings::pixelHeight)*sizeof(char));
	
	
	glPixelStorei(GL_PACK_ALIGNMENT,1);
	
	// Left Image
	glReadBuffer(GL_BACK_LEFT);
	glReadPixels(0, 0, (int)Settings::pixelWidth, (int)Settings::pixelHeight, 
				 GL_BGR,GL_UNSIGNED_BYTE, image);
	
	FIBITMAP* leftImage = FreeImage_ConvertFromRawBits(image, (int)Settings::pixelWidth, 
													   (int)Settings::pixelHeight, 
													   3*Settings::pixelWidth, 24, 0xFF0000, 
													   0x00FF00, 0x0000FF, false); 
	FreeImage_Save(FIF_BMP, leftImage, "left.bmp", 0);
	
	// Right image
	glReadBuffer(GL_BACK_RIGHT);
	glReadPixels(0, 0, (int)Settings::pixelWidth, (int)Settings::pixelHeight,
				 GL_BGR, GL_UNSIGNED_BYTE, image);
	
	FIBITMAP* rightImage = FreeImage_ConvertFromRawBits(image, (int)Settings::pixelWidth, 
														(int)Settings::pixelHeight, 
														3*Settings::pixelWidth, 24, 0xFF0000, 
														0x00FF00, 0x0000FF, false); 
	FreeImage_Save(FIF_BMP, rightImage, "right.bmp", 0);
	
	free(image);
}
Пример #2
0
bool process_image(std::string infile, std::string outfile, double brightness, double gamma)
{
	DIR *editdir = opendir("img/edit");
	struct dirent *file;
	while ((file = readdir(editdir)) != NULL)
	{
		if (strcmp(file -> d_name, outfile.c_str()) == 0)
		{
			return false;
		}
	}
	closedir(editdir);
	infile = "img/" + infile;
	outfile = "img/edit/" + outfile;
	FIBITMAP *input = FreeImage_Load(FIF_PNG, infile.c_str());
	if (input == NULL)
	{
		std::cerr << "Failed to load " << infile << std::endl;
		exit(1);
	}
	if (!FreeImage_Save(FIF_PNG, input, outfile.c_str()))
	{
		FreeImage_Unload(input);
		std::cerr << "Failed to save " << outfile << std::endl;
		exit(1);
	}
	FreeImage_Unload(input);
	FIBITMAP *output = FreeImage_Load(FIF_PNG, outfile.c_str());
	if (output == NULL)
	{
		std::cerr << "Failed to load " << outfile << std::endl;
		exit(1);
	}
	unsigned int img_w = FreeImage_GetWidth(output);
	unsigned int img_h = FreeImage_GetHeight(output);
	RGBQUAD pixel;
	for (unsigned int x = 0; x < img_w; x++)
	{
		for (unsigned int y = 0; y < img_h; y++)
		{
			FreeImage_GetPixelColor(output, x, y, &pixel);
			pixel.rgbRed = int(clamp(0, pixel.rgbRed * brightness, 255));
			pixel.rgbBlue = int(clamp(0, pixel.rgbBlue * brightness, 255));
			pixel.rgbGreen = int(clamp(0, pixel.rgbGreen * brightness, 255));
			pixel.rgbRed = int(clamp(0, pow(((double) pixel.rgbRed) / 255.0f, gamma) * 255.0, 255));
			pixel.rgbBlue = int(clamp(0, pow(((double) pixel.rgbBlue) / 255.0f, gamma) * 255.0, 255));
			pixel.rgbGreen = int(clamp(0, pow(((double) pixel.rgbGreen) / 255.0f, gamma) * 255.0, 255));
			FreeImage_SetPixelColor(output, x, y, &pixel);
		}
	}
	if (!FreeImage_Save(FIF_PNG, output, outfile.c_str()))
	{
		FreeImage_Unload(input);
		std::cerr << "Failed to save " << outfile << std::endl;
		exit(1);
	}
	FreeImage_Unload(output);
	return true;
}
Пример #3
0
  void storeFreeImage(const Ref<Image>& img, const FileName& fileName)
  {
      FIBITMAP* dib = FreeImage_Allocate((int)img->width, (int)img->height, 24);

      for(size_t y = 0; y < img->height; y++)
      {
          for(size_t x = 0; x < img->width; x++)
          {
			  Color4 c = img->get(x, y);
              
              RGBQUAD Value = {0};
              Value.rgbRed   = (BYTE)(clamp(c.r) * 255.0f);
              Value.rgbGreen = (BYTE)(clamp(c.g) * 255.0f);
              Value.rgbBlue  = (BYTE)(clamp(c.b) * 255.0f);

              FreeImage_SetPixelColor(dib, (unsigned int)x, (unsigned int)y, &Value);
          }
      }

      FIBITMAP* fiLogo = loadWatermark();

      unsigned int LogoWidth  = FreeImage_GetWidth (fiLogo);
      unsigned int LogoHeight = FreeImage_GetHeight(fiLogo);

      if(LogoWidth > img->width || LogoHeight > img->height)
      {
          FreeImage_Unload(fiLogo);

          FREE_IMAGE_FORMAT fif = FreeImage_GetFIFFromFilename(fileName.c_str());
          if(FreeImage_FIFSupportsWriting(fif))
              FreeImage_Save(fif, dib, fileName.c_str());

          FreeImage_Unload(dib);
      }
      else
      {
          int x_pos = (int)img->width  - LogoWidth;
          int y_pos = (int)img->height - LogoHeight;

          FIBITMAP* fiFG = FreeImage_Allocate((int)img->width, (int)img->height, 32);
          BOOL b = FreeImage_Paste(fiFG, fiLogo, x_pos, y_pos, 255);
          FreeImage_Unload(fiLogo);

          FIBITMAP* fiNew = FreeImage_Composite(fiFG, FALSE, NULL, dib);
          FreeImage_Unload(dib);

          FREE_IMAGE_FORMAT fif = FreeImage_GetFIFFromFilename(fileName.c_str());

          int save_flags = 0;
          if(fif == FIF_JPEG)
              save_flags = JPEG_QUALITYSUPERB | JPEG_BASELINE | JPEG_OPTIMIZE;

          if(FreeImage_FIFSupportsWriting(fif))
              FreeImage_Save(fif, fiNew, fileName.c_str(), save_flags);

          FreeImage_Unload(fiNew);
      }
  }
Пример #4
0
//----------------------------------------------------------------
void  ofImage::saveImageFromPixels(string fileName, ofPixels &pix){

	if (pix.bAllocated == false){
		ofLog(OF_LOG_ERROR,"error saving image - pixels aren't allocated");
		return;
	}

	#ifdef TARGET_LITTLE_ENDIAN
		if (pix.bytesPerPixel != 1) swapRgb(pix);
	#endif

	FIBITMAP * bmp	= getBmpFromPixels(pix);

	#ifdef TARGET_LITTLE_ENDIAN
		if (pix.bytesPerPixel != 1) swapRgb(pix);
	#endif

	fileName = ofToDataPath(fileName);
	if (pix.bAllocated == true){
		FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
		fif = FreeImage_GetFileType(fileName.c_str(), 0);
		if(fif == FIF_UNKNOWN) {
			// or guess via filename
			fif = FreeImage_GetFIFFromFilename(fileName.c_str());
		}
		if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) {
			FreeImage_Save(fif, bmp, fileName.c_str(), 0);
		}
	}

	if (bmp != NULL){
		FreeImage_Unload(bmp);
	}
}
Пример #5
0
bool SaveTextureToFile(const char* filename, const void* data,  int w, int h)
{
	bool ret = false;
	FIBITMAP* bitmap = nullptr;

	bitmap = FreeImage_AllocateT(FIT_BITMAP, w, h, 32);
	CHECK(bitmap);

	RGBQUAD dst;
	const Color* imageData = (const Color*)data;
	for (int y = 0; y < h; ++y)
	{
		for (int x = 0; x < w; ++x)
		{
			const Color& src = imageData[((h - 1 - y) * w + x)];
			dst.rgbBlue = (BYTE)(src.b * 255);
			dst.rgbGreen = (BYTE)(src.g * 255);
			dst.rgbRed = (BYTE)(src.r * 255);
			dst.rgbReserved = 255;
			CHECK(FreeImage_SetPixelColor(bitmap, x, y, &dst));
		}
	}

	CHECK(FreeImage_Save(FIF_BMP, bitmap, filename, BMP_DEFAULT));

	ret = true;
Exit0:
	if (bitmap)
		FreeImage_Unload(bitmap);
	return ret;
}
Пример #6
0
static int
write_img(char *name, const greyscale_image *img) {
  FIBITMAP *image;
  RGBQUAD aPixel;
  int i,j;

  image = FreeImage_Allocate(img->width, img->height, 24, 0, 0, 0);
  if(!image) {
    perror("FreeImage_Allocate");
    return -1;
  }
  for(i = 0; i < img->height; i++) {
    for(j = 0; j < img->width; j++) {
      float v = img->v[i*img->width + j];
      if (v > 1.0) v = 1.0;
      else if (v < 0) v = 0.0;
      v *= 255.0;

      aPixel.rgbRed = (unsigned char) v;
      aPixel.rgbGreen = (unsigned char) v;
      aPixel.rgbBlue = (unsigned char) v;

      FreeImage_SetPixelColor(image, j, i, &aPixel);
    }
  }
  if(!FreeImage_Save(FIF_JPEG, image, name, 0)) {
    perror("FreeImage_Save");
  }
  FreeImage_Unload(image);

  return 0;
}
Пример #7
0
  void write_image(const string& file, const SampleBuffer& buffer)
  {
    const float samples = static_cast<float>(buffer.samples());
    FIBITMAP* dib = FreeImage_Allocate(buffer.width(), buffer.height(),
        32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);

    const unsigned int BYTESPP =
      FreeImage_GetLine(dib) / FreeImage_GetWidth(dib);
    for (unsigned int y = 0; y < FreeImage_GetHeight(dib); ++y) {
      BYTE* bits = FreeImage_GetScanLine(dib, y);

      for (unsigned int x = 0; x < FreeImage_GetWidth(dib); ++x) {
        vec3 c = gamma_correct(buffer.get(x, y) / samples) * 255.0f;
        bits[FI_RGBA_RED]   = static_cast<BYTE>(c.r);
        bits[FI_RGBA_GREEN] = static_cast<BYTE>(c.g);
        bits[FI_RGBA_BLUE]  = static_cast<BYTE>(c.b);
        bits[FI_RGBA_ALPHA] = 255;

        bits += BYTESPP;
      }
    }

    if (!FreeImage_Save(FIF_PNG, dib, file.c_str(), 0)) {
      string err = "Failed to save screenshot to file '";
      err += file;
      err += '\'';
      throw err;
    }

    FreeImage_Unload(dib);
  }
Пример #8
0
void test32BitsChannels(unsigned width, unsigned height) {
	BOOL bResult = FALSE;

	// create a test 8-bit image
	FIBITMAP *src = createZonePlateImage(width, height, 128);
	if(src != NULL) {
		// convert to 32-bit
		FIBITMAP *tmp = FreeImage_ConvertTo32Bits(src);
		FreeImage_Unload(src);
		src = tmp;
	}
	assert(src != NULL);

	// save for further examination
	bResult = FreeImage_Save(FIF_PNG, src, "zoneplate.png", PNG_DEFAULT);
	assert(bResult);

	// test get/set channel
	// -------------------------	
	FIBITMAP *channel = FreeImage_GetChannel(src, FICC_ALPHA);
	assert(channel != NULL);
	bResult = FreeImage_SetChannel(src, channel, FICC_ALPHA);
	assert(bResult);	
	FreeImage_Unload(channel);

	FreeImage_Unload(src);
}
Пример #9
0
BOOL fipImage::save(const char* lpszPathName, int flag) const {
	FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
	BOOL bSuccess = FALSE;

	// Try to guess the file format from the file extension
	fif = FreeImage_GetFIFFromFilename(lpszPathName);
	if(fif != FIF_UNKNOWN ) {
		// Check that the dib can be saved in this format
		BOOL bCanSave;

		FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(_dib);
		if(image_type == FIT_BITMAP) {
			// standard bitmap type
			WORD bpp = FreeImage_GetBPP(_dib);
			bCanSave = (FreeImage_FIFSupportsWriting(fif) && FreeImage_FIFSupportsExportBPP(fif, bpp));
		} else {
			// special bitmap type
			bCanSave = FreeImage_FIFSupportsExportType(fif, image_type);
		}

		if(bCanSave) {
			bSuccess = FreeImage_Save(fif, _dib, lpszPathName, flag);
			return bSuccess;
		}
	}
	return bSuccess;
}
Пример #10
0
/** Generic image writer
@param dib Pointer to the dib to be saved
@param lpszPathName Pointer to the full file name
@param flag Optional save flag constant
@return Returns true if successful, returns false otherwise
*/
bool GenericWriter(const bitmap_ptr& dib, const std::string& lpszPathName, int flag) {
	auto fif = FIF_UNKNOWN;
	auto bSuccess = FALSE;
	// check if file path is not empty
	if (lpszPathName.empty())
		return false;
	if (dib) {
		// try to guess the file format from the file extension
		fif = FreeImage_GetFIFFromFilename(lpszPathName.c_str());
		if (fif != FIF_UNKNOWN) {
			// check that the plugin has sufficient writing and export capabilities ...
			if (FreeImage_FIFSupportsWriting(fif) && FreeImage_FIFSupportsExportType(fif, FreeImage_GetImageType(dib.get()))) {
				// ok, we can save the file
				bSuccess = FreeImage_Save(fif, dib.get(), lpszPathName.c_str(), flag);
				// unless an abnormal bug, we are done !
			}
			else {
				std::cout << "Can't save file" << lpszPathName << std::endl;
			}
		}
    else {
      std::cerr << "Can't determine output file type" << std::endl;
    }
	}
	return (bSuccess == TRUE);
}
Пример #11
0
bool ZitexConverter::convert(const QString & inFileName, const ConfigDao & configuration)
{
   auto inFileNameStdStr = inFileName.toStdString();

   Zitex::Reader reader;
   Zitex::Reader::Data data;

   reader.readFromFile(inFileNameStdStr, data);

   for (uint32_t it = 0; it < data.header->texImagesNum; ++it)
   {
      Zitex::TexImageHeader * texImageHeader = data.texImages[it].header;

      if (texImageHeader->level == 0)
      {
         auto width = texImageHeader->width;
         auto height = texImageHeader->height;

         FIBITMAP * fiBitmap = FreeImage_Allocate(width, height, 32);

         squish::DecompressImage(FreeImage_GetBits(fiBitmap), width, height, data.texImages[it].data,
                                 data.header->squishFlags);

         // section(".", 0, -2) copyes from begin to 2nd section from end.
         // The first section from end is the extension

         std::string outFileNameStdStr = inFileName.section(".", 0, -2).append(".png").toStdString();

         FreeImage_FlipVertical(fiBitmap);
         FreeImage_Save(FIF_PNG, fiBitmap, outFileNameStdStr.c_str());

         FreeImage_Unload(fiBitmap);
      }
   }
}
Пример #12
0
bool RGBAImage::WriteToFile(const char* filename)
{
	const FREE_IMAGE_FORMAT fileType = FreeImage_GetFIFFromFilename(filename);
	if(FIF_UNKNOWN == fileType)
	{
		printf("Can't save to unknown filetype %s\n", filename);
		return false;
	}

	FIBITMAP* bitmap = FreeImage_Allocate(Width, Height, 32, 0x000000ff, 0x0000ff00, 0x00ff0000);
	if(!bitmap)
	{
		printf("Failed to create freeimage for %s\n", filename);
		return false;
	}

	const unsigned int* source = Data;
	for( int y=0; y < Height; y++, source += Width )
	{
		unsigned int* scanline = (unsigned int*)FreeImage_GetScanLine(bitmap, Height - y - 1 );
		memcpy(scanline, source, sizeof(source[0]) * Width);
	}

	FreeImage_SetTransparent(bitmap, true);
	FIBITMAP* converted = FreeImage_ConvertTo24Bits(bitmap);


	const bool result = !!FreeImage_Save(fileType, converted, filename);
	if(!result)
		printf("Failed to save to %s\n", filename);

	FreeImage_Unload(converted);
	FreeImage_Unload(bitmap);
	return result;
}
Пример #13
0
void Film::output(string path){
  int maxIntensity = 255;
  int bpp = 24;
  RGBQUAD color;
  FreeImage_Initialise();
  FIBITMAP* bitmap = FreeImage_Allocate(sceneWidth,
					sceneHeight,
					bpp);
  for(int h = 0; h < sceneHeight; h++){
    vector<Color> row = pixelData[h];
    for(int w = 0; w < sceneWidth; w++){
      Color pixelColor = row[w];
      color.rgbRed = pixelColor.getR() * maxIntensity;
      color.rgbGreen = pixelColor.getG() * maxIntensity;
      color.rgbBlue = pixelColor.getB() * maxIntensity;
      FreeImage_SetPixelColor(bitmap, w, h, &color);
    }
  }
  if (FreeImage_Save(FIF_PNG, bitmap, path.c_str(), 0)) {
    cout << "Image saved to " << path << endl;
    cout << sceneWidth << endl;
  }
  else {
    cerr << "Couldn't save image to " << path << endl;
    exit(1);
  }

  FreeImage_DeInitialise();
}
Пример #14
0
void pre_lzw::do_lzw(const QDir & d){
    FreeImage_Initialise(true);
    QString label_out = "";
    QString dst = ui.lineEdit_2->text();
    QString d_src = d.path();
    QString serial_str = d_src.right(5);
    QDir dst_dir(dst);
    dst_dir.mkdir(serial_str);
    QString image_name = "", image_name_path(""), saved_name("");
    int dot_pos = 0;
    QFileInfoList handled_images = d.entryInfoList();
    QList<QFileInfo>::iterator images_iter = handled_images.begin();
    
    FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
    for(; images_iter < handled_images.end(); ++images_iter){
        image_name_path = (*images_iter).absoluteFilePath();
        if((*images_iter).isDir()){
            continue;
        }
        FIBITMAP *handled_image = 0;
        image_name = (*images_iter).fileName();
        dot_pos = image_name.indexOf(".");
        saved_name = dst + "\\" + serial_str + "\\" + image_name.left(dot_pos) + "_c.tif";
        label_out += saved_name + "\n";
        fif = FreeImage_GetFileType(image_name_path.toStdString().c_str());
        handled_image = FreeImage_Load(fif, image_name_path.toStdString().c_str());
        FreeImage_Save(FIF_TIFF, handled_image, saved_name.toStdString().c_str(), TIFF_LZW);
        FreeImage_Unload(handled_image);
    }
//    ui.label->setText(label_out);
    FreeImage_DeInitialise();

}
Пример #15
0
/**
Test loading from a buffer attached to a memory stream
*/
void testLoadMemIO(const char *lpszPathName) {
	struct stat buf;
	int result;

	// get data associated with lpszPathName
	result = stat(lpszPathName, &buf);
	if(result == 0) {
		// allocate a memory buffer and load temporary data
		BYTE *mem_buffer = (BYTE*)malloc(buf.st_size * sizeof(BYTE));
		if(mem_buffer) {
			FILE *stream = fopen(lpszPathName, "rb");
			if(stream) {
				fread(mem_buffer, sizeof(BYTE), buf.st_size, stream);
				fclose(stream);

				// attach the binary data to a memory stream
				fipMemoryIO memIO(mem_buffer, buf.st_size);

				// get the file type
				FREE_IMAGE_FORMAT fif = memIO.getFileType();

				// load an image from the memory stream
				FIBITMAP *check = memIO.read(fif, PNG_DEFAULT);

				// save as a regular file
				FreeImage_Save(FIF_PNG, check, "blob.png", PNG_DEFAULT);
				
				// close the stream (memIO is destroyed)
			}

			// user is responsible for freeing the data
			free(mem_buffer);
		}
	}
}
Пример #16
0
//----------------------------------------------------------------
void ofSaveImage(ofPixels & pix, string fileName, ofImageQualityType qualityLevel) {

	if (pix.isAllocated() == false){
		ofLog(OF_LOG_ERROR,"error saving image - pixels aren't allocated");
		return;
	}

	#ifdef TARGET_LITTLE_ENDIAN
		pix.swapRgb();
	#endif

	FIBITMAP * bmp	= getBmpFromPixels(pix);

	#ifdef TARGET_LITTLE_ENDIAN
		pix.swapRgb();
	#endif
	
	fileName = ofToDataPath(fileName);
	FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
	fif = FreeImage_GetFileType(fileName.c_str(), 0);
	if(fif == FIF_UNKNOWN) {
		// or guess via filename
		fif = FreeImage_GetFIFFromFilename(fileName.c_str());
	}
	if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) {
		if(fif == FIF_JPEG) {
			int quality = JPEG_QUALITYSUPERB;
			switch(qualityLevel) {
				case OF_IMAGE_QUALITY_WORST: quality = JPEG_QUALITYBAD; break;
				case OF_IMAGE_QUALITY_LOW: quality = JPEG_QUALITYAVERAGE; break;
				case OF_IMAGE_QUALITY_MEDIUM: quality = JPEG_QUALITYNORMAL; break;
				case OF_IMAGE_QUALITY_HIGH: quality = JPEG_QUALITYGOOD; break;
				case OF_IMAGE_QUALITY_BEST: quality = JPEG_QUALITYSUPERB; break;
			}
			FreeImage_Save(fif, bmp, fileName.c_str(), quality);
		} else {
			if(qualityLevel != OF_IMAGE_QUALITY_BEST) {
				ofLog(OF_LOG_WARNING, "ofImageCompressionType only applies to JPEG images, ignoring value.");
			}
			FreeImage_Save(fif, bmp, fileName.c_str());
		}
	}

	if (bmp != NULL){
		FreeImage_Unload(bmp);
	}
}
Пример #17
0
///
//  Save an image using the FreeImage library
//
bool SaveImage(char *fileName, char *buffer, int width, int height)
{
    FREE_IMAGE_FORMAT format = FreeImage_GetFIFFromFilename(fileName);
    FIBITMAP *image = FreeImage_ConvertFromRawBits((BYTE*)buffer, width,
                        height, width * 4, 32,
                        0xFF000000, 0x00FF0000, 0x0000FF00);
    return (FreeImage_Save(format, image, fileName) == TRUE) ? true : false;
}
Пример #18
0
void rtgu::image_io::write_image(char const* filename, any_image const& image)
{
  FREE_IMAGE_FORMAT fi_image_format = FreeImage_GetFIFFromFilename(filename);

  FIBITMAP* fi_image = detail::get_FIBITMAP(image);

  BOOL result = FreeImage_Save(fi_image_format, fi_image, filename);
}
Пример #19
0
    //---------------------------------------------------------------------
    void FreeImageCodec::codeToFile(MemoryDataStreamPtr& input,
        const String& outFileName, Codec::CodecDataPtr& pData) const
    {
        FIBITMAP* fiBitmap = encode(input, pData);

        FreeImage_Save((FREE_IMAGE_FORMAT)mFreeImageType, fiBitmap, outFileName.c_str());
        FreeImage_Unload(fiBitmap);
    }
Пример #20
0
void ImagePNG::save(std::string name)
{
	std::string filename = name+".png";
	if(bitmap != nullptr)
	{
		FreeImage_Save(FIF_PNG,bitmap,filename.c_str(),0);
	}
}
Пример #21
0
/**
 * This method saves the image to an given file.
 * The image type will determined by the file ending.
 *
 * @param szFile the path of the image file to save
 * @return true if the image data was saved, else false
 */
bool fipImage::save( const char * szFile ) const{

	FREE_IMAGE_FORMAT freeImageFormat = FreeImage_GetFIFFromFilename( szFile );
	if ( freeImageFormat == FIF_UNKNOWN ){
		return false;
	}
	
	return FreeImage_Save( freeImageFormat, pImageData, szFile);
}
Пример #22
0
int main(int argc, char** argv)
{
  int winx = 1920;
  int winy = 1080;

  glfwInit();

  glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
  glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 4);

  GLFWwindow* window = glfwCreateWindow(winx, winy, "IGS View GLFW", NULL, NULL);
  if (!window) {
    glfwTerminate();
    return -1;
  }

  glfwSetKeyCallback(window, glfw_key);
  glfwSetMouseButtonCallback(window, glfw_mousebutton);
  glfwSetCursorPosCallback(window, glfw_motion);

  /* Make the window's context current */
  glfwMakeContextCurrent(window);

  glewExperimental = true;
  glewInit();

  the_app = std::make_shared<application>(argc, argv, winx, winy);

  bool result_feedback = false;

  /* Loop until the user closes the window */
  while (!glfwWindowShouldClose(window))
  {
    glut_display();
#if 1
    if (!result_feedback) {
      std::vector<std::array<uint8_t, 3>> data(winx*winy);
      glReadPixels(0, 0, winx, winy, GL_RGB, GL_UNSIGNED_BYTE, &data[0]);

      FIBITMAP* image = FreeImage_ConvertFromRawBits((unsigned char*)&data[0], winx, winy, 3 * winx, 24, 0xFF0000, 0x00FF00, 0x0000FF, false);
      FreeImage_Save(FIF_BMP, image, "result.bmp", 0);
      FreeImage_Unload(image);

      result_feedback = true;
    }
#endif
    glfwSwapBuffers(window);
    glfwPollEvents();
  }

  glfwTerminate();

  the_app.reset();

  return 0;
}
Пример #23
0
//you can pass 0 for width or height to keep aspect ratio
bool resizeImage(const std::string& path, int maxWidth, int maxHeight)
{
	// nothing to do
	if(maxWidth == 0 && maxHeight == 0)
		return true;

	FREE_IMAGE_FORMAT format = FIF_UNKNOWN;
	FIBITMAP* image = NULL;
	
	//detect the filetype
	format = FreeImage_GetFileType(path.c_str(), 0);
	if(format == FIF_UNKNOWN)
		format = FreeImage_GetFIFFromFilename(path.c_str());
	if(format == FIF_UNKNOWN)
	{
		LOG(LogError) << "Error - could not detect filetype for image \"" << path << "\"!";
		return false;
	}

	//make sure we can read this filetype first, then load it
	if(FreeImage_FIFSupportsReading(format))
	{
		image = FreeImage_Load(format, path.c_str());
	}else{
		LOG(LogError) << "Error - file format reading not supported for image \"" << path << "\"!";
		return false;
	}

	float width = (float)FreeImage_GetWidth(image);
	float height = (float)FreeImage_GetHeight(image);

	if(maxWidth == 0)
	{
		maxWidth = (int)((maxHeight / height) * width);
	}else if(maxHeight == 0)
	{
		maxHeight = (int)((maxWidth / width) * height);
	}

	FIBITMAP* imageRescaled = FreeImage_Rescale(image, maxWidth, maxHeight, FILTER_BILINEAR);
	FreeImage_Unload(image);

	if(imageRescaled == NULL)
	{
		LOG(LogError) << "Could not resize image! (not enough memory? invalid bitdepth?)";
		return false;
	}

	bool saved = FreeImage_Save(format, imageRescaled, path.c_str());
	FreeImage_Unload(imageRescaled);

    if(!saved) {
		LOG(LogError) << "Failed to save resized image!";
    }

	return saved;
}
Пример #24
0
bool SaveImage(Graphics::TBitmap* picture, AnsiString path, TYPE bit_per_pixel, int flags)
{
	FIBITMAP *image = FreeImage_Allocate(picture->Width, picture->Height, 32);
	if(!image) return false;
	
	picture->PixelFormat = pf32bit;
	
	if(!WriteImage(image, picture))
	{
		FreeImage_Unload(image);
		return false;
	}

	AnsiString ext((((AnsiString)ExtractFileExt(path))).UpperCase());

	if (ext == ".BMP")
	{
		if(FreeImage_Save(FIF_BMP, BitrateConversion(image,bit_per_pixel), path.c_str(), BMP_DEFAULT))
		{
			FreeImage_Unload(image);
			return true;
		}	
	}	
	else if (ext == ".JPG")
	{
		if(FreeImage_Save(FIF_JPEG, FreeImage_ConvertTo24Bits(image), path.c_str(), flags))
		{
			FreeImage_Unload(image);
			return true;
		}
	}		
	else if (ext == ".TIF")
	{
		if(FreeImage_Save(FIF_TIFF, FreeImage_ConvertTo24Bits(image), path.c_str(), TIFF_DEFAULT))
		{
			FreeImage_Unload(image);
			return true;
		}	
	}
		
	FreeImage_Unload(image);
	return false;
}
int main (int argc, char ** argv)
{
	if (argc != 2){
		printf("you need to give me the number of frames to captures\n");
		exit(-1);
	}
	int num_frames = atoi(argv[1]);
	initialize_pru();
	start_pru();
	FILE * image_data = fopen("/media/usb/image.data", "w");
	if (image_data == NULL){
		fprintf(stderr, "Failed to open image output file");
		exit(-1);
	}

	const char  *version = FreeImage_GetVersion();
	printf("Freeimage version %s\n", version);

	FIBITMAP* dib = FreeImage_Allocate(320, 203, 16, 0xF800, 0x07E0,0x001F); // allocate 320x203 RGB565 bitmap

	int bytespp = FreeImage_GetLine(dib)/FreeImage_GetWidth(dib);

	FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib);

	if (image_type == FIT_BITMAP){
		printf("1\n");
	}

	printf("%d %d\n", FreeImage_GetHeight(dib), FreeImage_GetWidth(dib));

	BYTE * bits = FreeImage_GetBits(dib);
	FILE * fp = fopen("image.data", "rb");
	char filename[] = "/root/1314-BeagleBone-Quadcopter/code/ControlTower/ramfs/latest_image.bmp";
	int i = 0;

	for (i = 0; i < num_frames; i++){
		while(i==pruDataMem_int[100]){usleep(100000);}
		int buffer = pruDataMem_int[1];
		printf("%d buffer=%d\n", pruDataMem_int[100], buffer);
		if (i%10==0){
			memcpy(bits, pru1_ddr+buffer*320*240*2, 320*203*2);
			FreeImage_Save(FIF_BMP, dib, filename,0);
		}
	}
	uninitialize_pru();
	fflush(image_data);
	printf("%d\n", ((volatile uint8_t *)pru1_ddr)[0]);
	fclose(image_data);

	prussdrv_pru_disable (PRU_NUM);
	prussdrv_exit ();

	return(0);
}
Пример #26
0
void WindowGL::screenshot(std::string filename)
{
	unsigned char* buffer = new unsigned char[800 * 600 * 3]; //TODO: dodac sciaganie wymiarow okna z WindowGL
	glReadPixels(0, 0, SIZE_W, SIZE_H, GL_BGR, GL_UNSIGNED_BYTE, buffer);
	std::cout << "INFO: Saving screen to: " << filename << std::endl;
	FIBITMAP * bitmap = FreeImage_ConvertFromRawBits(buffer, SIZE_W, SIZE_H, 800 * 3, 24, 0xFF0000, 0x00FF00, 0x0000FF, false);
	FreeImage_Save(FREE_IMAGE_FORMAT::FIF_PNG, bitmap, filename.c_str());

	FreeImage_Unload(bitmap);
	delete[] buffer;
}
Пример #27
0
void saveScreenshot(string fname) {
	int pix = w * h;
	BYTE pixels[3*pix];	
	glReadBuffer(GL_FRONT);
	glReadPixels(0,0,w,h,GL_BGR,GL_UNSIGNED_BYTE, pixels);

	FIBITMAP *img = FreeImage_ConvertFromRawBits(pixels, w, h, w * 3, 24, 0xFF0000, 0x00FF00, 0x0000FF, false);
	
	std::cout << "Saving screenshot: " << fname << "\n";

	FreeImage_Save(FIF_PNG, img, fname.c_str(), 0);
}
Пример #28
0
int main(int argc, char* argv[]) {
	if (argc != 2) {
		cerr << "ERROR: NO INPUT FILE\n";
		exit(1);
	}
	readfile(argv[1]);
	Camera camera;
	FIBITMAP* bitmap = FreeImage_Allocate(Width, Height, BPP);
	Process(bitmap, camera, 8);
	FreeImage_Save(FIF_PNG, bitmap, "filename.png", 0);
	return 0;
}
Пример #29
0
void saveScreenshot() {
    int pix = windowWidth * windowHeight;
    BYTE pixels[3*pix];
    glReadBuffer(GL_FRONT);
    glReadPixels(0,0,windowWidth,windowHeight,GL_BGR,GL_UNSIGNED_BYTE,pixels);

    FIBITMAP *img = FreeImage_ConvertFromRawBits(pixels, windowWidth, windowHeight, windowWidth * 3, 24, 0xFF0000, 0x00FF00, 0x0000FF, false);

    std::cout << "Saving screenshot: screenshot.png\n";

    FreeImage_Save(FIF_PNG, img, "screenshot.png", 0);
}
Пример #30
-12
void capture()
{
	if (doo > 0){ doo = 0; }
	else{ doo++; return; }
	if (capture_frame >= 250) exit(0);

	int mWin_width = 800;
	int mWin_height = 600;
	// Make the BYTE array, factor of 3 because it's RBG.
	BYTE* pixels = new BYTE[3 * mWin_width * mWin_height];

	glReadPixels(0, 0, mWin_width, mWin_height, GL_RGB, GL_UNSIGNED_BYTE, pixels);
	for (int i = 0; i < mWin_height; i++)
		for (int j = 0; j < mWin_width; j++)
		{
			BYTE tmp = pixels[i*(mWin_width * 3) + (j * 3) + 0];
			pixels[i*(mWin_width * 3) + (j * 3) + 0] = pixels[i*(mWin_width * 3) + (j * 3) + 2];
			pixels[i*(mWin_width * 3) + (j * 3) + 2] = tmp;
		}

	// Convert to FreeImage format & save to file
	FIBITMAP* image = FreeImage_ConvertFromRawBits(pixels, mWin_width, mWin_height, 3 * mWin_width, 24, 0xFF0000, 0x00FF00, 0x0000FF, false);
	char filename[200];
	sprintf(filename, "F:/Result_Seen/temp/Image/%05d.png", capture_frame);
	capture_frame++;
	FreeImage_Save(FIF_PNG, image, filename, 0);

	// Free resources
	FreeImage_Unload(image);
	delete[] pixels;
}