Exemplo n.º 1
1
void encode(string infile, string outfile, string payload)
{
	BMP input;
	if(!input.ReadFromFile(infile.c_str()))
	{
		cout << "The Bitmap doesn\'t exist!" << endl;
		return;
	}
	int msglength = payload.length() * 2;
	if(msglength > input.TellWidth() * input.TellHeight())
	{
		cout << "That message is too large for that image! (" << msglength << " as opposed to " << input.TellWidth() * input.TellHeight() << "; " << input.TellWidth() << " * " << input.TellHeight() << ")"<<endl;
		return;
	}
	stringstream msglength_ss;
	msglength_ss << setfill('0') << setw(8) << hex << msglength;
	string msglength_str = msglength_ss.str();

	uchar msgLength_split[8];
	for(uint i = 0; i < msglength_str.length(); i++)
	{
		msgLength_split[i] = (uchar)single_char_to_int(msglength_str[i]);
	}

	char* payload_split = new char[payload.length() * 2];
	for(uint i = 0; i < payload.length() * 2 - 1; i+=2)
	{
		payload_split[i] = payload[i / 2] >> 4;
		payload_split[i + 1] = payload[i/ 2] & 0x0F;
	}
	RGBApixel pix;
	for(int x = 0; x < 8; x++)
	{
		pix = input.GetPixel(x, 0);
		pix.Blue &= 0xF0;
		pix.Blue += msgLength_split[x];
		input.SetPixel(x, 0, pix);
	}

	for(int y = 0; y < input.TellHeight(); y++)
	{
		for(int x = 0; x < input.TellWidth(); x++)
		{
			if(y == 0 && x < 8)
				continue;
			pix = input.GetPixel(x, y);
			if(payload.length() * 2 > (uint)input.TellWidth() * y + x - 8)
			{
				pix.Blue &= 0xF0;
				pix.Blue += payload_split[input.TellWidth() * y + x - 8];
			}
			input.SetPixel(x, y, pix);
		}
	}
	fclose(fopen(outfile.c_str(),"w"));
	input.WriteToFile(outfile.c_str());
	delete[] payload_split;
}
Exemplo n.º 2
0
//store output data to disk
void writeFile(BMP img, int id, int iter){
	string name;
	stringstream sstm;
	if(id==1){
		for (short i =0; i<HEIGHT; i++){
			for (short j = 0; j<WIDTH; j++){
				img(i,j)->Red = (label[i][j] +3)*42; //normalize to [0, 255]
				img(i,j)->Green = (label[i][j] +3)*42;
				img(i,j)->Blue = (label[i][j] +3)*42;
			}
		}
		
		sstm << iter << "label" <<".bmp";
		name = sstm.str();
		img.WriteToFile(name.c_str());
		printf("\nlabel image stored");
	}
	else{ //zeroLevelSet
		for (short i =0; i<HEIGHT; i++){
			for (short j = 0; j<WIDTH; j++){
				img(i,j)->Red = zeroLevelSet[i][j]; 
				img(i,j)->Green = zeroLevelSet[i][j]; 
				img(i,j)->Blue = zeroLevelSet[i][j]; 
			}
		}
		sstm << iter << "zero" <<".bmp";
		name = sstm.str();
		img.WriteToFile(name.c_str());
		printf("\nzero image stored\n");
	}
}
Exemplo n.º 3
0
Arquivo: IO.cpp Projeto: N4TT/LevelSet
void writeFile(BMP img, int id){
	if(id == 1){ //label
		for (int i =0; i<HEIGHT; i++){
			for (int j = 0; j<WIDTH; j++){
				img(i,j)->Red = (label[i][j] +3)*42; //normalize to [0, 255]
				img(i,j)->Green = (label[i][j] +3)*42;
				img(i,j)->Blue = (label[i][j] +3)*42;
			}
		}
		img.WriteToFile("output label.bmp");
		printf("\nlabel image stored");
	}
	else{ //zeroLevelSet
		for (int i =0; i<HEIGHT; i++){
			for (int j = 0; j<WIDTH; j++){
				//printf(" (%i,%i) ", i, j);
				img(i,j)->Red = zeroLevelSet[i][j]; 
				img(i,j)->Green = zeroLevelSet[i][j]; 
				img(i,j)->Blue = zeroLevelSet[i][j]; 
			}
		}
		img.WriteToFile("output zero.bmp");
		printf("\nzero image stored\n");
	}
}
Exemplo n.º 4
0
void pacmanTests() {
	cout << "Testing PacMan" << endl;

	// PAC MAN BFS
	BMP img;
	img.ReadFromFile("pacMan.bmp");
	rainbowColorPicker BFSfiller(1.0/1000.0);
	animation pacManBFS = BFSfill(img, img.TellWidth()/2, img.TellHeight()/2,
	                               BFSfiller, 8000, INT_MAX);
	img.WriteToFile("pacManBFS.bmp");
	cout << "\tWrote pacManBFS.bmp" << endl;
	//blueManBFS.write("pacManBFS.gif");

	// PAC MAN DFS
	img.ReadFromFile("pacMan.bmp");
	rainbowColorPicker DFSfiller(1.0/1000.0);
	animation pacManDFS = DFSfill(img, img.TellWidth()/2, img.TellHeight()/2,
	                               DFSfiller, 8000, INT_MAX);
	img.WriteToFile("pacManDFS.bmp");
	cout << "\tWrote pacManDFS.bmp" << endl;


	// Make ANTI image
	BMP antiImg;
	antiImg.ReadFromFile("pacMan.bmp");
	RGBApixel black;
	black.Red = black.Green = black.Blue = 0;
	RGBApixel grey;
	grey.Red = grey.Green = grey.Blue = 1;
	BFSfillSolid(antiImg, 10, 10, grey, 8000, INT_MAX);
	BFSfillSolid(antiImg, antiImg.TellWidth()/2, antiImg.TellHeight()/2, black, 8000, INT_MAX);

	// ANTI PAC MAN BFS
	img = antiImg;
	rainbowColorPicker aBFSfiller(1.0/1000.0);
	animation aManBFS = BFSfill(img, 20, 20, aBFSfiller, 0, 2000);
	//img.WriteToFile("antiPacManBFS.bmp");
	aManBFS.write("antiPacManBFS.gif");
	cout << "\tWrote antiPacManBFS.gif" << endl;

	// ANTI PAC MAN DFS
	img = antiImg;
	rainbowColorPicker aDFSfiller(1.0/1000.0);
	animation aManDFS = DFSfill(img, 20, 20, aDFSfiller, 0, 2000);
	//img.WriteToFile("antiPacManDFS.bmp");
	aManDFS.write("antiPacManDFS.gif");
	cout << "\tWrote antiPacManDFS.gif" << endl;
}
bool EasyBMP_Screenshot( const char* FileName )
{
    BMP Output;

    GLsizei viewport[4];
    glGetIntegerv( GL_VIEWPORT , viewport );

    int width = viewport[2] - viewport[0];
    int height = viewport[3] - viewport[1];

    Output.SetSize(width,height);

    GLint swapbytes, lsbfirst, rowlength, skiprows, skippixels, alignment;

    /* Save current pixel store state. */
    glGetIntegerv(GL_UNPACK_SWAP_BYTES, &swapbytes);
    glGetIntegerv(GL_UNPACK_LSB_FIRST, &lsbfirst);
    glGetIntegerv(GL_UNPACK_ROW_LENGTH, &rowlength);
    glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skiprows);
    glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skippixels);
    glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment);

    /* Set desired pixel store state. */

    glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE);
    glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
    glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
    glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
    glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    RGBApixel* pixels;
    pixels = new RGBApixel [ Output.TellWidth() * Output.TellHeight() ];
    glReadPixels( viewport[0],viewport[1], width,height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);

    int n=0;
    for( int j=Output.TellHeight()-1 ; j >= 0 ; j-- )
    {
        for( int i=0; i < Output.TellWidth() ; i++ )
        {
            Output(i,j)->Red = (pixels[n]).Blue;
            Output(i,j)->Green = (pixels[n]).Green;
            Output(i,j)->Blue = (pixels[n]).Red;
            n++;
        }
    }

    /* Restore current pixel store state. */
    glPixelStorei(GL_UNPACK_SWAP_BYTES, swapbytes);
    glPixelStorei(GL_UNPACK_LSB_FIRST, lsbfirst);
    glPixelStorei(GL_UNPACK_ROW_LENGTH, rowlength);
    glPixelStorei(GL_UNPACK_SKIP_ROWS, skiprows);
    glPixelStorei(GL_UNPACK_SKIP_PIXELS, skippixels);
    glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);


    Output.WriteToFile( FileName );

    return true;
}
Exemplo n.º 6
0
//数组转图像
void array2bmp()
{
    int i,j;
    BMP bmp;
    RGBApixel pix_black={0};//R=0 G=0 B=0为黑色
    RGBApixel pix_white={255,255,255,0};//白色

    bmp.SetSize(3,3);
    bmp.SetBitDepth(1);
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            if(array[i][j]==1)
            {
                bmp.SetPixel( i,  j,pix_black);
            }
            else
            {
                bmp.SetPixel( i,  j,pix_white);
            }
        }
    }

    bmp.WriteToFile("examp_array2bmp.bmp");
    printf("array2bmp suc...\n");
}
Exemplo n.º 7
0
void Camera::raytrace(Node *node, const std::vector<Light*>& lights) {
  BMP output;
  output.SetSize(width,height);
  output.SetBitDepth(24);
  for(int i = 0; i < width; i++) {
    for(int j = 0; j < height; j++) {
      output(i,j)->Red = 0;
      output(i,j)->Green = 0;
      output(i,j)->Blue = 0;
    }
  }

  float aRatio = (float)width/height;

  glm::vec3 xAxis = glm::cross(fwd, up);
  glm::vec3 yAxis = glm::cross(xAxis, fwd);

  float xFov = std::atan(std::tan(yFov) * aRatio);

  xAxis *= std::tan(xFov/2) * glm::length(fwd) / glm::length(xAxis);
  yAxis *= std::tan(yFov/2) * glm::length(fwd) / glm::length(yAxis);

  for(unsigned int j = 0; j < height; j++) {
    std::cout << "\rline " << j << std::flush;
    #pragma omp parallel for
    for(unsigned int i = 0; i < width; i++) {

      // indirect illumination
      glm::vec3 color(0);
      for(int d = 0; d < density; d++) {
        float x = (float(i) + float(rand())/RAND_MAX) / width;
        float y = (float(j) + float(rand())/RAND_MAX) / height;
        std::cout << "dbg " << fwd << " " << xAxis << " " << yAxis << "\n";
        glm::vec3 dir = glm::normalize(fwd + (2*x-1)*xAxis + (1-2*y)*yAxis);
        Ray ray(pos, dir, rayCount, true);

        glm::vec4 dirCol = rayIter(ray, node, lights);
        glm::vec3 mcCol;
        if(dirCol[3] < 1 && mcIter > 0) {
          for(int w = 0; w < mcIter; w++)
            mcCol += rayIter(ray,node);
          mcCol /= float(mcIter);
        } else {
          dirCol[3] = 1;
        }
        color += (1.f - dirCol[3])*mcCol + dirCol[3]*glm::vec3(dirCol);
      }
      color /= float(density);


      output(i,j)->Red = 255.0*glm::clamp(color[0],0.f,1.f);
      output(i,j)->Green = 255.0*glm::clamp(color[1],0.f,1.f);
      output(i,j)->Blue = 255.0*glm::clamp(color[2],0.f,1.f);
    }
  }
  output.WriteToFile(outFile.c_str());
  exit(0);
}
bool Image::writeToBMPFile(const std::string & outputFileName)
{
  bool success = true;

  if( m_pixels != NULL )
    {
    // create bitmap image
    BMP outputImage;
    outputImage.SetSize(m_numCols, m_numRows);
    outputImage.SetBitDepth( 24 );

    double maxVal = m_pixels[0];
    double minVal = m_pixels[0];
    // Maximum and minimum values
    for( int i = 1; i < m_numRows * m_numCols; ++i )
      {
      if( m_pixels[i] > maxVal )
        {
        maxVal = m_pixels[i];
        }
      if( m_pixels[i] <= minVal )
        {
        minVal = m_pixels[i];
        }
      }
    for( int r = 0; r < m_numRows; ++r )
      {
      for( int c = 0; c < m_numCols; ++c )
        {
        // get pixel value and clamp between 0 and 255
        double val = 255.0 * (m_pixels[r * m_numCols + c] - minVal) / (maxVal - minVal);

        if( val < 0 )
          {
          val = 0;
          }
        if( val > 255 )
          {
          val = 255;
          }
        // set output color based on mapping
        RGBApixel pixelVal;
        pixelVal.Blue = (int)val; pixelVal.Green = (int)val; pixelVal.Red = (int)val;
        outputImage.SetPixel(c, r, pixelVal);
        }
      }

    // write to file
    success = outputImage.WriteToFile( outputFileName.c_str() );

    }
  else
    {
    success = false;
    }

  return success;
}
Exemplo n.º 9
0
void outputImage(const char *filename = "out.bmp", const char *rawfilename = "out.raw")
{
	//raw output
	target->ToRawFile(rawfilename);

	//bmp output
	BMP out;
	target->ToBMP(out);
	out.WriteToFile(filename);
}
Exemplo n.º 10
0
static cell AMX_NATIVE_CALL n_SetImageSize( AMX* amx, cell* params ){
	amx_StrParam(amx,params[1],tmp);
	posx = params[2];
	posy = params[3];
	BMP Image;
	Image.ReadFromFile(tmp);
	Image.CreateStandardColorTable();
	Image.SetSize(posx,posy);
	return Image.WriteToFile(tmp);
}
Exemplo n.º 11
0
// test -- tripleRotate()
void testTripleRotate()
{
   int width, height;
   List<RGBApixel> pixelList;
   setup("in_02.bmp", pixelList, width, height);
   pixelList.tripleRotate(4);

   BMP imgOut;
   buildImage(imgOut, pixelList, width, height);
   imgOut.WriteToFile("rotated.bmp");
}
Exemplo n.º 12
0
void w2f(GlobalMap &globalMap, int i, int j, int size=1025)
{
	char fileName[6] = {'0','0','.','b','m','p'};
	fileName[0]=i+48;
	fileName[1]=j+48;
		
	short z;
		
	RGBApixel color;
	BMP image;
	image.SetSize(size,size);
	image.SetBitDepth(16);

	for(int y=0; y<size; y++)
	{
		for(int x=0; x<size; x++)
		{
			z= globalMap.getLocalMap(i,j)->getHeight(x,y);
			if(z<0)
			{
				color.Red=0;
				color.Green=0;
				color.Blue=(z+32768)/129;
				color.Alpha=0;
			}
			if(z>=0 && z<20000)
			{	
				color.Red=0;
				color.Green=z/134+100;
				color.Blue=0;
				color.Alpha=0;
			}
			if(z>=20000 && z<25000)
			{
				color.Red=(z-20000)/500+200;
				color.Green=(z-20000)/500+200;
				color.Blue=(z-20000)/500+200;
				color.Alpha=0;
			}
			if(z>=25000)
			{
				color.Red=255;
				color.Green=255;
				color.Blue=255;
				color.Alpha=0;
			}
			
			image.SetPixel(x,y, color);
		}
	}

	image.WriteToFile(fileName);
}
Exemplo n.º 13
0
void BitmapRawConverter::pixelsToBitmap(char *outFilename) {
    BMP out;
    out.SetSize(width, height);
    out.SetBitDepth(24);

    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            out.SetPixel(i, j, getPixel(i,j));
        }
    }
    out.WriteToFile(outFilename);
}
Exemplo n.º 14
0
int main()
{ 
   SquareMaze m;
   m.makeMaze(2,2);
   std::cout << "MakeMaze complete" << std::endl;

   BMP* unsolved = m.drawMaze();
   unsolved->WriteToFile("unsolved.bmp");
   delete unsolved;
   std::cout << "drawMaze complete" << std::endl;

 
   m.solveMaze();
   std::cout << "solveMaze complete" << std::endl;

   BMP* solved = m.drawMazeWithSolution();
   solved->WriteToFile("solved.bmp");
   delete solved;
   std::cout << "drawMazeWithSolution complete" << std::endl;

   return 0;
}
Exemplo n.º 15
0
int main(int argc, char** argv) {

    if (argc != 2) {
        cout << "Incorrect input. Please enter the name of the configuration file." << endl; 
        return -1; 
    } 
    Reader * config = new Reader(argv[1]);
    
    int width = config->getWIDTH();
    int height = config->getHEIGHT();
    int x = config->getX();
    int y = config->getY();
    int z = config->getZ();

    Camera * rayGenerator = new Camera(config->getEYEP(), config->getVDIR(), 
                                                config->getUVEC(), config->getFOVY(), width, height);
    BMP output;
    output.SetSize(width, height);
    output.SetBitDepth(24);

    Raymarch * raymarch = new Raymarch(config->getVB(), rayGenerator, config->getEYEP(), 
                                        config->getMRGB(), config->getBRGB(), 
                                        config->getLCOL(), config->getLPOS(), config->getOFST());
    
    for (int w = 0; w < width; w++) {
		cout << "Rendering: " << (float) w/width << endl;
        for (int h = 0; h < height; h++) {
            /*
            // Ray direction color test
            output(w,h)->Red = abs(rayGenerator->getRayDirection(w,h).x) *255;
            output(w,h)->Green = abs(rayGenerator->getRayDirection(w,h).y) *255;
            output(w,h)->Blue = abs(rayGenerator->getRayDirection(w,h).z) *255;
            */
            glm::vec3 colors = raymarch->getColor(w,h, config->getSTEP(), glm::vec3(x, y, z));
            colors*=255.0;
            if (colors.x > 255) 
                colors.x = 255;
            if (colors.y > 255) 
                colors.y = 255;
            if (colors.z > 255) 
                colors.z = 255;
            output(w,h)->Red =colors.x;
            output(w,h)->Green = colors.y;
            output(w,h)->Blue = colors.z;
        }
    }
    
    output.WriteToFile(config->getFILE());
	cout << "File has been finished rendering." <<endl;
    return 0;
}
Exemplo n.º 16
0
int main( int argc, char *argv[] )
{
    cout << endl
         << "Using EasyBMP Version " << _EasyBMP_Version_ << endl << endl
         << "Copyright (c) by the EasyBMP Project 2005-6" << endl
         << "WWW: http://easybmp.sourceforge.net" << endl << endl;

    BMP Text;
    Text.ReadFromFile("EasyBMPtext.bmp");

    BMP Background;
    Background.ReadFromFile("EasyBMPbackground.bmp");

    BMP Output;
    Output.SetSize( Background.TellWidth() , Background.TellHeight() );
    Output.SetBitDepth( 24 );

    RangedPixelToPixelCopy( Background, 0, Output.TellWidth() - 1,
                            Output.TellHeight() - 1 , 0,
                            Output, 0, 0 );

    RangedPixelToPixelCopyTransparent( Text, 0, 380,
                                       43, 0,
                                       Output, 110, 5,
                                       *Text(0, 0) );

    RangedPixelToPixelCopyTransparent( Text, 0, Text.TellWidth() - 1,
                                       Text.TellWidth() - 1, 50,
                                       Output, 100, 442,
                                       *Text(0, 49) );

    Output.SetBitDepth( 32 );
    cout << "writing 32bpp ... " << endl;
    Output.WriteToFile( "EasyBMPoutput32bpp.bmp" );

    Output.SetBitDepth( 24 );
    cout << "writing 24bpp ... " << endl;
    Output.WriteToFile( "EasyBMPoutput24bpp.bmp" );

    Output.SetBitDepth( 8 );
    cout << "writing 8bpp ... " << endl;
    Output.WriteToFile( "EasyBMPoutput8bpp.bmp" );

    Output.SetBitDepth( 4 );
    cout << "writing 4bpp ... " << endl;
    Output.WriteToFile( "EasyBMPoutput4bpp.bmp" );

    Output.SetBitDepth( 1 );
    cout << "writing 1bpp ... " << endl;
    Output.WriteToFile( "EasyBMPoutput1bpp.bmp" );

    Output.SetBitDepth( 24 );
    Rescale( Output, 'p' , 50 );
    cout << "writing 24bpp scaled image ..." << endl;
    Output.WriteToFile( "EasyBMPoutput24bpp_rescaled.bmp" );

    return 0;
}
Exemplo n.º 17
0
// test -- removeNth()
void testRemoveNth()
{
   int width, height;
   List<RGBApixel> pixelList;
   setup("in_01.bmp", pixelList, width, height);

   pixelList.removeNth(4, 2);

   // reconstruct the image
   // note: original width was divisible by four, so this works
   BMP imgOut;
   buildImage(imgOut, pixelList, 3 * (width / 4) , height);
   imgOut.WriteToFile("removed.bmp");
}
Exemplo n.º 18
0
int main (){
   
   // initializing variables

   bool sucess;
   BMP in;
   BMP out;
   int width,height,i,j,new_j,new_i;

   // Set Classes to contain image

   sucess=in.ReadFromFile("in.bmp");
   //cout<<sucess<<endl;
   sucess=out.ReadFromFile("in.bmp");
   //cout<<sucess<<endl;

   // Find height and width
   // starting from 0 not 1 so decrement 
  
   width=(in.TellWidth());
   width--;
   height=in.TellHeight();
   height--;
   //cout<<in.TellWidth()<<endl;
   //cout<<in.TellHeight()<<endl;

   // runs horizontally across the image
   for (i=0;i<=width;i++){

      // runs vertically across image
      for (j=0;j<=height;j++){

         // code for finding pixel to change 
         new_i=width-i;
         new_j=height-j;

         // code for changing output image  
         out(new_i,new_j)->Red =in(i,j)->Red;
         out(new_i,new_j)->Green =in(i,j)->Green;
         out(new_i,new_j)->Blue =in(i,j)->Blue;
        
      }	
   }
   //cout<<"Exiting For loops"<<endl;
   
   // write output image to disk
   out.WriteToFile("out.bmp");
   //cout<<"Finished writing out.bmp"<<endl;
   return 0;
}
Exemplo n.º 19
0
void Camera::printImage(char* outputName) {
	BMP output;
	output.SetSize(imgWidth, imgHeight);
	output.SetBitDepth(24);
	glm::vec3 outR;
	for (int i = 0; i < imgWidth; i++) {
		for (int j = 0; j < imgHeight; j++) {
			outR = glm::abs(glm::normalize(getDirectionFromCoordinate(i,j)-eye));
			output(i,j)->Red = outR.x * 255;
			output(i,j)->Green = outR.y * 255;
			output(i,j)->Blue = outR.z * 255;
		}
	}
	output.WriteToFile(outputName);
}
Exemplo n.º 20
0
int main(void) {

    BMP TextImage;
    TextImage.ReadFromFile("text.bmp");
    toBlackAndWhite(TextImage);

    int symbolCount = 0, lineCount = 0;
    countAndColor(TextImage, symbolCount, lineCount);
    
    TextImage.WriteToFile("output.bmp");

    std::cout << "symbols: " << symbolCount << std::endl;
    std::cout << "lines: " << lineCount << std::endl;

}
Exemplo n.º 21
0
        bool ExportBMP( const _TImg_t     & in_indexed,
                        const std::string & filepath )
    {
        //shorten this static constant
        typedef utils::do_exponent_of_2_<_TImg_t::pixel_t::mypixeltrait_t::BITS_PER_PIXEL> NbColorsPP_t;
        BMP output;
        output.SetBitDepth(_TImg_t::pixel_t::GetBitsPerPixel());

        if( in_indexed.getNbColors() != NbColorsPP_t::value )
        {
#ifdef _DEBUG
            assert(false);
#endif
            throw std::runtime_error( "ERROR: The tiled image to write to a bitmap image file has an invalid amount of color in its palette!" );
        }
        //copy palette
        for( int i = 0; i < NbColorsPP_t::value; ++i )
            output.SetColor( i, colorRGB24ToRGBApixel( in_indexed.getPalette()[i] ) );

        //Copy image
        output.SetSize( in_indexed.getNbPixelWidth(), in_indexed.getNbPixelHeight() );

        for( int i = 0; i < output.TellWidth(); ++i )
        {
            for( int j = 0; j < output.TellHeight(); ++j )
            {
                auto &  refpixel = in_indexed.getPixel( i, j );
                uint8_t temp     = static_cast<uint8_t>( refpixel.getWholePixelData() );
                output.SetPixel( i,j, colorRGB24ToRGBApixel( in_indexed.getPalette()[temp] ) ); //We need to input the color directly thnaks to EasyBMP
            }
        }

        bool bsuccess = false;
        try
        {
            bsuccess = output.WriteToFile( filepath.c_str() );
        }
        catch( std::exception e )
        {
            cerr << "<!>- Error outputing image : " << filepath <<"\n"
                 << "     Exception details : \n"     
                 << "        " <<e.what()  <<"\n";

            assert(false);
            bsuccess = false;
        }
        return bsuccess;
    }
