dove@UCBVAX.BERKELEY.EDU (Webster Dove) (10/03/88)
InterViews caused g++-1.25.0 to core dump. It seems to generate spurious
error messages on g++-1.27.0.
Has anyone out there gotten it compiled with anything more recent than
1.22.2?
Could InterViews be used by the developers as an additional test suite
beyond what is in libg++-1.25.0?
With g++-1.27.0 compiling InterViews-2.3/src/lib/bitmap.c I get the
following errors. (The code is at the end of the message.)
---------
g++ -c -I.. -DX11 -O -finline-functions ../bitmap.c
use .cc filename extension!
In function struct Bitmap *Bitmap::Bitmap (short int *, int, int):
../bitmap.c:37: too few arguments for constructor `Bitmap'
../bitmap.c:37: no default constructor defined for type `Bitmap'
In function struct Bitmap *Bitmap::Bitmap (struct Bitmap *):
../bitmap.c:48: too few arguments for constructor `Bitmap'
../bitmap.c:48: no default constructor defined for type `Bitmap'
In function struct Bitmap *Bitmap::Bitmap (const char *):
../bitmap.c:292: too few arguments for constructor `Bitmap'
../bitmap.c:292: no default constructor defined for type `Bitmap'
*** Error code 1
----- bitmap.h
/*
* Bitmap - Bit map for InterViews
*/
#ifndef bitmap_h
#define bitmap_h
#include <InterViews/defs.h>
#include <InterViews/resource.h>
class Canvas;
class Color;
class Font;
class Transformer;
class Bitmap : public Resource {
void * bitmap;
void * pixmap;
short * data;
int width;
int height;
Coord x0;
Coord y0;
Color * foreground;
Color * background;
void Init();
void FreeMaps();
int Index( int x, int y ) { return (width+15)/16 * (height-y-1) + x/16; }
short Bit( int x, int ) { return 1 << ( x%16 ); }
boolean Valid( int x, int y ) {
return ! (x < 0 || x >= width || y < 0 || y >= height);
}
public:
Bitmap(const char * filename); // bitmap(1) file
Bitmap(short *, int width, int height); // raw data
Bitmap(Bitmap *); // copy
~Bitmap();
void Draw(Canvas *);
int Width();
int Height();
void SetColors(Color * f, Color * b);
Color * GetFgColor();
Color * GetBgColor();
void Transform(Transformer *);
void Scale(float x, float y);
void Rotate(float);
void SetOrigin(int x0, int y0);
void GetOrigin(int& x0, int& y0);
void FlipHorizontal();
void FlipVertical();
void Rotate90();
void Invert();
boolean Peek(int x, int y);
void Poke(boolean bit, int x, int y);
};
#endif
--------- bitmap.c
/*
* Bitmap - Bit map for InterViews
*/
#include <InterViews/bitmap.h>
#include <InterViews/transformer.h>
#include <InterViews/Xwindow.h>
#include <InterViews/Xoutput.h>
#include <InterViews/paint.h>
#include <InterViews/canvas.h>
extern void bcopy( void * src, void * dst, int count );
extern void bzero( void * dst, int count );
#ifdef X10
# define DoFreePixmap(p) XFreePixmap(p)
#endif
#ifdef X11
# define DoFreePixmap(p) XFreePixmap(_World_dpy, p)
# define BitmapSize(w, h) \
((w)*(h)*XBitmapUnit(_World_dpy) + XBitmapPad(_World_dpy) - 1) >> 3
#endif
Bitmap::Bitmap( short * d, int w, int h ) {
Init();
width = w;
height = h;
int size = BitmapSize( w, h );
data = new short[ size/2 ];
if ( d != nil ) {
bcopy( d, data, size );
} else {
bzero( data, size );
}
}
Bitmap::Bitmap( Bitmap * b ) {
Init();
width = b->width;
height = b->height;
if ( b->data != nil ) {
int size = BitmapSize(width,height);
data = new short[ size/2 ];
bcopy( b->data, data, size );
}
}
void Bitmap::Init() {
x0 = 0;
y0 = 0;
width = 0;
height = 0;
data = nil;
bitmap = nil;
pixmap = nil;
foreground = black;
background = white;
}
Bitmap::~Bitmap() {
FreeMaps();
delete data;
}
int Bitmap::Width() { return width; }
int Bitmap::Height() { return height; }
void Bitmap::SetColors(Color * fg, Color * bg ) {
if ( fg != foreground ) {
if ( pixmap != nil ) {
DoFreePixmap(pixmap);
pixmap = nil;
}
foreground = fg;
}
if ( bg != background ) {
if ( pixmap != nil ) {
DoFreePixmap(pixmap);
pixmap = nil;
}
background = bg;
}
}
Color * Bitmap::GetFgColor() {
return foreground;
}
Color * Bitmap::GetBgColor() {
return background;
}
void Bitmap::Transform(Transformer * t) {
int x1 = 0, y1 = 0;
int x2 = 0, y2 = height-1;
int x3 = width-1, y3 = height-1;
int x4 = width-1, y4 = 0;
t->Transform( x1, y1 );
t->Transform( x2, y2 );
t->Transform( x3, y3 );
t->Transform( x4, y4 );
t->Invert();
int xmax = max(x1,max(x2,max(x3,x4)));
int xmin = min(x1,min(x2,min(x3,x4)));
int ymax = max(y1,max(y2,max(y3,y4)));
int ymin = min(y1,min(y2,min(y3,y4)));
Bitmap * b = new Bitmap( nil, xmax-xmin+1, ymax-ymin+1 );
for ( int x = xmin; x <= xmax; ++x ) {
for ( int y = ymin; y <= ymax; ++y ) {
int xx = x;
int yy = y;
t->Transform( xx, yy );
b->Poke( Peek(xx,yy), x-xmin, y-ymin );
}
}
delete data;
data = b->data;
width = b->width;
height = b->height;
b->data = nil;
delete b;
FreeMaps();
}
void Bitmap::Scale(float sx, float sy) {
Transformer * t = new Transformer;
t->Scale(sx,sy);
Transform(t);
delete t;
}
void Bitmap::Rotate(float angle) {
Transformer * t = new Transformer;
t->Rotate(angle);
Transform(t);
delete t;
}
void Bitmap::SetOrigin(int x, int y) {
x0 = x;
y0 = y;
}
void Bitmap::GetOrigin(int &x, int &y ) {
x = x0;
y = y0;
}
void Bitmap::FlipHorizontal() {
for ( int x = 0; x < width/2; ++x ) {
for ( int y = 0; y < height; ++y ) {
boolean bit = Peek( x, y );
Poke( Peek( width-x-1, y ), x, y );
Poke( bit, width-x-1, y );
}
}
FreeMaps();
}
void Bitmap::FlipVertical() {
for ( int x = 0; x < width; ++x ) {
for ( int y = 0; y < height/2; ++y ) {
boolean bit = Peek( x, y );
Poke( Peek( x, height-y-1 ), x, y );
Poke( bit, x, height-y-1 );
}
}
FreeMaps();
}
void Bitmap::Invert() {
for ( int x = 0; x < width; ++x ) {
for ( int y = 0; y < height; ++y ) {
Poke( !Peek(x,y), x, y );
}
}
FreeMaps();
}
void Bitmap::Rotate90() {
Bitmap * b = new Bitmap( nil, height, width );
for ( int x = 0; x < width; ++x ) {
for ( int y = 0; y < height; ++y ) {
b->Poke( Peek(x,y), width-y-1, x );
}
}
delete data;
data = b->data;
b->data = nil;
width = b->width;
height = b->height;
delete b;
FreeMaps();
}
boolean Bitmap::Peek( int x, int y ) {
if ( Valid(x,y) ) {
return (data[Index(x,y)] & Bit(x,y)) != 0;
} else {
return false;
}
}
void Bitmap::Poke( boolean bit, int x, int y ) {
if ( Valid(x,y) ) {
if ( bit ) {
data[Index(x,y)] |= Bit(x,y);
} else {
data[Index(x,y)] &= ~Bit(x,y);
}
}
}
#ifdef X10
extern int XReadBitmapFile(
const char * filename,
int& width, int& height, short*& data,
int *x_hot, int *y_hot
);
Bitmap::Bitmap( const char * filename ) {
Init();
XReadBitmapFile(filename, width, height, data, nil, nil);
}
void Bitmap::FreeMaps() {
if ( bitmap != nil ) {
XFreeBitmap( bitmap );
bitmap = nil;
}
if ( pixmap != nil ) {
DoFreePixmap( pixmap );
pixmap = nil;
}
}
void Bitmap::Draw( Canvas * c ) {
if ( bitmap == nil && data != nil ) {
bitmap = XStoreBitmap( width, height, data );
}
if ( pixmap == nil && bitmap != nil ) {
pixmap = XMakePixmap( bitmap,
foreground->PixelValue(), background->PixelValue()
);
}
int xx = x0 - c->left;
int yy = (c->height - 1) - (height - 1) - (y0 - c->bottom);
if ( pixmap != nil ) {
XPixmapPut(c->id,
0, 0, xx, yy, width, height,
pixmap, GXcopy, AllPlanes
);
} else {
XPixSet(c->id, xx, yy, width, height, background->PixelValue());
if ( bitmap != nil ) {
XPixFill(c->id,
xx, yy, width, height, foreground->PixelValue(),
bitmap, GXcopy, AllPlanes
);
}
}
}
#endif
#ifdef X11
extern int XReadBitmapFile(
XDisplay *, XDrawable, const char *,
int& width, int& height, XPixmap&,
int * x_hot, int * y_hot
);
extern XPixmap XCreateBitmapFromData(
XDisplay*, XDrawable, void *, int, int
);
Bitmap::Bitmap( const char * filename ) {
Init();
XReadBitmapFile(
_World_dpy, _World_root, filename, width, height, pixmap, nil, nil
);
}
void Bitmap::FreeMaps() {
if ( pixmap != nil ) {
DoFreePixmap( pixmap );
pixmap = nil;
}
}
void Bitmap::Draw( Canvas * c ) {
if ( pixmap == nil && data != nil ) {
pixmap = XCreateBitmapFromData(
_World_dpy, _World_root, data, width, height
);
}
if ( pixmap != nil ) {
int xx = x0;
int yy = (c->height - 1) - (height - 1) - y0;
Xgc gc = XCreateGC(_World_dpy, _World_root, 0, nil);
XSetForeground(_World_dpy, gc, foreground->PixelValue());
XSetBackground(_World_dpy, gc, background->PixelValue());
XCopyArea(
_World_dpy, pixmap, c->id, gc, 0, 0, width, height, xx, yy
);
c->WaitForCopy();
}
}
#endifekrell@ulysses.att.com (10/03/88)
if you read a message I sent a while ago, you'll find the changes that
are needed to compile InterViews 2.3 with g++ 1.25. The ones to bitmap.c
are:
*** old/bitmap.c Mon Sep 5 17:58:25 1988
--- bitmap.c Thu Sep 15 13:51:28 1988
***************
*** 11,17 ****
return (x >= 0 && x < width && y >= 0 && y < height);
}
! Bitmap::Bitmap (void* d, int w, int h) {
Init();
width = w;
height = h;
--- 11,17 ----
return (x >= 0 && x < width && y >= 0 && y < height);
}
! Bitmap::Bitmap (void* d, int w, int h) : () {
Init();
width = w;
height = h;
***************
*** 24,30 ****
}
}
! Bitmap::Bitmap (Bitmap* b) {
Init();
width = b->width;
height = b->height;
--- 24,30 ----
}
}
! Bitmap::Bitmap (Bitmap* b) : () {
Init();
width = b->width;
height = b->height;