C:/Documents and Settings/mtauraso/Desktop/proj3/projectX/textureAdd.cpp

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string>
00004 #include <io.h>
00005 #include <set>
00006 #include <map>
00007 #include <iostream>
00008 
00009 #include "SDL.h"
00010 #include "SDL_image.h"
00011 
00012 using namespace std;
00013 
00014 void stripExtension(string& filename)
00015 {
00016         filename.erase(filename.size()-1,1);
00017         filename.erase(filename.size()-1,1);
00018         filename.erase(filename.size()-1,1);
00019         filename.erase(filename.size()-1,1);
00020 }
00021 
00022 void readFiles(set<string> &textures, set<string> &pixels, string extension)
00023 {
00024         struct _finddata_t file;
00025         intptr_t hFile;
00026 
00027         if( (hFile = _findfirst( ("textures/*." + extension).c_str(), &file )) != -1L ) {
00028                 do {
00029                         string filename(file.name);
00030                         stripExtension(filename);
00031                         string end = filename.substr(filename.size() - 2,2);
00032                         if(end == "_p") {                               
00033                                 filename.erase(filename.size()-1,1);
00034                                 filename.erase(filename.size()-1,1);
00035                                 pixels.insert(filename);
00036                         }
00037                         else 
00038                                 textures.insert(filename);
00039                 }
00040                 while( _findnext( hFile, &file ) == 0 );
00041 
00042                 _findclose( hFile );
00043         }
00044 }
00045 
00046 void checkCollisions(map<Uint32,string> &colors, set<string> &pixels, string extension, SDL_PixelFormat *&fmt)
00047 {
00048         for(set<string>::iterator filename = pixels.begin(); filename != pixels.end(); filename++) {
00049                 // http://manuals.thexdershome.com/SDL-1.2.5/html/sdlpixelformat.html
00050                 SDL_Surface* surface = IMG_Load(("textures/" + *filename + "_p." + extension).c_str());
00051                 Uint32 pixel;
00052 
00053                 fmt=surface->format;
00054                 SDL_LockSurface(surface);
00055                 pixel=*((Uint32*)surface->pixels);
00056                 SDL_UnlockSurface(surface);
00057 
00058                 if(colors.find(pixel) != colors.end())
00059                         cerr << "Collision found: " << ("textures/" + (*colors.find(pixel)).second + "_p." + extension + " and ")
00060                                                                                 << ("textures/" + *filename + "_p." + extension + "\n");
00061                 else 
00062                         colors[pixel] = *filename;
00063                 SDL_FreeSurface(surface);
00064         }
00065 }
00066 
00067 
00068 
00069 int main(int argc,char *argv[])
00070 {
00071 
00072         set<string> texturesPNG;
00073         set<string> pixelsPNG;
00074         set<string> texturesBMP;
00075         set<string> pixelsBMP;
00076 
00077         readFiles(texturesPNG,pixelsPNG,"png");
00078         readFiles(texturesBMP,pixelsBMP,"bmp");
00079 
00080         map<Uint32,string> colors;
00081         SDL_PixelFormat *fmt = NULL;
00082 
00083         checkCollisions(colors,pixelsPNG,"png",fmt);
00084         checkCollisions(colors,pixelsBMP,"bmp",fmt);
00085 
00086         return 1;
00087 }
00088 
00089 

Generated on Sat Apr 22 15:05:20 2006 for ProjectX by  doxygen 1.4.6-NO