void PadBMP( BMP& Input , int NewWidth , int NewHeight )
{
// if the NewWidth and NewHight are unchanged, exit

    if( NewWidth  == Input.TellWidth() &&
            NewHeight == Input.TellHeight() )
    {
        return;
    }

// find max range for the copy, so that cropping occurs
// if necessary

    int MaxWidth = Input.TellWidth();
    if( MaxWidth > NewWidth )
    {
        MaxWidth = NewWidth;
    }

    int MaxHeight = Input.TellHeight();
    if( MaxHeight > NewHeight )
    {
        MaxHeight = NewHeight;
    }

// create a temporary image to hold the original pixels

    BMP Temp;
    Temp.SetSize(NewWidth,NewHeight);
    Temp.SetBitDepth( Input.TellBitDepth() );
    int i,j;
    int Difference = Temp.TellHeight() - MaxHeight;
    for( i=0 ; i < MaxWidth ; i++ )
    {
        for( j=0 ; j < MaxHeight ; j++ )
        {
            *Temp(i,j+Difference) = *Input(i,j);
        }
    }

// resize the original image, and recopy the pixels

    Input.SetSize(NewWidth,NewHeight);
    for( i=0 ; i < Input.TellWidth() ; i++ )
    {
        for( j=0 ; j < Input.TellHeight() ; j++ )
        {
            *Input(i,j) = *Temp(i,j);
        }
    }

    Temp.SetSize(1,1);
    Temp.SetBitDepth(24);

    return;
}
Exemplo n.º 2
0
static cell AMX_NATIVE_CALL n_FSetImageSize( AMX* amx, cell* params ){
	posx = params[1];
	posy = params[2];
	GlobalImage.CreateStandardColorTable();
	GlobalImage.SetSize(posx,posy);
	return 1;
}
Exemplo n.º 3
0
// Utility function which rebuilds an image from a list of pixels
void buildImage(BMP & image, List<RGBApixel> theList, int width, int height) 
{
   if (width * height != theList.length()) {
      cout << "Error: invalid parameters to buildImage.\n";
      return;
   }

   image.SetSize(width, height);
   int x = 0, y = 0;
   theList.front();
   for (int pos = 0; pos < theList.length(); pos++) {
      *image(x,y) = theList.retrieve();

      // move to next pixel position
      x++;
      if (x >= width) {
         x = 0;
         y++;
      }

      // avoid spurious warning message
      if (pos != theList.length() - 1)
         theList.forwardOne();
   }
}
Exemplo n.º 4
0
// creates a BMP from a CImage
// assumes all float values have already been scaled to [0.0, 255.0]
BMP * CImage::toBmp()
{
    BMP * bmp = new BMP();
    bmp->SetSize(m_width, m_height);

    // for smaller output file size
    bmp->SetBitDepth(8);
    // 8-bit bitmaps need a color table
    CreateGrayscaleColorTable(*bmp);

    for (int col = 0; col < m_width; col++)
    {
        for (int row = 0; row < m_height; row++)
        {
            // Output is grayscale, so R, G, and B components are equal.
            // ScaleAndDisplayDisparityValues() et. al. in stereo.cpp have already
            //  scaled all float pixel values to [0, 255].
            ebmpBYTE byteVal = (ebmpBYTE) getValue(row, col, 0);
            (* bmp)(col, row)->Red = byteVal;
            (* bmp)(col, row)->Green = byteVal;
            (* bmp)(col, row)->Blue = byteVal;
        }
    }

    
    return bmp;
}
Exemplo n.º 5
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");
}
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.º 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);
}
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;
}
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.º 10
0
bool HBITMAPtoBMP(HDC hDC,HBITMAP hBitmap,BMP& OutputImage)
{
 using namespace std;
 bool output = false;
    
 BITMAPINFO BitInfo;
 ZeroMemory(&BitInfo, sizeof(BITMAPINFO));
 BitInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
 
 // get all manner of information from the incoming bitmap

 if(!::GetDIBits(hDC, hBitmap, 0, 0, NULL, &BitInfo, DIB_RGB_COLORS))
 { return false; }
 
 // Set the size and bit depth of the BMP object

 OutputImage.SetSize( BitInfo.bmiHeader.biWidth ,BitInfo.bmiHeader.biHeight );
 OutputImage.SetBitDepth(32);

 // reconfigure BitInfo.bmiHeader such that the resulting bitmap will be 
 // 32 bits per pixel. This is _MUCH_ simpler 
 
 BitInfo.bmiHeader.biBitCount = 32;
 BitInfo.bmiHeader.biCompression = 0;
 BitInfo.bmiHeader.biSizeImage = OutputImage.TellHeight()*OutputImage.TellWidth()*4;
 
 // I don't understand the +5 part here. -- Paul 

// BYTE *pData = new BYTE[BitInfo.bmiHeader.biSizeImage + 5];
// BYTE *pData = new BYTE[Output.TellHeight()*Output.TellWidth()*4+5];
 BYTE *pData = new BYTE [BitInfo.bmiHeader.biSizeImage];
 
 // now get the actual data
    
 if(!::GetDIBits(hDC, hBitmap, 0, BitInfo.bmiHeader.biHeight, pData, &BitInfo, DIB_RGB_COLORS))
 { return false; }
 
 // transfer that data into the BMP object
 
 int i,j;
 int k=0;
 for( j=OutputImage.TellHeight()-1 ; j >= 0 ; j-- )
 {
  for( i=0; i < OutputImage.TellWidth() ; i++ )
  {
   OutputImage(i,j)->Blue = *(pData+k); k++;
   OutputImage(i,j)->Green = *(pData+k); k++;
   OutputImage(i,j)->Red = *(pData+k); k++;
   OutputImage(i,j)->Alpha = *(pData+k); k++;
  }
 }
 
 delete (pData);
 
 return true;
}
Exemplo n.º 11
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.º 12
0
// same as above, but highlights a range of depths in red,
// and, colors all depths outside that range black in refImage
// highlight_low and high are values in [1,100]
BMP * CImage::toHighlightedBmp(int highlight_low, int highlight_high, BMP * refBmp)
{
    // scale range to be highlighted to [0,255]
    highlight_low = ((float) highlight_low) * 255.0/100.0 - 2.55;
    highlight_high = ((float) highlight_high) * 255.0/100.0;

    BMP * bmp = new BMP();
    bmp->SetSize(m_width, m_height);

    // for smaller output file size
    bmp->SetBitDepth(8);
    // 8-bit bitmaps need a color table
    CreateGrayscaleColorTable(*bmp);

    // add red to the color table
    RGBApixel highlightColor;
    highlightColor.Red = 255;
    highlightColor.Green = 0;
    highlightColor.Blue = 0;
    highlightColor.Alpha = 0;
    bmp->SetColor(highlight_low, highlightColor);

    // copy pixels to bmp
    for (int col = 0; col < m_width; col++)
    {
        for (int row = 0; row < m_height; row++)
        {
            float pixel = getValue(row, col, 0);
            if (highlight_low <= pixel && pixel <= highlight_high)
            {
                (* bmp)(col, row)->Red = 255;
                (* bmp)(col, row)->Green = 0;
                (* bmp)(col, row)->Blue = 0;
            }
            else
            {
                // Output is grayscale, so R, G, and B components are equal.
                // ScaleAndDisplayDisparityValues() et. al. in stereo.cpp have already
                //  scaled all float pixel values to [0, 255].
                ebmpBYTE byteVal = (ebmpBYTE) pixel;
                (* bmp)(col, row)->Red = byteVal;
                (* bmp)(col, row)->Green = byteVal;
                (* bmp)(col, row)->Blue = byteVal;

                // color non-highlighted areas black in refBmp
                (* refBmp)(col, row)->Red = 0;
                (* refBmp)(col, row)->Green = 0;
                (* refBmp)(col, row)->Blue = 0;
            }
        }
    }

    
    return bmp;
}
Exemplo n.º 13
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.º 14
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);
}
void CopyBMP( BMP& Input , BMP& Output )
{
    Output.SetSize( Input.TellWidth() , Input.TellHeight() );

    for( int j=0 ; j < Input.TellHeight() ; j++ )
    {
        for( int i=0 ; i < Input.TellWidth() ; i++ )
        {
            *Output(i,j) = *Input(i,j);
        }
    }
    return;
}
Exemplo n.º 16
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.º 17
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.º 18
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.º 19
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.º 20
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.º 21
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.º 22
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.º 23
0
BMP testColorPicker(colorPicker * picker) {
	BMP img;
	img.SetSize(FUNCTORTESTWIDTH, FUNCTORTESTHEIGHT);
	RGBApixel px;

	for(int x = 1; x < FUNCTORTESTWIDTH; x = x + x)
		for(int y = 1; y < FUNCTORTESTHEIGHT; y = y + y) {
			px = (*picker)(x, y);
			cout << "\toperator()(" << x << ", " << y << ") = {" << (int)px.Red << ", ";
			cout << (int)px.Green << ", " << (int)px.Blue << "}" << endl;
		}

	for(int x = 0; x < FUNCTORTESTWIDTH; x++)
		for(int y = 0; y < FUNCTORTESTHEIGHT; y++){
			*img(x, y) = (*picker)(x, y);
		}

	return img;
}
Exemplo n.º 24
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.º 25
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.º 26
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;
}
Exemplo n.º 28
0
//decompress
//	reconstructs image by transversing the tree
BMP Quadtree::decompress(){
	BMP ret;

	if (root==NULL)
		return ret;

	int width=root->pixels;
	int height=root->pixels;
	
	//set image size	
	ret.SetSize(width,height);

	for(int y=0;y<height;y++){
		for(int x=0;x<width;x++){
			//get pixel information for specified (x,y)
			*ret(x,y)=getPixel(x,y);
		}
	}
//	cout<<endl;
	return ret;
}
Exemplo n.º 29
0
void raycast(mat4 cameraMatrix) {
	int width = 800;
	int height = 600;

	const float Wd2 = width/2;
	const float Hd2 = height/2;

	BMP output;
	output.SetSize(width, height);
	output.SetBitDepth(24);
	
	glm::vec4 camerapos = glm::vec4(0, 0, 0, 0);

	for(int x = 0; x < width; x++) 
	{
		for(int y = 0; y < height; y++) 
		{
			float xtemp = x - Wd2;
			float ytemp = y - Hd2;

			xtemp = xtemp/Wd2;
			ytemp = ytemp/Hd2;

			glm::vec4 pixelpos = glm::vec4(xtemp,ytemp,1,0);
			glm::vec4 ray = camerapos-pixelpos;
			ray = glm::normalize(ray);

			vec4 color = intersectTest(ray);
			
			output(x,y)->Red = color.r;
			output(x,y)->Green = color.g;
			output(x,y)->Blue = color.b;
			
		}
	}

	output.WriteToFile("raytrace.bmp");
	return;
}
Exemplo n.º 30
0
//*******************
// outputs the image to a bmp
// by writing the value of the array we have 
// to each of RG, and B
//*******************
void outputImg(void){
  //setup Output IMG
  BMP OutputIMG;
  
  int byte;
  OutputIMG.SetBitDepth(DEPTH);
  OutputIMG.SetSize(COLUMNS,ROWS);
  
  cout<< "Output Image to File" << endl;
  for( int j=0 ; j < ROWS ; j++)
    {
      for( int i=0 ; i < COLUMNS ; i++)
	{
	  byte =  imageArray[i][j];
	  OutputIMG(i,j)->Red = byte;
	  OutputIMG(i,j)->Green = byte;
	  OutputIMG(i,j)->Blue = byte;
	}
    }
  
  OutputIMG.WriteToFile("Output.bmp");
  cout << "\n**** NOW GO OPEN Output.BMP ******" << endl;
}