diddi
Posts: 4
Joined: Wed Nov 06, 2013 12:58 pm

include jpg viewer in a c++ code

Wed Nov 06, 2013 1:13 pm

Hi everybody,
I'm working on the folloing project: A Raspberry equipped with a LCD-Display and selction buttons is used to select jpg-files from a USB stick. Once a picture is select it should be viewed on an HDMI-display (TV eg.)
The selection menue is written in C++. This works fine already.
The critical moment is when I pass the filename to an extern viewer program. So far I have tried feh. I'm not able to pass feh- commands from my C++ program to the viewer.
My question:
- Does anybody know a C++ library for a viewer which I can include into my code?
- Does anybody know a simple viewer that has a kind of "remote mode" in which it accepts commands from wothin a c++ program?
- Does anybody know a simple viewer that has a C++ interface (such as a viewer.h) ?

Thanks a lot

diddi

User avatar
AndyD
Posts: 2333
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: include jpg viewer in a c++ code

Thu Nov 07, 2013 1:43 am

You could easily write a simple image viewer using SDL and SDL_image. I found from googling feh that it is an X11 image viewer. Are you going to be using X on your HDMI display? It may be simpler to just display the images on the framebuffer. Either way SDL would be a good way to start. I wrote a very simple image viewer using SDL about a year ago. It is available here on github.

diddi
Posts: 4
Joined: Wed Nov 06, 2013 12:58 pm

Re: include jpg viewer in a c++ code

Fri Nov 08, 2013 4:41 pm

Thanks a lot for your reply and the idea using sdl-image.. As I'm pretty new on both C-programming and linux I first was trying the X-enviroment but later had the idea that there should be some buffer which is streamed to an HDMI device. As the project is a "slide projector" on a HDMI-TV-screen this should be the right approach.
I'll play around with your example and report my progress.. Hopefully it works out.

Dietrich

diddi
Posts: 4
Joined: Wed Nov 06, 2013 12:58 pm

Re: include jpg viewer in a c++ code

Tue Nov 12, 2013 7:58 am

Hi AndyD,
thanks again for the tipp. It works fine with SDL.
jpgs from a digital camera nowadays can have easily > 10MB. Then SDL on a raspi (jpgs loaded from an USB stick) works pretty slow and doesn't scale either. As you seem to be fit with this subject two more questions:
- Is there any tool to scale down images within a reasonable time ( one way would be to resize them to HDTV-resolution)
- Is there any way to load and process (e.g. scale) images in the background, while the previous image is shown.

Thanks and greeting to the southern half of the earth.

Dietrich

User avatar
AndyD
Posts: 2333
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: include jpg viewer in a c++ code

Tue Nov 12, 2013 7:45 pm

diddi wrote:...jpgs from a digital camera nowadays can have easily > 10MB. Then SDL on a raspi (jpgs loaded from an USB stick) works pretty slow and doesn't scale either. As you seem to be fit with this subject two more questions:
- Is there any tool to scale down images within a reasonable time ( one way would be to resize them to HDTV-resolution)
- Is there any way to load and process (e.g. scale) images in the background, while the previous image is shown.

Thanks and greeting to the southern half of the earth.

Dietrich
Yes, images straight out of the camera are pretty big. Resizing them will take a bit of time. I am not an expert on SDL, but after a quick search I can see that SDL doesn't appear to have code to resize images. I found SDL_rotozoom which is a part of SDL_gfx. This might be acceptable, but I expect it would be slow.

Another possible solution is to use the ImageMagick suite of programs to resize the images on the memory stick and place them in a temporary folder and display them from there.

jviyer
Posts: 30
Joined: Mon Nov 04, 2013 3:48 pm

Re: include jpg viewer in a c++ code

Sun Dec 08, 2013 6:03 pm

AndyD wrote:You could easily write a simple image viewer using SDL and SDL_image. I found from googling feh that it is an X11 image viewer. Are you going to be using X on your HDMI display? It may be simpler to just display the images on the framebuffer. Either way SDL would be a good way to start. I wrote a very simple image viewer using SDL about a year ago. It is available here on github.
AndyD
Thanks for the info about sdl. If I wanted the img to be shown on a small window <saw h by w> instead of it using the whole screen, is there a way to do it ? <perhaps something inside the code I could modify and recompile ?>
Thanks

User avatar
AndyD
Posts: 2333
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: include jpg viewer in a c++ code

Mon Dec 09, 2013 11:18 am

jviyer,
I have never used SDL, other than creating a simple example about a year ago for some one on this forum. I had a quick look, it appear that when you call SDL_BlitSurface() you can specify a source rectangle and a destination rectangle. The source rectangle allows you to only display a clipped region from you image. The destination rectangle allows you to specify the screen location where the image will be displayed.
Hope that helps!

diddi
Posts: 4
Joined: Wed Nov 06, 2013 12:58 pm

Re: include jpg viewer in a c++ code

Fri Mar 07, 2014 11:30 am

It took quite a while - but things work out ok now. Depending on the size of a picture it takes some seconds to resize it (using SDL_rotozoom) to the screen size. But during the time you watch the slide, the program preloads another picture and saves in a preload buffer. Inbetween a remote control (using wiringPi) has been added and it works fine.
My friend has programmed a mp3-player which runs together with the picture viewer on the same raspi.
If anybody would like the code feel free to contact me.

Dietrich

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 24129
Joined: Sat Jul 30, 2011 7:41 pm

Re: include jpg viewer in a c++ code

Fri Mar 07, 2014 11:32 am

I'm wondering whether using the libjpeg library (pretty easy to use) might give you faster performance.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I think it’s wrong that only one company makes the game Monopoly.” – Steven Wright

Return to “C/C++”