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
//数组转图像
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.º 3
0
void tile(BMP& Input, BMP& Output) {
    if (Input.TellHeight() == 1) {
        Output.SetPixel(Output.TellWidth() - 1, 0, Input.GetPixel(0, 0));
    }
    else {
        BMP* ScaledInput = new BMP(Input);
        Rescale(*ScaledInput, 'p', 50);

        // SW quadrant
        RangedPixelToPixelCopy(*ScaledInput, 0, ScaledInput -> TellWidth(), 0, ScaledInput -> TellHeight(), 
                Output, Output.TellWidth() - 2 * ScaledInput -> TellWidth(), ScaledInput -> TellHeight());

        // NE quadrant
        tile(*ScaledInput, Output);

        // NW quadrant
        RangedPixelToPixelCopy(Output, Output.TellWidth() - ScaledInput -> TellWidth(), Output.TellWidth() - ScaledInput -> TellWidth() / 2 - 1,
                0, ScaledInput -> TellHeight() - 1, Output, Output.TellWidth() - 2 * ScaledInput -> TellWidth(), 0);

        RangedPixelToPixelCopy(Output, Output.TellWidth() - ScaledInput -> TellWidth(), Output.TellWidth() - ScaledInput -> TellWidth() / 2 - 1,
                0, ScaledInput -> TellHeight() - 1, Output, Output.TellWidth() - 3 * ScaledInput -> TellWidth() / 2, 0);

        // SE quadrant
        RangedPixelToPixelCopy(Output, Output.TellWidth() - ScaledInput -> TellWidth(), Output.TellWidth() - 1, ScaledInput -> TellHeight() / 2,
                ScaledInput -> TellHeight()  - 1, Output, Output.TellWidth() - ScaledInput -> TellWidth(), ScaledInput -> TellHeight());

        RangedPixelToPixelCopy(Output, Output.TellWidth() - ScaledInput -> TellWidth(), Output.TellWidth() - 1, ScaledInput -> TellHeight() / 2,
                ScaledInput -> TellHeight() - 1, Output, Output.TellWidth() - ScaledInput -> TellWidth(), 3 * ScaledInput -> TellHeight() / 2);
    }

}
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.º 5
0
void drawBox(BMP &image, int lowx, int lowy, int highx, int highy) {

    RGBApixel redPixel;
    // make pixel red
    redPixel.Red = 255;
    redPixel.Blue = 0;
    redPixel.Green = 0;

    // color upper and bottom bounds
    for (int i = lowx; i <= highx; ++i) {
        image.SetPixel(i, lowy, redPixel);
        image.SetPixel(i, highy, redPixel);
    }
    
    // color left and right bounds
    for (int j = lowy; j <= highy; ++j) {
        image.SetPixel(lowx, j, redPixel);
        image.SetPixel(highx, j, redPixel);
    }
}
Exemplo n.º 6
0
void copy(BMP & InImg, BMP & OutImg, int xPos, int yPos) {
  // copy image to larger final picture so that the InImg is placed in row i, column j of OutImg
    int width = InImg.TellWidth();
    RGBApixel curPixel;

    for (int i = 0; i < width; i++) {
        for (int j = 0; j < width; j++) {
            curPixel = InImg.GetPixel(i, j);
            OutImg.SetPixel(xPos * width + i, yPos * width + j, curPixel);
        }
    }
}
Exemplo n.º 7
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.º 8
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.º 9
0
static cell AMX_NATIVE_CALL n_FSetPixelRGBA( AMX* amx, cell* params ){
	posx = params[1];
	posy = params[2];
	RGBApixel value;
	
	value.Red = (ebmpBYTE)params[4];
	value.Green = (ebmpBYTE)params[5];
	value.Blue = (ebmpBYTE)params[6];
	value.Alpha = (ebmpBYTE)params[7];
	
	GlobalImage.SetBitDepth(24);
	GlobalImage.GetPixel(posx,posy);
	GlobalImage.SetPixel(posx,posy,value);
	return 1;
}
Exemplo n.º 10
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.º 11
0
void graydata2BMP(unsigned char* data, BMP& bmp ){
	int k=0;
	int width =bmp.TellWidth();
	int height=bmp.TellHeight();

	for (int i=0; i<height; i++){
		for (int j=0; j<width; j++){
			RGBApixel pix;
			pix.Blue =data[k];
			pix.Red  =data[k];
			pix.Green=data[k];
			bmp.SetPixel(j,i,pix);
			k++;
		}
	}
}
Exemplo n.º 12
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.º 13
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.º 14
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.º 15
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);
}
Exemplo n.º 16
0
int hpx_main()
{
    BMP SetImage;
    SetImage.SetBitDepth(24);
    SetImage.SetSize(sizeX * 2,sizeY);
    hpx::util::high_resolution_timer t;

    {
        using namespace std;

        using hpx::future;
        using hpx::async;
        using hpx::wait_all;

        int const max_iteration = 255;

        vector<future<int> > iteration;
        iteration.reserve(sizeX*sizeY);

        hpx::cout << "Initial setup completed in " 
                  << t.elapsed() 
                  << "s. Initializing and running futures...\n";
        t.restart();

        hpx::id_type const here = hpx::find_here();
        fractals_action fractal_pixel;

        for (int i = 0; i < sizeX; i++)
        {
            for (int j = 0; j < sizeY; j++)
            {
                float x0 = (float)i * 3.5f / (float)sizeX - 2.5f;
                float y0 = (float)j * 2.0f / (float)sizeY - 1.0f;

                iteration.push_back(async(fractal_pixel, here, x0, y0, max_iteration));
            }
        }
        wait_all(iteration);

        hpx::cout << sizeX*sizeY << " calculations run in " 
                  << t.elapsed() 
                  << "s. Transferring from futures to general memory...\n";
        t.restart();

        for (int i = 0; i < sizeX; ++i)
        {
            for (int j = 0; j < sizeY; ++j)
            {
                int it = iteration[i*sizeX + j].get();
                for (int k = 0; k < 2; ++k)
                {
                    int p = (it * 255) / max_iteration;
                    SetImage.SetPixel(i * 2 + k, j, RGBApixel(p, p, p));
                }
            }
        }
    }

    hpx::cout << "Transfer process completed in " 
              << t.elapsed() << "s. Writing to hard disk...\n";
    t.restart();

    SetImage.WriteToFile("out.bmp");
    
    hpx::cout << "Fractal image written to file \"out.bmp\" from memory in " 
              << t.elapsed() << "s.\nInitializing shutdown process.\n";

    return hpx::finalize(); // Handles HPX shutdown
}
Exemplo n.º 17
0
void w2fBIG(GlobalMap &globalMap, int number, int lsize=1025, int gsizex=3, int gsizey=3)
{
	short z;

	RGBApixel color;
	BMP image;
	image.SetSize(gsizex*lsize,gsizey*lsize);
	image.SetBitDepth(32);

	for(int b=0; b<gsizey; b++)
	{
		for(int a=0; a<gsizex; a++)
		{
			for(int y=0; y<lsize; y++)
			{
				for(int x=0; x<lsize; x++)
				{
					z= globalMap.getLocalMap(a,b)->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;
					}
					/*
					if(z%250<5 && z%250>-5)
					{
						color.Red=0;
						color.Green=0;
						color.Blue=0;
						color.Alpha=0;
					}
					*/
					image.SetPixel(x+a*1025,y+b*1025, color);
				}
			}
		}
	}
	char fileName[12];
	sprintf(fileName, "map_%d.bmp", number);
	image.WriteToFile(fileName);
}
Exemplo n.º 18
0
void Camera::renderRayBoxIntersection(unsigned int width, unsigned int height, float m_bgcolor[], float m_boxcolor[], std::string& outputFile){

	BMP file;
	file.SetSize(width,height);
	file.SetBitDepth(24);

	Vector myVectorEyetoMiddle(m_direction.normalize());

	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

	
	RGBApixel BGColor; 
	BGColor.Red = (ebmpBYTE) m_bgcolor[0]*255;
	BGColor.Green = (ebmpBYTE) m_bgcolor[1]*255;
	BGColor.Blue = (ebmpBYTE) m_bgcolor[2]*255;
	BGColor.Alpha = 0;
			
	RGBApixel BoxColor; 
	BoxColor.Red = (ebmpBYTE) m_boxcolor[0]*255;
	BoxColor.Green = (ebmpBYTE) m_boxcolor[1]*255;
	BoxColor.Blue = (ebmpBYTE) m_boxcolor[2]*255;
	BoxColor.Alpha = 0;

	double UnitCube[2][3] = { {0, 0, -1},  {1, 1, 0} };  //cube

	double a1 = UnitCube[0][0] - m_position[0];
	double a2 = UnitCube[1][0] - m_position[0];
	double b1 = UnitCube[0][1] - m_position[1];
	double b2 = UnitCube[1][1] - m_position[1];
	double c1 = UnitCube[0][2] - m_position[2];
	double c2 = UnitCube[1][2] - m_position[2];

	for(unsigned int i=0;i<width;i++){
		for(unsigned int j=0;j<height;j++){


			
			double t1x, t2x, t1y, t2y, t1z, t2z;
		    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);
		
			t1x =  a1 / myRayCasting[0];
			t2x =  a2 / myRayCasting[0];
			t1y =  b1 / myRayCasting[1];
			t2y =  b2 / myRayCasting[1];
			t1z =  c1 / myRayCasting[2];
			t2z =  c2 / myRayCasting[2];
			
			bool hit = RayBoxIntersection( t1x, t2x, t1y, t2y, t1z, t2z );

			if (!hit)
				file.SetPixel(i, height-j-1, BGColor);
			else
				file.SetPixel(i, height-j-1, BoxColor);
		}
	}

	file.WriteToFile(outputFile.c_str());
}
Exemplo n.º 19
0
int hpx_main()
{
    BMP SetImage;
    SetImage.SetBitDepth(24);
    SetImage.SetSize(sizeX * 2, sizeY);
    hpx::util::high_resolution_timer t;

    {
        using namespace std;

        using hpx::future;
        using hpx::async;
        using hpx::wait_all;

        int const max_iteration = 255;

        vector<future<int> > iteration;
        iteration.reserve(sizeX*sizeY);

        hpx::cout << "Initial setup completed in "
                  << t.elapsed()
                  << "s. Initializing and running futures...\n"
                  << hpx::flush;
        t.restart();

        {
            hpx::threads::executors::local_queue_executor exec;

            for (int i = 0; i < sizeX; ++i)
            {
                for (int j = 0; j < sizeY; ++j)
                {
                    float x0 = (float)i * 3.5f / (float)sizeX - 2.5f;
                    float y0 = (float)j * 2.0f / (float)sizeY - 1.0f;

                    iteration.push_back(async(exec, &fractal_pixel_value,
                        x0, y0, max_iteration));
                }
            }

            // the executor's destructor will wait for all spawned tasks to
            // finish executing
        }

        hpx::cout << sizeX*sizeY << " calculations run in "
                  << t.elapsed()
                  << "s. Transferring from futures to general memory...\n"
                  << hpx::flush;
        t.restart();

        for (int i = 0; i < sizeX; ++i)
        {
            for (int j = 0; j < sizeY; ++j)
            {
                int it = iteration[i*sizeX + j].get();
                for (int k = 0; k < 2; ++k)
                {
                    int p = (it * 255) / max_iteration;
                    SetImage.SetPixel(i * 2 + k, j, RGBApixel(p, p, p));
                }
            }
        }
    }

    hpx::cout << "Transfer process completed in "
              << t.elapsed() << "s. Writing to hard disk...\n"
              << hpx::flush;
    t.restart();

    SetImage.WriteToFile("out.bmp");

    hpx::cout << "Fractal image written to file \"out.bmp\" from memory in "
              << t.elapsed() << "s.\nShutting down process.\n"
              << hpx::flush;

    return hpx::finalize(); // Handles HPX shutdown
}
Exemplo n.º 20
0
int main(int argc, char* argv[]) {
	srand (time(NULL));

	int fracSelect = atoi(argv[1]);
	int colSelect = atoi(argv[2]);
	int x0 = atoi(argv[3]);
	int x1 = atoi(argv[4]);
	int y0 = atoi(argv[5]);
	int y1 = atoi(argv[6]);
	double width = atoi(argv[7]);
	double height = atoi(argv[8]);

	vector<Fractal*> fracSel(5);
	fracSel[0] = new Mandelbrot();
	fracSel[1] = new BurningShip();
	fracSel[2] = new BlurningShip();
	fracSel[3] = new RandNumb();
	fracSel[4] = new Eye();


	vector<Colorer*> colSel(10);
	colSel[0] = new RedAlphaColorer();
	colSel[1] = new GreenAlphaColorer();
	colSel[2] = new BlueAlphaColorer();
	colSel[3] = new GrayAlphaColorer();
	colSel[4] = new RedColorer();
	colSel[5] = new GreenColorer();
	colSel[6] = new BlueColorer();
	colSel[7] = new GrayColorer();
	colSel[8] = new EclipseColorer();
	colSel[9] = new InverseColorer();

	// Declare a new bitmap object
	BMP AnImage;
	// Set size to 640 £ 480
	AnImage.SetSize(width,height);
	// Set its color depth to 8-bits
	AnImage.SetBitDepth(32);

	cout << "File info:" << endl;
	cout << AnImage.TellWidth() << " x " << AnImage.TellHeight()
		<< " at " << AnImage.TellBitDepth() << " bpp" << endl;

#pragma omp parallel
	{
#pragma omp for
		for(int x = 0.0; x < int(width); x+= 1.0){
			for(int y = 0.0; y < int(height); y += 1.0){
				double xcurr = map(x, 0, width, x0, x1); //Change last two inputs to user input
				double ycurr = map(y, 0, height, y0, y1); //Change last two inputs to user input
				int color = fracSel[fracSelect]->testPoint(xcurr, ycurr);
				if(color >= 255) { color = 0; }
				AnImage.SetPixel(x,y,colSel[colSelect]->colorPoint(color));
			}
		}
	}
	AnImage.WriteToFile(argv[10]);

	cout << "File save complete." << endl;

	int c;
	cin >> c;
	return EXIT_SUCCESS;
};
int findPic(BMP & I, int xleft, int yleft, int boxWidth, int boxHeight, letterData data[], int letterCount)
{
  // cout << xleft << ' ' << yleft << ' ' << boxWidth << ' ' << boxHeight << ' ' << endl;
  /*****************/
  RGBApixel blue;
  blue.Red = 0;
  blue.Green = 0;
  blue.Blue = 255;
  /*****************/
  RGBApixel other;
  other.Red = 255;
  other.Green = 167;
  other.Blue = 0;
  /*****************/
  RGBApixel other1;
  other1.Red = 75;
  other1.Green = 194;
  other1.Blue = 188;
  /*****************/
  RGBApixel other2;
  other2.Red = 223;
  other2.Green = 252;
  other2.Blue = 18;
  /****************/
  RGBApixel other3;
  other3.Red = 252;
  other3.Green = 18;
  other3.Blue = 228;
  /****************/
  RGBApixel other4;
  other4.Red = 149;
  other4.Green = 86;
  other4.Blue = 83;
  /****************/
  RGBApixel other5;
  other5.Red = 255;
  other5.Green = 0;
  other5.Blue = 255;
  /****************/



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

  bool visited[width][height];

  for (int j = 0; j < height; j++)
    for (int i = 0; i < width; i++)
      visited[i][j] = false;

  int numReg = 0;
  queue Q1;

  int regCount;

  float reg1;
  float reg2;
  float reg3;
  float reg4;
  float reg5;
  float reg6;
  float reg7;

  for (int k = yleft; k < yleft + boxHeight + 1; k++){
    for (int j = xleft; j < xleft + boxWidth + 1; j++){
      if (visited[j - xleft][k - yleft] == true)
	continue;
      if(I(j, k)->Red >= 200 && I(j, k)->Green >= 200
	 && I(j, k)->Blue >= 200){
	numReg ++;

	regCount = 0;
	
	Q1.insert(new point(j, k));
	visited[j- xleft][k- yleft] = true;

	reg1 = 0;
	reg2 = 0;
	reg3 = 0;
	reg4 = 0;
	reg5 = 0;
	reg6 = 0;
	reg7 = 0;

	while(!Q1.isEmpty()){
	  point p = Q1.del();
	  int x = p.getx();
	  int y = p.gety();

	  regCount++;

	  if(numReg == 1){
	    I.SetPixel(x, y, blue);
	    reg1++;
	  }
	  else if (numReg == 2){
	    I.SetPixel(x, y, other);
	    reg2++;
	  }
	  else if (numReg == 3){
            I.SetPixel(x, y, other1);
	    reg3++;
	  }
	  else if (numReg == 4){
            I.SetPixel(x, y, other2);
	    reg4++;
	  }
	  else if (numReg == 5){
            I.SetPixel(x, y, other3);
	    reg5++;
	  }
	  else if (numReg == 6){
            I.SetPixel(x, y, other4);
	    reg6++;
	  }
	  else if (numReg == 7){
            I.SetPixel(x, y, other5);
	    reg7++;
	  }

	  

	  for (int m = y - 1; m <= y + 1; m++){
	    for (int l = x - 1; l <= x + 1; l++){
	      if (visited[l][m] == false){
		visited[l][m] = true;
		if (I(l, m)->Blue >= 200 && I(l, m)->Red >= 200 && I(l, m)->Green >= 200)
		  Q1.insert(new point(l, m));
	      }
	    }
	  }

	}
      }
      cout << reg1 << ' ' << reg1 << endl;
      data[letterCount].region1 = reg1;
      data[letterCount].region2 = reg2;
      data[letterCount].region3 = reg3;
      data[letterCount].region4 = reg4;
      data[letterCount].region5 = reg5;
      data[letterCount].region6 = reg6;
      data[letterCount].region7 = reg7;
      //cout << regCount << endl;
      //other.Red -= 64;
      //other.Green -= 64;
      //other.Blue += 64;
    }
  } 
  return numReg;
}
void Conversion(BMP & imageIn, BMP & imageOut, letterData data [])
{
  
  //RGB color declaration of green and red
  /***************/
  RGBApixel red;
  red.Red = 255;
  red.Green = 0;
  red.Blue = 0;
  /**************/
  RGBApixel green;
  green.Red = 0;
  green.Green = 255;
  green.Blue = 0;
  /*************/

  // declaration of variables to count
  //amount of lines and letters in the image
  int letterCount = 0;
  int lineCount = 0;

  //Declares the height and width of image
  int width = imageIn.TellWidth();
  int height = imageIn.TellHeight();
  

  imageOut.SetSize(width, height);

  //boolean 2d-array to verify if a pixel has
  // been visited or not
  bool visited[width][height];

  //inistializes the array setting all values equal
  //to false
  for (int i = 0; i < height; i++)
    for (int j = 0; j < width; j++)
      visited[j][i] = false;

  //x and y high and low values of a pixel
  float xlow = 0;
  float xhigh = width;

  float ylow = 0;
  float yhigh = height;

  // Declares a value for the top of a line an
  // bottom of a line
  int lineBottom = 0;
  int lineTop = 0;

  queue Q;

  //int numHoles = -1;

  //int pixelCount = 0;

  float ratio = 0;

  vector<int>holes;
  vector<float>AR;
  vector<float>area;
  vector<int>gPixel;
  queue GQ;

  float greenPixel;

  // Nested loops to loop over every pixel in the image
  for (int j = 0; j < height; j++){// Start for1
    for (int k = 0; k < width; k++){// Start for 2
      if (visited[k][j] == true)
	continue;
      //Checks to see if the pixel is black
      if (imageIn(k, j)->Red >= 20){
	visited[k][j] = true;
	continue;
      }
      greenPixel = 0;  
      letterCount++;

      float q1 = 0;
      float q2 = 0;
      float q3 = 0;
      float q4 = 0;


      xlow = k;
      ylow = j;
      xhigh = k;
      yhigh = j;

      Q.insert(new point(k, j));

      int currentTop = ylow;
      int currentBottom = yhigh;

      visited[k][j] = true;

      //data[letterCount].area = (xhigh - xlow) * (yhigh - ylow);

      while(!Q.isEmpty()){// Start while
	//gets point value of a pixel
	greenPixel++;
	point p = Q.del();
	int x = p.getx();
	int y = p.gety();
	//cout << x << ' ' << y << endl;
	int w = ((xhigh - xlow) / 2) + xlow;
	int h = ((yhigh - ylow) / 2) + xlow;
	//cout << w << ' ' << h << endl;
	if ( x <= w && x >= xlow ){
	  if ( y <= h && y >= ylow )
	    q1++;
	  if ( y >= h && y <= yhigh )
	    q3++;
	}
	if ( x >= w && x <= xhigh ){
	  if ( y <= h && y >= ylow )
	    q2++;
	  if ( y >= h && y <= yhigh )
	    q4++;
	}


	GQ.insert(new point(x, y));

	imageOut.SetPixel(x, y, green);

	if(x < xlow)
	  xlow = x;
	if(y < ylow)
	  ylow = y;
	if (x > xhigh)
	  xhigh = x;
	if (y > yhigh)
	  yhigh = y;

	//finds the neighbors of a pixel by
	// finding the pixels around it that are black
	for (int l = y - 1; l <= y + 1; l++){// Start for3
	  for (int m = x - 1; m <= x + 1; m++){// Start for 4
	    if (visited[m][l] == false){// Start if1
	      visited [m][l] = true;
	      if (imageIn(m, l)->Red == 0)
		Q.insert(new point(m, l));
	    }// End if1
	  }// End for4
	}// End for 3
      }// End whil

      //draws bounding boxes around each letter
      for (int i = xlow - 1; i <= xhigh + 1; i++){
	imageOut.SetPixel(i, ylow - 1, red);
	imageOut.SetPixel(i, yhigh + 1, red);
      }

      for (int j = ylow - 1; j <= yhigh + 1; j++){
	imageOut.SetPixel(xlow - 1, j, red);
	imageOut.SetPixel(xhigh + 1, j, red);
      }

      //finds the number of lines in the image
      if (currentTop > lineBottom){
	lineCount++;
	lineTop = currentTop;
	lineBottom = currentBottom;
      }

      //cout << xhigh - xlow << ' ' << yhigh - ylow << endl;


      int numHoles = findPic (imageOut, xlow, ylow, xhigh - xlow, yhigh - ylow, data, letterCount);
      data[letterCount].holes = numHoles;
      data[letterCount].gPixelCount = greenPixel;

      data[letterCount].ratio = (xhigh - xlow)/(yhigh - ylow);

      data[letterCount].quad1 = q1;
      data[letterCount].quad2 = q2;
      data[letterCount].quad3 = q3;
      data[letterCount].quad4 = q4;

      data[letterCount].area = (xhigh - xlow) * (yhigh - ylow);
      cout << data[letterCount].area << endl;

      /*** for the vector *******/
      holes.push_back(numHoles);

      AR.push_back(ratio);
      gPixel.push_back(greenPixel);

      /****** Finished **********/

      //cout << data[k - k + 1].pixelCount << endl;

      //cout << data[letterCount].quad1 << ' ' << data[letterCount].quad2 << ' ' << data[letterCount].quad3 << 
      //' ' << data[letterCount].quad4 << ' ' << endl;

    }// End for2
  }// End for1

  //cout << "Letter Count: " << letterCount << endl;
  //cout << "Line Count: " << lineCount << endl;
  //cout << numHoles << endl;
  print(letterCount, data);
  // cout << greenPixel << endl;
  //percent(letterCount, area, GQ, xhigh - xlow, yhigh - ylow);
}
Exemplo n.º 23
0
Arquivo: x.cpp Projeto: J-Liu/EasyBMP
int main(int argc, char* argv[])
{
  int width = 161, height = 161, layer = 80;
  int i, j;

  nifti_image *nim = NULL;
  char *fin = "/Users/jia/Desktop/F1_58-ed.nii";

  nim = nifti_image_read(fin, 1);
  if (!nim) {
    fprintf(stderr,"** failed to read NIfTI image from '%s'\n", fin);
    return 2;
  }

  printf("%dD, x=%d y=%d z=%d t=%d u=%d v=%d w=%d\n",
         nim->ndim, nim->nx, nim->ny, nim->nz,
         nim->nt, nim->nu, nim->nv, nim->nw);
  printf("nvox=%d nbyper=%d\n",
         nim->nvox, nim->nbyper);
  printf("%fD x=%f y=%f z=%f t=%f u=%f v=%f w=%f\n",
         nim->pixdim[0], nim->dx, nim->dy, nim->dz,
         nim->dt, nim->du, nim->dv, nim->dw);

  unsigned short *q = static_cast<unsigned short *>(nim->data);
  unsigned short max = 0, min = 0, mean = 0;
  unsigned long long sum = 0;

  for (int i = width*height*layer; i < width*height*(layer+1); i++) {
    sum += q[i];
//    printf("%u\n", q[i]);
    if (q[i] > max)
      max = q[i];
  }

  mean = sum / (width*height);
  printf("max=%u min=%u mean=%u\n", max, min, mean);

//===================================================================
//        suv_max_group = max(temp_img)*weight/(decay_factor*dose);
//        suv_mean_group = mean(temp_img)*weight/(decay_factor*dose);
//weight INPUT
//dose INPUT
//time INPUT
//half_life INPUT
//decay_factor  = 2^(-time*60/half_life);
//===================================================================

  int weight = 156;
  int dose = 156;
  int time = 16;
  int half_life = 15;
  int decay_factor = 2^(-time*60/half_life);
  printf("weight=%d decay_factor=%d dose=%d\n", weight, decay_factor, dose);

  int suv_max = max * weight / (decay_factor * dose);
  int suv_mean = mean * weight / (decay_factor * dose);
  printf("suv_max=%d suv_mean=%d\n", suv_max, suv_mean);

  unsigned short p[width*height];
  for (int i = 0; i < width*height; i++) {
    p[i] = q[width*height*layer + i] * 255 / max;
  }

  BMP Output;
  Output.SetSize(width, height);
  Output.SetBitDepth(24);

  for (i = 0; i < height; i++) {
    for (j = 0; j < width; j++) {
      RGBApixel NewPixel;

      if (check_area(i, j) == 1) {
          NewPixel.Red = p[i*width + j];
          NewPixel.Green = p[i*width + j];
          NewPixel.Blue = p[i*width + j];
      } else {
          NewPixel.Red = 0;
          NewPixel.Green = 0;
          NewPixel.Blue = 0;
      }
      NewPixel.Alpha = 0;
      Output.SetPixel(i, j, NewPixel);
    }
  }

  Output.SetBitDepth(32);
  Output.WriteToFile("EasyBMPoutput32bpp.bmp");

  Output.SetBitDepth(24);
  Output.WriteToFile("EasyBMPoutput24bpp.bmp");

  Output.SetBitDepth(8);
  Output.WriteToFile("EasyBMPoutput8bpp.bmp");

  Output.SetBitDepth(4);
  Output.WriteToFile("EasyBMPoutput4bpp.bmp");

  Output.SetBitDepth(1);
  Output.WriteToFile("EasyBMPoutput1bpp.bmp");

  Output.SetBitDepth(24);
  Rescale(Output, 'p', 50);
  Output.WriteToFile("EasyBMPoutput24bpp_rescaled.bmp");

  /* and clean up memory */
  nifti_image_free(nim);

  return 0;
}