diff --git a/NEWS.txt b/NEWS.txt index e65ef7645..25c8efa90 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -13,6 +13,7 @@ NEWS + Fixed a bug with multiple editors and paste command. + Fixed a bug in the File Open dialog when user presses ENTER key with an empty file name. ++ Fixed critical bugs in rendering code. 0.6.1 ----- diff --git a/makefile.lst b/makefile.lst index 45488c509..6ce38be71 100644 --- a/makefile.lst +++ b/makefile.lst @@ -181,7 +181,6 @@ COMMON_SOURCES = \ src/raster/dirty.cpp \ src/raster/gfxobj.cpp \ src/raster/image.cpp \ - src/raster/image_impl.cpp \ src/raster/layer.cpp \ src/raster/mask.cpp \ src/raster/palette.cpp \ diff --git a/src/jinete/jmem.cpp b/src/jinete/jmem.cpp index 71763cc55..3ce6d4ced 100644 --- a/src/jinete/jmem.cpp +++ b/src/jinete/jmem.cpp @@ -81,7 +81,11 @@ char *jstrdup(const char *string) ////////////////////////////////////////////////////////////////////// // With leak detection -#define BACKTRACE_LEVELS 16 +#if defined(__GNUC__) + #define BACKTRACE_LEVELS 4 +#else + #define BACKTRACE_LEVELS 16 +#endif #if defined _MSC_VER @@ -218,8 +222,15 @@ static void addslot(void *ptr, unsigned long size) assert(size != 0); // __builtin_return_address is a GCC extension +#if defined(__GNUC__) + p->backtrace[0] = __builtin_return_address(4); + p->backtrace[1] = __builtin_return_address(3); + p->backtrace[2] = __builtin_return_address(2); + p->backtrace[3] = __builtin_return_address(1); +#else for (int c=0; cbacktrace[c] = __builtin_return_address(BACKTRACE_LEVELS-c); +#endif p->ptr = ptr; p->size = size; diff --git a/src/raster/image_impl.cpp b/src/raster/image_impl.cpp deleted file mode 100644 index 62749a139..000000000 --- a/src/raster/image_impl.cpp +++ /dev/null @@ -1,539 +0,0 @@ -/* ASE - Allegro Sprite Editor - * Copyright (C) 2001-2009 David Capello - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "config.h" - -#include "raster/image_impl.h" - -template<> -void ImageImpl::to_allegro(BITMAP *bmp, int _x, int _y) const -{ - const_address_t addr = raw_pixels(); - unsigned long bmp_address; - int depth = bitmap_color_depth(bmp); - int x, y; - - bmp_select(bmp); - - switch (depth) { - - case 8: -#if defined GFX_MODEX && !defined ALLEGRO_UNIX - if (is_planar_bitmap(bmp)) { - for (y=0; yline[_y]; - - for (x=0; xw; x++) { - outportw(0x3C4, (0x100<<((_x+x)&3))|2); - bmp_write8(bmp_address+((_x+x)>>2), - makecol8((*addr) & 0xff, - ((*addr)>>8) & 0xff, - ((*addr)>>16) & 0xff)); - addr++; - } - - _y++; - } - } - else { -#endif - for (y=0; y>8) & 0xff, - ((*addr)>>16) & 0xff)); - addr++; - bmp_address++; - } - - _y++; - } -#if defined GFX_MODEX && !defined ALLEGRO_UNIX - } -#endif - break; - - case 15: - _x <<= 1; - - for (y=0; y>8) & 0xff, - ((*addr)>>16) & 0xff)); - addr++; - bmp_address += 2; - } - - _y++; - } - break; - - case 16: - _x <<= 1; - - for (y=0; y>8) & 0xff, - ((*addr)>>16) & 0xff)); - addr++; - bmp_address += 2; - } - - _y++; - } - break; - - case 24: - _x *= 3; - - for (y=0; y>8) & 0xff, - ((*addr)>>16) & 0xff)); - addr++; - bmp_address += 3; - } - - _y++; - } - break; - - case 32: - _x <<= 2; - - for (y=0; y>8) & 0xff, - ((*addr)>>16) & 0xff, - ((*addr)>>24) & 0xff)); - addr++; - bmp_address += 4; - } - - _y++; - } - break; - } - - bmp_unwrite_line(bmp); -} - -template<> -void ImageImpl::to_allegro(BITMAP *bmp, int _x, int _y) const -{ - const_address_t addr = raw_pixels(); - unsigned long bmp_address; - int depth = bitmap_color_depth(bmp); - int x, y; - - bmp_select(bmp); - - switch (depth) { - - case 8: -#if defined GFX_MODEX && !defined ALLEGRO_UNIX - if (is_planar_bitmap(bmp)) { - for (y=0; yline[_y]; - - for (x=0; x>2), - _index_cmap[(*addr) & 0xff]); - addr++; - } - - _y++; - } - } - else { -#endif - for (y=0; y -void ImageImpl::to_allegro(BITMAP *bmp, int _x, int _y) const -{ -#define RGB_TRIPLET \ - _rgb_scale_6[_current_palette[_index_cmap[(*addr)]].r], \ - _rgb_scale_6[_current_palette[_index_cmap[(*addr)]].g], \ - _rgb_scale_6[_current_palette[_index_cmap[(*addr)]].b] - - const_address_t addr = raw_pixels(); - unsigned long bmp_address; - int depth = bitmap_color_depth(bmp); - int x, y; - - bmp_select(bmp); - - switch (depth) { - - case 8: -#if defined GFX_MODEX && !defined ALLEGRO_UNIX - if (is_planar_bitmap (bmp)) { - for (y=0; yline[_y]; - - for (x=0; x>2), _index_cmap[(*addr)]); - address++; - } - - _y++; - } - } - else { -#endif - for (y=0; y -void ImageImpl::to_allegro(BITMAP *bmp, int _x, int _y) const -{ - const_address_t addr; - unsigned long bmp_address; - int depth = bitmap_color_depth(bmp); - div_t d, beg_d = div(0, 8); - int color[2]; - int x, y; - - bmp_select(bmp); - - switch (depth) { - - case 8: - color[0] = makecol8(0, 0, 0); - color[1] = makecol8(255, 255, 255); - -#if defined GFX_MODEX && !defined ALLEGRO_UNIX - if (is_planar_bitmap(bmp)) { - for (y=0; yline[_y]; - - d = beg_d; - for (x=0; x>2), - color[((*addr) & (1<::merge(const Image* src, int x, int y, int opacity, } } +template<> +void ImageImpl::to_allegro(BITMAP *bmp, int _x, int _y) const +{ + const_address_t addr = raw_pixels(); + unsigned long bmp_address; + int depth = bitmap_color_depth(bmp); + int x, y; + + bmp_select(bmp); + + switch (depth) { + + case 8: +#if defined GFX_MODEX && !defined ALLEGRO_UNIX + if (is_planar_bitmap(bmp)) { + for (y=0; yline[_y]; + + for (x=0; xw; x++) { + outportw(0x3C4, (0x100<<((_x+x)&3))|2); + bmp_write8(bmp_address+((_x+x)>>2), + makecol8((*addr) & 0xff, + ((*addr)>>8) & 0xff, + ((*addr)>>16) & 0xff)); + addr++; + } + + _y++; + } + } + else { +#endif + for (y=0; y>8) & 0xff, + ((*addr)>>16) & 0xff)); + addr++; + bmp_address++; + } + + _y++; + } +#if defined GFX_MODEX && !defined ALLEGRO_UNIX + } +#endif + break; + + case 15: + _x <<= 1; + + for (y=0; y>8) & 0xff, + ((*addr)>>16) & 0xff)); + addr++; + bmp_address += 2; + } + + _y++; + } + break; + + case 16: + _x <<= 1; + + for (y=0; y>8) & 0xff, + ((*addr)>>16) & 0xff)); + addr++; + bmp_address += 2; + } + + _y++; + } + break; + + case 24: + _x *= 3; + + for (y=0; y>8) & 0xff, + ((*addr)>>16) & 0xff)); + addr++; + bmp_address += 3; + } + + _y++; + } + break; + + case 32: + _x <<= 2; + + for (y=0; y>8) & 0xff, + ((*addr)>>16) & 0xff, + ((*addr)>>24) & 0xff)); + addr++; + bmp_address += 4; + } + + _y++; + } + break; + } + + bmp_unwrite_line(bmp); +} + +template<> +void ImageImpl::to_allegro(BITMAP *bmp, int _x, int _y) const +{ + const_address_t addr = raw_pixels(); + unsigned long bmp_address; + int depth = bitmap_color_depth(bmp); + int x, y; + + bmp_select(bmp); + + switch (depth) { + + case 8: +#if defined GFX_MODEX && !defined ALLEGRO_UNIX + if (is_planar_bitmap(bmp)) { + for (y=0; yline[_y]; + + for (x=0; x>2), + _index_cmap[(*addr) & 0xff]); + addr++; + } + + _y++; + } + } + else { +#endif + for (y=0; y +void ImageImpl::to_allegro(BITMAP *bmp, int _x, int _y) const +{ +#define RGB_TRIPLET \ + _rgb_scale_6[_current_palette[_index_cmap[(*addr)]].r], \ + _rgb_scale_6[_current_palette[_index_cmap[(*addr)]].g], \ + _rgb_scale_6[_current_palette[_index_cmap[(*addr)]].b] + + const_address_t addr = raw_pixels(); + unsigned long bmp_address; + int depth = bitmap_color_depth(bmp); + int x, y; + + bmp_select(bmp); + + switch (depth) { + + case 8: +#if defined GFX_MODEX && !defined ALLEGRO_UNIX + if (is_planar_bitmap (bmp)) { + for (y=0; yline[_y]; + + for (x=0; x>2), _index_cmap[(*addr)]); + address++; + } + + _y++; + } + } + else { +#endif + for (y=0; y +void ImageImpl::to_allegro(BITMAP *bmp, int _x, int _y) const +{ + const_address_t addr; + unsigned long bmp_address; + int depth = bitmap_color_depth(bmp); + div_t d, beg_d = div(0, 8); + int color[2]; + int x, y; + + bmp_select(bmp); + + switch (depth) { + + case 8: + color[0] = makecol8(0, 0, 0); + color[1] = makecol8(255, 255, 255); + +#if defined GFX_MODEX && !defined ALLEGRO_UNIX + if (is_planar_bitmap(bmp)) { + for (y=0; yline[_y]; + + d = beg_d; + for (x=0; x>2), + color[((*addr) & (1< +inline typename Traits::address_t image_address_fast(const Image* image, int x, int y) +{ + assert(x >= 0 && x < image->w); + assert(y >= 0 && y < image->h); + + return ((((typename Traits::pixel_t**)image->line)[y])+x); +} + template inline typename Traits::pixel_t image_getpixel_fast(const Image* image, int x, int y) { diff --git a/src/util/render.cpp b/src/util/render.cpp index 56e236d7f..0f35cb6a8 100644 --- a/src/util/render.cpp +++ b/src/util/render.cpp @@ -28,7 +28,6 @@ #include "modules/palettes.h" #include "modules/tools.h" #include "raster/image.h" -#include "raster/image_impl.h" #include "raster/raster.h" ////////////////////////////////////////////////////////////////////// @@ -157,8 +156,8 @@ static void merge_zoomed_image(Image *dst, Image *src, assert(dst_x >= 0 && dst_x < dst->w); // get addresses to each line (beginning of 'src', 'dst', etc.) - src_address = ((ImageImpl*)src)->line_address(src_y) + src_x; - dst_address = ((ImageImpl*)dst)->line_address(dst_y) + dst_x; + src_address = image_address_fast(src, src_x, src_y); + dst_address = image_address_fast(dst, dst_x, dst_y); dst_address_end = dst_address + dst_w; scanline_address = scanline; @@ -166,10 +165,11 @@ static void merge_zoomed_image(Image *dst, Image *src, for (x=0; x= scanline); assert(scanline_address < scanline + src_w); - assert(src_address >= ((ImageImpl*)src)->line_address(src_y) + src_x); - assert(src_address < ((ImageImpl*)src)->line_address(src_y) + src_x + src_w); - assert(dst_address >= ((ImageImpl*)dst)->line_address(dst_y) + dst_x); - assert(dst_address < ((ImageImpl*)dst)->line_address(dst_y) + dst_x + dst_w); + + assert(src_address >= image_address_fast(src, src_x, src_y)); + assert(src_address <= image_address_fast(src, src_x+src_w-1, src_y)); + assert(dst_address >= image_address_fast(dst, dst_x, dst_y)); + assert(dst_address <= image_address_fast(dst, dst_x+dst_w-1, dst_y)); assert(dst_address < dst_address_end); blender(scanline_address, dst_address, src_address, opacity); @@ -193,7 +193,7 @@ static void merge_zoomed_image(Image *dst, Image *src, // draw the line in `dst' for (box_y=0; box_y*)dst)->line_address(dst_y) + dst_x; + dst_address = image_address_fast(dst, dst_x, dst_y); dst_address_end = dst_address + dst_w; scanline_address = scanline; @@ -204,8 +204,8 @@ static void merge_zoomed_image(Image *dst, Image *src, for (box_x=0; box_x= scanline); assert(scanline_address < scanline + src_w); - assert(dst_address >= ((ImageImpl*)dst)->line_address(dst_y) + dst_x); - assert(dst_address < ((ImageImpl*)dst)->line_address(dst_y) + dst_x + dst_w); + assert(dst_address >= image_address_fast(dst, dst_x, dst_y)); + assert(dst_address <= image_address_fast(dst, dst_x+dst_w-1, dst_y)); assert(dst_address < dst_address_end); (*dst_address++) = (*scanline_address); @@ -221,8 +221,9 @@ static void merge_zoomed_image(Image *dst, Image *src, // the rest of the line for (; x= ((ImageImpl*)dst)->line_address(dst_y) + dst_x); - assert(dst_address < ((ImageImpl*)dst)->line_address(dst_y) + dst_x + dst_w); + assert(dst_address >= image_address_fast(dst, dst_x, dst_y)); + assert(dst_address <= image_address_fast(dst, dst_x+dst_w-1, dst_y)); + assert(dst_address < dst_address_end); (*dst_address++) = (*scanline_address);