Esempio n. 1
0
void ReadFile(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()) == 0)
            img.ReAllocate(CShape(), typeid(uchar), sizeof(uchar), true);
        if (img.PixType() == typeid(uchar))
            ReadFileTGA(*(CByteImage *) &img, filename);
        else {
            CByteImage imgAux;
            ReadFileTGA(imgAux, filename);

            if(img.PixType() == typeid(float)) TypeConvert(imgAux, *(CFloatImage*) &img);
            else
                throw CError("Cannot load image into img with this type of buffer");
        }
    } else if (strcasecmp(dot, ".jpg") == 0 || strcasecmp(dot, ".jpeg") == 0) {
        if ((&img.PixType()) == 0)
            img.ReAllocate(CShape(), typeid(uchar), sizeof(uchar), true);
        if (img.PixType() == typeid(uchar))
            ReadFileJPEG(*(CByteImage *) &img, filename);
        else {
            CByteImage imgAux;
            ReadFileJPEG(imgAux, filename);

            if(img.PixType() == typeid(float)) TypeConvert(imgAux, *(CFloatImage*) &img);
            else
                throw CError("Cannot load image into img with this type of buffer");
        }

    } else
        throw CError("ReadFile(%s): file type not supported", filename);
}
Esempio n. 2
0
void ReadFile (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()) == 0)
            img.ReAllocate(CShape(), typeid(uchar), sizeof(uchar), true);
        if (img.PixType() == typeid(uchar))
            ReadFileTGA(*(CByteImage *) &img, filename);
        else
           throw CError("ReadFile(%s): haven't implemented conversions yet", filename);
    }
    else
        throw CError("ReadFile(%s): file type not supported", filename);
}