/** * Returns 1 (true) if the image object passed as a parameter * exists and is added successfully to the manager creating a new image cloning from a previous one. * @param pNewImage Pointer to a new image object. * @param pOldImage Pointer to the image that is to be cloned. */ bool IND_ImageManager::clone(IND_Image *pNewImage, IND_Image *pOldImage) { g_debug->header("Cloning Image", DebugApi::LogHeaderBegin); if (!_ok || !pNewImage || !pOldImage || !pOldImage->getFreeImageHandle()) { writeMessage(); return 0; } // ----- Image creation using FreeImage ----- // Clone the old image FIBITMAP* image = FreeImage_Clone(pOldImage->getFreeImageHandle()); if (!image) { g_debug->header("Image could not be cloned", DebugApi::LogHeaderError); return 0; } // Attributes pNewImage->setWidth(pOldImage->getWidth()); pNewImage->setHeight(pOldImage->getHeight()); pNewImage->setBpp(pOldImage->getBpp()); pNewImage->setBytespp(pOldImage->getBytespp()); pNewImage->setFormatInt(pOldImage->getFormatInt()); char ext [128]; getExtensionFromName(pOldImage->getName(),ext); pNewImage->setExtension(ext); pNewImage->setPointer(FreeImage_GetBits(image)); pNewImage->setName("Image cloned"); pNewImage->setFreeImageHandle(image); // ----- Put the object into the manager ----- addToList(pNewImage); // ----- g_debug ----- g_debug->header("File name:", DebugApi::LogHeaderInfo); g_debug->dataChar(pOldImage->getName(), 1); g_debug->header("Image cloned", DebugApi::LogHeaderEnd); return 1; }
/** * Loads an image. Returns a pointer to a FIBITMAP if the path to the file is correct and if Indielib support the image format. * Otherwise null is returned. * @param pName Pointer to name of the image file to load. */ FIBITMAP* IND_ImageManager::load(const char *pName) { g_debug->header("Loading Image", DebugApi::LogHeaderBegin); if(!pName) { g_debug->header("Invalid File name provided (null)",DebugApi::LogHeaderError); return NULL; } g_debug->header("File name:", DebugApi::LogHeaderInfo); g_debug->dataChar(pName, 1); if (!_ok) { writeMessage(); return NULL; } // ----- checking file extension ----- //TODO: Refactor this to use FreeImage getfileType char ext [128]; getExtensionFromName(pName,ext); if (!checkExtImage(ext)){ g_debug->header("Unknown extension", DebugApi::LogHeaderError); return NULL; } g_debug->header("Extension:", DebugApi::LogHeaderInfo); g_debug->dataChar(ext, 1); // ----- Load image ----- FREE_IMAGE_FORMAT imgFormat = FreeImage_GetFileType(pName, 0); if (FIF_UNKNOWN == imgFormat) { g_debug->header("Image not found", DebugApi::LogHeaderError); return NULL; } FIBITMAP* image = FreeImage_Load(imgFormat, pName, 0); if (!image) { g_debug->header("Image could not be loaded", DebugApi::LogHeaderError); return NULL; } return image; }
/** * Returns 1 (true) if the image object passed as a parameter * exists and is added successfully to the manager. * Supports the following graphics formats: * bmp, png, tga, jpg and pcx. * @param pNewImage Pointer no a new image object. * @param pName Image name. */ bool IND_ImageManager::add(IND_Image *pNewImage, const char *pName) { // TODO: clean up documentation, maybe create and refer to a method in FreeimageHelper that returns // a stringarray of all Indielib supported types.. g_debug->header("Loading Image", DebugApi::LogHeaderBegin); if(!pName) { g_debug->header("Invalid File name provided (null)",DebugApi::LogHeaderError); return 0; } g_debug->header("File name:", DebugApi::LogHeaderInfo); g_debug->dataChar(pName, 1); if (!_ok) { writeMessage(); return 0; } // ----- Obtaining and checking file extension ----- //TODO: Refactor this to use FreeImage getfileType char ext [128]; getExtensionFromName(pName,ext); if (checkExtImage(ext)) { pNewImage->setExtension(ext); g_debug->header("Extension:", DebugApi::LogHeaderInfo); g_debug->dataChar(ext, 1); } else { g_debug->header("Unknown extension", DebugApi::LogHeaderError); return 0; } // ----- Load image ----- FREE_IMAGE_FORMAT imgFormat = FreeImage_GetFileType(pName, 0); if (FIF_UNKNOWN == imgFormat) { g_debug->header("Image not found", DebugApi::LogHeaderError); return 0; } FIBITMAP* image = FreeImage_Load(imgFormat, pName, 0); if (!image) { g_debug->header("Image could not be loaded", DebugApi::LogHeaderError); return 0; } // Attributes pNewImage->setWidth(FreeImage_GetWidth(image)); pNewImage->setHeight(FreeImage_GetHeight(image)); IND_ColorFormat indFormat = FreeImageHelper::calculateINDFormat(image); pNewImage->setFormatInt(indFormat); pNewImage->setBpp(FreeImage_GetBPP(image)); pNewImage->setBytespp(pNewImage->getBpp()/8); pNewImage->setPointer(FreeImage_GetBits(image)); pNewImage->setName(pName); pNewImage->setFreeImageHandle(image); // ----- Puts the object into the manager ----- addToList(pNewImage); // ----- g_debug ----- g_debug->header("Size:", DebugApi::LogHeaderInfo); g_debug->dataInt(pNewImage->getWidth(), 0); g_debug->dataChar("x", 0); g_debug->dataInt(pNewImage->getHeight(), 1); g_debug->header("Bpp:", DebugApi::LogHeaderInfo); g_debug->dataInt(pNewImage->getBytespp(), 1); g_debug->header("Format:", DebugApi::LogHeaderInfo); g_debug->dataChar(pNewImage->getFormatString(), 1); g_debug->header("Image loaded", DebugApi::LogHeaderEnd); return 1; }
/** @b Parameters: @arg @b pNewTmxMap Pointer no a new IND_TmxMap object. @arg @b pName TmxMap filename @b Operation: This function returns 1 (true) if the image object passed as a parameter exists and is added successfully to the manager. It supports the following file formats: tmx. */ bool IND_TmxMapManager::add(IND_TmxMap *pNewTmxMap,const char *pName) { g_debug->header("Loading TmxMap", DebugApi::LogHeaderBegin); if(!pName) { g_debug->header("Invalid File name provided (null)",DebugApi::LogHeaderError); return 0; } g_debug->header("File name:", DebugApi::LogHeaderInfo); g_debug->dataChar(pName, 1); if (!_ok) { writeMessage(); return 0; } // ----- Obtaining and checking file extension ----- char ext [128]; getExtensionFromName(pName,ext); if (!checkExtImage(ext)){ g_debug->header("Unknown extension", DebugApi::LogHeaderError); return 0; } // ----- Load TmxMap ----- Tmx::Map *map = new Tmx::Map(); map->ParseFile(pName); if (map->HasError()) { g_debug->header("Error code:", 2); //g_debug->dataChar(map->GetErrorCode(), 1); //TODO g_debug->header("Error text:", 2); g_debug->dataChar(map->GetErrorText().c_str(), 1); DISPOSE(map); return 0; } // ----- Load TmxMap tilesetimagesheet ----- string tmxPath; string imagePath; string s = string(pName); size_t lastPosTemp = s.find_last_of("\\/"); if(lastPosTemp == string::npos){ tmxPath = "./"; } else{ tmxPath = s.substr(0, lastPosTemp + 1); } imagePath = tmxPath.append(map->GetTileset(0)->GetImage()->GetSource()); // FIXME : this is very wrong we need to store an array of images instead.... i.e NO '0' // ----- Load image ----- FREE_IMAGE_FORMAT imgFormat = FreeImage_GetFileType(imagePath.c_str(), 0); if (FIF_UNKNOWN == imgFormat) { g_debug->header("Image not found", 2); DISPOSE(map); return 0; } FIBITMAP* image = FreeImage_Load(imgFormat, imagePath.c_str(), 0); if (!image) { g_debug->header("Image could not be loaded", 2); DISPOSE(map); return 0; } // ----- Attributes ----- pNewTmxMap->setTmxMapHandle(map); pNewTmxMap->setName(pName); pNewTmxMap->setImage(image); // FIXME should be added to an array pNewTmxMap->setImagePath(imagePath.c_str()); // FIXME should be added to an array // ----- Puts the object into the manager ----- addToList(pNewTmxMap); // ----- g_debug ----- g_debug->header("TmxMap loaded", 6); return 1; }