예제 #1
1
Fl_RGB_Image *img_to_rgb(const char *file)
{
  FILE *fp;
  size_t len;
  unsigned char bytes[8];
  struct stat st;

  if (!file || stat(file, &st) == -1 || st.st_size > IMGFILE_MAX) {
    return NULL;
  }

  /* get filetype from extension */
  if (HASEXT(file, ".svg")) {
    if (st.st_size > SVG_MAX) {
      return NULL;
    }
    Fl_SVG_Image *svg = new Fl_SVG_Image(file, NULL);
    CHECK_IF_LOADED(svg)
    return svg;
  }

  if (HASEXT(file, ".svgz") || HASEXT(file, ".svg.gz")) {
    if (st.st_size > SVGZ_MAX) {
      return NULL;
    }
    Fl_SVG_Image *svg = new Fl_SVG_Image(file, NULL);
    CHECK_IF_LOADED(svg)
    return svg;
  }

  if (HASEXT(file, ".xpm")) {
    Fl_XPM_Image *xpm = new Fl_XPM_Image(file);
    CHECK_IF_LOADED(xpm)
    Fl_RGB_Image *rgb = new Fl_RGB_Image(xpm, Fl_Color(0));
    delete xpm;
    return rgb;
  }

  if (HASEXT(file, ".xbm")) {
    Fl_XBM_Image *in = new Fl_XBM_Image(file);
    CHECK_IF_LOADED(in)
    Fl_Image_Surface *surf = new Fl_Image_Surface(in->w(), in->h());
    if (!surf) {
      delete in;
      return NULL;
    }
    surf->set_current();
    fl_color(FL_WHITE);
    fl_rectf(0, 0, in->w(), in->h());
    fl_color(FL_BLACK);
    in->draw(0, 0);
    Fl_RGB_Image *rgb = surf->image();
    delete in;
    delete surf;
    return rgb;
  }

  /* get filetype from magic bytes */
  if (!(fp = fopen(file, "r"))) {
    return NULL;
  }

  len = fread(bytes, 1, sizeof(bytes), fp);
  if (ferror(fp) || len < sizeof(bytes)) {
    fclose(fp);
    return NULL;
  }

  fclose(fp);

  if (memcmp(bytes, "\211PNG\r\n\032\n", 8) == 0) {
    Fl_PNG_Image *png = new Fl_PNG_Image(file);
    CHECK_IF_LOADED(png)
    return png;
  }
예제 #2
0
 void setGUIColorScheme(int colorScheme)
 {
   double  rgamma = 1.0;
   double  ggamma = 1.0;
   double  bgamma = 1.0;
   switch (colorScheme) {
   case 1:
     {
       Fl::scheme("none");
       Fl::set_color(FL_FOREGROUND_COLOR, 0, 0, 0);
       Fl::set_color(FL_BACKGROUND2_COLOR, 255, 255, 255);
       Fl::set_color(FL_INACTIVE_COLOR, 150, 148, 144);
       Fl::set_color(FL_SELECTION_COLOR, 0, 0, 128);
       Fl::set_color(Fl_Color(1), 255, 0, 0);
       Fl::set_color(Fl_Color(2), 0, 0, 0);
       Fl::set_color(Fl_Color(3), 0, 224, 0);
       Fl::set_color(Fl_Color(6), 191, 255, 255);
       rgamma = std::log(212.0 / 255.0) / std::log(16.0 / 23.0);
       ggamma = std::log(208.0 / 255.0) / std::log(16.0 / 23.0);
       bgamma = std::log(200.0 / 255.0) / std::log(16.0 / 23.0);
     }
     break;
   case 2:
     {
       Fl::scheme("plastic");
       Fl::set_color(FL_FOREGROUND_COLOR, 0, 0, 0);
       Fl::set_color(FL_BACKGROUND2_COLOR, 255, 255, 255);
       Fl::set_color(FL_INACTIVE_COLOR, 148, 148, 148);
       Fl::set_color(FL_SELECTION_COLOR, 0, 0, 128);
       Fl::set_color(Fl_Color(1), 192, 0, 0);
       Fl::set_color(Fl_Color(2), 0, 0, 0);
       Fl::set_color(Fl_Color(3), 255, 0, 0);
       Fl::set_color(Fl_Color(6), 0, 0, 0);
       rgamma = std::log(208.0 / 255.0) / std::log(16.0 / 23.0);
       ggamma = std::log(208.0 / 255.0) / std::log(16.0 / 23.0);
       bgamma = std::log(208.0 / 255.0) / std::log(16.0 / 23.0);
     }
     break;
   case 3:
     {
       Fl::scheme("gtk+");
       Fl::set_color(FL_FOREGROUND_COLOR, 0, 0, 0);
       Fl::set_color(FL_BACKGROUND2_COLOR, 255, 255, 255);
       Fl::set_color(FL_INACTIVE_COLOR, 195, 194, 193);
       Fl::set_color(FL_SELECTION_COLOR, 169, 209, 255);
       Fl::set_color(Fl_Color(1), 255, 0, 0);
       Fl::set_color(Fl_Color(2), 0, 0, 0);
       Fl::set_color(Fl_Color(3), 0, 224, 255);
       Fl::set_color(Fl_Color(6), 191, 255, 255);
       rgamma = std::log(235.0 / 255.0) / std::log(17.0 / 23.0);
       ggamma = std::log(233.0 / 255.0) / std::log(17.0 / 23.0);
       bgamma = std::log(232.0 / 255.0) / std::log(17.0 / 23.0);
     }
     break;
   default:
     Fl::scheme("none");
     Fl::set_color(FL_FOREGROUND_COLOR, 224, 224, 224);
     Fl::set_color(FL_BACKGROUND2_COLOR, 0, 0, 0);
     Fl::set_color(FL_INACTIVE_COLOR, 184, 184, 184);
     Fl::set_color(FL_SELECTION_COLOR, 127, 218, 255);
     Fl::set_color(Fl_Color(1), 255, 0, 0);
     Fl::set_color(Fl_Color(2), 128, 255, 128);
     Fl::set_color(Fl_Color(3), 255, 255, 0);
     Fl::set_color(Fl_Color(6), 191, 255, 255);
     for (int i = 0; i < 24; i++) {
       unsigned char c = colorTable[i];
       Fl::set_color(Fl_Color(int(FL_GRAY_RAMP) + i), c, c, c);
     }
     return;
   }
   for (int i = 0; i < 24; i++) {
     int     r = int(std::pow(double(i) / 23.0, rgamma) * 255.0 + 0.5);
     int     g = int(std::pow(double(i) / 23.0, ggamma) * 255.0 + 0.5);
     int     b = int(std::pow(double(i) / 23.0, bgamma) * 255.0 + 0.5);
     Fl::set_color(Fl_Color(int(FL_GRAY_RAMP) + i),
                   (unsigned char) r, (unsigned char) g, (unsigned char) b);
   }
 }
예제 #3
0
파일: sparkline.cpp 프로젝트: qartis/dori
 void draw() {
     draw_box(FL_BORDER_BOX, 0, 0, w(), h(), Fl_Color(175));
     fl_color(FL_BLACK);
     fl_font(labelfont(), labelsize());
     fl_draw(tip, 3, 3, w()-6, h()-6, Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_WRAP));
 }