! * \brief IPLFileIO::loadFile * \param filename * \param image pass by pointer reference, because we need to change the pointer * \return */
| 30 | * \return |
| 31 | */ |
| 32 | bool IPLFileIO::loadFile(std::string filename, IPLImage*& image, std::string& information) |
| 33 | { |
| 34 | std::string formatNames[37] = {"BMP", "ICO", "JPEG", "JNG", |
| 35 | "KOALA", "LBM", "MNG", "PBM", |
| 36 | "PBMRAW", "PCD", "PCX", "PGM", "PGMRAW", |
| 37 | "PNG", "PPM", "PPMRAW", "RAS", |
| 38 | "TARGA", "TIFF", "WBMP", "PSD", "CUT", |
| 39 | "XBM", "XPM", "DDS", "GIF", "HDR", |
| 40 | "FAXG3", "SGI", "EXR", "J2K", "JP2", |
| 41 | "PFM", "PICT", "RAW", "WEBP", "JXR"}; |
| 42 | |
| 43 | std::string typeNames[13] = {"UNKNOWN", "BITMAP", "UINT16", "INT16", |
| 44 | "UINT32", "INT32", "FLOAT", "DOUBLE", |
| 45 | "COMPLEX", "RGB16", "RGBA16", "RGBF", |
| 46 | "RGBAF"}; |
| 47 | |
| 48 | |
| 49 | std::string filePath; |
| 50 | |
| 51 | // try loading relative filepaths to the _baseDir |
| 52 | if(!IPLFileIO::isAbsolutePath(filename)) |
| 53 | { |
| 54 | filePath.append(IPLFileIO::_baseDir).append("/").append(filename); |
| 55 | } |
| 56 | else |
| 57 | { |
| 58 | filePath.append(filename); |
| 59 | } |
| 60 | |
| 61 | FREE_IMAGE_FORMAT format = FIF_UNKNOWN; |
| 62 | format = FreeImage_GetFileType(filePath.c_str()); |
| 63 | if(format == FIF_UNKNOWN) |
| 64 | { |
| 65 | return false; |
| 66 | } |
| 67 | |
| 68 | FIBITMAP *dib = FreeImage_Load(format, filePath.c_str()); |
| 69 | int width = FreeImage_GetWidth(dib); |
| 70 | int height = FreeImage_GetHeight(dib); |
| 71 | |
| 72 | // all files need to be flipped |
| 73 | FreeImage_FlipVertical(dib); |
| 74 | |
| 75 | if(FreeImage_GetBPP(dib) == 8) |
| 76 | { |
| 77 | // grayscale images |
| 78 | |
| 79 | // convert to 32 bit |
| 80 | FIBITMAP *dib2 = FreeImage_ConvertToGreyscale(dib); |
| 81 | |
| 82 | // clear old image |
| 83 | delete image; |
| 84 | // create new instance with the right dimensions |
| 85 | image = new IPLImage(IPL_IMAGE_GRAYSCALE, width, height); |
| 86 | |
| 87 | for(int y = 0; y < height; y++) |
| 88 | { |
| 89 | for(int x = 0; x < width; x++) |
nothing calls this directly
no test coverage detected