Ticket #8598: nut-allocate.diff
File nut-allocate.diff, 3.0 KB (added by , 14 years ago) |
---|
-
engines/scumm/nut_renderer.cpp
30 30 NutRenderer::NutRenderer(ScummEngine *vm) : 31 31 _vm(vm), 32 32 _loaded(false), 33 _numChars(0) { 33 _numChars(0), 34 _decodedData(0) { 34 35 memset(_chars, 0, sizeof(_chars)); 35 36 } 36 37 37 38 NutRenderer::~NutRenderer() { 38 for (int i = 0; i < _numChars; i++) { 39 delete []_chars[i].src; 40 } 39 delete [] _decodedData; 41 40 } 42 41 43 42 void smush_decode_codec1(byte *dst, const byte *src, int left, int top, int width, int height, int pitch); … … 89 88 } 90 89 91 90 uint32 length = file.readUint32BE(); 92 byte *dataSrc = (byte *)malloc(length);91 byte *dataSrc = new byte[length]; 93 92 file.read(dataSrc, length); 94 93 file.close(); 95 94 … … 99 98 return false; 100 99 } 101 100 101 // We pre-decode the font, which may seem wasteful at first. Actually, 102 // the memory needed for just the decoded glyphs is smaller than the 103 // whole of the undecoded font file. 104 102 105 _numChars = READ_LE_UINT16(dataSrc + 10); 103 106 assert(_numChars <= ARRAYSIZE(_chars)); 107 104 108 uint32 offset = 0; 109 uint32 decodedLength = 0; 105 110 for (int l = 0; l < _numChars; l++) { 111 offset += READ_BE_UINT32(dataSrc + offset + 4) + 16; 112 int width = READ_LE_UINT16(dataSrc + offset + 14); 113 int height = READ_LE_UINT16(dataSrc + offset + 16); 114 decodedLength += (width * height); 115 } 116 117 // If characters have transparency, then bytes just get skipped and 118 // so there may appear some garbage. That's why we have to fill it 119 // with zeroes first. 120 121 _decodedData = new byte[decodedLength]; 122 memset(_decodedData, 0, decodedLength); 123 124 byte *decodedPtr = _decodedData; 125 126 offset = 0; 127 for (int l = 0; l < _numChars; l++) { 106 128 offset += READ_BE_UINT32(dataSrc + offset + 4) + 8; 107 129 if (READ_BE_UINT32(dataSrc + offset) != 'FRME') { 108 130 error("NutRenderer::loadFont(%s) there is no FRME chunk %d (offset %x)", filename, l, offset); … … 118 140 _chars[l].yoffs = READ_LE_UINT16(dataSrc + offset + 12); 119 141 _chars[l].width = READ_LE_UINT16(dataSrc + offset + 14); 120 142 _chars[l].height = READ_LE_UINT16(dataSrc + offset + 16); 121 const int srcSize = _chars[l].width * _chars[l].height; 122 _chars[l].src = new byte[srcSize]; 123 // If characters have transparency, then bytes just get skipped and 124 // so there may appear some garbage. That's why we have to fill it 125 // with zeroes first. 126 memset(_chars[l].src, 0, srcSize); 143 _chars[l].src = decodedPtr; 127 144 145 decodedPtr += (_chars[l].width * _chars[l].height); 146 128 147 const uint8 *fobjptr = dataSrc + offset + 22; 129 148 switch (codec) { 130 149 case 1: … … 139 158 } 140 159 } 141 160 142 free(dataSrc);161 delete [] dataSrc; 143 162 _loaded = true; 144 163 return true; 145 164 } -
engines/scumm/nut_renderer.h
34 34 ScummEngine *_vm; 35 35 bool _loaded; 36 36 int _numChars; 37 byte *_decodedData; 37 38 struct { 38 39 int xoffs; 39 40 int yoffs;