Tiny Core Linux
General TC => Programming & Scripting - Unofficial => Topic started by: nimday on August 05, 2017, 09:44:11 PM
-
A little screenshot program with FLTK & libpng
Tested with FLWM & JWM
flshot.cpp (or any name you like)
#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
#!/bin/sh
prog='flshot'
echo 'Compiling ...'
g++ $prog.cpp -o $prog `fltk-config --cxxflags --use-images --ldflags`
-
It does not compile for me :(
tce-load -i compiletc fltk-1.3-dev:
/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:
/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 ?
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 ?
-
Hi polikuo
Maybe you also need libpng-dev.tcz?
-
Hi polikuo
Maybe you also need libpng-dev.tcz?
It's there, included as a dep of fltk-full-dev.
-
Add -fno-rtti -fno-exceptions to build with the default fltk.
-
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.
-
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.
-
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
(https://s5.postimg.org/6f99ec9ur/image.png) (https://postimg.org/image/6f99ec9ur/)
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 :)
-
@curaga, Can you please test this with 64 ?
If you have time.
-
I don't use 64-bit TC right now, sorry.
-
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.
-
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
-
piCore is 32-bit
-
Thanks again, btw i have new issue with 1.3.4
http://forum.tinycorelinux.net/index.php/topic,21296.0.html