Having trouble showing BMP images in XPCE (Unix/X11)

Hello everyone, I’m using: SWI-Prolog version 8.2.4.
I’m trying to show images in a frame in Prolog, I have read the userguide of XPCE and replicated the code of FileViewer demo. I made some modifications to the code to show an image in a certain window, the code seems to work pretty well when the format of the image is a JPG/JPEG but I want to be able to read also BMP images, is this possible in Unix/X11?
I have also read that a possible way to solve this is to convert this BMP files to JPG files, but this is not practical for our goals.

My predicate of viewing a file is called view as the same example provided (FileViewer Demo) and looks like this:

% your code here
view(DirObj, F) :-
    send(new(V, view(F)), open),
    get(DirObj, file(F), FileObj),
    new(I,image(FileObj)),
    new(Bitmap,bitmap(I)),
    send(V,display,Bitmap).

Thanks

This works fine:

:- use_module(library(pce)).

view :-
    new(D, directory('/usr/lib/swi-prolog/xpce/prolog/lib/dialog/bitmaps/')),
    view(D, 'slider.bm').

view(DirObj, F) :-
    send(new(V, view(F)), open),
    get(DirObj, file(F), FileObj),
    new(I,image(FileObj)),
    new(Bitmap,bitmap(I)),
    send(V,display,Bitmap).

It is a bit odd usage of class view, which is a window showing an editor. Being a window it can display a bitmap on top of of the editor, but whether that is a good idea …

If that doesn’t work, could it be that your file is not a good old X11 bitmap file?

Ok, the code you provided me works well, however it was my fault to not provide the full idea of what I meant to do. The approach I’m searching with this application is to show images on a window from a directory, the predicate bitmap works perfectly with JPG/JPEG images but not for BMP images. I have tried to search in the documentation another predicate that would let me show a BMP file but I can not find anything.

:- use_module(library(pce)).

fileviewer(Dir) :-
    new(DirObj, directory(Dir)),
    new(F, frame('File Viewer')),
    send(F, append(new(B, browser))),
    send(new(D, dialog), below(B)),
    send(D, append(button(view,
        message(@prolog, view,
            DirObj, B?selection?key)))),
    send(D, append(button(quit,
    message(F, destroy)))),
    send(B, members(DirObj?files)),
    send(F, open).

view(DirObj, F) :-
    send(new(V, view(F)), open),
    get(DirObj, file(F), FileObj),
    new(I,image(FileObj)),
    new(Bitmap,bitmap(I)),
    send(V,display,Bitmap).

I am truly sorry if my questions are kind of basic but I am just getting started working with XPCE.

Sorry, I misread the question

No. It is long ago, but AFAIK we use the Windows functions to read Windows BMP files. These functions are not around on X11/Linux. Best option is probably to use ImageMagic’s convert(1) tool, calling it as something like this.

 process_create(path(convert), [file('myfile.bmp'), file('myfile.gif')], [])

Of course you could also extend the image import code and send a PR :slight_smile:

Note that xpce is a bit old school. These days it is more popular to write a webserver in SWI-Prolog and use your browser as frontend …

Ok, sorry for answering this late but I was making tests. Changing the BMP image to a GIF works perfectly. I’ll take into account the Web Server, thank you for your support.