Exemplo n.º 22
0
bool _surf_save_bmp(const d_surf * srf, const char * filename) {

	if (!filename)
		return false;

	if (!srf) {
		writelog(LOG_ERROR,"surf_save_png : no surf loaded");
		return false;
	}

	writelog(LOG_MESSAGE,"Saving surf %s to file %s (BMP)", srf->getName(), filename);

	size_t NN = srf->getCountX();
	size_t MM = srf->getCountY();
	
	BMP res;
	res.SetSize(NN,MM);
	res.SetBitDepth(24);
	REAL minz, maxz;
	srf->getMinMaxZ(minz, maxz);

	size_t i, j;
	double gray_color;
	for (j = 0; j < MM; j++) {
		for (i = 0; i < NN; i++) {
			REAL value = srf->getValueIJ(i,MM-j-1);
			if (value == srf->undef_value) {
				res(i,j)->Red = 0;
				res(i,j)->Green = 0;
				res(i,j)->Blue = 0;
				res(i,j)->Alpha = 0;
			} else {
				gray_color = MAX(0,MIN(255,floor((value - minz)/(maxz-minz)*255 + 0.5)));
				res(i,j)->Red = (ebmpBYTE)gray_color;
				res(i,j)->Green = (ebmpBYTE)gray_color;
				res(i,j)->Blue = (ebmpBYTE)gray_color;
				res(i,j)->Alpha = 255;
			}

		}
	}
	

	res.WriteToFile(filename);

	return true;

};
Exemplo n.º 23
0
int _tmain(int argc, _TCHAR* argv[])
{
	BMP finalImage;
	BufferParser* configInfo = new BufferParser(argv[1]);
	configInfo->parseFile();

	Ray* camera = new Ray(configInfo->getDelta(), configInfo->getStep(), configInfo->getBufferSize(), configInfo->getBackgroundColor(), configInfo->getMaterialColor(), configInfo->getResolution(),
		configInfo->getCameraPosition(), configInfo->getViewingDirection(), configInfo->getUpVector(), configInfo->getFOVY(), configInfo->getLightPosition(), configInfo->getLightColor(), configInfo->getVoxelBuffer());
	finalImage.SetSize(configInfo->getResolution().x, configInfo->getResolution().y);

	int halfwayDone = configInfo->getResolution().y/2;
	int quarterDone = configInfo->getResolution().y/4;


	//Iterate through pixels and calculate vector
	for (int i = 0; i<configInfo->getResolution().y; i++){
			
		if (i == quarterDone){
			cout<<"25% complete"<<endl;
		}
		else if(i == halfwayDone){
			cout<<"50% complete"<<endl;
		}
		else if(i == halfwayDone+quarterDone){
			cout<<"75% complete"<<endl;
		}

		for (int j = 0; j<configInfo->getResolution().x; j++) {

			glm::vec3 color = camera->rayMarch(j,i);

			finalImage(j,configInfo->getResolution().y-1-i)->Red = color.x * 255;
			finalImage(j,configInfo->getResolution().y-1-i)->Green = color.y * 255;
			finalImage(j,configInfo->getResolution().y-1-i)->Blue = color.z * 255;	
		}
	}

	finalImage.WriteToFile(configInfo->getOutputFileName());

	delete configInfo; 
	delete camera;
	

return 0 ; 
} 
Exemplo n.º 24
0
int main(int argc, char* argv[]) {
  BMP canvas;
  canvas.SetSize(128, 128);

  const Vector2 truck_center(64, 64);

  /* TODO: Why can't I construct a new Truck?  Is should be a valid Drawable.
   * Could it be missing something that would prevent it from being constructed?
   */
  Drawable* truck = new Truck(truck_center);

  truck->draw(&canvas);

  canvas.WriteToFile("test_pure_virtual.bmp");

  delete truck;
  return 0;
}
Exemplo n.º 25
0
static cell AMX_NATIVE_CALL n_SetPixelRGBA( AMX* amx, cell* params ){
	amx_StrParam(amx,params[1],tmp);
	BMP Image;
	posx = params[2];
	posy = params[3];
	Image.ReadFromFile(tmp);
	RGBApixel value;
	
	value.Red = (ebmpBYTE)params[4];
	value.Green = (ebmpBYTE)params[5];
	value.Blue = (ebmpBYTE)params[6];
	value.Alpha = (ebmpBYTE)params[7];
	
	Image.SetBitDepth(24);
	Image.GetPixel(posx,posy);
	Image.SetPixel(posx,posy,value);
	return Image.WriteToFile(tmp);
}
Exemplo n.º 26
0
void Camera::debugRender(unsigned int width, unsigned int height, std::string& outputFile)
{
	BMP file;
	file.SetSize(width,height);
	file.SetBitDepth(24);

	
	double d = m_direction.length();              //Distance from Eye to Middle point of the image

	Vector myVectorEyetoMiddle(m_direction);
	myVectorEyetoMiddle *= d;    //C in full length

	double tanfovx = tan(m_fovRad)*double(width)/height ;  
    Vector myEyeVectorX = myVectorEyetoMiddle.crossProduct(m_up) ;      //A
	Vector myEyeVectorY = myEyeVectorX.crossProduct(myVectorEyetoMiddle) ;      //B

	Vector myMiddlePoint =  myVectorEyetoMiddle + m_position;

	Vector myImageVectorX = myEyeVectorX *  ( myVectorEyetoMiddle.normalize().length() * tanfovx / myEyeVectorX.length() );    //H
	Vector myImageVectorY = myEyeVectorY *  ( myVectorEyetoMiddle.normalize().length() * tan(m_fovRad) / myEyeVectorY.length() );    //V

	for(unsigned int i=0;i<width;i++){
		for(unsigned int j=0;j<height;j++){
			
		    double sx,sy;
			sx = double(i)/width;
			sy = double(j)/height;

			Vector P =  myImageVectorX*(2*sx-1) + myImageVectorY*(2*sy-1) + myMiddlePoint ;
			Vector myRayCasting = (P - m_position)*(1.0 / (P - m_position).normalize().length()); //RayDirection = (P - E)/normalize(P - E);
		
			Vector normalizedRay = myRayCasting.normalize();

			RGBApixel NewColor;
			NewColor.Red = (ebmpBYTE) abs(normalizedRay[0])*255;
			NewColor.Green = (ebmpBYTE) abs(normalizedRay[1])*255;
			NewColor.Blue = (ebmpBYTE) abs(normalizedRay[2])*255;
			NewColor.Alpha = 0;
			file.SetPixel(i, height-j-1, NewColor);
		}
	}

	file.WriteToFile(outputFile.c_str());
}
Exemplo n.º 27
0
void save_image(const Matrix<std::tuple<T, T, T>> &im, const char *path)
{
    BMP out;
    out.SetSize(im.n_cols, im.n_rows);

    T r, g, b;
    RGBApixel p;
    p.Alpha = 255;
    for (uint i = 0; i < im.n_rows; ++i) {
        for (uint j = 0; j < im.n_cols; ++j) {
            tie(r, g, b) = im(i, j);
            p.Red = clip(r); p.Green = clip(g); p.Blue = clip(b);
            out.SetPixel(j, i, p);
        }
    }

    if (!out.WriteToFile(path))
        throw string("Error writing file ") + string(path);
}
Exemplo n.º 28
0
void DisplayClass::doRayTrace() {
	graph->rootNode->computeAllInverses();
	unsigned int width = static_cast<int>(*resoX);
	unsigned int height = static_cast<int>(*resoY);
	glm::vec3 A = glm::cross(rayCamera->center, rayCamera->up);
	glm::vec3 B = glm::cross(A, rayCamera->center);
	glm::vec3 M = rayCamera->center + rayCamera->eye;
	glm::vec3 V = (B * glm::length(rayCamera->center) * tan(glm::radians(rayCamera->fovy)))/ glm::length(B);
	//float fovx = atan(length(V) * (*WriteBMP::resoX/ *WriteBMP::resoY)/length(M));
	glm::vec3 H = (*resoX/ *resoY) * V;
	H.x = H.y;
	H.y = 0.0f;
	H.z = 0.0f;
	BMP output;
	output.SetSize(width, height);
	output.SetBitDepth(24);
	glm::vec3 P;
	glm::vec3 D;
	glm::vec3* E = new glm::vec3(rayCamera->eye.x, rayCamera->eye.y, rayCamera->eye.z);
	glm::vec3* color = new glm::vec3();
	std::cout << "Beginning raytrace" << std::endl;
	for(unsigned int x = 0; x < width; x++) {
		for(unsigned int y = 0; y < height; y++) {
			color = new glm::vec3(0.0f, 0.0f, 0.0f);
			E->x = rayCamera->eye.x;
			E->y = rayCamera->eye.y;
			E->z = rayCamera->eye.z;
			P = DisplayClass::mapPoint(x, height - y - 1, M, H, V);
			D = glm::normalize(P - *E);///glm::length(P - *E);
			traceRay(color, 0, *E, D, 1.0f, 1.0f, *rayLightCol->at(0));
			output(x, y)->Red = 255 * color->x;
			output(x, y)->Green = 255 * color->y;
			output(x, y)->Blue = 255 * color->z;
			delete color;
			color = 0;
		}
		if (x % 10 == 0) {
			std::cout << "finished vertical line: " << x << std::endl;
		}
	}
	std::cout << "Finished raytrace!" << std::endl;
	output.WriteToFile(rayOutputFile->c_str());
}
Exemplo n.º 29
0
void save_image(const Image &im, const char *path)
{
    BMP out;
    out.SetSize(im.n_cols, im.n_rows);

    int r, g, b;
    RGBApixel p;
    p.Alpha = 255;
    for (int i = 0; i < im.n_rows; ++i) {
        for (int j = 0; j < im.n_cols; ++j) {
            tie(r, g, b) = im(i, j);
            p.Red = r; p.Green = g; p.Blue = b;
            out.SetPixel(j, i, p);
        }
    }

    if (!out.WriteToFile(path))
        throw string("Error writing file ") + string(path);
}
int main (int argc, char* argv[])
{

  BMP image;
  image.ReadFromFile("input.bmp");

  int width = image.TellWidth();
  int height = image.TellHeight();

  letterData data[10000];

  BMP imageOut;
  imageOut.SetSize(width, height);

  Conversion(image, imageOut, data);
  

  imageOut.WriteToFile("output.bmp");
  return 0;
}