use ii instead of i in for loop

This commit is contained in:
Jeremie Roy 2013-04-23 22:48:34 +02:00
parent 5096f82d12
commit 119317686c
4 changed files with 78 additions and 78 deletions

View file

@ -76,12 +76,12 @@ int _main_(int /*_argc*/, char** /*_argv*/)
FontHandle fonts[64];
fonts[fontsCount++] = distance_font;
//generate various sub distance field fonts at various size
int step=4;
for(int i = 64; i>1 ; i-=step)
int32_t step=4;
for(int32_t ii = 64; ii>1 ; ii-=step)
{
if(i<32) step = 2;
if(ii<32) step = 2;
//instantiate a usable font
FontHandle font = fontManager->createScaledFontToPixelSize(distance_font, i);
FontHandle font = fontManager->createScaledFontToPixelSize(distance_font, ii);
fonts[fontsCount++] = font;
}
//You can unload the truetype files at this stage, but in that case, the set of glyph's will be limited to the set of preloaded glyph
@ -92,9 +92,9 @@ int _main_(int /*_argc*/, char** /*_argv*/)
textBufferManager->setPenPosition(staticText, 10.0f, 70.0f);
textBufferManager->setTextColor(staticText, 0xFFFFFFFF);
//textBufferManager->setTextColor(staticText, 0x000000FF);
for(size_t i = 0; i< fontsCount; ++i)
for(uint32_t ii = 0; ii< fontsCount; ++ii)
{
textBufferManager->appendText(staticText, fonts[i], L"The quick brown fox jumps over the lazy dog\n");
textBufferManager->appendText(staticText, fonts[ii], L"The quick brown fox jumps over the lazy dog\n");
//textBufferManager->appendText(staticText, fonts[i], L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\n");
}
@ -144,9 +144,9 @@ int _main_(int /*_argc*/, char** /*_argv*/)
}
//destroy the fonts
for(size_t i=0; i<fontsCount;++i)
for(uint32_t ii=0; ii<fontsCount;++ii)
{
fontManager->destroyFont(fonts[i]);
fontManager->destroyFont(fonts[ii]);
}
textBufferManager->destroyTextBuffer(staticText);

View file

