WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: FLTK Picture-See (AKA fl_picsee) - tiny GPL picture viewer using FLTK  (Read 14583 times)

Offline MikeLockmoore

  • Hero Member
  • *****
  • Posts: 525
  • Good software needn't be big!
Hello! I did not see (or perhaps I overlooked) a simple graphics image viewer applet in TC base or in the TCE/TCZ appbrowser, so I coded up one in FLTK. 

This program's executable is tiny (> 6K!  ;D) and loads images really fast.  It supports:
 * .JPG / JPEG
 * .GIF
 * .PNG
 * .BMP
 * .XBM
 * .XPM

It can be also launced from the command line.  Assuming it is placed in /usr/local/bin, or some other place in the search path, simply invoke:

# fl_picsee {{filename, which may include path}}

It works well with Rox-Filer if you set the run action to launch it.  In Rox, right-click, select "Set Run Action...", then put something like the following in the "Enter a shell command" text field:
Code: [Select]
/usr/local/bin/fl_picsee "$@"
Downsides?  It does not support scrolling and will not resize the image if it is too big to see on your screen.  The full path and file name in the title will be clipped if the window title bar is not long enough (especially true for small images), and the window maximizing button does not really work.  As I learn more about FLTK, I will try to address these shortcomings.

This 0.8.0 version is an alpha release only.  I have not learned fully how to make a .tce or .tcz distribution, so I am posting the GPL source code.  Perhaps Jason can package it for me once until I learn how to do it myself.  Or if given permission, I can attach the binary directly.

This requires the 1.1 version of FLTK, which is standard in TC 1.3 (and earlier, I assume).

Please address bug reports and and comments to this thread.  Hope you like it!

Source Code (EDIT, updated to version 0.8.1, which has some modifications to handle filenames that are too short or too long):

Code: [Select]
// fl_picsee  -- A FLTK-based picture viewer
#define appver "0.8.1"

