Esempio n. 1
0
    ALLEGRO_BITMAP *open(const std::string filename) {

        debugArgs("io::image", "Loading '%s'...", filename.data());

        ALLEGRO_BITMAP *img = NULL;

        void *rbuf;
        ALLEGRO_FILE *fp = file::open(filename, &rbuf);

        if (fp != NULL) {
            std::string ext = filename.substr(filename.find_last_of("."));
            img = al_load_bitmap_f(fp, ext.data());
            file::close(fp, &rbuf);
        } 
        
        if (img) {
            debugArgs("io::image", "Loaded '%s'", filename.data());

        } else {
            debugArgs("io::image", "Failed to load '%s'", filename.data());
        }

        return img;

    }
		characterImageCache* characterImageManager::cacheImage(std::string imageName, std::string dataName) {
			
			if (characterImageManager::cacheList.find(imageName)==characterImageManager::cacheList.end()) { //Cache was not previously generated, so generate it
				characterImageCache* newCache = new characterImageCache();
				//int oldFlags = al_get_new_bitmap_flags();
				//al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR | ALLEGRO_MAG_LINEAR);
				newCache->image  = al_load_bitmap_f(gameEngine::resources::graphics.openSubFile(imageName),".png"); //Load the image to cache
				//al_set_new_bitmap_flags(oldFlags);
				ALLEGRO_FILE * imageData = gameEngine::resources::graphics.openSubFile(dataName,false);
				al_fread(imageData,&newCache->imageOriginX,sizeof(unsigned short));
				 al_fread(imageData,&newCache->imageOriginY,sizeof(unsigned short));
				 al_fread(imageData,&newCache->imageRelativeX,sizeof(short));
				 al_fread(imageData,&newCache->imageRelativeY,sizeof(short));



				 al_fclose(imageData);
				newCache->usageCount = 1; //One person is now using it..
				cacheList[imageName] = newCache; //Add the cache to the map to.. cache it :p
				//std::cout << "Loaded image and cached it for first time.." << std::endl;
				return newCache;
			}else{ //Cache already exists, so return the existing one
				//std::cout << "Using previously cached image..." << std::endl;
				characterImageManager::cacheList[imageName]->usageCount ++; //A new renderer is using this cache
				return characterImageManager::cacheList[imageName];
			}
		}
/* This has to load bitmaps from CPA and disk (for skeled) */
ALLEGRO_BITMAP *my_load_bitmap(std::string filename)
{
	CPA *cpa;
	ALLEGRO_FILE *f;
	if (engine) {
		cpa = engine->get_cpa();
	}
	else {
		cpa = NULL;
	}
	if (cpa) {
		f = cpa->load(filename);
	}
	else {
		f = al_fopen(filename.c_str(), "rb");
	}
	if (!f) {
		return NULL;
	}
	ALLEGRO_BITMAP *bmp;
//#if defined ANDROID || defined ALLEGRO_IPHONE || defined ALLEGRO_RASPBERRYPI
	bmp = al_load_bitmap_f(f, ".png");
/*#else
	if (!engine || !cpa) {
		bmp = al_load_bitmap_f(f, ".png");
	}
	else {
		bmp = al_load_bitmap_f(f, ".png");
	}
#endif*/
	al_fclose(f);
	return bmp;
}
Esempio n. 4
0
ALLEGRO_BITMAP * load_packed_bitmap(unsigned char *mem, int mem_size)
{
    /* fail nicely :) */
    if (mem == NULL)
        return NULL;
    ALLEGRO_FILE *mem_file = al_open_memfile(mem, mem_size, "r");
    /* file type determined by second arg */
    ALLEGRO_BITMAP *bm = al_load_bitmap_f(mem_file, ".png");
    al_fclose(mem_file);

    return bm;
}
Esempio n. 5
0
background* backgroundManager::loadBackground(int ind) { //Load specified background

	if (preloadedBackgrounds.find(ind)==preloadedBackgrounds.end()) { //Background was not previously loaded
		background* newBG = new background(); 
			newBG->id = ind;
			std::stringstream bufferPNG;
			bufferPNG << ":bg:" << ind << ".png";
			newBG->bitmap = al_load_bitmap_f(gameEngine::resources::graphics.openSubFile(bufferPNG.str()),".png"); //Load the background Image

			preloadedBackgrounds[ind] = newBG;
			return newBG;
	}else{
		return preloadedBackgrounds[ind]; //Return preloaded background
	}

}
Esempio n. 6
0
File: io.c Progetto: BonsaiDen/kuusi
ALLEGRO_BITMAP *ioLoadBitmap(const char *filename) {

    unsigned int len;
    char *ext;
    ALLEGRO_FILE *fp = NULL;
    ALLEGRO_BITMAP *img = NULL;

    debugLog("io: load bitmap \"%s\"\n", filename);

    len = strlen(filename);
    ext = (char*)calloc(5, sizeof(char));
    strcpy(ext, filename + (len - 4));

    fp = ioOpenFile(filename);
    img = al_load_bitmap_f(fp, ext);

    free(ext);

    debugLog("io: bitmap \"%s\" loaded\n", filename);

    return img;
}
Esempio n. 7
0
 /**
     Loads a bitmap from file.
     @param file file.
     @param ext filename extension.
  */
 Bitmap(const File &file, const char *ext) : Shared(al_load_bitmap_f(file.get(), ext), al_destroy_bitmap) {
 }
Esempio n. 8
0
 /**
     loads a bitmap from a file.
     @param file file.
     @param ext filename extension.
  */
 bool load(const File &file, const char *ext) {
     reset(al_load_bitmap_f(file.get(), ext), al_destroy_bitmap);
     return (bool)(*this);
 }