WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Screenshot with FLTK  (Read 295 times)

Offline nimday

  • Jr. Member
  • **
  • Posts: 61
Screenshot with FLTK
« on: August 05, 2017, 05:44:11 PM »
A little screenshot program with FLTK & libpng
Tested with FLWM & JWM

flshot.cpp (or any name you like)
Code: [Select]
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/fl_draw.H>
//#include <FL/x.H>
#include <X11/extensions/shape.h>
#include <png.h>

XRectangle rect;
unsigned char *p;
char fname[128];

void save_png(const char *dst,unsigned char* pixels,int w,int h){
 
  FILE *fp;
  fp = fl_fopen(dst, "wb");
  png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
  png_infop info = png_create_info_struct(png);
  png_bytep ptr = (png_bytep)pixels;
  png_init_io(png, fp);
  png_set_IHDR(png, info, w, h, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
               PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
  png_write_info(png, info);
 
  for (int i = h; i > 0; i--, ptr += w * 3) {
    png_write_row(png,ptr);
  }

  png_write_end(png,info);
  png_destroy_write_struct(&png, &info);
 
  fclose(fp);
}


class WIN : public Fl_Window {
 public:
   
   WIN(int w, int h, const char*l = 0):Fl_Window(w,h,l){}
 
   void draw(){
   Fl::wait(10);
   p = fl_read_image(0,0,0,w(),h());
   if(p){
  save_png(fname,p,w(),h());
  delete[]p;
   }
   hide();
   }
   
};

int main(int argc, char *argv[]) {
WIN *win = new WIN(30,30);
win->border(0);
win->fullscreen();
win->show();
XShapeCombineRectangles(fl_display,fl_xid(win),0,0,0,&rect,0,ShapeSet,0);
strcpy(fname,argc>1 ? argv[1] : "screenshot.png");
return Fl::run();
}


build
Code: [Select]
#!/bin/sh
prog='flshot'
echo 'Compiling ...'
g++ $prog.cpp -o $prog `fltk-config --cxxflags --use-images --ldflags`

Offline polikuo

  • Full Member
  • ***
  • Posts: 185
Re: Screenshot with FLTK
« Reply #1 on: August 06, 2017, 06:21:57 PM »
It does not compile for me  :(

tce-load -i compiletc fltk-1.3-dev:
Code: [Select]
/tmp/cc3RHBQS.o:(.rodata._ZTI3WIN[_ZTI3WIN]+0x10): undefined reference to `typeinfo for Fl_Window'
collect2: error: ld returned 1 exit status

tce-load -i compiletc fltk-full-dev:
Code: [Select]
/usr/local/bin/ld: /tmp/ccMoNlrG.o: undefined reference to symbol 'png_create_write_struct@@PNG16_0'
/usr/local/lib/libpng16.so.16: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

Have I done something wrong ?
Code: [Select]
g++ flshot.cpp -o flshot `fltk-config --cxxflags --use-images --ldflags`
Running TC 64 with openbox.

BTW, what's the difference between this and "/usr/local/bin/screenshot.sh" from Xprogs ?

Offline Rich

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 5337
Re: Screenshot with FLTK
« Reply #2 on: August 06, 2017, 07:14:27 PM »
Hi polikuo
Maybe you also need  libpng-dev.tcz?

Offline polikuo

  • Full Member
  • ***
  • Posts: 185
Re: Screenshot with FLTK
« Reply #3 on: August 06, 2017, 09:52:17 PM »
Hi polikuo
Maybe you also need  libpng-dev.tcz?

It's there, included as a dep of fltk-full-dev.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 9518
Re: Screenshot with FLTK
« Reply #4 on: August 07, 2017, 12:08:46 AM »
Add -fno-rtti -fno-exceptions to build with the default fltk.
The only barriers that can stop you are the ones you create yourself.

Offline polikuo

  • Full Member
  • ***
  • Posts: 185
Re: Screenshot with FLTK
« Reply #5 on: August 07, 2017, 01:13:45 AM »
Add -fno-rtti -fno-exceptions to build with the default fltk.

Thanks, it compiles this time. (Using FLWM & JWM)
However, the created screenshot.png is nothing but a screen-size black rectangle.

@nimday, the "/usr/local/bin/screenshot.sh" from Xprogs creates a screen shot as well.
Is that what your program does ?
P.S. your program halts with openbox, nothing is created.

Offline Rich

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 5337
Re: Screenshot with FLTK
« Reply #6 on: August 07, 2017, 05:46:29 AM »
Hi nimday
I'm not trying to belittle your effort, just wanted to point out there are 2 extensions already available for screen shots.

windowshot.tcz - A script that allows you to capture the whole screen or just an individual window.

grabber.tcz - A program that allows you to capture the whole screen or just the section you select with the mouse.

There might be others. I'm just aware of these two because I helped to develop them.

Offline nimday

  • Jr. Member
  • **
  • Posts: 61
Re: Screenshot with FLTK
« Reply #7 on: August 07, 2017, 08:37:01 PM »
Add -fno-rtti -fno-exceptions to build with the default fltk.

Thanks, it compiles this time. (Using FLWM & JWM)
However, the created screenshot.png is nothing but a screen-size black rectangle.

@nimday, the "/usr/local/bin/screenshot.sh" from Xprogs creates a screen shot as well.
Is that what your program does ?
P.S. your program halts with openbox, nothing is created.

I'm sorry for that, i tried that with TC 8 32 bit
I'll try 64 bit later, Maybe that's the issue

Here the screenshot from the program



Hi nimday
I'm not trying to belittle your effort, just wanted to point out there are 2 extensions already available for screen shots.

windowshot.tcz - A script that allows you to capture the whole screen or just an individual window.

grabber.tcz - A program that allows you to capture the whole screen or just the section you select with the mouse.

There might be others. I'm just aware of these two because I helped to develop them.


No problem,  Just wanted to share and now this program has a bug :)

Offline nimday

  • Jr. Member
  • **
  • Posts: 61
Re: Screenshot with FLTK
« Reply #8 on: August 07, 2017, 09:00:18 PM »
@curaga, Can you please test this with 64 ?
If you have time.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 9518
Re: Screenshot with FLTK
« Reply #9 on: August 07, 2017, 11:13:31 PM »
I don't use 64-bit TC right now, sorry.
The only barriers that can stop you are the ones you create yourself.

Online Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 9371
Re: Screenshot with FLTK
« Reply #10 on: August 08, 2017, 12:40:32 AM »
it compiles 64bit, but the resulting screenshot.png is a black square

Offline polikuo

  • Full Member
  • ***
  • Posts: 185
Re: Screenshot with FLTK
« Reply #11 on: August 08, 2017, 02:51:40 AM »
No problem,  Just wanted to share and now this program has a bug :)

No worries.

FYI, on PiCore, some headers can not be found on the repo.
ex: #include <X11/extensions/shapeconst.h>

I grab xorg-proto.tcz from TC64 repo and it compiles.
It also halt with openbox, and creates a black square using FLWM.

Offline nimday

  • Jr. Member
  • **
  • Posts: 61
Re: Screenshot with FLTK
« Reply #12 on: August 08, 2017, 06:44:19 PM »
it compiles 64bit, but the resulting screenshot.png is a black square

No problem,  Just wanted to share and now this program has a bug :)

No worries.

FYI, on PiCore, some headers can not be found on the repo.
ex: #include <X11/extensions/shapeconst.h>

I grab xorg-proto.tcz from TC64 repo and it compiles.
It also halt with openbox, and creates a black square using FLWM.

Thank you both for testing
It seems the problem is 64 bit

Online Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 9371
Re: Screenshot with FLTK
« Reply #13 on: August 08, 2017, 11:18:31 PM »
piCore is 32-bit

Offline nimday

  • Jr. Member
  • **
  • Posts: 61
Re: Screenshot with FLTK
« Reply #14 on: August 09, 2017, 06:29:00 PM »
Thanks again, btw i have new issue with 1.3.4

http://forum.tinycorelinux.net/index.php/topic,21296.0.html