-static void paintown_draw_sprite_ex16( BITMAP * dst, BITMAP * src, int dx, int dy, int mode, int flip );
-static void paintown_light16(BITMAP * dst, const int x, const int y, const int width, const int height, const int start_y, const int focus_alpha, const int edge_alpha, const int focus_color, const int edge_color);
-static void paintown_applyTrans16(BITMAP * dst, const int color);
-
-const int Bitmap::MaskColor = MASK_COLOR_16;
-
-const int Bitmap::MODE_TRANS = 0;
-const int Bitmap::MODE_SOLID = 1;
-
-const int Bitmap::SPRITE_NO_FLIP = 0;
-const int Bitmap::SPRITE_V_FLIP = 1;
-const int Bitmap::SPRITE_H_FLIP = 2;
-
-const int Bitmap::SPRITE_NORMAL = 1;
-const int Bitmap::SPRITE_LIT = 2;
-const int Bitmap::SPRITE_TRANS = 3;
-
-Bitmap * Bitmap::Screen = NULL;
-Bitmap * Scaler = NULL;
-Bitmap * Buffer = NULL;
-
-Bitmap::Bitmap():
-own( NULL ),
-error( false ){
- setBitmap( create_bitmap( 10, 10 ) );
- if ( ! getBitmap() ){
- error = true;
- cerr << "Could not create bitmap!" << endl;
- } else {
- clear();
- own = new int;
- *own = 1;
- }
-}
-
-Bitmap::Bitmap( int x, int y ):
-own( NULL ),
-error( false ){
- if ( x < 1 ){
- x = 1;
- }
- if ( y < 1 ){
- y = 1;
- }
- setBitmap( create_bitmap( x, y ) );
- if ( ! getBitmap() ){
- error = true;
- cerr << "Could not create bitmap!" << endl;
- } else {
- clear();
- own = new int;
- *own = 1;
- }
-}
-
-/* If a BITMAP is given to us, we didn't make it so we don't own it */
-void Bitmap::ellipse( int x, int y, int rx, int ry, int color ) const {
- ::ellipse( getBitmap(), x, y, rx, ry, color );
-}
-
-void Bitmap::ellipseFill( int x, int y, int rx, int ry, int color ) const {
- ::ellipsefill( getBitmap(), x, y, rx, ry, color );
-}
-
-void Bitmap::rectangle( int x1, int y1, int x2, int y2, int color ) const{
- ::rect( getBitmap(), x1, y1, x2, y2, color );
-}
-
-void Bitmap::border( int min, int max, int color ) const {
- int w = getWidth();
- int h = getHeight();
- for ( int i = min; i < max; i++ ){
- rectangle( i, i, w - 1 - i, h - 1 - i, color );
- }
-}
-
-void Bitmap::rectangleFill( int x1, int y1, int x2, int y2, int color ) const{
- ::rectfill( getBitmap(), x1, y1, x2, y2, color );
-}
-
-/*
-int Bitmap::getPixel( int x, int y ){
- if ( x >= 0 && x < my_bitmap->w && y >= 0 && y <= my_bitmap->h )
- return _getpixel16( my_bitmap, x, y );
- return -1;
-}
-*/
-
-/*
-int Bitmap::makeColor( int r, int g, int b ){
- return makecol16( r, g, b );
-}
-*/
-
-void Bitmap::hLine( const int x1, const int y, const int x2, const int color ) const{
- ::hline( getBitmap(), x1, y, x2, color );
-}
-
-void Bitmap::horizontalLine( const int x1, const int y, const int x2, const int color ) const{
- this->hLine( x1, y, x2, color );
-}
-
-void Bitmap::vLine( const int y1, const int x, const int y2, const int color ) const{
- ::vline( getBitmap(), x, y1, y2, color );
-}
-
-void Bitmap::polygon( const int * verts, const int nverts, const int color ) const{
- ::polygon( getBitmap(), nverts, verts, color );
-}
-
-void Bitmap::arc(const int x, const int y, const double ang1, const double ang2, const int radius, const int color ) const{
- ::arc( getBitmap(), x, y, ::ftofix(ang1), ::ftofix(ang2), radius, color );
-}
-
-/*
-void Bitmap::clear(){
- this->fill( 0 );
-}
-*/
-
-void Bitmap::fill( int color ) const{
- ::clear_to_color( getBitmap(), color );
-}
-
-void Bitmap::draw( const int x, const int y, const Bitmap & where ) const {
- paintown_draw_sprite_ex16( where.getBitmap(), getBitmap(), x, y, Bitmap::SPRITE_NORMAL, Bitmap::SPRITE_NO_FLIP );
- // ::draw_sprite( where.getBitmap(), getBitmap(), x, y );
-}
-
-void Bitmap::draw(const int x, const int y, const int startWidth, const int startHeight, const int width, const int height, const Bitmap & where) const {
- sub.draw(x + startWidth, y + startHeight, where);
-}
-
-void Bitmap::drawHFlip( const int x, const int y, const Bitmap & where ) const {
- paintown_draw_sprite_ex16( where.getBitmap(), getBitmap(), x, y, Bitmap::SPRITE_NORMAL, Bitmap::SPRITE_H_FLIP );
- // ::draw_sprite_h_flip( where.getBitmap(), getBitmap(), x, y );
-}
-
-void Bitmap::drawHFlip(const int x, const int y, const int startWidth, const int startHeight, const int width, const int height, const Bitmap & where) const {
-void Bitmap::Stretch( const Bitmap & where, const int sourceX, const int sourceY, const int sourceWidth, const int sourceHeight, const int destX, const int destY, const int destWidth, const int destHeight ) const {
-/* defined at allegro/include/internal/aintern.h:466 */
-extern EXTERNAL_VARIABLE int _blender_col_16;
-/* defined at allegro/include/internal/aintern.h:470 */
-extern EXTERNAL_VARIABLE int _blender_alpha;
-
-static void paintown_draw_sprite_ex16( BITMAP * dst, BITMAP * src, int dx, int dy, int mode, int flip ){
- int x, y, w, h;
- int x_dir = 1, y_dir = 1;
- int dxbeg, dybeg;
- int sxbeg, sybeg;
- PAINTOWN_DLS_BLENDER lit_blender;
- PAINTOWN_DTS_BLENDER trans_blender;
-
- ASSERT(dst);
- ASSERT(src);
-
- if ( flip & Bitmap::SPRITE_V_FLIP ){
- y_dir = -1;
- }
- if ( flip & Bitmap::SPRITE_H_FLIP ){
- x_dir = -1;
- }
-
- if (dst->clip) {
- int tmp;
-
- tmp = dst->cl - dx;
- sxbeg = ((tmp < 0) ? 0 : tmp);
- dxbeg = sxbeg + dx;
-
- tmp = dst->cr - dx;
- w = ((tmp > src->w) ? src->w : tmp) - sxbeg;
- if (w <= 0)
- return;
-
- if ( flip & Bitmap::SPRITE_H_FLIP ){
- /* use backward drawing onto dst */
- sxbeg = src->w - (sxbeg + w);
- dxbeg += w - 1;
- }
-
- tmp = dst->ct - dy;
- sybeg = ((tmp < 0) ? 0 : tmp);
- dybeg = sybeg + dy;
-
- tmp = dst->cb - dy;
- h = ((tmp > src->h) ? src->h : tmp) - sybeg;
- if (h <= 0)
- return;
-
- if ( flip & Bitmap::SPRITE_V_FLIP ){
- /* use backward drawing onto dst */
- sybeg = src->h - (sybeg + h);
- dybeg += h - 1;
- }
- } else {
- w = src->w;
- h = src->h;
- sxbeg = 0;
- sybeg = 0;
- dxbeg = dx;
- if ( flip & Bitmap::SPRITE_H_FLIP ){
- dxbeg = dx + w - 1;
- }
- dybeg = dy;
- if ( flip & Bitmap::SPRITE_V_FLIP ){
- dybeg = dy + h - 1;
- }
- }
-
- lit_blender = PAINTOWN_MAKE_DLS_BLENDER(0);
- trans_blender = PAINTOWN_MAKE_DTS_BLENDER();
-
- if (dst->id & (BMP_ID_VIDEO | BMP_ID_SYSTEM)) {
- bmp_select(dst);
-
-#if 0
- switch (mode){
- case Bitmap::SPRITE_NORMAL : {
- for (y = 0; y < h; y++) {
- PAINTOWN_PIXEL_PTR s = PAINTOWN_OFFSET_PIXEL_PTR(src->line[sybeg + y], sxbeg);
- PAINTOWN_PIXEL_PTR d = PAINTOWN_OFFSET_PIXEL_PTR(bmp_write_line(dst, dybeg + y * y_dir), dxbeg);
- for (x = w - 1; x >= 0; PAINTOWN_INC_PIXEL_PTR(s), PAINTOWN_INC_PIXEL_PTR_EX(d,x_dir), x--) {
-
- unsigned long c = PAINTOWN_GET_MEMORY_PIXEL(s);
- if (!PAINTOWN_IS_SPRITE_MASK(src, c)) {
- PAINTOWN_PUT_PIXEL(d, c);
- }
- }
- }
-
- break;
- }
- case Bitmap::SPRITE_LIT : {
- for (y = 0; y < h; y++) {
- PAINTOWN_PIXEL_PTR s = PAINTOWN_OFFSET_PIXEL_PTR(src->line[sybeg + y], sxbeg);
- PAINTOWN_PIXEL_PTR d = PAINTOWN_OFFSET_PIXEL_PTR(bmp_write_line(dst, dybeg + y * y_dir), dxbeg);
- for (x = w - 1; x >= 0; PAINTOWN_INC_PIXEL_PTR(s), PAINTOWN_INC_PIXEL_PTR_EX(d,x_dir), x--) {
-
- unsigned long c = PAINTOWN_GET_MEMORY_PIXEL(s);
- if (!PAINTOWN_IS_SPRITE_MASK(src, c)) {
- c = PAINTOWN_DLSX_BLEND(lit_blender, c);
- PAINTOWN_PUT_PIXEL(d, c);
- }
- }
- }
- break;
- }
- case Bitmap::SPRITE_TRANS : {
- for (y = 0; y < h; y++) {
- PAINTOWN_PIXEL_PTR s = PAINTOWN_OFFSET_PIXEL_PTR(src->line[sybeg + y], sxbeg);
- PAINTOWN_PIXEL_PTR d = PAINTOWN_OFFSET_PIXEL_PTR(bmp_write_line(dst, dybeg + y * y_dir), dxbeg);
- for (x = w - 1; x >= 0; PAINTOWN_INC_PIXEL_PTR(s), PAINTOWN_INC_PIXEL_PTR_EX(d,x_dir), x--) {
-
- unsigned long c = PAINTOWN_GET_MEMORY_PIXEL(s);
- if (!PAINTOWN_IS_SPRITE_MASK(src, c)) {
- c = PAINTOWN_DTS_BLEND(trans_blender, PAINTOWN_GET_PIXEL(d), c);
- PAINTOWN_PUT_PIXEL(d, c);
- }
- }
- }
- break;
- }
- }
-#endif
-
- for (y = 0; y < h; y++) {
- PAINTOWN_PIXEL_PTR s = PAINTOWN_OFFSET_PIXEL_PTR(src->line[sybeg + y], sxbeg);
-
- /* flipped if y_dir is -1 */
- PAINTOWN_PIXEL_PTR d = PAINTOWN_OFFSET_PIXEL_PTR(bmp_write_line(dst, dybeg + y * y_dir), dxbeg);
-
- /* d is incremented by x_dir, -1 if flipped */
- for (x = w - 1; x >= 0; PAINTOWN_INC_PIXEL_PTR(s), PAINTOWN_INC_PIXEL_PTR_EX(d,x_dir), x--) {
- unsigned long c = PAINTOWN_GET_MEMORY_PIXEL(s);
- if (!PAINTOWN_IS_SPRITE_MASK(src, c)) {
- switch( mode ){
- case Bitmap::SPRITE_NORMAL : break;
- case Bitmap::SPRITE_LIT : {
- c = PAINTOWN_DLSX_BLEND(lit_blender, c);
- break;
- }
- case Bitmap::SPRITE_TRANS : {
- c = PAINTOWN_DTS_BLEND(trans_blender, PAINTOWN_GET_PIXEL(d), c);
- break;
- }
- }
- PAINTOWN_PUT_PIXEL(d, c);
- }
- }
- }
-
- bmp_unwrite_line(dst);
- }
- else {
-
- switch (mode){
- case Bitmap::SPRITE_NORMAL : {
- for (y = 0; y < h; y++) {
- PAINTOWN_PIXEL_PTR s = PAINTOWN_OFFSET_PIXEL_PTR(src->line[sybeg + y], sxbeg);
- PAINTOWN_PIXEL_PTR d = PAINTOWN_OFFSET_PIXEL_PTR(bmp_write_line(dst, dybeg + y * y_dir), dxbeg);
-
- for (x = w - 1; x >= 0; PAINTOWN_INC_PIXEL_PTR(s), PAINTOWN_INC_PIXEL_PTR_EX(d,x_dir), x--) {
- unsigned long c = PAINTOWN_GET_MEMORY_PIXEL(s);
- if (!PAINTOWN_IS_SPRITE_MASK(src, c)) {
- PAINTOWN_PUT_MEMORY_PIXEL(d, c);
- }
- }
- }
-
- break;
- }
- case Bitmap::SPRITE_LIT : {
- for (y = 0; y < h; y++) {
- PAINTOWN_PIXEL_PTR s = PAINTOWN_OFFSET_PIXEL_PTR(src->line[sybeg + y], sxbeg);
- PAINTOWN_PIXEL_PTR d = PAINTOWN_OFFSET_PIXEL_PTR(bmp_write_line(dst, dybeg + y * y_dir), dxbeg);
-
- for (x = w - 1; x >= 0; PAINTOWN_INC_PIXEL_PTR(s), PAINTOWN_INC_PIXEL_PTR_EX(d,x_dir), x--) {
- unsigned long c = PAINTOWN_GET_MEMORY_PIXEL(s);
- if (!PAINTOWN_IS_SPRITE_MASK(src, c)) {
- c = PAINTOWN_DLSX_BLEND(lit_blender, c);
- PAINTOWN_PUT_MEMORY_PIXEL(d, c);
- }
- }
- }
- break;
- }
- case Bitmap::SPRITE_TRANS : {
- for (y = 0; y < h; y++) {
- PAINTOWN_PIXEL_PTR s = PAINTOWN_OFFSET_PIXEL_PTR(src->line[sybeg + y], sxbeg);
- PAINTOWN_PIXEL_PTR d = PAINTOWN_OFFSET_PIXEL_PTR(bmp_write_line(dst, dybeg + y * y_dir), dxbeg);
-
- for (x = w - 1; x >= 0; PAINTOWN_INC_PIXEL_PTR(s), PAINTOWN_INC_PIXEL_PTR_EX(d,x_dir), x--) {
- unsigned long c = PAINTOWN_GET_MEMORY_PIXEL(s);
- if (!PAINTOWN_IS_SPRITE_MASK(src, c)) {
- c = PAINTOWN_DTS_BLEND(trans_blender, PAINTOWN_GET_PIXEL(d), c);
- PAINTOWN_PUT_MEMORY_PIXEL(d, c);
- }
- }
- }
- break;
- }
- }
-
-#if 0
- for (y = 0; y < h; y++) {
- PAINTOWN_PIXEL_PTR s = PAINTOWN_OFFSET_PIXEL_PTR(src->line[sybeg + y], sxbeg);
- PAINTOWN_PIXEL_PTR d = PAINTOWN_OFFSET_PIXEL_PTR(bmp_write_line(dst, dybeg + y * y_dir), dxbeg);
-
- for (x = w - 1; x >= 0; PAINTOWN_INC_PIXEL_PTR(s), PAINTOWN_INC_PIXEL_PTR_EX(d,x_dir), x--) {
- unsigned long c = PAINTOWN_GET_MEMORY_PIXEL(s);
- if (!PAINTOWN_IS_SPRITE_MASK(src, c)) {
- switch( mode ){
- case Bitmap::SPRITE_NORMAL : break;
- case Bitmap::SPRITE_LIT : {
- c = PAINTOWN_DLSX_BLEND(lit_blender, c);
- break;
- }
- case Bitmap::SPRITE_TRANS : {
- c = PAINTOWN_DTS_BLEND(trans_blender, PAINTOWN_GET_PIXEL(d), c);
- break;
- }
- }
- PAINTOWN_PUT_MEMORY_PIXEL(d, c);
- }
- }
- }
-#endif
- }
-}
-
-/* mix pixels with the given color in with each non-masking pixel in dst */
-static void paintown_applyTrans16(BITMAP * dst, const int color){
- int y1 = 0;
- int y2 = dst->h;
- int x1 = 0;
- int x2 = dst->w - 1;
-
- if (dst->clip){
- y1 = dst->ct;
- y2 = dst->cb - 1;
- x1 = dst->cl;
- x2 = dst->cr - 1;
- }
-
- PAINTOWN_DTS_BLENDER trans_blender;
- trans_blender = PAINTOWN_MAKE_DTS_BLENDER();
- if (dst->id & (BMP_ID_VIDEO | BMP_ID_SYSTEM)) {
- } else {
- for (int y = y1; y < y2; y++) {
- PAINTOWN_PIXEL_PTR d = PAINTOWN_OFFSET_PIXEL_PTR(bmp_write_line(dst, y), x1);
- for (int x = x2; x >= x1; PAINTOWN_INC_PIXEL_PTR_EX(d,1), x--) {
- unsigned long c = PAINTOWN_GET_MEMORY_PIXEL(d);
- if (!PAINTOWN_IS_SPRITE_MASK(dst, c)) {
- c = PAINTOWN_DTS_BLEND(trans_blender, color, c);
- PAINTOWN_PUT_MEMORY_PIXEL(d, c);
- }
- }
- }
- }
-}
-
-/* ultra special-case for drawing a light (like from a lamp).
- * center of light is x,y and shines in a perfect isosolese triangle.
- */
-static void paintown_light16(BITMAP * dst, const int x, const int y, const int width, const int height, const int start_y, const int focus_alpha, const int edge_alpha, const int focus_color, const int edge_color){
-
- int dxbeg = x - width;
- int x_dir = 1;
- unsigned char * alphas = new unsigned char[width];