@ -89,22 +89,22 @@ bool RectanglePacker::addRectangle(uint16_t _width, uint16_t _height, uint16_t&
_outX = 0;
_outY = 0;
uint32_t i;
uint32_t ii;
best_height = INT_MAX;
best_index = -1;
best_width = INT_MAX;
for( i = 0; i < m_skyline.size(); ++i )
for( ii = 0; ii < m_skyline.size(); ++ii )
{
y = fit( i, _width, _height );
y = fit( ii, _width, _height );
if( y >= 0 )
{
node = &m_skyline[i];
node = &m_skyline[ii];
if( ( (y + _height) < best_height ) ||
( ((y + _height) == best_height) && (node->m_width < best_width)) )
{
best_height = y + _height;
best_index = i;
best_index = ii;
best_width = node->m_width;
_outX = node->m_x;
_outY = y;
@ -120,10 +120,10 @@ bool RectanglePacker::addRectangle(uint16_t _width, uint16_t _height, uint16_t&
Node newNode(_outX, _outY + _height, _width);
m_skyline.insert(m_skyline.begin() + best_index, newNode);
for(i = best_index+1; i < m_skyline.size(); ++i)
for(ii = best_index+1; ii < m_skyline.size(); ++ii)
{
node = &m_skyline[i];
prev = &m_skyline[i-1];
node = &m_skyline[ii];
prev = &m_skyline[ii-1];
if (node->m_x < (prev->m_x + prev->m_width) )
{
int shrink = prev->m_x + prev->m_width - node->m_x;
@ -131,8 +131,8 @@ bool RectanglePacker::addRectangle(uint16_t _width, uint16_t _height, uint16_t&
node->m_width -= shrink;
if (node->m_width <= 0)
{
m_skyline.erase(m_skyline.begin() + i);
--i;
m_skyline.erase(m_skyline.begin() + ii);
--ii;
}
else
{
@ -206,17 +206,17 @@ void RectanglePacker::merge()
{
Node* node;
Node* next;
uint32_t i;
uint32_t ii;
for( i=0; i < m_skyline.size()-1; ++i )
for( ii=0; ii < m_skyline.size()-1; ++ii )
{
node = (Node *) &m_skyline[i];
next = (Node *) &m_skyline[i+1];
node = (Node *) &m_skyline[ii];
next = (Node *) &m_skyline[ii+1];
if( node->m_y == next->m_y )
{
node->m_width += next->m_width;
m_skyline.erase(m_skyline.begin() + i + 1);
--i;
m_skyline.erase(m_skyline.begin() + ii + 1);
--ii;
}
}
}
@ -234,9 +234,9 @@ Atlas::Atlas(uint16_t _textureSize, uint16_t _maxRegionsCount )
assert(_textureSize >= 64 && _textureSize <= 4096 && "suspicious texture size" );
assert(_maxRegionsCount >= 64 && _maxRegionsCount <= 32000 && "suspicious _regions count" );
m_layers = new PackedLayer[24];
for(int i=0; i<24;++i)
for(int ii=0; ii<24;++ii)
{
m_layers[i].packer.init(_textureSize, _textureSize);
m_layers[ii].packer.init(_textureSize, _textureSize);
}
m_usedLayers = 0;
m_usedFaces = 0;
@ -330,9 +330,9 @@ uint16_t Atlas::addRegion(uint16_t _width, uint16_t _height, const uint8_t* _bit
return UINT16_MAX;
}
//create new layers
for(int i=0; i < _type;++i)
for(int ii=0; ii < _type; ++ii)
{
m_layers[idx+i].faceRegion.setMask(_type, m_usedFaces, i);
m_layers[idx+ii].faceRegion.setMask(_type, m_usedFaces, ii);
}
m_usedLayers += _type;
m_usedFaces++;
@ -367,7 +367,7 @@ void Atlas::updateRegion(const AtlasRegion& _region, const uint8_t* _bitmapBuffe
uint8_t* outLineBuffer = m_textureBuffer + _region.getFaceIndex() * (m_textureSize*m_textureSize*4) + (((_region.m_y *m_textureSize)+_region.m_x)*4);
//update the cpu buffer
for(int y = 0; y < _region.m_height; ++y)
for(int yy = 0; yy < _region.m_height; ++yy)
{
memcpy(outLineBuffer, inLineBuffer, _region.m_width * 4);
inLineBuffer += _region.m_width*4;
@ -383,14 +383,14 @@ void Atlas::updateRegion(const AtlasRegion& _region, const uint8_t* _bitmapBuffe
uint8_t* outLineBuffer = (m_textureBuffer + _region.getFaceIndex() * (m_textureSize*m_textureSize*4) + (((_region.m_y *m_textureSize)+_region.m_x)*4));
//update the cpu buffer
for(int y = 0; y<_region.m_height; ++y)
for(int yy = 0; yy<_region.m_height; ++yy)
{
for(int x = 0; x<_region.m_width; ++x)
for(int xx = 0; xx<_region.m_width; ++xx)
{
outLineBuffer[(x*4) + layer] = inLineBuffer[x];
outLineBuffer[(xx*4) + layer] = inLineBuffer[xx];
}
//update the GPU buffer
memcpy(mem->data + y*_region.m_width*4, outLineBuffer, _region.m_width*4);
memcpy(mem->data + yy*_region.m_width*4, outLineBuffer, _region.m_width*4);
inLineBuffer += _region.m_width;
outLineBuffer += m_textureSize*4;
}

View file

@ -206,10 +206,10 @@ bool FontManager::TrueTypeFont::bakeGlyphAlpha(CodePoint_t _codePoint, GlyphInfo
int32_t charsize = 1;
int32_t depth=1;
int32_t stride = bitmap->bitmap.pitch;
for( int32_t i=0; i<h; ++i )
for( int32_t ii=0; ii<h; ++ii )
{
memcpy(_outBuffer+(i*w) * charsize * depth,
bitmap->bitmap.buffer + (i*stride) * charsize, w * charsize * depth );
memcpy(_outBuffer+(ii*w) * charsize * depth,
bitmap->bitmap.buffer + (ii*stride) * charsize, w * charsize * depth );
}
FT_Done_Glyph(glyph);
return true;
@ -248,10 +248,10 @@ bool FontManager::TrueTypeFont::bakeGlyphSubpixel(CodePoint_t _codePoint, GlyphI
int32_t charsize = 1;
int32_t depth=3;
int32_t stride = bitmap->bitmap.pitch;
for( int32_t i=0; i<h; ++i )
for( int32_t ii=0; ii<h; ++ii )
{
memcpy(_outBuffer+(i*w) * charsize * depth,
bitmap->bitmap.buffer + (i*stride) * charsize, w * charsize * depth );
memcpy(_outBuffer+(ii*w) * charsize * depth,
bitmap->bitmap.buffer + (ii*stride) * charsize, w * charsize * depth );
}
FT_Done_Glyph(glyph);
return true;
@ -267,61 +267,61 @@ void make_distance_map( unsigned char *img, unsigned char *outImg, unsigned int
double * data = (double *) calloc( width * height, sizeof(double) );
double * outside = (double *) calloc( width * height, sizeof(double) );
double * inside = (double *) calloc( width * height, sizeof(double) );
uint32_t i;
uint32_t ii;
// Convert img into double (data)
double img_min = 255, img_max = -255;
for( i=0; i<width*height; ++i)
for( ii=0; ii<width*height; ++ii)
{
double v = img[i];
data[i] = v;
double v = img[ii];
data[ii] = v;
if (v > img_max) img_max = v;
if (v < img_min) img_min = v;
}
// Rescale image levels between 0 and 1
for( i=0; i<width*height; ++i)
for( ii=0; ii<width*height; ++ii)
{
data[i] = (img[i]-img_min)/(img_max-img_min);
data[ii] = (img[ii]-img_min)/(img_max-img_min);
}
// Compute outside = edtaa3(bitmap); % Transform background (0's)
computegradient( data, width, height, gx, gy);
edtaa3(data, gx, gy, width, height, xdist, ydist, outside);
for( i=0; i<width*height; ++i)
if( outside[i] < 0 )
outside[i] = 0.0;
for( ii=0; ii<width*height; ++ii)
if( outside[ii] < 0 )
outside[ii] = 0.0;
// Compute inside = edtaa3(1-bitmap); % Transform foreground (1's)
memset(gx, 0, sizeof(double)*width*height );
memset(gy, 0, sizeof(double)*width*height );
for( i=0; i<width*height; ++i)
data[i] = 1.0 - data[i];
for( ii=0; ii<width*height; ++ii)
data[ii] = 1.0 - data[ii];
computegradient( data, width, height, gx, gy);
edtaa3(data, gx, gy, width, height, xdist, ydist, inside);
for( i=0; i<width*height; ++i)
if( inside[i] < 0 )
inside[i] = 0.0;
for( ii=0; ii<width*height; ++ii)
if( inside[ii] < 0 )
inside[ii] = 0.0;
// distmap = outside - inside; % Bipolar distance field
unsigned char *out = outImg;//(unsigned char *) malloc( width * height * sizeof(unsigned char) );
for( i=0; i<width*height; ++i)
for( ii=0; ii<width*height; ++ii)
{
//out[i] = 127 - outside[i]*8;
//if(out[i]<0) out[i] = 0;
//out[i] += inside[i]*16;
//if(out[i]>255) out[i] = 255;
outside[i] -= inside[i];
outside[i] = 128 + outside[i]*16;
outside[ii] -= inside[ii];
outside[ii] = 128 + outside[ii]*16;
//if(outside[i] > 8) outside[i] = 8;
//if(inside[i] > 8) outside[i] = 8;
//outside[i] = 128 - inside[i]*8 + outside[i]*8;
if( outside[i] < 0 ) outside[i] = 0;
if( outside[i] > 255 ) outside[i] = 255;
out[i] = 255 - (unsigned char) outside[i];
if( outside[ii] < 0 ) outside[ii] = 0;
if( outside[ii] > 255 ) outside[ii] = 255;
out[ii] = 255 - (unsigned char) outside[ii];
//out[i] = (unsigned char) outside[i];
}
@ -374,11 +374,11 @@ bool FontManager::TrueTypeFont::bakeGlyphDistance(CodePoint_t _codePoint, GlyphI
int32_t depth=1;
int32_t stride = bitmap->bitmap.pitch;
for(int32_t i=0; i<h; ++i )
for(int32_t ii=0; ii<h; ++ii )
{
memcpy(_outBuffer+(i*w) * charsize * depth,
bitmap->bitmap.buffer + (i*stride) * charsize, w * charsize * depth );
memcpy(_outBuffer+(ii*w) * charsize * depth,
bitmap->bitmap.buffer + (ii*stride) * charsize, w * charsize * depth );
}
FT_Done_Glyph(glyph);
@ -398,9 +398,9 @@ bool FontManager::TrueTypeFont::bakeGlyphDistance(CodePoint_t _codePoint, GlyphI
memset(alphaImg, 0, nw*nh*sizeof(uint8_t));
//copy the original buffer to the temp one
for(uint32_t i= dh; i< nh-dh; ++i)
for(uint32_t ii= dh; ii< nh-dh; ++ii)
{
memcpy(alphaImg+i*nw+dw, _outBuffer+(i-dh)*w, w);
memcpy(alphaImg+ii*nw+dw, _outBuffer+(ii-dh)*w, w);
}
make_distance_map(alphaImg, _outBuffer, nw, nh);
@ -653,10 +653,10 @@ bool FontManager::preloadGlyph(FontHandle _handle, const wchar_t* _string)
if(font.m_trueTypeFont != NULL)
{
//parse string
for( uint32_t i=0, end = wcslen(_string) ; i < end; ++i )
for( uint32_t ii=0, end = wcslen(_string) ; ii < end; ++ii )
{
//if glyph cached, continue
CodePoint_t codePoint = _string[i];
CodePoint_t codePoint = _string[ii];
if(!preloadGlyph(_handle, codePoint))
{
return false;

View file

@ -288,10 +288,10 @@ void TextBuffer::appendText(FontHandle _fontHandle, const wchar_t * _string)
}
//parse string
for( uint32_t i=0, end = wcslen(_string) ; i < end; ++i )
for( uint32_t ii=0, end = wcslen(_string) ; ii < end; ++ii )
{
//if glyph cached, continue
uint32_t _codePoint = _string[i];
uint32_t _codePoint = _string[ii];
if(m_fontManager->getGlyphInfo(_fontHandle, _codePoint, glyph))
{
appendGlyph(_codePoint, font, glyph);
@ -489,19 +489,19 @@ void TextBuffer::appendGlyph(CodePoint_t _codePoint, const FontInfo& _font, cons
void TextBuffer::verticalCenterLastLine(float _dy, float _top, float _bottom)
{
for( uint32_t i=m_lineStartIndex; i < m_vertexCount; i+=4 )
for( uint32_t ii=m_lineStartIndex; ii < m_vertexCount; ii+=4 )
{
if( m_styleBuffer[i] == STYLE_BACKGROUND)
if( m_styleBuffer[ii] == STYLE_BACKGROUND)
{
m_vertexBuffer[i+0].y = _top;
m_vertexBuffer[i+1].y = _bottom;
m_vertexBuffer[i+2].y = _bottom;
m_vertexBuffer[i+3].y = _top;
m_vertexBuffer[ii+0].y = _top;
m_vertexBuffer[ii+1].y = _bottom;
m_vertexBuffer[ii+2].y = _bottom;
m_vertexBuffer[ii+3].y = _top;
}else{
m_vertexBuffer[i+0].y += _dy;
m_vertexBuffer[i+1].y += _dy;
m_vertexBuffer[i+2].y += _dy;
m_vertexBuffer[i+3].y += _dy;
m_vertexBuffer[ii+0].y += _dy;
m_vertexBuffer[ii+1].y += _dy;
m_vertexBuffer[ii+2].y += _dy;
m_vertexBuffer[ii+3].y += _dy;
}
}
}