/* -------------------------------------------------------
   Copyright 2009 Michael A. Losh
   
    "FLTK Picture-See" (also known as "fl_picsee")  is free software:
you can redistribute it and/or modify it under the terms of
    the GNU General Public License as published by the
    Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    FLTK Picture-See is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with FLTK Picture-See.  If not, see <http://www.gnu.org/licenses/>.
-----------------------------------------------------------------*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <FL/Fl.H>
#include <FL/fl_ask.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Shared_Image.H>
#include <FL/Fl_BMP_Image.H>
#include <FL/Fl_GIF_Image.H>
#include <FL/Fl_JPEG_Image.H>
#include <FL/Fl_PNG_Image.H>
#include <FL/Fl_XBM_Image.H>
#include <FL/Fl_XPM_Image.H>
#include <FL/Fl_Box.H>

int main(int argc, char** argv) {
int h, w;
int len = 0;
Fl_Image * fi_p = NULL;
char title[128] = "";
char filename[256];
char ext[8];
    fl_register_images();                       // initialize image lib
if (argc > 1) {
memset(filename, 0, 256);
strncpy(filename, argv[1], 255);
len = strlen(filename);
}
if (len > 4) {
printf("Loading image '%s'\n", filename);
sprintf(title, "%120s - FLTK Picture-See %s", filename, appver);

ext[0] = toupper(filename[len - 4]);
ext[1] = toupper(filename[len - 3]);
ext[2] = toupper(filename[len - 2]);
ext[3] = toupper(filename[len - 1]);
ext[4] = 0;

printf("File type appears to be '%s'\n", ext);

if (!strcmp(ext, ".JPG") || !strcmp(ext, "JPEG")) {
fi_p = new Fl_JPEG_Image(argv[1]);
}
else if (!strcmp(ext, ".PNG")) {
fi_p = new Fl_PNG_Image(argv[1]);
}
else if (!strcmp(ext, ".BMP")) {
fi_p = new Fl_BMP_Image(argv[1]);
}
else if (!strcmp(ext, ".GIF")) {
fi_p = new Fl_GIF_Image(argv[1]);
}
else if (!strcmp(ext, ".XBM")) {
fi_p = new Fl_XBM_Image(argv[1]);
}
else if (!strcmp(ext, ".XPM")) {
fi_p = new Fl_XPM_Image(argv[1]);
}
else {
fl_alert("File with name ending '%s' is not a known type.  FLTK Picture-See will exit.\n", ext);
return -1;
}

h = fi_p->h();
if (h < 80) h = 80;
w = fi_p->w();
if (w < 120) w = 120;

Fl_Window     win(w + 24, h + 24, title); 
Fl_Box        box(10,10, w + 2, h + 2);
box.image(fi_p);                           
win.show();
return(Fl::run());
}
}

--
Mike "Lockmoore" Losh
« Last Edit: April 14, 2009, 04:12:38 AM by MikeLockmoore »

Offline ^thehatsrule^

  • Administrator
  • Hero Member
  • *****
  • Posts: 1726
Re: FLTK Picture-See (AKA fl_picsee) - tiny GPL picture viewer using FLTK
« Reply #1 on: April 14, 2009, 01:21:25 AM »
This reminds me of mikshaw's(?) fltk icon viewer app.

That, and the Fl_Shared_Image class may be of interest.  (There's also some code problems that could be improved upon, fwiw)

Offline MikeLockmoore

  • Hero Member
  • *****
  • Posts: 525
  • Good software needn't be big!
Re: FLTK Picture-See (AKA fl_picsee) - tiny GPL picture viewer using FLTK
« Reply #2 on: April 14, 2009, 04:17:26 AM »
@thehatsrule: I'm not familiar with those so far.  Viewing icons might be a nice additional feature.

All:

When I build fl_picsee, I dynamically link to libfltk.so and libfltk_images.so.  I'm not sure that libfltk_images.so is in the TC core (I'll check soon).  If not, maybe fl_see should be statically linked to the image functions?  Or some of the additional fltk libs be available as a extension without needing all of compiletc.tce?

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10965
Re: FLTK Picture-See (AKA fl_picsee) - tiny GPL picture viewer using FLTK
« Reply #3 on: April 14, 2009, 08:53:24 AM »
- libfltk_images is in the base
- imlib2_view may be of interest ;)

Currently your app is pretty similar in functionality, but it will quite soon surpass the imlib2 app I believe.
The only barriers that can stop you are the ones you create yourself.

Offline MikeLockmoore

  • Hero Member
  • *****
  • Posts: 525
  • Good software needn't be big!
Re: FLTK Picture-See (AKA fl_picsee) - tiny GPL picture viewer using FLTK
« Reply #4 on: April 14, 2009, 09:37:33 AM »
Quote
- imlib2_view may be of interest

I guess I did overlook something in the base.   :-[  I'm not trying to duplicate what is already available, expecially if it available in the base!  If it's open-source, maybe I can offer a patch based on a new feature in my viewer (if any). 

I mostly wrote fl_picsee as an warm-up exercise with FLTK.
--
Mike L. 

Offline roberts

  • Administrator
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: FLTK Picture-See (AKA fl_picsee) - tiny GPL picture viewer using FLTK
« Reply #5 on: April 14, 2009, 10:22:33 AM »
imlib2_view could use a GUI.
A native fltk image viewer would be very nice.
I encourage you to continue.

Note: boot tinycore base norestore nolocal
Then try to run program program.
Doing such will show if it is dependent on compiletc or any other extension.

Whenever possible I would also encourage the use of fluid projects.
That way it is easy to add/adjust GUI elements.
10+ Years Contributing to Linux Open Source Projects.

Offline MikeLockmoore

  • Hero Member
  • *****
  • Posts: 525
  • Good software needn't be big!
Re: FLTK Picture-See (AKA fl_picsee) - tiny GPL picture viewer using FLTK
« Reply #6 on: April 14, 2009, 09:41:57 PM »
roberts:

I tested my latest version, 0.8.2, using the 'base norestore nolocal' and it runs fine!  I have not tried fluid yet, since fl_picsee does not really have much of a designed GUI, but I would like to try it out when I port my hexadecimal file viewer app.

Version 0.8.2 of fl_picsee will open the FLTK file chooser if no command-line parameter is available (e.g. if it were in the app menu?).  In this file chooser, a thumbnail preview is available as an option!  The nice thing is that this comes with the standard FLTK file chooser and FLTK image library for free.  My compiled executable has bloated up to 6.2K, but I think the extra file chooser feature is worth 1K or so.  Even at 6.2K, it is smaller than imlib2_view. ;)  If there is a file passed as a command-line parameter, the image opens immediately, as in the earlier versions.

One issue is that the file chooser dialog itself has some very jagged fonts in the file selection list and other fields.  I would guess this is because FLTK as built into TC base has very limited fonts, which get stretched when needed.

I'll attach my updated source file and my makefile.  Maybe Jason W. can build it and make an initial beta-test .tce/.tcz that people can try?  I would like to learn how to make extension files myself in the near future.  I understand most of the steps documented in the Wiki, but I have not used autoconf, so the configure stuff does not apply to building and installing this app.
--
Mike L.

Offline Jason W

  • Administrator
  • Hero Member
  • *****
  • Posts: 9730
Re: FLTK Picture-See (AKA fl_picsee) - tiny GPL picture viewer using FLTK
« Reply #7 on: April 15, 2009, 04:38:45 AM »
I'll make an extension of this and post it if you would like.

Offline MikeLockmoore

  • Hero Member
  • *****
  • Posts: 525
  • Good software needn't be big!
Re: FLTK Picture-See (AKA fl_picsee) - tiny GPL picture viewer using FLTK
« Reply #8 on: April 15, 2009, 05:41:33 AM »
Jason:

Yes, please!  And if you could describe how you made the extension from this stuff, I would appreciate it.  Then I could try to make the next version for this or other simple apps. Thanks!, Mike L.

Offline Jason W

  • Administrator
  • Hero Member
  • *****
  • Posts: 9730
Re: FLTK Picture-See (AKA fl_picsee) - tiny GPL picture viewer using FLTK
« Reply #9 on: April 15, 2009, 02:37:23 PM »
I am posting the extension now, and here is a script that builds it into a tce:

Code: [Select]
#!/bin/bash
#required extensions: compiletc, bash, advcomp
make
mkdir -p picsee/usr/local/{bin,tce.menu}
cp fl_picsee picsee/usr/local/bin/
echo "<JWM>" > picsee/usr/local/tce.menu/fl_picsee
echo "<Program label=\"FL_picsee\">/usr/local/bin/fl_picsee</Program>" >> picsee/usr/local/tce.menu/fl_picsee
echo "</JWM>" >> picsee/usr/local/tce.menu/fl_picsee
cd picsee
find usr -not -type d > /tmp/list
tar -T /tmp/list -czvf /home/tc/fl_picsee.tce
cd /home/tc
advdev -z4 fl_picsee.tce
#create info file manually
md5sum fl_picsee.tce > fl_picsee.tce.md5.txt
tar -ztf fl_picsee.tce > fl_picsee.tce.list


Offline ^thehatsrule^

  • Administrator
  • Hero Member
  • *****
  • Posts: 1726
Re: FLTK Picture-See (AKA fl_picsee) - tiny GPL picture viewer using FLTK
« Reply #10 on: April 15, 2009, 04:55:15 PM »
See the wiki entry on creating extensions for more info.

Offline MikeLockmoore

  • Hero Member
  • *****
  • Posts: 525
  • Good software needn't be big!
Re: FLTK Picture-See (AKA fl_picsee) - tiny GPL picture viewer using FLTK
« Reply #11 on: April 15, 2009, 05:26:04 PM »
I appreciate seeing the script, Jason.  The Wiki document is great, but it covers many scenarios.  Seeing how this script works for a simple case helps make the Wiki info more clear.  I'll be able to manage this easily in the future.  Maybe a generic version of this script could be added to the text in the Wiki? Like so? (Maybe my comments are not 100% accurate, but I hope they are close).

Code: [Select]
#!/bin/bash
#required extensions: compiletc, bash, advcomp
#Script to package a simple application as a Tiny Core Extension
THE_APP=your_app_name_here
THE_APP_LABEL='Your label here'

#Create the binary version of the application
make

#Create a directory tree mimicking the installed files
mkdir -p ${THE_APP}/usr/local/{bin,tce.menu}

#Copy the application binary to the install tree
cp  ${THE_APP} ${THE_APP}/usr/local/bin/

#Create a menu entry file
echo "<JWM>" > ${THE_APP}/usr/local/tce.menu/${THE_APP}
echo "<Program label=\"${THE_APP_LABEL}\">/usr/local/bin/${THE_APP}</Program>" >> ${THE_APP}/usr/local/tce.menu/${THE_APP}
echo "</JWM>" >> ${THE_APP}/usr/local/tce.menu/${THE_APP}

#Make a list of the files to be installed
cd ${THE_APP}
find usr -not -type d > /tmp/list

#Archive and compress the files in the installation list
tar -T /tmp/list -czvf /home/tc/${THE_APP}.tce

#Further compress the .tce file
cd /home/tc
advdev -z4 ${THE_APP}.tce

#Create md5 checksum and info files manually
md5sum ${THE_APP}.tce > ${THE_APP}.tce.md5.txt
tar -ztf ${THE_APP}.tce > ${THE_APP}.tce.list

As I said in the News forum, thanks for helping with this!  I hope some people find this app and the discussion on making extensions useful.  :)
--
Mike L.
« Last Edit: April 15, 2009, 08:00:08 PM by MikeLockmoore »

Offline roberts

  • Administrator
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: FLTK Picture-See (AKA fl_picsee) - tiny GPL picture viewer using FLTK
« Reply #12 on: April 19, 2009, 10:37:59 AM »
Adding fl_picsee to the next cut of the base system. Replaces imlib2_view.
10+ Years Contributing to Linux Open Source Projects.

Offline MikeLockmoore

  • Hero Member
  • *****
  • Posts: 525
  • Good software needn't be big!
Re: FLTK Picture-See (AKA fl_picsee) - tiny GPL picture viewer using FLTK
« Reply #13 on: April 20, 2009, 07:26:20 AM »
RobertS: Wow, I'm humbled and honored.  Let me know if you think any changes are needed.  We can bump up the version number prior to release.
--
Mike

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10965
Re: FLTK Picture-See (AKA fl_picsee) - tiny GPL picture viewer using FLTK
« Reply #14 on: April 20, 2009, 09:23:56 AM »
Some ideas:

- scaling, and when not scaled, scrolling
- have the filename of the pic as the tooltip of the image
- clicking on the image could open the file selector (or maybe have a separate button for it?)
- handling of the case where several pics have been entered on the command line: either the way of showimage of sdl_image (pressing the right or left keys would go to the next/prev image), or arrow buttons
- slideshows :)
« Last Edit: April 20, 2009, 09:25:35 AM by curaga »
The only barriers that can stop you are the ones you create yourself.