Skip to content

Webp image support#1279

Merged
kaamui merged 7 commits into
OpenBoard-org:devfrom
sebojolais:WebpImageSupport
Jun 18, 2025
Merged

Webp image support#1279
kaamui merged 7 commits into
OpenBoard-org:devfrom
sebojolais:WebpImageSupport

Conversation

@sebojolais
Copy link
Copy Markdown
Contributor

Fix this issue: #1278

@sebojolais
Copy link
Copy Markdown
Contributor Author

This PR leads me to ask a question :

  • Are the the method
    QString UBFileSystemUtils::mimeTypeFromFileName(const QString& fileName)
    {
    QString ext = extension(fileName);
    if (ext == "xls" || ext == "xlsx") return "application/msexcel";
    if (ext == "ppt" || ext == "pptx") return "application/mspowerpoint";
    if (ext == "ief") return "image/ief";
    if (ext == "m3u") return "audio/x-mpegurl";
    if (ext == "key") return "application/x-iwork-keynote-sffkeynote";
    if (ext == "odf") return "application/vnd.oasis.opendocument.formula";
    if (ext == "aif" || ext == "aiff" || ext == "aifc") return "audio/x-aiff";
    if (ext == "odp") return "application/vnd.oasis.opendocument.presentation";
    if (ext == "xml") return "application/xml";
    if (ext == "rgb") return "image/x-rgb";
    if (ext == "ods") return "application/vnd.oasis.opendocument.spreadsheet";
    if (ext == "rtf") return "text/rtf";
    if (ext == "odt") return "application/vnd.oasis.opendocument.text";
    if (ext == "xbm") return "image/x-xbitmap";
    if (ext == "lsx" || ext == "lsf") return "video/x-la-asf";
    if (ext == "jfif") return "image/pipeg";
    if (ext == "ppm") return "image/x-portable-pixmap";
    if (ext == "csv") return "text/csv";
    if (ext == "pgm") return "image/x-portable-graymap";
    if (ext == "odc") return "application/vnd.oasis.opendocument.chart";
    if (ext == "odb") return "application/vnd.oasis.opendocument.database";
    if (ext == "cmx") return "image/x-cmx";
    if (ext == "ico") return "image/x-icon";
    if (ext == "mp3") return "audio/mpeg";
    if (ext == "wav") return "audio/x-wav";
    if (ext == "pbm") return "image/x-portable-bitmap";
    if (ext == "ras") return "image/x-cmu-raster";
    if (ext == "txt") return "text/plain";
    if (ext == "xpm") return "image/x-xpixmap";
    if (ext == "ra" || ext == "ram") return "audio/x-pn-realaudio";
    if (ext == "numbers") return "application/x-iwork-numbers-sffnumbers";
    if (ext == "snd" || ext == "au") return "audio/basic";
    if (ext == "zip") return "application/zip";
    if (ext == "pages") return "application/x-iwork-pages-sffpages";
    if (ext == "movie") return "video/x-sgi-movie";
    if (ext == "xwd") return "image/x-xwindowdump";
    if (ext == "pnm") return "image/x-portable-anymap";
    if (ext == "cod") return "image/cis-cod";
    if (ext == "doc" || ext == "docx") return "application/msword";
    if (ext == "html") return "text/html";
    if (ext == "mid" || ext == "rmi") return "audio/mid";
    if (ext == "jpeg" || ext == "jpg" || ext == "jpe") return "image/jpeg";
    if (ext == "png") return "image/png";
    if (ext == "bmp") return "image/bmp";
    if (ext == "tiff" || ext == "tif") return "image/tiff";
    if (ext == "gif") return "image/gif";
    if (ext == "svg" || ext == "svgz") return "image/svg+xml";
    if (ext == "pdf") return "application/pdf";
    if (ext == "mov" || ext == "qt") return "video/quicktime";
    if (ext == "mpg" || ext == "mpeg" || ext == "mp2" || ext == "mpe" || ext == "mpa" || ext == "mpv2") return "video/mpeg";
    if (ext == "mp4") return "video/mp4";
    if (ext == "asf" || ext == "asx" || ext == "asr") return "video/x-ms-asf";
    if (ext == "wmv") return "video/x-ms-wmv";
    if (ext == "wvx") return "video/x-ms-wvx";
    if (ext == "wm") return "video/x-ms-wm";
    if (ext == "wmx") return "video/x-ms-wmx";
    if (ext == "avi") return "video/x-msvideo";
    if (ext == "ogv") return "video/ogg";
    if (ext == "flv") return "video/x-flv"; // TODO UB 4.x ... we need to be smarter ... flash may need an external plugin :-(
    if (ext == "m4v") return "video/x-m4v";
    // W3C widget
    if (ext == "wgt") return "application/widget";
    if (ext == "wgs") return "application/search";
    // Apple widget
    if (ext == "wdgt") return "application/vnd.apple-widget"; //mime type invented by us :-( // NOTE @letsfindaway obsolete
    if (ext == "swf") return "application/x-shockwave-flash";
    if (ext == "rdf") return "application/openboard-document";
    return "";
    }
  • and the method
    QString UBFileSystemUtils::fileExtensionFromMimeType(const QString& pMimeType)
    {
    // TODO UB 4.x map from config file, based on a "good" source
    if (pMimeType == "application/msexcel") return "xls";
    if (pMimeType == "application/mspowerpoint") return "ppt";
    if (pMimeType == "image/ief") return "ief";
    if (pMimeType == "audio/x-mpegurl") return "m3u";
    if (pMimeType == "application/x-iwork-keynote-sffkeynote") return "key";
    if (pMimeType == "application/vnd.oasis.opendocument.formula") return "odf";
    if (pMimeType == "audio/x-aiff") return "aif";
    if (pMimeType == "application/vnd.oasis.opendocument.presentation") return "odp";
    if (pMimeType == "application/xml") return "xml";
    if (pMimeType == "image/x-rgb") return "rgb";
    if (pMimeType == "application/vnd.oasis.opendocument.spreadsheet") return "ods";
    if (pMimeType == "text/rtf") return "rtf";
    if (pMimeType == "application/vnd.oasis.opendocument.text") return "odt";
    if (pMimeType == "image/x-xbitmap") return "xbm";
    if (pMimeType == "video/x-la-asf") return "lsx";
    if (pMimeType == "image/pipeg") return "jfif";
    if (pMimeType == "image/x-portable-pixmap") return "ppm";
    if (pMimeType == "text/csv") return "csv";
    if (pMimeType == "image/x-portable-graymap") return "pgm";
    if (pMimeType == "application/vnd.oasis.opendocument.chart") return "odc";
    if (pMimeType == "application/vnd.oasis.opendocument.database") return "odb";
    if (pMimeType == "image/x-cmx") return "cmx";
    if (pMimeType == "image/x-icon") return "ico";
    if (pMimeType == "audio/mpeg") return "mp3";
    if (pMimeType == "audio/x-wav") return "wav";
    if (pMimeType == "image/x-portable-bitmap") return "pbm";
    if (pMimeType == "image/x-cmu-raster") return "ras";
    if (pMimeType == "text/plain") return "txt";
    if (pMimeType == "image/x-xpixmap") return "xpm";
    if (pMimeType == "audio/x-pn-realaudio") return "ram";
    if (pMimeType == "application/x-iwork-numbers-sffnumbers") return "numbers";
    if (pMimeType == "audio/basic") return "snd";
    if (pMimeType == "application/zip") return "zip";
    if (pMimeType == "application/x-iwork-pages-sffpages") return "pages";
    if (pMimeType == "video/x-sgi-movie") return "movie";
    if (pMimeType == "image/x-xwindowdump") return "xwd";
    if (pMimeType == "image/x-portable-anymap") return "pnm";
    if (pMimeType == "image/cis-cod") return "cod";
    if (pMimeType == "application/msword") return "doc";
    if (pMimeType == "text/html") return "html";
    if (pMimeType == "audio/mid") return "mid";
    if (pMimeType == "image/jpeg") return "jpeg";
    if (pMimeType == "image/png") return "png";
    if (pMimeType == "image/bmp") return "bmp";
    if (pMimeType == "image/tiff") return "tiff";
    if (pMimeType == "image/gif") return "gif";
    if (pMimeType == "image/svg+xml") return "svg";
    if (pMimeType == "application/pdf") return "pdf";
    if (pMimeType == "video/quicktime") return "mov";
    if (pMimeType == "video/mpeg") return "mpg";
    if (pMimeType == "video/mp4") return "mp4";
    if (pMimeType == "video/x-ms-asf") return "asf";
    if (pMimeType == "video/x-ms-wmv") return "wmv";
    if (pMimeType == "video/x-ms-wvx") return "wvx";
    if (pMimeType == "video/x-ms-wm") return "wm";
    if (pMimeType == "video/x-ms-wmx") return "wmx";
    if (pMimeType == "video/x-msvideo") return "avi";
    if (pMimeType == "video/ogg") return "ogv";
    if (pMimeType == "video/x-flv") return "flv";
    if (pMimeType == "video/x-m4v") return "m4v";
    if (pMimeType == "application/widget") return "wgt";
    if (pMimeType == "application/vnd.apple-widget") return "wdgt"; //mime type invented by us :-(
    if (pMimeType == "application/x-shockwave-flash") return "swf";
    return "";
    }

