2
// "$Id: fltk.cpp,v 1.1 2002/01/30 23:51:19 edgomez Exp $"
4
// fl_draw_image test program for the Fast Light Tool Kit (FLTK).
6
// Be sure to try every visual with the -v switch and try -m (monochrome)
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"
13
// To get the jpeg library:
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.
20
// The makefile assummes you decompressed and build these in a directory
21
// called "jpeg-6a" in the same location as the "FL" directory.
23
// Copyright 1998-2000 by Bill Spitzak and others.
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.
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.
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
40
// Please report all bugs and problems to "fltk-bugs@fltk.org".
44
#include <FL/fl_draw.H>
48
void readtheimage(const char *name); // below
56
#pragma comment(lib, "libjpeg.lib")
59
////////////////////////////////////////////////////////////////
61
#include <FL/Fl_Window.H>
64
class image_window : public Fl_Window {
67
image_window(int w,int h) : Fl_Window(w,h) {box(FL_NO_BOX);}
70
void image_window::draw() {
72
fl_draw_image_mono(ibuffer+1,0,0,width,height,depth,linedelta);
74
fl_draw_image(ibuffer,0,0,width,height,depth,linedelta);
77
////////////////////////////////////////////////////////////////
80
#include "list_visuals.cxx"
82
////////////////////////////////////////////////////////////////
85
int arg(int argc, char **argv, int &i) {
86
if (argv[i][1] == 'm') {mono = 1; i++; return 1;}
88
if (argv[i][1] == 'v') {
89
if (i+1 >= argc) return 0;
90
visid = atoi(argv[i+1]);
98
int main(int argc, char ** argv) {
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"
110
readtheimage(argv[i]);
111
image_window *window = new image_window(width,height);
115
XVisualInfo templt; int num;
116
templt.visualid = visid;
117
fl_visual = XGetVisualInfo(fl_display, VisualIDMask, &templt, &num);
119
fprintf(stderr, "No visual with id %d, use one of:\n",visid);
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*/
128
window->show(argc,argv);
132
////////////////////////////////////////////////////////////////
138
void readtheimage(const char *name) {
139
struct jpeg_decompress_struct cinfo;
140
struct jpeg_error_mgr jerr;
141
FILE * infile = fopen(name, "rb");
143
fprintf(stderr, "can't open %s\n", name);
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];
156
// for (int i=0; i<height; i++) {
157
for (int i=height; i--; ) {
158
jpeg_read_scanlines(&cinfo, &rp, 1);
161
jpeg_finish_decompress(&cinfo);
162
jpeg_destroy_decompress(&cinfo);
b'\\ No newline at end of file'