コード例 #1
0
ファイル: main.cpp プロジェクト: berak/vst2.0
unsigned int loadImage(const char * fname)
{
	if ( ! fname )
	{
		return 0;
	}
	BMP bmp;
	if ( ! bmp.ReadFromFile(fname) )
	{
		printf( "not loaded : %s\n",fname );
		return 0;
	}

	int w = bmp.TellWidth();
	int h = bmp.TellHeight();
	int d = bmp.TellBitDepth() / 8;
    RGBApixel* pix = bmp(0,0);
    char bytes[0x7ffff], *b=bytes;
    for ( int j=0; j<h; j++ )
    {
        for ( int i=0; i<w; i++ )
        {
			RGBApixel pix = bmp.GetPixel(i, j);
            *b++ = pix.Red;
            *b++ = pix.Green;
            *b++ = pix.Blue;
			if ( d == 4 )
				*b++ = pix.Alpha;            
        }        
    }
    size_t i = RGL::texCreate( w, h, d, bytes, true );;
    printf( "created : %d [%d %d %d] %s\n", i, w,h,d,fname );
    return i;
}
コード例 #2
0
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;
}
コード例 #3
0
int importImg(char* filename){
  BMP InputIMG;
  cout << "Starting BMP final code" << endl;
  
  cout << "Open File: " << filename << endl;
  if(!InputIMG.ReadFromFile(filename)){
    cout << "Invalid File Name..." << endl;
    return EXIT_FAILURE;
  }

  printFileInfo(InputIMG);
  COLUMNS = InputIMG.TellWidth();  // num cols
  ROWS = InputIMG.TellHeight(); // num rows
  DEPTH = InputIMG.TellBitDepth();
  
  //allocate Memory
  imageArray = new int *[COLUMNS] ; // row memory allocation
  for( int i = 0 ; i < COLUMNS ; i++ ){ // column memory allocation
    imageArray[i] = new int[ROWS];
  }

  thetas = new float *[COLUMNS];
  for(int i = 0; i < COLUMNS; i++) {
    thetas[i] = new float[ROWS];
  }

  magArray = new int *[COLUMNS];
  for(int i=0; i < COLUMNS; i++) {
    magArray[i] = new int[ROWS];
  }

  int Temp;
  cout<< "Saving Brightness values" << endl;
  for( int j=0 ; j < ROWS ; j++)
    {
      for( int i=0 ; i < COLUMNS ; i++)
	{
	  Temp = (int) floor( 0.299*InputIMG(i,j)->Red +
			      0.587*InputIMG(i,j)->Green +
			      0.114*InputIMG(i,j)->Blue );
	  imageArray[i][j] = Temp;
	}
    }

}
コード例 #4
0
void printFileInfo(BMP image){
  cout << endl << "File info:" << endl;
  cout << image.TellWidth() << " x " << image.TellHeight()
       << " at " << image.TellBitDepth() << " bpp" << endl << endl;
}
コード例 #5
0
ファイル: heliBMP.cpp プロジェクト: mziwisky/helipov
int main( int argc, char* argv[] )
{
    if( argc != 4 )
	{
		cout << "Usage: " << argv[0] << " (-t|-b) <inputfile.bmp> <outputfile.txt>"
		   	<< endl << endl;
		return 1;
	}
	
	//eventually, take these as parameters
	ringID = 128;
	ringOD = 686;
	numLEDs = 32;
	numSlices = 256;
	int *ledOrder = NULL;

	if( string(argv[1]) == "-t" ) {
		mirror = false;
		rotation = 0;
		int arr[] = {16,18,20,22,24,26,28,30,17,19,21,23,25,27,29,31,
							15,13,11,9,7,5,3,1,14,12,10,8,6,4,2,0};
		ledOrder = &arr[0];
	}
	else if( string(argv[1]) == "-b" ) {
		mirror = true;
		rotation = 0;
		int arr[] = {30,28,26,24,22,20,18,16,31,29,27,25,23,21,19,17,
							1,3,5,7,9,11,13,15,0,2,4,6,8,10,12,14};
		ledOrder = &arr[0];
	}
	else {
		cout << "Usage: " << argv[0] << " (-t|-b) <inputfile.bmp> <outputfile.txt>"
		   	<< endl << endl;
		return 1;
	}

	// ledOrder[0] = 16 means to light LED at r=0 (first LED), the 17th bit must be set
	// (set the bit with |= (1 << 16).
	// So ledOrder[31] = 0 means to light LED at r=31 (32nd LED), the 1st bit must be set.
	
	// read the bitmap and make sure it's square and 1 bpp
	if (!input.ReadFromFile(argv[2]))
		return 1;
	
	width = input.TellWidth();
	height = input.TellHeight();
	depth = input.TellBitDepth();

	cout << "BMP info:  " << width << " x " << height << " @ " << depth << " bpp" << endl;
	
	if ( width != height || depth != 1 )
	{
		cout << "Bad file -- must be square and 1 bpp depth." << endl << endl;
		return 1;
	}

	char* outputFile = argv[3];

	//calcGeometry(ringID, ringOD, height, width, numLEDs, numSlices);
	calcGeometry();

	// make an array of radialpixels
	RadialPixel radpix[numLEDs * numSlices];
	
	for (int j=0; j<numSlices; j++) {
		for (int i=0; i<numLEDs; i++) {
			radpix[numLEDs * j + i].th = j;
			radpix[numLEDs * j + i].r = i;
			setRadialPixel(&radpix[numLEDs * j + i]);
		}
	}

	// translate the radialpixels to bytecode
	FILE *out;
	out = fopen (outputFile,"w");
	makeByteCode(radpix, ledOrder, out);
	fclose(out);

	cout << "Byte code written to " << outputFile << endl << endl;
	return 0;
}
コード例 #6
0
ファイル: bmp_io.cpp プロジェクト: PsyCommando/ppmdu
        bool ImportBMP( _TImg_t           & out_timg, 
                        const std::string & filepath, 
                        unsigned int        forcedwidth, 
                        unsigned int        forcedheight, 
                        bool                erroronwrongres )
    {
        //The max nb of colors possible with that bitdepth!
        static const unsigned int NB_Colors_Support = utils::do_exponent_of_2_<_TImg_t::pixel_t::mypixeltrait_t::BITS_PER_PIXEL>::value;
        
        bool   hasWarnedOORPixel = false; //Whether we warned about out of range pixels at least once during the pixel loop! If applicable..
        bool   isWrongResolution = false;
        BMP    input;
        auto & outpal = out_timg.getPalette();

        input.ReadFromFile( filepath.c_str() );

        if( input.TellBitDepth() != _TImg_t::pixel_t::GetBitsPerPixel() )
        {
            //We don't support anything with a different bitdepth!
            //Mention the palette length mismatch
            cerr <<"\n<!>-ERROR: The file : " <<filepath <<", is not a " <<_TImg_t::pixel_t::GetBitsPerPixel() 
                 <<"bpp indexed bmp ! Its in fact " <<input.TellBitDepth() <<"bpp!\n"
                 <<"Make sure the bmp file is saved as " <<_TImg_t::pixel_t::GetBitsPerPixel() <<"bpp, "
                 <<NB_Colors_Support << " colors!\n";

            return false;
        }

        //Only force resolution when we were asked to!
        if( forcedwidth != 0 && forcedheight != 0 )
            isWrongResolution = input.TellWidth() != forcedwidth || input.TellHeight() != forcedheight;
        if( erroronwrongres && isWrongResolution )
        {
            cerr <<"\n<!>-ERROR: The file : " <<filepath <<" has an unexpected resolution!\n"
                 <<"             Expected :" <<forcedwidth <<"x" <<forcedheight <<", and got " <<input.TellWidth() <<"x" <<input.TellHeight() 
                 <<"! Skipping!\n";
            return false;
        }


        if( utils::LibraryWide::getInstance().Data().isVerboseOn() && input.TellNumberOfColors() <= NB_Colors_Support )
        {
            //Mention the palette length mismatch
            cerr <<"\n<!>-Warning: " <<filepath <<" has a different palette length than expected!\n"
                 <<"Fixing and continuing happily..\n";
        }
        out_timg.setNbColors( NB_Colors_Support );

        //Build palette
        const unsigned int nbColors = static_cast<unsigned int>( ( input.TellNumberOfColors() > 0 )? input.TellNumberOfColors() : 0 );
        if( nbColors == 0 )
            throw runtime_error("ERROR: BMP image being imported has an invalid palette!");
        for( unsigned int i = 0; i < nbColors; ++i )
        {
            RGBApixel acolor = input.GetColor(i);
            outpal[i].red   = acolor.Red;
            outpal[i].green = acolor.Green;
            outpal[i].blue  = acolor.Blue;
            //Alpha is ignored
        }

        //Image Resolution
        int tiledwidth  = (forcedwidth  != 0)? forcedwidth  : input.TellWidth();
        int tiledheight = (forcedheight != 0)? forcedheight : input.TellHeight();

        //Make sure the height and width are divisible by the size of the tiles!
        if( tiledwidth % _TImg_t::tile_t::WIDTH )
            tiledwidth = CalcClosestHighestDenominator( tiledwidth,  _TImg_t::tile_t::WIDTH );

        if( tiledheight % _TImg_t::tile_t::HEIGHT )
            tiledheight = CalcClosestHighestDenominator( tiledheight,  _TImg_t::tile_t::HEIGHT );

        //Resize target image
        out_timg.setPixelResolution( tiledwidth, tiledheight );

        //If the image we read is not divisible by the dimension of our tiles, 
        // we have to ensure that we won't got out of bound while copying!
        int maxCopyWidth  = out_timg.getNbPixelWidth();
        int maxCopyHeight = out_timg.getNbPixelHeight();

        if( maxCopyWidth != input.TellWidth() || maxCopyHeight != input.TellHeight() )
        {
            //Take the smallest resolution, so we don't go out of bound!
            maxCopyWidth  = std::min( input.TellWidth(),  maxCopyWidth );
            maxCopyHeight = std::min( input.TellHeight(), maxCopyHeight );
        }

        //Copy pixels over
        for( int i = 0; i < maxCopyWidth; ++i )
        {
            for( int j = 0; j < maxCopyHeight; ++j )
            {
                RGBApixel apixel = input.GetPixel(i,j);

                //First we need to find out what index the color is..
                gimg::colorRGB24::colordata_t colorindex = FindIndexForColor( apixel, outpal );

                if( !hasWarnedOORPixel && colorindex == -1 )
                {
                    //We got a problem
                    cerr <<"\n<!>-Warning: Image " <<filepath <<", has pixels with colors that aren't in the colormap/palette!\n"
                         <<"Defaulting pixels out of range to color 0!\n";
                    hasWarnedOORPixel = true;
                    colorindex        = 0;
                }

                out_timg.getPixel( i, j ) = colorindex;
            }
        }

        return true;
    }
