00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <common/ImageID.h>
00022 #include <common/Defines.h>
00023 #include <XML/XMLParser.h>
00024
00025 ImageID::ImageID()
00026 {
00027 }
00028
00029 ImageID::~ImageID()
00030 {
00031 }
00032
00033 bool ImageID::initFromString(
00034 const char *type,
00035 const char *imageName,
00036 const char *alphaName,
00037 bool invert)
00038 {
00039 type_ = type;
00040 imageName_ = imageName;
00041 alphaName_ = alphaName;
00042 invert_ = invert;
00043 return true;
00044 }
00045
00046
00047 bool ImageID::initFromNode(const char *directory, XMLNode *imageNode)
00048 {
00049 XMLNode *typeNode = 0;
00050 if (!imageNode->getNamedParameter("type", typeNode)) return false;
00051 type_ = typeNode->getContent();
00052 if (0 != strcmp("bmp", type_.c_str()) &&
00053 0 != strcmp("png", type_.c_str()))
00054 {
00055 return imageNode->returnError(
00056 S3D::formatStringBuffer(
00057 "Unknown image type \"%s\"",
00058 type_.c_str()));
00059 }
00060
00061 std::string image, alpha;
00062 if (!imageNode->getNamedChild("image", image)) return false;
00063 imageName_ = std::string(directory) + std::string("/") + image;
00064 if (!S3D::fileExists(S3D::getDataFile(imageName_.c_str())))
00065 {
00066 return imageNode->returnError(
00067 S3D::formatStringBuffer(
00068 "Image file \"%s\" does not exist",
00069 imageName_.c_str()));
00070 }
00071
00072 if (imageNode->getNamedChild("alpha", alpha, false))
00073 {
00074 alphaName_ = std::string(directory) + std::string("/") + alpha;
00075 if (!S3D::fileExists(S3D::getDataFile(alphaName_.c_str())))
00076 {
00077 return imageNode->returnError(
00078 S3D::formatStringBuffer(
00079 "Alpha file \"%s\" does not exist",
00080 alphaName_.c_str()));
00081 return false;
00082 }
00083 }
00084
00085 invert_ = false;
00086 imageNode->getNamedChild("invert", invert_, false);
00087
00088 return imageNode->failChildren();
00089 }
00090
00091 const char *ImageID::getStringHash()
00092 {
00093 hash_ = imageName_ + "-" + alphaName_ + (invert_?"A":"B");
00094 return hash_.c_str();
00095 }