void WriteFile(const CImage& img, const char* filename) { // Determine the file extension const char *dot = strrchr(filename, '.'); if (strcasecmp(dot, ".tga") == 0 || strcasecmp(dot, ".tga") == 0) { if (img.PixType() == typeid(uchar)) WriteFileTGA(*(CByteImage *) &img, filename); else if(img.PixType() == typeid(float)) { CByteImage tmp(img.Shape()); TypeConvert(*(CFloatImage *) &img, tmp); WriteFileTGA(tmp, filename); } else { throw CError("Filetype not supported"); } } else if (strcasecmp(dot, ".jpg") == 0 || strcasecmp(dot, ".jpeg") == 0) { if (img.PixType() == typeid(uchar)) WriteFileJPEG(*(CByteImage *) &img, filename, 90); else if(img.PixType() == typeid(float)) { CByteImage tmp(img.Shape()); TypeConvert(*(CFloatImage *) &img, tmp); WriteFileJPEG(tmp, filename, 90); } else { throw CError("Filetype not supported"); } } else throw CError("WriteFile(%s): file type not supported", filename); }
void WriteFile(CImage& img, const char* filename) { // Determine the file extension char *dot = strrchr((char *) filename, '.'); if (strcmp(dot, ".tga") == 0 || strcmp(dot, ".tga") == 0) { if (img.PixType() == typeid(uchar)) WriteFileTGA(*(CByteImage *) &img, filename); else throw CError("ReadFile(%s): haven't implemented conversions yet", filename); } else throw CError("WriteFile(%s): file type not supported", filename); }