Ticket #8362: cjk_v2.diff

File cjk_v2.diff, 17.1 KB (added by SF/wonst719, 20 years ago)

Updated patch

  • scumm/charset.cpp

    RCS file: /cvsroot/scummvm/scummvm/scumm/charset.cpp,v
    retrieving revision 2.119
    diff -u -r2.119 charset.cpp
     
    2323#include "scumm/scumm.h"
    2424#include "scumm/nut_renderer.h"
    2525
     26#include "scumm/cjkcode.h"
     27
    2628namespace Scumm {
    2729
    2830void ScummEngine::loadCJKFont() {
    2931        _useCJKMode = false;
    30         if ((_gameId == GID_DIG || _gameId == GID_CMI) && (_language == Common::KO_KOR || _language == Common::JA_JPN || _language == Common::ZH_TWN)) {
     32        if (_language == Common::JA_JPN && _version <= 5) { // FM-TOWNS v3 / v5 Kanji
    3133                File fp;
     34                int numChar = 256 * 32;
     35                _2byteWidth = 16;
     36                _2byteHeight = 16;
     37                // use FM-TOWNS font rom, since game files don't have kanji font resources
     38                if (fp.open("fmt_fnt.rom", File::kFileReadMode, getGameDataPath())
     39                        || fp.open("fmt_fnt.rom", File::kFileReadMode, "./")) {
     40                        _useCJKMode = true;
     41                        debug(2, "Loading FM-TOWNS Kanji rom");
     42                        _2byteFontPtr = new byte[((_2byteWidth + 7) / 8) * _2byteHeight * numChar];
     43                        fp.read(_2byteFontPtr, ((_2byteWidth + 7) / 8) * _2byteHeight * numChar);
     44                        fp.close();
     45                }
     46        } else if (_language == Common::KO_KOR || _language == Common::JA_JPN || _language == Common::ZH_TWN) {
     47                File fp;
     48                int numChar = 0;
    3249                const char *fontFile = NULL;
     50
    3351                switch(_language) {
    3452                case Common::KO_KOR:
    3553                        fontFile = "korean.fnt";
     54                        numChar = 2350;
    3655                        break;
    3756                case Common::JA_JPN:
    3857                        fontFile = (_gameId == GID_DIG) ? "kanji16.fnt" : "japanese.fnt";
     58                        numChar = 1024; //FIXME
    3959                        break;
    4060                case Common::ZH_TWN:
    4161                        if (_gameId == GID_CMI) {
    4262                                fontFile = "chinese.fnt";
     63                                numChar = 1; //FIXME
    4364                        }
    4465                        break;
    4566                default:
    4667                        break;
    4768                }
    48                 if (fontFile && fp.open(fontFile)) {
     69
     70                char pathS[1024];
     71                char pathV[1024];
     72                sprintf(pathS, "%sresource/", getGameDataPath());
     73                sprintf(pathV, "%svideo/", getGameDataPath());
     74                if (fontFile && (fp.open(fontFile, File::kFileReadMode, getGameDataPath())
     75                                || fp.open(fontFile, File::kFileReadMode, pathS)
     76                                || fp.open(fontFile, File::kFileReadMode, pathV))) {
    4977                        debug(2, "Loading CJK Font");
    5078                        _useCJKMode = true;
    5179                        fp.seek(2, SEEK_CUR);
    5280                        _2byteWidth = fp.readByte();
    5381                        _2byteHeight = fp.readByte();
    5482
    55                         int numChar = 0;
    56                         switch(_language) {
    57                         case Common::KO_KOR:
    58                                 numChar = 2350;
    59                                 break;
    60                         case Common::JA_JPN:
    61                                 numChar = (_gameId == GID_DIG) ? 1024 : 2048; //FIXME
    62                                 break;
    63                         case Common::ZH_TWN:
    64                                 numChar = 1; //FIXME
    65                                 break;
    66                         default:
    67                                 break;
    68                         }
    69                         _2byteFontPtr = new byte[((_2byteWidth + 7) / 8) * _2byteHeight * numChar];
    70                         fp.read(_2byteFontPtr, ((_2byteWidth + 7) / 8) * _2byteHeight * numChar);
    71                         fp.close();
    72                 }
    73         } else if (_language == Common::JA_JPN && _version == 5) { // FM-TOWNS Kanji
    74                 File fp;
    75                 int numChar = 256 * 32;
    76                 _2byteWidth = 16;
    77                 _2byteHeight = 16;
    78                 // use FM-TOWNS font rom, since game files don't have kanji font resources
    79                 if (fp.open("fmt_fnt.rom")) {
    80                         _useCJKMode = true;
    81                         debug(2, "Loading FM-TOWNS Kanji rom");
    8283                        _2byteFontPtr = new byte[((_2byteWidth + 7) / 8) * _2byteHeight * numChar];
    8384                        fp.read(_2byteFontPtr, ((_2byteWidth + 7) / 8) * _2byteHeight * numChar);
    8485                        fp.close();
     86                } else {
     87                        warning("Couldn't load any font");
    8588                }
    8689        }
    8790}
    8891
    89 static int SJIStoFMTChunk(int f, int s) //convert sjis code to fmt font offset
     92static int SJIStoFMTChunk(int f, int s) //converts sjis code to fmt font offset
    9093{
    9194        enum {
    9295                KANA = 0,
    9396                KANJI = 1,
    9497                EKANJI = 2
    9598        };
    96         int base = s - (s % 32) - 1;
    97         int c = 0, p = 0, chunk_f = 0, chunk = 0, cr, kanjiType = KANA;
     99        int base = s - ((s + 1) % 32);
     100        int c = 0, p = 0, chunk_f = 0, chunk = 0, cr = 0, kanjiType = KANA;
    98101
    99102        if (f >= 0x81 && f <= 0x84) kanjiType = KANA;
    100103        if (f >= 0x88 && f <= 0x9f) kanjiType = KANJI;
     
    115118                chunk_f = c + 2 * p;
    116119        }
    117120
     121        // Base corrections
    118122        if (base == 0x7f && s == 0x7f)
    119                 base -= 0x20; //correction
    120         if ((base == 0x7f && s == 0x9e) || (base == 0x9f && s == 0xbe) || (base == 0xbf && s == 0xde))
    121                 base += 0x20; //correction
     123                base -= 0x20;
     124        if (base == 0x9f && s == 0xbe)
     125                base += 0x20;
     126        if (base == 0xbf && s == 0xde)
     127                base += 0x20;
     128        //if (base == 0x7f && s == 0x9e)
     129        //      base += 0x20;
    122130
    123131        switch(base) {
    124132        case 0x3f:
     
    158166                else if (kanjiType == EKANJI) chunk = 144;
    159167                break;
    160168        default:
     169                warning("Invaild Char! f %x s %x base %x c %d p %d", f, s, base, c, p);
    161170                return 0;
    162171        }
    163172       
     173        debug(6, "Kanji: %c%c f 0x%x s 0x%x base 0x%x c %d p %d chunk %d cr %d index %d", f, s, f, s, base, c, p, chunk, cr, ((chunk_f + chunk) * 32 + (s - base)) + cr);
    164174        return ((chunk_f + chunk) * 32 + (s - base)) + cr;
    165175}
    166176
     
    238248        _fontPtr += _numChars;
    239249}
    240250
     251int CharsetRendererCommon::getFontHeight() {
     252        if(_vm->_useCJKMode)
     253                return MAX(_vm->_2byteHeight + 1, (int)_fontPtr[1]);
     254        else
     255                return _fontPtr[1];
     256}
     257
     258int CharsetRendererV3::getFontHeight() {
     259        if(_vm->_useCJKMode)
     260                return MAX(_vm->_2byteHeight + 1, 8);
     261        else
     262                return 8;
     263}
     264
    241265// do spacing for variable width old-style font
    242266int CharsetRendererClassic::getCharWidth(byte chr) {
    243         if (chr >= 0x80 && _vm->_useCJKMode)
    244                 return 6;
     267        if (chr >= 0x80 && _vm->_useCJKMode)
     268                return _vm->_2byteWidth / 2;
    245269        int spacing = 0;
    246270
    247271        int offs = READ_LE_UINT32(_fontPtr + chr * 4 + 4);
     
    276300                if (chr == 0xD)
    277301                        break;
    278302                if (chr == 254 || chr == 255) {
     303                        //process in LE
     304                        if(chr == 254 && checkKSCode(text[pos], chr) && _vm->_useCJKMode) {
     305                                goto loc_avoid_ks_fe;
     306                        }
    279307                        chr = text[pos++];
    280308                        if (chr == 3)   // 'WAIT'
    281309                                break;
     
    299327                                continue;
    300328                        }
    301329                }
    302                 width += getCharWidth(chr);
     330loc_avoid_ks_fe:
     331                if ((chr & 0x80) && _vm->_useCJKMode) {
     332                        pos++;
     333                        width += _vm->_2byteWidth;
     334                } else {
     335                        width += getCharWidth(chr);
     336                }
    303337        }
    304338
    305339        setCurID(oldID);
     
    333367                } else if (chr == '@')
    334368                        continue;
    335369                if (chr == 254 || chr == 255) {
     370                        //process in LE
     371                        if(chr == 254 && checkKSCode(str[pos], chr) && _vm->_useCJKMode) {
     372                                goto loc_avoid_ks_fe;
     373                        }
    336374                        chr = str[pos++];
    337375                        if (chr == 3) // 'Wait'
    338376                                break;
     
    366404                if (chr == ' ')
    367405                        lastspace = pos - 1;
    368406
    369                 curw += getCharWidth(chr);
     407loc_avoid_ks_fe:
     408                if ((chr & 0x80) && _vm->_useCJKMode) {
     409                        pos++;
     410                        curw += _vm->_2byteWidth;
     411                } else {
     412                        curw += getCharWidth(chr);
     413                }
    370414                if (lastspace == -1)
    371415                        continue;
    372416                if (curw > maxwidth) {
     
    11051149}
    11061150
    11071151int CharsetRendererV3::getCharWidth(byte chr) {
     1152        if (chr & 0x80 && _vm->_useCJKMode)
     1153                return _vm->_2byteWidth / 2;
    11081154        int spacing = 0;
    11091155
    11101156        spacing = *(_widthTable + chr);
     
    11291175
    11301176void CharsetRendererV3::printChar(int chr) {
    11311177        // Indy3 / Zak256 / Loom
     1178        int width, height, origWidth, origHeight;
    11321179        VirtScreen *vs;
    1133         byte *char_ptr, *dest_ptr;
    1134         int width, height;
    1135         int drawTop;
     1180        byte *charPtr, *dst;
     1181        int is2byte = (chr >= 0x80 && _vm->_useCJKMode) ? 1 : 0;
    11361182
    11371183        checkRange(_vm->_numCharsets - 1, 0, _curId, "Printing with bad charset %d");
    11381184
     
    11421188        if (chr == '@')
    11431189                return;
    11441190
     1191        if (is2byte) {
     1192                charPtr = _vm->get2byteCharPtr(chr);
     1193                width = _vm->_2byteWidth;
     1194                height = _vm->_2byteHeight;
     1195        } else {
     1196                charPtr = _fontPtr + chr * 8;
     1197//              width = height = 8;
     1198                width = getCharWidth(chr);
     1199                height = 8;
     1200        }
     1201
     1202        origWidth = width;
     1203        origHeight = height;
     1204
     1205        if (_dropShadow) {
     1206                width++;
     1207                height++;
     1208        }
     1209
    11451210        if (_firstChar) {
    11461211                _str.left = _left;
    11471212                _str.top = _top;
     
    11501215                _firstChar = false;
    11511216        }
    11521217
    1153         width = height = 8;
    1154         if (_dropShadow) {
    1155                 width++;
    1156                 height++;
    1157         }
    1158 
    1159         drawTop = _top - vs->topline;
    1160         char_ptr = _fontPtr + chr * 8;
     1218        int drawTop = _top - vs->topline;
    11611219
    11621220        _vm->markRectAsDirty(vs->number, _left, _left + width, drawTop, drawTop + height);
    11631221       
     
    11661224                _textScreenID = vs->number;
    11671225        }
    11681226        if (_ignoreCharsetMask || !vs->hasTwoBuffers) {
    1169                 dest_ptr = vs->getPixels(_left, drawTop);
    1170                 drawBits1(*vs, dest_ptr, char_ptr, drawTop, 8, 8);
     1227                dst = vs->getPixels(_left, drawTop);
     1228                drawBits1(*vs, dst, charPtr, drawTop, origWidth, origHeight);
    11711229        } else {
    1172                 dest_ptr = (byte *)_vm->gdi._textSurface.pixels + _top * _vm->gdi._textSurface.pitch + _left;
    1173                 drawBits1(_vm->gdi._textSurface, dest_ptr, char_ptr, drawTop, 8, 8);
     1230                dst = (byte *)_vm->gdi._textSurface.pixels + _top * _vm->gdi._textSurface.pitch + _left;
     1231                drawBits1(_vm->gdi._textSurface, dst, charPtr, drawTop, origWidth, origHeight);
    11741232        }
    11751233
    11761234        if (_str.left > _left)
    11771235                _str.left = _left;
    11781236
    1179         _left += getCharWidth(chr);
     1237        _left += origWidth;
    11801238
    11811239        if (_str.right < _left) {
    11821240                _str.right = _left;
     
    11891247}
    11901248
    11911249void CharsetRendererV3::drawChar(int chr, const Graphics::Surface &s, int x, int y) {
    1192         byte *char_ptr, *dest_ptr;
    1193         char_ptr = _fontPtr + chr * 8;
    1194         dest_ptr = (byte *)s.pixels + y * s.pitch + x;
    1195         drawBits1(s, dest_ptr, char_ptr, y, 8, 8);
     1250        byte *charPtr, *dst;
     1251        int width, height;
     1252        int is2byte = (chr >= 0x80 && _vm->_useCJKMode) ? 1 : 0;
     1253        if (is2byte) {
     1254                charPtr = _vm->get2byteCharPtr(chr);
     1255                width = _vm->_2byteWidth;
     1256                height = _vm->_2byteHeight;
     1257        } else {
     1258                charPtr = _fontPtr + chr * 8;
     1259//              width = height = 8;
     1260                width = getCharWidth(chr);
     1261                height = 8;
     1262        }
     1263        dst = (byte *)s.pixels + y * s.pitch + x;
     1264        drawBits1(s, dst, charPtr, y, width, height);
    11961265}
    11971266
    11981267
     
    12161285        int type = *_fontPtr;
    12171286        if (is2byte) {
    12181287                _dropShadow = true;
     1288                _shadowColor = (_vm->_features & GF_FMTOWNS) ? 8 : 0;
    12191289                charPtr = _vm->get2byteCharPtr(chr);
    12201290                width = _vm->_2byteWidth;
    12211291                height = _vm->_2byteHeight;
     
    14041474void CharsetRendererClassic::drawChar(int chr, const Graphics::Surface &s, int x, int y) {
    14051475        const byte *charPtr;
    14061476        byte *dst;
     1477        int width, height;
     1478        int is2byte = (chr >= 0x80 && _vm->_useCJKMode) ? 1 : 0;
    14071479
    1408         uint32 charOffs = READ_LE_UINT32(_fontPtr + chr * 4 + 4);
    1409         assert(charOffs < 0x10000);
    1410         if (!charOffs)
    1411                 return;
    1412         charPtr = _fontPtr + charOffs;
    1413        
    1414         int width = charPtr[0];
    1415         int height = charPtr[1];
     1480        if (is2byte) {
     1481                _dropShadow = true;
     1482                _shadowColor = (_vm->_features & GF_FMTOWNS) ? 8 : 0;
     1483                charPtr = _vm->get2byteCharPtr(chr);
     1484                width = _vm->_2byteWidth;
     1485                height = _vm->_2byteHeight;
     1486        } else {
     1487                uint32 charOffs = READ_LE_UINT32(_fontPtr + chr * 4 + 4);
     1488                assert(charOffs < 0x10000);
     1489                if (!charOffs)
     1490                        return;
     1491                charPtr = _fontPtr + charOffs;
     1492               
     1493                width = charPtr[0];
     1494                height = charPtr[1];
    14161495
    1417         charPtr += 4;   // Skip over char header
     1496                charPtr += 4;   // Skip over char header
     1497        }
    14181498
    14191499        dst = (byte *)s.pixels + y * s.pitch + x;
    1420         drawBitsN(s, dst, charPtr, *_fontPtr, y, width, height);
     1500
     1501        if (is2byte) {
     1502                drawBits1(s, dst, charPtr, y, width, height);
     1503        } else {
     1504                drawBitsN(s, dst, charPtr, *_fontPtr, y, width, height);
     1505        }
    14211506}
    14221507
    14231508void CharsetRendererClassic::drawBitsN(const Graphics::Surface &s, byte *dst, const byte *src, byte bpp, int drawTop, int width, int height) {
     
    15401625        int height = _current->getCharHeight(chr);
    15411626
    15421627        if (chr >= 256 && _vm->_useCJKMode)
    1543                 width = 16;
     1628                width = _vm->_2byteWidth;
    15441629
    15451630        shadow.right = _left + width + 2;
    15461631        shadow.bottom = _top + height + 2;
  • scumm/charset.h

    RCS file: /cvsroot/scummvm/scummvm/scumm/charset.h,v
    retrieving revision 2.31
    diff -u -r2.31 charset.h
     
    9494
    9595        void setCurID(byte id);
    9696       
    97         int getFontHeight() { return _fontPtr[1]; }
     97        int getFontHeight();
    9898};
    9999
    100100class CharsetRendererClassic : public CharsetRendererCommon {
     
    122122        void drawChar(int chr, const Graphics::Surface &s, int x, int y);
    123123        void setCurID(byte id);
    124124        void setColor(byte color);
    125         int getFontHeight() { return 8; }
     125        int getFontHeight();
    126126        int getCharWidth(byte chr);
    127127};
    128128
  • scumm/nut_renderer.cpp

    RCS file: /cvsroot/scummvm/scummvm/scumm/nut_renderer.cpp,v
    retrieving revision 1.52
    diff -u -r1.52 nut_renderer.cpp
     
    204204                return 0;
    205205        }
    206206
    207         if (c >= 0x80 && _vm->_useCJKMode) {
    208                 if (_vm->_gameId == GID_CMI)
    209                         return 8;
    210                 if (_vm->_gameId == GID_DIG)
    211                         return 6;
    212                 return 0;
    213         }
     207        if (c >= 0x80 && _vm->_useCJKMode)
     208                return _vm->_2byteWidth / 2;
    214209
    215210        if (c >= _numChars)
    216211                error("invalid character in NutRenderer::getCharWidth : %d (%d)", c, _numChars);
     
    225220                return 0;
    226221        }
    227222
    228         if (c >= 0x80 && _vm->_useCJKMode) {
    229                 if (_vm->_gameId == GID_CMI)
    230                         return 16;
    231                 if (_vm->_gameId == GID_DIG)
    232                         return 10;
    233                 return 0;
    234         }
     223        if (c >= 0x80 && _vm->_useCJKMode)
     224                return _vm->_2byteHeight;
    235225
    236226        if (c >= _numChars)
    237227                error("invalid character in NutRenderer::getCharHeight : %d (%d)", c, _numChars);
  • scumm/string.cpp

    RCS file: /cvsroot/scummvm/scummvm/scumm/string.cpp,v
    retrieving revision 1.258
    diff -u -r1.258 string.cpp
     
    3232#include "scumm/verbs.h"
    3333#include "scumm/sound.h"
    3434
     35#include "scumm/cjkcode.h"
     36
    3537namespace Scumm {
    3638
    3739void ScummEngine::printString(int m, const byte *msg) {
     
    103105        int code = (_heversion >= 80) ? 127 : 64;
    104106        char value[32];
    105107
     108        bool cmi_pos_hack = false;
     109
    106110        if (!_haveMsg)
    107111                return;
    108112
     
    283287                                warning("CHARSET_1: invalid code %d", c);
    284288                        }
    285289                } else if (c == 0xFE || c == 0xFF) {
     290                        //WORKAROUND
     291                        //to avoid korean code 0xfe treated as charset message code.
     292                        if(c == 0xFE && checkKSCode(*(buffer + 1), c) && _useCJKMode) {
     293                                goto loc_avoid_ks_fe;
     294                        }
    286295                        c = *buffer++;
    287296                        switch(c) {
    288297                        case 1:
     
    343352                                warning("CHARSET_1: invalid code %d", c);
    344353                        }
    345354                } else {
     355loc_avoid_ks_fe:
    346356                        _charset->_left = _charset->_nextLeft;
    347357                        _charset->_top = _charset->_nextTop;
    348358                        if (c & 0x80 && _useCJKMode)
    349                                 if (_language == 6 && ((c > 0x84 && c < 0x88) || (c > 0x9f && c < 0xe0) || (c > 0xea && c <= 0xff)))
     359                                if (_language == Common::JA_JPN && !checkSJISCode(c)) {
    350360                                        c = 0x20; //not in S-JIS
    351                                 else
    352                                         c += *buffer++ * 256;
     361                                } else {
     362                                        c += *buffer++ * 256; //LE
     363                                        if(_gameId == GID_CMI) { //HACK: This fixes korean text position in COMI (off by 6 pixel)
     364                                                cmi_pos_hack = true;
     365                                                _charset->_top += 6;
     366                                        }
     367                                }
    353368                        if (_version <= 3) {
    354369                                _charset->printChar(c);
    355370                        } else {
     
    363378                                } else
    364379                                        _charset->printChar(c);
    365380                        }
     381                        if(cmi_pos_hack) {
     382                                cmi_pos_hack = false;
     383                                _charset->_top -= 6;
     384                        }
    366385
    367386                        _charset->_nextLeft = _charset->_left;
    368387                        _charset->_nextTop = _charset->_top;
     
    389408        uint color;
    390409        int code = (_heversion >= 80) ? 127 : 64;
    391410
     411        bool cmi_pos_hack = false;
     412
    392413        addMessageToStack(msg, buf, sizeof(buf));
    393414
    394415        _charset->_top = _string[a].ypos + _screenTop;
     
    491512                                        _charset->_blitAlso = true;
    492513                                }
    493514                        }
    494                         if (c >= 0x80 && _useCJKMode)
    495                                 c += buf[i++] * 256;
     515                        if (c & 0x80 && _useCJKMode) {
     516                                if (_language == Common::JA_JPN && !checkSJISCode(c)) {
     517                                        c = 0x20; //not in S-JIS
     518                                } else {
     519                                        c += buf[i++] * 256;
     520                                        if(_gameId == GID_CMI) {
     521                                                cmi_pos_hack = true;
     522                                                _charset->_top += 6;
     523                                        }
     524                                }
     525                        }
    496526                        _charset->printChar(c);
    497527                        _charset->_blitAlso = false;
     528
     529                        if(cmi_pos_hack) {
     530                                cmi_pos_hack = false;
     531                                _charset->_top -= 6;
     532                        }
    498533                }
    499534        }
    500535
     
    729764                do {
    730765                        c = *buf++;
    731766                        if (c != 0 && c != 0xFF) {
    732                                 if (c >= 0x80 && _useCJKMode)
    733                                         c += *buf++ * 256;
     767                                if (c & 0x80 && _useCJKMode) {
     768                                        if (_language == Common::JA_JPN && !checkSJISCode(c)) {
     769                                                c = 0x20; //not in S-JIS
     770                                        } else {
     771                                                c += *buf++ * 256;
     772                                        }
     773                                }
    734774                                _charset->printChar(c);
    735775                        }
    736776                } while (c);
  • scumm/smush/smush_font.cpp

    RCS file: /cvsroot/scummvm/scummvm/scumm/smush/smush_font.cpp,v
    retrieving revision 1.23
    diff -u -r1.23 smush_font.cpp
     
    4343
    4444        int width = 0;
    4545        while (*str) {
    46                 width += getCharWidth(*str++);
     46                if(*str & 0x80 && g_scumm->_useCJKMode) {
     47                        width += g_scumm->_2byteWidth + 1;
     48                        str += 2;
     49                } else
     50                        width += getCharWidth(*str++);
    4751        }
    4852        return width;
    4953}
     
    118122        int h = _vm->_2byteHeight;
    119123
    120124        byte *src = _vm->get2byteCharPtr(idx);
    121         byte *dst = buffer + dst_width * (y + (_vm->_gameId == GID_CMI ? 7 : 2)) + x;
     125        byte *dst = buffer + dst_width * (y + (_vm->_gameId == GID_CMI ? 7 : (_vm->_gameId == GID_DIG ? 2 : 0))) + x;
    122126        byte bits = 0;
    123127
    124128        char color = (_color != -1) ? _color : 1;
     129
    125130        if (_new_colors)
    126                 color = (char)0xff; //FIXME;
     131                color = (char)0xff;
     132
     133        if (g_scumm->_gameId == GID_FT)
     134                color = 1;
     135
    127136        for (int j = 0; j < h; j++) {
    128137                for (int i = 0; i < w; i++) {
    129138                        if ((i % 8) == 0)
    130139                                bits = *src++;
    131140                        if (bits & revBitMask[i % 8]) {
    132141                                dst[i + 1] = 0;
     142                                dst[dst_width + i] = 0;
     143                                dst[dst_width + i + 1] = 0;
    133144                                dst[i] = color;
    134145                        }
    135146                }