11 #include "GmshConfig.h"
13 #if defined(HAVE_FLTK)
15 #include <FL/Fl_JPEG_Image.H>
16 #include <FL/Fl_PNM_Image.H>
17 #include <FL/Fl_PNG_Image.H>
18 #include <FL/Fl_BMP_Image.H>
22 static PViewDataList *Img2Data(Fl_RGB_Image &img_init,
int quads = 1,
23 int resizex = 0,
int resizey = 0)
25 img_init.desaturate();
29 if(!resizex || !resizey)
30 img = (Fl_RGB_Image *)img_init.copy();
32 img = (Fl_RGB_Image *)img_init.copy(resizex, resizey);
34 const unsigned char *data = img->array;
35 int height = img->h();
39 if(dim != 1 && dim != 2) {
40 Msg::Error(
"Unable to obtain one-channel image");
47 for(
int i = 0; i < height - 1; i++) {
48 const unsigned char *a = data + i * width * dim;
49 const unsigned char *
a1 = data + (i + 1) * width * dim;
50 double y = height - i - 1;
51 double y1 = height - i - 2;
52 for(
int j = 0; j < width - 1; j++) {
55 double val1 = (double)a[j * dim] / 255.;
56 double val2 = (double)
a1[j * dim] / 255.;
57 double val3 = (double)
a1[(j + 1) * dim] / 255.;
58 double val4 = (double)a[(j + 1) * dim] / 255.;
72 d->
SQ.push_back(val1);
73 d->
SQ.push_back(val2);
74 d->
SQ.push_back(val3);
75 d->
SQ.push_back(val4);
88 d->
ST.push_back(val1);
89 d->
ST.push_back(val2);
90 d->
ST.push_back(val3);
101 d->
ST.push_back(val1);
102 d->
ST.push_back(val3);
103 d->
ST.push_back(val4);
112 static int EndPos(
const char *name,
PViewData *d)
115 char name_pos[256], title[256];
116 strcpy(name_pos, name);
117 strcat(name_pos,
".pos");
119 for(i = strlen(name) - 1; i >= 0; i--) {
120 if(name[i] ==
'/' || name[i] ==
'\\')
break;
125 strcpy(title, &name[i + 1]);
138 int read_pnm(
const std::string &fileName)
140 Fl_PNM_Image img(fileName.c_str());
141 return EndPos(fileName.c_str(), Img2Data(img));
144 int read_jpeg(
const std::string &fileName)
146 Fl_JPEG_Image img(fileName.c_str());
147 return EndPos(fileName.c_str(), Img2Data(img));
150 int read_png(
const std::string &fileName)
152 Fl_PNG_Image img(fileName.c_str());
153 return EndPos(fileName.c_str(), Img2Data(img));
156 int read_bmp(
const std::string &fileName)
158 Fl_BMP_Image img(fileName.c_str());
159 return EndPos(fileName.c_str(), Img2Data(img));