+
+enum FileType {
+ EPS,
+ PNG,
+ JPEG,
+ GIF,
+ PDF,
+ UNKNOWN
+};
+
+bool isEPS(string const & filename)
+{
+ if (filename.empty() || !IsFileReadable(filename)) return false;
+
+ ifstream ifs(filename.c_str());
+
+ if (!ifs) return false; // Couldn't open file...
+
+ bool is_eps = false; // Have we recognized the file as EPS?
+ string to_find = "%!PS-Adobe-"; // The string we use to recognize
+ int const max_attempts = 500; // Maximum strings to read to attempt recognition
+ int count = 0; // Counter of attempts.
+ string str;
+ for (; count < max_attempts; ++count) {
+ if (ifs.eof()) {
+ lyxerr[Debug::INFO] << "InsetGraphics (isEPS)"
+ " End of file reached and it wasn't found to be EPS!" << endl;
+ break;
+ }
+
+ ifs >> str;
+ if (str.find(to_find)) {
+ is_eps = true;
+ break;
+ }
+ }
+
+ return is_eps;
+}
+
+enum FileType classifyFileType(string const & filename, string const & suffix)
+{
+ if (suffix == "png")
+ return PNG;
+ else if (suffix == "jpg" || suffix == "jpeg")
+ return JPEG;
+ else if (suffix == "gif")
+ return GIF;
+ else if (suffix == "pdf")
+ return PDF;
+ else if (isEPS(filename))
+ return EPS;
+
+ return UNKNOWN;
+}
+
+string decideOutputImageFormat(string const & suffix, enum FileType type)