Add Fl_BMP_Image class and docos.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1914 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Michael R Sweet 2002-01-06 17:51:12 +00:00
parent 2d6a98560e
commit e0bfbbd558
11 changed files with 425 additions and 17 deletions

View File

@ -1,5 +1,7 @@
CHANGES IN FLTK 1.1.0b9
- Add Fl_BMP_Image class to support loading of Windows
bitmap (BMP) files.
- The shiny demo didn't work on some systems (no
single-buffered OpenGL visual), and the new box types
were reset when show(argc, argv) was called.

41
FL/Fl_BMP_Image.H Normal file
View File

@ -0,0 +1,41 @@
//
// "$Id: Fl_BMP_Image.H,v 1.1.2.1 2002/01/06 17:51:12 easysw Exp $"
//
// BMP image header file for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2002 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems to "fltk-bugs@fltk.org".
//
#ifndef Fl_BMP_Image_H
#define Fl_BMP_Image_H
# include "Fl_Image.H"
class FL_EXPORT Fl_BMP_Image : public Fl_RGB_Image {
public:
Fl_BMP_Image(const char* filename);
};
#endif
//
// End of "$Id: Fl_BMP_Image.H,v 1.1.2.1 2002/01/06 17:51:12 easysw Exp $".
//

View File

@ -14,6 +14,7 @@ widgets.html
Fl.html
Fl_Adjuster.html
Fl_Bitmap.html
Fl_BMP_Image.html
Fl_Box.html
Fl_Browser_.html
Fl_Browser.html

View File

@ -13,6 +13,7 @@ description of the <TT>fl_</TT> functions, see
<A HREF="Fl.html">Fl</A><BR>
<A HREF="Fl_Adjuster.html">Fl_Adjuster</A><BR>
<A HREF="Fl_Bitmap.html">Fl_Bitmap</A><BR>
<A HREF="Fl_BMP_Image.html">Fl_BMP_Image</A><BR>
<A HREF="Fl_Box.html">Fl_Box</A><BR>
<A HREF="Fl_Browser_.html">Fl_Browser_</A><BR>
<A HREF="Fl_Browser.html">Fl_Browser</A><BR>
@ -112,6 +113,7 @@ description of the <TT>fl_</TT> functions, see
</UL>
<LI><A HREF="Fl_RGB_Image.html">Fl_RGB_Image</A><BR>
<UL>
<LI><A HREF="Fl_BMP_Image.html">Fl_BMP_Image</A><BR>
<LI><A HREF="Fl_JPEG_Image.html">Fl_JPEG_Image</A><BR>
<LI><A HREF="Fl_PNG_Image.html">Fl_PNG_Image</A><BR>
<LI><A HREF="Fl_PNM_Image.html">Fl_PNM_Image</A><BR>

View File