コード例 #7
0
ファイル: main.cpp プロジェクト: Chohonski/FractalMaker
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;
};
コード例 #8
0
ファイル: SoXipLoadBMP.cpp プロジェクト: mcaylus/XipNehe
SbXipImage* SoXipLoadBMP::loadBMP(const char *fileName)
{
    try
    {
        BMP bmp;
        bmp.ReadFromFile(fileName);

        int numBits = bmp.TellBitDepth();
        int width = bmp.TellWidth();
        int height = bmp.TellHeight();

        int bitsStored = 8;
        int samplesPerPixel = 0;
        SbXipImage::ComponentType compType = SbXipImage::INTERLEAVED;
        SbXipImage::ComponentLayoutType compLayoutType = SbXipImage::RGB;

        if(numBits<=24)
        {
            samplesPerPixel = 3;
            compLayoutType = SbXipImage::RGB;
        }
        else if(numBits == 32)
        {
            samplesPerPixel = 4;
            compLayoutType = SbXipImage::RGBA;
        }

        SbVec3f pos(0, 0, 0);
        SbVec3f scale(width, height, 1);
        SbMatrix rotMatrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1);

        SbMatrix modelMatrix;
        modelMatrix.setScale(scale);
        //modelMatrix.setTransform(pos, SbRotation(rotMatrix), scale);

        SbXipImage *image = new SbXipImage(SbXipImageDimensions(width, height, 1), SbXipImageDimensions(width, height, 1),
                                           SbXipImage::UNSIGNED_BYTE, bitsStored, samplesPerPixel, compType, compLayoutType, modelMatrix);
        unsigned char *buffer = (unsigned char *) image->refBufferPtr();

        if(numBits<=24)
        {
            for(int i = 0; i < height; i++)
            {
                for(int j = 0; j < width; j++)
                {
                    RGBApixel pixel = bmp.GetPixel(j,(height -1) - i );

                    buffer[3*i*width+3*j] = pixel.Red;
                    buffer[3*i*width+3*j+1] = pixel.Green;
                    buffer[3*i*width+3*j+2] = pixel.Blue;

                }
            }
        }
        else if(numBits == 32)
        {
            for(int i=0; i<height; i++)
            {
                for(int j=0; j<width; j++)
                {
                    RGBApixel pixel = bmp.GetPixel(j, height-i);

                    buffer[4*i*width+4*j] = pixel.Red;
                    buffer[4*i*width+4*j+1] = pixel.Green;
                    buffer[4*i*width+4*j+2] = pixel.Blue;
                    buffer[4*i*width+4*j+3] = pixel.Alpha;
                }
            }
        }

        image->unrefBufferPtr();

        return image;
    }
    catch(...)
    {
        SoDebugError::postInfo(__FILE__, "Exception loadBMP");

        // Fix me need to delete allocated memory!
        return 0;
    }
}