~ubuntu-branches/ubuntu/hoary/devil/hoary

« back to all changes in this revision

Viewing changes to test/Fltk/fltk.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Marcelo E. Magallon
  • Date: 2005-01-03 19:57:42 UTC
  • Revision ID: james.westby@ubuntu.com-20050103195742-4ipkplcwygu3irv0
Tags: upstream-1.6.7
ImportĀ upstreamĀ versionĀ 1.6.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// "$Id: fltk.cpp,v 1.1 2002/01/30 23:51:19 edgomez Exp $"
 
3
//
 
4
// fl_draw_image test program for the Fast Light Tool Kit (FLTK).
 
5
//
 
6
// Be sure to try every visual with the -v switch and try -m (monochrome)
 
7
// on each of them.
 
8
//
 
9
// This program requires either the libjpeg.a library or an internal DD
 
10
// library to read images (this is chosen by the presence of the "DD"
 
11
// #define).
 
12
//
 
13
// To get the jpeg library:
 
14
//
 
15
// The "official" archive site for this software is ftp.uu.net (Internet
 
16
// address 192.48.96.9).  The most recent released version can always be
 
17
// found there in directory graphics/jpeg.  This particular version will
 
18
// be archived as graphics/jpeg/jpegsrc.v6a.tar.gz.
 
19
//
 
20
// The makefile assummes you decompressed and build these in a directory
 
21
// called "jpeg-6a" in the same location as the "FL" directory.
 
22
//
 
23
// Copyright 1998-2000 by Bill Spitzak and others.
 
24
//
 
25
// This library is free software; you can redistribute it and/or
 
26
// modify it under the terms of the GNU Library General Public
 
27
// License as published by the Free Software Foundation; either
 
28
// version 2 of the License, or (at your option) any later version.
 
29
//
 
30
// This library is distributed in the hope that it will be useful,
 
31
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
32
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
33
// Library General Public License for more details.
 
34
//
 
35
// You should have received a copy of the GNU Library General Public
 
36
// License along with this library; if not, write to the Free Software
 
37
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 
38
// USA.
 
39
//
 
40
// Please report all bugs and problems to "fltk-bugs@fltk.org".
 
41
//
 
42
 
 
43
#include <FL/Fl.H>
 
44
#include <FL/fl_draw.H>
 
45
#include <stdio.h>
 
46
#include <stdlib.h>
 
47
 
 
48
void readtheimage(const char *name); // below
 
49
int width;
 
50
int height;
 
51
int depth;
 
52
int linedelta;
 
53
uchar *ibuffer;
 
54
 
 
55
 
 
56
#pragma comment(lib, "libjpeg.lib")
 
57
 
 
58
 
 
59
////////////////////////////////////////////////////////////////
 
60
 
 
61
#include <FL/Fl_Window.H>
 
62
int mono;
 
63
 
 
64
class image_window : public Fl_Window {
 
65
  void draw();
 
66
public:
 
67
  image_window(int w,int h) : Fl_Window(w,h) {box(FL_NO_BOX);}
 
68
};
 
69
 
 
70
void image_window::draw() {
 
71
  if (mono)
 
72
    fl_draw_image_mono(ibuffer+1,0,0,width,height,depth,linedelta);
 
73
  else
 
74
    fl_draw_image(ibuffer,0,0,width,height,depth,linedelta);
 
75
}
 
76
 
 
77
////////////////////////////////////////////////////////////////
 
78
 
 
79
#include <FL/x.H>
 
80
#include "list_visuals.cxx"
 
81
 
 
82
////////////////////////////////////////////////////////////////
 
83
 
 
84
int visid = -1;
 
85
int arg(int argc, char **argv, int &i) {
 
86
  if (argv[i][1] == 'm') {mono = 1; i++; return 1;}
 
87
 
 
88
  if (argv[i][1] == 'v') {
 
89
    if (i+1 >= argc) return 0;
 
90
    visid = atoi(argv[i+1]);
 
91
    i += 2;
 
92
    return 2;
 
93
  }
 
94
 
 
95
  return 0;
 
96
}
 
97
 
 
98
int main(int argc, char ** argv) {
 
99
 
 
100
  int i = 1;
 
101
  if (!Fl::args(argc,argv,i,arg) || i != argc-1) {
 
102
    fprintf(stderr,"usage: %s <switches> image_file\n"
 
103
" -v # : use visual\n"
 
104
" -m : monochrome\n"
 
105
"%s\n",
 
106
            argv[0],Fl::help);
 
107
    exit(1);
 
108
  }
 
109
 
 
110
  readtheimage(argv[i]);
 
111
  image_window *window = new image_window(width,height);
 
112
 
 
113
  if (visid>=0) {
 
114
    /*fl_open_display();
 
115
    XVisualInfo templt; int num;
 
116
    templt.visualid = visid;
 
117
    fl_visual = XGetVisualInfo(fl_display, VisualIDMask, &templt, &num);
 
118
    if (!fl_visual) {
 
119
      fprintf(stderr, "No visual with id %d, use one of:\n",visid);
 
120
      //list_visuals();
 
121
      exit(1);
 
122
    }
 
123
    fl_colormap = XCreateColormap(fl_display, RootWindow(fl_display,fl_screen),
 
124
                                fl_visual->visual, AllocNone);
 
125
    fl_xpixel(FL_BLACK); // make sure black is allocated*/
 
126
  }
 
127
 
 
128
  window->show(argc,argv);
 
129
  return Fl::run();
 
130
}
 
131
 
 
132
////////////////////////////////////////////////////////////////
 
133
 
 
134
extern "C" {
 
135
#include "jpeglib.h"
 
136
}
 
137
 
 
138
void readtheimage(const char *name) {
 
139
  struct jpeg_decompress_struct cinfo;
 
140
  struct jpeg_error_mgr jerr;
 
141
  FILE * infile = fopen(name, "rb");
 
142
  if (!infile) {
 
143
    fprintf(stderr, "can't open %s\n", name);
 
144
    exit(1);
 
145
  }
 
146
  cinfo.err = jpeg_std_error(&jerr);
 
147
  jpeg_create_decompress(&cinfo);
 
148
  jpeg_stdio_src(&cinfo, infile);
 
149
  jpeg_read_header(&cinfo, TRUE);
 
150
  jpeg_start_decompress(&cinfo);
 
151
  width = cinfo.output_width;
 
152
  height = cinfo.output_height;
 
153
  depth = cinfo.output_components;
 
154
  ibuffer = new uchar[width*height*depth];
 
155
  uchar *rp = ibuffer;
 
156
  //  for (int i=0; i<height; i++) {
 
157
  for (int i=height; i--; ) {
 
158
    jpeg_read_scanlines(&cinfo, &rp, 1);
 
159
    rp += width*depth;
 
160
  }
 
161
  jpeg_finish_decompress(&cinfo);
 
162
  jpeg_destroy_decompress(&cinfo);
 
163
  fclose(infile);
 
164
}
 
 
b'\\ No newline at end of file'