diff --git a/docs/changes.txt b/docs/changes.txt index fbce5118cb..6feb607043 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -119,6 +119,7 @@ All (GUI): - Add wxDataViewRenderer::GetAccessibleDescription(). - Improve wxImage::Scale() handling of pixels with alpha channel (Tim Kosse). - Fix parsing of RGBA strings in wxColour (Laurent Poujoulat). +- Refactor code in wxQuantize() for MSVC to avoid crash. wxGTK: diff --git a/src/common/quantize.cpp b/src/common/quantize.cpp index 044314e447..16c2509ff7 100644 --- a/src/common/quantize.cpp +++ b/src/common/quantize.cpp @@ -1026,17 +1026,6 @@ pass2_no_dither (j_decompress_ptr cinfo, } } -#ifdef __VISUALC__ -/* - for (yet) unknown reasons, the following code produces - bad results or even crashes if the code optimization is - enabled in VC++ - - disable optimization for now until the reason is discovered -*/ - #pragma optimize ("", off) -#endif - void pass2_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows) @@ -1137,7 +1126,18 @@ pass2_fs_dither (j_decompress_ptr cinfo, bnexterr = cur0; /* Process component 0 */ delta = cur0 * 2; +/* + Calculating cur0, cur1, cur2 gives bad results if code + optimization is enabled in VC++. This is apparently caused + by some bug in the compiler. + Use refactored code until it is fixed. +*/ +#ifdef __VISUALC__ + /* Use refactored code to prevent invalid optimization. */ + cur0 *= 3; /* form error * 3 */ +#else cur0 += delta; /* form error * 3 */ +#endif errorptr[0] = (FSERROR) (bpreverr0 + cur0); cur0 += delta; /* form error * 5 */ bpreverr0 = belowerr0 + cur0; @@ -1145,7 +1145,12 @@ pass2_fs_dither (j_decompress_ptr cinfo, cur0 += delta; /* form error * 7 */ bnexterr = cur1; /* Process component 1 */ delta = cur1 * 2; +#ifdef __VISUALC__ + /* Use refactored code to prevent invalid optimization. */ + cur1 *= 3; /* form error * 3 */ +#else cur1 += delta; /* form error * 3 */ +#endif errorptr[1] = (FSERROR) (bpreverr1 + cur1); cur1 += delta; /* form error * 5 */ bpreverr1 = belowerr1 + cur1; @@ -1153,7 +1158,12 @@ pass2_fs_dither (j_decompress_ptr cinfo, cur1 += delta; /* form error * 7 */ bnexterr = cur2; /* Process component 2 */ delta = cur2 * 2; +#ifdef __VISUALC__ + /* Use refactored code to prevent invalid optimization. */ + cur2 *= 3; /* form error * 3 */ +#else cur2 += delta; /* form error * 3 */ +#endif errorptr[2] = (FSERROR) (bpreverr2 + cur2); cur2 += delta; /* form error * 5 */ bpreverr2 = belowerr2 + cur2; @@ -1177,9 +1187,6 @@ pass2_fs_dither (j_decompress_ptr cinfo, errorptr[2] = (FSERROR) bpreverr2; } } -#ifdef __VISUALC__ - #pragma optimize ("", on) -#endif /* * Initialize the error-limiting transfer function (lookup table).