@ -1,5 +1,5 @@
//
// "$Id: Fluid_Image.cxx,v 1.7.2.9.2.6 2002/01/01 15:11:29 easysw Exp $"
// "$Id: Fluid_Image.cxx,v 1.7.2.9.2.7 2002/01/06 17:51:12 easysw Exp $"
//
// Pixmap label support for the Fast Light Tool Kit (FLTK).
//
@ -211,7 +211,7 @@ Fluid_Image::~Fluid_Image() {
const char *ui_find_image_name;
Fluid_Image *ui_find_image(const char *oldname) {
goto_source_dir();
const char *name = fl_file_chooser("Image?","*.{bm|gif|jpg|pbm|pgm|png|ppm|xbm|xpm}",oldname);
const char *name = fl_file_chooser("Image?","*.{bm|bmp|gif|jpg|pbm|pgm|png|ppm|xbm|xpm}",oldname);
ui_find_image_name = name;
Fluid_Image *ret = (name && *name) ? Fluid_Image::find(name) : 0;
leave_source_dir();
@ -220,5 +220,5 @@ Fluid_Image *ui_find_image(const char *oldname) {
//
// End of "$Id: Fluid_Image.cxx,v 1.7.2.9.2.6 2002/01/01 15:11:29 easysw Exp $".
// End of "$Id: Fluid_Image.cxx,v 1.7.2.9.2.7 2002/01/06 17:51:12 easysw Exp $".
//

353
src/Fl_BMP_Image.cxx Normal file
View File

@ -0,0 +1,353 @@
//
// "$Id: Fl_BMP_Image.cxx,v 1.1.2.1 2002/01/06 17:51:12 easysw Exp $"
//
// Fl_BMP_Image routines.
//
// Copyright 1997-2002 by Easy Software Products.
// Image support donated by Matthias Melcher, Copyright 2000.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems to "fltk-bugs@fltk.org".
//
// Contents:
//
// Fl_BMP_Image::Fl_BMP_Image() - Load a BMP image file.
//
//
// Include necessary header files...
//
#include <FL/Fl_BMP_Image.H>
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
//
// BMP definitions...
//
#ifndef BI_RGB
# define BI_RGB 0 // No compression - straight BGR data
# define BI_RLE8 1 // 8-bit run-length compression
# define BI_RLE4 2 // 4-bit run-length compression
# define BI_BITFIELDS 3 // RGB bitmap with RGB masks
#endif // !BI_RGB
//
// Local functions...
//
static int read_long(FILE *fp);
static unsigned short read_word(FILE *fp);
static unsigned int read_dword(FILE *fp);
//
// 'Fl_BMP_Image::Fl_BMP_Image()' - Load a BMP image file.
//
Fl_BMP_Image::Fl_BMP_Image(const char *bmp) // I - File to read
: Fl_RGB_Image(0,0,0) {
FILE *fp; // File pointer
int info_size, // Size of info header
depth, // Depth of image (bits)
compression, // Type of compression
colors_used, // Number of colors used
x, y, // Looping vars
color, // Color of RLE pixel
count, // Number of times to repeat
temp, // Temporary color
align; // Alignment bytes
uchar bit, // Bit in image
byte; // Byte in image
uchar *ptr; // Pointer into pixels
uchar colormap[256][4];// Colormap
// Open the file...
if ((fp = fopen(bmp, "rb")) == NULL) return;
// Get the header...
getc(fp); // Skip "BM" sync chars
getc(fp);
read_dword(fp); // Skip size
read_word(fp); // Skip reserved stuff
read_word(fp);
read_dword(fp);
// Then the bitmap information...
info_size = read_dword(fp);
w(read_long(fp));
h(read_long(fp));
read_word(fp);
depth = read_word(fp);
compression = read_dword(fp);
read_dword(fp);
read_long(fp);
read_long(fp);
colors_used = read_dword(fp);
read_dword(fp);
if (info_size > 40)
for (info_size -= 40; info_size > 0; info_size --)
getc(fp);
// Get colormap...
if (colors_used == 0 && depth <= 8)
colors_used = 1 << depth;
fread(colormap, colors_used, 4, fp);
// Setup image and buffers...
d(3);
array = new uchar[w() * h() * d()];
// Read the image data...
color = 0;
count = 0;
align = 0;
byte = 0;
temp = 0;
for (y = h() - 1; y >= 0; y --) {
ptr = (uchar *)array + y * w() * d();
switch (depth)
{
case 1 : // Bitmap
for (x = w(), bit = 128; x > 0; x --) {
if (bit == 128) byte = getc(fp);
if (byte & bit) {
*ptr++ = colormap[1][2];
*ptr++ = colormap[1][1];
*ptr++ = colormap[1][0];
} else {
*ptr++ = colormap[0][2];
*ptr++ = colormap[0][1];
*ptr++ = colormap[0][0];
}
if (bit > 1)
bit >>= 1;
else
bit = 128;
}
// Read remaining bytes to align to 32 bits...
for (temp = (w() + 7) / 8; temp & 3; temp ++) {
getc(fp);
}
break;
case 4 : // 16-color
for (x = w(), bit = 0xf0; x > 0; x --) {
// Get a new count as needed...
if (compression != BI_RLE4 && count == 0) {
count = 2;
color = -1;
}
if (count == 0) {
while (align > 0) {
align --;
getc(fp);
}
if ((count = getc(fp)) == 0) {
if ((count = getc(fp)) == 0) {
// End of line...
x ++;
continue;
} else if (count == 1) {
// End of image...
break;
} else if (count == 2) {
// Delta...
count = getc(fp) * getc(fp) * w();
color = 0;
} else {
// Absolute...
color = -1;
align = ((4 - (count & 3)) / 2) & 1;
}
} else {
color = getc(fp);
}
}
// Get a new color as needed...
count --;
if (bit == 0xf0) {
if (color < 0) temp = getc(fp);
else temp = color;
// Copy the color value...
*ptr++ = colormap[temp >> 4][2];
*ptr++ = colormap[temp >> 4][1];
*ptr++ = colormap[temp >> 4][0];
bit = 0x0f;
} else {
// Copy the color value...
*ptr++ = colormap[temp & 15][2];
*ptr++ = colormap[temp & 15][1];
*ptr++ = colormap[temp & 15][0];
bit = 0xf0;
}
}
if (!compression) {
// Read remaining bytes to align to 32 bits...
for (temp = (w() + 1) / 2; temp & 3; temp ++) {
getc(fp);
}
}
break;
case 8 : // 256-color
for (x = w(); x > 0; x --) {
// Get a new count as needed...
if (compression != BI_RLE8) {
count = 1;
color = -1;
}
if (count == 0) {
while (align > 0) {
align --;
getc(fp);
}
if ((count = getc(fp)) == 0) {
if ((count = getc(fp)) == 0) {
// End of line...
x ++;
continue;
} else if (count == 1) {
// End of image...
break;
} else if (count == 2) {
// Delta...
count = getc(fp) * getc(fp) * w();
color = 0;
} else {
// Absolute...
color = -1;
align = (2 - (count & 1)) & 1;
}
} else {
color = getc(fp);
}
}
// Get a new color as needed...
if (color < 0) temp = getc(fp);
else temp = color;
count --;
// Copy the color value...
*ptr++ = colormap[temp][2];
*ptr++ = colormap[temp][1];
*ptr++ = colormap[temp][0];
}
if (!compression) {
// Read remaining bytes to align to 32 bits...
for (temp = w(); temp & 3; temp ++) {
getc(fp);
}
}
break;
case 24 : // 24-bit RGB
for (x = w(); x > 0; x --, ptr += 3) {
ptr[2] = getc(fp);
ptr[1] = getc(fp);
ptr[0] = getc(fp);
}
// Read remaining bytes to align to 32 bits...
for (temp = w() * 3; temp & 3; temp ++) {
getc(fp);
}
break;
}
}
// Close the file and return...
fclose(fp);
}
//
// 'read_word()' - Read a 16-bit unsigned integer.
//
static unsigned short // O - 16-bit unsigned integer
read_word(FILE *fp) { // I - File to read from
unsigned char b0, b1; // Bytes from file
b0 = getc(fp);
b1 = getc(fp);
return ((b1 << 8) | b0);
}
//
// 'read_dword()' - Read a 32-bit unsigned integer.
//
static unsigned int // O - 32-bit unsigned integer
read_dword(FILE *fp) { // I - File to read from
unsigned char b0, b1, b2, b3; // Bytes from file
b0 = getc(fp);
b1 = getc(fp);
b2 = getc(fp);
b3 = getc(fp);
return ((((((b3 << 8) | b2) << 8) | b1) << 8) | b0);
}
//
// 'read_long()' - Read a 32-bit signed integer.
//
static int // O - 32-bit signed integer
read_long(FILE *fp) { // I - File to read from
unsigned char b0, b1, b2, b3; // Bytes from file
b0 = getc(fp);
b1 = getc(fp);
b2 = getc(fp);
b3 = getc(fp);
return ((int)(((((b3 << 8) | b2) << 8) | b1) << 8) | b0);
}
//
// End of "$Id: Fl_BMP_Image.cxx,v 1.1.2.1 2002/01/06 17:51:12 easysw Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_File_Icon2.cxx,v 1.1.2.11 2002/01/02 13:49:38 easysw Exp $"
// "$Id: Fl_File_Icon2.cxx,v 1.1.2.12 2002/01/06 17:51:12 easysw Exp $"
//
// Fl_File_Icon system icon routines.
//
@ -733,7 +733,7 @@ Fl_File_Icon::load_system_icons(void)
{
// Create the default icons...
new Fl_File_Icon("*", Fl_File_Icon::PLAIN, sizeof(plain) / sizeof(plain[0]), plain);
new Fl_File_Icon("*.{bmp|bw|gif|jpg|pbm|pcd|pgm|ppm|png|ras|rgb|tif|xbm|xpm}", Fl_File_Icon::PLAIN,
new Fl_File_Icon("*.{bm|bmp|bw|gif|jpg|pbm|pcd|pgm|ppm|png|ras|rgb|tif|xbm|xpm}", Fl_File_Icon::PLAIN,
sizeof(image) / sizeof(image[0]), image);
new Fl_File_Icon("*", Fl_File_Icon::DIRECTORY, sizeof(dir) / sizeof(dir[0]), dir);
}
@ -931,5 +931,5 @@ get_kde_val(char *str,
//
// End of "$Id: Fl_File_Icon2.cxx,v 1.1.2.11 2002/01/02 13:49:38 easysw Exp $".
// End of "$Id: Fl_File_Icon2.cxx,v 1.1.2.12 2002/01/06 17:51:12 easysw Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Shared_Image.cxx,v 1.23.2.6 2002/01/01 15:11:31 easysw Exp $"
// "$Id: Fl_Shared_Image.cxx,v 1.23.2.7 2002/01/06 17:51:12 easysw Exp $"
//
// Shared image code for the Fast Light Tool Kit (FLTK).
//
@ -29,6 +29,7 @@
#include <FL/Fl.H>
#include <FL/Fl_Shared_Image.H>
#include <FL/Fl_BMP_Image.H>
#include <FL/Fl_GIF_Image.H>
#include <FL/Fl_JPEG_Image.H>
#include <FL/Fl_PNG_Image.H>
@ -225,6 +226,8 @@ Fl_Shared_Image::reload() {
else if (memcmp(header, "\377\330\377", 3) == 0 && // Start-of-Image
header[3] >= 0xe0 && header[3] <= 0xef) // APPn
img = new Fl_JPEG_Image(name_);
else if (memcmp(header, "BM", 2) == 0) // BMP file
img = new Fl_BMP_Image(name_);
else if (header[0] == 'P' && header[1] >= '1' && header[1] <= '6') // Portable anymap
img = new Fl_PNM_Image(name_);
else if (memcmp(header, "#define", 7) == 0) // XBM file
@ -382,5 +385,5 @@ Fl_Shared_Image::get(const char *n, int W, int H) {
//
// End of "$Id: Fl_Shared_Image.cxx,v 1.23.2.6 2002/01/01 15:11:31 easysw Exp $".
// End of "$Id: Fl_Shared_Image.cxx,v 1.23.2.7 2002/01/06 17:51:12 easysw Exp $".
//

View File

@ -1,5 +1,5 @@
#
# "$Id: Makefile,v 1.18.2.14.2.29 2002/01/06 13:40:32 easysw Exp $"
# "$Id: Makefile,v 1.18.2.14.2.30 2002/01/06 17:51:12 easysw Exp $"
#
# Library makefile for the Fast Light Tool Kit (FLTK).
#
@ -27,6 +27,7 @@ CPPFILES = \
Fl.cxx \
Fl_Adjuster.cxx \
Fl_Bitmap.cxx \
Fl_BMP_Image.cxx \
Fl_Browser.cxx \
Fl_Browser_.cxx \
Fl_Browser_load.cxx \
@ -350,5 +351,5 @@ uninstall:
#
# End of "$Id: Makefile,v 1.18.2.14.2.29 2002/01/06 13:40:32 easysw Exp $".
# End of "$Id: Makefile,v 1.18.2.14.2.30 2002/01/06 17:51:12 easysw Exp $".
#

View File

@ -11,6 +11,9 @@ Fl_Bitmap.o: ../FL/Fl.H ../FL/Enumerations.H ../FL/Fl_Export.H ../FL/x.H
Fl_Bitmap.o: ../FL/Fl_Window.H ../FL/fl_draw.H ../FL/Fl_Widget.H
Fl_Bitmap.o: ../FL/Fl_Menu_Item.H ../FL/Fl_Widget.H ../FL/Fl_Bitmap.H
Fl_Bitmap.o: ../FL/Fl_Image.H ../FL/x.H
Fl_BMP_Image.o: ../FL/Fl_BMP_Image.H ../FL/Fl_Image.H ../FL/x.H
Fl_BMP_Image.o: ../FL/Enumerations.H ../FL/Fl_Export.H ../FL/Fl_Window.H
Fl_BMP_Image.o: ../config.h
Fl_Browser.o: ../FL/Fl.H ../FL/Enumerations.H ../FL/Fl_Export.H
Fl_Browser.o: ../FL/Fl_Browser.H ../FL/Fl_Browser_.H ../FL/Fl_Group.H
Fl_Browser.o: ../FL/Fl_Widget.H ../FL/Fl_Scrollbar.H ../FL/Fl_Slider.H
@ -88,8 +91,8 @@ Fl_File_Chooser2.o: ../FL/Fl_Window.H flstring.h ../config.h
Fl_File_Icon.o: ../config.h ../FL/Fl_File_Icon.H ../FL/Fl.H
Fl_File_Icon.o: ../FL/Enumerations.H ../FL/Fl_Export.H ../FL/Fl_Widget.H
Fl_File_Icon.o: ../FL/fl_draw.H ../FL/filename.H
Fl_File_Icon2.o: flstring.h ../config.h ../FL/Fl_File_Icon.H ../FL/Fl.H
Fl_File_Icon2.o: ../FL/Enumerations.H ../FL/Fl_Export.H
Fl_File_Icon2.o: flstring.h ../config.h ../FL/math.h ../FL/Fl_File_Icon.H
Fl_File_Icon2.o: ../FL/Fl.H ../FL/Enumerations.H ../FL/Fl_Export.H
Fl_File_Icon2.o: ../FL/Fl_Shared_Image.H ../FL/Fl_Image.H ../FL/x.H
Fl_File_Icon2.o: ../FL/Fl_Window.H ../FL/Fl_Widget.H ../FL/fl_draw.H
Fl_File_Icon2.o: ../FL/filename.H
@ -111,7 +114,8 @@ Fl_Help_View.o: ../FL/Fl_Help_View.H ../FL/Fl.H ../FL/Enumerations.H
Fl_Help_View.o: ../FL/Fl_Export.H ../FL/Fl_Group.H ../FL/Fl_Widget.H
Fl_Help_View.o: ../FL/Fl_Scrollbar.H ../FL/Fl_Slider.H ../FL/Fl_Valuator.H
Fl_Help_View.o: ../FL/fl_draw.H ../FL/Fl_Shared_Image.H ../FL/Fl_Image.H
Fl_Help_View.o: ../FL/x.H ../FL/Fl_Window.H flstring.h ../config.h
Fl_Help_View.o: ../FL/x.H ../FL/Fl_Window.H ../FL/Fl_Pixmap.H flstring.h
Fl_Help_View.o: ../config.h
Fl_Image.o: ../FL/Fl.H ../FL/Enumerations.H ../FL/Fl_Export.H ../FL/fl_draw.H
Fl_Image.o: ../FL/x.H ../FL/Fl_Window.H ../FL/Fl_Widget.H
Fl_Image.o: ../FL/Fl_Menu_Item.H ../FL/Fl_Widget.H ../FL/Fl_Image.H ../FL/x.H
@ -192,7 +196,8 @@ Fl_Scrollbar.o: ../FL/Fl_Scrollbar.H ../FL/Fl_Slider.H ../FL/Fl_Valuator.H
Fl_Scrollbar.o: ../FL/Fl_Widget.H ../FL/fl_draw.H
Fl_Shared_Image.o: ../FL/Fl.H ../FL/Enumerations.H ../FL/Fl_Export.H
Fl_Shared_Image.o: ../FL/Fl_Shared_Image.H ../FL/Fl_Image.H ../FL/x.H
Fl_Shared_Image.o: ../FL/Fl_Window.H ../FL/Fl_GIF_Image.H ../FL/Fl_Pixmap.H
Fl_Shared_Image.o: ../FL/Fl_Window.H ../FL/Fl_BMP_Image.H
Fl_Shared_Image.o: ../FL/Fl_GIF_Image.H ../FL/Fl_Pixmap.H
Fl_Shared_Image.o: ../FL/Fl_JPEG_Image.H ../FL/Fl_PNG_Image.H
Fl_Shared_Image.o: ../FL/Fl_PNM_Image.H ../FL/Fl_XBM_Image.H
Fl_Shared_Image.o: ../FL/Fl_Bitmap.H ../FL/Fl_XPM_Image.H

View File

@ -1,5 +1,5 @@
//
// "$Id: pixmap_browser.cxx,v 1.5.2.4.2.4 2002/01/01 15:11:33 easysw Exp $"
// "$Id: pixmap_browser.cxx,v 1.5.2.4.2.5 2002/01/06 17:51:12 easysw Exp $"
//
// A shared image test program for the Fast Light Tool Kit (FLTK).
//
@ -67,7 +67,7 @@ void file_cb(const char *n) {
void button_cb(Fl_Widget *,void *) {
fl_file_chooser_callback(file_cb);
fl_file_chooser("Image file?","*.{gif,jpg,pbm,pgm,png,ppm,xbm,xpm}", name);
fl_file_chooser("Image file?","*.{bm,bmp,gif,jpg,pbm,pgm,png,ppm,xbm,xpm}", name);
fl_file_chooser_callback(0);
}
@ -94,5 +94,5 @@ int main(int argc, char **argv) {
}
//
// End of "$Id: pixmap_browser.cxx,v 1.5.2.4.2.4 2002/01/01 15:11:33 easysw Exp $".
// End of "$Id: pixmap_browser.cxx,v 1.5.2.4.2.5 2002/01/06 17:51:12 easysw Exp $".
//