Thank you very much, I am sure it wiil help me.
I'll check it
thanks again
bela







> > > Well, FWIW, I'd still go with using Fl_Preferences to get the
> > > persistence - it produces human readable output and is already part
> > > of fltk, rather than adding boost (which I had a lot of trouble with
> > > in the early days, so I'm wary of it now - although I accept that it
> > > probably an awful lot better now!)
> > >
> > > --
> > > Ian
> > >
> >
> > Do you think that from preferences you can store the object, it seems 
> > difficult, preferences are properties for the object, but what about the 
> > positions in caneva??
> > Would you please explain your idea?
> > thanks
> >
>
> sorry for my english,
> I post you a little app showing how to save 24 bits/pixel (RGB - 16.7 million 
> colors) bmp images.
> not sure that subclass of Fl_Box and my draw() and handle() methods are 
> bugfree.
>
> make a selection rect and then press "save"
>
> here is fluid file:
> *****************************************
>
> # data file for the Fltk User Interface Designer (fluid)
> version 1.0106
> header_name {.h}
> code_name {.cxx}
> decl {\#include <stdio.h>} {public
> }
>
> decl {\#include <stdlib.h>} {public
> }
>
> decl {\#include <FL/fl_draw.H>} {public
> }
>
> decl {\#include <FL/Fl_Widget.H>} {public
> }
>
> decl {\#include <FL/Fl_Box.H>} {public
> }
>
> decl {\#include "bmppix.h"} {public
> }
>
> decl {BMPhf hf_bmp;} {public
> }
>
> decl {BMPhi hi_bmp;} {public
> }
>
> decl {mRGB   myRGB;} {public
> }
>
> decl {FILE *outbmp;} {public
> }
>
> decl {int cnt;} {public
> }
>
> decl {unsigned char pixRGB[3];} {public
> }
>
> decl {int ev_p_x;} {public
> }
>
> decl {int ev_p_y;} {public
> }
>
> decl {int ev_r_x;} {public
> }
>
> decl {int ev_r_y;} {public
> }
>
> decl {int ev_w;} {public
> }
>
> decl {int ev_h;} {public
> }
>
> decl {int ev_w3;} {public
> }
>
> decl {int clr_ovr;} {public
> }
>
> class Mydrwbox {open : {public Fl_Box}
> } {
>   Function {draw()} {open private return_type void
>   } {
>     code {fl_overlay_clear();
> fl_push_clip(this->x(), this->y(), this->w(), this->h());
> fl_draw_box(FL_FLAT_BOX, this->x(), this->y(), this->w(), this->h(), 
> (Fl_Color)53);
>
> //....
> fl_line_style(FL_SOLID,5);
> fl_color(180,180,180);
> fl_line(this->w()/2+this->x(),this->y(),this->w()/2+this->x(),this->h()+this->y());
> fl_color(220,80,80);
> fl_line(this->x(),this->h()/2+this->y(),this->w()+this->x(),this->h()/2+this->y());
> fl_pop_clip();} {}
>   }
>   Function {handle(int e)} {open private return_type int
>   } {
>     code {int ret = Fl_Box::handle(e);
> switch(e)
>   {
>   case FL_PUSH:
>      ev_p_x=Fl::event_x(); ev_p_y=Fl::event_y();
> /*                    fl_read_image(pixRGB, ev_p_x, ev_p_y, 1, 1, 0);  
> printf("RGB: %u  %u  %u\\n",pixRGB[0],pixRGB[1],pixRGB[2]); */
>      return(1);
>   case FL_RELEASE:
>      ev_r_x=Fl::event_x(); ev_r_y=Fl::event_y();
>      return(1);
>   case FL_DRAG:
>      ev_w=Fl::event_x()-ev_p_x;
>      ev_h=Fl::event_y()-ev_p_y;
>      mybox->window()->make_current();
>      fl_overlay_rect(ev_p_x, ev_p_y, ev_w, ev_h);
>      return(1);
>   }
> return(ret);} {}
>   }
>   Function {redraw()} {return_type void
>   } {
>     code {this->draw();} {}
>   }
>   decl {public: Mydrwbox(int x,int y,int w,int h):Fl_Box(x,y,w,h) {}} {public
>   }
> }
>
> Function {} {} {
>   code {clr_ovr=0;
> cnt=0;} {}
>   Fl_Window myw {
>     xywh {454 389 520 325} type Double visible
>   } {
>     Fl_Box mybox {
>       xywh {5 5 510 165} labeltype NO_LABEL when 0
>       class Mydrwbox
>     }
>     Fl_Button quitbut {
>       label Quit
>       callback {quitbut_cb()}
>       xywh {365 280 115 25}
>     }
>     Fl_Button sv {
>       label save
>       callback {sv_cb()}
>       xywh {40 280 115 25}
>     }
>   }
> }
>
> Function {quitbut_cb()} {return_type void
> } {
>   code {exit(0);} {}
> }
>
> Function {sv_cb()} {open return_type void
> } {
>   code {int njunkb=0;
> int cnt1=0;
> unsigned char *pnt;
> unsigned char *pn2;
> unsigned char padd;
> div_t result;
>
> myw->damage(1);myw->redraw();
> mybox->damage(1); mybox->redraw();fl_overlay_clear();
>
> mybox->window()->make_current();
> mybox->damage(1); mybox->redraw();  /* 2 redraw , Double_Window (maybe 
> fl_read_image reads the buffer before) */
>
> /*printf("ev_p_x: %d   ev_p_y: %d   ev_w: %d   ev_h: %d\\n", ev_p_x, ev_p_y, 
> ev_w, ev_h);*/
>
> if (ev_w<0) { ev_p_x=ev_r_x; ev_w=ev_w*(-1); }
> if (ev_h<0) { ev_p_y=ev_r_y; ev_h=ev_h*(-1); }
> ev_w3=ev_w*3; padd=0;
>
> result = div (ev_w3,4);
> njunkb = 4 - result.rem;
> if(njunkb == 4) njunkb = 0;
>
> /*printf("ev_p_x: %d   ev_p_y: %d   ev_w: %d   ev_h: %d   njunkb: %d\\n", 
> ev_p_x, ev_p_y, ev_w, ev_h, njunkb);*/
>
> pnt = (unsigned char *) malloc ((ev_w3 * ev_h)+1);
> if (pnt == 0){printf("no enougth memory\\n"); exit(1);}
>
> fl_read_image(pnt, ev_p_x, ev_p_y, ev_w, ev_h, 0);
>
> hf_bmp.bfType='MB';
> hf_bmp.bfRes1=0; hf_bmp.bfRes2=0;
> hf_bmp.bfOffBits=54;
>
> hi_bmp.biSize=40;
> hi_bmp.biWidth=ev_w;
> hi_bmp.biHeight=ev_h;
> hi_bmp.biPlanes=1;
> hi_bmp.biBitCount=24;
> hi_bmp.biCompression=0;
> hi_bmp.biSizeImage=((ev_w * ev_h * 3) + (njunkb * ev_h));
> hi_bmp.biXPixPerMeter=0;
> hi_bmp.biYPixPerMeter=0;
> hi_bmp.biClrUsed=0;
> hi_bmp.biClrImportant=0;
>
> hf_bmp.bfSize=54 + hi_bmp.biSizeImage;
>
> if((outbmp = fopen("out.bmp","wb")) == NULL){
>   printf("Errore in apertura file di out\\n\\n"); }
>
> fwrite (&hf_bmp.bfType, 2, 1, outbmp);
> fwrite (&hf_bmp.bfSize, 4, 1, outbmp); /* printf("hf_bmp.bfSize: 
> %u\\n",hf_bmp.bfSize); */
> fwrite (&hf_bmp.bfRes1, 2, 1, outbmp);
> fwrite (&hf_bmp.bfRes2, 2, 1, outbmp);
> fwrite (&hf_bmp.bfOffBits, 4, 1, outbmp);
>
> fwrite (&hi_bmp.biSize, 4, 1, outbmp);
> fwrite (&hi_bmp.biWidth, 4, 1, outbmp);
> fwrite (&hi_bmp.biHeight, 4, 1, outbmp);
> fwrite (&hi_bmp.biPlanes, 2, 1, outbmp);
> fwrite (&hi_bmp.biBitCount, 2, 1, outbmp);
> fwrite (&hi_bmp.biCompression, 4, 1, outbmp);
> fwrite (&hi_bmp.biSizeImage, 4, 1, outbmp);
> fwrite (&hi_bmp.biXPixPerMeter, 4, 1, outbmp);
> fwrite (&hi_bmp.biYPixPerMeter, 4, 1, outbmp);
> fwrite (&hi_bmp.biClrUsed, 4, 1, outbmp);
> fwrite (&hi_bmp.biClrImportant, 4, 1, outbmp);
>
> for(cnt=1;cnt<=ev_h;cnt++)
>   {
>   pn2=pnt+(ev_w3*(ev_h-cnt));
>   for(cnt1=0;cnt1<ev_w3;cnt1=cnt1+3)
>     {
>     fwrite ((pn2+cnt1+2),1,1,outbmp);
>     fwrite ((pn2+cnt1+1),1,1,outbmp);
>     fwrite ((pn2+cnt1),1,1,outbmp);
>     }
>   for(cnt1=0;cnt1<njunkb;cnt1++)
>     fwrite (&padd, 1, 1, outbmp);
>   }
>
> free(pnt);
> fclose(outbmp);} {selected
>   }
> }
>
> *****************************************
>
> and here is bmppix.h:
> *****************************************
>
> /* bmppix.h */
> typedef struct         // 14 bytes
> {
>  unsigned short bfType;      // 2  BM
>  unsigned       bfSize;      // 4  size of the bitmap file
>  unsigned short bfRes1;      // 2  not used
>  unsigned short bfRes2;      // 2  not used
>  unsigned       bfOffBits;   // 4 number of bytes from the
>                              //   beginning of the file to
>                              //   the starting Pix Data byte
> } BMPhf;
>
> typedef struct          // 40 bytes
> {
>  unsigned       biSize;       // 4 size of the Head Info in bytes
>  unsigned       biWidth;      // 4 width in pixels
>  unsigned       biHeight;     // 4 height in pixels
>  unsigned short biPlanes;     // 2 number of planes (must set to 1)
>  unsigned short biBitCount;   // 2 bits per pixel
>                               // 1: (black/white). In 1-bit mode the color 
> table
>                               // has to contain 2 entries (usually white and 
> black).
>                               // If a bit in the image data is clear, it 
> points to
>                               // the first palette entry.
>                               // If the bit is set, it points to the second.
>                               // 4: (16 colors). In 4-bit mode the color 
> table must contain
>                               // 16 colors. Every byte in the image data 
> represents two pixels.
>                               // The byte is split into the higher 4 bits and 
> the lower 4 bits
>                               // and each value of them points to a palette 
> entry.
>                               // 8: (256 colors). In 8-bit mode every byte 
> represents a pixel.
>                               // The value points to an entry in the color 
> table which contains
>                               // 256 entries
>                               // 24: (16.7 million colors). Three bytes 
> represent one pixel.
>                               // The first byte represents the red part,
>                               // the second the green and the third the blue 
> part.
>                               // There is no need for a palette because every 
> pixel
>                               // contains a literal RGB-value, so the palette 
> is omitted.
>  unsigned      biCompression; // 4 0 for uncompressed images
>  unsigned      biSizeImage;   // 4 length of the bitmap image data in bytes
>  unsigned     biXPixPerMeter; // 4 pixels per meter (usually set to 0)
>  unsigned     biYPixPerMeter; // 4 pixels per meter (usually set to 0)
>  unsigned      biClrUsed;     // 4 number of colors
>  unsigned      biClrImportant;// 4 number of significant colors
> } BMPhi;
>
> typedef struct
> {
>  unsigned char mred;
>  unsigned char mgre;
>  unsigned char mblu;
> } mRGB;
>
> *****************************************
>
> I hope this can help You
> bye.

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to