are really usefull ?
Because since Qt 5, there are these methods that do the job for us in an exhaustive way:

@kaamui
Copy link
Copy Markdown
Member

kaamui commented Jun 18, 2025

Hi @sebojolais,

Maybe these functions could be simplified or extend Qt ones, but removed I'm not sure because of our own extensions and filetypes

@kaamui kaamui merged commit eba6eb9 into OpenBoard-org:dev Jun 18, 2025
@sebojolais sebojolais deleted the WebpImageSupport branch June 18, 2025 19:33
@sebojolais
Copy link
Copy Markdown
Contributor Author

sebojolais commented Jun 18, 2025

Hi @sebojolais,

Maybe these functions could be simplified or extend Qt ones, but removed I'm not sure because of our own extensions and filetypes

Yes it is true, we have to keep them.

But there are some benefits to change the implementation by using QT API for common mime-types and keeping the parts for our own format:

  • Any issue like mine with a file type not supported will be fix if it is supported by Qt
  • No more code to support new standard, it will be done by Qt
  • We have to maintain our code just to support our own format, no more stuff for standard.

More details about the formats that OB will support after the modifications. It seems that since Qt 6, the mimetypes detection is provided by the freedesktop.org shared-mime-info project. https://doc.qt.io/qt-6/qmimedatabase.html. So the numbers of file format supported by the function will be wide.

Are you agree to modify these functions in this sense ? If yes, I can provide a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants