Beispiel #1
0
/*
 * IconFromBMP
 */
void IconFromBMP()
{
	CRaster bmp;
	int rval = bmp.LoadBMP(bannerfilename);
	if (rval < 0) exit(1);

	if (bmp.width != 32 || bmp.height != 32) {
		fprintf(stderr, "Image should be 32 x 32.\n");
		exit(1);
	}

	Banner banner;
	memset(&banner, 0, sizeof(banner));
	banner.version = 1;

	// tile data (4 bit / tile, 4x4 total tiles)
	// 32 bytes per tile (in 4 bit mode)
	for (int row=0; row<4; row++)
	{
		for (int col=0; col<4; col++)
		{
			for (int y=0; y<8; y++)
			{
				for (int x=0; x<8; x+=2)
				{
					unsigned char b0 = bmp[row*8 + y][col*8 + x + 0];
					unsigned char b1 = bmp[row*8 + y][col*8 + x + 1];
					banner.tile_data[row][col][y][x/2] = (b1 << 4) | b0;
				}
			}
		}
	}

	// palette
	for (int i = 0; i < 16; i++)
	{
		banner.palette[i] = RGBQuadToRGB16(bmp.palette[i]);
	}

	// put title
	for (int i=0; bannertext[i]; i++)
	{
		char c = bannertext[i];
		if (c == ';') c = 0x0A;
		for (int l=0; l<6; l++)
		{
			banner.title[l][i] = c;
		}
	}
	
	// calculate CRC
	banner.crc = CalcBannerCRC(banner);

	fwrite(&banner, 1, sizeof(banner), fNDS);
}
int main()
{

    static CRaster bmp, bmp_temp;
    int width_tile, minus_sep, total_cut, nhor, nver, acum1=0, acum2=0, nver_aux, nhor_aux, i,j,i_aux,j_aux;


    //TEMPORAL
    int x_aux = 0;
    int intnsig_aux;

    cout << "********************************\n";
    cout << "*  CUTTER WITH FALCON SUPPORT  *\n";
    cout << "********************************" << endl << endl << "By Com_GP ([email protected]) 06/12/2002" << endl << "SUPPORTS 128x128 AND 256x256 TILES WITH 2 PIXELS OF SEPARATION" << endl << endl;


    RGBQUAD *rgbq_aux;        //Points wherever the palette starts
//    char ** Raster_aux, ** Raster_main;        //Points wherever the image bytes start
    char cc [256];
    char string1 [16];

    //Ask for the name of the bmp file
    printf ("Name of the file you want to open (EX: Htile24bpp.bmp)\n");
    gets (cc);
    printf ("\n\n");

    bmp.LoadBMP (cc);

    ofstream pr;

    pr.open("pr.txt");
    if(!pr)
        cout << "ERROR GUARDANDO EN EL FICHERO" << endl;
    else
    {

        pr << "# Start Set X has X tiles, Terrain type 4" << endl << "SET 4" << endl;

        int menus = 0;
        while( (menus != 1) && (menus != 2))
        {
            //The width of the tile
            cout << "Choose the width and height (its a square) of the tile" << endl;
            cout << "    (1).- 128x128\n" << "    (2).- 256x256\n" << endl;
            cout << "OPTION --> ";
            cin >> menus;
            cout << endl;
            switch( menus )
            {
            case 1:
                width_tile = 128;
                break;
            case 2:
                width_tile = 256;
                break;
            default:
                cout << "ERROR, MUST BE BETWEEN 1 AND 2" << endl;
                system("PAUSE");
                break;
            }
        }

        //Separation between tiles
        cout << "Separation between tiles = ";
        minus_sep = 2;
        cout << minus_sep << endl;



        //bmp_temp = bmp ASIGNACIONES DE TODOS LOS CAMPOS INCLUIDA LA PALETA
        bmp_temp.Width = width_tile;
        bmp_temp.Height = width_tile;
        bmp_temp.BPP = bmp.BPP;
        bmp_temp.Palette = bmp.Palette;
        bmp_temp.pbmi = bmp.pbmi;
        bmp_temp.pbmi->bmiHeader.biHeight = (width_tile);
        bmp_temp.pbmi->bmiHeader.biWidth = (width_tile);

        //new temp memory for the temp tile

        total_cut = width_tile + minus_sep;

        //HASTA AQUI BIEN 23/11/02 01:19
        bmp_temp.Raster = new char*[total_cut];
        for( i = 0; i <= total_cut; i++ )
            bmp_temp.Raster[i] = new char[total_cut];

        //HASTA AQUI BIEN 23/11/02 01:23
        nver = (bmp.Width / total_cut);
//            nver = (bmp.Height /total_cut);

        cout << "Name of the FILE (ex: HnameX*.bmp, NO MORE THAN 5 CHARACTERS) to save\n";
        gets(string1);
//            string1 += "Hname**";
//            string1 = string1 + ".bmp";

        int temp_i = 0;
        cout << "CORRECTOR FOR INCLINATION = " << temp_i << endl;


        nver_aux = 0;
        nhor_aux = 0;
        while( nver > 0)
        {
            nhor = ( bmp.Height / total_cut );
            while( nhor > 0)
            {
                acum1 = 0;
                i_aux = 0;
                for ( i = (total_cut*(acum1+nhor_aux)); i < (((acum1+nhor_aux)*total_cut)+(width_tile)); i++ )
                {
                    acum2 = 0;
                    j_aux = 0;
                    for ( j = (total_cut*(acum2+nver_aux)); j < (((acum2+nver_aux)*total_cut)+(width_tile)); j++ )
                    {
                        bmp_temp.Raster[i_aux][j_aux] = bmp.Raster[i][j];//Aqui hay algun problema
//                               cout <<"[" << i_aux << "][" << j_aux <<"]," <<"  [" << i << "][" << j <<"]" << endl;
                        j_aux++;
                    }
//                         system("PAUSE");
                    acum2++;
                    i_aux++;
                }
                acum1++;
//                     nver_aux = 0;

//                     cout <<"[" << nver << "][" << nhor <<"]" << endl;
//                     cout <<"[" << nver_aux << "][" << nhor_aux <<"]" << endl << endl;

                nhor--;
                nhor_aux++;



                x_aux++;

                switch( nhor_aux - 1 )
                {
                case 0:
                    switch( nver_aux )
                    {
//[0,x]
                    case 0:
                        string1[6] = '7';
                        cout << "TILE 7 ---> DONE" << endl;
                        break;
                    case 1:
                        string1[6] = 'B';
                        cout << "TILE b ---> DONE" << endl;
                        break;
                    case 2:
                        string1[6] = '8';
                        cout << "TILE 8 ---> DONE" << endl;
                        break;
                    case 3:
                        string1[6] = 'C';
                        cout << "TILE c ---> DONE" << endl;
                        break;
                    case 4:
                        string1[6] = '4';
                        cout << "TILE 4 ---> DONE" << endl;
                        break;
                    default:
                        break;
                    }
                    break;
//[1,x]
                case 1:
                    switch( nver_aux )
                    {
                    case 0:
                        string1[6] = 'D';
                        cout << "TILE d ---> DONE" << endl;
                        break;
                    case 1:
                        string1[6] = 'E';
                        cout << "TILE e ---> DONE" << endl;
                        break;
                    case 2:
                        string1[6] = 'A';
                        cout << "TILE a ---> DONE" << endl;
                        break;
                    case 3:
                        string1[6] = 'F';
                        cout << "TILE f ---> DONE" << endl;
                        break;
                    case 4:
                        string1[6] = '5';
                        cout << "TILE 5 ---> DONE" << endl;
                        break;
                    default:
                        break;
                    }
                    break;
//[2,x]
                case 2:
                    switch( nver_aux )
                    {
                    case 0:
                        string1[6] = 'x';
                        break;
                    case 1:
                        string1[6] = 'x';
                        break;
                    case 2:
                        string1[6] = '2';
                        cout << "TILE 2 ---> DONE" << endl;
                        break;
                    case 3:
                        string1[6] = '3';
                        cout << "TILE 3 ---> DONE" << endl;
                        break;
                    case 4:
                        string1[6] = '1';
                        cout << "TILE 1 ---> DONE" << endl;
                        break;
                    default:
                        break;
                    }
                    break;
                default:
                    break;
                }

//Borrar                   cout << (string1[5]) << " " << char(nver_aux) << endl;
//                   string1[7] = char(48 + nhor_aux - 1);
//                   string1[8] = char(48 + nver_aux);

                //GUARDAR EN FICHERO
                if( string1[6] != 'x' ) {
                    SaveBMP (string1, bmp_temp, temp_i );
                    string1[8]='p';
                    string1[9]='c';
                    string1[10]='x';
                    pr << string1 << " 0 0" <<  endl;
                    string1[8]='b';
                    string1[9]='m';
                    string1[10]='p';
                }
//                     system("PAUSE");




            }

            nhor_aux = 0;
            nver--;
            nver_aux++;
        }
        cout << "CUTTING DONE THE FILES SHOULD BE DONE" << endl;
        cout << "DONT FORGET TO ERASE THE HnameXx.bmp, ITS UNUSEFULL" << endl;
        system("PAUSE");

        pr << "ENDSET" << endl << endl;

    }
    return 0;
}
int main()
{

    static CRaster bmp, bmp_temp;
    int width_tile, minus_sep, total_cut, nhor, nver, acum1=0, acum2=0, nver_aux, nhor_aux, i,j,i_aux,j_aux;


    //TEMPORAL
    int x_aux = 0;
    int intnsig_aux;

    cout << "********************************\n";
    cout << "*  CUTTER WITH FALCON SUPPORT  *\n";
    cout << "********************************" << endl << endl << "By Com_GP ([email protected]) 06/12/2002" << endl << "SUPPORTS 128x128 AND 256x256 TILES WITH 2 PIXELS OF SEPARATION" << endl << endl;
    system("PAUSE");

    RGBQUAD *rgbq_aux;        //Points wherever the palette starts
//    char ** Raster_aux, ** Raster_main;        //Points wherever the image bytes start
//    char cc [256];
//    char string1 [12];
    string cc, string1;

    string s_aux;
    int nfiles;
    int menus = 0;

  ofstream pr;
  ifstream ifs;

  pr.open("texturebin.txt");
  if(!pr)
         cout << "ERROR GUARDANDO EN EL FICHERO" << endl;
  else
  {

  ifs.open("list8bpp.txt");
  if(!ifs)
      cout << "ERROR OPENING THE SCRIPT FILE" << endl;
  else{

  getline( ifs, s_aux);
  nfiles = String2Int( s_aux );
  cout << "NUMBER OF FILES = " << nfiles << endl;


while( nfiles > 0 )
{
  getline( ifs, cc );
  getline( ifs, string1 );

  getline( ifs, s_aux );
  menus = String2Int( s_aux );

  //Ask for the name of the bmp file
  printf ("The file opened is ------> ");
  cout << cc;
  printf ("\n\n");

  bmp.LoadBMP (cc.c_str());

        pr << "# Start Set X has X tiles, Terrain type 4" << endl << "SET 4" << endl;


            //The width of the tile
            cout << "The width and height (its a square) of the tile is ---> ";
            switch( menus )
            {
                 case 1:
                     cout << "128x128\n\n";
                     width_tile = 128;
                 break;
                 case 2:
                     cout << "256x256\n\n";
                     width_tile = 256;
                 break;
                 case 3:
                     cout << "512x512\n\n";
                     width_tile = 512;
                 break;
                 default:
                     cout << "ERROR, MUST BE BETWEEN 1 AND 2, CHECK THE list8bpp.txt FILE" << endl;
                     system("PAUSE");
                 break;
            }

            //Separation between tiles
            cout << "Separation between tiles = ";
            minus_sep = 2;
            cout << minus_sep << endl;



            //bmp_temp = bmp ASIGNACIONES DE TODOS LOS CAMPOS INCLUIDA LA PALETA
            bmp_temp.Width = width_tile;
            bmp_temp.Height = width_tile;
            bmp_temp.BPP = bmp.BPP;
            bmp_temp.Palette = bmp.Palette;
            bmp_temp.pbmi = bmp.pbmi;
            bmp_temp.pbmi->bmiHeader.biHeight = (width_tile);
            bmp_temp.pbmi->bmiHeader.biWidth = (width_tile);

            //new temp memory for the temp tile

            total_cut = width_tile + minus_sep;

            //HASTA AQUI BIEN 23/11/02 01:19
            bmp_temp.Raster = new char*[total_cut];
            for( i = 0; i <= total_cut; i++ )
		          bmp_temp.Raster[i] = new char[total_cut];

            //HASTA AQUI BIEN 23/11/02 01:23
            nver = (bmp.Width / total_cut);
//            nver = (bmp.Height /total_cut);

            cout << "Name of the FILE in which is gonna be saved";
            cout << string1;
            cout << endl;

            int temp_i = 0;
            cout << "CORRECTOR FOR INCLINATION = " << temp_i << endl;


            nver_aux = 0;
            nhor_aux = 0;
            while( nver > 0)
            {
                nhor = ( bmp.Height / total_cut );
                while( nhor > 0)
                {
                     acum1 = 0;
                     i_aux = 0;
                     for ( i = (total_cut*(acum1+nhor_aux)); i < (((acum1+nhor_aux)*total_cut)+(width_tile)); i++ )
                     {
                         acum2 = 0;
                         j_aux = 0;
                         for ( j = (total_cut*(acum2+nver_aux)); j < (((acum2+nver_aux)*total_cut)+(width_tile)); j++ )
                         {
                               bmp_temp.Raster[i_aux][j_aux] = bmp.Raster[i][j];//Aqui hay algun problema
                               j_aux++;
                         }

                         acum2++;
                         i_aux++;
                     }
                     acum1++;
                     nhor--;
                     nhor_aux++;



                     x_aux++;


/*****************
cout << "nver_aux = " << nver_aux << endl;
cout << "nhor_aux -1 = " << nver_aux - 1 << endl;
system("PAUSE");
*****************/
                   switch( nhor_aux - 1 )
                   {
                           case 0:
                               switch( nver_aux )
                               {
//[0,x]
                                   case 0:
                                       string1[7] = '0';
                                       cout << "TILE 0 ---> DONE" << endl;
                                   break;
                                   case 1:
                                       string1[7] = '1';
                                       cout << "TILE 1 ---> DONE" << endl;
                                   break;
                                   case 2:
                                       string1[7] = '2';
                                       cout << "TILE 2 ---> DONE" << endl;
                                   break;
                                   case 3:
                                       string1[7] = '3';
                                       cout << "TILE 3 ---> DONE" << endl;
                                   break;
                                   default:
                                   break;
                               }
                           break;
//[1,x]
                           case 1:
                               switch( nver_aux )
                               {
                                   case 0:
                                       string1[7] = '4';
                                       cout << "TILE 4 ---> DONE" << endl;
                                   break;
                                   case 1:
                                       string1[7] = '5';
                                       cout << "TILE 5 ---> DONE" << endl;
                                   break;
                                   case 2:
                                       string1[7] = '6';
                                       cout << "TILE 6 ---> DONE" << endl;
                                   break;
                                   case 3:
                                       string1[7] = '7';
                                       cout << "TILE 7 ---> DONE" << endl;
                                   break;
                                   default:
                                   break;
                               }
                           break;
//[2,x]
                           case 2:
                               switch( nver_aux )
                               {
                                   case 0:
                                       string1[7] = '8';
                                       cout << "TILE 8 ---> DONE" << endl;
                                   break;
                                   case 1:
                                       string1[7] = '9';
                                       cout << "TILE 9 ---> DONE" << endl;
                                   break;
                                   case 2:
                                       string1[7] = 'A';
                                       cout << "TILE A ---> DONE" << endl;
                                   break;
                                   case 3:
                                       string1[7] = 'B';
                                       cout << "TILE B ---> DONE" << endl;
                                   break;
                                   default:
                                   break;
                               }
                           break;

//[3,x]
                           case 3:
                               switch( nver_aux )
                               {
                                   case 0:
                                       string1[7] = 'C';
                                       cout << "TILE C ---> DONE" << endl;
                                   break;
                                   case 1:
                                       string1[7] = 'D';
                                       cout << "TILE D ---> DONE" << endl;
                                   break;
                                   case 2:
                                       string1[7] = 'E';
                                       cout << "TILE E ---> DONE" << endl;
                                   break;
                                   case 3:
                                       string1[7] = 'F';
                                       cout << "TILE F ---> DONE" << endl;
                                   break;
                                   default:
                                   break;
                               }
                           break;

                           default:
                           break;
                   }


                     cout << x_aux << endl;
                     //GUARDAR EN FICHERO
                     SaveBMP (string1.c_str(), bmp_temp, temp_i );

                     string1[9]='p';
                     string1[10]='c';
                     string1[11]='x';

                     switch( x_aux )
                               {
                                   case 1:
                                       string1[7] = '0';
                                   break;
                                   case 2:
                                       string1[7] = '1';
                                   break;
                                   case 3:
                                       string1[7] = '2';
                                   break;
                                   case 4:
                                       string1[7] = '3';
                                   break;
                                   case 5:
                                       string1[7] = '4';
                                   break;
                                   case 6:
                                       string1[7] = '5';
                                   break;
                                   case 7:
                                       string1[7] = '6';
                                   break;
                                   case 8:
                                       string1[7] = '7';
                                   break;
                                   case 9:
                                       string1[7] = '8';
                                   break;
                                   case 10:
                                       string1[7] = '9';
                                   break;
                                   case 11:
                                       string1[7] = 'A';
                                   break;
                                   case 12:
                                       string1[7] = 'B';
                                   break;
                                   case 13:
                                       string1[7] = 'C';
                                   break;
                                   case 14:
                                       string1[7] = 'D';
                                   break;
                                   case 15:
                                       string1[7] = 'E';
                                   break;
                                   case 16:
                                       string1[7] = 'F';
                                   break;



                                   default:
                                   break;
                               }


                     pr << string1 << " 0 0" <<  endl;
                     string1[9]='b';
                     string1[10]='m';
                     string1[11]='p';
            }

                nhor_aux = 0;
                nver--;
                nver_aux++;
            }
          cout << "Cutting of the set done, 13 files should be done" << endl;
          system("PAUSE");

          pr << "ENDSET" << endl << endl;

nfiles--;
}    //end while
    ifs.close();
    }
  pr.close();
  }
  cout << "A texturebin.txt should be done" << endl;
    return 0;
}
int main()
{

  static CRaster bmp, bmp_temp;
  int width_tile, minus_sep, total_cut, nhor, nver, acum1=0, acum2=0, nver_aux, nhor_aux, i,j,i_aux,j_aux;
  int nfiles_aux;

  int x_aux = 0;
  int intnsig_aux;
  string cc, string1, naming;

  cout << "********************************\n";
  cout << "*  CUTTER WITH FALCON SUPPORT  *\n";
  cout << "********************************" << endl << endl << "By Com_GP ([email protected]) DATE: " << "23/01/2003" << endl << "SUPPORTS 128x128, 256x256 AND 512x512 TILES WITH 2 PIXELS OF SEPARATION" << endl << endl;
//    system("PAUSE");

  RGBQUAD *rgbq_aux;        //Points wherever the palette starts

  string s_aux;
  int nfiles;
  int menus = 0;

  ofstream pr;
  ifstream ifs;

  pr.open("texturebin.txt");
  if(!pr)
         cout << "ERROR SAVING TEXTURE.BIN, NO MEMORY??" << endl;
  else
  {

  ifs.open("list8bpp.txt");
  if(!ifs)
      cout << "ERROR OPENING THE SCRIPT FILE" << endl;
  else{

  getline( ifs, s_aux);
  nfiles = String2Int( s_aux );
  cout << "NUMBER OF FILES = " << nfiles << endl;

 while( nfiles > 0 )
 {
  getline( ifs, cc );
  getline( ifs, string1 );

  getline( ifs, s_aux );
  menus = String2Int( s_aux );

  //**ESTO**
  getline( ifs, s_aux);
  nfiles_aux = String2Int( s_aux );

  //NAMING PROCEDURE
  getline( ifs, naming );

  //Ask for the name of the bmp file
  printf ("The file opened is ------> ");
  cout << cc;
  printf ("\n\n");

  if ( bmp.LoadBMP (cc.c_str()))
      return 0;

        pr << "# Start Set X has X tiles, Terrain type 4" << endl << "SET 4" << endl;


            //The width of the tile
            cout << "The width and height (its a square) of the tile is ---> ";
            switch( menus )
            {
                 case 1:
                     cout << "128x128\n\n";
                     width_tile = 128;
                 break;
                 case 2:
                     cout << "256x256\n\n";
                     width_tile = 256;
                 break;
                 case 3:
                     cout << "512x512\n\n";
                     width_tile = 512;
                 break;
                 default:
                     cout << "ERROR, MUST BE BETWEEN 1 AND 2, CHECK THE list8bpp.txt FILE" << endl;
                     system("PAUSE");
                 break;
            }

            //Separation between tiles
            cout << "Separation between tiles = ";
            minus_sep = 2;
            cout << minus_sep << endl;

            //bmp_temp = bmp ASIGNACIONES DE TODOS LOS CAMPOS INCLUIDA LA PALETA
            bmp_temp.Width = width_tile;
            bmp_temp.Height = width_tile;
            bmp_temp.BPP = bmp.BPP;
            bmp_temp.Palette = bmp.Palette;
            bmp_temp.pbmi = bmp.pbmi;
            bmp_temp.pbmi->bmiHeader.biHeight = (width_tile);
            bmp_temp.pbmi->bmiHeader.biWidth = (width_tile);

            total_cut = width_tile + minus_sep;

            //new temp memory for the temp tile
            bmp_temp.Raster = new char*[total_cut];
            for( i = 0; i <= total_cut; i++ )
		          bmp_temp.Raster[i] = new char[total_cut];

            nver = (bmp.Width / total_cut);

            cout << "Name of the FILE in which is gonna be saved -> ";
            cout << string1;
            cout << endl;

            int temp_i = 0;
            cout << "CORRECTOR FOR INCLINATION = " << temp_i << endl;


            nver_aux = 0;
            nhor_aux = 0;
            while( nver > 0)
            {
                nhor = ( bmp.Height / total_cut );
                while( nhor > 0)
                {
                     acum1 = 0;
                     i_aux = 0;
                     for ( i = (total_cut*(acum1+nhor_aux)); i < (((acum1+nhor_aux)*total_cut)+(width_tile)); i++ )
                     {
                         acum2 = 0;
                         j_aux = 0;
                         for ( j = (total_cut*(acum2+nver_aux)); j < (((acum2+nver_aux)*total_cut)+(width_tile)); j++ )
                         {
                               bmp_temp.Raster[i_aux][j_aux] = bmp.Raster[i][j];//Aqui hay algun problema
//                               cout <<"[" << i_aux << "][" << j_aux <<"]," <<"  [" << i << "][" << j <<"]" << endl;
                               j_aux++;
                         }
//                         system("PAUSE");
                         acum2++;
                         i_aux++;
                     }
                     acum1++;

                     nhor--;
                     nhor_aux++;



                     x_aux++;

                   switch( nhor_aux - 1 )
                   {
                           case 0:
                               switch( nver_aux )
                               {
                                   case 0:
                                       string1[7] = naming[0];
                                       cout << "TILE " << naming[0] << " ---> DONE" << endl;
                                   break;
                                   case 1:
                                       string1[7] = naming[2];
                                       cout << "TILE " << naming[2] << " ---> DONE" << endl;
                                   break;
                                   case 2:
                                       string1[7] = naming[4];
                                       cout << "TILE " << naming[4] << " ---> DONE" << endl;
                                   break;
                                   case 3:
                                       string1[7] = naming[6];
                                       cout << "TILE " << naming[6] << " ---> DONE" << endl;
                                   break;
                                   case 4:
                                       string1[7] = naming[8];
                                       cout << "TILE " << naming[8] << " ---> DONE" << endl;
                                   break;
                                   case 5:
                                       string1[7] = naming[10];
                                       cout << "TILE " << naming[10] << " ---> DONE" << endl;
                                   break;
                                   case 6:
                                       string1[7] = naming[12];
                                       cout << "TILE " << naming[12] << " ---> DONE" << endl;
                                   break;
                                   case 7:
                                       string1[7] = naming[14];
                                       cout << "TILE " << naming[14] << " ---> DONE" << endl;
                                   break;
                                   case 8:
                                       string1[7] = naming[16];
                                       cout << "TILE " << naming[16] << " ---> DONE" << endl;
                                   break;
                                   case 9:
                                       string1[7] = naming[18];
                                       cout << "TILE " << naming[18] << " ---> DONE" << endl;
                                   break;
                                   case 10:
                                       string1[7] = naming[20];
                                       cout << "TILE " << naming[20] << " ---> DONE" << endl;
                                   break;
                                   case 11:
                                       string1[7] = naming[22];
                                       cout << "TILE " << naming[22] << " ---> DONE" << endl;
                                   break;
                                   case 12:
                                       string1[7] = naming[24];
                                       cout << "TILE " << naming[24] << " ---> DONE" << endl;
                                   break;
                                   case 13:
                                       string1[7] = naming[26];
                                       cout << "TILE " << naming[26] << " ---> DONE" << endl;
                                   break;
                                   case 14:
                                       string1[7] = naming[28];
                                       cout << "TILE " << naming[28] << " ---> DONE" << endl;
                                   break;
                                   case 15:
                                       string1[7] = naming[30];
                                       cout << "TILE " << naming[30] << " ---> DONE" << endl;
                                   break;

                                   default:
                                   break;
                               }
                           break;

                           default:
                           break;
                   }

                   if(nfiles_aux>0){
                     nfiles_aux--;
                     //GUARDAR EN FICHERO
                     if( string1[7] != 'x' ){
                     SaveBMP (string1.c_str(), bmp_temp, temp_i );
                     string1[9]='p';
                     string1[10]='c';
                     string1[11]='x';
                     pr << string1 << " 0 0" <<  endl;
                     string1[9]='b';
                     string1[10]='m';
                     string1[11]='p';
                     }
                   }
            }

                nhor_aux = 0;
                nver--;
                nver_aux++;
            }
          cout << "Cutting of the set done, " << x_aux << " files should be done" << endl;
          system("PAUSE");

          pr << "ENDSET" << endl << endl;

 nfiles--;
 }
 //end while
 ifs.close();
 }
 pr.close();
 }
 cout << "A texturebin.txt should be done" << endl;
 return 0;
}
Beispiel #5
0
/*
 * Create
 */
void Create()
{
	fNDS = fopen(ndsfilename, "wb");
	if (!fNDS) { fprintf(stderr, "Cannot open file '%s'.\n", ndsfilename); exit(1); }

	bool bSecureSyscalls = false;
	char *headerfilename = (headerfilename_or_size && (strtoul(headerfilename_or_size,0,0) == 0)) ? headerfilename_or_size : 0;
	u32 headersize = headerfilename_or_size ? strtoul(headerfilename_or_size,0,0) : 0x200;

	// initial header data
	if (headerfilename)
	{
		// header template
		FILE *fi = fopen(headerfilename, "rb");
		if (!fi) { fprintf(stderr, "Cannot open file '%s'.\n", headerfilename); exit(1); }
		fread(&header, 1, 0x200, fi);
		fclose(fi);

		if ((header.arm9_ram_address + 0x800 == header.arm9_entry_address) || (header.rom_header_size > 0x200))
		{
			bSecureSyscalls = true;
		}
	}
	else	// set header default values
	{
		// clear header
		memset(&header, 0, sizeof(header));
		memcpy(header.gamecode, "####", 4);

		if ((arm9RamAddress + 0x800 == arm9Entry) || (headersize > 0x200))
		{
			bSecureSyscalls = true;
		}
		else
		{
			header.reserved2 = 0x04;		// autostart
			*(unsigned_int *)(((unsigned char *)&header) + 0x0) = 0xEA00002E;		// for PassMe's that start @ 0x08000000
		}
		*(unsigned_int *)(((unsigned char *)&header) + 0x60) = 1<<22 | latency2<<16 | 1<<14 | 1<<13 | latency1;	// ROM control info 1
		*(unsigned_int *)(((unsigned char *)&header) + 0x64) = 1<<29 | latency2<<16 | latency1;	// ROM control info 2
		*(unsigned_short *)(((unsigned char *)&header) + 0x6E) = 0x051E;	// ROM control info 3
	}
	if (headersize) header.rom_header_size = headersize;
	if (header.rom_header_size == 0) header.rom_header_size = bSecureSyscalls ? 0x4000 : 0x200;

	// load a logo
	if (logofilename)
	{
		char *p = strrchr(logofilename, '.');
		if (!strcmp(p, ".bmp"))
		{
			CRaster raster;
			if (raster.LoadBMP(logofilename) < 0) exit(1);
			unsigned char white = (raster.palette[0].rgbGreen >= 128) ? 0 : 1;
			if (LogoConvert(raster.raster, header.logo, white) < 0) exit(1);
		}
		else
		{
			FILE *fi = fopen(logofilename, "rb");
			if (!fi) { fprintf(stderr, "Cannot open file '%s'.\n", logofilename); exit(1); }
			fread(&header.logo, 1, 156, fi);
			fclose(fi);
		}
	}
	else if (bSecureSyscalls)	// use Nintendo logo
	{
		memcpy(((unsigned char *)&header) + 0xC0, nintendo_logo, sizeof(nintendo_logo));
	}
	else	// add small NDS loader
	{
		if (loadme_size != 156) { fprintf(stderr, "loadme size error\n"); exit(1); }
		memcpy(header.logo, loadme, loadme_size);		// self-contained NDS loader for *Me GBA cartridge boot
		memcpy(&header.offset_0xA0, "SRAM_V110", 9);		// allow GBA cartridge SRAM backup
		memcpy(&header.offset_0xAC, "PASS01\x96", 7);		// automatically start with FlashMe, make it look more like a GBA rom
	}

	// override default title/game/maker codes
	if (title) strncpy(header.title, title, 12);
	if (gamecode) strncpy(header.gamecode, gamecode, 4);
	if (makercode) strncpy((char *)header.makercode, makercode, 2);

	// --------------------------

	fseek(fNDS, header.rom_header_size, SEEK_SET);

	// ARM9 binary
	if (arm9filename)
	{
		header.arm9_rom_offset = (ftell(fNDS) + arm9_align) &~ arm9_align;
		fseek(fNDS, header.arm9_rom_offset, SEEK_SET);

		unsigned int entry_address = arm9Entry ? arm9Entry : (unsigned int)header.arm9_entry_address;		// template
		unsigned int ram_address = arm9RamAddress ? arm9RamAddress : (unsigned int)header.arm9_ram_address;		// template
		if (!ram_address && entry_address) ram_address = entry_address;
		if (!entry_address && ram_address) entry_address = ram_address;
		if (!ram_address) { ram_address = entry_address = 0x02000000; }

		// add dummy area for secure syscalls
		header.arm9_size = 0;
		if (bSecureSyscalls)
		{
			unsigned_int x;
			FILE *fARM9 = fopen(arm9filename, "rb");
			if (fARM9)
			{
				fread(&x, sizeof(x), 1, fARM9);
				fclose(fARM9);
				if (x != 0xE7FFDEFF)	// not already exist?
				{
					x = 0xE7FFDEFF;
					for (int i=0; i<0x800/4; i++) fwrite(&x, sizeof(x), 1, fNDS);
					header.arm9_size = 0x800;
				}
			}
		}

		unsigned int size = 0;


		if (HasElfExtension(arm9filename) || HasElfHeader(arm9filename) )
			CopyFromElf(arm9filename, &entry_address, &ram_address, &size);
		else
			CopyFromBin(arm9filename, 0, &size);
		header.arm9_entry_address = entry_address;
		header.arm9_ram_address = ram_address;
		header.arm9_size = header.arm9_size + ((size + 3) &~ 3);
	}
	else
	{
		fprintf(stderr, "ARM9 binary file required.\n");
		exit(1);
	}

	// ARM9 overlay table
	if (arm9ovltablefilename)
	{
		unsigned_int x1 = 0xDEC00621; fwrite(&x1, sizeof(x1), 1, fNDS);		// 0x2106c0de magic
		unsigned_int x2 = 0x00000AD8; fwrite(&x2, sizeof(x2), 1, fNDS);		// ???
		unsigned_int x3 = 0x00000000; fwrite(&x3, sizeof(x3), 1, fNDS);		// ???

		header.arm9_overlay_offset = ftell(fNDS);		// do not align
		fseek(fNDS, header.arm9_overlay_offset, SEEK_SET);
		unsigned int size = 0;
		CopyFromBin(arm9ovltablefilename, &size);
		header.arm9_overlay_size = size;
		overlay_files += size / sizeof(OverlayEntry);
		if (!size) header.arm9_overlay_offset = 0;
	}

	// COULD BE HERE: ARM9 overlay files, no padding before or between. end is padded with 0xFF's and then followed by ARM7 binary
	// fseek(fNDS, 1388772, SEEK_CUR);		// test for ASME

	// ARM7 binary
	header.arm7_rom_offset = (ftell(fNDS) + arm7_align) &~ arm7_align;
	fseek(fNDS, header.arm7_rom_offset, SEEK_SET);

	char *devkitProPATH;
	devkitProPATH = getenv("DEVKITPRO");

	#ifdef __WIN32__
	// convert to standard windows path
	if ( devkitProPATH && devkitProPATH[0] == '/' ) {
		devkitProPATH[0] = devkitProPATH[1];
		devkitProPATH[1] = ':';
	}
	#endif

	if ( !arm7filename) {
		char arm7PathName[MAXPATHLEN];

		if (!devkitProPATH) {
			fprintf(stderr,"No arm7 specified and DEVKITPRO missing from environment!\n");
			exit(1);
		}

		strcpy(arm7PathName,devkitProPATH);
		strcat(arm7PathName,"/libnds/default.elf");
		arm7filename = arm7PathName;
	}

	unsigned int entry_address = arm7Entry ? arm7Entry : (unsigned int)header.arm7_entry_address;		// template
	unsigned int ram_address = arm7RamAddress ? arm7RamAddress : (unsigned int)header.arm7_ram_address;		// template
	if (!ram_address && entry_address) ram_address = entry_address;
	if (!entry_address && ram_address) entry_address = ram_address;
	if (!ram_address) { ram_address = entry_address = 0x037f8000; }

	unsigned int size = 0;

	if (HasElfExtension(arm7filename))
		CopyFromElf(arm7filename, &entry_address, &ram_address, &size);
	else
		CopyFromBin(arm7filename, &size);

	header.arm7_entry_address = entry_address;
	header.arm7_ram_address = ram_address;
	header.arm7_size = ((size + 3) &~ 3);

	// ARM7 overlay table
	if (arm7ovltablefilename)
	{
		header.arm7_overlay_offset = ftell(fNDS);		// do not align
		fseek(fNDS, header.arm7_overlay_offset, SEEK_SET);
		unsigned int size = 0;
		CopyFromBin(arm7ovltablefilename, &size);
		header.arm7_overlay_size = size;
		overlay_files += size / sizeof(OverlayEntry);
		if (!size) header.arm7_overlay_offset = 0;
	}

	// COULD BE HERE: probably ARM7 overlay files, just like for ARM9
	//

	if (overlay_files && !overlaydir)
	{
		fprintf(stderr, "Overlay directory required!.\n");
		exit(1);
	}

	// filesystem
	//if (filerootdir || overlaydir)
	{
		// read directory structure
		free_file_id = overlay_files;
		free_dir_id++;
		directory_count++;
		TreeNode *filetree;
		if (filerootdir)
			filetree = ReadDirectory(new TreeNode(), filerootdir);
		else
			filetree = new TreeNode();		// dummy root node 0xF000

		// calculate offsets required for FNT and FAT
		_entry_start = 8*directory_count;		// names come after directory structs
		header.fnt_offset = (ftell(fNDS) + fnt_align) &~ fnt_align;
		header.fnt_size =
			_entry_start +		// directory structs
			total_name_size +	// total number of name characters for dirs and files
			directory_count*4 +	// directory: name length (1), dir id (2), end-character (1)
			file_count*1 +		// files: name length (1)
			- 3;				// root directory only has an end-character
		file_count += overlay_files;		// didn't take overlay files into FNT size, but have to be calculated into FAT size
		header.fat_offset = (header.fnt_offset + header.fnt_size + fat_align) &~ fat_align;
		header.fat_size = file_count * 8;		// each entry contains top & bottom offset

		// banner after FNT/FAT
		if (bannerfilename)
		{
			header.banner_offset = (header.fat_offset + header.fat_size + banner_align) &~ banner_align;
			file_top = header.banner_offset + 0x840;
			fseek(fNDS, header.banner_offset, SEEK_SET);
			if (bannertype == BANNER_IMAGE)
			{
				char * Ext = strrchr(bannerfilename, '.');
				if (Ext && strcasecmp(Ext, ".bmp") == 0)
					IconFromBMP();
				else if (Ext && strcasecmp(Ext, ".grf") == 0)
					IconFromGRF();
				else
				{
					fprintf(stderr,
						"Banner File Error: Unknown extension '%s'!\n", Ext);
					exit(1);
				}
			}
			else
			{
				CopyFromBin(bannerfilename, 0);
			}
		}
		else
		{
			file_top = header.fat_offset + header.fat_size;
			header.banner_offset = 0;
		}

		file_end = file_top;	// no file data as yet

		// add (hidden) overlay files
		for (unsigned int i=0; i<overlay_files; i++)
		{
			char s[32]; sprintf(s, OVERLAY_FMT, i/*free_file_id*/);
			AddFile(overlaydir, "/", s, i/*free_file_id*/);
			//free_file_id++;		// incremented up to overlay_files
		}

		// add all other (visible) files
		AddDirectory(filetree, "/", 0xF000, directory_count);
		fseek(fNDS, file_end, SEEK_SET);

		if (verbose)
		{
			printf("%u directories.\n", directory_count);
			printf("%u normal files.\n", file_count - overlay_files);
			printf("%u overlay files.\n", overlay_files);
		}
	}

	// --------------------------

	// align file size
	unsigned int newfilesize = file_end;	//ftell(fNDS);
	newfilesize = (newfilesize + 3) & ~3;	// align to 4 bytes
	header.application_end_offset = newfilesize;
	if (newfilesize != file_end ) {
		fseek(fNDS, newfilesize-1, SEEK_SET);
		fputc(0, fNDS);
	}
	// calculate device capacity
	newfilesize |= newfilesize >> 16; newfilesize |= newfilesize >> 8;
	newfilesize |= newfilesize >> 4; newfilesize |= newfilesize >> 2;
	newfilesize |= newfilesize >> 1; newfilesize++;
	if (newfilesize <= 128*1024) newfilesize = 128*1024;
	int devcap = -18;
	unsigned int x = newfilesize;
	while (x != 0) { x >>= 1; devcap++; }
	header.devicecap = (devcap < 0) ? 0 : devcap;

	// fix up header CRCs and write header
	header.logo_crc = CalcLogoCRC(header);
	header.header_crc = CalcHeaderCRC(header);
	fseek(fNDS, 0, SEEK_SET);
	fwrite(&header, 0x200, 1, fNDS);

	fclose(fNDS);
}
int main()
{

    static CRaster bmp, bmp_temp;
    int width_tile, minus_sep, total_cut, nhor, nver, acum1=0, acum2=0, nver_aux, nhor_aux, i,j,i_aux,j_aux;


    //TEMPORAL
    int x_aux = 0;
    int intnsig_aux;

    RGBQUAD *rgbq_aux;        //Points wherever the palette starts
//    char ** Raster_aux, ** Raster_main;        //Points wherever the image bytes start
    char cc [256];
    char string1 [16];

  //Ask for the name of the bmp file
  printf ("Name of the file you want to open (EX: 512x512.bmp)\n");
  gets (cc);
  printf ("\n\n");

  bmp.LoadBMP (cc);


            //The width of the tile
            cout << "The width and height (its a square) of the tile" << endl;
            cin >> width_tile;

            //Separation between tiles
            cout << "Separation between tiles" << endl;
            cin >> minus_sep;



            //bmp_temp = bmp ASIGNACIONES DE TODOS LOS CAMPOS INCLUIDA LA PALETA
            bmp_temp.Width = width_tile;
            bmp_temp.Height = width_tile;
            bmp_temp.BPP = bmp.BPP;
            bmp_temp.Palette = bmp.Palette;
            bmp_temp.pbmi = bmp.pbmi;
            bmp_temp.pbmi->bmiHeader.biHeight = (width_tile);
            bmp_temp.pbmi->bmiHeader.biWidth = (width_tile);

            //new temp memory for the temp tile

            total_cut = width_tile + minus_sep;

            //HASTA AQUI BIEN 23/11/02 01:19
            bmp_temp.Raster = new char*[total_cut];
            for( i = 0; i <= total_cut; i++ )
		          bmp_temp.Raster[i] = new char[total_cut];

            //HASTA AQUI BIEN 23/11/02 01:23
            nver = (bmp.Width / total_cut);
//            nver = (bmp.Height /total_cut);

            cout << "Name of the FILE (ex: HnameX*.bmp, NO MORE THAN 5 CHARACTERS) to save\n";
            gets(string1);
//            string1 += "Hname**";
//            string1 = string1 + ".bmp";

            int temp_i;
            cout << "CORRECTOR FOR INCLINATION, USUALLY 0 --> ";
            cin >> temp_i;


            nver_aux = 0;
            nhor_aux = 0;
            while( nver > 0)
            {
                nhor = ( bmp.Height / total_cut );
                while( nhor > 0)
                {
                     acum1 = 0;
                     i_aux = 0;
                     for ( i = (total_cut*(acum1+nhor_aux)); i < (((acum1+nhor_aux)*total_cut)+(width_tile)); i++ )
                     {
                         acum2 = 0;
                         j_aux = 0;
                         for ( j = (total_cut*(acum2+nver_aux)); j < (((acum2+nver_aux)*total_cut)+(width_tile)); j++ )
                         {
                               bmp_temp.Raster[i_aux][j_aux] = bmp.Raster[i][j];//Aqui hay algun problema
//                               cout <<"[" << i_aux << "][" << j_aux <<"]," <<"  [" << i << "][" << j <<"]" << endl;
                               j_aux++;
                         }
//                         system("PAUSE");
                         acum2++;
                         i_aux++;
                     }
                     acum1++;
//                     nver_aux = 0;

                     cout <<"[" << nver << "][" << nhor <<"]" << endl;
                     cout <<"[" << nver_aux << "][" << nhor_aux <<"]" << endl << endl;

                     nhor--;
                     nhor_aux++;



                     x_aux++;

                   switch( nhor_aux - 1 )
                   {
                           case 0:
                               switch( nver_aux )
                               {
//[0,x]
                                   case 0:
                                       string1[6] = '7';
                                   break;
                                   case 1:
                                       string1[6] = 'B';
                                   break;
                                   case 2:
                                       string1[6] = '8';
                                   break;
                                   case 3:
                                       string1[6] = 'C';
                                   break;
                                   case 4:
                                       string1[6] = '4';
                                   break;
                                   default:
                                   break;
                               }
                           break;
//[1,x]
                           case 1:
                               switch( nver_aux )
                               {
                                   case 0:
                                       string1[6] = 'D';
                                   break;
                                   case 1:
                                       string1[6] = 'E';
                                   break;
                                   case 2:
                                       string1[6] = 'A';
                                   break;
                                   case 3:
                                       string1[6] = 'F';
                                   break;
                                   case 4:
                                       string1[6] = '5';
                                   break;
                                   default:
                                   break;
                               }
                           break;
//[2,x]
                           case 2:
                               switch( nver_aux )
                               {
                                   case 0:
                                       string1[6] = '0';
                                   break;
                                   case 1:
                                       string1[6] = 'x';
                                   break;
                                   case 2:
                                       string1[6] = 'x';
                                   break;
                                   case 3:
                                       string1[6] = 'x';
                                   break;
                                   case 4:
                                       string1[6] = 'x';
                                   break;
                                   default:
                                   break;
                               }
                           break;
                           default:
                           break;
                   }

//Borrar                   cout << (string1[5]) << " " << char(nver_aux) << endl;
//                   string1[7] = char(48 + nhor_aux - 1);
//                   string1[8] = char(48 + nver_aux);

                     //GUARDAR EN FICHERO
                     SaveBMP (string1, bmp_temp, temp_i );
//                     system("PAUSE");




                }

                nhor_aux = 0;
                nver--;
                nver_aux++;
            }
          cout << "CUTTING DONE THE " << x_aux << " FILES SHOULD BE DONE" << endl;
          system("PAUSE");
//end     FIN

//
    return 0;
}